@finos/legend-application-data-cube 0.3.0 → 0.3.2

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 (31) hide show
  1. package/lib/components/builder/LegendDataCubeCreator.d.ts.map +1 -1
  2. package/lib/components/builder/LegendDataCubeCreator.js +5 -1
  3. package/lib/components/builder/LegendDataCubeCreator.js.map +1 -1
  4. package/lib/components/builder/source/UserDefinedFunctionDataCubeSourceBuilder.d.ts +46 -0
  5. package/lib/components/builder/source/UserDefinedFunctionDataCubeSourceBuilder.d.ts.map +1 -0
  6. package/lib/components/builder/source/UserDefinedFunctionDataCubeSourceBuilder.js +203 -0
  7. package/lib/components/builder/source/UserDefinedFunctionDataCubeSourceBuilder.js.map +1 -0
  8. package/lib/index.css +1 -1
  9. package/lib/package.json +5 -5
  10. package/lib/stores/LegendDataCubeDataCubeEngine.d.ts.map +1 -1
  11. package/lib/stores/LegendDataCubeDataCubeEngine.js +25 -2
  12. package/lib/stores/LegendDataCubeDataCubeEngine.js.map +1 -1
  13. package/lib/stores/builder/LegendDataCubeCreatorState.d.ts.map +1 -1
  14. package/lib/stores/builder/LegendDataCubeCreatorState.js +3 -0
  15. package/lib/stores/builder/LegendDataCubeCreatorState.js.map +1 -1
  16. package/lib/stores/builder/source/LegendDataCubeSourceBuilderState.d.ts +2 -1
  17. package/lib/stores/builder/source/LegendDataCubeSourceBuilderState.d.ts.map +1 -1
  18. package/lib/stores/builder/source/LegendDataCubeSourceBuilderState.js +1 -0
  19. package/lib/stores/builder/source/LegendDataCubeSourceBuilderState.js.map +1 -1
  20. package/lib/stores/builder/source/UserDefinedFunctionDataCubeSourceBuilderState.d.ts +50 -0
  21. package/lib/stores/builder/source/UserDefinedFunctionDataCubeSourceBuilderState.d.ts.map +1 -0
  22. package/lib/stores/builder/source/UserDefinedFunctionDataCubeSourceBuilderState.js +120 -0
  23. package/lib/stores/builder/source/UserDefinedFunctionDataCubeSourceBuilderState.js.map +1 -0
  24. package/package.json +15 -15
  25. package/src/components/builder/LegendDataCubeCreator.tsx +10 -0
  26. package/src/components/builder/source/UserDefinedFunctionDataCubeSourceBuilder.tsx +373 -0
  27. package/src/stores/LegendDataCubeDataCubeEngine.ts +56 -0
  28. package/src/stores/builder/LegendDataCubeCreatorState.tsx +7 -0
  29. package/src/stores/builder/source/LegendDataCubeSourceBuilderState.ts +1 -0
  30. package/src/stores/builder/source/UserDefinedFunctionDataCubeSourceBuilderState.ts +176 -0
  31. package/tsconfig.json +2 -0
@@ -79,6 +79,9 @@ import {
79
79
  V1_TinyInt,
80
80
  V1_SmallInt,
81
81
  V1_serializePureModelContextData,
82
+ V1_deserializePureModelContext,
83
+ type V1_ConcreteFunctionDefinition,
84
+ V1_deserializeValueSpecification,
82
85
  } from '@finos/legend-graph';
83
86
  import {
84
87
  _elementPtr,
@@ -96,6 +99,8 @@ import {
96
99
  type DataCubeExecutionOptions,
97
100
  type DataCubeCacheInitializationOptions,
98
101
  DataCubeExecutionError,
102
+ RawUserDefinedFunctionDataCubeSource,
103
+ ADHOC_FUNCTION_DATA_CUBE_SOURCE_TYPE,
99
104
  } from '@finos/legend-data-cube';
100
105
  import {
101
106
  isNonNullable,
@@ -223,6 +228,57 @@ export class LegendDataCubeDataCubeEngine extends DataCubeEngine {
223
228
  }
224
229
  return source;
225
230
  }
231
+ case ADHOC_FUNCTION_DATA_CUBE_SOURCE_TYPE: {
232
+ const rawSource =
233
+ RawUserDefinedFunctionDataCubeSource.serialization.fromJson(value);
234
+ const deserializedModel = V1_deserializePureModelContext(
235
+ rawSource.model,
236
+ );
237
+
238
+ if (
239
+ rawSource.runtime === undefined ||
240
+ !(deserializedModel instanceof V1_PureModelContextPointer)
241
+ ) {
242
+ throw new Error(
243
+ `Unsupported user defined function source. Runtime is needed and model must be a pointer.`,
244
+ );
245
+ }
246
+
247
+ const source = new AdhocQueryDataCubeSource();
248
+ source.runtime = rawSource.runtime;
249
+ source.model = rawSource.model;
250
+ if (deserializedModel.sdlcInfo instanceof V1_LegendSDLC) {
251
+ const sdlcInfo = deserializedModel.sdlcInfo;
252
+ const fetchedFunction =
253
+ await this._depotServerClient.getVersionEntity(
254
+ sdlcInfo.groupId,
255
+ sdlcInfo.artifactId,
256
+ sdlcInfo.version,
257
+ rawSource.functionPath,
258
+ );
259
+ const functionContent =
260
+ fetchedFunction.content as V1_ConcreteFunctionDefinition;
261
+
262
+ //TODO add support for parameters
263
+ if (functionContent.body.length > 1) {
264
+ throw new Error(
265
+ `Unsupported user defined function source. Functions with parameters are not yet supported.`,
266
+ );
267
+ }
268
+
269
+ source.query = V1_deserializeValueSpecification(
270
+ functionContent.body[0] as PlainObject,
271
+ this._application.pluginManager.getPureProtocolProcessorPlugins(),
272
+ );
273
+ source.columns = (
274
+ await this._getLambdaRelationType(
275
+ this.serializeValueSpecification(_lambda([], [source.query])),
276
+ source.model,
277
+ )
278
+ ).columns;
279
+ }
280
+ return source;
281
+ }
226
282
  case LEGEND_QUERY_DATA_CUBE_SOURCE_TYPE: {
227
283
  const rawSource =
228
284
  RawLegendQueryDataCubeSource.serialization.fromJson(value);
@@ -42,6 +42,7 @@ import {
42
42
  } from './LegendDataCubeBuilderStore.js';
43
43
  import { generateBuilderRoute } from '../../__lib__/LegendDataCubeNavigation.js';
44
44
  import { LocalFileDataCubeSourceBuilderState } from './source/LocalFileDataCubeSourceBuilderState.js';
45
+ import { UserDefinedFunctionDataCubeSourceBuilderState } from './source/UserDefinedFunctionDataCubeSourceBuilderState.js';
45
46
 
46
47
  const DEFAULT_SOURCE_TYPE = LegendDataCubeSourceBuilderType.LEGEND_QUERY;
47
48
 
@@ -111,6 +112,12 @@ export class LegendDataCubeCreatorState {
111
112
  this._application,
112
113
  this._engine,
113
114
  );
115
+ case LegendDataCubeSourceBuilderType.USER_DEFINED_FUNCTION:
116
+ return new UserDefinedFunctionDataCubeSourceBuilderState(
117
+ this._application,
118
+ this._engine,
119
+ this._store,
120
+ );
114
121
  default:
115
122
  throw new UnsupportedOperationError(
116
123
  `Can't create source builder for unsupported type '${type}'`,
@@ -23,6 +23,7 @@ export enum LegendDataCubeSourceBuilderType {
23
23
  LEGEND_QUERY = 'Legend Query',
24
24
  ADHOC_QUERY = 'Ad hoc Query',
25
25
  LOCAL_FILE = 'Local File',
26
+ USER_DEFINED_FUNCTION = 'User Defined Function',
26
27
  }
27
28
 
28
29
  export abstract class LegendDataCubeSourceBuilderState {
@@ -0,0 +1,176 @@
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
+ ActionState,
19
+ IllegalStateError,
20
+ assertErrorThrown,
21
+ type PlainObject,
22
+ } from '@finos/legend-shared';
23
+ import {
24
+ LegendDataCubeSourceBuilderState,
25
+ LegendDataCubeSourceBuilderType,
26
+ } from './LegendDataCubeSourceBuilderState.js';
27
+ import { StoreProjectData } from '@finos/legend-server-depot';
28
+ import type { LegendDataCubeBuilderStore } from '../LegendDataCubeBuilderStore.js';
29
+ import type { LegendDataCubeDataCubeEngine } from '../../LegendDataCubeDataCubeEngine.js';
30
+ import type { LegendDataCubeApplicationStore } from '../../LegendDataCubeBaseStore.js';
31
+ import { action, flow, makeObservable, observable, runInAction } from 'mobx';
32
+ import {
33
+ V1_LegendSDLC,
34
+ type V1_PackageableRuntime,
35
+ V1_PureModelContextPointer,
36
+ V1_serializePureModelContext,
37
+ type V1_ConcreteFunctionDefinition,
38
+ } from '@finos/legend-graph';
39
+ import {
40
+ type DataCubeConfiguration,
41
+ RawUserDefinedFunctionDataCubeSource,
42
+ } from '@finos/legend-data-cube';
43
+
44
+ export class UserDefinedFunctionDataCubeSourceBuilderState extends LegendDataCubeSourceBuilderState {
45
+ projects: StoreProjectData[] = [];
46
+ currentProject?: StoreProjectData | undefined;
47
+ currentProjectVersions?: string[] | undefined;
48
+ currentVersionId?: string | undefined;
49
+ builderStore: LegendDataCubeBuilderStore;
50
+ functions: V1_ConcreteFunctionDefinition[] | undefined;
51
+ currentFunction?: V1_ConcreteFunctionDefinition | undefined;
52
+ currentRuntime?: V1_PackageableRuntime | undefined;
53
+ runtimes?: V1_PackageableRuntime[] | undefined;
54
+
55
+ readonly loadProjectsState = ActionState.create();
56
+
57
+ constructor(
58
+ application: LegendDataCubeApplicationStore,
59
+ engine: LegendDataCubeDataCubeEngine,
60
+ builderStore: LegendDataCubeBuilderStore,
61
+ ) {
62
+ super(application, engine);
63
+ this.builderStore = builderStore;
64
+
65
+ makeObservable(this, {
66
+ loadProjects: flow,
67
+ currentFunction: observable,
68
+ projects: observable,
69
+ currentProject: observable,
70
+ currentProjectVersions: observable,
71
+ currentVersionId: observable,
72
+ currentRuntime: observable,
73
+ setCurrentProject: action,
74
+ setCurrentProjectVersions: action,
75
+ setCurrentVersionId: action,
76
+ setCurrentRuntime: action,
77
+ });
78
+ }
79
+
80
+ setCurrentProject(val: StoreProjectData | undefined): void {
81
+ this.currentProject = val;
82
+ }
83
+
84
+ setCurrentProjectVersions(val: string[] | undefined): void {
85
+ this.currentProjectVersions = val;
86
+ }
87
+
88
+ setCurrentVersionId(val: string | undefined): void {
89
+ this.currentVersionId = val;
90
+ }
91
+
92
+ getProjects(): StoreProjectData[] {
93
+ return this.projects;
94
+ }
95
+
96
+ setFunctions(val: V1_ConcreteFunctionDefinition[] | undefined): void {
97
+ this.functions = val;
98
+ }
99
+
100
+ setCurrentFunction(val: V1_ConcreteFunctionDefinition | undefined): void {
101
+ runInAction(() => {
102
+ this.currentFunction = val;
103
+ });
104
+ }
105
+
106
+ setCurrentRuntime(val: V1_PackageableRuntime | undefined): void {
107
+ this.currentRuntime = val;
108
+ }
109
+
110
+ setRuntimes(val: V1_PackageableRuntime[] | undefined): void {
111
+ this.runtimes = val;
112
+ }
113
+
114
+ *loadProjects() {
115
+ this.loadProjectsState.inProgress();
116
+ try {
117
+ this.projects = (
118
+ (yield this.builderStore.depotServerClient.getProjects()) as PlainObject<StoreProjectData>[]
119
+ ).map((v) => StoreProjectData.serialization.fromJson(v));
120
+ this.loadProjectsState.pass();
121
+ } catch (error) {
122
+ assertErrorThrown(error);
123
+ this.builderStore.application.notificationService.notifyError(error);
124
+ this.loadProjectsState.fail();
125
+ }
126
+ }
127
+
128
+ override get label(): LegendDataCubeSourceBuilderType {
129
+ return LegendDataCubeSourceBuilderType.USER_DEFINED_FUNCTION;
130
+ }
131
+
132
+ override get isValid(): boolean {
133
+ return Boolean(
134
+ this.currentFunction &&
135
+ this.currentRuntime &&
136
+ this.currentProject &&
137
+ this.currentVersionId,
138
+ );
139
+ }
140
+
141
+ override async generateSourceData(): Promise<PlainObject> {
142
+ if (!this.isValid) {
143
+ throw new IllegalStateError(
144
+ `Can't generate source data: project, version, function, or runtime are not set`,
145
+ );
146
+ }
147
+
148
+ const source = new RawUserDefinedFunctionDataCubeSource();
149
+ if (
150
+ this.currentProject &&
151
+ this.currentVersionId &&
152
+ this.currentRuntime &&
153
+ this.currentFunction
154
+ ) {
155
+ source.functionPath = this.currentFunction.path;
156
+ source.runtime = this.currentRuntime.path;
157
+ const sdlc = new V1_LegendSDLC(
158
+ this.currentProject.groupId,
159
+ this.currentProject.artifactId,
160
+ this.currentVersionId,
161
+ );
162
+ const modelContextPointer = new V1_PureModelContextPointer(
163
+ undefined,
164
+ sdlc,
165
+ );
166
+ source.model = V1_serializePureModelContext(modelContextPointer);
167
+ }
168
+ return RawUserDefinedFunctionDataCubeSource.serialization.toJson(source);
169
+ }
170
+
171
+ override finalizeConfiguration(configuration: DataCubeConfiguration) {
172
+ if (this.currentFunction) {
173
+ configuration.name = this.currentFunction.name;
174
+ }
175
+ }
176
+ }
package/tsconfig.json CHANGED
@@ -68,6 +68,7 @@
68
68
  "./src/stores/builder/source/LegendDataCubeSourceBuilderState.ts",
69
69
  "./src/stores/builder/source/LegendQueryDataCubeSourceBuilderState.ts",
70
70
  "./src/stores/builder/source/LocalFileDataCubeSourceBuilderState.ts",
71
+ "./src/stores/builder/source/UserDefinedFunctionDataCubeSourceBuilderState.ts",
71
72
  "./src/stores/model/LegendQueryDataCubeSource.ts",
72
73
  "./src/stores/model/LocalFileDataCubeSource.ts",
73
74
  "./src/application/LegendDataCube.tsx",
@@ -84,6 +85,7 @@
84
85
  "./src/components/builder/source/AdhocQueryDataCubeSourceBuilder.tsx",
85
86
  "./src/components/builder/source/LegendQueryDataCubeSourceBuilder.tsx",
86
87
  "./src/components/builder/source/LocalFileDataCubeSourceBuilder.tsx",
88
+ "./src/components/builder/source/UserDefinedFunctionDataCubeSourceBuilder.tsx",
87
89
  "./src/stores/builder/LegendDataCubeBuilderStore.tsx",
88
90
  "./src/stores/builder/LegendDataCubeCreatorState.tsx",
89
91
  "./src/stores/builder/LegendDataCubeLoaderState.tsx"