@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
|
@@ -24,240 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
import {RuntimeList, allDatabases} from '../../runtimes';
|
|
26
26
|
import {databasesFromEnvironmentOr} from '../../util';
|
|
27
|
-
import
|
|
28
|
-
|
|
29
|
-
export const orderBySharedTests = (
|
|
30
|
-
runtimes: RuntimeList,
|
|
31
|
-
_splitFunction?: (column: string, splitChar: string) => string
|
|
32
|
-
) => {
|
|
33
|
-
afterAll(async () => {
|
|
34
|
-
await runtimes.closeAll();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
async function validateCompilation(
|
|
38
|
-
databaseName: string,
|
|
39
|
-
sql: string
|
|
40
|
-
): Promise<boolean> {
|
|
41
|
-
try {
|
|
42
|
-
const runtime = runtimes.runtimeMap.get(databaseName);
|
|
43
|
-
if (runtime === undefined) {
|
|
44
|
-
throw new Error(`Unknown database ${databaseName}`);
|
|
45
|
-
}
|
|
46
|
-
await (
|
|
47
|
-
await runtime.connections.lookupConnection(databaseName)
|
|
48
|
-
).runSQL(`WITH test AS(\n${sql}) SELECT '[{"foo":1}]' as results`);
|
|
49
|
-
} catch (e) {
|
|
50
|
-
console.log(`SQL: didn't compile\n=============\n${sql}`);
|
|
51
|
-
throw e;
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const expressionModels = new Map<string, malloy.ModelMaterializer>();
|
|
57
|
-
runtimes.runtimeMap.forEach((runtime, databaseName) =>
|
|
58
|
-
expressionModels.set(
|
|
59
|
-
databaseName,
|
|
60
|
-
runtime.loadModel(`
|
|
61
|
-
source: models is table('malloytest.aircraft_models'){
|
|
62
|
-
measure: model_count is count()
|
|
63
|
-
}
|
|
64
|
-
`)
|
|
65
|
-
)
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
expressionModels.forEach((orderByModel, databaseName) => {
|
|
69
|
-
it(`boolean type - ${databaseName}`, async () => {
|
|
70
|
-
const result = await orderByModel
|
|
71
|
-
.loadQuery(
|
|
72
|
-
`
|
|
73
|
-
query: models-> {
|
|
74
|
-
group_by: big is seats >=20
|
|
75
|
-
aggregate: model_count is count()
|
|
76
|
-
}
|
|
77
|
-
`
|
|
78
|
-
)
|
|
79
|
-
.run();
|
|
80
|
-
expect(result.data.row(0).cell('big').value).toBe(false);
|
|
81
|
-
expect(result.data.row(0).cell('model_count').value).toBe(58451);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it(`boolean in pipeline - ${databaseName}`, async () => {
|
|
85
|
-
const result = await orderByModel
|
|
86
|
-
.loadQuery(
|
|
87
|
-
`
|
|
88
|
-
query: models->{
|
|
89
|
-
group_by:
|
|
90
|
-
manufacturer,
|
|
91
|
-
big is seats >=21
|
|
92
|
-
aggregate: model_count is count()
|
|
93
|
-
}->{
|
|
94
|
-
group_by: big
|
|
95
|
-
aggregate: model_count is model_count.sum()
|
|
96
|
-
}
|
|
97
|
-
`
|
|
98
|
-
)
|
|
99
|
-
.run();
|
|
100
|
-
expect(result.data.row(0).cell('big').value).toBe(false);
|
|
101
|
-
expect(result.data.row(0).cell('model_count').value).toBe(58500);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it(`filtered measures in model are aggregates #352 - ${databaseName}`, async () => {
|
|
105
|
-
const result = await orderByModel
|
|
106
|
-
.loadQuery(
|
|
107
|
-
`
|
|
108
|
-
query: models->{
|
|
109
|
-
aggregate: j_names is model_count {where: manufacturer ~ 'J%'}
|
|
110
|
-
}
|
|
111
|
-
-> {
|
|
112
|
-
group_by: j_names
|
|
113
|
-
}
|
|
114
|
-
`
|
|
115
|
-
)
|
|
116
|
-
.run();
|
|
117
|
-
expect(result.data.row(0).cell('j_names').value).toBe(1358);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it(`reserved words are quoted - ${databaseName}`, async () => {
|
|
121
|
-
const sql = await orderByModel
|
|
122
|
-
.loadQuery(
|
|
123
|
-
`
|
|
124
|
-
query: models->{
|
|
125
|
-
aggregate: fetch is count()
|
|
126
|
-
}->{
|
|
127
|
-
group_by: fetch
|
|
128
|
-
}
|
|
129
|
-
`
|
|
130
|
-
)
|
|
131
|
-
.getSQL();
|
|
132
|
-
await validateCompilation(databaseName, sql);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it(`reserved words are quoted in turtles - ${databaseName}`, async () => {
|
|
136
|
-
const sql = await orderByModel
|
|
137
|
-
.loadQuery(
|
|
138
|
-
`
|
|
139
|
-
query: models->{
|
|
140
|
-
nest: withx is {
|
|
141
|
-
group_by: select is UPPER(manufacturer)
|
|
142
|
-
aggregate: fetch is count()
|
|
143
|
-
}
|
|
144
|
-
} -> {
|
|
145
|
-
project:
|
|
146
|
-
withxz is lower(withx.select)
|
|
147
|
-
fetch is withx.fetch
|
|
148
|
-
}
|
|
149
|
-
`
|
|
150
|
-
)
|
|
151
|
-
.getSQL();
|
|
152
|
-
await validateCompilation(databaseName, sql);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it.skip('reserved words in structure definitions', async () => {
|
|
156
|
-
const sql = await orderByModel
|
|
157
|
-
.loadQuery(
|
|
158
|
-
`
|
|
159
|
-
query: models->{
|
|
160
|
-
nest: withx is {
|
|
161
|
-
group_by: is select is UPPER(manufacturer)
|
|
162
|
-
aggregate: fetch is count()
|
|
163
|
-
}
|
|
164
|
-
} -> {
|
|
165
|
-
project: withxis lower(withx.select)
|
|
166
|
-
project: fetch is with.fetch
|
|
167
|
-
}
|
|
168
|
-
`
|
|
169
|
-
)
|
|
170
|
-
.getSQL();
|
|
171
|
-
await validateCompilation(databaseName, sql);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it(`aggregate and scalar conditions - ${databaseName}`, async () => {
|
|
175
|
-
const sql = await orderByModel
|
|
176
|
-
.loadQuery(
|
|
177
|
-
`
|
|
178
|
-
query: models->{
|
|
179
|
-
aggregate: model_count is count(){? manufacturer ? ~'A%' }
|
|
180
|
-
}
|
|
181
|
-
`
|
|
182
|
-
)
|
|
183
|
-
.getSQL();
|
|
184
|
-
await validateCompilation(databaseName, sql);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
// I'm not sure I have the syntax right here...
|
|
188
|
-
it(`modeled having simple - ${databaseName}`, async () => {
|
|
189
|
-
const result = await orderByModel
|
|
190
|
-
.loadQuery(
|
|
191
|
-
`
|
|
192
|
-
source: popular_names is from(models->{
|
|
193
|
-
having: model_count > 100
|
|
194
|
-
group_by: manufacturer
|
|
195
|
-
aggregate: model_count
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
query: popular_names->{
|
|
199
|
-
order_by: 2
|
|
200
|
-
project: manufacturer, model_count
|
|
201
|
-
}
|
|
202
|
-
`
|
|
203
|
-
)
|
|
204
|
-
.run();
|
|
205
|
-
expect(result.data.row(0).cell('model_count').value).toBe(102);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it(`modeled having complex - ${databaseName}`, async () => {
|
|
209
|
-
const result = await orderByModel
|
|
210
|
-
.loadQuery(
|
|
211
|
-
`
|
|
212
|
-
source: popular_names is from(models->{
|
|
213
|
-
having: model_count > 100
|
|
214
|
-
group_by: manufacturer
|
|
215
|
-
aggregate: model_count
|
|
216
|
-
nest: l is {
|
|
217
|
-
top: 5
|
|
218
|
-
group_by: manufacturer
|
|
219
|
-
aggregate: model_count
|
|
220
|
-
}
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
query: popular_names->{
|
|
224
|
-
order_by: 2
|
|
225
|
-
project: manufacturer, model_count
|
|
226
|
-
}
|
|
227
|
-
`
|
|
228
|
-
)
|
|
229
|
-
.run();
|
|
230
|
-
expect(result.data.row(0).cell('model_count').value).toBe(102);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it(`turtle references joined element - ${databaseName}`, async () => {
|
|
234
|
-
const sql = await orderByModel
|
|
235
|
-
.loadQuery(
|
|
236
|
-
`
|
|
237
|
-
source: a is table('malloytest.aircraft'){
|
|
238
|
-
primary_key: tail_num
|
|
239
|
-
measure: aircraft_count is count(*)
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
source: f is table('malloytest.flights'){
|
|
243
|
-
primary_key: id2
|
|
244
|
-
join_one: a with tail_num
|
|
245
|
-
|
|
246
|
-
measure: flight_count is count()
|
|
247
|
-
query: foo is {
|
|
248
|
-
group_by: carrier
|
|
249
|
-
aggregate: flight_count
|
|
250
|
-
aggregate: a.aircraft_count
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
query: f->foo
|
|
254
|
-
`
|
|
255
|
-
)
|
|
256
|
-
.getSQL();
|
|
257
|
-
await validateCompilation(databaseName, sql);
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
};
|
|
27
|
+
import {orderBySharedTests} from '../shared/orderby';
|
|
261
28
|
|
|
262
29
|
const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));
|
|
263
30
|
|
|
@@ -24,93 +24,7 @@
|
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
25
|
import {RuntimeList, allDatabases} from '../../runtimes';
|
|
26
26
|
import {databasesFromEnvironmentOr} from '../../util';
|
|
27
|
-
|
|
28
|
-
export const problemsSharedTests = (
|
|
29
|
-
runtimes: RuntimeList,
|
|
30
|
-
_splitFunction?: (column: string, splitChar: string) => string
|
|
31
|
-
) => {
|
|
32
|
-
afterAll(async () => {
|
|
33
|
-
await runtimes.closeAll();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
async function getError<T>(fn: () => Promise<T>) {
|
|
37
|
-
try {
|
|
38
|
-
await fn();
|
|
39
|
-
} catch (error) {
|
|
40
|
-
return error;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
runtimes.runtimeMap.forEach((runtime, databaseName) => {
|
|
45
|
-
describe('warnings', () => {
|
|
46
|
-
// Today we don't show errors after the first model entry with an error,
|
|
47
|
-
// so this can't work yet.
|
|
48
|
-
it.skip(`can appear after errors - ${databaseName}`, async () => {
|
|
49
|
-
const source = `
|
|
50
|
-
source: foo is table('asdfds');
|
|
51
|
-
source: bar is table('malloytest.state_facts') {
|
|
52
|
-
dimension: a is LENGTH('foo')
|
|
53
|
-
}
|
|
54
|
-
`;
|
|
55
|
-
const error = await getError(() => runtime.getModel(source));
|
|
56
|
-
expect(error).not.toBeUndefined();
|
|
57
|
-
expect(error).toMatchObject({
|
|
58
|
-
problems: [
|
|
59
|
-
{
|
|
60
|
-
severity: 'error',
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
message:
|
|
64
|
-
"Case insensitivity for function names is deprecated, use 'length' instead",
|
|
65
|
-
severity: 'warn',
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it(`can appear before errors - ${databaseName}`, async () => {
|
|
72
|
-
const source = `
|
|
73
|
-
source: bar is table('malloytest.state_facts') {
|
|
74
|
-
dimension: a is LENGTH('foo')
|
|
75
|
-
}
|
|
76
|
-
source: foo is table('asdfds');
|
|
77
|
-
`;
|
|
78
|
-
const error = await getError(() => runtime.getModel(source));
|
|
79
|
-
expect(error).not.toBeUndefined();
|
|
80
|
-
expect(error).toMatchObject({
|
|
81
|
-
problems: [
|
|
82
|
-
{
|
|
83
|
-
message:
|
|
84
|
-
"Case insensitivity for function names is deprecated, use 'length' instead",
|
|
85
|
-
severity: 'warn',
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
severity: 'error',
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it(`can appear alone - ${databaseName}`, async () => {
|
|
95
|
-
const source = `
|
|
96
|
-
source: bar is table('malloytest.state_facts') {
|
|
97
|
-
dimension: a is LENGTH('foo')
|
|
98
|
-
}
|
|
99
|
-
`;
|
|
100
|
-
const model = await runtime.getModel(source);
|
|
101
|
-
expect(model).toMatchObject({
|
|
102
|
-
problems: [
|
|
103
|
-
{
|
|
104
|
-
message:
|
|
105
|
-
"Case insensitivity for function names is deprecated, use 'length' instead",
|
|
106
|
-
severity: 'warn',
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
};
|
|
27
|
+
import {problemsSharedTests} from '../shared/problems';
|
|
114
28
|
|
|
115
29
|
const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));
|
|
116
30
|
|
|
@@ -26,77 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
import {RuntimeList, allDatabases} from '../../runtimes';
|
|
28
28
|
import {databasesFromEnvironmentOr} from '../../util';
|
|
29
|
-
|
|
30
|
-
// No prebuilt shared model, each test is complete. Makes debugging easier.
|
|
31
|
-
|
|
32
|
-
export const sqlExpressionsSharedTests = (
|
|
33
|
-
runtimes: RuntimeList,
|
|
34
|
-
_splitFunction?: (column: string, splitChar: string) => string
|
|
35
|
-
) => {
|
|
36
|
-
afterAll(async () => {
|
|
37
|
-
await runtimes.closeAll();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
runtimes.runtimeMap.forEach((runtime, databaseName) => {
|
|
41
|
-
it(`sql expression with turducken - ${databaseName}`, async () => {
|
|
42
|
-
const result = await runtime
|
|
43
|
-
.loadQuery(
|
|
44
|
-
`
|
|
45
|
-
run: ${databaseName}.sql(
|
|
46
|
-
"""SELECT * FROM (%{
|
|
47
|
-
${databaseName}.table('malloytest.state_facts') -> {
|
|
48
|
-
aggregate: c is count()
|
|
49
|
-
}
|
|
50
|
-
}) AS state_facts """
|
|
51
|
-
) -> {
|
|
52
|
-
project: *
|
|
53
|
-
}
|
|
54
|
-
`
|
|
55
|
-
)
|
|
56
|
-
.run();
|
|
57
|
-
expect(result.data.value[0]['c']).toBe(51);
|
|
58
|
-
});
|
|
59
|
-
it(`sql expression in second of two queries in same block, dependent on first query - ${databaseName}`, async () => {
|
|
60
|
-
const result = await runtime
|
|
61
|
-
.loadQuery(
|
|
62
|
-
`
|
|
63
|
-
query:
|
|
64
|
-
a is ${databaseName}.table('malloytest.state_facts') -> {
|
|
65
|
-
aggregate: c is count()
|
|
66
|
-
}
|
|
67
|
-
b is ${databaseName}.sql(
|
|
68
|
-
"""SELECT * FROM (%{ -> a -> { project: * } }) AS state_facts """
|
|
69
|
-
) -> {
|
|
70
|
-
project: *
|
|
71
|
-
}
|
|
72
|
-
run: b
|
|
73
|
-
`
|
|
74
|
-
)
|
|
75
|
-
.run();
|
|
76
|
-
expect(result.data.value[0]['c']).toBe(51);
|
|
77
|
-
});
|
|
78
|
-
it(`sql expression in other sql expression - ${databaseName}`, async () => {
|
|
79
|
-
const result = await runtime
|
|
80
|
-
.loadQuery(
|
|
81
|
-
`
|
|
82
|
-
run: ${databaseName}.sql("""
|
|
83
|
-
SELECT * from (%{
|
|
84
|
-
${databaseName}.sql("""SELECT 1 as one""") -> { group_by: one }
|
|
85
|
-
}) as the_table
|
|
86
|
-
""") -> { group_by: one }
|
|
87
|
-
`
|
|
88
|
-
)
|
|
89
|
-
.run();
|
|
90
|
-
expect(result.data.value[0]['one']).toBe(1);
|
|
91
|
-
});
|
|
92
|
-
it(`run sql expression as query - ${databaseName}`, async () => {
|
|
93
|
-
const result = await runtime
|
|
94
|
-
.loadQuery(`run: ${databaseName}.sql("""SELECT 1 as one""")`)
|
|
95
|
-
.run();
|
|
96
|
-
expect(result.data.value[0]['one']).toBe(1);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
};
|
|
29
|
+
import {sqlExpressionsSharedTests} from '../shared/sql_expressions';
|
|
100
30
|
|
|
101
31
|
const runtimes = new RuntimeList(databasesFromEnvironmentOr(allDatabases));
|
|
102
32
|
|