Skip to content

Commit

Permalink
Fix issue that made declare and extend: not work
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherswenson committed Nov 15, 2024
1 parent 2ebf63e commit 2d11df5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
43 changes: 25 additions & 18 deletions packages/malloy/src/lang/ast/field-space/dynamic-space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,20 @@ export abstract class DynamicSpace
extends StaticSpace
implements SourceFieldSpace
{
protected final: model.SourceDef | undefined;
protected sourceDef: model.SourceDef | undefined;
protected fromSource: model.SourceDef;
completions: (() => void)[] = [];
private complete = false;
private parameters: HasParameter[] = [];
protected newTimezone?: string;

constructor(extending: SourceDef) {
super(structuredClone(extending));
this.fromSource = extending;
this.final = undefined;
}

isComplete(): void {
this.complete = true;
this.sourceDef = undefined;
}

protected setEntry(name: string, value: SpaceEntry): void {
if (this.final) {
if (this.complete) {
throw new Error('Space already final');
}
super.setEntry(name, value);
Expand Down Expand Up @@ -101,8 +96,16 @@ export abstract class DynamicSpace
this.newTimezone = tz;
}

structDef(): model.SourceDef {
if (this.final === undefined) {
// Used to compute the current structDef, but not making any claims that it is the
// final structDef;
partialStructDef(): model.SourceDef {
const result = this.generateSourceDef();
this.sourceDef = undefined;
return result;
}

private generateSourceDef(): model.SourceDef {
if (this.sourceDef === undefined) {
// Grab all the parameters so that we can populate the "final" structDef
// with parameters immediately so that views can see them when they are translating
const parameters = {};
Expand All @@ -112,8 +115,8 @@ export abstract class DynamicSpace
}
}

this.final = {...this.fromSource, fields: []};
this.final.parameters = parameters;
this.sourceDef = {...this.fromSource, fields: []};
this.sourceDef.parameters = parameters;
// Need to process the entities in specific order
const fields: [string, SpaceField][] = [];
const joins: [string, SpaceField][] = [];
Expand All @@ -134,13 +137,13 @@ export abstract class DynamicSpace
if (field instanceof JoinSpaceField) {
const joinStruct = field.join.structDef(parameterSpace);
if (!ErrorFactory.didCreate(joinStruct)) {
this.final.fields.push(joinStruct);
this.sourceDef.fields.push(joinStruct);
fixupJoins.push([field.join, joinStruct]);
}
} else {
const fieldDef = field.fieldDef();
if (fieldDef) {
this.final.fields.push(fieldDef);
this.sourceDef.fields.push(fieldDef);
}
// TODO I'm just removing this, but perhaps instead I should just filter
// out ReferenceFields and still make this check.
Expand All @@ -155,11 +158,15 @@ export abstract class DynamicSpace
join.fixupJoinOn(this, missingOn);
}
}
if (this.newTimezone && model.isSourceDef(this.final)) {
this.final.queryTimezone = this.newTimezone;
if (this.newTimezone && model.isSourceDef(this.sourceDef)) {
this.sourceDef.queryTimezone = this.newTimezone;
}
this.isComplete();
return this.final;
return this.sourceDef;
}

structDef(): model.SourceDef {
this.complete = true;
return this.generateSourceDef();
}

emptyStructDef(): SourceDef {
Expand Down
8 changes: 2 additions & 6 deletions packages/malloy/src/lang/ast/field-space/query-spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,14 @@ export abstract class QueryOperationSpace
}
}

// TODO this will need to be a map from paths to booleans once I support joins...
private alreadyInvalidCubeUsage = false;
protected validateCubeUsage(
newCubeUsage: model.CubeUsage,
logTo: MalloyElement
) {
if (this.alreadyInvalidCubeUsage) return;

const source = this.inputSpace().structDef();
if (isEmptyCubeUsage(this.cubeUsage)) return;
if (isEmptyCubeUsage(newCubeUsage)) return;
const source = this.inputSpace().partialStructDef();

const resolved = resolveCubeSources(source, this.cubeUsage);

Expand Down Expand Up @@ -333,7 +331,6 @@ export abstract class QuerySpace extends QueryOperationSpace {
// fields, but the individual fields didn't have field defs.
}
}
this.isComplete();
return fields;
}

Expand Down Expand Up @@ -393,7 +390,6 @@ export abstract class QuerySpace extends QueryOperationSpace {
if (this.newTimezone) {
segment.queryTimezone = this.newTimezone;
}
this.isComplete();
return segment;
}

Expand Down

0 comments on commit 2d11df5

Please sign in to comment.