Skip to content

Commit

Permalink
feat(SchemaTree): add actions for topic (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
krosy1337 authored Aug 15, 2023
1 parent ce4bf6d commit 6700136
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 45 deletions.
3 changes: 3 additions & 0 deletions src/containers/Tenant/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
"actions.openPreview": "Open preview",
"actions.createTable": "Create table...",
"actions.createExternalTable": "Create external table...",
"actions.createTopic": "Create topic...",
"actions.dropTable": "Drop table...",
"actions.dropTopic": "Drop topic...",
"actions.alterTable": "Alter table...",
"actions.alterTopic": "Alter topic...",
"actions.selectQuery": "Select query...",
"actions.upsertQuery": "Upsert query..."
}
3 changes: 3 additions & 0 deletions src/containers/Tenant/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
"actions.openPreview": "Открыть превью",
"actions.createTable": "Создать таблицу...",
"actions.createExternalTable": "Создать внешнюю таблицу...",
"actions.createTopic": "Создать топик...",
"actions.dropTable": "Удалить таблицу...",
"actions.dropTopic": "Удалить топик...",
"actions.alterTable": "Изменить таблицу...",
"actions.alterTopic": "Изменить топик...",
"actions.selectQuery": "Select запрос...",
"actions.upsertQuery": "Upsert запрос..."
}
89 changes: 89 additions & 0 deletions src/containers/Tenant/utils/queryTemplates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
export const createTableTemplate = (path: string) => {
return `CREATE TABLE \`${path}/my_table\`
(
\`id\` Uint64,
\`name\` String,
PRIMARY KEY (\`id\`)
);`;
};
export const alterTableTemplate = (path: string) => {
return `ALTER TABLE \`${path}\`
ADD COLUMN is_deleted Bool;`;
};
export const selectQueryTemplate = (path: string) => {
return `SELECT *
FROM \`${path}\`
LIMIT 10;`;
};
export const upsertQueryTemplate = (path: string) => {
return `UPSERT INTO \`${path}\`
( \`id\`, \`name\` )
VALUES ( );`;
};

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

export 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\`=""
);`;
};

export const createTopicTemplate = (path: string) => {
return `-- docs: https://ydb.tech/en/docs/yql/reference/syntax/create_topic
CREATE TOPIC \`${path}/my_topic\` (
CONSUMER consumer1,
CONSUMER consumer2 WITH (read_from = Datetime('2022-12-01T12:13:22Z')) -- Sets up the message write time starting from which the consumer will receive data.
-- Value type: Datetime OR Timestamp OR integer (unix-timestamp in the numeric format).
-- Default value: now
) WITH (
min_active_partitions = 5, -- Minimum number of topic partitions.
partition_count_limit = 10, -- Maximum number of active partitions in the topic. 0 is interpreted as unlimited.
retention_period = Interval('PT12H'), -- Data retention period in the topic. Value type: Interval, default value: 18h.
retention_storage_mb = 1, -- Limit on the maximum disk space occupied by the topic data.
-- When this value is exceeded, the older data is cleared, like under a retention policy.
-- 0 is interpreted as unlimited.
partition_write_speed_bytes_per_second = 2097152, -- Maximum allowed write speed per partition.
partition_write_burst_bytes = 2097152 -- Write quota allocated for write bursts.
-- When set to zero, the actual write_burst value is equalled to
-- the quota value (this allows write bursts of up to one second).
);`;
};

export const alterTopicTemplate = (path: string) => {
return `-- docs: https://ydb.tech/en/docs/yql/reference/syntax/alter_topic
ALTER TOPIC \`${path}\`
ADD CONSUMER new_consumer WITH (read_from = 0), -- Sets up the message write time starting from which the consumer will receive data.
-- Value type: Datetime OR Timestamp OR integer (unix-timestamp in the numeric format).
-- Default value: now
ALTER CONSUMER consumer1 SET (read_from = Datetime('2023-12-01T12:13:22Z')),
DROP CONSUMER consumer2,
SET (
min_active_partitions = 10, -- Minimum number of topic partitions.
partition_count_limit = 15, -- Maximum number of active partitions in the topic. 0 is interpreted as unlimited.
retention_period = Interval('PT36H'), -- Data retention period in the topic. Value type: Interval, default value: 18h.
retention_storage_mb = 10, -- Limit on the maximum disk space occupied by the topic data.
-- When this value is exceeded, the older data is cleared, like under a retention policy.
-- 0 is interpreted as unlimited.
partition_write_speed_bytes_per_second = 3145728, -- Maximum allowed write speed per partition.
partition_write_burst_bytes = 1048576 -- Write quota allocated for write bursts.
-- When set to zero, the actual write_burst value is equalled to
-- the quota value (this allows write bursts of up to one second).
);`;
};

export const dropTopicTemplate = (path: string) => {
return `DROP TOPIC \`${path}\`;`;
};
2 changes: 1 addition & 1 deletion src/containers/Tenant/utils/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const pathTypeToNodeType: Record<EPathType, NavigationTreeNodeType | undefined>

[EPathType.EPathTypeColumnTable]: 'column_table',

[EPathType.EPathTypeCdcStream]: 'topic',
[EPathType.EPathTypeCdcStream]: 'stream',
[EPathType.EPathTypePersQueueGroup]: 'topic',

[EPathType.EPathTypeExternalDataSource]: 'external_data_source',
Expand Down
71 changes: 27 additions & 44 deletions src/containers/Tenant/utils/schemaActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,17 @@ import createToast from '../../../utils/createToast';

import i18n from '../i18n';

const createTableTemplate = (path: string) => {
return `CREATE TABLE \`${path}/my_table\`
(
\`id\` Uint64,
\`name\` String,
PRIMARY KEY (\`id\`)
);`;
};
const alterTableTemplate = (path: string) => {
return `ALTER TABLE \`${path}\`
ADD COLUMN is_deleted Bool;`;
};
const selectQueryTemplate = (path: string) => {
return `SELECT *
FROM \`${path}\`
LIMIT 10;`;
};
const upsertQueryTemplate = (path: string) => {
return `UPSERT INTO \`${path}\`
( \`id\`, \`name\` )
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\`=""
);`;
};
import {
alterTableTemplate,
alterTopicTemplate,
createExternalTableTemplate,
createTableTemplate,
createTopicTemplate,
dropExternalTableTemplate,
dropTopicTemplate,
selectQueryTemplate,
upsertQueryTemplate,
} from './queryTemplates';

interface ActionsAdditionalEffects {
setQueryMode: SetQueryModeIfAvailable;
Expand Down Expand Up @@ -92,6 +61,9 @@ const bindActions = (
'query',
i18n('actions.externalTableSelectUnavailable'),
),
createTopic: inputQuery(createTopicTemplate, 'script'),
alterTopic: inputQuery(alterTopicTemplate, 'script'),
dropTopic: inputQuery(dropTopicTemplate, 'script'),
copyPath: () => {
try {
copy(path);
Expand Down Expand Up @@ -121,7 +93,10 @@ export const getActions =

const DIR_SET: ActionsSet = [
[copyItem],
[{text: i18n('actions.createTable'), action: actions.createTable}],
[
{text: i18n('actions.createTable'), action: actions.createTable},
{text: i18n('actions.createTopic'), action: actions.createTopic},
],
];
const TABLE_SET: ActionsSet = [
[copyItem],
Expand All @@ -132,6 +107,14 @@ export const getActions =
],
];

const TOPIC_SET: ActionsSet = [
[copyItem],
[
{text: i18n('actions.alterTopic'), action: actions.alterTopic},
{text: i18n('actions.dropTopic'), action: actions.dropTopic},
],
];

const EXTERNAL_TABLE_SET = [
[copyItem],
[
Expand Down Expand Up @@ -160,7 +143,7 @@ export const getActions =
column_table: TABLE_SET,

index_table: JUST_COPY,
topic: JUST_COPY,
topic: TOPIC_SET,
stream: JUST_COPY,

index: JUST_COPY,
Expand Down

0 comments on commit 6700136

Please sign in to comment.