12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- use std:: collections:: BTreeMap ;
15
+ use std:: collections:: HashMap ;
16
16
use std:: sync:: Arc ;
17
17
18
18
use databend_common_exception:: ErrorCode ;
19
19
use databend_common_exception:: Result ;
20
- use databend_common_meta_app:: schema:: CreateOption ;
21
- use databend_common_meta_app:: schema:: CreateTableReq ;
22
- use databend_common_meta_app:: schema:: DropTableByIdReq ;
23
- use databend_common_meta_app:: schema:: TableMeta ;
24
- use databend_common_meta_app:: schema:: TableNameIdent ;
20
+ use databend_common_meta_app:: schema:: UpsertTableOptionReq ;
21
+ use databend_common_meta_types:: MatchSeq ;
25
22
use databend_common_sql:: plans:: AlterViewPlan ;
26
23
use databend_common_sql:: Planner ;
27
- use databend_common_storages_view:: view_table:: VIEW_ENGINE ;
28
24
29
25
use crate :: interpreters:: Interpreter ;
30
26
use crate :: pipelines:: PipelineBuildResult ;
@@ -54,27 +50,12 @@ impl Interpreter for AlterViewInterpreter {
54
50
55
51
#[ async_backtrace:: framed]
56
52
async fn execute2 ( & self ) -> Result < PipelineBuildResult > {
57
- // drop view
58
53
let catalog = self . ctx . get_catalog ( & self . plan . catalog ) . await ?;
59
54
if let Ok ( tbl) = catalog
60
55
. get_table ( & self . plan . tenant , & self . plan . database , & self . plan . view_name )
61
56
. await
62
57
{
63
- let db = catalog
64
- . get_database ( & self . plan . tenant , & self . plan . database )
65
- . await ?;
66
- catalog
67
- . drop_table_by_id ( DropTableByIdReq {
68
- if_exists : true ,
69
- tenant : self . plan . tenant . clone ( ) ,
70
- table_name : self . plan . view_name . clone ( ) ,
71
- tb_id : tbl. get_id ( ) ,
72
- db_id : db. get_db_info ( ) . ident . db_id ,
73
- } )
74
- . await ?;
75
-
76
- // create new view
77
- let mut options = BTreeMap :: new ( ) ;
58
+ let mut options = HashMap :: new ( ) ;
78
59
let subquery = if self . plan . column_names . is_empty ( ) {
79
60
self . plan . subquery . clone ( )
80
61
} else {
@@ -94,22 +75,17 @@ impl Interpreter for AlterViewInterpreter {
94
75
self . plan. column_names. join( ", " )
95
76
)
96
77
} ;
97
- options. insert ( "query" . to_string ( ) , subquery) ;
78
+ options. insert ( "query" . to_string ( ) , Some ( subquery) ) ;
98
79
99
- let plan = CreateTableReq {
100
- create_option : CreateOption :: CreateIfNotExists ,
101
- name_ident : TableNameIdent {
102
- tenant : self . plan . tenant . clone ( ) ,
103
- db_name : self . plan . database . clone ( ) ,
104
- table_name : self . plan . view_name . clone ( ) ,
105
- } ,
106
- table_meta : TableMeta {
107
- engine : VIEW_ENGINE . to_string ( ) ,
108
- options,
109
- ..Default :: default ( )
110
- } ,
80
+ let req = UpsertTableOptionReq {
81
+ table_id : tbl. get_id ( ) ,
82
+ seq : MatchSeq :: Exact ( tbl. get_table_info ( ) . ident . seq ) ,
83
+ options,
111
84
} ;
112
- catalog. create_table ( plan) . await ?;
85
+
86
+ catalog
87
+ . upsert_table_option ( & self . plan . tenant , & self . plan . database , req)
88
+ . await ?;
113
89
114
90
Ok ( PipelineBuildResult :: create ( ) )
115
91
} else {
0 commit comments