-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmeta.ts
More file actions
63 lines (56 loc) · 2.02 KB
/
meta.ts
File metadata and controls
63 lines (56 loc) · 2.02 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Utf8, TimeNanosecond } from '@apache-arrow/esnext-esm';
import { UUIDType } from '../types/uuid.js';
import type { Column, ColumnResolver } from './column.js';
import { createColumn } from './column.js';
import type { Resource } from './resource.js';
import type { Table } from './table.js';
import { getPrimaryKeys } from './table.js';
export type ClientMeta = {
id: () => string;
};
export const parentCqUUIDResolver = (): ColumnResolver => {
return (_: ClientMeta, r: Resource, c: Column) => {
if (r.parent === null) {
return Promise.resolve(r.setColumData(c.name, null));
}
const parentCqID = r.parent.getColumnData(cqIDColumn.name);
return Promise.resolve(r.setColumData(c.name, parentCqID));
};
};
// These columns are managed and populated by the source plugins
export const cqIDColumn = createColumn({
name: '_cq_id',
type: new UUIDType(),
description: 'Internal CQ ID of the row',
notNull: true,
unique: true,
});
export const cqParentIDColumn = createColumn({
name: '_cq_parent_id',
type: new UUIDType(),
description: 'Internal CQ ID of the parent row',
resolver: parentCqUUIDResolver(),
ignoreInTests: true,
});
// These columns are managed and populated by the destination plugin
export const cqSyncTimeColumn = createColumn({
name: '_cq_sync_time',
type: new TimeNanosecond(),
description: 'Internal CQ row of when sync was started (this will be the same for all rows in a single fetch)',
ignoreInTests: true,
});
export const cqSourceNameColumn = createColumn({
name: '_cq_source_name',
type: new Utf8(),
description: 'Internal CQ row that references the source plugin name data was retrieved',
ignoreInTests: true,
});
export const addCQIDsColumns = (table: Table): Table => {
const hasPks = getPrimaryKeys(table).length > 0;
const cqID = hasPks ? cqIDColumn : { ...cqIDColumn, primaryKey: true };
return {
...table,
columns: [cqID, cqParentIDColumn, ...table.columns],
relations: table.relations.map((relation) => addCQIDsColumns(relation)),
};
};