@malloydata/malloy-profiler 0.0.331 → 0.0.332

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.
@@ -0,0 +1,9 @@
1
+ import type * as Malloy from '@malloydata/malloy-interfaces';
2
+ export declare function generateBigComposite(): {
3
+ code: string;
4
+ schema: Malloy.Schema;
5
+ dimensions: Malloy.FieldInfo[];
6
+ preaggregates: Malloy.FieldInfo[];
7
+ partitionField: Malloy.FieldInfoWithDimension;
8
+ compileQueryRequest: Malloy.CompileQueryRequest;
9
+ };
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright Contributors to the Malloy project
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.generateBigComposite = generateBigComposite;
8
+ const malloy_1 = require("@malloydata/malloy");
9
+ function _getAllCombinations(current, remaining, result) {
10
+ if (remaining.length === 0) {
11
+ if (current.length > 0) {
12
+ result.push(current);
13
+ }
14
+ return;
15
+ }
16
+ _getAllCombinations([...current, remaining[0]], remaining.slice(1), result);
17
+ _getAllCombinations(current, remaining.slice(1), result);
18
+ }
19
+ function getAllCombinations(items) {
20
+ const result = [];
21
+ _getAllCombinations([], items, result);
22
+ return result;
23
+ }
24
+ function generateBigComposite() {
25
+ const dimensionCount = 3;
26
+ const preaggregateCount = 50;
27
+ const dimensions = [];
28
+ for (let i = 0; i < dimensionCount; i++) {
29
+ dimensions.push({
30
+ kind: 'dimension',
31
+ name: `dim_${i}`,
32
+ type: { kind: 'string_type' },
33
+ });
34
+ }
35
+ const dimensionNames = dimensions.map(f => f.name);
36
+ const preaggregates = [];
37
+ for (let i = 0; i < preaggregateCount; i++) {
38
+ preaggregates.push({
39
+ kind: 'dimension',
40
+ name: `preaggregate_${i}`,
41
+ type: { kind: 'number_type', subtype: 'decimal' },
42
+ });
43
+ }
44
+ const partitionField = {
45
+ kind: 'dimension',
46
+ name: 'partition_name',
47
+ type: { kind: 'string_type' },
48
+ };
49
+ const schema = {
50
+ fields: [...dimensions, ...preaggregates, partitionField],
51
+ };
52
+ const tableName = 'cube';
53
+ const connectionName = 'connection';
54
+ let code = `
55
+ ##! experimental { composite_sources access_modifiers }
56
+ `;
57
+ const slices = getAllCombinations(dimensionNames);
58
+ const sliceNames = [];
59
+ for (const slice of slices) {
60
+ const partitionName = slice.join('.');
61
+ const sliceName = `cube:${partitionName}`;
62
+ sliceNames.push(sliceName);
63
+ code += `
64
+ source: \`${sliceName}\` is ${connectionName}.table('${tableName}') include {
65
+ public: ${slice.join(', ')}
66
+ internal: ${partitionField.name}
67
+ internal: ${preaggregates.map(a => a.name).join(',')}
68
+ } extend {
69
+ where: ${partitionField.name} = '${partitionName}'
70
+ }
71
+
72
+ `;
73
+ }
74
+ code += `
75
+ source: cube is compose(
76
+ ${sliceNames.map(n => ` \`${n}\``).join(',\n')}
77
+ ) include {
78
+ public: *
79
+ internal: ${preaggregates.map(a => a.name).join(',')}
80
+ internal: ${partitionField.name}
81
+ } extend {
82
+ measure:
83
+ ${preaggregates.map(a => ` total_${a.name} is ${a.name}.sum()`).join('\n')}
84
+ }
85
+
86
+ // Some extensions of the cube to bulk up the size...
87
+
88
+ source: cube_ext_1 is cube
89
+ source: cube_ext_2 is cube
90
+ source: cube_ext_3 is cube
91
+ source: cube_ext_4 is cube
92
+ source: cube_ext_5 is cube
93
+ `;
94
+ const fileName = 'file://big_composite.malloy';
95
+ const compileModelResponse = malloy_1.API.stateless.compileModel({
96
+ model_url: fileName,
97
+ compiler_needs: {
98
+ files: [
99
+ {
100
+ url: fileName,
101
+ contents: code,
102
+ },
103
+ ],
104
+ connections: [
105
+ {
106
+ name: connectionName,
107
+ dialect: 'duckdb',
108
+ },
109
+ ],
110
+ table_schemas: [
111
+ {
112
+ name: tableName,
113
+ connection_name: connectionName,
114
+ schema,
115
+ },
116
+ ],
117
+ },
118
+ exclude_references: true,
119
+ });
120
+ const compileQueryRequest = {
121
+ exclude_references: true,
122
+ model_url: fileName,
123
+ query: {
124
+ definition: {
125
+ kind: 'arrow',
126
+ source: {
127
+ kind: 'source_reference',
128
+ name: 'cube',
129
+ },
130
+ view: {
131
+ kind: 'segment',
132
+ operations: [
133
+ {
134
+ kind: 'group_by',
135
+ field: {
136
+ expression: {
137
+ kind: 'field_reference',
138
+ name: dimensions[0].name,
139
+ },
140
+ },
141
+ },
142
+ {
143
+ kind: 'aggregate',
144
+ field: {
145
+ expression: {
146
+ kind: 'field_reference',
147
+ name: `total_${preaggregates[0].name}`,
148
+ },
149
+ },
150
+ },
151
+ ],
152
+ },
153
+ },
154
+ },
155
+ compiler_needs: {
156
+ translations: compileModelResponse.translations,
157
+ },
158
+ };
159
+ return {
160
+ code,
161
+ schema,
162
+ dimensions,
163
+ preaggregates,
164
+ partitionField,
165
+ compileQueryRequest,
166
+ };
167
+ }
168
+ console.log(JSON.stringify(generateBigComposite().compileQueryRequest));
169
+ //# sourceMappingURL=big_composite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"big_composite.js","sourceRoot":"","sources":["../src/big_composite.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAuBH,oDAoJC;AAvKD,+CAAuC;AAEvC,SAAS,mBAAmB,CAAI,OAAY,EAAE,SAAc,EAAE,MAAa;IACzE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;QACD,OAAO;IACT,CAAC;IACD,mBAAmB,CAAC,CAAC,GAAG,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC5E,mBAAmB,CAAC,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAC3D,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CAAC,SAAS,CAAC,oBAAoB,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -21,8 +21,8 @@
21
21
  "time": "ts-node src/timer.ts"
22
22
  },
23
23
  "dependencies": {
24
- "@malloydata/malloy": "0.0.331",
25
- "@malloydata/malloy-interfaces": "0.0.331"
24
+ "@malloydata/malloy": "0.0.332",
25
+ "@malloydata/malloy-interfaces": "0.0.332"
26
26
  },
27
- "version": "0.0.331"
27
+ "version": "0.0.332"
28
28
  }
@@ -0,0 +1,177 @@
1
+ /*
2
+ * Copyright Contributors to the Malloy project
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /* eslint-disable no-console */
7
+ import type * as Malloy from '@malloydata/malloy-interfaces';
8
+ import {API} from '@malloydata/malloy';
9
+
10
+ function _getAllCombinations<T>(current: T[], remaining: T[], result: T[][]) {
11
+ if (remaining.length === 0) {
12
+ if (current.length > 0) {
13
+ result.push(current);
14
+ }
15
+ return;
16
+ }
17
+ _getAllCombinations([...current, remaining[0]], remaining.slice(1), result);
18
+ _getAllCombinations(current, remaining.slice(1), result);
19
+ }
20
+
21
+ function getAllCombinations<T>(items: T[]): T[][] {
22
+ const result: T[][] = [];
23
+ _getAllCombinations([], items, result);
24
+ return result;
25
+ }
26
+
27
+ export function generateBigComposite() {
28
+ const dimensionCount = 3;
29
+ const preaggregateCount = 50;
30
+ const dimensions: Malloy.FieldInfo[] = [];
31
+ for (let i = 0; i < dimensionCount; i++) {
32
+ dimensions.push({
33
+ kind: 'dimension',
34
+ name: `dim_${i}`,
35
+ type: {kind: 'string_type'},
36
+ });
37
+ }
38
+ const dimensionNames = dimensions.map(f => f.name);
39
+ const preaggregates: Malloy.FieldInfo[] = [];
40
+ for (let i = 0; i < preaggregateCount; i++) {
41
+ preaggregates.push({
42
+ kind: 'dimension',
43
+ name: `preaggregate_${i}`,
44
+ type: {kind: 'number_type', subtype: 'decimal'},
45
+ });
46
+ }
47
+ const partitionField: Malloy.FieldInfo = {
48
+ kind: 'dimension',
49
+ name: 'partition_name',
50
+ type: {kind: 'string_type'},
51
+ };
52
+ const schema: Malloy.Schema = {
53
+ fields: [...dimensions, ...preaggregates, partitionField],
54
+ };
55
+ const tableName = 'cube';
56
+ const connectionName = 'connection';
57
+ let code = `
58
+ ##! experimental { composite_sources access_modifiers }
59
+ `;
60
+ const slices = getAllCombinations(dimensionNames);
61
+ const sliceNames: string[] = [];
62
+ for (const slice of slices) {
63
+ const partitionName = slice.join('.');
64
+ const sliceName = `cube:${partitionName}`;
65
+ sliceNames.push(sliceName);
66
+ code += `
67
+ source: \`${sliceName}\` is ${connectionName}.table('${tableName}') include {
68
+ public: ${slice.join(', ')}
69
+ internal: ${partitionField.name}
70
+ internal: ${preaggregates.map(a => a.name).join(',')}
71
+ } extend {
72
+ where: ${partitionField.name} = '${partitionName}'
73
+ }
74
+
75
+ `;
76
+ }
77
+
78
+ code += `
79
+ source: cube is compose(
80
+ ${sliceNames.map(n => ` \`${n}\``).join(',\n')}
81
+ ) include {
82
+ public: *
83
+ internal: ${preaggregates.map(a => a.name).join(',')}
84
+ internal: ${partitionField.name}
85
+ } extend {
86
+ measure:
87
+ ${preaggregates.map(a => ` total_${a.name} is ${a.name}.sum()`).join('\n')}
88
+ }
89
+
90
+ // Some extensions of the cube to bulk up the size...
91
+
92
+ source: cube_ext_1 is cube
93
+ source: cube_ext_2 is cube
94
+ source: cube_ext_3 is cube
95
+ source: cube_ext_4 is cube
96
+ source: cube_ext_5 is cube
97
+ `;
98
+
99
+ const fileName = 'file://big_composite.malloy';
100
+
101
+ const compileModelResponse = API.stateless.compileModel({
102
+ model_url: fileName,
103
+ compiler_needs: {
104
+ files: [
105
+ {
106
+ url: fileName,
107
+ contents: code,
108
+ },
109
+ ],
110
+ connections: [
111
+ {
112
+ name: connectionName,
113
+ dialect: 'duckdb',
114
+ },
115
+ ],
116
+ table_schemas: [
117
+ {
118
+ name: tableName,
119
+ connection_name: connectionName,
120
+ schema,
121
+ },
122
+ ],
123
+ },
124
+ exclude_references: true,
125
+ });
126
+
127
+ const compileQueryRequest: Malloy.CompileQueryRequest = {
128
+ exclude_references: true,
129
+ model_url: fileName,
130
+ query: {
131
+ definition: {
132
+ kind: 'arrow',
133
+ source: {
134
+ kind: 'source_reference',
135
+ name: 'cube',
136
+ },
137
+ view: {
138
+ kind: 'segment',
139
+ operations: [
140
+ {
141
+ kind: 'group_by',
142
+ field: {
143
+ expression: {
144
+ kind: 'field_reference',
145
+ name: dimensions[0].name,
146
+ },
147
+ },
148
+ },
149
+ {
150
+ kind: 'aggregate',
151
+ field: {
152
+ expression: {
153
+ kind: 'field_reference',
154
+ name: `total_${preaggregates[0].name}`,
155
+ },
156
+ },
157
+ },
158
+ ],
159
+ },
160
+ },
161
+ },
162
+ compiler_needs: {
163
+ translations: compileModelResponse.translations,
164
+ },
165
+ };
166
+
167
+ return {
168
+ code,
169
+ schema,
170
+ dimensions,
171
+ preaggregates,
172
+ partitionField,
173
+ compileQueryRequest,
174
+ };
175
+ }
176
+
177
+ console.log(JSON.stringify(generateBigComposite().compileQueryRequest));