-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathutils.ts
27 lines (24 loc) · 1.04 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import type {WithRequiredFields} from '../../../../types/common';
import type {SchemaData} from './types';
export function getPartitioningKeys(tableData: SchemaData[]): string[] {
return tableData
.filter((row): row is WithRequiredFields<SchemaData, 'partitioningColumnIndex' | 'name'> =>
Boolean(
row.partitioningColumnIndex !== undefined &&
row.partitioningColumnIndex !== -1 &&
row.name,
),
)
.sort(
(column1, column2) => column1.partitioningColumnIndex - column2.partitioningColumnIndex,
)
.map((row) => row.name);
}
export function getPrimaryKeys(tableData: SchemaData[]): string[] {
return tableData
.filter((row): row is WithRequiredFields<SchemaData, 'keyColumnIndex' | 'name'> =>
Boolean(row.keyColumnIndex !== undefined && row.keyColumnIndex !== -1 && row.name),
)
.sort((column1, column2) => column1.keyColumnIndex - column2.keyColumnIndex)
.map((row) => row.name);
}