@@ -207,6 +207,17 @@ class QuestDBVisitor extends BaseVisitor {
207207 return token ?. image ?? ""
208208 }
209209
210+ /** Return the image of the first token found in a single-alternative CST children record. */
211+ private firstTokenImage ( ctx : CstChildrenRecord ) : string | undefined {
212+ for ( const key of Object . keys ( ctx ) ) {
213+ const tokens = ( ctx as Record < string , IToken [ ] > ) [ key ]
214+ if ( Array . isArray ( tokens ) && tokens . length > 0 && tokens [ 0 ] . image ) {
215+ return tokens [ 0 ] . image
216+ }
217+ }
218+ return undefined
219+ }
220+
210221 // ==========================================================================
211222 // Entry Points
212223 // ==========================================================================
@@ -599,9 +610,7 @@ class QuestDBVisitor extends BaseVisitor {
599610 unnestClause ( ctx : UnnestClauseCstChildren ) : AST . TableRef {
600611 const unnest : AST . UnnestSource = {
601612 type : "unnest" ,
602- args : ctx . unnestArg . map (
603- ( a : CstNode ) => this . visit ( a ) as AST . UnnestArg ,
604- ) ,
613+ args : ctx . unnestArg . map ( ( a : CstNode ) => this . visit ( a ) as AST . UnnestArg ) ,
605614 }
606615 if ( ctx . With && ctx . Ordinality ) {
607616 unnest . withOrdinality = true
@@ -1341,7 +1350,9 @@ class QuestDBVisitor extends BaseVisitor {
13411350 parquetConfig ( ctx : ParquetConfigCstChildren ) : AST . ParquetConfig {
13421351 const result : AST . ParquetConfig = { type : "parquetConfig" }
13431352 if ( ctx . parquetEncoding ) {
1344- result . encoding = ( this . visit ( ctx . parquetEncoding ) as string ) . toUpperCase ( )
1353+ result . encoding = (
1354+ this . visit ( ctx . parquetEncoding ) as string
1355+ ) . toUpperCase ( )
13451356 }
13461357 if ( ctx . parquetCompression ) {
13471358 result . compression = (
@@ -1358,24 +1369,11 @@ class QuestDBVisitor extends BaseVisitor {
13581369 }
13591370
13601371 parquetEncoding ( ctx : ParquetEncodingCstChildren ) : string {
1361- // Find the first token present in the context
1362- for ( const key of Object . keys ( ctx ) ) {
1363- const val = ( ctx as Record < string , unknown > ) [ key ]
1364- if ( Array . isArray ( val ) && val . length > 0 && val [ 0 ] . image ) {
1365- return val [ 0 ] . image . toUpperCase ( )
1366- }
1367- }
1368- return "DEFAULT"
1372+ return this . firstTokenImage ( ctx ) ?. toUpperCase ( ) ?? "DEFAULT"
13691373 }
13701374
13711375 parquetCompression ( ctx : ParquetCompressionCstChildren ) : string {
1372- for ( const key of Object . keys ( ctx ) ) {
1373- const val = ( ctx as Record < string , unknown > ) [ key ]
1374- if ( Array . isArray ( val ) && val . length > 0 && val [ 0 ] . image ) {
1375- return val [ 0 ] . image . toUpperCase ( )
1376- }
1377- }
1378- return ""
1376+ return this . firstTokenImage ( ctx ) ?. toUpperCase ( ) ?? ""
13791377 }
13801378
13811379 castDefinition ( ctx : CastDefinitionCstChildren ) : AST . CastDefinition {
@@ -1945,9 +1943,7 @@ class QuestDBVisitor extends BaseVisitor {
19451943 actionType : "alterColumn" ,
19461944 column,
19471945 alterType : "setParquet" ,
1948- parquetConfig : this . visit (
1949- ctx . parquetConfig ,
1950- ) as AST . ParquetConfig ,
1946+ parquetConfig : this . visit ( ctx . parquetConfig ) as AST . ParquetConfig ,
19511947 } as AST . AlterColumnAction
19521948 }
19531949
0 commit comments