-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGoogleSQLParser.g4
2061 lines (1621 loc) · 63.3 KB
/
GoogleSQLParser.g4
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
parser grammar GoogleSQLParser;
options {
tokenVocab = GoogleSQLLexer;
}
root: stmts EOF;
stmts: stmt (SEMI_SYMBOL stmt)* SEMI_SYMBOL?;
stmt:
statement_level_hint? (
query_statement
| alter_statement
| analyze_statement
| assert_statement
| aux_load_data_statement
| clone_data_statement
| dml_statement
| merge_statement
| truncate_statement
| begin_statement
| set_statement
| commit_statement
| start_batch_statement
| run_batch_statement
| abort_batch_statement
| create_constant_statement
| create_connection_statement
| create_database_statement
| create_function_statement
| rollback_statement
);
create_function_statement:
CREATE_SYMBOL opt_or_replace? opt_create_scope? opt_aggregate? FUNCTION_SYMBOL opt_if_not_exists
? function_declaration opt_function_returns? opt_sql_security_clause? opt_determinism_level?
opt_language_or_remote_with_connection? unordered_options_body?;
opt_determinism_level:
DETERMINISTIC_SYMBOL
| NOT_SYMBOL DETERMINISTIC_SYMBOL
| IMMUTABLE_SYMBOL
| STABLE_SYMBOL
| VOLATILE_SYMBOL;
opt_sql_security_clause:
SQL_SYMBOL SECURITY_SYMBOL sql_security_clause_kind;
sql_security_clause_kind: INVOKER_SYMBOL | DEFINER_SYMBOL;
as_sql_function_body_or_string:
AS_SYMBOL sql_function_body
| AS_SYMBOL string_literal;
sql_function_body:
LR_BRACKET_SYMBOL expression RR_BRACKET_SYMBOL
| LR_BRACKET_SYMBOL SELECT_SYMBOL {
p.NotifyErrorListeners("The body of each CREATE FUNCTION statement is an expression, not a query; to use a query as an expression, the query must be wrapped with additional parentheses to make it a scalar subquery expression", nil, nil)
};
unordered_options_body:
opt_options_list as_sql_function_body_or_string?
| as_sql_function_body_or_string opt_options_list?;
opt_language_or_remote_with_connection:
LANGUAGE_SYMBOL identifier remote_with_connection_clause?
| remote_with_connection_clause language?;
language: LANGUAGE_SYMBOL identifier;
remote_with_connection_clause:
REMOTE_SYMBOL with_connection_clause?
| with_connection_clause;
with_connection_clause: WITH_SYMBOL connection_clause;
opt_function_returns: opt_returns;
opt_returns: RETURNS_SYMBOL type_or_tvf_schema;
function_declaration: path_expression function_parameters;
function_parameters:
LR_BRACKET_SYMBOL (
function_parameter (COMMA_SYMBOL function_parameter)*
)? RR_BRACKET_SYMBOL;
function_parameter:
identifier type_or_tvf_schema opt_as_alias_with_required_as? opt_default_expression?
opt_not_aggregate?
| type_or_tvf_schema opt_as_alias_with_required_as? opt_not_aggregate?;
opt_not_aggregate: NOT_SYMBOL AGGREGATE_SYMBOL;
opt_default_expression: DEFAULT_SYMBOL expression;
type_or_tvf_schema:
type
| templated_parameter_type
| tvf_schema;
tvf_schema:
TABLE_SYMBOL template_type_open tvf_schema_column (
COMMA_SYMBOL tvf_schema_column
)* template_type_close;
tvf_schema_column: identifier type | type;
templated_parameter_type: ANY_SYMBOL templated_parameter_kind;
templated_parameter_kind:
PROTO_SYMBOL
| ENUM_SYMBOL
| STRUCT_SYMBOL
| ARRAY_SYMBOL
| identifier;
opt_aggregate: AGGREGATE_SYMBOL;
create_database_statement:
CREATE_SYMBOL DATABASE_SYMBOL path_expression opt_options_list?;
create_connection_statement:
CREATE_SYMBOL opt_or_replace? CONNECTION_SYMBOL opt_if_not_exists? path_expression
opt_options_list?;
create_constant_statement:
CREATE_SYMBOL opt_or_replace? opt_create_scope? CONSTANT_SYMBOL opt_if_not_exists?
path_expression EQUAL_OPERATOR expression;
opt_or_replace: OR_SYMBOL REPLACE_SYMBOL;
opt_create_scope:
TEMP_SYMBOL
| TEMPORARY_SYMBOL
| PUBLIC_SYMBOL
| PRIVATE_SYMBOL;
run_batch_statement: RUN_SYMBOL BATCH_SYMBOL;
abort_batch_statement: ABORT_SYMBOL BATCH_SYMBOL;
start_batch_statement: START_SYMBOL BATCH_SYMBOL identifier?;
rollback_statement: ROLLBACK_SYMBOL TRANSACTION_SYMBOL?;
commit_statement: COMMIT_SYMBOL TRANSACTION_SYMBOL?;
set_statement:
SET_SYMBOL TRANSACTION_SYMBOL transaction_mode_list
| SET_SYMBOL identifier EQUAL_OPERATOR expression
| SET_SYMBOL named_parameter_expression EQUAL_OPERATOR expression
| SET_SYMBOL system_variable_expression EQUAL_OPERATOR expression
| SET_SYMBOL LR_BRACKET_SYMBOL identifier_list RR_BRACKET_SYMBOL EQUAL_OPERATOR expression
| SET_SYMBOL identifier COMMA_SYMBOL identifier EQUAL_OPERATOR {
p.NotifyErrorListeners("Using SET with multiple variable required parentheses around the variable list", nil, nil)
};
identifier_list: identifier (COMMA_SYMBOL identifier)*;
begin_statement:
begin_transaction_keywords transaction_mode_list?;
begin_transaction_keywords:
START_SYMBOL TRANSACTION_SYMBOL
| BEGIN_SYMBOL TRANSACTION_SYMBOL?;
transaction_mode_list:
transaction_mode (COMMA_SYMBOL transaction_mode)*;
transaction_mode:
READ_SYMBOL ONLY_SYMBOL
| READ_SYMBOL WRITE_SYMBOL
| ISOLATION_SYMBOL LEVEL_SYMBOL identifier
| ISOLATION_SYMBOL LEVEL_SYMBOL identifier identifier;
truncate_statement:
TRUNCATE_SYMBOL TABLE_SYMBOL maybe_dashed_path_expression opt_where_expression?;
merge_statement:
MERGE_SYMBOL INTO_SYMBOL? maybe_dashed_path_expression as_alias? USING_SYMBOL merge_source
ON_SYMBOL expression (merge_when_clause)+;
merge_source: table_path_expression | table_subquery;
merge_when_clause:
WHEN_SYMBOL MATCHED_SYMBOL opt_and_expression? THEN_SYMBOL merge_action
| WHEN_SYMBOL NOT_SYMBOL MATCHED_SYMBOL by_target? opt_and_expression? THEN_SYMBOL merge_action
| WHEN_SYMBOL NOT_SYMBOL MATCHED_SYMBOL BY_SYMBOL SOURCE_SYMBOL opt_and_expression? THEN_SYMBOL
merge_action;
merge_action:
INSERT_SYMBOL column_list? merge_insert_value_list_or_source_row
| UPDATE_SYMBOL SET_SYMBOL update_item_list
| DELETE_SYMBOL;
merge_insert_value_list_or_source_row:
VALUES_SYMBOL insert_values_row
| ROW_SYMBOL;
by_target: BY_SYMBOL TARGET_SYMBOL;
opt_and_expression: AND_SYMBOL expression;
statement_level_hint: hint;
// query_statement: https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax
query_statement: query;
dml_statement:
insert_statement
| delete_statement
| update_statement;
update_statement:
UPDATE_SYMBOL maybe_dashed_generalized_path_expression hint? as_alias? opt_with_offset_and_alias
? SET_SYMBOL update_item_list from_clause? opt_where_expression? opt_assert_rows_modified?
opt_returning_clause?;
delete_statement:
DELETE_SYMBOL FROM_SYMBOL? maybe_dashed_generalized_path_expression hint? as_alias?
opt_with_offset_and_alias? opt_where_expression? opt_assert_rows_modified?
opt_returning_clause?;
insert_statement:
insert_statement_prefix column_list? insert_values_or_query opt_assert_rows_modified?
opt_returning_clause?
| insert_statement_prefix column_list? insert_values_list_or_table_clause on_conflict_clause
opt_assert_rows_modified? opt_returning_clause?
| insert_statement_prefix column_list? LR_BRACKET_SYMBOL query RR_BRACKET_SYMBOL
on_conflict_clause opt_assert_rows_modified? opt_returning_clause?;
on_conflict_clause:
ON_SYMBOL CONFLICT_SYMBOL opt_conflict_target? DO_SYMBOL NOTHING_SYMBOL
| ON_SYMBOL CONFLICT_SYMBOL opt_conflict_target? DO_SYMBOL UPDATE_SYMBOL SET_SYMBOL
update_item_list opt_where_expression?;
opt_where_expression: WHERE_SYMBOL expression;
opt_conflict_target:
column_list
| ON_SYMBOL UNIQUE_SYMBOL CONSTRAINT_SYMBOL identifier;
update_item_list: update_item (COMMA_SYMBOL update_item)*;
update_item: update_set_value | nested_dml_statement;
update_set_value:
generalized_path_expression EQUAL_OPERATOR expression_or_default;
nested_dml_statement:
LR_BRACKET_SYMBOL dml_statement RR_BRACKET_SYMBOL;
insert_values_list_or_table_clause:
insert_values_list
| table_clause_unreversed;
table_clause_unreversed: TABLE_SYMBOL table_clause_no_keyword;
table_clause_no_keyword:
path_expression where_clause?
| tvf_with_suffixes where_clause?;
opt_returning_clause:
THEN_SYMBOL RETURN_SYMBOL select_list
| THEN_SYMBOL RETURN_SYMBOL WITH_SYMBOL ACTION_SYMBOL select_list
| THEN_SYMBOL RETURN_SYMBOL WITH_SYMBOL ACTION_SYMBOL AS_SYMBOL identifier select_list;
opt_assert_rows_modified:
ASSERT_ROWS_MODIFIED_SYMBOL possibly_cast_int_literal_or_parameter;
insert_values_or_query: insert_values_list | query;
insert_values_list:
VALUES_SYMBOL insert_values_row (
COMMA_SYMBOL insert_values_row
)*;
insert_values_row:
LR_BRACKET_SYMBOL expression_or_default (
COMMA_SYMBOL expression_or_default
)* RR_BRACKET_SYMBOL;
expression_or_default: expression | DEFAULT_SYMBOL;
insert_statement_prefix:
INSERT_SYMBOL opt_or_ignore_replace_update? opt_into? maybe_dashed_generalized_path_expression
hint?;
maybe_dashed_generalized_path_expression:
generalized_path_expression
| dashed_path_expression;
opt_into: INTO_SYMBOL;
opt_or_ignore_replace_update:
OR_SYMBOL IGNORE_SYMBOL
| IGNORE_SYMBOL
| OR_SYMBOL REPLACE_SYMBOL
| REPLACE_SYMBOL
| OR_SYMBOL UPDATE_SYMBOL
| UPDATE_SYMBOL;
alter_statement:
ALTER_SYMBOL table_or_table_function opt_if_exists? maybe_dashed_path_expression
alter_action_list
| ALTER_SYMBOL schema_object_kind opt_if_exists? path_expression alter_action_list
| ALTER_SYMBOL generic_entity_type opt_if_exists? path_expression alter_action_list
| ALTER_SYMBOL generic_entity_type opt_if_exists? alter_action_list
| ALTER_SYMBOL PRIVILEGE_SYMBOL RESTRICTION_SYMBOL opt_if_exists? ON_SYMBOL privilege_list
ON_SYMBOL identifier path_expression
| ALTER_SYMBOL ROW_SYMBOL ACCESS_SYMBOL POLICY_SYMBOL opt_if_exists? identifier ON_SYMBOL
path_expression row_access_policy_alter_action_list
| ALTER_SYMBOL ALL_SYMBOL ROW_SYMBOL ACCESS_SYMBOL POLICIES_SYMBOL ON_SYMBOL path_expression
row_access_policy_alter_action;
analyze_statement:
ANALYZE_SYMBOL opt_options_list? table_and_column_info_list?;
assert_statement: ASSERT_SYMBOL expression opt_description?;
aux_load_data_statement:
LOAD_SYMBOL DATA_SYMBOL append_or_overwrite maybe_dashed_path_expression_with_scope
table_element_list? load_data_partitions_clause? collate_clause?
partition_by_clause_prefix_no_hint? cluster_by_clause_prefix_no_hint? opt_options_list?
aux_load_data_from_files_options_list opt_external_table_with_clauses?;
clone_data_statement:
CLONE_SYMBOL DATA_SYMBOL INTO_SYMBOL maybe_dashed_path_expression FROM_SYMBOL
clone_data_source_list;
clone_data_source_list:
clone_data_source (UNION_SYMBOL ALL_SYMBOL clone_data_source)*;
clone_data_source:
maybe_dashed_path_expression opt_at_system_time? where_clause?;
opt_external_table_with_clauses:
with_partition_columns_clause with_connection_clause
| with_partition_columns_clause
| with_connection_clause;
with_partition_columns_clause:
WITH_SYMBOL PARTITION_SYMBOL COLUMNS_SYMBOL table_element_list?;
aux_load_data_from_files_options_list:
FROM_SYMBOL FILES_SYMBOL options_list;
cluster_by_clause_prefix_no_hint:
CLUSTER_SYMBOL BY_SYMBOL expression (COMMA_SYMBOL expression)*;
load_data_partitions_clause:
OVERWRITE_SYMBOL? PARTITIONS_SYMBOL LR_BRACKET_SYMBOL expression RR_BRACKET_SYMBOL;
maybe_dashed_path_expression_with_scope:
TEMP_SYMBOL TABLE_SYMBOL maybe_dashed_path_expression
| TEMPORARY_SYMBOL TABLE_SYMBOL maybe_dashed_path_expression
| maybe_dashed_path_expression;
table_element_list:
LR_BRACKET_SYMBOL (
table_element (COMMA_SYMBOL table_element)* COMMA_SYMBOL?
)? RR_BRACKET_SYMBOL;
table_element:
table_column_definition
| table_constraint_definition;
table_constraint_definition:
primary_key_spec
| table_constraint_spec
| identifier identifier table_constraint_spec;
append_or_overwrite: INTO_SYMBOL | OVERWRITE_SYMBOL;
opt_description: AS_SYMBOL string_literal;
table_and_column_info_list:
table_and_column_info (COMMA_SYMBOL table_and_column_info)*;
table_and_column_info:
maybe_dashed_path_expression column_list?;
row_access_policy_alter_action_list:
row_access_policy_alter_action (
COMMA_SYMBOL row_access_policy_alter_action
)*;
row_access_policy_alter_action:
grant_to_clause
| FILTER_SYMBOL USING_SYMBOL LR_BRACKET_SYMBOL expression RR_BRACKET_SYMBOL
| REVOKE_SYMBOL FROM_SYMBOL LR_BRACKET_SYMBOL grantee_list RR_BRACKET_SYMBOL
| REVOKE_SYMBOL FROM_SYMBOL ALL_SYMBOL
| RENAME_SYMBOL TO_SYMBOL identifier;
grant_to_clause:
GRANT_SYMBOL TO_SYMBOL LR_BRACKET_SYMBOL grantee_list RR_BRACKET_SYMBOL;
grantee_list:
string_literal_or_parameter (
COMMA_SYMBOL string_literal_or_parameter
)*;
privilege_list: privilege (COMMA_SYMBOL privilege)*;
privilege: privilege_name path_expression_list_with_parens?;
path_expression_list_with_parens:
LR_BRACKET_SYMBOL path_expression_list RR_BRACKET_SYMBOL;
privilege_name: identifier | SELECT_SYMBOL;
generic_entity_type: generic_entity_type_unchecked;
generic_entity_type_unchecked: IDENTIFIER | PROJECT_SYMBOL;
schema_object_kind:
AGGREGATE_SYMBOL FUNCTION_SYMBOL
| APPROX_SYMBOL VIEW_SYMBOL
| CONNECTION_SYMBOL
| CONSTANT_SYMBOL
| DATABASE_SYMBOL
| EXTERNAL_SYMBOL table_or_table_function
| EXTERNAL_SYMBOL SCHEMA_SYMBOL
| FUNCTION_SYMBOL
| INDEX_SYMBOL
| MATERIALIZED_SYMBOL VIEW_SYMBOL
| MODEL_SYMBOL
| PROCEDURE_SYMBOL
| SCHEMA_SYMBOL
| VIEW_SYMBOL;
alter_action_list: alter_action (COMMA_SYMBOL alter_action)*;
alter_action:
SET_SYMBOL OPTIONS_SYMBOL options_list
| SET_SYMBOL AS_SYMBOL generic_entity_body
| ADD_SYMBOL table_constraint_spec
| ADD_SYMBOL primary_key_spec
| ADD_SYMBOL CONSTRAINT_SYMBOL opt_if_not_exists? identifier
primary_key_or_table_constraint_spec
| DROP_SYMBOL CONSTRAINT_SYMBOL opt_if_exists? identifier
| DROP_SYMBOL PRIMARY_SYMBOL KEY_SYMBOL opt_if_exists?
| ALTER_SYMBOL CONSTRAINT_SYMBOL opt_if_exists? identifier constraint_enforcement
| ALTER_SYMBOL CONSTRAINT_SYMBOL opt_if_exists? identifier SET_SYMBOL OPTIONS_SYMBOL
options_list
| ADD_SYMBOL COLUMN_SYMBOL opt_if_not_exists? table_column_definition column_position?
fill_using_expression?
| DROP_SYMBOL COLUMN_SYMBOL opt_if_exists? identifier
| RENAME_SYMBOL COLUMN_SYMBOL opt_if_exists? identifier TO_SYMBOL identifier
| ALTER_SYMBOL COLUMN_SYMBOL opt_if_exists? identifier SET_SYMBOL DATA_SYMBOL TYPE_SYMBOL
field_schema
| ALTER_SYMBOL COLUMN_SYMBOL opt_if_exists? identifier SET_SYMBOL OPTIONS_SYMBOL options_list
| ALTER_SYMBOL COLUMN_SYMBOL opt_if_exists? identifier SET_SYMBOL DEFAULT_SYMBOL expression
| ALTER_SYMBOL COLUMN_SYMBOL opt_if_exists? identifier DROP_SYMBOL DEFAULT_SYMBOL
| ALTER_SYMBOL COLUMN_SYMBOL opt_if_exists? identifier DROP_SYMBOL NOT_SYMBOL NULL_SYMBOL
| ALTER_SYMBOL COLUMN_SYMBOL opt_if_exists? identifier DROP_SYMBOL GENERATED_SYMBOL
| RENAME_SYMBOL TO_SYMBOL path_expression
| SET_SYMBOL DEFAULT_SYMBOL collate_clause
| ADD_SYMBOL ROW_SYMBOL DELETION_SYMBOL POLICY_SYMBOL opt_if_not_exists? LR_BRACKET_SYMBOL
expression RR_BRACKET_SYMBOL
| REPLACE_SYMBOL ROW_SYMBOL DELETION_SYMBOL POLICY_SYMBOL opt_if_exists? LR_BRACKET_SYMBOL
expression RR_BRACKET_SYMBOL
| DROP_SYMBOL ROW_SYMBOL DELETION_SYMBOL POLICY_SYMBOL opt_if_exists?
| ALTER_SYMBOL generic_sub_entity_type opt_if_exists? identifier alter_action
| ADD_SYMBOL generic_sub_entity_type opt_if_not_exists? identifier
| DROP_SYMBOL generic_sub_entity_type opt_if_exists? identifier
| spanner_alter_column_action
| spanner_set_on_delete_action;
spanner_set_on_delete_action:
SET_SYMBOL ON_SYMBOL DELETE_SYMBOL foreign_key_action;
spanner_alter_column_action:
ALTER_SYMBOL COLUMN_SYMBOL opt_if_exists? identifier column_schema_inner
not_null_column_attribute? spanner_generated_or_default? opt_options_list?;
spanner_generated_or_default:
AS_SYMBOL LR_BRACKET_SYMBOL expression RR_BRACKET_SYMBOL STORED_SYMBOL;
generic_sub_entity_type: sub_entity_type_identifier;
sub_entity_type_identifier: IDENTIFIER | REPLICA_SYMBOL;
fill_using_expression: FILL_SYMBOL USING_SYMBOL expression;
column_position:
PRECEDING_SYMBOL identifier
| FOLLOWING_SYMBOL identifier;
table_column_definition:
identifier table_column_schema column_attributes? opt_options_list?;
column_attributes: column_attribute+ constraint_enforcement?;
column_attribute:
primary_key_column_attribute
| foreign_key_column_attribute
| hidden_column_attribute
| not_null_column_attribute;
primary_key_column_attribute: PRIMARY_SYMBOL KEY_SYMBOL;
foreign_key_column_attribute:
opt_constraint_identity? foreign_key_reference;
hidden_column_attribute: HIDDEN_SYMBOL;
opt_constraint_identity: CONSTRAINT_SYMBOL identifier;
table_column_schema:
column_schema_inner collate_clause? opt_column_info?
| generated_column_info;
opt_column_info:
generated_column_info invalid_default_column? {
if localctx.Invalid_default_column() != nil {
p.NotifyErrorListeners("Syntax error: \"DEFAULT\" and \"GENERATED ALWAYS AS\" clauses must not be both provided for the column", nil, nil)
}
}
| default_column_info invalid_generated_column? {
if localctx.Invalid_generated_column() != nil {
p.NotifyErrorListeners("Syntax error: \"DEFAULT\" and \"GENERATED ALWAYS AS\" clauses must not be both provided for the column", nil, nil)
}
};
invalid_generated_column: generated_column_info;
invalid_default_column: default_column_info;
default_column_info: DEFAULT_SYMBOL expression;
generated_column_info:
generated_mode LR_BRACKET_SYMBOL expression RR_BRACKET_SYMBOL stored_mode?
| generated_mode identity_column_info;
identity_column_info:
IDENTITY_SYMBOL LR_BRACKET_SYMBOL opt_start_with? opt_increment_by? opt_maxvalue? opt_minvalue?
opt_cycle? RR_BRACKET_SYMBOL;
opt_start_with: START_SYMBOL WITH_SYMBOL signed_numeric_literal;
opt_increment_by:
INCREMENT_SYMBOL BY_SYMBOL signed_numeric_literal;
opt_maxvalue: MAXVALUE_SYMBOL signed_numeric_literal;
opt_minvalue: MINVALUE_SYMBOL signed_numeric_literal;
opt_cycle: CYCLE_SYMBOL | NO_SYMBOL CYCLE_SYMBOL;
signed_numeric_literal:
integer_literal
| numeric_literal
| bignumeric_literal
| floating_point_literal
| MINUS_OPERATOR integer_literal
| MINUS_OPERATOR floating_point_literal;
// All rules reference stored_mode should make stored_mode optional.
stored_mode: STORED_SYMBOL VOLATILE_SYMBOL | STORED_SYMBOL;
generated_mode:
GENERATED_SYMBOL AS_SYMBOL
| GENERATED_SYMBOL ALWAYS_SYMBOL AS_SYMBOL
| GENERATED_SYMBOL BY_SYMBOL DEFAULT_SYMBOL AS_SYMBOL
| AS_SYMBOL;
column_schema_inner:
raw_column_schema_inner opt_type_parameters?;
raw_column_schema_inner:
simple_column_schema_inner
| array_column_schema_inner
| struct_column_schema_inner
| range_column_schema_inner;
range_column_schema_inner:
RANGE_SYMBOL template_type_open field_schema template_type_close;
struct_column_schema_inner:
STRUCT_SYMBOL template_type_open (
struct_column_field (COMMA_SYMBOL struct_column_field)*
)? template_type_close;
struct_column_field:
column_schema_inner collate_clause? opt_field_attributes?
| identifier field_schema;
simple_column_schema_inner: path_expression | INTERVAL_SYMBOL;
array_column_schema_inner:
ARRAY_SYMBOL template_type_open field_schema template_type_close;
field_schema:
column_schema_inner collate_clause? opt_field_attributes? opt_options_list?;
opt_field_attributes: not_null_column_attribute;
not_null_column_attribute: NOT_SYMBOL NULL_SYMBOL;
primary_key_or_table_constraint_spec:
primary_key_spec
| table_constraint_spec;
opt_if_not_exists: IF_SYMBOL NOT_SYMBOL EXISTS_SYMBOL;
primary_key_spec:
PRIMARY_SYMBOL KEY_SYMBOL primary_key_element_list constraint_enforcement? opt_options_list?;
primary_key_element_list:
LR_BRACKET_SYMBOL (
primary_key_element (COMMA_SYMBOL primary_key_element)*
)? RR_BRACKET_SYMBOL;
primary_key_element: identifier asc_or_desc? null_order?;
table_constraint_spec:
CHECK_SYMBOL LR_BRACKET_SYMBOL expression RR_BRACKET_SYMBOL constraint_enforcement?
opt_options_list?
| FOREIGN_SYMBOL KEY_SYMBOL column_list foreign_key_reference constraint_enforcement?
opt_options_list?;
foreign_key_reference:
REFERENCES_SYMBOL path_expression column_list opt_foreign_key_match? opt_foreign_key_action?;
opt_foreign_key_action:
foreign_key_on_update foreign_key_on_delete?
| foreign_key_on_delete foreign_key_on_update?;
foreign_key_on_update:
ON_SYMBOL UPDATE_SYMBOL foreign_key_action;
foreign_key_on_delete:
ON_SYMBOL DELETE_SYMBOL foreign_key_action;
foreign_key_action:
NO_SYMBOL ACTION_SYMBOL
| RESTRICT_SYMBOL
| CASCADE_SYMBOL
| SET_SYMBOL NULL_SYMBOL;
opt_foreign_key_match: MATCH_SYMBOL foreign_key_match_mode;
foreign_key_match_mode:
SIMPLE_SYMBOL
| FULL_SYMBOL
| NOT_SYMBOL DISTINCT_SYMBOL;
column_list:
LR_BRACKET_SYMBOL identifier (COMMA_SYMBOL identifier)* RR_BRACKET_SYMBOL;
opt_options_list: OPTIONS_SYMBOL options_list;
constraint_enforcement: NOT_SYMBOL? ENFORCED_SYMBOL;
generic_entity_body: json_literal | string_literal;
opt_if_exists: IF_SYMBOL EXISTS_SYMBOL;
table_or_table_function: TABLE_SYMBOL FUNCTION_SYMBOL?;
query: query_without_pipe_operators;
query_without_pipe_operators:
with_clause query_primary_or_set_operation order_by_clause? limit_offset_clause?
| with_clause_with_trailing_comma select_or_from_keyword {p.NotifyErrorListeners("Syntax error: Trailing comma after the WITH clause before the main query is not allowed", nil, nil)
}
| with_clause PIPE_SYMBOL {p.NotifyErrorListeners("Syntax error: A pipe operator cannot follow the WITH clause before the main query; The main query usually starts with SELECT or FROM here", nil, nil)
}
| query_primary_or_set_operation order_by_clause? limit_offset_clause?
| with_clause? from_clause {p.NotifyErrorListeners("Syntax error: Unexpected FROM", nil, nil)}
// FIXME(zp): Inject the keyword from original input.
| with_clause? from_clause bad_keyword_after_from_query {p.NotifyErrorListeners("Syntax error: <KEYWORD> not supported after FROM query; Consider using pipe operator `|>` ", nil, nil)
}
| with_clause? from_clause bad_keyword_after_from_query_allows_parens {p.NotifyErrorListeners("Syntax error: <KEYWORD> not supported after FROM query; Consider using pipe operator `|>` ", nil, nil)
};
bad_keyword_after_from_query:
WHERE_SYMBOL
| SELECT_SYMBOL
| GROUP_SYMBOL;
bad_keyword_after_from_query_allows_parens:
ORDER_SYMBOL
| UNION_SYMBOL
| INTERSECT_SYMBOL
| EXCEPT_SYMBOL
| LIMIT_SYMBOL;
with_clause_with_trailing_comma: with_clause COMMA_SYMBOL;
select_or_from_keyword: SELECT_SYMBOL | FROM_SYMBOL;
query_primary_or_set_operation:
query_primary
| query_set_operation;
query_set_operation: query_set_operation_prefix;
query_set_operation_prefix:
query_primary query_set_operation_item+
| query_primary set_operation_metadata FROM_SYMBOL { p.NotifyErrorListeners("Syntax error: Unexpected FROM;FROM queries following a set operation must be parenthesized", nil, nil);
}
| query_set_operation_prefix set_operation_metadata FROM_SYMBOL { p.NotifyErrorListeners("Syntax error: Unexpected FROM;FROM queries following a set operation must be parenthesized", nil, nil);
};
query_set_operation_item: set_operation_metadata query_primary;
query_primary:
select
| parenthesized_query opt_as_alias_with_required_as?;
set_operation_metadata:
opt_corresponding_outer_mode? query_set_operation_type hint? all_or_distinct opt_strict?
opt_column_match_suffix?;
opt_column_match_suffix:
CORRESPONDING_SYMBOL
| CORRESPONDING_SYMBOL BY_SYMBOL;
opt_strict: STRICT_SYMBOL;
all_or_distinct: ALL_SYMBOL | DISTINCT_SYMBOL;
query_set_operation_type:
UNION_SYMBOL
| EXCEPT_SYMBOL
| INTERSECT_SYMBOL;
opt_corresponding_outer_mode:
FULL_SYMBOL opt_outer?
| OUTER_SYMBOL
| LEFT_SYMBOL opt_outer?;
opt_outer: OUTER_SYMBOL;
with_clause:
WITH_SYMBOL RECURSIVE_SYMBOL? aliased_query (
COMMA_SYMBOL aliased_query
)*;
aliased_query:
identifier AS_SYMBOL parenthesized_query opt_aliased_query_modifiers?;
opt_aliased_query_modifiers: recursion_depth_modifier;
recursion_depth_modifier:
WITH_SYMBOL DEPTH_SYMBOL opt_as_alias_with_required_as?
| WITH_SYMBOL DEPTH_SYMBOL opt_as_alias_with_required_as? BETWEEN_SYMBOL
possibly_unbounded_int_literal_or_parameter AND_SYMBOL
possibly_unbounded_int_literal_or_parameter
| WITH_SYMBOL DEPTH_SYMBOL opt_as_alias_with_required_as? MAX_SYMBOL
possibly_unbounded_int_literal_or_parameter;
possibly_unbounded_int_literal_or_parameter:
int_literal_or_parameter
| UNBOUNDED_SYMBOL;
int_literal_or_parameter:
integer_literal
| parameter_expression
| system_variable_expression;
order_by_clause: order_by_clause_prefix;
order_by_clause_prefix:
ORDER_SYMBOL hint? BY_SYMBOL ordering_expression (
COMMA_SYMBOL ordering_expression
)*;
ordering_expression:
expression collate_clause? asc_or_desc? null_order?;
select: select_clause from_clause? opt_clauses_following_from?;
opt_clauses_following_from:
where_clause group_by_clause? having_clause? qualify_clause_nonreserved? window_clause?
| opt_clauses_following_where;
opt_clauses_following_where:
group_by_clause having_clause? qualify_clause_nonreserved? window_clause?
| opt_clauses_following_group_by;
opt_clauses_following_group_by:
having_clause qualify_clause_nonreserved? window_clause?
| qualify_clause_nonreserved window_clause?
| window_clause;
window_clause: window_clause_prefix;
window_clause_prefix:
WINDOW_SYMBOL window_definition (
COMMA_SYMBOL window_definition
)*;
window_definition: identifier AS_SYMBOL window_specification;
where_clause: WHERE_SYMBOL expression;
having_clause: HAVING_SYMBOL expression;
group_by_clause: group_by_all | group_by_clause_prefix;
group_by_all: group_by_preamble ALL_SYMBOL;
select_clause:
SELECT_SYMBOL hint? opt_select_with? all_or_distinct? opt_select_as_clause? select_list
| SELECT_SYMBOL hint? opt_select_with? all_or_distinct? opt_select_as_clause? FROM_SYMBOL {p.NotifyErrorListeners("Syntax error: SELECT list must not be empty", nil, nil)
};
opt_select_as_clause:
AS_SYMBOL STRUCT_SYMBOL
| AS_SYMBOL path_expression;
opt_select_with:
WITH_SYMBOL identifier
| WITH_SYMBOL identifier OPTIONS_SYMBOL options_list;
// from_clause: https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#from_clause
from_clause: FROM_SYMBOL from_clause_contents;
from_clause_contents:
table_primary from_clause_contents_suffix*
| AT_SYMBOL {p.NotifyErrorListeners("Query parameters cannot be used in place of table names",nil,nil)
}
| QUESTION_SYMBOL {p.NotifyErrorListeners("Query parameters cannot be used in place of table names",nil,nil)
}
| ATAT_SYMBOL {p.NotifyErrorListeners("System variables cannot be used in place of table names",nil,nil)
};
from_clause_contents_suffix:
COMMA_SYMBOL table_primary
| opt_natural? join_type? join_hint? JOIN_SYMBOL hint? table_primary on_or_using_clause_list?;
table_primary:
tvf_with_suffixes
| table_path_expression
| LR_BRACKET_SYMBOL join RR_BRACKET_SYMBOL
| table_subquery
| table_primary match_recognize_clause
| table_primary sample_clause;
tvf_with_suffixes:
tvf_prefix_no_args RR_BRACKET_SYMBOL hint? pivot_or_unpivot_clause_and_aliases?
| tvf_prefix RR_BRACKET_SYMBOL hint? pivot_or_unpivot_clause_and_aliases?;
pivot_or_unpivot_clause_and_aliases:
AS_SYMBOL identifier
| identifier
| AS_SYMBOL identifier pivot_clause as_alias?
| AS_SYMBOL identifier unpivot_clause as_alias?
| AS_SYMBOL identifier qualify_clause_nonreserved {
p.NotifyErrorListeners("QUALIFY clause must be used in conjunction with WHERE or GROUP BY or HAVING clause", nil, nil);
}
| identifier pivot_clause as_alias
| identifier unpivot_clause as_alias
| identifier qualify_clause_nonreserved {
p.NotifyErrorListeners("QUALIFY clause must be used in conjunction with WHERE or GROUP BY or HAVING clause", nil, nil);
}
| pivot_clause as_alias?
| unpivot_clause as_alias?
| qualify_clause_nonreserved {
p.NotifyErrorListeners("QUALIFY clause must be used in conjunction with WHERE or GROUP BY or HAVING clause", nil, nil);
};
as_alias: AS_SYMBOL? identifier;
sample_clause:
TABLESAMPLE_SYMBOL identifier LR_BRACKET_SYMBOL sample_size RR_BRACKET_SYMBOL
opt_sample_clause_suffix;
opt_sample_clause_suffix:
repeatable_clause
| WITH_SYMBOL WEIGHT_SYMBOL repeatable_clause?
| WITH_SYMBOL WEIGHT_SYMBOL identifier repeatable_clause?
| WITH_SYMBOL WEIGHT_SYMBOL AS_SYMBOL identifier repeatable_clause?;
repeatable_clause:
REPEATABLE_SYMBOL LR_BRACKET_SYMBOL possibly_cast_int_literal_or_parameter RR_BRACKET_SYMBOL;
possibly_cast_int_literal_or_parameter:
cast_int_literal_or_parameter
| int_literal_or_parameter;
cast_int_literal_or_parameter:
CAST_SYMBOL LR_BRACKET_SYMBOL int_literal_or_parameter AS_SYMBOL type opt_format?
RR_BRACKET_SYMBOL;
sample_size:
sample_size_value sample_size_unit partition_by_clause_prefix_no_hint?;
sample_size_value:
possibly_cast_int_literal_or_parameter
| floating_point_literal;
sample_size_unit: ROWS_SYMBOL | PERCENT_SYMBOL;
partition_by_clause_prefix_no_hint:
PARTITION_SYMBOL BY_SYMBOL expression (
COMMA_SYMBOL expression
)*;
match_recognize_clause:
MATCH_RECOGNIZE_SYMBOL LR_BRACKET_SYMBOL partition_by_clause_prefix? order_by_clause
MEASURES_SYMBOL select_list_prefix_with_as_aliases PATTERN_SYMBOL LR_BRACKET_SYMBOL
row_pattern_expr RR_BRACKET_SYMBOL DEFINE_SYMBOL with_expression_variable_prefix
RR_BRACKET_SYMBOL as_alias?;
row_pattern_expr:
row_pattern_concatenation
| row_pattern_expr STROKE_SYMBOL row_pattern_concatenation;
row_pattern_concatenation:
row_pattern_factor
| row_pattern_concatenation row_pattern_factor;
row_pattern_factor:
identifier
| LR_BRACKET_SYMBOL row_pattern_expr RR_BRACKET_SYMBOL;
select_list_prefix_with_as_aliases:
select_column_expr_with_as_alias (
COMMA_SYMBOL select_column_expr_with_as_alias
)*;
select_column_expr_with_as_alias:
expression AS_SYMBOL identifier;
table_subquery:
parenthesized_query opt_pivot_or_unpivot_clause_and_alias?;
join: table_primary join_item*;
// join_item resolves the mutually left-recursive for [join, join_input]. join_input: join |
// table_primary;
join_item:
opt_natural? join_type? join_hint? JOIN_SYMBOL hint? table_primary on_or_using_clause_list?;
on_or_using_clause_list: on_or_using_clause+;
on_or_using_clause: on_clause | using_clause;
using_clause:
USING_SYMBOL LR_BRACKET_SYMBOL identifier (
DOT_SYMBOL identifier
)* RR_BRACKET_SYMBOL;
join_hint: HASH_SYMBOL | LOOKUP_SYMBOL;
table_path_expression:
table_path_expression_base hint? opt_pivot_or_unpivot_clause_and_alias?
opt_with_offset_and_alias? opt_at_system_time?;
opt_at_system_time:
FOR_SYMBOL SYSTEM_SYMBOL TIME_SYMBOL AS_SYMBOL OF_SYMBOL expression
| FOR_SYMBOL SYSTEM_TIME_SYMBOL AS_SYMBOL OF_SYMBOL expression;
opt_with_offset_and_alias: WITH_SYMBOL OFFSET_SYMBOL as_alias?;
opt_pivot_or_unpivot_clause_and_alias:
AS_SYMBOL identifier
| identifier
| AS_SYMBOL identifier pivot_clause as_alias?
| AS_SYMBOL identifier unpivot_clause as_alias?
| AS_SYMBOL identifier qualify_clause_nonreserved {p.NotifyErrorListeners("QUALIFY clause must be used in conjunction with WHERE or GROUP BY or HAVING clause", nil, nil)
}
| identifier pivot_clause as_alias?
| identifier unpivot_clause as_alias?
| identifier qualify_clause_nonreserved {p.NotifyErrorListeners("QUALIFY clause must be used in conjunction with WHERE or GROUP BY or HAVING clause", nil, nil)
}
| pivot_clause as_alias?
| unpivot_clause as_alias?
| qualify_clause_nonreserved {p.NotifyErrorListeners("QUALIFY clause must be used in conjunction with WHERE or GROUP BY or HAVING clause", nil, nil)
};
table_path_expression_base:
unnest_expression
| maybe_slashed_or_dashed_path_expression
| path_expression LS_BRACKET_SYMBOL {p.NotifyErrorListeners("Syntax error: Array element access is not allowed in the FROM clause without UNNEST; Use UNNEST(<expression>)",nil,nil)
}
| path_expression DOT_SYMBOL LR_BRACKET_SYMBOL {p.NotifyErrorListeners("Syntax error: Generalized field access is not allowed in the FROM clause without UNNEST; Use UNNEST(<expression>)",nil,nil)
}
| unnest_expression LS_BRACKET_SYMBOL {p.NotifyErrorListeners("Syntax error: Array element access is not allowed in the FROM clause without UNNEST; Use UNNEST(<expression>)",nil,nil)
}
| unnest_expression DOT_SYMBOL LR_BRACKET_SYMBOL {p.NotifyErrorListeners("Syntax error: Generalized field access is not allowed in the FROM clause without UNNEST; Use UNNEST(<expression>)",nil,nil)
};
maybe_slashed_or_dashed_path_expression:
maybe_dashed_path_expression
| slashed_path_expression;
maybe_dashed_path_expression:
path_expression
| dashed_path_expression;
dashed_path_expression:
dashed_identifier
| dashed_path_expression DOT_SYMBOL identifier;