@finos/legend-query-builder 4.15.42 → 4.15.43
Sign up to get free protection for your applications and to get access to all the features.
- 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 +1 -1
- 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/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 +5 -5
- package/src/graph/QueryBuilderMetaModelConst.ts +5 -1
- package/src/stores/QueryBuilderStateBuilder.ts +21 -3
- 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
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ResultModifierValueSpecificationBuilder.d.ts","sourceRoot":"","sources":["../../../../../src/stores/fetch-structure/tds/result-modifier/ResultModifierValueSpecificationBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EASvB,wBAAwB,EAIzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,gBAAgB,EAEjB,MAAM,iDAAiD,CAAC;AACzD,OAAO,KAAK,EACV,2BAA2B,EAC3B,eAAe,EAChB,MAAM,mCAAmC,CAAC;AAG3C,MAAM,MAAM,8BAA8B,GAAG;IAC3C,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,qBAAqB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC7C,CAAC;AAEF,8BAAsB,uCAAuC;IAC3D,0BAA0B,EAAE,wBAAwB,GAAG,SAAS,CAAC;IACjE,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAC9C,OAAO,EAAE,8BAA8B,GAAG,SAAS,CAAC;IAEpD,QAAQ,UAAS;IACjB,WAAW,EAAE,eAAe,EAAE,GAAG,SAAS,CAAC;IAC3C,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;gBAExB,iBAAiB,EAAE,iBAAiB;IAIhD,IAAI,iBAAiB,IAAI,wBAAwB,CAKhD;IAED,QAAQ,KAAK,oBAAoB,IAAI,MAAM,CAAC;IAC5C,QAAQ,KAAK,gBAAgB,IAAI,MAAM,CA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IAAa,oBAAoB,IAAI,MAAM,CAE1C;IAED,IAAa,eAAe,IAAI,MAAM,CAErC;IACD,IAAa,gBAAgB,IAAI,MAAM,CAEtC;IAEQ,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,kBAAkB;CAGtE;AAED,qBAAa,4CAA6C,SAAQ,uCAAuC;IACvG,IAAa,iBAAiB,IAAI,MAAM,CAEvC;IACD,IAAa,iBAAiB,IAAI,MAAM,CAEvC;IACD,IAAa,eAAe,IAAI,MAAM,CAErC;IACD,IAAa,gBAAgB,IAAI,MAAM,CAEtC;IACD,IAAa,gBAAgB,IAAI,MAAM,CAEtC;IACD,IAAa,oBAAoB,IAAI,MAAM,CAE1C;IAEQ,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,kBAAkB;CAOtE;AAED,eAAO,MAAM,uBAAuB,wBACb,2BAA2B,kBAChC,cAAc,WACrB,OAAO,YACN,8BAA8B,GAAG,SAAS,KACnD,cAeF,CAAC"}
|
package/lib/stores/fetch-structure/tds/result-modifier/ResultModifierValueSpecificationBuilder.js
ADDED
@@ -0,0 +1,213 @@
|
|
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
|
+
import { ColSpec, ColSpecInstanceValue, CollectionInstanceValue, GenericType, GenericTypeExplicitReference, Multiplicity, PrimitiveInstanceValue, PrimitiveType, SimpleFunctionExpression, createPrimitiveInstance_String, extractElementNameFromPath, matchFunctionName, } from '@finos/legend-graph';
|
17
|
+
import { COLUMN_SORT_TYPE, QUERY_BUILDER_SUPPORTED_FUNCTIONS, } from '../../../../graph/QueryBuilderMetaModelConst.js';
|
18
|
+
import { guaranteeNonNullable } from '@finos/legend-shared';
|
19
|
+
export class ResultModifierValueSpecificationBuilder {
|
20
|
+
_currentResultModifierFunc;
|
21
|
+
graphManagerState;
|
22
|
+
options;
|
23
|
+
distinct = false;
|
24
|
+
sortColumns;
|
25
|
+
limit;
|
26
|
+
slice;
|
27
|
+
constructor(graphManagerState) {
|
28
|
+
this.graphManagerState = graphManagerState;
|
29
|
+
}
|
30
|
+
get currentExpression() {
|
31
|
+
return guaranteeNonNullable(this._currentResultModifierFunc, `Current expression needs to be defined to build result modifier`);
|
32
|
+
}
|
33
|
+
get supportedResultModifiersFunctions() {
|
34
|
+
return [
|
35
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_PROJECT,
|
36
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_GROUP_BY,
|
37
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_FILTER,
|
38
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.OLAP_GROUPBY,
|
39
|
+
];
|
40
|
+
}
|
41
|
+
getSortTypeFunctionName(sortType) {
|
42
|
+
return sortType === COLUMN_SORT_TYPE.ASC
|
43
|
+
? this.ascFunctionname
|
44
|
+
: this.descFunctionName;
|
45
|
+
}
|
46
|
+
// builders
|
47
|
+
setCurrentResultModifierFunction(val) {
|
48
|
+
this._currentResultModifierFunc = val;
|
49
|
+
}
|
50
|
+
withOptions(options) {
|
51
|
+
this.options = options;
|
52
|
+
return this;
|
53
|
+
}
|
54
|
+
withDistinct(distinct) {
|
55
|
+
this.distinct = distinct;
|
56
|
+
return this;
|
57
|
+
}
|
58
|
+
withSortColumns(sortCols) {
|
59
|
+
if (sortCols?.length) {
|
60
|
+
this.sortColumns = sortCols;
|
61
|
+
}
|
62
|
+
return this;
|
63
|
+
}
|
64
|
+
withLimit(limit) {
|
65
|
+
this.limit = limit;
|
66
|
+
return this;
|
67
|
+
}
|
68
|
+
withSlice(slice) {
|
69
|
+
this.slice = slice;
|
70
|
+
return this;
|
71
|
+
}
|
72
|
+
// builder
|
73
|
+
buildDistinctFunction() {
|
74
|
+
const distinctFunction = new SimpleFunctionExpression(extractElementNameFromPath(this.distinctFunctionName));
|
75
|
+
distinctFunction.parametersValues[0] = this.currentExpression;
|
76
|
+
this.setCurrentResultModifierFunction(distinctFunction);
|
77
|
+
}
|
78
|
+
buildSortFunction(sortColumns) {
|
79
|
+
const sortFunction = new SimpleFunctionExpression(extractElementNameFromPath(this.sortFunctionName));
|
80
|
+
const multiplicity = this.graphManagerState.graph.getMultiplicity(sortColumns.length, sortColumns.length);
|
81
|
+
const collection = new CollectionInstanceValue(multiplicity, undefined);
|
82
|
+
collection.values = sortColumns.map((e) => this.buildSortExpression(e));
|
83
|
+
sortFunction.parametersValues[0] = this.currentExpression;
|
84
|
+
sortFunction.parametersValues[1] = collection;
|
85
|
+
this.setCurrentResultModifierFunction(sortFunction);
|
86
|
+
}
|
87
|
+
buildSortExpression(sortColumnState) {
|
88
|
+
const sortColumnFunction = new SimpleFunctionExpression(extractElementNameFromPath(this.getSortTypeFunctionName(sortColumnState.sortType)));
|
89
|
+
sortColumnFunction.parametersValues[0] = this.buildColumnValueSpec(sortColumnState.columnState.columnName);
|
90
|
+
return sortColumnFunction;
|
91
|
+
}
|
92
|
+
buildLimitFunction(limit) {
|
93
|
+
const limitPrimitiveInstanceVal = new PrimitiveInstanceValue(GenericTypeExplicitReference.create(new GenericType(PrimitiveType.INTEGER)));
|
94
|
+
limitPrimitiveInstanceVal.values = [
|
95
|
+
Math.min(limit
|
96
|
+
? this.options?.withDataOverflowCheck
|
97
|
+
? limit + 1
|
98
|
+
: limit
|
99
|
+
: Number.MAX_SAFE_INTEGER, this.options?.overridingLimit
|
100
|
+
? this.options.withDataOverflowCheck
|
101
|
+
? this.options.overridingLimit + 1
|
102
|
+
: this.options.overridingLimit
|
103
|
+
: Number.MAX_SAFE_INTEGER),
|
104
|
+
];
|
105
|
+
const takeFunction = new SimpleFunctionExpression(extractElementNameFromPath(this.limitFunctionName));
|
106
|
+
takeFunction.parametersValues[0] = this.currentExpression;
|
107
|
+
takeFunction.parametersValues[1] = limitPrimitiveInstanceVal;
|
108
|
+
this.setCurrentResultModifierFunction(takeFunction);
|
109
|
+
}
|
110
|
+
buildSliceFunction(slice) {
|
111
|
+
const sliceStart = slice[0];
|
112
|
+
const sliceEnd = slice[1];
|
113
|
+
const startVal = new PrimitiveInstanceValue(GenericTypeExplicitReference.create(new GenericType(PrimitiveType.INTEGER)));
|
114
|
+
const endVal = new PrimitiveInstanceValue(GenericTypeExplicitReference.create(new GenericType(PrimitiveType.INTEGER)));
|
115
|
+
startVal.values = [sliceStart];
|
116
|
+
endVal.values = [sliceEnd];
|
117
|
+
const sliceFunction = new SimpleFunctionExpression(extractElementNameFromPath(this.sliceFunctionName));
|
118
|
+
sliceFunction.parametersValues = [this.currentExpression, startVal, endVal];
|
119
|
+
this.setCurrentResultModifierFunction(sliceFunction);
|
120
|
+
}
|
121
|
+
build(lambdaFunction) {
|
122
|
+
if (lambdaFunction.expressionSequence.length === 1) {
|
123
|
+
const func = lambdaFunction.expressionSequence[0];
|
124
|
+
if (func instanceof SimpleFunctionExpression) {
|
125
|
+
if (matchFunctionName(func.functionName, this.supportedResultModifiersFunctions)) {
|
126
|
+
this._currentResultModifierFunc = func;
|
127
|
+
// build distinct()
|
128
|
+
if (this.distinct) {
|
129
|
+
this.buildDistinctFunction();
|
130
|
+
}
|
131
|
+
// build sort()
|
132
|
+
if (this.sortColumns) {
|
133
|
+
this.buildSortFunction(this.sortColumns);
|
134
|
+
}
|
135
|
+
// build take()
|
136
|
+
if (this.limit || this.options?.overridingLimit) {
|
137
|
+
this.buildLimitFunction(this.limit);
|
138
|
+
}
|
139
|
+
// build slice()
|
140
|
+
if (this.slice) {
|
141
|
+
this.buildSliceFunction(this.slice);
|
142
|
+
}
|
143
|
+
lambdaFunction.expressionSequence[0] = this.currentExpression;
|
144
|
+
return lambdaFunction;
|
145
|
+
}
|
146
|
+
}
|
147
|
+
}
|
148
|
+
return lambdaFunction;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
export class TDSResultModifierValueSpecificationBuilder extends ResultModifierValueSpecificationBuilder {
|
152
|
+
get limitFunctionName() {
|
153
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_TAKE;
|
154
|
+
}
|
155
|
+
get sliceFunctionName() {
|
156
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.SLICE;
|
157
|
+
}
|
158
|
+
get sortFunctionName() {
|
159
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_SORT;
|
160
|
+
}
|
161
|
+
get distinctFunctionName() {
|
162
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_DISTINCT;
|
163
|
+
}
|
164
|
+
get ascFunctionname() {
|
165
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_ASC;
|
166
|
+
}
|
167
|
+
get descFunctionName() {
|
168
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_DESC;
|
169
|
+
}
|
170
|
+
buildColumnValueSpec(columnName) {
|
171
|
+
return createPrimitiveInstance_String(columnName);
|
172
|
+
}
|
173
|
+
}
|
174
|
+
export class TypedResultModifierValueSpecificationBuilder extends ResultModifierValueSpecificationBuilder {
|
175
|
+
get limitFunctionName() {
|
176
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_LIMIT;
|
177
|
+
}
|
178
|
+
get sliceFunctionName() {
|
179
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_SLICE;
|
180
|
+
}
|
181
|
+
get ascFunctionname() {
|
182
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_ASC;
|
183
|
+
}
|
184
|
+
get descFunctionName() {
|
185
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_DESC;
|
186
|
+
}
|
187
|
+
get sortFunctionName() {
|
188
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_SORT;
|
189
|
+
}
|
190
|
+
get distinctFunctionName() {
|
191
|
+
return QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_DISTINCT;
|
192
|
+
}
|
193
|
+
buildColumnValueSpec(columnName) {
|
194
|
+
const colSpec = new ColSpecInstanceValue(Multiplicity.ONE, undefined);
|
195
|
+
const value = new ColSpec();
|
196
|
+
value.name = columnName;
|
197
|
+
colSpec.values = [value];
|
198
|
+
return colSpec;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
export const appendResultSetModifier = (resultModifierState, lambdaFunction, isTyped, options) => {
|
202
|
+
const builder = isTyped
|
203
|
+
? new TypedResultModifierValueSpecificationBuilder(resultModifierState.tdsState.queryBuilderState.graphManagerState)
|
204
|
+
: new TDSResultModifierValueSpecificationBuilder(resultModifierState.tdsState.queryBuilderState.graphManagerState);
|
205
|
+
return builder
|
206
|
+
.withOptions(options)
|
207
|
+
.withDistinct(resultModifierState.distinct)
|
208
|
+
.withSortColumns(resultModifierState.sortColumns)
|
209
|
+
.withLimit(resultModifierState.limit)
|
210
|
+
.withSlice(resultModifierState.slice)
|
211
|
+
.build(lambdaFunction);
|
212
|
+
};
|
213
|
+
//# sourceMappingURL=ResultModifierValueSpecificationBuilder.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ResultModifierValueSpecificationBuilder.js","sourceRoot":"","sources":["../../../../../src/stores/fetch-structure/tds/result-modifier/ResultModifierValueSpecificationBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAIL,OAAO,EACP,oBAAoB,EACpB,uBAAuB,EACvB,WAAW,EACX,4BAA4B,EAC5B,YAAY,EACZ,sBAAsB,EACt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,CAAC,WAAW,CAAC;SAChD,SAAS,CAAC,mBAAmB,CAAC,KAAK,CAAC;SACpC,SAAS,CAAC,mBAAmB,CAAC,KAAK,CAAC;SACpC,KAAK,CAAC,cAAc,CAAC,CAAC;AAC3B,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@finos/legend-query-builder",
|
3
|
-
"version": "4.15.
|
3
|
+
"version": "4.15.43",
|
4
4
|
"description": "Legend query builder core",
|
5
5
|
"keywords": [
|
6
6
|
"legend",
|
@@ -44,10 +44,10 @@
|
|
44
44
|
"dependencies": {
|
45
45
|
"@finos/legend-application": "16.0.21",
|
46
46
|
"@finos/legend-art": "7.1.78",
|
47
|
-
"@finos/legend-code-editor": "2.0.
|
48
|
-
"@finos/legend-data-cube": "0.0.
|
49
|
-
"@finos/legend-graph": "32.0.
|
50
|
-
"@finos/legend-lego": "2.0.
|
47
|
+
"@finos/legend-code-editor": "2.0.38",
|
48
|
+
"@finos/legend-data-cube": "0.0.45",
|
49
|
+
"@finos/legend-graph": "32.0.6",
|
50
|
+
"@finos/legend-lego": "2.0.41",
|
51
51
|
"@finos/legend-server-depot": "6.0.77",
|
52
52
|
"@finos/legend-shared": "11.0.0",
|
53
53
|
"@finos/legend-storage": "3.0.119",
|
@@ -121,7 +121,11 @@ export enum QUERY_BUILDER_SUPPORTED_FUNCTIONS {
|
|
121
121
|
// Relation
|
122
122
|
RELATION_PROJECT = 'meta::pure::functions::relation::project',
|
123
123
|
RELATION_LIMIT = 'meta::pure::functions::relation::limit',
|
124
|
-
|
124
|
+
RELATION_ASC = 'meta::pure::functions::relation::ascending',
|
125
|
+
RELATION_DESC = 'meta::pure::functions::relation::descending',
|
126
|
+
RELATION_DISTINCT = 'meta::pure::functions::relation::distinct',
|
127
|
+
RELATION_SORT = 'meta::pure::functions::relation::sort',
|
128
|
+
RELATION_SLICE = 'meta::pure::functions::relation::slice',
|
125
129
|
// filter
|
126
130
|
CONTAINS = 'meta::pure::functions::string::contains',
|
127
131
|
ENDS_WITH = 'meta::pure::functions::string::endsWith',
|
@@ -54,6 +54,7 @@ import {
|
|
54
54
|
RuntimePointer,
|
55
55
|
PackageableElementExplicitReference,
|
56
56
|
MILESTONING_STEREOTYPE,
|
57
|
+
type ColSpecInstanceValue,
|
57
58
|
} from '@finos/legend-graph';
|
58
59
|
import { processTDSPostFilterExpression } from './fetch-structure/tds/post-filter/QueryBuilderPostFilterStateBuilder.js';
|
59
60
|
import { processFilterExpression } from './filter/QueryBuilderFilterStateBuilder.js';
|
@@ -69,6 +70,7 @@ import {
|
|
69
70
|
processInternalizeExpression,
|
70
71
|
} from './fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeStateBuilder.js';
|
71
72
|
import {
|
73
|
+
processRelationSortDirectionExpression,
|
72
74
|
processTDSColExpression,
|
73
75
|
processTDSDistinctExpression,
|
74
76
|
processTDSProjectExpression,
|
@@ -669,10 +671,10 @@ export class QueryBuilderValueSpecificationProcessor
|
|
669
671
|
processTDSColExpression(valueSpecification, this.queryBuilderState);
|
670
672
|
return;
|
671
673
|
} else if (
|
672
|
-
matchFunctionName(
|
673
|
-
functionName,
|
674
|
+
matchFunctionName(functionName, [
|
674
675
|
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_TAKE,
|
675
|
-
|
676
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_LIMIT,
|
677
|
+
])
|
676
678
|
) {
|
677
679
|
processTDSTakeExpression(
|
678
680
|
valueSpecification,
|
@@ -725,6 +727,18 @@ export class QueryBuilderValueSpecificationProcessor
|
|
725
727
|
this.queryBuilderState,
|
726
728
|
);
|
727
729
|
return;
|
730
|
+
} else if (
|
731
|
+
matchFunctionName(functionName, [
|
732
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_ASC,
|
733
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_DESC,
|
734
|
+
])
|
735
|
+
) {
|
736
|
+
processRelationSortDirectionExpression(
|
737
|
+
valueSpecification,
|
738
|
+
this.parentExpression,
|
739
|
+
this.queryBuilderState,
|
740
|
+
);
|
741
|
+
return;
|
728
742
|
} else if (
|
729
743
|
matchFunctionName(
|
730
744
|
functionName,
|
@@ -994,6 +1008,10 @@ export class QueryBuilderValueSpecificationProcessor
|
|
994
1008
|
`Can't process col spec array expression with parent expression of function ${this.parentExpression.functionName}()`,
|
995
1009
|
);
|
996
1010
|
}
|
1011
|
+
|
1012
|
+
visit_ColSpecInstance(valueSpeciciation: ColSpecInstanceValue): void {
|
1013
|
+
throw new Error('Method not implemented.');
|
1014
|
+
}
|
997
1015
|
}
|
998
1016
|
|
999
1017
|
export const processParameters = (
|
@@ -29,6 +29,7 @@ import {
|
|
29
29
|
VariableExpression,
|
30
30
|
PrimitiveInstanceValue,
|
31
31
|
LambdaFunctionInstanceValue,
|
32
|
+
ColSpecInstanceValue,
|
32
33
|
} from '@finos/legend-graph';
|
33
34
|
import {
|
34
35
|
assertNonNullable,
|
@@ -603,7 +604,7 @@ export const processTDSSortDirectionExpression = (
|
|
603
604
|
// check parameters
|
604
605
|
assertTrue(
|
605
606
|
expression.parametersValues.length === 1,
|
606
|
-
`Can't process ${functionName}() expression: ${functionName}() expects
|
607
|
+
`Can't process ${functionName}() expression: ${functionName}() expects one argument`,
|
607
608
|
);
|
608
609
|
|
609
610
|
// build state
|
@@ -633,3 +634,65 @@ export const processTDSSortDirectionExpression = (
|
|
633
634
|
}
|
634
635
|
}
|
635
636
|
};
|
637
|
+
|
638
|
+
export const processRelationSortDirectionExpression = (
|
639
|
+
expression: SimpleFunctionExpression,
|
640
|
+
parentExpression: SimpleFunctionExpression | undefined,
|
641
|
+
queryBuilderState: QueryBuilderState,
|
642
|
+
): void => {
|
643
|
+
const functionName = expression.functionName;
|
644
|
+
|
645
|
+
// check parent expression
|
646
|
+
assertTrue(
|
647
|
+
Boolean(
|
648
|
+
parentExpression &&
|
649
|
+
matchFunctionName(
|
650
|
+
parentExpression.functionName,
|
651
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_SORT,
|
652
|
+
),
|
653
|
+
),
|
654
|
+
`Can't process ${functionName}() expression: only support ${functionName}() used within a sort() expression`,
|
655
|
+
);
|
656
|
+
|
657
|
+
// check parameters
|
658
|
+
assertTrue(
|
659
|
+
expression.parametersValues.length === 1,
|
660
|
+
`Can't process ${functionName}() expression: ${functionName}() expects one argument`,
|
661
|
+
);
|
662
|
+
|
663
|
+
// build state
|
664
|
+
if (
|
665
|
+
queryBuilderState.fetchStructureState.implementation instanceof
|
666
|
+
QueryBuilderTDSState
|
667
|
+
) {
|
668
|
+
const projectionState =
|
669
|
+
queryBuilderState.fetchStructureState.implementation;
|
670
|
+
const value = guaranteeType(
|
671
|
+
expression.parametersValues[0],
|
672
|
+
ColSpecInstanceValue,
|
673
|
+
);
|
674
|
+
assertTrue(
|
675
|
+
value.values.length === 1,
|
676
|
+
`Can't process ${functionName}() expression: Col Spec Instance Value expects one value`,
|
677
|
+
);
|
678
|
+
const sortColumnName = guaranteeNonNullable(
|
679
|
+
value.values[0],
|
680
|
+
`Col Spec value expected in Col Spec Instance Value`,
|
681
|
+
).name;
|
682
|
+
const queryBuilderProjectionColumnState = projectionState.tdsColumns.find(
|
683
|
+
(e) => e.columnName === sortColumnName,
|
684
|
+
);
|
685
|
+
if (queryBuilderProjectionColumnState) {
|
686
|
+
const sortColumnState = new SortColumnState(
|
687
|
+
queryBuilderProjectionColumnState,
|
688
|
+
);
|
689
|
+
sortColumnState.sortType = matchFunctionName(
|
690
|
+
functionName,
|
691
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_ASC,
|
692
|
+
)
|
693
|
+
? COLUMN_SORT_TYPE.ASC
|
694
|
+
: COLUMN_SORT_TYPE.DESC;
|
695
|
+
projectionState.resultSetModifierState.addSortColumn(sortColumnState);
|
696
|
+
}
|
697
|
+
}
|
698
|
+
};
|
package/src/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.ts
CHANGED
@@ -27,7 +27,6 @@ import {
|
|
27
27
|
V1_serializeRawValueSpecification,
|
28
28
|
V1_transformRawLambda,
|
29
29
|
V1_GraphTransformerContextBuilder,
|
30
|
-
matchFunctionName,
|
31
30
|
PrimitiveType,
|
32
31
|
LambdaFunctionInstanceValue,
|
33
32
|
} from '@finos/legend-graph';
|
@@ -42,10 +41,6 @@ import {
|
|
42
41
|
QueryBuilderSimpleProjectionColumnState,
|
43
42
|
} from './QueryBuilderProjectionColumnState.js';
|
44
43
|
import type { QueryBuilderTDSState } from '../QueryBuilderTDSState.js';
|
45
|
-
import {
|
46
|
-
type QueryResultSetModifierState,
|
47
|
-
type SortColumnState,
|
48
|
-
} from '../QueryResultSetModifierState.js';
|
49
44
|
import { QUERY_BUILDER_SUPPORTED_FUNCTIONS } from '../../../../graph/QueryBuilderMetaModelConst.js';
|
50
45
|
import { buildGenericLambdaFunctionInstanceValue } from '../../../QueryBuilderValueSpecificationHelper.js';
|
51
46
|
import {
|
@@ -54,139 +49,9 @@ import {
|
|
54
49
|
} from '../../../QueryBuilderValueSpecificationBuilderHelper.js';
|
55
50
|
import { appendOLAPGroupByState } from '../window/QueryBuilderWindowValueSpecificationBuilder.js';
|
56
51
|
import { appendPostFilter } from '../post-filter/QueryBuilderPostFilterValueSpecificationBuilder.js';
|
57
|
-
import { buildTDSSortTypeExpression } from '../QueryBuilderTDSHelper.js';
|
58
52
|
import { buildRelationProjection } from './QueryBuilderRelationProjectValueSpecBuidler.js';
|
59
53
|
import { QueryBuilderAggregateOperator_Wavg } from '../aggregation/operators/QueryBuilderAggregateOperator_Wavg.js';
|
60
|
-
|
61
|
-
const buildSortExpression = (
|
62
|
-
sortColumnState: SortColumnState,
|
63
|
-
): SimpleFunctionExpression =>
|
64
|
-
buildTDSSortTypeExpression(
|
65
|
-
sortColumnState.sortType,
|
66
|
-
sortColumnState.columnState.columnName,
|
67
|
-
);
|
68
|
-
|
69
|
-
const appendResultSetModifier = (
|
70
|
-
resultModifierState: QueryResultSetModifierState,
|
71
|
-
lambdaFunction: LambdaFunction,
|
72
|
-
options?:
|
73
|
-
| {
|
74
|
-
overridingLimit?: number | undefined;
|
75
|
-
withDataOverflowCheck?: boolean | undefined;
|
76
|
-
}
|
77
|
-
| undefined,
|
78
|
-
): LambdaFunction => {
|
79
|
-
if (lambdaFunction.expressionSequence.length === 1) {
|
80
|
-
const func = lambdaFunction.expressionSequence[0];
|
81
|
-
if (func instanceof SimpleFunctionExpression) {
|
82
|
-
if (
|
83
|
-
matchFunctionName(func.functionName, [
|
84
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_PROJECT,
|
85
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_GROUP_BY,
|
86
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_FILTER,
|
87
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.OLAP_GROUPBY,
|
88
|
-
])
|
89
|
-
) {
|
90
|
-
let currentExpression = func;
|
91
|
-
|
92
|
-
// build distinct()
|
93
|
-
if (resultModifierState.distinct) {
|
94
|
-
const distinctFunction = new SimpleFunctionExpression(
|
95
|
-
extractElementNameFromPath(
|
96
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_DISTINCT,
|
97
|
-
),
|
98
|
-
);
|
99
|
-
distinctFunction.parametersValues[0] = currentExpression;
|
100
|
-
currentExpression = distinctFunction;
|
101
|
-
}
|
102
|
-
|
103
|
-
// build sort()
|
104
|
-
if (resultModifierState.sortColumns.length) {
|
105
|
-
const sortFunction = new SimpleFunctionExpression(
|
106
|
-
extractElementNameFromPath(
|
107
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_SORT,
|
108
|
-
),
|
109
|
-
);
|
110
|
-
const multiplicity =
|
111
|
-
resultModifierState.tdsState.queryBuilderState.graphManagerState.graph.getMultiplicity(
|
112
|
-
resultModifierState.sortColumns.length,
|
113
|
-
resultModifierState.sortColumns.length,
|
114
|
-
);
|
115
|
-
const collection = new CollectionInstanceValue(
|
116
|
-
multiplicity,
|
117
|
-
undefined,
|
118
|
-
);
|
119
|
-
collection.values =
|
120
|
-
resultModifierState.sortColumns.map(buildSortExpression);
|
121
|
-
sortFunction.parametersValues[0] = currentExpression;
|
122
|
-
sortFunction.parametersValues[1] = collection;
|
123
|
-
currentExpression = sortFunction;
|
124
|
-
}
|
125
|
-
|
126
|
-
// build take()
|
127
|
-
if (resultModifierState.limit || options?.overridingLimit) {
|
128
|
-
const limit = new PrimitiveInstanceValue(
|
129
|
-
GenericTypeExplicitReference.create(
|
130
|
-
new GenericType(PrimitiveType.INTEGER),
|
131
|
-
),
|
132
|
-
);
|
133
|
-
limit.values = [
|
134
|
-
Math.min(
|
135
|
-
resultModifierState.limit
|
136
|
-
? options?.withDataOverflowCheck
|
137
|
-
? resultModifierState.limit + 1
|
138
|
-
: resultModifierState.limit
|
139
|
-
: Number.MAX_SAFE_INTEGER,
|
140
|
-
options?.overridingLimit
|
141
|
-
? options.withDataOverflowCheck
|
142
|
-
? options.overridingLimit + 1
|
143
|
-
: options.overridingLimit
|
144
|
-
: Number.MAX_SAFE_INTEGER,
|
145
|
-
),
|
146
|
-
];
|
147
|
-
const takeFunction = new SimpleFunctionExpression(
|
148
|
-
extractElementNameFromPath(
|
149
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_TAKE,
|
150
|
-
),
|
151
|
-
);
|
152
|
-
takeFunction.parametersValues[0] = currentExpression;
|
153
|
-
takeFunction.parametersValues[1] = limit;
|
154
|
-
currentExpression = takeFunction;
|
155
|
-
}
|
156
|
-
// build slice()
|
157
|
-
if (resultModifierState.slice) {
|
158
|
-
const sliceStart = resultModifierState.slice[0];
|
159
|
-
const sliceEnd = resultModifierState.slice[1];
|
160
|
-
const startVal = new PrimitiveInstanceValue(
|
161
|
-
GenericTypeExplicitReference.create(
|
162
|
-
new GenericType(PrimitiveType.INTEGER),
|
163
|
-
),
|
164
|
-
);
|
165
|
-
const endVal = new PrimitiveInstanceValue(
|
166
|
-
GenericTypeExplicitReference.create(
|
167
|
-
new GenericType(PrimitiveType.INTEGER),
|
168
|
-
),
|
169
|
-
);
|
170
|
-
startVal.values = [sliceStart];
|
171
|
-
endVal.values = [sliceEnd];
|
172
|
-
const sliceFunction = new SimpleFunctionExpression(
|
173
|
-
extractElementNameFromPath(QUERY_BUILDER_SUPPORTED_FUNCTIONS.SLICE),
|
174
|
-
);
|
175
|
-
sliceFunction.parametersValues = [
|
176
|
-
currentExpression,
|
177
|
-
startVal,
|
178
|
-
endVal,
|
179
|
-
];
|
180
|
-
currentExpression = sliceFunction;
|
181
|
-
}
|
182
|
-
|
183
|
-
lambdaFunction.expressionSequence[0] = currentExpression;
|
184
|
-
return lambdaFunction;
|
185
|
-
}
|
186
|
-
}
|
187
|
-
}
|
188
|
-
return lambdaFunction;
|
189
|
-
};
|
54
|
+
import { appendResultSetModifier } from '../result-modifier/ResultModifierValueSpecificationBuilder.js';
|
190
55
|
|
191
56
|
const buildProjectColFunc = (
|
192
57
|
tdsState: QueryBuilderTDSState,
|
@@ -542,14 +407,19 @@ export const appendProjection = (
|
|
542
407
|
appendPostFilter(tdsState.postFilterState, lambdaFunction);
|
543
408
|
|
544
409
|
// build result set modifiers
|
545
|
-
appendResultSetModifier(
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
410
|
+
appendResultSetModifier(
|
411
|
+
tdsState.resultSetModifierState,
|
412
|
+
lambdaFunction,
|
413
|
+
tdsState.queryBuilderState.isFetchStructureTyped,
|
414
|
+
{
|
415
|
+
overridingLimit:
|
416
|
+
options?.isBuildingExecutionQuery && !options.isExportingResult
|
417
|
+
? queryBuilderState.resultState.previewLimit
|
418
|
+
: undefined,
|
419
|
+
withDataOverflowCheck:
|
420
|
+
options?.isBuildingExecutionQuery && !options.isExportingResult
|
421
|
+
? options.withDataOverflowCheck
|
422
|
+
: undefined,
|
423
|
+
},
|
424
|
+
);
|
555
425
|
};
|