UNPKG

dt-sql-parser

Version:

SQL Parsers for BigData, built with antlr4

1,046 lines (1,045 loc) 1.37 MB
// Generated from dt-sql-parser/src/grammar/spark/SparkSqlParser.g4 by ANTLR 4.13.1 // @ts-nocheck import * as antlr from "antlr4ng"; import { SQLParserBase } from '../SQLParserBase'; export class SparkSqlParser extends SQLParserBase { get grammarFileName() { return "SparkSqlParser.g4"; } get literalNames() { return SparkSqlParser.literalNames; } get symbolicNames() { return SparkSqlParser.symbolicNames; } get ruleNames() { return SparkSqlParser.ruleNames; } get serializedATN() { return SparkSqlParser._serializedATN; } createFailedPredicateException(predicate, message) { return new antlr.FailedPredicateException(this, predicate, message); } constructor(input) { super(input); this.interpreter = new antlr.ParserATNSimulator(this, SparkSqlParser._ATN, SparkSqlParser.decisionsToDFA, new antlr.PredictionContextCache()); } program() { let localContext = new ProgramContext(this.context, this.state); this.enterRule(localContext, 0, SparkSqlParser.RULE_program); let _la; try { this.enterOuterAlt(localContext, 1); { this.state = 353; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); while ((((_la) & ~0x1F) === 0 && ((1 << _la) & 10500) !== 0) || ((((_la - 33)) & ~0x1F) === 0 && ((1 << (_la - 33)) & 67896321) !== 0) || ((((_la - 81)) & ~0x1F) === 0 && ((1 << (_la - 81)) & 100696297) !== 0) || ((((_la - 123)) & ~0x1F) === 0 && ((1 << (_la - 123)) & 16842817) !== 0) || ((((_la - 167)) & ~0x1F) === 0 && ((1 << (_la - 167)) & 2102291) !== 0) || _la === 205 || ((((_la - 238)) & ~0x1F) === 0 && ((1 << (_la - 238)) & 2181171413) !== 0) || ((((_la - 273)) & ~0x1F) === 0 && ((1 << (_la - 273)) & 1048833) !== 0) || ((((_la - 317)) & ~0x1F) === 0 && ((1 << (_la - 317)) & 536949281) !== 0)) { { { this.state = 350; this.singleStatement(); } } this.state = 355; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); } this.state = 356; this.match(SparkSqlParser.EOF); } } catch (re) { if (re instanceof antlr.RecognitionException) { localContext.exception = re; this.errorHandler.reportError(this, re); this.errorHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localContext; } singleStatement() { let localContext = new SingleStatementContext(this.context, this.state); this.enterRule(localContext, 2, SparkSqlParser.RULE_singleStatement); let _la; try { this.enterOuterAlt(localContext, 1); { this.state = 358; this.statement(); this.state = 360; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 1) { { this.state = 359; this.match(SparkSqlParser.SEMICOLON); } } } } catch (re) { if (re instanceof antlr.RecognitionException) { localContext.exception = re; this.errorHandler.reportError(this, re); this.errorHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localContext; } statement() { let localContext = new StatementContext(this.context, this.state); this.enterRule(localContext, 4, SparkSqlParser.RULE_statement); let _la; try { let alternative; this.state = 1319; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 151, this.context)) { case 1: localContext = new StatementDefaultContext(localContext); this.enterOuterAlt(localContext, 1); { this.state = 362; this.query(); } break; case 2: localContext = new DmlStatementContext(localContext); this.enterOuterAlt(localContext, 2); { this.state = 364; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 346) { { this.state = 363; this.ctes(); } } this.state = 366; this.dmlStatementNoWith(); } break; case 3: localContext = new UseNamespaceContext(localContext); this.enterOuterAlt(localContext, 3); { this.state = 367; this.match(SparkSqlParser.KW_USE); this.state = 369; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 3, this.context)) { case 1: { this.state = 368; this.namespace(); } break; } this.state = 371; this.namespaceName(); } break; case 4: localContext = new SetCatalogContext(localContext); this.enterOuterAlt(localContext, 4); { this.state = 372; this.match(SparkSqlParser.KW_SET); this.state = 373; this.match(SparkSqlParser.KW_CATALOG); this.state = 376; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 4, this.context)) { case 1: { this.state = 374; this.identifier(); } break; case 2: { this.state = 375; this.stringLit(); } break; } } break; case 5: localContext = new CreateNamespaceContext(localContext); this.enterOuterAlt(localContext, 5); { this.state = 378; this.match(SparkSqlParser.KW_CREATE); this.state = 379; this.namespace(); this.state = 381; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 5, this.context)) { case 1: { this.state = 380; this.ifNotExists(); } break; } this.state = 383; this.namespaceNameCreate(); this.state = 393; this.errorHandler.sync(this); alternative = this.interpreter.adaptivePredict(this.tokenStream, 7, this.context); while (alternative !== 2 && alternative !== antlr.ATN.INVALID_ALT_NUMBER) { if (alternative === 1) { { this.state = 391; this.errorHandler.sync(this); switch (this.tokenStream.LA(1)) { case SparkSqlParser.KW_COMMENT: { { this.state = 384; this.match(SparkSqlParser.KW_COMMENT); this.state = 385; localContext._comment = this.stringLit(); } } break; case SparkSqlParser.KW_LOCATION: { { this.state = 386; this.match(SparkSqlParser.KW_LOCATION); this.state = 387; this.stringLit(); } } break; case SparkSqlParser.KW_WITH: { { this.state = 388; this.match(SparkSqlParser.KW_WITH); this.state = 389; _la = this.tokenStream.LA(1); if (!(_la === 78 || _la === 229)) { this.errorHandler.recoverInline(this); } else { this.errorHandler.reportMatch(this); this.consume(); } this.state = 390; this.propertyList(); } } break; default: throw new antlr.NoViableAltException(this); } } } this.state = 395; this.errorHandler.sync(this); alternative = this.interpreter.adaptivePredict(this.tokenStream, 7, this.context); } } break; case 6: localContext = new SetNamespacePropertiesContext(localContext); this.enterOuterAlt(localContext, 6); { this.state = 396; this.match(SparkSqlParser.KW_ALTER); this.state = 397; this.namespace(); this.state = 398; this.namespaceName(); this.state = 399; this.match(SparkSqlParser.KW_SET); this.state = 400; _la = this.tokenStream.LA(1); if (!(_la === 78 || _la === 229)) { this.errorHandler.recoverInline(this); } else { this.errorHandler.reportMatch(this); this.consume(); } this.state = 401; this.propertyList(); } break; case 7: localContext = new SetNamespaceLocationContext(localContext); this.enterOuterAlt(localContext, 7); { this.state = 403; this.match(SparkSqlParser.KW_ALTER); this.state = 404; this.namespace(); this.state = 405; this.namespaceName(); this.state = 406; this.match(SparkSqlParser.KW_SET); this.state = 407; this.match(SparkSqlParser.KW_LOCATION); this.state = 408; this.stringLit(); } break; case 8: localContext = new DropNamespaceContext(localContext); this.enterOuterAlt(localContext, 8); { this.state = 410; this.match(SparkSqlParser.KW_DROP); this.state = 411; this.namespace(); this.state = 413; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 8, this.context)) { case 1: { this.state = 412; this.ifExists(); } break; } this.state = 415; this.namespaceName(); this.state = 417; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 34 || _la === 247) { { this.state = 416; _la = this.tokenStream.LA(1); if (!(_la === 34 || _la === 247)) { this.errorHandler.recoverInline(this); } else { this.errorHandler.reportMatch(this); this.consume(); } } } } break; case 9: localContext = new ShowNamespacesContext(localContext); this.enterOuterAlt(localContext, 9); { this.state = 419; this.match(SparkSqlParser.KW_SHOW); this.state = 420; _la = this.tokenStream.LA(1); if (!(_la === 73 || _la === 191 || _la === 262)) { this.errorHandler.recoverInline(this); } else { this.errorHandler.reportMatch(this); this.consume(); } this.state = 423; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 10, this.context)) { case 1: { this.state = 421; _la = this.tokenStream.LA(1); if (!(_la === 123 || _la === 140)) { this.errorHandler.recoverInline(this); } else { this.errorHandler.reportMatch(this); this.consume(); } this.state = 422; this.multipartIdentifier(); } break; } this.state = 429; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 163 || _la === 377 || _la === 378) { { this.state = 426; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 163) { { this.state = 425; this.match(SparkSqlParser.KW_LIKE); } } this.state = 428; localContext._pattern = this.stringLit(); } } } break; case 10: localContext = new CreateTableContext(localContext); this.enterOuterAlt(localContext, 10); { this.state = 431; this.match(SparkSqlParser.KW_CREATE); this.state = 433; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 298) { { this.state = 432; this.match(SparkSqlParser.KW_TEMPORARY); } } this.state = 436; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 109) { { this.state = 435; this.match(SparkSqlParser.KW_EXTERNAL); } } this.state = 438; this.match(SparkSqlParser.KW_TABLE); this.state = 440; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 15, this.context)) { case 1: { this.state = 439; this.ifNotExists(); } break; } this.state = 442; this.tableNameCreate(); this.state = 447; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 16, this.context)) { case 1: { this.state = 443; this.match(SparkSqlParser.LEFT_PAREN); this.state = 444; this.createOrReplaceTableColTypeList(); this.state = 445; this.match(SparkSqlParser.RIGHT_PAREN); } break; } this.state = 450; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 332) { { this.state = 449; this.tableProvider(); } } this.state = 452; this.createTableClauses(); this.state = 457; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 19, this.context)) { case 1: { this.state = 454; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 20) { { this.state = 453; this.match(SparkSqlParser.KW_AS); } } this.state = 456; this.query(); } break; } } break; case 11: localContext = new CreateTableLikeContext(localContext); this.enterOuterAlt(localContext, 11); { this.state = 459; this.match(SparkSqlParser.KW_CREATE); this.state = 460; this.match(SparkSqlParser.KW_TABLE); this.state = 462; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 20, this.context)) { case 1: { this.state = 461; this.ifNotExists(); } break; } this.state = 464; localContext._target = this.tableNameCreate(); this.state = 465; this.match(SparkSqlParser.KW_LIKE); this.state = 466; localContext._source = this.tableName(); this.state = 477; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); while (_la === 162 || _la === 170 || _la === 257 || _la === 283 || _la === 297 || _la === 332) { { this.state = 475; this.errorHandler.sync(this); switch (this.tokenStream.LA(1)) { case SparkSqlParser.KW_USING: { this.state = 467; this.tableProvider(); } break; case SparkSqlParser.KW_ROW: { this.state = 468; this.rowFormat(); } break; case SparkSqlParser.KW_STORED: { this.state = 469; this.createFileFormat(); } break; case SparkSqlParser.KW_LOCATION: { { this.state = 470; this.match(SparkSqlParser.KW_LOCATION); this.state = 471; this.stringLit(); } } break; case SparkSqlParser.KW_TBLPROPERTIES: { { this.state = 472; this.match(SparkSqlParser.KW_TBLPROPERTIES); this.state = 473; localContext._tableProps = this.propertyList(); } } break; case SparkSqlParser.KW_LIFECYCLE: { this.state = 474; this.tableLifecycle(); } break; default: throw new antlr.NoViableAltException(this); } } this.state = 479; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); } } break; case 12: localContext = new ReplaceTableContext(localContext); this.enterOuterAlt(localContext, 12); { this.state = 482; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 59) { { this.state = 480; this.match(SparkSqlParser.KW_CREATE); this.state = 481; this.match(SparkSqlParser.KW_OR); } } this.state = 484; this.match(SparkSqlParser.KW_REPLACE); this.state = 485; this.match(SparkSqlParser.KW_TABLE); this.state = 486; this.tableNameCreate(); this.state = 491; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 24, this.context)) { case 1: { this.state = 487; this.match(SparkSqlParser.LEFT_PAREN); this.state = 488; this.createOrReplaceTableColTypeList(); this.state = 489; this.match(SparkSqlParser.RIGHT_PAREN); } break; } this.state = 494; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 332) { { this.state = 493; this.tableProvider(); } } this.state = 496; this.createTableClauses(); this.state = 501; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 27, this.context)) { case 1: { this.state = 498; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 20) { { this.state = 497; this.match(SparkSqlParser.KW_AS); } } this.state = 500; this.query(); } break; } } break; case 13: localContext = new AnalyzeContext(localContext); this.enterOuterAlt(localContext, 13); { this.state = 503; this.match(SparkSqlParser.KW_ANALYZE); this.state = 504; this.match(SparkSqlParser.KW_TABLE); this.state = 505; this.tableName(); this.state = 507; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 217) { { this.state = 506; this.partitionSpec(); } } this.state = 509; this.match(SparkSqlParser.KW_COMPUTE); this.state = 510; this.match(SparkSqlParser.KW_STATISTICS); this.state = 518; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 29, this.context)) { case 1: { this.state = 511; this.match(SparkSqlParser.KW_NOSCAN); } break; case 2: { this.state = 512; this.match(SparkSqlParser.KW_FOR); this.state = 513; this.match(SparkSqlParser.KW_COLUMNS); this.state = 514; this.columnNameSeq(); } break; case 3: { this.state = 515; this.match(SparkSqlParser.KW_FOR); this.state = 516; this.match(SparkSqlParser.KW_ALL); this.state = 517; this.match(SparkSqlParser.KW_COLUMNS); } break; } } break; case 14: localContext = new AnalyzeTablesContext(localContext); this.enterOuterAlt(localContext, 14); { this.state = 520; this.match(SparkSqlParser.KW_ANALYZE); this.state = 521; this.match(SparkSqlParser.KW_TABLES); this.state = 524; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 123 || _la === 140) { { this.state = 522; _la = this.tokenStream.LA(1); if (!(_la === 123 || _la === 140)) { this.errorHandler.recoverInline(this); } else { this.errorHandler.reportMatch(this); this.consume(); } this.state = 523; this.namespaceName(); } } this.state = 526; this.match(SparkSqlParser.KW_COMPUTE); this.state = 527; this.match(SparkSqlParser.KW_STATISTICS); this.state = 529; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 196) { { this.state = 528; this.match(SparkSqlParser.KW_NOSCAN); } } } break; case 15: localContext = new AlterTableAddColumnContext(localContext); this.enterOuterAlt(localContext, 15); { this.state = 531; this.match(SparkSqlParser.KW_ALTER); this.state = 532; this.match(SparkSqlParser.KW_TABLE); this.state = 533; this.tableName(); this.state = 534; this.match(SparkSqlParser.KW_ADD); this.state = 535; this.match(SparkSqlParser.KW_COLUMN); this.state = 536; this.qualifiedColTypeWithPositionForAdd(); } break; case 16: localContext = new AlterTableAddColumnsContext(localContext); this.enterOuterAlt(localContext, 16); { this.state = 538; this.match(SparkSqlParser.KW_ALTER); this.state = 539; this.match(SparkSqlParser.KW_TABLE); this.state = 540; this.tableName(); this.state = 541; this.match(SparkSqlParser.KW_ADD); this.state = 542; this.match(SparkSqlParser.KW_COLUMNS); this.state = 543; this.match(SparkSqlParser.LEFT_PAREN); this.state = 544; this.qualifiedColTypeWithPositionSeqForAdd(); this.state = 545; this.match(SparkSqlParser.RIGHT_PAREN); } break; case 17: localContext = new RenameTableColumnContext(localContext); this.enterOuterAlt(localContext, 17); { this.state = 547; this.match(SparkSqlParser.KW_ALTER); this.state = 548; this.match(SparkSqlParser.KW_TABLE); this.state = 549; localContext._table = this.tableName(); this.state = 550; this.match(SparkSqlParser.KW_RENAME); this.state = 551; this.match(SparkSqlParser.KW_COLUMN); this.state = 552; this.columnName(); this.state = 553; this.match(SparkSqlParser.KW_TO); this.state = 554; this.columnNameCreate(); } break; case 18: localContext = new AlterTableDropColumnContext(localContext); this.enterOuterAlt(localContext, 18); { this.state = 556; this.match(SparkSqlParser.KW_ALTER); this.state = 557; this.match(SparkSqlParser.KW_TABLE); this.state = 558; this.tableName(); this.state = 559; this.match(SparkSqlParser.KW_DROP); this.state = 560; this.match(SparkSqlParser.KW_COLUMN); this.state = 562; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 32, this.context)) { case 1: { this.state = 561; this.ifExists(); } break; } this.state = 564; this.columnName(); } break; case 19: localContext = new DropTableColumnsContext(localContext); this.enterOuterAlt(localContext, 19); { this.state = 566; this.match(SparkSqlParser.KW_ALTER); this.state = 567; this.match(SparkSqlParser.KW_TABLE); this.state = 568; this.tableName(); this.state = 569; this.match(SparkSqlParser.KW_DROP); this.state = 570; this.match(SparkSqlParser.KW_COLUMNS); this.state = 572; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 137) { { this.state = 571; this.ifExists(); } } this.state = 574; this.match(SparkSqlParser.LEFT_PAREN); this.state = 575; this.columnNameSeq(); this.state = 576; this.match(SparkSqlParser.RIGHT_PAREN); } break; case 20: localContext = new RenameTableContext(localContext); this.enterOuterAlt(localContext, 20); { this.state = 578; this.match(SparkSqlParser.KW_ALTER); this.state = 583; this.errorHandler.sync(this); switch (this.tokenStream.LA(1)) { case SparkSqlParser.KW_TABLE: { this.state = 579; this.match(SparkSqlParser.KW_TABLE); this.state = 580; this.tableName(); } break; case SparkSqlParser.KW_VIEW: { this.state = 581; this.match(SparkSqlParser.KW_VIEW); this.state = 582; this.viewName(); } break; default: throw new antlr.NoViableAltException(this); } this.state = 585; this.match(SparkSqlParser.KW_RENAME); this.state = 586; this.match(SparkSqlParser.KW_TO); this.state = 587; this.multipartIdentifier(); } break; case 21: localContext = new SetTablePropertiesContext(localContext); this.enterOuterAlt(localContext, 21); { this.state = 589; this.match(SparkSqlParser.KW_ALTER); this.state = 594; this.errorHandler.sync(this); switch (this.tokenStream.LA(1)) { case SparkSqlParser.KW_TABLE: { this.state = 590; this.match(SparkSqlParser.KW_TABLE); this.state = 591; this.tableName(); } break; case SparkSqlParser.KW_VIEW: { this.state = 592; this.match(SparkSqlParser.KW_VIEW); this.state = 593; this.viewName(); } break; default: throw new antlr.NoViableAltException(this); } this.state = 596; this.match(SparkSqlParser.KW_SET); this.state = 597; this.match(SparkSqlParser.KW_TBLPROPERTIES); this.state = 598; this.propertyList(); } break; case 22: localContext = new UnsetTablePropertiesContext(localContext); this.enterOuterAlt(localContext, 22); { this.state = 600; this.match(SparkSqlParser.KW_ALTER); this.state = 605; this.errorHandler.sync(this); switch (this.tokenStream.LA(1)) { case SparkSqlParser.KW_TABLE: { this.state = 601; this.match(SparkSqlParser.KW_TABLE); this.state = 602; this.tableName(); } break; case SparkSqlParser.KW_VIEW: { this.state = 603; this.match(SparkSqlParser.KW_VIEW); this.state = 604; this.viewName(); } break; default: throw new antlr.NoViableAltException(this); } this.state = 607; this.match(SparkSqlParser.KW_UNSET); this.state = 608; this.match(SparkSqlParser.KW_TBLPROPERTIES); this.state = 610; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 137) { { this.state = 609; this.ifExists(); } } this.state = 612; this.propertyList(); } break; case 23: localContext = new AlterTableAlterColumnContext(localContext); this.enterOuterAlt(localContext, 23); { this.state = 614; this.match(SparkSqlParser.KW_ALTER); this.state = 615; this.match(SparkSqlParser.KW_TABLE); this.state = 616; localContext._table = this.tableName(); this.state = 617; _la = this.tokenStream.LA(1); if (!(_la === 11 || _la === 39)) { this.errorHandler.recoverInline(this); } else { this.errorHandler.reportMatch(this); this.consume(); } this.state = 619; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 38, this.context)) { case 1: { this.state = 618; this.match(SparkSqlParser.KW_COLUMN); } break; } this.state = 621; localContext._column = this.columnName(); this.state = 623; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 39, this.context)) { case 1: { this.state = 622; this.alterColumnAction(); } break; } } break; case 24: localContext = new HiveChangeColumnContext(localContext); this.enterOuterAlt(localContext, 24); { this.state = 625; this.match(SparkSqlParser.KW_ALTER); this.state = 626; this.match(SparkSqlParser.KW_TABLE); this.state = 627; localContext._table = this.tableName(); this.state = 629; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 217) { { this.state = 628; this.partitionSpec(); } } this.state = 631; this.match(SparkSqlParser.KW_CHANGE); this.state = 633; this.errorHandler.sync(this); switch (this.interpreter.adaptivePredict(this.tokenStream, 41, this.context)) { case 1: { this.state = 632; this.match(SparkSqlParser.KW_COLUMN); } break; } this.state = 635; localContext._colName = this.columnName(); this.state = 636; this.columnType(); this.state = 638; this.errorHandler.sync(this); _la = this.tokenStream.LA(1); if (_la === 9 || _la === 116) { { this.state = 637; this.colPosition(); } } }