Skip to content

Commit 48ee882

Browse files
committed
fix(schema-compiler): Allow calling cube functions in yaml python blocks
1 parent c97f99a commit 48ee882

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

packages/cubejs-schema-compiler/src/parser/Python3Parser.g4

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ testlist_comp: (test | star_expr) (
228228
comp_for
229229
| (COMMA (test | star_expr))* (COMMA)?
230230
);
231-
trailer: '(' (arglist)? ')' | '[' subscriptlist ']' | '.' NAME;
231+
trailer: callArguments | '[' subscriptlist ']' | '.' NAME;
232232
subscriptlist: subscript (COMMA subscript)* (COMMA)?;
233233
subscript: test | (test)? ':' (test)? (sliceop)?;
234234
sliceop: ':' (test)?;
@@ -251,6 +251,8 @@ dictorsetmaker: (
251251

252252
classdef: 'class' NAME ('(' (arglist)? ')')? ':' suite;
253253

254+
callArguments: '(' (arglist)? ')';
255+
254256
arglist: argument (COMMA argument)* (COMMA)?;
255257

256258
// The reason that keywords are test nodes instead of NAME is that using NAME results in an

packages/cubejs-schema-compiler/src/parser/PythonParser.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
LambdefContext,
2020
Single_string_template_atomContext,
2121
ArglistContext,
22+
CallArgumentsContext,
2223
} from './Python3Parser';
2324
import { UserError } from '../compiler/UserError';
2425
import { Python3ParserVisitor } from './Python3ParserVisitor';
@@ -36,7 +37,7 @@ const nodeVisitor = <R>(visitor: { visitNode: (node: RuleNode, children: R[]) =>
3637
const result: R[] = [];
3738
for (let i = 0; i < node.childCount; i++) {
3839
const child = node.getChild(i);
39-
if (child && child.childCount) {
40+
if (child?.childCount) {
4041
result.push(child.accept(this));
4142
}
4243
}
@@ -175,13 +176,22 @@ export class PythonParser {
175176
} else {
176177
return singleNodeReturn();
177178
}
178-
} else if (node instanceof TrailerContext) {
179-
const name = node.NAME();
179+
} else if (node instanceof CallArgumentsContext) {
180180
const argsList = node.arglist();
181181
if (argsList) {
182-
// trailer with arglist have a single child: arguments _list_
182+
// arglist have a single child: arguments _list_
183183
const args = children[0];
184184
return { call: args };
185+
} else {
186+
return { call: [] };
187+
}
188+
} else if (node instanceof TrailerContext) {
189+
const name = node.NAME();
190+
const argsList = node.callArguments();
191+
if (argsList) {
192+
// trailer with callArguments have a single child: CallArgumentsContext
193+
// which was already processed (see other if branch)
194+
return children[0];
185195
} else if (name) {
186196
return { identifier: t.identifier(name.text) };
187197
} else {

0 commit comments

Comments
 (0)