@malloydata/malloy-tests 0.0.310 → 0.0.311

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.310",
25
- "@malloydata/db-duckdb": "0.0.310",
26
- "@malloydata/db-postgres": "0.0.310",
27
- "@malloydata/db-snowflake": "0.0.310",
28
- "@malloydata/db-trino": "0.0.310",
29
- "@malloydata/malloy": "0.0.310",
30
- "@malloydata/malloy-tag": "0.0.310",
31
- "@malloydata/render": "0.0.310",
24
+ "@malloydata/db-bigquery": "0.0.311",
25
+ "@malloydata/db-duckdb": "0.0.311",
26
+ "@malloydata/db-postgres": "0.0.311",
27
+ "@malloydata/db-snowflake": "0.0.311",
28
+ "@malloydata/db-trino": "0.0.311",
29
+ "@malloydata/malloy": "0.0.311",
30
+ "@malloydata/malloy-tag": "0.0.311",
31
+ "@malloydata/render": "0.0.311",
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.310"
41
+ "version": "0.0.311"
42
42
  }
@@ -0,0 +1,41 @@
1
+ #! /bin/bash
2
+ #
3
+ # Setup postgres as a docker container
4
+ #
5
+ set -e
6
+
7
+ rm -rf .tmp
8
+ mkdir .tmp
9
+
10
+ # run docker
11
+ SCRIPTDIR=$(cd $(dirname $0); pwd)
12
+ DATADIR=$(dirname $SCRIPTDIR)/data/postgres
13
+
14
+ // set these in your enviornment
15
+ export PGHOST=localhost
16
+ export PGPORT=5432
17
+ export PGUSER=root
18
+ export PGPASSWORD=postgres
19
+
20
+ docker run -p 5432:5432 -d -v $DATADIR:/init_data \
21
+ --name postgres-malloy \
22
+ -e POSTGRES_USER=root -e POSTGRES_PASSWORD=postgres \
23
+ --health-cmd pg_isready \
24
+ --health-interval 10s \
25
+ --health-timeout 5s \
26
+ --health-retries 5 \
27
+ -d postgres
28
+
29
+ CONTAINER_NAME="postgres-malloy"
30
+
31
+ echo "Waiting for container $CONTAINER_NAME to become healthy..."
32
+
33
+ while [ "$(docker inspect -f {{.State.Health.Status}} $CONTAINER_NAME)" != "healthy" ]; do
34
+ sleep 2; # Adjust the sleep duration as needed
35
+ done
36
+
37
+ echo "Container $CONTAINER_NAME is now healthy!"
38
+
39
+ # configure
40
+ echo CREATE EXTENSION tsm_system_rows\; | psql
41
+ gunzip -c ${DATADIR}/malloytest-postgres.sql.gz | psql
@@ -0,0 +1,7 @@
1
+ #! /bin/bash
2
+
3
+ # clear tmp files
4
+ rm -rf .tmp
5
+
6
+ # stop container
7
+ docker rm -f postgres-malloy
@@ -183,6 +183,21 @@ describe.each(runtimes.runtimeList)('filter expressions %s', (dbName, db) => {
183
183
  select: nm
184
184
  }`).malloyResultMatches(abc, got('xback'));
185
185
  });
186
+ test('string or with pipe', async () => {
187
+ await expect(`
188
+ run: abc -> {
189
+ where: s ~ f'abc | def'
190
+ select: nm; order_by: nm asc
191
+ }`).malloyResultMatches(abc, got('abc,def'));
192
+ });
193
+
194
+ test('string and with semicolon', async () => {
195
+ await expect(`
196
+ run: abc -> {
197
+ where: s ~ f'%b% ; %c'
198
+ select: nm; order_by: nm asc
199
+ }`).malloyResultMatches(abc, got('abc'));
200
+ });
186
201
  });
187
202
 
188
203
  describe('numeric filter expressions', () => {
@@ -319,6 +334,13 @@ describe.each(runtimes.runtimeList)('filter expressions %s', (dbName, db) => {
319
334
  select: n; order_by: n asc
320
335
  }`).malloyResultMatches(nums, [{n: 0}, {n: 1}]);
321
336
  });
337
+ test('not <=1', async () => {
338
+ await expect(`
339
+ run: nums -> {
340
+ where: n ~ f'not <=1'
341
+ select: n; order_by: n asc
342
+ }`).malloyResultMatches(nums, [{n: 2}, {n: 3}, {n: 4}]);
343
+ });
322
344
  });
323
345
 
324
346
  const testBoolean = db.dialect.booleanType === 'supported';
@@ -365,6 +387,27 @@ describe.each(runtimes.runtimeList)('filter expressions %s', (dbName, db) => {
365
387
  select: t; order_by: t asc
366
388
  }`).malloyResultMatches(facts, [{t: 'false'}, {t: 'true'}]);
367
389
  });
390
+ test.when(testBoolean)('not true', async () => {
391
+ await expect(`
392
+ run: facts -> {
393
+ where: b ~ f'not true'
394
+ select: t; order_by: t asc
395
+ }`).malloyResultMatches(facts, [{t: 'false'}, {t: 'null'}]);
396
+ });
397
+ test.when(testBoolean)('not false', async () => {
398
+ await expect(`
399
+ run: facts -> {
400
+ where: b ~ f'not false'
401
+ select: t; order_by: t asc
402
+ }`).malloyResultMatches(facts, [{t: 'true'}]);
403
+ });
404
+ test.when(testBoolean)('not =false', async () => {
405
+ await expect(`
406
+ run: facts -> {
407
+ where: b ~ f'not =false'
408
+ select: t; order_by: t asc
409
+ }`).malloyResultMatches(facts, [{t: 'null'}, {t: 'true'}]);
410
+ });
368
411
  test.when(testBoolean)('empty boolean filter', async () => {
369
412
  await expect(`
370
413
  run: facts -> {
@@ -274,6 +274,33 @@ runtimes.runtimeMap.forEach((runtime, databaseName) => {
274
274
  });
275
275
  });
276
276
 
277
+ it(`symmetric sum and average large - ${databaseName}`, async () => {
278
+ await expect(`
279
+ source: a is ${databaseName}.table('malloytest.airports') extend {
280
+ primary_key: code
281
+ dimension: big_elevation is elevation * 100000
282
+ measure:
283
+ total_elevation is elevation.sum()
284
+ average_elevation is floor(elevation.avg())
285
+ total_big_elevation is big_elevation.sum()
286
+ average_big_elevation is floor(big_elevation.avg())
287
+ }
288
+ query: two_rows is ${databaseName}.table('malloytest.state_facts') -> {select: state; limit: 2}
289
+ source: b is two_rows extend {
290
+ join_cross: a on 1=1
291
+ }
292
+
293
+ run: b -> {aggregate: a.total_elevation, a.average_elevation, a.total_big_elevation, a.average_big_elevation}
294
+ // run: two_rows
295
+
296
+ `).malloyResultMatches(runtime, {
297
+ total_elevation: 22629146,
298
+ average_elevation: 1143,
299
+ total_big_elevation: 2262914600000,
300
+ average_big_elevation: 114329035,
301
+ });
302
+ });
303
+
277
304
  it(`limit - provided - ${databaseName}`, async () => {
278
305
  // a cross join produces a Many to Many result.
279
306
  // symmetric aggregate are needed on both sides of the join
@@ -919,6 +946,34 @@ SELECT row_to_json(finalStage) as row FROM __stage0 AS finalStage`);
919
946
  `).malloyResultMatches(runtime, {'fun.t1': 52});
920
947
  });
921
948
 
949
+ // not sure this works on all dialect.
950
+ it("stage names don't conflict- ${databaseName}", async () => {
951
+ await expect(`
952
+ source: airports is ${databaseName}.table('malloytest.state_facts') extend {
953
+ }
954
+
955
+ query: st0 is airports -> {
956
+ select: state
957
+ } -> {
958
+ select: *
959
+ }
960
+
961
+ query: st1 is airports -> {
962
+ select: state
963
+ } -> {
964
+ select: *
965
+ }
966
+
967
+ query: u is ${databaseName}.sql("""SELECT * FROM %{st0 } as x UNION ALL %{st1 }""") -> {
968
+ select: *
969
+ }
970
+ // # test.debug
971
+ run: u -> {
972
+ aggregate: c is count()
973
+ }
974
+ `).malloyResultMatches(runtime, {c: 102});
975
+ });
976
+
922
977
  const sql1234 = `${databaseName}.sql('SELECT 1 as ${q`a`}, 2 as ${q`b`} UNION ALL SELECT 3, 4')`;
923
978
 
924
979
  it(`sql as source - ${databaseName}`, async () => {