@malloydata/db-trino 0.0.140 → 0.0.141-dev240410194001
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/trino_connection.js
CHANGED
|
@@ -240,10 +240,16 @@ class TrinoConnection {
|
|
|
240
240
|
// JSON.stringify(malloyRow[column.name])
|
|
241
241
|
// );
|
|
242
242
|
}
|
|
243
|
-
else if (malloyColumns[i].type === 'number' &&
|
|
243
|
+
else if (malloyColumns[i].type === 'number' &&
|
|
244
|
+
typeof row[i] === 'string') {
|
|
244
245
|
// decimal numbers come back as strings
|
|
245
246
|
malloyRow[column.name] = +row[i];
|
|
246
247
|
}
|
|
248
|
+
else if (malloyColumns[i].type === 'timestamp' &&
|
|
249
|
+
typeof row[i] === 'string') {
|
|
250
|
+
// timestamps come back as strings
|
|
251
|
+
malloyRow[column.name] = new Date(row[i]);
|
|
252
|
+
}
|
|
247
253
|
else {
|
|
248
254
|
malloyRow[column.name] = row[i];
|
|
249
255
|
}
|
|
@@ -460,9 +466,9 @@ class TrinoConnection {
|
|
|
460
466
|
// TODO: Handle time zone type annotation, which is an
|
|
461
467
|
// exception to the types not containing spaces assumption
|
|
462
468
|
innerType = innerType.replace(/ with time zone$/, '');
|
|
463
|
-
let parts = innerType.match(/^(
|
|
469
|
+
let parts = innerType.match(/^(.+?)\s((array\(|row\().*)$/);
|
|
464
470
|
if (parts === null) {
|
|
465
|
-
parts = innerType.match(/^(
|
|
471
|
+
parts = innerType.match(/^(.+)\s(\S+)$/);
|
|
466
472
|
}
|
|
467
473
|
if (parts) {
|
|
468
474
|
const innerName = parts[1];
|
|
@@ -23,12 +23,14 @@
|
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
const _1 = require(".");
|
|
26
|
-
//
|
|
26
|
+
// array(varchar) is array
|
|
27
27
|
const ARRAY_SCHEMA = 'array(integer)';
|
|
28
|
-
//
|
|
28
|
+
// row(...) is inline
|
|
29
29
|
const INLINE_SCHEMA = 'row(a double, b integer, c varchar(60))';
|
|
30
|
-
//
|
|
30
|
+
// array(row(....)) is nested
|
|
31
31
|
const NESTED_SCHEMA = 'array(row(a double, b integer, c varchar(60)))';
|
|
32
|
+
// array(row(..., array(row(....)))) is deeply nested
|
|
33
|
+
const DEEP_SCHEMA = 'array(row(a double, b array(row(c integer, d varchar(60)))))';
|
|
32
34
|
describe('Trino connection', () => {
|
|
33
35
|
let connection;
|
|
34
36
|
beforeAll(() => {
|
|
@@ -112,6 +114,52 @@ describe('Trino connection', () => {
|
|
|
112
114
|
'type': 'string',
|
|
113
115
|
});
|
|
114
116
|
});
|
|
117
|
+
it('parses deep nesting', () => {
|
|
118
|
+
expect(connection.malloyTypeFromTrinoType('test', DEEP_SCHEMA)).toEqual({
|
|
119
|
+
'name': 'test',
|
|
120
|
+
'type': 'struct',
|
|
121
|
+
'dialect': 'trino',
|
|
122
|
+
'structRelationship': {
|
|
123
|
+
'fieldName': 'test',
|
|
124
|
+
'isArray': true,
|
|
125
|
+
'type': 'nested',
|
|
126
|
+
},
|
|
127
|
+
'structSource': {
|
|
128
|
+
'type': 'nested',
|
|
129
|
+
},
|
|
130
|
+
'fields': [
|
|
131
|
+
{
|
|
132
|
+
'name': 'a',
|
|
133
|
+
'numberType': 'float',
|
|
134
|
+
'type': 'number',
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
'name': 'b',
|
|
138
|
+
'type': 'struct',
|
|
139
|
+
'dialect': 'trino',
|
|
140
|
+
'structRelationship': {
|
|
141
|
+
'fieldName': 'b',
|
|
142
|
+
'isArray': true,
|
|
143
|
+
'type': 'nested',
|
|
144
|
+
},
|
|
145
|
+
'structSource': {
|
|
146
|
+
'type': 'nested',
|
|
147
|
+
},
|
|
148
|
+
'fields': [
|
|
149
|
+
{
|
|
150
|
+
'name': 'c',
|
|
151
|
+
'numberType': 'integer',
|
|
152
|
+
'type': 'number',
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
'name': 'd',
|
|
156
|
+
'type': 'string',
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
});
|
|
162
|
+
});
|
|
115
163
|
});
|
|
116
164
|
describe('splitColumns', () => {
|
|
117
165
|
it('handles internal rows', () => {
|