@finos/legend-query-builder 0.4.3 → 0.4.4

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 (64) hide show
  1. package/lib/components/QueryBuilder.d.ts +0 -1
  2. package/lib/components/QueryBuilder.d.ts.map +1 -1
  3. package/lib/components/QueryBuilderDiffPanel.d.ts +0 -1
  4. package/lib/components/QueryBuilderDiffPanel.d.ts.map +1 -1
  5. package/lib/components/QueryBuilderParametersPanel.d.ts +0 -1
  6. package/lib/components/QueryBuilderParametersPanel.d.ts.map +1 -1
  7. package/lib/components/QueryBuilderParametersPanel.js +2 -4
  8. package/lib/components/QueryBuilderParametersPanel.js.map +1 -1
  9. package/lib/components/QueryBuilderPropertyExpressionEditor.d.ts +0 -1
  10. package/lib/components/QueryBuilderPropertyExpressionEditor.d.ts.map +1 -1
  11. package/lib/components/QueryBuilderResultPanel.d.ts +0 -1
  12. package/lib/components/QueryBuilderResultPanel.d.ts.map +1 -1
  13. package/lib/components/QueryBuilderSideBar.d.ts +0 -1
  14. package/lib/components/QueryBuilderSideBar.d.ts.map +1 -1
  15. package/lib/components/QueryBuilderTextEditor.d.ts +0 -1
  16. package/lib/components/QueryBuilderTextEditor.d.ts.map +1 -1
  17. package/lib/components/QueryBuilderUnsupportedQueryEditor.d.ts +0 -1
  18. package/lib/components/QueryBuilderUnsupportedQueryEditor.d.ts.map +1 -1
  19. package/lib/components/explorer/QueryBuilderFunctionsExplorerPanel.d.ts +0 -1
  20. package/lib/components/explorer/QueryBuilderFunctionsExplorerPanel.d.ts.map +1 -1
  21. package/lib/components/explorer/QueryBuilderMilestoningEditor.d.ts +0 -1
  22. package/lib/components/explorer/QueryBuilderMilestoningEditor.d.ts.map +1 -1
  23. package/lib/components/explorer/QueryBuilderPropertySearchPanel.d.ts +0 -1
  24. package/lib/components/explorer/QueryBuilderPropertySearchPanel.d.ts.map +1 -1
  25. package/lib/components/fetch-structure/QueryBuilderFetchStructurePanel.d.ts +0 -1
  26. package/lib/components/fetch-structure/QueryBuilderFetchStructurePanel.d.ts.map +1 -1
  27. package/lib/components/fetch-structure/QueryBuilderGraphFetchTreePanel.d.ts +0 -1
  28. package/lib/components/fetch-structure/QueryBuilderGraphFetchTreePanel.d.ts.map +1 -1
  29. package/lib/components/fetch-structure/QueryBuilderOLAPGroupByPanel_.d.ts +0 -1
  30. package/lib/components/fetch-structure/QueryBuilderOLAPGroupByPanel_.d.ts.map +1 -1
  31. package/lib/components/fetch-structure/QueryBuilderPostFilterPanel.d.ts +0 -1
  32. package/lib/components/fetch-structure/QueryBuilderPostFilterPanel.d.ts.map +1 -1
  33. package/lib/components/fetch-structure/QueryBuilderPostTDSPanel.d.ts +0 -1
  34. package/lib/components/fetch-structure/QueryBuilderPostTDSPanel.d.ts.map +1 -1
  35. package/lib/components/fetch-structure/QueryBuilderResultModifierPanel.d.ts +0 -1
  36. package/lib/components/fetch-structure/QueryBuilderResultModifierPanel.d.ts.map +1 -1
  37. package/lib/components/fetch-structure/QueryBuilderTDSPanel.d.ts +0 -1
  38. package/lib/components/fetch-structure/QueryBuilderTDSPanel.d.ts.map +1 -1
  39. package/lib/components/filter/QueryBuilderFilterPanel.d.ts +0 -1
  40. package/lib/components/filter/QueryBuilderFilterPanel.d.ts.map +1 -1
  41. package/lib/components/shared/LambdaEditor.d.ts +0 -1
  42. package/lib/components/shared/LambdaEditor.d.ts.map +1 -1
  43. package/lib/components/shared/LambdaParameterValuesEditor.d.ts +0 -1
  44. package/lib/components/shared/LambdaParameterValuesEditor.d.ts.map +1 -1
  45. package/lib/components/watermark/QueryBuilderWatermark.d.ts +0 -1
  46. package/lib/components/watermark/QueryBuilderWatermark.d.ts.map +1 -1
  47. package/lib/index.css +16 -0
  48. package/lib/package.json +6 -6
  49. package/lib/stores/QueryBuilderResultState.d.ts +1 -2
  50. package/lib/stores/QueryBuilderResultState.d.ts.map +1 -1
  51. package/lib/stores/QueryBuilderResultState.js +7 -12
  52. package/lib/stores/QueryBuilderResultState.js.map +1 -1
  53. package/lib/stores/QueryBuilderValueSpecificationBuilder.d.ts.map +1 -1
  54. package/lib/stores/QueryBuilderValueSpecificationBuilder.js +9 -4
  55. package/lib/stores/QueryBuilderValueSpecificationBuilder.js.map +1 -1
  56. package/lib/stores/shared/LambdaParameterState.d.ts +14 -2
  57. package/lib/stores/shared/LambdaParameterState.d.ts.map +1 -1
  58. package/lib/stores/shared/LambdaParameterState.js +79 -6
  59. package/lib/stores/shared/LambdaParameterState.js.map +1 -1
  60. package/package.json +13 -13
  61. package/src/components/QueryBuilderParametersPanel.tsx +2 -7
  62. package/src/stores/QueryBuilderResultState.ts +19 -17
  63. package/src/stores/QueryBuilderValueSpecificationBuilder.ts +14 -7
  64. package/src/stores/shared/LambdaParameterState.ts +151 -10
@@ -19,11 +19,26 @@ import {
19
19
  type Type,
20
20
  type ValueSpecification,
21
21
  type PureModel,
22
+ type GraphManagerState,
23
+ type RawLambda,
22
24
  GenericType,
23
25
  GenericTypeExplicitReference,
24
26
  observe_ValueSpecification,
25
27
  observe_VariableExpression,
26
28
  VariableExpression,
29
+ SimpleFunctionExpression,
30
+ PackageableElementExplicitReference,
31
+ LambdaFunction,
32
+ FunctionType,
33
+ CORE_PURE_PATH,
34
+ extractElementNameFromPath,
35
+ Multiplicity,
36
+ PrimitiveInstanceValue,
37
+ PrimitiveType,
38
+ SUPPORTED_FUNCTIONS,
39
+ areMultiplicitiesEqual,
40
+ ParameterValue,
41
+ buildRawLambdaFromLambdaFunction,
27
42
  } from '@finos/legend-graph';
28
43
  import {
29
44
  addUniqueEntry,
@@ -32,6 +47,8 @@ import {
32
47
  hashArray,
33
48
  IllegalStateError,
34
49
  uuid,
50
+ isNonNullable,
51
+ guaranteeNonNullable,
35
52
  } from '@finos/legend-shared';
36
53
  import { makeObservable, observable, action, computed } from 'mobx';
37
54
  import { generateVariableExpressionMockValue } from './ValueSpecificationEditorHelper.js';
@@ -49,6 +66,137 @@ enum LAMABA_PARAMETER_HASH_STRUCTURE {
49
66
  LAMBDA_PARAMETER_STATE = 'LAMBDA_PARAMETER_STATE',
50
67
  LAMBDA_PARAMETERS_STATE = 'LAMBDA_PARAMETERS_STATE',
51
68
  }
69
+
70
+ export const buildParametersLetLambdaFunc = (
71
+ graph: PureModel,
72
+ lambdaParametersStates: LambdaParameterState[],
73
+ ): LambdaFunction => {
74
+ const letlambdaFunction = new LambdaFunction(
75
+ new FunctionType(
76
+ PackageableElementExplicitReference.create(
77
+ graph.getType(CORE_PURE_PATH.ANY),
78
+ ),
79
+ Multiplicity.ONE,
80
+ ),
81
+ );
82
+ letlambdaFunction.expressionSequence = lambdaParametersStates
83
+ .map((queryParamState) => {
84
+ if (queryParamState.value) {
85
+ const letFunc = new SimpleFunctionExpression(
86
+ extractElementNameFromPath(SUPPORTED_FUNCTIONS.LET),
87
+ );
88
+ const letVar = new PrimitiveInstanceValue(
89
+ GenericTypeExplicitReference.create(
90
+ new GenericType(PrimitiveType.STRING),
91
+ ),
92
+ );
93
+ letVar.values = [queryParamState.variableName];
94
+ letFunc.parametersValues.push(letVar);
95
+ letFunc.parametersValues.push(queryParamState.value);
96
+ return letFunc;
97
+ }
98
+ return undefined;
99
+ })
100
+ .filter(isNonNullable);
101
+ return letlambdaFunction;
102
+ };
103
+
104
+ /**
105
+ * For most query executions we will use the stragtical method of sending in `paramValues` as part of the execution input payload.
106
+ * However when the user wants to use a function value as the parameter value, engine does not understand this i.e for date param the functions `now()`, `today()`.
107
+ * Engine Does not support this because those functions require a building of execution nodes inside the execution plan.
108
+ * To continue supporting this execution flow , we will add let statements for parameter values with function values so that they can be evaluated to constants in the execution plan.
109
+ */
110
+ export const doesLambdaParameterStateContainFunctionValues = (
111
+ parameterState: LambdaParameterState,
112
+ ): boolean =>
113
+ parameterState.value instanceof SimpleFunctionExpression &&
114
+ [Multiplicity.ONE, Multiplicity.ZERO_ONE].some((p) =>
115
+ areMultiplicitiesEqual(p, parameterState.parameter.multiplicity),
116
+ );
117
+
118
+ export const getParameterStatesWithFunctionValues = (
119
+ parameterStates: LambdaParameterState[],
120
+ ): LambdaParameterState[] =>
121
+ parameterStates.filter(doesLambdaParameterStateContainFunctionValues);
122
+
123
+ export const buildExecutionParameterValues = (
124
+ paramStates: LambdaParameterState[],
125
+ graphState: GraphManagerState,
126
+ ): ParameterValue[] =>
127
+ paramStates
128
+ .filter((ps) => !doesLambdaParameterStateContainFunctionValues(ps))
129
+ .map((queryParamState) => {
130
+ const paramValue = new ParameterValue();
131
+ paramValue.name = queryParamState.parameter.name;
132
+ paramValue.value = graphState.graphManager.serializeValueSpecification(
133
+ guaranteeNonNullable(queryParamState.value),
134
+ );
135
+ return paramValue;
136
+ });
137
+
138
+ export const getExecutionQueryFromRawLambda = (
139
+ rawLambda: RawLambda,
140
+ parameterStates: LambdaParameterState[],
141
+ graphManagerState: GraphManagerState,
142
+ ): RawLambda => {
143
+ const paramsWithLetStatements =
144
+ getParameterStatesWithFunctionValues(parameterStates);
145
+ if (paramsWithLetStatements.length > 0) {
146
+ const execuLambdaFunction = buildParametersLetLambdaFunc(
147
+ graphManagerState.graph,
148
+ paramsWithLetStatements,
149
+ );
150
+ // remove parameters added as let statements from lambda parameters
151
+ execuLambdaFunction.functionType.parameters = parameterStates
152
+ .filter((ps) => !paramsWithLetStatements.includes(ps))
153
+ .map((e) => e.parameter);
154
+ const execQuery = buildRawLambdaFromLambdaFunction(
155
+ execuLambdaFunction,
156
+ graphManagerState,
157
+ );
158
+ // reset paramaters
159
+ if (Array.isArray(rawLambda.body) && Array.isArray(execQuery.body)) {
160
+ execQuery.body = [
161
+ ...(execQuery.body as object[]),
162
+ ...(rawLambda.body as object[]),
163
+ ];
164
+ return execQuery;
165
+ }
166
+ }
167
+ return rawLambda;
168
+ };
169
+
170
+ export const buildExecutionQueryFromLambdaFunction = (
171
+ lambdaFunction: LambdaFunction,
172
+ parameterStates: LambdaParameterState[],
173
+ graphManagerState: GraphManagerState,
174
+ ): LambdaFunction => {
175
+ const funcParameterStates =
176
+ getParameterStatesWithFunctionValues(parameterStates);
177
+ if (funcParameterStates.length) {
178
+ // To handle parameter value with function calls we
179
+ // 1. remove those parameters from parameter list
180
+ // 2. add let statements with parameter values
181
+ lambdaFunction.functionType.parameters = parameterStates
182
+ .filter((ps) => !funcParameterStates.includes(ps))
183
+ .map((e) => e.parameter);
184
+ const letsFuncs = buildParametersLetLambdaFunc(
185
+ graphManagerState.graph,
186
+ funcParameterStates,
187
+ );
188
+ lambdaFunction.expressionSequence = [
189
+ ...letsFuncs.expressionSequence,
190
+ ...lambdaFunction.expressionSequence,
191
+ ];
192
+ } else {
193
+ lambdaFunction.functionType.parameters = parameterStates.map(
194
+ (e) => e.parameter,
195
+ );
196
+ }
197
+ return lambdaFunction;
198
+ };
199
+
52
200
  export class LambdaParameterState implements Hashable {
53
201
  readonly uuid = uuid();
54
202
  readonly parameter: VariableExpression;
@@ -109,18 +257,11 @@ export class LambdaParameterState implements Hashable {
109
257
 
110
258
  changeMultiplicity(
111
259
  variableExpression: VariableExpression,
112
- lowerBound: number,
113
- uppderBound: number | undefined,
260
+ mul: Multiplicity,
114
261
  ): void {
115
262
  const current = this.parameter.multiplicity;
116
- if (
117
- current.lowerBound !== lowerBound ||
118
- current.upperBound !== uppderBound
119
- ) {
120
- valueSpecification_setMultiplicity(
121
- variableExpression,
122
- this.graph.getMultiplicity(lowerBound, uppderBound),
123
- );
263
+ if (!areMultiplicitiesEqual(current, mul)) {
264
+ valueSpecification_setMultiplicity(variableExpression, mul);
124
265
  this.mockParameterValue();
125
266
  }
126
267
  }