Skip to content

Commit 5029579

Browse files
fix(SchemaTree): add actions to external objects (#497)
1 parent 88d9041 commit 5029579

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/containers/Tenant/i18n/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"actions.copyPath": "Copy path",
1414
"actions.openPreview": "Open preview",
1515
"actions.createTable": "Create table...",
16+
"actions.createExternalTable": "Create external table...",
17+
"actions.dropTable": "Drop table...",
1618
"actions.alterTable": "Alter table...",
1719
"actions.selectQuery": "Select query...",
1820
"actions.upsertQuery": "Upsert query..."

src/containers/Tenant/i18n/ru.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"actions.copyPath": "Скопировать путь",
1414
"actions.openPreview": "Открыть превью",
1515
"actions.createTable": "Создать таблицу...",
16+
"actions.createExternalTable": "Создать внешнюю таблицу...",
17+
"actions.dropTable": "Удалить таблицу...",
1618
"actions.alterTable": "Изменить таблицу...",
1719
"actions.selectQuery": "Select запрос...",
1820
"actions.upsertQuery": "Upsert запрос..."

src/containers/Tenant/utils/schemaActions.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ const upsertQueryTemplate = (path: string) => {
3636
VALUES ( );`;
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+
3959
interface 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

Comments
 (0)