@malloydata/malloy-tests 0.0.215 → 0.0.216-dev241118202522

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.215",
25
- "@malloydata/db-duckdb": "^0.0.215",
26
- "@malloydata/db-postgres": "^0.0.215",
27
- "@malloydata/db-snowflake": "^0.0.215",
28
- "@malloydata/db-trino": "^0.0.215",
29
- "@malloydata/malloy": "^0.0.215",
30
- "@malloydata/render": "^0.0.215",
24
+ "@malloydata/db-bigquery": "^0.0.216-dev241118202522",
25
+ "@malloydata/db-duckdb": "^0.0.216-dev241118202522",
26
+ "@malloydata/db-postgres": "^0.0.216-dev241118202522",
27
+ "@malloydata/db-snowflake": "^0.0.216-dev241118202522",
28
+ "@malloydata/db-trino": "^0.0.216-dev241118202522",
29
+ "@malloydata/malloy": "^0.0.216-dev241118202522",
30
+ "@malloydata/render": "^0.0.216-dev241118202522",
31
31
  "events": "^3.3.0",
32
32
  "jsdom": "^22.1.0",
33
33
  "luxon": "^2.4.0",
@@ -37,5 +37,5 @@
37
37
  "@types/jsdom": "^21.1.1",
38
38
  "@types/luxon": "^2.4.0"
39
39
  },
40
- "version": "0.0.215"
40
+ "version": "0.0.216-dev241118202522"
41
41
  }
@@ -0,0 +1,177 @@
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, allDatabases} from '../../runtimes';
9
+ import {databasesFromEnvironmentOr} from '../../util';
10
+ import '../../util/db-jest-matchers';
11
+
12
+ const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));
13
+
14
+ afterAll(async () => {
15
+ await runtimes.closeAll();
16
+ });
17
+
18
+ runtimes.runtimeMap.forEach((runtime, databaseName) => {
19
+ it(`basic composite usage - ${databaseName}`, async () => {
20
+ await expect(`
21
+ ##! experimental.composite_sources
22
+ source: state_facts is ${databaseName}.table('malloytest.state_facts')
23
+ source: x is compose(state_facts, state_facts extend { dimension: foo is 1 })
24
+ run: x -> { group_by: foo }
25
+ `).malloyResultMatches(runtime, {foo: 1});
26
+ });
27
+ it(`composite source used in join - ${databaseName}`, async () => {
28
+ await expect(`
29
+ ##! experimental.composite_sources
30
+ source: state_facts is ${databaseName}.table('malloytest.state_facts')
31
+ source: x is compose(state_facts, state_facts extend { dimension: foo is 1 })
32
+ source: y is ${databaseName}.table('malloytest.state_facts') extend {
33
+ join_one: x on x.state = state
34
+ }
35
+ run: y -> { group_by: x.foo }
36
+ `).malloyResultMatches(runtime, {foo: 1});
37
+ });
38
+ it(`composite used in join on - ${databaseName}`, async () => {
39
+ await expect(`
40
+ ##! experimental.composite_sources
41
+ source: state_facts is ${databaseName}.table('malloytest.state_facts')
42
+ source: x is compose(state_facts, state_facts extend { dimension: state_copy is state })
43
+ source: y is ${databaseName}.table('malloytest.state_facts') extend {
44
+ // Join california by testing state copy;
45
+ // composite field usage is in join on, so the composite source with state_copy should
46
+ // be selected whenever this join is used
47
+ join_one: ca is x on ca.state_copy = 'CA'
48
+ }
49
+ run: y -> { group_by: ca.state; where: state = 'IL' }
50
+ `).malloyResultMatches(runtime, {state: 'CA'});
51
+ });
52
+ // TODO test always join composite field usage
53
+ it(`composite field used in view - ${databaseName}`, async () => {
54
+ await expect(`
55
+ ##! experimental.composite_sources
56
+ source: state_facts is ${databaseName}.table('malloytest.state_facts')
57
+ source: x is compose(state_facts, state_facts extend { dimension: foo is 1 }) extend {
58
+ view: v is { group_by: foo }
59
+ }
60
+ run: x -> v
61
+ `).malloyResultMatches(runtime, {foo: 1});
62
+ });
63
+ it(`composite field used in view refined with scalar - ${databaseName}`, async () => {
64
+ await expect(`
65
+ ##! experimental.composite_sources
66
+ source: state_facts is ${databaseName}.table('malloytest.state_facts')
67
+ source: x is compose(state_facts, state_facts extend { dimension: foo is 1 }) extend {
68
+ view: v is {
69
+ group_by: state
70
+ where: state = 'CA'
71
+ limit: 1
72
+ }
73
+ }
74
+ run: x -> v + foo
75
+ `).malloyResultMatches(runtime, {foo: 1, state: 'CA'});
76
+ });
77
+ it(`composite field used in view refined with literal view - ${databaseName}`, async () => {
78
+ await expect(`
79
+ ##! experimental.composite_sources
80
+ source: state_facts is ${databaseName}.table('malloytest.state_facts')
81
+ source: x is compose(state_facts, state_facts extend { dimension: foo is 1 }) extend {
82
+ view: v is {
83
+ group_by: state
84
+ where: state = 'CA'
85
+ limit: 1
86
+ }
87
+ }
88
+ run: x -> v + { group_by: foo }
89
+ `).malloyResultMatches(runtime, {foo: 1, state: 'CA'});
90
+ });
91
+ it(`composite field used in refined query - ${databaseName}`, async () => {
92
+ await expect(`
93
+ ##! experimental.composite_sources
94
+ source: state_facts is ${databaseName}.table('malloytest.state_facts')
95
+ source: x is compose(state_facts, state_facts extend { dimension: foo is 1 }) extend {
96
+ view: v is {
97
+ group_by: state
98
+ where: state = 'CA'
99
+ limit: 1
100
+ }
101
+ }
102
+ query: v is x -> v
103
+ run: v + { group_by: foo }
104
+ `).malloyResultMatches(runtime, {foo: 1, state: 'CA'});
105
+ });
106
+ it(`composite of a composite - ${databaseName}`, async () => {
107
+ await expect(`
108
+ ##! experimental.composite_sources
109
+ source: state_facts is ${databaseName}.table('malloytest.state_facts')
110
+ source: x is compose(
111
+ state_facts,
112
+ state_facts extend { dimension: foo is 1 }
113
+ )
114
+ source: y is compose(
115
+ x,
116
+ x extend { dimension: bar is 2 }
117
+ )
118
+ // in order to get bar, we need to use the second composite input, which is itself a composite source
119
+ // then in order to get foo, we need to resolve the inner composite source to its second input
120
+ run: y -> { group_by: foo, bar }
121
+ `).malloyResultMatches(runtime, {foo: 1, bar: 2});
122
+ });
123
+ it(`definitions from composite extension carry through - ${databaseName}`, async () => {
124
+ await expect(`
125
+ ##! experimental.composite_sources
126
+ source: state_facts is ${databaseName}.table('malloytest.state_facts')
127
+ source: x is compose(
128
+ state_facts,
129
+ state_facts extend { dimension: foo is 1 }
130
+ ) extend {
131
+ dimension: bar is 2
132
+ }
133
+ run: x -> { group_by: foo, bar }
134
+ `).malloyResultMatches(runtime, {foo: 1, bar: 2});
135
+ });
136
+ it(`filters from composite extension carry through - ${databaseName}`, async () => {
137
+ await expect(`
138
+ ##! experimental.composite_sources
139
+ source: state_facts is ${databaseName}.table('malloytest.state_facts')
140
+ source: x is compose(
141
+ state_facts,
142
+ state_facts extend { dimension: foo is 1 }
143
+ ) extend {
144
+ where: state = 'CA'
145
+ }
146
+ run: x -> { group_by: foo, state }
147
+ `).malloyResultMatches(runtime, {foo: 1, state: 'CA'});
148
+ });
149
+ it(`composite of a composite where greedy is bad- ${databaseName}`, async () => {
150
+ await expect(`
151
+ ##! experimental.composite_sources
152
+ source: state_facts is ${databaseName}.table('malloytest.state_facts')
153
+ source: x is compose(
154
+ compose(
155
+ state_facts extend { dimension: foo is 1.1, bar is 2.1 },
156
+ state_facts extend { dimension: foo is 1.2, baz is 3.2 }
157
+ ),
158
+ state_facts extend { dimension: foo is 1.3, bar is 2.3, baz is 3.3 }
159
+ )
160
+ // even though the first composite has all the fields foo, bar, baz; it is impossible
161
+ // to resolve it using the first composite, because you can't have both bar and baz
162
+ // so the second input source is used instead
163
+ run: x -> { group_by: foo, bar, baz }
164
+ `).malloyResultMatches(runtime, {foo: 1.3, bar: 2.3, baz: 3.3});
165
+ });
166
+ it(`composite with parameters - ${databaseName}`, async () => {
167
+ await expect(`
168
+ ##! experimental { composite_sources parameters }
169
+ source: state_facts is ${databaseName}.table('malloytest.state_facts')
170
+ source: x(param is 1) is compose(
171
+ state_facts extend { dimension: a is param },
172
+ state_facts extend { dimension: b is param + 1 }
173
+ )
174
+ run: x(param is 2) -> { group_by: b }
175
+ `).malloyResultMatches(runtime, {b: 3});
176
+ });
177
+ });