Skip to content

Commit 333b53d

Browse files
authored
fix(schema-compiler): Fix view transpilation for worker_threads and native flows (#9980)
1 parent 82825a8 commit 333b53d

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

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

Lines changed: 12 additions & 5 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
}
@@ -564,7 +569,9 @@ export class DataSchemaCompiler {
564569
// which doesn't allow passing any function objects, so we need to sanitize the symbols.
565570
// Communication with native backend also involves deserialization.
566571
const cubeSymbols: Record<string, Record<string, boolean>> = Object.fromEntries(
567-
Object.entries(this.cubeSymbols.symbols as Record<string, Record<string, any>>)
572+
[...Object.entries(this.cubeOnlySymbols.symbols as Record<string, Record<string, any>>),
573+
...Object.entries(this.cubeAndViewSymbols.symbols as Record<string, Record<string, any>>)
574+
]
568575
.map(
569576
([key, value]: [string, Record<string, any>]) => [key, Object.fromEntries(
570577
Object.keys(value).map((k) => [k, true]),

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)