/
Hive.g
2420 lines (2148 loc) · 59.4 KB
/
Hive.g
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
grammar Hive;
options
{
output=AST;
ASTLabelType=CommonTree;
backtrack=false;
k=3;
}
tokens {
TOK_INSERT;
TOK_QUERY;
TOK_SELECT;
TOK_SELECTDI;
TOK_SELEXPR;
TOK_FROM;
TOK_TAB;
TOK_PARTSPEC;
TOK_PARTVAL;
TOK_DIR;
TOK_LOCAL_DIR;
TOK_TABREF;
TOK_SUBQUERY;
TOK_INSERT_INTO;
TOK_DESTINATION;
TOK_ALLCOLREF;
TOK_TABLE_OR_COL;
TOK_FUNCTION;
TOK_FUNCTIONDI;
TOK_FUNCTIONSTAR;
TOK_WHERE;
TOK_OP_EQ;
TOK_OP_NE;
TOK_OP_LE;
TOK_OP_LT;
TOK_OP_GE;
TOK_OP_GT;
TOK_OP_DIV;
TOK_OP_ADD;
TOK_OP_SUB;
TOK_OP_MUL;
TOK_OP_MOD;
TOK_OP_BITAND;
TOK_OP_BITNOT;
TOK_OP_BITOR;
TOK_OP_BITXOR;
TOK_OP_AND;
TOK_OP_OR;
TOK_OP_NOT;
TOK_OP_LIKE;
TOK_TRUE;
TOK_FALSE;
TOK_TRANSFORM;
TOK_SERDE;
TOK_SERDENAME;
TOK_SERDEPROPS;
TOK_EXPLIST;
TOK_ALIASLIST;
TOK_GROUPBY;
TOK_HAVING;
TOK_ORDERBY;
TOK_CLUSTERBY;
TOK_DISTRIBUTEBY;
TOK_SORTBY;
TOK_UNION;
TOK_JOIN;
TOK_LEFTOUTERJOIN;
TOK_RIGHTOUTERJOIN;
TOK_FULLOUTERJOIN;
TOK_UNIQUEJOIN;
TOK_LOAD;
TOK_EXPORT;
TOK_IMPORT;
TOK_NULL;
TOK_ISNULL;
TOK_ISNOTNULL;
TOK_TINYINT;
TOK_SMALLINT;
TOK_INT;
TOK_BIGINT;
TOK_BOOLEAN;
TOK_FLOAT;
TOK_DOUBLE;
TOK_DATE;
TOK_DATETIME;
TOK_TIMESTAMP;
TOK_STRING;
TOK_LIST;
TOK_STRUCT;
TOK_MAP;
TOK_UNIONTYPE;
TOK_COLTYPELIST;
TOK_CREATEDATABASE;
TOK_CREATETABLE;
TOK_CREATEINDEX;
TOK_CREATEINDEX_INDEXTBLNAME;
TOK_DEFERRED_REBUILDINDEX;
TOK_DROPINDEX;
TOK_LIKETABLE;
TOK_DESCTABLE;
TOK_DESCFUNCTION;
TOK_ALTERTABLE_PARTITION;
TOK_ALTERTABLE_RENAME;
TOK_ALTERTABLE_ADDCOLS;
TOK_ALTERTABLE_RENAMECOL;
TOK_ALTERTABLE_REPLACECOLS;
TOK_ALTERTABLE_ADDPARTS;
TOK_ALTERTABLE_DROPPARTS;
TOK_ALTERTABLE_ALTERPARTS_PROTECTMODE;
TOK_ALTERTABLE_TOUCH;
TOK_ALTERTABLE_ARCHIVE;
TOK_ALTERTABLE_UNARCHIVE;
TOK_ALTERTABLE_SERDEPROPERTIES;
TOK_ALTERTABLE_SERIALIZER;
TOK_TABLE_PARTITION;
TOK_ALTERTABLE_FILEFORMAT;
TOK_ALTERTABLE_LOCATION;
TOK_ALTERTABLE_PROPERTIES;
TOK_ALTERTABLE_CHANGECOL_AFTER_POSITION;
TOK_ALTERINDEX_REBUILD;
TOK_ALTERINDEX_PROPERTIES;
TOK_MSCK;
TOK_SHOWDATABASES;
TOK_SHOWTABLES;
TOK_SHOWFUNCTIONS;
TOK_SHOWPARTITIONS;
TOK_SHOW_TABLESTATUS;
TOK_SHOWLOCKS;
TOK_LOCKTABLE;
TOK_UNLOCKTABLE;
TOK_SWITCHDATABASE;
TOK_DROPDATABASE;
TOK_DROPTABLE;
TOK_DATABASECOMMENT;
TOK_TABCOLLIST;
TOK_TABCOL;
TOK_TABLECOMMENT;
TOK_TABLEPARTCOLS;
TOK_TABLEBUCKETS;
TOK_TABLEROWFORMAT;
TOK_TABLEROWFORMATFIELD;
TOK_TABLEROWFORMATCOLLITEMS;
TOK_TABLEROWFORMATMAPKEYS;
TOK_TABLEROWFORMATLINES;
TOK_TBLSEQUENCEFILE;
TOK_TBLTEXTFILE;
TOK_TBLRCFILE;
TOK_TABLEFILEFORMAT;
TOK_FILEFORMAT_GENERIC;
TOK_OFFLINE;
TOK_ENABLE;
TOK_DISABLE;
TOK_READONLY;
TOK_NO_DROP;
TOK_STORAGEHANDLER;
TOK_ALTERTABLE_CLUSTER_SORT;
TOK_TABCOLNAME;
TOK_TABLELOCATION;
TOK_PARTITIONLOCATION;
TOK_TABLEBUCKETSAMPLE;
TOK_TABLESPLITSAMPLE;
TOK_TMP_FILE;
TOK_TABSORTCOLNAMEASC;
TOK_TABSORTCOLNAMEDESC;
TOK_CHARSETLITERAL;
TOK_CREATEFUNCTION;
TOK_DROPFUNCTION;
TOK_CREATEVIEW;
TOK_DROPVIEW;
TOK_ALTERVIEW_PROPERTIES;
TOK_ALTERVIEW_ADDPARTS;
TOK_ALTERVIEW_DROPPARTS;
TOK_ALTERVIEW_RENAME;
TOK_VIEWPARTCOLS;
TOK_EXPLAIN;
TOK_TABLESERIALIZER;
TOK_TABLEPROPERTIES;
TOK_TABLEPROPLIST;
TOK_INDEXPROPERTIES;
TOK_INDEXPROPLIST;
TOK_TABTYPE;
TOK_LIMIT;
TOK_TABLEPROPERTY;
TOK_IFEXISTS;
TOK_IFNOTEXISTS;
TOK_ORREPLACE;
TOK_HINTLIST;
TOK_HINT;
TOK_MAPJOIN;
TOK_STREAMTABLE;
TOK_HOLD_DDLTIME;
TOK_HINTARGLIST;
TOK_USERSCRIPTCOLNAMES;
TOK_USERSCRIPTCOLSCHEMA;
TOK_RECORDREADER;
TOK_RECORDWRITER;
TOK_LEFTSEMIJOIN;
TOK_LATERAL_VIEW;
TOK_TABALIAS;
TOK_ANALYZE;
TOK_CREATEROLE;
TOK_DROPROLE;
TOK_GRANT;
TOK_REVOKE;
TOK_SHOW_GRANT;
TOK_PRIVILEGE_LIST;
TOK_PRIVILEGE;
TOK_PRINCIPAL_NAME;
TOK_USER;
TOK_GROUP;
TOK_ROLE;
TOK_GRANT_WITH_OPTION;
TOK_PRIV_ALL;
TOK_PRIV_ALTER_METADATA;
TOK_PRIV_ALTER_DATA;
TOK_PRIV_DROP;
TOK_PRIV_INDEX;
TOK_PRIV_LOCK;
TOK_PRIV_SELECT;
TOK_PRIV_SHOW_DATABASE;
TOK_PRIV_CREATE;
TOK_PRIV_OBJECT;
TOK_PRIV_OBJECT_COL;
TOK_GRANT_ROLE;
TOK_REVOKE_ROLE;
TOK_SHOW_ROLE_GRANT;
TOK_SHOWINDEXES;
TOK_INDEXCOMMENT;
TOK_DESCDATABASE;
TOK_DATABASEPROPERTIES;
TOK_DATABASELOCATION;
TOK_DBPROPLIST;
TOK_ALTERDATABASE_PROPERTIES;
TOK_ALTERTABLE_ALTERPARTS_MERGEFILES;
TOK_TABNAME;
TOK_TABSRC;
TOK_RESTRICT;
TOK_CASCADE;
}
// Package headers
@header {
package org.apache.hadoop.hive.ql.parse;
}
@lexer::header {package org.apache.hadoop.hive.ql.parse;}
@members {
Stack msgs = new Stack<String>();
}
@rulecatch {
catch (RecognitionException e) {
reportError(e);
throw e;
}
}
// starting rule
statement
: explainStatement EOF
| execStatement EOF
;
explainStatement
@init { msgs.push("explain statement"); }
@after { msgs.pop(); }
: KW_EXPLAIN (isExtended=KW_EXTENDED)? execStatement -> ^(TOK_EXPLAIN execStatement $isExtended?)
;
execStatement
@init { msgs.push("statement"); }
@after { msgs.pop(); }
: queryStatementExpression
| loadStatement
| exportStatement
| importStatement
| ddlStatement
;
loadStatement
@init { msgs.push("load statement"); }
@after { msgs.pop(); }
: KW_LOAD KW_DATA (islocal=KW_LOCAL)? KW_INPATH (path=StringLiteral) (isoverwrite=KW_OVERWRITE)? KW_INTO KW_TABLE (tab=tableOrPartition)
-> ^(TOK_LOAD $path $tab $islocal? $isoverwrite?)
;
exportStatement
@init { msgs.push("export statement"); }
@after { msgs.pop(); }
: KW_EXPORT KW_TABLE (tab=tableOrPartition) KW_TO (path=StringLiteral)
-> ^(TOK_EXPORT $tab $path)
;
importStatement
@init { msgs.push("import statement"); }
@after { msgs.pop(); }
: KW_IMPORT ((ext=KW_EXTERNAL)? KW_TABLE (tab=tableOrPartition))? KW_FROM (path=StringLiteral) tableLocation?
-> ^(TOK_IMPORT $path $tab? $ext? tableLocation?)
;
ddlStatement
@init { msgs.push("ddl statement"); }
@after { msgs.pop(); }
: createDatabaseStatement
| switchDatabaseStatement
| dropDatabaseStatement
| createTableStatement
| dropTableStatement
| alterStatement
| descStatement
| showStatement
| metastoreCheck
| createViewStatement
| dropViewStatement
| createFunctionStatement
| createIndexStatement
| dropIndexStatement
| dropFunctionStatement
| analyzeStatement
| lockStatement
| unlockStatement
| createRoleStatement
| dropRoleStatement
| grantPrivileges
| revokePrivileges
| showGrants
| showRoleGrants
| grantRole
| revokeRole
;
ifExists
@init { msgs.push("if exists clause"); }
@after { msgs.pop(); }
: KW_IF KW_EXISTS
-> ^(TOK_IFEXISTS)
;
restrictOrCascade
@init { msgs.push("restrict or cascade clause"); }
@after { msgs.pop(); }
: KW_RESTRICT
-> ^(TOK_RESTRICT)
| KW_CASCADE
-> ^(TOK_CASCADE)
;
ifNotExists
@init { msgs.push("if not exists clause"); }
@after { msgs.pop(); }
: KW_IF KW_NOT KW_EXISTS
-> ^(TOK_IFNOTEXISTS)
;
orReplace
@init { msgs.push("or replace clause"); }
@after { msgs.pop(); }
: KW_OR KW_REPLACE
-> ^(TOK_ORREPLACE)
;
createDatabaseStatement
@init { msgs.push("create database statement"); }
@after { msgs.pop(); }
: KW_CREATE (KW_DATABASE|KW_SCHEMA)
ifNotExists?
name=Identifier
dbLocation?
databaseComment?
(KW_WITH KW_DBPROPERTIES dbprops=dbProperties)?
-> ^(TOK_CREATEDATABASE $name ifNotExists? dbLocation? databaseComment? $dbprops?)
;
dbLocation
@init { msgs.push("database location specification"); }
@after { msgs.pop(); }
:
KW_LOCATION locn=StringLiteral -> ^(TOK_DATABASELOCATION $locn)
;
dbProperties
@init { msgs.push("dbproperties"); }
@after { msgs.pop(); }
:
LPAREN dbPropertiesList RPAREN -> ^(TOK_DATABASEPROPERTIES dbPropertiesList)
;
dbPropertiesList
@init { msgs.push("database properties list"); }
@after { msgs.pop(); }
:
keyValueProperty (COMMA keyValueProperty)* -> ^(TOK_DBPROPLIST keyValueProperty+)
;
switchDatabaseStatement
@init { msgs.push("switch database statement"); }
@after { msgs.pop(); }
: KW_USE Identifier
-> ^(TOK_SWITCHDATABASE Identifier)
;
dropDatabaseStatement
@init { msgs.push("drop database statement"); }
@after { msgs.pop(); }
: KW_DROP (KW_DATABASE|KW_SCHEMA) ifExists? Identifier restrictOrCascade?
-> ^(TOK_DROPDATABASE Identifier ifExists? restrictOrCascade?)
;
databaseComment
@init { msgs.push("database's comment"); }
@after { msgs.pop(); }
: KW_COMMENT comment=StringLiteral
-> ^(TOK_DATABASECOMMENT $comment)
;
createTableStatement
@init { msgs.push("create table statement"); }
@after { msgs.pop(); }
: KW_CREATE (ext=KW_EXTERNAL)? KW_TABLE ifNotExists? name=tableName
( like=KW_LIKE likeName=tableName
tableLocation?
| (LPAREN columnNameTypeList RPAREN)?
tableComment?
tablePartition?
tableBuckets?
tableRowFormat?
tableFileFormat?
tableLocation?
tablePropertiesPrefixed?
(KW_AS selectStatement)?
)
-> ^(TOK_CREATETABLE $name $ext? ifNotExists?
^(TOK_LIKETABLE $likeName?)
columnNameTypeList?
tableComment?
tablePartition?
tableBuckets?
tableRowFormat?
tableFileFormat?
tableLocation?
tablePropertiesPrefixed?
selectStatement?
)
;
createIndexStatement
@init { msgs.push("create index statement");}
@after {msgs.pop();}
: KW_CREATE KW_INDEX indexName=Identifier
KW_ON KW_TABLE tab=tableName LPAREN indexedCols=columnNameList RPAREN
KW_AS typeName=StringLiteral
autoRebuild?
indexPropertiesPrefixed?
indexTblName?
tableRowFormat?
tableFileFormat?
tableLocation?
tablePropertiesPrefixed?
indexComment?
->^(TOK_CREATEINDEX $indexName $typeName $tab $indexedCols
autoRebuild?
indexPropertiesPrefixed?
indexTblName?
tableRowFormat?
tableFileFormat?
tableLocation?
tablePropertiesPrefixed?
indexComment?)
;
indexComment
@init { msgs.push("comment on an index");}
@after {msgs.pop();}
:
KW_COMMENT comment=StringLiteral -> ^(TOK_INDEXCOMMENT $comment)
;
autoRebuild
@init { msgs.push("auto rebuild index");}
@after {msgs.pop();}
: KW_WITH KW_DEFERRED KW_REBUILD
->^(TOK_DEFERRED_REBUILDINDEX)
;
indexTblName
@init { msgs.push("index table name");}
@after {msgs.pop();}
: KW_IN KW_TABLE indexTbl=tableName
->^(TOK_CREATEINDEX_INDEXTBLNAME $indexTbl)
;
indexPropertiesPrefixed
@init { msgs.push("table properties with prefix"); }
@after { msgs.pop(); }
:
KW_IDXPROPERTIES! indexProperties
;
indexProperties
@init { msgs.push("index properties"); }
@after { msgs.pop(); }
:
LPAREN indexPropertiesList RPAREN -> ^(TOK_INDEXPROPERTIES indexPropertiesList)
;
indexPropertiesList
@init { msgs.push("index properties list"); }
@after { msgs.pop(); }
:
keyValueProperty (COMMA keyValueProperty)* -> ^(TOK_INDEXPROPLIST keyValueProperty+)
;
dropIndexStatement
@init { msgs.push("drop index statement");}
@after {msgs.pop();}
: KW_DROP KW_INDEX ifExists? indexName=Identifier KW_ON tab=tableName
->^(TOK_DROPINDEX $indexName $tab ifExists?)
;
dropTableStatement
@init { msgs.push("drop statement"); }
@after { msgs.pop(); }
: KW_DROP KW_TABLE ifExists? tableName -> ^(TOK_DROPTABLE tableName ifExists?)
;
alterStatement
@init { msgs.push("alter statement"); }
@after { msgs.pop(); }
: KW_ALTER!
(
KW_TABLE! alterTableStatementSuffix
|
KW_VIEW! alterViewStatementSuffix
|
KW_INDEX! alterIndexStatementSuffix
|
KW_DATABASE! alterDatabaseStatementSuffix
)
;
alterTableStatementSuffix
@init { msgs.push("alter table statement"); }
@after { msgs.pop(); }
: alterStatementSuffixRename
| alterStatementSuffixAddCol
| alterStatementSuffixRenameCol
| alterStatementSuffixDropPartitions
| alterStatementSuffixAddPartitions
| alterStatementSuffixTouch
| alterStatementSuffixArchive
| alterStatementSuffixUnArchive
| alterStatementSuffixProperties
| alterStatementSuffixSerdeProperties
| alterTblPartitionStatement
| alterStatementSuffixClusterbySortby
;
alterViewStatementSuffix
@init { msgs.push("alter view statement"); }
@after { msgs.pop(); }
: alterViewSuffixProperties
| alterStatementSuffixRename
-> ^(TOK_ALTERVIEW_RENAME alterStatementSuffixRename)
| alterStatementSuffixAddPartitions
-> ^(TOK_ALTERVIEW_ADDPARTS alterStatementSuffixAddPartitions)
| alterStatementSuffixDropPartitions
-> ^(TOK_ALTERVIEW_DROPPARTS alterStatementSuffixDropPartitions)
;
alterIndexStatementSuffix
@init { msgs.push("alter index statement"); }
@after { msgs.pop(); }
: indexName=Identifier
(KW_ON tableNameId=Identifier)
partitionSpec?
(
KW_REBUILD
->^(TOK_ALTERINDEX_REBUILD $tableNameId $indexName partitionSpec?)
|
KW_SET KW_IDXPROPERTIES
indexProperties
->^(TOK_ALTERINDEX_PROPERTIES $tableNameId $indexName indexProperties)
)
;
alterDatabaseStatementSuffix
@init { msgs.push("alter database statement"); }
@after { msgs.pop(); }
: alterDatabaseSuffixProperties
;
alterDatabaseSuffixProperties
@init { msgs.push("alter database properties statement"); }
@after { msgs.pop(); }
: name=Identifier KW_SET KW_DBPROPERTIES dbProperties
-> ^(TOK_ALTERDATABASE_PROPERTIES $name dbProperties)
;
alterStatementSuffixRename
@init { msgs.push("rename statement"); }
@after { msgs.pop(); }
: oldName=Identifier KW_RENAME KW_TO newName=Identifier
-> ^(TOK_ALTERTABLE_RENAME $oldName $newName)
;
alterStatementSuffixAddCol
@init { msgs.push("add column statement"); }
@after { msgs.pop(); }
: Identifier (add=KW_ADD | replace=KW_REPLACE) KW_COLUMNS LPAREN columnNameTypeList RPAREN
-> {$add != null}? ^(TOK_ALTERTABLE_ADDCOLS Identifier columnNameTypeList)
-> ^(TOK_ALTERTABLE_REPLACECOLS Identifier columnNameTypeList)
;
alterStatementSuffixRenameCol
@init { msgs.push("rename column name"); }
@after { msgs.pop(); }
: Identifier KW_CHANGE KW_COLUMN? oldName=Identifier newName=Identifier colType (KW_COMMENT comment=StringLiteral)? alterStatementChangeColPosition?
->^(TOK_ALTERTABLE_RENAMECOL Identifier $oldName $newName colType $comment? alterStatementChangeColPosition?)
;
alterStatementChangeColPosition
: first=KW_FIRST|KW_AFTER afterCol=Identifier
->{$first != null}? ^(TOK_ALTERTABLE_CHANGECOL_AFTER_POSITION )
-> ^(TOK_ALTERTABLE_CHANGECOL_AFTER_POSITION $afterCol)
;
alterStatementSuffixAddPartitions
@init { msgs.push("add partition statement"); }
@after { msgs.pop(); }
: Identifier KW_ADD ifNotExists? partitionSpec partitionLocation? (partitionSpec partitionLocation?)*
-> ^(TOK_ALTERTABLE_ADDPARTS Identifier ifNotExists? (partitionSpec partitionLocation?)+)
;
alterStatementSuffixTouch
@init { msgs.push("touch statement"); }
@after { msgs.pop(); }
: Identifier KW_TOUCH (partitionSpec)*
-> ^(TOK_ALTERTABLE_TOUCH Identifier (partitionSpec)*)
;
alterStatementSuffixArchive
@init { msgs.push("archive statement"); }
@after { msgs.pop(); }
: Identifier KW_ARCHIVE (partitionSpec)*
-> ^(TOK_ALTERTABLE_ARCHIVE Identifier (partitionSpec)*)
;
alterStatementSuffixUnArchive
@init { msgs.push("unarchive statement"); }
@after { msgs.pop(); }
: Identifier KW_UNARCHIVE (partitionSpec)*
-> ^(TOK_ALTERTABLE_UNARCHIVE Identifier (partitionSpec)*)
;
partitionLocation
@init { msgs.push("partition location"); }
@after { msgs.pop(); }
:
KW_LOCATION locn=StringLiteral -> ^(TOK_PARTITIONLOCATION $locn)
;
alterStatementSuffixDropPartitions
@init { msgs.push("drop partition statement"); }
@after { msgs.pop(); }
: Identifier KW_DROP ifExists? partitionSpec (COMMA partitionSpec)*
-> ^(TOK_ALTERTABLE_DROPPARTS Identifier partitionSpec+ ifExists?)
;
alterStatementSuffixProperties
@init { msgs.push("alter properties statement"); }
@after { msgs.pop(); }
: name=Identifier KW_SET KW_TBLPROPERTIES tableProperties
-> ^(TOK_ALTERTABLE_PROPERTIES $name tableProperties)
;
alterViewSuffixProperties
@init { msgs.push("alter view properties statement"); }
@after { msgs.pop(); }
: name=Identifier KW_SET KW_TBLPROPERTIES tableProperties
-> ^(TOK_ALTERVIEW_PROPERTIES $name tableProperties)
;
alterStatementSuffixSerdeProperties
@init { msgs.push("alter serdes statement"); }
@after { msgs.pop(); }
: name=Identifier KW_SET KW_SERDE serdeName=StringLiteral (KW_WITH KW_SERDEPROPERTIES tableProperties)?
-> ^(TOK_ALTERTABLE_SERIALIZER $name $serdeName tableProperties?)
| name=Identifier KW_SET KW_SERDEPROPERTIES tableProperties
-> ^(TOK_ALTERTABLE_SERDEPROPERTIES $name tableProperties)
;
tablePartitionPrefix
@init {msgs.push("table partition prefix");}
@after {msgs.pop();}
:name=Identifier partitionSpec?
->^(TOK_TABLE_PARTITION $name partitionSpec?)
;
alterTblPartitionStatement
@init {msgs.push("alter table partition statement");}
@after {msgs.pop();}
: tablePartitionPrefix alterTblPartitionStatementSuffix
-> ^(TOK_ALTERTABLE_PARTITION tablePartitionPrefix alterTblPartitionStatementSuffix)
;
alterTblPartitionStatementSuffix
@init {msgs.push("alter table partition statement suffix");}
@after {msgs.pop();}
: alterStatementSuffixFileFormat
| alterStatementSuffixLocation
| alterStatementSuffixProtectMode
| alterStatementSuffixMergeFiles
;
alterStatementSuffixFileFormat
@init {msgs.push("alter fileformat statement"); }
@after {msgs.pop();}
: KW_SET KW_FILEFORMAT fileFormat
-> ^(TOK_ALTERTABLE_FILEFORMAT fileFormat)
;
alterStatementSuffixLocation
@init {msgs.push("alter location");}
@after {msgs.pop();}
: KW_SET KW_LOCATION newLoc=StringLiteral
-> ^(TOK_ALTERTABLE_LOCATION $newLoc)
;
alterStatementSuffixProtectMode
@init { msgs.push("alter partition protect mode statement"); }
@after { msgs.pop(); }
: alterProtectMode
-> ^(TOK_ALTERTABLE_ALTERPARTS_PROTECTMODE alterProtectMode)
;
alterStatementSuffixMergeFiles
@init { msgs.push(""); }
@after { msgs.pop(); }
: KW_CONCATENATE
-> ^(TOK_ALTERTABLE_ALTERPARTS_MERGEFILES)
;
alterProtectMode
@init { msgs.push("protect mode specification enable"); }
@after { msgs.pop(); }
: KW_ENABLE alterProtectModeMode -> ^(TOK_ENABLE alterProtectModeMode)
| KW_DISABLE alterProtectModeMode -> ^(TOK_DISABLE alterProtectModeMode)
;
alterProtectModeMode
@init { msgs.push("protect mode specification enable"); }
@after { msgs.pop(); }
: KW_OFFLINE -> ^(TOK_OFFLINE)
| KW_NO_DROP -> ^(TOK_NO_DROP)
| KW_READONLY -> ^(TOK_READONLY)
;
alterStatementSuffixClusterbySortby
@init {msgs.push("alter cluster by sort by statement");}
@after{msgs.pop();}
:name=Identifier tableBuckets
->^(TOK_ALTERTABLE_CLUSTER_SORT $name tableBuckets)
|
name=Identifier KW_NOT KW_CLUSTERED
->^(TOK_ALTERTABLE_CLUSTER_SORT $name)
;
fileFormat
@init { msgs.push("file format specification"); }
@after { msgs.pop(); }
: KW_SEQUENCEFILE -> ^(TOK_TBLSEQUENCEFILE)
| KW_TEXTFILE -> ^(TOK_TBLTEXTFILE)
| KW_RCFILE -> ^(TOK_TBLRCFILE)
| KW_INPUTFORMAT inFmt=StringLiteral KW_OUTPUTFORMAT outFmt=StringLiteral (KW_INPUTDRIVER inDriver=StringLiteral KW_OUTPUTDRIVER outDriver=StringLiteral)?
-> ^(TOK_TABLEFILEFORMAT $inFmt $outFmt $inDriver? $outDriver?)
| genericSpec=Identifier -> ^(TOK_FILEFORMAT_GENERIC $genericSpec)
;
tabTypeExpr
@init { msgs.push("specifying table types"); }
@after { msgs.pop(); }
: Identifier (DOT^ (Identifier | KW_ELEM_TYPE | KW_KEY_TYPE | KW_VALUE_TYPE))*
;
partTypeExpr
@init { msgs.push("specifying table partitions"); }
@after { msgs.pop(); }
: tabTypeExpr partitionSpec? -> ^(TOK_TABTYPE tabTypeExpr partitionSpec?)
;
descStatement
@init { msgs.push("describe statement"); }
@after { msgs.pop(); }
: (KW_DESCRIBE|KW_DESC) (descOptions=KW_FORMATTED|descOptions=KW_EXTENDED)? (parttype=partTypeExpr) -> ^(TOK_DESCTABLE $parttype $descOptions?)
| (KW_DESCRIBE|KW_DESC) KW_FUNCTION KW_EXTENDED? (name=descFuncNames) -> ^(TOK_DESCFUNCTION $name KW_EXTENDED?)
| (KW_DESCRIBE|KW_DESC) KW_DATABASE KW_EXTENDED? (dbName=Identifier) -> ^(TOK_DESCDATABASE $dbName KW_EXTENDED?)
;
analyzeStatement
@init { msgs.push("analyze statement"); }
@after { msgs.pop(); }
: KW_ANALYZE KW_TABLE (parttype=tableOrPartition) KW_COMPUTE KW_STATISTICS -> ^(TOK_ANALYZE $parttype)
;
showStatement
@init { msgs.push("show statement"); }
@after { msgs.pop(); }
: KW_SHOW (KW_DATABASES|KW_SCHEMAS) (KW_LIKE showStmtIdentifier)? -> ^(TOK_SHOWDATABASES showStmtIdentifier?)
| KW_SHOW KW_TABLES ((KW_FROM|KW_IN) db_name=Identifier)? (KW_LIKE showStmtIdentifier|showStmtIdentifier)? -> ^(TOK_SHOWTABLES (TOK_FROM $db_name)? showStmtIdentifier?)
| KW_SHOW KW_FUNCTIONS showStmtIdentifier? -> ^(TOK_SHOWFUNCTIONS showStmtIdentifier?)
| KW_SHOW KW_PARTITIONS Identifier partitionSpec? -> ^(TOK_SHOWPARTITIONS Identifier partitionSpec?)
| KW_SHOW KW_TABLE KW_EXTENDED ((KW_FROM|KW_IN) db_name=Identifier)? KW_LIKE showStmtIdentifier partitionSpec?
-> ^(TOK_SHOW_TABLESTATUS showStmtIdentifier $db_name? partitionSpec?)
| KW_SHOW KW_LOCKS (parttype=partTypeExpr)? (isExtended=KW_EXTENDED)? -> ^(TOK_SHOWLOCKS $parttype? $isExtended?)
| KW_SHOW (showOptions=KW_FORMATTED)? (KW_INDEX|KW_INDEXES) KW_ON showStmtIdentifier ((KW_FROM|KW_IN) db_name=Identifier)?
-> ^(TOK_SHOWINDEXES showStmtIdentifier $showOptions? $db_name?)
;
lockStatement
@init { msgs.push("lock statement"); }
@after { msgs.pop(); }
: KW_LOCK KW_TABLE tableName partitionSpec? lockMode -> ^(TOK_LOCKTABLE tableName lockMode partitionSpec?)
;
lockMode
@init { msgs.push("lock mode"); }
@after { msgs.pop(); }
: KW_SHARED | KW_EXCLUSIVE
;
unlockStatement
@init { msgs.push("unlock statement"); }
@after { msgs.pop(); }
: KW_UNLOCK KW_TABLE tableName partitionSpec? -> ^(TOK_UNLOCKTABLE tableName partitionSpec?)
;
createRoleStatement
@init { msgs.push("create role"); }
@after { msgs.pop(); }
: KW_CREATE kwRole roleName=Identifier
-> ^(TOK_CREATEROLE $roleName)
;
dropRoleStatement
@init {msgs.push("drop role");}
@after {msgs.pop();}
: KW_DROP kwRole roleName=Identifier
-> ^(TOK_DROPROLE $roleName)
;
grantPrivileges
@init {msgs.push("grant privileges");}
@after {msgs.pop();}
: KW_GRANT privList=privilegeList
privilegeObject?
KW_TO principalSpecification
(KW_WITH withOption)?
-> ^(TOK_GRANT $privList principalSpecification privilegeObject? withOption?)
;
revokePrivileges
@init {msgs.push("revoke privileges");}
@afer {msgs.pop();}
: KW_REVOKE privilegeList privilegeObject? KW_FROM principalSpecification
-> ^(TOK_REVOKE privilegeList principalSpecification privilegeObject?)
;
grantRole
@init {msgs.push("grant role");}
@after {msgs.pop();}
: KW_GRANT kwRole Identifier (COMMA Identifier)* KW_TO principalSpecification
-> ^(TOK_GRANT_ROLE principalSpecification Identifier+)
;
revokeRole
@init {msgs.push("revoke role");}
@after {msgs.pop();}
: KW_REVOKE kwRole Identifier (COMMA Identifier)* KW_FROM principalSpecification
-> ^(TOK_REVOKE_ROLE principalSpecification Identifier+)
;
showRoleGrants
@init {msgs.push("show role grants");}
@after {msgs.pop();}
: KW_SHOW kwRole KW_GRANT principalName
-> ^(TOK_SHOW_ROLE_GRANT principalName)
;
showGrants
@init {msgs.push("show grants");}
@after {msgs.pop();}
: KW_SHOW KW_GRANT principalName privilegeIncludeColObject?
-> ^(TOK_SHOW_GRANT principalName privilegeIncludeColObject?)
;
privilegeIncludeColObject
@init {msgs.push("privilege object including columns");}
@after {msgs.pop();}
: KW_ON (table=KW_TABLE|KW_DATABASE) Identifier (LPAREN cols=columnNameList RPAREN)? partitionSpec?
-> ^(TOK_PRIV_OBJECT_COL Identifier $table? $cols? partitionSpec?)
;
privilegeObject
@init {msgs.push("privilege subject");}
@after {msgs.pop();}
: KW_ON (table=KW_TABLE|KW_DATABASE) Identifier partitionSpec?
-> ^(TOK_PRIV_OBJECT Identifier $table? partitionSpec?)
;
privilegeList
@init {msgs.push("grant privilege list");}
@after {msgs.pop();}
: privlegeDef (COMMA privlegeDef)*
-> ^(TOK_PRIVILEGE_LIST privlegeDef+)
;
privlegeDef
@init {msgs.push("grant privilege");}
@after {msgs.pop();}
: privilegeType (LPAREN cols=columnNameList RPAREN)?
-> ^(TOK_PRIVILEGE privilegeType $cols?)
;
privilegeType
@init {msgs.push("privilege type");}
@after {msgs.pop();}
: KW_ALL -> ^(TOK_PRIV_ALL)
| KW_ALTER -> ^(TOK_PRIV_ALTER_METADATA)
| KW_UPDATE -> ^(TOK_PRIV_ALTER_DATA)
| KW_CREATE -> ^(TOK_PRIV_CREATE)
| KW_DROP -> ^(TOK_PRIV_DROP)
| KW_INDEX -> ^(TOK_PRIV_INDEX)
| KW_LOCK -> ^(TOK_PRIV_LOCK)
| KW_SELECT -> ^(TOK_PRIV_SELECT)
| KW_SHOW_DATABASE -> ^(TOK_PRIV_SHOW_DATABASE)
;
principalSpecification
@init { msgs.push("user/group/role name list"); }
@after { msgs.pop(); }
: principalName (COMMA principalName)* -> ^(TOK_PRINCIPAL_NAME principalName+)
;
principalName
@init {msgs.push("user|group|role name");}
@after {msgs.pop();}
: kwUser Identifier -> ^(TOK_USER Identifier)
| KW_GROUP Identifier -> ^(TOK_GROUP Identifier)
| kwRole Identifier -> ^(TOK_ROLE Identifier)
;
withOption
@init {msgs.push("grant with option");}
@after {msgs.pop();}
: KW_GRANT KW_OPTION
-> ^(TOK_GRANT_WITH_OPTION)
;
metastoreCheck
@init { msgs.push("metastore check statement"); }
@after { msgs.pop(); }
: KW_MSCK (repair=KW_REPAIR)? (KW_TABLE table=Identifier partitionSpec? (COMMA partitionSpec)*)?
-> ^(TOK_MSCK $repair? ($table partitionSpec*)?)
;
createFunctionStatement
@init { msgs.push("create function statement"); }
@after { msgs.pop(); }
: KW_CREATE KW_TEMPORARY KW_FUNCTION Identifier KW_AS StringLiteral
-> ^(TOK_CREATEFUNCTION Identifier StringLiteral)
;
dropFunctionStatement
@init { msgs.push("drop temporary function statement"); }
@after { msgs.pop(); }
: KW_DROP KW_TEMPORARY KW_FUNCTION ifExists? Identifier
-> ^(TOK_DROPFUNCTION Identifier ifExists?)