@malloydata/malloy-tests 0.0.299 → 0.0.301
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 +9 -9
- package/src/core/api.spec.ts +16 -0
- package/src/databases/all/composite_sources.spec.ts +62 -1
- package/src/databases/all/orderby.spec.ts +2 -2
- package/src/databases/bigquery/handexpr.spec.ts +255 -726
- package/src/databases/bigquery/malloy_query.spec.ts +165 -317
- package/src/databases/duckdb/streaming.spec.ts +172 -23
- package/src/models/faa_model.ts +275 -883
- package/src/models/medicare_model.ts +69 -231
- package/src/util/index.ts +0 -61
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import type {WriteStream} from '@malloydata/malloy';
|
|
25
|
-
import {CSVWriter} from '@malloydata/malloy';
|
|
25
|
+
import {CSVWriter, JSONWriter} from '@malloydata/malloy';
|
|
26
26
|
import {describeIfDatabaseAvailable} from '../../util';
|
|
27
27
|
import {RuntimeList} from '../../runtimes';
|
|
28
28
|
|
|
@@ -40,7 +40,7 @@ class StringAccumulator implements WriteStream {
|
|
|
40
40
|
|
|
41
41
|
const runtimes = ['duckdb'];
|
|
42
42
|
|
|
43
|
-
const [
|
|
43
|
+
const [describe, databases] = describeIfDatabaseAvailable(runtimes);
|
|
44
44
|
|
|
45
45
|
function modelText(databaseName: string) {
|
|
46
46
|
return `source: airports is ${databaseName}.table('test/data/duckdb/airports.parquet') extend {
|
|
@@ -101,15 +101,17 @@ describe('Streaming tests', () => {
|
|
|
101
101
|
});
|
|
102
102
|
|
|
103
103
|
runtimes.runtimeMap.forEach((runtime, databaseName) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
describe('csv', () => {
|
|
105
|
+
it(`stream nested results - ${databaseName}`, async () => {
|
|
106
|
+
const stream = runtime
|
|
107
|
+
.loadModel(modelText(databaseName))
|
|
108
|
+
.loadQuery('run: airports -> airports_by_region')
|
|
109
|
+
.runStream();
|
|
110
|
+
const accumulator = new StringAccumulator();
|
|
111
|
+
const csvWriter = new CSVWriter(accumulator);
|
|
112
|
+
await csvWriter.process(stream);
|
|
113
|
+
const expectedCsv = `\
|
|
114
|
+
faa_region,by_state,,,,by_facility_type,,airport_count
|
|
113
115
|
AGL,state,airport_count,by_county,,facility_type,airport_count,4437
|
|
114
116
|
,IL,890,county,airport_count,AIRPORT,3443,
|
|
115
117
|
,,,COOK,51,HELIPORT,826,
|
|
@@ -125,25 +127,172 @@ ASW,state,airport_count,by_county,,facility_type,airport_count,3268
|
|
|
125
127
|
,,,PLAQUEMINES,31,,,
|
|
126
128
|
,,,VERMILION,29,,,
|
|
127
129
|
`;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
expect(accumulator.accumulatedValue).toBe(expectedCsv);
|
|
131
|
+
});
|
|
130
132
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
it(`stream simple results - ${databaseName}`, async () => {
|
|
134
|
+
const stream = runtime
|
|
135
|
+
.loadModel(modelText(databaseName))
|
|
136
|
+
.loadQuery('run: airports -> higher_elevation')
|
|
137
|
+
.runStream();
|
|
138
|
+
const accumulator = new StringAccumulator();
|
|
139
|
+
const csvWriter = new CSVWriter(accumulator);
|
|
140
|
+
await csvWriter.process(stream);
|
|
141
|
+
const expectedCsv = `\
|
|
142
|
+
faa_region,airport_count,avg_elevation
|
|
140
143
|
ANM,2102,3284.3910561370126
|
|
141
144
|
AWP,1503,1667.0991350632069
|
|
142
145
|
ACE,1579,1339.0139328689045
|
|
143
146
|
ASW,3268,1007.2873317013464
|
|
144
147
|
AGL,4437,983.4800540906018
|
|
145
148
|
`;
|
|
146
|
-
|
|
149
|
+
expect(accumulator.accumulatedValue).toBe(expectedCsv);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('json', () => {
|
|
154
|
+
it(`stream nested results - ${databaseName}`, async () => {
|
|
155
|
+
const stream = runtime
|
|
156
|
+
.loadModel(modelText(databaseName))
|
|
157
|
+
.loadQuery('run: airports -> airports_by_region')
|
|
158
|
+
.runStream();
|
|
159
|
+
const accumulator = new StringAccumulator();
|
|
160
|
+
const jsonWriter = new JSONWriter(accumulator);
|
|
161
|
+
await jsonWriter.process(stream);
|
|
162
|
+
const expectedJson = `\
|
|
163
|
+
[
|
|
164
|
+
{
|
|
165
|
+
"faa_region": "AGL",
|
|
166
|
+
"by_state": [
|
|
167
|
+
{
|
|
168
|
+
"state": "IL",
|
|
169
|
+
"airport_count": 890,
|
|
170
|
+
"by_county": [
|
|
171
|
+
{
|
|
172
|
+
"county": "COOK",
|
|
173
|
+
"airport_count": 51
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"county": "LA SALLE",
|
|
177
|
+
"airport_count": 39
|
|
178
|
+
}
|
|
179
|
+
]
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"state": "OH",
|
|
183
|
+
"airport_count": 749,
|
|
184
|
+
"by_county": [
|
|
185
|
+
{
|
|
186
|
+
"county": "FRANKLIN",
|
|
187
|
+
"airport_count": 27
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"county": "CUYAHOGA",
|
|
191
|
+
"airport_count": 27
|
|
192
|
+
}
|
|
193
|
+
]
|
|
194
|
+
}
|
|
195
|
+
],
|
|
196
|
+
"by_facility_type": [
|
|
197
|
+
{
|
|
198
|
+
"facility_type": "AIRPORT",
|
|
199
|
+
"airport_count": 3443
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
"facility_type": "HELIPORT",
|
|
203
|
+
"airport_count": 826
|
|
204
|
+
}
|
|
205
|
+
],
|
|
206
|
+
"airport_count": 4437
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"faa_region": "ASW",
|
|
210
|
+
"by_state": [
|
|
211
|
+
{
|
|
212
|
+
"state": "TX",
|
|
213
|
+
"airport_count": 1845,
|
|
214
|
+
"by_county": [
|
|
215
|
+
{
|
|
216
|
+
"county": "HARRIS",
|
|
217
|
+
"airport_count": 135
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"county": "TARRANT",
|
|
221
|
+
"airport_count": 63
|
|
222
|
+
}
|
|
223
|
+
]
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
"state": "LA",
|
|
227
|
+
"airport_count": 500,
|
|
228
|
+
"by_county": [
|
|
229
|
+
{
|
|
230
|
+
"county": "PLAQUEMINES",
|
|
231
|
+
"airport_count": 31
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"county": "VERMILION",
|
|
235
|
+
"airport_count": 29
|
|
236
|
+
}
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
"by_facility_type": [
|
|
241
|
+
{
|
|
242
|
+
"facility_type": "AIRPORT",
|
|
243
|
+
"airport_count": 2341
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"facility_type": "HELIPORT",
|
|
247
|
+
"airport_count": 861
|
|
248
|
+
}
|
|
249
|
+
],
|
|
250
|
+
"airport_count": 3268
|
|
251
|
+
}
|
|
252
|
+
]
|
|
253
|
+
`;
|
|
254
|
+
expect(accumulator.accumulatedValue).toBe(expectedJson);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it(`stream simple results - ${databaseName}`, async () => {
|
|
258
|
+
const stream = runtime
|
|
259
|
+
.loadModel(modelText(databaseName))
|
|
260
|
+
.loadQuery('run: airports -> higher_elevation')
|
|
261
|
+
.runStream();
|
|
262
|
+
const accumulator = new StringAccumulator();
|
|
263
|
+
const jsonWriter = new JSONWriter(accumulator);
|
|
264
|
+
await jsonWriter.process(stream);
|
|
265
|
+
const expectedJson = `\
|
|
266
|
+
[
|
|
267
|
+
{
|
|
268
|
+
"faa_region": "ANM",
|
|
269
|
+
"airport_count": 2102,
|
|
270
|
+
"avg_elevation": 3284.3910561370126
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
"faa_region": "AWP",
|
|
274
|
+
"airport_count": 1503,
|
|
275
|
+
"avg_elevation": 1667.0991350632069
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
"faa_region": "ACE",
|
|
279
|
+
"airport_count": 1579,
|
|
280
|
+
"avg_elevation": 1339.0139328689045
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"faa_region": "ASW",
|
|
284
|
+
"airport_count": 3268,
|
|
285
|
+
"avg_elevation": 1007.2873317013464
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
"faa_region": "AGL",
|
|
289
|
+
"airport_count": 4437,
|
|
290
|
+
"avg_elevation": 983.4800540906018
|
|
291
|
+
}
|
|
292
|
+
]
|
|
293
|
+
`;
|
|
294
|
+
expect(accumulator.accumulatedValue).toBe(expectedJson);
|
|
295
|
+
});
|
|
147
296
|
});
|
|
148
297
|
});
|
|
149
298
|
});
|