Skip to content

Commit 09d7cf0

Browse files
fix(SchemaViewer): use partitioning keys order from HashColumns
1 parent 0a49720 commit 09d7cf0

File tree

7 files changed

+425
-31
lines changed

7 files changed

+425
-31
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
import type {TEvDescribeSchemeResult} from '../../../../../types/api/schema';
2+
import {EPathType} from '../../../../../types/api/schema';
3+
import {prepareSchemaData, prepareViewSchema} from '../prepareData';
4+
5+
describe('prepareSchemaData', () => {
6+
it('correctly parses row table data', () => {
7+
const data: TEvDescribeSchemeResult = {
8+
PathDescription: {
9+
Table: {
10+
Name: 'my_row_table',
11+
Columns: [
12+
{
13+
Name: 'id',
14+
Type: 'Uint64',
15+
TypeId: 4,
16+
Id: 1,
17+
Family: 0,
18+
FamilyName: 'default',
19+
NotNull: false,
20+
},
21+
{
22+
Name: 'category_id',
23+
Type: 'Uint64',
24+
TypeId: 4,
25+
Id: 2,
26+
Family: 0,
27+
FamilyName: 'default',
28+
NotNull: true,
29+
},
30+
{
31+
Name: 'name',
32+
Type: 'Utf8',
33+
TypeId: 4608,
34+
Id: 3,
35+
Family: 0,
36+
FamilyName: 'default',
37+
DefaultFromLiteral: {
38+
type: {
39+
type_id: 'UTF8',
40+
},
41+
value: {
42+
text_value: 'Ivan',
43+
},
44+
},
45+
NotNull: true,
46+
},
47+
{
48+
Name: 'updated_on',
49+
Type: 'Datetime',
50+
TypeId: 49,
51+
Id: 4,
52+
Family: 0,
53+
FamilyName: 'default',
54+
NotNull: false,
55+
},
56+
],
57+
KeyColumnNames: ['category_id', 'name', 'id'],
58+
KeyColumnIds: [2, 3, 1],
59+
PartitionConfig: {
60+
ColumnFamilies: [
61+
{
62+
Id: 0,
63+
StorageConfig: {
64+
SysLog: {
65+
PreferredPoolKind: 'ssd',
66+
},
67+
Log: {
68+
PreferredPoolKind: 'ssd',
69+
},
70+
Data: {
71+
PreferredPoolKind: 'ssd',
72+
},
73+
},
74+
},
75+
],
76+
},
77+
},
78+
},
79+
};
80+
81+
const result = [
82+
{
83+
id: 1,
84+
name: 'id',
85+
keyColumnIndex: 2,
86+
type: 'Uint64',
87+
notNull: false,
88+
autoIncrement: false,
89+
defaultValue: '-',
90+
familyName: undefined,
91+
prefferedPoolKind: undefined,
92+
columnCodec: undefined,
93+
},
94+
{
95+
id: 2,
96+
name: 'category_id',
97+
keyColumnIndex: 0,
98+
type: 'Uint64',
99+
notNull: true,
100+
autoIncrement: false,
101+
defaultValue: '-',
102+
familyName: undefined,
103+
prefferedPoolKind: undefined,
104+
columnCodec: undefined,
105+
},
106+
{
107+
id: 3,
108+
name: 'name',
109+
keyColumnIndex: 1,
110+
type: 'Utf8',
111+
notNull: true,
112+
autoIncrement: false,
113+
defaultValue: 'Ivan',
114+
familyName: undefined,
115+
prefferedPoolKind: undefined,
116+
columnCodec: undefined,
117+
},
118+
{
119+
id: 4,
120+
name: 'updated_on',
121+
keyColumnIndex: -1,
122+
type: 'Datetime',
123+
notNull: false,
124+
autoIncrement: false,
125+
defaultValue: '-',
126+
familyName: undefined,
127+
prefferedPoolKind: undefined,
128+
columnCodec: undefined,
129+
},
130+
];
131+
132+
expect(prepareSchemaData(EPathType.EPathTypeTable, data)).toEqual(result);
133+
});
134+
it('correctly parses column table data', () => {
135+
const data: TEvDescribeSchemeResult = {
136+
PathDescription: {
137+
ColumnTableDescription: {
138+
Name: 'my_column_table',
139+
Schema: {
140+
Columns: [
141+
{
142+
Id: 1,
143+
Name: 'title',
144+
Type: 'Utf8',
145+
TypeId: 4608,
146+
NotNull: true,
147+
StorageId: '',
148+
DefaultValue: {},
149+
ColumnFamilyId: 0,
150+
},
151+
{
152+
Id: 2,
153+
Name: 'author',
154+
Type: 'Utf8',
155+
TypeId: 4608,
156+
NotNull: true,
157+
StorageId: '',
158+
DefaultValue: {},
159+
ColumnFamilyId: 0,
160+
},
161+
{
162+
Id: 3,
163+
Name: 'id',
164+
Type: 'Int64',
165+
TypeId: 3,
166+
NotNull: true,
167+
StorageId: '',
168+
DefaultValue: {},
169+
ColumnFamilyId: 0,
170+
},
171+
{
172+
Id: 4,
173+
Name: 'body',
174+
Type: 'Utf8',
175+
TypeId: 4608,
176+
NotNull: false,
177+
StorageId: '',
178+
DefaultValue: {},
179+
ColumnFamilyId: 0,
180+
},
181+
],
182+
KeyColumnNames: ['author', 'title', 'id'],
183+
Version: '1',
184+
Options: {
185+
SchemeNeedActualization: false,
186+
},
187+
ColumnFamilies: [
188+
{
189+
Id: 0,
190+
Name: 'default',
191+
},
192+
],
193+
},
194+
ColumnShardCount: 64,
195+
Sharding: {
196+
ColumnShards: ['72075186224107692'],
197+
HashSharding: {
198+
Function: 'HASH_FUNCTION_CONSISTENCY_64',
199+
Columns: ['id', 'author', 'title'],
200+
},
201+
},
202+
StorageConfig: {
203+
DataChannelCount: 64,
204+
},
205+
},
206+
},
207+
};
208+
const result = [
209+
{
210+
id: 1,
211+
name: 'title',
212+
keyColumnIndex: 1,
213+
partitioningColumnIndex: 2,
214+
type: 'Utf8',
215+
notNull: true,
216+
},
217+
{
218+
id: 2,
219+
name: 'author',
220+
keyColumnIndex: 0,
221+
partitioningColumnIndex: 1,
222+
type: 'Utf8',
223+
notNull: true,
224+
},
225+
{
226+
id: 3,
227+
name: 'id',
228+
keyColumnIndex: 2,
229+
partitioningColumnIndex: 0,
230+
type: 'Int64',
231+
notNull: true,
232+
},
233+
{
234+
id: 4,
235+
name: 'body',
236+
keyColumnIndex: -1,
237+
partitioningColumnIndex: -1,
238+
type: 'Utf8',
239+
notNull: false,
240+
},
241+
];
242+
expect(prepareSchemaData(EPathType.EPathTypeColumnTable, data)).toEqual(result);
243+
});
244+
it('returns empty array if data is undefined, empty or null', () => {
245+
expect(prepareSchemaData(EPathType.EPathTypeTable, {})).toEqual([]);
246+
expect(prepareSchemaData(EPathType.EPathTypeTable, undefined)).toEqual([]);
247+
expect(prepareSchemaData(EPathType.EPathTypeTable, null)).toEqual([]);
248+
});
249+
});
250+
251+
describe('prepareViewSchema', () => {
252+
it('correctly parses data', () => {
253+
const data = [
254+
{name: 'cost', type: 'Int32'},
255+
{name: 'id', type: 'Int32'},
256+
{name: 'price', type: 'Double'},
257+
{name: 'value', type: 'Utf8?'},
258+
];
259+
const result = [
260+
{type: 'Int32', name: 'cost'},
261+
{type: 'Int32', name: 'id'},
262+
{type: 'Double', name: 'price'},
263+
{type: 'Utf8', name: 'value'},
264+
];
265+
266+
expect(prepareViewSchema(data)).toEqual(result);
267+
});
268+
it('returns empty array if data is undefined or empty', () => {
269+
expect(prepareViewSchema()).toEqual([]);
270+
expect(prepareViewSchema([])).toEqual([]);
271+
});
272+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import {getPartitioningKeys, getPrimaryKeys} from '../utils';
2+
3+
describe('getPartitioningKeys', () => {
4+
it('returns column in the provided order', () => {
5+
const data1 = [
6+
{
7+
id: 1,
8+
name: 'l_linenumber',
9+
keyColumnIndex: 0,
10+
partitioningColumnIndex: 1,
11+
type: 'Int64',
12+
notNull: true,
13+
},
14+
{
15+
id: 2,
16+
name: 'l_orderkey',
17+
keyColumnIndex: 1,
18+
partitioningColumnIndex: 0,
19+
type: 'Int64',
20+
notNull: true,
21+
},
22+
];
23+
24+
expect(getPartitioningKeys(data1)).toEqual(['l_orderkey', 'l_linenumber']);
25+
26+
const data2 = [
27+
{
28+
id: 1,
29+
name: 'title',
30+
keyColumnIndex: 1,
31+
partitioningColumnIndex: 2,
32+
type: 'Utf8',
33+
notNull: true,
34+
},
35+
{
36+
id: 2,
37+
name: 'author',
38+
keyColumnIndex: 0,
39+
partitioningColumnIndex: 1,
40+
type: 'Utf8',
41+
notNull: true,
42+
},
43+
{
44+
id: 3,
45+
name: 'id',
46+
keyColumnIndex: 2,
47+
partitioningColumnIndex: 0,
48+
type: 'Int64',
49+
notNull: true,
50+
},
51+
{
52+
id: 4,
53+
name: 'body',
54+
keyColumnIndex: -1,
55+
partitioningColumnIndex: -1,
56+
type: 'Utf8',
57+
notNull: false,
58+
},
59+
];
60+
expect(getPartitioningKeys(data2)).toEqual(['id', 'author', 'title']);
61+
});
62+
});
63+
64+
describe('getPrimaryKeys', () => {
65+
it('returns column in the provided order', () => {
66+
const data = [
67+
{
68+
id: 1,
69+
name: 'id',
70+
keyColumnIndex: 2,
71+
type: 'Uint64',
72+
notNull: false,
73+
autoIncrement: false,
74+
},
75+
{
76+
id: 2,
77+
name: 'category_id',
78+
keyColumnIndex: 0,
79+
type: 'Uint64',
80+
notNull: true,
81+
autoIncrement: false,
82+
},
83+
{
84+
id: 3,
85+
name: 'name',
86+
keyColumnIndex: 1,
87+
type: 'Utf8',
88+
notNull: true,
89+
autoIncrement: false,
90+
},
91+
{
92+
id: 4,
93+
name: 'updated_on',
94+
keyColumnIndex: -1,
95+
type: 'Datetime',
96+
notNull: false,
97+
autoIncrement: false,
98+
},
99+
];
100+
101+
expect(getPrimaryKeys(data)).toEqual(['category_id', 'name', 'id']);
102+
});
103+
});

src/containers/Tenant/Schema/SchemaViewer/prepareData.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,14 @@ function prepareColumnTableSchema(data: TColumnTableDescription = {}): SchemaDat
103103
const keyColumnIndex =
104104
KeyColumnNames?.findIndex((keyColumnName) => keyColumnName === Name) ?? -1;
105105

106-
const isPartitioningKeyColumn = Boolean(
107-
HashColumns?.find((hashColumnName) => hashColumnName === Name),
108-
);
106+
const partitioningColumnIndex =
107+
HashColumns?.findIndex((hashColumnName) => hashColumnName === Name) ?? -1;
109108

110109
return {
111110
id: Id,
112111
name: Name,
113112
keyColumnIndex,
114-
isPartitioningKeyColumn,
113+
partitioningColumnIndex,
115114
type: Type,
116115
notNull: NotNull,
117116
};

0 commit comments

Comments
 (0)