-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathBaseSegment.ts
97 lines (80 loc) · 2.4 KB
/
BaseSegment.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import type { BaseQuery } from './BaseQuery';
import { CubeSymbols } from "../compiler/CubeSymbols";
export class BaseSegment {
public readonly expression: any;
public readonly expressionCubeName: any;
public readonly expressionName: any;
public readonly isMemberExpression: boolean = false;
public readonly joinHint: Array<string> = [];
public constructor(
protected readonly query: BaseQuery,
public readonly segment: string | any
) {
if (segment.expression) {
this.expression = segment.expression;
this.expressionCubeName = segment.cubeName;
// In case of SQL push down expressionName doesn't contain cube name. It's just a column name.
this.expressionName = segment.expressionName || `${segment.cubeName}.${segment.name}`;
this.isMemberExpression = !!segment.definition;
} else {
// TODO move this `as` to static types
const segmentPath = segment as string;
const { path, joinHint } = CubeSymbols.joinHintFromPath(segmentPath);
this.segment = path;
this.joinHint = joinHint;
}
}
public filterToWhere() {
return this.segmentSql();
}
public segmentSql() {
if (this.expression) {
return this.query.evaluateSymbolSql(this.expressionCubeName, this.expressionName, this.definition(), 'segment');
}
return this.query.segmentSql(this);
}
public filterParams() {
return [];
}
public segmentDefinition() {
return this.query.cubeEvaluator.segmentByPath(this.segment);
}
public isMultiStage() {
if (this.expression) { // TODO
return false;
}
return this.definition().multiStage;
}
public definition(): any {
if (this.expression) {
return {
sql: this.expression
};
}
return this.segmentDefinition();
}
public getMembers() {
return [this];
}
public cube() {
if (this.expression) {
return this.query.cubeEvaluator.cubeFromPath(this.expressionCubeName);
}
return this.query.cubeEvaluator.cubeFromPath(this.segment);
}
public sqlDefinition() {
return this.segmentDefinition().sql;
}
public path() {
if (this.expression) {
return null;
}
return this.query.cubeEvaluator.parsePath('segments', this.segment);
}
public expressionPath() {
if (this.expression) {
return `expr:${this.expression.expressionName}`;
}
return this.query.cubeEvaluator.pathFromArray(this.path());
}
}