PageRenderTime 145ms CodeModel.GetById 37ms app.highlight 96ms RepoModel.GetById 1ms app.codeStats 1ms

/tags/release-0.0.0-rc0/hive/external/ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g

#
text | 2309 lines | 2046 code | 263 blank | 0 comment | 0 complexity | bf8dc2eefb76e53ba4689ce71cab660b MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/**
   2   Licensed to the Apache Software Foundation (ASF) under one or more
   3   contributor license agreements.  See the NOTICE file distributed with
   4   this work for additional information regarding copyright ownership.
   5   The ASF licenses this file to You under the Apache License, Version 2.0
   6   (the "License"); you may not use this file except in compliance with
   7   the License.  You may obtain a copy of the License at
   8
   9       http://www.apache.org/licenses/LICENSE-2.0
  10
  11   Unless required by applicable law or agreed to in writing, software
  12   distributed under the License is distributed on an "AS IS" BASIS,
  13   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14   See the License for the specific language governing permissions and
  15   limitations under the License.
  16*/
  17grammar Hive;
  18
  19options
  20{
  21output=AST;
  22ASTLabelType=CommonTree;
  23backtrack=false;
  24k=3;
  25}
  26
  27tokens {
  28TOK_INSERT;
  29TOK_QUERY;
  30TOK_SELECT;
  31TOK_SELECTDI;
  32TOK_SELEXPR;
  33TOK_FROM;
  34TOK_TAB;
  35TOK_PARTSPEC;
  36TOK_PARTVAL;
  37TOK_DIR;
  38TOK_LOCAL_DIR;
  39TOK_TABREF;
  40TOK_SUBQUERY;
  41TOK_DESTINATION;
  42TOK_ALLCOLREF;
  43TOK_TABLE_OR_COL;
  44TOK_FUNCTION;
  45TOK_FUNCTIONDI;
  46TOK_FUNCTIONSTAR;
  47TOK_WHERE;
  48TOK_OP_EQ;
  49TOK_OP_NE;
  50TOK_OP_LE;
  51TOK_OP_LT;
  52TOK_OP_GE;
  53TOK_OP_GT;
  54TOK_OP_DIV;
  55TOK_OP_ADD;
  56TOK_OP_SUB;
  57TOK_OP_MUL;
  58TOK_OP_MOD;
  59TOK_OP_BITAND;
  60TOK_OP_BITNOT;
  61TOK_OP_BITOR;
  62TOK_OP_BITXOR;
  63TOK_OP_AND;
  64TOK_OP_OR;
  65TOK_OP_NOT;
  66TOK_OP_LIKE;
  67TOK_TRUE;
  68TOK_FALSE;
  69TOK_TRANSFORM;
  70TOK_SERDE;
  71TOK_SERDENAME;
  72TOK_SERDEPROPS;
  73TOK_EXPLIST;
  74TOK_ALIASLIST;
  75TOK_GROUPBY;
  76TOK_HAVING;
  77TOK_ORDERBY;
  78TOK_CLUSTERBY;
  79TOK_DISTRIBUTEBY;
  80TOK_SORTBY;
  81TOK_UNION;
  82TOK_JOIN;
  83TOK_LEFTOUTERJOIN;
  84TOK_RIGHTOUTERJOIN;
  85TOK_FULLOUTERJOIN;
  86TOK_UNIQUEJOIN;
  87TOK_LOAD;
  88TOK_NULL;
  89TOK_ISNULL;
  90TOK_ISNOTNULL;
  91TOK_TINYINT;
  92TOK_SMALLINT;
  93TOK_INT;
  94TOK_BIGINT;
  95TOK_BOOLEAN;
  96TOK_FLOAT;
  97TOK_DOUBLE;
  98TOK_DATE;
  99TOK_DATETIME;
 100TOK_TIMESTAMP;
 101TOK_STRING;
 102TOK_LIST;
 103TOK_STRUCT;
 104TOK_MAP;
 105TOK_UNIONTYPE;
 106TOK_COLTYPELIST;
 107TOK_CREATEDATABASE;
 108TOK_CREATETABLE;
 109TOK_CREATEINDEX;
 110TOK_CREATEINDEX_INDEXTBLNAME;
 111TOK_DEFERRED_REBUILDINDEX;
 112TOK_DROPINDEX;
 113TOK_LIKETABLE;
 114TOK_DESCTABLE;
 115TOK_DESCFUNCTION;
 116TOK_ALTERTABLE_PARTITION;
 117TOK_ALTERTABLE_RENAME;
 118TOK_ALTERTABLE_ADDCOLS;
 119TOK_ALTERTABLE_RENAMECOL;
 120TOK_ALTERTABLE_REPLACECOLS;
 121TOK_ALTERTABLE_ADDPARTS;
 122TOK_ALTERTABLE_DROPPARTS;
 123TOK_ALTERTABLE_ALTERPARTS_PROTECTMODE;
 124TOK_ALTERTABLE_TOUCH;
 125TOK_ALTERTABLE_ARCHIVE;
 126TOK_ALTERTABLE_UNARCHIVE;
 127TOK_ALTERTABLE_SERDEPROPERTIES;
 128TOK_ALTERTABLE_SERIALIZER;
 129TOK_TABLE_PARTITION;
 130TOK_ALTERTABLE_FILEFORMAT;
 131TOK_ALTERTABLE_LOCATION;
 132TOK_ALTERTABLE_PROPERTIES;
 133TOK_ALTERTABLE_CHANGECOL_AFTER_POSITION;
 134TOK_ALTERINDEX_REBUILD;
 135TOK_ALTERINDEX_PROPERTIES;
 136TOK_MSCK;
 137TOK_SHOWDATABASES;
 138TOK_SHOWTABLES;
 139TOK_SHOWFUNCTIONS;
 140TOK_SHOWPARTITIONS;
 141TOK_SHOW_TABLESTATUS;
 142TOK_SHOWLOCKS;
 143TOK_LOCKTABLE;
 144TOK_UNLOCKTABLE;
 145TOK_SWITCHDATABASE;
 146TOK_DROPDATABASE;
 147TOK_DROPTABLE;
 148TOK_DATABASECOMMENT;
 149TOK_TABCOLLIST;
 150TOK_TABCOL;
 151TOK_TABLECOMMENT;
 152TOK_TABLEPARTCOLS;
 153TOK_TABLEBUCKETS;
 154TOK_TABLEROWFORMAT;
 155TOK_TABLEROWFORMATFIELD;
 156TOK_TABLEROWFORMATCOLLITEMS;
 157TOK_TABLEROWFORMATMAPKEYS;
 158TOK_TABLEROWFORMATLINES;
 159TOK_TBLSEQUENCEFILE;
 160TOK_TBLTEXTFILE;
 161TOK_TBLRCFILE;
 162TOK_TABLEFILEFORMAT;
 163TOK_FILEFORMAT_GENERIC;
 164TOK_OFFLINE;
 165TOK_ENABLE;
 166TOK_DISABLE;
 167TOK_READONLY;
 168TOK_NO_DROP;
 169TOK_STORAGEHANDLER;
 170TOK_ALTERTABLE_CLUSTER_SORT;
 171TOK_TABCOLNAME;
 172TOK_TABLELOCATION;
 173TOK_PARTITIONLOCATION;
 174TOK_TABLESAMPLE;
 175TOK_TMP_FILE;
 176TOK_TABSORTCOLNAMEASC;
 177TOK_TABSORTCOLNAMEDESC;
 178TOK_CHARSETLITERAL;
 179TOK_CREATEFUNCTION;
 180TOK_DROPFUNCTION;
 181TOK_CREATEVIEW;
 182TOK_DROPVIEW;
 183TOK_ALTERVIEW_PROPERTIES;
 184TOK_EXPLAIN;
 185TOK_TABLESERIALIZER;
 186TOK_TABLEPROPERTIES;
 187TOK_TABLEPROPLIST;
 188TOK_INDEXPROPERTIES;
 189TOK_INDEXPROPLIST;
 190TOK_TABTYPE;
 191TOK_LIMIT;
 192TOK_TABLEPROPERTY;
 193TOK_IFEXISTS;
 194TOK_IFNOTEXISTS;
 195TOK_HINTLIST;
 196TOK_HINT;
 197TOK_MAPJOIN;
 198TOK_STREAMTABLE;
 199TOK_HOLD_DDLTIME;
 200TOK_HINTARGLIST;
 201TOK_USERSCRIPTCOLNAMES;
 202TOK_USERSCRIPTCOLSCHEMA;
 203TOK_RECORDREADER;
 204TOK_RECORDWRITER;
 205TOK_LEFTSEMIJOIN;
 206TOK_LATERAL_VIEW;
 207TOK_TABALIAS;
 208TOK_ANALYZE;
 209TOK_CREATEROLE;
 210TOK_DROPROLE;
 211TOK_GRANT;
 212TOK_REVOKE;
 213TOK_SHOW_GRANT;
 214TOK_PRIVILEGE_LIST;
 215TOK_PRIVILEGE;
 216TOK_PRINCIPAL_NAME;
 217TOK_USER;
 218TOK_GROUP;
 219TOK_ROLE;
 220TOK_GRANT_WITH_OPTION;
 221TOK_PRIV_ALL;
 222TOK_PRIV_ALTER_METADATA;
 223TOK_PRIV_ALTER_DATA;
 224TOK_PRIV_DROP;
 225TOK_PRIV_INDEX;
 226TOK_PRIV_LOCK;
 227TOK_PRIV_SELECT;
 228TOK_PRIV_SHOW_DATABASE;
 229TOK_PRIV_CREATE;
 230TOK_PRIV_OBJECT;
 231TOK_PRIV_OBJECT_COL;
 232TOK_GRANT_ROLE;
 233TOK_REVOKE_ROLE;
 234TOK_SHOW_ROLE_GRANT;
 235TOK_SHOWINDEXES;
 236TOK_INDEXCOMMENT;
 237TOK_DESCDATABASE;
 238TOK_DATABASEPROPERTIES;
 239TOK_DBPROPLIST;
 240TOK_ALTERDATABASE_PROPERTIES;
 241TOK_TABNAME;
 242TOK_TABSRC;
 243}
 244
 245
 246// Package headers
 247@header {
 248package org.apache.hadoop.hive.ql.parse;
 249}
 250@lexer::header {package org.apache.hadoop.hive.ql.parse;}
 251
 252
 253@members {
 254  Stack msgs = new Stack<String>();
 255}
 256
 257@rulecatch {
 258catch (RecognitionException e) {
 259 reportError(e);
 260  throw e;
 261}
 262}
 263
 264// starting rule
 265statement
 266	: explainStatement EOF
 267	| execStatement EOF
 268	;
 269
 270explainStatement
 271@init { msgs.push("explain statement"); }
 272@after { msgs.pop(); }
 273	: KW_EXPLAIN (isExtended=KW_EXTENDED)? execStatement -> ^(TOK_EXPLAIN execStatement $isExtended?)
 274	;
 275
 276execStatement
 277@init { msgs.push("statement"); }
 278@after { msgs.pop(); }
 279    : queryStatementExpression
 280    | loadStatement
 281    | ddlStatement
 282    ;
 283
 284loadStatement
 285@init { msgs.push("load statement"); }
 286@after { msgs.pop(); }
 287    : KW_LOAD KW_DATA (islocal=KW_LOCAL)? KW_INPATH (path=StringLiteral) (isoverwrite=KW_OVERWRITE)? KW_INTO KW_TABLE (tab=tableOrPartition)
 288    -> ^(TOK_LOAD $path $tab $islocal? $isoverwrite?)
 289    ;
 290
 291ddlStatement
 292@init { msgs.push("ddl statement"); }
 293@after { msgs.pop(); }
 294    : createDatabaseStatement
 295    | switchDatabaseStatement
 296    | dropDatabaseStatement
 297    | createTableStatement
 298    | dropTableStatement
 299    | alterStatement
 300    | descStatement
 301    | showStatement
 302    | metastoreCheck
 303    | createViewStatement
 304    | dropViewStatement
 305    | createFunctionStatement
 306    | createIndexStatement
 307    | dropIndexStatement
 308    | dropFunctionStatement
 309    | analyzeStatement
 310    | lockStatement
 311    | unlockStatement
 312    | createRoleStatement
 313    | dropRoleStatement
 314    | grantPrivileges
 315    | revokePrivileges
 316    | showGrants
 317    | showRoleGrants
 318    | grantRole
 319    | revokeRole
 320    ;
 321
 322ifExists
 323@init { msgs.push("if exists clause"); }
 324@after { msgs.pop(); }
 325    : KW_IF KW_EXISTS
 326    -> ^(TOK_IFEXISTS)
 327    ;
 328
 329ifNotExists
 330@init { msgs.push("if not exists clause"); }
 331@after { msgs.pop(); }
 332    : KW_IF KW_NOT KW_EXISTS
 333    -> ^(TOK_IFNOTEXISTS)
 334    ;
 335
 336
 337createDatabaseStatement
 338@init { msgs.push("create database statement"); }
 339@after { msgs.pop(); }
 340    : KW_CREATE (KW_DATABASE|KW_SCHEMA)
 341        ifNotExists?
 342        name=Identifier
 343        databaseComment?
 344        (KW_WITH KW_DBPROPERTIES dbprops=dbProperties)?
 345    -> ^(TOK_CREATEDATABASE $name ifNotExists? databaseComment? $dbprops?)
 346    ;
 347
 348dbProperties
 349@init { msgs.push("dbproperties"); }
 350@after { msgs.pop(); }
 351    :
 352      LPAREN dbPropertiesList RPAREN -> ^(TOK_DATABASEPROPERTIES dbPropertiesList)
 353    ;
 354
 355dbPropertiesList
 356@init { msgs.push("database properties list"); }
 357@after { msgs.pop(); }
 358    :
 359      keyValueProperty (COMMA keyValueProperty)* -> ^(TOK_DBPROPLIST keyValueProperty+)
 360    ;
 361
 362 
 363switchDatabaseStatement
 364@init { msgs.push("switch database statement"); }
 365@after { msgs.pop(); }
 366    : KW_USE Identifier
 367    -> ^(TOK_SWITCHDATABASE Identifier)
 368    ;
 369
 370dropDatabaseStatement
 371@init { msgs.push("drop database statement"); }
 372@after { msgs.pop(); }
 373    : KW_DROP (KW_DATABASE|KW_SCHEMA) ifExists? Identifier
 374    -> ^(TOK_DROPDATABASE Identifier ifExists?)
 375    ;
 376
 377databaseComment
 378@init { msgs.push("database's comment"); }
 379@after { msgs.pop(); }
 380    : KW_COMMENT comment=StringLiteral
 381    -> ^(TOK_DATABASECOMMENT $comment)
 382    ;
 383
 384createTableStatement
 385@init { msgs.push("create table statement"); }
 386@after { msgs.pop(); }
 387    : KW_CREATE (ext=KW_EXTERNAL)? KW_TABLE ifNotExists? name=tableName
 388      (  like=KW_LIKE likeName=tableName
 389         tableLocation?
 390       | (LPAREN columnNameTypeList RPAREN)?
 391         tableComment?
 392         tablePartition?
 393         tableBuckets?
 394         tableRowFormat?
 395         tableFileFormat?
 396         tableLocation?
 397         tablePropertiesPrefixed?
 398         (KW_AS selectStatement)?
 399      )
 400    -> ^(TOK_CREATETABLE $name $ext? ifNotExists?
 401         ^(TOK_LIKETABLE $likeName?)
 402         columnNameTypeList?
 403         tableComment?
 404         tablePartition?
 405         tableBuckets?
 406         tableRowFormat?
 407         tableFileFormat?
 408         tableLocation?
 409         tablePropertiesPrefixed?
 410         selectStatement?
 411        )
 412    ;
 413
 414createIndexStatement
 415@init { msgs.push("create index statement");}
 416@after {msgs.pop();}
 417    : KW_CREATE KW_INDEX indexName=Identifier
 418      KW_ON KW_TABLE tab=tableName LPAREN indexedCols=columnNameList RPAREN
 419      KW_AS typeName=StringLiteral
 420      autoRebuild?
 421      indexPropertiesPrefixed?
 422      indexTblName?
 423      tableRowFormat?
 424      tableFileFormat?
 425      tableLocation?
 426      tablePropertiesPrefixed?
 427      indexComment?
 428    ->^(TOK_CREATEINDEX $indexName $typeName $tab $indexedCols 
 429        autoRebuild?
 430        indexPropertiesPrefixed?
 431        indexTblName?
 432        tableRowFormat?
 433        tableFileFormat?
 434        tableLocation?
 435        tablePropertiesPrefixed?
 436        indexComment?)
 437    ;
 438
 439indexComment
 440@init { msgs.push("comment on an index");}
 441@after {msgs.pop();}
 442        :
 443                KW_COMMENT comment=StringLiteral  -> ^(TOK_INDEXCOMMENT $comment)
 444        ;
 445
 446autoRebuild
 447@init { msgs.push("auto rebuild index");}
 448@after {msgs.pop();}
 449    : KW_WITH KW_DEFERRED KW_REBUILD
 450    ->^(TOK_DEFERRED_REBUILDINDEX)
 451    ;
 452
 453indexTblName
 454@init { msgs.push("index table name");}
 455@after {msgs.pop();}
 456    : KW_IN KW_TABLE indexTbl=tableName
 457    ->^(TOK_CREATEINDEX_INDEXTBLNAME $indexTbl)
 458    ;
 459
 460indexPropertiesPrefixed
 461@init { msgs.push("table properties with prefix"); }
 462@after { msgs.pop(); }
 463    :
 464        KW_IDXPROPERTIES! indexProperties
 465    ;
 466
 467indexProperties
 468@init { msgs.push("index properties"); }
 469@after { msgs.pop(); }
 470    :
 471      LPAREN indexPropertiesList RPAREN -> ^(TOK_INDEXPROPERTIES indexPropertiesList)
 472    ;
 473
 474indexPropertiesList
 475@init { msgs.push("index properties list"); }
 476@after { msgs.pop(); }
 477    :
 478      keyValueProperty (COMMA keyValueProperty)* -> ^(TOK_INDEXPROPLIST keyValueProperty+)
 479    ;
 480
 481dropIndexStatement
 482@init { msgs.push("drop index statement");}
 483@after {msgs.pop();}
 484    : KW_DROP KW_INDEX ifExists? indexName=Identifier KW_ON tab=tableName
 485    ->^(TOK_DROPINDEX $indexName $tab ifExists?)
 486    ;
 487
 488dropTableStatement
 489@init { msgs.push("drop statement"); }
 490@after { msgs.pop(); }
 491    : KW_DROP KW_TABLE ifExists? tableName -> ^(TOK_DROPTABLE tableName ifExists?)
 492    ;
 493
 494alterStatement
 495@init { msgs.push("alter statement"); }
 496@after { msgs.pop(); }
 497    : KW_ALTER!
 498        (
 499            KW_TABLE! alterTableStatementSuffix
 500        |
 501            KW_VIEW! alterViewStatementSuffix
 502        |
 503            KW_INDEX! alterIndexStatementSuffix
 504        |
 505            KW_DATABASE! alterDatabaseStatementSuffix
 506        )
 507    ;
 508
 509alterTableStatementSuffix
 510@init { msgs.push("alter table statement"); }
 511@after { msgs.pop(); }
 512    : alterStatementSuffixRename
 513    | alterStatementSuffixAddCol
 514    | alterStatementSuffixRenameCol
 515    | alterStatementSuffixDropPartitions
 516    | alterStatementSuffixAddPartitions
 517    | alterStatementSuffixTouch
 518    | alterStatementSuffixArchive
 519    | alterStatementSuffixUnArchive
 520    | alterStatementSuffixProperties
 521    | alterStatementSuffixSerdeProperties
 522    | alterTblPartitionStatement
 523    | alterStatementSuffixClusterbySortby
 524    ;
 525
 526alterViewStatementSuffix
 527@init { msgs.push("alter view statement"); }
 528@after { msgs.pop(); }
 529    : alterViewSuffixProperties
 530    ;
 531
 532alterIndexStatementSuffix
 533@init { msgs.push("alter index statement"); }
 534@after { msgs.pop(); }
 535    : indexName=Identifier
 536      (KW_ON tableNameId=Identifier)
 537      partitionSpec?
 538    (
 539      KW_REBUILD
 540      ->^(TOK_ALTERINDEX_REBUILD $tableNameId $indexName partitionSpec?)
 541    |
 542      KW_SET KW_IDXPROPERTIES
 543      indexProperties
 544      ->^(TOK_ALTERINDEX_PROPERTIES $tableNameId $indexName indexProperties)
 545    )
 546    ;
 547
 548alterDatabaseStatementSuffix
 549@init { msgs.push("alter database statement"); }
 550@after { msgs.pop(); }
 551    : alterDatabaseSuffixProperties
 552    ;
 553    
 554alterDatabaseSuffixProperties
 555@init { msgs.push("alter database properties statement"); }
 556@after { msgs.pop(); }
 557    : name=Identifier KW_SET KW_DBPROPERTIES dbProperties
 558    -> ^(TOK_ALTERDATABASE_PROPERTIES $name dbProperties)
 559    ;
 560
 561alterStatementSuffixRename
 562@init { msgs.push("rename statement"); }
 563@after { msgs.pop(); }
 564    : oldName=Identifier KW_RENAME KW_TO newName=Identifier
 565    -> ^(TOK_ALTERTABLE_RENAME $oldName $newName)
 566    ;
 567
 568alterStatementSuffixAddCol
 569@init { msgs.push("add column statement"); }
 570@after { msgs.pop(); }
 571    : Identifier (add=KW_ADD | replace=KW_REPLACE) KW_COLUMNS LPAREN columnNameTypeList RPAREN
 572    -> {$add != null}? ^(TOK_ALTERTABLE_ADDCOLS Identifier columnNameTypeList)
 573    ->                 ^(TOK_ALTERTABLE_REPLACECOLS Identifier columnNameTypeList)
 574    ;
 575
 576alterStatementSuffixRenameCol
 577@init { msgs.push("rename column name"); }
 578@after { msgs.pop(); }
 579    : Identifier KW_CHANGE KW_COLUMN? oldName=Identifier newName=Identifier colType (KW_COMMENT comment=StringLiteral)? alterStatementChangeColPosition?
 580    ->^(TOK_ALTERTABLE_RENAMECOL Identifier $oldName $newName colType $comment? alterStatementChangeColPosition?)
 581    ;
 582
 583alterStatementChangeColPosition
 584    : first=KW_FIRST|KW_AFTER afterCol=Identifier
 585    ->{$first != null}? ^(TOK_ALTERTABLE_CHANGECOL_AFTER_POSITION )
 586    -> ^(TOK_ALTERTABLE_CHANGECOL_AFTER_POSITION $afterCol)
 587    ;
 588
 589alterStatementSuffixAddPartitions
 590@init { msgs.push("add partition statement"); }
 591@after { msgs.pop(); }
 592    : Identifier KW_ADD ifNotExists? partitionSpec partitionLocation? (partitionSpec partitionLocation?)*
 593    -> ^(TOK_ALTERTABLE_ADDPARTS Identifier ifNotExists? (partitionSpec partitionLocation?)+)
 594    ;
 595
 596alterStatementSuffixTouch
 597@init { msgs.push("touch statement"); }
 598@after { msgs.pop(); }
 599    : Identifier KW_TOUCH (partitionSpec)*
 600    -> ^(TOK_ALTERTABLE_TOUCH Identifier (partitionSpec)*)
 601    ;
 602
 603alterStatementSuffixArchive
 604@init { msgs.push("archive statement"); }
 605@after { msgs.pop(); }
 606    : Identifier KW_ARCHIVE (partitionSpec)*
 607    -> ^(TOK_ALTERTABLE_ARCHIVE Identifier (partitionSpec)*)
 608    ;
 609
 610alterStatementSuffixUnArchive
 611@init { msgs.push("unarchive statement"); }
 612@after { msgs.pop(); }
 613    : Identifier KW_UNARCHIVE (partitionSpec)*
 614    -> ^(TOK_ALTERTABLE_UNARCHIVE Identifier (partitionSpec)*)
 615    ;
 616
 617partitionLocation
 618@init { msgs.push("partition location"); }
 619@after { msgs.pop(); }
 620    :
 621      KW_LOCATION locn=StringLiteral -> ^(TOK_PARTITIONLOCATION $locn)
 622    ;
 623
 624alterStatementSuffixDropPartitions
 625@init { msgs.push("drop partition statement"); }
 626@after { msgs.pop(); }
 627    : Identifier KW_DROP ifExists? partitionSpec (COMMA partitionSpec)*
 628    -> ^(TOK_ALTERTABLE_DROPPARTS Identifier partitionSpec+ ifExists?)
 629    ;
 630
 631alterStatementSuffixProperties
 632@init { msgs.push("alter properties statement"); }
 633@after { msgs.pop(); }
 634    : name=Identifier KW_SET KW_TBLPROPERTIES tableProperties
 635    -> ^(TOK_ALTERTABLE_PROPERTIES $name tableProperties)
 636    ;
 637
 638alterViewSuffixProperties
 639@init { msgs.push("alter view properties statement"); }
 640@after { msgs.pop(); }
 641    : name=Identifier KW_SET KW_TBLPROPERTIES tableProperties
 642    -> ^(TOK_ALTERVIEW_PROPERTIES $name tableProperties)
 643    ;
 644
 645alterStatementSuffixSerdeProperties
 646@init { msgs.push("alter serdes statement"); }
 647@after { msgs.pop(); }
 648    : name=Identifier KW_SET KW_SERDE serdeName=StringLiteral (KW_WITH KW_SERDEPROPERTIES tableProperties)?
 649    -> ^(TOK_ALTERTABLE_SERIALIZER $name $serdeName tableProperties?)
 650    | name=Identifier KW_SET KW_SERDEPROPERTIES tableProperties
 651    -> ^(TOK_ALTERTABLE_SERDEPROPERTIES $name tableProperties)
 652    ;
 653
 654tablePartitionPrefix
 655@init {msgs.push("table partition prefix");}
 656@after {msgs.pop();}
 657  :name=Identifier partitionSpec?
 658  ->^(TOK_TABLE_PARTITION $name partitionSpec?)
 659  ;
 660
 661alterTblPartitionStatement
 662@init {msgs.push("alter table partition statement");}
 663@after {msgs.pop();}
 664  :  tablePartitionPrefix alterTblPartitionStatementSuffix
 665  -> ^(TOK_ALTERTABLE_PARTITION tablePartitionPrefix alterTblPartitionStatementSuffix)
 666  ;
 667
 668alterTblPartitionStatementSuffix
 669@init {msgs.push("alter table partition statement suffix");}
 670@after {msgs.pop();}
 671  : alterStatementSuffixFileFormat
 672  | alterStatementSuffixLocation
 673  | alterStatementSuffixProtectMode
 674  ;
 675
 676alterStatementSuffixFileFormat
 677@init {msgs.push("alter fileformat statement"); }
 678@after {msgs.pop();}
 679	: KW_SET KW_FILEFORMAT fileFormat
 680	-> ^(TOK_ALTERTABLE_FILEFORMAT fileFormat)
 681	;
 682
 683alterStatementSuffixLocation
 684@init {msgs.push("alter location");}
 685@after {msgs.pop();}
 686  : KW_SET KW_LOCATION newLoc=StringLiteral
 687  -> ^(TOK_ALTERTABLE_LOCATION $newLoc)
 688  ;
 689
 690alterStatementSuffixProtectMode
 691@init { msgs.push("alter partition protect mode statement"); }
 692@after { msgs.pop(); }
 693    : alterProtectMode
 694    -> ^(TOK_ALTERTABLE_ALTERPARTS_PROTECTMODE alterProtectMode)
 695    ;
 696
 697alterProtectMode
 698@init { msgs.push("protect mode specification enable"); }
 699@after { msgs.pop(); }
 700    : KW_ENABLE alterProtectModeMode  -> ^(TOK_ENABLE alterProtectModeMode)
 701    | KW_DISABLE alterProtectModeMode  -> ^(TOK_DISABLE alterProtectModeMode)
 702    ;
 703
 704alterProtectModeMode
 705@init { msgs.push("protect mode specification enable"); }
 706@after { msgs.pop(); }
 707    : KW_OFFLINE  -> ^(TOK_OFFLINE)
 708    | KW_NO_DROP  -> ^(TOK_NO_DROP)
 709    | KW_READONLY  -> ^(TOK_READONLY)
 710    ;
 711
 712
 713alterStatementSuffixClusterbySortby
 714@init {msgs.push("alter cluster by sort by statement");}
 715@after{msgs.pop();}
 716	:name=Identifier tableBuckets
 717	->^(TOK_ALTERTABLE_CLUSTER_SORT $name tableBuckets)
 718	|
 719	name=Identifier KW_NOT KW_CLUSTERED
 720	->^(TOK_ALTERTABLE_CLUSTER_SORT $name)
 721	;
 722
 723fileFormat
 724@init { msgs.push("file format specification"); }
 725@after { msgs.pop(); }
 726    : KW_SEQUENCEFILE  -> ^(TOK_TBLSEQUENCEFILE)
 727    | KW_TEXTFILE  -> ^(TOK_TBLTEXTFILE)
 728    | KW_RCFILE  -> ^(TOK_TBLRCFILE)
 729    | KW_INPUTFORMAT inFmt=StringLiteral KW_OUTPUTFORMAT outFmt=StringLiteral (KW_INPUTDRIVER inDriver=StringLiteral KW_OUTPUTDRIVER outDriver=StringLiteral)?
 730      -> ^(TOK_TABLEFILEFORMAT $inFmt $outFmt $inDriver? $outDriver?)
 731    | genericSpec=Identifier -> ^(TOK_FILEFORMAT_GENERIC $genericSpec)
 732    ;
 733
 734tabTypeExpr
 735@init { msgs.push("specifying table types"); }
 736@after { msgs.pop(); }
 737
 738   : Identifier (DOT^ (Identifier | KW_ELEM_TYPE | KW_KEY_TYPE | KW_VALUE_TYPE))*
 739   ;
 740
 741partTypeExpr
 742@init { msgs.push("specifying table partitions"); }
 743@after { msgs.pop(); }
 744    :  tabTypeExpr partitionSpec? -> ^(TOK_TABTYPE tabTypeExpr partitionSpec?)
 745    ;
 746
 747descStatement
 748@init { msgs.push("describe statement"); }
 749@after { msgs.pop(); }
 750    : (KW_DESCRIBE|KW_DESC) (descOptions=KW_FORMATTED|descOptions=KW_EXTENDED)? (parttype=partTypeExpr) -> ^(TOK_DESCTABLE $parttype $descOptions?)
 751    | (KW_DESCRIBE|KW_DESC) KW_FUNCTION KW_EXTENDED? (name=descFuncNames) -> ^(TOK_DESCFUNCTION $name KW_EXTENDED?)
 752    | (KW_DESCRIBE|KW_DESC) KW_DATABASE KW_EXTENDED? (dbName=Identifier) -> ^(TOK_DESCDATABASE $dbName KW_EXTENDED?)
 753    ;
 754
 755analyzeStatement
 756@init { msgs.push("analyze statement"); }
 757@after { msgs.pop(); }
 758    : KW_ANALYZE KW_TABLE (parttype=tableOrPartition) KW_COMPUTE KW_STATISTICS -> ^(TOK_ANALYZE $parttype)
 759    ;
 760
 761showStatement
 762@init { msgs.push("show statement"); }
 763@after { msgs.pop(); }
 764    : KW_SHOW (KW_DATABASES|KW_SCHEMAS) (KW_LIKE showStmtIdentifier)? -> ^(TOK_SHOWDATABASES showStmtIdentifier?)
 765    | KW_SHOW KW_TABLES ((KW_FROM|KW_IN) db_name=Identifier)? (KW_LIKE showStmtIdentifier|showStmtIdentifier)?  -> ^(TOK_SHOWTABLES (TOK_FROM $db_name)? showStmtIdentifier?)
 766    | KW_SHOW KW_FUNCTIONS showStmtIdentifier?  -> ^(TOK_SHOWFUNCTIONS showStmtIdentifier?)
 767    | KW_SHOW KW_PARTITIONS Identifier partitionSpec? -> ^(TOK_SHOWPARTITIONS Identifier partitionSpec?)
 768    | KW_SHOW KW_TABLE KW_EXTENDED ((KW_FROM|KW_IN) db_name=Identifier)? KW_LIKE showStmtIdentifier partitionSpec?
 769    -> ^(TOK_SHOW_TABLESTATUS showStmtIdentifier $db_name? partitionSpec?)
 770    | KW_SHOW KW_LOCKS (parttype=partTypeExpr)? (isExtended=KW_EXTENDED)? -> ^(TOK_SHOWLOCKS $parttype? $isExtended?)
 771    | KW_SHOW (showOptions=KW_FORMATTED)? (KW_INDEX|KW_INDEXES) KW_ON showStmtIdentifier ((KW_FROM|KW_IN) db_name=Identifier)?
 772    -> ^(TOK_SHOWINDEXES showStmtIdentifier $showOptions? $db_name?)  
 773    ;
 774
 775lockStatement
 776@init { msgs.push("lock statement"); }
 777@after { msgs.pop(); }
 778    : KW_LOCK KW_TABLE tableName partitionSpec? lockMode -> ^(TOK_LOCKTABLE tableName lockMode partitionSpec?)
 779    ;
 780
 781lockMode
 782@init { msgs.push("lock mode"); }
 783@after { msgs.pop(); }
 784    : KW_SHARED | KW_EXCLUSIVE
 785    ;
 786
 787unlockStatement
 788@init { msgs.push("unlock statement"); }
 789@after { msgs.pop(); }
 790    : KW_UNLOCK KW_TABLE tableName partitionSpec?  -> ^(TOK_UNLOCKTABLE tableName partitionSpec?)
 791    ;
 792
 793createRoleStatement
 794@init { msgs.push("create role"); }
 795@after { msgs.pop(); }
 796    : KW_CREATE kwRole roleName=Identifier
 797    -> ^(TOK_CREATEROLE $roleName)
 798    ;
 799
 800dropRoleStatement
 801@init {msgs.push("drop role");}
 802@after {msgs.pop();}
 803    : KW_DROP kwRole roleName=Identifier
 804    -> ^(TOK_DROPROLE $roleName)
 805    ;
 806
 807grantPrivileges
 808@init {msgs.push("grant privileges");}
 809@after {msgs.pop();}
 810    : KW_GRANT privList=privilegeList 
 811      privilegeObject?
 812      KW_TO principalSpecification
 813      (KW_WITH withOption)?
 814    -> ^(TOK_GRANT $privList principalSpecification privilegeObject? withOption?)
 815    ;
 816
 817revokePrivileges
 818@init {msgs.push("revoke privileges");}
 819@afer {msgs.pop();}
 820    : KW_REVOKE privilegeList privilegeObject? KW_FROM principalSpecification
 821    -> ^(TOK_REVOKE privilegeList principalSpecification privilegeObject?)
 822    ;
 823
 824grantRole
 825@init {msgs.push("grant role");}
 826@after {msgs.pop();}
 827    : KW_GRANT kwRole Identifier (COMMA Identifier)* KW_TO principalSpecification
 828    -> ^(TOK_GRANT_ROLE principalSpecification Identifier+)
 829    ;
 830
 831revokeRole
 832@init {msgs.push("revoke role");}
 833@after {msgs.pop();}
 834    : KW_REVOKE kwRole Identifier (COMMA Identifier)* KW_FROM principalSpecification
 835    -> ^(TOK_REVOKE_ROLE principalSpecification Identifier+)
 836    ;
 837
 838showRoleGrants
 839@init {msgs.push("show role grants");}
 840@after {msgs.pop();}
 841    : KW_SHOW kwRole KW_GRANT principalName
 842    -> ^(TOK_SHOW_ROLE_GRANT principalName)
 843    ;
 844
 845showGrants
 846@init {msgs.push("show grants");}
 847@after {msgs.pop();}
 848    : KW_SHOW KW_GRANT principalName privilegeIncludeColObject?
 849    -> ^(TOK_SHOW_GRANT principalName privilegeIncludeColObject?)
 850    ;
 851
 852privilegeIncludeColObject
 853@init {msgs.push("privilege object including columns");}
 854@after {msgs.pop();}
 855    : KW_ON (table=KW_TABLE|KW_DATABASE) Identifier (LPAREN cols=columnNameList RPAREN)? partitionSpec?
 856    -> ^(TOK_PRIV_OBJECT_COL Identifier $table? $cols? partitionSpec?)
 857    ;
 858
 859privilegeObject
 860@init {msgs.push("privilege subject");}
 861@after {msgs.pop();}
 862    : KW_ON (table=KW_TABLE|KW_DATABASE) Identifier partitionSpec?
 863    -> ^(TOK_PRIV_OBJECT Identifier $table? partitionSpec?)
 864    ;
 865
 866privilegeList
 867@init {msgs.push("grant privilege list");}
 868@after {msgs.pop();}
 869    : privlegeDef (COMMA privlegeDef)* 
 870    -> ^(TOK_PRIVILEGE_LIST privlegeDef+)
 871    ;
 872
 873privlegeDef
 874@init {msgs.push("grant privilege");}
 875@after {msgs.pop();}
 876    : privilegeType (LPAREN cols=columnNameList RPAREN)?
 877    -> ^(TOK_PRIVILEGE privilegeType $cols?)
 878    ;
 879    
 880privilegeType
 881@init {msgs.push("privilege type");}
 882@after {msgs.pop();}
 883    : KW_ALL -> ^(TOK_PRIV_ALL)
 884    | KW_ALTER -> ^(TOK_PRIV_ALTER_METADATA)
 885    | KW_UPDATE -> ^(TOK_PRIV_ALTER_DATA)
 886    | KW_CREATE -> ^(TOK_PRIV_CREATE)
 887    | KW_DROP -> ^(TOK_PRIV_DROP)
 888    | KW_INDEX -> ^(TOK_PRIV_INDEX)
 889    | KW_LOCK -> ^(TOK_PRIV_LOCK)
 890    | KW_SELECT -> ^(TOK_PRIV_SELECT)
 891    | KW_SHOW_DATABASE -> ^(TOK_PRIV_SHOW_DATABASE)
 892    ;
 893
 894principalSpecification
 895@init { msgs.push("user/group/role name list"); }
 896@after { msgs.pop(); }
 897    : principalName (COMMA principalName)* -> ^(TOK_PRINCIPAL_NAME principalName+)
 898    ;
 899
 900principalName
 901@init {msgs.push("user|group|role name");}
 902@after {msgs.pop();}
 903    : kwUser Identifier -> ^(TOK_USER Identifier)
 904    | KW_GROUP Identifier -> ^(TOK_GROUP Identifier)
 905    | kwRole Identifier -> ^(TOK_ROLE Identifier)
 906    ;
 907
 908withOption
 909@init {msgs.push("grant with option");}
 910@after {msgs.pop();}
 911    : KW_GRANT KW_OPTION
 912    -> ^(TOK_GRANT_WITH_OPTION)
 913    ;
 914
 915metastoreCheck
 916@init { msgs.push("metastore check statement"); }
 917@after { msgs.pop(); }
 918    : KW_MSCK (repair=KW_REPAIR)? (KW_TABLE table=Identifier partitionSpec? (COMMA partitionSpec)*)?
 919    -> ^(TOK_MSCK $repair? ($table partitionSpec*)?)
 920    ;
 921
 922createFunctionStatement
 923@init { msgs.push("create function statement"); }
 924@after { msgs.pop(); }
 925    : KW_CREATE KW_TEMPORARY KW_FUNCTION Identifier KW_AS StringLiteral
 926    -> ^(TOK_CREATEFUNCTION Identifier StringLiteral)
 927    ;
 928
 929dropFunctionStatement
 930@init { msgs.push("drop temporary function statement"); }
 931@after { msgs.pop(); }
 932    : KW_DROP KW_TEMPORARY KW_FUNCTION ifExists? Identifier
 933    -> ^(TOK_DROPFUNCTION Identifier ifExists?)
 934    ;
 935
 936createViewStatement
 937@init {
 938    msgs.push("create view statement");
 939}
 940@after { msgs.pop(); }
 941    : KW_CREATE KW_VIEW ifNotExists? name=tableName
 942        (LPAREN columnNameCommentList RPAREN)? tableComment?
 943        tablePropertiesPrefixed?
 944        KW_AS
 945        selectStatement
 946    -> ^(TOK_CREATEVIEW $name ifNotExists?
 947         columnNameCommentList?
 948         tableComment?
 949         tablePropertiesPrefixed?
 950         selectStatement
 951        )
 952    ;
 953
 954dropViewStatement
 955@init { msgs.push("drop view statement"); }
 956@after { msgs.pop(); }
 957    : KW_DROP KW_VIEW ifExists? viewName -> ^(TOK_DROPVIEW viewName ifExists?)
 958    ;
 959
 960showStmtIdentifier
 961@init { msgs.push("Identifier for show statement"); }
 962@after { msgs.pop(); }
 963    : Identifier
 964    | StringLiteral
 965    ;
 966
 967tableComment
 968@init { msgs.push("table's comment"); }
 969@after { msgs.pop(); }
 970    :
 971      KW_COMMENT comment=StringLiteral  -> ^(TOK_TABLECOMMENT $comment)
 972    ;
 973
 974tablePartition
 975@init { msgs.push("table partition specification"); }
 976@after { msgs.pop(); }
 977    : KW_PARTITIONED KW_BY LPAREN columnNameTypeList RPAREN
 978    -> ^(TOK_TABLEPARTCOLS columnNameTypeList)
 979    ;
 980
 981tableBuckets
 982@init { msgs.push("table buckets specification"); }
 983@after { msgs.pop(); }
 984    :
 985      KW_CLUSTERED KW_BY LPAREN bucketCols=columnNameList RPAREN (KW_SORTED KW_BY LPAREN sortCols=columnNameOrderList RPAREN)? KW_INTO num=Number KW_BUCKETS
 986    -> ^(TOK_TABLEBUCKETS $bucketCols $sortCols? $num)
 987    ;
 988
 989rowFormat
 990@init { msgs.push("serde specification"); }
 991@after { msgs.pop(); }
 992    : rowFormatSerde -> ^(TOK_SERDE rowFormatSerde)
 993    | rowFormatDelimited -> ^(TOK_SERDE rowFormatDelimited)
 994    |   -> ^(TOK_SERDE)
 995    ;
 996
 997recordReader
 998@init { msgs.push("record reader specification"); }
 999@after { msgs.pop(); }
1000    : KW_RECORDREADER StringLiteral -> ^(TOK_RECORDREADER StringLiteral)
1001    |   -> ^(TOK_RECORDREADER)
1002    ;
1003
1004recordWriter
1005@init { msgs.push("record writer specification"); }
1006@after { msgs.pop(); }
1007    : KW_RECORDWRITER StringLiteral -> ^(TOK_RECORDWRITER StringLiteral)
1008    |   -> ^(TOK_RECORDWRITER)
1009    ;
1010
1011rowFormatSerde
1012@init { msgs.push("serde format specification"); }
1013@after { msgs.pop(); }
1014    : KW_ROW KW_FORMAT KW_SERDE name=StringLiteral (KW_WITH KW_SERDEPROPERTIES serdeprops=tableProperties)?
1015    -> ^(TOK_SERDENAME $name $serdeprops?)
1016    ;
1017
1018rowFormatDelimited
1019@init { msgs.push("serde properties specification"); }
1020@after { msgs.pop(); }
1021    :
1022      KW_ROW KW_FORMAT KW_DELIMITED tableRowFormatFieldIdentifier? tableRowFormatCollItemsIdentifier? tableRowFormatMapKeysIdentifier? tableRowFormatLinesIdentifier?
1023    -> ^(TOK_SERDEPROPS tableRowFormatFieldIdentifier? tableRowFormatCollItemsIdentifier? tableRowFormatMapKeysIdentifier? tableRowFormatLinesIdentifier?)
1024    ;
1025
1026tableRowFormat
1027@init { msgs.push("table row format specification"); }
1028@after { msgs.pop(); }
1029    :
1030      rowFormatDelimited
1031    -> ^(TOK_TABLEROWFORMAT rowFormatDelimited)
1032    | rowFormatSerde
1033    -> ^(TOK_TABLESERIALIZER rowFormatSerde)
1034    ;
1035
1036tablePropertiesPrefixed
1037@init { msgs.push("table properties with prefix"); }
1038@after { msgs.pop(); }
1039    :
1040        KW_TBLPROPERTIES! tableProperties
1041    ;
1042
1043tableProperties
1044@init { msgs.push("table properties"); }
1045@after { msgs.pop(); }
1046    :
1047      LPAREN tablePropertiesList RPAREN -> ^(TOK_TABLEPROPERTIES tablePropertiesList)
1048    ;
1049
1050tablePropertiesList
1051@init { msgs.push("table properties list"); }
1052@after { msgs.pop(); }
1053    :
1054      keyValueProperty (COMMA keyValueProperty)* -> ^(TOK_TABLEPROPLIST keyValueProperty+)
1055    ;
1056
1057keyValueProperty
1058@init { msgs.push("specifying key/value property"); }
1059@after { msgs.pop(); }
1060    :
1061      key=StringLiteral EQUAL value=StringLiteral -> ^(TOK_TABLEPROPERTY $key $value)
1062    ;
1063
1064tableRowFormatFieldIdentifier
1065@init { msgs.push("table row format's field separator"); }
1066@after { msgs.pop(); }
1067    :
1068      KW_FIELDS KW_TERMINATED KW_BY fldIdnt=StringLiteral (KW_ESCAPED KW_BY fldEscape=StringLiteral)?
1069    -> ^(TOK_TABLEROWFORMATFIELD $fldIdnt $fldEscape?)
1070    ;
1071
1072tableRowFormatCollItemsIdentifier
1073@init { msgs.push("table row format's column separator"); }
1074@after { msgs.pop(); }
1075    :
1076      KW_COLLECTION KW_ITEMS KW_TERMINATED KW_BY collIdnt=StringLiteral
1077    -> ^(TOK_TABLEROWFORMATCOLLITEMS $collIdnt)
1078    ;
1079
1080tableRowFormatMapKeysIdentifier
1081@init { msgs.push("table row format's map key separator"); }
1082@after { msgs.pop(); }
1083    :
1084      KW_MAP KW_KEYS KW_TERMINATED KW_BY mapKeysIdnt=StringLiteral
1085    -> ^(TOK_TABLEROWFORMATMAPKEYS $mapKeysIdnt)
1086    ;
1087
1088tableRowFormatLinesIdentifier
1089@init { msgs.push("table row format's line separator"); }
1090@after { msgs.pop(); }
1091    :
1092      KW_LINES KW_TERMINATED KW_BY linesIdnt=StringLiteral
1093    -> ^(TOK_TABLEROWFORMATLINES $linesIdnt)
1094    ;
1095
1096tableFileFormat
1097@init { msgs.push("table file format specification"); }
1098@after { msgs.pop(); }
1099    :
1100      KW_STORED KW_AS KW_SEQUENCEFILE  -> TOK_TBLSEQUENCEFILE
1101      | KW_STORED KW_AS KW_TEXTFILE  -> TOK_TBLTEXTFILE
1102      | KW_STORED KW_AS KW_RCFILE  -> TOK_TBLRCFILE
1103      | KW_STORED KW_AS KW_INPUTFORMAT inFmt=StringLiteral KW_OUTPUTFORMAT outFmt=StringLiteral (KW_INPUTDRIVER inDriver=StringLiteral KW_OUTPUTDRIVER outDriver=StringLiteral)?
1104      -> ^(TOK_TABLEFILEFORMAT $inFmt $outFmt $inDriver? $outDriver?)
1105      | KW_STORED KW_BY storageHandler=StringLiteral
1106         (KW_WITH KW_SERDEPROPERTIES serdeprops=tableProperties)?
1107      -> ^(TOK_STORAGEHANDLER $storageHandler $serdeprops?)
1108      | KW_STORED KW_AS genericSpec=Identifier
1109      -> ^(TOK_FILEFORMAT_GENERIC $genericSpec)
1110    ;
1111
1112tableLocation
1113@init { msgs.push("table location specification"); }
1114@after { msgs.pop(); }
1115    :
1116      KW_LOCATION locn=StringLiteral -> ^(TOK_TABLELOCATION $locn)
1117    ;
1118
1119columnNameTypeList
1120@init { msgs.push("column name type list"); }
1121@after { msgs.pop(); }
1122    : columnNameType (COMMA columnNameType)* -> ^(TOK_TABCOLLIST columnNameType+)
1123    ;
1124
1125columnNameColonTypeList
1126@init { msgs.push("column name type list"); }
1127@after { msgs.pop(); }
1128    : columnNameColonType (COMMA columnNameColonType)* -> ^(TOK_TABCOLLIST columnNameColonType+)
1129    ;
1130
1131columnNameList
1132@init { msgs.push("column name list"); }
1133@after { msgs.pop(); }
1134    : columnName (COMMA columnName)* -> ^(TOK_TABCOLNAME columnName+)
1135    ;
1136
1137columnName
1138@init { msgs.push("column name"); }
1139@after { msgs.pop(); }
1140    :
1141      Identifier
1142    ;
1143
1144columnNameOrderList
1145@init { msgs.push("column name order list"); }
1146@after { msgs.pop(); }
1147    : columnNameOrder (COMMA columnNameOrder)* -> ^(TOK_TABCOLNAME columnNameOrder+)
1148    ;
1149
1150columnNameOrder
1151@init { msgs.push("column name order"); }
1152@after { msgs.pop(); }
1153    : Identifier (asc=KW_ASC | desc=KW_DESC)?
1154    -> {$desc == null}? ^(TOK_TABSORTCOLNAMEASC Identifier)
1155    ->                  ^(TOK_TABSORTCOLNAMEDESC Identifier)
1156    ;
1157
1158columnNameCommentList
1159@init { msgs.push("column name comment list"); }
1160@after { msgs.pop(); }
1161    : columnNameComment (COMMA columnNameComment)* -> ^(TOK_TABCOLNAME columnNameComment+)
1162    ;
1163
1164columnNameComment
1165@init { msgs.push("column name comment"); }
1166@after { msgs.pop(); }
1167    : colName=Identifier (KW_COMMENT comment=StringLiteral)?
1168    -> ^(TOK_TABCOL $colName TOK_NULL $comment?)
1169    ;
1170
1171columnRefOrder
1172@init { msgs.push("column order"); }
1173@after { msgs.pop(); }
1174    : expression (asc=KW_ASC | desc=KW_DESC)?
1175    -> {$desc == null}? ^(TOK_TABSORTCOLNAMEASC expression)
1176    ->                  ^(TOK_TABSORTCOLNAMEDESC expression)
1177    ;
1178
1179columnNameType
1180@init { msgs.push("column specification"); }
1181@after { msgs.pop(); }
1182    : colName=Identifier colType (KW_COMMENT comment=StringLiteral)?
1183    -> {$comment == null}? ^(TOK_TABCOL $colName colType)
1184    ->                     ^(TOK_TABCOL $colName colType $comment)
1185    ;
1186
1187columnNameColonType
1188@init { msgs.push("column specification"); }
1189@after { msgs.pop(); }
1190    : colName=Identifier COLON colType (KW_COMMENT comment=StringLiteral)?
1191    -> {$comment == null}? ^(TOK_TABCOL $colName colType)
1192    ->                     ^(TOK_TABCOL $colName colType $comment)
1193    ;
1194
1195colType
1196@init { msgs.push("column type"); }
1197@after { msgs.pop(); }
1198    : type
1199    ;
1200
1201colTypeList
1202@init { msgs.push("column type list"); }
1203@after { msgs.pop(); }
1204    : colType (COMMA colType)* -> ^(TOK_COLTYPELIST colType+)
1205    ;
1206
1207type
1208    : primitiveType
1209    | listType
1210    | structType
1211    | mapType
1212    | unionType;
1213
1214primitiveType
1215@init { msgs.push("primitive type specification"); }
1216@after { msgs.pop(); }
1217    : KW_TINYINT       ->    TOK_TINYINT
1218    | KW_SMALLINT      ->    TOK_SMALLINT
1219    | KW_INT           ->    TOK_INT
1220    | KW_BIGINT        ->    TOK_BIGINT
1221    | KW_BOOLEAN       ->    TOK_BOOLEAN
1222    | KW_FLOAT         ->    TOK_FLOAT
1223    | KW_DOUBLE        ->    TOK_DOUBLE
1224    | KW_DATE          ->    TOK_DATE
1225    | KW_DATETIME      ->    TOK_DATETIME
1226    | KW_TIMESTAMP     ->    TOK_TIMESTAMP
1227    | KW_STRING        ->    TOK_STRING
1228    ;
1229
1230listType
1231@init { msgs.push("list type"); }
1232@after { msgs.pop(); }
1233    : KW_ARRAY LESSTHAN type GREATERTHAN   -> ^(TOK_LIST type)
1234    ;
1235
1236structType
1237@init { msgs.push("struct type"); }
1238@after { msgs.pop(); }
1239    : KW_STRUCT LESSTHAN columnNameColonTypeList GREATERTHAN -> ^(TOK_STRUCT columnNameColonTypeList)
1240    ;
1241
1242mapType
1243@init { msgs.push("map type"); }
1244@after { msgs.pop(); }
1245    : KW_MAP LESSTHAN left=primitiveType COMMA right=type GREATERTHAN
1246    -> ^(TOK_MAP $left $right)
1247    ;
1248
1249unionType
1250@init { msgs.push("uniontype type"); }
1251@after { msgs.pop(); }
1252    : KW_UNIONTYPE LESSTHAN colTypeList GREATERTHAN -> ^(TOK_UNIONTYPE colTypeList)
1253    ;
1254
1255queryOperator
1256@init { msgs.push("query operator"); }
1257@after { msgs.pop(); }
1258    : KW_UNION KW_ALL -> ^(TOK_UNION)
1259    ;
1260
1261// select statement select ... from ... where ... group by ... order by ...
1262queryStatementExpression
1263    : queryStatement (queryOperator^ queryStatement)*
1264    ;
1265
1266queryStatement
1267    :
1268    fromClause
1269    ( b+=body )+ -> ^(TOK_QUERY fromClause body+)
1270    | regular_body
1271    ;
1272
1273regular_body
1274   :
1275   insertClause
1276   selectClause
1277   fromClause
1278   whereClause?
1279   groupByClause?
1280   havingClause?
1281   orderByClause?
1282   clusterByClause?
1283   distributeByClause?
1284   sortByClause?
1285   limitClause? -> ^(TOK_QUERY fromClause ^(TOK_INSERT insertClause
1286                     selectClause whereClause? groupByClause? havingClause? orderByClause? clusterByClause?
1287                     distributeByClause? sortByClause? limitClause?))
1288   |
1289   selectStatement
1290   ;
1291
1292selectStatement
1293   :
1294   selectClause
1295   fromClause
1296   whereClause?
1297   groupByClause?
1298   havingClause?
1299   orderByClause?
1300   clusterByClause?
1301   distributeByClause?
1302   sortByClause?
1303   limitClause? -> ^(TOK_QUERY fromClause ^(TOK_INSERT ^(TOK_DESTINATION ^(TOK_DIR TOK_TMP_FILE))
1304                     selectClause whereClause? groupByClause? havingClause? orderByClause? clusterByClause?
1305                     distributeByClause? sortByClause? limitClause?))
1306   ;
1307
1308
1309body
1310   :
1311   insertClause
1312   selectClause
1313   whereClause?
1314   groupByClause?
1315   havingClause?
1316   orderByClause?
1317   clusterByClause?
1318   distributeByClause?
1319   sortByClause?
1320   limitClause? -> ^(TOK_INSERT insertClause?
1321                     selectClause whereClause? groupByClause? havingClause? orderByClause? clusterByClause?
1322                     distributeByClause? sortByClause? limitClause?)
1323   |
1324   selectClause
1325   whereClause?
1326   groupByClause?
1327   havingClause?
1328   orderByClause?
1329   clusterByClause?
1330   distributeByClause?
1331   sortByClause?
1332   limitClause? -> ^(TOK_INSERT ^(TOK_DESTINATION ^(TOK_DIR TOK_TMP_FILE))
1333                     selectClause whereClause? groupByClause? havingClause? orderByClause? clusterByClause?
1334                     distributeByClause? sortByClause? limitClause?)
1335   ;
1336
1337insertClause
1338@init { msgs.push("insert clause"); }
1339@after { msgs.pop(); }
1340   :
1341   KW_INSERT KW_OVERWRITE destination -> ^(TOK_DESTINATION destination)
1342   ;
1343
1344destination
1345@init { msgs.push("destination specification"); }
1346@after { msgs.pop(); }
1347   :
1348     KW_LOCAL KW_DIRECTORY StringLiteral -> ^(TOK_LOCAL_DIR StringLiteral)
1349   | KW_DIRECTORY StringLiteral -> ^(TOK_DIR StringLiteral)
1350   | KW_TABLE tableOrPartition -> ^(tableOrPartition)
1351   ;
1352
1353limitClause
1354@init { msgs.push("limit clause"); }
1355@after { msgs.pop(); }
1356   :
1357   KW_LIMIT num=Number -> ^(TOK_LIMIT $num)
1358   ;
1359
1360//----------------------- Rules for parsing selectClause -----------------------------
1361// select a,b,c ...
1362selectClause
1363@init { msgs.push("select clause"); }
1364@after { msgs.pop(); }
1365    :
1366    KW_SELECT hintClause? (((KW_ALL | dist=KW_DISTINCT)? selectList)
1367                          | (transform=KW_TRANSFORM selectTrfmClause))
1368     -> {$transform == null && $dist == null}? ^(TOK_SELECT hintClause? selectList)
1369     -> {$transform == null && $dist != null}? ^(TOK_SELECTDI hintClause? selectList)
1370     -> ^(TOK_SELECT hintClause? ^(TOK_SELEXPR selectTrfmClause) )
1371    |
1372    trfmClause  ->^(TOK_SELECT ^(TOK_SELEXPR trfmClause))
1373    ;
1374
1375selectList
1376@init { msgs.push("select list"); }
1377@after { msgs.pop(); }
1378    :
1379    selectItem ( COMMA  selectItem )* -> selectItem+
1380    ;
1381
1382selectTrfmClause
1383@init { msgs.push("transform clause"); }
1384@after { msgs.pop(); }
1385    :
1386    LPAREN selectExpressionList RPAREN
1387    inSerde=rowFormat inRec=recordWriter
1388    KW_USING StringLiteral
1389    ( KW_AS ((LPAREN (aliasList | columnNameTypeList) RPAREN) | (aliasList | columnNameTypeList)))?
1390    outSerde=rowFormat outRec=recordReader
1391    -> ^(TOK_TRANSFORM selectExpressionList $inSerde $inRec StringLiteral $outSerde $outRec aliasList? columnNameTypeList?)
1392    ;
1393
1394hintClause
1395@init { msgs.push("hint clause"); }
1396@after { msgs.pop(); }
1397    :
1398    DIVIDE STAR PLUS hintList STAR DIVIDE -> ^(TOK_HINTLIST hintList)
1399    ;
1400
1401hintList
1402@init { msgs.push("hint list"); }
1403@after { msgs.pop(); }
1404    :
1405    hintItem (COMMA hintItem)* -> hintItem+
1406    ;
1407
1408hintItem
1409@init { msgs.push("hint item"); }
1410@after { msgs.pop(); }
1411    :
1412    hintName (LPAREN hintArgs RPAREN)? -> ^(TOK_HINT hintName hintArgs?)
1413    ;
1414
1415hintName
1416@init { msgs.push("hint name"); }
1417@after { msgs.pop(); }
1418    :
1419    KW_MAPJOIN -> TOK_MAPJOIN
1420    | KW_STREAMTABLE -> TOK_STREAMTABLE
1421    | KW_HOLD_DDLTIME -> TOK_HOLD_DDLTIME
1422    ;
1423
1424hintArgs
1425@init { msgs.push("hint arguments"); }
1426@after { msgs.pop(); }
1427    :
1428    hintArgName (COMMA hintArgName)* -> ^(TOK_HINTARGLIST hintArgName+)
1429    ;
1430
1431hintArgName
1432@init { msgs.push("hint argument name"); }
1433@after { msgs.pop(); }
1434    :
1435    Identifier
1436    ;
1437
1438selectItem
1439@init { msgs.push("selection target"); }
1440@after { msgs.pop(); }
1441    :
1442    ( selectExpression  ((KW_AS? Identifier) | (KW_AS LPAREN Identifier (COMMA Identifier)* RPAREN))?) -> ^(TOK_SELEXPR selectExpression Identifier*)
1443    ;
1444
1445trfmClause
1446@init { msgs.push("transform clause"); }
1447@after { msgs.pop(); }
1448    :
1449    (   KW_MAP    selectExpressionList
1450      | KW_REDUCE selectExpressionList )
1451    inSerde=rowFormat inRec=recordWriter
1452    KW_USING StringLiteral
1453    ( KW_AS ((LPAREN (aliasList | columnNameTypeList) RPAREN) | (aliasList | columnNameTypeList)))?
1454    outSerde=rowFormat outRec=recordReader
1455    -> ^(TOK_TRANSFORM selectExpressionList $inSerde $inRec StringLiteral $outSerde $outRec aliasList? columnNameTypeList?)
1456    ;
1457
1458selectExpression
1459@init { msgs.push("select expression"); }
1460@after { msgs.pop(); }
1461    :
1462    expression | tableAllColumns
1463    ;
1464
1465selectExpressionList
1466@init { msgs.push("select expression list"); }
1467@after { msgs.pop(); }
1468    :
1469    selectExpression (COMMA selectExpression)* -> ^(TOK_EXPLIST selectExpression+)
1470    ;
1471
1472
1473//-----------------------------------------------------------------------------------
1474
1475tableAllColumns
1476    : STAR
1477        -> ^(TOK_ALLCOLREF)
1478    | tableName DOT STAR
1479        -> ^(TOK_ALLCOLREF tableName)
1480    ;
1481
1482// (table|column)
1483tableOrColumn
1484@init { msgs.push("table or column identifier"); }
1485@after { msgs.pop(); }
1486    :
1487    Identifier -> ^(TOK_TABLE_OR_COL Identifier)
1488    ;
1489
1490expressionList
1491@init { msgs.push("expression list"); }
1492@after { msgs.pop(); }
1493    :
1494    expression (COMMA expression)* -> ^(TOK_EXPLIST expression+)
1495    ;
1496
1497aliasList
1498@init { msgs.push("alias list"); }
1499@after { msgs.pop(); }
1500    :
1501    Identifier (COMMA Identifier)* -> ^(TOK_ALIASLIST Identifier+)
1502    ;
1503
1504//----------------------- Rules for parsing fromClause ------------------------------
1505// from [col1, col2, col3] table1, [col4, col5] table2
1506fromClause
1507@init { msgs.push("from clause"); }
1508@after { msgs.pop(); }
1509    :
1510    KW_FROM joinSource -> ^(TOK_FROM joinSource)
1511    ;
1512
1513joinSource
1514@init { msgs.push("join source"); }
1515@after { msgs.pop(); }
1516    : fromSource ( joinToken^ fromSource (KW_ON! expression)? )*
1517    | uniqueJoinToken^ uniqueJoinSource (COMMA! uniqueJoinSource)+
1518    ;
1519
1520uniqueJoinSource
1521@init { msgs.push("join source"); }
1522@after { msgs.pop(); }
1523    : KW_PRESERVE? fromSource uniqueJoinExpr
1524    ;
1525
1526uniqueJoinExpr
1527@init { msgs.push("unique join expression list"); }
1528@after { msgs.pop(); }
1529    : LPAREN e1+=expression (COMMA e1+=expression)* RPAREN
1530      -> ^(TOK_EXPLIST $e1*)
1531    ;
1532
1533uniqueJoinToken
1534@init { msgs.push("unique join"); }
1535@after { msgs.pop(); }
1536    : KW_UNIQUEJOIN -> TOK_UNIQUEJOIN;
1537
1538joinToken
1539@init { msgs.push("join type specifier"); }
1540@after { msgs.pop(); }
1541    :
1542      KW_JOIN                     -> TOK_JOIN
1543    | KW_LEFT  KW_OUTER KW_JOIN   -> TOK_LEFTOUTERJOIN
1544    | KW_RIGHT KW_OUTER KW_JOIN   -> TOK_RIGHTOUTERJOIN
1545    | KW_FULL  KW_OUTER KW_JOIN   -> TOK_FULLOUTERJOIN
1546    | KW_LEFT  KW_SEMI  KW_JOIN   -> TOK_LEFTSEMIJOIN
1547    ;
1548
1549lateralView
1550@init {msgs.push("lateral view"); }
1551@after {msgs.pop(); }
1552	:
1553	KW_LATERAL KW_VIEW function tableAlias KW_AS Identifier (COMMA Identifier)* -> ^(TOK_LATERAL_VIEW ^(TOK_SELECT ^(TOK_SELEXPR function Identifier+ tableAlias)))
1554	;
1555
1556tableAlias
1557@init {msgs.push("table alias"); }
1558@after {msgs.pop(); }
1559    :
1560    Identifier -> ^(TOK_TABALIAS Identifier)
1561    ;
1562
1563fromSource
1564@init { msgs.push("from source"); }
1565@after { msgs.pop(); }
1566    :
1567    (tableSource | subQuerySource) (lateralView^)*
1568    ;
1569
1570tableSample
1571@init { msgs.push("table sample specification"); }
1572@after { msgs.pop(); }
1573    :
1574    KW_TABLESAMPLE LPAREN KW_BUCKET (numerator=Number) KW_OUT KW_OF (denominator=Number) (KW_ON expr+=expression (COMMA expr+=expression)*)? RPAREN -> ^(TOK_TABLESAMPLE $numerator $denominator $expr*)
1575    ;
1576
1577tableSource
1578@init { msgs.push("table source"); }
1579@after { msgs.pop(); }
1580    : tabname=tableName (ts=tableSample)? (alias=Identifier)?
1581    -> ^(TOK_TABREF $tabname $ts? $alias?)
1582    ;
1583
1584tableName
1585@init { msgs.push("table name"); }
1586@after { msgs.pop(); }
1587    : (db=Identifier DOT)? tab=Identifier
1588    -> ^(TOK_TABNAME $db? $tab)
1589    ;
1590
1591viewName
1592@init { msgs.push("view name"); }
1593@after { msgs.pop(); }
1594    :
1595    (db=Identifier DOT)? view=Identifier
1596    -> ^(TOK_TABNAME $db? $view)
1597    ;
1598
1599subQuerySource
1600@init { msgs.push("subquery source"); }
1601@after { msgs.pop(); }
1602    :
1603    LPAREN queryStatementExpression RPAREN Identifier -> ^(TOK_SUBQUERY queryStatementExpression Identifier)
1604    ;
1605
1606//----------------------- Rules for parsing whereClause -----------------------------
1607// where a=b and ...
1608whereClause
1609@init { msgs.push("where clause"); }
1610@after { msgs.pop(); }
1611    :
1612    KW_WHERE searchCondition -> ^(TOK_WHERE searchCondition)
1613    ;
1614
1615searchCondition
1616@init { msgs.push("search condition"); }
1617@after { msgs.pop(); }
1618    :
1619    expression
1620    ;
1621
1622//-----------------------------------------------------------------------------------
1623
1624// group by a,b
1625groupByClause
1626@init { msgs.push("group by clause"); }
1627@after { msgs.pop(); }
1628    :
1629    KW_GROUP KW_BY
1630    groupByExpression
1631    ( COMMA groupByExpression )*
1632    -> ^(TOK_GROUPBY groupByExpression+)
1633    ;
1634
1635groupByExpression
1636@init { msgs.push("group by expression"); }
1637@after { msgs.pop(); }
1638    :
1639    expression
1640    ;
1641
1642havingClause
1643@init { msgs.push("having clause"); }
1644@after { msgs.pop(); }
1645    :
1646    KW_HAVING havingCondition -> ^(TOK_HAVING havingCondition)
1647    ;
1648
1649havingCondition
1650@init { msgs.push("having condition"); }
1651@after { msgs.pop(); }
1652    :
1653    expression
1654    ;
1655
1656// order by a,b
1657orderByClause
1658@init { msgs.push("order by clause"); }
1659@after { msgs.pop(); }
1660    :
1661    KW_ORDER KW_BY
1662    columnRefOrder
1663    ( COMMA columnRefOrder)* -> ^(TOK_ORDERBY columnRefOrder+)
1664    ;
1665
1666clusterByClause
1667@init { msgs.push("cluster by clause"); }
1668@after { msgs.pop(); }
1669    :
1670    KW_CLUSTER KW_BY
1671    expression
1672    ( COMMA expression )* -> ^(TOK_CLUSTERBY expression+)
1673    ;
1674
1675distributeByClause
1676@init { msgs.push("distribute by clause"); }
1677@after { msgs.pop(); }
1678    :
1679    KW_DISTRIBUTE KW_BY
1680    expression (COMMA expression)* -> ^(TOK_DISTRIBUTEBY expression+)
1681    ;
1682
1683sortByClause
1684@init { msgs.push("sort by clause"); }
1685@after { msgs.pop(); }
1686    :
1687    KW_SORT KW_BY
1688    columnRefOrder
1689    ( COMMA columnRefOrder)* -> ^(TOK_SORTBY columnRefOrder+)
1690    ;
1691
1692// fun(par1, par2, par3)
1693function
1694@init { msgs.push("function specification"); }
1695@after { msgs.pop(); }
1696    :
1697    functionName
1698    LPAREN
1699      (
1700        (star=STAR)
1701        | (dist=KW_DISTINCT)? (expression (COMMA expression)*)?
1702      )
1703    RPAREN -> {$star != null}? ^(TOK_FUNCTIONSTAR functionName)
1704           -> {$dist == null}? ^(TOK_FUNCTION functionName (expression+)?)
1705                            -> ^(TOK_FUNCTIONDI functionName (expression+)?)
1706    ;
1707
1708functionName
1709@init { msgs.push("function name"); }
1710@after { msgs.pop(); }
1711    : // Keyword IF is also a function name
1712    Identifier | KW_IF | KW_ARRAY | KW_MAP | KW_STRUCT | KW_UNIONTYPE
1713    ;
1714
1715castExpression
1716@init { msgs.push("cast expression"); }
1717@after { msgs.pop(); }
1718    :
1719    KW_CAST
1720    LPAREN
1721          expression
1722          KW_AS
1723          primitiveType
1724    RPAREN -> ^(TOK_FUNCTION primitiveType expression)
1725    ;
1726
1727caseExpression
1728@init { msgs.push("case expression"); }
1729@after { msgs.pop(); }
1730    :
1731    KW_CASE expression
1732    (KW_WHEN expression KW_THEN expression)+
1733    (KW_ELSE expression)?
1734    KW_END -> ^(TOK_FUNCTION KW_CASE expression*)
1735    ;
1736
1737whenExpression
1738@init { msgs.push("case expression"); }
1739@after { msgs.pop(); }
1740    :
1741    KW_CASE
1742     ( KW_WHEN expression KW_THEN expression)+
1743    (KW_ELSE expression)?
1744    KW_END -> ^(TOK_FUNCTION KW_WHEN expression*)
1745    ;
1746
1747constant
1748@init { msgs.push("constant"); }
1749@after { msgs.pop(); }
1750    :
1751    Number
1752    | StringLiteral
1753    | charSetStringLiteral
1754    | booleanValue
1755    ;
1756
1757charSetStringLiteral
1758@init { msgs.push("character string literal"); }
1759@after { msgs.pop(); }
1760    :
1761    csName=CharSetName csLiteral=CharSetLiteral -> ^(TOK_CHARSETLITERAL $csName $csLiteral)
1762    ;
1763
1764expression
1765@init { msgs.push("expression specification"); }
1766@after { msgs.pop(); }
1767    :
1768    precedenceOrExpression
1769    ;
1770
1771atomExpression
1772    :
1773    KW_NULL -> TOK_NULL
1774    | constant
1775    | function
1776    | castExpression
1777    | caseExpression
1778    | whenExpression
1779    | tableOrColumn
1780    | LPAREN! expression RPAREN!
1781    ;
1782
1783
1784precedenceFieldExpression
1785    :
1786    atomExpression ((LSQUARE^ expression RSQUARE!) | (DOT^ Identifier))*
1787    ;
1788
1789precedenceUnaryOperator
1790    :
1791    PLUS | MINUS | TILDE
1792    ;
1793
1794nullCondition
1795    :
1796    KW_NULL -> ^(TOK_ISNULL)
1797    | KW_NOT KW_NULL -> ^(TOK_ISNOTNULL)
1798    ;
1799
1800precedenceUnaryPrefixExpression
1801    :
1802    (precedenceUnaryOperator^)* precedenceFieldExpression
1803    ;
1804
1805precedenceUnarySuffixExpression
1806    : precedenceUnaryPrefixExpression (a=KW_IS nullCondition)?
1807    -> {$a != null}? ^(TOK_FUNCTION nullCondition precedenceUnaryPrefixExpression)
1808    -> precedenceUnaryPrefixExpression
1809    ;
1810
1811
1812precedenceBitwiseXorOperator
1813    :
1814    BITWISEXOR
1815    ;
1816
1817precedenceBitwiseXorExpression
1818    :
1819    precedenceUnarySuffixExpression (precedenceBitwiseXorOperator^ precedenceUnarySuffixExpression)*
1820    ;
1821
1822
1823precedenceStarOperator
1824    :
1825    STAR | DIVIDE | MOD | DIV
1826    ;
1827
1828precedenceStarExpression
1829    :
1830    precedenceBitwiseXorExpression (precedenceStarOperator^ precedenceBitwiseXorExpression)*
1831    ;
1832
1833
1834precedencePlusOperator
1835    :
1836    PLUS | MINUS
1837    ;
1838
1839precedencePlusExpression
1840    :
1841    precedenceStarExpression (precedencePlusOperator^ precedenceStarExpression)*
1842    ;
1843
1844
1845precedenceAmpersandOperator
1846    :
1847    AMPERSAND
1848    ;
1849
1850precedenceAmpersandExpression
1851    :
1852    precedencePlusExpression (precedenceAmpersandOperator^ precedencePlusExpression)*
1853    ;
1854
1855
1856precedenceBitwiseOrOperator
1857    :
1858    BITWISEOR
1859    ;
1860
1861precedenceBitwiseOrExpression
1862    :
1863    precedenceAmpersandExpression (precedenceBitwiseOrOperator^ precedenceAmpersandExpression)*
1864    ;
1865
1866
1867precedenceEqualOperator
1868    :
1869    EQUAL | NOTEQUAL | LESSTHANOREQUALTO | LESSTHAN | GREATERTHANOREQUALTO | GREATERTHAN
1870    | KW_LIKE | KW_RLIKE | KW_REGEXP
1871    ;
1872
1873precedenceEqualExpression
1874    :
1875    precedenceBitwiseOrExpression ( (precedenceEqualOperator^ precedenceBitwiseOrExpression) | (inOperator^ expressions) )*
1876    ;
1877
1878inOperator
1879    :
1880    KW_IN -> ^(TOK_FUNCTION KW_IN)
1881    ;
1882
1883expressions
1884    :
1885    LPAREN expression (COMMA expression)* RPAREN -> expression*
1886    ;
1887
1888precedenceNotOperator
1889    :
1890    KW_NOT
1891    ;
1892
1893precedenceNotExpression
1894    :
1895    (precedenceNotOperator^)* precedenceEqualExpression
1896    ;
1897
1898
1899precedenceAndOperator
1900    :
1901    KW_AND
1902    ;
1903
1904precedenceAndExpression
1905    :
1906    p

Large files files are truncated, but you can click here to view the full file