@@ -36,6 +36,26 @@ const upsertQueryTemplate = (path: string) => {
3636VALUES ( );` ;
3737} ;
3838
39+ const dropExternalTableTemplate = ( path : string ) => {
40+ return `DROP EXTERNAL TABLE \`${ path } \`;` ;
41+ } ;
42+
43+ const createExternalTableTemplate = ( path : string ) => {
44+ // Remove data source name from path
45+ // to create table in the same folder with data source
46+ const targetPath = path . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) ;
47+
48+ return `CREATE EXTERNAL TABLE \`${ targetPath } /my_external_table\` (
49+ column1 Int,
50+ column2 Int
51+ ) WITH (
52+ DATA_SOURCE="${ path } ",
53+ LOCATION="",
54+ FORMAT="json_as_string",
55+ \`file_pattern\`=""
56+ );` ;
57+ } ;
58+
3959interface ActionsAdditionalEffects {
4060 setQueryMode : SetQueryModeIfAvailable ;
4161 setActivePath : ( path : string ) => void ;
@@ -66,6 +86,8 @@ const bindActions = (
6686 alterTable : inputQuery ( alterTableTemplate , 'script' ) ,
6787 selectQuery : inputQuery ( selectQueryTemplate ) ,
6888 upsertQuery : inputQuery ( upsertQueryTemplate ) ,
89+ createExternalTable : inputQuery ( createExternalTableTemplate , 'script' ) ,
90+ dropExternalTable : inputQuery ( dropExternalTableTemplate , 'script' ) ,
6991 selectQueryFromExternalTable : inputQuery (
7092 selectQueryTemplate ,
7193 'query' ,
@@ -126,6 +148,12 @@ export const getActions =
126148 action : actions . selectQueryFromExternalTable ,
127149 } ,
128150 ] ,
151+ [ { text : i18n ( 'actions.dropTable' ) , action : actions . dropExternalTable } ] ,
152+ ] ;
153+
154+ const EXTERNAL_DATA_SOURCE_SET = [
155+ [ copyItem ] ,
156+ [ { text : i18n ( 'actions.createExternalTable' ) , action : actions . createExternalTable } ] ,
129157 ] ;
130158
131159 const JUST_COPY : ActionsSet = [ copyItem ] ;
@@ -145,7 +173,7 @@ export const getActions =
145173 index : JUST_COPY ,
146174
147175 external_table : EXTERNAL_TABLE_SET ,
148- external_data_source : JUST_COPY ,
176+ external_data_source : EXTERNAL_DATA_SOURCE_SET ,
149177 } ;
150178
151179 return nodeTypeToActions [ type ] ;
0 commit comments