Skip to content

Commit 99a70b3

Browse files
committed
fix(schema-compiler): Fix view transpilation for worker_threads and native flows
1 parent 1aeea98 commit 99a70b3

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export type DataSchemaCompilerOptions = {
7373
nativeInstance: NativeInstance;
7474
cubeFactory: Function;
7575
cubeDictionary: CubeDictionary;
76-
cubeSymbols: CubeSymbols;
76+
cubeOnlySymbols: CubeSymbols;
77+
cubeAndViewSymbols: CubeSymbols;
7778
cubeCompilers?: CompilerInterface[];
7879
contextCompilers?: CompilerInterface[];
7980
transpilers?: TranspilerInterface[];
@@ -131,7 +132,9 @@ export class DataSchemaCompiler {
131132

132133
private readonly cubeDictionary: CubeDictionary;
133134

134-
private readonly cubeSymbols: CubeSymbols;
135+
private readonly cubeOnlySymbols: CubeSymbols;
136+
137+
private readonly cubeAndViewSymbols: CubeSymbols;
135138

136139
// Actually should be something like
137140
// createCube(cubeDefinition: CubeDefinition): CubeDefinitionExtended
@@ -187,7 +190,8 @@ export class DataSchemaCompiler {
187190
this.cubeNameCompilers = options.cubeNameCompilers || [];
188191
this.extensions = options.extensions || {};
189192
this.cubeDictionary = options.cubeDictionary;
190-
this.cubeSymbols = options.cubeSymbols;
193+
this.cubeOnlySymbols = options.cubeOnlySymbols;
194+
this.cubeAndViewSymbols = options.cubeAndViewSymbols;
191195
this.cubeFactory = options.cubeFactory;
192196
this.filesToCompile = options.filesToCompile || [];
193197
this.omitErrors = options.omitErrors || false;
@@ -531,7 +535,8 @@ export class DataSchemaCompiler {
531535
// Free unneeded resources
532536
this.compileV8ContextCache = null;
533537
this.cubeDictionary.free();
534-
this.cubeSymbols.free();
538+
this.cubeOnlySymbols.free();
539+
this.cubeAndViewSymbols.free();
535540
return res;
536541
});
537542
}
@@ -563,14 +568,23 @@ export class DataSchemaCompiler {
563568
// The structured clone algorithm (@see https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
564569
// which doesn't allow passing any function objects, so we need to sanitize the symbols.
565570
// Communication with native backend also involves deserialization.
566-
const cubeSymbols: Record<string, Record<string, boolean>> = Object.fromEntries(
567-
Object.entries(this.cubeSymbols.symbols as Record<string, Record<string, any>>)
571+
const cubeOnlySymbols: Record<string, Record<string, boolean>> = Object.fromEntries(
572+
Object.entries(this.cubeOnlySymbols.symbols as Record<string, Record<string, any>>)
573+
.map(
574+
([key, value]: [string, Record<string, any>]) => [key, Object.fromEntries(
575+
Object.keys(value).map((k) => [k, true]),
576+
)],
577+
),
578+
);
579+
const cubeViewSymbols: Record<string, Record<string, boolean>> = Object.fromEntries(
580+
Object.entries(this.cubeAndViewSymbols.symbols as Record<string, Record<string, any>>)
568581
.map(
569582
([key, value]: [string, Record<string, any>]) => [key, Object.fromEntries(
570583
Object.keys(value).map((k) => [k, true]),
571584
)],
572585
),
573586
);
587+
const cubeSymbols = { ...cubeOnlySymbols, ...cubeViewSymbols };
574588

575589
// Transpilers are the same for all files within phase.
576590
const transpilerNames: string[] = this.transpilers.map(t => t.constructor.name);

packages/cubejs-schema-compiler/src/compiler/PrepareCompiler.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const prepareCompiler = (repo: SchemaFileRepository, options: PrepareComp
7777

7878
const compilerId = uuidv4();
7979

80-
const compiler = new DataSchemaCompiler(repo, Object.assign({}, {
80+
const compiler = new DataSchemaCompiler(repo, {
8181
cubeNameCompilers: [cubeDictionary],
8282
preTranspileCubeCompilers: [cubeSymbols, cubeValidator],
8383
transpilers,
@@ -91,7 +91,8 @@ export const prepareCompiler = (repo: SchemaFileRepository, options: PrepareComp
9191
cubeFactory: cubeSymbols.createCube.bind(cubeSymbols),
9292
compilerCache,
9393
cubeDictionary,
94-
cubeSymbols,
94+
cubeOnlySymbols: cubeSymbols,
95+
cubeAndViewSymbols: viewCompiler,
9596
extensions: {
9697
Funnels,
9798
RefreshKeys,
@@ -102,7 +103,8 @@ export const prepareCompiler = (repo: SchemaFileRepository, options: PrepareComp
102103
nativeInstance,
103104
yamlCompiler,
104105
compilerId,
105-
}, options));
106+
...options
107+
});
106108

107109
return {
108110
compiler,

0 commit comments

Comments
 (0)