@@ -442,7 +442,14 @@ export class CstToAstConverter {
442442 // --------------------------------------------------------------------- FROM
443443
444444 private fromFromCommand ( ctx : cst . FromCommandContext ) : ast . ESQLCommand < 'from' > {
445- const command = this . createCommand ( 'from' , ctx ) ;
445+ return this . fromFromCompatibleCommand ( 'from' , ctx ) ;
446+ }
447+
448+ private fromFromCompatibleCommand < Name extends string > (
449+ commandName : Name ,
450+ ctx : antlr . ParserRuleContext & Pick < cst . FromCommandContext , 'indexPatternAndMetadataFields' >
451+ ) : ast . ESQLCommand < Name > {
452+ const command = this . createCommand ( commandName , ctx ) ;
446453 const indexPatternCtx = ctx . indexPatternAndMetadataFields ( ) ;
447454 const metadataCtx = indexPatternCtx . metadata ( ) ;
448455 const sources = indexPatternCtx
@@ -477,25 +484,7 @@ export class CstToAstConverter {
477484 // ----------------------------------------------------------------------- TS
478485
479486 private fromTimeseriesCommand ( ctx : cst . TimeSeriesCommandContext ) : ast . ESQLCommand < 'ts' > {
480- const command = this . createCommand ( 'ts' , ctx ) ;
481- const indexPatternCtx = ctx . indexPatternAndMetadataFields ( ) ;
482- const metadataCtx = indexPatternCtx . metadata ( ) ;
483- const sources = indexPatternCtx
484- . getTypedRuleContexts ( cst . IndexPatternContext as any )
485- . map ( ( sourceCtx ) => this . toSource ( sourceCtx ) ) ;
486-
487- command . args . push ( ...sources ) ;
488-
489- if ( metadataCtx && metadataCtx . METADATA ( ) ) {
490- const name = metadataCtx . METADATA ( ) . getText ( ) . toLowerCase ( ) ;
491- const option = this . toOption ( name , metadataCtx ) ;
492- const optionArgs = this . toColumnsFromCommand ( metadataCtx ) ;
493-
494- option . args . push ( ...optionArgs ) ;
495- command . args . push ( option ) ;
496- }
497-
498- return command ;
487+ return this . fromFromCompatibleCommand ( 'ts' , ctx ) ;
499488 }
500489
501490 // --------------------------------------------------------------------- SHOW
@@ -1526,7 +1515,7 @@ export class CstToAstConverter {
15261515 ) : ast . ESQLColumn [ ] {
15271516 const identifiers = this . extractIdentifiers ( ctx ) ;
15281517
1529- return this . makeColumnsOutOfIdentifiers ( identifiers ) ;
1518+ return this . toColumns ( identifiers ) ;
15301519 }
15311520
15321521 private extractIdentifiers (
@@ -1568,7 +1557,7 @@ export class CstToAstConverter {
15681557 return context ;
15691558 }
15701559
1571- private makeColumnsOutOfIdentifiers ( identifiers : antlr . ParserRuleContext [ ] ) : ast . ESQLColumn [ ] {
1560+ private toColumns ( identifiers : antlr . ParserRuleContext [ ] ) : ast . ESQLColumn [ ] {
15721561 const args : ast . ESQLColumn [ ] =
15731562 identifiers
15741563 . filter ( ( child ) => textExistsAndIsValid ( child . getText ( ) ) )
0 commit comments