@malloydata/malloy-tests 0.0.144 → 0.0.145

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.144",
25
- "@malloydata/db-duckdb": "^0.0.144",
26
- "@malloydata/db-postgres": "^0.0.144",
27
- "@malloydata/db-snowflake": "^0.0.144",
28
- "@malloydata/db-trino": "^0.0.144",
29
- "@malloydata/malloy": "^0.0.144",
30
- "@malloydata/render": "^0.0.144",
24
+ "@malloydata/db-bigquery": "^0.0.145",
25
+ "@malloydata/db-duckdb": "^0.0.145",
26
+ "@malloydata/db-postgres": "^0.0.145",
27
+ "@malloydata/db-snowflake": "^0.0.145",
28
+ "@malloydata/db-trino": "^0.0.145",
29
+ "@malloydata/malloy": "^0.0.145",
30
+ "@malloydata/render": "^0.0.145",
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.144"
39
+ "version": "0.0.145"
40
40
  }
@@ -23,7 +23,7 @@
23
23
  */
24
24
 
25
25
  import {RuntimeList, allDatabases} from '../../runtimes';
26
- import {databasesFromEnvironmentOr} from '../../util';
26
+ import {brokenIn, databasesFromEnvironmentOr} from '../../util';
27
27
  import '../../util/db-jest-matchers';
28
28
  import * as malloy from '@malloydata/malloy';
29
29
 
@@ -112,29 +112,32 @@ expressionModels.forEach((expressionModel, databaseName) => {
112
112
  };
113
113
 
114
114
  describe('concat', () => {
115
- it(`works - ${databaseName}`, async () => {
116
- const expected = {
117
- 'bigquery': 'foo2003-01-01 12:00:00+00',
118
- 'snowflake': 'foo2003-01-01T12:00:00.000Z',
119
- };
120
-
121
- await funcTestMultiple(
122
- ["concat('foo', 'bar')", 'foobar'],
123
- ["concat(1, 'bar')", '1bar'],
124
- [
125
- "concat('cons', true)",
126
- databaseName === 'postgres' ? 'const' : 'construe',
127
- ],
128
- ["concat('foo', @2003)", 'foo2003-01-01'],
129
- [
130
- "concat('foo', @2003-01-01 12:00:00)",
131
- expected[databaseName] ?? 'foo2003-01-01 12:00:00',
132
- ],
133
- // TODO Maybe implement consistent null behavior
134
- // ["concat('foo', null)", null],
135
- ['concat()', '']
136
- );
137
- });
115
+ it.when(!brokenIn('trino', databaseName) /* crswenson */)(
116
+ `works - ${databaseName}`,
117
+ async () => {
118
+ const expected = {
119
+ 'bigquery': 'foo2003-01-01 12:00:00+00',
120
+ 'snowflake': 'foo2003-01-01T12:00:00.000Z',
121
+ };
122
+
123
+ await funcTestMultiple(
124
+ ["concat('foo', 'bar')", 'foobar'],
125
+ ["concat(1, 'bar')", '1bar'],
126
+ [
127
+ "concat('cons', true)",
128
+ databaseName === 'postgres' ? 'const' : 'construe',
129
+ ],
130
+ ["concat('foo', @2003)", 'foo2003-01-01'],
131
+ [
132
+ "concat('foo', @2003-01-01 12:00:00)",
133
+ expected[databaseName] ?? 'foo2003-01-01 12:00:00',
134
+ ],
135
+ // TODO Maybe implement consistent null behavior
136
+ // ["concat('foo', null)", null],
137
+ ['concat()', '']
138
+ );
139
+ }
140
+ );
138
141
  });
139
142
 
140
143
  describe('round', () => {
@@ -430,6 +433,33 @@ expressionModels.forEach((expressionModel, databaseName) => {
430
433
  expect(result.data.path(2, 'neg_r').value).toBe(-3);
431
434
  expect(result.data.path(3, 'neg_r').value).toBe(-3);
432
435
  });
436
+
437
+ it(`properly isolated nested calculations - ${databaseName}`, async () => {
438
+ const result = await expressionModel
439
+ .loadQuery(
440
+ `run: ${databaseName}.table('malloytest.airports') -> {
441
+ group_by: faa_region
442
+ aggregate: airport_count is count()
443
+ calculate: id is row_number()
444
+ nest: by_fac_type is {
445
+ group_by: fac_type
446
+ aggregate: airport_count is count()
447
+ calculate: id2 is row_number()
448
+ nest: elevation is {
449
+ aggregate: avg_elevation is elevation.avg()
450
+ }
451
+ limit: 2
452
+ }
453
+ }
454
+ -> {
455
+ // should be 2 rows, max of 2
456
+ group_by: by_fac_type.id2
457
+ order_by: id2 desc
458
+ }`
459
+ )
460
+ .run();
461
+ expect(result.data.path(0, 'id2').value).toBe(2);
462
+ });
433
463
  });
434
464
 
435
465
  describe('lag', () => {
@@ -24,7 +24,12 @@
24
24
 
25
25
  import {RuntimeList, allDatabases} from '../../runtimes';
26
26
  import '../../util/db-jest-matchers';
27
- import {databasesFromEnvironmentOr, mkSqlEqWith, runQuery} from '../../util';
27
+ import {
28
+ brokenIn,
29
+ databasesFromEnvironmentOr,
30
+ mkSqlEqWith,
31
+ runQuery,
32
+ } from '../../util';
28
33
  import {DateTime as LuxonDateTime} from 'luxon';
29
34
 
30
35
  const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));
@@ -457,15 +462,18 @@ describe.each(runtimes.runtimeList)('%s date and time', (dbName, runtime) => {
457
462
  });
458
463
  });
459
464
 
460
- test('dependant join dialect fragments', async () => {
461
- await expect(`
465
+ test.when(!brokenIn('trino', dbName) /* mtoy */)(
466
+ 'dependant join dialect fragments',
467
+ async () => {
468
+ await expect(`
462
469
  source: timeData is ${dbName}.sql("""${timeSQL}""")
463
470
  run: timeData -> {
464
471
  extend: {join_one: joined is timeData on t_date = joined.t_date}
465
472
  group_by: t_month is joined.t_timestamp.month
466
473
  }
467
474
  `).malloyResultMatches(runtime, {t_month: new Date('2021-02-01')});
468
- });
475
+ }
476
+ );
469
477
 
470
478
  describe('timezone set correctly', () => {
471
479
  test('timezone set in source used by query', async () => {
@@ -613,54 +621,63 @@ const utc_2020 = LuxonDateTime.fromObject(
613
621
  );
614
622
 
615
623
  describe.each(runtimes.runtimeList)('%s: tz literals', (dbName, runtime) => {
616
- test(`${dbName} - default timezone is UTC`, async () => {
617
- // this makes sure that the tests which use the test timezome are actually
618
- // testing something ... file this under "abundance of caution". It
619
- // really tests nothing, but I feel calmer with this here.
620
- const query = runtime.loadQuery(
621
- `
624
+ test.when(!brokenIn('trino', dbName) /* mtoy */)(
625
+ `${dbName} - default timezone is UTC`,
626
+ async () => {
627
+ // this makes sure that the tests which use the test timezome are actually
628
+ // testing something ... file this under "abundance of caution". It
629
+ // really tests nothing, but I feel calmer with this here.
630
+ const query = runtime.loadQuery(
631
+ `
622
632
  run: ${dbName}.sql("SELECT 1 as one") -> {
623
633
  group_by: literal_time is @2020-02-20 00:00:00
624
634
  }
625
635
  `
626
- );
627
- const result = await query.run();
628
- const literal = result.data.path(0, 'literal_time').value as Date;
629
- const have = LuxonDateTime.fromJSDate(literal);
630
- expect(have.valueOf()).toEqual(utc_2020.valueOf());
631
- });
632
-
633
- test('literal with zone name', async () => {
634
- const query = runtime.loadQuery(
635
- `
636
+ );
637
+ const result = await query.run();
638
+ const literal = result.data.path(0, 'literal_time').value as Date;
639
+ const have = LuxonDateTime.fromJSDate(literal);
640
+ expect(have.valueOf()).toEqual(utc_2020.valueOf());
641
+ }
642
+ );
643
+
644
+ test.when(!brokenIn('trino', dbName) /* mtoy */)(
645
+ 'literal with zone name',
646
+ async () => {
647
+ const query = runtime.loadQuery(
648
+ `
636
649
  run: ${dbName}.sql("SELECT 1 as one") -> {
637
650
  group_by: literal_time is @2020-02-20 00:00:00[America/Mexico_City]
638
651
  }
639
652
  `
640
- );
641
- const result = await query.run();
642
- const literal = result.data.path(0, 'literal_time').value as Date;
643
- const have = LuxonDateTime.fromJSDate(literal);
644
- expect(have.valueOf()).toEqual(zone_2020.valueOf());
645
- });
653
+ );
654
+ const result = await query.run();
655
+ const literal = result.data.path(0, 'literal_time').value as Date;
656
+ const have = LuxonDateTime.fromJSDate(literal);
657
+ expect(have.valueOf()).toEqual(zone_2020.valueOf());
658
+ }
659
+ );
646
660
  });
647
661
 
648
662
  describe.each(runtimes.runtimeList)('%s: query tz', (dbName, runtime) => {
649
663
  const q = runtime.getQuoter();
650
- test('literal timestamps', async () => {
651
- const query = runtime.loadQuery(
652
- `
664
+ test.when(!brokenIn('trino', dbName) /* mtoy */)(
665
+ 'literal timestamps',
666
+ async () => {
667
+ const query = runtime.loadQuery(
668
+ `
653
669
  run: ${dbName}.sql("SELECT 1 as one") -> {
654
670
  timezone: '${zone}'
655
671
  group_by: literal_time is @2020-02-20 00:00:00
656
672
  }
657
673
  `
658
- );
659
- const result = await query.run();
660
- const literal = result.data.path(0, 'literal_time').value as Date;
661
- const have = LuxonDateTime.fromJSDate(literal);
662
- expect(have.valueOf()).toEqual(zone_2020.valueOf());
663
- });
674
+ );
675
+ const result = await query.run();
676
+ const literal = result.data.path(0, 'literal_time').value as Date;
677
+ const have = LuxonDateTime.fromJSDate(literal);
678
+ expect(have.valueOf()).toEqual(zone_2020.valueOf());
679
+ }
680
+ );
664
681
 
665
682
  test('extract', async () => {
666
683
  await expect(
@@ -674,7 +691,7 @@ describe.each(runtimes.runtimeList)('%s: query tz', (dbName, runtime) => {
674
691
  ).malloyResultMatches(runtime, {mex_midnight: 18, mex_day: 19});
675
692
  });
676
693
 
677
- test('truncate day', async () => {
694
+ test.when(!brokenIn('trino', dbName) /* mtoy */)('truncate day', async () => {
678
695
  // At midnight in london it the 19th in Mexico, so that truncates to
679
696
  // midnight on the 19th
680
697
  const mex_19 = LuxonDateTime.fromISO('2020-02-19T00:00:00', {zone});
@@ -687,26 +704,32 @@ describe.each(runtimes.runtimeList)('%s: query tz', (dbName, runtime) => {
687
704
  ).malloyResultMatches(runtime, {mex_day: mex_19.toJSDate()});
688
705
  });
689
706
 
690
- test('cast timestamp to date', async () => {
691
- // At midnight in london it is the 19th in Mexico, so when we cast that
692
- // to a date, it should be the 19th.
693
- await expect(
694
- `run: ${dbName}.sql("SELECT 1 as x") -> {
707
+ test.when(!brokenIn('trino', dbName) /* mtoy */)(
708
+ 'cast timestamp to date',
709
+ async () => {
710
+ // At midnight in london it is the 19th in Mexico, so when we cast that
711
+ // to a date, it should be the 19th.
712
+ await expect(
713
+ `run: ${dbName}.sql("SELECT 1 as x") -> {
695
714
  timezone: '${zone}'
696
715
  extend: { dimension: utc_midnight is @2020-02-20 00:00:00[UTC] }
697
716
  select: mex_day is day(utc_midnight::date)
698
717
  }`
699
- ).malloyResultMatches(runtime, {mex_day: 19});
700
- });
701
-
702
- test('cast date to timestamp', async () => {
703
- await expect(
704
- `run: ${dbName}.sql(""" SELECT DATE '2020-02-20' AS ${q`mex_20`} """) -> {
718
+ ).malloyResultMatches(runtime, {mex_day: 19});
719
+ }
720
+ );
721
+
722
+ test.when(!brokenIn('trino', dbName) /* mtoy */)(
723
+ 'cast date to timestamp',
724
+ async () => {
725
+ await expect(
726
+ `run: ${dbName}.sql(""" SELECT DATE '2020-02-20' AS ${q`mex_20`} """) -> {
705
727
  timezone: '${zone}'
706
728
  select: mex_ts is mex_20::timestamp
707
729
  }`
708
- ).malloyResultMatches(runtime, {mex_ts: zone_2020.toJSDate()});
709
- });
730
+ ).malloyResultMatches(runtime, {mex_ts: zone_2020.toJSDate()});
731
+ }
732
+ );
710
733
  });
711
734
 
712
735
  afterAll(async () => {