Skip to content

Commit

Permalink
make schema explain shareable
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoy-googly-moogly committed Jan 16, 2025
1 parent 9a18bef commit 79365a4
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/malloy-db-trino/src/trino_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,10 @@ export class PrestoConnection extends TrinoPrestoConnection {
);
}

protected async fillStructDefForSqlBlockSchema(
sql: string,
structDef: StructDef
): Promise<void> {
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(
Expand All @@ -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<void> {
const explainResult = await this.runSQL(`EXPLAIN ${sql}`, {});
PrestoConnection.schemaFromExplain(explainResult, structDef, this.dialect);
}

unpackArray(data: unknown): unknown[] {
return JSON.parse(data as string);
}
Expand Down

0 comments on commit 79365a4

Please sign in to comment.