@malloydata/malloy-tests 0.0.193 → 0.0.194-dev241001212731

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.193",
25
- "@malloydata/db-duckdb": "^0.0.193",
26
- "@malloydata/db-postgres": "^0.0.193",
27
- "@malloydata/db-snowflake": "^0.0.193",
28
- "@malloydata/db-trino": "^0.0.193",
29
- "@malloydata/malloy": "^0.0.193",
30
- "@malloydata/render": "^0.0.193",
24
+ "@malloydata/db-bigquery": "^0.0.194-dev241001212731",
25
+ "@malloydata/db-duckdb": "^0.0.194-dev241001212731",
26
+ "@malloydata/db-postgres": "^0.0.194-dev241001212731",
27
+ "@malloydata/db-snowflake": "^0.0.194-dev241001212731",
28
+ "@malloydata/db-trino": "^0.0.194-dev241001212731",
29
+ "@malloydata/malloy": "^0.0.194-dev241001212731",
30
+ "@malloydata/render": "^0.0.194-dev241001212731",
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.193"
39
+ "version": "0.0.194-dev241001212731"
40
40
  }
@@ -0,0 +1,149 @@
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} from '../../runtimes';
9
+ import '../../util/db-jest-matchers';
10
+ import {describeIfDatabaseAvailable} from '../../util';
11
+ import {Explore, Field} from '@malloydata/malloy';
12
+
13
+ const [describe, databases] = describeIfDatabaseAvailable(['duckdb']);
14
+ const dbs = new RuntimeList(databases);
15
+
16
+ function referenceId(field: Field | Explore) {
17
+ if (field.isExplore() || field.isQueryField()) {
18
+ return undefined;
19
+ }
20
+ return field.referenceId;
21
+ }
22
+
23
+ describe.each(dbs.runtimeList)('%s', (dbName, runtime) => {
24
+ describe('reference id', () => {
25
+ it('is correct for field references in table', async () => {
26
+ const query = `
27
+ run: duckdb.sql("SELECT 1 as one") -> {
28
+ group_by: one
29
+ nest: a is {
30
+ group_by: one
31
+ }
32
+ nest: b is {
33
+ group_by: one is "fake"
34
+ }
35
+ nest: c is {
36
+ # this reference has an annotation
37
+ group_by: one
38
+ }
39
+ }
40
+ `;
41
+
42
+ const result = await runtime.loadQuery(query).run();
43
+ const actual = referenceId(result.data.path(0, 'one').field);
44
+ expect(actual).not.toBeUndefined();
45
+ expect(referenceId(result.data.path(0, 'a', 0, 'one').field)).toBe(
46
+ actual
47
+ );
48
+ const bOne = referenceId(result.data.path(0, 'b', 0, 'one').field);
49
+ expect(bOne).not.toBe(undefined);
50
+ expect(bOne).not.toBe(actual);
51
+ expect(referenceId(result.data.path(0, 'c', 0, 'one').field)).toBe(
52
+ actual
53
+ );
54
+ });
55
+
56
+ it('is correct for measures', async () => {
57
+ const query = `
58
+ run: duckdb.sql("SELECT 1 as one") extend {
59
+ measure: c is count()
60
+ } -> {
61
+ aggregate: c
62
+ nest: a is {
63
+ aggregate: c
64
+ }
65
+ nest: b is {
66
+ aggregate: c is count() * 2
67
+ }
68
+ nest: d is {
69
+ # this reference has an annotation
70
+ aggregate: c
71
+ }
72
+ }
73
+ `;
74
+
75
+ const result = await runtime.loadQuery(query).run();
76
+ const actual = referenceId(result.data.path(0, 'c').field);
77
+ expect(actual).not.toBeUndefined();
78
+ expect(referenceId(result.data.path(0, 'a', 'c').field)).toBe(actual);
79
+ const bC = referenceId(result.data.path(0, 'b', 'c').field);
80
+ expect(bC).not.toBe(undefined);
81
+ expect(bC).not.toBe(actual);
82
+ expect(referenceId(result.data.path(0, 'd', 'c').field)).toBe(actual);
83
+ });
84
+
85
+ it('is correct for field references from extend block', async () => {
86
+ const query = `
87
+ run: duckdb.sql("SELECT 1 as one") -> {
88
+ extend: {
89
+ dimension: two is 2
90
+ }
91
+ group_by: two
92
+ nest: a is {
93
+ group_by: two
94
+ }
95
+ nest: b is {
96
+ group_by: two is "fake"
97
+ }
98
+ nest: c is {
99
+ # this reference has an annotation
100
+ group_by: two
101
+ }
102
+ }
103
+ `;
104
+
105
+ const result = await runtime.loadQuery(query).run();
106
+ const actual = referenceId(result.data.path(0, 'two').field);
107
+ expect(actual).not.toBeUndefined();
108
+ expect(referenceId(result.data.path(0, 'a', 0, 'two').field)).toBe(
109
+ actual
110
+ );
111
+ const bTwo = referenceId(result.data.path(0, 'b', 0, 'two').field);
112
+ expect(bTwo).not.toBe(undefined);
113
+ expect(bTwo).not.toBe(actual);
114
+ expect(referenceId(result.data.path(0, 'c', 0, 'two').field)).toBe(
115
+ actual
116
+ );
117
+ });
118
+
119
+ it.skip('is unequal for different nest/extend blocks', async () => {
120
+ const query = `
121
+ run: duckdb.sql("SELECT 1 as one") -> {
122
+ nest: a is {
123
+ extend: {
124
+ dimension: three is 3
125
+ }
126
+ group_by: three
127
+ }
128
+ nest: b is {
129
+ extend: {
130
+ dimension: three is 4
131
+ }
132
+ group_by: three
133
+ }
134
+ }
135
+ `;
136
+
137
+ const result = await runtime.loadQuery(query).run();
138
+ const actual = referenceId(result.data.path(0, 'a', 0, 'three').field);
139
+ expect(actual).not.toBeUndefined();
140
+ expect(referenceId(result.data.path(0, 'b', 0, 'three').field)).toBe(
141
+ actual
142
+ );
143
+ });
144
+ });
145
+ });
146
+
147
+ afterAll(async () => {
148
+ await dbs.closeAll();
149
+ });