@malloydata/malloy-tests 0.0.288 → 0.0.290
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/render/render.spec.ts +132 -50
- package/src/runtimes.d.ts +53 -0
- package/src/render/drill.spec.ts +0 -338
package/package.json
CHANGED
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@jest/globals": "^29.4.3",
|
|
24
|
-
"@malloydata/db-bigquery": "0.0.
|
|
25
|
-
"@malloydata/db-duckdb": "0.0.
|
|
26
|
-
"@malloydata/db-postgres": "0.0.
|
|
27
|
-
"@malloydata/db-snowflake": "0.0.
|
|
28
|
-
"@malloydata/db-trino": "0.0.
|
|
29
|
-
"@malloydata/malloy": "0.0.
|
|
30
|
-
"@malloydata/malloy-tag": "0.0.
|
|
31
|
-
"@malloydata/render": "0.0.
|
|
24
|
+
"@malloydata/db-bigquery": "0.0.290",
|
|
25
|
+
"@malloydata/db-duckdb": "0.0.290",
|
|
26
|
+
"@malloydata/db-postgres": "0.0.290",
|
|
27
|
+
"@malloydata/db-snowflake": "0.0.290",
|
|
28
|
+
"@malloydata/db-trino": "0.0.290",
|
|
29
|
+
"@malloydata/malloy": "0.0.290",
|
|
30
|
+
"@malloydata/malloy-tag": "0.0.290",
|
|
31
|
+
"@malloydata/render": "0.0.290",
|
|
32
32
|
"events": "^3.3.0",
|
|
33
33
|
"jsdom": "^22.1.0",
|
|
34
34
|
"luxon": "^2.4.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"@types/jsdom": "^21.1.1",
|
|
39
39
|
"@types/luxon": "^2.4.0"
|
|
40
40
|
},
|
|
41
|
-
"version": "0.0.
|
|
41
|
+
"version": "0.0.290"
|
|
42
42
|
}
|
|
@@ -21,11 +21,16 @@
|
|
|
21
21
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import type
|
|
24
|
+
import {API, type ModelMaterializer, type Result} from '@malloydata/malloy';
|
|
25
25
|
import {RuntimeList, runtimeFor} from '../runtimes';
|
|
26
26
|
import {describeIfDatabaseAvailable} from '../util';
|
|
27
27
|
import {JSDOM} from 'jsdom';
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
let HTMLView;
|
|
30
|
+
|
|
31
|
+
function convertResultToMalloyResult(result: Result) {
|
|
32
|
+
return API.util.wrapResult(result);
|
|
33
|
+
}
|
|
29
34
|
|
|
30
35
|
async function runUnsupportedRenderTest(
|
|
31
36
|
connectionName: string,
|
|
@@ -44,9 +49,13 @@ async function runUnsupportedRenderTest(
|
|
|
44
49
|
const result = await runtime.loadModel(src).loadQueryByName('q').run();
|
|
45
50
|
// console.log("DATA", result.data.toObject());
|
|
46
51
|
const document = new JSDOM().window.document;
|
|
47
|
-
const html = await new HTMLView(document).render(
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
const html = await new HTMLView(document).render(
|
|
53
|
+
convertResultToMalloyResult(result),
|
|
54
|
+
{
|
|
55
|
+
dataStyles: {},
|
|
56
|
+
useLegacy: true,
|
|
57
|
+
}
|
|
58
|
+
);
|
|
50
59
|
expect(html.innerHTML).toContain('<thead>');
|
|
51
60
|
expect(html.innerHTML).toContain(rendered);
|
|
52
61
|
// console.log(html.innerHTML);
|
|
@@ -59,9 +68,26 @@ const [describe, databases] = describeIfDatabaseAvailable([
|
|
|
59
68
|
'duckdb',
|
|
60
69
|
]);
|
|
61
70
|
const duckdb = runtimeFor('duckdb');
|
|
62
|
-
describe('rendering results', () => {
|
|
71
|
+
describe.skip('rendering results', () => {
|
|
63
72
|
const runtimes = new RuntimeList(databases);
|
|
64
73
|
|
|
74
|
+
beforeAll(async () => {
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
global.window = global.document.defaultView;
|
|
78
|
+
global.navigator = global.window.navigator;
|
|
79
|
+
HTMLView = (await import('@malloydata/render')).HTMLView;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
afterAll(() => {
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
delete global.window;
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
delete global.navigator;
|
|
89
|
+
});
|
|
90
|
+
|
|
65
91
|
beforeEach(() => {
|
|
66
92
|
jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
67
93
|
});
|
|
@@ -82,8 +108,9 @@ describe('rendering results', () => {
|
|
|
82
108
|
`;
|
|
83
109
|
const result = await runtime.loadQuery(src).run();
|
|
84
110
|
const document = new JSDOM().window.document;
|
|
85
|
-
await new HTMLView(document).render(result, {
|
|
111
|
+
await new HTMLView(document).render(convertResultToMalloyResult(result), {
|
|
86
112
|
dataStyles: {},
|
|
113
|
+
useLegacy: true,
|
|
87
114
|
});
|
|
88
115
|
}
|
|
89
116
|
});
|
|
@@ -297,19 +324,26 @@ describe('rendering results', () => {
|
|
|
297
324
|
test('regular table', async () => {
|
|
298
325
|
const result = await model.loadQueryByName('by_name').run();
|
|
299
326
|
const document = new JSDOM().window.document;
|
|
300
|
-
const html = await new HTMLView(document).render(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
327
|
+
const html = await new HTMLView(document).render(
|
|
328
|
+
convertResultToMalloyResult(result),
|
|
329
|
+
{
|
|
330
|
+
dataStyles: {},
|
|
331
|
+
useLegacy: true,
|
|
332
|
+
}
|
|
333
|
+
);
|
|
304
334
|
expect(html).toMatchSnapshot();
|
|
305
335
|
});
|
|
306
336
|
|
|
307
337
|
test('transposed table', async () => {
|
|
308
338
|
const result = await model.loadQueryByName('by_name_transposed').run();
|
|
309
339
|
const document = new JSDOM().window.document;
|
|
310
|
-
const html = await new HTMLView(document).render(
|
|
311
|
-
|
|
312
|
-
|
|
340
|
+
const html = await new HTMLView(document).render(
|
|
341
|
+
convertResultToMalloyResult(result),
|
|
342
|
+
{
|
|
343
|
+
dataStyles: {},
|
|
344
|
+
useLegacy: true,
|
|
345
|
+
}
|
|
346
|
+
);
|
|
313
347
|
|
|
314
348
|
expect(html).toMatchSnapshot();
|
|
315
349
|
});
|
|
@@ -372,9 +406,13 @@ describe('rendering results', () => {
|
|
|
372
406
|
test('rendered correctly table', async () => {
|
|
373
407
|
const result = await modelMaterializer.loadQueryByName('by_name').run();
|
|
374
408
|
const document = new JSDOM().window.document;
|
|
375
|
-
const html = await new HTMLView(document).render(
|
|
376
|
-
|
|
377
|
-
|
|
409
|
+
const html = await new HTMLView(document).render(
|
|
410
|
+
convertResultToMalloyResult(result),
|
|
411
|
+
{
|
|
412
|
+
dataStyles: {},
|
|
413
|
+
useLegacy: true,
|
|
414
|
+
}
|
|
415
|
+
);
|
|
378
416
|
|
|
379
417
|
expect(html).toMatchSnapshot();
|
|
380
418
|
});
|
|
@@ -384,9 +422,13 @@ describe('rendering results', () => {
|
|
|
384
422
|
.loadQueryByName('by_name_db')
|
|
385
423
|
.run();
|
|
386
424
|
const document = new JSDOM().window.document;
|
|
387
|
-
const html = await new HTMLView(document).render(
|
|
388
|
-
|
|
389
|
-
|
|
425
|
+
const html = await new HTMLView(document).render(
|
|
426
|
+
convertResultToMalloyResult(result),
|
|
427
|
+
{
|
|
428
|
+
dataStyles: {},
|
|
429
|
+
useLegacy: true,
|
|
430
|
+
}
|
|
431
|
+
);
|
|
390
432
|
|
|
391
433
|
expect(html).toMatchSnapshot();
|
|
392
434
|
});
|
|
@@ -447,9 +489,13 @@ describe('rendering results', () => {
|
|
|
447
489
|
.loadQueryByName('by_name')
|
|
448
490
|
.run();
|
|
449
491
|
const document = new JSDOM().window.document;
|
|
450
|
-
const html = await new HTMLView(document).render(
|
|
451
|
-
|
|
452
|
-
|
|
492
|
+
const html = await new HTMLView(document).render(
|
|
493
|
+
convertResultToMalloyResult(result),
|
|
494
|
+
{
|
|
495
|
+
dataStyles: {},
|
|
496
|
+
useLegacy: true,
|
|
497
|
+
}
|
|
498
|
+
);
|
|
453
499
|
|
|
454
500
|
expect(html).toMatchSnapshot();
|
|
455
501
|
});
|
|
@@ -499,9 +545,13 @@ describe('rendering results', () => {
|
|
|
499
545
|
.loadQueryByName('flatten')
|
|
500
546
|
.run();
|
|
501
547
|
const document = new JSDOM().window.document;
|
|
502
|
-
const html = await new HTMLView(document).render(
|
|
503
|
-
|
|
504
|
-
|
|
548
|
+
const html = await new HTMLView(document).render(
|
|
549
|
+
convertResultToMalloyResult(result),
|
|
550
|
+
{
|
|
551
|
+
dataStyles: {},
|
|
552
|
+
useLegacy: true,
|
|
553
|
+
}
|
|
554
|
+
);
|
|
505
555
|
|
|
506
556
|
expect(html).toMatchSnapshot();
|
|
507
557
|
});
|
|
@@ -520,9 +570,13 @@ describe('rendering results', () => {
|
|
|
520
570
|
.loadQueryByName('mex_query')
|
|
521
571
|
.run();
|
|
522
572
|
const document = new JSDOM().window.document;
|
|
523
|
-
const html = await new HTMLView(document).render(
|
|
524
|
-
|
|
525
|
-
|
|
573
|
+
const html = await new HTMLView(document).render(
|
|
574
|
+
convertResultToMalloyResult(result),
|
|
575
|
+
{
|
|
576
|
+
dataStyles: {},
|
|
577
|
+
useLegacy: true,
|
|
578
|
+
}
|
|
579
|
+
);
|
|
526
580
|
|
|
527
581
|
expect(html).toMatchSnapshot();
|
|
528
582
|
});
|
|
@@ -544,9 +598,13 @@ describe('rendering results', () => {
|
|
|
544
598
|
.loadQueryByName('data_trunc')
|
|
545
599
|
.run();
|
|
546
600
|
const document = new JSDOM().window.document;
|
|
547
|
-
const html = await new HTMLView(document).render(
|
|
548
|
-
|
|
549
|
-
|
|
601
|
+
const html = await new HTMLView(document).render(
|
|
602
|
+
convertResultToMalloyResult(result),
|
|
603
|
+
{
|
|
604
|
+
dataStyles: {},
|
|
605
|
+
useLegacy: true,
|
|
606
|
+
}
|
|
607
|
+
);
|
|
550
608
|
|
|
551
609
|
expect(html).toMatchSnapshot();
|
|
552
610
|
});
|
|
@@ -567,9 +625,13 @@ describe('rendering results', () => {
|
|
|
567
625
|
.loadQueryByName('mex_query')
|
|
568
626
|
.run();
|
|
569
627
|
const document = new JSDOM().window.document;
|
|
570
|
-
const html = await new HTMLView(document).render(
|
|
571
|
-
|
|
572
|
-
|
|
628
|
+
const html = await new HTMLView(document).render(
|
|
629
|
+
convertResultToMalloyResult(result),
|
|
630
|
+
{
|
|
631
|
+
dataStyles: {},
|
|
632
|
+
useLegacy: true,
|
|
633
|
+
}
|
|
634
|
+
);
|
|
573
635
|
|
|
574
636
|
expect(html).toMatchSnapshot();
|
|
575
637
|
});
|
|
@@ -592,9 +654,13 @@ describe('rendering results', () => {
|
|
|
592
654
|
.loadQueryByName('mexico_point_map')
|
|
593
655
|
.run();
|
|
594
656
|
const document = new JSDOM().window.document;
|
|
595
|
-
const html = await new HTMLView(document).render(
|
|
596
|
-
|
|
597
|
-
|
|
657
|
+
const html = await new HTMLView(document).render(
|
|
658
|
+
convertResultToMalloyResult(result),
|
|
659
|
+
{
|
|
660
|
+
dataStyles: {},
|
|
661
|
+
useLegacy: true,
|
|
662
|
+
}
|
|
663
|
+
);
|
|
598
664
|
|
|
599
665
|
expect(html).toMatchSnapshot();
|
|
600
666
|
});
|
|
@@ -617,9 +683,13 @@ describe('rendering results', () => {
|
|
|
617
683
|
.loadQueryByName('number_query')
|
|
618
684
|
.run();
|
|
619
685
|
const document = new JSDOM().window.document;
|
|
620
|
-
const html = await new HTMLView(document).render(
|
|
621
|
-
|
|
622
|
-
|
|
686
|
+
const html = await new HTMLView(document).render(
|
|
687
|
+
convertResultToMalloyResult(result),
|
|
688
|
+
{
|
|
689
|
+
dataStyles: {},
|
|
690
|
+
useLegacy: true,
|
|
691
|
+
}
|
|
692
|
+
);
|
|
623
693
|
|
|
624
694
|
expect(html).toMatchSnapshot();
|
|
625
695
|
});
|
|
@@ -647,9 +717,13 @@ describe('rendering results', () => {
|
|
|
647
717
|
.loadQueryByName('bytes_query')
|
|
648
718
|
.run();
|
|
649
719
|
const document = new JSDOM().window.document;
|
|
650
|
-
const html = await new HTMLView(document).render(
|
|
651
|
-
|
|
652
|
-
|
|
720
|
+
const html = await new HTMLView(document).render(
|
|
721
|
+
convertResultToMalloyResult(result),
|
|
722
|
+
{
|
|
723
|
+
dataStyles: {},
|
|
724
|
+
useLegacy: true,
|
|
725
|
+
}
|
|
726
|
+
);
|
|
653
727
|
|
|
654
728
|
expect(html).toMatchSnapshot();
|
|
655
729
|
});
|
|
@@ -676,9 +750,13 @@ describe('rendering results', () => {
|
|
|
676
750
|
.loadQueryByName('bytes_query')
|
|
677
751
|
.run();
|
|
678
752
|
const document = new JSDOM().window.document;
|
|
679
|
-
const html = await new HTMLView(document).render(
|
|
680
|
-
|
|
681
|
-
|
|
753
|
+
const html = await new HTMLView(document).render(
|
|
754
|
+
convertResultToMalloyResult(result),
|
|
755
|
+
{
|
|
756
|
+
dataStyles: {},
|
|
757
|
+
useLegacy: true,
|
|
758
|
+
}
|
|
759
|
+
);
|
|
682
760
|
|
|
683
761
|
expect(html).toMatchSnapshot();
|
|
684
762
|
});
|
|
@@ -740,9 +818,13 @@ describe('rendering results', () => {
|
|
|
740
818
|
.loadQueryByName('duration_query')
|
|
741
819
|
.run();
|
|
742
820
|
const document = new JSDOM().window.document;
|
|
743
|
-
const html = await new HTMLView(document).render(
|
|
744
|
-
|
|
745
|
-
|
|
821
|
+
const html = await new HTMLView(document).render(
|
|
822
|
+
convertResultToMalloyResult(result),
|
|
823
|
+
{
|
|
824
|
+
dataStyles: {},
|
|
825
|
+
useLegacy: true,
|
|
826
|
+
}
|
|
827
|
+
);
|
|
746
828
|
|
|
747
829
|
expect(html).toMatchSnapshot();
|
|
748
830
|
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Connection, MalloyQueryData, QueryDataRow, Result, RunSQLOptions, ModelCache } from '@malloydata/malloy';
|
|
2
|
+
import { SingleConnectionRuntime, InMemoryURLReader, CacheManager } from '@malloydata/malloy';
|
|
3
|
+
import { BigQueryConnection } from '@malloydata/db-bigquery';
|
|
4
|
+
import { DuckDBConnection } from '@malloydata/db-duckdb';
|
|
5
|
+
import { DuckDBWASMConnection } from '@malloydata/db-duckdb/wasm';
|
|
6
|
+
import { SnowflakeConnection } from '@malloydata/db-snowflake';
|
|
7
|
+
import { PooledPostgresConnection } from '@malloydata/db-postgres';
|
|
8
|
+
import { MySQLConnection } from '@malloydata/db-mysql/src/mysql_connection';
|
|
9
|
+
export declare class SnowflakeTestConnection extends SnowflakeConnection {
|
|
10
|
+
runSQL(sqlCommand: string, options?: RunSQLOptions): Promise<MalloyQueryData>;
|
|
11
|
+
}
|
|
12
|
+
export declare class BigQueryTestConnection extends BigQueryConnection {
|
|
13
|
+
runSQL(sqlCommand: string, options?: RunSQLOptions): Promise<MalloyQueryData>;
|
|
14
|
+
}
|
|
15
|
+
export declare class MySQLTestConnection extends MySQLConnection {
|
|
16
|
+
runSQL(sqlCommand: string, options?: RunSQLOptions): Promise<MalloyQueryData>;
|
|
17
|
+
}
|
|
18
|
+
export declare class PostgresTestConnection extends PooledPostgresConnection {
|
|
19
|
+
runSQL(sqlCommand: string, options?: RunSQLOptions): Promise<MalloyQueryData>;
|
|
20
|
+
}
|
|
21
|
+
export declare class DuckDBTestConnection extends DuckDBConnection {
|
|
22
|
+
runSQL(sqlCommand: string, options?: RunSQLOptions): Promise<MalloyQueryData>;
|
|
23
|
+
}
|
|
24
|
+
export declare class DuckDBWASMTestConnection extends DuckDBWASMConnection {
|
|
25
|
+
runSQL(sqlCommand: string, options?: RunSQLOptions): Promise<MalloyQueryData>;
|
|
26
|
+
}
|
|
27
|
+
export declare class TestCacheManager extends CacheManager {
|
|
28
|
+
readonly _modelCache: ModelCache;
|
|
29
|
+
constructor(_modelCache: ModelCache);
|
|
30
|
+
}
|
|
31
|
+
export declare class TestURLReader extends InMemoryURLReader {
|
|
32
|
+
constructor();
|
|
33
|
+
setFile(url: URL, contents: string): void;
|
|
34
|
+
deleteFile(url: URL): void;
|
|
35
|
+
}
|
|
36
|
+
export declare function rows(qr: Result): QueryDataRow[];
|
|
37
|
+
export declare function runtimeFor(dbName: string): SingleConnectionRuntime;
|
|
38
|
+
export declare function testRuntimeFor(connection: Connection): SingleConnectionRuntime<Connection>;
|
|
39
|
+
/**
|
|
40
|
+
* All databases which should be tested by default. Experimental dialects
|
|
41
|
+
* should not be in this list. Use MALLOY_DATABASE=dialect_name to test those
|
|
42
|
+
*/
|
|
43
|
+
export declare const allDatabases: string[];
|
|
44
|
+
type RuntimeDatabaseNames = (typeof allDatabases)[number];
|
|
45
|
+
export declare class RuntimeList {
|
|
46
|
+
runtimeMap: Map<string, SingleConnectionRuntime<Connection>>;
|
|
47
|
+
runtimeList: Array<[string, SingleConnectionRuntime]>;
|
|
48
|
+
constructor();
|
|
49
|
+
constructor(databaseList: RuntimeDatabaseNames[]);
|
|
50
|
+
constructor(externalConnections: SingleConnectionRuntime[]);
|
|
51
|
+
closeAll(): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
package/src/render/drill.spec.ts
DELETED
|
@@ -1,338 +0,0 @@
|
|
|
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 {runtimeFor} from '../runtimes';
|
|
9
|
-
import {getDataTree} from '@malloydata/render';
|
|
10
|
-
import {API} from '@malloydata/malloy';
|
|
11
|
-
|
|
12
|
-
const duckdb = runtimeFor('duckdb');
|
|
13
|
-
|
|
14
|
-
describe('drill query', () => {
|
|
15
|
-
const model = `
|
|
16
|
-
##! experimental { parameters }
|
|
17
|
-
source: carriers is duckdb.table('test/data/duckdb/carriers.parquet') extend {
|
|
18
|
-
primary_key: code
|
|
19
|
-
measure: carrier_count is count()
|
|
20
|
-
}
|
|
21
|
-
source: flights is duckdb.table('test/data/duckdb/flights/part.*.parquet') extend {
|
|
22
|
-
primary_key: id2
|
|
23
|
-
// rename some fields as from their physical names
|
|
24
|
-
rename: \`Origin Code\` is origin
|
|
25
|
-
measure: flight_count is count()
|
|
26
|
-
join_one: carriers with carrier
|
|
27
|
-
|
|
28
|
-
view: top_carriers is {
|
|
29
|
-
group_by: carriers.nickname
|
|
30
|
-
aggregate:
|
|
31
|
-
flight_count
|
|
32
|
-
limit: 1
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
view: over_time is {
|
|
36
|
-
group_by: dep_month is month(dep_time)
|
|
37
|
-
aggregate: flight_count
|
|
38
|
-
limit: 1
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
view: by_origin is {
|
|
42
|
-
group_by: \`Origin Code\`
|
|
43
|
-
aggregate: flight_count
|
|
44
|
-
limit: 1
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
view: no_filter is {
|
|
48
|
-
aggregate: flight_count
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
view: cool_carriers is {
|
|
52
|
-
where: carrier = 'AA' or carrier = 'WN'
|
|
53
|
-
group_by: \`Origin Code\`
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
view: negative_value is {
|
|
57
|
-
group_by: negative_one is -1
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
source: flights_with_parameters(
|
|
61
|
-
number_param is 1,
|
|
62
|
-
string_param is 'foo',
|
|
63
|
-
boolean_param is true,
|
|
64
|
-
date_param is @2000,
|
|
65
|
-
timestamp_param is @2004-01-01 10:00,
|
|
66
|
-
filter_expression_param::filter<number> is f'> 3'
|
|
67
|
-
) is flights
|
|
68
|
-
source: flights_with_timestamp_param(
|
|
69
|
-
timestamp_param is @2004-01-01 10:00
|
|
70
|
-
) is flights
|
|
71
|
-
query: top_carriers is flights -> top_carriers
|
|
72
|
-
query: over_time is flights -> over_time
|
|
73
|
-
query: by_origin is flights -> by_origin
|
|
74
|
-
query: no_filter is flights -> no_filter
|
|
75
|
-
query: cool_carriers is flights -> cool_carriers
|
|
76
|
-
query: negative_value is flights -> negative_value
|
|
77
|
-
query: literal_with_nested_view_stable is flights -> {
|
|
78
|
-
where:
|
|
79
|
-
\`Origin Code\` ~ f'SFO, ORD',
|
|
80
|
-
destination = 'SJC'
|
|
81
|
-
group_by: carrier
|
|
82
|
-
nest: cool_carriers
|
|
83
|
-
}
|
|
84
|
-
query: literal_with_nested_view_unstable is flights -> {
|
|
85
|
-
where:
|
|
86
|
-
carriers.nickname ~ '%A%',
|
|
87
|
-
distance > 100,
|
|
88
|
-
month(dep_time) = 7
|
|
89
|
-
group_by: carrier
|
|
90
|
-
nest: cool_carriers
|
|
91
|
-
having: flight_count > 100
|
|
92
|
-
}
|
|
93
|
-
query: already_has_some_drills is flights -> {
|
|
94
|
-
drill:
|
|
95
|
-
\`Origin Code\` ~ f\`SFO, ORD\`,
|
|
96
|
-
destination = "SJC",
|
|
97
|
-
carrier = "AA",
|
|
98
|
-
cool_carriers.\`Origin Code\` = "ORD"
|
|
99
|
-
} + over_time
|
|
100
|
-
query: source_has_parameters is flights_with_parameters(
|
|
101
|
-
number_param is 1,
|
|
102
|
-
string_param is 'foo',
|
|
103
|
-
boolean_param is true,
|
|
104
|
-
date_param is @2000,
|
|
105
|
-
timestamp_param is @2004-01-01 10:00,
|
|
106
|
-
filter_expression_param is f'> 3'
|
|
107
|
-
) -> top_carriers
|
|
108
|
-
query: source_has_timezone_param is flights_with_timestamp_param(
|
|
109
|
-
timestamp_param is @2004-01-01 10:00:00[America/Los_Angeles]
|
|
110
|
-
) -> top_carriers
|
|
111
|
-
query: only_default_params is flights_with_parameters -> top_carriers
|
|
112
|
-
`;
|
|
113
|
-
|
|
114
|
-
beforeEach(() => {
|
|
115
|
-
jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test('can handle joined-in table fields', async () => {
|
|
119
|
-
const result = await duckdb
|
|
120
|
-
.loadModel(model)
|
|
121
|
-
.loadQueryByName('top_carriers')
|
|
122
|
-
.run();
|
|
123
|
-
const table = getDataTree(API.util.wrapResult(result));
|
|
124
|
-
const expDrillQuery =
|
|
125
|
-
'run: flights -> { drill: top_carriers.nickname = "Southwest" } + { select: * }';
|
|
126
|
-
const row = table.rows[0];
|
|
127
|
-
expect(row.getDrillQueryMalloy()).toEqual(expDrillQuery);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test('can handle expression fields', async () => {
|
|
131
|
-
const result = await duckdb
|
|
132
|
-
.loadModel(model)
|
|
133
|
-
.loadQueryByName('over_time')
|
|
134
|
-
.run();
|
|
135
|
-
const table = getDataTree(API.util.wrapResult(result));
|
|
136
|
-
const expDrillQuery =
|
|
137
|
-
'run: flights -> { drill: over_time.dep_month = 8 } + { select: * }';
|
|
138
|
-
const row = table.rows[0];
|
|
139
|
-
expect(row.getDrillQueryMalloy()).toEqual(expDrillQuery);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test('can handle renamed and multi-word field names', async () => {
|
|
143
|
-
const result = await duckdb
|
|
144
|
-
.loadModel(model)
|
|
145
|
-
.loadQueryByName('by_origin')
|
|
146
|
-
.run();
|
|
147
|
-
const table = getDataTree(API.util.wrapResult(result));
|
|
148
|
-
const expDrillQuery =
|
|
149
|
-
'run: flights -> { drill: by_origin.`Origin Code` = "ATL" } + { select: * }';
|
|
150
|
-
const row = table.rows[0];
|
|
151
|
-
expect(row.getDrillQueryMalloy()).toEqual(expDrillQuery);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test('can handle queries with no filter', async () => {
|
|
155
|
-
const result = await duckdb
|
|
156
|
-
.loadModel(model)
|
|
157
|
-
.loadQueryByName('no_filter')
|
|
158
|
-
.run();
|
|
159
|
-
const table = getDataTree(API.util.wrapResult(result));
|
|
160
|
-
const expDrillQuery = 'run: flights -> { select: * }';
|
|
161
|
-
const row = table.rows[0];
|
|
162
|
-
expect(row.getDrillQueryMalloy()).toEqual(expDrillQuery);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test('can handle view filters', async () => {
|
|
166
|
-
const result = await duckdb
|
|
167
|
-
.loadModel(model)
|
|
168
|
-
.loadQueryByName('cool_carriers')
|
|
169
|
-
.run();
|
|
170
|
-
const table = getDataTree(API.util.wrapResult(result));
|
|
171
|
-
const expDrillQuery =
|
|
172
|
-
'run: flights -> { drill: cool_carriers.`Origin Code` = "ABQ" } + { select: * }';
|
|
173
|
-
const row = table.rows[0];
|
|
174
|
-
expect(row.getDrillQueryMalloy()).toEqual(expDrillQuery);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
test('can handle filters that are not in a view (not stable compatible)', async () => {
|
|
178
|
-
const result = await duckdb
|
|
179
|
-
.loadModel(model)
|
|
180
|
-
.loadQueryByName('literal_with_nested_view_unstable')
|
|
181
|
-
.run();
|
|
182
|
-
const table = getDataTree(API.util.wrapResult(result));
|
|
183
|
-
const expDrillQuery = `run: flights -> {
|
|
184
|
-
drill:
|
|
185
|
-
carriers.nickname ~ '%A%',
|
|
186
|
-
distance > 100,
|
|
187
|
-
month(dep_time) = 7,
|
|
188
|
-
carrier = "AA"
|
|
189
|
-
} + { select: * }`;
|
|
190
|
-
const row1 = table.rows[0];
|
|
191
|
-
expect(row1.getDrillQueryMalloy()).toEqual(expDrillQuery);
|
|
192
|
-
const nest = row1.column('cool_carriers');
|
|
193
|
-
expect(nest.isRepeatedRecord()).toBe(true);
|
|
194
|
-
if (nest.isRepeatedRecord()) {
|
|
195
|
-
const expDrillQuery = `run: flights -> {
|
|
196
|
-
drill:
|
|
197
|
-
carriers.nickname ~ '%A%',
|
|
198
|
-
distance > 100,
|
|
199
|
-
month(dep_time) = 7,
|
|
200
|
-
carrier = "AA",
|
|
201
|
-
cool_carriers.\`Origin Code\` = "ABQ"
|
|
202
|
-
} + { select: * }`;
|
|
203
|
-
const row = nest.rows[0];
|
|
204
|
-
expect(row.getDrillQueryMalloy()).toEqual(expDrillQuery);
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
test('can handle filters that are not in a view (stable compatible)', async () => {
|
|
209
|
-
const result = await duckdb
|
|
210
|
-
.loadModel(model)
|
|
211
|
-
.loadQueryByName('literal_with_nested_view_stable')
|
|
212
|
-
.run();
|
|
213
|
-
const table = getDataTree(API.util.wrapResult(result));
|
|
214
|
-
const expDrillQuery = `run: flights -> {
|
|
215
|
-
drill:
|
|
216
|
-
\`Origin Code\` ~ f\`SFO, ORD\`,
|
|
217
|
-
destination = "SJC",
|
|
218
|
-
carrier = "AA"
|
|
219
|
-
} + { select: * }`;
|
|
220
|
-
const row1 = table.rows[0];
|
|
221
|
-
expect(row1.getDrillQueryMalloy()).toEqual(expDrillQuery);
|
|
222
|
-
const nest = row1.column('cool_carriers');
|
|
223
|
-
expect(nest.isRepeatedRecord()).toBe(true);
|
|
224
|
-
if (nest.isRepeatedRecord()) {
|
|
225
|
-
const expDrillQuery = `run: flights -> {
|
|
226
|
-
drill:
|
|
227
|
-
\`Origin Code\` ~ f\`SFO, ORD\`,
|
|
228
|
-
destination = "SJC",
|
|
229
|
-
carrier = "AA",
|
|
230
|
-
cool_carriers.\`Origin Code\` = "ORD"
|
|
231
|
-
} + { select: * }`;
|
|
232
|
-
const row = nest.rows[0];
|
|
233
|
-
expect(row.getDrillQueryMalloy()).toEqual(expDrillQuery);
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
test('can handle drills that are already there', async () => {
|
|
238
|
-
const result = await duckdb
|
|
239
|
-
.loadModel(model)
|
|
240
|
-
.loadQueryByName('already_has_some_drills')
|
|
241
|
-
.run();
|
|
242
|
-
const table = getDataTree(API.util.wrapResult(result));
|
|
243
|
-
const expDrillQuery = `run: flights -> {
|
|
244
|
-
drill:
|
|
245
|
-
\`Origin Code\` ~ f\`SFO, ORD\`,
|
|
246
|
-
destination = "SJC",
|
|
247
|
-
carrier = "AA",
|
|
248
|
-
cool_carriers.\`Origin Code\` = "ORD",
|
|
249
|
-
over_time.dep_month = 5
|
|
250
|
-
} + { select: * }`;
|
|
251
|
-
const row = table.rows[0];
|
|
252
|
-
expect(row.getDrillQueryMalloy()).toEqual(expDrillQuery);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
test('negative number can be used in stable query filter', async () => {
|
|
256
|
-
const result = await duckdb
|
|
257
|
-
.loadModel(model)
|
|
258
|
-
.loadQueryByName('negative_value')
|
|
259
|
-
.run();
|
|
260
|
-
const table = getDataTree(API.util.wrapResult(result));
|
|
261
|
-
const expDrillQuery =
|
|
262
|
-
'run: flights -> { drill: negative_value.negative_one = -1 } + { select: * }';
|
|
263
|
-
const row = table.rows[0];
|
|
264
|
-
expect(row.getDrillQueryMalloy()).toEqual(expDrillQuery);
|
|
265
|
-
expect(row.getStableDrillQuery()).toMatchObject({
|
|
266
|
-
definition: {
|
|
267
|
-
kind: 'arrow',
|
|
268
|
-
source: {
|
|
269
|
-
kind: 'source_reference',
|
|
270
|
-
name: 'flights',
|
|
271
|
-
},
|
|
272
|
-
view: {
|
|
273
|
-
kind: 'segment',
|
|
274
|
-
operations: [
|
|
275
|
-
{
|
|
276
|
-
filter: {
|
|
277
|
-
field_reference: {
|
|
278
|
-
name: 'negative_one',
|
|
279
|
-
path: ['negative_value'],
|
|
280
|
-
},
|
|
281
|
-
kind: 'literal_equality',
|
|
282
|
-
value: {
|
|
283
|
-
kind: 'number_literal',
|
|
284
|
-
number_value: -1,
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
kind: 'drill',
|
|
288
|
-
},
|
|
289
|
-
],
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
describe('source parameters', () => {
|
|
296
|
-
test('can handle source parameters', async () => {
|
|
297
|
-
const result = await duckdb
|
|
298
|
-
.loadModel(model)
|
|
299
|
-
.loadQueryByName('source_has_parameters')
|
|
300
|
-
.run();
|
|
301
|
-
const table = getDataTree(API.util.wrapResult(result));
|
|
302
|
-
const expDrillQuery = `run: flights_with_parameters(
|
|
303
|
-
number_param is 1,
|
|
304
|
-
string_param is "foo",
|
|
305
|
-
boolean_param is true,
|
|
306
|
-
date_param is @2000,
|
|
307
|
-
timestamp_param is @2004-01-01 10:00,
|
|
308
|
-
filter_expression_param is f\`> 3\`
|
|
309
|
-
) -> { drill: top_carriers.nickname = "Southwest" } + { select: * }`;
|
|
310
|
-
const row = table.rows[0];
|
|
311
|
-
expect(row.getDrillQueryMalloy()).toEqual(expDrillQuery);
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
test('can handle timezone in source parameter', async () => {
|
|
315
|
-
const result = await duckdb
|
|
316
|
-
.loadModel(model)
|
|
317
|
-
.loadQueryByName('source_has_timezone_param')
|
|
318
|
-
.run();
|
|
319
|
-
const table = getDataTree(API.util.wrapResult(result));
|
|
320
|
-
const expDrillQuery =
|
|
321
|
-
'run: flights_with_timestamp_param(timestamp_param is @2004-01-01 10:00:00[America/Los_Angeles]) -> { drill: top_carriers.nickname = "Southwest" } + { select: * }';
|
|
322
|
-
const row = table.rows[0];
|
|
323
|
-
expect(row.getDrillQueryMalloy()).toEqual(expDrillQuery);
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
test('default_params_are_not_included', async () => {
|
|
327
|
-
const result = await duckdb
|
|
328
|
-
.loadModel(model)
|
|
329
|
-
.loadQueryByName('only_default_params')
|
|
330
|
-
.run();
|
|
331
|
-
const table = getDataTree(API.util.wrapResult(result));
|
|
332
|
-
const expDrillQuery =
|
|
333
|
-
'run: flights_with_parameters -> { drill: top_carriers.nickname = "Southwest" } + { select: * }';
|
|
334
|
-
const row = table.rows[0];
|
|
335
|
-
expect(row.getDrillQueryMalloy()).toEqual(expDrillQuery);
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
});
|