From 8e2b010643f1ddcce353626312167961f8ee47b8 Mon Sep 17 00:00:00 2001 From: Christopher Swenson Date: Fri, 15 Nov 2024 11:33:19 -0600 Subject: [PATCH] Small tweaks and comment changes --- .../src/lang/ast/source-elements/cube-source.ts | 10 ++-------- packages/malloy/src/lang/ast/struct-utils.ts | 3 +-- packages/malloy/src/model/cube_utils.ts | 12 +++++------- packages/malloy/src/model/malloy_types.ts | 3 ++- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/packages/malloy/src/lang/ast/source-elements/cube-source.ts b/packages/malloy/src/lang/ast/source-elements/cube-source.ts index 4c2b54a23..1fa461832 100644 --- a/packages/malloy/src/lang/ast/source-elements/cube-source.ts +++ b/packages/malloy/src/lang/ast/source-elements/cube-source.ts @@ -37,13 +37,6 @@ export class CubeSource extends Source { parameterSpace: ParameterSpace | undefined, pList: HasParameter[] | undefined ): SourceDef { - // TODO think about params for cube sources and test that this works... - /** - * source: foo(a is 1) is cube( - * duckdb.table('foo') extend { dimension: x is a }, - * duckdb.table('bar') extend { dimension: x is a } - * ) - */ const sourceDefs = this.sources.map(source => source.withParameters(parameterSpace, pList) ); @@ -79,7 +72,8 @@ export class CubeSource extends Source { as: undefined, e: {node: 'cubeField'}, cubeUsage: {fields: [fieldName], joinedUsage: {}}, - // TODO code and location are wrong... + code: this.code, + location: this.codeLocation, }; fields.push(cubeField); } diff --git a/packages/malloy/src/lang/ast/struct-utils.ts b/packages/malloy/src/lang/ast/struct-utils.ts index 0d36cb7a8..dc12172fa 100644 --- a/packages/malloy/src/lang/ast/struct-utils.ts +++ b/packages/malloy/src/lang/ast/struct-utils.ts @@ -70,8 +70,7 @@ export function opOutputStruct( logTo.logError( 'failed-to-compute-output-schema', `INTERNAL ERROR model/Segment.nextStructDef: ${e.message}\n` + - `QUERY: ${inspect(opDesc, {breakLength: 72, depth: Infinity})}\n` + - `STACK: ${e.stack}` + `QUERY: ${inspect(opDesc, {breakLength: 72, depth: Infinity})}` ); } } diff --git a/packages/malloy/src/model/cube_utils.ts b/packages/malloy/src/model/cube_utils.ts index 022161786..a87cf6fe5 100644 --- a/packages/malloy/src/model/cube_utils.ts +++ b/packages/malloy/src/model/cube_utils.ts @@ -15,8 +15,6 @@ import { SourceDef, } from './malloy_types'; -// TODO handle joins... - type CubeError = | {code: 'not_a_cube'; data: {path: string[]}} | {code: 'cube_not_defined'; data: {path: string[]}} @@ -34,11 +32,12 @@ function _resolveCubeSources( if (source.type === 'cube') { let found = false; overSources: for (const inputSource of source.sources) { + const fieldNames = new Set(); + for (const field of inputSource.fields) { + fieldNames.add(field.as ?? field.name); + } for (const usage of cubeUsage.fields) { - // TODO handle joins - if ( - inputSource.fields.find(f => f.as ?? f.name === usage) === undefined - ) { + if (!fieldNames.has(usage)) { continue overSources; } } @@ -266,7 +265,6 @@ function cubeUsageWithoutNonCubeFields( } return { fields: cubeUsage.fields.filter(f => isCubeField(sourceFieldsByName[f])), - // TODO not sure about this? joinedUsage: cubeUsage.joinedUsage, }; } diff --git a/packages/malloy/src/model/malloy_types.ts b/packages/malloy/src/model/malloy_types.ts index e5e6062fb..c28c9f5d5 100644 --- a/packages/malloy/src/model/malloy_types.ts +++ b/packages/malloy/src/model/malloy_types.ts @@ -1062,7 +1062,8 @@ export interface TableSourceDef extends SourceDefBase { export interface CubeSourceDef extends SourceDefBase { type: 'cube'; - sources: SourceDef[]; // TODO maybe this should be StructRef[], but that makes a lot of stuff harder. + // TODO make cube sources support StructRefs + sources: SourceDef[]; } /*