@finos/legend-query-builder 4.14.45 → 4.14.46
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/__lib__/QueryBuilderTesting.d.ts +1 -0
- package/lib/__lib__/QueryBuilderTesting.d.ts.map +1 -1
- package/lib/__lib__/QueryBuilderTesting.js +1 -0
- package/lib/__lib__/QueryBuilderTesting.js.map +1 -1
- package/lib/components/fetch-structure/QueryBuilderFetchStructurePanel.d.ts.map +1 -1
- package/lib/components/fetch-structure/QueryBuilderFetchStructurePanel.js.map +1 -1
- package/lib/components/fetch-structure/QueryBuilderTDSPanel.d.ts.map +1 -1
- package/lib/components/fetch-structure/QueryBuilderTDSPanel.js +93 -2
- package/lib/components/fetch-structure/QueryBuilderTDSPanel.js.map +1 -1
- package/lib/graph/QueryBuilderMetaModelConst.d.ts +1 -0
- package/lib/graph/QueryBuilderMetaModelConst.d.ts.map +1 -1
- package/lib/graph/QueryBuilderMetaModelConst.js +1 -0
- package/lib/graph/QueryBuilderMetaModelConst.js.map +1 -1
- package/lib/index.css +2 -2
- package/lib/index.css.map +1 -1
- package/lib/package.json +1 -1
- package/lib/stores/QueryBuilderStateHashUtils.d.ts +1 -0
- package/lib/stores/QueryBuilderStateHashUtils.d.ts.map +1 -1
- package/lib/stores/QueryBuilderStateHashUtils.js +1 -0
- package/lib/stores/QueryBuilderStateHashUtils.js.map +1 -1
- package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.d.ts.map +1 -1
- package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.js +2 -0
- package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.js.map +1 -1
- package/lib/stores/fetch-structure/tds/aggregation/QueryBuilderAggregateOperator.d.ts +2 -0
- package/lib/stores/fetch-structure/tds/aggregation/QueryBuilderAggregateOperator.d.ts.map +1 -1
- package/lib/stores/fetch-structure/tds/aggregation/QueryBuilderAggregateOperator.js +8 -0
- package/lib/stores/fetch-structure/tds/aggregation/QueryBuilderAggregateOperator.js.map +1 -1
- package/lib/stores/fetch-structure/tds/aggregation/QueryBuilderAggregateOperatorLoader.d.ts.map +1 -1
- package/lib/stores/fetch-structure/tds/aggregation/QueryBuilderAggregateOperatorLoader.js +2 -0
- package/lib/stores/fetch-structure/tds/aggregation/QueryBuilderAggregateOperatorLoader.js.map +1 -1
- package/lib/stores/fetch-structure/tds/aggregation/QueryBuilderAggregationState.d.ts +1 -0
- package/lib/stores/fetch-structure/tds/aggregation/QueryBuilderAggregationState.d.ts.map +1 -1
- package/lib/stores/fetch-structure/tds/aggregation/QueryBuilderAggregationState.js +7 -3
- package/lib/stores/fetch-structure/tds/aggregation/QueryBuilderAggregationState.js.map +1 -1
- package/lib/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperatorValueSpecificationBuilder.d.ts.map +1 -1
- package/lib/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperatorValueSpecificationBuilder.js.map +1 -1
- package/lib/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperator_Percentile.d.ts +37 -0
- package/lib/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperator_Percentile.d.ts.map +1 -0
- package/lib/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperator_Percentile.js +123 -0
- package/lib/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperator_Percentile.js.map +1 -0
- package/package.json +3 -3
- package/src/__lib__/QueryBuilderTesting.ts +1 -0
- package/src/components/fetch-structure/QueryBuilderFetchStructurePanel.tsx +0 -1
- package/src/components/fetch-structure/QueryBuilderTDSPanel.tsx +208 -4
- package/src/graph/QueryBuilderMetaModelConst.ts +1 -0
- package/src/stores/QueryBuilderStateHashUtils.ts +1 -0
- package/src/stores/fetch-structure/tds/QueryBuilderTDSState.ts +5 -0
- package/src/stores/fetch-structure/tds/aggregation/QueryBuilderAggregateOperator.ts +10 -0
- package/src/stores/fetch-structure/tds/aggregation/QueryBuilderAggregateOperatorLoader.ts +2 -0
- package/src/stores/fetch-structure/tds/aggregation/QueryBuilderAggregationState.ts +9 -3
- package/src/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperatorValueSpecificationBuilder.ts +0 -1
- package/src/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperator_Percentile.ts +241 -0
- package/tsconfig.json +1 -0
@@ -0,0 +1,241 @@
|
|
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
|
+
matchFunctionName,
|
19
|
+
PRIMITIVE_TYPE,
|
20
|
+
type ValueSpecification,
|
21
|
+
SimpleFunctionExpression,
|
22
|
+
VariableExpression,
|
23
|
+
type PureModel,
|
24
|
+
type AbstractPropertyExpression,
|
25
|
+
GenericType,
|
26
|
+
GenericTypeExplicitReference,
|
27
|
+
Multiplicity,
|
28
|
+
PrimitiveInstanceValue,
|
29
|
+
PrimitiveType,
|
30
|
+
extractElementNameFromPath,
|
31
|
+
} from '@finos/legend-graph';
|
32
|
+
import { QueryBuilderAggregateColumnState } from '../QueryBuilderAggregationState.js';
|
33
|
+
import { QueryBuilderAggregateOperator } from '../QueryBuilderAggregateOperator.js';
|
34
|
+
import {
|
35
|
+
type QueryBuilderProjectionColumnState,
|
36
|
+
QueryBuilderSimpleProjectionColumnState,
|
37
|
+
} from '../../projection/QueryBuilderProjectionColumnState.js';
|
38
|
+
import { QUERY_BUILDER_SUPPORTED_FUNCTIONS } from '../../../../../graph/QueryBuilderMetaModelConst.js';
|
39
|
+
import {
|
40
|
+
type Hashable,
|
41
|
+
hashArray,
|
42
|
+
assertTrue,
|
43
|
+
guaranteeType,
|
44
|
+
} from '@finos/legend-shared';
|
45
|
+
import { QUERY_BUILDER_STATE_HASH_STRUCTURE } from '../../../../QueryBuilderStateHashUtils.js';
|
46
|
+
import { action, makeObservable, observable } from 'mobx';
|
47
|
+
|
48
|
+
export class QueryBuilderAggregateOperator_Percentile
|
49
|
+
extends QueryBuilderAggregateOperator
|
50
|
+
implements Hashable
|
51
|
+
{
|
52
|
+
percentile: number | undefined;
|
53
|
+
acending: boolean | undefined;
|
54
|
+
continuous: boolean | undefined;
|
55
|
+
|
56
|
+
constructor() {
|
57
|
+
super();
|
58
|
+
makeObservable(this, {
|
59
|
+
percentile: observable,
|
60
|
+
acending: observable,
|
61
|
+
continuous: observable,
|
62
|
+
setPercentile: action,
|
63
|
+
setAcending: action,
|
64
|
+
setContinuous: action,
|
65
|
+
});
|
66
|
+
}
|
67
|
+
|
68
|
+
setPercentile(val: number | undefined) {
|
69
|
+
this.percentile = val;
|
70
|
+
}
|
71
|
+
|
72
|
+
setAcending(val: boolean | undefined) {
|
73
|
+
this.acending = val;
|
74
|
+
}
|
75
|
+
|
76
|
+
setContinuous(val: boolean | undefined) {
|
77
|
+
this.continuous = val;
|
78
|
+
}
|
79
|
+
|
80
|
+
getLabel(projectionColumnState: QueryBuilderProjectionColumnState): string {
|
81
|
+
return 'percentile';
|
82
|
+
}
|
83
|
+
|
84
|
+
isCompatibleWithColumn(
|
85
|
+
projectionColumnState: QueryBuilderProjectionColumnState,
|
86
|
+
): boolean {
|
87
|
+
if (
|
88
|
+
projectionColumnState instanceof QueryBuilderSimpleProjectionColumnState
|
89
|
+
) {
|
90
|
+
const propertyType =
|
91
|
+
projectionColumnState.propertyExpressionState.propertyExpression.func
|
92
|
+
.value.genericType.value.rawType;
|
93
|
+
return (
|
94
|
+
[
|
95
|
+
PRIMITIVE_TYPE.NUMBER,
|
96
|
+
PRIMITIVE_TYPE.INTEGER,
|
97
|
+
PRIMITIVE_TYPE.DECIMAL,
|
98
|
+
PRIMITIVE_TYPE.FLOAT,
|
99
|
+
] as string[]
|
100
|
+
).includes(propertyType.path);
|
101
|
+
}
|
102
|
+
return true;
|
103
|
+
}
|
104
|
+
|
105
|
+
buildAggregateExpression(
|
106
|
+
propertyExpression: AbstractPropertyExpression | undefined,
|
107
|
+
variableName: string,
|
108
|
+
graph: PureModel,
|
109
|
+
): ValueSpecification {
|
110
|
+
const percentileValue = this.percentile ?? 0;
|
111
|
+
const expression = new SimpleFunctionExpression(
|
112
|
+
extractElementNameFromPath(QUERY_BUILDER_SUPPORTED_FUNCTIONS.PERCENTILE),
|
113
|
+
);
|
114
|
+
const percentile = new PrimitiveInstanceValue(
|
115
|
+
GenericTypeExplicitReference.create(
|
116
|
+
new GenericType(PrimitiveType.NUMBER),
|
117
|
+
),
|
118
|
+
);
|
119
|
+
percentile.values = [percentileValue];
|
120
|
+
if (
|
121
|
+
this.acending === undefined ||
|
122
|
+
this.continuous === undefined ||
|
123
|
+
(this.acending && this.continuous)
|
124
|
+
) {
|
125
|
+
expression.parametersValues.push(
|
126
|
+
new VariableExpression(variableName, Multiplicity.ONE),
|
127
|
+
percentile,
|
128
|
+
);
|
129
|
+
} else {
|
130
|
+
const acending = new PrimitiveInstanceValue(
|
131
|
+
GenericTypeExplicitReference.create(
|
132
|
+
new GenericType(PrimitiveType.BOOLEAN),
|
133
|
+
),
|
134
|
+
);
|
135
|
+
acending.values = [this.acending];
|
136
|
+
const continuous = new PrimitiveInstanceValue(
|
137
|
+
GenericTypeExplicitReference.create(
|
138
|
+
new GenericType(PrimitiveType.BOOLEAN),
|
139
|
+
),
|
140
|
+
);
|
141
|
+
continuous.values = [this.continuous];
|
142
|
+
expression.parametersValues.push(
|
143
|
+
new VariableExpression(variableName, Multiplicity.ONE),
|
144
|
+
percentile,
|
145
|
+
acending,
|
146
|
+
continuous,
|
147
|
+
);
|
148
|
+
}
|
149
|
+
return expression;
|
150
|
+
}
|
151
|
+
|
152
|
+
buildAggregateColumnState(
|
153
|
+
expression: SimpleFunctionExpression,
|
154
|
+
lambdaParam: VariableExpression,
|
155
|
+
projectionColumnState: QueryBuilderProjectionColumnState,
|
156
|
+
): QueryBuilderAggregateColumnState | undefined {
|
157
|
+
if (
|
158
|
+
matchFunctionName(
|
159
|
+
expression.functionName,
|
160
|
+
QUERY_BUILDER_SUPPORTED_FUNCTIONS.PERCENTILE,
|
161
|
+
)
|
162
|
+
) {
|
163
|
+
const aggregateColumnState = new QueryBuilderAggregateColumnState(
|
164
|
+
projectionColumnState.tdsState.aggregationState,
|
165
|
+
projectionColumnState,
|
166
|
+
new QueryBuilderAggregateOperator_Percentile(),
|
167
|
+
);
|
168
|
+
|
169
|
+
const currentOperator = guaranteeType(
|
170
|
+
aggregateColumnState.operator,
|
171
|
+
QueryBuilderAggregateOperator_Percentile,
|
172
|
+
);
|
173
|
+
|
174
|
+
aggregateColumnState.setLambdaParameterName(lambdaParam.name);
|
175
|
+
|
176
|
+
assertTrue(
|
177
|
+
[2, 4].includes(expression.parametersValues.length),
|
178
|
+
`Can't process percentile() expression: percentile() expects 2 or 4 argument`,
|
179
|
+
);
|
180
|
+
|
181
|
+
// variable
|
182
|
+
const variableExpression = guaranteeType(
|
183
|
+
expression.parametersValues[0],
|
184
|
+
VariableExpression,
|
185
|
+
`Can't process percentile() expression: only support percentile() immediately following a variable expression`,
|
186
|
+
);
|
187
|
+
assertTrue(
|
188
|
+
aggregateColumnState.lambdaParameterName === variableExpression.name,
|
189
|
+
`Can't process percentile() expression: expects variable used in lambda body '${variableExpression.name}' to match lambda parameter '${aggregateColumnState.lambdaParameterName}'`,
|
190
|
+
);
|
191
|
+
const percentile = guaranteeType(
|
192
|
+
expression.parametersValues[1],
|
193
|
+
PrimitiveInstanceValue,
|
194
|
+
`Can't process percentile() expression: percentile() expects arugment #2 to be a primitive instance value`,
|
195
|
+
);
|
196
|
+
currentOperator.percentile = percentile.values[0] as number;
|
197
|
+
|
198
|
+
if (expression.parametersValues.length === 4) {
|
199
|
+
const acending = guaranteeType(
|
200
|
+
expression.parametersValues[2],
|
201
|
+
PrimitiveInstanceValue,
|
202
|
+
`Can't process percentile() expression: percentile() expects arugment #3 to be a primitive instance value`,
|
203
|
+
);
|
204
|
+
currentOperator.acending = acending.values[0] as boolean;
|
205
|
+
const continuous = guaranteeType(
|
206
|
+
expression.parametersValues[3],
|
207
|
+
PrimitiveInstanceValue,
|
208
|
+
`Can't process percentile() expression: percentile() expects arugment #4 to be a primitive instance value`,
|
209
|
+
);
|
210
|
+
currentOperator.continuous = continuous.values[0] as boolean;
|
211
|
+
}
|
212
|
+
// operator
|
213
|
+
assertTrue(
|
214
|
+
this.isCompatibleWithColumn(aggregateColumnState.projectionColumnState),
|
215
|
+
`Can't process percentile() expression: property is not compatible with operator`,
|
216
|
+
);
|
217
|
+
aggregateColumnState.setOperator(currentOperator);
|
218
|
+
return aggregateColumnState;
|
219
|
+
}
|
220
|
+
|
221
|
+
return undefined;
|
222
|
+
}
|
223
|
+
|
224
|
+
override get getOperator(): QueryBuilderAggregateOperator {
|
225
|
+
return new QueryBuilderAggregateOperator_Percentile();
|
226
|
+
}
|
227
|
+
|
228
|
+
override get allValidationIssues(): string[] {
|
229
|
+
const validationIssues: string[] = [];
|
230
|
+
if (this.percentile === undefined || this.percentile > 100) {
|
231
|
+
validationIssues.push('Invalid Aggregation Argument for Percentile');
|
232
|
+
}
|
233
|
+
return validationIssues;
|
234
|
+
}
|
235
|
+
|
236
|
+
get hashCode(): string {
|
237
|
+
return hashArray([
|
238
|
+
QUERY_BUILDER_STATE_HASH_STRUCTURE.AGGREGATE_OPERATOR_PERCENTILE,
|
239
|
+
]);
|
240
|
+
}
|
241
|
+
}
|
package/tsconfig.json
CHANGED
@@ -128,6 +128,7 @@
|
|
128
128
|
"./src/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperator_JoinString.ts",
|
129
129
|
"./src/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperator_Max.ts",
|
130
130
|
"./src/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperator_Min.ts",
|
131
|
+
"./src/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperator_Percentile.ts",
|
131
132
|
"./src/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperator_StdDev_Population.ts",
|
132
133
|
"./src/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperator_StdDev_Sample.ts",
|
133
134
|
"./src/stores/fetch-structure/tds/aggregation/operators/QueryBuilderAggregateOperator_Sum.ts",
|