@malloydata/db-trino 0.0.375 → 0.0.377
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 +36 -46
- package/package.json +2 -2
package/dist/trino_connection.js
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.TrinoConnection = exports.PrestoConnection = exports.TrinoPrestoConnection = void 0;
|
|
26
26
|
const malloy_1 = require("@malloydata/malloy");
|
|
27
|
+
const internal_1 = require("@malloydata/malloy/internal");
|
|
27
28
|
const connection_1 = require("@malloydata/malloy/connection");
|
|
28
29
|
const presto_js_client_1 = require("@prestodb/presto-js-client");
|
|
29
30
|
const crypto_1 = require("crypto");
|
|
@@ -368,7 +369,7 @@ exports.TrinoConnection = TrinoConnection;
|
|
|
368
369
|
* ARRAY_TYPE: ARRAY '(' TYPE ')'
|
|
369
370
|
* REC_TYPE: REC '(' "name" TYPE (, "name" TYPE)* ')'
|
|
370
371
|
*/
|
|
371
|
-
class TrinoPrestoSchemaParser extends
|
|
372
|
+
class TrinoPrestoSchemaParser extends internal_1.TinyParser {
|
|
372
373
|
constructor(input, dialect) {
|
|
373
374
|
super(input, {
|
|
374
375
|
space: /^\s+/,
|
|
@@ -382,39 +383,31 @@ class TrinoPrestoSchemaParser extends malloy_1.TinyParser {
|
|
|
382
383
|
}
|
|
383
384
|
fieldNameList() {
|
|
384
385
|
this.skipTo(']'); // Skip to end of plan
|
|
385
|
-
this.
|
|
386
|
+
this.expect('['); // Expect start of name list
|
|
386
387
|
const fieldNames = [];
|
|
387
388
|
for (;;) {
|
|
388
|
-
const nmToken = this.
|
|
389
|
+
const nmToken = this.expect('id');
|
|
389
390
|
fieldNames.push(nmToken.text);
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
if (sep.type !== ']') {
|
|
395
|
-
throw this.parseError(`Unexpected '${sep.text}' while getting field name list`);
|
|
391
|
+
if (!this.match(',')) {
|
|
392
|
+
this.expect(']');
|
|
393
|
+
break;
|
|
396
394
|
}
|
|
397
|
-
break;
|
|
398
395
|
}
|
|
399
396
|
return fieldNames;
|
|
400
397
|
}
|
|
401
398
|
parseQueryPlan() {
|
|
402
399
|
const fieldNames = this.fieldNameList();
|
|
403
400
|
const fields = [];
|
|
404
|
-
this.
|
|
401
|
+
this.expect('arrow', '[');
|
|
405
402
|
for (let nameIndex = 0;; nameIndex += 1) {
|
|
406
403
|
const name = fieldNames[nameIndex];
|
|
407
|
-
this.
|
|
404
|
+
this.expect('id', ':');
|
|
408
405
|
const nextType = this.typeDef();
|
|
409
406
|
fields.push((0, malloy_1.mkFieldDef)(nextType, name));
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}
|
|
414
|
-
if (sep.text !== ']') {
|
|
415
|
-
throw this.parseError(`Unexpected '${sep.text}' between field types`);
|
|
407
|
+
if (!this.match(',')) {
|
|
408
|
+
this.expect(']');
|
|
409
|
+
break;
|
|
416
410
|
}
|
|
417
|
-
break;
|
|
418
411
|
}
|
|
419
412
|
if (fields.length !== fieldNames.length) {
|
|
420
413
|
throw new Error(`Presto schema error mismatched ${fields.length} types and ${fieldNames.length} fields`);
|
|
@@ -422,26 +415,25 @@ class TrinoPrestoSchemaParser extends malloy_1.TinyParser {
|
|
|
422
415
|
return fields;
|
|
423
416
|
}
|
|
424
417
|
typeDef() {
|
|
425
|
-
|
|
418
|
+
var _a;
|
|
419
|
+
const typToken = this.read();
|
|
426
420
|
if (typToken.type === 'eof') {
|
|
427
421
|
throw this.parseError('Unexpected EOF parsing type, expected a type name');
|
|
428
422
|
}
|
|
429
|
-
else if (typToken.text === 'row'
|
|
423
|
+
else if (typToken.text === 'row') {
|
|
424
|
+
this.expect('(');
|
|
430
425
|
const fields = [];
|
|
431
426
|
for (;;) {
|
|
432
|
-
const name = this.
|
|
433
|
-
if (name
|
|
434
|
-
throw this.parseError(
|
|
427
|
+
const name = (_a = this.match('id')) !== null && _a !== void 0 ? _a : this.match('quoted_name');
|
|
428
|
+
if (!name) {
|
|
429
|
+
throw this.parseError('Expected property name');
|
|
435
430
|
}
|
|
436
431
|
const getDef = this.typeDef();
|
|
437
432
|
fields.push((0, malloy_1.mkFieldDef)(getDef, name.text));
|
|
438
|
-
|
|
439
|
-
|
|
433
|
+
if (!this.match(',')) {
|
|
434
|
+
this.expect(')');
|
|
440
435
|
break;
|
|
441
436
|
}
|
|
442
|
-
if (sep.text === ',') {
|
|
443
|
-
continue;
|
|
444
|
-
}
|
|
445
437
|
}
|
|
446
438
|
const def = {
|
|
447
439
|
type: 'record',
|
|
@@ -449,9 +441,10 @@ class TrinoPrestoSchemaParser extends malloy_1.TinyParser {
|
|
|
449
441
|
};
|
|
450
442
|
return def;
|
|
451
443
|
}
|
|
452
|
-
else if (typToken.text === 'array'
|
|
444
|
+
else if (typToken.text === 'array') {
|
|
445
|
+
this.expect('(');
|
|
453
446
|
const elType = this.typeDef();
|
|
454
|
-
this.
|
|
447
|
+
this.expect(')');
|
|
455
448
|
return elType.type === 'record'
|
|
456
449
|
? {
|
|
457
450
|
type: 'array',
|
|
@@ -460,41 +453,38 @@ class TrinoPrestoSchemaParser extends malloy_1.TinyParser {
|
|
|
460
453
|
}
|
|
461
454
|
: { type: 'array', elementTypeDef: elType };
|
|
462
455
|
}
|
|
463
|
-
else if (typToken.text === 'map'
|
|
456
|
+
else if (typToken.text === 'map') {
|
|
457
|
+
this.expect('(');
|
|
464
458
|
const _keyType = this.typeDef();
|
|
465
|
-
this.
|
|
459
|
+
this.expect(',');
|
|
466
460
|
const _valType = this.typeDef();
|
|
467
|
-
this.
|
|
461
|
+
this.expect(')');
|
|
468
462
|
return { type: 'sql native' };
|
|
469
463
|
}
|
|
470
464
|
else if (typToken.type === 'id') {
|
|
471
465
|
const sqlType = typToken.text.toLowerCase();
|
|
472
466
|
if (sqlType === 'varchar') {
|
|
473
|
-
if (this.
|
|
474
|
-
this.
|
|
475
|
-
}
|
|
467
|
+
if (this.match('('))
|
|
468
|
+
this.expect('id', ')');
|
|
476
469
|
}
|
|
477
470
|
else if (sqlType === 'timestamp') {
|
|
478
|
-
if (this.
|
|
479
|
-
this.
|
|
480
|
-
|
|
481
|
-
if (this.peek().text === 'with') {
|
|
482
|
-
this.nextText('with', 'time', 'zone');
|
|
471
|
+
if (this.match('('))
|
|
472
|
+
this.expect('id', ')');
|
|
473
|
+
if (this.matchText('with', 'time', 'zone')) {
|
|
483
474
|
return { type: 'timestamptz' };
|
|
484
475
|
}
|
|
485
476
|
return { type: 'timestamp' };
|
|
486
477
|
}
|
|
487
478
|
const typeDef = this.dialect.sqlTypeToMalloyType(sqlType);
|
|
488
479
|
if (typeDef.type === 'number' && sqlType === 'decimal') {
|
|
489
|
-
this.
|
|
490
|
-
if (this.
|
|
491
|
-
this.next(',', 'id');
|
|
480
|
+
this.expect('(', 'id');
|
|
481
|
+
if (this.match(',', 'id')) {
|
|
492
482
|
typeDef.numberType = 'float';
|
|
493
483
|
}
|
|
494
484
|
else {
|
|
495
485
|
typeDef.numberType = 'integer';
|
|
496
486
|
}
|
|
497
|
-
this.
|
|
487
|
+
this.expect(')');
|
|
498
488
|
}
|
|
499
489
|
if (typeDef === undefined) {
|
|
500
490
|
throw this.parseError(`Can't parse presto type ${sqlType}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/db-trino",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.377",
|
|
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.
|
|
25
|
+
"@malloydata/malloy": "0.0.377",
|
|
26
26
|
"@prestodb/presto-js-client": "^1.0.0",
|
|
27
27
|
"gaxios": "^4.2.0",
|
|
28
28
|
"luxon": "^3.5.0",
|