@malloydata/db-trino 0.0.374 → 0.0.376

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.
@@ -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 malloy_1.TinyParser {
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.next('['); // Expect start of name list
386
+ this.expect('['); // Expect start of name list
386
387
  const fieldNames = [];
387
388
  for (;;) {
388
- const nmToken = this.next('id');
389
+ const nmToken = this.expect('id');
389
390
  fieldNames.push(nmToken.text);
390
- const sep = this.next();
391
- if (sep.type === ',') {
392
- continue;
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.next('arrow', '[');
401
+ this.expect('arrow', '[');
405
402
  for (let nameIndex = 0;; nameIndex += 1) {
406
403
  const name = fieldNames[nameIndex];
407
- this.next('id', ':');
404
+ this.expect('id', ':');
408
405
  const nextType = this.typeDef();
409
406
  fields.push((0, malloy_1.mkFieldDef)(nextType, name));
410
- const sep = this.next();
411
- if (sep.text === ',') {
412
- continue;
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
- const typToken = this.next();
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' && this.next('(')) {
423
+ else if (typToken.text === 'row') {
424
+ this.expect('(');
430
425
  const fields = [];
431
426
  for (;;) {
432
- const name = this.next();
433
- if (name.type !== 'id' && name.type !== 'quoted_name') {
434
- throw this.parseError(`Expected property name, got '${name.type}'`);
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
- const sep = this.next();
439
- if (sep.text === ')') {
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' && this.next('(')) {
444
+ else if (typToken.text === 'array') {
445
+ this.expect('(');
453
446
  const elType = this.typeDef();
454
- this.next(')');
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' && this.next('(')) {
456
+ else if (typToken.text === 'map') {
457
+ this.expect('(');
464
458
  const _keyType = this.typeDef();
465
- this.next(',');
459
+ this.expect(',');
466
460
  const _valType = this.typeDef();
467
- this.next(')');
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.peek().type === '(') {
474
- this.next('(', 'id', ')');
475
- }
467
+ if (this.match('('))
468
+ this.expect('id', ')');
476
469
  }
477
470
  else if (sqlType === 'timestamp') {
478
- if (this.peek().text === '(') {
479
- this.next('(', 'id', ')');
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.next('(', 'id');
490
- if (this.peek().type === ',') {
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.next(')');
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.374",
3
+ "version": "0.0.376",
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.374",
25
+ "@malloydata/malloy": "0.0.376",
26
26
  "@prestodb/presto-js-client": "^1.0.0",
27
27
  "gaxios": "^4.2.0",
28
28
  "luxon": "^3.5.0",