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

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 (112) hide show
  1. package/lib/__lib__/LegendDataCubeNavigation.d.ts +2 -0
  2. package/lib/__lib__/LegendDataCubeNavigation.d.ts.map +1 -1
  3. package/lib/__lib__/LegendDataCubeNavigation.js +2 -0
  4. package/lib/__lib__/LegendDataCubeNavigation.js.map +1 -1
  5. package/lib/application/LegendDataCubeApplicationConfig.d.ts +4 -0
  6. package/lib/application/LegendDataCubeApplicationConfig.d.ts.map +1 -1
  7. package/lib/application/LegendDataCubeApplicationConfig.js +5 -0
  8. package/lib/application/LegendDataCubeApplicationConfig.js.map +1 -1
  9. package/lib/application/__test-utils__/LegendDataCubeApplicationTestUtils.d.ts +18 -0
  10. package/lib/application/__test-utils__/LegendDataCubeApplicationTestUtils.d.ts.map +1 -0
  11. package/lib/application/__test-utils__/LegendDataCubeApplicationTestUtils.js +48 -0
  12. package/lib/application/__test-utils__/LegendDataCubeApplicationTestUtils.js.map +1 -0
  13. package/lib/components/LegendDataCubeBlockingWindow.d.ts +2 -1
  14. package/lib/components/LegendDataCubeBlockingWindow.d.ts.map +1 -1
  15. package/lib/components/LegendDataCubeBlockingWindow.js +8 -3
  16. package/lib/components/LegendDataCubeBlockingWindow.js.map +1 -1
  17. package/lib/components/__test-utils__/LegendDataCubeStoreTestUtils.d.ts +42 -0
  18. package/lib/components/__test-utils__/LegendDataCubeStoreTestUtils.d.ts.map +1 -0
  19. package/lib/components/__test-utils__/LegendDataCubeStoreTestUtils.js +104 -0
  20. package/lib/components/__test-utils__/LegendDataCubeStoreTestUtils.js.map +1 -0
  21. package/lib/components/builder/LegendDataCubeBuilder.d.ts +5 -0
  22. package/lib/components/builder/LegendDataCubeBuilder.d.ts.map +1 -1
  23. package/lib/components/builder/LegendDataCubeBuilder.js +26 -5
  24. package/lib/components/builder/LegendDataCubeBuilder.js.map +1 -1
  25. package/lib/components/builder/LegendDataCubeBuilderStoreProvider.d.ts.map +1 -1
  26. package/lib/components/builder/LegendDataCubeBuilderStoreProvider.js +1 -1
  27. package/lib/components/builder/LegendDataCubeBuilderStoreProvider.js.map +1 -1
  28. package/lib/components/builder/LegendDataCubePartialSourceLoader.d.ts +19 -0
  29. package/lib/components/builder/LegendDataCubePartialSourceLoader.d.ts.map +1 -0
  30. package/lib/components/builder/LegendDataCubePartialSourceLoader.js +50 -0
  31. package/lib/components/builder/LegendDataCubePartialSourceLoader.js.map +1 -0
  32. package/lib/components/builder/LegendDataCubeSourceViewer.d.ts.map +1 -1
  33. package/lib/components/builder/LegendDataCubeSourceViewer.js +61 -1
  34. package/lib/components/builder/LegendDataCubeSourceViewer.js.map +1 -1
  35. package/lib/components/builder/source/LocalFileDataCubeSourceBuilder.d.ts.map +1 -1
  36. package/lib/components/builder/source/LocalFileDataCubeSourceBuilder.js +1 -2
  37. package/lib/components/builder/source/LocalFileDataCubeSourceBuilder.js.map +1 -1
  38. package/lib/components/builder/source/loader/LocalFileDataCubePartialSourceLoader.d.ts +22 -0
  39. package/lib/components/builder/source/loader/LocalFileDataCubePartialSourceLoader.d.ts.map +1 -0
  40. package/lib/components/builder/source/loader/LocalFileDataCubePartialSourceLoader.js +28 -0
  41. package/lib/components/builder/source/loader/LocalFileDataCubePartialSourceLoader.js.map +1 -0
  42. package/lib/index.css +2 -2
  43. package/lib/index.css.map +1 -1
  44. package/lib/package.json +3 -1
  45. package/lib/stores/LegendDataCubeBaseStore.d.ts +2 -1
  46. package/lib/stores/LegendDataCubeBaseStore.d.ts.map +1 -1
  47. package/lib/stores/LegendDataCubeBaseStore.js +6 -3
  48. package/lib/stores/LegendDataCubeBaseStore.js.map +1 -1
  49. package/lib/stores/LegendDataCubeDataCubeEngine.d.ts +6 -3
  50. package/lib/stores/LegendDataCubeDataCubeEngine.d.ts.map +1 -1
  51. package/lib/stores/LegendDataCubeDataCubeEngine.js +127 -106
  52. package/lib/stores/LegendDataCubeDataCubeEngine.js.map +1 -1
  53. package/lib/stores/LegendDataCubeDuckDBEngine.d.ts +11 -4
  54. package/lib/stores/LegendDataCubeDuckDBEngine.d.ts.map +1 -1
  55. package/lib/stores/LegendDataCubeDuckDBEngine.js +83 -16
  56. package/lib/stores/LegendDataCubeDuckDBEngine.js.map +1 -1
  57. package/lib/stores/builder/LegendDataCubeBuilderStore.d.ts +4 -0
  58. package/lib/stores/builder/LegendDataCubeBuilderStore.d.ts.map +1 -1
  59. package/lib/stores/builder/LegendDataCubeBuilderStore.js +58 -17
  60. package/lib/stores/builder/LegendDataCubeBuilderStore.js.map +1 -1
  61. package/lib/stores/builder/LegendDataCubeLoaderState.d.ts +11 -2
  62. package/lib/stores/builder/LegendDataCubeLoaderState.d.ts.map +1 -1
  63. package/lib/stores/builder/LegendDataCubeLoaderState.js +28 -1
  64. package/lib/stores/builder/LegendDataCubeLoaderState.js.map +1 -1
  65. package/lib/stores/builder/LegendDataCubeSourceLoaderState.d.ts +44 -0
  66. package/lib/stores/builder/LegendDataCubeSourceLoaderState.d.ts.map +1 -0
  67. package/lib/stores/builder/LegendDataCubeSourceLoaderState.js +101 -0
  68. package/lib/stores/builder/LegendDataCubeSourceLoaderState.js.map +1 -0
  69. package/lib/stores/builder/source/LocalFileDataCubeSourceBuilderState.d.ts +3 -2
  70. package/lib/stores/builder/source/LocalFileDataCubeSourceBuilderState.d.ts.map +1 -1
  71. package/lib/stores/builder/source/LocalFileDataCubeSourceBuilderState.js +7 -10
  72. package/lib/stores/builder/source/LocalFileDataCubeSourceBuilderState.js.map +1 -1
  73. package/lib/stores/builder/source/loader/LegendDataCubePartialSourceLoaderState.d.ts +29 -0
  74. package/lib/stores/builder/source/loader/LegendDataCubePartialSourceLoaderState.d.ts.map +1 -0
  75. package/lib/stores/builder/source/loader/LegendDataCubePartialSourceLoaderState.js +25 -0
  76. package/lib/stores/builder/source/loader/LegendDataCubePartialSourceLoaderState.js.map +1 -0
  77. package/lib/stores/builder/source/loader/LocalFileDataCubePartialSourceLoaderState.d.ts +43 -0
  78. package/lib/stores/builder/source/loader/LocalFileDataCubePartialSourceLoaderState.d.ts.map +1 -0
  79. package/lib/stores/builder/source/loader/LocalFileDataCubePartialSourceLoaderState.js +142 -0
  80. package/lib/stores/builder/source/loader/LocalFileDataCubePartialSourceLoaderState.js.map +1 -0
  81. package/lib/stores/model/LegendQueryDataCubeSource.d.ts +2 -1
  82. package/lib/stores/model/LegendQueryDataCubeSource.d.ts.map +1 -1
  83. package/lib/stores/model/LegendQueryDataCubeSource.js +1 -0
  84. package/lib/stores/model/LegendQueryDataCubeSource.js.map +1 -1
  85. package/lib/stores/model/LocalFileDataCubeSource.d.ts +3 -8
  86. package/lib/stores/model/LocalFileDataCubeSource.d.ts.map +1 -1
  87. package/lib/stores/model/LocalFileDataCubeSource.js +5 -15
  88. package/lib/stores/model/LocalFileDataCubeSource.js.map +1 -1
  89. package/package.json +13 -11
  90. package/src/__lib__/LegendDataCubeNavigation.ts +21 -0
  91. package/src/application/LegendDataCubeApplicationConfig.ts +10 -0
  92. package/src/application/__test-utils__/LegendDataCubeApplicationTestUtils.ts +52 -0
  93. package/src/components/LegendDataCubeBlockingWindow.tsx +8 -2
  94. package/src/components/__test-utils__/LegendDataCubeStoreTestUtils.tsx +231 -0
  95. package/src/components/builder/LegendDataCubeBuilder.tsx +51 -6
  96. package/src/components/builder/LegendDataCubeBuilderStoreProvider.tsx +3 -0
  97. package/src/components/builder/LegendDataCubePartialSourceLoader.tsx +108 -0
  98. package/src/components/builder/LegendDataCubeSourceViewer.tsx +171 -1
  99. package/src/components/builder/source/LocalFileDataCubeSourceBuilder.tsx +1 -2
  100. package/src/components/builder/source/loader/LocalFileDataCubePartialSourceLoader.tsx +60 -0
  101. package/src/stores/LegendDataCubeBaseStore.ts +13 -6
  102. package/src/stores/LegendDataCubeDataCubeEngine.ts +161 -120
  103. package/src/stores/LegendDataCubeDuckDBEngine.ts +101 -17
  104. package/src/stores/builder/LegendDataCubeBuilderStore.tsx +96 -24
  105. package/src/stores/builder/LegendDataCubeLoaderState.tsx +44 -1
  106. package/src/stores/builder/LegendDataCubeSourceLoaderState.tsx +145 -0
  107. package/src/stores/builder/source/LocalFileDataCubeSourceBuilderState.ts +9 -14
  108. package/src/stores/builder/source/loader/LegendDataCubePartialSourceLoaderState.ts +41 -0
  109. package/src/stores/builder/source/loader/LocalFileDataCubePartialSourceLoaderState.ts +217 -0
  110. package/src/stores/model/LegendQueryDataCubeSource.ts +2 -0
  111. package/src/stores/model/LocalFileDataCubeSource.ts +6 -15
  112. package/tsconfig.json +8 -1
@@ -0,0 +1,217 @@
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
+ csvStringify,
20
+ guaranteeNonNullable,
21
+ IllegalStateError,
22
+ parseCSVFile,
23
+ type PlainObject,
24
+ } from '@finos/legend-shared';
25
+ import { makeObservable, observable, action } from 'mobx';
26
+ import type { LegendDataCubeApplicationStore } from '../../../LegendDataCubeBaseStore.js';
27
+ import type { LegendDataCubeDataCubeEngine } from '../../../LegendDataCubeDataCubeEngine.js';
28
+ import {
29
+ LocalFileDataCubeSourceFormat,
30
+ RawLocalFileQueryDataCubeSource,
31
+ } from '../../../model/LocalFileDataCubeSource.js';
32
+ import { LegendDataCubePartialSourceLoaderState } from './LegendDataCubePartialSourceLoaderState.js';
33
+ import { LegendDataCubeSourceLoaderType } from '../../LegendDataCubeSourceLoaderState.js';
34
+
35
+ export class LocalFileDataCubePartialSourceLoaderState extends LegendDataCubePartialSourceLoaderState {
36
+ readonly processState = ActionState.create();
37
+
38
+ fileName?: string | undefined;
39
+ fileFormat?: LocalFileDataCubeSourceFormat | undefined;
40
+ // NOTE: type string is suitable for CSV/Excel, etc. but will not be appropriate
41
+ // for other format that we want to support, e.g. arrow/parquet
42
+ fileData?: string | undefined;
43
+ previewText?: string | undefined;
44
+ rowCount?: number | undefined;
45
+ columnNames?: string[] | undefined;
46
+
47
+ constructor(
48
+ application: LegendDataCubeApplicationStore,
49
+ engine: LegendDataCubeDataCubeEngine,
50
+ ) {
51
+ super(application, engine);
52
+
53
+ makeObservable(this, {
54
+ fileName: observable,
55
+ setFileName: action,
56
+
57
+ columnNames: observable,
58
+ setColumnNames: action,
59
+
60
+ fileFormat: observable,
61
+ setFileFormat: action,
62
+
63
+ fileData: observable,
64
+ setFileData: action,
65
+
66
+ previewText: observable,
67
+ setPreviewText: action,
68
+
69
+ rowCount: observable,
70
+ setRowCount: action,
71
+ });
72
+ }
73
+
74
+ setFileName(fileName: string | undefined) {
75
+ this.fileName = fileName;
76
+ }
77
+
78
+ setColumnNames(columnNames: string[] | undefined) {
79
+ this.columnNames = columnNames;
80
+ }
81
+
82
+ setFileFormat(format: LocalFileDataCubeSourceFormat | undefined) {
83
+ this.fileFormat = format;
84
+ }
85
+
86
+ setFileData(data: string | undefined) {
87
+ this.fileData = data;
88
+ }
89
+
90
+ setRowCount(count: number | undefined) {
91
+ this.rowCount = count;
92
+ }
93
+
94
+ setPreviewText(text: string | undefined) {
95
+ this.previewText = text;
96
+ }
97
+
98
+ override initialize(): void {
99
+ this.setFileName(undefined);
100
+ this.setColumnNames(undefined);
101
+ this.setFileFormat(undefined);
102
+ this.setFileData(undefined);
103
+ this.setRowCount(undefined);
104
+ this.setPreviewText(undefined);
105
+ }
106
+
107
+ processFile(file: File | undefined) {
108
+ this.setFileName(undefined);
109
+ this.setColumnNames(undefined);
110
+ this.setFileFormat(undefined);
111
+ this.setFileData(undefined);
112
+ this.setRowCount(undefined);
113
+ this.setPreviewText(undefined);
114
+
115
+ if (!file) {
116
+ return;
117
+ }
118
+
119
+ this.processState.inProgress();
120
+
121
+ const fileName = file.name;
122
+ const fileFormat = fileName.split('.').pop();
123
+
124
+ switch (fileFormat?.toLowerCase()) {
125
+ case LocalFileDataCubeSourceFormat.CSV.toLowerCase(): {
126
+ parseCSVFile(file, {
127
+ complete: (result) => {
128
+ this.setFileData(
129
+ csvStringify(result.data, { escapeChar: `'`, quoteChar: `'` }),
130
+ );
131
+ this.setColumnNames(
132
+ Object.keys(result.data.at(0) as object).filter(
133
+ (key) => key !== '',
134
+ ),
135
+ );
136
+ this.setFileName(fileName);
137
+ this.setFileFormat(LocalFileDataCubeSourceFormat.CSV);
138
+ this.setRowCount(result.data.length);
139
+ this.setPreviewText(
140
+ csvStringify(result.data.slice(0, 100), {
141
+ escapeChar: `'`,
142
+ quoteChar: `'`,
143
+ }),
144
+ );
145
+ },
146
+ header: true,
147
+ dynamicTyping: false,
148
+ skipEmptyLines: true,
149
+ });
150
+ break;
151
+ }
152
+ default: {
153
+ this.processState.complete();
154
+ throw new IllegalStateError(
155
+ `Can't process file with format '${fileFormat}'`,
156
+ );
157
+ }
158
+ }
159
+
160
+ this.processState.complete();
161
+ }
162
+
163
+ override get isValid(): boolean {
164
+ return Boolean(this.fileData);
165
+ }
166
+
167
+ override get label(): LegendDataCubeSourceLoaderType {
168
+ return LegendDataCubeSourceLoaderType.LOCAL_FILE;
169
+ }
170
+
171
+ override async load(source: PlainObject | undefined): Promise<PlainObject> {
172
+ const deserializedSource =
173
+ RawLocalFileQueryDataCubeSource.serialization.fromJson(
174
+ guaranteeNonNullable(source),
175
+ );
176
+
177
+ if (
178
+ !this.fileData ||
179
+ !this.fileName ||
180
+ !this.fileFormat ||
181
+ this.rowCount === undefined
182
+ ) {
183
+ throw new IllegalStateError(
184
+ `Can't load source data: file data and information is not set`,
185
+ );
186
+ }
187
+
188
+ const intersectingColumns = guaranteeNonNullable(
189
+ this.columnNames?.filter((col) =>
190
+ deserializedSource.columnNames.includes(col),
191
+ ),
192
+ );
193
+ if (intersectingColumns.length !== deserializedSource.columnNames.length) {
194
+ throw new Error(
195
+ `Columns mismatch: Expected [${deserializedSource.columnNames.join(',')}], got [${this.columnNames?.join(',')}]`,
196
+ );
197
+ }
198
+
199
+ const tableDetails = guaranteeNonNullable(
200
+ await this._engine.ingestLocalFileData(
201
+ this.fileData,
202
+ this.fileFormat,
203
+ deserializedSource._ref,
204
+ ),
205
+ `Can't load source data: failed to ingest data from local file`,
206
+ );
207
+
208
+ // TODO: do a type check for columns
209
+ const rawSource = new RawLocalFileQueryDataCubeSource();
210
+ rawSource.fileName = this.fileName;
211
+ rawSource.fileFormat = this.fileFormat;
212
+ rawSource._ref = tableDetails.dbReference;
213
+ rawSource.columnNames = tableDetails.columnNames;
214
+
215
+ return RawLocalFileQueryDataCubeSource.serialization.toJson(rawSource);
216
+ }
217
+ }
@@ -19,6 +19,7 @@ import type {
19
19
  QueryInfo,
20
20
  V1_Lambda,
21
21
  V1_ParameterValue,
22
+ V1_ValueSpecification,
22
23
  } from '@finos/legend-graph';
23
24
  import {
24
25
  SerializationFactory,
@@ -36,6 +37,7 @@ export class LegendQueryDataCubeSource extends DataCubeSource {
36
37
  runtime!: string;
37
38
  model!: PlainObject;
38
39
  parameterValues: V1_ParameterValue[] = [];
40
+ letParameterValueSpec: V1_ValueSpecification[] = [];
39
41
  }
40
42
 
41
43
  export class RawLegendQueryDataCubeSource {
@@ -15,13 +15,13 @@
15
15
  */
16
16
 
17
17
  import { DataCubeSource } from '@finos/legend-data-cube';
18
- import { type V1_PureModelContextData } from '@finos/legend-graph';
18
+ import type { V1_PureModelContextData } from '@finos/legend-graph';
19
19
  import {
20
20
  SerializationFactory,
21
21
  usingConstantValueSchema,
22
22
  type PlainObject,
23
23
  } from '@finos/legend-shared';
24
- import { createModelSchema, primitive, raw } from 'serializr';
24
+ import { createModelSchema, list, primitive } from 'serializr';
25
25
 
26
26
  export const LOCAL_FILE_QUERY_DATA_CUBE_SOURCE_TYPE = 'localFile';
27
27
 
@@ -36,32 +36,23 @@ export class LocalFileDataCubeSource extends DataCubeSource {
36
36
  db!: string;
37
37
  schema!: string;
38
38
  table!: string;
39
- count!: number;
40
39
  fileName!: string;
41
40
  fileFormat!: LocalFileDataCubeSourceFormat;
42
41
  }
43
42
 
44
43
  export class RawLocalFileQueryDataCubeSource {
45
- model!: PlainObject<V1_PureModelContextData>;
46
- runtime!: string;
47
- db!: string;
48
- schema!: string;
49
- table!: string;
50
- count!: number;
51
44
  fileName!: string;
52
45
  fileFormat!: LocalFileDataCubeSourceFormat;
46
+ _ref!: string;
47
+ columnNames!: string[];
53
48
 
54
49
  static readonly serialization = new SerializationFactory(
55
50
  createModelSchema(RawLocalFileQueryDataCubeSource, {
56
51
  _type: usingConstantValueSchema(LOCAL_FILE_QUERY_DATA_CUBE_SOURCE_TYPE),
57
- count: primitive(),
58
- db: primitive(),
59
52
  fileFormat: primitive(),
60
53
  fileName: primitive(),
61
- model: raw(),
62
- runtime: primitive(),
63
- schema: primitive(),
64
- table: primitive(),
54
+ _ref: primitive(),
55
+ columnNames: list(primitive()),
65
56
  }),
66
57
  );
67
58
  }
package/tsconfig.json CHANGED
@@ -60,6 +60,7 @@
60
60
  "./src/application/LegendDataCubeApplicationConfig.ts",
61
61
  "./src/application/LegendDataCubeApplicationPlugin.ts",
62
62
  "./src/application/LegendDataCubePluginManager.ts",
63
+ "./src/application/__test-utils__/LegendDataCubeApplicationTestUtils.ts",
63
64
  "./src/stores/DuckDBWASM.d.ts",
64
65
  "./src/stores/LegendDataCubeBaseStore.ts",
65
66
  "./src/stores/LegendDataCubeDataCubeEngine.ts",
@@ -69,26 +70,32 @@
69
70
  "./src/stores/builder/source/LegendQueryDataCubeSourceBuilderState.ts",
70
71
  "./src/stores/builder/source/LocalFileDataCubeSourceBuilderState.ts",
71
72
  "./src/stores/builder/source/UserDefinedFunctionDataCubeSourceBuilderState.ts",
73
+ "./src/stores/builder/source/loader/LegendDataCubePartialSourceLoaderState.ts",
74
+ "./src/stores/builder/source/loader/LocalFileDataCubePartialSourceLoaderState.ts",
72
75
  "./src/stores/model/LegendQueryDataCubeSource.ts",
73
76
  "./src/stores/model/LocalFileDataCubeSource.ts",
74
77
  "./src/application/LegendDataCube.tsx",
75
78
  "./src/components/LegendDataCubeBlockingWindow.tsx",
76
79
  "./src/components/LegendDataCubeFrameworkProvider.tsx",
77
80
  "./src/components/LegendDataCubeWebApplication.tsx",
81
+ "./src/components/__test-utils__/LegendDataCubeStoreTestUtils.tsx",
78
82
  "./src/components/builder/LegendDataCubeBuilder.tsx",
79
83
  "./src/components/builder/LegendDataCubeBuilderStoreProvider.tsx",
80
84
  "./src/components/builder/LegendDataCubeCreator.tsx",
81
85
  "./src/components/builder/LegendDataCubeDeleteConfirmation.tsx",
82
86
  "./src/components/builder/LegendDataCubeLoader.tsx",
87
+ "./src/components/builder/LegendDataCubePartialSourceLoader.tsx",
83
88
  "./src/components/builder/LegendDataCubeSaver.tsx",
84
89
  "./src/components/builder/LegendDataCubeSourceViewer.tsx",
85
90
  "./src/components/builder/source/AdhocQueryDataCubeSourceBuilder.tsx",
86
91
  "./src/components/builder/source/LegendQueryDataCubeSourceBuilder.tsx",
87
92
  "./src/components/builder/source/LocalFileDataCubeSourceBuilder.tsx",
88
93
  "./src/components/builder/source/UserDefinedFunctionDataCubeSourceBuilder.tsx",
94
+ "./src/components/builder/source/loader/LocalFileDataCubePartialSourceLoader.tsx",
89
95
  "./src/stores/builder/LegendDataCubeBuilderStore.tsx",
90
96
  "./src/stores/builder/LegendDataCubeCreatorState.tsx",
91
- "./src/stores/builder/LegendDataCubeLoaderState.tsx"
97
+ "./src/stores/builder/LegendDataCubeLoaderState.tsx",
98
+ "./src/stores/builder/LegendDataCubeSourceLoaderState.tsx"
92
99
  ],
93
100
  "include": [
94
101
  "src/**/*.ts",