@finos/legend-query-builder 4.14.96 → 4.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. package/lib/components/QueryBuilder.d.ts.map +1 -1
  2. package/lib/components/QueryBuilder.js +2 -1
  3. package/lib/components/QueryBuilder.js.map +1 -1
  4. package/lib/components/data-cube/QueryBuilderDataCube.d.ts +22 -0
  5. package/lib/components/data-cube/QueryBuilderDataCube.d.ts.map +1 -0
  6. package/lib/components/data-cube/QueryBuilderDataCube.js +48 -0
  7. package/lib/components/data-cube/QueryBuilderDataCube.js.map +1 -0
  8. package/lib/components/filter/QueryBuilderFilterPanel.js +2 -2
  9. package/lib/components/filter/QueryBuilderFilterPanel.js.map +1 -1
  10. package/lib/components/result/QueryBuilderResultPanel.d.ts.map +1 -1
  11. package/lib/components/result/QueryBuilderResultPanel.js +6 -3
  12. package/lib/components/result/QueryBuilderResultPanel.js.map +1 -1
  13. package/lib/components/result/tds/QueryBuilderTDSGridResult.d.ts.map +1 -1
  14. package/lib/components/result/tds/QueryBuilderTDSGridResult.js +2 -3
  15. package/lib/components/result/tds/QueryBuilderTDSGridResult.js.map +1 -1
  16. package/lib/components/result/tds/QueryBuilderTDSResultShared.d.ts +2 -2
  17. package/lib/components/result/tds/QueryBuilderTDSResultShared.d.ts.map +1 -1
  18. package/lib/components/result/tds/QueryBuilderTDSResultShared.js +19 -155
  19. package/lib/components/result/tds/QueryBuilderTDSResultShared.js.map +1 -1
  20. package/lib/graph-manager/QueryBuilderConfig.d.ts +5 -1
  21. package/lib/graph-manager/QueryBuilderConfig.d.ts.map +1 -1
  22. package/lib/graph-manager/QueryBuilderConfig.js +6 -1
  23. package/lib/graph-manager/QueryBuilderConfig.js.map +1 -1
  24. package/lib/index.css +1 -1
  25. package/lib/index.d.ts +2 -0
  26. package/lib/index.d.ts.map +1 -1
  27. package/lib/index.js +2 -0
  28. package/lib/index.js.map +1 -1
  29. package/lib/package.json +2 -1
  30. package/lib/stores/QueryBuilderState.d.ts +2 -0
  31. package/lib/stores/QueryBuilderState.d.ts.map +1 -1
  32. package/lib/stores/QueryBuilderState.js +9 -19
  33. package/lib/stores/QueryBuilderState.js.map +1 -1
  34. package/lib/stores/data-cube/QueryBuilderDataCubeApplicationEngine.d.ts +38 -0
  35. package/lib/stores/data-cube/QueryBuilderDataCubeApplicationEngine.d.ts.map +1 -0
  36. package/lib/stores/data-cube/QueryBuilderDataCubeApplicationEngine.js +71 -0
  37. package/lib/stores/data-cube/QueryBuilderDataCubeApplicationEngine.js.map +1 -0
  38. package/lib/stores/data-cube/QueryBuilderDataCubeEngine.d.ts +52 -0
  39. package/lib/stores/data-cube/QueryBuilderDataCubeEngine.d.ts.map +1 -0
  40. package/lib/stores/data-cube/QueryBuilderDataCubeEngine.js +149 -0
  41. package/lib/stores/data-cube/QueryBuilderDataCubeEngine.js.map +1 -0
  42. package/lib/stores/data-cube/QueryBuilderDataCubeEngineHelper.d.ts +19 -0
  43. package/lib/stores/data-cube/QueryBuilderDataCubeEngineHelper.d.ts.map +1 -0
  44. package/lib/stores/data-cube/QueryBuilderDataCubeEngineHelper.js +31 -0
  45. package/lib/stores/data-cube/QueryBuilderDataCubeEngineHelper.js.map +1 -0
  46. package/lib/stores/fetch-structure/QueryBuilderFetchStructureImplementationState.d.ts +1 -0
  47. package/lib/stores/fetch-structure/QueryBuilderFetchStructureImplementationState.d.ts.map +1 -1
  48. package/lib/stores/fetch-structure/QueryBuilderFetchStructureImplementationState.js.map +1 -1
  49. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.d.ts +1 -0
  50. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.d.ts.map +1 -1
  51. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.js +3 -0
  52. package/lib/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.js.map +1 -1
  53. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.d.ts +1 -0
  54. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.d.ts.map +1 -1
  55. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.js +3 -0
  56. package/lib/stores/fetch-structure/tds/QueryBuilderTDSState.js.map +1 -1
  57. package/lib/stores/filter/QueryBuilderFilterOperator.d.ts +1 -1
  58. package/lib/stores/filter/QueryBuilderFilterOperator.d.ts.map +1 -1
  59. package/lib/stores/filter/QueryBuilderFilterState.d.ts +1 -1
  60. package/lib/stores/filter/QueryBuilderFilterState.d.ts.map +1 -1
  61. package/lib/stores/filter/QueryBuilderFilterState.js +3 -8
  62. package/lib/stores/filter/QueryBuilderFilterState.js.map +1 -1
  63. package/lib/stores/filter/QueryBuilderFilterStateBuilder.js +1 -1
  64. package/lib/stores/filter/QueryBuilderFilterStateBuilder.js.map +1 -1
  65. package/lib/stores/filter/operators/QueryBuilderFilterOperator_Contain.d.ts +2 -2
  66. package/lib/stores/filter/operators/QueryBuilderFilterOperator_Contain.d.ts.map +1 -1
  67. package/lib/stores/filter/operators/QueryBuilderFilterOperator_Contain.js +3 -3
  68. package/lib/stores/filter/operators/QueryBuilderFilterOperator_Contain.js.map +1 -1
  69. package/lib/stores/filter/operators/QueryBuilderFilterOperator_EndWith.d.ts +2 -2
  70. package/lib/stores/filter/operators/QueryBuilderFilterOperator_EndWith.d.ts.map +1 -1
  71. package/lib/stores/filter/operators/QueryBuilderFilterOperator_EndWith.js +3 -3
  72. package/lib/stores/filter/operators/QueryBuilderFilterOperator_EndWith.js.map +1 -1
  73. package/lib/stores/filter/operators/QueryBuilderFilterOperator_Equal.d.ts +2 -2
  74. package/lib/stores/filter/operators/QueryBuilderFilterOperator_Equal.d.ts.map +1 -1
  75. package/lib/stores/filter/operators/QueryBuilderFilterOperator_Equal.js +2 -2
  76. package/lib/stores/filter/operators/QueryBuilderFilterOperator_Equal.js.map +1 -1
  77. package/lib/stores/filter/operators/QueryBuilderFilterOperator_GreaterThan.d.ts +1 -1
  78. package/lib/stores/filter/operators/QueryBuilderFilterOperator_GreaterThan.d.ts.map +1 -1
  79. package/lib/stores/filter/operators/QueryBuilderFilterOperator_GreaterThan.js +2 -2
  80. package/lib/stores/filter/operators/QueryBuilderFilterOperator_GreaterThan.js.map +1 -1
  81. package/lib/stores/filter/operators/QueryBuilderFilterOperator_GreaterThanEqual.d.ts +1 -1
  82. package/lib/stores/filter/operators/QueryBuilderFilterOperator_GreaterThanEqual.d.ts.map +1 -1
  83. package/lib/stores/filter/operators/QueryBuilderFilterOperator_GreaterThanEqual.js +2 -2
  84. package/lib/stores/filter/operators/QueryBuilderFilterOperator_GreaterThanEqual.js.map +1 -1
  85. package/lib/stores/filter/operators/QueryBuilderFilterOperator_In.d.ts +2 -2
  86. package/lib/stores/filter/operators/QueryBuilderFilterOperator_In.d.ts.map +1 -1
  87. package/lib/stores/filter/operators/QueryBuilderFilterOperator_In.js +2 -2
  88. package/lib/stores/filter/operators/QueryBuilderFilterOperator_In.js.map +1 -1
  89. package/lib/stores/filter/operators/QueryBuilderFilterOperator_IsEmpty.d.ts +2 -2
  90. package/lib/stores/filter/operators/QueryBuilderFilterOperator_IsEmpty.d.ts.map +1 -1
  91. package/lib/stores/filter/operators/QueryBuilderFilterOperator_IsEmpty.js +2 -2
  92. package/lib/stores/filter/operators/QueryBuilderFilterOperator_IsEmpty.js.map +1 -1
  93. package/lib/stores/filter/operators/QueryBuilderFilterOperator_LessThan.d.ts +1 -1
  94. package/lib/stores/filter/operators/QueryBuilderFilterOperator_LessThan.d.ts.map +1 -1
  95. package/lib/stores/filter/operators/QueryBuilderFilterOperator_LessThan.js +2 -2
  96. package/lib/stores/filter/operators/QueryBuilderFilterOperator_LessThan.js.map +1 -1
  97. package/lib/stores/filter/operators/QueryBuilderFilterOperator_LessThanEqual.d.ts +1 -1
  98. package/lib/stores/filter/operators/QueryBuilderFilterOperator_LessThanEqual.d.ts.map +1 -1
  99. package/lib/stores/filter/operators/QueryBuilderFilterOperator_LessThanEqual.js +2 -2
  100. package/lib/stores/filter/operators/QueryBuilderFilterOperator_LessThanEqual.js.map +1 -1
  101. package/lib/stores/filter/operators/QueryBuilderFilterOperator_StartWith.d.ts +2 -2
  102. package/lib/stores/filter/operators/QueryBuilderFilterOperator_StartWith.d.ts.map +1 -1
  103. package/lib/stores/filter/operators/QueryBuilderFilterOperator_StartWith.js +3 -3
  104. package/lib/stores/filter/operators/QueryBuilderFilterOperator_StartWith.js.map +1 -1
  105. package/package.json +7 -6
  106. package/src/components/QueryBuilder.tsx +4 -0
  107. package/src/components/data-cube/QueryBuilderDataCube.tsx +116 -0
  108. package/src/components/filter/QueryBuilderFilterPanel.tsx +2 -2
  109. package/src/components/result/QueryBuilderResultPanel.tsx +24 -0
  110. package/src/components/result/tds/QueryBuilderTDSGridResult.tsx +2 -3
  111. package/src/components/result/tds/QueryBuilderTDSResultShared.tsx +26 -332
  112. package/src/graph-manager/QueryBuilderConfig.ts +7 -1
  113. package/src/index.ts +2 -0
  114. package/src/stores/QueryBuilderState.ts +13 -27
  115. package/src/stores/data-cube/QueryBuilderDataCubeApplicationEngine.ts +109 -0
  116. package/src/stores/data-cube/QueryBuilderDataCubeEngine.ts +255 -0
  117. package/src/stores/data-cube/QueryBuilderDataCubeEngineHelper.ts +41 -0
  118. package/src/stores/fetch-structure/QueryBuilderFetchStructureImplementationState.ts +1 -0
  119. package/src/stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.ts +4 -0
  120. package/src/stores/fetch-structure/tds/QueryBuilderTDSState.ts +4 -0
  121. package/src/stores/filter/QueryBuilderFilterOperator.ts +1 -1
  122. package/src/stores/filter/QueryBuilderFilterState.ts +5 -10
  123. package/src/stores/filter/QueryBuilderFilterStateBuilder.ts +1 -1
  124. package/src/stores/filter/operators/QueryBuilderFilterOperator_Contain.ts +5 -3
  125. package/src/stores/filter/operators/QueryBuilderFilterOperator_EndWith.ts +5 -3
  126. package/src/stores/filter/operators/QueryBuilderFilterOperator_Equal.ts +2 -2
  127. package/src/stores/filter/operators/QueryBuilderFilterOperator_GreaterThan.ts +4 -2
  128. package/src/stores/filter/operators/QueryBuilderFilterOperator_GreaterThanEqual.ts +4 -2
  129. package/src/stores/filter/operators/QueryBuilderFilterOperator_In.ts +2 -2
  130. package/src/stores/filter/operators/QueryBuilderFilterOperator_IsEmpty.ts +2 -2
  131. package/src/stores/filter/operators/QueryBuilderFilterOperator_LessThan.ts +4 -2
  132. package/src/stores/filter/operators/QueryBuilderFilterOperator_LessThanEqual.ts +4 -2
  133. package/src/stores/filter/operators/QueryBuilderFilterOperator_StartWith.ts +5 -3
  134. package/tsconfig.json +4 -0
@@ -19,7 +19,12 @@ import { createModelSchema, optional, primitive } from 'serializr';
19
19
 
20
20
  export class QueryBuilderConfig {
21
21
  /**
22
- * This flag is to disable query builder chat feature
22
+ * This flag is to enable export to cube
23
+ */
24
+ TEMPORARY__enableExportToCube = false;
25
+
26
+ /**
27
+ * This flag is to disable query builder chat features
23
28
  */
24
29
  TEMPORARY__disableQueryBuilderChat = false;
25
30
 
@@ -41,6 +46,7 @@ export class QueryBuilderConfig {
41
46
  static readonly serialization = new SerializationFactory(
42
47
  createModelSchema(QueryBuilderConfig, {
43
48
  TEMPORARY__disableQueryBuilderChat: optional(primitive()),
49
+ TEMPORARY__enableExportToCube: optional(primitive()),
44
50
  TEMPORARY__enableGridEnterpriseMode: optional(primitive()),
45
51
  legendAIServiceURL: optional(primitive()),
46
52
  zipkinTraceBaseURL: optional(primitive()),
package/src/index.ts CHANGED
@@ -126,3 +126,5 @@ export * from './stores/filter/QueryBuilderFilterValueSpecificationBuilder.js';
126
126
  export * from './stores/QueryBuilderValueSpecificationHelper.js';
127
127
  export * from './stores/filter/QueryBuilderFilterState.js';
128
128
  export * from './stores/filter/QueryBuilderFilterStateBuilder.js';
129
+ export * from './stores/data-cube/QueryBuilderDataCubeApplicationEngine.js';
130
+ export * from './stores/data-cube/QueryBuilderDataCubeEngine.js';
@@ -68,14 +68,10 @@ import {
68
68
  buildLambdaVariableExpressions,
69
69
  buildRawLambdaFromLambdaFunction,
70
70
  PrimitiveType,
71
- SimpleFunctionExpression,
72
- extractElementNameFromPath,
73
- SUPPORTED_FUNCTIONS,
74
71
  PackageableElementExplicitReference,
75
- InstanceValue,
76
- Multiplicity,
77
72
  RuntimePointer,
78
73
  QueryExplicitExecutionContext,
74
+ attachFromQuery,
79
75
  } from '@finos/legend-graph';
80
76
  import { buildLambdaFunction } from './QueryBuilderValueSpecificationBuilder.js';
81
77
  import type {
@@ -158,6 +154,7 @@ export abstract class QueryBuilderState implements CommandRegistrar {
158
154
  isCheckingEntitlments = false;
159
155
  isCalendarEnabled = false;
160
156
  isLocalModeEnabled = false;
157
+ isCubeEnabled = false;
161
158
  INTERNAL__enableInitializingDefaultSimpleExpressionValue = false;
162
159
 
163
160
  lambdaWriteMode = QUERY_BUILDER_LAMBDA_WRITER_MODE.STANDARD;
@@ -208,6 +205,7 @@ export abstract class QueryBuilderState implements CommandRegistrar {
208
205
  class: observable,
209
206
  isQueryChatOpened: observable,
210
207
  isLocalModeEnabled: observable,
208
+ isCubeEnabled: observable,
211
209
  getAllFunction: observable,
212
210
  lambdaWriteMode: observable,
213
211
  INTERNAL__enableInitializingDefaultSimpleExpressionValue: observable,
@@ -221,6 +219,7 @@ export abstract class QueryBuilderState implements CommandRegistrar {
221
219
  setShowParametersPanel: action,
222
220
  setIsEditingWatermark: action,
223
221
  setIsCalendarEnabled: action,
222
+ setIsCubeEnabled: action,
224
223
  setIsCheckingEntitlments: action,
225
224
  setClass: action,
226
225
  setIsQueryChatOpened: action,
@@ -266,7 +265,6 @@ export abstract class QueryBuilderState implements CommandRegistrar {
266
265
 
267
266
  this.workflowState = workflowState;
268
267
  this.sourceInfo = sourceInfo;
269
- //extra check for only QA currently.
270
268
  this.isQueryChatOpened =
271
269
  (!this.config?.TEMPORARY__disableQueryBuilderChat &&
272
270
  this.applicationStore.settingService.getBooleanValue(
@@ -383,6 +381,10 @@ export abstract class QueryBuilderState implements CommandRegistrar {
383
381
  this.isLocalModeEnabled = val;
384
382
  }
385
383
 
384
+ setIsCubeEnabled(val: boolean): void {
385
+ this.isCubeEnabled = val;
386
+ }
387
+
386
388
  setInternalize(val: QueryBuilderInternalizeState | undefined): void {
387
389
  this.internalizeState = val;
388
390
  }
@@ -601,28 +603,12 @@ export abstract class QueryBuilderState implements CommandRegistrar {
601
603
  RuntimePointer,
602
604
  ).packageableRuntime;
603
605
  const lambdaFunc = buildLambdaFunction(this);
604
- const currentExpression = guaranteeNonNullable(
605
- lambdaFunc.expressionSequence[0],
606
+ const fromQuery = attachFromQuery(
607
+ lambdaFunc,
608
+ mapping,
609
+ runtimePointer.value,
606
610
  );
607
- const _func = new SimpleFunctionExpression(
608
- extractElementNameFromPath(SUPPORTED_FUNCTIONS.FROM),
609
- );
610
-
611
- const mappingInstance = new InstanceValue(Multiplicity.ONE, undefined);
612
- mappingInstance.values = [
613
- PackageableElementExplicitReference.create(mapping),
614
- ];
615
- const runtimeInstance = new InstanceValue(Multiplicity.ONE, undefined);
616
- runtimeInstance.values = [
617
- PackageableElementExplicitReference.create(runtimePointer.value),
618
- ];
619
- _func.parametersValues = [
620
- currentExpression,
621
- mappingInstance,
622
- runtimeInstance,
623
- ];
624
- lambdaFunc.expressionSequence = [_func];
625
- return buildRawLambdaFromLambdaFunction(lambdaFunc, this.graphManagerState);
611
+ return buildRawLambdaFromLambdaFunction(fromQuery, this.graphManagerState);
626
612
  }
627
613
 
628
614
  getQueryReturnType(): Type {
@@ -0,0 +1,109 @@
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
+ APPLICATION_EVENT,
19
+ shouldDisplayVirtualAssistantDocumentationEntry,
20
+ type GenericLegendApplicationStore,
21
+ } from '@finos/legend-application';
22
+ import {
23
+ DataCubeApplicationEngine,
24
+ type ActionAlert,
25
+ } from '@finos/legend-data-cube';
26
+ import { LogEvent, type DocumentationEntry } from '@finos/legend-shared';
27
+
28
+ export class QueryBuilderDataCubeApplicationEngine extends DataCubeApplicationEngine {
29
+ private readonly application: GenericLegendApplicationStore;
30
+
31
+ constructor(application: GenericLegendApplicationStore) {
32
+ super();
33
+
34
+ this.application = application;
35
+ }
36
+
37
+ get documentationUrl(): string | undefined {
38
+ return this.application.documentationService.url;
39
+ }
40
+
41
+ getDocumentationEntry(key: string) {
42
+ return this.application.documentationService.getDocEntry(key);
43
+ }
44
+
45
+ openDocumentationEntry(entry: DocumentationEntry) {
46
+ this.currentDocumentationEntry = entry;
47
+ }
48
+
49
+ shouldDisplayDocumentationEntry(entry: DocumentationEntry) {
50
+ return shouldDisplayVirtualAssistantDocumentationEntry(entry);
51
+ }
52
+
53
+ openLink(url: string) {
54
+ this.application.navigationService.navigator.visitAddress(url);
55
+ }
56
+
57
+ setWindowTitle(title: string) {
58
+ this.application.layoutService.setWindowTitle(title);
59
+ }
60
+
61
+ alertAction(alertInfo: ActionAlert | undefined) {
62
+ this.currentActionAlert = alertInfo;
63
+ }
64
+
65
+ alertUnhandledError(error: Error) {
66
+ this.application.alertUnhandledError(error);
67
+ }
68
+
69
+ logDebug(message: string, ...data: unknown[]) {
70
+ this.application.logService.debug(
71
+ LogEvent.create(APPLICATION_EVENT.DEBUG),
72
+ message,
73
+ ...data,
74
+ );
75
+ }
76
+
77
+ debugProcess(processName: string, ...data: unknown[]) {
78
+ this.application.logService.debug(
79
+ LogEvent.create(APPLICATION_EVENT.DEBUG),
80
+ `\n------ START DEBUG PROCESS: ${processName} ------\n`,
81
+ ...data,
82
+ `\n------- END DEBUG PROCESS: ${processName} -------\n`,
83
+ );
84
+ }
85
+
86
+ logInfo(event: LogEvent, ...data: unknown[]) {
87
+ this.application.logService.info(event, ...data);
88
+ }
89
+
90
+ logWarning(event: LogEvent, ...data: unknown[]) {
91
+ this.application.logService.warn(event, ...data);
92
+ }
93
+
94
+ logError(event: LogEvent, ...data: unknown[]) {
95
+ this.application.logService.error(event, ...data);
96
+ }
97
+
98
+ logUnhandledError(error: Error) {
99
+ this.application.logUnhandledError(error);
100
+ }
101
+
102
+ logIllegalStateError(message: string, error?: Error) {
103
+ this.logError(
104
+ LogEvent.create(APPLICATION_EVENT.ILLEGAL_APPLICATION_STATE_OCCURRED),
105
+ message,
106
+ error,
107
+ );
108
+ }
109
+ }
@@ -0,0 +1,255 @@
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
+ SUPPORTED_FUNCTIONS,
19
+ V1_AppliedFunction,
20
+ V1_Lambda,
21
+ RawLambda,
22
+ RelationalExecutionActivities,
23
+ TDSExecutionResult,
24
+ V1_deserializeRawValueSpecification,
25
+ V1_deserializeValueSpecification,
26
+ V1_RawLambda,
27
+ V1_serializeValueSpecification,
28
+ type GraphManagerState,
29
+ type PureModel,
30
+ type V1_ValueSpecification,
31
+ } from '@finos/legend-graph';
32
+ import {
33
+ _elementPtr,
34
+ _functionName,
35
+ DataCubeGetBaseQueryResult,
36
+ DataCubeEngine,
37
+ type CompletionItem,
38
+ DataCubeQuerySource,
39
+ type DataCubeInfrastructureInfo,
40
+ type RelationType,
41
+ DataCubeQuery,
42
+ } from '@finos/legend-data-cube';
43
+ import { guaranteeType, LogService } from '@finos/legend-shared';
44
+
45
+ export class _DataCubeQuery {
46
+ name: string;
47
+ query: string;
48
+ partialQuery: string;
49
+ source: DataCubeQuerySource;
50
+
51
+ constructor(
52
+ name: string,
53
+ query: string,
54
+ partialQuery: string,
55
+ source: DataCubeQuerySource,
56
+ ) {
57
+ this.name = name;
58
+ this.query = query;
59
+ this.partialQuery = partialQuery;
60
+ this.source = source;
61
+ }
62
+ }
63
+
64
+ export class QueryBuilderDataCubeQuerySource extends DataCubeQuerySource {}
65
+ export class QueryBuilderDataCubeEngine extends DataCubeEngine {
66
+ readonly logService = new LogService();
67
+ readonly graphState: GraphManagerState;
68
+ readonly selectInitialQuery: RawLambda;
69
+ readonly mappingPath: string | undefined;
70
+ readonly runtimePath: string;
71
+ constructor(
72
+ selectQuery: RawLambda,
73
+ mappingPath: string | undefined,
74
+ runtimePath: string,
75
+ graphManagerState: GraphManagerState,
76
+ ) {
77
+ super();
78
+ this.graphState = graphManagerState;
79
+ this.selectInitialQuery = selectQuery;
80
+ this.mappingPath = mappingPath;
81
+ this.runtimePath = runtimePath;
82
+ }
83
+
84
+ get sourceLabel(): string {
85
+ return `Query Builder Report`;
86
+ }
87
+ override getBaseQuery(): Promise<DataCubeGetBaseQueryResult> {
88
+ return this.buildBaseQuery();
89
+ }
90
+
91
+ async buildBaseQuery(): Promise<DataCubeGetBaseQueryResult> {
92
+ const timestamp = Date.now();
93
+ let srcFuncExp = V1_deserializeValueSpecification(
94
+ this.graphState.graphManager.serializeRawValueSpecification(
95
+ this.selectInitialQuery,
96
+ ),
97
+ [],
98
+ );
99
+ // We could do a further check here to ensure the experssion is an applied funciton
100
+ // this is because data cube expects an expression to be able to built further upon the queery
101
+ if (
102
+ srcFuncExp instanceof V1_Lambda &&
103
+ srcFuncExp.body.length === 1 &&
104
+ srcFuncExp.body[0]
105
+ ) {
106
+ srcFuncExp = srcFuncExp.body[0];
107
+ }
108
+ const fromFuncExp = new V1_AppliedFunction();
109
+ fromFuncExp.function = _functionName(SUPPORTED_FUNCTIONS.FROM);
110
+ fromFuncExp.parameters = [srcFuncExp];
111
+ if (this.mappingPath) {
112
+ fromFuncExp.parameters.push(_elementPtr(this.mappingPath));
113
+ }
114
+ if (this.runtimePath) {
115
+ fromFuncExp.parameters.push(_elementPtr(this.runtimePath));
116
+ }
117
+ const [relationType, queryString, fromQuerystring] = await Promise.all([
118
+ this.getRelationalType(this.selectInitialQuery),
119
+ this.graphState.graphManager.valueSpecificationToPureCode(
120
+ V1_serializeValueSpecification(srcFuncExp, []),
121
+ ),
122
+ this.graphState.graphManager.valueSpecificationToPureCode(
123
+ V1_serializeValueSpecification(fromFuncExp, []),
124
+ ),
125
+ ]);
126
+ const columns = relationType.columns;
127
+ const source = new QueryBuilderDataCubeQuerySource();
128
+ source.columns = columns;
129
+ source.mapping = this.mappingPath;
130
+ source.runtime = this.runtimePath;
131
+ source.query = queryString;
132
+ const partialQuery = `~[${columns.map((e) => `'${e.name}'`)}]->select()`;
133
+ const result = new DataCubeQuery(this.sourceLabel, fromQuerystring);
134
+ result.partialQuery = partialQuery;
135
+ result.source = source;
136
+ const baseQueryResult = new DataCubeGetBaseQueryResult();
137
+ baseQueryResult.timestamp = timestamp;
138
+ baseQueryResult.query = result;
139
+ baseQueryResult.partialQuery = await this.parseQuery(partialQuery);
140
+ baseQueryResult.sourceQuery = srcFuncExp;
141
+ return baseQueryResult;
142
+ }
143
+
144
+ get graph(): PureModel {
145
+ return this.graphState.graph;
146
+ }
147
+
148
+ private buildRawLambdaFromValueSpec(query: V1_ValueSpecification): RawLambda {
149
+ const json = guaranteeType(
150
+ V1_deserializeRawValueSpecification(
151
+ V1_serializeValueSpecification(query, []),
152
+ ),
153
+ V1_RawLambda,
154
+ );
155
+ return new RawLambda(json.parameters, json.body);
156
+ }
157
+
158
+ override getInfrastructureInfo(): Promise<DataCubeInfrastructureInfo> {
159
+ // we return undefined as we assume the grid license is set at the application level where query builder is built
160
+ return Promise.resolve({
161
+ gridClientLicense: undefined,
162
+ });
163
+ }
164
+ override async getQueryTypeahead(
165
+ code: string,
166
+ query: V1_ValueSpecification,
167
+ ): Promise<CompletionItem[]> {
168
+ const lambda = this.buildRawLambdaFromValueSpec(query);
169
+ const queryString =
170
+ await this.graphState.graphManager.lambdaToPureCode(lambda);
171
+ const offset = queryString.length;
172
+ const codeBlock = queryString + code;
173
+ const result = await this.graphState.graphManager.getCodeComplete(
174
+ codeBlock,
175
+ this.graph,
176
+ offset,
177
+ );
178
+ return result.completions;
179
+ }
180
+
181
+ override async parseQuery(
182
+ code: string,
183
+ returnSourceInformation?: boolean,
184
+ ): Promise<V1_ValueSpecification> {
185
+ return V1_deserializeValueSpecification(
186
+ await this.graphState.graphManager.pureCodeToValueSpecification(
187
+ code,
188
+ returnSourceInformation,
189
+ ),
190
+ [],
191
+ );
192
+ }
193
+
194
+ override getQueryRelationType(
195
+ query: V1_ValueSpecification,
196
+ ): Promise<RelationType> {
197
+ const lambda = this.buildRawLambdaFromValueSpec(query);
198
+ return this.getRelationalType(lambda);
199
+ }
200
+
201
+ async getRelationalType(query: RawLambda): Promise<RelationType> {
202
+ const realtion_type =
203
+ await this.graphState.graphManager.getLambdaRelationType(
204
+ query,
205
+ this.graph,
206
+ );
207
+ return realtion_type;
208
+ }
209
+
210
+ override async getQueryCodeRelationReturnType(
211
+ code: string,
212
+ baseQuery: V1_ValueSpecification,
213
+ ): Promise<RelationType> {
214
+ const queryString =
215
+ await this.graphState.graphManager.valueSpecificationToPureCode(
216
+ V1_serializeValueSpecification(baseQuery, []),
217
+ );
218
+ const fullQuery = code + queryString;
219
+ return this.getRelationalType(
220
+ await this.graphState.graphManager.pureCodeToLambda(fullQuery),
221
+ );
222
+ }
223
+
224
+ override async executeQuery(query: V1_Lambda): Promise<{
225
+ result: TDSExecutionResult;
226
+ executedQuery: string;
227
+ executedSQL: string;
228
+ }> {
229
+ const lambda = this.buildRawLambdaFromValueSpec(query);
230
+ const [executionWithMetadata, queryString] = await Promise.all([
231
+ this.graphState.graphManager.runQuery(
232
+ lambda,
233
+ undefined,
234
+ undefined,
235
+ this.graph,
236
+ ),
237
+ this.graphState.graphManager.lambdaToPureCode(lambda),
238
+ ]);
239
+ const expectedTDS = guaranteeType(
240
+ executionWithMetadata.executionResult,
241
+ TDSExecutionResult,
242
+ 'Query returned expected to be of tabular data set',
243
+ );
244
+ const sql = expectedTDS.activities?.[0];
245
+ let sqlString = '### NO SQL FOUND';
246
+ if (sql instanceof RelationalExecutionActivities) {
247
+ sqlString = sql.sql;
248
+ }
249
+ return {
250
+ result: expectedTDS,
251
+ executedQuery: queryString,
252
+ executedSQL: sqlString,
253
+ };
254
+ }
255
+ }
@@ -0,0 +1,41 @@
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 { type DataCubeEngine } from '@finos/legend-data-cube';
18
+ import type { QueryBuilderState } from '../QueryBuilderState.js';
19
+ import { RuntimePointer } from '@finos/legend-graph';
20
+ import { QueryBuilderDataCubeEngine } from './QueryBuilderDataCubeEngine.js';
21
+
22
+ export const createDataCubeEngineFromQueryBuilder = (
23
+ queryBuilderState: QueryBuilderState,
24
+ ): DataCubeEngine | undefined => {
25
+ const runtime =
26
+ queryBuilderState.executionContextState.runtimeValue instanceof
27
+ RuntimePointer
28
+ ? queryBuilderState.executionContextState.runtimeValue.packageableRuntime
29
+ .value.path
30
+ : undefined;
31
+ if (!runtime) {
32
+ return undefined;
33
+ }
34
+ const queryBuilderEngine = new QueryBuilderDataCubeEngine(
35
+ queryBuilderState.buildQuery(),
36
+ queryBuilderState.executionContextState.mapping?.path,
37
+ runtime,
38
+ queryBuilderState.graphManagerState,
39
+ );
40
+ return queryBuilderEngine;
41
+ };
@@ -61,6 +61,7 @@ export abstract class QueryBuilderFetchStructureImplementationState
61
61
  abstract get fetchStructureValidationIssues(): string[];
62
62
  abstract get allValidationIssues(): string[];
63
63
  abstract get fetchLabel(): string;
64
+ abstract get canBeExportedToCube(): boolean;
64
65
 
65
66
  abstract onClassChange(_class: Class | undefined): void;
66
67
  abstract revealCompilationError(compilationError: CompilationError): boolean;
@@ -309,6 +309,10 @@ export class QueryBuilderGraphFetchTreeState
309
309
  return 'Class Properties';
310
310
  }
311
311
 
312
+ override get canBeExportedToCube(): boolean {
313
+ return false;
314
+ }
315
+
312
316
  get usedExplorerTreePropertyNodeIDs(): string[] {
313
317
  if (!this.treeData) {
314
318
  return [];
@@ -205,6 +205,10 @@ export class QueryBuilderTDSState
205
205
  return 'Columns';
206
206
  }
207
207
 
208
+ override get canBeExportedToCube(): boolean {
209
+ return true;
210
+ }
211
+
208
212
  override get TEMPORARY__showPostFetchStructurePanel(): boolean {
209
213
  return (
210
214
  this.queryBuilderState.filterState.showPanel ||
@@ -27,7 +27,7 @@ import type {
27
27
  export abstract class QueryBuilderFilterOperator implements Hashable {
28
28
  readonly uuid = uuid();
29
29
 
30
- abstract getLabel(): string;
30
+ abstract getLabel(filterConditionState: FilterConditionState): string;
31
31
 
32
32
  abstract isCompatibleWithFilterConditionProperty(
33
33
  filterConditionState: FilterConditionState,
@@ -246,7 +246,6 @@ export class FilterConditionState implements Hashable {
246
246
  constructor(
247
247
  filterState: QueryBuilderFilterState,
248
248
  propertyExpression: AbstractPropertyExpression,
249
- operator?: QueryBuilderFilterOperator,
250
249
  ) {
251
250
  makeObservable(this, {
252
251
  propertyExpressionState: observable,
@@ -272,15 +271,11 @@ export class FilterConditionState implements Hashable {
272
271
  );
273
272
 
274
273
  // operator
275
- if (operator) {
276
- this.operator = operator;
277
- } else {
278
- assertTrue(
279
- this.operators.length !== 0,
280
- `Can't find an operator for property '${this.propertyExpressionState.path}': no operators registered`,
281
- );
282
- this.operator = this.operators[0] as QueryBuilderFilterOperator;
283
- }
274
+ assertTrue(
275
+ this.operators.length !== 0,
276
+ `Can't find an operator for property '${this.propertyExpressionState.path}': no operators registered`,
277
+ );
278
+ this.operator = this.operators[0] as QueryBuilderFilterOperator;
284
279
  this.buildRightConditionValueFromValueSpec(
285
280
  this.operator.getDefaultFilterConditionValue(this),
286
281
  );
@@ -332,7 +332,7 @@ const processFilterTree = (
332
332
  assertTrue(
333
333
  parentLambdaVariableName === variableName,
334
334
  `Can't process ${extractElementNameFromPath(
335
- filterConditionState.operator.getLabel(),
335
+ filterConditionState.operator.getLabel(filterConditionState),
336
336
  )}() expression: expects variable used in lambda body '${variableName}' to match lambda parameter '${parentLambdaVariableName}'`,
337
337
  );
338
338
  filterState.addNodeFromNode(
@@ -46,7 +46,7 @@ export class QueryBuilderFilterOperator_Contain
46
46
  extends QueryBuilderFilterOperator
47
47
  implements Hashable
48
48
  {
49
- getLabel(): string {
49
+ getLabel(filterConditionState: FilterConditionState): string {
50
50
  return 'contains';
51
51
  }
52
52
 
@@ -90,7 +90,9 @@ export class QueryBuilderFilterOperator_Contain
90
90
  }
91
91
  default:
92
92
  throw new UnsupportedOperationError(
93
- `Can't get default value for filter operator '${this.getLabel()}' when the LHS property is of type '${propertyType.path}'`,
93
+ `Can't get default value for filter operator '${this.getLabel(
94
+ filterConditionState,
95
+ )}' when the LHS property is of type '${propertyType.path}'`,
94
96
  );
95
97
  }
96
98
  }
@@ -126,7 +128,7 @@ export class QueryBuilderFilterOperator_Contain
126
128
  }
127
129
 
128
130
  export class QueryBuilderFilterOperator_NotContain extends QueryBuilderFilterOperator_Contain {
129
- override getLabel(): string {
131
+ override getLabel(filterConditionState: FilterConditionState): string {
130
132
  return `doesn't contain`;
131
133
  }
132
134
 
@@ -46,7 +46,7 @@ export class QueryBuilderFilterOperator_EndWith
46
46
  extends QueryBuilderFilterOperator
47
47
  implements Hashable
48
48
  {
49
- getLabel(): string {
49
+ getLabel(filterConditionState: FilterConditionState): string {
50
50
  return 'ends with';
51
51
  }
52
52
 
@@ -90,7 +90,9 @@ export class QueryBuilderFilterOperator_EndWith
90
90
  }
91
91
  default:
92
92
  throw new UnsupportedOperationError(
93
- `Can't get default value for filter operator '${this.getLabel()}' when the LHS property is of type '${propertyType.path}'`,
93
+ `Can't get default value for filter operator '${this.getLabel(
94
+ filterConditionState,
95
+ )}' when the LHS property is of type '${propertyType.path}'`,
94
96
  );
95
97
  }
96
98
  }
@@ -126,7 +128,7 @@ export class QueryBuilderFilterOperator_EndWith
126
128
  }
127
129
 
128
130
  export class QueryBuilderFilterOperator_NotEndWith extends QueryBuilderFilterOperator_EndWith {
129
- override getLabel(): string {
131
+ override getLabel(filterConditionState: FilterConditionState): string {
130
132
  return `doesn't end with`;
131
133
  }
132
134
 
@@ -44,7 +44,7 @@ export class QueryBuilderFilterOperator_Equal
44
44
  extends QueryBuilderFilterOperator
45
45
  implements Hashable
46
46
  {
47
- getLabel(): string {
47
+ getLabel(filterConditionState: FilterConditionState): string {
48
48
  return 'is';
49
49
  }
50
50
 
@@ -143,7 +143,7 @@ export class QueryBuilderFilterOperator_Equal
143
143
  }
144
144
 
145
145
  export class QueryBuilderFilterOperator_NotEqual extends QueryBuilderFilterOperator_Equal {
146
- override getLabel(): string {
146
+ override getLabel(filterConditionState: FilterConditionState): string {
147
147
  return `is not`;
148
148
  }
149
149