@malloydata/malloy-tests 0.0.299 → 0.0.301

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.299",
25
- "@malloydata/db-duckdb": "0.0.299",
26
- "@malloydata/db-postgres": "0.0.299",
27
- "@malloydata/db-snowflake": "0.0.299",
28
- "@malloydata/db-trino": "0.0.299",
29
- "@malloydata/malloy": "0.0.299",
30
- "@malloydata/malloy-tag": "0.0.299",
31
- "@malloydata/render": "0.0.299",
24
+ "@malloydata/db-bigquery": "0.0.301",
25
+ "@malloydata/db-duckdb": "0.0.301",
26
+ "@malloydata/db-postgres": "0.0.301",
27
+ "@malloydata/db-snowflake": "0.0.301",
28
+ "@malloydata/db-trino": "0.0.301",
29
+ "@malloydata/malloy": "0.0.301",
30
+ "@malloydata/malloy-tag": "0.0.301",
31
+ "@malloydata/render": "0.0.301",
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.299"
41
+ "version": "0.0.301"
42
42
  }
@@ -39,6 +39,22 @@ if (!envDatabases.includes('duckdb')) {
39
39
  describe.skip = describe;
40
40
  }
41
41
 
42
+ describe('basic', () => {
43
+ test('can get query by name from explore', async () => {
44
+ const model = runtime.loadModel(`
45
+ source: s1 is duckdb.table('malloytest.aircraft') extend {
46
+ view: v is {
47
+ where: state = 'CA'
48
+ group_by: state
49
+ }
50
+ }
51
+ `);
52
+ const q1 = model.loadExploreByName('s1');
53
+ const oneState = await q1.loadQueryByName('v').run();
54
+ expect(oneState.data.path(0, 'state').value).toBe('CA');
55
+ });
56
+ });
57
+
42
58
  describe('extendModel', () => {
43
59
  test('can run query in extend section', async () => {
44
60
  const model = runtime.loadModel(`
@@ -275,7 +275,7 @@ describe.each(runtimes.runtimeList)('%s', (databaseName, runtime) => {
275
275
  ),
276
276
  state_facts extend { dimension: foo is 1.3, bar is 2.3, baz is 3.3 }
277
277
  )
278
- // even though the first composite has all the fields foo, bar, baz; it is impossible
278
+ // even though the first composite hAS all the fields foo, bar, baz; it is impossible
279
279
  // to resolve it using the first composite, because you can't have both bar and baz
280
280
  // so the second input source is used instead
281
281
  run: x -> { group_by: foo, bar, baz }
@@ -541,4 +541,65 @@ describe.each(runtimes.runtimeList)('%s', (databaseName, runtime) => {
541
541
  run: x -> { group_by: x }
542
542
  `).malloyResultMatches(runtime, {x: 'b1'});
543
543
  });
544
+ describe('partition composites', () => {
545
+ const id = (n: string) => (databaseName === 'snowflake' ? `"${n}"` : n);
546
+ test('partition composite basic', async () => {
547
+ await expect(`
548
+ #! experimental { partition_composite { partition_field=p partitions={a={a} b={b}} } }
549
+ source: comp is ${databaseName}.sql("""
550
+ SELECT 10 AS ${id('a')}, 0 AS ${id('b')}, 'a' AS ${id('p')}
551
+ UNION ALL SELECT 20 AS ${id('a')}, 0 AS ${id('b')}, 'a' AS ${id('p')}
552
+ UNION ALL SELECT 0 AS ${id('a')}, 1 AS ${id('b')}, 'b' AS ${id('p')}
553
+ UNION ALL SELECT 0 AS ${id('a')}, 2 AS ${id('b')}, 'b' AS ${id('p')}
554
+ """)
555
+
556
+ run: comp -> {
557
+ aggregate: a_avg is a.avg()
558
+ aggregate: c is count()
559
+ }
560
+ `).malloyResultMatches(runtime, {a_avg: 15, c: 2});
561
+ });
562
+ test('extended partition composite', async () => {
563
+ await expect(`
564
+ #! experimental { partition_composite { partition_field=p partitions={a={a} b={b}} } }
565
+ source: comp is ${databaseName}.sql("""
566
+ SELECT 10 AS ${id('a')}, 0 AS ${id('b')}, 'a' AS ${id('p')}
567
+ UNION ALL SELECT 20 AS ${id('a')}, 0 AS ${id('b')}, 'a' AS ${id('p')}
568
+ UNION ALL SELECT 0 AS ${id('a')}, 1 AS ${id('b')}, 'b' AS ${id('p')}
569
+ UNION ALL SELECT 0 AS ${id('a')}, 2 AS ${id('b')}, 'b' AS ${id('p')}
570
+ """)
571
+
572
+ source: comp_ext is comp extend {
573
+ measure: a_avg is a.avg()
574
+ }
575
+
576
+ run: comp_ext -> {
577
+ aggregate: a_avg
578
+ aggregate: c is count()
579
+ }
580
+ `).malloyResultMatches(runtime, {a_avg: 15, c: 2});
581
+ });
582
+ test('partition composite nested in composite', async () => {
583
+ await expect(`
584
+ ##! experimental.composite_sources
585
+ #! experimental { partition_composite { partition_field=p partitions={a={a} b={b}} } }
586
+ source: part_comp is ${databaseName}.sql("""
587
+ SELECT 10 AS ${id('a')}, 0 AS ${id('b')}, 'a' AS ${id('p')}
588
+ UNION ALL SELECT 20 AS ${id('a')}, 0 AS ${id('b')}, 'a' AS ${id('p')}
589
+ UNION ALL SELECT 0 AS ${id('a')}, 1 AS ${id('b')}, 'b' AS ${id('p')}
590
+ UNION ALL SELECT 0 AS ${id('a')}, 2 AS ${id('b')}, 'b' AS ${id('p')}
591
+ """)
592
+
593
+ source: comp is compose(
594
+ part_comp,
595
+ ${databaseName}.sql('SELECT 10 AS ${id('c')}')
596
+ )
597
+
598
+ run: comp -> {
599
+ aggregate: a_avg is a.avg()
600
+ aggregate: c is count()
601
+ }
602
+ `).malloyResultMatches(runtime, {a_avg: 15, c: 2});
603
+ });
604
+ });
544
605
  });
@@ -55,9 +55,9 @@ describe.each(runtimes.runtimeList)('%s', (databaseName, runtime) => {
55
55
  run: models->{
56
56
  group_by:
57
57
  manufacturer,
58
- big is seats >=21
58
+ big is seats >= 21
59
59
  aggregate: model_count is count()
60
- }->{
60
+ } -> {
61
61
  group_by: big
62
62
  aggregate: model_count is model_count.sum()
63
63
  }