@malloydata/db-trino 0.0.220-dev241204170603 → 0.0.220-dev241205182408
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Connection, ConnectionConfig, MalloyQueryData, PersistSQLResults, QueryData, QueryOptionsReader, QueryRunStats, RunSQLOptions, TrinoDialect, StructDef, TableSourceDef, SQLSourceDef, AtomicTypeDef } from '@malloydata/malloy';
|
|
1
|
+
import { Connection, ConnectionConfig, MalloyQueryData, PersistSQLResults, QueryData, QueryOptionsReader, QueryRunStats, RunSQLOptions, TrinoDialect, StructDef, TableSourceDef, SQLSourceDef, AtomicTypeDef, FieldDef } from '@malloydata/malloy';
|
|
2
2
|
import { BaseConnection } from '@malloydata/malloy/connection';
|
|
3
3
|
export interface TrinoManagerOptions {
|
|
4
4
|
credentials?: {
|
|
@@ -42,8 +42,8 @@ export declare abstract class TrinoPrestoConnection extends BaseConnection imple
|
|
|
42
42
|
get supportsNesting(): boolean;
|
|
43
43
|
manifestTemporaryTable(_sqlCommand: string): Promise<string>;
|
|
44
44
|
unpackArray(data: unknown): unknown[];
|
|
45
|
-
convertRow(
|
|
46
|
-
convertNest(
|
|
45
|
+
convertRow(fields: FieldDef[], rawRow: unknown): {};
|
|
46
|
+
convertNest(fields: FieldDef[], _data: unknown): unknown[];
|
|
47
47
|
runSQL(sqlCommand: string, options?: RunSQLOptions, _rowIndex?: number): Promise<MalloyQueryData>;
|
|
48
48
|
private resultRow;
|
|
49
49
|
runSQLBlockAndFetchResultSchema(_sqlBlock: SQLSourceDef, _options?: RunSQLOptions): Promise<{
|
package/dist/trino_connection.js
CHANGED
|
@@ -146,20 +146,21 @@ class TrinoPrestoConnection extends connection_1.BaseConnection {
|
|
|
146
146
|
unpackArray(data) {
|
|
147
147
|
return data;
|
|
148
148
|
}
|
|
149
|
-
convertRow(
|
|
149
|
+
convertRow(fields, rawRow) {
|
|
150
150
|
var _a;
|
|
151
151
|
const retRow = {};
|
|
152
152
|
const row = this.unpackArray(rawRow);
|
|
153
|
-
for (let i = 0; i <
|
|
154
|
-
const field =
|
|
153
|
+
for (let i = 0; i < fields.length; i++) {
|
|
154
|
+
const field = fields[i];
|
|
155
155
|
if (field.type === 'record') {
|
|
156
|
-
retRow[field.name] = this.convertRow(field, row[i]);
|
|
156
|
+
retRow[field.name] = this.convertRow(field.fields, row[i]);
|
|
157
157
|
}
|
|
158
158
|
else if ((0, malloy_1.isRepeatedRecord)(field)) {
|
|
159
|
-
retRow[field.name] = this.convertNest(field, row[i]);
|
|
159
|
+
retRow[field.name] = this.convertNest(field.fields, row[i]);
|
|
160
160
|
}
|
|
161
161
|
else if (field.type === 'array') {
|
|
162
|
-
|
|
162
|
+
// mtoy todo don't understand this line actually
|
|
163
|
+
retRow[field.name] = this.convertNest(field.fields.slice(0, 1), row[i]);
|
|
163
164
|
}
|
|
164
165
|
else {
|
|
165
166
|
retRow[field.name] = (_a = row[i]) !== null && _a !== void 0 ? _a : null;
|
|
@@ -168,12 +169,12 @@ class TrinoPrestoConnection extends connection_1.BaseConnection {
|
|
|
168
169
|
//console.log(retRow);
|
|
169
170
|
return retRow;
|
|
170
171
|
}
|
|
171
|
-
convertNest(
|
|
172
|
+
convertNest(fields, _data) {
|
|
172
173
|
const data = this.unpackArray(_data);
|
|
173
174
|
const ret = [];
|
|
174
175
|
const rows = (data === null || data === undefined ? [] : data);
|
|
175
176
|
for (const row of rows) {
|
|
176
|
-
ret.push(this.convertRow(
|
|
177
|
+
ret.push(this.convertRow(fields, row));
|
|
177
178
|
}
|
|
178
179
|
return ret;
|
|
179
180
|
}
|
|
@@ -202,13 +203,13 @@ class TrinoPrestoConnection extends connection_1.BaseConnection {
|
|
|
202
203
|
}
|
|
203
204
|
resultRow(colSchema, rawRow) {
|
|
204
205
|
if (colSchema.type === 'record') {
|
|
205
|
-
return this.convertRow(colSchema, rawRow);
|
|
206
|
+
return this.convertRow(colSchema.fields, rawRow);
|
|
206
207
|
}
|
|
207
|
-
else if (
|
|
208
|
+
else if ((0, malloy_1.isRepeatedRecordType)(colSchema)) {
|
|
209
|
+
return this.convertNest(colSchema.fields, rawRow);
|
|
210
|
+
}
|
|
211
|
+
else if ((0, malloy_1.isScalarArrayType)(colSchema)) {
|
|
208
212
|
const elType = colSchema.elementTypeDef;
|
|
209
|
-
if (elType.type === 'record_element') {
|
|
210
|
-
return this.convertNest(colSchema, rawRow);
|
|
211
|
-
}
|
|
212
213
|
let theArray = this.unpackArray(rawRow);
|
|
213
214
|
if (elType.type === 'array') {
|
|
214
215
|
theArray = theArray.map(el => this.resultRow(elType, el));
|
|
@@ -295,10 +296,7 @@ class TrinoPrestoConnection extends connection_1.BaseConnection {
|
|
|
295
296
|
if (innerType.type === 'record') {
|
|
296
297
|
const complexStruct = {
|
|
297
298
|
type: 'array',
|
|
298
|
-
name,
|
|
299
299
|
elementTypeDef: { type: 'record_element' },
|
|
300
|
-
dialect: this.dialectName,
|
|
301
|
-
join: 'many',
|
|
302
300
|
fields: innerType.fields,
|
|
303
301
|
};
|
|
304
302
|
return complexStruct;
|
|
@@ -306,11 +304,7 @@ class TrinoPrestoConnection extends connection_1.BaseConnection {
|
|
|
306
304
|
else {
|
|
307
305
|
const arrayStruct = {
|
|
308
306
|
type: 'array',
|
|
309
|
-
name,
|
|
310
307
|
elementTypeDef: innerType,
|
|
311
|
-
dialect: this.dialectName,
|
|
312
|
-
join: 'many',
|
|
313
|
-
fields: (0, malloy_1.arrayEachFields)(innerType),
|
|
314
308
|
};
|
|
315
309
|
return arrayStruct;
|
|
316
310
|
}
|
|
@@ -322,9 +316,6 @@ class TrinoPrestoConnection extends connection_1.BaseConnection {
|
|
|
322
316
|
const innerTypes = this.splitColumns(structMatch[3]);
|
|
323
317
|
const recordType = {
|
|
324
318
|
type: 'record',
|
|
325
|
-
name,
|
|
326
|
-
dialect: this.dialectName,
|
|
327
|
-
join: 'one',
|
|
328
319
|
fields: [],
|
|
329
320
|
};
|
|
330
321
|
for (let innerType of innerTypes) {
|
|
@@ -340,7 +331,7 @@ class TrinoPrestoConnection extends connection_1.BaseConnection {
|
|
|
340
331
|
const innerName = parts[1].replace(/^"(.+(?="$))"$/, '$1');
|
|
341
332
|
const innerTrinoType = parts[2];
|
|
342
333
|
const innerMalloyType = this.malloyTypeFromTrinoType(innerName, innerTrinoType);
|
|
343
|
-
recordType.fields.push(
|
|
334
|
+
recordType.fields.push((0, malloy_1.mkFieldDef)(innerMalloyType, innerName, this.dialectName));
|
|
344
335
|
}
|
|
345
336
|
}
|
|
346
337
|
return recordType;
|
|
@@ -353,7 +344,7 @@ class TrinoPrestoConnection extends connection_1.BaseConnection {
|
|
|
353
344
|
const type = row[4] || row[1];
|
|
354
345
|
const malloyType = this.malloyTypeFromTrinoType(name, type);
|
|
355
346
|
// console.log('>', row, '\n<', malloyType);
|
|
356
|
-
structDef.fields.push(
|
|
347
|
+
structDef.fields.push((0, malloy_1.mkFieldDef)(malloyType, name, this.dialectName));
|
|
357
348
|
}
|
|
358
349
|
}
|
|
359
350
|
async loadSchemaForSqlBlock(sqlBlock, structDef, element) {
|
|
@@ -489,7 +480,7 @@ class PrestoExplainParser extends malloy_1.TinyParser {
|
|
|
489
480
|
const name = fieldNames[nameIndex];
|
|
490
481
|
this.next('id', ':');
|
|
491
482
|
const nextType = this.typeDef();
|
|
492
|
-
fields.push(
|
|
483
|
+
fields.push((0, malloy_1.mkFieldDef)(nextType, name, this.dialect.name));
|
|
493
484
|
const sep = this.next();
|
|
494
485
|
if (sep.text === ',') {
|
|
495
486
|
continue;
|
|
@@ -514,7 +505,7 @@ class PrestoExplainParser extends malloy_1.TinyParser {
|
|
|
514
505
|
for (;;) {
|
|
515
506
|
const name = this.next('quoted_name');
|
|
516
507
|
const getDef = this.typeDef();
|
|
517
|
-
fields.push(
|
|
508
|
+
fields.push((0, malloy_1.mkFieldDef)(getDef, name.text, this.dialect.name));
|
|
518
509
|
const sep = this.next();
|
|
519
510
|
if (sep.text === ')') {
|
|
520
511
|
break;
|
|
@@ -525,9 +516,6 @@ class PrestoExplainParser extends malloy_1.TinyParser {
|
|
|
525
516
|
}
|
|
526
517
|
const def = {
|
|
527
518
|
type: 'record',
|
|
528
|
-
name: '',
|
|
529
|
-
join: 'one',
|
|
530
|
-
dialect: this.dialect.name,
|
|
531
519
|
fields,
|
|
532
520
|
};
|
|
533
521
|
return def;
|
|
@@ -535,15 +523,13 @@ class PrestoExplainParser extends malloy_1.TinyParser {
|
|
|
535
523
|
else if (typToken.text === 'array' && this.next('(')) {
|
|
536
524
|
const elType = this.typeDef();
|
|
537
525
|
this.next(')');
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
};
|
|
546
|
-
return def;
|
|
526
|
+
return elType.type === 'record'
|
|
527
|
+
? {
|
|
528
|
+
type: 'array',
|
|
529
|
+
elementTypeDef: { type: 'record_element' },
|
|
530
|
+
fields: elType.fields,
|
|
531
|
+
}
|
|
532
|
+
: { type: 'array', elementTypeDef: elType };
|
|
547
533
|
}
|
|
548
534
|
else if (typToken.type === 'id') {
|
|
549
535
|
const sqlType = typToken.text;
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const malloy_1 = require("@malloydata/malloy");
|
|
26
25
|
const _1 = require(".");
|
|
27
26
|
// array(varchar) is array
|
|
28
27
|
const ARRAY_SCHEMA = 'array(integer)';
|
|
@@ -51,30 +50,20 @@ describe('Trino connection', () => {
|
|
|
51
50
|
describe('schema parser', () => {
|
|
52
51
|
it('parses arrays', () => {
|
|
53
52
|
expect(connection.malloyTypeFromTrinoType('test', ARRAY_SCHEMA)).toEqual({
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
'dialect': 'trino',
|
|
57
|
-
'elementTypeDef': intType,
|
|
58
|
-
'join': 'many',
|
|
59
|
-
'fields': (0, malloy_1.arrayEachFields)(intType),
|
|
53
|
+
type: 'array',
|
|
54
|
+
elementTypeDef: intType,
|
|
60
55
|
});
|
|
61
56
|
});
|
|
62
57
|
it('parses inline', () => {
|
|
63
58
|
expect(connection.malloyTypeFromTrinoType('test', INLINE_SCHEMA)).toEqual({
|
|
64
|
-
'name': 'test',
|
|
65
59
|
'type': 'record',
|
|
66
|
-
'dialect': 'trino',
|
|
67
|
-
'join': 'one',
|
|
68
60
|
'fields': recordSchema,
|
|
69
61
|
});
|
|
70
62
|
});
|
|
71
63
|
it('parses nested', () => {
|
|
72
64
|
expect(connection.malloyTypeFromTrinoType('test', NESTED_SCHEMA)).toEqual({
|
|
73
|
-
'name': 'test',
|
|
74
65
|
'type': 'array',
|
|
75
66
|
'elementTypeDef': { type: 'record_element' },
|
|
76
|
-
'dialect': 'trino',
|
|
77
|
-
'join': 'many',
|
|
78
67
|
'fields': recordSchema,
|
|
79
68
|
});
|
|
80
69
|
});
|
|
@@ -83,11 +72,8 @@ describe('Trino connection', () => {
|
|
|
83
72
|
});
|
|
84
73
|
it('parses deep nesting', () => {
|
|
85
74
|
expect(connection.malloyTypeFromTrinoType('test', DEEP_SCHEMA)).toEqual({
|
|
86
|
-
'name': 'test',
|
|
87
75
|
'type': 'array',
|
|
88
|
-
'dialect': 'trino',
|
|
89
76
|
'elementTypeDef': { type: 'record_element' },
|
|
90
|
-
'join': 'many',
|
|
91
77
|
'fields': [
|
|
92
78
|
{ 'name': 'a', ...doubleType },
|
|
93
79
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/db-trino",
|
|
3
|
-
"version": "0.0.220-
|
|
3
|
+
"version": "0.0.220-dev241205182408",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"prepublishOnly": "npm run build"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@malloydata/malloy": "^0.0.220-
|
|
25
|
+
"@malloydata/malloy": "^0.0.220-dev241205182408",
|
|
26
26
|
"@prestodb/presto-js-client": "^1.0.0",
|
|
27
27
|
"gaxios": "^4.2.0",
|
|
28
28
|
"trino-client": "^0.2.2"
|