Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/grpc/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { pluginV3 } from '@cloudquery/plugin-pb-javascript';
import grpc = require('@grpc/grpc-js');

import { Plugin } from '../plugin/plugin.js';
import { encode as encodeTables } from '../schema/table.js';
import { encodeTables } from '../schema/table.js';

export class MigrateTable extends pluginV3.cloudquery.plugin.v3.Sync.MessageMigrateTable {}
export class SyncResponse extends pluginV3.cloudquery.plugin.v3.Sync.Response {}
Expand Down
8 changes: 4 additions & 4 deletions src/scheduler/scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { SyncStream, SyncResponse, MigrateTable } from '../grpc/plugin.js';
import { ClientMeta } from '../schema/meta.js';
import { Table } from '../schema/table.js';
import { Table, encodeTable } from '../schema/table.js';

export type Options = {
deterministicCQId: boolean;
};

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

stream.end();
return await Promise.resolve();
};
12 changes: 8 additions & 4 deletions src/schema/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,13 @@ export const toArrowSchema = (table: Table) => {
return new Schema(fields, metadata);
};

export const encode = (tables: Table[]): Uint8Array[] => {
const schemas = tables.map((table) => toArrowSchema(table));
const arrowTables = schemas.map((schema) => new ArrowTable(schema));
const bytes = arrowTables.map((table) => tableToIPC(table));
export const encodeTable = (table: Table): Uint8Array => {
const schema = toArrowSchema(table);
const arrowTable = new ArrowTable(schema);
const bytes = tableToIPC(arrowTable);
return bytes;
};

export const encodeTables = (tables: Table[]): Uint8Array[] => {
return tables.map((table) => encodeTable(table));
};