@finos/legend-application-query 5.0.2 → 5.1.0

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.
Files changed (81) hide show
  1. package/lib/components/QueryBuilderFetchStructurePanel.d.ts.map +1 -1
  2. package/lib/components/QueryBuilderFetchStructurePanel.js +1 -1
  3. package/lib/components/QueryBuilderFetchStructurePanel.js.map +1 -1
  4. package/lib/components/QueryBuilderFilterPanel.d.ts.map +1 -1
  5. package/lib/components/QueryBuilderFilterPanel.js +17 -4
  6. package/lib/components/QueryBuilderFilterPanel.js.map +1 -1
  7. package/lib/components/QueryBuilderFunctionsExplorerPanel.d.ts.map +1 -1
  8. package/lib/components/QueryBuilderFunctionsExplorerPanel.js.map +1 -1
  9. package/lib/components/QueryBuilderParameterPanel.d.ts.map +1 -1
  10. package/lib/components/QueryBuilderParameterPanel.js +3 -2
  11. package/lib/components/QueryBuilderParameterPanel.js.map +1 -1
  12. package/lib/components/QueryBuilderPostFilterPanel.d.ts.map +1 -1
  13. package/lib/components/QueryBuilderPostFilterPanel.js +17 -4
  14. package/lib/components/QueryBuilderPostFilterPanel.js.map +1 -1
  15. package/lib/components/QueryBuilderProjectionPanel.d.ts.map +1 -1
  16. package/lib/components/QueryBuilderProjectionPanel.js +6 -2
  17. package/lib/components/QueryBuilderProjectionPanel.js.map +1 -1
  18. package/lib/components/QueryBuilderResultPanel.d.ts.map +1 -1
  19. package/lib/components/QueryBuilderResultPanel.js +3 -1
  20. package/lib/components/QueryBuilderResultPanel.js.map +1 -1
  21. package/lib/components/QueryBuilderSetupPanel.d.ts.map +1 -1
  22. package/lib/components/QueryBuilderSetupPanel.js +5 -3
  23. package/lib/components/QueryBuilderSetupPanel.js.map +1 -1
  24. package/lib/index.css +2 -2
  25. package/lib/index.css.map +1 -1
  26. package/lib/package.json +1 -1
  27. package/lib/stores/QueryBuilderFetchStructureState.d.ts +2 -1
  28. package/lib/stores/QueryBuilderFetchStructureState.d.ts.map +1 -1
  29. package/lib/stores/QueryBuilderFetchStructureState.js +2 -2
  30. package/lib/stores/QueryBuilderFetchStructureState.js.map +1 -1
  31. package/lib/stores/QueryBuilderFilterState.d.ts +4 -0
  32. package/lib/stores/QueryBuilderFilterState.d.ts.map +1 -1
  33. package/lib/stores/QueryBuilderFilterState.js +28 -2
  34. package/lib/stores/QueryBuilderFilterState.js.map +1 -1
  35. package/lib/stores/QueryBuilderOperatorLoader.d.ts +47 -0
  36. package/lib/stores/QueryBuilderOperatorLoader.d.ts.map +1 -0
  37. package/lib/stores/QueryBuilderOperatorLoader.js +94 -0
  38. package/lib/stores/QueryBuilderOperatorLoader.js.map +1 -0
  39. package/lib/stores/QueryBuilderPostFilterState.d.ts +5 -2
  40. package/lib/stores/QueryBuilderPostFilterState.d.ts.map +1 -1
  41. package/lib/stores/QueryBuilderPostFilterState.js +25 -1
  42. package/lib/stores/QueryBuilderPostFilterState.js.map +1 -1
  43. package/lib/stores/QueryBuilderPreviewDataHelper.d.ts +4 -3
  44. package/lib/stores/QueryBuilderPreviewDataHelper.d.ts.map +1 -1
  45. package/lib/stores/QueryBuilderPreviewDataHelper.js +77 -97
  46. package/lib/stores/QueryBuilderPreviewDataHelper.js.map +1 -1
  47. package/lib/stores/QueryBuilderProjectionState.d.ts +3 -2
  48. package/lib/stores/QueryBuilderProjectionState.d.ts.map +1 -1
  49. package/lib/stores/QueryBuilderProjectionState.js +17 -32
  50. package/lib/stores/QueryBuilderProjectionState.js.map +1 -1
  51. package/lib/stores/QueryBuilderState.d.ts +1 -0
  52. package/lib/stores/QueryBuilderState.d.ts.map +1 -1
  53. package/lib/stores/QueryBuilderState.js +8 -58
  54. package/lib/stores/QueryBuilderState.js.map +1 -1
  55. package/lib/stores/QueryBuilderTestUtils.d.ts +24 -0
  56. package/lib/stores/QueryBuilderTestUtils.d.ts.map +1 -0
  57. package/lib/stores/QueryBuilderTestUtils.js +49 -0
  58. package/lib/stores/QueryBuilderTestUtils.js.map +1 -0
  59. package/lib/stores/QueryBuilderTypeaheadHelper.d.ts +24 -0
  60. package/lib/stores/QueryBuilderTypeaheadHelper.d.ts.map +1 -0
  61. package/lib/stores/QueryBuilderTypeaheadHelper.js +89 -0
  62. package/lib/stores/QueryBuilderTypeaheadHelper.js.map +1 -0
  63. package/package.json +8 -8
  64. package/src/components/QueryBuilderFetchStructurePanel.tsx +4 -1
  65. package/src/components/QueryBuilderFilterPanel.tsx +31 -4
  66. package/src/components/QueryBuilderFunctionsExplorerPanel.tsx +1 -0
  67. package/src/components/QueryBuilderParameterPanel.tsx +3 -2
  68. package/src/components/QueryBuilderPostFilterPanel.tsx +31 -4
  69. package/src/components/QueryBuilderProjectionPanel.tsx +19 -2
  70. package/src/components/QueryBuilderResultPanel.tsx +6 -0
  71. package/src/components/QueryBuilderSetupPanel.tsx +5 -3
  72. package/src/stores/QueryBuilderFetchStructureState.ts +9 -2
  73. package/src/stores/QueryBuilderFilterState.ts +43 -0
  74. package/src/stores/QueryBuilderOperatorLoader.ts +133 -0
  75. package/src/stores/QueryBuilderPostFilterState.ts +40 -1
  76. package/src/stores/QueryBuilderPreviewDataHelper.ts +122 -217
  77. package/src/stores/QueryBuilderProjectionState.ts +29 -46
  78. package/src/stores/QueryBuilderState.ts +23 -94
  79. package/src/stores/QueryBuilderTestUtils.ts +93 -0
  80. package/src/stores/QueryBuilderTypeaheadHelper.ts +149 -0
  81. package/tsconfig.json +3 -0
@@ -14,27 +14,12 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import {
18
- type AbstractPropertyExpression,
19
- type Class,
20
- type PureModel,
21
- GenericType,
22
- GenericTypeExplicitReference,
23
- PrimitiveInstanceValue,
24
- PRIMITIVE_TYPE,
25
- CollectionInstanceValue,
26
- CORE_PURE_PATH,
27
- extractElementNameFromPath,
28
- FunctionType,
29
- LambdaFunction,
30
- Multiplicity,
31
- SimpleFunctionExpression,
32
- TYPICAL_MULTIPLICITY_TYPE,
17
+ import type {
18
+ RawLambda,
19
+ AbstractPropertyExpression,
33
20
  } from '@finos/legend-graph';
34
- import {
35
- DEFAULT_LAMBDA_VARIABLE_NAME,
36
- QUERY_BUILDER_SUPPORTED_FUNCTIONS,
37
- } from '../QueryBuilder_Const.js';
21
+ import { guaranteeNonNullable } from '@finos/legend-shared';
22
+ import type { QueryBuilderAggregateOperator } from './QueryBuilderAggregationState.js';
38
23
  import { QueryBuilderAggregateOperator_Average } from './aggregateOperators/QueryBuilderAggregateOperator_Average.js';
39
24
  import { QueryBuilderAggregateOperator_Count } from './aggregateOperators/QueryBuilderAggregateOperator_Count.js';
40
25
  import { QueryBuilderAggregateOperator_DistinctCount } from './aggregateOperators/QueryBuilderAggregateOperator_DistinctCount.js';
@@ -43,109 +28,82 @@ import { QueryBuilderAggregateOperator_Min } from './aggregateOperators/QueryBui
43
28
  import { QueryBuilderAggregateOperator_StdDev_Population } from './aggregateOperators/QueryBuilderAggregateOperator_StdDev_Population.js';
44
29
  import { QueryBuilderAggregateOperator_StdDev_Sample } from './aggregateOperators/QueryBuilderAggregateOperator_StdDev_Sample.js';
45
30
  import { QueryBuilderAggregateOperator_Sum } from './aggregateOperators/QueryBuilderAggregateOperator_Sum.js';
46
- import type { QueryBuilderAggregateOperator } from './QueryBuilderAggregationState.js';
47
- import { buildGetAllFunction } from './QueryBuilderLambdaBuilder.js';
48
- import { buildGenericLambdaFunctionInstanceValue } from './QueryBuilderValueSpecificationBuilderHelper.js';
31
+ import { QueryBuilderSimpleProjectionColumnState } from './QueryBuilderProjectionState.js';
32
+ import type { QueryBuilderState } from './QueryBuilderState.js';
33
+ import {
34
+ COLUMN_SORT_TYPE,
35
+ SortColumnState,
36
+ } from './QueryResultSetModifierState.js';
49
37
 
50
- const buildGroupByFunction = (
51
- getAllFunction: SimpleFunctionExpression,
52
- propertyExpression: AbstractPropertyExpression,
53
- aggregates: [QueryBuilderAggregateOperator, string][],
54
- includePropertyValue: boolean,
55
- graph: PureModel,
56
- ): SimpleFunctionExpression => {
57
- const multiplicityOne = graph.getTypicalMultiplicity(
58
- TYPICAL_MULTIPLICITY_TYPE.ONE,
59
- );
60
- const typeAny = graph.getType(CORE_PURE_PATH.ANY);
61
- const typeString = graph.getPrimitiveType(PRIMITIVE_TYPE.STRING);
62
- const lambdaFunction = new LambdaFunction(
63
- new FunctionType(typeAny, multiplicityOne),
64
- );
38
+ const PREVIEW_DATA_TAKE_LIMIT = 10;
39
+ const PREVIEW_DATA_NON_NUMERIC_VALUE_COLUMN_NAME = 'Value';
40
+ const PREVIEW_DATA_NON_NUMERIC_COUNT_COLUMN_NAME = 'Count';
65
41
 
66
- const groupByFunction = new SimpleFunctionExpression(
67
- extractElementNameFromPath(QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_GROUP_BY),
68
- multiplicityOne,
69
- );
42
+ enum NUMERIC_AGG_FUNC {
43
+ COUNT = 'Count',
44
+ DISTINCT_COUNT = 'Distinct Count',
45
+ SUM = 'Sum',
46
+ MIN = 'Min',
47
+ MAX = 'Max',
48
+ AVERAGE = 'Average',
49
+ STD_DEV_POPULATION = 'Std Dev (Population)',
50
+ STD_DEV_SAMPLE = 'Std Dev (Sample)',
51
+ }
70
52
 
71
- const colLambdas = new CollectionInstanceValue(
72
- graph.getTypicalMultiplicity(
73
- includePropertyValue
74
- ? TYPICAL_MULTIPLICITY_TYPE.ONE
75
- : TYPICAL_MULTIPLICITY_TYPE.ZERO,
76
- ),
77
- );
78
- const aggregateLambdas = new CollectionInstanceValue(
79
- new Multiplicity(aggregates.length, aggregates.length),
80
- );
81
- const noOfCols = aggregates.length + (includePropertyValue ? 1 : 0);
82
- const colAliases = new CollectionInstanceValue(
83
- new Multiplicity(noOfCols, noOfCols),
84
- );
53
+ const NUMERIC_AGG_FUNC_TO_AGG_OP: [
54
+ NUMERIC_AGG_FUNC,
55
+ typeof QueryBuilderAggregateOperator,
56
+ ][] = [
57
+ [NUMERIC_AGG_FUNC.COUNT, QueryBuilderAggregateOperator_Count],
58
+ [
59
+ NUMERIC_AGG_FUNC.DISTINCT_COUNT,
60
+ QueryBuilderAggregateOperator_DistinctCount,
61
+ ],
62
+ [NUMERIC_AGG_FUNC.SUM, QueryBuilderAggregateOperator_Sum],
63
+ [NUMERIC_AGG_FUNC.MIN, QueryBuilderAggregateOperator_Min],
64
+ [NUMERIC_AGG_FUNC.MAX, QueryBuilderAggregateOperator_Max],
65
+ [NUMERIC_AGG_FUNC.AVERAGE, QueryBuilderAggregateOperator_Average],
66
+ [
67
+ NUMERIC_AGG_FUNC.STD_DEV_POPULATION,
68
+ QueryBuilderAggregateOperator_StdDev_Population,
69
+ ],
70
+ [
71
+ NUMERIC_AGG_FUNC.STD_DEV_SAMPLE,
72
+ QueryBuilderAggregateOperator_StdDev_Sample,
73
+ ],
74
+ ];
85
75
 
86
- if (includePropertyValue) {
87
- colLambdas.values.push(
88
- buildGenericLambdaFunctionInstanceValue(
89
- DEFAULT_LAMBDA_VARIABLE_NAME,
90
- [propertyExpression],
91
- graph,
92
- ),
93
- );
94
- const valueColAlias = new PrimitiveInstanceValue(
95
- GenericTypeExplicitReference.create(new GenericType(typeString)),
96
- multiplicityOne,
97
- );
98
- valueColAlias.values.push('Value');
99
- colAliases.values.push(valueColAlias);
100
- }
76
+ const createProjectionColumn = (
77
+ queryBuilderState: QueryBuilderState,
78
+ propertyExpression: AbstractPropertyExpression,
79
+ columnName: string,
80
+ ): QueryBuilderSimpleProjectionColumnState => {
81
+ const col = new QueryBuilderSimpleProjectionColumnState(
82
+ queryBuilderState.fetchStructureState.projectionState,
83
+ propertyExpression,
84
+ false,
85
+ );
86
+ col.setColumnName(columnName);
87
+ return col;
88
+ };
101
89
 
102
- aggregates.forEach((pair) => {
103
- const aggregateFunctionExpression = new SimpleFunctionExpression(
104
- extractElementNameFromPath(QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_AGG),
105
- multiplicityOne,
106
- );
107
- aggregateFunctionExpression.parametersValues = [
108
- buildGenericLambdaFunctionInstanceValue(
109
- DEFAULT_LAMBDA_VARIABLE_NAME,
110
- [propertyExpression],
111
- graph,
112
- ),
113
- buildGenericLambdaFunctionInstanceValue(
114
- DEFAULT_LAMBDA_VARIABLE_NAME,
115
- [
116
- pair[0].buildAggregateExpression(
117
- propertyExpression,
118
- DEFAULT_LAMBDA_VARIABLE_NAME,
119
- graph,
120
- ),
121
- ],
122
- graph,
123
- ),
124
- ];
125
- aggregateLambdas.values.push(aggregateFunctionExpression);
90
+ const createQueryBuilderState = (
91
+ queryBuilderState: QueryBuilderState,
92
+ ): QueryBuilderState => {
93
+ const builderState = queryBuilderState.createBareBuilderState();
94
+ builderState.querySetupState = queryBuilderState.querySetupState;
95
+ return builderState;
96
+ };
126
97
 
127
- const colAlias = new PrimitiveInstanceValue(
128
- GenericTypeExplicitReference.create(new GenericType(typeString)),
129
- multiplicityOne,
130
- );
131
- colAlias.values.push(pair[1]);
132
- colAliases.values.push(colAlias);
133
- });
134
- groupByFunction.parametersValues = [
135
- getAllFunction,
136
- colLambdas,
137
- aggregateLambdas,
138
- colAliases,
139
- ];
140
- lambdaFunction.expressionSequence[0] = groupByFunction;
141
- return groupByFunction;
98
+ export type QueryBuilderPreviewData = {
99
+ columns: string[];
100
+ rows: { values: (string | number)[] }[];
142
101
  };
143
102
 
144
103
  export const buildNumericPreviewDataQuery = (
104
+ queryBuilderState: QueryBuilderState,
145
105
  propertyExpression: AbstractPropertyExpression,
146
- _class: Class,
147
- graph: PureModel,
148
- ): LambdaFunction => {
106
+ ): RawLambda => {
149
107
  // Build the following query
150
108
  //
151
109
  // ClassX.all()->groupBy(
@@ -171,44 +129,29 @@ export const buildNumericPreviewDataQuery = (
171
129
  // 'Std Dev (Sample)'
172
130
  // ]
173
131
  // )
174
- const multiplicityOne = graph.getTypicalMultiplicity(
175
- TYPICAL_MULTIPLICITY_TYPE.ONE,
176
- );
177
- const typeAny = graph.getType(CORE_PURE_PATH.ANY);
178
- const lambdaFunction = new LambdaFunction(
179
- new FunctionType(typeAny, multiplicityOne),
180
- );
181
- const groupByFunction = buildGroupByFunction(
182
- buildGetAllFunction(_class, multiplicityOne),
183
- propertyExpression,
184
- [
185
- [new QueryBuilderAggregateOperator_Count(), 'Count'],
186
- [new QueryBuilderAggregateOperator_DistinctCount(), 'Distinct Count'],
187
- [new QueryBuilderAggregateOperator_Sum(), 'Sum'],
188
- [new QueryBuilderAggregateOperator_Min(), 'Min'],
189
- [new QueryBuilderAggregateOperator_Max(), 'Max'],
190
- [new QueryBuilderAggregateOperator_Average(), 'Average'],
191
- [
192
- new QueryBuilderAggregateOperator_StdDev_Population(),
193
- 'Standard Deviation (Population)',
194
- ],
195
- [
196
- new QueryBuilderAggregateOperator_StdDev_Sample(),
197
- 'Standard Deviation (Sample)',
198
- ],
199
- ] as [QueryBuilderAggregateOperator, string][],
200
- false,
201
- graph,
202
- );
203
- lambdaFunction.expressionSequence[0] = groupByFunction;
204
- return lambdaFunction;
132
+ const builderState = createQueryBuilderState(queryBuilderState);
133
+ const projectionState = builderState.fetchStructureState.projectionState;
134
+ const aggregationState = projectionState.aggregationState;
135
+ NUMERIC_AGG_FUNC_TO_AGG_OP.forEach((val) => {
136
+ const colState = createProjectionColumn(
137
+ builderState,
138
+ propertyExpression,
139
+ val[0],
140
+ );
141
+ projectionState.columns.push(colState);
142
+ const valAggOp = guaranteeNonNullable(
143
+ aggregationState.operators.find((t) => t instanceof val[1]),
144
+ );
145
+ aggregationState.changeColumnAggregateOperator(valAggOp, colState);
146
+ });
147
+
148
+ return builderState.resultState.buildExecutionRawLambda();
205
149
  };
206
150
 
207
151
  export const buildNonNumericPreviewDataQuery = (
152
+ queryBuilderState: QueryBuilderState,
208
153
  propertyExpression: AbstractPropertyExpression,
209
- _class: Class,
210
- graph: PureModel,
211
- ): LambdaFunction => {
154
+ ): RawLambda => {
212
155
  // Build the following query
213
156
  //
214
157
  // ClassX.all()->groupBy(
@@ -216,85 +159,47 @@ export const buildNonNumericPreviewDataQuery = (
216
159
  // x|$x.prop
217
160
  // ],
218
161
  // [
219
- // agg(x|$x.prop, x|$x->distinct()->count())
162
+ // agg(x|$x.prop, x|$x->count())
220
163
  // ],
221
164
  // [
222
165
  // 'Value',
223
166
  // 'Count'
224
167
  // ]
225
- // )->take(10)->sort([desc('Count'), asc('Value')])
226
- const multiplicityOne = graph.getTypicalMultiplicity(
227
- TYPICAL_MULTIPLICITY_TYPE.ONE,
228
- );
229
- const typeAny = graph.getType(CORE_PURE_PATH.ANY);
230
- const lambdaFunction = new LambdaFunction(
231
- new FunctionType(typeAny, multiplicityOne),
232
- );
233
-
234
- // build groupBy()
235
- const groupByFunction = buildGroupByFunction(
236
- buildGetAllFunction(_class, multiplicityOne),
168
+ // )->sort([desc('Count'), asc('Value')])->take(10)
169
+ const builderState = createQueryBuilderState(queryBuilderState);
170
+ const valueProjectionColState = createProjectionColumn(
171
+ builderState,
237
172
  propertyExpression,
238
- [[new QueryBuilderAggregateOperator_Count(), 'Count']] as [
239
- QueryBuilderAggregateOperator,
240
- string,
241
- ][],
242
- true,
243
- graph,
173
+ PREVIEW_DATA_NON_NUMERIC_VALUE_COLUMN_NAME,
244
174
  );
245
- lambdaFunction.expressionSequence[0] = groupByFunction;
246
-
247
- // build sort()
248
- const sortFunction = new SimpleFunctionExpression(
249
- extractElementNameFromPath(QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_SORT),
250
- multiplicityOne,
251
- );
252
- const sortColumnFunctions = new CollectionInstanceValue(
253
- new Multiplicity(2, 2),
254
- undefined,
175
+ const valueCountProjectionState = createProjectionColumn(
176
+ builderState,
177
+ propertyExpression,
178
+ PREVIEW_DATA_NON_NUMERIC_COUNT_COLUMN_NAME,
255
179
  );
256
- sortColumnFunctions.values = [
257
- [QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_DESC, 'Count'],
258
- [QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_ASC, 'Value'],
259
- ].map((pair) => {
260
- const sortColumnFunction = new SimpleFunctionExpression(
261
- extractElementNameFromPath(pair[0] as string),
262
- multiplicityOne,
263
- );
264
- const sortColumnName = new PrimitiveInstanceValue(
265
- GenericTypeExplicitReference.create(
266
- new GenericType(graph.getPrimitiveType(PRIMITIVE_TYPE.STRING)),
267
- ),
268
- multiplicityOne,
269
- );
270
- sortColumnName.values = [pair[1]];
271
- sortColumnFunction.parametersValues[0] = sortColumnName;
272
- return sortColumnFunction;
273
- });
274
- sortFunction.parametersValues[0] = groupByFunction;
275
- sortFunction.parametersValues[1] = sortColumnFunctions;
276
-
277
- // build take()
278
- const limit = new PrimitiveInstanceValue(
279
- GenericTypeExplicitReference.create(
280
- new GenericType(graph.getPrimitiveType(PRIMITIVE_TYPE.INTEGER)),
180
+ builderState.fetchStructureState.projectionState.columns = [
181
+ valueProjectionColState,
182
+ valueCountProjectionState,
183
+ ];
184
+ const distinctCountOp = guaranteeNonNullable(
185
+ builderState.fetchStructureState.projectionState.aggregationState.operators.find(
186
+ (t) => t instanceof QueryBuilderAggregateOperator_Count,
281
187
  ),
282
- multiplicityOne,
283
188
  );
284
- limit.values = [10];
285
- const takeFunction = new SimpleFunctionExpression(
286
- extractElementNameFromPath(QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_TAKE),
287
- multiplicityOne,
189
+ builderState.fetchStructureState.projectionState.aggregationState.changeColumnAggregateOperator(
190
+ distinctCountOp,
191
+ valueCountProjectionState,
288
192
  );
289
- takeFunction.parametersValues[0] = sortFunction;
290
- takeFunction.parametersValues[1] = limit;
291
-
292
- lambdaFunction.expressionSequence[0] = takeFunction;
293
-
294
- return lambdaFunction;
295
- };
296
-
297
- export type QueryBuilderPreviewData = {
298
- columns: string[];
299
- rows: { values: (string | number)[] }[];
193
+ // result set
194
+ builderState.resultSetModifierState.limit = PREVIEW_DATA_TAKE_LIMIT;
195
+ const sortValueCount = new SortColumnState(
196
+ builderState,
197
+ valueCountProjectionState,
198
+ );
199
+ sortValueCount.sortType = COLUMN_SORT_TYPE.DESC;
200
+ builderState.resultSetModifierState.sortColumns = [
201
+ sortValueCount,
202
+ new SortColumnState(builderState, valueProjectionColState),
203
+ ];
204
+ return builderState.resultState.buildExecutionRawLambda();
300
205
  };
@@ -68,30 +68,22 @@ import {
68
68
  RawLambda,
69
69
  stub_RawLambda,
70
70
  isStubbed_RawLambda,
71
- buildRawLambdaFromLambdaFunction,
72
71
  } from '@finos/legend-graph';
73
72
  import {
74
73
  DEFAULT_LAMBDA_VARIABLE_NAME,
75
74
  QUERY_BUILDER_SOURCE_ID_LABEL,
76
75
  } from '../QueryBuilder_Const.js';
77
- import { QueryBuilderAggregationState } from './QueryBuilderAggregationState.js';
78
- import { QueryBuilderAggregateOperator_Count } from './aggregateOperators/QueryBuilderAggregateOperator_Count.js';
79
- import { QueryBuilderAggregateOperator_Distinct } from './aggregateOperators/QueryBuilderAggregateOperator_Distinct.js';
80
- import { QueryBuilderAggregateOperator_Sum } from './aggregateOperators/QueryBuilderAggregateOperator_Sum.js';
81
- import { QueryBuilderAggregateOperator_Average } from './aggregateOperators/QueryBuilderAggregateOperator_Average.js';
82
- import { QueryBuilderAggregateOperator_StdDev_Population } from './aggregateOperators/QueryBuilderAggregateOperator_StdDev_Population.js';
83
- import { QueryBuilderAggregateOperator_StdDev_Sample } from './aggregateOperators/QueryBuilderAggregateOperator_StdDev_Sample.js';
84
- import { QueryBuilderAggregateOperator_DistinctCount } from './aggregateOperators/QueryBuilderAggregateOperator_DistinctCount.js';
85
- import { QueryBuilderAggregateOperator_Min } from './aggregateOperators/QueryBuilderAggregateOperator_Min.js';
86
- import { QueryBuilderAggregateOperator_Max } from './aggregateOperators/QueryBuilderAggregateOperator_Max.js';
87
- import { QueryBuilderAggregateOperator_JoinString } from './aggregateOperators/QueryBuilderAggregateOperator_JoinString.js';
76
+ import {
77
+ type QueryBuilderAggregateOperator,
78
+ QueryBuilderAggregationState,
79
+ } from './QueryBuilderAggregationState.js';
80
+ import { buildGenericLambdaFunctionInstanceValue } from './QueryBuilderValueSpecificationBuilderHelper.js';
81
+ import { LambdaEditorState } from '@finos/legend-application';
88
82
  import {
89
83
  type QueryBuilderPreviewData,
90
- buildNonNumericPreviewDataQuery,
91
84
  buildNumericPreviewDataQuery,
85
+ buildNonNumericPreviewDataQuery,
92
86
  } from './QueryBuilderPreviewDataHelper.js';
93
- import { buildGenericLambdaFunctionInstanceValue } from './QueryBuilderValueSpecificationBuilderHelper.js';
94
- import { LambdaEditorState } from '@finos/legend-application';
95
87
 
96
88
  export enum QUERY_BUILDER_PROJECTION_DND_TYPE {
97
89
  PROJECTION_COLUMN = 'PROJECTION_COLUMN',
@@ -380,7 +372,10 @@ export class QueryBuilderProjectionState {
380
372
  aggregationState: QueryBuilderAggregationState;
381
373
  isConvertDerivationProjectionObjects = false;
382
374
 
383
- constructor(queryBuilderState: QueryBuilderState) {
375
+ constructor(
376
+ queryBuilderState: QueryBuilderState,
377
+ operators: QueryBuilderAggregateOperator[],
378
+ ) {
384
379
  makeAutoObservable(this, {
385
380
  queryBuilderState: false,
386
381
  removeColumn: action,
@@ -390,18 +385,7 @@ export class QueryBuilderProjectionState {
390
385
  });
391
386
 
392
387
  this.queryBuilderState = queryBuilderState;
393
- this.aggregationState = new QueryBuilderAggregationState(this, [
394
- new QueryBuilderAggregateOperator_Count(),
395
- new QueryBuilderAggregateOperator_DistinctCount(),
396
- new QueryBuilderAggregateOperator_Distinct(),
397
- new QueryBuilderAggregateOperator_Sum(),
398
- new QueryBuilderAggregateOperator_Average(),
399
- new QueryBuilderAggregateOperator_Min(),
400
- new QueryBuilderAggregateOperator_Max(),
401
- new QueryBuilderAggregateOperator_StdDev_Population(),
402
- new QueryBuilderAggregateOperator_StdDev_Sample(),
403
- new QueryBuilderAggregateOperator_JoinString(),
404
- ]);
388
+ this.aggregationState = new QueryBuilderAggregationState(this, operators);
405
389
  }
406
390
 
407
391
  *convertDerivationProjectionObjects(): GeneratorFn<void> {
@@ -709,13 +693,9 @@ export class QueryBuilderProjectionState {
709
693
  case PRIMITIVE_TYPE.FLOAT: {
710
694
  const previewResult =
711
695
  (yield this.queryBuilderState.graphManagerState.graphManager.executeMapping(
712
- buildRawLambdaFromLambdaFunction(
713
- buildNumericPreviewDataQuery(
714
- propertyExpression,
715
- this.queryBuilderState.querySetupState._class,
716
- this.queryBuilderState.graphManagerState.graph,
717
- ),
718
- this.queryBuilderState.graphManagerState,
696
+ buildNumericPreviewDataQuery(
697
+ this.queryBuilderState,
698
+ propertyExpression,
719
699
  ),
720
700
  this.queryBuilderState.querySetupState.mapping,
721
701
  runtime,
@@ -752,13 +732,9 @@ export class QueryBuilderProjectionState {
752
732
  case PRIMITIVE_TYPE.DATETIME: {
753
733
  const previewResult =
754
734
  (yield this.queryBuilderState.graphManagerState.graphManager.executeMapping(
755
- buildRawLambdaFromLambdaFunction(
756
- buildNonNumericPreviewDataQuery(
757
- propertyExpression,
758
- this.queryBuilderState.querySetupState._class,
759
- this.queryBuilderState.graphManagerState.graph,
760
- ),
761
- this.queryBuilderState.graphManagerState,
735
+ buildNonNumericPreviewDataQuery(
736
+ this.queryBuilderState,
737
+ propertyExpression,
762
738
  ),
763
739
  this.queryBuilderState.querySetupState.mapping,
764
740
  runtime,
@@ -795,17 +771,24 @@ export class QueryBuilderProjectionState {
795
771
  }
796
772
 
797
773
  isValidProjectionState(): boolean {
774
+ return Boolean(!this.getValidationErrorMessage());
775
+ }
776
+
777
+ getValidationErrorMessage(): string | undefined {
798
778
  if (this.queryBuilderState.fetchStructureState.isProjectionMode()) {
799
- // duplicate columns check
800
779
  const hasDuplicatedProjectionColumns = this.columns.some(
801
780
  (column) =>
802
781
  this.columns.filter((c) => c.columnName === column.columnName)
803
782
  .length > 1,
804
783
  );
805
- // no columns check
784
+ if (hasDuplicatedProjectionColumns) {
785
+ return 'Query has duplicated projection columns';
786
+ }
806
787
  const hasNoProjectionColumns = this.columns.length === 0;
807
- return !hasDuplicatedProjectionColumns && !hasNoProjectionColumns;
788
+ if (hasNoProjectionColumns) {
789
+ return 'Query has no projection columns';
790
+ }
808
791
  }
809
- return true;
792
+ return undefined;
810
793
  }
811
794
  }