Skip to content

Commit cc81623

Browse files
authoredFeb 6, 2025··
feat: extend alter table query templates with enable auto split (#1913)
1 parent fe3845c commit cc81623

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed
 

‎src/containers/Tenant/i18n/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
"actions.dropTopic": "Drop topic...",
3939
"actions.dropView": "Drop view...",
4040
"actions.alterTable": "Alter table...",
41+
"actions.manageColumns": "Manage columns...",
42+
"actions.manageAutoPartitioning": "Manage auto partitioning...",
4143
"actions.addTableIndex": "Add index...",
4244
"actions.createCdcStream": "Create changefeed...",
4345
"actions.alterTopic": "Alter topic...",

‎src/containers/Tenant/utils/schemaActions.tsx

+14-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
dropTableTemplate,
3434
dropTopicTemplate,
3535
dropViewTemplate,
36+
manageAutoPartitioningTemplate,
3637
selectQueryTemplate,
3738
upsertQueryTemplate,
3839
} from './schemaQueryTemplates';
@@ -101,6 +102,7 @@ const bindActions = (
101102
dropAsyncReplication: inputQuery(dropAsyncReplicationTemplate),
102103
alterTable: inputQuery(alterTableTemplate),
103104
dropTable: inputQuery(dropTableTemplate),
105+
manageAutoPartitioning: inputQuery(manageAutoPartitioningTemplate),
104106
selectQuery: inputQuery(selectQueryTemplate),
105107
upsertQuery: inputQuery(upsertQueryTemplate),
106108
createExternalTable: inputQuery(createExternalTableTemplate),
@@ -183,6 +185,16 @@ export const getActions =
183185
{text: i18n('actions.createView'), action: actions.createView},
184186
];
185187

188+
const alterTableGroupItem = {
189+
text: i18n('actions.alterTable'),
190+
items: [
191+
{text: i18n('actions.manageColumns'), action: actions.alterTable},
192+
{
193+
text: i18n('actions.manageAutoPartitioning'),
194+
action: actions.manageAutoPartitioning,
195+
},
196+
],
197+
};
186198
const DB_SET: ActionsSet = [[copyItem, connectToDBItem], createEntitiesSet];
187199

188200
const DIR_SET: ActionsSet = [[copyItem], createEntitiesSet];
@@ -200,7 +212,7 @@ export const getActions =
200212
const ROW_TABLE_SET: ActionsSet = [
201213
[copyItem],
202214
[
203-
{text: i18n('actions.alterTable'), action: actions.alterTable},
215+
alterTableGroupItem,
204216
{text: i18n('actions.dropTable'), action: actions.dropTable},
205217
getActionWithLoader({
206218
text: i18n('actions.selectQuery'),
@@ -219,7 +231,7 @@ export const getActions =
219231
const COLUMN_TABLE_SET: ActionsSet = [
220232
[copyItem],
221233
[
222-
{text: i18n('actions.alterTable'), action: actions.alterTable},
234+
alterTableGroupItem,
223235
{text: i18n('actions.dropTable'), action: actions.dropTable},
224236
{text: i18n('actions.selectQuery'), action: actions.selectQuery},
225237
{text: i18n('actions.upsertQuery'), action: actions.upsertQuery},

‎src/containers/Tenant/utils/schemaQueryTemplates.ts

+15
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ ALTER TABLE ${path}
8484
-- DROP COLUMN some_existing_column
8585
\${2:ADD COLUMN numeric_column Int32};`;
8686
};
87+
88+
export const manageAutoPartitioningTemplate = (params?: SchemaQueryParams) => {
89+
const path = params?.relativePath ? `\`${params?.relativePath}\`` : '${1:<my_table>}';
90+
91+
return `-- documentation about partitioning https://ydb.tech/docs/en/concepts/datamodel/table#partitioning
92+
93+
ALTER TABLE ${path} SET
94+
(
95+
AUTO_PARTITIONING_BY_LOAD = ENABLED, -- If a partition consumes more than 50% of the CPU for a few dozens of seconds, it is enqueued for splitting.
96+
AUTO_PARTITIONING_BY_SIZE = ENABLED, -- If a partition size exceeds the value specified by the AUTO_PARTITIONING_PARTITION_SIZE_MB parameter, it is enqueued for splitting.
97+
AUTO_PARTITIONING_PARTITION_SIZE_MB = 2048,
98+
AUTO_PARTITIONING_MIN_PARTITIONS_COUNT = 10, -- Partitions are merged only if their actual number exceeds the value specified by this parameter.
99+
AUTO_PARTITIONING_MAX_PARTITIONS_COUNT = 100 -- Partitions are split only if their number doesn't exceed the value specified by this parameter.
100+
)`;
101+
};
87102
export const selectQueryTemplate = (params?: SchemaQueryParams) => {
88103
const path = params?.relativePath ? `\`${params?.relativePath}\`` : '${2:<my_table>}';
89104
const columns =

0 commit comments

Comments
 (0)
Please sign in to comment.