@narrative.io/data-collaboration-sdk-ts 0.0.150 → 0.0.151
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/nql/AstParser.d.ts
CHANGED
|
@@ -194,6 +194,7 @@ export interface Concat {
|
|
|
194
194
|
as?: string;
|
|
195
195
|
operands: Expression[];
|
|
196
196
|
}
|
|
197
|
+
export type Node = Select | Expression | Deduplication | Table | BooleanExpression | ArithmeticExpression | StringExpression | Join | AttributeRef | DatasetColumnRef | RawRef | Lit | FunctionCall | Add | Divide | Multiply | Subtract | UnaryMinus | And | Or | Not | Between | Equals | NotEquals | Lt | Lte | Gt | Gte | In | IsNull | Like | Concat;
|
|
197
198
|
export declare function parseStatement(n: ast.NqlAst): Statement | Raw;
|
|
198
199
|
export declare function parseCreateMaterializedView(n: ast.NqlCreateMaterializedView): CreateMaterializedView;
|
|
199
200
|
export declare function parseExplain(n: ast.NqlExplain): Explain | Raw;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
function findTraversalTargets(node) {
|
|
2
|
+
switch (node.type) {
|
|
3
|
+
case "function":
|
|
4
|
+
return node.args;
|
|
5
|
+
case "+":
|
|
6
|
+
case "/":
|
|
7
|
+
case "*":
|
|
8
|
+
case "-":
|
|
9
|
+
case "and":
|
|
10
|
+
case "or":
|
|
11
|
+
case "||":
|
|
12
|
+
return node.operands;
|
|
13
|
+
case "unary_-":
|
|
14
|
+
return [node.operand];
|
|
15
|
+
case "is_null":
|
|
16
|
+
return [node.operand];
|
|
17
|
+
case "like":
|
|
18
|
+
return [node.value];
|
|
19
|
+
case "not":
|
|
20
|
+
return node.operand.type !== "nql" ? [node.operand] : [];
|
|
21
|
+
case "between":
|
|
22
|
+
return [node.operand, node.lower, node.upper];
|
|
23
|
+
case "=":
|
|
24
|
+
case "<>":
|
|
25
|
+
case "<":
|
|
26
|
+
case "<=":
|
|
27
|
+
case ">":
|
|
28
|
+
case ">=":
|
|
29
|
+
return [node.left, node.right];
|
|
30
|
+
case "in": {
|
|
31
|
+
const inTargets = [node.expression];
|
|
32
|
+
if (Array.isArray(node.values)) {
|
|
33
|
+
inTargets.push(...node.values);
|
|
34
|
+
}
|
|
35
|
+
return inTargets;
|
|
36
|
+
}
|
|
37
|
+
case "deduplication":
|
|
38
|
+
return node.expressions;
|
|
39
|
+
case "select": {
|
|
40
|
+
const selectTargets = [...node.columns];
|
|
41
|
+
if (node.where !== null &&
|
|
42
|
+
node.where !== undefined &&
|
|
43
|
+
node.where.type !== "nql") {
|
|
44
|
+
selectTargets.push(node.where);
|
|
45
|
+
}
|
|
46
|
+
if (node.deduplication !== null &&
|
|
47
|
+
node.deduplication !== undefined &&
|
|
48
|
+
node.deduplication.type !== "nql") {
|
|
49
|
+
selectTargets.push(node.deduplication);
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(node.from)) {
|
|
52
|
+
node.from.forEach((table) => {
|
|
53
|
+
selectTargets.push(table);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return selectTargets;
|
|
57
|
+
}
|
|
58
|
+
case "rosetta_stone":
|
|
59
|
+
case "dataset":
|
|
60
|
+
case "raw_table": {
|
|
61
|
+
if (node.join?.condition != null) {
|
|
62
|
+
return [node.join];
|
|
63
|
+
}
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
case "join":
|
|
67
|
+
if (node.condition !== null && node.condition !== undefined) {
|
|
68
|
+
return [node.condition];
|
|
69
|
+
}
|
|
70
|
+
return [];
|
|
71
|
+
default:
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function traverseParsedAst(node, callback) {
|
|
76
|
+
callback(node);
|
|
77
|
+
findTraversalTargets(node).forEach((childNode) => {
|
|
78
|
+
traverseParsedAst(childNode, callback);
|
|
79
|
+
});
|
|
80
|
+
}
|