SQLv1Antlr4.g.in 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189
  1. grammar SQLv1Antlr4;
  2. options {
  3. language = Cpp;
  4. }
  5. // Input is a list of statements.
  6. sql_query: sql_stmt_list | PRAGMA ANSI DIGITS ansi_sql_stmt_list;
  7. sql_stmt_list: SEMICOLON* sql_stmt (SEMICOLON+ sql_stmt)* SEMICOLON* EOF;
  8. ansi_sql_stmt_list: SEMICOLON* EOF;
  9. lambda_body: SEMICOLON* (lambda_stmt SEMICOLON+)* RETURN expr SEMICOLON*;
  10. lambda_stmt:
  11. named_nodes_stmt
  12. | import_stmt
  13. ;
  14. sql_stmt: (EXPLAIN (QUERY PLAN)?)? sql_stmt_core;
  15. sql_stmt_core:
  16. pragma_stmt
  17. | select_stmt
  18. | named_nodes_stmt
  19. | create_table_stmt
  20. | drop_table_stmt
  21. | use_stmt
  22. | into_table_stmt
  23. | commit_stmt
  24. | update_stmt
  25. | delete_stmt
  26. | rollback_stmt
  27. | declare_stmt
  28. | import_stmt
  29. | export_stmt
  30. | alter_table_stmt
  31. | alter_external_table_stmt
  32. | do_stmt
  33. | define_action_or_subquery_stmt
  34. | if_stmt
  35. | for_stmt
  36. | values_stmt
  37. | create_user_stmt
  38. | alter_user_stmt
  39. | create_group_stmt
  40. | alter_group_stmt
  41. | drop_role_stmt
  42. | create_object_stmt
  43. | alter_object_stmt
  44. | drop_object_stmt
  45. | create_external_data_source_stmt
  46. | alter_external_data_source_stmt
  47. | drop_external_data_source_stmt
  48. | create_replication_stmt
  49. | drop_replication_stmt
  50. | create_topic_stmt
  51. | alter_topic_stmt
  52. | drop_topic_stmt
  53. | grant_permissions_stmt
  54. | revoke_permissions_stmt
  55. | alter_table_store_stmt
  56. | upsert_object_stmt
  57. | create_view_stmt
  58. | drop_view_stmt
  59. | alter_replication_stmt
  60. | create_resource_pool_stmt
  61. | alter_resource_pool_stmt
  62. | drop_resource_pool_stmt
  63. | create_backup_collection_stmt
  64. | alter_backup_collection_stmt
  65. | drop_backup_collection_stmt
  66. | analyze_stmt
  67. | create_resource_pool_classifier_stmt
  68. | alter_resource_pool_classifier_stmt
  69. | drop_resource_pool_classifier_stmt
  70. | backup_stmt
  71. | restore_stmt
  72. | alter_sequence_stmt
  73. | create_transfer_stmt
  74. | alter_transfer_stmt
  75. | drop_transfer_stmt
  76. ;
  77. expr:
  78. or_subexpr (OR or_subexpr)*
  79. | type_name_composite;
  80. or_subexpr: and_subexpr (AND and_subexpr)*;
  81. and_subexpr: xor_subexpr (XOR xor_subexpr)*;
  82. xor_subexpr: eq_subexpr cond_expr?;
  83. distinct_from_op: IS NOT? DISTINCT FROM;
  84. cond_expr:
  85. NOT? match_op eq_subexpr (ESCAPE eq_subexpr)?
  86. | NOT? IN COMPACT? in_expr
  87. | (ISNULL | NOTNULL | IS NULL | (IS)? NOT NULL)
  88. | NOT? BETWEEN (SYMMETRIC | ASYMMETRIC)? eq_subexpr AND eq_subexpr
  89. | ((EQUALS | EQUALS2 | NOT_EQUALS | NOT_EQUALS2 | distinct_from_op) eq_subexpr)+ /* order of the eq subexpressions is reversed! */
  90. ;
  91. match_op: LIKE | ILIKE | GLOB | REGEXP | RLIKE | MATCH;
  92. eq_subexpr: neq_subexpr ((LESS | LESS_OR_EQ | GREATER | GREATER_OR_EQ) neq_subexpr)*;
  93. // workaround for recursive types, '??' and closing '>>'
  94. shift_right: GREATER GREATER;
  95. rot_right: GREATER GREATER PIPE;
  96. double_question: QUESTION QUESTION;
  97. neq_subexpr: bit_subexpr ((SHIFT_LEFT | shift_right | ROT_LEFT | rot_right | AMPERSAND | PIPE | CARET) bit_subexpr)*
  98. // trailing QUESTIONs are used in optional simple types (String?) and optional lambda args: ($x, $y?) -> ($x)
  99. (double_question neq_subexpr | QUESTION+)?;
  100. bit_subexpr: add_subexpr ((PLUS | MINUS) add_subexpr)*;
  101. add_subexpr: mul_subexpr ((ASTERISK | SLASH | PERCENT) mul_subexpr)*;
  102. mul_subexpr: con_subexpr (DOUBLE_PIPE con_subexpr)*;
  103. con_subexpr: unary_subexpr | unary_op unary_subexpr;
  104. unary_op: PLUS | MINUS | TILDA | NOT;
  105. unary_subexpr_suffix: ((key_expr | invoke_expr | DOT (bind_parameter | DIGITS | an_id_or_type)))* (COLLATE an_id)?;
  106. unary_casual_subexpr: (id_expr | atom_expr) unary_subexpr_suffix;
  107. in_unary_casual_subexpr: (id_expr_in | in_atom_expr) unary_subexpr_suffix;
  108. unary_subexpr: unary_casual_subexpr | json_api_expr;
  109. in_unary_subexpr: in_unary_casual_subexpr | json_api_expr;
  110. list_literal: LBRACE_SQUARE expr_list? COMMA? RBRACE_SQUARE;
  111. expr_dict_list: expr (COLON expr)? (COMMA expr (COLON expr)?)*;
  112. dict_literal: LBRACE_CURLY expr_dict_list? COMMA? RBRACE_CURLY;
  113. expr_struct_list: expr COLON expr (COMMA expr COLON expr)*;
  114. struct_literal: STRUCT_OPEN expr_struct_list? COMMA? STRUCT_CLOSE;
  115. atom_expr:
  116. literal_value
  117. | bind_parameter
  118. | lambda
  119. | cast_expr
  120. | exists_expr
  121. | case_expr
  122. | an_id_or_type NAMESPACE (id_or_type | STRING_VALUE)
  123. | value_constructor
  124. | bitcast_expr
  125. | list_literal
  126. | dict_literal
  127. | struct_literal
  128. ;
  129. in_atom_expr:
  130. literal_value
  131. | bind_parameter
  132. | lambda
  133. | cast_expr
  134. | case_expr
  135. | an_id_or_type NAMESPACE (id_or_type | STRING_VALUE)
  136. | LPAREN select_stmt RPAREN
  137. // TODO: resolve ANTLR error: rule in_atom_expr has non-LL(*) decision due to recursive rule invocations reachable from alts 3,8
  138. // | LPAREN values_stmt RPAREN
  139. | value_constructor
  140. | bitcast_expr
  141. | list_literal
  142. | dict_literal
  143. | struct_literal
  144. ;
  145. cast_expr: CAST LPAREN expr AS type_name_or_bind RPAREN;
  146. bitcast_expr: BITCAST LPAREN expr AS type_name_simple RPAREN;
  147. exists_expr: EXISTS LPAREN (select_stmt | values_stmt) RPAREN;
  148. case_expr: CASE expr? when_expr+ (ELSE expr)? END;
  149. lambda: smart_parenthesis (ARROW (LPAREN expr RPAREN | LBRACE_CURLY lambda_body RBRACE_CURLY) )?;
  150. in_expr: in_unary_subexpr;
  151. // ANSI SQL JSON support
  152. json_api_expr: json_value | json_exists | json_query;
  153. jsonpath_spec: STRING_VALUE;
  154. json_variable_name: id_expr | STRING_VALUE;
  155. json_variable: expr AS json_variable_name;
  156. json_variables: json_variable (COMMA json_variable)*;
  157. json_common_args: expr COMMA jsonpath_spec (PASSING json_variables)?;
  158. json_case_handler: ERROR | NULL | DEFAULT expr;
  159. json_value: JSON_VALUE LPAREN
  160. json_common_args
  161. (RETURNING type_name_simple)?
  162. (json_case_handler ON (EMPTY | ERROR))*
  163. RPAREN;
  164. json_exists_handler: (TRUE | FALSE | UNKNOWN | ERROR) ON ERROR;
  165. json_exists: JSON_EXISTS LPAREN
  166. json_common_args
  167. json_exists_handler?
  168. RPAREN;
  169. json_query_wrapper: WITHOUT ARRAY? | WITH (CONDITIONAL | UNCONDITIONAL)? ARRAY?;
  170. json_query_handler: ERROR | NULL | EMPTY ARRAY | EMPTY OBJECT;
  171. json_query: JSON_QUERY LPAREN
  172. json_common_args
  173. (json_query_wrapper WRAPPER)?
  174. (json_query_handler ON EMPTY)?
  175. (json_query_handler ON ERROR)?
  176. RPAREN;
  177. // struct, tuple or named list
  178. smart_parenthesis: LPAREN named_expr_list? COMMA? RPAREN;
  179. expr_list: expr (COMMA expr)*;
  180. pure_column_list: LPAREN an_id (COMMA an_id)* RPAREN;
  181. pure_column_or_named: bind_parameter | an_id;
  182. pure_column_or_named_list: LPAREN pure_column_or_named (COMMA pure_column_or_named)* RPAREN;
  183. column_name: opt_id_prefix an_id;
  184. without_column_name: an_id DOT an_id | an_id_without;
  185. column_list: column_name (COMMA column_name)* COMMA?;
  186. without_column_list: without_column_name (COMMA without_column_name)* COMMA?;
  187. named_expr: expr (AS an_id_or_type)?;
  188. named_expr_list: named_expr (COMMA named_expr)*;
  189. invoke_expr: LPAREN (opt_set_quantifier named_expr_list COMMA? | ASTERISK)? RPAREN invoke_expr_tail;
  190. // null_treatment can only happen after window functions LAG/LEAD/NTH/FIRST_VALUE/LAST_VALUE
  191. // filter_clause can only happen after aggregation functions
  192. invoke_expr_tail:
  193. (null_treatment | filter_clause)? (OVER window_name_or_specification)?
  194. ;
  195. using_call_expr: (an_id_or_type NAMESPACE an_id_or_type | an_id_expr | bind_parameter | EXTERNAL FUNCTION) invoke_expr;
  196. key_expr: LBRACE_SQUARE expr RBRACE_SQUARE;
  197. when_expr: WHEN expr THEN expr;
  198. literal_value:
  199. integer
  200. | real
  201. | STRING_VALUE
  202. | BLOB // it's unused right now
  203. | NULL
  204. | CURRENT_TIME // it's unused right now
  205. | CURRENT_DATE // it's unused right now
  206. | CURRENT_TIMESTAMP // it's unused right now
  207. | bool_value
  208. | EMPTY_ACTION
  209. ;
  210. bind_parameter: DOLLAR (an_id_or_type | TRUE | FALSE);
  211. opt_bind_parameter: bind_parameter QUESTION?;
  212. bind_parameter_list: bind_parameter (COMMA bind_parameter)*;
  213. named_bind_parameter: bind_parameter (AS bind_parameter)?;
  214. named_bind_parameter_list: named_bind_parameter (COMMA named_bind_parameter)*;
  215. signed_number: (PLUS | MINUS)? (integer | real);
  216. type_name_simple: an_id_pure;
  217. integer_or_bind: integer | bind_parameter;
  218. type_name_tag: id | STRING_VALUE | bind_parameter;
  219. struct_arg: type_name_tag COLON type_name_or_bind;
  220. struct_arg_positional:
  221. type_name_tag type_name_or_bind (NOT? NULL)?
  222. | type_name_or_bind AS type_name_tag; //deprecated
  223. variant_arg: (type_name_tag COLON)? type_name_or_bind;
  224. callable_arg: variant_arg (LBRACE_CURLY AUTOMAP RBRACE_CURLY)?;
  225. callable_arg_list: callable_arg (COMMA callable_arg)*;
  226. type_name_decimal: DECIMAL LPAREN integer_or_bind COMMA integer_or_bind RPAREN;
  227. type_name_optional: OPTIONAL LESS type_name_or_bind GREATER;
  228. type_name_tuple: TUPLE (LESS (type_name_or_bind (COMMA type_name_or_bind)* COMMA?)? GREATER | NOT_EQUALS2);
  229. type_name_struct: STRUCT (LESS (struct_arg (COMMA struct_arg)* COMMA?)? GREATER | NOT_EQUALS2);
  230. type_name_variant: VARIANT LESS variant_arg (COMMA variant_arg)* COMMA? GREATER;
  231. type_name_list: LIST LESS type_name_or_bind GREATER;
  232. type_name_stream: STREAM LESS type_name_or_bind GREATER;
  233. type_name_flow: FLOW LESS type_name_or_bind GREATER;
  234. type_name_dict: DICT LESS type_name_or_bind COMMA type_name_or_bind GREATER;
  235. type_name_set: SET LESS type_name_or_bind GREATER;
  236. type_name_enum: ENUM LESS type_name_tag (COMMA type_name_tag)* COMMA? GREATER;
  237. type_name_resource: RESOURCE LESS type_name_tag GREATER;
  238. type_name_tagged: TAGGED LESS type_name_or_bind COMMA type_name_tag GREATER;
  239. type_name_callable: CALLABLE LESS LPAREN callable_arg_list? COMMA? (LBRACE_SQUARE callable_arg_list RBRACE_SQUARE)? RPAREN ARROW type_name_or_bind GREATER;
  240. type_name_composite:
  241. ( type_name_optional
  242. | type_name_tuple
  243. | type_name_struct
  244. | type_name_variant
  245. | type_name_list
  246. | type_name_stream
  247. | type_name_flow
  248. | type_name_dict
  249. | type_name_set
  250. | type_name_enum
  251. | type_name_resource
  252. | type_name_tagged
  253. | type_name_callable
  254. ) QUESTION*;
  255. type_name:
  256. type_name_composite
  257. | (type_name_decimal | type_name_simple) QUESTION*;
  258. type_name_or_bind: type_name | bind_parameter;
  259. value_constructor_literal: STRING_VALUE;
  260. value_constructor:
  261. VARIANT LPAREN expr COMMA expr COMMA expr RPAREN
  262. | ENUM LPAREN expr COMMA expr RPAREN
  263. | CALLABLE LPAREN expr COMMA expr RPAREN
  264. ;
  265. declare_stmt: DECLARE bind_parameter AS type_name (EQUALS literal_value)?;
  266. module_path: DOT? an_id (DOT an_id)*;
  267. import_stmt: IMPORT module_path SYMBOLS named_bind_parameter_list;
  268. export_stmt: EXPORT bind_parameter_list;
  269. call_action: (bind_parameter | EMPTY_ACTION) LPAREN expr_list? RPAREN;
  270. inline_action: BEGIN define_action_or_subquery_body END DO;
  271. do_stmt: DO (call_action | inline_action);
  272. pragma_stmt: PRAGMA opt_id_prefix_or_type an_id (EQUALS pragma_value | LPAREN pragma_value (COMMA pragma_value)* RPAREN)?;
  273. pragma_value:
  274. signed_number
  275. | id
  276. | STRING_VALUE
  277. | bool_value
  278. | bind_parameter
  279. ;
  280. /// TODO: NULLS FIRST\LAST?
  281. sort_specification: expr (ASC | DESC)?;
  282. sort_specification_list: sort_specification (COMMA sort_specification)*;
  283. select_stmt: select_kind_parenthesis (select_op select_kind_parenthesis)*;
  284. select_unparenthesized_stmt: select_kind_partial (select_op select_kind_parenthesis)*;
  285. select_kind_parenthesis: select_kind_partial | LPAREN select_kind_partial RPAREN;
  286. select_op: UNION (ALL)? | INTERSECT | EXCEPT;
  287. select_kind_partial: select_kind
  288. (LIMIT expr ((OFFSET | COMMA) expr)?)?
  289. ;
  290. select_kind: (DISCARD)? (process_core | reduce_core | select_core) (INTO RESULT pure_column_or_named)?;
  291. process_core:
  292. PROCESS STREAM? named_single_source (COMMA named_single_source)* (USING using_call_expr (AS an_id)?
  293. (WITH external_call_settings)?
  294. (WHERE expr)? (HAVING expr)? (ASSUME order_by_clause)?)?
  295. ;
  296. external_call_param: an_id EQUALS expr;
  297. external_call_settings: external_call_param (COMMA external_call_param)*;
  298. reduce_core:
  299. REDUCE named_single_source (COMMA named_single_source)* (PRESORT sort_specification_list)?
  300. ON column_list USING ALL? using_call_expr (AS an_id)?
  301. (WHERE expr)? (HAVING expr)? (ASSUME order_by_clause)?
  302. ;
  303. opt_set_quantifier: (ALL | DISTINCT)?;
  304. select_core:
  305. (FROM join_source)? SELECT STREAM? opt_set_quantifier result_column (COMMA result_column)* COMMA? (WITHOUT without_column_list)? (FROM join_source)? (WHERE expr)?
  306. group_by_clause? (HAVING expr)? window_clause? ext_order_by_clause?
  307. ;
  308. // ISO/IEC 9075-2:2016(E) 7.7 <row pattern recognition clause>
  309. row_pattern_recognition_clause: MATCH_RECOGNIZE LPAREN
  310. window_partition_clause?
  311. order_by_clause?
  312. row_pattern_measures?
  313. row_pattern_rows_per_match?
  314. row_pattern_common_syntax
  315. RPAREN
  316. ;
  317. row_pattern_rows_per_match:
  318. ONE ROW PER MATCH
  319. | ALL ROWS PER MATCH row_pattern_empty_match_handling?
  320. ;
  321. row_pattern_empty_match_handling: SHOW EMPTY MATCHES | OMIT EMPTY MATCHES | WITH UNMATCHED ROWS;
  322. // ISO/IEC 9075-2:2016(E) 7.8 <row pattern measures>
  323. row_pattern_measures: MEASURES row_pattern_measure_list;
  324. row_pattern_measure_list: row_pattern_measure_definition (COMMA row_pattern_measure_definition)*;
  325. row_pattern_measure_definition: expr AS an_id;
  326. // ISO/IEC 9075-2:2016(E) 7.9 <row pattern common syntax>
  327. row_pattern_common_syntax:
  328. (AFTER MATCH row_pattern_skip_to)?
  329. row_pattern_initial_or_seek?
  330. PATTERN LPAREN row_pattern RPAREN
  331. row_pattern_subset_clause?
  332. DEFINE row_pattern_definition_list
  333. ;
  334. row_pattern_skip_to:
  335. TSKIP TO NEXT ROW
  336. | TSKIP PAST LAST ROW
  337. | TSKIP TO FIRST row_pattern_skip_to_variable_name
  338. | TSKIP TO LAST row_pattern_skip_to_variable_name
  339. | TSKIP TO row_pattern_skip_to_variable_name
  340. ;
  341. row_pattern_skip_to_variable_name: row_pattern_variable_name;
  342. row_pattern_initial_or_seek: INITIAL | SEEK;
  343. row_pattern: row_pattern_term (PIPE row_pattern_term)*;
  344. row_pattern_term: row_pattern_factor+;
  345. row_pattern_factor: row_pattern_primary row_pattern_quantifier?;
  346. row_pattern_quantifier:
  347. ASTERISK QUESTION?
  348. | PLUS QUESTION?
  349. | QUESTION QUESTION?
  350. | LBRACE_CURLY integer? COMMA integer? RBRACE_CURLY QUESTION?
  351. | LBRACE_CURLY integer RBRACE_CURLY
  352. ;
  353. row_pattern_primary:
  354. row_pattern_primary_variable_name
  355. | DOLLAR
  356. | CARET
  357. | LPAREN row_pattern? RPAREN
  358. | LBRACE_CURLY MINUS row_pattern MINUS RBRACE_CURLY
  359. | row_pattern_permute
  360. ;
  361. row_pattern_primary_variable_name: row_pattern_variable_name;
  362. row_pattern_permute: PERMUTE LPAREN
  363. row_pattern (COMMA row_pattern)*
  364. RPAREN
  365. ;
  366. row_pattern_subset_clause: SUBSET row_pattern_subset_list;
  367. row_pattern_subset_list: row_pattern_subset_item (COMMA row_pattern_subset_item)*;
  368. row_pattern_subset_item: row_pattern_subset_item_variable_name EQUALS LPAREN
  369. row_pattern_subset_rhs RPAREN
  370. ;
  371. row_pattern_subset_item_variable_name: row_pattern_variable_name;
  372. row_pattern_subset_rhs: row_pattern_subset_rhs_variable_name (COMMA row_pattern_subset_rhs_variable_name)*;
  373. row_pattern_subset_rhs_variable_name: row_pattern_variable_name;
  374. row_pattern_definition_list: row_pattern_definition (COMMA row_pattern_definition)*;
  375. row_pattern_definition: row_pattern_definition_variable_name AS row_pattern_definition_search_condition;
  376. row_pattern_definition_variable_name: row_pattern_variable_name;
  377. row_pattern_definition_search_condition: search_condition;
  378. search_condition: expr;
  379. //TODO allow use tokens as vars https://st.yandex-team.ru/YQL-16223
  380. row_pattern_variable_name: identifier;
  381. order_by_clause: ORDER BY sort_specification_list;
  382. ext_order_by_clause: ASSUME? order_by_clause;
  383. group_by_clause: GROUP COMPACT? BY opt_set_quantifier grouping_element_list (WITH an_id)?;
  384. grouping_element_list: grouping_element (COMMA grouping_element)*;
  385. grouping_element:
  386. ordinary_grouping_set
  387. | rollup_list
  388. | cube_list
  389. | grouping_sets_specification
  390. //empty_grouping_set inside smart_parenthesis
  391. | hopping_window_specification
  392. ;
  393. /// expect column (named column), or parenthesis list columns, or expression (named expression), or list expression
  394. ordinary_grouping_set: named_expr;
  395. ordinary_grouping_set_list: ordinary_grouping_set (COMMA ordinary_grouping_set)*;
  396. rollup_list: ROLLUP LPAREN ordinary_grouping_set_list RPAREN;
  397. cube_list: CUBE LPAREN ordinary_grouping_set_list RPAREN;
  398. /// SQL2003 grouping_set_list == grouping_element_list
  399. grouping_sets_specification: GROUPING SETS LPAREN grouping_element_list RPAREN;
  400. hopping_window_specification: HOP LPAREN expr COMMA expr COMMA expr COMMA expr RPAREN;
  401. result_column:
  402. opt_id_prefix ASTERISK
  403. | expr (AS an_id_or_type | an_id_as_compat)?
  404. ;
  405. join_source: ANY? flatten_source (join_op ANY? flatten_source join_constraint?)*;
  406. named_column: column_name (AS an_id)?;
  407. flatten_by_arg:
  408. named_column
  409. | LPAREN named_expr_list COMMA? RPAREN
  410. ;
  411. flatten_source: named_single_source (FLATTEN ((OPTIONAL|LIST|DICT)? BY flatten_by_arg | COLUMNS))?;
  412. named_single_source: single_source row_pattern_recognition_clause? ((AS an_id | an_id_as_compat) pure_column_list?)? (sample_clause | tablesample_clause)?;
  413. single_source:
  414. table_ref
  415. | LPAREN select_stmt RPAREN
  416. | LPAREN values_stmt RPAREN
  417. ;
  418. sample_clause: SAMPLE expr;
  419. tablesample_clause: TABLESAMPLE sampling_mode LPAREN expr RPAREN repeatable_clause?;
  420. sampling_mode: (BERNOULLI | SYSTEM);
  421. repeatable_clause: REPEATABLE LPAREN expr RPAREN;
  422. join_op:
  423. COMMA
  424. | (NATURAL)? ((LEFT (ONLY | SEMI)? | RIGHT (ONLY | SEMI)? | EXCLUSION | FULL)? (OUTER)? | INNER | CROSS) JOIN
  425. ;
  426. join_constraint:
  427. ON expr
  428. | USING pure_column_or_named_list
  429. ;
  430. returning_columns_list: RETURNING (ASTERISK | an_id (COMMA an_id)*);
  431. into_table_stmt: (INSERT | INSERT OR ABORT | INSERT OR REVERT | INSERT OR IGNORE | UPSERT | REPLACE) INTO into_simple_table_ref into_values_source returning_columns_list?;
  432. into_values_source:
  433. pure_column_list? values_source
  434. | DEFAULT VALUES
  435. ;
  436. values_stmt: VALUES values_source_row_list;
  437. values_source: values_stmt | select_stmt;
  438. values_source_row_list: values_source_row (COMMA values_source_row)*;
  439. values_source_row: LPAREN expr_list RPAREN;
  440. simple_values_source: expr_list | select_stmt;
  441. create_external_data_source_stmt: CREATE (OR REPLACE)? EXTERNAL DATA SOURCE (IF NOT EXISTS)? object_ref
  442. with_table_settings
  443. ;
  444. alter_external_data_source_stmt: ALTER EXTERNAL DATA SOURCE object_ref
  445. alter_external_data_source_action (COMMA alter_external_data_source_action)*
  446. ;
  447. alter_external_data_source_action:
  448. alter_table_set_table_setting_uncompat
  449. | alter_table_set_table_setting_compat
  450. | alter_table_reset_table_setting
  451. //| alter_table_rename_to // TODO
  452. ;
  453. drop_external_data_source_stmt: DROP EXTERNAL DATA SOURCE (IF EXISTS)? object_ref;
  454. create_view_stmt: CREATE VIEW (IF NOT EXISTS)? object_ref
  455. create_object_features?
  456. AS select_stmt
  457. ;
  458. drop_view_stmt: DROP VIEW (IF EXISTS)? object_ref;
  459. upsert_object_stmt: UPSERT OBJECT object_ref
  460. LPAREN TYPE object_type_ref RPAREN
  461. create_object_features?
  462. ;
  463. create_object_stmt: CREATE OBJECT (IF NOT EXISTS)? object_ref
  464. LPAREN TYPE object_type_ref RPAREN
  465. create_object_features?
  466. ;
  467. create_object_features: WITH object_features;
  468. alter_object_stmt: ALTER OBJECT object_ref
  469. LPAREN TYPE object_type_ref RPAREN
  470. alter_object_features
  471. ;
  472. alter_object_features: SET object_features;
  473. drop_object_stmt: DROP OBJECT (IF EXISTS)? object_ref
  474. LPAREN TYPE object_type_ref RPAREN
  475. drop_object_features?
  476. ;
  477. drop_object_features: WITH object_features;
  478. object_feature_value: id_or_type | bind_parameter | STRING_VALUE | bool_value;
  479. object_feature_kv: an_id_or_type EQUALS object_feature_value;
  480. object_feature_flag: an_id_or_type;
  481. object_feature: object_feature_kv | object_feature_flag;
  482. object_features: object_feature | LPAREN object_feature (COMMA object_feature)* RPAREN;
  483. object_type_ref: an_id_or_type;
  484. create_table_stmt: CREATE (OR REPLACE)? (TABLE | TABLESTORE | EXTERNAL TABLE | TEMP TABLE | TEMPORARY TABLE) (IF NOT EXISTS)? simple_table_ref LPAREN create_table_entry (COMMA create_table_entry)* COMMA? RPAREN
  485. table_inherits?
  486. table_partition_by?
  487. with_table_settings?
  488. table_tablestore?
  489. table_as_source?;
  490. create_table_entry:
  491. column_schema
  492. | table_constraint
  493. | table_index
  494. | family_entry
  495. | changefeed
  496. | an_id_schema
  497. ;
  498. create_backup_collection_stmt: CREATE backup_collection create_backup_collection_entries? WITH LPAREN backup_collection_settings RPAREN;
  499. alter_backup_collection_stmt: ALTER backup_collection (alter_backup_collection_actions | alter_backup_collection_entries);
  500. drop_backup_collection_stmt: DROP backup_collection;
  501. create_backup_collection_entries: DATABASE | create_backup_collection_entries_many;
  502. create_backup_collection_entries_many: LPAREN table_list RPAREN;
  503. table_list: TABLE an_id_table (COMMA TABLE an_id_table)*;
  504. alter_backup_collection_actions: alter_backup_collection_action (COMMA alter_backup_collection_action)*;
  505. alter_backup_collection_action:
  506. alter_table_set_table_setting_compat
  507. | alter_table_reset_table_setting
  508. ;
  509. alter_backup_collection_entries: alter_backup_collection_entry (COMMA alter_backup_collection_entry)*;
  510. alter_backup_collection_entry:
  511. ADD DATABASE
  512. | DROP DATABASE
  513. | ADD TABLE an_id_table
  514. | DROP TABLE an_id_table
  515. ;
  516. backup_collection: BACKUP COLLECTION object_ref;
  517. backup_collection_settings: backup_collection_settings_entry (COMMA backup_collection_settings_entry)*;
  518. backup_collection_settings_entry: an_id EQUALS table_setting_value;
  519. backup_stmt: BACKUP object_ref (INCREMENTAL)?;
  520. restore_stmt: RESTORE object_ref (AT STRING_VALUE)?;
  521. table_inherits: INHERITS LPAREN simple_table_ref_core (COMMA simple_table_ref_core)* RPAREN;
  522. table_partition_by: PARTITION BY HASH pure_column_list;
  523. with_table_settings: WITH LPAREN table_settings_entry (COMMA table_settings_entry)* RPAREN;
  524. table_tablestore: TABLESTORE simple_table_ref_core;
  525. table_settings_entry: an_id EQUALS table_setting_value;
  526. table_as_source: AS values_source;
  527. alter_table_stmt: ALTER TABLE simple_table_ref alter_table_action (COMMA alter_table_action)*;
  528. alter_table_action:
  529. alter_table_add_column
  530. | alter_table_drop_column
  531. | alter_table_alter_column
  532. | alter_table_add_column_family
  533. | alter_table_alter_column_family
  534. | alter_table_set_table_setting_uncompat
  535. | alter_table_set_table_setting_compat
  536. | alter_table_reset_table_setting
  537. | alter_table_add_index
  538. | alter_table_drop_index
  539. | alter_table_rename_to
  540. | alter_table_add_changefeed
  541. | alter_table_alter_changefeed
  542. | alter_table_drop_changefeed
  543. | alter_table_rename_index_to
  544. | alter_table_alter_index
  545. | alter_table_alter_column_drop_not_null
  546. ;
  547. alter_external_table_stmt: ALTER EXTERNAL TABLE simple_table_ref alter_external_table_action (COMMA alter_external_table_action)*;
  548. alter_external_table_action:
  549. alter_table_add_column
  550. | alter_table_drop_column
  551. | alter_table_set_table_setting_uncompat
  552. | alter_table_set_table_setting_compat
  553. | alter_table_reset_table_setting
  554. //| alter_table_rename_to // TODO
  555. ;
  556. alter_table_store_stmt: ALTER TABLESTORE object_ref alter_table_store_action (COMMA alter_table_store_action)*;
  557. alter_table_store_action:
  558. alter_table_add_column
  559. | alter_table_drop_column
  560. ;
  561. alter_table_add_column: ADD COLUMN? column_schema;
  562. alter_table_drop_column: DROP COLUMN? an_id;
  563. alter_table_alter_column: ALTER COLUMN an_id SET family_relation;
  564. alter_table_alter_column_drop_not_null: ALTER COLUMN an_id DROP NOT NULL;
  565. alter_table_add_column_family: ADD family_entry;
  566. alter_table_alter_column_family: ALTER FAMILY an_id SET an_id family_setting_value;
  567. alter_table_set_table_setting_uncompat: SET an_id table_setting_value;
  568. alter_table_set_table_setting_compat: SET LPAREN alter_table_setting_entry (COMMA alter_table_setting_entry)* RPAREN;
  569. alter_table_reset_table_setting: RESET LPAREN an_id (COMMA an_id)* RPAREN;
  570. alter_table_add_index: ADD table_index;
  571. alter_table_drop_index: DROP INDEX an_id;
  572. alter_table_rename_to: RENAME TO an_id_table;
  573. alter_table_rename_index_to: RENAME INDEX an_id TO an_id;
  574. alter_table_add_changefeed: ADD changefeed;
  575. alter_table_alter_changefeed: ALTER CHANGEFEED an_id changefeed_alter_settings;
  576. alter_table_drop_changefeed: DROP CHANGEFEED an_id;
  577. alter_table_alter_index: ALTER INDEX an_id alter_table_alter_index_action;
  578. column_schema: an_id_schema type_name_or_bind family_relation? opt_column_constraints;
  579. family_relation: FAMILY an_id;
  580. opt_column_constraints: (NOT? NULL)? (DEFAULT expr)?;
  581. column_order_by_specification: an_id (ASC | DESC)?;
  582. table_constraint:
  583. PRIMARY KEY LPAREN an_id (COMMA an_id)* RPAREN
  584. | PARTITION BY LPAREN an_id (COMMA an_id)* RPAREN
  585. | ORDER BY LPAREN column_order_by_specification (COMMA column_order_by_specification)* RPAREN
  586. ;
  587. table_index: INDEX an_id table_index_type
  588. ON LPAREN an_id_schema (COMMA an_id_schema)* RPAREN
  589. (COVER LPAREN an_id_schema (COMMA an_id_schema)* RPAREN)?
  590. with_index_settings?
  591. ;
  592. table_index_type: (global_index | local_index) (USING index_subtype)?;
  593. global_index: GLOBAL UNIQUE? (SYNC | ASYNC)?;
  594. local_index: LOCAL;
  595. index_subtype: an_id;
  596. with_index_settings: WITH LPAREN index_setting_entry (COMMA index_setting_entry)* COMMA? RPAREN;
  597. index_setting_entry: an_id EQUALS index_setting_value;
  598. index_setting_value:
  599. id_or_type
  600. | STRING_VALUE
  601. | integer
  602. | bool_value
  603. ;
  604. changefeed: CHANGEFEED an_id WITH LPAREN changefeed_settings RPAREN;
  605. changefeed_settings: changefeed_settings_entry (COMMA changefeed_settings_entry)*;
  606. changefeed_settings_entry: an_id EQUALS changefeed_setting_value;
  607. changefeed_setting_value: expr;
  608. changefeed_alter_settings:
  609. DISABLE
  610. | SET LPAREN changefeed_settings RPAREN
  611. ;
  612. alter_table_setting_entry: an_id EQUALS table_setting_value;
  613. table_setting_value:
  614. id
  615. | STRING_VALUE
  616. | integer
  617. | split_boundaries
  618. | ttl_tier_list ON an_id (AS (SECONDS | MILLISECONDS | MICROSECONDS | NANOSECONDS))?
  619. | bool_value
  620. ;
  621. ttl_tier_list: expr (ttl_tier_action (COMMA expr ttl_tier_action)*)?;
  622. ttl_tier_action:
  623. TO EXTERNAL DATA SOURCE an_id
  624. | DELETE
  625. ;
  626. family_entry: FAMILY an_id family_settings;
  627. family_settings: LPAREN (family_settings_entry (COMMA family_settings_entry)*)? RPAREN;
  628. family_settings_entry: an_id EQUALS family_setting_value;
  629. family_setting_value:
  630. STRING_VALUE
  631. | integer
  632. ;
  633. split_boundaries:
  634. LPAREN literal_value_list (COMMA literal_value_list)* RPAREN
  635. | literal_value_list
  636. ;
  637. literal_value_list: LPAREN literal_value (COMMA literal_value)* RPAREN;
  638. alter_table_alter_index_action:
  639. alter_table_set_table_setting_uncompat
  640. | alter_table_set_table_setting_compat
  641. | alter_table_reset_table_setting
  642. ;
  643. drop_table_stmt: DROP (TABLE | TABLESTORE | EXTERNAL TABLE) (IF EXISTS)? simple_table_ref;
  644. create_user_stmt: CREATE USER role_name user_option*;
  645. alter_user_stmt: ALTER USER role_name (WITH? user_option+ | RENAME TO role_name);
  646. create_group_stmt: CREATE GROUP role_name (WITH USER role_name (COMMA role_name)* COMMA?)?;
  647. alter_group_stmt: ALTER GROUP role_name ((ADD|DROP) USER role_name (COMMA role_name)* COMMA? | RENAME TO role_name);
  648. drop_role_stmt: DROP (USER|GROUP) (IF EXISTS)? role_name (COMMA role_name)* COMMA?;
  649. role_name: an_id_or_type | bind_parameter;
  650. user_option: authentication_option | login_option;
  651. authentication_option: password_option | hash_option;
  652. password_option: ENCRYPTED? PASSWORD expr;
  653. hash_option: HASH expr;
  654. login_option: LOGIN | NOLOGIN;
  655. grant_permissions_stmt: GRANT permission_name_target ON an_id_schema (COMMA an_id_schema)* TO role_name (COMMA role_name)* COMMA? (WITH GRANT OPTION)?;
  656. revoke_permissions_stmt: REVOKE (GRANT OPTION FOR)? permission_name_target ON an_id_schema (COMMA an_id_schema)* FROM role_name (COMMA role_name)*;
  657. permission_id:
  658. CONNECT
  659. | LIST
  660. | INSERT
  661. | MANAGE
  662. | DROP
  663. | GRANT
  664. | MODIFY (TABLES | ATTRIBUTES)
  665. | (UPDATE | ERASE) ROW
  666. | (REMOVE | DESCRIBE | ALTER) SCHEMA
  667. | SELECT (TABLES | ATTRIBUTES | ROW)?
  668. | (USE | FULL) LEGACY?
  669. | CREATE (DIRECTORY | TABLE | QUEUE)?
  670. ;
  671. permission_name: permission_id | STRING_VALUE;
  672. permission_name_target: permission_name (COMMA permission_name)* COMMA? | ALL PRIVILEGES?;
  673. create_resource_pool_stmt: CREATE RESOURCE POOL object_ref
  674. with_table_settings
  675. ;
  676. alter_resource_pool_stmt: ALTER RESOURCE POOL object_ref
  677. alter_resource_pool_action (COMMA alter_resource_pool_action)*
  678. ;
  679. alter_resource_pool_action:
  680. alter_table_set_table_setting_compat
  681. | alter_table_reset_table_setting
  682. ;
  683. drop_resource_pool_stmt: DROP RESOURCE POOL object_ref;
  684. create_resource_pool_classifier_stmt: CREATE RESOURCE POOL CLASSIFIER object_ref
  685. with_table_settings
  686. ;
  687. alter_resource_pool_classifier_stmt: ALTER RESOURCE POOL CLASSIFIER object_ref
  688. alter_resource_pool_classifier_action (COMMA alter_resource_pool_classifier_action)*
  689. ;
  690. alter_resource_pool_classifier_action:
  691. alter_table_set_table_setting_compat
  692. | alter_table_reset_table_setting
  693. ;
  694. drop_resource_pool_classifier_stmt: DROP RESOURCE POOL CLASSIFIER object_ref;
  695. create_replication_stmt: CREATE ASYNC REPLICATION object_ref
  696. FOR replication_target (COMMA replication_target)*
  697. WITH LPAREN replication_settings RPAREN
  698. ;
  699. replication_target: object_ref AS object_ref;
  700. replication_settings: replication_settings_entry (COMMA replication_settings_entry)*;
  701. replication_settings_entry: an_id EQUALS expr;
  702. alter_replication_stmt: ALTER ASYNC REPLICATION object_ref alter_replication_action (COMMA alter_replication_action)*;
  703. alter_replication_action:
  704. alter_replication_set_setting
  705. ;
  706. alter_replication_set_setting: SET LPAREN replication_settings RPAREN;
  707. drop_replication_stmt: DROP ASYNC REPLICATION object_ref CASCADE?;
  708. lambda_or_parameter:
  709. lambda
  710. | bind_parameter
  711. ;
  712. create_transfer_stmt: CREATE TRANSFER object_ref
  713. FROM object_ref TO object_ref (USING lambda_or_parameter)?
  714. WITH LPAREN transfer_settings RPAREN
  715. ;
  716. transfer_settings: transfer_settings_entry (COMMA transfer_settings_entry)*;
  717. transfer_settings_entry: an_id EQUALS expr;
  718. alter_transfer_stmt: ALTER TRANSFER object_ref alter_transfer_action (COMMA alter_transfer_action)*;
  719. alter_transfer_action:
  720. alter_transfer_set_setting
  721. | alter_transfer_set_using
  722. ;
  723. alter_transfer_set_setting: SET LPAREN transfer_settings RPAREN;
  724. alter_transfer_set_using: SET USING lambda_or_parameter;
  725. drop_transfer_stmt: DROP TRANSFER object_ref CASCADE?;
  726. action_or_subquery_args: opt_bind_parameter (COMMA opt_bind_parameter)*;
  727. define_action_or_subquery_stmt: DEFINE (ACTION|SUBQUERY) bind_parameter LPAREN action_or_subquery_args? RPAREN AS define_action_or_subquery_body END DEFINE;
  728. define_action_or_subquery_body: SEMICOLON* (sql_stmt_core (SEMICOLON+ sql_stmt_core)* SEMICOLON*)?;
  729. if_stmt: EVALUATE? IF expr do_stmt (ELSE do_stmt)?;
  730. for_stmt: EVALUATE? PARALLEL? FOR bind_parameter IN expr do_stmt (ELSE do_stmt)?;
  731. table_ref: (cluster_expr DOT)? COMMAT? (table_key | an_id_expr LPAREN (table_arg (COMMA table_arg)* COMMA?)? RPAREN | bind_parameter (LPAREN expr_list? RPAREN)? (VIEW view_name)?) table_hints?;
  732. table_key: id_table_or_type (VIEW view_name)?;
  733. table_arg: COMMAT? named_expr (VIEW view_name)?;
  734. table_hints: WITH (table_hint | LPAREN table_hint (COMMA table_hint)* RPAREN);
  735. table_hint:
  736. an_id_hint (EQUALS (type_name_tag | LPAREN type_name_tag (COMMA type_name_tag)* COMMA? RPAREN))?
  737. | (SCHEMA | COLUMNS) EQUALS? type_name_or_bind
  738. | SCHEMA EQUALS? LPAREN (struct_arg_positional (COMMA struct_arg_positional)*)? COMMA? RPAREN
  739. ;
  740. object_ref: (cluster_expr DOT)? id_or_at;
  741. simple_table_ref_core: object_ref | COMMAT? bind_parameter;
  742. simple_table_ref: simple_table_ref_core table_hints?;
  743. into_simple_table_ref: simple_table_ref (ERASE BY pure_column_list)?;
  744. delete_stmt: BATCH? DELETE FROM simple_table_ref (WHERE expr | ON into_values_source)? returning_columns_list?;
  745. update_stmt: BATCH? UPDATE simple_table_ref (SET set_clause_choice (WHERE expr)? | ON into_values_source) returning_columns_list?;
  746. /// out of 2003 standart
  747. set_clause_choice: set_clause_list | multiple_column_assignment;
  748. set_clause_list: set_clause (COMMA set_clause)*;
  749. set_clause: set_target EQUALS expr;
  750. set_target: column_name;
  751. multiple_column_assignment: set_target_list EQUALS LPAREN simple_values_source RPAREN;
  752. set_target_list: LPAREN set_target (COMMA set_target)* RPAREN;
  753. // topics
  754. create_topic_stmt: CREATE TOPIC (IF NOT EXISTS)? topic_ref create_topic_entries? with_topic_settings?;
  755. create_topic_entries: LPAREN create_topic_entry (COMMA create_topic_entry)* RPAREN;
  756. create_topic_entry:
  757. topic_create_consumer_entry
  758. ;
  759. with_topic_settings: WITH LPAREN topic_settings RPAREN;
  760. alter_topic_stmt: ALTER TOPIC (IF EXISTS)? topic_ref alter_topic_action (COMMA alter_topic_action)*;
  761. alter_topic_action:
  762. alter_topic_add_consumer
  763. | alter_topic_alter_consumer
  764. | alter_topic_drop_consumer
  765. | alter_topic_set_settings
  766. | alter_topic_reset_settings
  767. ;
  768. alter_topic_add_consumer: ADD topic_create_consumer_entry;
  769. topic_create_consumer_entry: CONSUMER an_id topic_consumer_with_settings?;
  770. alter_topic_alter_consumer: ALTER CONSUMER topic_consumer_ref alter_topic_alter_consumer_entry;
  771. alter_topic_alter_consumer_entry:
  772. topic_alter_consumer_set
  773. | topic_alter_consumer_reset
  774. ;
  775. alter_topic_drop_consumer: DROP CONSUMER topic_consumer_ref;
  776. topic_alter_consumer_set: SET LPAREN topic_consumer_settings RPAREN;
  777. topic_alter_consumer_reset: RESET LPAREN an_id (COMMA an_id)* RPAREN;
  778. alter_topic_set_settings: SET LPAREN topic_settings RPAREN;
  779. alter_topic_reset_settings: RESET LPAREN an_id (COMMA an_id_pure)* RPAREN;
  780. drop_topic_stmt: DROP TOPIC (IF EXISTS)? topic_ref;
  781. topic_settings: topic_settings_entry (COMMA topic_settings_entry)*;
  782. topic_settings_entry: an_id EQUALS topic_setting_value;
  783. topic_setting_value:
  784. expr
  785. ;
  786. topic_consumer_with_settings: WITH LPAREN topic_consumer_settings RPAREN;
  787. topic_consumer_settings: topic_consumer_settings_entry (COMMA topic_consumer_settings_entry)*;
  788. topic_consumer_settings_entry: an_id EQUALS topic_consumer_setting_value;
  789. topic_consumer_setting_value:
  790. expr
  791. ;
  792. topic_ref: (cluster_expr DOT)? an_id;
  793. topic_consumer_ref: an_id_pure;
  794. /// window function supp
  795. // differ from 2003 for resolve conflict
  796. null_treatment: RESPECT NULLS | IGNORE NULLS;
  797. filter_clause: FILTER LPAREN WHERE expr RPAREN;
  798. window_name_or_specification: window_name | window_specification;
  799. window_name: an_id_window;
  800. window_clause: WINDOW window_definition_list;
  801. window_definition_list: window_definition (COMMA window_definition)*;
  802. window_definition: new_window_name AS window_specification;
  803. new_window_name: window_name;
  804. window_specification: LPAREN window_specification_details RPAREN;
  805. window_specification_details:
  806. existing_window_name?
  807. window_partition_clause?
  808. window_order_clause?
  809. window_frame_clause?
  810. ;
  811. existing_window_name: window_name;
  812. window_partition_clause: PARTITION COMPACT? BY named_expr_list;
  813. window_order_clause: order_by_clause;
  814. window_frame_clause: window_frame_units window_frame_extent window_frame_exclusion?;
  815. window_frame_units: ROWS | RANGE | GROUPS;
  816. window_frame_extent: window_frame_bound | window_frame_between;
  817. window_frame_between: BETWEEN window_frame_bound AND window_frame_bound;
  818. window_frame_bound:
  819. CURRENT ROW
  820. | (expr | UNBOUNDED) (PRECEDING | FOLLOWING)
  821. ;
  822. window_frame_exclusion: EXCLUDE CURRENT ROW | EXCLUDE GROUP | EXCLUDE TIES | EXCLUDE NO OTHERS;
  823. // EXTRAS
  824. use_stmt: USE cluster_expr;
  825. subselect_stmt: (LPAREN select_stmt RPAREN | select_unparenthesized_stmt);
  826. // TODO: [fatal] rule named_nodes_stmt has non-LL(*) decision due to recursive rule invocations reachable from alts 1,3
  827. // named_nodes_stmt: bind_parameter_list EQUALS (expr | subselect_stmt | values_stmt | LPAREN values_stmt RPAREN);
  828. named_nodes_stmt: bind_parameter_list EQUALS (expr | subselect_stmt);
  829. commit_stmt: COMMIT;
  830. rollback_stmt: ROLLBACK;
  831. analyze_table: simple_table_ref (LPAREN column_list RPAREN)?;
  832. analyze_table_list: analyze_table (COMMA analyze_table)* COMMA?;
  833. analyze_stmt: ANALYZE analyze_table_list;
  834. alter_sequence_stmt: ALTER SEQUENCE (IF EXISTS)? object_ref alter_sequence_action+;
  835. alter_sequence_action:
  836. START WITH? integer
  837. | RESTART WITH? integer
  838. | RESTART
  839. | INCREMENT BY? integer
  840. ;
  841. // Special rules that allow to use certain keywords as identifiers.
  842. identifier: ID_PLAIN | ID_QUOTED;
  843. id: identifier | keyword;
  844. id_schema:
  845. identifier
  846. | keyword_compat
  847. | keyword_expr_uncompat
  848. // | keyword_table_uncompat
  849. | keyword_select_uncompat
  850. // | keyword_alter_uncompat
  851. | keyword_in_uncompat
  852. | keyword_window_uncompat
  853. | keyword_hint_uncompat
  854. ;
  855. id_expr:
  856. identifier
  857. | keyword_compat
  858. // | keyword_expr_uncompat
  859. // | keyword_table_uncompat
  860. // | keyword_select_uncompat
  861. | keyword_alter_uncompat
  862. | keyword_in_uncompat
  863. | keyword_window_uncompat
  864. | keyword_hint_uncompat
  865. ;
  866. id_expr_in:
  867. identifier
  868. | keyword_compat
  869. // | keyword_expr_uncompat
  870. // | keyword_table_uncompat
  871. // | keyword_select_uncompat
  872. | keyword_alter_uncompat
  873. // | keyword_in_uncompat
  874. | keyword_window_uncompat
  875. | keyword_hint_uncompat
  876. ;
  877. id_window:
  878. identifier
  879. | keyword_compat
  880. | keyword_expr_uncompat
  881. | keyword_table_uncompat
  882. | keyword_select_uncompat
  883. | keyword_alter_uncompat
  884. | keyword_in_uncompat
  885. // | keyword_window_uncompat
  886. | keyword_hint_uncompat
  887. ;
  888. id_table:
  889. identifier
  890. | keyword_compat
  891. | keyword_expr_uncompat
  892. // | keyword_table_uncompat
  893. | keyword_select_uncompat
  894. // | keyword_alter_uncompat
  895. | keyword_in_uncompat
  896. | keyword_window_uncompat
  897. | keyword_hint_uncompat
  898. ;
  899. id_without:
  900. identifier
  901. | keyword_compat
  902. // | keyword_expr_uncompat
  903. | keyword_table_uncompat
  904. // | keyword_select_uncompat
  905. | keyword_alter_uncompat
  906. | keyword_in_uncompat
  907. | keyword_window_uncompat
  908. | keyword_hint_uncompat
  909. ;
  910. id_hint:
  911. identifier
  912. | keyword_compat
  913. | keyword_expr_uncompat
  914. | keyword_table_uncompat
  915. | keyword_select_uncompat
  916. | keyword_alter_uncompat
  917. | keyword_in_uncompat
  918. | keyword_window_uncompat
  919. // | keyword_hint_uncompat
  920. ;
  921. id_as_compat: identifier | keyword_as_compat;
  922. // ANSI-aware versions of various identifiers with support double-quoted identifiers when PRAGMA AnsiQuotedIdentifiers; is present
  923. an_id: id | STRING_VALUE;
  924. an_id_or_type: id_or_type | STRING_VALUE;
  925. an_id_schema: id_schema | STRING_VALUE;
  926. an_id_expr: id_expr | STRING_VALUE;
  927. an_id_expr_in: id_expr_in | STRING_VALUE;
  928. an_id_window: id_window | STRING_VALUE;
  929. an_id_table: id_table | STRING_VALUE;
  930. an_id_without: id_without | STRING_VALUE;
  931. an_id_hint: id_hint | STRING_VALUE;
  932. an_id_pure: identifier | STRING_VALUE;
  933. an_id_as_compat: id_as_compat | STRING_VALUE;
  934. view_name: an_id | PRIMARY KEY;
  935. opt_id_prefix: (an_id DOT)?;
  936. cluster_expr: (an_id COLON)? (pure_column_or_named | ASTERISK);
  937. id_or_type: id | type_id;
  938. opt_id_prefix_or_type: (an_id_or_type DOT)?;
  939. id_or_at: COMMAT? an_id_or_type;
  940. id_table_or_type: an_id_table | type_id;
  941. id_table_or_at: COMMAT? id_table_or_type;
  942. keyword:
  943. keyword_compat
  944. | keyword_expr_uncompat
  945. | keyword_table_uncompat
  946. | keyword_select_uncompat
  947. | keyword_alter_uncompat
  948. | keyword_in_uncompat
  949. | keyword_window_uncompat
  950. | keyword_hint_uncompat
  951. ;
  952. keyword_expr_uncompat:
  953. ASYMMETRIC
  954. | BETWEEN
  955. | BITCAST
  956. | CASE
  957. | CAST
  958. | CUBE
  959. | CURRENT_DATE
  960. | CURRENT_TIME
  961. | CURRENT_TIMESTAMP
  962. | EMPTY_ACTION
  963. | EXISTS
  964. | FROM
  965. | FULL
  966. | HOP
  967. | JSON_EXISTS
  968. | JSON_VALUE
  969. | JSON_QUERY
  970. | NOT
  971. | NULL
  972. | PROCESS
  973. | REDUCE
  974. | RETURN
  975. | RETURNING
  976. | ROLLUP
  977. | SELECT
  978. | SYMMETRIC
  979. | UNBOUNDED
  980. | WHEN
  981. | WHERE
  982. ;
  983. keyword_table_uncompat:
  984. ANY
  985. | ERASE
  986. | STREAM
  987. ;
  988. keyword_select_uncompat:
  989. ALL
  990. | AS
  991. | ASSUME
  992. | DISTINCT
  993. | EXCEPT
  994. | HAVING
  995. | INTERSECT
  996. | LIMIT
  997. | UNION
  998. | WINDOW
  999. | WITHOUT
  1000. ;
  1001. keyword_alter_uncompat:
  1002. COLUMN
  1003. ;
  1004. keyword_in_uncompat:
  1005. COMPACT
  1006. ;
  1007. keyword_window_uncompat:
  1008. GROUPS
  1009. | RANGE
  1010. | ROWS
  1011. ;
  1012. keyword_hint_uncompat:
  1013. SCHEMA
  1014. | COLUMNS
  1015. ;
  1016. keyword_as_compat:
  1017. ABORT
  1018. | ACTION
  1019. | ADD
  1020. | AFTER
  1021. | ALTER
  1022. | ANALYZE
  1023. | AND
  1024. | ANSI
  1025. | ARRAY
  1026. | ASC
  1027. | ASYNC
  1028. | AT
  1029. | ATTACH
  1030. | ATTRIBUTES
  1031. | AUTOINCREMENT
  1032. | BACKUP
  1033. | BATCH
  1034. | BEFORE
  1035. | BEGIN
  1036. | BERNOULLI
  1037. | BY
  1038. | CASCADE
  1039. | CHANGEFEED
  1040. | CHECK
  1041. | CLASSIFIER
  1042. // | COLLATE
  1043. | COLLECTION
  1044. | COMMIT
  1045. | CONDITIONAL
  1046. | CONFLICT
  1047. | CONNECT
  1048. | CONSTRAINT
  1049. | CONSUMER
  1050. | COVER
  1051. | CREATE
  1052. // | CROSS
  1053. | CURRENT
  1054. | DATA
  1055. | DATABASE
  1056. | DECIMAL
  1057. | DECLARE
  1058. | DEFAULT
  1059. | DEFERRABLE
  1060. | DEFERRED
  1061. // | DEFINE
  1062. | DELETE
  1063. | DESC
  1064. | DESCRIBE
  1065. | DETACH
  1066. | DIRECTORY
  1067. | DISABLE
  1068. | DISCARD
  1069. // | DO
  1070. | DROP
  1071. | EACH
  1072. | ELSE
  1073. | EMPTY
  1074. | ENCRYPTED
  1075. | END
  1076. | ERROR
  1077. | ESCAPE
  1078. | EVALUATE
  1079. | EXCLUDE
  1080. // | EXCLUSION
  1081. | EXCLUSIVE
  1082. | EXPLAIN
  1083. | EXPORT
  1084. | EXTERNAL
  1085. | FAIL
  1086. | FAMILY
  1087. | FILTER
  1088. | FIRST
  1089. | FLATTEN
  1090. | FOLLOWING
  1091. | FOR
  1092. | FOREIGN
  1093. | FUNCTION
  1094. | GLOB
  1095. | GLOBAL
  1096. | GRANT
  1097. | GROUP
  1098. | GROUPING
  1099. | HASH
  1100. | IF
  1101. | IGNORE
  1102. | ILIKE
  1103. | IMMEDIATE
  1104. | IMPORT
  1105. | IN
  1106. | INCREMENT
  1107. | INCREMENTAL
  1108. | INDEX
  1109. | INDEXED
  1110. | INHERITS
  1111. | INITIAL
  1112. | INITIALLY
  1113. // | INNER
  1114. | INSERT
  1115. | INSTEAD
  1116. | INTO
  1117. | IS
  1118. // | ISNULL
  1119. // | JOIN
  1120. // | KEY
  1121. | LAST
  1122. // | LEFT
  1123. | LEGACY
  1124. | LIKE
  1125. | LOCAL
  1126. | LOGIN
  1127. | MANAGE
  1128. | MATCH
  1129. | MATCHES
  1130. | MATCH_RECOGNIZE
  1131. | MEASURES
  1132. | MICROSECONDS
  1133. | MILLISECONDS
  1134. | MODIFY
  1135. | NANOSECONDS
  1136. // | NATURAL
  1137. | NEXT
  1138. | NO
  1139. | NOLOGIN
  1140. // | NOTNULL
  1141. | NULLS
  1142. | OBJECT
  1143. | OF
  1144. | OFFSET
  1145. | OMIT
  1146. // | ON
  1147. | ONE
  1148. | ONLY
  1149. | OPTION
  1150. | OR
  1151. | ORDER
  1152. | OTHERS
  1153. // | OUTER
  1154. // | OVER
  1155. | PARALLEL
  1156. | PARTITION
  1157. | PASSING
  1158. | PASSWORD
  1159. | PAST
  1160. | PATTERN
  1161. | PER
  1162. | PERMUTE
  1163. | PLAN
  1164. | POOL
  1165. | PRAGMA
  1166. | PRECEDING
  1167. // | PRESORT
  1168. | PRIMARY
  1169. | PRIVILEGES
  1170. | QUERY
  1171. | QUEUE
  1172. | RAISE
  1173. // | READ
  1174. | REFERENCES
  1175. | REGEXP
  1176. | REINDEX
  1177. | RELEASE
  1178. | REMOVE
  1179. | RENAME
  1180. | REPLACE
  1181. | REPLICATION
  1182. | RESET
  1183. | RESPECT
  1184. | RESTART
  1185. | RESTORE
  1186. | RESTRICT
  1187. // | RESULT
  1188. | REVERT
  1189. | REVOKE
  1190. // | RIGHT
  1191. | RLIKE
  1192. | ROLLBACK
  1193. | ROW
  1194. // | SAMPLE
  1195. | SAVEPOINT
  1196. | SECONDS
  1197. | SEEK
  1198. // | SEMI
  1199. | SETS
  1200. | SHOW
  1201. | TSKIP
  1202. | SEQUENCE
  1203. | SOURCE
  1204. | START
  1205. | SUBQUERY
  1206. | SUBSET
  1207. | SYMBOLS
  1208. | SYNC
  1209. | SYSTEM
  1210. | TABLE
  1211. | TABLES
  1212. | TABLESAMPLE
  1213. | TABLESTORE
  1214. | TEMP
  1215. | TEMPORARY
  1216. | THEN
  1217. | TIES
  1218. | TO
  1219. | TOPIC
  1220. | TRANSACTION
  1221. | TRANSFER
  1222. | TRIGGER
  1223. | TYPE
  1224. | UNCONDITIONAL
  1225. | UNIQUE
  1226. | UNKNOWN
  1227. | UNMATCHED
  1228. | UPDATE
  1229. | UPSERT
  1230. | USE
  1231. | USER
  1232. // | USING
  1233. | VACUUM
  1234. | VALUES
  1235. // | VIEW
  1236. | VIRTUAL
  1237. // | WITH
  1238. | WRAPPER
  1239. // | WRITE
  1240. | XOR
  1241. ;
  1242. // insert new keyword into keyword_as_compat also
  1243. keyword_compat: (
  1244. ABORT
  1245. | ACTION
  1246. | ADD
  1247. | AFTER
  1248. | ALTER
  1249. | ANALYZE
  1250. | AND
  1251. | ANSI
  1252. | ARRAY
  1253. | ASC
  1254. | ASYNC
  1255. | AT
  1256. | ATTACH
  1257. | ATTRIBUTES
  1258. | AUTOINCREMENT
  1259. | BACKUP
  1260. | BATCH
  1261. | BEFORE
  1262. | BEGIN
  1263. | BERNOULLI
  1264. | BY
  1265. | CASCADE
  1266. | CHANGEFEED
  1267. | CHECK
  1268. | CLASSIFIER
  1269. | COLLATE
  1270. | COLLECTION
  1271. | COMMIT
  1272. | CONDITIONAL
  1273. | CONFLICT
  1274. | CONNECT
  1275. | CONSTRAINT
  1276. | CONSUMER
  1277. | COVER
  1278. | CREATE
  1279. | CROSS
  1280. | CURRENT
  1281. | DATA
  1282. | DATABASE
  1283. | DECIMAL
  1284. | DECLARE
  1285. | DEFAULT
  1286. | DEFERRABLE
  1287. | DEFERRED
  1288. | DEFINE
  1289. | DELETE
  1290. | DESC
  1291. | DESCRIBE
  1292. | DETACH
  1293. | DIRECTORY
  1294. | DISABLE
  1295. | DISCARD
  1296. | DO
  1297. | DROP
  1298. | EACH
  1299. | ELSE
  1300. | EMPTY
  1301. | ENCRYPTED
  1302. | END
  1303. | ERROR
  1304. | ESCAPE
  1305. | EVALUATE
  1306. | EXCLUDE
  1307. | EXCLUSION
  1308. | EXCLUSIVE
  1309. | EXPLAIN
  1310. | EXPORT
  1311. | EXTERNAL
  1312. | FAIL
  1313. | FAMILY
  1314. | FILTER
  1315. | FIRST
  1316. | FLATTEN
  1317. | FOLLOWING
  1318. | FOR
  1319. | FOREIGN
  1320. | FUNCTION
  1321. | GLOB
  1322. | GLOBAL
  1323. | GRANT
  1324. | GROUP
  1325. | GROUPING
  1326. | HASH
  1327. | IF
  1328. | IGNORE
  1329. | ILIKE
  1330. | IMMEDIATE
  1331. | IMPORT
  1332. | IN
  1333. | INCREMENT
  1334. | INCREMENTAL
  1335. | INDEX
  1336. | INDEXED
  1337. | INHERITS
  1338. | INITIAL
  1339. | INITIALLY
  1340. | INNER
  1341. | INSERT
  1342. | INSTEAD
  1343. | INTO
  1344. | IS
  1345. | ISNULL
  1346. | JOIN
  1347. | KEY
  1348. | LAST
  1349. | LEFT
  1350. | LEGACY
  1351. | LIKE
  1352. | LOCAL
  1353. | LOGIN
  1354. | MANAGE
  1355. | MATCH
  1356. | MATCHES
  1357. | MATCH_RECOGNIZE
  1358. | MEASURES
  1359. | MICROSECONDS
  1360. | MILLISECONDS
  1361. | MODIFY
  1362. | NANOSECONDS
  1363. | NATURAL
  1364. | NEXT
  1365. | NO
  1366. | NOLOGIN
  1367. | NOTNULL
  1368. | NULLS
  1369. | OBJECT
  1370. | OF
  1371. | OFFSET
  1372. | OMIT
  1373. | ON
  1374. | ONE
  1375. | ONLY
  1376. | OPTION
  1377. | OR
  1378. | ORDER
  1379. | OTHERS
  1380. | OUTER
  1381. | OVER
  1382. | PARALLEL
  1383. | PARTITION
  1384. | PASSING
  1385. | PASSWORD
  1386. | PAST
  1387. | PATTERN
  1388. | PER
  1389. | PERMUTE
  1390. | PLAN
  1391. | POOL
  1392. | PRAGMA
  1393. | PRECEDING
  1394. | PRESORT
  1395. | PRIMARY
  1396. | PRIVILEGES
  1397. | QUERY
  1398. | QUEUE
  1399. | RAISE
  1400. // | READ
  1401. | REFERENCES
  1402. | REGEXP
  1403. | REINDEX
  1404. | RELEASE
  1405. | REMOVE
  1406. | RENAME
  1407. | REPLACE
  1408. | REPLICATION
  1409. | RESET
  1410. | RESPECT
  1411. | RESTART
  1412. | RESTORE
  1413. | RESTRICT
  1414. | RESULT
  1415. | REVERT
  1416. | REVOKE
  1417. | RIGHT
  1418. | RLIKE
  1419. | ROLLBACK
  1420. | ROW
  1421. | SAMPLE
  1422. | SAVEPOINT
  1423. | SECONDS
  1424. | SEEK
  1425. | SEMI
  1426. | SETS
  1427. | SHOW
  1428. | TSKIP
  1429. | SEQUENCE
  1430. | SOURCE
  1431. | START
  1432. | SUBQUERY
  1433. | SUBSET
  1434. | SYMBOLS
  1435. | SYNC
  1436. | SYSTEM
  1437. | TABLE
  1438. | TABLES
  1439. | TABLESAMPLE
  1440. | TABLESTORE
  1441. | TEMP
  1442. | TEMPORARY
  1443. | THEN
  1444. | TIES
  1445. | TO
  1446. | TOPIC
  1447. | TRANSACTION
  1448. | TRANSFER
  1449. | TRIGGER
  1450. | TYPE
  1451. | UNCONDITIONAL
  1452. | UNIQUE
  1453. | UNKNOWN
  1454. | UNMATCHED
  1455. | UPDATE
  1456. | UPSERT
  1457. | USE
  1458. | USER
  1459. | USING
  1460. | VACUUM
  1461. | VALUES
  1462. | VIEW
  1463. | VIRTUAL
  1464. | WITH
  1465. | WRAPPER
  1466. // | WRITE
  1467. | XOR
  1468. );
  1469. type_id:
  1470. OPTIONAL
  1471. | TUPLE
  1472. | STRUCT
  1473. | VARIANT
  1474. | LIST
  1475. // | STREAM
  1476. | FLOW
  1477. | DICT
  1478. | SET
  1479. | ENUM
  1480. | RESOURCE
  1481. | TAGGED
  1482. | CALLABLE
  1483. ;
  1484. bool_value: (TRUE | FALSE);
  1485. real: REAL;
  1486. integer: DIGITS | INTEGER_VALUE;
  1487. //
  1488. // Lexer
  1489. //
  1490. EQUALS: '=';
  1491. EQUALS2: '==';
  1492. NOT_EQUALS: '!=';
  1493. NOT_EQUALS2: '<>';
  1494. LESS: '<';
  1495. LESS_OR_EQ: '<=';
  1496. GREATER: '>';
  1497. GREATER_OR_EQ: '>=';
  1498. SHIFT_LEFT: '<<';
  1499. ROT_LEFT: '|<<';
  1500. AMPERSAND: '&';
  1501. PIPE: '|';
  1502. DOUBLE_PIPE: '||';
  1503. STRUCT_OPEN: '<|';
  1504. STRUCT_CLOSE: '|>';
  1505. PLUS: '+';
  1506. MINUS: '-';
  1507. TILDA: '~';
  1508. ASTERISK: '*';
  1509. SLASH: '/';
  1510. PERCENT: '%';
  1511. SEMICOLON: ';';
  1512. DOT: '.';
  1513. COMMA: ',';
  1514. LPAREN: '(';
  1515. RPAREN: ')';
  1516. QUESTION: '?';
  1517. COLON: ':';
  1518. COMMAT: '@';
  1519. DOLLAR: '$';
  1520. LBRACE_CURLY: '{';
  1521. RBRACE_CURLY: '}';
  1522. CARET: '^';
  1523. NAMESPACE: '::';
  1524. ARROW: '->';
  1525. RBRACE_SQUARE: ']';
  1526. LBRACE_SQUARE: '['; // pair ]
  1527. fragment BACKSLASH: '\\';
  1528. fragment QUOTE_DOUBLE: '"';
  1529. fragment QUOTE_SINGLE: '\'';
  1530. fragment BACKTICK: '`';
  1531. fragment DOUBLE_COMMAT: '@@';
  1532. // http://www.antlr.org/wiki/pages/viewpage.action?pageId=1782
  1533. fragment A:('a'|'A');
  1534. fragment B:('b'|'B');
  1535. fragment C:('c'|'C');
  1536. fragment D:('d'|'D');
  1537. fragment E:('e'|'E');
  1538. fragment F:('f'|'F');
  1539. fragment G:('g'|'G');
  1540. fragment H:('h'|'H');
  1541. fragment I:('i'|'I');
  1542. fragment J:('j'|'J');
  1543. fragment K:('k'|'K');
  1544. fragment L:('l'|'L');
  1545. fragment M:('m'|'M');
  1546. fragment N:('n'|'N');
  1547. fragment O:('o'|'O');
  1548. fragment P:('p'|'P');
  1549. fragment Q:('q'|'Q');
  1550. fragment R:('r'|'R');
  1551. fragment S:('s'|'S');
  1552. fragment T:('t'|'T');
  1553. fragment U:('u'|'U');
  1554. fragment V:('v'|'V');
  1555. fragment W:('w'|'W');
  1556. fragment X:('x'|'X');
  1557. fragment Y:('y'|'Y');
  1558. fragment Z:('z'|'Z');
  1559. ABORT: A B O R T;
  1560. ACTION: A C T I O N;
  1561. ADD: A D D;
  1562. AFTER: A F T E R;
  1563. ALL: A L L;
  1564. ALTER: A L T E R;
  1565. ANALYZE: A N A L Y Z E;
  1566. AND: A N D;
  1567. ANSI: A N S I;
  1568. ANY: A N Y;
  1569. ARRAY: A R R A Y;
  1570. AS: A S;
  1571. ASC: A S C;
  1572. ASSUME: A S S U M E;
  1573. ASYMMETRIC: A S Y M M E T R I C;
  1574. ASYNC: A S Y N C;
  1575. AT: A T;
  1576. ATTACH: A T T A C H;
  1577. ATTRIBUTES: A T T R I B U T E S;
  1578. AUTOINCREMENT: A U T O I N C R E M E N T;
  1579. AUTOMAP: A U T O M A P;
  1580. BACKUP: B A C K U P;
  1581. BATCH: B A T C H;
  1582. COLLECTION: C O L L E C T I O N;
  1583. BEFORE: B E F O R E;
  1584. BEGIN: B E G I N;
  1585. BERNOULLI: B E R N O U L L I;
  1586. BETWEEN: B E T W E E N;
  1587. BITCAST: B I T C A S T;
  1588. BY: B Y;
  1589. CALLABLE: C A L L A B L E;
  1590. CASCADE: C A S C A D E;
  1591. CASE: C A S E;
  1592. CAST: C A S T;
  1593. CHANGEFEED: C H A N G E F E E D;
  1594. CHECK: C H E C K;
  1595. CLASSIFIER: C L A S S I F I E R;
  1596. COLLATE: C O L L A T E;
  1597. COLUMN: C O L U M N;
  1598. COLUMNS: C O L U M N S;
  1599. COMMIT: C O M M I T;
  1600. COMPACT: C O M P A C T;
  1601. CONDITIONAL: C O N D I T I O N A L;
  1602. CONFLICT: C O N F L I C T;
  1603. CONNECT: C O N N E C T;
  1604. CONSTRAINT: C O N S T R A I N T;
  1605. CONSUMER: C O N S U M E R;
  1606. COVER: C O V E R;
  1607. CREATE: C R E A T E;
  1608. CROSS: C R O S S;
  1609. CUBE: C U B E;
  1610. CURRENT: C U R R E N T;
  1611. CURRENT_DATE: C U R R E N T '_' D A T E;
  1612. CURRENT_TIME: C U R R E N T '_' T I M E;
  1613. CURRENT_TIMESTAMP: C U R R E N T '_' T I M E S T A M P;
  1614. DATA: D A T A;
  1615. DATABASE: D A T A B A S E;
  1616. DECIMAL: D E C I M A L;
  1617. DECLARE: D E C L A R E;
  1618. DEFAULT: D E F A U L T;
  1619. DEFERRABLE: D E F E R R A B L E;
  1620. DEFERRED: D E F E R R E D;
  1621. DEFINE: D E F I N E;
  1622. DELETE: D E L E T E;
  1623. DESC: D E S C;
  1624. DESCRIBE: D E S C R I B E;
  1625. DETACH: D E T A C H;
  1626. DICT: D I C T;
  1627. DIRECTORY: D I R E C T O R Y;
  1628. DISABLE: D I S A B L E;
  1629. DISCARD: D I S C A R D;
  1630. DISTINCT: D I S T I N C T;
  1631. DO: D O;
  1632. DROP: D R O P;
  1633. // TODO: fix sql formatter and drop EACH
  1634. EACH: E A C H;
  1635. ELSE: E L S E;
  1636. EMPTY: E M P T Y;
  1637. EMPTY_ACTION: E M P T Y '_' A C T I O N;
  1638. ENCRYPTED: E N C R Y P T E D;
  1639. END: E N D;
  1640. ENUM: E N U M;
  1641. ERASE: E R A S E;
  1642. ERROR: E R R O R;
  1643. ESCAPE: E S C A P E;
  1644. EVALUATE: E V A L U A T E;
  1645. EXCEPT: E X C E P T;
  1646. EXCLUDE: E X C L U D E;
  1647. EXCLUSION: E X C L U S I O N;
  1648. EXCLUSIVE: E X C L U S I V E;
  1649. EXISTS: E X I S T S;
  1650. EXPLAIN: E X P L A I N;
  1651. EXPORT: E X P O R T;
  1652. EXTERNAL: E X T E R N A L;
  1653. FAIL: F A I L;
  1654. FALSE: F A L S E;
  1655. FAMILY: F A M I L Y;
  1656. FILTER: F I L T E R;
  1657. FIRST: F I R S T;
  1658. FLATTEN: F L A T T E N;
  1659. FLOW: F L O W;
  1660. FOLLOWING: F O L L O W I N G;
  1661. FOR: F O R;
  1662. FOREIGN: F O R E I G N;
  1663. FROM: F R O M;
  1664. FULL: F U L L;
  1665. FUNCTION: F U N C T I O N;
  1666. GLOB: G L O B;
  1667. GLOBAL: G L O B A L;
  1668. GRANT: G R A N T;
  1669. GROUP: G R O U P;
  1670. GROUPING: G R O U P I N G;
  1671. GROUPS: G R O U P S;
  1672. HASH: H A S H;
  1673. HAVING: H A V I N G;
  1674. HOP: H O P;
  1675. IF: I F;
  1676. IGNORE: I G N O R E;
  1677. ILIKE: I L I K E;
  1678. IMMEDIATE: I M M E D I A T E;
  1679. IMPORT: I M P O R T;
  1680. IN: I N;
  1681. INCREMENT: I N C R E M E N T;
  1682. INCREMENTAL: I N C R E M E N T A L;
  1683. INDEX: I N D E X;
  1684. INDEXED: I N D E X E D;
  1685. INHERITS: I N H E R I T S;
  1686. INITIAL: I N I T I A L;
  1687. INITIALLY: I N I T I A L L Y;
  1688. INNER: I N N E R;
  1689. INSERT: I N S E R T;
  1690. INSTEAD: I N S T E A D;
  1691. INTERSECT: I N T E R S E C T;
  1692. INTO: I N T O;
  1693. IS: I S;
  1694. ISNULL: I S N U L L;
  1695. JOIN: J O I N;
  1696. JSON_EXISTS: J S O N '_' E X I S T S;
  1697. JSON_QUERY: J S O N '_' Q U E R Y;
  1698. JSON_VALUE: J S O N '_' V A L U E;
  1699. KEY: K E Y;
  1700. LAST: L A S T;
  1701. LEFT: L E F T;
  1702. LEGACY: L E G A C Y;
  1703. LIKE: L I K E;
  1704. LIMIT: L I M I T;
  1705. LIST: L I S T;
  1706. LOCAL: L O C A L;
  1707. LOGIN: L O G I N;
  1708. MANAGE: M A N A G E;
  1709. MATCH: M A T C H;
  1710. MATCHES: M A T C H E S;
  1711. MATCH_RECOGNIZE: M A T C H '_' R E C O G N I Z E;
  1712. MEASURES: M E A S U R E S;
  1713. MICROSECONDS: M I C R O S E C O N D S;
  1714. MILLISECONDS: M I L L I S E C O N D S;
  1715. MODIFY: M O D I F Y;
  1716. NANOSECONDS: N A N O S E C O N D S;
  1717. NATURAL: N A T U R A L;
  1718. NEXT: N E X T;
  1719. NO: N O;
  1720. NOLOGIN: N O L O G I N;
  1721. NOT: N O T;
  1722. NOTNULL: N O T N U L L;
  1723. NULL: N U L L;
  1724. NULLS: N U L L S;
  1725. OBJECT: O B J E C T;
  1726. OF: O F;
  1727. OFFSET: O F F S E T;
  1728. OMIT: O M I T;
  1729. ON: O N;
  1730. ONE: O N E;
  1731. ONLY: O N L Y;
  1732. OPTION: O P T I O N;
  1733. OPTIONAL: O P T I O N A L;
  1734. OR: O R;
  1735. ORDER: O R D E R;
  1736. OTHERS: O T H E R S;
  1737. OUTER: O U T E R;
  1738. OVER: O V E R;
  1739. PARALLEL: P A R A L L E L;
  1740. PARTITION: P A R T I T I O N;
  1741. PASSING: P A S S I N G;
  1742. PASSWORD: P A S S W O R D;
  1743. PAST: P A S T;
  1744. PATTERN: P A T T E R N;
  1745. PER: P E R;
  1746. PERMUTE: P E R M U T E;
  1747. PLAN: P L A N;
  1748. POOL: P O O L;
  1749. PRAGMA: P R A G M A;
  1750. PRECEDING: P R E C E D I N G;
  1751. PRESORT: P R E S O R T;
  1752. PRIMARY: P R I M A R Y;
  1753. PRIVILEGES: P R I V I L E G E S;
  1754. PROCESS: P R O C E S S;
  1755. QUERY: Q U E R Y;
  1756. QUEUE: Q U E U E;
  1757. RAISE: R A I S E;
  1758. RANGE: R A N G E;
  1759. //READ: R E A D;
  1760. REDUCE: R E D U C E;
  1761. REFERENCES: R E F E R E N C E S;
  1762. REGEXP: R E G E X P;
  1763. REINDEX: R E I N D E X;
  1764. RELEASE: R E L E A S E;
  1765. REMOVE: R E M O V E;
  1766. RENAME: R E N A M E;
  1767. REPEATABLE: R E P E A T A B L E;
  1768. REPLACE: R E P L A C E;
  1769. REPLICATION: R E P L I C A T I O N;
  1770. RESET: R E S E T;
  1771. RESOURCE: R E S O U R C E;
  1772. RESPECT: R E S P E C T;
  1773. RESTART: R E S T A R T;
  1774. RESTORE: R E S T O R E;
  1775. RESTRICT: R E S T R I C T;
  1776. RESULT: R E S U L T;
  1777. RETURN: R E T U R N;
  1778. RETURNING: R E T U R N I N G;
  1779. REVERT: R E V E R T;
  1780. REVOKE: R E V O K E;
  1781. RIGHT: R I G H T;
  1782. RLIKE: R L I K E;
  1783. ROLLBACK: R O L L B A C K;
  1784. ROLLUP: R O L L U P;
  1785. ROW: R O W;
  1786. ROWS: R O W S;
  1787. SAMPLE: S A M P L E;
  1788. SAVEPOINT: S A V E P O I N T;
  1789. SCHEMA: S C H E M A;
  1790. SECONDS: S E C O N D S;
  1791. SEEK: S E E K;
  1792. SELECT: S E L E C T;
  1793. SEMI: S E M I;
  1794. SET: S E T;
  1795. SETS: S E T S;
  1796. SHOW: S H O W;
  1797. TSKIP: S K I P;
  1798. SEQUENCE: S E Q U E N C E;
  1799. SOURCE: S O U R C E;
  1800. START: S T A R T;
  1801. STREAM: S T R E A M;
  1802. STRUCT: S T R U C T;
  1803. SUBQUERY: S U B Q U E R Y;
  1804. SUBSET: S U B S E T;
  1805. SYMBOLS: S Y M B O L S;
  1806. SYMMETRIC: S Y M M E T R I C;
  1807. SYNC: S Y N C;
  1808. SYSTEM: S Y S T E M;
  1809. TABLE: T A B L E;
  1810. TABLES: T A B L E S;
  1811. TABLESAMPLE: T A B L E S A M P L E;
  1812. TABLESTORE: T A B L E S T O R E;
  1813. TAGGED: T A G G E D;
  1814. TEMP: T E M P;
  1815. TEMPORARY: T E M P O R A R Y;
  1816. THEN: T H E N;
  1817. TIES: T I E S;
  1818. TO: T O;
  1819. TOPIC: T O P I C;
  1820. TRANSACTION: T R A N S A C T I O N;
  1821. TRANSFER: T R A N S F E R;
  1822. TRIGGER: T R I G G E R;
  1823. TRUE: T R U E;
  1824. TUPLE: T U P L E;
  1825. TYPE: T Y P E;
  1826. UNBOUNDED: U N B O U N D E D;
  1827. UNCONDITIONAL: U N C O N D I T I O N A L;
  1828. UNION: U N I O N;
  1829. UNIQUE: U N I Q U E;
  1830. UNKNOWN: U N K N O W N;
  1831. UNMATCHED: U N M A T C H E D;
  1832. UPDATE: U P D A T E;
  1833. UPSERT: U P S E R T;
  1834. USE: U S E;
  1835. USER: U S E R;
  1836. USING: U S I N G;
  1837. VACUUM: V A C U U M;
  1838. VALUES: V A L U E S;
  1839. VARIANT: V A R I A N T;
  1840. VIEW: V I E W;
  1841. VIRTUAL: V I R T U A L;
  1842. WHEN: W H E N;
  1843. WHERE: W H E R E;
  1844. WINDOW: W I N D O W;
  1845. WITH: W I T H;
  1846. WITHOUT: W I T H O U T;
  1847. WRAPPER: W R A P P E R;
  1848. //WRITE: W R I T E;
  1849. XOR: X O R;
  1850. // YQL Default Lexer:
  1851. // GRAMMAR_STRING_CORE_SINGLE = ~(QUOTE_SINGLE | BACKSLASH) | (BACKSLASH .)
  1852. // GRAMMAR_STRING_CORE_DOUBLE = ~(QUOTE_DOUBLE | BACKSLASH) | (BACKSLASH .)
  1853. // ANSI Lexer:
  1854. // GRAMMAR_STRING_CORE_SINGLE = ~QUOTE_SINGLE | (QUOTE_SINGLE QUOTE_SINGLE)
  1855. // GRAMMAR_STRING_CORE_DOUBLE = ~QUOTE_DOUBLE | (QUOTE_DOUBLE QUOTE_DOUBLE)
  1856. fragment STRING_CORE_SINGLE: @GRAMMAR_STRING_CORE_SINGLE@;
  1857. fragment STRING_CORE_DOUBLE: @GRAMMAR_STRING_CORE_DOUBLE@;
  1858. fragment STRING_SINGLE: (QUOTE_SINGLE STRING_CORE_SINGLE* QUOTE_SINGLE);
  1859. fragment STRING_DOUBLE: (QUOTE_DOUBLE STRING_CORE_DOUBLE* QUOTE_DOUBLE);
  1860. fragment STRING_MULTILINE: (DOUBLE_COMMAT .*? DOUBLE_COMMAT)+ COMMAT?;
  1861. STRING_VALUE: ((STRING_SINGLE | STRING_DOUBLE | STRING_MULTILINE) (S | U | Y | J | P (T | B | V)?)?);
  1862. ID_PLAIN: ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | DIGIT)*;
  1863. fragment ID_QUOTED_CORE: '\\'. | '``' | ~('`' | '\\');
  1864. ID_QUOTED: BACKTICK ID_QUOTED_CORE* BACKTICK;
  1865. fragment DIGIT: '0'..'9';
  1866. fragment HEXDIGIT: '0'..'9' | 'a'..'f' | 'A'..'F';
  1867. fragment HEXDIGITS: '0' X HEXDIGIT+;
  1868. fragment OCTDIGITS: '0' O ('0'..'8')+;
  1869. fragment BINDIGITS: '0' B ('0' | '1')+;
  1870. fragment DECDIGITS: DIGIT+;
  1871. DIGITS: DECDIGITS | HEXDIGITS | OCTDIGITS | BINDIGITS;
  1872. // not all combinations of P/U with L/S/T/I/B/N are actually valid - this is resolved in sql.cpp
  1873. INTEGER_VALUE: DIGITS ((P | U)? (L | S | T | I | B | N)?);
  1874. fragment FLOAT_EXP : E (PLUS | MINUS)? DECDIGITS ;
  1875. REAL:
  1876. (
  1877. DECDIGITS DOT DIGIT* FLOAT_EXP?
  1878. | DECDIGITS FLOAT_EXP
  1879. // | DOT DECDIGITS FLOAT_EXP? // Conflicts with tuple element access through DOT
  1880. ) (F | P (F ('4'|'8') | N)?)?
  1881. ;
  1882. BLOB: X QUOTE_SINGLE HEXDIGIT+ QUOTE_SINGLE;
  1883. // YQL Default Lexer:
  1884. // GRAMMAR_MULTILINE_COMMENT_CORE = .
  1885. // ANSI Lexer:
  1886. // GRAMMAR_MULTILINE_COMMENT_CORE = MULTILINE_COMMENT | .
  1887. fragment MULTILINE_COMMENT: '/*' ( @GRAMMAR_MULTILINE_COMMENT_CORE@ )*? '*/';
  1888. fragment LINE_COMMENT: '--' ~('\n'|'\r')* ('\r' '\n'? | '\n' | EOF);
  1889. WS: (' '|'\r'|'\t'|'\u000C'|'\n')->channel(HIDDEN);
  1890. COMMENT: (MULTILINE_COMMENT|LINE_COMMENT)->channel(HIDDEN);