-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix(SchemaViewer): use partitioning keys order from HashColumns #1916
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
272 changes: 272 additions & 0 deletions
272
src/containers/Tenant/Schema/SchemaViewer/__tests__/prepareData.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,272 @@ | ||
import type {TEvDescribeSchemeResult} from '../../../../../types/api/schema'; | ||
import {EPathType} from '../../../../../types/api/schema'; | ||
import {prepareSchemaData, prepareViewSchema} from '../prepareData'; | ||
|
||
describe('prepareSchemaData', () => { | ||
it('correctly parses row table data', () => { | ||
const data: TEvDescribeSchemeResult = { | ||
PathDescription: { | ||
Table: { | ||
Name: 'my_row_table', | ||
Columns: [ | ||
{ | ||
Name: 'id', | ||
Type: 'Uint64', | ||
TypeId: 4, | ||
Id: 1, | ||
Family: 0, | ||
FamilyName: 'default', | ||
NotNull: false, | ||
}, | ||
{ | ||
Name: 'category_id', | ||
Type: 'Uint64', | ||
TypeId: 4, | ||
Id: 2, | ||
Family: 0, | ||
FamilyName: 'default', | ||
NotNull: true, | ||
}, | ||
{ | ||
Name: 'name', | ||
Type: 'Utf8', | ||
TypeId: 4608, | ||
Id: 3, | ||
Family: 0, | ||
FamilyName: 'default', | ||
DefaultFromLiteral: { | ||
type: { | ||
type_id: 'UTF8', | ||
}, | ||
value: { | ||
text_value: 'Ivan', | ||
}, | ||
}, | ||
NotNull: true, | ||
}, | ||
{ | ||
Name: 'updated_on', | ||
Type: 'Datetime', | ||
TypeId: 49, | ||
Id: 4, | ||
Family: 0, | ||
FamilyName: 'default', | ||
NotNull: false, | ||
}, | ||
], | ||
KeyColumnNames: ['category_id', 'name', 'id'], | ||
KeyColumnIds: [2, 3, 1], | ||
PartitionConfig: { | ||
ColumnFamilies: [ | ||
{ | ||
Id: 0, | ||
StorageConfig: { | ||
SysLog: { | ||
PreferredPoolKind: 'ssd', | ||
}, | ||
Log: { | ||
PreferredPoolKind: 'ssd', | ||
}, | ||
Data: { | ||
PreferredPoolKind: 'ssd', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const result = [ | ||
{ | ||
id: 1, | ||
name: 'id', | ||
keyColumnIndex: 2, | ||
type: 'Uint64', | ||
notNull: false, | ||
autoIncrement: false, | ||
defaultValue: '-', | ||
familyName: undefined, | ||
prefferedPoolKind: undefined, | ||
columnCodec: undefined, | ||
}, | ||
{ | ||
id: 2, | ||
name: 'category_id', | ||
keyColumnIndex: 0, | ||
type: 'Uint64', | ||
notNull: true, | ||
autoIncrement: false, | ||
defaultValue: '-', | ||
familyName: undefined, | ||
prefferedPoolKind: undefined, | ||
columnCodec: undefined, | ||
}, | ||
{ | ||
id: 3, | ||
name: 'name', | ||
keyColumnIndex: 1, | ||
type: 'Utf8', | ||
notNull: true, | ||
autoIncrement: false, | ||
defaultValue: 'Ivan', | ||
familyName: undefined, | ||
prefferedPoolKind: undefined, | ||
columnCodec: undefined, | ||
}, | ||
{ | ||
id: 4, | ||
name: 'updated_on', | ||
keyColumnIndex: -1, | ||
type: 'Datetime', | ||
notNull: false, | ||
autoIncrement: false, | ||
defaultValue: '-', | ||
familyName: undefined, | ||
prefferedPoolKind: undefined, | ||
columnCodec: undefined, | ||
}, | ||
]; | ||
|
||
expect(prepareSchemaData(EPathType.EPathTypeTable, data)).toEqual(result); | ||
}); | ||
it('correctly parses column table data', () => { | ||
const data: TEvDescribeSchemeResult = { | ||
PathDescription: { | ||
ColumnTableDescription: { | ||
Name: 'my_column_table', | ||
Schema: { | ||
Columns: [ | ||
{ | ||
Id: 1, | ||
Name: 'title', | ||
Type: 'Utf8', | ||
TypeId: 4608, | ||
NotNull: true, | ||
StorageId: '', | ||
DefaultValue: {}, | ||
ColumnFamilyId: 0, | ||
}, | ||
{ | ||
Id: 2, | ||
Name: 'author', | ||
Type: 'Utf8', | ||
TypeId: 4608, | ||
NotNull: true, | ||
StorageId: '', | ||
DefaultValue: {}, | ||
ColumnFamilyId: 0, | ||
}, | ||
{ | ||
Id: 3, | ||
Name: 'id', | ||
Type: 'Int64', | ||
TypeId: 3, | ||
NotNull: true, | ||
StorageId: '', | ||
DefaultValue: {}, | ||
ColumnFamilyId: 0, | ||
}, | ||
{ | ||
Id: 4, | ||
Name: 'body', | ||
Type: 'Utf8', | ||
TypeId: 4608, | ||
NotNull: false, | ||
StorageId: '', | ||
DefaultValue: {}, | ||
ColumnFamilyId: 0, | ||
}, | ||
], | ||
KeyColumnNames: ['author', 'title', 'id'], | ||
Version: '1', | ||
Options: { | ||
SchemeNeedActualization: false, | ||
}, | ||
ColumnFamilies: [ | ||
{ | ||
Id: 0, | ||
Name: 'default', | ||
}, | ||
], | ||
}, | ||
ColumnShardCount: 64, | ||
Sharding: { | ||
ColumnShards: ['72075186224107692'], | ||
HashSharding: { | ||
Function: 'HASH_FUNCTION_CONSISTENCY_64', | ||
Columns: ['id', 'author', 'title'], | ||
}, | ||
}, | ||
StorageConfig: { | ||
DataChannelCount: 64, | ||
}, | ||
}, | ||
}, | ||
}; | ||
const result = [ | ||
{ | ||
id: 1, | ||
name: 'title', | ||
keyColumnIndex: 1, | ||
partitioningColumnIndex: 2, | ||
type: 'Utf8', | ||
notNull: true, | ||
}, | ||
{ | ||
id: 2, | ||
name: 'author', | ||
keyColumnIndex: 0, | ||
partitioningColumnIndex: 1, | ||
type: 'Utf8', | ||
notNull: true, | ||
}, | ||
{ | ||
id: 3, | ||
name: 'id', | ||
keyColumnIndex: 2, | ||
partitioningColumnIndex: 0, | ||
type: 'Int64', | ||
notNull: true, | ||
}, | ||
{ | ||
id: 4, | ||
name: 'body', | ||
keyColumnIndex: -1, | ||
partitioningColumnIndex: -1, | ||
type: 'Utf8', | ||
notNull: false, | ||
}, | ||
]; | ||
expect(prepareSchemaData(EPathType.EPathTypeColumnTable, data)).toEqual(result); | ||
}); | ||
it('returns empty array if data is undefined, empty or null', () => { | ||
expect(prepareSchemaData(EPathType.EPathTypeTable, {})).toEqual([]); | ||
expect(prepareSchemaData(EPathType.EPathTypeTable, undefined)).toEqual([]); | ||
expect(prepareSchemaData(EPathType.EPathTypeTable, null)).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe('prepareViewSchema', () => { | ||
it('correctly parses data', () => { | ||
const data = [ | ||
{name: 'cost', type: 'Int32'}, | ||
{name: 'id', type: 'Int32'}, | ||
{name: 'price', type: 'Double'}, | ||
{name: 'value', type: 'Utf8?'}, | ||
]; | ||
const result = [ | ||
{type: 'Int32', name: 'cost'}, | ||
{type: 'Int32', name: 'id'}, | ||
{type: 'Double', name: 'price'}, | ||
{type: 'Utf8', name: 'value'}, | ||
]; | ||
|
||
expect(prepareViewSchema(data)).toEqual(result); | ||
}); | ||
it('returns empty array if data is undefined or empty', () => { | ||
expect(prepareViewSchema()).toEqual([]); | ||
expect(prepareViewSchema([])).toEqual([]); | ||
}); | ||
}); |
103 changes: 103 additions & 0 deletions
103
src/containers/Tenant/Schema/SchemaViewer/__tests__/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import {getPartitioningKeys, getPrimaryKeys} from '../utils'; | ||
|
||
describe('getPartitioningKeys', () => { | ||
it('returns column in the provided order', () => { | ||
const data1 = [ | ||
{ | ||
id: 1, | ||
name: 'l_linenumber', | ||
keyColumnIndex: 0, | ||
partitioningColumnIndex: 1, | ||
type: 'Int64', | ||
notNull: true, | ||
}, | ||
{ | ||
id: 2, | ||
name: 'l_orderkey', | ||
keyColumnIndex: 1, | ||
partitioningColumnIndex: 0, | ||
type: 'Int64', | ||
notNull: true, | ||
}, | ||
]; | ||
|
||
expect(getPartitioningKeys(data1)).toEqual(['l_orderkey', 'l_linenumber']); | ||
|
||
const data2 = [ | ||
{ | ||
id: 1, | ||
name: 'title', | ||
keyColumnIndex: 1, | ||
partitioningColumnIndex: 2, | ||
type: 'Utf8', | ||
notNull: true, | ||
}, | ||
{ | ||
id: 2, | ||
name: 'author', | ||
keyColumnIndex: 0, | ||
partitioningColumnIndex: 1, | ||
type: 'Utf8', | ||
notNull: true, | ||
}, | ||
{ | ||
id: 3, | ||
name: 'id', | ||
keyColumnIndex: 2, | ||
partitioningColumnIndex: 0, | ||
type: 'Int64', | ||
notNull: true, | ||
}, | ||
{ | ||
id: 4, | ||
name: 'body', | ||
keyColumnIndex: -1, | ||
partitioningColumnIndex: -1, | ||
type: 'Utf8', | ||
notNull: false, | ||
}, | ||
]; | ||
expect(getPartitioningKeys(data2)).toEqual(['id', 'author', 'title']); | ||
}); | ||
}); | ||
|
||
describe('getPrimaryKeys', () => { | ||
it('returns column in the provided order', () => { | ||
const data = [ | ||
{ | ||
id: 1, | ||
name: 'id', | ||
keyColumnIndex: 2, | ||
type: 'Uint64', | ||
notNull: false, | ||
autoIncrement: false, | ||
}, | ||
{ | ||
id: 2, | ||
name: 'category_id', | ||
keyColumnIndex: 0, | ||
type: 'Uint64', | ||
notNull: true, | ||
autoIncrement: false, | ||
}, | ||
{ | ||
id: 3, | ||
name: 'name', | ||
keyColumnIndex: 1, | ||
type: 'Utf8', | ||
notNull: true, | ||
autoIncrement: false, | ||
}, | ||
{ | ||
id: 4, | ||
name: 'updated_on', | ||
keyColumnIndex: -1, | ||
type: 'Datetime', | ||
notNull: false, | ||
autoIncrement: false, | ||
}, | ||
]; | ||
|
||
expect(getPrimaryKeys(data)).toEqual(['category_id', 'name', 'id']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no external tables in our dev clusters and there is no possibility to add them since feature flag is turned off and there is issue with flags. I didn't want to use generated response instead of real backend data, so I left external tables without tests for now