Skip to content

Commit bbf6d22

Browse files
refactor: revert transpiler ensureCubeParam changes, keep evaluation-level fixes
Transpilation already correctly handles CUBE context for mask.sql - when mask.sql references cube members or CUBE explicitly, the transpiler adds CUBE as a parameter. The default CUBE context issue is in the evaluation path, not transpilation. Reverted: - CubePropContextTranspiler: removed maskSqlPattern, ensureCubeParam - YamlCompiler: removed ensureCubeParam plumbing - Removed 'mask.sql should always have CUBE as default parameter' test Kept: - Tesseract mask_sql dependency collection fixes (dimension + measure) - mask.sql with CUBE reference resolution test - All smoke tests (non-Tesseract and Tesseract) Co-authored-by: Pavel Tiunov <pavel.tiunov@gmail.com>
1 parent d168562 commit bbf6d22

3 files changed

Lines changed: 9 additions & 47 deletions

File tree

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,8 @@ export class YamlCompiler {
154154
for (const p of transpiledFieldsPatterns) {
155155
const fullPath = propertyPath.join('.');
156156
if (fullPath.match(p)) {
157-
const isMaskSql = /^(measures|dimensions)\.[_a-zA-Z][_a-zA-Z0-9]*\.mask\.sql$/.test(fullPath);
158157
if (typeof obj === 'string' && ['sql', 'sqlTable'].includes(propertyPath[propertyPath.length - 1])) {
159-
return this.parsePythonIntoArrowFunction(`f"${this.escapeDoubleQuotes(obj)}"`, cubeName, obj, errorsReport, isMaskSql);
158+
return this.parsePythonIntoArrowFunction(`f"${this.escapeDoubleQuotes(obj)}"`, cubeName, obj, errorsReport);
160159
} else if (typeof obj === 'string') {
161160
return this.parsePythonIntoArrowFunction(obj, cubeName, obj, errorsReport);
162161
} else if (Array.isArray(obj)) {
@@ -274,9 +273,9 @@ export class YamlCompiler {
274273
return result.join('');
275274
}
276275

277-
private parsePythonIntoArrowFunction(codeString: string, cubeName, originalObj, errorsReport: ErrorReporter, ensureCubeParam = false) {
276+
private parsePythonIntoArrowFunction(codeString: string, cubeName, originalObj, errorsReport: ErrorReporter) {
278277
const ast = this.parsePythonAndTranspileToJs(codeString, errorsReport);
279-
return this.astIntoArrowFunction(ast as any, codeString, cubeName, undefined, ensureCubeParam);
278+
return this.astIntoArrowFunction(ast as any, codeString, cubeName);
280279
}
281280

282281
private parsePythonAndTranspileToJs(codeString: string, errorsReport: ErrorReporter): t.Program | t.NullLiteral {
@@ -294,7 +293,7 @@ export class YamlCompiler {
294293
return t.nullLiteral();
295294
}
296295

297-
private astIntoArrowFunction(input: t.Program | t.NullLiteral, codeString: string, cubeName, resolveSymbol?: (string) => any, ensureCubeParam = false) {
296+
private astIntoArrowFunction(input: t.Program | t.NullLiteral, codeString: string, cubeName, resolveSymbol?: (string) => any) {
298297
const initialJs = babelGenerator(input, {}, codeString).code;
299298

300299
// Re-parse generated JS to set all necessary parent paths
@@ -312,7 +311,7 @@ export class YamlCompiler {
312311

313312
const traverseObj = {
314313
Program: (babelPath) => {
315-
CubePropContextTranspiler.replaceValueWithArrowFunction(<(string) => any>resolveSymbol, babelPath.get('body')[0].get('expression'), ensureCubeParam);
314+
CubePropContextTranspiler.replaceValueWithArrowFunction(<(string) => any>resolveSymbol, babelPath.get('body')[0].get('expression'));
316315
},
317316
};
318317

packages/cubejs-schema-compiler/src/compiler/transpilers/CubePropContextTranspiler.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ export const transpiledFieldsPatterns: Array<RegExp> = [
3737
/^(measures|dimensions)\.[_a-zA-Z][_a-zA-Z0-9]*\.mask\.sql$/,
3838
];
3939

40-
const maskSqlPattern = /^(measures|dimensions)\.[_a-zA-Z][_a-zA-Z0-9]*\.mask\.sql$/;
41-
4240
export const transpiledFields: Set<String> = new Set<String>();
4341

4442
transpiledFieldsPatterns?.forEach((r) => {
@@ -78,11 +76,11 @@ export class CubePropContextTranspiler implements TranspilerInterface {
7876
};
7977
}
8078

81-
protected transformObjectProperty(path: NodePath<t.ObjectProperty>, resolveSymbol: SymbolResolver, ensureCubeParam = false) {
82-
CubePropContextTranspiler.replaceValueWithArrowFunction(resolveSymbol, path.get('value'), ensureCubeParam);
79+
protected transformObjectProperty(path: NodePath<t.ObjectProperty>, resolveSymbol: SymbolResolver) {
80+
CubePropContextTranspiler.replaceValueWithArrowFunction(resolveSymbol, path.get('value'));
8381
}
8482

85-
public static replaceValueWithArrowFunction(resolveSymbol: (name: string) => any, value: NodePath<any>, ensureCubeParam = false) {
83+
public static replaceValueWithArrowFunction(resolveSymbol: (name: string) => any, value: NodePath<any>) {
8684
// If the current value is already an arrow function, update its parameters and keep the body
8785
if (t.isArrowFunctionExpression(value.node)) {
8886
const bodyPath = value.get('body') as NodePath<any>;
@@ -91,10 +89,6 @@ export class CubePropContextTranspiler implements TranspilerInterface {
9189
bodyPath,
9290
);
9391

94-
if (ensureCubeParam && !knownIds.includes('CUBE')) {
95-
knownIds.push('CUBE');
96-
}
97-
9892
value.replaceWith(
9993
t.arrowFunctionExpression(
10094
knownIds.map(i => t.identifier(i)),
@@ -108,10 +102,6 @@ export class CubePropContextTranspiler implements TranspilerInterface {
108102
value,
109103
);
110104

111-
if (ensureCubeParam && !knownIds.includes('CUBE')) {
112-
knownIds.push('CUBE');
113-
}
114-
115105
value.replaceWith(
116106
t.arrowFunctionExpression(
117107
knownIds.map(i => t.identifier(i)),
@@ -145,8 +135,7 @@ export class CubePropContextTranspiler implements TranspilerInterface {
145135
// eslint-disable-next-line no-restricted-syntax
146136
for (const p of transpiledFieldsPatterns) {
147137
if (fullPath.match(p)) {
148-
const isMaskSql = maskSqlPattern.test(fullPath);
149-
this.transformObjectProperty(path, resolveSymbol, isMaskSql);
138+
this.transformObjectProperty(path, resolveSymbol);
150139
return;
151140
}
152141
}

packages/cubejs-schema-compiler/test/unit/transpilers.test.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -379,32 +379,6 @@ describe('Transpilers', () => {
379379
expect(transpiledMaskSql!.toString()).toMatch('SECURITY_CONTEXT.cubeCloud.userAttributes');
380380
});
381381

382-
it('CubePropContextTranspiler mask.sql should always have CUBE as default parameter', async () => {
383-
const { cubeEvaluator, compiler } = prepareJsCompiler(`
384-
cube(\`Test\`, {
385-
sql: 'SELECT * FROM users',
386-
dimensions: {
387-
userId: {
388-
sql: \`userId\`,
389-
type: 'string'
390-
},
391-
masked_dim: {
392-
sql: \`price\`,
393-
type: 'number',
394-
mask: {
395-
sql: \`-1\`,
396-
}
397-
}
398-
}
399-
})
400-
`);
401-
402-
await compiler.compile();
403-
404-
const transpiledMaskSql = (cubeEvaluator.cubeFromPath('Test').dimensions.masked_dim as any).mask.sql;
405-
expect(transpiledMaskSql!.toString()).toMatch('CUBE');
406-
});
407-
408382
it('CubePropContextTranspiler mask.sql with CUBE reference should resolve correctly', async () => {
409383
const compilers = prepareJsCompiler(`
410384
cube(\`Test\`, {

0 commit comments

Comments
 (0)