Skip to content

fix(SchemaTree): add actions to external objects #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/containers/Tenant/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"actions.copyPath": "Copy path",
"actions.openPreview": "Open preview",
"actions.createTable": "Create table...",
"actions.createExternalTable": "Create external table...",
"actions.dropTable": "Drop table...",
"actions.alterTable": "Alter table...",
"actions.selectQuery": "Select query...",
"actions.upsertQuery": "Upsert query..."
Expand Down
2 changes: 2 additions & 0 deletions src/containers/Tenant/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"actions.copyPath": "Скопировать путь",
"actions.openPreview": "Открыть превью",
"actions.createTable": "Создать таблицу...",
"actions.createExternalTable": "Создать внешнюю таблицу...",
"actions.dropTable": "Удалить таблицу...",
"actions.alterTable": "Изменить таблицу...",
"actions.selectQuery": "Select запрос...",
"actions.upsertQuery": "Upsert запрос..."
Expand Down
30 changes: 29 additions & 1 deletion src/containers/Tenant/utils/schemaActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ const upsertQueryTemplate = (path: string) => {
VALUES ( );`;
};

const dropExternalTableTemplate = (path: string) => {
return `DROP EXTERNAL TABLE \`${path}\`;`;
};

const createExternalTableTemplate = (path: string) => {
// Remove data source name from path
// to create table in the same folder with data source
const targetPath = path.split('/').slice(0, -1).join('/');

return `CREATE EXTERNAL TABLE \`${targetPath}/my_external_table\` (
column1 Int,
column2 Int
) WITH (
DATA_SOURCE="${path}",
LOCATION="",
FORMAT="json_as_string",
\`file_pattern\`=""
);`;
};

interface ActionsAdditionalEffects {
setQueryMode: SetQueryModeIfAvailable;
setActivePath: (path: string) => void;
Expand Down Expand Up @@ -66,6 +86,8 @@ const bindActions = (
alterTable: inputQuery(alterTableTemplate, 'script'),
selectQuery: inputQuery(selectQueryTemplate),
upsertQuery: inputQuery(upsertQueryTemplate),
createExternalTable: inputQuery(createExternalTableTemplate, 'script'),
dropExternalTable: inputQuery(dropExternalTableTemplate, 'script'),
selectQueryFromExternalTable: inputQuery(
selectQueryTemplate,
'query',
Expand Down Expand Up @@ -126,6 +148,12 @@ export const getActions =
action: actions.selectQueryFromExternalTable,
},
],
[{text: i18n('actions.dropTable'), action: actions.dropExternalTable}],
];

const EXTERNAL_DATA_SOURCE_SET = [
[copyItem],
[{text: i18n('actions.createExternalTable'), action: actions.createExternalTable}],
];

const JUST_COPY: ActionsSet = [copyItem];
Expand All @@ -145,7 +173,7 @@ export const getActions =
index: JUST_COPY,

external_table: EXTERNAL_TABLE_SET,
external_data_source: JUST_COPY,
external_data_source: EXTERNAL_DATA_SOURCE_SET,
};

return nodeTypeToActions[type];
Expand Down