@malloydata/malloy-tests 0.0.135 → 0.0.136-dev240326234246
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/api.spec.d.ts +1 -0
- package/dist/api.spec.js +113 -0
- package/dist/api.spec.js.map +1 -0
- package/dist/databases/all/db_index.spec.d.ts +1 -0
- package/dist/databases/all/db_index.spec.js +126 -0
- package/dist/databases/all/db_index.spec.js.map +1 -0
- package/dist/databases/all/expr.spec.d.ts +1 -0
- package/dist/databases/all/expr.spec.js +652 -0
- package/dist/databases/all/expr.spec.js.map +1 -0
- package/dist/databases/all/functions.spec.d.ts +1 -0
- package/dist/databases/all/functions.spec.js +1180 -0
- package/dist/databases/all/functions.spec.js.map +1 -0
- package/dist/databases/all/join.spec.d.ts +1 -0
- package/dist/databases/all/join.spec.js +255 -0
- package/dist/databases/all/join.spec.js.map +1 -0
- package/dist/databases/all/lenses.spec.d.ts +1 -0
- package/dist/databases/all/lenses.spec.js +374 -0
- package/dist/databases/all/lenses.spec.js.map +1 -0
- package/dist/databases/all/nomodel.spec.d.ts +1 -0
- package/dist/databases/all/nomodel.spec.js +1070 -0
- package/dist/databases/all/nomodel.spec.js.map +1 -0
- package/dist/databases/all/orderby.spec.d.ts +1 -0
- package/dist/databases/all/orderby.spec.js +170 -0
- package/dist/databases/all/orderby.spec.js.map +1 -0
- package/dist/databases/all/problems.spec.d.ts +1 -0
- package/dist/databases/all/problems.spec.js +106 -0
- package/dist/databases/all/problems.spec.js.map +1 -0
- package/dist/databases/all/sql_expressions.spec.d.ts +1 -0
- package/dist/databases/all/sql_expressions.spec.js +73 -0
- package/dist/databases/all/sql_expressions.spec.js.map +1 -0
- package/dist/databases/all/time.spec.d.ts +1 -0
- package/dist/databases/all/time.spec.js +602 -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 +723 -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 +66 -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 +840 -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 +52 -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 +213 -0
- package/dist/databases/bigquery-duckdb/nested_source_table.spec.js.map +1 -0
- package/dist/databases/duckdb/duckdb.spec.d.ts +1 -0
- package/dist/databases/duckdb/duckdb.spec.js +124 -0
- package/dist/databases/duckdb/duckdb.spec.js.map +1 -0
- package/dist/databases/duckdb/streaming.spec.d.ts +1 -0
- package/dist/databases/duckdb/streaming.spec.js +142 -0
- package/dist/databases/duckdb/streaming.spec.js.map +1 -0
- package/dist/databases/multi-connection/multi_connection.spec.d.ts +1 -0
- package/dist/databases/multi-connection/multi_connection.spec.js +120 -0
- package/dist/databases/multi-connection/multi_connection.spec.js.map +1 -0
- package/dist/databases/postgres/postgres.spec.d.ts +1 -0
- package/dist/databases/postgres/postgres.spec.js +140 -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 +5 -0
- package/dist/databases/shared/test_list.js.map +1 -0
- package/dist/databases/streaming/streaming.spec.d.ts +1 -0
- package/dist/databases/streaming/streaming.spec.js +93 -0
- package/dist/databases/streaming/streaming.spec.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 +4 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/jestMatcher.spec.d.ts +1 -0
- package/dist/jestMatcher.spec.js +81 -0
- package/dist/jestMatcher.spec.js.map +1 -0
- package/dist/model/sql_source.spec.d.ts +1 -0
- package/dist/model/sql_source.spec.js +47 -0
- package/dist/model/sql_source.spec.js.map +1 -0
- package/dist/models/faa_model.d.ts +5 -0
- package/dist/models/faa_model.js +997 -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 +259 -0
- package/dist/models/medicare_model.js.map +1 -0
- package/dist/render/drill.spec.d.ts +1 -0
- package/dist/render/drill.spec.js +107 -0
- package/dist/render/drill.spec.js.map +1 -0
- package/dist/render/render.spec.d.ts +1 -0
- package/dist/render/render.spec.js +548 -0
- package/dist/render/render.spec.js.map +1 -0
- package/dist/runtimes.d.ts +35 -0
- package/dist/runtimes.js +180 -0
- package/dist/runtimes.js.map +1 -0
- package/dist/tags.spec.d.ts +8 -0
- package/dist/tags.spec.js +490 -0
- package/dist/tags.spec.js.map +1 -0
- package/dist/util/db-jest-matchers.d.ts +30 -0
- package/dist/util/db-jest-matchers.js +157 -0
- package/dist/util/db-jest-matchers.js.map +1 -0
- package/dist/util/index.d.ts +15 -0
- package/dist/util/index.js +182 -0
- package/dist/util/index.js.map +1 -0
- package/package.json +8 -8
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const luxon_1 = require("luxon");
|
|
26
|
+
const runtimes_1 = require("../../runtimes");
|
|
27
|
+
require("../../util/db-jest-matchers");
|
|
28
|
+
const util_1 = require("../../util");
|
|
29
|
+
// TODO identify which tests need to run on wasm and move them into their own file
|
|
30
|
+
const runtimes = ['duckdb', 'duckdb_wasm'];
|
|
31
|
+
const [describe, databases] = (0, util_1.describeIfDatabaseAvailable)(runtimes);
|
|
32
|
+
const allDucks = new runtimes_1.RuntimeList(databases);
|
|
33
|
+
describe.each(allDucks.runtimeList)('duckdb:%s', (dbName, runtime) => {
|
|
34
|
+
it('can open tables with wildcards', async () => {
|
|
35
|
+
await expect(`
|
|
36
|
+
run: duckdb.table('test/data/duckdb/flights/part.*.parquet') -> {
|
|
37
|
+
top: 1
|
|
38
|
+
group_by: carrier;
|
|
39
|
+
}
|
|
40
|
+
`).malloyResultMatches(runtime, { carrier: 'AA' });
|
|
41
|
+
});
|
|
42
|
+
it('accepts all schema numbers', async () => {
|
|
43
|
+
const allNumeric = [
|
|
44
|
+
'BIGINT',
|
|
45
|
+
'DOUBLE',
|
|
46
|
+
'FLOAT',
|
|
47
|
+
'FLOAT4',
|
|
48
|
+
'FLOAT8',
|
|
49
|
+
'HUGEINT',
|
|
50
|
+
'INT',
|
|
51
|
+
'INT1',
|
|
52
|
+
'INT2',
|
|
53
|
+
'INT4',
|
|
54
|
+
'INT8',
|
|
55
|
+
'INTEGER',
|
|
56
|
+
'LONG',
|
|
57
|
+
'REAL',
|
|
58
|
+
'SHORT',
|
|
59
|
+
'SIGNED',
|
|
60
|
+
'SMALLINT',
|
|
61
|
+
'TINYINT',
|
|
62
|
+
'UBIGINT',
|
|
63
|
+
'UINTEGER',
|
|
64
|
+
'USMALLINT',
|
|
65
|
+
'UTINYINT',
|
|
66
|
+
];
|
|
67
|
+
const allFields = allNumeric.map(numType => `a${numType.toLowerCase()}`);
|
|
68
|
+
const query = `
|
|
69
|
+
run: ${dbName}.sql("""
|
|
70
|
+
SELECT
|
|
71
|
+
${allNumeric
|
|
72
|
+
.map(numType => `1::${numType} as a${numType.toLowerCase()}`)
|
|
73
|
+
.join(',\n')}
|
|
74
|
+
""") -> {
|
|
75
|
+
aggregate:
|
|
76
|
+
${allFields
|
|
77
|
+
.map(fieldType => `sum_${fieldType} is sum(${fieldType})`)
|
|
78
|
+
.join('\n')}
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
await expect(query).malloyResultMatches(runtime, allNumeric.reduce((building, ent) => {
|
|
82
|
+
building[`sum_a${ent.toLowerCase()}`] = 1;
|
|
83
|
+
return building;
|
|
84
|
+
}, {}));
|
|
85
|
+
});
|
|
86
|
+
it('can open json files', async () => {
|
|
87
|
+
await expect(`
|
|
88
|
+
run: duckdb.table('test/data/duckdb/test.json') -> {
|
|
89
|
+
select: *
|
|
90
|
+
}`).malloyResultMatches(runtime, { foo: 'bar' });
|
|
91
|
+
});
|
|
92
|
+
it('supports timezones', async () => {
|
|
93
|
+
await runtime.connection.runSQL("SET TimeZone='CET'");
|
|
94
|
+
const result = await runtime.connection.runSQL("SELECT current_setting('TimeZone')");
|
|
95
|
+
expect(result.rows[0]).toEqual({ "current_setting('TimeZone')": 'CET' });
|
|
96
|
+
});
|
|
97
|
+
it('supports varchars with parameters', async () => {
|
|
98
|
+
await expect("run: duckdb.sql(\"SELECT 'a'::VARCHAR as abc, 'a3'::VARCHAR(3) as abc3\")").malloyResultMatches(runtime, { abc: 'a', abc3: 'a3' });
|
|
99
|
+
});
|
|
100
|
+
describe('time', () => {
|
|
101
|
+
const zone = 'America/Mexico_City'; // -06:00 no DST
|
|
102
|
+
const zone_2020 = luxon_1.DateTime.fromObject({
|
|
103
|
+
year: 2020,
|
|
104
|
+
month: 2,
|
|
105
|
+
day: 20,
|
|
106
|
+
hour: 0,
|
|
107
|
+
minute: 0,
|
|
108
|
+
second: 0,
|
|
109
|
+
}, {
|
|
110
|
+
zone,
|
|
111
|
+
});
|
|
112
|
+
test('can cast TIMESTAMPTZ to timestamp', async () => {
|
|
113
|
+
await expect(`run: duckdb.sql("""
|
|
114
|
+
SELECT TIMESTAMPTZ '2020-02-20 00:00:00 ${zone}' as t_tstz
|
|
115
|
+
""") -> {
|
|
116
|
+
select: mex_220 is t_tstz::timestamp
|
|
117
|
+
}`).malloyResultMatches(runtime, { mex_220: zone_2020.toJSDate() });
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
afterAll(async () => {
|
|
122
|
+
await allDucks.closeAll();
|
|
123
|
+
});
|
|
124
|
+
//# sourceMappingURL=duckdb.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duckdb.spec.js","sourceRoot":"","sources":["../../../src/databases/duckdb/duckdb.spec.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;AAEH,iCAA+B;AAC/B,6CAA2C;AAC3C,uCAAqC;AACrC,qCAAuD;AAEvD,kFAAkF;AAClF,MAAM,QAAQ,GAAG,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;AAE3C,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,IAAA,kCAA2B,EAAC,QAAQ,CAAC,CAAC;AACpE,MAAM,QAAQ,GAAG,IAAI,sBAAW,CAAC,SAAS,CAAC,CAAC;AAE5C,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;IACnE,EAAE,CAAC,gCAAgC,EAAE,KAAK,IAAI,EAAE;QAC9C,MAAM,MAAM,CAAC;;;;;KAKZ,CAAC,CAAC,mBAAmB,CAAC,OAAO,EAAE,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;QAC1C,MAAM,UAAU,GAAG;YACjB,QAAQ;YACR,QAAQ;YACR,OAAO;YACP,QAAQ;YACR,QAAQ;YACR,SAAS;YAC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
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const malloy_1 = require("@malloydata/malloy");
|
|
26
|
+
const util_1 = require("../../util");
|
|
27
|
+
const runtimes_1 = require("../../runtimes");
|
|
28
|
+
class StringAccumulator {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.accumulatedValue = '';
|
|
31
|
+
}
|
|
32
|
+
write(text) {
|
|
33
|
+
this.accumulatedValue += text;
|
|
34
|
+
}
|
|
35
|
+
close() {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const runtimes = ['duckdb'];
|
|
40
|
+
const [_describe, databases] = (0, util_1.describeIfDatabaseAvailable)(runtimes);
|
|
41
|
+
function modelText(databaseName) {
|
|
42
|
+
return `source: airports is ${databaseName}.table('test/data/duckdb/airports.parquet') extend {
|
|
43
|
+
rename: facility_type is fac_type
|
|
44
|
+
|
|
45
|
+
measure: airport_count is count()
|
|
46
|
+
measure: avg_elevation is avg(elevation)
|
|
47
|
+
|
|
48
|
+
view: higher_elevation is {
|
|
49
|
+
group_by: faa_region
|
|
50
|
+
aggregate: airport_count, avg_elevation
|
|
51
|
+
order_by: avg_elevation desc
|
|
52
|
+
limit: 5
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
view: by_county is {
|
|
56
|
+
where: county != null
|
|
57
|
+
group_by: county
|
|
58
|
+
aggregate: airport_count
|
|
59
|
+
limit: 2
|
|
60
|
+
order_by: airport_count desc, county desc
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
view: by_state is {
|
|
64
|
+
where: state != null
|
|
65
|
+
group_by: state
|
|
66
|
+
aggregate: airport_count
|
|
67
|
+
limit: 2
|
|
68
|
+
nest: by_county
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
view: by_facility_type is {
|
|
72
|
+
group_by: facility_type
|
|
73
|
+
aggregate:
|
|
74
|
+
airport_count
|
|
75
|
+
limit: 2
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
view: airports_by_region is {
|
|
79
|
+
group_by: faa_region
|
|
80
|
+
nest:
|
|
81
|
+
by_state
|
|
82
|
+
by_facility_type
|
|
83
|
+
limit: 2
|
|
84
|
+
aggregate: airport_count
|
|
85
|
+
}
|
|
86
|
+
}`;
|
|
87
|
+
}
|
|
88
|
+
describe('Streaming tests', () => {
|
|
89
|
+
if (!databases.length) {
|
|
90
|
+
it.skip('skipped', () => { });
|
|
91
|
+
}
|
|
92
|
+
const runtimes = new runtimes_1.RuntimeList(databases);
|
|
93
|
+
afterAll(async () => {
|
|
94
|
+
await runtimes.closeAll();
|
|
95
|
+
});
|
|
96
|
+
runtimes.runtimeMap.forEach((runtime, databaseName) => {
|
|
97
|
+
it(`stream nested results to CSV - ${databaseName}`, async () => {
|
|
98
|
+
const stream = runtime
|
|
99
|
+
.loadModel(modelText(databaseName))
|
|
100
|
+
.loadQuery('run: airports -> airports_by_region')
|
|
101
|
+
.runStream();
|
|
102
|
+
const accummulator = new StringAccumulator();
|
|
103
|
+
const csvWriter = new malloy_1.CSVWriter(accummulator);
|
|
104
|
+
await csvWriter.process(stream);
|
|
105
|
+
const expectedCsv = `faa_region,by_state,,,,by_facility_type,,airport_count
|
|
106
|
+
AGL,state,airport_count,by_county,,facility_type,airport_count,4437
|
|
107
|
+
,IL,890,county,airport_count,AIRPORT,3443,
|
|
108
|
+
,,,COOK,51,HELIPORT,826,
|
|
109
|
+
,,,LA SALLE,39,,,
|
|
110
|
+
,OH,749,county,airport_count,,,
|
|
111
|
+
,,,FRANKLIN,27,,,
|
|
112
|
+
,,,CUYAHOGA,27,,,
|
|
113
|
+
ASW,state,airport_count,by_county,,facility_type,airport_count,3268
|
|
114
|
+
,TX,1845,county,airport_count,AIRPORT,2341,
|
|
115
|
+
,,,HARRIS,135,HELIPORT,861,
|
|
116
|
+
,,,TARRANT,63,,,
|
|
117
|
+
,LA,500,county,airport_count,,,
|
|
118
|
+
,,,PLAQUEMINES,31,,,
|
|
119
|
+
,,,VERMILION,29,,,
|
|
120
|
+
`;
|
|
121
|
+
expect(accummulator.accumulatedValue).toBe(expectedCsv);
|
|
122
|
+
});
|
|
123
|
+
it(`stream simple results to CSV - ${databaseName}`, async () => {
|
|
124
|
+
const stream = runtime
|
|
125
|
+
.loadModel(modelText(databaseName))
|
|
126
|
+
.loadQuery('run: airports -> higher_elevation')
|
|
127
|
+
.runStream();
|
|
128
|
+
const accummulator = new StringAccumulator();
|
|
129
|
+
const csvWriter = new malloy_1.CSVWriter(accummulator);
|
|
130
|
+
await csvWriter.process(stream);
|
|
131
|
+
const expectedCsv = `faa_region,airport_count,avg_elevation
|
|
132
|
+
ANM,2102,3284.3910561370126
|
|
133
|
+
AWP,1503,1667.0991350632069
|
|
134
|
+
ACE,1579,1339.0139328689045
|
|
135
|
+
ASW,3268,1007.2873317013464
|
|
136
|
+
AGL,4437,983.4800540906018
|
|
137
|
+
`;
|
|
138
|
+
expect(accummulator.accumulatedValue).toBe(expectedCsv);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
//# sourceMappingURL=streaming.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.spec.js","sourceRoot":"","sources":["../../../src/databases/duckdb/streaming.spec.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;AAEH,+CAA0D;AAC1D,qCAAuD;AACvD,6CAA2C;AAE3C,MAAM,iBAAiB;IAAvB;QACS,qBAAgB,GAAG,EAAE,CAAC;IAS/B,CAAC;IAPC,KAAK,CAAC,IAAY;QAChB,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC;IAChC,CAAC;IAED,KAAK;QACH,OAAO;IACT,CAAC;CACF;AAED,MAAM,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAC;AAE5B,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,IAAA,kCAA2B,EAAC,QAAQ,CAAC,CAAC;AAErE,SAAS,SAAS,CAAC,YAAoB;IACrC,OAAO,uBAAuB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4C1C,CAAC;AACH,CAAC;AAED,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE;QACrB,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;KAC9B;IACD,MAAM,QAAQ,GAAG,IAAI,sBAAW,CAAC,SAAS,CAAC,CAA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AC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2023 Google LLC
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
7
|
+
* a copy of this software and associated documentation files
|
|
8
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
9
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
10
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
11
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
12
|
+
* subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be
|
|
15
|
+
* included in all copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
19
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
20
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
21
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
22
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
23
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
28
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
29
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
30
|
+
}
|
|
31
|
+
Object.defineProperty(o, k2, desc);
|
|
32
|
+
}) : (function(o, m, k, k2) {
|
|
33
|
+
if (k2 === undefined) k2 = k;
|
|
34
|
+
o[k2] = m[k];
|
|
35
|
+
}));
|
|
36
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
37
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
38
|
+
}) : function(o, v) {
|
|
39
|
+
o["default"] = v;
|
|
40
|
+
});
|
|
41
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
42
|
+
if (mod && mod.__esModule) return mod;
|
|
43
|
+
var result = {};
|
|
44
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
45
|
+
__setModuleDefault(result, mod);
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
const malloy = __importStar(require("@malloydata/malloy"));
|
|
51
|
+
const malloy_1 = require("@malloydata/malloy");
|
|
52
|
+
const runtimes_1 = require("../../runtimes");
|
|
53
|
+
const util_1 = require("../../util");
|
|
54
|
+
const [, databases] = (0, util_1.describeIfDatabaseAvailable)(['duckdb', 'postgres']);
|
|
55
|
+
// *** NOTE ***
|
|
56
|
+
// this is a special case (for now): a test that REQUIRES two databases - duckdb AND postgres
|
|
57
|
+
const describe = databases.filter(d => ['postgres', 'duckdb'].includes(d)).length >= 2
|
|
58
|
+
? globalThis.describe
|
|
59
|
+
: globalThis.describe.skip;
|
|
60
|
+
describe('Multi-connection', () => {
|
|
61
|
+
const ddbConnection = new runtimes_1.DuckDBTestConnection('duckdb', 'test/data/duckdb/duckdb_test.db');
|
|
62
|
+
const postgresConnection = new runtimes_1.PostgresTestConnection('postgres');
|
|
63
|
+
const files = new malloy_1.EmptyURLReader();
|
|
64
|
+
const connectionMap = new malloy.FixedConnectionMap(new Map(Object.entries({
|
|
65
|
+
duckdb: ddbConnection,
|
|
66
|
+
postgres: postgresConnection,
|
|
67
|
+
})), 'duckdb');
|
|
68
|
+
const runtime = new malloy.Runtime(files, connectionMap);
|
|
69
|
+
afterAll(async () => {
|
|
70
|
+
await postgresConnection.close();
|
|
71
|
+
});
|
|
72
|
+
const expressionModelText = `
|
|
73
|
+
source: duckdb_state_facts is duckdb.table('malloytest.state_facts') extend {
|
|
74
|
+
measure: state_count is count(state)+2
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
source: postgres_aircraft is postgres.table('malloytest.aircraft') extend {
|
|
78
|
+
measure: aircraft_count is count(tail_num)+4
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
const expressionModel = runtime.loadModel(expressionModelText);
|
|
82
|
+
it('duckdb query', async () => {
|
|
83
|
+
const result = await expressionModel
|
|
84
|
+
.loadQuery(`
|
|
85
|
+
run: duckdb_state_facts-> {
|
|
86
|
+
aggregate: state_count
|
|
87
|
+
}
|
|
88
|
+
`)
|
|
89
|
+
.run();
|
|
90
|
+
// console.log(result.sql);
|
|
91
|
+
expect(result.data.path(0, 'state_count').value).toBe(53);
|
|
92
|
+
});
|
|
93
|
+
it('postgres query', async () => {
|
|
94
|
+
const result = await expressionModel
|
|
95
|
+
.loadQuery(`
|
|
96
|
+
run: postgres_aircraft-> {
|
|
97
|
+
aggregate: aircraft_count
|
|
98
|
+
}
|
|
99
|
+
`)
|
|
100
|
+
.run();
|
|
101
|
+
expect(result.data.path(0, 'aircraft_count').value).toBe(3603);
|
|
102
|
+
});
|
|
103
|
+
it('postgres raw query', async () => {
|
|
104
|
+
const result = await runtime
|
|
105
|
+
.loadQuery(`
|
|
106
|
+
run: postgres.table('malloytest.airports')->{
|
|
107
|
+
group_by:
|
|
108
|
+
version is version!()
|
|
109
|
+
aggregate:
|
|
110
|
+
code_count is count(code)
|
|
111
|
+
airport_count is count()
|
|
112
|
+
}
|
|
113
|
+
`)
|
|
114
|
+
.run();
|
|
115
|
+
expect(result.data.path(0, 'airport_count').value).toBe(19793);
|
|
116
|
+
expect(result.data.path(0, 'version').value).toMatch(/Postgre/);
|
|
117
|
+
expect(result.data.path(0, 'code_count').value).toBe(19793);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
//# sourceMappingURL=multi_connection.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi_connection.spec.js","sourceRoot":"","sources":["../../../src/databases/multi-connection/multi_connection.spec.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B;;;;;;;;;;;;;;;;;;;;;GAqBG;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,8DAA8D;AAE9D,2DAA6C;AAC7C,+CAAkD;AAClD,6CAA4E;AAC5E,qCAAuD;AAEvD,MAAM,CAAC,EAAE,SAAS,CAAC,GAAG,IAAA,kCAA2B,EAAC,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;AAE1E,eAAe;AACf,6FAA6F;AAC7F,MAAM,QAAQ,GACZ,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC;IACnE,CAAC,CAAC,UAAU,CAAC,QAAQ;IACrB,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC;AAE/B,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,MAAM,aAAa,GAAG,IAAI,+BAAoB,CAC5C,QAAQ,EACR,iCAAiC,CAClC,CAAC;IACF,MAAM,kBAAkB,GAAG,IAAI,iCAAsB,CAAC,UAAU,CAAC,CAAC;IAClE,MAAM,KAAK,GAAG,IAAI,uBAAc,EAAE,CAAC;I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;aACA,GAAG,EAAE,CAAC;QACT,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAChE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '../../util/db-jest-matchers';
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
/* eslint-disable no-console */
|
|
26
|
+
const runtimes_1 = require("../../runtimes");
|
|
27
|
+
const util_1 = require("../../util");
|
|
28
|
+
require("../../util/db-jest-matchers");
|
|
29
|
+
const luxon_1 = require("luxon");
|
|
30
|
+
const [describe] = (0, util_1.describeIfDatabaseAvailable)(['postgres']);
|
|
31
|
+
describe('Postgres tests', () => {
|
|
32
|
+
const runtimeList = new runtimes_1.RuntimeList(['postgres']);
|
|
33
|
+
const runtime = runtimeList.runtimeMap.get('postgres');
|
|
34
|
+
if (runtime === undefined) {
|
|
35
|
+
throw new Error("Couldn't build runtime");
|
|
36
|
+
}
|
|
37
|
+
// Idempotently create schema and tables with capital letters to use in tests.
|
|
38
|
+
beforeAll(async () => {
|
|
39
|
+
await runtime.connection.runSQL('create schema if not exists "UpperSchema";');
|
|
40
|
+
await Promise.all([
|
|
41
|
+
runtime.connection.runSQL('create table if not exists "UpperSchema"."UpperSchemaUpperTable" as select 1 as one;'),
|
|
42
|
+
runtime.connection.runSQL('create table if not exists "UpperTablePublic" as select 1 as one;'),
|
|
43
|
+
]);
|
|
44
|
+
});
|
|
45
|
+
afterAll(async () => {
|
|
46
|
+
await runtimeList.closeAll();
|
|
47
|
+
});
|
|
48
|
+
it('run an sql query', async () => {
|
|
49
|
+
await expect('run: postgres.sql("SELECT 1 as n") -> { select: n }').malloyResultMatches(runtime, { n: 1 });
|
|
50
|
+
});
|
|
51
|
+
it('mixed case col names are properly quoted so they retain case in results', async () => {
|
|
52
|
+
await expect(`
|
|
53
|
+
run: postgres.sql('SELECT 1 as "upperLower"') -> { select: upperLower }
|
|
54
|
+
`).malloyResultMatches(runtime, { upperLower: 1 });
|
|
55
|
+
});
|
|
56
|
+
it('fields which are sql keywords are quoted', async () => {
|
|
57
|
+
await expect(`
|
|
58
|
+
run: postgres.sql('SELECT 1 as "select"') -> {
|
|
59
|
+
select:
|
|
60
|
+
select
|
|
61
|
+
create is select + 1
|
|
62
|
+
}
|
|
63
|
+
`).malloyResultMatches(runtime, { select: 1, create: 2 });
|
|
64
|
+
});
|
|
65
|
+
async function oneExists(rt, tn) {
|
|
66
|
+
try {
|
|
67
|
+
const lookForOne = await rt
|
|
68
|
+
.loadQuery(`run: postgres.sql('SELECT one FROM ${tn}')`)
|
|
69
|
+
.run();
|
|
70
|
+
const one = lookForOne.data.path(0, 'one').value;
|
|
71
|
+
return one === 1;
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
it('will quote to properly access mixed case table name', async () => {
|
|
78
|
+
if (await oneExists(runtime, 'public."UpperTablePublic"')) {
|
|
79
|
+
await expect(`
|
|
80
|
+
run: postgres.table('public.UpperTablePublic') -> { select: one }
|
|
81
|
+
`).malloyResultMatches(runtime, { one: 1 });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
it('quote to properly access mixes case schema name', async () => {
|
|
85
|
+
if (await oneExists(runtime, '"UpperSchema"."UpperSchemaUpperTable"')) {
|
|
86
|
+
await expect(`
|
|
87
|
+
run: postgres.table('UpperSchema.UpperSchemaUpperTable') -> { select: one }
|
|
88
|
+
`).malloyResultMatches(runtime, { one: 1 });
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
it('passes unsupported data', async () => {
|
|
92
|
+
const result = await runtime
|
|
93
|
+
.loadQuery('run: postgres.sql("SELECT int4range(10, 20) as ranger")')
|
|
94
|
+
.run();
|
|
95
|
+
expect(result.data.value[0]['ranger']).toBeDefined();
|
|
96
|
+
});
|
|
97
|
+
it('supports varchars with parameters', async () => {
|
|
98
|
+
await expect("run: postgres.sql(\"SELECT 'a'::VARCHAR as abc, 'a3'::VARCHAR(3) as abc3\")").malloyResultMatches(runtime, { abc: 'a', abc3: 'a3' });
|
|
99
|
+
});
|
|
100
|
+
describe('time', () => {
|
|
101
|
+
const zone = 'America/Mexico_City'; // -06:00 no DST
|
|
102
|
+
const zone_2020 = luxon_1.DateTime.fromObject({
|
|
103
|
+
year: 2020,
|
|
104
|
+
month: 2,
|
|
105
|
+
day: 20,
|
|
106
|
+
hour: 0,
|
|
107
|
+
minute: 0,
|
|
108
|
+
second: 0,
|
|
109
|
+
}, {
|
|
110
|
+
zone,
|
|
111
|
+
});
|
|
112
|
+
test('can cast TIMESTAMPTZ to timestamp', async () => {
|
|
113
|
+
await expect(`run: postgres.sql("""
|
|
114
|
+
SELECT TIMESTAMPTZ '2020-02-20 00:00:00 ${zone}' as t_tstz
|
|
115
|
+
""") -> {
|
|
116
|
+
select: mex_220 is t_tstz::timestamp
|
|
117
|
+
}`).malloyResultMatches(runtime, { mex_220: zone_2020.toJSDate() });
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
describe('numbers', () => {
|
|
121
|
+
it.each([
|
|
122
|
+
'SMALLINT',
|
|
123
|
+
'INTEGER',
|
|
124
|
+
'BIGINT',
|
|
125
|
+
'DECIMAL',
|
|
126
|
+
'NUMERIC',
|
|
127
|
+
'REAL',
|
|
128
|
+
'DOUBLE PRECISION',
|
|
129
|
+
])('supports %s', async (sqlType) => {
|
|
130
|
+
const result = await runtime
|
|
131
|
+
.loadQuery(`run: postgres.sql("SELECT 10::${sqlType} as d")`)
|
|
132
|
+
.run();
|
|
133
|
+
const field = result.data.field.allFields[0];
|
|
134
|
+
expect(field.isAtomicField()).toBe(true);
|
|
135
|
+
expect(field.isNumber()).toBe(true);
|
|
136
|
+
expect(result.data.value[0]['d']).toEqual(10);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
//# sourceMappingURL=postgres.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres.spec.js","sourceRoot":"","sources":["../../../src/databases/postgres/postgres.spec.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;AAEH,+BAA+B;AAE/B,6CAA2C;AAE3C,qCAAuD;AACvD,uCAAqC;AACrC,iCAA+B;AAE/B,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAA,kCAA2B,EAAC,CAAC,UAAU,CAAC,CAAC,CAAC;AAE7D,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,MAAM,WAAW,GAAG,IAAI,sBAAW,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACvD,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;KAC3C;IAED,8EAA8E;IAC9E,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,OAAO,CAAC,UAAU,CAAC,MAAM,CAC7B,4CAA4C,CAC7C,CAAC;QACF,MAAM,OAAO,CAAC,GAAG,CAAC;YAChB,OAAO,CAAC,UAAU,CAAC,MAAM,CACvB,sFAAsF,CACvF;YACD,OAAO,CAAC,UAAU,CAAC,MAAM,CACvB,mEAAmE,CACpE;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,KAAK,IAAI,EAAE;QAClB,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kBAAkB,EAAE,KAAK,IAAI,EAAE;QAChC,MAAM,MAAM,CACV,qDAAqD,CACtD,CAAC,mBAAmB,CAAC,OAAO,EAAE,EAAC,CAAC,EAAE,CAAC,EAAC,CAAC,C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