Skip to content

Commit

Permalink
feat(Navigation/CreateTableModal): add ordered dynamic table creation…
Browse files Browse the repository at this point in the history
… [YTFRONT-4658]
  • Loading branch information
KostyaAvtushko committed Feb 3, 2025
1 parent 2edc61b commit 4b94f6c
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/ui/src/ui/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import ClusterSelectControl from './controls/ClusterSelectControl/ClusterSelectC
import SortableListControl from '../../components/Dialog/controls/SortableListControl/SortableListControl';
import BytesControl, {NumberControl} from '../../components/Dialog/controls/BytesControl';
import RoleListControl from './controls/RoleListControl/RoleListControl';
import CreateTableTabField from '../../navigation/Navigation/PathEditorModal/CreateTableModal/CreateTableTabField/CreateTableTabField';
import CreateTableTabField from '../../pages/navigation/modals/CreateTableModal/CreateTableTabField/CreateTableTabField';
import {
GroupSuggestControl,
LockSuggestControl,
} from '../../navigation/Navigation/PathEditorModal/CreateTableModal/CreateTableSuggests/CreateTableSuggests';
} from '../../pages/navigation/modals/CreateTableModal/CreateTableSuggests/CreateTableSuggests';
import SelectWithSubItems from './controls/SelectWithSubItems/SelectWithSubItems';
import CreatePoolParentSuggest from '../../pages/scheduling/Instruments/CreatePoolDialog/CreatePoolParentSuggest';
import TabletCellBundlesSuggest from '../../pages/components/TabletCellBundlesSuggest/TabletCellBundlesSuggest';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {SelectSingle} from '../../../../components/Select/Select';
import Error from '../../../../components/Error/Error';
import Icon from '../../../../components/Icon/Icon';
import TTLInfo from '../../../../components/TTLInfo/TTLInfo';
import CreateTableModal from '../../../../navigation/Navigation/PathEditorModal/CreateTableModal/CreateTableModal';
import CreateTableModal from '../../modals/CreateTableModal/CreateTableModal';
import {isCreateTableModalVisible} from '../../../../store/selectors/navigation/modals/create-table';

import MapNodesTable from './MapNodesTable';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
normalizeErasureCodec,
storageOptionFromErasureCodec,
} from '../../../utils/cypress-attributes';
import {makeLink} from '../../../navigation/Navigation/PathEditorModal/CreateTableModal/CreateTableModal';
import {makeLink} from './CreateTableModal/CreateTableModal';
import {
getCompressionCodecs,
getErasureCodecs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {SelectWithSubItemsProps} from '../../../../components/Dialog/controls/Se
import {docsUrl, getNewTableReplicasCount} from '../../../../config';

import './CreateTableModal.scss';
import {DESCENDING} from './CreateTableTabField/CreateTableTabField';
import {ASCENDING, DESCENDING} from './CreateTableTabField/CreateTableTabField';
import {FIX_MY_TYPE} from '../../../../types';
import UIFactory from '../../../../UIFactory';

Expand All @@ -67,9 +67,10 @@ export function makeLink(url: string, label = 'Help', inline = false) {
return inline ? link : <div>{link}</div>;
}

const TableType = {
DYNAMIC: 'dynamic',
STATIC: 'static',
enum TableType {
QUEUE = 'queue',
DYNAMIC = 'dynamic',
STATIC = 'static',
};

const AGGREGATE_CHOICES = [{value: SELECT_EMPTY_VALUE, text: 'default'}].concat(
Expand Down Expand Up @@ -165,7 +166,7 @@ interface TableSettingsTab {
uniqueKeys: boolean;
name: string;
replicasCount: string;
tableType: 'static' | 'dynamic';
tableType: TableType;
}

function genNewName(items: Array<{name: string}>, name: string) {
Expand Down Expand Up @@ -245,9 +246,8 @@ class CreateTableModalContentImpl extends React.Component<Props> {
} = values;
const columns = this.reorderColumns(columnsRaw);

const isDynamic = tableType === TableType.DYNAMIC;
const attributes: Record<string, any> = {
dynamic: isDynamic,
dynamic: tableType === TableType.QUEUE || tableType == TableType.DYNAMIC,
optimize_for,
};

Expand Down Expand Up @@ -314,19 +314,23 @@ class CreateTableModalContentImpl extends React.Component<Props> {
});
};

validateColumnDataType(columnData: ColumnData, isDynamicTable: boolean) {
validateColumnDataType(columnData: ColumnData, tableType: TableType) {
const {dataType, optional} = columnData || {};

if (dataType === ColumnDataTypes.ANY || dataType === ColumnDataTypes.YSON) {
if (isDynamicTable && this.isOrderedColumn(columnData)) {
if (tableType === TableType.DYNAMIC && this.isOrderedColumn(columnData)) {
return `Key-column should not be of type [${dataType}]`;
}
if (!optional) {
return `Column with type [${dataType}] should be optional.`;
}
}

if (tableType === TableType.QUEUE && this.isSortedColumn(columnData)) {
return "Queue must not have any sorted columns";
}

if (isDynamicTable && this.isDescendingColumn(columnData)) {
if (tableType === TableType.DYNAMIC && this.isDescendingColumn(columnData)) {
return "Dynamic tables do not support 'Descending' order";
}

Expand Down Expand Up @@ -356,13 +360,13 @@ class CreateTableModalContentImpl extends React.Component<Props> {
return undefined;
}

validateColumnData(columnData: ColumnData, isDynamicTable: boolean) {
validateColumnData(columnData: ColumnData, tableType: TableType) {
const res: Record<string, string> = {};
const aggregate = this.validateAggregate(columnData);
if (aggregate) {
res.aggregate = aggregate;
}
const dataType = this.validateColumnDataType(columnData, isDynamicTable);
const dataType = this.validateColumnDataType(columnData, tableType);
if (dataType) {
res.dataType = dataType;
}
Expand Down Expand Up @@ -398,11 +402,20 @@ class CreateTableModalContentImpl extends React.Component<Props> {
return Boolean(this.props.keyColumns[id]);
}

isAscendingColumn(columnData: ColumnData) {
const {id} = columnData;
return this.props.keyColumns[id] === ASCENDING;
}

isDescendingColumn(columnData: ColumnData) {
const {id} = columnData;
return this.props.keyColumns[id] === DESCENDING;
}

isSortedColumn(columnData: ColumnData) {
return this.isAscendingColumn(columnData) || this.isDescendingColumn(columnData);
}

validateTableSettings(tableSettings: TableSettingsTab, columns: Array<ColumnData>) {
const res: Partial<Record<keyof TableSettingsTab, string>> = {};
const hasOrderedColumn = some_(columns, (colData) => this.isOrderedColumn(colData));
Expand All @@ -417,7 +430,11 @@ class CreateTableModalContentImpl extends React.Component<Props> {

if (tableType === TableType.DYNAMIC && (!hasOrderedColumn || !hasUnorderedColumn)) {
res.tableType =
'Any dynamic table must have at least one sorted column and one unsorted column';
'Dynamic table must have at least one sorted column and one unsorted column';
}

if (tableType === TableType.QUEUE && hasOrderedColumn) {
res.tableType = 'Queue must not have any sorted columns'
}

if (tableType === TableType.DYNAMIC && !res.tableType) {
Expand Down Expand Up @@ -463,6 +480,7 @@ class CreateTableModalContentImpl extends React.Component<Props> {
const columns: Array<ColumnData> = values[COLUMNS];
this.columns = columns;
const nameCounters: Record<string, Array<number>> = {};

forEach_(columns, (columnData, index) => {
const {name} = columnData;
const nameIndexes = nameCounters[name];
Expand All @@ -475,7 +493,7 @@ class CreateTableModalContentImpl extends React.Component<Props> {
// Validate column
setError(
`${COLUMNS}[${index}]`,
this.validateColumnData(columnData, tableType === TableType.DYNAMIC),
this.validateColumnData(columnData, tableType),
);
});
forEach_(nameCounters, (indices) => {
Expand Down Expand Up @@ -610,11 +628,15 @@ class CreateTableModalContentImpl extends React.Component<Props> {
options: [
{
value: TableType.STATIC,
label: 'Static',
label: 'Static table',
},
{
value: TableType.DYNAMIC,
label: 'Dynamic',
label: 'Dynamic table',
},
{
value: TableType.QUEUE,
label: 'Queue',
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
remoteCopy,
} from '../../../store/actions/navigation/modals/remote-copy-modal';
import {getCluster} from '../../../store/selectors/global';
import {makeLink} from '../../../navigation/Navigation/PathEditorModal/CreateTableModal/CreateTableModal';
import {makeLink} from './CreateTableModal/CreateTableModal';
import {YTError} from '../../../types';
import {RemoteCopyParams} from '../../../../@types/types';
import {AxiosError} from 'axios';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import {DialogError, FormApi, YTDFDialog} from '../../../components/Dialog';
import {makeLink} from '../../../navigation/Navigation/PathEditorModal/CreateTableModal/CreateTableModal';
import {makeLink} from './CreateTableModal/CreateTableModal';
import {useDispatch, useSelector} from 'react-redux';
import {
hideTableEraseModal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
tableSortModalLoadColumns,
} from '../../../../store/actions/navigation/modals/table-merge-sort-modal';
import {getCurrentUserName} from '../../../../store/selectors/global';
import {makeLink} from '../../../../navigation/Navigation/PathEditorModal/CreateTableModal/CreateTableModal';
import {makeLink} from '../CreateTableModal/CreateTableModal';
import {parseBytes} from '../../../../utils';
import {docsUrl} from '../../../../config';
import UIFactory from '../../../../UIFactory';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
tableSortModalLoadColumns,
} from '../../../../store/actions/navigation/modals/table-merge-sort-modal';
import {getCurrentUserName} from '../../../../store/selectors/global';
import {makeLink} from '../../../../navigation/Navigation/PathEditorModal/CreateTableModal/CreateTableModal';
import {makeLink} from '../CreateTableModal/CreateTableModal';
import './TableSortModal.scss';
import {ColumnSortByInfo} from './TableSortByControl';
import {docsUrl} from '../../../../config';
Expand Down

0 comments on commit 4b94f6c

Please sign in to comment.