@malloydata/malloy-tests 0.0.263 → 0.0.264-dev250414221049
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,14 +21,14 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@jest/globals": "^29.4.3",
|
|
24
|
-
"@malloydata/db-bigquery": "^0.0.
|
|
25
|
-
"@malloydata/db-duckdb": "^0.0.
|
|
26
|
-
"@malloydata/db-postgres": "^0.0.
|
|
27
|
-
"@malloydata/db-snowflake": "^0.0.
|
|
28
|
-
"@malloydata/db-trino": "^0.0.
|
|
29
|
-
"@malloydata/malloy": "^0.0.
|
|
30
|
-
"@malloydata/malloy-tag": "^0.0.
|
|
31
|
-
"@malloydata/render": "^0.0.
|
|
24
|
+
"@malloydata/db-bigquery": "^0.0.264-dev250414221049",
|
|
25
|
+
"@malloydata/db-duckdb": "^0.0.264-dev250414221049",
|
|
26
|
+
"@malloydata/db-postgres": "^0.0.264-dev250414221049",
|
|
27
|
+
"@malloydata/db-snowflake": "^0.0.264-dev250414221049",
|
|
28
|
+
"@malloydata/db-trino": "^0.0.264-dev250414221049",
|
|
29
|
+
"@malloydata/malloy": "^0.0.264-dev250414221049",
|
|
30
|
+
"@malloydata/malloy-tag": "^0.0.264-dev250414221049",
|
|
31
|
+
"@malloydata/render": "^0.0.264-dev250414221049",
|
|
32
32
|
"events": "^3.3.0",
|
|
33
33
|
"jsdom": "^22.1.0",
|
|
34
34
|
"luxon": "^2.4.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"@types/jsdom": "^21.1.1",
|
|
39
39
|
"@types/luxon": "^2.4.0"
|
|
40
40
|
},
|
|
41
|
-
"version": "0.0.
|
|
41
|
+
"version": "0.0.264-dev250414221049"
|
|
42
42
|
}
|
|
@@ -26,15 +26,17 @@ const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));
|
|
|
26
26
|
* so fix that one first if the tests are failing.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
+
function literalNum(num: Number): Expr {
|
|
30
|
+
const literal = num.toString();
|
|
31
|
+
return {node: 'numberLiteral', literal, sql: literal};
|
|
32
|
+
}
|
|
33
|
+
|
|
29
34
|
describe.each(runtimes.runtimeList)(
|
|
30
35
|
'compound atomic datatypes %s',
|
|
31
36
|
(conName, runtime) => {
|
|
32
37
|
const supportsNestedArrays = runtime.dialect.nestedArrays;
|
|
33
38
|
const quote = runtime.dialect.sqlMaybeQuoteIdentifier;
|
|
34
|
-
|
|
35
|
-
const literal = num.toString();
|
|
36
|
-
return {node: 'numberLiteral', literal, sql: literal};
|
|
37
|
-
}
|
|
39
|
+
|
|
38
40
|
const empty = `${conName}.sql("SELECT 0 as z")`;
|
|
39
41
|
function arraySelectVal(...val: Number[]): string {
|
|
40
42
|
const literal: ArrayLiteralNode = {
|
|
@@ -67,7 +69,6 @@ describe.each(runtimes.runtimeList)(
|
|
|
67
69
|
literal.sql = runtime.dialect.sqlLiteralRecord(literal);
|
|
68
70
|
return literal;
|
|
69
71
|
}
|
|
70
|
-
|
|
71
72
|
function recordSelectVal(fromObj: Record<string, number>): string {
|
|
72
73
|
return runtime.dialect.sqlLiteralRecord(recordLiteral(fromObj));
|
|
73
74
|
}
|
|
@@ -89,6 +90,8 @@ describe.each(runtimes.runtimeList)(
|
|
|
89
90
|
const evens = `${conName}.sql("""
|
|
90
91
|
SELECT ${evensSQL} AS ${quote('evens')}
|
|
91
92
|
""")`;
|
|
93
|
+
const d4 = [1, 2, 3, 4];
|
|
94
|
+
const d4SQL = arraySelectVal(...d4);
|
|
92
95
|
|
|
93
96
|
describe('simple arrays', () => {
|
|
94
97
|
test('array literal dialect function', async () => {
|
|
@@ -158,24 +161,26 @@ describe.each(runtimes.runtimeList)(
|
|
|
158
161
|
{die_roll: 4},
|
|
159
162
|
]);
|
|
160
163
|
});
|
|
161
|
-
test.
|
|
164
|
+
test.when(canReadCompoundSchema)('cross join two arrays', async () => {
|
|
162
165
|
await expect(`
|
|
163
|
-
run: ${
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
group_by: roll
|
|
168
|
-
aggregate:
|
|
166
|
+
run: ${conName}.sql("""
|
|
167
|
+
SELECT ${d4SQL} as ${quote('d1')}, ${d4SQL} as ${quote('d2')}
|
|
168
|
+
""") -> { select: roll is d1.each + d2.each }
|
|
169
|
+
-> {
|
|
170
|
+
group_by: roll
|
|
171
|
+
aggregate: n is count()
|
|
172
|
+
order_by: roll asc
|
|
169
173
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
{roll:
|
|
173
|
-
{roll:
|
|
174
|
-
{roll:
|
|
175
|
-
{roll:
|
|
176
|
-
{roll:
|
|
177
|
-
{roll:
|
|
178
|
-
|
|
174
|
+
`).matchesRows(
|
|
175
|
+
runtime,
|
|
176
|
+
{roll: 2, n: 1},
|
|
177
|
+
{roll: 3, n: 2},
|
|
178
|
+
{roll: 4, n: 3},
|
|
179
|
+
{roll: 5, n: 4},
|
|
180
|
+
{roll: 6, n: 3},
|
|
181
|
+
{roll: 7, n: 2},
|
|
182
|
+
{roll: 8, n: 1}
|
|
183
|
+
);
|
|
179
184
|
});
|
|
180
185
|
// can't use special chars in column names in bq
|
|
181
186
|
test.when(conName !== 'bigquery')(
|
|
@@ -243,6 +248,25 @@ describe.each(runtimes.runtimeList)(
|
|
|
243
248
|
run: ${empty} extend { dimension: aoa is [[1,2]] } -> { select: aoa.each.each }
|
|
244
249
|
`).malloyResultMatches(runtime, [{each: 1}, {each: 2}]);
|
|
245
250
|
});
|
|
251
|
+
test('group by array', async () => {
|
|
252
|
+
const oddsObj = [1, 3, 5, 7];
|
|
253
|
+
const oddsSql = arraySelectVal(...oddsObj);
|
|
254
|
+
await expect(`
|
|
255
|
+
run: ${conName}.sql("""
|
|
256
|
+
SELECT ${evensSQL} as ${quote('nums')}, 1 as ${quote('n')}
|
|
257
|
+
UNION ALL SELECT ${evensSQL}, 10
|
|
258
|
+
UNION ALL SELECT ${oddsSql}, 100
|
|
259
|
+
UNION ALL SELECT ${oddsSql}, 1000
|
|
260
|
+
""") -> {
|
|
261
|
+
group_by: nums
|
|
262
|
+
aggregate: addem is n.sum()
|
|
263
|
+
order_by: addem asc
|
|
264
|
+
}`).matchesRows(
|
|
265
|
+
runtime,
|
|
266
|
+
{nums: evensObj, addem: 11},
|
|
267
|
+
{nums: oddsObj, addem: 1100}
|
|
268
|
+
);
|
|
269
|
+
});
|
|
246
270
|
});
|
|
247
271
|
describe('record', () => {
|
|
248
272
|
function rec_eq(as?: string): Record<string, Number> {
|
|
@@ -433,10 +457,10 @@ describe.each(runtimes.runtimeList)(
|
|
|
433
457
|
{a: 10, b: 11},
|
|
434
458
|
{a: 20, b: 21},
|
|
435
459
|
];
|
|
436
|
-
const abMalloy = '[{a is 10, b is 11}, {a is 20, b is 21}]';
|
|
437
460
|
function selectAB(n: string) {
|
|
438
461
|
return `SELECT ${ab} AS ${quote(n)}`;
|
|
439
462
|
}
|
|
463
|
+
const abMalloy = '[{a is 10, b is 11}, {a is 20, b is 21}]';
|
|
440
464
|
|
|
441
465
|
test('repeated record from nest', async () => {
|
|
442
466
|
await expect(`
|
|
@@ -302,4 +302,15 @@ describe.each(runtimes.runtimeList)('%s', (databaseName, runtime) => {
|
|
|
302
302
|
}
|
|
303
303
|
`).malloyResultMatches(joinModel, {c: 0});
|
|
304
304
|
});
|
|
305
|
+
|
|
306
|
+
it.when(runtime.dialect.nestedArrays)(
|
|
307
|
+
'finds join dependency in non basic atomic fields',
|
|
308
|
+
async () => {
|
|
309
|
+
await expect(`
|
|
310
|
+
run: ${databaseName}.sql("SELECT 1 as n")
|
|
311
|
+
extend { dimension: a1 is [[1]], a2 is [[2]] }
|
|
312
|
+
-> { select: pick_a1 is pick a1.each when true else a2.each }
|
|
313
|
+
`).matchesRows(runtime, {pick_a1: [1]});
|
|
314
|
+
}
|
|
315
|
+
);
|
|
305
316
|
});
|