@@ -44,7 +44,6 @@ import {
44
44
FieldDef ,
45
45
TinyParser ,
46
46
isRepeatedRecord ,
47
- AtomicFieldDef ,
48
47
} from '@malloydata/malloy' ;
49
48
50
49
import { BaseConnection } from '@malloydata/malloy/connection' ;
@@ -260,7 +259,7 @@ export abstract class TrinoPrestoConnection
260
259
const columns = r . columns ;
261
260
262
261
const malloyColumns = columns . map ( c =>
263
- this . malloyTypeFromTrinoType ( c . name , c . type )
262
+ mkFieldDef ( this . malloyTypeFromTrinoType ( c . type ) , c . name )
264
263
) ;
265
264
266
265
const malloyRows : QueryDataRow [ ] = [ ] ;
@@ -348,24 +347,16 @@ export abstract class TrinoPrestoConnection
348
347
//while (!(await result.next()).done);
349
348
}
350
349
351
- public malloyTypeFromTrinoType (
352
- name : string ,
353
- trinoType : string
354
- ) : AtomicFieldDef {
355
- const atomicType = new TrinoPrestoSchemaParser (
356
- trinoType ,
357
- this . dialect
358
- ) . typeDef ( ) ;
359
- const def = mkFieldDef ( atomicType , name ) ;
360
- return def ;
350
+ public malloyTypeFromTrinoType ( trinoType : string ) : AtomicTypeDef {
351
+ const typeParse = new TrinoPrestoSchemaParser ( trinoType , this . dialect ) ;
352
+ return typeParse . typeDef ( ) ;
361
353
}
362
354
363
355
structDefFromSchema ( rows : string [ ] [ ] , structDef : StructDef ) : void {
364
356
for ( const row of rows ) {
365
357
const name = row [ 0 ] ;
366
358
const type = row [ 4 ] || row [ 1 ] ;
367
- const malloyType = this . malloyTypeFromTrinoType ( name , type ) ;
368
- // console.log('>', row, '\n<', malloyType);
359
+ const malloyType = mkFieldDef ( this . malloyTypeFromTrinoType ( type ) , name ) ;
369
360
structDef . fields . push ( mkFieldDef ( malloyType , name ) ) ;
370
361
}
371
362
}
@@ -611,7 +602,10 @@ class TrinoPrestoSchemaParser extends TinyParser {
611
602
} else if ( typToken . text === 'row' && this . next ( '(' ) ) {
612
603
const fields : FieldDef [ ] = [ ] ;
613
604
for ( ; ; ) {
614
- const name = this . next ( 'quoted_name' ) ;
605
+ const name = this . next ( ) ;
606
+ if ( name . type !== 'id' && name . type !== 'quoted_name' ) {
607
+ throw this . parseError ( 'Expected property name' ) ;
608
+ }
615
609
const getDef = this . typeDef ( ) ;
616
610
fields . push ( mkFieldDef ( getDef , name . text ) ) ;
617
611
const sep = this . next ( ) ;
@@ -637,10 +631,10 @@ class TrinoPrestoSchemaParser extends TinyParser {
637
631
fields : elType . fields ,
638
632
}
639
633
: { type : 'array' , elementTypeDef : elType } ;
640
- } else if ( typToken . type === 'id' ) {
634
+ } else if ( typToken . type === 'id' || typToken . type === 'quoted_name' ) {
641
635
const sqlType = typToken . text ;
642
- const def = this . dialect . sqlTypeToMalloyType ( sqlType ) ;
643
- if ( def === undefined ) {
636
+ const typeDef = this . dialect . sqlTypeToMalloyType ( sqlType ) ;
637
+ if ( typeDef === undefined ) {
644
638
throw this . parseError ( `Can't parse presto type ${ sqlType } ` ) ;
645
639
}
646
640
if ( sqlType === 'varchar' ) {
@@ -650,7 +644,7 @@ class TrinoPrestoSchemaParser extends TinyParser {
650
644
} else if ( sqlType === 'timezone' && this . peek ( ) . text === 'with' ) {
651
645
this . nextText ( 'with' , 'time' , 'zone' ) ;
652
646
}
653
- return def ;
647
+ return typeDef ;
654
648
}
655
649
throw this . parseError (
656
650
`'${ typToken . text } ' unexpected while looking for a type`
0 commit comments