@finos/legend-query-builder 4.15.41 → 4.15.43
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/lib/graph/QueryBuilderMetaModelConst.d.ts +5 -0
- package/lib/graph/QueryBuilderMetaModelConst.d.ts.map +1 -1
- package/lib/graph/QueryBuilderMetaModelConst.js +5 -0
- package/lib/graph/QueryBuilderMetaModelConst.js.map +1 -1
- package/lib/index.css +1 -1
- package/lib/package.json +3 -3
- package/lib/stores/QueryBuilderStateBuilder.d.ts +2 -1
- package/lib/stores/QueryBuilderStateBuilder.d.ts.map +1 -1
- package/lib/stores/QueryBuilderStateBuilder.js +15 -2
- package/lib/stores/QueryBuilderStateBuilder.js.map +1 -1
- package/lib/stores/data-cube/QueryBuilderDataCubeEngine.d.ts +7 -8
- package/lib/stores/data-cube/QueryBuilderDataCubeEngine.d.ts.map +1 -1
- package/lib/stores/data-cube/QueryBuilderDataCubeEngine.js +46 -48
- package/lib/stores/data-cube/QueryBuilderDataCubeEngine.js.map +1 -1
- package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionStateBuilder.d.ts +1 -0
- package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionStateBuilder.d.ts.map +1 -1
- package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionStateBuilder.js +26 -2
- package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionStateBuilder.js.map +1 -1
- package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.d.ts.map +1 -1
- package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.js +3 -75
- package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.js.map +1 -1
- package/lib/stores/fetch-structure/tds/result-modifier/ResultModifierValueSpecificationBuilder.d.ts +74 -0
- package/lib/stores/fetch-structure/tds/result-modifier/ResultModifierValueSpecificationBuilder.d.ts.map +1 -0
- package/lib/stores/fetch-structure/tds/result-modifier/ResultModifierValueSpecificationBuilder.js +213 -0
- package/lib/stores/fetch-structure/tds/result-modifier/ResultModifierValueSpecificationBuilder.js.map +1 -0
- package/package.json +9 -9
- package/src/graph/QueryBuilderMetaModelConst.ts +5 -1
- package/src/stores/QueryBuilderStateBuilder.ts +21 -3
- package/src/stores/data-cube/QueryBuilderDataCubeEngine.ts +86 -86
- package/src/stores/fetch-structure/tds/projection/QueryBuilderProjectionStateBuilder.ts +64 -1
- package/src/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.ts +16 -146
- package/src/stores/fetch-structure/tds/result-modifier/ResultModifierValueSpecificationBuilder.ts +337 -0
- package/tsconfig.json +1 -0
package/src/stores/fetch-structure/tds/result-modifier/ResultModifierValueSpecificationBuilder.ts
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2020-present, Goldman Sachs
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
type GraphManagerState,
|
|
19
|
+
type LambdaFunction,
|
|
20
|
+
type ValueSpecification,
|
|
21
|
+
ColSpec,
|
|
22
|
+
ColSpecInstanceValue,
|
|
23
|
+
CollectionInstanceValue,
|
|
24
|
+
GenericType,
|
|
25
|
+
GenericTypeExplicitReference,
|
|
26
|
+
Multiplicity,
|
|
27
|
+
PrimitiveInstanceValue,
|
|
28
|
+
PrimitiveType,
|
|
29
|
+
SimpleFunctionExpression,
|
|
30
|
+
createPrimitiveInstance_String,
|
|
31
|
+
extractElementNameFromPath,
|
|
32
|
+
matchFunctionName,
|
|
33
|
+
} from '@finos/legend-graph';
|
|
34
|
+
import {
|
|
35
|
+
COLUMN_SORT_TYPE,
|
|
36
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS,
|
|
37
|
+
} from '../../../../graph/QueryBuilderMetaModelConst.js';
|
|
38
|
+
import type {
|
|
39
|
+
QueryResultSetModifierState,
|
|
40
|
+
SortColumnState,
|
|
41
|
+
} from '../QueryResultSetModifierState.js';
|
|
42
|
+
import { guaranteeNonNullable } from '@finos/legend-shared';
|
|
43
|
+
|
|
44
|
+
export type ResultModifierValueSpecOptions = {
|
|
45
|
+
overridingLimit?: number | undefined;
|
|
46
|
+
withDataOverflowCheck?: boolean | undefined;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export abstract class ResultModifierValueSpecificationBuilder {
|
|
50
|
+
_currentResultModifierFunc: SimpleFunctionExpression | undefined;
|
|
51
|
+
readonly graphManagerState: GraphManagerState;
|
|
52
|
+
options: ResultModifierValueSpecOptions | undefined;
|
|
53
|
+
|
|
54
|
+
distinct = false;
|
|
55
|
+
sortColumns: SortColumnState[] | undefined;
|
|
56
|
+
limit?: number | undefined;
|
|
57
|
+
slice: [number, number] | undefined;
|
|
58
|
+
|
|
59
|
+
constructor(graphManagerState: GraphManagerState) {
|
|
60
|
+
this.graphManagerState = graphManagerState;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get currentExpression(): SimpleFunctionExpression {
|
|
64
|
+
return guaranteeNonNullable(
|
|
65
|
+
this._currentResultModifierFunc,
|
|
66
|
+
`Current expression needs to be defined to build result modifier`,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
// function
|
|
70
|
+
abstract get distinctFunctionName(): string;
|
|
71
|
+
abstract get sortFunctionName(): string;
|
|
72
|
+
abstract get limitFunctionName(): string;
|
|
73
|
+
abstract get sliceFunctionName(): string;
|
|
74
|
+
abstract get ascFunctionname(): string;
|
|
75
|
+
abstract get descFunctionName(): string;
|
|
76
|
+
|
|
77
|
+
get supportedResultModifiersFunctions(): string[] {
|
|
78
|
+
return [
|
|
79
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_PROJECT,
|
|
80
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_GROUP_BY,
|
|
81
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_FILTER,
|
|
82
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.OLAP_GROUPBY,
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
getSortTypeFunctionName(sortType: COLUMN_SORT_TYPE): string {
|
|
86
|
+
return sortType === COLUMN_SORT_TYPE.ASC
|
|
87
|
+
? this.ascFunctionname
|
|
88
|
+
: this.descFunctionName;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// builders
|
|
92
|
+
setCurrentResultModifierFunction(val: SimpleFunctionExpression): void {
|
|
93
|
+
this._currentResultModifierFunc = val;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
withOptions(
|
|
97
|
+
options: ResultModifierValueSpecOptions | undefined,
|
|
98
|
+
): ResultModifierValueSpecificationBuilder {
|
|
99
|
+
this.options = options;
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
withDistinct(distinct: boolean): ResultModifierValueSpecificationBuilder {
|
|
104
|
+
this.distinct = distinct;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
withSortColumns(
|
|
109
|
+
sortCols: SortColumnState[] | undefined,
|
|
110
|
+
): ResultModifierValueSpecificationBuilder {
|
|
111
|
+
if (sortCols?.length) {
|
|
112
|
+
this.sortColumns = sortCols;
|
|
113
|
+
}
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
withLimit(
|
|
118
|
+
limit: number | undefined,
|
|
119
|
+
): ResultModifierValueSpecificationBuilder {
|
|
120
|
+
this.limit = limit;
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
withSlice(
|
|
125
|
+
slice: [number, number] | undefined,
|
|
126
|
+
): ResultModifierValueSpecificationBuilder {
|
|
127
|
+
this.slice = slice;
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// builder
|
|
132
|
+
buildDistinctFunction(): void {
|
|
133
|
+
const distinctFunction = new SimpleFunctionExpression(
|
|
134
|
+
extractElementNameFromPath(this.distinctFunctionName),
|
|
135
|
+
);
|
|
136
|
+
distinctFunction.parametersValues[0] = this.currentExpression;
|
|
137
|
+
this.setCurrentResultModifierFunction(distinctFunction);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
buildSortFunction(sortColumns: SortColumnState[]): void {
|
|
141
|
+
const sortFunction = new SimpleFunctionExpression(
|
|
142
|
+
extractElementNameFromPath(this.sortFunctionName),
|
|
143
|
+
);
|
|
144
|
+
const multiplicity = this.graphManagerState.graph.getMultiplicity(
|
|
145
|
+
sortColumns.length,
|
|
146
|
+
sortColumns.length,
|
|
147
|
+
);
|
|
148
|
+
const collection = new CollectionInstanceValue(multiplicity, undefined);
|
|
149
|
+
collection.values = sortColumns.map((e) => this.buildSortExpression(e));
|
|
150
|
+
sortFunction.parametersValues[0] = this.currentExpression;
|
|
151
|
+
sortFunction.parametersValues[1] = collection;
|
|
152
|
+
this.setCurrentResultModifierFunction(sortFunction);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
buildSortExpression(
|
|
156
|
+
sortColumnState: SortColumnState,
|
|
157
|
+
): SimpleFunctionExpression {
|
|
158
|
+
const sortColumnFunction = new SimpleFunctionExpression(
|
|
159
|
+
extractElementNameFromPath(
|
|
160
|
+
this.getSortTypeFunctionName(sortColumnState.sortType),
|
|
161
|
+
),
|
|
162
|
+
);
|
|
163
|
+
sortColumnFunction.parametersValues[0] = this.buildColumnValueSpec(
|
|
164
|
+
sortColumnState.columnState.columnName,
|
|
165
|
+
);
|
|
166
|
+
return sortColumnFunction;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
abstract buildColumnValueSpec(colName: string): ValueSpecification;
|
|
170
|
+
|
|
171
|
+
buildLimitFunction(limit?: number | undefined) {
|
|
172
|
+
const limitPrimitiveInstanceVal = new PrimitiveInstanceValue(
|
|
173
|
+
GenericTypeExplicitReference.create(
|
|
174
|
+
new GenericType(PrimitiveType.INTEGER),
|
|
175
|
+
),
|
|
176
|
+
);
|
|
177
|
+
limitPrimitiveInstanceVal.values = [
|
|
178
|
+
Math.min(
|
|
179
|
+
limit
|
|
180
|
+
? this.options?.withDataOverflowCheck
|
|
181
|
+
? limit + 1
|
|
182
|
+
: limit
|
|
183
|
+
: Number.MAX_SAFE_INTEGER,
|
|
184
|
+
this.options?.overridingLimit
|
|
185
|
+
? this.options.withDataOverflowCheck
|
|
186
|
+
? this.options.overridingLimit + 1
|
|
187
|
+
: this.options.overridingLimit
|
|
188
|
+
: Number.MAX_SAFE_INTEGER,
|
|
189
|
+
),
|
|
190
|
+
];
|
|
191
|
+
const takeFunction = new SimpleFunctionExpression(
|
|
192
|
+
extractElementNameFromPath(this.limitFunctionName),
|
|
193
|
+
);
|
|
194
|
+
takeFunction.parametersValues[0] = this.currentExpression;
|
|
195
|
+
takeFunction.parametersValues[1] = limitPrimitiveInstanceVal;
|
|
196
|
+
this.setCurrentResultModifierFunction(takeFunction);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
buildSliceFunction(slice: [number, number]): void {
|
|
200
|
+
const sliceStart = slice[0];
|
|
201
|
+
const sliceEnd = slice[1];
|
|
202
|
+
const startVal = new PrimitiveInstanceValue(
|
|
203
|
+
GenericTypeExplicitReference.create(
|
|
204
|
+
new GenericType(PrimitiveType.INTEGER),
|
|
205
|
+
),
|
|
206
|
+
);
|
|
207
|
+
const endVal = new PrimitiveInstanceValue(
|
|
208
|
+
GenericTypeExplicitReference.create(
|
|
209
|
+
new GenericType(PrimitiveType.INTEGER),
|
|
210
|
+
),
|
|
211
|
+
);
|
|
212
|
+
startVal.values = [sliceStart];
|
|
213
|
+
endVal.values = [sliceEnd];
|
|
214
|
+
const sliceFunction = new SimpleFunctionExpression(
|
|
215
|
+
extractElementNameFromPath(this.sliceFunctionName),
|
|
216
|
+
);
|
|
217
|
+
sliceFunction.parametersValues = [this.currentExpression, startVal, endVal];
|
|
218
|
+
this.setCurrentResultModifierFunction(sliceFunction);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
build(lambdaFunction: LambdaFunction): LambdaFunction {
|
|
222
|
+
if (lambdaFunction.expressionSequence.length === 1) {
|
|
223
|
+
const func = lambdaFunction.expressionSequence[0];
|
|
224
|
+
if (func instanceof SimpleFunctionExpression) {
|
|
225
|
+
if (
|
|
226
|
+
matchFunctionName(
|
|
227
|
+
func.functionName,
|
|
228
|
+
this.supportedResultModifiersFunctions,
|
|
229
|
+
)
|
|
230
|
+
) {
|
|
231
|
+
this._currentResultModifierFunc = func;
|
|
232
|
+
|
|
233
|
+
// build distinct()
|
|
234
|
+
if (this.distinct) {
|
|
235
|
+
this.buildDistinctFunction();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// build sort()
|
|
239
|
+
if (this.sortColumns) {
|
|
240
|
+
this.buildSortFunction(this.sortColumns);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// build take()
|
|
244
|
+
if (this.limit || this.options?.overridingLimit) {
|
|
245
|
+
this.buildLimitFunction(this.limit);
|
|
246
|
+
}
|
|
247
|
+
// build slice()
|
|
248
|
+
if (this.slice) {
|
|
249
|
+
this.buildSliceFunction(this.slice);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
lambdaFunction.expressionSequence[0] = this.currentExpression;
|
|
253
|
+
return lambdaFunction;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return lambdaFunction;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export class TDSResultModifierValueSpecificationBuilder extends ResultModifierValueSpecificationBuilder {
|
|
262
|
+
override get limitFunctionName(): string {
|
|
263
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_TAKE;
|
|
264
|
+
}
|
|
265
|
+
override get sliceFunctionName(): string {
|
|
266
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.SLICE;
|
|
267
|
+
}
|
|
268
|
+
override get sortFunctionName(): string {
|
|
269
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_SORT;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
override get distinctFunctionName(): string {
|
|
273
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_DISTINCT;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
override get ascFunctionname(): string {
|
|
277
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_ASC;
|
|
278
|
+
}
|
|
279
|
+
override get descFunctionName(): string {
|
|
280
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_DESC;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
override buildColumnValueSpec(columnName: string): ValueSpecification {
|
|
284
|
+
return createPrimitiveInstance_String(columnName);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export class TypedResultModifierValueSpecificationBuilder extends ResultModifierValueSpecificationBuilder {
|
|
289
|
+
override get limitFunctionName(): string {
|
|
290
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_LIMIT;
|
|
291
|
+
}
|
|
292
|
+
override get sliceFunctionName(): string {
|
|
293
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_SLICE;
|
|
294
|
+
}
|
|
295
|
+
override get ascFunctionname(): string {
|
|
296
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_ASC;
|
|
297
|
+
}
|
|
298
|
+
override get descFunctionName(): string {
|
|
299
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_DESC;
|
|
300
|
+
}
|
|
301
|
+
override get sortFunctionName(): string {
|
|
302
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_SORT;
|
|
303
|
+
}
|
|
304
|
+
override get distinctFunctionName(): string {
|
|
305
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_DISTINCT;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
override buildColumnValueSpec(columnName: string): ValueSpecification {
|
|
309
|
+
const colSpec = new ColSpecInstanceValue(Multiplicity.ONE, undefined);
|
|
310
|
+
const value = new ColSpec();
|
|
311
|
+
value.name = columnName;
|
|
312
|
+
colSpec.values = [value];
|
|
313
|
+
return colSpec;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export const appendResultSetModifier = (
|
|
318
|
+
resultModifierState: QueryResultSetModifierState,
|
|
319
|
+
lambdaFunction: LambdaFunction,
|
|
320
|
+
isTyped: boolean,
|
|
321
|
+
options?: ResultModifierValueSpecOptions | undefined,
|
|
322
|
+
): LambdaFunction => {
|
|
323
|
+
const builder = isTyped
|
|
324
|
+
? new TypedResultModifierValueSpecificationBuilder(
|
|
325
|
+
resultModifierState.tdsState.queryBuilderState.graphManagerState,
|
|
326
|
+
)
|
|
327
|
+
: new TDSResultModifierValueSpecificationBuilder(
|
|
328
|
+
resultModifierState.tdsState.queryBuilderState.graphManagerState,
|
|
329
|
+
);
|
|
330
|
+
return builder
|
|
331
|
+
.withOptions(options)
|
|
332
|
+
.withDistinct(resultModifierState.distinct)
|
|
333
|
+
.withSortColumns(resultModifierState.sortColumns)
|
|
334
|
+
.withLimit(resultModifierState.limit)
|
|
335
|
+
.withSlice(resultModifierState.slice)
|
|
336
|
+
.build(lambdaFunction);
|
|
337
|
+
};
|
package/tsconfig.json
CHANGED
|
@@ -164,6 +164,7 @@
|
|
|
164
164
|
"./src/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.ts",
|
|
165
165
|
"./src/stores/fetch-structure/tds/projection/QueryBuilderRelationProjectValueSpecBuidler.ts",
|
|
166
166
|
"./src/stores/fetch-structure/tds/projection/QueryBuilderTypedProjectionStateBuilder.ts",
|
|
167
|
+
"./src/stores/fetch-structure/tds/result-modifier/ResultModifierValueSpecificationBuilder.ts",
|
|
167
168
|
"./src/stores/fetch-structure/tds/window/QueryBuilderWindowGroupByOperatorLoader.ts",
|
|
168
169
|
"./src/stores/fetch-structure/tds/window/QueryBuilderWindowState.ts",
|
|
169
170
|
"./src/stores/fetch-structure/tds/window/QueryBuilderWindowStateBuilder.ts",
|