@malloydata/malloy-tests 0.0.67 → 0.0.68-dev230808194809
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/dist/databases/all/db_index.spec.d.ts +1 -0
- package/dist/databases/all/db_index.spec.js +36 -0
- package/dist/databases/all/db_index.spec.js.map +1 -0
- package/dist/databases/all/expr.spec.d.ts +0 -2
- package/dist/databases/all/expr.spec.js +2 -547
- package/dist/databases/all/expr.spec.js.map +1 -1
- package/dist/databases/all/functions.spec.d.ts +1 -2
- package/dist/databases/all/functions.spec.js +2 -751
- package/dist/databases/all/functions.spec.js.map +1 -1
- package/dist/databases/all/join.spec.d.ts +1 -2
- package/dist/databases/all/join.spec.js +2 -276
- package/dist/databases/all/join.spec.js.map +1 -1
- package/dist/databases/all/nomodel.spec.d.ts +1 -2
- package/dist/databases/all/nomodel.spec.js +2 -923
- package/dist/databases/all/nomodel.spec.js.map +1 -1
- package/dist/databases/all/orderby.spec.d.ts +1 -2
- package/dist/databases/all/orderby.spec.js +2 -191
- package/dist/databases/all/orderby.spec.js.map +1 -1
- package/dist/databases/all/problems.spec.d.ts +1 -2
- package/dist/databases/all/problems.spec.js +2 -80
- package/dist/databases/all/problems.spec.js.map +1 -1
- package/dist/databases/all/sql_expressions.spec.d.ts +1 -2
- package/dist/databases/all/sql_expressions.spec.js +2 -62
- package/dist/databases/all/sql_expressions.spec.js.map +1 -1
- package/dist/databases/all/time.spec.d.ts +1 -3
- package/dist/databases/all/time.spec.js +2 -615
- package/dist/databases/all/time.spec.js.map +1 -1
- package/dist/databases/{all/index.spec.d.ts → shared/db_index.d.ts} +1 -0
- package/dist/databases/{all/index.spec.js → shared/db_index.js} +2 -33
- package/dist/databases/shared/db_index.js.map +1 -0
- package/dist/databases/shared/expr.d.ts +3 -0
- package/dist/databases/shared/expr.js +551 -0
- package/dist/databases/shared/expr.js.map +1 -0
- package/dist/databases/shared/functions.d.ts +3 -0
- package/dist/databases/shared/functions.js +754 -0
- package/dist/databases/shared/functions.js.map +1 -0
- package/dist/databases/shared/join.d.ts +3 -0
- package/dist/databases/shared/join.js +302 -0
- package/dist/databases/shared/join.js.map +1 -0
- package/dist/databases/shared/nomodel.d.ts +3 -0
- package/dist/databases/shared/nomodel.js +950 -0
- package/dist/databases/shared/nomodel.js.map +1 -0
- package/dist/databases/shared/orderby.d.ts +3 -0
- package/dist/databases/shared/orderby.js +217 -0
- package/dist/databases/shared/orderby.js.map +1 -0
- package/dist/databases/shared/problems.d.ts +3 -0
- package/dist/databases/shared/problems.js +106 -0
- package/dist/databases/shared/problems.js.map +1 -0
- package/dist/databases/shared/sql_expressions.d.ts +3 -0
- package/dist/databases/shared/sql_expressions.js +88 -0
- package/dist/databases/shared/sql_expressions.js.map +1 -0
- package/dist/databases/shared/test_list.js +18 -18
- package/dist/databases/shared/test_list.js.map +1 -1
- package/dist/databases/shared/time.d.ts +3 -0
- package/dist/databases/shared/time.js +640 -0
- package/dist/databases/shared/time.js.map +1 -0
- package/dist/index.d.ts +9 -10
- package/dist/index.js +19 -21
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/databases/all/db_index.spec.ts +37 -0
- package/src/databases/all/expr.spec.ts +2 -670
- package/src/databases/all/functions.spec.ts +1 -1101
- package/src/databases/all/join.spec.ts +1 -315
- package/src/databases/all/nomodel.spec.ts +2 -1124
- package/src/databases/all/orderby.spec.ts +1 -234
- package/src/databases/all/problems.spec.ts +1 -87
- package/src/databases/all/sql_expressions.spec.ts +1 -71
- package/src/databases/all/time.spec.ts +1 -761
- package/src/databases/{all/index.spec.ts → shared/db_index.ts} +2 -13
- package/src/databases/shared/expr.ts +695 -0
- package/src/databases/shared/functions.ts +1126 -0
- package/src/databases/shared/join.ts +340 -0
- package/src/databases/shared/nomodel.ts +1150 -0
- package/src/databases/shared/orderby.ts +260 -0
- package/src/databases/shared/problems.ts +113 -0
- package/src/databases/shared/sql_expressions.ts +96 -0
- package/src/databases/shared/test_list.ts +9 -9
- package/src/databases/shared/time.ts +786 -0
- package/src/index.ts +10 -11
- package/dist/databases/all/index.spec.js.map +0 -1
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import {RuntimeList} from '../../runtimes';
|
|
26
|
+
import '../../util/db-jest-matchers';
|
|
27
|
+
const joinModelText = `
|
|
28
|
+
source: aircraft_models is table('malloytest.aircraft_models') {
|
|
29
|
+
primary_key: aircraft_model_code
|
|
30
|
+
measure: model_count is count(*)
|
|
31
|
+
query: manufacturer_models is {
|
|
32
|
+
group_by: manufacturer
|
|
33
|
+
aggregate: num_models is count(*)
|
|
34
|
+
}
|
|
35
|
+
query: manufacturer_seats is {
|
|
36
|
+
group_by: manufacturer
|
|
37
|
+
aggregate: total_seats is seats.sum()
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
source: aircraft is table('malloytest.aircraft'){
|
|
42
|
+
primary_key: tail_num
|
|
43
|
+
measure: aircraft_count is count(*)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
source: funnel is from(aircraft_models->manufacturer_models) {
|
|
47
|
+
join_one: seats is from(aircraft_models->manufacturer_seats)
|
|
48
|
+
with manufacturer
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
// const models = new Map<string, malloy.ModelMaterializer>();
|
|
53
|
+
// runtimes.runtimeMap.forEach((runtime, key) => {
|
|
54
|
+
// models.set(key, runtime.loadModel(joinModelText));
|
|
55
|
+
// });
|
|
56
|
+
|
|
57
|
+
export const joinSharedTests = (
|
|
58
|
+
runtimes: RuntimeList,
|
|
59
|
+
_splitFunction?: (column: string, splitChar: string) => string
|
|
60
|
+
) => {
|
|
61
|
+
afterAll(async () => {
|
|
62
|
+
await runtimes.closeAll();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('join expression tests', () => {
|
|
66
|
+
runtimes.runtimeMap.forEach((runtime, database) => {
|
|
67
|
+
it(`model source refine join - ${database}`, async () => {
|
|
68
|
+
const result = await runtime
|
|
69
|
+
.loadModel(joinModelText)
|
|
70
|
+
.loadQuery(
|
|
71
|
+
`
|
|
72
|
+
source: a2 is aircraft {
|
|
73
|
+
join_one: aircraft_models with aircraft_model_code
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
query: a2 -> {
|
|
77
|
+
aggregate:
|
|
78
|
+
aircraft_count
|
|
79
|
+
aircraft_models.model_count
|
|
80
|
+
}
|
|
81
|
+
`
|
|
82
|
+
)
|
|
83
|
+
.run();
|
|
84
|
+
expect(result.data.value[0]['model_count']).toBe(1416);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it(`model source refine in query join - ${database}`, async () => {
|
|
88
|
+
const result = await runtime
|
|
89
|
+
.loadModel(joinModelText)
|
|
90
|
+
.loadQuery(
|
|
91
|
+
`
|
|
92
|
+
query: aircraft {
|
|
93
|
+
join_one: aircraft_models with aircraft_model_code
|
|
94
|
+
} -> {
|
|
95
|
+
aggregate:
|
|
96
|
+
aircraft_count
|
|
97
|
+
aircraft_models.model_count
|
|
98
|
+
}
|
|
99
|
+
`
|
|
100
|
+
)
|
|
101
|
+
.run();
|
|
102
|
+
expect(result.data.value[0]['model_count']).toBe(1416);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it(`model: join fact table query - ${database}`, async () => {
|
|
106
|
+
const result = await runtime
|
|
107
|
+
.loadModel(joinModelText)
|
|
108
|
+
.loadQuery(
|
|
109
|
+
`
|
|
110
|
+
query: aircraft_models {
|
|
111
|
+
join_one: am_facts is from(
|
|
112
|
+
aircraft_models->{
|
|
113
|
+
group_by: m is manufacturer
|
|
114
|
+
aggregate: num_models is count(*)
|
|
115
|
+
}) with manufacturer
|
|
116
|
+
} -> {
|
|
117
|
+
project:
|
|
118
|
+
manufacturer
|
|
119
|
+
am_facts.num_models
|
|
120
|
+
order_by: 2 desc
|
|
121
|
+
limit: 1
|
|
122
|
+
}
|
|
123
|
+
`
|
|
124
|
+
)
|
|
125
|
+
.run();
|
|
126
|
+
expect(result.data.value[0]['num_models']).toBe(1147);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it(`model: source based on query - ${database}`, async () => {
|
|
130
|
+
const result = await runtime
|
|
131
|
+
.loadModel(joinModelText)
|
|
132
|
+
.loadQuery(
|
|
133
|
+
`
|
|
134
|
+
query:
|
|
135
|
+
aircraft_models-> {
|
|
136
|
+
group_by: m is manufacturer
|
|
137
|
+
aggregate: num_models is count(*)
|
|
138
|
+
}
|
|
139
|
+
-> {
|
|
140
|
+
project:
|
|
141
|
+
m
|
|
142
|
+
num_models
|
|
143
|
+
order_by: 2 desc
|
|
144
|
+
limit: 1
|
|
145
|
+
}
|
|
146
|
+
`
|
|
147
|
+
)
|
|
148
|
+
.run();
|
|
149
|
+
expect(result.data.value[0]['num_models']).toBe(1147);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it(`model: funnel - merge two queries - ${database}`, async () => {
|
|
153
|
+
const result = await runtime
|
|
154
|
+
.loadModel(joinModelText)
|
|
155
|
+
.loadQuery(
|
|
156
|
+
`
|
|
157
|
+
query: from(aircraft_models->{
|
|
158
|
+
group_by: m is manufacturer
|
|
159
|
+
aggregate: num_models is count(*)
|
|
160
|
+
}){
|
|
161
|
+
join_one: seats is from(
|
|
162
|
+
aircraft_models->{
|
|
163
|
+
group_by: m is manufacturer
|
|
164
|
+
aggregate: total_seats is seats.sum()
|
|
165
|
+
}
|
|
166
|
+
) with m
|
|
167
|
+
}
|
|
168
|
+
-> {
|
|
169
|
+
project:
|
|
170
|
+
m
|
|
171
|
+
num_models
|
|
172
|
+
seats.total_seats
|
|
173
|
+
order_by: 2 desc
|
|
174
|
+
limit: 1
|
|
175
|
+
}
|
|
176
|
+
`
|
|
177
|
+
)
|
|
178
|
+
.run();
|
|
179
|
+
expect(result.data.value[0]['num_models']).toBe(1147);
|
|
180
|
+
expect(result.data.value[0]['total_seats']).toBe(252771);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it(`model: modeled funnel - ${database}`, async () => {
|
|
184
|
+
const result = await runtime
|
|
185
|
+
.loadModel(joinModelText)
|
|
186
|
+
.loadQuery(
|
|
187
|
+
`
|
|
188
|
+
source: foo is from(aircraft_models-> manufacturer_models){
|
|
189
|
+
join_one: seats is from(aircraft_models->manufacturer_seats)
|
|
190
|
+
with manufacturer
|
|
191
|
+
}
|
|
192
|
+
query: foo-> {
|
|
193
|
+
project:
|
|
194
|
+
manufacturer,
|
|
195
|
+
num_models,
|
|
196
|
+
seats.total_seats
|
|
197
|
+
order_by: 2 desc
|
|
198
|
+
limit: 1
|
|
199
|
+
}
|
|
200
|
+
`
|
|
201
|
+
)
|
|
202
|
+
.run();
|
|
203
|
+
expect(result.data.value[0]['num_models']).toBe(1147);
|
|
204
|
+
expect(result.data.value[0]['total_seats']).toBe(252771);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it(`model: modeled funnel2 - ${database}`, async () => {
|
|
208
|
+
const result = await runtime
|
|
209
|
+
.loadModel(joinModelText)
|
|
210
|
+
.loadQuery(
|
|
211
|
+
`
|
|
212
|
+
query: funnel->{
|
|
213
|
+
project:
|
|
214
|
+
manufacturer
|
|
215
|
+
num_models
|
|
216
|
+
seats.total_seats
|
|
217
|
+
order_by: 2 desc
|
|
218
|
+
limit: 1
|
|
219
|
+
}
|
|
220
|
+
`
|
|
221
|
+
)
|
|
222
|
+
.run();
|
|
223
|
+
expect(result.data.value[0]['num_models']).toBe(1147);
|
|
224
|
+
expect(result.data.value[0]['total_seats']).toBe(252771);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it(`model: double_pipe - ${database}`, async () => {
|
|
228
|
+
const result = await runtime
|
|
229
|
+
.loadModel(joinModelText)
|
|
230
|
+
.loadQuery(
|
|
231
|
+
`
|
|
232
|
+
query: aircraft_models->{
|
|
233
|
+
group_by: manufacturer
|
|
234
|
+
aggregate: f is count(*)
|
|
235
|
+
}->{
|
|
236
|
+
aggregate: f_sum is f.sum()
|
|
237
|
+
}->{
|
|
238
|
+
project: f_sum2 is f_sum+1
|
|
239
|
+
}
|
|
240
|
+
`
|
|
241
|
+
)
|
|
242
|
+
.run();
|
|
243
|
+
expect(result.data.value[0]['f_sum2']).toBe(60462);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test(`model: unnest is left join - ${database}`, async () => {
|
|
247
|
+
const result = await runtime
|
|
248
|
+
.loadModel(joinModelText)
|
|
249
|
+
.loadQuery(
|
|
250
|
+
`
|
|
251
|
+
// produce a table with 4 rows that has a nested element
|
|
252
|
+
query: a_states is table('malloytest.state_facts')-> {
|
|
253
|
+
where: state ? ~ 'A%'
|
|
254
|
+
group_by: state
|
|
255
|
+
nest: somthing is {group_by: state}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// join the 4 rows and reference the
|
|
259
|
+
// nested column. should return all the rows.
|
|
260
|
+
// If the unnest is an inner join, we'll get back just 4 rows.
|
|
261
|
+
query: table('malloytest.state_facts') {
|
|
262
|
+
join_one: a_states is from(->a_states) with state
|
|
263
|
+
}
|
|
264
|
+
-> {
|
|
265
|
+
group_by: state
|
|
266
|
+
aggregate: c is count()
|
|
267
|
+
nest: a is {
|
|
268
|
+
group_by: a_states.somthing.state
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
`
|
|
272
|
+
)
|
|
273
|
+
.run();
|
|
274
|
+
// console.log(result.data.toObject());
|
|
275
|
+
expect(result.data.rowCount).toBeGreaterThan(4);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
// not sure how to solve this one yet.
|
|
279
|
+
it(`All joins at the same level - ${database}`, async () => {
|
|
280
|
+
const result = await runtime
|
|
281
|
+
.loadQuery(
|
|
282
|
+
`
|
|
283
|
+
source: flights is table('malloytest.flights') {
|
|
284
|
+
join_one: aircraft is table('malloytest.aircraft')
|
|
285
|
+
on tail_num = aircraft.tail_num
|
|
286
|
+
join_one: aircraft_models is table('malloytest.aircraft_models')
|
|
287
|
+
on aircraft.aircraft_model_code = aircraft_models.aircraft_model_code
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
query: flights -> {
|
|
291
|
+
group_by: aircraft_models.seats
|
|
292
|
+
aggregate: flight_count is count()
|
|
293
|
+
}
|
|
294
|
+
`
|
|
295
|
+
)
|
|
296
|
+
.run();
|
|
297
|
+
// console.log(result.data.toObject());
|
|
298
|
+
expect(result.data.rowCount).toBeGreaterThan(4);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it(`join issue440 - ${database}`, async () => {
|
|
302
|
+
const result = await runtime
|
|
303
|
+
.loadQuery(
|
|
304
|
+
`
|
|
305
|
+
source: aircraft_models is table('malloytest.aircraft_models')
|
|
306
|
+
|
|
307
|
+
source: aircraft is table('malloytest.aircraft')
|
|
308
|
+
|
|
309
|
+
source: flights is table('malloytest.flights'){
|
|
310
|
+
join_one: aircraft on aircraft.tail_num = tail_num
|
|
311
|
+
join_one: aircraft_models on aircraft_models.aircraft_model_code = aircraft.aircraft_model_code
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
query: flights-> {
|
|
315
|
+
group_by: testingtwo is aircraft_models.model
|
|
316
|
+
}
|
|
317
|
+
`
|
|
318
|
+
)
|
|
319
|
+
.run();
|
|
320
|
+
// console.log(result.data.toObject());
|
|
321
|
+
expect(result.data.rowCount).toBeGreaterThan(4);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it(`join issue1092 - ${database}`, async () => {
|
|
325
|
+
const result = await runtime
|
|
326
|
+
.loadQuery(
|
|
327
|
+
`
|
|
328
|
+
query: table('malloytest.state_facts') -> {
|
|
329
|
+
join_one: sf is table('malloytest.state_facts') on sf.state = state
|
|
330
|
+
aggregate: x is sf.births.sum() { ? state = 'CA' }
|
|
331
|
+
}
|
|
332
|
+
`
|
|
333
|
+
)
|
|
334
|
+
.run();
|
|
335
|
+
// console.log(result.data.toObject());
|
|
336
|
+
expect(result.data.rowCount).toBe(1);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
};
|