@@ -159,7 +159,7 @@ var (
159159 {Token : TokenChange , Lexer : LexDdlAlterColumn },
160160 {Token : TokenWith , Lexer : LexJsonOrKeyValue , Optional : true },
161161 }
162- // SqlCreate CREATE {SCHEMA | DATABASE | SOURCE | TABLE | VIEW | CONTINUOUSVIEW}
162+ // SqlCreate CREATE {SCHEMA | INDEX | DATABASE | SOURCE | TABLE | VIEW | CONTINUOUSVIEW}
163163 SqlCreate = []* Clause {
164164 {Token : TokenCreate , Lexer : LexCreate },
165165 {Token : TokenEngine , Lexer : LexDdlTableStorage , Optional : true },
@@ -397,6 +397,7 @@ func LexCreate(l *Lexer) StateFn {
397397 /*
398398 CREATE TABLE [IF NOT EXISTS] <identity> [WITH]
399399 CREATE SOURCE [IF NOT EXISTS] <identity> [WITH]
400+ CREATE INDEX [IF NOT EXISTS] <identity> [WITH]
400401 CREATE [OR REPLACE] VIEW <identity> AS <select_statement> [WITH]
401402 */
402403
@@ -413,6 +414,11 @@ func LexCreate(l *Lexer) StateFn {
413414 l .Emit (TokenTable )
414415 l .Push ("LexDdlTable" , LexDdlTable )
415416 return nil
417+ case "index" :
418+ l .ConsumeWord (keyWord )
419+ l .Emit (TokenIndex )
420+ l .Push ("LexDdlIndex" , LexDdlIndex )
421+ return nil
416422 case "source" :
417423 l .ConsumeWord (keyWord )
418424 l .Emit (TokenSource )
@@ -550,6 +556,72 @@ func LexDrop(l *Lexer) StateFn {
550556 return lexNotExists
551557}
552558
559+ // LexDdlIndex data definition language index
560+ func LexDdlIndex (l * Lexer ) StateFn {
561+
562+ /*
563+ CREATE INDEX [IF NOT EXISTS] index_name (column_name,...)
564+ */
565+ l .SkipWhiteSpaces ()
566+ r := l .Next ()
567+
568+ // Cover the logic and grouping
569+ switch r {
570+ case '(' :
571+ // Start of columns
572+ l .Emit (TokenLeftParenthesis )
573+ l .Push ("LexDdlTableColumn" , LexDdlIndex )
574+ return LexColumnNames
575+ case ')' :
576+ // end of columns
577+ l .Emit (TokenRightParenthesis )
578+ return LexDdlTableStorage
579+ case '-' , '/' : // comment?
580+ p := l .Peek ()
581+ if p == '-' {
582+ l .backup ()
583+ l .Push ("LexDdlIndex" , LexDdlIndex )
584+ return LexInlineComment
585+ }
586+ u .Warnf ("unhandled comment non inline " )
587+ case ';' :
588+ l .backup ()
589+ return nil
590+ }
591+
592+ l .backup ()
593+ word := strings .ToLower (l .PeekWord ())
594+ switch word {
595+ case "if" :
596+ l .Push ("LexDdlIndex" , LexDdlIndex )
597+ return lexNotExists
598+ case "with" :
599+ l .ConsumeWord ("with" )
600+ l .Emit (TokenWith )
601+ return LexJsonOrKeyValue
602+ case "on" :
603+ l .ConsumeWord ("on" )
604+ l .Emit (TokenOn )
605+ return LexDdlIndex
606+ }
607+ r = l .Peek ()
608+ if r == ',' {
609+ l .Emit (TokenComma )
610+ l .Push ("LexDdlIndex" , l .clauseState ())
611+ return LexExpressionOrIdentity
612+ }
613+ if l .isNextKeyword (word ) {
614+ return nil
615+ }
616+ // ensure we don't get into a recursive death spiral here?
617+ if len (l .stack ) < 10 {
618+ l .Push ("LexDdlIndex" , LexDdlIndex )
619+ } else {
620+ u .Errorf ("Gracefully refusing to add more LexDdlIndex: " )
621+ }
622+ return LexExpressionOrIdentity
623+ }
624+
553625// LexDdlTable data definition language table
554626func LexDdlTable (l * Lexer ) StateFn {
555627
0 commit comments