@malloydata/malloy-tests 0.0.123-dev240209165819 → 0.0.123-dev240209222024

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,139 @@
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 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
+ const runtimes = new runtimes_1.RuntimeList(databases);
90
+ afterAll(async () => {
91
+ await runtimes.closeAll();
92
+ });
93
+ runtimes.runtimeMap.forEach((runtime, databaseName) => {
94
+ it(`stream nested results to CSV - ${databaseName}`, async () => {
95
+ const stream = runtime
96
+ .loadModel(modelText(databaseName))
97
+ .loadQuery('run: airports -> airports_by_region')
98
+ .runStream();
99
+ const accummulator = new StringAccumulator();
100
+ const csvWriter = new malloy_1.CSVWriter(accummulator);
101
+ await csvWriter.process(stream);
102
+ const expectedCsv = `faa_region,by_state,,,,by_facility_type,,airport_count
103
+ AGL,state,airport_count,by_county,,facility_type,airport_count,4437
104
+ ,IL,890,county,airport_count,AIRPORT,3443,
105
+ ,,,COOK,51,HELIPORT,826,
106
+ ,,,LA SALLE,39,,,
107
+ ,OH,749,county,airport_count,,,
108
+ ,,,FRANKLIN,27,,,
109
+ ,,,CUYAHOGA,27,,,
110
+ ASW,state,airport_count,by_county,,facility_type,airport_count,3268
111
+ ,TX,1845,county,airport_count,AIRPORT,2341,
112
+ ,,,HARRIS,135,HELIPORT,861,
113
+ ,,,TARRANT,63,,,
114
+ ,LA,500,county,airport_count,,,
115
+ ,,,PLAQUEMINES,31,,,
116
+ ,,,VERMILION,29,,,
117
+ `;
118
+ expect(accummulator.accumulatedValue).toBe(expectedCsv);
119
+ });
120
+ it(`stream simple results to CSV - ${databaseName}`, async () => {
121
+ const stream = runtime
122
+ .loadModel(modelText(databaseName))
123
+ .loadQuery('run: airports -> higher_elevation')
124
+ .runStream();
125
+ const accummulator = new StringAccumulator();
126
+ const csvWriter = new malloy_1.CSVWriter(accummulator);
127
+ await csvWriter.process(stream);
128
+ const expectedCsv = `faa_region,airport_count,avg_elevation
129
+ ANM,2102,3284.3910561370126
130
+ AWP,1503,1667.0991350632069
131
+ ACE,1579,1339.0139328689045
132
+ ASW,3268,1007.2873317013464
133
+ AGL,4437,983.4800540906018
134
+ `;
135
+ expect(accummulator.accumulatedValue).toBe(expectedCsv);
136
+ });
137
+ });
138
+ });
139
+ //# 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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AAS,GAAG,IAAI,kBAAS,CAAC,YAAY,CAAC,CAAC;YAC9C,MAAM,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAChC,MAAM,WAAW,GAAG;;;;;;CAMzB,CAAC;YACI,MAAM,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -18,11 +18,11 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@jest/globals": "^29.4.3",
21
- "@malloydata/db-bigquery": "^0.0.123-dev240209165819",
22
- "@malloydata/db-duckdb": "^0.0.123-dev240209165819",
23
- "@malloydata/db-postgres": "^0.0.123-dev240209165819",
24
- "@malloydata/malloy": "^0.0.123-dev240209165819",
25
- "@malloydata/render": "^0.0.123-dev240209165819",
21
+ "@malloydata/db-bigquery": "^0.0.123-dev240209222024",
22
+ "@malloydata/db-duckdb": "^0.0.123-dev240209222024",
23
+ "@malloydata/db-postgres": "^0.0.123-dev240209222024",
24
+ "@malloydata/malloy": "^0.0.123-dev240209222024",
25
+ "@malloydata/render": "^0.0.123-dev240209222024",
26
26
  "jsdom": "^22.1.0",
27
27
  "luxon": "^2.4.0",
28
28
  "madge": "^6.0.0"
@@ -31,5 +31,5 @@
31
31
  "@types/jsdom": "^21.1.1",
32
32
  "@types/luxon": "^2.4.0"
33
33
  },
34
- "version": "0.0.123-dev240209165819"
34
+ "version": "0.0.123-dev240209222024"
35
35
  }
@@ -0,0 +1,145 @@
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 {WriteStream, CSVWriter} from '@malloydata/malloy';
25
+ import {describeIfDatabaseAvailable} from '../../util';
26
+ import {RuntimeList} from '../../runtimes';
27
+
28
+ class StringAccumulator implements WriteStream {
29
+ public accumulatedValue = '';
30
+
31
+ write(text: string) {
32
+ this.accumulatedValue += text;
33
+ }
34
+
35
+ close() {
36
+ return;
37
+ }
38
+ }
39
+
40
+ const runtimes = ['duckdb'];
41
+
42
+ const [_describe, databases] = describeIfDatabaseAvailable(runtimes);
43
+
44
+ function modelText(databaseName: string) {
45
+ return `source: airports is ${databaseName}.table('test/data/duckdb/airports.parquet') extend {
46
+ rename: facility_type is fac_type
47
+
48
+ measure: airport_count is count()
49
+ measure: avg_elevation is avg(elevation)
50
+
51
+ view: higher_elevation is {
52
+ group_by: faa_region
53
+ aggregate: airport_count, avg_elevation
54
+ order_by: avg_elevation desc
55
+ limit: 5
56
+ }
57
+
58
+ view: by_county is {
59
+ where: county != null
60
+ group_by: county
61
+ aggregate: airport_count
62
+ limit: 2
63
+ order_by: airport_count desc, county desc
64
+ }
65
+
66
+ view: by_state is {
67
+ where: state != null
68
+ group_by: state
69
+ aggregate: airport_count
70
+ limit: 2
71
+ nest: by_county
72
+ }
73
+
74
+ view: by_facility_type is {
75
+ group_by: facility_type
76
+ aggregate:
77
+ airport_count
78
+ limit: 2
79
+ }
80
+
81
+ view: airports_by_region is {
82
+ group_by: faa_region
83
+ nest:
84
+ by_state
85
+ by_facility_type
86
+ limit: 2
87
+ aggregate: airport_count
88
+ }
89
+ }`;
90
+ }
91
+
92
+ describe('Streaming tests', () => {
93
+ const runtimes = new RuntimeList(databases);
94
+
95
+ afterAll(async () => {
96
+ await runtimes.closeAll();
97
+ });
98
+
99
+ runtimes.runtimeMap.forEach((runtime, databaseName) => {
100
+ it(`stream nested results to CSV - ${databaseName}`, async () => {
101
+ const stream = runtime
102
+ .loadModel(modelText(databaseName))
103
+ .loadQuery('run: airports -> airports_by_region')
104
+ .runStream();
105
+ const accummulator = new StringAccumulator();
106
+ const csvWriter = new CSVWriter(accummulator);
107
+ await csvWriter.process(stream);
108
+ const expectedCsv = `faa_region,by_state,,,,by_facility_type,,airport_count
109
+ AGL,state,airport_count,by_county,,facility_type,airport_count,4437
110
+ ,IL,890,county,airport_count,AIRPORT,3443,
111
+ ,,,COOK,51,HELIPORT,826,
112
+ ,,,LA SALLE,39,,,
113
+ ,OH,749,county,airport_count,,,
114
+ ,,,FRANKLIN,27,,,
115
+ ,,,CUYAHOGA,27,,,
116
+ ASW,state,airport_count,by_county,,facility_type,airport_count,3268
117
+ ,TX,1845,county,airport_count,AIRPORT,2341,
118
+ ,,,HARRIS,135,HELIPORT,861,
119
+ ,,,TARRANT,63,,,
120
+ ,LA,500,county,airport_count,,,
121
+ ,,,PLAQUEMINES,31,,,
122
+ ,,,VERMILION,29,,,
123
+ `;
124
+ expect(accummulator.accumulatedValue).toBe(expectedCsv);
125
+ });
126
+
127
+ it(`stream simple results to CSV - ${databaseName}`, async () => {
128
+ const stream = runtime
129
+ .loadModel(modelText(databaseName))
130
+ .loadQuery('run: airports -> higher_elevation')
131
+ .runStream();
132
+ const accummulator = new StringAccumulator();
133
+ const csvWriter = new CSVWriter(accummulator);
134
+ await csvWriter.process(stream);
135
+ const expectedCsv = `faa_region,airport_count,avg_elevation
136
+ ANM,2102,3284.3910561370126
137
+ AWP,1503,1667.0991350632069
138
+ ACE,1579,1339.0139328689045
139
+ ASW,3268,1007.2873317013464
140
+ AGL,4437,983.4800540906018
141
+ `;
142
+ expect(accummulator.accumulatedValue).toBe(expectedCsv);
143
+ });
144
+ });
145
+ });