From 79365a4f4fbd230c277297b773ea4ab806b83571 Mon Sep 17 00:00:00 2001 From: Michael Toy <66150587+mtoy-googly-moogly@users.noreply.github.com> Date: Thu, 16 Jan 2025 13:56:00 -0800 Subject: [PATCH] make schema explain shareable --- .../malloy-db-trino/src/trino_connection.ts | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/malloy-db-trino/src/trino_connection.ts b/packages/malloy-db-trino/src/trino_connection.ts index 3f65754a9..37dcf0e84 100644 --- a/packages/malloy-db-trino/src/trino_connection.ts +++ b/packages/malloy-db-trino/src/trino_connection.ts @@ -439,17 +439,10 @@ export class PrestoConnection extends TrinoPrestoConnection { ); } - protected async fillStructDefForSqlBlockSchema( - sql: string, - structDef: StructDef - ): Promise { - const explainResult = await this.runSQL(`EXPLAIN ${sql}`, {}); - this.schemaFromExplain(explainResult, structDef); - } - - protected schemaFromExplain( + static schemaFromExplain( explainResult: MalloyQueryData, - structDef: StructDef + structDef: StructDef, + dialect: Dialect ) { if (explainResult.rows.length === 0) { throw new Error( @@ -474,10 +467,18 @@ export class PrestoConnection extends TrinoPrestoConnection { ); } - const schemaDesc = new TrinoPrestoSchemaParser(lines[0], this.dialect); + const schemaDesc = new TrinoPrestoSchemaParser(lines[0], dialect); structDef.fields = schemaDesc.parseQueryPlan(); } + protected async fillStructDefForSqlBlockSchema( + sql: string, + structDef: StructDef + ): Promise { + const explainResult = await this.runSQL(`EXPLAIN ${sql}`, {}); + PrestoConnection.schemaFromExplain(explainResult, structDef, this.dialect); + } + unpackArray(data: unknown): unknown[] { return JSON.parse(data as string); }