Skip to content

Commit f6413d2

Browse files
authored
fix: Encode tables in migrate messages (#38)
1 parent 0eb6d62 commit f6413d2

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/grpc/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { pluginV3 } from '@cloudquery/plugin-pb-javascript';
22
import grpc = require('@grpc/grpc-js');
33

44
import { Plugin } from '../plugin/plugin.js';
5-
import { encode as encodeTables } from '../schema/table.js';
5+
import { encodeTables } from '../schema/table.js';
66

77
export class MigrateTable extends pluginV3.cloudquery.plugin.v3.Sync.MessageMigrateTable {}
88
export class SyncResponse extends pluginV3.cloudquery.plugin.v3.Sync.Response {}

src/scheduler/scheduler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { SyncStream, SyncResponse, MigrateTable } from '../grpc/plugin.js';
22
import { ClientMeta } from '../schema/meta.js';
3-
import { Table } from '../schema/table.js';
3+
import { Table, encodeTable } from '../schema/table.js';
44

55
export type Options = {
66
deterministicCQId: boolean;
77
};
88

99
export const sync = async (client: ClientMeta, tables: Table[], stream: SyncStream, options: Options) => {
10-
for (const { name } of tables) {
11-
const table = new TextEncoder().encode(name);
10+
for (const table of tables) {
1211
// eslint-disable-next-line @typescript-eslint/naming-convention
13-
stream.write(new SyncResponse({ migrate_table: new MigrateTable({ table }) }));
12+
stream.write(new SyncResponse({ migrate_table: new MigrateTable({ table: encodeTable(table) }) }));
1413
}
1514

15+
stream.end();
1616
return await Promise.resolve();
1717
};

src/schema/table.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,13 @@ export const toArrowSchema = (table: Table) => {
142142
return new Schema(fields, metadata);
143143
};
144144

145-
export const encode = (tables: Table[]): Uint8Array[] => {
146-
const schemas = tables.map((table) => toArrowSchema(table));
147-
const arrowTables = schemas.map((schema) => new ArrowTable(schema));
148-
const bytes = arrowTables.map((table) => tableToIPC(table));
145+
export const encodeTable = (table: Table): Uint8Array => {
146+
const schema = toArrowSchema(table);
147+
const arrowTable = new ArrowTable(schema);
148+
const bytes = tableToIPC(arrowTable);
149149
return bytes;
150150
};
151+
152+
export const encodeTables = (tables: Table[]): Uint8Array[] => {
153+
return tables.map((table) => encodeTable(table));
154+
};

0 commit comments

Comments
 (0)