@malloydata/malloy-tests 0.0.66-dev230807232724
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/README.md +29 -0
- package/bin/dump_malloytest.sh +1 -0
- package/bin/postgres_init.sh +9 -0
- package/bin/postgres_start.sh +2 -0
- package/bin/postgres_stop.sh +2 -0
- package/data/duckdb/README.md +4 -0
- package/data/duckdb/aircraft.parquet +0 -0
- package/data/duckdb/aircraft_models.parquet +0 -0
- package/data/duckdb/airports.parquet +0 -0
- package/data/duckdb/alltypes.parquet +0 -0
- package/data/duckdb/alltypes2.parquet +0 -0
- package/data/duckdb/bq_medicare_test.parquet +0 -0
- package/data/duckdb/carriers.parquet +0 -0
- package/data/duckdb/flights/part.0.parquet +0 -0
- package/data/duckdb/flights/part.1.parquet +0 -0
- package/data/duckdb/flights/part.2.parquet +0 -0
- package/data/duckdb/flights.parquet +0 -0
- package/data/duckdb/flights_partitioned.parquet +0 -0
- package/data/duckdb/ga_sample.parquet +0 -0
- package/data/duckdb/numbers.parquet +0 -0
- package/data/duckdb/state_facts.parquet +0 -0
- package/data/duckdb/test.json +3 -0
- package/data/duckdb/words.parquet +0 -0
- package/data/duckdb/words_bigger.parquet +0 -0
- package/data/postgres/malloytest-postgres.sql.gz +0 -0
- package/data/postgres/state_facts.sql +366 -0
- package/dist/api.spec.d.ts +1 -0
- package/dist/api.spec.js +77 -0
- package/dist/api.spec.js.map +1 -0
- package/dist/databases/all/expr.spec.d.ts +3 -0
- package/dist/databases/all/expr.spec.js +581 -0
- package/dist/databases/all/expr.spec.js.map +1 -0
- package/dist/databases/all/functions.spec.d.ts +2 -0
- package/dist/databases/all/functions.spec.js +784 -0
- package/dist/databases/all/functions.spec.js.map +1 -0
- package/dist/databases/all/index.spec.d.ts +2 -0
- package/dist/databases/all/index.spec.js +154 -0
- package/dist/databases/all/index.spec.js.map +1 -0
- package/dist/databases/all/join.spec.d.ts +2 -0
- package/dist/databases/all/join.spec.js +309 -0
- package/dist/databases/all/join.spec.js.map +1 -0
- package/dist/databases/all/nomodel.spec.d.ts +2 -0
- package/dist/databases/all/nomodel.spec.js +957 -0
- package/dist/databases/all/nomodel.spec.js.map +1 -0
- package/dist/databases/all/orderby.spec.d.ts +2 -0
- package/dist/databases/all/orderby.spec.js +224 -0
- package/dist/databases/all/orderby.spec.js.map +1 -0
- package/dist/databases/all/problems.spec.d.ts +2 -0
- package/dist/databases/all/problems.spec.js +113 -0
- package/dist/databases/all/problems.spec.js.map +1 -0
- package/dist/databases/all/sql_expressions.spec.d.ts +2 -0
- package/dist/databases/all/sql_expressions.spec.js +96 -0
- package/dist/databases/all/sql_expressions.spec.js.map +1 -0
- package/dist/databases/all/time.spec.d.ts +3 -0
- package/dist/databases/all/time.spec.js +647 -0
- package/dist/databases/all/time.spec.js.map +1 -0
- package/dist/databases/bigquery/double_truncation.spec.d.ts +1 -0
- package/dist/databases/bigquery/double_truncation.spec.js +50 -0
- package/dist/databases/bigquery/double_truncation.spec.js.map +1 -0
- package/dist/databases/bigquery/handexpr.spec.d.ts +1 -0
- package/dist/databases/bigquery/handexpr.spec.js +713 -0
- package/dist/databases/bigquery/handexpr.spec.js.map +1 -0
- package/dist/databases/bigquery/injestion_time_partitioning.spec.d.ts +1 -0
- package/dist/databases/bigquery/injestion_time_partitioning.spec.js +235 -0
- package/dist/databases/bigquery/injestion_time_partitioning.spec.js.map +1 -0
- package/dist/databases/bigquery/joined_filters.spec.d.ts +1 -0
- package/dist/databases/bigquery/joined_filters.spec.js +72 -0
- package/dist/databases/bigquery/joined_filters.spec.js.map +1 -0
- package/dist/databases/bigquery/json.spec.d.ts +1 -0
- package/dist/databases/bigquery/json.spec.js +86 -0
- package/dist/databases/bigquery/json.spec.js.map +1 -0
- package/dist/databases/bigquery/malloy_query.spec.d.ts +1 -0
- package/dist/databases/bigquery/malloy_query.spec.js +906 -0
- package/dist/databases/bigquery/malloy_query.spec.js.map +1 -0
- package/dist/databases/bigquery/performance.skipped.spec.d.ts +1 -0
- package/dist/databases/bigquery/performance.skipped.spec.js +70 -0
- package/dist/databases/bigquery/performance.skipped.spec.js.map +1 -0
- package/dist/databases/bigquery/time.spec.d.ts +1 -0
- package/dist/databases/bigquery/time.spec.js +55 -0
- package/dist/databases/bigquery/time.spec.js.map +1 -0
- package/dist/databases/bigquery/wildcard_table_names.spec.d.ts +1 -0
- package/dist/databases/bigquery/wildcard_table_names.spec.js +212 -0
- package/dist/databases/bigquery/wildcard_table_names.spec.js.map +1 -0
- package/dist/databases/bigquery-duckdb/nested_source_table.spec.d.ts +1 -0
- package/dist/databases/bigquery-duckdb/nested_source_table.spec.js +247 -0
- package/dist/databases/bigquery-duckdb/nested_source_table.spec.js.map +1 -0
- package/dist/databases/bigquery-postgres/multi_connection.spec.d.ts +1 -0
- package/dist/databases/bigquery-postgres/multi_connection.spec.js +138 -0
- package/dist/databases/bigquery-postgres/multi_connection.spec.js.map +1 -0
- package/dist/databases/bigquery-postgres/streaming.spec.d.ts +1 -0
- package/dist/databases/bigquery-postgres/streaming.spec.js +88 -0
- package/dist/databases/bigquery-postgres/streaming.spec.js.map +1 -0
- package/dist/databases/duckdb/duckdb.spec.d.ts +1 -0
- package/dist/databases/duckdb/duckdb.spec.js +116 -0
- package/dist/databases/duckdb/duckdb.spec.js.map +1 -0
- package/dist/databases/postgres/postgres.spec.d.ts +1 -0
- package/dist/databases/postgres/postgres.spec.js +137 -0
- package/dist/databases/postgres/postgres.spec.js.map +1 -0
- package/dist/databases/shared/test_list.d.ts +3 -0
- package/dist/databases/shared/test_list.js +24 -0
- package/dist/databases/shared/test_list.js.map +1 -0
- package/dist/dependencies.spec.d.ts +1 -0
- package/dist/dependencies.spec.js +63 -0
- package/dist/dependencies.spec.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/model/utils.spec.d.ts +1 -0
- package/dist/model/utils.spec.js +38 -0
- package/dist/model/utils.spec.js.map +1 -0
- package/dist/models/faa_model.d.ts +5 -0
- package/dist/models/faa_model.js +977 -0
- package/dist/models/faa_model.js.map +1 -0
- package/dist/models/medicare_model.d.ts +4 -0
- package/dist/models/medicare_model.js +243 -0
- package/dist/models/medicare_model.js.map +1 -0
- package/dist/render/render.spec.d.ts +1 -0
- package/dist/render/render.spec.js +551 -0
- package/dist/render/render.spec.js.map +1 -0
- package/dist/runtimes.d.ts +33 -0
- package/dist/runtimes.js +147 -0
- package/dist/runtimes.js.map +1 -0
- package/dist/tags.spec.d.ts +1 -0
- package/dist/tags.spec.js +259 -0
- package/dist/tags.spec.js.map +1 -0
- package/dist/util/db-jest-matchers.d.ts +19 -0
- package/dist/util/db-jest-matchers.js +90 -0
- package/dist/util/db-jest-matchers.js.map +1 -0
- package/dist/util/index.d.ts +16 -0
- package/dist/util/index.js +171 -0
- package/dist/util/index.js.map +1 -0
- package/package.json +35 -0
- package/src/api.spec.ts +84 -0
- package/src/databases/all/expr.spec.ts +704 -0
- package/src/databases/all/functions.spec.ts +1135 -0
- package/src/databases/all/index.spec.ts +178 -0
- package/src/databases/all/join.spec.ts +350 -0
- package/src/databases/all/nomodel.spec.ts +1159 -0
- package/src/databases/all/orderby.spec.ts +268 -0
- package/src/databases/all/problems.spec.ts +121 -0
- package/src/databases/all/sql_expressions.spec.ts +107 -0
- package/src/databases/all/time.spec.ts +793 -0
- package/src/databases/bigquery/double_truncation.spec.ts +51 -0
- package/src/databases/bigquery/handexpr.spec.ts +782 -0
- package/src/databases/bigquery/injestion_time_partitioning.spec.ts +268 -0
- package/src/databases/bigquery/joined_filters.spec.ts +75 -0
- package/src/databases/bigquery/json.spec.ts +95 -0
- package/src/databases/bigquery/malloy_query.spec.ts +1036 -0
- package/src/databases/bigquery/performance.skipped.spec.ts +73 -0
- package/src/databases/bigquery/time.spec.ts +59 -0
- package/src/databases/bigquery/wildcard_table_names.spec.ts +233 -0
- package/src/databases/bigquery-duckdb/nested_source_table.spec.ts +268 -0
- package/src/databases/bigquery-postgres/multi_connection.spec.ts +143 -0
- package/src/databases/bigquery-postgres/streaming.spec.ts +100 -0
- package/src/databases/duckdb/duckdb.spec.ts +131 -0
- package/src/databases/postgres/postgres.spec.ts +167 -0
- package/src/databases/shared/test_list.ts +24 -0
- package/src/dependencies.spec.ts +62 -0
- package/src/index.ts +36 -0
- package/src/model/utils.spec.ts +37 -0
- package/src/models/faa_model.ts +995 -0
- package/src/models/medicare_model.ts +246 -0
- package/src/render/__snapshots__/render.spec.ts.snap +12574 -0
- package/src/render/render.spec.ts +670 -0
- package/src/runtimes.ts +182 -0
- package/src/tags.spec.ts +277 -0
- package/src/util/db-jest-matchers.ts +128 -0
- package/src/util/index.ts +191 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
|
|
27
|
+
import * as malloy from '@malloydata/malloy';
|
|
28
|
+
import {EmptyURLReader} from '@malloydata/malloy';
|
|
29
|
+
import {BigQueryTestConnection, PostgresTestConnection} from '../../runtimes';
|
|
30
|
+
import {describeIfDatabaseAvailable} from '../../util';
|
|
31
|
+
|
|
32
|
+
const res = describeIfDatabaseAvailable(['bigquery', 'postgres']);
|
|
33
|
+
let [describe] = res;
|
|
34
|
+
const [, databases] = res;
|
|
35
|
+
|
|
36
|
+
// *** NOTE ***
|
|
37
|
+
// this is a special case (for now): a test that REQUIRES two databases - bigquery AND postgres
|
|
38
|
+
describe =
|
|
39
|
+
databases.filter(d => ['postgres', 'bigquery'].includes(d)).length >= 2
|
|
40
|
+
? describe
|
|
41
|
+
: describe.skip;
|
|
42
|
+
|
|
43
|
+
describe('Multi-connection', () => {
|
|
44
|
+
const bqConnection = new BigQueryTestConnection(
|
|
45
|
+
'bigquery',
|
|
46
|
+
{},
|
|
47
|
+
{defaultProject: 'malloy-data'}
|
|
48
|
+
);
|
|
49
|
+
const postgresConnection = new PostgresTestConnection('postgres');
|
|
50
|
+
const files = new EmptyURLReader();
|
|
51
|
+
|
|
52
|
+
const connectionMap = new malloy.FixedConnectionMap(
|
|
53
|
+
new Map(
|
|
54
|
+
Object.entries({
|
|
55
|
+
bigquery: bqConnection,
|
|
56
|
+
postgres: postgresConnection,
|
|
57
|
+
})
|
|
58
|
+
),
|
|
59
|
+
'bigquery'
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const runtime = new malloy.Runtime(files, connectionMap);
|
|
63
|
+
|
|
64
|
+
afterAll(async () => {
|
|
65
|
+
await postgresConnection.close();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const expressionModelText = `
|
|
69
|
+
source: default_aircraft is table('malloytest.aircraft'){
|
|
70
|
+
measure: aircraft_count is count(DISTINCT tail_num)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
source: bigquery_state_facts is table('malloytest.state_facts'){
|
|
74
|
+
measure: state_count is count(DISTINCT state)+2
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
source: postgres_aircraft is table('postgres:malloytest.aircraft'){
|
|
78
|
+
measure: aircraft_count is count(DISTINCT tail_num)+4
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
|
|
82
|
+
const expressionModel = runtime.loadModel(expressionModelText);
|
|
83
|
+
|
|
84
|
+
it('default query', async () => {
|
|
85
|
+
const result = await expressionModel
|
|
86
|
+
.loadQuery(
|
|
87
|
+
`
|
|
88
|
+
query: default_aircraft-> {
|
|
89
|
+
aggregate: aircraft_count
|
|
90
|
+
}
|
|
91
|
+
`
|
|
92
|
+
)
|
|
93
|
+
.run();
|
|
94
|
+
// console.log(result.sql);
|
|
95
|
+
expect(result.data.path(0, 'aircraft_count').value).toBe(3599);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('bigquery query', async () => {
|
|
99
|
+
const result = await expressionModel
|
|
100
|
+
.loadQuery(
|
|
101
|
+
`
|
|
102
|
+
query: bigquery_state_facts-> {
|
|
103
|
+
aggregate: state_count
|
|
104
|
+
}
|
|
105
|
+
`
|
|
106
|
+
)
|
|
107
|
+
.run();
|
|
108
|
+
// console.log(result.sql);
|
|
109
|
+
expect(result.data.path(0, 'state_count').value).toBe(53);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('postgres query', async () => {
|
|
113
|
+
const result = await expressionModel
|
|
114
|
+
.loadQuery(
|
|
115
|
+
`
|
|
116
|
+
query: postgres_aircraft-> {
|
|
117
|
+
aggregate: aircraft_count
|
|
118
|
+
}
|
|
119
|
+
`
|
|
120
|
+
)
|
|
121
|
+
.run();
|
|
122
|
+
expect(result.data.path(0, 'aircraft_count').value).toBe(3603);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('postgres raw query', async () => {
|
|
126
|
+
const result = await runtime
|
|
127
|
+
.loadQuery(
|
|
128
|
+
`
|
|
129
|
+
query: table('postgres:malloytest.airports')->{
|
|
130
|
+
group_by:
|
|
131
|
+
version is version!()
|
|
132
|
+
aggregate:
|
|
133
|
+
code_count is count(distinct code)
|
|
134
|
+
airport_count is count()
|
|
135
|
+
}
|
|
136
|
+
`
|
|
137
|
+
)
|
|
138
|
+
.run();
|
|
139
|
+
expect(result.data.path(0, 'airport_count').value).toBe(19793);
|
|
140
|
+
expect(result.data.path(0, 'version').value).toMatch(/Postgre/);
|
|
141
|
+
expect(result.data.path(0, 'code_count').value).toBe(19793);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Google LLC
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
* a copy of this software and associated documentation files
|
|
6
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
7
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
8
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
9
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
* subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be
|
|
13
|
+
* included in all copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
18
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
19
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
20
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
21
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
CSVWriter,
|
|
26
|
+
DataRecord,
|
|
27
|
+
JSONWriter,
|
|
28
|
+
WriteStream,
|
|
29
|
+
} from '@malloydata/malloy';
|
|
30
|
+
import {RuntimeList} from '../../runtimes';
|
|
31
|
+
import {describeIfDatabaseAvailable} from '../../util';
|
|
32
|
+
|
|
33
|
+
class StringAccumulator implements WriteStream {
|
|
34
|
+
public accumulatedValue = '';
|
|
35
|
+
|
|
36
|
+
write(text: string) {
|
|
37
|
+
this.accumulatedValue += text;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
close() {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const [describe, databases] = describeIfDatabaseAvailable([
|
|
46
|
+
'bigquery',
|
|
47
|
+
'postgres',
|
|
48
|
+
]);
|
|
49
|
+
|
|
50
|
+
describe('Streaming tests', () => {
|
|
51
|
+
const runtimes = new RuntimeList(databases);
|
|
52
|
+
|
|
53
|
+
afterAll(async () => {
|
|
54
|
+
await runtimes.closeAll();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
runtimes.runtimeMap.forEach((runtime, databaseName) => {
|
|
58
|
+
it(`basic stream test - ${databaseName}`, async () => {
|
|
59
|
+
const stream = runtime
|
|
60
|
+
.loadModel("source: airports is table('malloytest.airports') {}")
|
|
61
|
+
.loadQuery('query: airports -> { project: code }')
|
|
62
|
+
.runStream({rowLimit: 10});
|
|
63
|
+
const rows: DataRecord[] = [];
|
|
64
|
+
for await (const row of stream) {
|
|
65
|
+
rows.push(row);
|
|
66
|
+
}
|
|
67
|
+
expect(rows.length).toBe(10);
|
|
68
|
+
expect(rows[0].cell('code').string.value).toBe('1Q9');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it(`stream to JSON - ${databaseName}`, async () => {
|
|
72
|
+
const stream = runtime
|
|
73
|
+
.loadModel("source: airports is table('malloytest.airports') {}")
|
|
74
|
+
.loadQuery('query: airports -> { project: code }')
|
|
75
|
+
.runStream({rowLimit: 1});
|
|
76
|
+
const accummulator = new StringAccumulator();
|
|
77
|
+
const jsonWriter = new JSONWriter(accummulator);
|
|
78
|
+
await jsonWriter.process(stream);
|
|
79
|
+
expect(accummulator.accumulatedValue).toBe(
|
|
80
|
+
`[
|
|
81
|
+
{
|
|
82
|
+
"code": "1Q9"
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
`
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it(`stream to CSV - ${databaseName}`, async () => {
|
|
90
|
+
const stream = runtime
|
|
91
|
+
.loadModel("source: airports is table('malloytest.airports') {}")
|
|
92
|
+
.loadQuery('query: airports -> { project: code }')
|
|
93
|
+
.runStream({rowLimit: 1});
|
|
94
|
+
const accummulator = new StringAccumulator();
|
|
95
|
+
const csvWriter = new CSVWriter(accummulator);
|
|
96
|
+
await csvWriter.process(stream);
|
|
97
|
+
expect(accummulator.accumulatedValue).toBe('code\n1Q9\n');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Google LLC
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
* a copy of this software and associated documentation files
|
|
6
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
7
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
8
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
9
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
* subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be
|
|
13
|
+
* included in all copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
18
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
19
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
20
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
21
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import {DateTime} from 'luxon';
|
|
25
|
+
import {RuntimeList} from '../../runtimes';
|
|
26
|
+
import '../../util/db-jest-matchers';
|
|
27
|
+
import {describeIfDatabaseAvailable} from '../../util';
|
|
28
|
+
|
|
29
|
+
const runtimes = ['duckdb', 'duckdb_wasm'];
|
|
30
|
+
|
|
31
|
+
const [_describe, databases] = describeIfDatabaseAvailable(runtimes);
|
|
32
|
+
const allDucks = new RuntimeList(databases);
|
|
33
|
+
|
|
34
|
+
describe.each(allDucks.runtimeList)('duckdb:%s', (dbName, runtime) => {
|
|
35
|
+
it('can open tables with wildcards', async () => {
|
|
36
|
+
const result = await runtime
|
|
37
|
+
.loadQuery(
|
|
38
|
+
`
|
|
39
|
+
query: table('duckdb:test/data/duckdb/flights/part.*.parquet') -> {
|
|
40
|
+
top: 1
|
|
41
|
+
group_by: carrier;
|
|
42
|
+
}
|
|
43
|
+
`
|
|
44
|
+
)
|
|
45
|
+
.run();
|
|
46
|
+
expect(result.data.path(0, 'carrier').value).toEqual('AA');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('accepts all schema numbers', async () => {
|
|
50
|
+
const allInts = [
|
|
51
|
+
'BIGINT',
|
|
52
|
+
'INTEGER',
|
|
53
|
+
'TINYINT',
|
|
54
|
+
'SMALLINT',
|
|
55
|
+
'UBIGINT',
|
|
56
|
+
'UINTEGER',
|
|
57
|
+
'UTINYINT',
|
|
58
|
+
'USMALLINT',
|
|
59
|
+
'HUGEINT',
|
|
60
|
+
];
|
|
61
|
+
const allFields = allInts.map(intType => `a${intType.toLowerCase()}`);
|
|
62
|
+
const query = `
|
|
63
|
+
sql: allInts is { connection: "${dbName}" select: """
|
|
64
|
+
SELECT
|
|
65
|
+
${allInts
|
|
66
|
+
.map(intType => `1::${intType} as a${intType.toLowerCase()}`)
|
|
67
|
+
.join(',\n')}
|
|
68
|
+
"""}
|
|
69
|
+
query: from_sql(allInts) -> {
|
|
70
|
+
aggregate:
|
|
71
|
+
${allFields
|
|
72
|
+
.map(fieldType => `sum_${fieldType} is sum(${fieldType})`)
|
|
73
|
+
.join('\n')}
|
|
74
|
+
}
|
|
75
|
+
`;
|
|
76
|
+
const result = await runtime.loadQuery(query).run();
|
|
77
|
+
for (const fieldType of allFields) {
|
|
78
|
+
expect(result.data.path(0, `sum_${fieldType}`).value).toEqual(1);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('can open json files', async () => {
|
|
83
|
+
const result = await runtime
|
|
84
|
+
.loadQuery(
|
|
85
|
+
`
|
|
86
|
+
query: table('duckdb:test/data/duckdb/test.json') -> {
|
|
87
|
+
project: *
|
|
88
|
+
}
|
|
89
|
+
`
|
|
90
|
+
)
|
|
91
|
+
.run();
|
|
92
|
+
expect(result.data.path(0, 'foo').value).toEqual('bar');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('supports timezones', async () => {
|
|
96
|
+
await runtime.connection.runSQL("SET TimeZone='CET'");
|
|
97
|
+
const result = await runtime.connection.runSQL(
|
|
98
|
+
"SELECT current_setting('TimeZone')"
|
|
99
|
+
);
|
|
100
|
+
expect(result.rows[0]).toEqual({"current_setting('TimeZone')": 'CET'});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('time', () => {
|
|
104
|
+
const zone = 'America/Mexico_City'; // -06:00 no DST
|
|
105
|
+
const zone_2020 = DateTime.fromObject({
|
|
106
|
+
year: 2020,
|
|
107
|
+
month: 2,
|
|
108
|
+
day: 20,
|
|
109
|
+
hour: 0,
|
|
110
|
+
minute: 0,
|
|
111
|
+
second: 0,
|
|
112
|
+
zone,
|
|
113
|
+
});
|
|
114
|
+
// TODO: Investigate why its no working.
|
|
115
|
+
test.skip('can use unsupported types', async () => {
|
|
116
|
+
await expect(runtime).queryMatches(
|
|
117
|
+
`sql: timeData is { connection: "duckdb" select: """
|
|
118
|
+
SELECT TIMESTAMPTZ '2020-02-20 00:00:00 ${zone}' as t_tstz
|
|
119
|
+
"""}
|
|
120
|
+
query: from_sql(timeData) -> {
|
|
121
|
+
project: mex_220 is t_tstz::timestamp
|
|
122
|
+
}`,
|
|
123
|
+
{mex_220: zone_2020.toJSDate()}
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
afterAll(async () => {
|
|
130
|
+
await allDucks.closeAll();
|
|
131
|
+
});
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Google LLC
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
* a copy of this software and associated documentation files
|
|
6
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
7
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
8
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
9
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
* subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be
|
|
13
|
+
* included in all copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
18
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
19
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
20
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
21
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/* eslint-disable no-console */
|
|
25
|
+
|
|
26
|
+
import {RuntimeList} from '../../runtimes';
|
|
27
|
+
import {describeIfDatabaseAvailable} from '../../util';
|
|
28
|
+
import '../../util/db-jest-matchers';
|
|
29
|
+
import {DateTime} from 'luxon';
|
|
30
|
+
|
|
31
|
+
const [describe] = describeIfDatabaseAvailable(['postgres']);
|
|
32
|
+
|
|
33
|
+
describe('Postgres tests', () => {
|
|
34
|
+
const runtimeList = new RuntimeList(['postgres']);
|
|
35
|
+
const runtime = runtimeList.runtimeMap.get('postgres');
|
|
36
|
+
if (runtime === undefined) {
|
|
37
|
+
throw new Error("Couldn't build runtime");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Idempotently create schema and tables with capital letters to use in tests.
|
|
41
|
+
beforeAll(async () => {
|
|
42
|
+
await runtime.connection.runSQL(
|
|
43
|
+
'create schema if not exists "UpperSchema";'
|
|
44
|
+
);
|
|
45
|
+
await Promise.all([
|
|
46
|
+
runtime.connection.runSQL(
|
|
47
|
+
'create table if not exists "UpperSchema"."UpperSchemaUpperTable" as select 1 as one;'
|
|
48
|
+
),
|
|
49
|
+
runtime.connection.runSQL(
|
|
50
|
+
'create table if not exists "UpperTablePublic" as select 1 as one;'
|
|
51
|
+
),
|
|
52
|
+
]);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
afterAll(async () => {
|
|
56
|
+
await runtimeList.closeAll();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('sql_block', async () => {
|
|
60
|
+
const result = await runtime
|
|
61
|
+
.loadQuery(
|
|
62
|
+
`
|
|
63
|
+
sql: one is {select:"""
|
|
64
|
+
SELECT 1 as n
|
|
65
|
+
"""}
|
|
66
|
+
|
|
67
|
+
query: from_sql(one) -> { project: n }
|
|
68
|
+
`
|
|
69
|
+
)
|
|
70
|
+
.run();
|
|
71
|
+
expect(result.data.value[0]['n']).toBe(1);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('quote field name', async () => {
|
|
75
|
+
const result = await runtime
|
|
76
|
+
.loadQuery(
|
|
77
|
+
`
|
|
78
|
+
sql: one is {select:"""
|
|
79
|
+
SELECT 1 as "upperLower"
|
|
80
|
+
"""}
|
|
81
|
+
|
|
82
|
+
query: from_sql(one) -> { project: upperLower }
|
|
83
|
+
`
|
|
84
|
+
)
|
|
85
|
+
.run();
|
|
86
|
+
expect(result.data.value[0]['upperLower']).toBe(1);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('quote keyword', async () => {
|
|
90
|
+
const result = await runtime
|
|
91
|
+
.loadQuery(
|
|
92
|
+
`
|
|
93
|
+
sql: one is {select:"""
|
|
94
|
+
SELECT 1 as "select"
|
|
95
|
+
"""}
|
|
96
|
+
|
|
97
|
+
query: from_sql(one) -> {
|
|
98
|
+
project:
|
|
99
|
+
select
|
|
100
|
+
create is select + 1
|
|
101
|
+
}
|
|
102
|
+
`
|
|
103
|
+
)
|
|
104
|
+
.run();
|
|
105
|
+
expect(result.data.value[0]['select']).toBe(1);
|
|
106
|
+
expect(result.data.value[0]['create']).toBe(2);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// these started failing and I'm not sure why (lloyd, skipping for now)
|
|
110
|
+
it.skip('quote table name', async () => {
|
|
111
|
+
const result = await runtime
|
|
112
|
+
.loadQuery(
|
|
113
|
+
`
|
|
114
|
+
query: table('public.UpperTablePublic') -> { project: one }
|
|
115
|
+
`
|
|
116
|
+
)
|
|
117
|
+
.run();
|
|
118
|
+
expect(result.data.value[0]['one']).toBe(1);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it.skip('quote schema name', async () => {
|
|
122
|
+
const result = await runtime
|
|
123
|
+
.loadQuery(
|
|
124
|
+
`
|
|
125
|
+
query: table('UpperSchema.UpperSchemaUpperTable') -> { project: one }
|
|
126
|
+
`
|
|
127
|
+
)
|
|
128
|
+
.run();
|
|
129
|
+
expect(result.data.value[0]['one']).toBe(1);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('passes unsupported data', async () => {
|
|
133
|
+
const result = await runtime
|
|
134
|
+
.loadQuery(
|
|
135
|
+
`
|
|
136
|
+
sql: badType is { select: """SELECT int4range(10, 20) as ranger""" }
|
|
137
|
+
query: from_sql(badType)->{ project: *}
|
|
138
|
+
`
|
|
139
|
+
)
|
|
140
|
+
.run();
|
|
141
|
+
expect(result.data.value[0]['ranger']).toBeDefined();
|
|
142
|
+
});
|
|
143
|
+
describe('time', () => {
|
|
144
|
+
const zone = 'America/Mexico_City'; // -06:00 no DST
|
|
145
|
+
const zone_2020 = DateTime.fromObject({
|
|
146
|
+
year: 2020,
|
|
147
|
+
month: 2,
|
|
148
|
+
day: 20,
|
|
149
|
+
hour: 0,
|
|
150
|
+
minute: 0,
|
|
151
|
+
second: 0,
|
|
152
|
+
zone,
|
|
153
|
+
});
|
|
154
|
+
// TODO: Investigate why this test is not working.
|
|
155
|
+
test.skip('can use unsupported types', async () => {
|
|
156
|
+
await expect(runtime).queryMatches(
|
|
157
|
+
`sql: timeData is { connection: "postgres" select: """
|
|
158
|
+
SELECT TIMESTAMPTZ '2020-02-20 00:00:00 ${zone}' as t_tstz
|
|
159
|
+
"""}
|
|
160
|
+
query: from_sql(timeData) -> {
|
|
161
|
+
project: mex_220 is t_tstz::timestamp
|
|
162
|
+
}`,
|
|
163
|
+
{mex_220: zone_2020.toJSDate()}
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {RuntimeList} from '../../runtimes';
|
|
2
|
+
import {exprSharedTests} from '../all/expr.spec';
|
|
3
|
+
import {functionsSharedTests} from '../all/functions.spec';
|
|
4
|
+
import {indexSharedTests} from '../all/index.spec';
|
|
5
|
+
import {joinSharedTests} from '../all/join.spec';
|
|
6
|
+
import {noModelSharedTests} from '../all/nomodel.spec';
|
|
7
|
+
import {orderBySharedTests} from '../all/orderby.spec';
|
|
8
|
+
import {problemsSharedTests} from '../all/problems.spec';
|
|
9
|
+
import {sqlExpressionsSharedTests} from '../all/sql_expressions.spec';
|
|
10
|
+
import {timeSharedTests} from '../all/time.spec';
|
|
11
|
+
|
|
12
|
+
export type DatabaseTestSet = (runtimeList: RuntimeList) => void;
|
|
13
|
+
|
|
14
|
+
export const allDatabaseTestSets: DatabaseTestSet[] = [
|
|
15
|
+
exprSharedTests,
|
|
16
|
+
functionsSharedTests,
|
|
17
|
+
indexSharedTests,
|
|
18
|
+
joinSharedTests,
|
|
19
|
+
noModelSharedTests,
|
|
20
|
+
orderBySharedTests,
|
|
21
|
+
problemsSharedTests,
|
|
22
|
+
sqlExpressionsSharedTests,
|
|
23
|
+
timeSharedTests,
|
|
24
|
+
];
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Google LLC
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
* a copy of this software and associated documentation files
|
|
6
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
7
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
8
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
9
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
* subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be
|
|
13
|
+
* included in all copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
18
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
19
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
20
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
21
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import madge from 'madge';
|
|
25
|
+
|
|
26
|
+
describe('dependencies', () => {
|
|
27
|
+
function getMessage(circles: string[][]): string {
|
|
28
|
+
let message = 'Circular References:\n';
|
|
29
|
+
for (const circle of circles) {
|
|
30
|
+
message += ' ';
|
|
31
|
+
for (const dep of circle) {
|
|
32
|
+
message += `${dep} -> `;
|
|
33
|
+
}
|
|
34
|
+
message += `${circle[0]}\n`;
|
|
35
|
+
}
|
|
36
|
+
return message;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
it('typescript references should not be circular', async () => {
|
|
40
|
+
const deps = await madge('packages', {
|
|
41
|
+
fileExtensions: ['ts'],
|
|
42
|
+
excludeRegExp: [/malloy\/src\/lang/, /\.d\.ts/],
|
|
43
|
+
});
|
|
44
|
+
expect(deps.circular().length, getMessage(deps.circular())).toBe(0);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('javascript references should not be circular', async () => {
|
|
48
|
+
const deps = await madge('packages', {
|
|
49
|
+
fileExtensions: ['js'],
|
|
50
|
+
});
|
|
51
|
+
expect(deps.circular().length, getMessage(deps.circular())).toBe(0);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Enable more strict circular checks if we refactor lang again.
|
|
55
|
+
it.skip('malloy/src/lang typescript should not be circular', async () => {
|
|
56
|
+
const deps = await madge('packages', {
|
|
57
|
+
fileExtensions: ['ts'],
|
|
58
|
+
excludeRegExp: [/malloy\/src\/lang\/lib/, /\.d\.ts/],
|
|
59
|
+
});
|
|
60
|
+
expect(deps.circular().length, getMessage(deps.circular())).toBe(0);
|
|
61
|
+
});
|
|
62
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Google LLC
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
* a copy of this software and associated documentation files
|
|
6
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
7
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
8
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
9
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
* subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be
|
|
13
|
+
* included in all copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
18
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
19
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
20
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
21
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export {RuntimeList, testRuntimeFor} from './runtimes';
|
|
25
|
+
|
|
26
|
+
export {allDatabaseTestSets} from './databases/shared/test_list';
|
|
27
|
+
|
|
28
|
+
export {exprSharedTests} from './databases/all/expr.spec';
|
|
29
|
+
export {functionsSharedTests} from './databases/all/functions.spec';
|
|
30
|
+
export {indexSharedTests} from './databases/all/index.spec';
|
|
31
|
+
export {joinSharedTests} from './databases/all/join.spec';
|
|
32
|
+
export {noModelSharedTests} from './databases/all/nomodel.spec';
|
|
33
|
+
export {orderBySharedTests} from './databases/all/orderby.spec';
|
|
34
|
+
export {problemsSharedTests} from './databases/all/problems.spec';
|
|
35
|
+
export {sqlExpressionsSharedTests} from './databases/all/sql_expressions.spec';
|
|
36
|
+
export {timeSharedTests} from './databases/all/time.spec';
|