@malloydata/malloy-tests 0.0.157 → 0.0.158-dev240805161224

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.
package/package.json CHANGED
@@ -21,13 +21,13 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@jest/globals": "^29.4.3",
24
- "@malloydata/db-bigquery": "^0.0.157",
25
- "@malloydata/db-duckdb": "^0.0.157",
26
- "@malloydata/db-postgres": "^0.0.157",
27
- "@malloydata/db-snowflake": "^0.0.157",
28
- "@malloydata/db-trino": "^0.0.157",
29
- "@malloydata/malloy": "^0.0.157",
30
- "@malloydata/render": "^0.0.157",
24
+ "@malloydata/db-bigquery": "^0.0.158-dev240805161224",
25
+ "@malloydata/db-duckdb": "^0.0.158-dev240805161224",
26
+ "@malloydata/db-postgres": "^0.0.158-dev240805161224",
27
+ "@malloydata/db-snowflake": "^0.0.158-dev240805161224",
28
+ "@malloydata/db-trino": "^0.0.158-dev240805161224",
29
+ "@malloydata/malloy": "^0.0.158-dev240805161224",
30
+ "@malloydata/render": "^0.0.158-dev240805161224",
31
31
  "jsdom": "^22.1.0",
32
32
  "luxon": "^2.4.0",
33
33
  "madge": "^6.0.0"
@@ -36,5 +36,5 @@
36
36
  "@types/jsdom": "^21.1.1",
37
37
  "@types/luxon": "^2.4.0"
38
38
  },
39
- "version": "0.0.157"
39
+ "version": "0.0.158-dev240805161224"
40
40
  }
@@ -541,30 +541,6 @@ describe.each(runtimes.runtimeList)('%s', (databaseName, runtime) => {
541
541
  });
542
542
  });
543
543
 
544
- it('sql_functions - experimental feature is ignored', async () => {
545
- const query = await expressionModel.loadQuery(
546
- `
547
- source: a is ${databaseName}.table('malloytest.aircraft_models') extend { where: aircraft_model_code ? '0270202' }
548
-
549
- run: a -> {
550
- group_by: manufacturer
551
- group_by: string_1 is sql_string("UPPER(\${manufacturer})")
552
- }
553
- `
554
- );
555
-
556
- const runResult = await query.run();
557
- const dataResult = runResult.data.toObject();
558
- expect(dataResult.length).toEqual(1);
559
- const firstRow = dataResult.at(0);
560
- if (firstRow !== undefined) {
561
- expect(firstRow['manufacturer']).toEqual('AHRENS AIRCRAFT CORP.');
562
- expect('string_1' in firstRow).toBeFalsy();
563
- } else {
564
- fail('exepected a single row, but found none');
565
- }
566
- });
567
-
568
544
  describe('[not yet supported]', () => {
569
545
  // See ${...} documentation for lookml here for guidance on remaining work:
570
546
  // https://cloud.google.com/looker/docs/reference/param-field-sql#sql_for_dimensions
@@ -0,0 +1,307 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {RuntimeList, allDatabases} from '../../runtimes';
9
+ import {databasesFromEnvironmentOr} from '../../util';
10
+ import '../../util/db-jest-matchers';
11
+
12
+ const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));
13
+
14
+ afterAll(async () => {
15
+ await runtimes.closeAll();
16
+ });
17
+
18
+ runtimes.runtimeMap.forEach((runtime, databaseName) => {
19
+ it(`number param used in dimension - ${databaseName}`, async () => {
20
+ await expect(`
21
+ ##! experimental.parameters
22
+ source: state_facts(param::number) is ${databaseName}.table('malloytest.state_facts') extend {
23
+ dimension: param_plus_one is param + 1
24
+ }
25
+ run: state_facts(param is 1) -> { group_by: param_plus_one }
26
+ `).malloyResultMatches(runtime, {param_plus_one: 2});
27
+ });
28
+ it(`number param used in sql function - ${databaseName}`, async () => {
29
+ await expect(`
30
+ ##! experimental { parameters sql_functions }
31
+ source: state_facts(param::number) is ${databaseName}.table('malloytest.state_facts') extend {
32
+ dimension: param_plus_one is sql_number("\${param} + 1")
33
+ }
34
+ run: state_facts(param is 1) -> { group_by: param_plus_one }
35
+ `).malloyResultMatches(runtime, {param_plus_one: 2});
36
+ });
37
+ it.skip(`string param used in group_by - ${databaseName}`, async () => {
38
+ await expect(`
39
+ ##! experimental.parameters
40
+ source: state_facts(param::string) is ${databaseName}.table('malloytest.state_facts') extend {
41
+ dimension: param_plus_one is param
42
+ }
43
+ run: state_facts(param is "foo") -> { group_by: param_val is param }
44
+ `).malloyResultMatches(runtime, {param_val: 'foo'});
45
+ });
46
+ it.skip(`reference field in source in argument - ${databaseName}`, async () => {
47
+ await expect(`
48
+ ##! experimental.parameters
49
+ source: state_facts(filter::boolean) is ${databaseName}.table('malloytest.state_facts') extend {
50
+ where: filter
51
+ }
52
+ run: state_facts(filter is state = 'CA') -> { group_by: state }
53
+ `).malloyResultMatches(runtime, {state: 'CA'});
54
+ });
55
+ it(`can pass param into joined source correctly - ${databaseName}`, async () => {
56
+ await expect(`
57
+ ##! experimental.parameters
58
+ source: state_facts(
59
+ state_filter::string
60
+ ) is ${databaseName}.table('malloytest.state_facts') extend {
61
+ where: state = state_filter
62
+ }
63
+
64
+ source: state_facts2(
65
+ state_filter::string
66
+ ) is ${databaseName}.table('malloytest.state_facts') extend {
67
+ where: state = state_filter
68
+
69
+ join_many: state_facts is state_facts(state_filter) on 1 = 1
70
+ }
71
+
72
+ run: state_facts2(state_filter is "CA") -> {
73
+ group_by:
74
+ s1 is state,
75
+ s2 is state_facts.state
76
+ aggregate: c is count()
77
+ }
78
+ `).malloyResultMatches(runtime, {s1: 'CA', s2: 'CA', c: 1});
79
+ });
80
+ it(`can pass param into extended source - ${databaseName}`, async () => {
81
+ await expect(`
82
+ ##! experimental.parameters
83
+ source: state_facts(param::number) is ${databaseName}.table('malloytest.state_facts') extend {
84
+ dimension: p is param
85
+ }
86
+ source: state_facts_ext(param::number) is state_facts(param)
87
+ run: state_facts_ext(param is 1) -> p
88
+ `).malloyResultMatches(runtime, {p: 1});
89
+ });
90
+ // TODO excepting a field outright removes it from the source, without consideration
91
+ // to other fields that use that removed field in their definition; consider
92
+ // changing rename/accept/except to modify a mapping layer between the underlying
93
+ // source and the created source, as well as a separate way to override the definition
94
+ // of a field deeply (without removing it or changing its type).
95
+ it.skip(`can use dimension that uses field that is excepted - ${databaseName}`, async () => {
96
+ await expect(
97
+ `
98
+ ##! experimental.parameters
99
+ source: state_facts is ${databaseName}.table('malloytest.state_facts') extend {
100
+ dimension: state_copy is state
101
+ }
102
+ source: state_facts_ext is state_facts extend {
103
+ except: state
104
+ }
105
+
106
+ run: state_facts_ext -> {
107
+ group_by: state_copy
108
+ order_by: state_copy desc
109
+ limit: 1
110
+ }
111
+ `
112
+ ).malloyResultMatches(runtime, {state_copy: 'AK'});
113
+ });
114
+ it.skip(`can shadow field that is excepted, using dimension that uses field that is excepted - ${databaseName}`, async () => {
115
+ await expect(
116
+ `
117
+ ##! experimental.parameters
118
+ source: state_facts is ${databaseName}.table('malloytest.state_facts') extend {
119
+ dimension: state_copy is state
120
+ }
121
+ source: state_facts_hardcode_state(state::string) is state_facts extend {
122
+ except: state
123
+ dimension: hardcoded_state is state
124
+ }
125
+
126
+ run: state_facts_hardcode_state(state is 'NOT A STATE') -> {
127
+ group_by: hardcoded_state, state_copy
128
+ order_by: state_copy desc
129
+ limit: 1
130
+ }
131
+ `
132
+ ).malloyResultMatches(runtime, {
133
+ hardcoded_state: 'NOT A STATE',
134
+ state_copy: 'AK',
135
+ });
136
+ });
137
+ it(`can shadow field that is excepted - ${databaseName}`, async () => {
138
+ await expect(
139
+ `
140
+ ##! experimental.parameters
141
+ source: state_facts is ${databaseName}.table('malloytest.state_facts')
142
+ source: state_facts_hardcode_state(state::string) is state_facts extend {
143
+ except: state
144
+ dimension: hardcoded_state is state
145
+ }
146
+
147
+ run: state_facts_hardcode_state(state is 'NOT A STATE') -> {
148
+ group_by: hardcoded_state
149
+ }
150
+ `
151
+ ).malloyResultMatches(runtime, {hardcoded_state: 'NOT A STATE'});
152
+ });
153
+ it(`default value propagates - ${databaseName}`, async () => {
154
+ await expect(
155
+ `
156
+ ##! experimental.parameters
157
+ source: ab_new(param::number is 10) is ${databaseName}.table('malloytest.state_facts') extend {
158
+ dimension: param_value is param
159
+ }
160
+ run: ab_new -> { group_by: param_value }
161
+ `
162
+ ).malloyResultMatches(runtime, {param_value: 10});
163
+ });
164
+ it(`default value can be overridden - ${databaseName}`, async () => {
165
+ await expect(
166
+ `
167
+ ##! experimental.parameters
168
+ source: ab_new(param::number is 10) is ${databaseName}.table('malloytest.state_facts') extend {
169
+ dimension: param_value is param
170
+ }
171
+ run: ab_new(param is 11) -> { group_by: param_value }
172
+ `
173
+ ).malloyResultMatches(runtime, {param_value: 11});
174
+ });
175
+ it(`default value passed through extension propagates - ${databaseName}`, async () => {
176
+ await expect(
177
+ `
178
+ ##! experimental.parameters
179
+ source: ab_new(param::number is 10) is ${databaseName}.table('malloytest.state_facts') extend {
180
+ dimension: param_value is param
181
+ }
182
+ source: ab_new_new(param::number is 11) is ab_new(param) extend {}
183
+ run: ab_new_new -> { group_by: param_value }
184
+ `
185
+ ).malloyResultMatches(runtime, {param_value: 11});
186
+ });
187
+ it(`use parameter in nested view - ${databaseName}`, async () => {
188
+ await expect(
189
+ `
190
+ ##! experimental.parameters
191
+ source: ab_new(param::number is 10) is ${databaseName}.table('malloytest.state_facts') extend {
192
+ dimension: param_value_1 is param
193
+ view: v is {
194
+ group_by: param_value_1
195
+ group_by: param_value_2 is param
196
+ nest: n is {
197
+ group_by: param_value_1
198
+ group_by: param_value_3 is param
199
+ }
200
+ }
201
+ }
202
+ run: ab_new -> v
203
+ `
204
+ ).malloyResultMatches(runtime, {
205
+ 'param_value_1': 10,
206
+ 'param_value_2': 10,
207
+ 'n.param_value_1': 10,
208
+ 'n.param_value_3': 10,
209
+ });
210
+ });
211
+ it.skip(`can pass param into joined source from query - ${databaseName}`, async () => {
212
+ await expect(`
213
+ ##! experimental.parameters
214
+ source: state_facts(
215
+ state_filter::string
216
+ ) is ${databaseName}.table('malloytest.state_facts') extend {
217
+ where: state = state_filter
218
+ }
219
+
220
+ source: state_facts2(
221
+ state_filter::string
222
+ ) is ${databaseName}.table('malloytest.state_facts') extend {
223
+ where: state = state_filter
224
+
225
+ join_many: state_facts is (state_facts(state_filter) -> { select: * }) on 1 = 1
226
+ }
227
+
228
+ run: state_facts2(state_filter is "CA") -> {
229
+ group_by:
230
+ s1 is state,
231
+ s2 is state_facts.state
232
+ aggregate: c is count()
233
+ }
234
+ `).malloyResultMatches(runtime, {s1: 'CA', s2: 'CA', c: 1});
235
+ });
236
+ it.skip(`can pass param into query definition - ${databaseName}`, async () => {
237
+ await expect(`
238
+ ##! experimental.parameters
239
+ source: state_facts(
240
+ state_filter::string
241
+ ) is ${databaseName}.table('malloytest.state_facts') extend {
242
+ where: state = state_filter
243
+ }
244
+
245
+ source: state_facts_query(state_filter::string) is state_facts(state_filter) -> { select: * }
246
+
247
+ run: state_facts_query(state_filter is "CA") -> {
248
+ select: state
249
+ }
250
+ `).malloyResultMatches(runtime, {state: 'CA'});
251
+ });
252
+ it(`can use param in join on - ${databaseName}`, async () => {
253
+ await expect(`
254
+ ##! experimental.parameters
255
+ source: state_facts is ${databaseName}.table('malloytest.state_facts')
256
+
257
+ source: state_facts2(
258
+ state_filter::string
259
+ ) is ${databaseName}.table('malloytest.state_facts') extend {
260
+ where: state = state_filter
261
+
262
+ join_many: state_facts on state_facts.state = state_filter
263
+ }
264
+
265
+ run: state_facts2(state_filter is "CA") -> {
266
+ group_by:
267
+ s1 is state,
268
+ s2 is state_facts.state
269
+ aggregate: c is count()
270
+ }
271
+ `).malloyResultMatches(runtime, {s1: 'CA', s2: 'CA', c: 1});
272
+ });
273
+ it(`can use param in join with - ${databaseName}`, async () => {
274
+ await expect(`
275
+ ##! experimental.parameters
276
+ source: state_facts is ${databaseName}.table('malloytest.state_facts') extend {
277
+ primary_key: state
278
+ }
279
+
280
+ source: state_facts2(
281
+ state_filter::string
282
+ ) is ${databaseName}.table('malloytest.state_facts') extend {
283
+ where: state = state_filter
284
+
285
+ join_one: state_facts with state_filter
286
+ }
287
+
288
+ run: state_facts2(state_filter is "CA") -> {
289
+ group_by:
290
+ s1 is state,
291
+ s2 is state_facts.state
292
+ aggregate: c is count()
293
+ }
294
+ `).malloyResultMatches(runtime, {s1: 'CA', s2: 'CA', c: 1});
295
+ });
296
+ it(`source arguments in query propagate when turned into source - ${databaseName}`, async () => {
297
+ await expect(`
298
+ ##! experimental.parameters
299
+ source: ab_new(param::number) is ${databaseName}.table('malloytest.state_facts') extend {
300
+ dimension: param_value is param
301
+ }
302
+ query: foo is ab_new(param is 1) -> { select: param_value }
303
+ source: foo_ext is foo
304
+ run: foo_ext -> { select: param_value }
305
+ `).malloyResultMatches(runtime, {param_value: 1});
306
+ });
307
+ });