@finos/legend-query-builder 4.18.7 → 4.18.9

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 (41) hide show
  1. package/lib/components/result/tds/QueryBuilderTDSGridShared.d.ts.map +1 -1
  2. package/lib/components/result/tds/QueryBuilderTDSGridShared.js +40 -0
  3. package/lib/components/result/tds/QueryBuilderTDSGridShared.js.map +1 -1
  4. package/lib/data-access-overview.css +1 -1
  5. package/lib/graph/QueryBuilderMetaModelConst.d.ts +1 -0
  6. package/lib/graph/QueryBuilderMetaModelConst.d.ts.map +1 -1
  7. package/lib/graph/QueryBuilderMetaModelConst.js +1 -0
  8. package/lib/graph/QueryBuilderMetaModelConst.js.map +1 -1
  9. package/lib/index.css +1 -1
  10. package/lib/package.json +1 -1
  11. package/lib/stores/QueryBuilderStateBuilder.d.ts.map +1 -1
  12. package/lib/stores/QueryBuilderStateBuilder.js +5 -1
  13. package/lib/stores/QueryBuilderStateBuilder.js.map +1 -1
  14. package/lib/stores/__test-utils__/TEST_DATA__QueryBuilder_Accessors.d.ts +45 -0
  15. package/lib/stores/__test-utils__/TEST_DATA__QueryBuilder_Accessors.d.ts.map +1 -1
  16. package/lib/stores/__test-utils__/TEST_DATA__QueryBuilder_Accessors.js +73 -0
  17. package/lib/stores/__test-utils__/TEST_DATA__QueryBuilder_Accessors.js.map +1 -1
  18. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.d.ts +29 -2
  19. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.d.ts.map +1 -1
  20. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.js +43 -5
  21. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.js.map +1 -1
  22. package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionStateBuilder.d.ts +6 -0
  23. package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionStateBuilder.d.ts.map +1 -1
  24. package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionStateBuilder.js +45 -3
  25. package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionStateBuilder.js.map +1 -1
  26. package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.d.ts +1 -1
  27. package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.d.ts.map +1 -1
  28. package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.js +103 -58
  29. package/lib/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.js.map +1 -1
  30. package/lib/stores/workflows/dataProduct/DataProductQueryBuilderState.d.ts.map +1 -1
  31. package/lib/stores/workflows/dataProduct/DataProductQueryBuilderState.js +13 -10
  32. package/lib/stores/workflows/dataProduct/DataProductQueryBuilderState.js.map +1 -1
  33. package/package.json +10 -10
  34. package/src/components/result/tds/QueryBuilderTDSGridShared.ts +57 -1
  35. package/src/graph/QueryBuilderMetaModelConst.ts +1 -0
  36. package/src/stores/QueryBuilderStateBuilder.ts +13 -0
  37. package/src/stores/__test-utils__/TEST_DATA__QueryBuilder_Accessors.ts +74 -0
  38. package/src/stores/fetch-structure/tds/QueryBuilderTDSState.ts +47 -5
  39. package/src/stores/fetch-structure/tds/projection/QueryBuilderProjectionStateBuilder.ts +99 -2
  40. package/src/stores/fetch-structure/tds/projection/QueryBuilderProjectionValueSpecificationBuilder.ts +208 -106
  41. package/src/stores/workflows/dataProduct/DataProductQueryBuilderState.ts +28 -27
@@ -18,9 +18,13 @@ import {
18
18
  type LambdaFunction,
19
19
  type ValueSpecification,
20
20
  CollectionInstanceValue,
21
+ ColSpec,
22
+ ColSpecArray,
23
+ ColSpecArrayInstance,
21
24
  extractElementNameFromPath,
22
25
  GenericType,
23
26
  GenericTypeExplicitReference,
27
+ Multiplicity,
24
28
  PrimitiveInstanceValue,
25
29
  SimpleFunctionExpression,
26
30
  INTERNAL__UnknownValueSpecification,
@@ -40,7 +44,10 @@ import {
40
44
  QueryBuilderDerivationProjectionColumnState,
41
45
  QueryBuilderSimpleProjectionColumnState,
42
46
  } from './QueryBuilderProjectionColumnState.js';
43
- import type { QueryBuilderTDSState } from '../QueryBuilderTDSState.js';
47
+ import {
48
+ type QueryBuilderTDSState,
49
+ TDS_PROJECTION_MODE,
50
+ } from '../QueryBuilderTDSState.js';
44
51
  import { QUERY_BUILDER_SUPPORTED_FUNCTIONS } from '../../../../graph/QueryBuilderMetaModelConst.js';
45
52
  import { buildGenericLambdaFunctionInstanceValue } from '../../../QueryBuilderValueSpecificationHelper.js';
46
53
  import {
@@ -110,6 +117,161 @@ const buildProjectColFunc = (
110
117
  return colFunc;
111
118
  };
112
119
 
120
+ const buildProjectionColumnLambda = (
121
+ tdsState: QueryBuilderTDSState,
122
+ projectionColumnState: QueryBuilderProjectionColumnState,
123
+ options?: LambdaFunctionBuilderOption,
124
+ ): ValueSpecification => {
125
+ if (
126
+ projectionColumnState instanceof QueryBuilderSimpleProjectionColumnState
127
+ ) {
128
+ return buildGenericLambdaFunctionInstanceValue(
129
+ [projectionColumnState.lambdaParameterName],
130
+ [
131
+ buildPropertyExpressionChain(
132
+ projectionColumnState.propertyExpressionState.propertyExpression,
133
+ projectionColumnState.propertyExpressionState.queryBuilderState,
134
+ projectionColumnState.lambdaParameterName,
135
+ options,
136
+ ),
137
+ ],
138
+ tdsState.queryBuilderState.graphManagerState.graph,
139
+ );
140
+ }
141
+ if (
142
+ projectionColumnState instanceof QueryBuilderDerivationProjectionColumnState
143
+ ) {
144
+ return new INTERNAL__UnknownValueSpecification(
145
+ V1_serializeRawValueSpecification(
146
+ V1_transformRawLambda(
147
+ projectionColumnState.lambda,
148
+ new V1_GraphTransformerContextBuilder(
149
+ // TODO?: do we need to include the plugins here?
150
+ [],
151
+ )
152
+ .withKeepSourceInformationFlag(
153
+ Boolean(options?.keepSourceInformation),
154
+ )
155
+ .build(),
156
+ ),
157
+ ),
158
+ );
159
+ }
160
+ throw new UnsupportedOperationError(
161
+ `Can't build project() column expression: unsupported projection column state`,
162
+ projectionColumnState,
163
+ );
164
+ };
165
+
166
+ /**
167
+ * Standard form: `precedingExpr->project([x|..., x|...], ['a','b'])`
168
+ */
169
+ const buildProjectExpression = (
170
+ tdsState: QueryBuilderTDSState,
171
+ precedingExpression: ValueSpecification,
172
+ options?: LambdaFunctionBuilderOption,
173
+ ): SimpleFunctionExpression => {
174
+ const queryBuilderState = tdsState.queryBuilderState;
175
+ const projectFunction = new SimpleFunctionExpression(
176
+ extractElementNameFromPath(QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_PROJECT),
177
+ );
178
+ const colLambdas = new CollectionInstanceValue(
179
+ queryBuilderState.graphManagerState.graph.getMultiplicity(
180
+ tdsState.projectionColumns.length,
181
+ tdsState.projectionColumns.length,
182
+ ),
183
+ );
184
+ const colAliases = new CollectionInstanceValue(
185
+ queryBuilderState.graphManagerState.graph.getMultiplicity(
186
+ tdsState.projectionColumns.length,
187
+ tdsState.projectionColumns.length,
188
+ ),
189
+ );
190
+ tdsState.projectionColumns.forEach((projectionColumnState) => {
191
+ const colAlias = new PrimitiveInstanceValue(
192
+ GenericTypeExplicitReference.create(
193
+ new GenericType(PrimitiveType.STRING),
194
+ ),
195
+ );
196
+ colAlias.values.push(projectionColumnState.columnName);
197
+ colAliases.values.push(colAlias);
198
+ colLambdas.values.push(
199
+ buildProjectionColumnLambda(tdsState, projectionColumnState, options),
200
+ );
201
+ });
202
+ projectFunction.parametersValues = [
203
+ precedingExpression,
204
+ colLambdas,
205
+ colAliases,
206
+ ];
207
+ return projectFunction;
208
+ };
209
+
210
+ /**
211
+ * Col-func form: `precedingExpr->project([col(x|..., 'a'), col(x|..., 'b')])`
212
+ */
213
+ const buildProjectColExpression = (
214
+ tdsState: QueryBuilderTDSState,
215
+ precedingExpression: ValueSpecification,
216
+ options?: LambdaFunctionBuilderOption,
217
+ ): SimpleFunctionExpression => {
218
+ const queryBuilderState = tdsState.queryBuilderState;
219
+ const projectFunction = new SimpleFunctionExpression(
220
+ extractElementNameFromPath(QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_PROJECT),
221
+ );
222
+ const colFuncCollection = new CollectionInstanceValue(
223
+ queryBuilderState.graphManagerState.graph.getMultiplicity(
224
+ tdsState.projectionColumns.length,
225
+ tdsState.projectionColumns.length,
226
+ ),
227
+ );
228
+ tdsState.projectionColumns.forEach((projectionColumnState) => {
229
+ colFuncCollection.values.push(
230
+ buildProjectColFunc(tdsState, projectionColumnState, options),
231
+ );
232
+ });
233
+ projectFunction.parametersValues = [precedingExpression, colFuncCollection];
234
+ return projectFunction;
235
+ };
236
+
237
+ /**
238
+ * Relation-style column selection: `precedingExpr->select(~[a, b])`.
239
+ *
240
+ * Only valid when every projection column is a simple reference to an
241
+ * existing relation column (no derivations / no property chains).
242
+ */
243
+ const buildSelectExpression = (
244
+ tdsState: QueryBuilderTDSState,
245
+ precedingExpression: ValueSpecification,
246
+ ): SimpleFunctionExpression => {
247
+ const selectFunction = new SimpleFunctionExpression(
248
+ extractElementNameFromPath(
249
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.RELATION_SELECT,
250
+ ),
251
+ );
252
+ const colSpecArrayInstance = new ColSpecArrayInstance(
253
+ Multiplicity.ONE,
254
+ undefined,
255
+ );
256
+ const colSpecArray = new ColSpecArray();
257
+ colSpecArrayInstance.values = [colSpecArray];
258
+ tdsState.projectionColumns.forEach((projectionColumnState) => {
259
+ if (
260
+ projectionColumnState instanceof
261
+ QueryBuilderDerivationProjectionColumnState
262
+ ) {
263
+ throw new UnsupportedOperationError(
264
+ `Can't build select(~[...]) expression: derivation column '${projectionColumnState.columnName}' is not supported in SELECT mode`,
265
+ );
266
+ }
267
+ const colSpec = new ColSpec();
268
+ colSpec.name = projectionColumnState.columnName;
269
+ colSpecArray.colSpecs.push(colSpec);
270
+ });
271
+ selectFunction.parametersValues = [precedingExpression, colSpecArrayInstance];
272
+ return selectFunction;
273
+ };
274
+
113
275
  export const appendProjection = (
114
276
  tdsState: QueryBuilderTDSState,
115
277
  lambdaFunction: LambdaFunction,
@@ -297,117 +459,57 @@ export const appendProjection = (
297
459
  ];
298
460
  lambdaFunction.expressionSequence[0] = groupByFunction;
299
461
  } else if (tdsState.projectionColumns.length) {
300
- if (!queryBuilderState.useRelation) {
301
- // projection
302
- const projectFunction = new SimpleFunctionExpression(
303
- extractElementNameFromPath(
304
- QUERY_BUILDER_SUPPORTED_FUNCTIONS.TDS_PROJECT,
305
- ),
306
- );
307
- if (tdsState.useColFunc) {
308
- const colFuncCollection = new CollectionInstanceValue(
309
- queryBuilderState.graphManagerState.graph.getMultiplicity(
310
- tdsState.projectionColumns.length,
311
- tdsState.projectionColumns.length,
312
- ),
313
- );
314
- tdsState.projectionColumns.forEach((projectionColumnState) => {
315
- colFuncCollection.values.push(
316
- buildProjectColFunc(tdsState, projectionColumnState, options),
462
+ switch (tdsState.resolveProjectionMode) {
463
+ case TDS_PROJECTION_MODE.PROJECT: {
464
+ if (queryBuilderState.useRelation) {
465
+ const projectFunction = buildRelationProjection(
466
+ precedingExpression,
467
+ tdsState,
468
+ options,
317
469
  );
318
- });
319
- projectFunction.parametersValues = [
470
+ const aggregationFunction = tdsState.aggregationState.columns.length
471
+ ? buildRelationAggregation(projectFunction, tdsState)
472
+ : null;
473
+ lambdaFunction.expressionSequence[0] =
474
+ aggregationFunction ?? projectFunction;
475
+ } else {
476
+ lambdaFunction.expressionSequence[0] = buildProjectExpression(
477
+ tdsState,
478
+ precedingExpression,
479
+ options,
480
+ );
481
+ }
482
+ break;
483
+ }
484
+ case TDS_PROJECTION_MODE.PROJECT_COL: {
485
+ if (queryBuilderState.useRelation) {
486
+ throw new UnsupportedOperationError(
487
+ `Can't build projection: '${TDS_PROJECTION_MODE.PROJECT_COL}' mode is not supported with relation queries`,
488
+ );
489
+ }
490
+ lambdaFunction.expressionSequence[0] = buildProjectColExpression(
491
+ tdsState,
320
492
  precedingExpression,
321
- colFuncCollection,
322
- ];
323
- } else {
324
- const colLambdas = new CollectionInstanceValue(
325
- queryBuilderState.graphManagerState.graph.getMultiplicity(
326
- tdsState.projectionColumns.length,
327
- tdsState.projectionColumns.length,
328
- ),
329
- );
330
- const colAliases = new CollectionInstanceValue(
331
- queryBuilderState.graphManagerState.graph.getMultiplicity(
332
- tdsState.projectionColumns.length,
333
- tdsState.projectionColumns.length,
334
- ),
493
+ options,
335
494
  );
336
- tdsState.projectionColumns.forEach((projectionColumnState) => {
337
- // column alias
338
- const colAlias = new PrimitiveInstanceValue(
339
- GenericTypeExplicitReference.create(
340
- new GenericType(PrimitiveType.STRING),
341
- ),
495
+ break;
496
+ }
497
+ case TDS_PROJECTION_MODE.SELECT: {
498
+ if (!queryBuilderState.useRelation) {
499
+ throw new UnsupportedOperationError(
500
+ `Can't build projection: '${TDS_PROJECTION_MODE.SELECT}' mode requires a relation query`,
342
501
  );
343
- colAlias.values.push(projectionColumnState.columnName);
344
- colAliases.values.push(colAlias);
345
-
346
- // column projection
347
- let columnLambda: ValueSpecification;
348
- if (
349
- projectionColumnState instanceof
350
- QueryBuilderSimpleProjectionColumnState
351
- ) {
352
- columnLambda = buildGenericLambdaFunctionInstanceValue(
353
- [projectionColumnState.lambdaParameterName],
354
- [
355
- buildPropertyExpressionChain(
356
- projectionColumnState.propertyExpressionState
357
- .propertyExpression,
358
- projectionColumnState.propertyExpressionState
359
- .queryBuilderState,
360
- projectionColumnState.lambdaParameterName,
361
- options,
362
- ),
363
- ],
364
- queryBuilderState.graphManagerState.graph,
365
- );
366
- } else if (
367
- projectionColumnState instanceof
368
- QueryBuilderDerivationProjectionColumnState
369
- ) {
370
- columnLambda = new INTERNAL__UnknownValueSpecification(
371
- V1_serializeRawValueSpecification(
372
- V1_transformRawLambda(
373
- projectionColumnState.lambda,
374
- new V1_GraphTransformerContextBuilder(
375
- // TODO?: do we need to include the plugins here?
376
- [],
377
- )
378
- .withKeepSourceInformationFlag(
379
- Boolean(options?.keepSourceInformation),
380
- )
381
- .build(),
382
- ),
383
- ),
384
- );
385
- } else {
386
- throw new UnsupportedOperationError(
387
- `Can't build project() column expression: unsupported projection column state`,
388
- projectionColumnState,
389
- );
390
- }
391
- colLambdas.values.push(columnLambda);
392
- });
393
- projectFunction.parametersValues = [
502
+ }
503
+ lambdaFunction.expressionSequence[0] = buildSelectExpression(
504
+ tdsState,
394
505
  precedingExpression,
395
- colLambdas,
396
- colAliases,
397
- ];
506
+ );
507
+ break;
398
508
  }
399
- lambdaFunction.expressionSequence[0] = projectFunction;
400
- } else {
401
- const projectFunction = buildRelationProjection(
402
- precedingExpression,
403
- tdsState,
404
- options,
405
- );
406
- const aggregationFunction = tdsState.aggregationState.columns.length
407
- ? buildRelationAggregation(projectFunction, tdsState)
408
- : null;
409
- lambdaFunction.expressionSequence[0] =
410
- aggregationFunction ?? projectFunction;
509
+ default:
510
+ throw new UnsupportedOperationError(
511
+ `Can't build projection: unsupported projection mode '${tdsState.projectionMode}'`,
512
+ );
411
513
  }
412
514
  }
413
515
  // build olapGroupBy
@@ -54,8 +54,7 @@ import {
54
54
  GenericTypeExplicitReference,
55
55
  findLakehouseAccessPointGroup,
56
56
  type PureModel,
57
- V1_RelationType,
58
- V1_getGenericTypeFullPath,
57
+ V1_buildRelationTypeFromAccessPointImplementation,
59
58
  LegendSDLC,
60
59
  DataProductAccessType,
61
60
  } from '@finos/legend-graph';
@@ -92,7 +91,6 @@ export const resolveDataProductAccessor = (
92
91
  artifact: V1_DataProductArtifact | undefined,
93
92
  relationMetadata?: RelationTypeMetadata | undefined,
94
93
  ): DataProductAccessor => {
95
- const relationType = new RelationType(accessPoint.title ?? accessPoint.id);
96
94
  if (artifact) {
97
95
  const artifactGroup = artifact.accessPointGroups.find((apg) =>
98
96
  apg.accessPointImplementations.some(
@@ -102,30 +100,25 @@ export const resolveDataProductAccessor = (
102
100
  const artifactImpl = artifactGroup?.accessPointImplementations.find(
103
101
  (apImpl) => apImpl.id === accessPoint.id,
104
102
  );
105
- const v1RelationType = artifactImpl?.lambdaGenericType?.typeArguments
106
- .map((typeArg) => typeArg.rawType)
107
- .find((rawType) => rawType instanceof V1_RelationType);
108
- if (v1RelationType) {
109
- relationType.columns = v1RelationType.columns.map(
110
- (col) =>
111
- new RelationColumn(
112
- col.name,
113
- GenericTypeExplicitReference.create(
114
- new GenericType(
115
- graph.getType(V1_getGenericTypeFullPath(col.genericType)),
116
- ),
117
- ),
118
- ),
119
- );
120
- return new DataProductAccessor(
121
- dataProduct.path,
122
- artifactGroup?.id,
123
- accessPoint.id,
124
- relationType,
125
- dataProduct,
126
- );
103
+ if (artifactImpl) {
104
+ const builtRelationType =
105
+ V1_buildRelationTypeFromAccessPointImplementation(
106
+ artifactImpl,
107
+ graph,
108
+ accessPoint.title ?? accessPoint.id,
109
+ );
110
+ if (builtRelationType) {
111
+ return new DataProductAccessor(
112
+ dataProduct.path,
113
+ artifactGroup?.id,
114
+ accessPoint.id,
115
+ builtRelationType,
116
+ dataProduct,
117
+ );
118
+ }
127
119
  }
128
120
  }
121
+ const relationType = new RelationType(accessPoint.title ?? accessPoint.id);
129
122
  if (relationMetadata) {
130
123
  relationType.columns = relationMetadata.columns.map(
131
124
  (col) =>
@@ -271,7 +264,9 @@ export class ModelAccessPointDataProductExecutionState extends DataProductExecut
271
264
 
272
265
  changeSelectedRuntime(val: PackageableRuntime): void {
273
266
  this.selectedRuntime = val;
274
- this.queryBuilderState.changeRuntime(val);
267
+ this.queryBuilderState.changeRuntime(
268
+ new RuntimePointer(PackageableElementExplicitReference.create(val)),
269
+ );
275
270
  }
276
271
 
277
272
  withAdhocRuntime(): ModelAccessPointDataProductExecutionState {
@@ -312,13 +307,19 @@ export class LakehouseDataProductExecutionState extends DataProductExecutionStat
312
307
  super(executionState, queryBuilderState);
313
308
  makeObservable(this, {
314
309
  withAdhocRuntime: observable,
310
+ selectedRuntime: observable,
311
+ changeSelectedRuntime: action,
312
+ compatibleRuntimes: computed,
313
+ showRuntimeOptions: computed,
315
314
  });
316
315
  this.selectedRuntime = this.compatibleRuntimes[0];
317
316
  }
318
317
 
319
318
  changeSelectedRuntime(val: PackageableRuntime): void {
320
319
  this.selectedRuntime = val;
321
- this.queryBuilderState.changeRuntime(val);
320
+ this.queryBuilderState.changeRuntime(
321
+ new RuntimePointer(PackageableElementExplicitReference.create(val)),
322
+ );
322
323
  }
323
324
 
324
325
  withAdhocRuntime(): LakehouseDataProductExecutionState {