diff options
author | YDBot <[email protected]> | 2025-10-23 18:38:13 +0000 |
---|---|---|
committer | YDBot <[email protected]> | 2025-10-23 18:38:13 +0000 |
commit | 564cf7cb2255a107b4f44c18b2a1844041f20b4d (patch) | |
tree | 6a4a60e8bde612dcc3ac7fd93fffbd36351d4e35 /yql/essentials/sql | |
parent | 89a17b25091c24744b7ebd0650b5b810457b1145 (diff) | |
parent | a703d86902fd02bd8e373d959b2498c034657449 (diff) |
Diffstat (limited to 'yql/essentials/sql')
65 files changed, 628 insertions, 3355 deletions
diff --git a/yql/essentials/sql/v1/SQLv1.g.in b/yql/essentials/sql/v1/SQLv1.g.in deleted file mode 100644 index 8675d3cfef8..00000000000 --- a/yql/essentials/sql/v1/SQLv1.g.in +++ /dev/null @@ -1,2298 +0,0 @@ -grammar SQLv1; - -options { - language = Cpp; - memoize = true; -} - -// Input is a list of statements. -sql_query: sql_stmt_list | PRAGMA ANSI DIGITS ansi_sql_stmt_list; -sql_stmt_list: SEMICOLON* sql_stmt (SEMICOLON+ sql_stmt)* SEMICOLON* EOF; -ansi_sql_stmt_list: SEMICOLON* EOF; - -lambda_body: SEMICOLON* (lambda_stmt SEMICOLON+)* RETURN expr SEMICOLON*; -lambda_stmt: - named_nodes_stmt - | import_stmt -; - -sql_stmt: (EXPLAIN (QUERY PLAN)?)? sql_stmt_core; - -sql_stmt_core: - pragma_stmt - | select_stmt - | named_nodes_stmt - | create_table_stmt - | drop_table_stmt - | use_stmt - | into_table_stmt - | commit_stmt - | update_stmt - | delete_stmt - | rollback_stmt - | declare_stmt - | import_stmt - | export_stmt - | alter_table_stmt - | alter_external_table_stmt - | do_stmt - | define_action_or_subquery_stmt - | if_stmt - | for_stmt - | values_stmt - | create_user_stmt - | alter_user_stmt - | create_group_stmt - | alter_group_stmt - | drop_role_stmt - | create_object_stmt - | alter_object_stmt - | drop_object_stmt - | create_external_data_source_stmt - | alter_external_data_source_stmt - | drop_external_data_source_stmt - | create_replication_stmt - | drop_replication_stmt - | create_topic_stmt - | alter_topic_stmt - | drop_topic_stmt - | grant_permissions_stmt - | revoke_permissions_stmt - | alter_table_store_stmt - | upsert_object_stmt - | create_view_stmt - | drop_view_stmt - | alter_replication_stmt - | create_resource_pool_stmt - | alter_resource_pool_stmt - | drop_resource_pool_stmt - | create_backup_collection_stmt - | alter_backup_collection_stmt - | drop_backup_collection_stmt - | analyze_stmt - | create_resource_pool_classifier_stmt - | alter_resource_pool_classifier_stmt - | drop_resource_pool_classifier_stmt - | backup_stmt - | restore_stmt - | alter_sequence_stmt - | create_transfer_stmt - | alter_transfer_stmt - | drop_transfer_stmt - | alter_database_stmt - | show_create_table_stmt - | create_streaming_query_stmt - | alter_streaming_query_stmt - | drop_streaming_query_stmt - | create_secret_stmt - | alter_secret_stmt - | drop_secret_stmt -; - -expr: - or_subexpr (OR or_subexpr)* - | type_name_composite; - -or_subexpr: and_subexpr (AND and_subexpr)*; - -and_subexpr: xor_subexpr (XOR xor_subexpr)*; - -xor_subexpr: eq_subexpr cond_expr?; - -distinct_from_op: IS NOT? DISTINCT FROM; - -cond_expr: - NOT? match_op eq_subexpr (ESCAPE eq_subexpr)? - | NOT? IN COMPACT? in_expr - | (ISNULL | NOTNULL | IS NULL | (IS)? NOT NULL) - | NOT? BETWEEN (SYMMETRIC | ASYMMETRIC)? eq_subexpr AND eq_subexpr - | ((EQUALS | EQUALS2 | NOT_EQUALS | NOT_EQUALS2 | distinct_from_op) eq_subexpr)+ /* order of the eq subexpressions is reversed! */ -; - -match_op: LIKE | ILIKE | GLOB | REGEXP | RLIKE | MATCH; - -eq_subexpr: neq_subexpr ((LESS | LESS_OR_EQ | GREATER | GREATER_OR_EQ) neq_subexpr)*; - -// workaround for recursive types, '??' and closing '>>' -shift_right: GREATER GREATER; -rot_right: GREATER GREATER PIPE; -double_question: QUESTION QUESTION; - -neq_subexpr: bit_subexpr ((SHIFT_LEFT | shift_right | ROT_LEFT | rot_right | AMPERSAND | PIPE | CARET) bit_subexpr)* - // trailing QUESTIONs are used in optional simple types (String?) and optional lambda args: ($x, $y?) -> ($x) - ((double_question neq_subexpr) => double_question neq_subexpr | QUESTION+)?; - -bit_subexpr: add_subexpr ((PLUS | MINUS) add_subexpr)*; - -add_subexpr: mul_subexpr ((ASTERISK | SLASH | PERCENT) mul_subexpr)*; - -mul_subexpr: con_subexpr (DOUBLE_PIPE con_subexpr)*; - -con_subexpr: unary_subexpr | unary_op unary_subexpr; - -unary_op: PLUS | MINUS | TILDA | NOT; - -unary_subexpr_suffix: ((key_expr | invoke_expr | DOT (bind_parameter | DIGITS | an_id_or_type)))* (COLLATE an_id)?; - -unary_casual_subexpr: (id_expr | atom_expr) unary_subexpr_suffix; - -in_unary_casual_subexpr: (id_expr_in | in_atom_expr) unary_subexpr_suffix; - -unary_subexpr: unary_casual_subexpr | json_api_expr; - -in_unary_subexpr: in_unary_casual_subexpr | json_api_expr; - -list_literal: LBRACE_SQUARE expr_list? COMMA? RBRACE_SQUARE; - -expr_dict_list: expr (COLON expr)? (COMMA expr (COLON expr)?)*; - -dict_literal: LBRACE_CURLY expr_dict_list? COMMA? RBRACE_CURLY; - -expr_struct_list: expr COLON expr (COMMA expr COLON expr)*; - -struct_literal: STRUCT_OPEN expr_struct_list? COMMA? STRUCT_CLOSE; - -atom_expr: - literal_value - | bind_parameter - | lambda - | cast_expr - | exists_expr - | case_expr - | an_id_or_type NAMESPACE (id_or_type | STRING_VALUE) - | value_constructor - | bitcast_expr - | list_literal - | dict_literal - | struct_literal -; - -in_atom_expr: - literal_value - | bind_parameter - | lambda - | cast_expr - | case_expr - | an_id_or_type NAMESPACE (id_or_type | STRING_VALUE) -// TODO: resolve ANTLR error: rule in_atom_expr has non-LL(*) decision due to recursive rule invocations reachable from alts 3,8 -// | LPAREN values_stmt RPAREN - | value_constructor - | bitcast_expr - | list_literal - | dict_literal - | struct_literal -; - -cast_expr: CAST LPAREN expr AS type_name_or_bind RPAREN; - -bitcast_expr: BITCAST LPAREN expr AS type_name_simple RPAREN; - -exists_expr: EXISTS LPAREN (select_stmt | values_stmt) RPAREN; - -case_expr: CASE expr? when_expr+ (ELSE expr)? END; - -lambda: smart_parenthesis (ARROW (LPAREN expr RPAREN | LBRACE_CURLY lambda_body RBRACE_CURLY) )?; - -in_expr: in_unary_subexpr; - -// ANSI SQL JSON support -json_api_expr: json_value | json_exists | json_query; - -jsonpath_spec: STRING_VALUE; - -json_variable_name: id_expr | STRING_VALUE; - -json_variable: expr AS json_variable_name; - -json_variables: json_variable (COMMA json_variable)*; - -json_common_args: expr COMMA jsonpath_spec (PASSING json_variables)?; - -json_case_handler: ERROR | NULL | DEFAULT expr; - -json_value: JSON_VALUE LPAREN - json_common_args - (RETURNING type_name_simple)? - (json_case_handler ON (EMPTY | ERROR))* -RPAREN; - -json_exists_handler: (TRUE | FALSE | UNKNOWN | ERROR) ON ERROR; - -json_exists: JSON_EXISTS LPAREN - json_common_args - json_exists_handler? -RPAREN; - -json_query_wrapper: WITHOUT ARRAY? | WITH (CONDITIONAL | UNCONDITIONAL)? ARRAY?; -json_query_handler: ERROR | NULL | EMPTY ARRAY | EMPTY OBJECT; - -json_query: JSON_QUERY LPAREN - json_common_args - (json_query_wrapper WRAPPER)? - (json_query_handler ON EMPTY)? - (json_query_handler ON ERROR)? -RPAREN; - -select_subexpr: - select_subexpr_intersect (union_op select_subexpr_intersect)* -; - -select_subexpr_intersect: - select_or_expr (intersect_op select_or_expr)* -; - -select_or_expr: select_kind_partial | tuple_or_expr; - -tuple_or_expr: expr (AS an_id_or_type)? (COMMA named_expr)* COMMA?; - -smart_parenthesis: LPAREN (select_subexpr | COMMA?) RPAREN; - -expr_list: expr (COMMA expr)*; - -pure_column_list: LPAREN an_id (COMMA an_id)* RPAREN; - -pure_column_or_named: bind_parameter | an_id; -pure_column_or_named_list: LPAREN pure_column_or_named (COMMA pure_column_or_named)* RPAREN; - -column_name: opt_id_prefix an_id; -without_column_name: an_id DOT an_id | an_id_without; - -column_list: column_name (COMMA column_name)* COMMA?; -without_column_list: without_column_name (COMMA without_column_name)* COMMA?; - -named_expr: expr (AS an_id_or_type)?; - -named_expr_list: named_expr (COMMA named_expr)*; - -invoke_expr: LPAREN (opt_set_quantifier named_expr_list COMMA? | ASTERISK)? RPAREN invoke_expr_tail; - -// null_treatment can only happen after window functions LAG/LEAD/NTH/FIRST_VALUE/LAST_VALUE -// filter_clause can only happen after aggregation functions -invoke_expr_tail: - (null_treatment | filter_clause)? (OVER window_name_or_specification)? -; - -using_call_expr: (an_id_or_type NAMESPACE an_id_or_type | an_id_expr | bind_parameter | EXTERNAL FUNCTION) invoke_expr; - -key_expr: LBRACE_SQUARE expr RBRACE_SQUARE; - -when_expr: WHEN expr THEN expr; - -literal_value: - integer - | real - | STRING_VALUE - | BLOB // it's unused right now - | NULL - | CURRENT_TIME // it's unused right now - | CURRENT_DATE // it's unused right now - | CURRENT_TIMESTAMP // it's unused right now - | bool_value - | EMPTY_ACTION -; - -bind_parameter: DOLLAR (an_id_or_type | TRUE | FALSE); -opt_bind_parameter: bind_parameter QUESTION?; - -bind_parameter_list: bind_parameter (COMMA bind_parameter)*; -named_bind_parameter: bind_parameter (AS bind_parameter)?; -named_bind_parameter_list: named_bind_parameter (COMMA named_bind_parameter)*; - -signed_number: (PLUS | MINUS)? (integer | real); - -type_name_simple: an_id_pure; - -integer_or_bind: integer | bind_parameter; -type_name_tag: id | STRING_VALUE | bind_parameter; - -struct_arg: type_name_tag COLON type_name_or_bind; -struct_arg_positional: - type_name_tag type_name_or_bind (NOT? NULL)? - | type_name_or_bind AS type_name_tag; //deprecated -variant_arg: (type_name_tag COLON)? type_name_or_bind; -callable_arg: variant_arg (LBRACE_CURLY AUTOMAP RBRACE_CURLY)?; -callable_arg_list: callable_arg (COMMA callable_arg)*; - -type_name_decimal: DECIMAL LPAREN integer_or_bind COMMA integer_or_bind RPAREN; -type_name_optional: OPTIONAL LESS type_name_or_bind GREATER; -type_name_tuple: TUPLE (LESS (type_name_or_bind (COMMA type_name_or_bind)* COMMA?)? GREATER | NOT_EQUALS2); -type_name_struct: STRUCT (LESS (struct_arg (COMMA struct_arg)* COMMA?)? GREATER | NOT_EQUALS2); -type_name_variant: VARIANT LESS variant_arg (COMMA variant_arg)* COMMA? GREATER; -type_name_list: LIST LESS type_name_or_bind GREATER; -type_name_stream: STREAM LESS type_name_or_bind GREATER; -type_name_flow: FLOW LESS type_name_or_bind GREATER; -type_name_dict: DICT LESS type_name_or_bind COMMA type_name_or_bind GREATER; -type_name_set: SET LESS type_name_or_bind GREATER; -type_name_enum: ENUM LESS type_name_tag (COMMA type_name_tag)* COMMA? GREATER; -type_name_resource: RESOURCE LESS type_name_tag GREATER; -type_name_tagged: TAGGED LESS type_name_or_bind COMMA type_name_tag GREATER; -type_name_callable: CALLABLE LESS LPAREN callable_arg_list? COMMA? (LBRACE_SQUARE callable_arg_list RBRACE_SQUARE)? RPAREN ARROW type_name_or_bind GREATER; - -type_name_composite: - ( type_name_optional - | type_name_tuple - | type_name_struct - | type_name_variant - | type_name_list - | type_name_stream - | type_name_flow - | type_name_dict - | type_name_set - | type_name_enum - | type_name_resource - | type_name_tagged - | type_name_callable - ) QUESTION*; - -type_name: - type_name_composite - | (type_name_decimal | type_name_simple) QUESTION*; - -type_name_or_bind: type_name | bind_parameter; - -value_constructor_literal: STRING_VALUE; -value_constructor: - VARIANT LPAREN expr COMMA expr COMMA expr RPAREN - | ENUM LPAREN expr COMMA expr RPAREN - | CALLABLE LPAREN expr COMMA expr RPAREN -; - -declare_stmt: DECLARE bind_parameter AS type_name (EQUALS literal_value)?; - -module_path: DOT? an_id (DOT an_id)*; -import_stmt: IMPORT module_path SYMBOLS named_bind_parameter_list; -export_stmt: EXPORT bind_parameter_list; - -call_action: (bind_parameter | EMPTY_ACTION) LPAREN expr_list? RPAREN; -inline_action: BEGIN define_action_or_subquery_body END DO; -do_stmt: DO (call_action | inline_action); -pragma_stmt: PRAGMA opt_id_prefix_or_type an_id (EQUALS pragma_value | LPAREN pragma_value (COMMA pragma_value)* RPAREN)?; - -pragma_value: - signed_number - | id - | STRING_VALUE - | bool_value - | bind_parameter -; - -/// TODO: NULLS FIRST\LAST? -sort_specification: expr (ASC | DESC)?; - -sort_specification_list: sort_specification (COMMA sort_specification)*; - -select_stmt: select_stmt_intersect (union_op select_stmt_intersect)*; - -select_stmt_intersect: select_kind_parenthesis (intersect_op select_kind_parenthesis)*; - -select_unparenthesized_stmt: select_unparenthesized_stmt_intersect (union_op select_stmt_intersect)*; - -select_unparenthesized_stmt_intersect: select_kind_partial (intersect_op select_kind_parenthesis)*; - -select_kind_parenthesis: select_kind_partial | LPAREN select_kind_partial RPAREN; - -union_op: (UNION | EXCEPT) (DISTINCT | ALL)?; - -intersect_op: INTERSECT (DISTINCT | ALL)?; - -select_kind_partial: select_kind - (LIMIT expr ((OFFSET | COMMA) expr)?)? - ; - -select_kind: (DISCARD)? (process_core | reduce_core | select_core) (INTO RESULT pure_column_or_named)?; - -process_core: - PROCESS STREAM? named_single_source (COMMA named_single_source)* (USING using_call_expr (AS an_id)? - (WITH external_call_settings)? - (WHERE expr)? (HAVING expr)? (ASSUME order_by_clause)?)? -; - -external_call_param: an_id EQUALS expr; -external_call_settings: external_call_param (COMMA external_call_param)*; - -reduce_core: - REDUCE named_single_source (COMMA named_single_source)* (PRESORT sort_specification_list)? - ON column_list USING ALL? using_call_expr (AS an_id)? - (WHERE expr)? (HAVING expr)? (ASSUME order_by_clause)? -; - -opt_set_quantifier: (ALL | DISTINCT)?; - -select_core: - (FROM join_source)? SELECT STREAM? opt_set_quantifier result_column (COMMA result_column)* COMMA? (WITHOUT (IF EXISTS)? without_column_list)? (FROM join_source)? (WHERE expr)? - group_by_clause? (HAVING expr)? window_clause? ext_order_by_clause? -; - -// ISO/IEC 9075-2:2016(E) 7.7 <row pattern recognition clause> -row_pattern_recognition_clause: MATCH_RECOGNIZE LPAREN - window_partition_clause? - order_by_clause? - row_pattern_measures? - row_pattern_rows_per_match? - row_pattern_common_syntax - RPAREN -; - -row_pattern_rows_per_match: - ONE ROW PER MATCH - | ALL ROWS PER MATCH row_pattern_empty_match_handling? -; - -row_pattern_empty_match_handling: SHOW EMPTY MATCHES | OMIT EMPTY MATCHES | WITH UNMATCHED ROWS; - -// ISO/IEC 9075-2:2016(E) 7.8 <row pattern measures> -row_pattern_measures: MEASURES row_pattern_measure_list; - -row_pattern_measure_list: row_pattern_measure_definition (COMMA row_pattern_measure_definition)*; - -row_pattern_measure_definition: expr AS an_id; - -// ISO/IEC 9075-2:2016(E) 7.9 <row pattern common syntax> -row_pattern_common_syntax: - (AFTER MATCH row_pattern_skip_to)? - row_pattern_initial_or_seek? - PATTERN LPAREN row_pattern RPAREN - row_pattern_subset_clause? - DEFINE row_pattern_definition_list -; - -row_pattern_skip_to: - SKIP TO NEXT ROW - | SKIP PAST LAST ROW - | SKIP TO FIRST row_pattern_skip_to_variable_name - | SKIP TO LAST row_pattern_skip_to_variable_name - | SKIP TO row_pattern_skip_to_variable_name -; - -row_pattern_skip_to_variable_name: row_pattern_variable_name; - -row_pattern_initial_or_seek: INITIAL | SEEK; - -row_pattern: row_pattern_term (PIPE row_pattern_term)*; - -row_pattern_term: row_pattern_factor+; - -row_pattern_factor: row_pattern_primary row_pattern_quantifier?; - -row_pattern_quantifier: - ASTERISK QUESTION? - | PLUS QUESTION? - | QUESTION QUESTION? - | LBRACE_CURLY integer? COMMA integer? RBRACE_CURLY QUESTION? - | LBRACE_CURLY integer RBRACE_CURLY -; - -row_pattern_primary: - row_pattern_primary_variable_name - | DOLLAR - | CARET - | LPAREN row_pattern? RPAREN - | LBRACE_CURLY MINUS row_pattern MINUS RBRACE_CURLY - | row_pattern_permute -; - -row_pattern_primary_variable_name: row_pattern_variable_name; - -row_pattern_permute: PERMUTE LPAREN - row_pattern (COMMA row_pattern)* - RPAREN -; - -row_pattern_subset_clause: SUBSET row_pattern_subset_list; - -row_pattern_subset_list: row_pattern_subset_item (COMMA row_pattern_subset_item)*; - -row_pattern_subset_item: row_pattern_subset_item_variable_name EQUALS LPAREN - row_pattern_subset_rhs RPAREN -; - -row_pattern_subset_item_variable_name: row_pattern_variable_name; - -row_pattern_subset_rhs: row_pattern_subset_rhs_variable_name (COMMA row_pattern_subset_rhs_variable_name)*; - -row_pattern_subset_rhs_variable_name: row_pattern_variable_name; - -row_pattern_definition_list: row_pattern_definition (COMMA row_pattern_definition)*; - -row_pattern_definition: row_pattern_definition_variable_name AS row_pattern_definition_search_condition; - -row_pattern_definition_variable_name: row_pattern_variable_name; - -row_pattern_definition_search_condition: search_condition; - -search_condition: expr; - -//TODO allow use tokens as vars https://st.yandex-team.ru/YQL-16223 -row_pattern_variable_name: identifier; - -order_by_clause: ORDER BY sort_specification_list; - -ext_order_by_clause: ASSUME? order_by_clause; - -group_by_clause: GROUP COMPACT? BY opt_set_quantifier grouping_element_list (WITH an_id)?; - -grouping_element_list: grouping_element (COMMA grouping_element)*; - -grouping_element: - ordinary_grouping_set - | rollup_list - | cube_list - | grouping_sets_specification -//empty_grouping_set inside smart_parenthesis - | hopping_window_specification -; - -/// expect column (named column), or parenthesis list columns, or expression (named expression), or list expression -ordinary_grouping_set: named_expr; -ordinary_grouping_set_list: ordinary_grouping_set (COMMA ordinary_grouping_set)*; - -rollup_list: ROLLUP LPAREN ordinary_grouping_set_list RPAREN; -cube_list: CUBE LPAREN ordinary_grouping_set_list RPAREN; - -/// SQL2003 grouping_set_list == grouping_element_list -grouping_sets_specification: GROUPING SETS LPAREN grouping_element_list RPAREN; - -hopping_window_specification: HOP LPAREN expr COMMA expr COMMA expr COMMA expr RPAREN; - -result_column: - opt_id_prefix ASTERISK - | expr (AS an_id_or_type | an_id_as_compat)? -; - -join_source: ANY? flatten_source (join_op ANY? flatten_source join_constraint?)*; - -named_column: column_name (AS an_id)?; - -flatten_by_arg: - named_column - | LPAREN named_expr_list COMMA? RPAREN -; - -flatten_source: named_single_source (FLATTEN ((OPTIONAL|LIST|DICT)? BY flatten_by_arg | COLUMNS))?; - -named_single_source: single_source row_pattern_recognition_clause? ((AS an_id | an_id_as_compat) pure_column_list?)? (sample_clause | tablesample_clause)?; - -single_source: - table_ref - | LPAREN select_stmt RPAREN - | LPAREN values_stmt RPAREN -; - -sample_clause: SAMPLE expr; - -tablesample_clause: TABLESAMPLE sampling_mode LPAREN expr RPAREN repeatable_clause?; - -sampling_mode: (BERNOULLI | SYSTEM); - -repeatable_clause: REPEATABLE LPAREN expr RPAREN; - -join_op: - COMMA - | (NATURAL)? ((LEFT (ONLY | SEMI)? | RIGHT (ONLY | SEMI)? | EXCLUSION | FULL)? (OUTER)? | INNER | CROSS) JOIN -; - -join_constraint: - ON expr - | USING pure_column_or_named_list -; - -returning_columns_list: RETURNING (ASTERISK | an_id (COMMA an_id)*); - -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?; - -into_values_source: - pure_column_list? values_source - | DEFAULT VALUES -; - -values_stmt: VALUES values_source_row_list; - -values_source: values_stmt | select_stmt; -values_source_row_list: values_source_row (COMMA values_source_row)*; -values_source_row: LPAREN expr_list RPAREN; - -create_external_data_source_stmt: CREATE (OR REPLACE)? EXTERNAL DATA SOURCE (IF NOT EXISTS)? object_ref - with_table_settings -; - -alter_external_data_source_stmt: ALTER EXTERNAL DATA SOURCE object_ref - alter_external_data_source_action (COMMA alter_external_data_source_action)* -; -alter_external_data_source_action: - alter_table_set_table_setting_uncompat - | alter_table_set_table_setting_compat - | alter_table_reset_table_setting -//| alter_table_rename_to // TODO -; - -drop_external_data_source_stmt: DROP EXTERNAL DATA SOURCE (IF EXISTS)? object_ref; - -create_streaming_query_stmt: CREATE (OR REPLACE)? STREAMING QUERY (IF NOT EXISTS)? object_ref - create_streaming_query_features? - streaming_query_definition -; -create_streaming_query_features: WITH streaming_query_settings; - -alter_streaming_query_stmt: ALTER STREAMING QUERY (IF EXISTS)? object_ref - alter_streaming_query_action -; -alter_streaming_query_action: - alter_streaming_query_set_settings - | alter_streaming_query_set_settings? streaming_query_definition -; -alter_streaming_query_set_settings: SET streaming_query_settings; - -streaming_query_settings: LPAREN streaming_query_setting (COMMA streaming_query_setting)* COMMA? RPAREN; -streaming_query_setting: an_id_or_type EQUALS streaming_query_setting_value; -streaming_query_setting_value: - id_or_type - | STRING_VALUE - | bool_value -; - -streaming_query_definition: AS DO inline_action; - -drop_streaming_query_stmt: DROP STREAMING QUERY (IF EXISTS)? object_ref; - -create_view_stmt: CREATE VIEW (IF NOT EXISTS)? object_ref - create_object_features? - AS select_stmt -; - -drop_view_stmt: DROP VIEW (IF EXISTS)? object_ref; - -upsert_object_stmt: UPSERT OBJECT object_ref - LPAREN TYPE object_type_ref RPAREN - create_object_features? -; -create_object_stmt: CREATE OBJECT (IF NOT EXISTS)? object_ref - LPAREN TYPE object_type_ref RPAREN - create_object_features? -; -create_object_features: WITH object_features; - -alter_object_stmt: ALTER OBJECT object_ref - LPAREN TYPE object_type_ref RPAREN - alter_object_features -; -alter_object_features: SET object_features; - -drop_object_stmt: DROP OBJECT (IF EXISTS)? object_ref - LPAREN TYPE object_type_ref RPAREN - drop_object_features? -; -drop_object_features: WITH object_features; - -object_feature_value: id_or_type | bind_parameter | STRING_VALUE | bool_value; -object_feature_kv: an_id_or_type EQUALS object_feature_value; -object_feature_flag: an_id_or_type; -object_feature: object_feature_kv | object_feature_flag; -object_features: object_feature | LPAREN object_feature (COMMA object_feature)* RPAREN; - -object_type_ref: an_id_or_type; - -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 - table_inherits? - table_partition_by? - with_table_settings? - table_tablestore? - table_as_source?; -create_table_entry: - column_schema - | table_constraint - | table_index - | family_entry - | changefeed - | an_id_schema -; - -create_backup_collection_stmt: CREATE backup_collection create_backup_collection_entries? WITH LPAREN backup_collection_settings RPAREN; -alter_backup_collection_stmt: ALTER backup_collection (alter_backup_collection_actions | alter_backup_collection_entries); -drop_backup_collection_stmt: DROP backup_collection; - -create_backup_collection_entries: DATABASE | create_backup_collection_entries_many; -create_backup_collection_entries_many: LPAREN table_list RPAREN; -table_list: TABLE an_id_table (COMMA TABLE an_id_table)*; - -alter_backup_collection_actions: alter_backup_collection_action (COMMA alter_backup_collection_action)*; -alter_backup_collection_action: - alter_table_set_table_setting_compat - | alter_table_reset_table_setting -; -alter_backup_collection_entries: alter_backup_collection_entry (COMMA alter_backup_collection_entry)*; -alter_backup_collection_entry: - ADD DATABASE - | DROP DATABASE - | ADD TABLE an_id_table - | DROP TABLE an_id_table -; -backup_collection: BACKUP COLLECTION object_ref; -backup_collection_settings: backup_collection_settings_entry (COMMA backup_collection_settings_entry)*; -backup_collection_settings_entry: an_id EQUALS table_setting_value; - -backup_stmt: BACKUP object_ref (INCREMENTAL)?; -restore_stmt: RESTORE object_ref (AT STRING_VALUE)?; - -table_inherits: INHERITS LPAREN simple_table_ref_core (COMMA simple_table_ref_core)* RPAREN; -table_partition_by: PARTITION BY HASH pure_column_list; -with_table_settings: WITH LPAREN table_settings_entry (COMMA table_settings_entry)* RPAREN; -table_tablestore: TABLESTORE simple_table_ref_core; -table_settings_entry: an_id EQUALS table_setting_value; -table_as_source: AS values_source; - -alter_database_stmt: ALTER DATABASE an_id_schema alter_database_action; -alter_database_action: - OWNER TO role_name - | set_database_settings -; -set_database_settings: SET LPAREN database_settings RPAREN; -database_settings: database_setting (COMMA database_setting)*; -database_setting: an_id EQUALS database_setting_value; -database_setting_value: - bool_value - | integer - | STRING_VALUE -; - -alter_table_stmt: ALTER TABLE simple_table_ref alter_table_action (COMMA alter_table_action)*; -alter_table_action: - alter_table_add_column - | alter_table_drop_column - | alter_table_alter_column - | alter_table_add_column_family - | alter_table_alter_column_family - | alter_table_set_table_setting_uncompat - | alter_table_set_table_setting_compat - | alter_table_reset_table_setting - | alter_table_add_index - | alter_table_drop_index - | alter_table_rename_to - | alter_table_add_changefeed - | alter_table_alter_changefeed - | alter_table_drop_changefeed - | alter_table_rename_index_to - | alter_table_alter_index - | alter_table_alter_column_drop_not_null - | alter_table_alter_column_set_not_null -; - -alter_external_table_stmt: ALTER EXTERNAL TABLE simple_table_ref alter_external_table_action (COMMA alter_external_table_action)*; -alter_external_table_action: - alter_table_add_column - | alter_table_drop_column - | alter_table_set_table_setting_uncompat - | alter_table_set_table_setting_compat - | alter_table_reset_table_setting -//| alter_table_rename_to // TODO -; - -alter_table_store_stmt: ALTER TABLESTORE object_ref alter_table_store_action (COMMA alter_table_store_action)*; -alter_table_store_action: - alter_table_add_column - | alter_table_drop_column -; - -alter_table_add_column: ADD COLUMN? column_schema; -alter_table_drop_column: DROP COLUMN? an_id; -alter_table_alter_column: ALTER COLUMN an_id SET family_relation; -alter_table_alter_column_drop_not_null: ALTER COLUMN an_id DROP NOT NULL; -alter_table_alter_column_set_not_null: ALTER COLUMN an_id SET NOT NULL; -alter_table_add_column_family: ADD family_entry; -alter_table_alter_column_family: ALTER FAMILY an_id SET an_id family_setting_value; -alter_table_set_table_setting_uncompat: SET an_id table_setting_value; -alter_table_set_table_setting_compat: SET LPAREN alter_table_setting_entry (COMMA alter_table_setting_entry)* RPAREN; -alter_table_reset_table_setting: RESET LPAREN an_id (COMMA an_id)* RPAREN; -alter_table_add_index: ADD table_index; -alter_table_drop_index: DROP INDEX an_id; -alter_table_rename_to: RENAME TO an_id_table; -alter_table_rename_index_to: RENAME INDEX an_id TO an_id; -alter_table_add_changefeed: ADD changefeed; -alter_table_alter_changefeed: ALTER CHANGEFEED an_id changefeed_alter_settings; -alter_table_drop_changefeed: DROP CHANGEFEED an_id; -alter_table_alter_index: ALTER INDEX an_id alter_table_alter_index_action; - -column_schema: an_id_schema type_name_or_bind column_option_list; - -column_option_list: column_option_list_space | column_option_list_comma; -column_option_list_space: (column_option)*; -column_option_list_comma: LPAREN column_option (COMMA column_option)* RPAREN; - -column_option: - family_relation - | nullability - | default_value - ; - -family_relation: FAMILY an_id; -nullability: NOT? NULL; -default_value: DEFAULT expr; - -column_order_by_specification: an_id (ASC | DESC)?; - -table_constraint: - PRIMARY KEY LPAREN an_id (COMMA an_id)* RPAREN - | PARTITION BY LPAREN an_id (COMMA an_id)* RPAREN - | ORDER BY LPAREN column_order_by_specification (COMMA column_order_by_specification)* RPAREN -; - -table_index: INDEX an_id table_index_type - ON LPAREN an_id_schema (COMMA an_id_schema)* RPAREN - (COVER LPAREN an_id_schema (COMMA an_id_schema)* RPAREN)? - with_index_settings? -; - -table_index_type: (global_index | local_index) (USING index_subtype)?; - -global_index: GLOBAL UNIQUE? (SYNC | ASYNC)?; -local_index: LOCAL; - -index_subtype: an_id; - -with_index_settings: WITH LPAREN index_setting_entry (COMMA index_setting_entry)* COMMA? RPAREN; -index_setting_entry: an_id EQUALS index_setting_value; -index_setting_value: - id_or_type - | STRING_VALUE - | integer - | bool_value -; - -changefeed: CHANGEFEED an_id WITH LPAREN changefeed_settings RPAREN; -changefeed_settings: changefeed_settings_entry (COMMA changefeed_settings_entry)*; -changefeed_settings_entry: an_id EQUALS changefeed_setting_value; -changefeed_setting_value: expr; -changefeed_alter_settings: - DISABLE - | SET LPAREN changefeed_settings RPAREN -; - -alter_table_setting_entry: an_id EQUALS table_setting_value; - -table_setting_value: - id - | STRING_VALUE - | integer - | split_boundaries - | ttl_tier_list ON an_id (AS (SECONDS | MILLISECONDS | MICROSECONDS | NANOSECONDS))? - | bool_value -; - -ttl_tier_list: expr (ttl_tier_action (COMMA expr ttl_tier_action)*)?; -ttl_tier_action: - TO EXTERNAL DATA SOURCE an_id - | DELETE -; - -family_entry: FAMILY an_id family_settings; -family_settings: LPAREN (family_settings_entry (COMMA family_settings_entry)*)? RPAREN; -family_settings_entry: an_id EQUALS family_setting_value; -family_setting_value: - STRING_VALUE - | integer -; - -split_boundaries: - LPAREN literal_value_list (COMMA literal_value_list)* RPAREN - | literal_value_list -; - -literal_value_list: LPAREN literal_value (COMMA literal_value)* RPAREN; - -alter_table_alter_index_action: - alter_table_set_table_setting_uncompat - | alter_table_set_table_setting_compat - | alter_table_reset_table_setting -; - -drop_table_stmt: DROP (TABLE | TABLESTORE | EXTERNAL TABLE) (IF EXISTS)? simple_table_ref; - -create_user_stmt: CREATE USER role_name user_option*; -alter_user_stmt: ALTER USER role_name (WITH? user_option+ | RENAME TO role_name); - -create_group_stmt: CREATE GROUP role_name (WITH USER role_name (COMMA role_name)* COMMA?)?; -alter_group_stmt: ALTER GROUP role_name ((ADD|DROP) USER role_name (COMMA role_name)* COMMA? | RENAME TO role_name); - -drop_role_stmt: DROP (USER|GROUP) (IF EXISTS)? role_name (COMMA role_name)* COMMA?; - -role_name: an_id_or_type | bind_parameter; - -user_option: authentication_option | login_option; - -authentication_option: password_option | hash_option; -password_option: ENCRYPTED? PASSWORD password_value; -password_value: STRING_VALUE | NULL; -hash_option: HASH STRING_VALUE; -login_option: LOGIN | NOLOGIN; - -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)?; -revoke_permissions_stmt: REVOKE (GRANT OPTION FOR)? permission_name_target ON an_id_schema (COMMA an_id_schema)* FROM role_name (COMMA role_name)*; - -permission_id: - CONNECT - | LIST - | INSERT - | MANAGE - | DROP - | GRANT - | MODIFY (TABLES | ATTRIBUTES) - | (UPDATE | ERASE) ROW - | (REMOVE | DESCRIBE | ALTER) SCHEMA - | SELECT (TABLES | ATTRIBUTES | ROW)? - | (USE | FULL) LEGACY? - | CREATE (DIRECTORY | TABLE | QUEUE)? -; - -permission_name: permission_id | STRING_VALUE; - -permission_name_target: permission_name (COMMA permission_name)* COMMA? | ALL PRIVILEGES?; - -create_resource_pool_stmt: CREATE RESOURCE POOL object_ref - with_table_settings -; - -alter_resource_pool_stmt: ALTER RESOURCE POOL object_ref - alter_resource_pool_action (COMMA alter_resource_pool_action)* -; -alter_resource_pool_action: - alter_table_set_table_setting_compat - | alter_table_reset_table_setting -; - -drop_resource_pool_stmt: DROP RESOURCE POOL object_ref; - -create_resource_pool_classifier_stmt: CREATE RESOURCE POOL CLASSIFIER object_ref - with_table_settings -; - -alter_resource_pool_classifier_stmt: ALTER RESOURCE POOL CLASSIFIER object_ref - alter_resource_pool_classifier_action (COMMA alter_resource_pool_classifier_action)* -; -alter_resource_pool_classifier_action: - alter_table_set_table_setting_compat - | alter_table_reset_table_setting -; - -drop_resource_pool_classifier_stmt: DROP RESOURCE POOL CLASSIFIER object_ref; - -create_replication_stmt: CREATE ASYNC REPLICATION object_ref - FOR replication_target (COMMA replication_target)* - WITH LPAREN replication_settings RPAREN -; - -replication_target: object_ref AS object_ref; -replication_settings: replication_settings_entry (COMMA replication_settings_entry)*; -replication_settings_entry: an_id EQUALS expr; - -alter_replication_stmt: ALTER ASYNC REPLICATION object_ref alter_replication_action (COMMA alter_replication_action)*; -alter_replication_action: - alter_replication_set_setting -; - -alter_replication_set_setting: SET LPAREN replication_settings RPAREN; - -drop_replication_stmt: DROP ASYNC REPLICATION object_ref CASCADE?; - -create_transfer_stmt: CREATE TRANSFER object_ref - FROM object_ref TO object_ref USING lambda_or_parameter - (WITH LPAREN transfer_settings RPAREN)? -; - -lambda_or_parameter: - lambda - | bind_parameter -; -transfer_settings: transfer_settings_entry (COMMA transfer_settings_entry)*; -transfer_settings_entry: an_id EQUALS expr; - -alter_transfer_stmt: ALTER TRANSFER object_ref alter_transfer_action (COMMA alter_transfer_action)*; -alter_transfer_action: - alter_transfer_set_setting - | alter_transfer_set_using -; - -alter_transfer_set_setting: SET LPAREN transfer_settings RPAREN; -alter_transfer_set_using: SET USING lambda_or_parameter; - -drop_transfer_stmt: DROP TRANSFER object_ref CASCADE?; - -action_or_subquery_args: opt_bind_parameter (COMMA opt_bind_parameter)*; - -define_action_or_subquery_stmt: DEFINE (ACTION|SUBQUERY) bind_parameter LPAREN action_or_subquery_args? RPAREN AS define_action_or_subquery_body END DEFINE; -define_action_or_subquery_body: SEMICOLON* (sql_stmt_core (SEMICOLON+ sql_stmt_core)* SEMICOLON*)?; - -if_stmt: EVALUATE? IF expr do_stmt (ELSE do_stmt)?; -for_stmt: EVALUATE? PARALLEL? FOR bind_parameter IN expr do_stmt (ELSE do_stmt)?; - -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?; - -table_key: id_table_or_type (VIEW view_name)?; -table_arg: COMMAT? named_expr (VIEW view_name)?; -table_hints: WITH (table_hint | LPAREN table_hint (COMMA table_hint)* RPAREN); -table_hint: - an_id_hint (EQUALS (type_name_tag | LPAREN type_name_tag (COMMA type_name_tag)* COMMA? RPAREN))? - | (SCHEMA | COLUMNS) EQUALS? type_name_or_bind - | SCHEMA EQUALS? LPAREN (struct_arg_positional (COMMA struct_arg_positional)*)? COMMA? RPAREN - | WATERMARK AS LPAREN expr RPAREN -; - -object_ref: (cluster_expr DOT)? id_or_at; -simple_table_ref_core: object_ref | (cluster_expr DOT)? COMMAT? bind_parameter; -simple_table_ref: simple_table_ref_core table_hints?; -into_simple_table_ref: simple_table_ref (ERASE BY pure_column_list)?; - -delete_stmt: BATCH? DELETE FROM simple_table_ref (WHERE expr | ON into_values_source)? returning_columns_list?; -update_stmt: BATCH? UPDATE simple_table_ref (SET set_clause_choice (WHERE expr)? | ON into_values_source) returning_columns_list?; - -/// out of 2003 standard -set_clause_choice: set_clause_list | multiple_column_assignment; - -set_clause_list: set_clause (COMMA set_clause)*; -set_clause: set_target EQUALS expr; -set_target: column_name; -multiple_column_assignment: set_target_list EQUALS smart_parenthesis; -set_target_list: LPAREN set_target (COMMA set_target)* RPAREN; - -// topics -create_topic_stmt: CREATE TOPIC (IF NOT EXISTS)? topic_ref create_topic_entries? with_topic_settings?; - -create_topic_entries: LPAREN create_topic_entry (COMMA create_topic_entry)* RPAREN; -create_topic_entry: - topic_create_consumer_entry -; -with_topic_settings: WITH LPAREN topic_settings RPAREN; - -alter_topic_stmt: ALTER TOPIC (IF EXISTS)? topic_ref alter_topic_action (COMMA alter_topic_action)*; -alter_topic_action: - alter_topic_add_consumer - | alter_topic_alter_consumer - | alter_topic_drop_consumer - | alter_topic_set_settings - | alter_topic_reset_settings -; - -alter_topic_add_consumer: ADD topic_create_consumer_entry; -topic_create_consumer_entry: CONSUMER an_id topic_consumer_with_settings?; - -alter_topic_alter_consumer: ALTER CONSUMER topic_consumer_ref alter_topic_alter_consumer_entry; -alter_topic_alter_consumer_entry: - topic_alter_consumer_set - | topic_alter_consumer_reset -; - -alter_topic_drop_consumer: DROP CONSUMER topic_consumer_ref; - -topic_alter_consumer_set: SET LPAREN topic_consumer_settings RPAREN; -topic_alter_consumer_reset: RESET LPAREN an_id (COMMA an_id)* RPAREN; - -alter_topic_set_settings: SET LPAREN topic_settings RPAREN; -alter_topic_reset_settings: RESET LPAREN an_id (COMMA an_id_pure)* RPAREN; - -drop_topic_stmt: DROP TOPIC (IF EXISTS)? topic_ref; - -topic_settings: topic_settings_entry (COMMA topic_settings_entry)*; -topic_settings_entry: an_id EQUALS topic_setting_value; -topic_setting_value: - expr -; - -topic_consumer_with_settings: WITH LPAREN topic_consumer_settings RPAREN; -topic_consumer_settings: topic_consumer_settings_entry (COMMA topic_consumer_settings_entry)*; -topic_consumer_settings_entry: an_id EQUALS topic_consumer_setting_value; -topic_consumer_setting_value: - expr -; - -topic_ref: (cluster_expr DOT)? an_id; -topic_consumer_ref: an_id_pure; - -/// window function supp -// differ from 2003 for resolve conflict -null_treatment: RESPECT NULLS | IGNORE NULLS; - -filter_clause: FILTER LPAREN WHERE expr RPAREN; - -window_name_or_specification: window_name | window_specification; - -window_name: an_id_window; - -window_clause: WINDOW window_definition_list; - -window_definition_list: window_definition (COMMA window_definition)*; - -window_definition: new_window_name AS window_specification; - -new_window_name: window_name; - -window_specification: LPAREN window_specification_details RPAREN; - -window_specification_details: - existing_window_name? - window_partition_clause? - window_order_clause? - window_frame_clause? -; - -existing_window_name: window_name; -window_partition_clause: PARTITION COMPACT? BY named_expr_list; -window_order_clause: order_by_clause; - -window_frame_clause: window_frame_units window_frame_extent window_frame_exclusion?; -window_frame_units: ROWS | RANGE | GROUPS; - -window_frame_extent: window_frame_bound | window_frame_between; - -window_frame_between: BETWEEN window_frame_bound AND window_frame_bound; - -window_frame_bound: - CURRENT ROW - | (expr | UNBOUNDED) (PRECEDING | FOLLOWING) -; - -window_frame_exclusion: EXCLUDE CURRENT ROW | EXCLUDE GROUP | EXCLUDE TIES | EXCLUDE NO OTHERS; - -// EXTRAS -use_stmt: USE cluster_expr; - -// TODO: [fatal] rule named_nodes_stmt has non-LL(*) decision due to recursive rule invocations reachable from alts 1,3 -// named_nodes_stmt: bind_parameter_list EQUALS (expr | subselect_stmt | values_stmt | LPAREN values_stmt RPAREN); -named_nodes_stmt: bind_parameter_list EQUALS (expr | select_unparenthesized_stmt); - -commit_stmt: COMMIT; - -rollback_stmt: ROLLBACK; - -analyze_table: simple_table_ref (LPAREN column_list RPAREN)?; -analyze_table_list: analyze_table (COMMA analyze_table)* COMMA?; -analyze_stmt: ANALYZE analyze_table_list; - -alter_sequence_stmt: ALTER SEQUENCE (IF EXISTS)? object_ref alter_sequence_action+; -alter_sequence_action: - START WITH? integer - | RESTART WITH? integer - | RESTART - | INCREMENT BY? integer -; - -show_create_table_stmt: SHOW CREATE (TABLE | VIEW) simple_table_ref; - -create_secret_stmt: CREATE SECRET object_ref - with_secret_settings -; -with_secret_settings: WITH LPAREN secret_setting_entry (COMMA secret_setting_entry)* RPAREN; -secret_setting_entry: an_id EQUALS secret_setting_value; -secret_setting_value: - STRING_VALUE - | bool_value - | bind_parameter -; - -alter_secret_stmt: ALTER SECRET object_ref - with_secret_settings -; - -drop_secret_stmt: DROP SECRET object_ref; - -// Special rules that allow to use certain keywords as identifiers. -identifier: ID_PLAIN | ID_QUOTED; -id: identifier | keyword; - -id_schema: - identifier - | keyword_compat - | keyword_expr_uncompat -// | keyword_table_uncompat - | keyword_select_uncompat -// | keyword_alter_uncompat - | keyword_in_uncompat - | keyword_window_uncompat - | keyword_hint_uncompat -; - -id_expr: - identifier - | keyword_compat -// | keyword_expr_uncompat -// | keyword_table_uncompat -// | keyword_select_uncompat - | keyword_alter_uncompat - | keyword_in_uncompat - | keyword_window_uncompat - | keyword_hint_uncompat -; - -id_expr_in: - identifier - | keyword_compat -// | keyword_expr_uncompat -// | keyword_table_uncompat -// | keyword_select_uncompat - | keyword_alter_uncompat -// | keyword_in_uncompat - | keyword_window_uncompat - | keyword_hint_uncompat -; - -id_window: - identifier - | keyword_compat - | keyword_expr_uncompat - | keyword_table_uncompat - | keyword_select_uncompat - | keyword_alter_uncompat - | keyword_in_uncompat -// | keyword_window_uncompat - | keyword_hint_uncompat -; - -id_table: - identifier - | keyword_compat - | keyword_expr_uncompat -// | keyword_table_uncompat - | keyword_select_uncompat -// | keyword_alter_uncompat - | keyword_in_uncompat - | keyword_window_uncompat - | keyword_hint_uncompat -; - -id_without: - identifier - | keyword_compat -// | keyword_expr_uncompat - | keyword_table_uncompat -// | keyword_select_uncompat - | keyword_alter_uncompat - | keyword_in_uncompat - | keyword_window_uncompat - | keyword_hint_uncompat -; - -id_hint: - identifier - | keyword_compat - | keyword_expr_uncompat - | keyword_table_uncompat - | keyword_select_uncompat - | keyword_alter_uncompat - | keyword_in_uncompat - | keyword_window_uncompat -// | keyword_hint_uncompat -; - -id_as_compat: identifier | keyword_as_compat; - -// ANSI-aware versions of various identifiers with support double-quoted identifiers when PRAGMA AnsiQuotedIdentifiers; is present -an_id: id | STRING_VALUE; -an_id_or_type: id_or_type | STRING_VALUE; -an_id_schema: id_schema | STRING_VALUE; -an_id_expr: id_expr | STRING_VALUE; -an_id_expr_in: id_expr_in | STRING_VALUE; -an_id_window: id_window | STRING_VALUE; -an_id_table: id_table | STRING_VALUE; -an_id_without: id_without | STRING_VALUE; -an_id_hint: id_hint | STRING_VALUE; -an_id_pure: identifier | STRING_VALUE; -an_id_as_compat: id_as_compat | STRING_VALUE; - -view_name: an_id | PRIMARY KEY; - -opt_id_prefix: (an_id DOT)?; -cluster_expr: (an_id COLON)? (pure_column_or_named | ASTERISK); - -id_or_type: id | type_id; -opt_id_prefix_or_type: (an_id_or_type DOT)?; -id_or_at: COMMAT? an_id_or_type; -id_table_or_type: an_id_table | type_id; -id_table_or_at: COMMAT? id_table_or_type; - -keyword: - keyword_compat - | keyword_expr_uncompat - | keyword_table_uncompat - | keyword_select_uncompat - | keyword_alter_uncompat - | keyword_in_uncompat - | keyword_window_uncompat - | keyword_hint_uncompat -; - -keyword_expr_uncompat: - ASYMMETRIC - | BETWEEN - | BITCAST - | CASE - | CAST - | CUBE - | CURRENT_DATE - | CURRENT_TIME - | CURRENT_TIMESTAMP - | EMPTY_ACTION - | EXISTS - | FROM - | FULL - | HOP - | JSON_EXISTS - | JSON_VALUE - | JSON_QUERY - | NOT - | NULL - | PROCESS - | REDUCE - | RETURN - | RETURNING - | ROLLUP - | SELECT - | SYMMETRIC - | UNBOUNDED - | WHEN - | WHERE -; - -keyword_table_uncompat: - ANY - | ERASE - | STREAM -; - -keyword_select_uncompat: - ALL - | AS - | ASSUME - | DISTINCT - | EXCEPT - | HAVING - | INTERSECT - | LIMIT - | UNION - | WINDOW - | WITHOUT -; - -keyword_alter_uncompat: - COLUMN -; - -keyword_in_uncompat: - COMPACT -; - -keyword_window_uncompat: - GROUPS - | RANGE - | ROWS -; - -keyword_hint_uncompat: - SCHEMA - | COLUMNS -; - -keyword_as_compat: - ABORT - | ACTION - | ADD - | AFTER - | ALTER - | ANALYZE - | AND - | ANSI - | ARRAY - | ASC - | ASYNC - | AT - | ATTACH - | ATTRIBUTES - | AUTOINCREMENT - | BACKUP - | BATCH - | BEFORE - | BEGIN - | BERNOULLI - | BY - | CASCADE - | CHANGEFEED - | CHECK - | CLASSIFIER - // | COLLATE - | COLLECTION - | COMMIT - | CONDITIONAL - | CONFLICT - | CONNECT - | CONSTRAINT - | CONSUMER - | COVER - | CREATE - // | CROSS - | CURRENT - | DATA - | DATABASE - | DECIMAL - | DECLARE - | DEFAULT - | DEFERRABLE - | DEFERRED - // | DEFINE - | DELETE - | DESC - | DESCRIBE - | DETACH - | DIRECTORY - | DISABLE - | DISCARD - // | DO - | DROP - | EACH - | ELSE - | EMPTY - | ENCRYPTED - | END - | ERROR - | ESCAPE - | EVALUATE - | EXCLUDE - // | EXCLUSION - | EXCLUSIVE - | EXPLAIN - | EXPORT - | EXTERNAL - | FAIL - | FAMILY - | FILTER - | FIRST - | FLATTEN - | FOLLOWING - | FOR - | FOREIGN - | FUNCTION - | GLOB - | GLOBAL - | GRANT - | GROUP - | GROUPING - | HASH - | IF - | IGNORE - | ILIKE - | IMMEDIATE - | IMPORT - | IN - | INCREMENT - | INCREMENTAL - | INDEX - | INDEXED - | INHERITS - | INITIAL - | INITIALLY - // | INNER - | INSERT - | INSTEAD - | INTO - | IS - // | ISNULL - // | JOIN - // | KEY - | LAST - // | LEFT - | LEGACY - | LIKE - | LOCAL - | LOGIN - | MANAGE - | MATCH - | MATCHES - | MATCH_RECOGNIZE - | MEASURES - | MICROSECONDS - | MILLISECONDS - | MODIFY - | NANOSECONDS - // | NATURAL - | NEXT - | NO - | NOLOGIN - // | NOTNULL - | NULLS - | OBJECT - | OF - | OFFSET - | OMIT - // | ON - | ONE - | ONLY - | OPTION - | OR - | ORDER - | OTHERS - // | OUTER - // | OVER - | OWNER - | PARALLEL - | PARTITION - | PASSING - | PASSWORD - | PAST - | PATTERN - | PER - | PERMUTE - | PLAN - | POOL - | PRAGMA - | PRECEDING - // | PRESORT - | PRIMARY - | PRIVILEGES - | QUERY - | QUEUE - | RAISE -// | READ - | REFERENCES - | REGEXP - | REINDEX - | RELEASE - | REMOVE - | RENAME - | REPLACE - | REPLICATION - | RESET - | RESPECT - | RESTART - | RESTORE - | RESTRICT - // | RESULT - | REVERT - | REVOKE - // | RIGHT - | RLIKE - | ROLLBACK - | ROW - // | SAMPLE - | SAVEPOINT - | SECONDS - | SECRET - | SEEK - // | SEMI - | SETS - | SHOW - | SKIP - | SEQUENCE - | SOURCE - | START - | STREAMING - | SUBQUERY - | SUBSET - | SYMBOLS - | SYNC - | SYSTEM - | TABLE - | TABLES - | TABLESAMPLE - | TABLESTORE - | TEMP - | TEMPORARY - | THEN - | TIES - | TO - | TOPIC - | TRANSACTION - | TRANSFER - | TRIGGER - | TYPE - | UNCONDITIONAL - | UNIQUE - | UNKNOWN - | UNMATCHED - | UPDATE - | UPSERT - | USE - | USER -// | USING - | VACUUM - | VALUES -// | VIEW - | VIRTUAL - | WATERMARK -// | WITH - | WRAPPER -// | WRITE - | XOR -; - -// insert new keyword into keyword_as_compat also -keyword_compat: ( - ABORT - | ACTION - | ADD - | AFTER - | ALTER - | ANALYZE - | AND - | ANSI - | ARRAY - | ASC - | ASYNC - | AT - | ATTACH - | ATTRIBUTES - | AUTOINCREMENT - | BACKUP - | BATCH - | BEFORE - | BEGIN - | BERNOULLI - | BY - | CASCADE - | CHANGEFEED - | CHECK - | CLASSIFIER - | COLLATE - | COLLECTION - | COMMIT - | CONDITIONAL - | CONFLICT - | CONNECT - | CONSTRAINT - | CONSUMER - | COVER - | CREATE - | CROSS - | CURRENT - | DATA - | DATABASE - | DECIMAL - | DECLARE - | DEFAULT - | DEFERRABLE - | DEFERRED - | DEFINE - | DELETE - | DESC - | DESCRIBE - | DETACH - | DIRECTORY - | DISABLE - | DISCARD - | DO - | DROP - | EACH - | ELSE - | EMPTY - | ENCRYPTED - | END - | ERROR - | ESCAPE - | EVALUATE - | EXCLUDE - | EXCLUSION - | EXCLUSIVE - | EXPLAIN - | EXPORT - | EXTERNAL - | FAIL - | FAMILY - | FILTER - | FIRST - | FLATTEN - | FOLLOWING - | FOR - | FOREIGN - | FUNCTION - | GLOB - | GLOBAL - | GRANT - | GROUP - | GROUPING - | HASH - | IF - | IGNORE - | ILIKE - | IMMEDIATE - | IMPORT - | IN - | INCREMENT - | INCREMENTAL - | INDEX - | INDEXED - | INHERITS - | INITIAL - | INITIALLY - | INNER - | INSERT - | INSTEAD - | INTO - | IS - | ISNULL - | JOIN - | KEY - | LAST - | LEFT - | LEGACY - | LIKE - | LOCAL - | LOGIN - | MANAGE - | MATCH - | MATCHES - | MATCH_RECOGNIZE - | MEASURES - | MICROSECONDS - | MILLISECONDS - | MODIFY - | NANOSECONDS - | NATURAL - | NEXT - | NO - | NOLOGIN - | NOTNULL - | NULLS - | OBJECT - | OF - | OFFSET - | OMIT - | ON - | ONE - | ONLY - | OPTION - | OR - | ORDER - | OTHERS - | OUTER - | OVER - | OWNER - | PARALLEL - | PARTITION - | PASSING - | PASSWORD - | PAST - | PATTERN - | PER - | PERMUTE - | PLAN - | POOL - | PRAGMA - | PRECEDING - | PRESORT - | PRIMARY - | PRIVILEGES - | QUERY - | QUEUE - | RAISE -// | READ - | REFERENCES - | REGEXP - | REINDEX - | RELEASE - | REMOVE - | RENAME - | REPLACE - | REPLICATION - | RESET - | RESPECT - | RESTART - | RESTORE - | RESTRICT - | RESULT - | REVERT - | REVOKE - | RIGHT - | RLIKE - | ROLLBACK - | ROW - | SAMPLE - | SAVEPOINT - | SECONDS - | SECRET - | SEEK - | SEMI - | SETS - | SHOW - | SKIP - | SEQUENCE - | SOURCE - | START - | STREAMING - | SUBQUERY - | SUBSET - | SYMBOLS - | SYNC - | SYSTEM - | TABLE - | TABLES - | TABLESAMPLE - | TABLESTORE - | TEMP - | TEMPORARY - | THEN - | TIES - | TO - | TOPIC - | TRANSACTION - | TRANSFER - | TRIGGER - | TYPE - | UNCONDITIONAL - | UNIQUE - | UNKNOWN - | UNMATCHED - | UPDATE - | UPSERT - | USE - | USER - | USING - | VACUUM - | VALUES - | VIEW - | VIRTUAL - | WATERMARK - | WITH - | WRAPPER -// | WRITE - | XOR - ); - -type_id: - OPTIONAL - | TUPLE - | STRUCT - | VARIANT - | LIST -// | STREAM - | FLOW - | DICT - | SET - | ENUM - | RESOURCE - | TAGGED - | CALLABLE -; - -bool_value: (TRUE | FALSE); -real: REAL; -integer: DIGITS | INTEGER_VALUE; - -// -// Lexer -// - -EQUALS: '='; -EQUALS2: '=='; -NOT_EQUALS: '!='; -NOT_EQUALS2: '<>'; -LESS: '<'; -LESS_OR_EQ: '<='; -GREATER: '>'; -GREATER_OR_EQ: '>='; -SHIFT_LEFT: '<<'; -ROT_LEFT: '|<<'; -AMPERSAND: '&'; -PIPE: '|'; -DOUBLE_PIPE: '||'; -STRUCT_OPEN: '<|'; -STRUCT_CLOSE: '|>'; -PLUS: '+'; -MINUS: '-'; -TILDA: '~'; -ASTERISK: '*'; -SLASH: '/'; -PERCENT: '%'; -SEMICOLON: ';'; -DOT: '.'; -COMMA: ','; -LPAREN: '('; -RPAREN: ')'; -QUESTION: '?'; -COLON: ':'; -COMMAT: '@'; -DOLLAR: '$'; -LBRACE_CURLY: '{'; -RBRACE_CURLY: '}'; -CARET: '^'; -NAMESPACE: '::'; -ARROW: '->'; -RBRACE_SQUARE: ']'; -LBRACE_SQUARE: '['; // pair ] - -fragment BACKSLASH: '\\'; -fragment QUOTE_DOUBLE: '"'; -fragment QUOTE_SINGLE: '\''; -fragment BACKTICK: '`'; -fragment DOUBLE_COMMAT: '@@'; - -// http://www.antlr.org/wiki/pages/viewpage.action?pageId=1782 -fragment A:('a'|'A'); -fragment B:('b'|'B'); -fragment C:('c'|'C'); -fragment D:('d'|'D'); -fragment E:('e'|'E'); -fragment F:('f'|'F'); -fragment G:('g'|'G'); -fragment H:('h'|'H'); -fragment I:('i'|'I'); -fragment J:('j'|'J'); -fragment K:('k'|'K'); -fragment L:('l'|'L'); -fragment M:('m'|'M'); -fragment N:('n'|'N'); -fragment O:('o'|'O'); -fragment P:('p'|'P'); -fragment Q:('q'|'Q'); -fragment R:('r'|'R'); -fragment S:('s'|'S'); -fragment T:('t'|'T'); -fragment U:('u'|'U'); -fragment V:('v'|'V'); -fragment W:('w'|'W'); -fragment X:('x'|'X'); -fragment Y:('y'|'Y'); -fragment Z:('z'|'Z'); - -ABORT: A B O R T; -ACTION: A C T I O N; -ADD: A D D; -AFTER: A F T E R; -ALL: A L L; -ALTER: A L T E R; -ANALYZE: A N A L Y Z E; -AND: A N D; -ANSI: A N S I; -ANY: A N Y; -ARRAY: A R R A Y; -AS: A S; -ASC: A S C; -ASSUME: A S S U M E; -ASYMMETRIC: A S Y M M E T R I C; -ASYNC: A S Y N C; -AT: A T; -ATTACH: A T T A C H; -ATTRIBUTES: A T T R I B U T E S; -AUTOINCREMENT: A U T O I N C R E M E N T; -AUTOMAP: A U T O M A P; -BACKUP: B A C K U P; -BATCH: B A T C H; -COLLECTION: C O L L E C T I O N; -BEFORE: B E F O R E; -BEGIN: B E G I N; -BERNOULLI: B E R N O U L L I; -BETWEEN: B E T W E E N; -BITCAST: B I T C A S T; -BY: B Y; -CALLABLE: C A L L A B L E; -CASCADE: C A S C A D E; -CASE: C A S E; -CAST: C A S T; -CHANGEFEED: C H A N G E F E E D; -CHECK: C H E C K; -CLASSIFIER: C L A S S I F I E R; -COLLATE: C O L L A T E; -COLUMN: C O L U M N; -COLUMNS: C O L U M N S; -COMMIT: C O M M I T; -COMPACT: C O M P A C T; -CONDITIONAL: C O N D I T I O N A L; -CONFLICT: C O N F L I C T; -CONNECT: C O N N E C T; -CONSTRAINT: C O N S T R A I N T; -CONSUMER: C O N S U M E R; -COVER: C O V E R; -CREATE: C R E A T E; -CROSS: C R O S S; -CUBE: C U B E; -CURRENT: C U R R E N T; -CURRENT_DATE: C U R R E N T '_' D A T E; -CURRENT_TIME: C U R R E N T '_' T I M E; -CURRENT_TIMESTAMP: C U R R E N T '_' T I M E S T A M P; -DATA: D A T A; -DATABASE: D A T A B A S E; -DECIMAL: D E C I M A L; -DECLARE: D E C L A R E; -DEFAULT: D E F A U L T; -DEFERRABLE: D E F E R R A B L E; -DEFERRED: D E F E R R E D; -DEFINE: D E F I N E; -DELETE: D E L E T E; -DESC: D E S C; -DESCRIBE: D E S C R I B E; -DETACH: D E T A C H; -DICT: D I C T; -DIRECTORY: D I R E C T O R Y; -DISABLE: D I S A B L E; -DISCARD: D I S C A R D; -DISTINCT: D I S T I N C T; -DO: D O; -DROP: D R O P; -// TODO: fix sql formatter and drop EACH -EACH: E A C H; -ELSE: E L S E; -EMPTY: E M P T Y; -EMPTY_ACTION: E M P T Y '_' A C T I O N; -ENCRYPTED: E N C R Y P T E D; -END: E N D; -ENUM: E N U M; -ERASE: E R A S E; -ERROR: E R R O R; -ESCAPE: E S C A P E; -EVALUATE: E V A L U A T E; -EXCEPT: E X C E P T; -EXCLUDE: E X C L U D E; -EXCLUSION: E X C L U S I O N; -EXCLUSIVE: E X C L U S I V E; -EXISTS: E X I S T S; -EXPLAIN: E X P L A I N; -EXPORT: E X P O R T; -EXTERNAL: E X T E R N A L; -FAIL: F A I L; -FALSE: F A L S E; -FAMILY: F A M I L Y; -FILTER: F I L T E R; -FIRST: F I R S T; -FLATTEN: F L A T T E N; -FLOW: F L O W; -FOLLOWING: F O L L O W I N G; -FOR: F O R; -FOREIGN: F O R E I G N; -FROM: F R O M; -FULL: F U L L; -FUNCTION: F U N C T I O N; -GLOB: G L O B; -GLOBAL: G L O B A L; -GRANT: G R A N T; -GROUP: G R O U P; -GROUPING: G R O U P I N G; -GROUPS: G R O U P S; -HASH: H A S H; -HAVING: H A V I N G; -HOP: H O P; -IF: I F; -IGNORE: I G N O R E; -ILIKE: I L I K E; -IMMEDIATE: I M M E D I A T E; -IMPORT: I M P O R T; -IN: I N; -INCREMENT: I N C R E M E N T; -INCREMENTAL: I N C R E M E N T A L; -INDEX: I N D E X; -INDEXED: I N D E X E D; -INHERITS: I N H E R I T S; -INITIAL: I N I T I A L; -INITIALLY: I N I T I A L L Y; -INNER: I N N E R; -INSERT: I N S E R T; -INSTEAD: I N S T E A D; -INTERSECT: I N T E R S E C T; -INTO: I N T O; -IS: I S; -ISNULL: I S N U L L; -JOIN: J O I N; -JSON_EXISTS: J S O N '_' E X I S T S; -JSON_QUERY: J S O N '_' Q U E R Y; -JSON_VALUE: J S O N '_' V A L U E; -KEY: K E Y; -LAST: L A S T; -LEFT: L E F T; -LEGACY: L E G A C Y; -LIKE: L I K E; -LIMIT: L I M I T; -LIST: L I S T; -LOCAL: L O C A L; -LOGIN: L O G I N; -MANAGE: M A N A G E; -MATCH: M A T C H; -MATCHES: M A T C H E S; -MATCH_RECOGNIZE: M A T C H '_' R E C O G N I Z E; -MEASURES: M E A S U R E S; -MICROSECONDS: M I C R O S E C O N D S; -MILLISECONDS: M I L L I S E C O N D S; -MODIFY: M O D I F Y; -NANOSECONDS: N A N O S E C O N D S; -NATURAL: N A T U R A L; -NEXT: N E X T; -NO: N O; -NOLOGIN: N O L O G I N; -NOT: N O T; -NOTNULL: N O T N U L L; -NULL: N U L L; -NULLS: N U L L S; -OBJECT: O B J E C T; -OF: O F; -OFFSET: O F F S E T; -OMIT: O M I T; -ON: O N; -ONE: O N E; -ONLY: O N L Y; -OPTION: O P T I O N; -OPTIONAL: O P T I O N A L; -OR: O R; -ORDER: O R D E R; -OTHERS: O T H E R S; -OUTER: O U T E R; -OVER: O V E R; -OWNER: O W N E R; -PARALLEL: P A R A L L E L; -PARTITION: P A R T I T I O N; -PASSING: P A S S I N G; -PASSWORD: P A S S W O R D; -PAST: P A S T; -PATTERN: P A T T E R N; -PER: P E R; -PERMUTE: P E R M U T E; -PLAN: P L A N; -POOL: P O O L; -PRAGMA: P R A G M A; -PRECEDING: P R E C E D I N G; -PRESORT: P R E S O R T; -PRIMARY: P R I M A R Y; -PRIVILEGES: P R I V I L E G E S; -PROCESS: P R O C E S S; -QUERY: Q U E R Y; -QUEUE: Q U E U E; -RAISE: R A I S E; -RANGE: R A N G E; -//READ: R E A D; -REDUCE: R E D U C E; -REFERENCES: R E F E R E N C E S; -REGEXP: R E G E X P; -REINDEX: R E I N D E X; -RELEASE: R E L E A S E; -REMOVE: R E M O V E; -RENAME: R E N A M E; -REPEATABLE: R E P E A T A B L E; -REPLACE: R E P L A C E; -REPLICATION: R E P L I C A T I O N; -RESET: R E S E T; -RESOURCE: R E S O U R C E; -RESPECT: R E S P E C T; -RESTART: R E S T A R T; -RESTORE: R E S T O R E; -RESTRICT: R E S T R I C T; -RESULT: R E S U L T; -RETURN: R E T U R N; -RETURNING: R E T U R N I N G; -REVERT: R E V E R T; -REVOKE: R E V O K E; -RIGHT: R I G H T; -RLIKE: R L I K E; -ROLLBACK: R O L L B A C K; -ROLLUP: R O L L U P; -ROW: R O W; -ROWS: R O W S; -SAMPLE: S A M P L E; -SAVEPOINT: S A V E P O I N T; -SCHEMA: S C H E M A; -SECONDS: S E C O N D S; -SEEK: S E E K; -SELECT: S E L E C T; -SEMI: S E M I; -SET: S E T; -SETS: S E T S; -SHOW: S H O W; -SKIP: S K I P; -SECRET: S E C R E T; -SEQUENCE: S E Q U E N C E; -SOURCE: S O U R C E; -START: S T A R T; -STREAM: S T R E A M; -STREAMING: S T R E A M I N G; -STRUCT: S T R U C T; -SUBQUERY: S U B Q U E R Y; -SUBSET: S U B S E T; -SYMBOLS: S Y M B O L S; -SYMMETRIC: S Y M M E T R I C; -SYNC: S Y N C; -SYSTEM: S Y S T E M; -TABLE: T A B L E; -TABLES: T A B L E S; -TABLESAMPLE: T A B L E S A M P L E; -TABLESTORE: T A B L E S T O R E; -TAGGED: T A G G E D; -TEMP: T E M P; -TEMPORARY: T E M P O R A R Y; -THEN: T H E N; -TIES: T I E S; -TO: T O; -TOPIC: T O P I C; -TRANSACTION: T R A N S A C T I O N; -TRANSFER: T R A N S F E R; -TRIGGER: T R I G G E R; -TRUE: T R U E; -TUPLE: T U P L E; -TYPE: T Y P E; -UNBOUNDED: U N B O U N D E D; -UNCONDITIONAL: U N C O N D I T I O N A L; -UNION: U N I O N; -UNIQUE: U N I Q U E; -UNKNOWN: U N K N O W N; -UNMATCHED: U N M A T C H E D; -UPDATE: U P D A T E; -UPSERT: U P S E R T; -USE: U S E; -USER: U S E R; -USING: U S I N G; -VACUUM: V A C U U M; -VALUES: V A L U E S; -VARIANT: V A R I A N T; -VIEW: V I E W; -VIRTUAL: V I R T U A L; -WATERMARK: W A T E R M A R K; -WHEN: W H E N; -WHERE: W H E R E; -WINDOW: W I N D O W; -WITH: W I T H; -WITHOUT: W I T H O U T; -WRAPPER: W R A P P E R; -//WRITE: W R I T E; -XOR: X O R; - -// YQL Default Lexer: -// GRAMMAR_STRING_CORE_SINGLE = ~(QUOTE_SINGLE | BACKSLASH) | (BACKSLASH .) -// GRAMMAR_STRING_CORE_DOUBLE = ~(QUOTE_DOUBLE | BACKSLASH) | (BACKSLASH .) - -// ANSI Lexer: -// GRAMMAR_STRING_CORE_SINGLE = ~QUOTE_SINGLE | (QUOTE_SINGLE QUOTE_SINGLE) -// GRAMMAR_STRING_CORE_DOUBLE = ~QUOTE_DOUBLE | (QUOTE_DOUBLE QUOTE_DOUBLE) - -fragment STRING_CORE_SINGLE: @GRAMMAR_STRING_CORE_SINGLE@; -fragment STRING_CORE_DOUBLE: @GRAMMAR_STRING_CORE_DOUBLE@; - -fragment STRING_SINGLE: (QUOTE_SINGLE STRING_CORE_SINGLE* QUOTE_SINGLE); -fragment STRING_DOUBLE: (QUOTE_DOUBLE STRING_CORE_DOUBLE* QUOTE_DOUBLE); -fragment STRING_MULTILINE: (DOUBLE_COMMAT .* DOUBLE_COMMAT)+ COMMAT?; - -STRING_VALUE: ((STRING_SINGLE | STRING_DOUBLE | STRING_MULTILINE) (S | U | Y | J | P (T | B | V)?)?); - -ID_PLAIN: ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | DIGIT)*; - -fragment ID_QUOTED_CORE: '``' | '\\`' | ~'`'; -ID_QUOTED: BACKTICK ID_QUOTED_CORE* BACKTICK; - -fragment DIGIT: '0'..'9'; -fragment HEXDIGIT: '0'..'9' | 'a'..'f' | 'A'..'F'; -fragment HEXDIGITS: '0' X HEXDIGIT+; -fragment OCTDIGITS: '0' O ('0'..'8')+; -fragment BINDIGITS: '0' B ('0' | '1')+; -fragment DECDIGITS: DIGIT+; -DIGITS: DECDIGITS | HEXDIGITS | OCTDIGITS | BINDIGITS; - -// not all combinations of P/U with L/S/T/I/B/N are actually valid - this is resolved in sql.cpp -INTEGER_VALUE: DIGITS ((P | U)? (L | S | T | I | B | N)?); - -fragment FLOAT_EXP : E (PLUS | MINUS)? DECDIGITS ; -REAL: - ( - DECDIGITS DOT DIGIT* FLOAT_EXP? - | DECDIGITS FLOAT_EXP -// | DOT DECDIGITS FLOAT_EXP? // Conflicts with tuple element access through DOT - ) (F | P (F ('4'|'8') | N)?)? - ; - -BLOB: X QUOTE_SINGLE HEXDIGIT+ QUOTE_SINGLE; - -// YQL Default Lexer: -// GRAMMAR_MULTILINE_COMMENT_CORE = . -// ANSI Lexer: -// GRAMMAR_MULTILINE_COMMENT_CORE = MULTILINE_COMMENT | . - -fragment MULTILINE_COMMENT: '/*' ( options {greedy=false;} : @GRAMMAR_MULTILINE_COMMENT_CORE@ )* '*/'; -fragment LINE_COMMENT: '--' ~('\n'|'\r')* ('\r' '\n'? | '\n' | EOF); -WS: (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}; -COMMENT: (MULTILINE_COMMENT|LINE_COMMENT) {$channel=HIDDEN;}; diff --git a/yql/essentials/sql/v1/SQLv1Antlr4.g.in b/yql/essentials/sql/v1/SQLv1Antlr4.g.in index 919da25318d..84f081054e6 100644 --- a/yql/essentials/sql/v1/SQLv1Antlr4.g.in +++ b/yql/essentials/sql/v1/SQLv1Antlr4.g.in @@ -326,6 +326,8 @@ type_name_enum: ENUM LESS type_name_tag (COMMA type_name_tag)* COMMA? GREATER; type_name_resource: RESOURCE LESS type_name_tag GREATER; type_name_tagged: TAGGED LESS type_name_or_bind COMMA type_name_tag GREATER; type_name_callable: CALLABLE LESS LPAREN callable_arg_list? COMMA? (LBRACE_SQUARE callable_arg_list RBRACE_SQUARE)? RPAREN ARROW type_name_or_bind GREATER; +type_name_linear: LINEAR LESS type_name_or_bind GREATER; +type_name_dynamiclinear: DYNAMICLINEAR LESS type_name_or_bind GREATER; type_name_composite: ( type_name_optional @@ -341,6 +343,8 @@ type_name_composite: | type_name_resource | type_name_tagged | type_name_callable + | type_name_linear + | type_name_dynamiclinear ) QUESTION*; type_name: @@ -655,7 +659,7 @@ drop_streaming_query_stmt: DROP STREAMING QUERY (IF EXISTS)? object_ref; create_view_stmt: CREATE VIEW (IF NOT EXISTS)? object_ref create_object_features? - AS select_stmt + AS (select_stmt | DO BEGIN define_action_or_subquery_body END DO) ; drop_view_stmt: DROP VIEW (IF EXISTS)? object_ref; @@ -1439,6 +1443,7 @@ keyword_as_compat: | DESCRIBE | DETACH | DIRECTORY + | DYNAMICLINEAR | DISABLE | DISCARD // | DO @@ -1497,6 +1502,7 @@ keyword_as_compat: // | LEFT | LEGACY | LIKE + | LINEAR | LOCAL | LOGIN | MANAGE @@ -1671,6 +1677,7 @@ keyword_compat: ( | DESCRIBE | DETACH | DIRECTORY + | DYNAMICLINEAR | DISABLE | DISCARD | DO @@ -1729,6 +1736,7 @@ keyword_compat: ( | LEFT | LEGACY | LIKE + | LINEAR | LOCAL | LOGIN | MANAGE @@ -2018,6 +2026,7 @@ DESCRIBE: D E S C R I B E; DETACH: D E T A C H; DICT: D I C T; DIRECTORY: D I R E C T O R Y; +DYNAMICLINEAR: D Y N A M I C L I N E A R; DISABLE: D I S A B L E; DISCARD: D I S C A R D; DISTINCT: D I S T I N C T; @@ -2095,6 +2104,7 @@ LEFT: L E F T; LEGACY: L E G A C Y; LIKE: L I K E; LIMIT: L I M I T; +LINEAR: L I N E A R; LIST: L I S T; LOCAL: L O C A L; LOGIN: L O G I N; diff --git a/yql/essentials/sql/v1/antlr_token.h b/yql/essentials/sql/v1/antlr_token.h index 8f349bf49ca..cd7ddfd7e6e 100644 --- a/yql/essentials/sql/v1/antlr_token.h +++ b/yql/essentials/sql/v1/antlr_token.h @@ -1,11 +1,9 @@ #pragma once -#include <yql/essentials/parser/proto_ast/gen/v1/SQLv1Lexer.h> #include <yql/essentials/parser/proto_ast/gen/v1_antlr4/SQLv1Antlr4Lexer.h> -#define ANTLR3_TOKEN(NAME) (SQLv1LexerTokens::TOKEN_##NAME << 16) #define ANTLR4_TOKEN(NAME) ((SQLv1Antlr4Lexer::TOKEN_##NAME << 16) + 1) -#define IS_TOKEN(USE_ANTLR4, ID, NAME) (UnifiedToken(USE_ANTLR4, ID) == ANTLR3_TOKEN(NAME) || UnifiedToken(USE_ANTLR4, ID) == ANTLR4_TOKEN(NAME)) +#define IS_TOKEN(USE_ANTLR4, ID, NAME) (UnifiedToken(USE_ANTLR4, ID) == ANTLR4_TOKEN(NAME)) namespace NSQLTranslationV1 { diff --git a/yql/essentials/sql/v1/builtin.cpp b/yql/essentials/sql/v1/builtin.cpp index e5ed591beec..4e9e61ae379 100644 --- a/yql/essentials/sql/v1/builtin.cpp +++ b/yql/essentials/sql/v1/builtin.cpp @@ -2853,8 +2853,13 @@ struct TBuiltinFuncInfo { TBuiltinFactoryCallback Callback; }; +struct TSimplePgFuncInfo { + std::string_view NativeFuncName; +}; + using TBuiltinFactoryCallbackMap = std::unordered_map<TString, TBuiltinFuncInfo, THash<TString>>; using TCoreFuncMap = std::unordered_map<TString, TCoreFuncInfo, THash<TString>>; +using TSimplePgFuncMap = std::unordered_map<TString, TSimplePgFuncInfo, THash<TString>>; TAggrFuncFactoryCallback BuildAggrFuncFactoryCallback( const TString& functionName, @@ -3008,6 +3013,7 @@ struct TBuiltinFuncData { const TBuiltinFactoryCallbackMap BuiltinFuncs; const TAggrFuncFactoryCallbackMap AggrFuncs; const TCoreFuncMap CoreFuncs; + const TSimplePgFuncMap SimplePgFuncs; TBuiltinFuncData() : BuiltinFuncs(MakeBuiltinFuncs()) @@ -3015,6 +3021,8 @@ struct TBuiltinFuncData { AggrFuncs(MakeAggrFuncs()) , CoreFuncs(MakeCoreFuncs()) + , + SimplePgFuncs(MakeSimplePgFuncMap()) { } @@ -3035,6 +3043,7 @@ struct TBuiltinFuncData { {"byteat", {"ByteAt", "Normal", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("ByteAt", 2, 2)}}, {"startswith", {"StartsWith", "Normal", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("StartsWith", 2, 2)}}, {"endswith", {"EndsWith", "Normal", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("EndsWith", 2, 2)}}, + {"concat", {"Concat", "Normal", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("SqlConcat", 1, -1)}}, // Numeric builtins {"abs", {"Abs", "Normal", BuildNamedArgcBuiltinFactoryCallback<TCallNodeImpl>("Abs", 1, 1)}}, @@ -3519,6 +3528,15 @@ struct TBuiltinFuncData { }; return coreFuncs; } + + TSimplePgFuncMap MakeSimplePgFuncMap() { + TSimplePgFuncMap simplePgFuncs = { + {"now", {"CurrentUtcTimestamp"}}, + {"to_date", {"DateTime::Format"}}, + {"round", {"Math::Round"}}, + }; + return simplePgFuncs; + } }; TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVector<TNodePtr>& args, @@ -3527,6 +3545,7 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec const TBuiltinFactoryCallbackMap& builtinFuncs = funcData->BuiltinFuncs; const TAggrFuncFactoryCallbackMap& aggrFuncs = funcData->AggrFuncs; const TCoreFuncMap& coreFuncs = funcData->CoreFuncs; + const TSimplePgFuncMap& simplePgFuncs = funcData->SimplePgFuncs; for (auto& arg : args) { if (!arg) { @@ -3584,6 +3603,13 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec nameSpace = "DateTime2"; } + // SimplePg shadows builtins + if (ctx.Scoped->SimplePgByDefault) { + if (simplePgFuncs.contains(lowerName)) { + ns = "simplepg"; + } + } + auto scriptType = NKikimr::NMiniKQL::ScriptTypeFromStr(ns); switch (scriptType) { case NKikimr::NMiniKQL::EScriptType::Python: @@ -3994,7 +4020,23 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec } else if (normalizedName == "sqlexternalfunction") { return new TCallNodeImpl(pos, "SqlExternalFunction", args); } else { - return new TInvalidBuiltin(pos, TStringBuilder() << "Unknown builtin: " << name); + TStringBuilder b; + b << "Unknown builtin: " << name; + auto simplePgFunc = simplePgFuncs.find(lowerName); + if (simplePgFunc != simplePgFuncs.end()) { + b << ", consider using " << simplePgFunc->second.NativeFuncName << " function instead."; + b << " It's possible to use SimplePg::" << lowerName << " function as well but with some performance overhead."; + } else { + bool isAggregateFunc = NYql::NPg::HasAggregation(name, NYql::NPg::EAggKind::Normal); + bool isNormalFunc = NYql::NPg::HasProc(name, NYql::NPg::EProcKind::Function); + if (isAggregateFunc) { + b << ", consider using PgAgg::" << name; + } else if (isNormalFunc) { + b << ", consider using Pg::" << name; + } + } + + return new TInvalidBuiltin(pos, b); } } @@ -4086,6 +4128,21 @@ TNodePtr BuildBuiltinFunc(TContext& ctx, TPosition pos, TString name, const TVec }; } + if (ns == "simplepg") { + auto simplePgFunc = simplePgFuncs.find(lowerName); + if (simplePgFunc == simplePgFuncs.end()) { + return new TInvalidBuiltin(pos, TStringBuilder() << "Unknown function: SimplePg::" << name); + } + + nameSpace = "SimplePg"; + name = lowerName; + if (!ctx.Warning(pos, TIssuesIds::CORE_SIMPLE_PG, [&](auto& out) { + out << "Consider using function " << simplePgFunc->second.NativeFuncName << " instead to avoid performance overhead"; + })) { + return nullptr; + } + } + TNodePtr typeConfig = MakeTypeConfig(pos, ns, usedArgs); return BuildSqlCall(ctx, pos, nameSpace, name, usedArgs, positionalArgs, namedArgs, externalTypes, TDeferredAtom(typeConfig, ctx), nullptr, nullptr, {}); @@ -4096,8 +4153,9 @@ void EnumerateBuiltins(const std::function<void(std::string_view name, std::stri const TBuiltinFactoryCallbackMap& builtinFuncs = funcData->BuiltinFuncs; const TAggrFuncFactoryCallbackMap& aggrFuncs = funcData->AggrFuncs; const TCoreFuncMap& coreFuncs = funcData->CoreFuncs; + const TSimplePgFuncMap& simplePgFuncs = funcData->SimplePgFuncs; - std::map<std::string_view, std::string_view> map; + std::map<TString, TString> map; for (const auto& x : builtinFuncs) { if (!x.second.CanonicalSqlName.empty()) { map.emplace(x.second.CanonicalSqlName, x.second.Kind); @@ -4114,6 +4172,10 @@ void EnumerateBuiltins(const std::function<void(std::string_view name, std::stri map.emplace(x.second.Name, "Normal"); } + for (const auto& x : simplePgFuncs) { + map.emplace(TString("SimplePg::") + x.first, "Normal"); + } + for (const auto& x : map) { callback(x.first, x.second); } diff --git a/yql/essentials/sql/v1/complete/name/service/static/name_service.cpp b/yql/essentials/sql/v1/complete/name/service/static/name_service.cpp index f53dc5d99cb..1fe54b249fb 100644 --- a/yql/essentials/sql/v1/complete/name/service/static/name_service.cpp +++ b/yql/essentials/sql/v1/complete/name/service/static/name_service.cpp @@ -139,6 +139,8 @@ public: "Resource", "Tagged", "Callable", + "Linear", + "DynamicLinear", }, NormalizeName)) , ParameterizedTypes_(BuildNameIndex( { diff --git a/yql/essentials/sql/v1/complete/sql_complete_ut.cpp b/yql/essentials/sql/v1/complete/sql_complete_ut.cpp index cbd95b8be39..3b2897fd30b 100644 --- a/yql/essentials/sql/v1/complete/sql_complete_ut.cpp +++ b/yql/essentials/sql/v1/complete/sql_complete_ut.cpp @@ -556,6 +556,7 @@ Y_UNIT_TEST(Select) { {FunctionName, "DateTime::Split()", 1}, {TypeName, "Decimal()", 1}, {TypeName, "Dict<>", 1}, + {TypeName, "DynamicLinear<>", 1}, {Keyword, "EMPTY_ACTION"}, {Keyword, "EXISTS()", 1}, {TypeName, "Enum<>", 1}, @@ -564,6 +565,7 @@ Y_UNIT_TEST(Select) { {Keyword, "JSON_EXISTS()", 1}, {Keyword, "JSON_QUERY()", 1}, {Keyword, "JSON_VALUE()", 1}, + {TypeName, "Linear<>", 1}, {TypeName, "List<>", 1}, {Keyword, "NOT"}, {Keyword, "NULL"}, @@ -820,6 +822,7 @@ Y_UNIT_TEST(SelectWhere) { {FunctionName, "DateTime::Split()", 1}, {TypeName, "Decimal()", 1}, {TypeName, "Dict<>", 1}, + {TypeName, "DynamicLinear<>", 1}, {Keyword, "EMPTY_ACTION"}, {Keyword, "EXISTS()", 1}, {TypeName, "Enum<>", 1}, @@ -828,6 +831,7 @@ Y_UNIT_TEST(SelectWhere) { {Keyword, "JSON_EXISTS()", 1}, {Keyword, "JSON_QUERY()", 1}, {Keyword, "JSON_VALUE()", 1}, + {TypeName, "Linear<>", 1}, {TypeName, "List<>", 1}, {Keyword, "NOT"}, {Keyword, "NULL"}, @@ -915,8 +919,10 @@ Y_UNIT_TEST(TypeName) { {TypeName, "Callable<>", 1}, {TypeName, "Decimal()", 1}, {TypeName, "Dict<>", 1}, + {TypeName, "DynamicLinear<>", 1}, {TypeName, "Enum<>", 1}, {TypeName, "Flow<>", 1}, + {TypeName, "Linear<>", 1}, {TypeName, "List<>", 1}, {TypeName, "Optional<>", 1}, {TypeName, "Resource<>", 1}, diff --git a/yql/essentials/sql/v1/context.h b/yql/essentials/sql/v1/context.h index b7db8ab358e..e5bbdb821fc 100644 --- a/yql/essentials/sql/v1/context.h +++ b/yql/essentials/sql/v1/context.h @@ -9,7 +9,7 @@ #include <yql/essentials/sql/settings/translation_settings.h> #include <yql/essentials/sql/cluster_mapping.h> -#include <yql/essentials/parser/proto_ast/gen/v1_proto_split/SQLv1Parser.pb.main.h> +#include <yql/essentials/parser/proto_ast/gen/v1_proto_split_antlr4/SQLv1Antlr4Parser.pb.main.h> #include <util/generic/hash.h> #include <util/generic/map.h> @@ -53,6 +53,7 @@ struct TScopedState: public TThrRefBase { bool StrictJoinKeyTypes = false; bool UnicodeLiterals = false; bool WarnUntypedStringLiterals = false; + bool SimplePgByDefault = false; TNamedNodesMap NamedNodes; struct TLocal { diff --git a/yql/essentials/sql/v1/format/sql_format.cpp b/yql/essentials/sql/v1/format/sql_format.cpp index aed116585a6..1877f23ac38 100644 --- a/yql/essentials/sql/v1/format/sql_format.cpp +++ b/yql/essentials/sql/v1/format/sql_format.cpp @@ -5,7 +5,7 @@ #include <yql/essentials/parser/lexer_common/lexer.h> #include <yql/essentials/core/sql_types/simple_types.h> -#include <yql/essentials/parser/proto_ast/gen/v1_proto_split/SQLv1Parser.pb.main.h> +#include <yql/essentials/parser/proto_ast/gen/v1_proto_split_antlr4/SQLv1Antlr4Parser.pb.main.h> #include <library/cpp/protobuf/util/simple_reflection.h> #include <library/cpp/resource/resource.h> @@ -805,7 +805,7 @@ private: break; } case TRule_value_constructor::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -2773,7 +2773,7 @@ private: VisitKeyword(msg.GetAlt_ttl_tier_action2().GetToken1()); break; case TRule_ttl_tier_action::ALT_NOT_SET: - break; + Y_UNREACHABLE(); } } @@ -3383,8 +3383,7 @@ bool SqlFormatSimple(const NSQLTranslationV1::TLexers& lexers, THashSet<TString> GetKeywords() { TString grammar; - // ANTLR4-MIGRATION: just change SQLv1 to SQLv1Antlr4 - Y_ENSURE(NResource::FindExact("SQLv1.g.in", &grammar)); + Y_ENSURE(NResource::FindExact("SQLv1Antlr4.g.in", &grammar)); THashSet<TString> res; TVector<TString> lines; Split(grammar, "\n", lines); diff --git a/yql/essentials/sql/v1/format/ut/ya.make b/yql/essentials/sql/v1/format/ut/ya.make deleted file mode 100644 index 690b13b6180..00000000000 --- a/yql/essentials/sql/v1/format/ut/ya.make +++ /dev/null @@ -1,14 +0,0 @@ -UNITTEST_FOR(yql/essentials/sql/v1/format) - -SRCS( - sql_format_ut.cpp -) - -PEERDIR( - yql/essentials/sql/v1/lexer/antlr3 - yql/essentials/sql/v1/lexer/antlr3_ansi - yql/essentials/sql/v1/proto_parser/antlr3 - yql/essentials/sql/v1/proto_parser/antlr3_ansi -) - -END() diff --git a/yql/essentials/sql/v1/format/ya.make b/yql/essentials/sql/v1/format/ya.make index d83e33a618f..c47e76e34b2 100644 --- a/yql/essentials/sql/v1/format/ya.make +++ b/yql/essentials/sql/v1/format/ya.make @@ -4,7 +4,6 @@ SRCS( sql_format.cpp ) -RESOURCE(DONT_PARSE yql/essentials/sql/v1/SQLv1.g.in SQLv1.g.in) RESOURCE(DONT_PARSE yql/essentials/sql/v1/SQLv1Antlr4.g.in SQLv1Antlr4.g.in) PEERDIR( @@ -12,7 +11,7 @@ PEERDIR( yql/essentials/sql/settings yql/essentials/sql/v1/lexer yql/essentials/sql/v1/proto_parser - yql/essentials/parser/proto_ast/gen/v1_proto_split + yql/essentials/parser/proto_ast/gen/v1_proto_split_antlr4 yql/essentials/core/sql_types library/cpp/protobuf/util library/cpp/resource @@ -25,6 +24,5 @@ RECURSE( ) RECURSE_FOR_TESTS( - ut ut_antlr4 ) diff --git a/yql/essentials/sql/v1/highlight/data_language_json.cpp b/yql/essentials/sql/v1/highlight/data_language_json.cpp new file mode 100644 index 00000000000..224a2630a02 --- /dev/null +++ b/yql/essentials/sql/v1/highlight/data_language_json.cpp @@ -0,0 +1,34 @@ +#include "data_language_json.h" + +#include <library/cpp/json/json_reader.h> +#include <library/cpp/resource/resource.h> + +namespace NSQLHighlight { + +TVector<TString> LoadTypes() { + TString resource = NResource::Find("types.json"); + NJson::TJsonValue json = NJson::ReadJsonFastTree(resource); + + TVector<TString> types; + for (const NJson::TJsonValue& value : json.GetArraySafe()) { + types.emplace_back(value["name"].GetStringSafe()); + } + return types; +} + +TVector<TString> LoadHints() { + TString resource = NResource::Find("statements_opensource.json"); + NJson::TJsonValue json = NJson::ReadJsonFastTree(resource); + + TVector<TString> hints; + for (const auto& [statement, services] : json.GetMapSafe()) { + for (const auto& [service, kinds] : services.GetMapSafe()) { + for (const auto& hint : kinds["hints"].GetArraySafe()) { + hints.emplace_back(hint["name"].GetStringSafe()); + } + } + } + return hints; +} + +} // namespace NSQLHighlight diff --git a/yql/essentials/sql/v1/highlight/data_language_json.h b/yql/essentials/sql/v1/highlight/data_language_json.h new file mode 100644 index 00000000000..1e2a7fdb9aa --- /dev/null +++ b/yql/essentials/sql/v1/highlight/data_language_json.h @@ -0,0 +1,12 @@ +#pragma once + +#include <util/generic/vector.h> +#include <util/generic/string.h> + +namespace NSQLHighlight { + +TVector<TString> LoadTypes(); + +TVector<TString> LoadHints(); + +} // namespace NSQLHighlight diff --git a/yql/essentials/sql/v1/highlight/sql_highlight.cpp b/yql/essentials/sql/v1/highlight/sql_highlight.cpp index 3f17934cef4..9ad8c6b383b 100644 --- a/yql/essentials/sql/v1/highlight/sql_highlight.cpp +++ b/yql/essentials/sql/v1/highlight/sql_highlight.cpp @@ -1,10 +1,11 @@ #include "sql_highlight.h" +#include "data_language_json.h" + #include <yql/essentials/sql/v1/lexer/regex/regex.h> #include <contrib/libs/re2/re2/re2.h> -#include <library/cpp/json/json_reader.h> #include <library/cpp/resource/resource.h> #include <util/generic/algorithm.h> @@ -104,6 +105,11 @@ TUnit MakeUnit<EUnitKind::BindParameterIdentifier>(Syntax& s) { template <> TUnit MakeUnit<EUnitKind::OptionIdentifier>(Syntax& s) { + TVector<NSQLTranslationV1::TRegexPattern> hints; + for (const TString& type : LoadHints()) { + hints.emplace_back(CaseInsensitive(type)); + } + return { .Kind = EUnitKind::OptionIdentifier, .Patterns = { @@ -113,25 +119,16 @@ TUnit MakeUnit<EUnitKind::OptionIdentifier>(Syntax& s) { .Before = TStringBuilder() << "PRAGMA" << s.Get("WS"), .IsCaseInsensitive = true, }, - { - .Body = s.Get("ID_PLAIN"), - .Before = TStringBuilder() << "WITH" << s.Get("WS"), - .IsCaseInsensitive = true, - }, - { - .Body = s.Get("ID_PLAIN"), - .After = " ?" + s.Get("EQUALS"), - .IsCaseInsensitive = true, - }}, + {Merged(std::move(hints))}, + }, }; } template <> TUnit MakeUnit<EUnitKind::TypeIdentifier>(Syntax& s) { TVector<NSQLTranslationV1::TRegexPattern> types; - NJson::TJsonValue json = NJson::ReadJsonFastTree(NResource::Find("types.json")); - for (const NJson::TJsonValue& value : json.GetArraySafe()) { - types.emplace_back(CaseInsensitive(value["name"].GetStringSafe())); + for (const TString& type : LoadTypes()) { + types.emplace_back(CaseInsensitive(type)); } return { diff --git a/yql/essentials/sql/v1/highlight/ya.make b/yql/essentials/sql/v1/highlight/ya.make index 103f1908aa0..d6ede67108f 100644 --- a/yql/essentials/sql/v1/highlight/ya.make +++ b/yql/essentials/sql/v1/highlight/ya.make @@ -1,6 +1,7 @@ LIBRARY() SRCS( + data_language_json.cpp sql_highlight_json.cpp sql_highlight.cpp sql_highlighter.cpp @@ -16,6 +17,7 @@ PEERDIR( RESOURCE( yql/essentials/sql/v1/highlight/ut/suite.json suite.json yql/essentials/data/language/types.json types.json + yql/essentials/data/language/statements_opensource.json statements_opensource.json ) END() diff --git a/yql/essentials/sql/v1/lexer/antlr3/lexer.cpp b/yql/essentials/sql/v1/lexer/antlr3/lexer.cpp deleted file mode 100644 index a0d9b577022..00000000000 --- a/yql/essentials/sql/v1/lexer/antlr3/lexer.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "lexer.h" -#include <yql/essentials/parser/proto_ast/gen/v1/SQLv1Lexer.h> -#include <yql/essentials/public/issue/yql_issue.h> -#include <yql/essentials/parser/proto_ast/collect_issues/collect_issues.h> -#include <yql/essentials/parser/proto_ast/antlr3/proto_ast_antlr3.h> - -namespace NALPDefault { -extern ANTLR_UINT8* SQLv1ParserTokenNames[]; -} // namespace NALPDefault - -namespace NSQLTranslationV1 { - -namespace { - -class TLexer: public NSQLTranslation::ILexer { -public: - bool Tokenize(const TString& query, const TString& queryName, const TTokenCallback& onNextToken, NYql::TIssues& issues, size_t maxErrors) final { - NYql::TIssues newIssues; - NSQLTranslation::TErrorCollectorOverIssues collector(newIssues, maxErrors, queryName); - NProtoAST::TLexerTokensCollector3<NALPDefault::SQLv1Lexer> tokensCollector(query, (const char**)NALPDefault::SQLv1ParserTokenNames, queryName); - tokensCollector.CollectTokens(collector, onNextToken); - issues.AddIssues(newIssues); - return !AnyOf(newIssues.begin(), newIssues.end(), [](auto issue) { return issue.GetSeverity() == NYql::ESeverity::TSeverityIds_ESeverityId_S_ERROR; }); - } -}; - -class TFactory: public NSQLTranslation::ILexerFactory { -public: - THolder<NSQLTranslation::ILexer> MakeLexer() const final { - return MakeHolder<TLexer>(); - } -}; - -} // namespace - -NSQLTranslation::TLexerFactoryPtr MakeAntlr3LexerFactory() { - return MakeIntrusive<TFactory>(); -} - -} // namespace NSQLTranslationV1 diff --git a/yql/essentials/sql/v1/lexer/antlr3/lexer.h b/yql/essentials/sql/v1/lexer/antlr3/lexer.h deleted file mode 100644 index 7d3bd550688..00000000000 --- a/yql/essentials/sql/v1/lexer/antlr3/lexer.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include <yql/essentials/parser/lexer_common/lexer.h> - -namespace NSQLTranslationV1 { - -NSQLTranslation::TLexerFactoryPtr MakeAntlr3LexerFactory(); - -} // namespace NSQLTranslationV1 diff --git a/yql/essentials/sql/v1/lexer/antlr3/ya.make b/yql/essentials/sql/v1/lexer/antlr3/ya.make deleted file mode 100644 index 8fd1537311c..00000000000 --- a/yql/essentials/sql/v1/lexer/antlr3/ya.make +++ /dev/null @@ -1,14 +0,0 @@ -LIBRARY() - -PEERDIR( - yql/essentials/parser/lexer_common - yql/essentials/public/issue - yql/essentials/parser/proto_ast/collect_issues - yql/essentials/parser/proto_ast/gen/v1 -) - -SRCS( - lexer.cpp -) - -END() diff --git a/yql/essentials/sql/v1/lexer/antlr3_ansi/lexer.cpp b/yql/essentials/sql/v1/lexer/antlr3_ansi/lexer.cpp deleted file mode 100644 index c7ee91a6260..00000000000 --- a/yql/essentials/sql/v1/lexer/antlr3_ansi/lexer.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "lexer.h" -#include <yql/essentials/parser/proto_ast/gen/v1_ansi/SQLv1Lexer.h> -#include <yql/essentials/public/issue/yql_issue.h> -#include <yql/essentials/parser/proto_ast/collect_issues/collect_issues.h> -#include <yql/essentials/parser/proto_ast/antlr3/proto_ast_antlr3.h> - -namespace NALPAnsi { -extern ANTLR_UINT8* SQLv1ParserTokenNames[]; -} // namespace NALPAnsi - -namespace NSQLTranslationV1 { - -namespace { - -class TLexer: public NSQLTranslation::ILexer { -public: - bool Tokenize(const TString& query, const TString& queryName, const TTokenCallback& onNextToken, NYql::TIssues& issues, size_t maxErrors) final { - NYql::TIssues newIssues; - NSQLTranslation::TErrorCollectorOverIssues collector(newIssues, maxErrors, queryName); - NProtoAST::TLexerTokensCollector3<NALPAnsi::SQLv1Lexer> tokensCollector(query, (const char**)NALPAnsi::SQLv1ParserTokenNames, queryName); - tokensCollector.CollectTokens(collector, onNextToken); - issues.AddIssues(newIssues); - return !AnyOf(newIssues.begin(), newIssues.end(), [](auto issue) { return issue.GetSeverity() == NYql::ESeverity::TSeverityIds_ESeverityId_S_ERROR; }); - } -}; - -class TFactory: public NSQLTranslation::ILexerFactory { -public: - THolder<NSQLTranslation::ILexer> MakeLexer() const final { - return MakeHolder<TLexer>(); - } -}; - -} // namespace - -NSQLTranslation::TLexerFactoryPtr MakeAntlr3AnsiLexerFactory() { - return MakeIntrusive<TFactory>(); -} - -} // namespace NSQLTranslationV1 diff --git a/yql/essentials/sql/v1/lexer/antlr3_ansi/lexer.h b/yql/essentials/sql/v1/lexer/antlr3_ansi/lexer.h deleted file mode 100644 index 7871fbff4cb..00000000000 --- a/yql/essentials/sql/v1/lexer/antlr3_ansi/lexer.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include <yql/essentials/parser/lexer_common/lexer.h> - -namespace NSQLTranslationV1 { - -NSQLTranslation::TLexerFactoryPtr MakeAntlr3AnsiLexerFactory(); - -} // namespace NSQLTranslationV1 diff --git a/yql/essentials/sql/v1/lexer/antlr3_ansi/ya.make b/yql/essentials/sql/v1/lexer/antlr3_ansi/ya.make deleted file mode 100644 index ed34a4fc28c..00000000000 --- a/yql/essentials/sql/v1/lexer/antlr3_ansi/ya.make +++ /dev/null @@ -1,14 +0,0 @@ -LIBRARY() - -PEERDIR( - yql/essentials/parser/lexer_common - yql/essentials/public/issue - yql/essentials/parser/proto_ast/collect_issues - yql/essentials/parser/proto_ast/gen/v1_ansi -) - -SRCS( - lexer.cpp -) - -END() diff --git a/yql/essentials/sql/v1/lexer/lexer.cpp b/yql/essentials/sql/v1/lexer/lexer.cpp index da546069b84..1324d3a4b2d 100644 --- a/yql/essentials/sql/v1/lexer/lexer.cpp +++ b/yql/essentials/sql/v1/lexer/lexer.cpp @@ -2,8 +2,6 @@ #include <yql/essentials/public/issue/yql_issue.h> #include <yql/essentials/parser/lexer_common/lexer.h> -#include <yql/essentials/sql/v1/lexer/antlr3/lexer.h> -#include <yql/essentials/sql/v1/lexer/antlr3_ansi/lexer.h> #include <yql/essentials/sql/v1/lexer/antlr4/lexer.h> #include <yql/essentials/sql/v1/lexer/antlr4_ansi/lexer.h> #include <yql/essentials/sql/settings/translation_settings.h> @@ -51,11 +49,7 @@ private: } static NSQLTranslation::TLexerFactoryPtr GetMaybeFactory(const TLexers& lexers, bool ansi, bool antlr4, ELexerFlavor flavor) { - if (!ansi && !antlr4 && flavor == ELexerFlavor::Default) { - return lexers.Antlr3; - } else if (ansi && !antlr4 && flavor == ELexerFlavor::Default) { - return lexers.Antlr3Ansi; - } else if (!ansi && antlr4 && flavor == ELexerFlavor::Default) { + if (!ansi && antlr4 && flavor == ELexerFlavor::Default) { return lexers.Antlr4; } else if (ansi && antlr4 && flavor == ELexerFlavor::Default) { return lexers.Antlr4Ansi; diff --git a/yql/essentials/sql/v1/lexer/lexer.h b/yql/essentials/sql/v1/lexer/lexer.h index 48d21a654f0..4dcad487f6d 100644 --- a/yql/essentials/sql/v1/lexer/lexer.h +++ b/yql/essentials/sql/v1/lexer/lexer.h @@ -5,8 +5,6 @@ namespace NSQLTranslationV1 { struct TLexers { - NSQLTranslation::TLexerFactoryPtr Antlr3; - NSQLTranslation::TLexerFactoryPtr Antlr3Ansi; NSQLTranslation::TLexerFactoryPtr Antlr4; NSQLTranslation::TLexerFactoryPtr Antlr4Ansi; NSQLTranslation::TLexerFactoryPtr Antlr4Pure; diff --git a/yql/essentials/sql/v1/lexer/lexer_ut.cpp b/yql/essentials/sql/v1/lexer/lexer_ut.cpp index 483787c159b..a79f3d077bd 100644 --- a/yql/essentials/sql/v1/lexer/lexer_ut.cpp +++ b/yql/essentials/sql/v1/lexer/lexer_ut.cpp @@ -4,8 +4,6 @@ #include <yql/essentials/core/issue/yql_issue.h> #include <yql/essentials/sql/settings/translation_settings.h> -#include <yql/essentials/sql/v1/lexer/antlr3/lexer.h> -#include <yql/essentials/sql/v1/lexer/antlr3_ansi/lexer.h> #include <yql/essentials/sql/v1/lexer/antlr4/lexer.h> #include <yql/essentials/sql/v1/lexer/antlr4_ansi/lexer.h> #include <yql/essentials/sql/v1/lexer/antlr4_pure/lexer.h> @@ -27,8 +25,6 @@ using namespace NSQLTranslation; using namespace NSQLTranslationV1; TLexers Lexers = { - .Antlr3 = MakeAntlr3LexerFactory(), - .Antlr3Ansi = MakeAntlr3AnsiLexerFactory(), .Antlr4 = MakeAntlr4LexerFactory(), .Antlr4Ansi = MakeAntlr4AnsiLexerFactory(), .Antlr4Pure = MakeAntlr4PureLexerFactory(), @@ -217,21 +213,6 @@ TVector<TString> InvalidQueries() { }; } -Y_UNIT_TEST(ErrorRecoveryAntlr3) { - TVector<TVector<TString>> actual = { - /* 0: */ {"EOF"}, - /* 1: */ {"SELECT", "WS", "EOF"}, - /* 2: */ {"EOF"}, - /* 3: */ {"WS", "SELECT", "WS", "ASTERISK", "WS", "ID_PLAIN (FR)", "EOF"}, - /* 4: */ {"ID_PLAIN (ELECT)", "WS", "ASTERISK", "WS", "WS", "FROM", "EOF"}, - /* 5: */ {"SELECT", "WS", "ID_PLAIN (rom)", "EOF"}, - /* 6: */ {"EOF"}, - /* 7: */ {"ID_PLAIN (lect)", "EOF"}, - /* 8: */ {"SELECT", "WS", "EOF"}, - }; - TestInvalidTokensSkipped(/* antlr4 = */ false, actual); -} - Y_UNIT_TEST(ErrorRecoveryAntlr4) { TVector<TVector<TString>> actual = { /* 0: */ {"EOF"}, @@ -266,21 +247,6 @@ Y_UNIT_TEST(IssuesCollected) { } } -Y_UNIT_TEST(IssueMessagesAntlr3) { - auto lexer3 = MakeLexer(Lexers, /* ansi = */ false, /* antlr4 = */ false); - - auto actual = GetIssueMessages(lexer3, "\xF0\x9F\x98\x8A SELECT * FR"); - - TVector<TString> expected = { - "<main>:1:0: Error: Unexpected character '\xF0\x9F\x98\x8A' (Unicode character <128522>) : cannot match to any predicted input...", - "<main>:1:1: Error: Unexpected character : cannot match to any predicted input...", - "<main>:1:2: Error: Unexpected character : cannot match to any predicted input...", - "<main>:1:3: Error: Unexpected character : cannot match to any predicted input...", - }; - - UNIT_ASSERT_VALUES_EQUAL(actual, expected); -} - Y_UNIT_TEST(IssueMessagesAntlr4) { auto lexer4 = MakeLexer(Lexers, /* ansi = */ false, /* antlr4 = */ true); diff --git a/yql/essentials/sql/v1/lexer/lexer_ut.h b/yql/essentials/sql/v1/lexer/lexer_ut.h index b4304eb7070..195a103d772 100644 --- a/yql/essentials/sql/v1/lexer/lexer_ut.h +++ b/yql/essentials/sql/v1/lexer/lexer_ut.h @@ -2,9 +2,7 @@ #include "lexer.h" -#define LEXER_NAME_ANSI_false_ANTLR4_false_FLAVOR_Default "antlr3" #define LEXER_NAME_ANSI_false_ANTLR4_true_FLAVOR_Default "antlr4" -#define LEXER_NAME_ANSI_true_ANTLR4_false_FLAVOR_Default "antlr3_ansi" #define LEXER_NAME_ANSI_true_ANTLR4_true_FLAVOR_Default "antlr4_ansi" #define LEXER_NAME_ANSI_false_ANTLR4_true_FLAVOR_Pure "antlr4_pure" #define LEXER_NAME_ANSI_true_ANTLR4_true_FLAVOR_Pure "antlr4_pure_ansi" @@ -17,21 +15,19 @@ static_cast<void (*)(NUnitTest::TTestContext&)>(&N<ANSI, ANTLR4, ELexerFlavor::FLAVOR>), \ /* forceFork = */ false) -#define Y_UNIT_TEST_ON_EACH_LEXER(N) \ - template <bool ANSI, bool ANTLR4, ELexerFlavor FLAVOR> \ - void N(NUnitTest::TTestContext&); \ - struct TTestRegistration##N { \ - TTestRegistration##N() { \ - Y_UNIT_TEST_ON_EACH_LEXER_ADD_TEST(N, false, false, Default); \ - Y_UNIT_TEST_ON_EACH_LEXER_ADD_TEST(N, false, true, Default); \ - Y_UNIT_TEST_ON_EACH_LEXER_ADD_TEST(N, true, false, Default); \ - Y_UNIT_TEST_ON_EACH_LEXER_ADD_TEST(N, true, true, Default); \ - Y_UNIT_TEST_ON_EACH_LEXER_ADD_TEST(N, false, true, Pure); \ - Y_UNIT_TEST_ON_EACH_LEXER_ADD_TEST(N, true, true, Pure); \ - Y_UNIT_TEST_ON_EACH_LEXER_ADD_TEST(N, false, false, Regex); \ - Y_UNIT_TEST_ON_EACH_LEXER_ADD_TEST(N, true, false, Regex); \ - } \ - }; \ - static TTestRegistration##N testRegistration##N; \ - template <bool ANSI, bool ANTLR4, ELexerFlavor FLAVOR> \ +#define Y_UNIT_TEST_ON_EACH_LEXER(N) \ + template <bool ANSI, bool ANTLR4, ELexerFlavor FLAVOR> \ + void N(NUnitTest::TTestContext&); \ + struct TTestRegistration##N { \ + TTestRegistration##N() { \ + Y_UNIT_TEST_ON_EACH_LEXER_ADD_TEST(N, false, true, Default); \ + Y_UNIT_TEST_ON_EACH_LEXER_ADD_TEST(N, true, true, Default); \ + Y_UNIT_TEST_ON_EACH_LEXER_ADD_TEST(N, false, true, Pure); \ + Y_UNIT_TEST_ON_EACH_LEXER_ADD_TEST(N, true, true, Pure); \ + Y_UNIT_TEST_ON_EACH_LEXER_ADD_TEST(N, false, false, Regex); \ + Y_UNIT_TEST_ON_EACH_LEXER_ADD_TEST(N, true, false, Regex); \ + } \ + }; \ + static TTestRegistration##N testRegistration##N; \ + template <bool ANSI, bool ANTLR4, ELexerFlavor FLAVOR> \ void N(NUnitTest::TTestContext&) diff --git a/yql/essentials/sql/v1/lexer/ut/ya.make b/yql/essentials/sql/v1/lexer/ut/ya.make index 87cb156cd93..d029af38a6b 100644 --- a/yql/essentials/sql/v1/lexer/ut/ya.make +++ b/yql/essentials/sql/v1/lexer/ut/ya.make @@ -3,8 +3,6 @@ UNITTEST_FOR(yql/essentials/sql/v1/lexer) PEERDIR( yql/essentials/core/issue yql/essentials/parser/lexer_common - yql/essentials/sql/v1/lexer/antlr3 - yql/essentials/sql/v1/lexer/antlr3_ansi yql/essentials/sql/v1/lexer/antlr4 yql/essentials/sql/v1/lexer/antlr4_ansi yql/essentials/sql/v1/lexer/antlr4_pure diff --git a/yql/essentials/sql/v1/lexer/ya.make b/yql/essentials/sql/v1/lexer/ya.make index 6462ced1991..d42dbfe8e71 100644 --- a/yql/essentials/sql/v1/lexer/ya.make +++ b/yql/essentials/sql/v1/lexer/ya.make @@ -16,8 +16,6 @@ SUPPRESSIONS( END() RECURSE( - antlr3 - antlr3_ansi antlr4 antlr4_ansi antlr4_pure diff --git a/yql/essentials/sql/v1/match_recognize.cpp b/yql/essentials/sql/v1/match_recognize.cpp index c70987efd48..f7e7fcb0c42 100644 --- a/yql/essentials/sql/v1/match_recognize.cpp +++ b/yql/essentials/sql/v1/match_recognize.cpp @@ -49,7 +49,10 @@ public: } BuildLookup("index"); break; - default: + case EColumnRefState::Deny: + case EColumnRefState::Allow: + case EColumnRefState::AsStringLiteral: + case EColumnRefState::AsPgType: ctx.Error(Pos_) << "Unexpected column reference state"; return false; } @@ -155,7 +158,11 @@ public: "Member", BuildAtom(ctx.Pos(), VarMatchedVarsName), Q(std::move(var)))); - default: + case EColumnRefState::Deny: + case EColumnRefState::Allow: + case EColumnRefState::AsStringLiteral: + case EColumnRefState::AsPgType: + case EColumnRefState::MatchRecognizeDefineAggregate: ctx.Error(Pos_) << "Unexpected column reference state"; return {}; } diff --git a/yql/essentials/sql/v1/node.cpp b/yql/essentials/sql/v1/node.cpp index 50dc8a47089..4bcc1815352 100644 --- a/yql/essentials/sql/v1/node.cpp +++ b/yql/essentials/sql/v1/node.cpp @@ -3157,7 +3157,7 @@ bool TUdfNode::DoInit(TContext& ctx, ISource* src) { if (!IsBackwardCompatibleFeatureAvailable(ctx.Settings.LangVer, NYql::MakeLangVersion(2025, 4), ctx.Settings.BackportMode)) { - ctx.Error() << "Udf: named argument Layers is not available before version 2025.03"; + ctx.Error() << "Udf: named argument Layers is not available before version 2025.04"; return false; } Layers_ = arg; diff --git a/yql/essentials/sql/v1/proto_parser/antlr3/proto_parser.cpp b/yql/essentials/sql/v1/proto_parser/antlr3/proto_parser.cpp deleted file mode 100644 index 10f9892d31c..00000000000 --- a/yql/essentials/sql/v1/proto_parser/antlr3/proto_parser.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "proto_parser.h" -#include <yql/essentials/parser/proto_ast/antlr3/proto_ast_antlr3.h> -#include <yql/essentials/parser/proto_ast/gen/v1/SQLv1Lexer.h> -#include <yql/essentials/parser/proto_ast/gen/v1/SQLv1Parser.h> -#include <yql/essentials/utils/yql_panic.h> - -namespace NSQLTranslationV1 { - -namespace { - -class TParser: public NSQLTranslation::IParser { -public: - google::protobuf::Message* Parse( - const TString& query, const TString& queryName, NProtoAST::IErrorCollector& err, - google::protobuf::Arena* arena) final { - YQL_ENSURE(arena); - NProtoAST::TProtoASTBuilder3<NALPDefault::SQLv1Parser, NALPDefault::SQLv1Lexer> builder(query, queryName, arena); - return builder.BuildAST(err); - } -}; - -class TFactory: public NSQLTranslation::IParserFactory { -public: - std::unique_ptr<NSQLTranslation::IParser> MakeParser() const final { - return std::make_unique<TParser>(); - } -}; - -} // namespace - -NSQLTranslation::TParserFactoryPtr MakeAntlr3ParserFactory() { - return MakeIntrusive<TFactory>(); -} - -} // namespace NSQLTranslationV1 diff --git a/yql/essentials/sql/v1/proto_parser/antlr3/proto_parser.h b/yql/essentials/sql/v1/proto_parser/antlr3/proto_parser.h deleted file mode 100644 index c72b0bb531f..00000000000 --- a/yql/essentials/sql/v1/proto_parser/antlr3/proto_parser.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include <yql/essentials/parser/proto_ast/common.h> - -namespace NSQLTranslationV1 { - -NSQLTranslation::TParserFactoryPtr MakeAntlr3ParserFactory(); - -} // namespace NSQLTranslationV1 diff --git a/yql/essentials/sql/v1/proto_parser/antlr3/ya.make b/yql/essentials/sql/v1/proto_parser/antlr3/ya.make deleted file mode 100644 index 1200caced99..00000000000 --- a/yql/essentials/sql/v1/proto_parser/antlr3/ya.make +++ /dev/null @@ -1,13 +0,0 @@ -LIBRARY() - -PEERDIR( - yql/essentials/utils - yql/essentials/parser/proto_ast/antlr3 - yql/essentials/parser/proto_ast/gen/v1 -) - -SRCS( - proto_parser.cpp -) - -END() diff --git a/yql/essentials/sql/v1/proto_parser/antlr3_ansi/proto_parser.cpp b/yql/essentials/sql/v1/proto_parser/antlr3_ansi/proto_parser.cpp deleted file mode 100644 index 50f8a676edf..00000000000 --- a/yql/essentials/sql/v1/proto_parser/antlr3_ansi/proto_parser.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "proto_parser.h" -#include <yql/essentials/parser/proto_ast/antlr3/proto_ast_antlr3.h> -#include <yql/essentials/parser/proto_ast/gen/v1_ansi/SQLv1Lexer.h> -#include <yql/essentials/parser/proto_ast/gen/v1_ansi/SQLv1Parser.h> -#include <yql/essentials/utils/yql_panic.h> - -namespace NSQLTranslationV1 { - -namespace { - -class TParser: public NSQLTranslation::IParser { -public: - google::protobuf::Message* Parse( - const TString& query, const TString& queryName, NProtoAST::IErrorCollector& err, - google::protobuf::Arena* arena) final { - YQL_ENSURE(arena); - NProtoAST::TProtoASTBuilder3<NALPAnsi::SQLv1Parser, NALPAnsi::SQLv1Lexer> builder(query, queryName, arena); - return builder.BuildAST(err); - } -}; - -class TFactory: public NSQLTranslation::IParserFactory { -public: - std::unique_ptr<NSQLTranslation::IParser> MakeParser() const final { - return std::make_unique<TParser>(); - } -}; - -} // namespace - -NSQLTranslation::TParserFactoryPtr MakeAntlr3AnsiParserFactory() { - return MakeIntrusive<TFactory>(); -} - -} // namespace NSQLTranslationV1 diff --git a/yql/essentials/sql/v1/proto_parser/antlr3_ansi/proto_parser.h b/yql/essentials/sql/v1/proto_parser/antlr3_ansi/proto_parser.h deleted file mode 100644 index f852e003ee9..00000000000 --- a/yql/essentials/sql/v1/proto_parser/antlr3_ansi/proto_parser.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include <yql/essentials/parser/proto_ast/common.h> - -namespace NSQLTranslationV1 { - -NSQLTranslation::TParserFactoryPtr MakeAntlr3AnsiParserFactory(); - -} // namespace NSQLTranslationV1 diff --git a/yql/essentials/sql/v1/proto_parser/antlr3_ansi/ya.make b/yql/essentials/sql/v1/proto_parser/antlr3_ansi/ya.make deleted file mode 100644 index ce8b3f7917a..00000000000 --- a/yql/essentials/sql/v1/proto_parser/antlr3_ansi/ya.make +++ /dev/null @@ -1,13 +0,0 @@ -LIBRARY() - -PEERDIR( - yql/essentials/utils - yql/essentials/parser/proto_ast/antlr3 - yql/essentials/parser/proto_ast/gen/v1_ansi -) - -SRCS( - proto_parser.cpp -) - -END() diff --git a/yql/essentials/sql/v1/proto_parser/parse_tree.h b/yql/essentials/sql/v1/proto_parser/parse_tree.h index 40ecdea8623..cfeeeca4fb1 100644 --- a/yql/essentials/sql/v1/proto_parser/parse_tree.h +++ b/yql/essentials/sql/v1/proto_parser/parse_tree.h @@ -1,6 +1,6 @@ #pragma once -#include <yql/essentials/parser/proto_ast/gen/v1_proto_split/SQLv1Parser.pb.main.h> +#include <yql/essentials/parser/proto_ast/gen/v1_proto_split_antlr4/SQLv1Antlr4Parser.pb.main.h> namespace NSQLTranslationV1 { diff --git a/yql/essentials/sql/v1/proto_parser/proto_parser.cpp b/yql/essentials/sql/v1/proto_parser/proto_parser.cpp index bba5e729635..176a1a349b9 100644 --- a/yql/essentials/sql/v1/proto_parser/proto_parser.cpp +++ b/yql/essentials/sql/v1/proto_parser/proto_parser.cpp @@ -4,8 +4,6 @@ #include <yql/essentials/parser/proto_ast/collect_issues/collect_issues.h> -#include <yql/essentials/sql/v1/proto_parser/antlr3/proto_parser.h> -#include <yql/essentials/sql/v1/proto_parser/antlr3_ansi/proto_parser.h> #include <yql/essentials/sql/v1/proto_parser/antlr4/proto_parser.h> #include <yql/essentials/sql/v1/proto_parser/antlr4_ansi/proto_parser.h> @@ -44,31 +42,11 @@ google::protobuf::Message* SqlAST(const TParsers& parsers, const TString& query, TGuard<TMutex> grd(SanitizerSQLTranslationMutex); #endif if (ansiLexer && !anlr4Parser) { - google::protobuf::Message* res = nullptr; - if (parsers.Antlr3Ansi) { - res = parsers.Antlr3Ansi->MakeParser()->Parse(query, queryName, err, arena); - if (!res) { - return res; - } - } else { - ReportError(err, "antlr3_ansi"); - return nullptr; - } - - return res; + ReportError(err, "antlr3_ansi"); + return nullptr; } else if (!ansiLexer && !anlr4Parser) { - google::protobuf::Message* res = nullptr; - if (parsers.Antlr3) { - res = parsers.Antlr3->MakeParser()->Parse(query, queryName, err, arena); - if (!res) { - return res; - } - } else { - ReportError(err, "antlr3"); - return nullptr; - } - - return res; + ReportError(err, "antlr3"); + return nullptr; } else if (ansiLexer && anlr4Parser) { google::protobuf::Message* res = nullptr; if (parsers.Antlr4Ansi) { diff --git a/yql/essentials/sql/v1/proto_parser/proto_parser.h b/yql/essentials/sql/v1/proto_parser/proto_parser.h index c4a3c663207..39f8f2cbf2e 100644 --- a/yql/essentials/sql/v1/proto_parser/proto_parser.h +++ b/yql/essentials/sql/v1/proto_parser/proto_parser.h @@ -24,4 +24,5 @@ google::protobuf::Message* SqlAST(const TParsers& parsers, const TString& query, NYql::TIssues& err, size_t maxErrors, bool ansiLexer, bool antlr4Parser, google::protobuf::Arena* arena); google::protobuf::Message* SqlAST(const TParsers& parsers, const TString& query, const TString& queryName, NAST::IErrorCollector& err, bool ansiLexer, bool antlr4Parser, google::protobuf::Arena* arena); + } // namespace NSQLTranslationV1 diff --git a/yql/essentials/sql/v1/proto_parser/ya.make b/yql/essentials/sql/v1/proto_parser/ya.make index 0fbe9f45469..27f057b0f35 100644 --- a/yql/essentials/sql/v1/proto_parser/ya.make +++ b/yql/essentials/sql/v1/proto_parser/ya.make @@ -3,7 +3,7 @@ LIBRARY() PEERDIR( yql/essentials/utils yql/essentials/parser/proto_ast/collect_issues - yql/essentials/parser/proto_ast/gen/v1_proto_split + yql/essentials/parser/proto_ast/gen/v1_proto_split_antlr4 ) SRCS( @@ -14,8 +14,6 @@ SRCS( END() RECURSE( - antlr3 - antlr3_ansi antlr4 antlr4_ansi ) diff --git a/yql/essentials/sql/v1/select.cpp b/yql/essentials/sql/v1/select.cpp index 860676ad1bc..a33c5cdae53 100644 --- a/yql/essentials/sql/v1/select.cpp +++ b/yql/essentials/sql/v1/select.cpp @@ -1128,8 +1128,6 @@ public: BuildLambda(Pos_, Y("row"), Args_[0])); break; } - default: - YQL_ENSURE(false, "Unexpected REDUCE mode"); } } diff --git a/yql/essentials/sql/v1/source.cpp b/yql/essentials/sql/v1/source.cpp index fd3764fb908..cb3c5ea8dbf 100644 --- a/yql/essentials/sql/v1/source.cpp +++ b/yql/essentials/sql/v1/source.cpp @@ -703,8 +703,9 @@ TNodePtr BuildFrameNode(const TFrameBound& frame, EFrameType frameType) { case FrameFollowing: settingStr = "following"; break; - default: + case FrameUndefined: YQL_ENSURE(false, "Unexpected frame setting"); + break; } TNodePtr node = frame.Bound; diff --git a/yql/essentials/sql/v1/sql.cpp b/yql/essentials/sql/v1/sql.cpp index 1fb88c6089b..c34e25112d4 100644 --- a/yql/essentials/sql/v1/sql.cpp +++ b/yql/essentials/sql/v1/sql.cpp @@ -125,7 +125,6 @@ bool NeedUseForAllStatements(const TRule_sql_stmt_core::AltCase& subquery) { case TRule_sql_stmt_core::kAltSqlStmtCore14: // export case TRule_sql_stmt_core::kAltSqlStmtCore18: // define action or subquery return true; - case TRule_sql_stmt_core::ALT_NOT_SET: case TRule_sql_stmt_core::kAltSqlStmtCore2: // select case TRule_sql_stmt_core::kAltSqlStmtCore4: // create table case TRule_sql_stmt_core::kAltSqlStmtCore5: // drop table @@ -188,6 +187,8 @@ bool NeedUseForAllStatements(const TRule_sql_stmt_core::AltCase& subquery) { case TRule_sql_stmt_core::kAltSqlStmtCore67: // alter secret case TRule_sql_stmt_core::kAltSqlStmtCore68: // drop secret return false; + case TRule_sql_stmt_core::ALT_NOT_SET: + Y_UNREACHABLE(); } } diff --git a/yql/essentials/sql/v1/sql.h b/yql/essentials/sql/v1/sql.h index be5bf5ce4f1..81056165855 100644 --- a/yql/essentials/sql/v1/sql.h +++ b/yql/essentials/sql/v1/sql.h @@ -4,7 +4,7 @@ #include <yql/essentials/parser/lexer_common/lexer.h> #include <yql/essentials/parser/lexer_common/hints.h> #include <yql/essentials/parser/proto_ast/common.h> -#include <yql/essentials/parser/proto_ast/gen/v1_proto_split/SQLv1Parser.pb.main.h> +#include <yql/essentials/parser/proto_ast/gen/v1_proto_split_antlr4/SQLv1Antlr4Parser.pb.main.h> #include <yql/essentials/public/issue/yql_warning.h> #include <yql/essentials/public/issue/yql_issue_manager.h> #include <yql/essentials/sql/settings/translation_settings.h> diff --git a/yql/essentials/sql/v1/sql_call_expr.cpp b/yql/essentials/sql/v1/sql_call_expr.cpp index f28da51216f..54f7738f8ae 100644 --- a/yql/essentials/sql/v1/sql_call_expr.cpp +++ b/yql/essentials/sql/v1/sql_call_expr.cpp @@ -160,7 +160,7 @@ bool TSqlCallExpr::Init(const TRule_value_constructor& node) { break; } case TRule_value_constructor::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } PositionalArgs_ = Args_; return true; @@ -239,7 +239,7 @@ bool TSqlCallExpr::Init(const TRule_using_call_expr& node) { break; } case TRule_using_call_expr::TBlock1::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } YQL_ENSURE(!DistinctAllowed_); UsingCallExpr_ = true; @@ -354,7 +354,7 @@ bool TSqlCallExpr::Init(const TRule_invoke_expr& node) { } break; case TRule_invoke_expr::TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -383,7 +383,7 @@ bool TSqlCallExpr::Init(const TRule_invoke_expr& node) { return false; } case TRule_invoke_expr_tail::TBlock1::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -423,7 +423,7 @@ bool TSqlCallExpr::Init(const TRule_invoke_expr& node) { break; } case TRule_window_name_or_specification::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } Ctx_.IncrementMonCounter("sql_features", "WindowFunctionOver"); } diff --git a/yql/essentials/sql/v1/sql_expression.cpp b/yql/essentials/sql/v1/sql_expression.cpp index dc311c66fb6..c3b36f45f7f 100644 --- a/yql/essentials/sql/v1/sql_expression.cpp +++ b/yql/essentials/sql/v1/sql_expression.cpp @@ -12,7 +12,6 @@ namespace NSQLTranslationV1 { -using NALPDefault::SQLv1LexerTokens; using NALPDefaultAntlr4::SQLv1Antlr4Lexer; using namespace NSQLv1Generated; @@ -31,7 +30,7 @@ TNodePtr TSqlExpression::BuildSourceOrNode(const TRule_expr& node) { return TypeNode(node.GetAlt_expr2().GetRule_type_name_composite1()); } case TRule_expr::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -66,7 +65,7 @@ TNodePtr TSqlExpression::Build(const TRule_lambda_or_parameter& node) { return namedNode; } case TRule_lambda_or_parameter::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -490,7 +489,7 @@ TMaybe<TExprOrIdent> TSqlExpression::LiteralExpr(const TRule_literal_value& node break; } case TRule_literal_value::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } if (!result.Expr) { return {}; @@ -584,7 +583,7 @@ void TSqlExpression::AddJsonVariable(const TRule_json_variable& node, TVector<TN break; } case TRule_json_variable_name::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } TNodePtr nameExpr = BuildQuotedAtom(namePos, rawName, nameFlags); @@ -648,7 +647,7 @@ TNodePtr TSqlExpression::JsonValueCaseHandler(const TRule_json_case_handler& nod mode = EJsonValueHandlerMode::DefaultValue; return Build(node.GetAlt_json_case_handler3().GetRule_expr2()); case TRule_json_case_handler::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -828,7 +827,7 @@ EJsonQueryHandler TSqlExpression::JsonQueryHandler(const TRule_json_query_handle case TRule_json_query_handler::kAltJsonQueryHandler4: return EJsonQueryHandler::EmptyObject; case TRule_json_query_handler::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -898,7 +897,7 @@ TNodePtr TSqlExpression::JsonApiExpr(const TRule_json_api_expr& node) { break; } case TRule_json_api_expr::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return result; @@ -922,18 +921,18 @@ TNodePtr TSqlExpression::RowPatternVarAccess(TString var, const TRule_unary_sube case TRule_id_or_type::kAltIdOrType2: break; case TRule_id_or_type::ALT_NOT_SET: - break; + Y_UNREACHABLE(); } break; } case TRule_an_id_or_type::kAltAnIdOrType2: break; case TRule_an_id_or_type::ALT_NOT_SET: - break; + Y_UNREACHABLE(); } break; case TRule_unary_subexpr_suffix_TBlock1_TBlock1_TAlt3_TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return {}; } @@ -988,7 +987,7 @@ TNodePtr TSqlExpression::UnaryCasualExpr(const TUnaryCasualExprRule& node, const break; } case TUnaryCasualExprRule::TBlock1::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } // bool onlyDots = true; @@ -1027,8 +1026,7 @@ TNodePtr TSqlExpression::UnaryCasualExpr(const TUnaryCasualExprRule& node, const break; } case TRule_unary_subexpr_suffix::TBlock1::TBlock1::ALT_NOT_SET: - AltNotImplemented("unary_subexpr_suffix", b); - return nullptr; + Y_UNREACHABLE(); } isFirstElem = false; @@ -1162,7 +1160,7 @@ TNodePtr TSqlExpression::UnaryCasualExpr(const TUnaryCasualExprRule& node, const break; } case TRule_unary_subexpr_suffix_TBlock1_TBlock1_TAlt3_TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } if (lastExpr) { @@ -1173,8 +1171,7 @@ TNodePtr TSqlExpression::UnaryCasualExpr(const TUnaryCasualExprRule& node, const break; } case TRule_unary_subexpr_suffix::TBlock1::TBlock1::ALT_NOT_SET: - AltNotImplemented("unary_subexpr_suffix", b); - return nullptr; + Y_UNREACHABLE(); } isFirstElem = false; @@ -1334,7 +1331,7 @@ TNodePtr TSqlExpression::ExistsRule(const TRule_exists_expr& rule) { break; } case TRule_exists_expr::TBlock3::ALT_NOT_SET: - AltNotImplemented("exists_expr", rule.GetBlock3()); + Y_UNREACHABLE(); } if (!source) { @@ -1456,7 +1453,7 @@ TMaybe<TExprOrIdent> TSqlExpression::AtomExpr(const TRule_atom_expr& node, const break; } case TRule_atom_expr::TAlt7::TBlock3::ALT_NOT_SET: - Y_ABORT("Unsigned number: you should change implementation according to grammar changes"); + Y_UNREACHABLE(); } result.Expr = BuildCallable(pos, module, name, {}); break; @@ -1478,7 +1475,7 @@ TMaybe<TExprOrIdent> TSqlExpression::AtomExpr(const TRule_atom_expr& node, const result.Expr = StructLiteral(node.GetAlt_atom_expr12().GetRule_struct_literal1()); break; case TRule_atom_expr::ALT_NOT_SET: - AltNotImplemented("atom_expr", node); + Y_UNREACHABLE(); } if (!result.Expr) { return {}; @@ -1542,7 +1539,7 @@ TMaybe<TExprOrIdent> TSqlExpression::InAtomExpr(const TRule_in_atom_expr& node, break; } case TRule_in_atom_expr::TAlt6::TBlock3::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } result.Expr = BuildCallable(pos, module, name, {}); break; @@ -1564,7 +1561,7 @@ TMaybe<TExprOrIdent> TSqlExpression::InAtomExpr(const TRule_in_atom_expr& node, result.Expr = StructLiteral(node.GetAlt_in_atom_expr11().GetRule_struct_literal1()); break; case TRule_in_atom_expr::ALT_NOT_SET: - AltNotImplemented("in_atom_expr", node); + Y_UNREACHABLE(); } if (!result.Expr) { return {}; @@ -1660,7 +1657,7 @@ bool TSqlExpression::SqlLambdaExprBody(TContext& ctx, const TRule_lambda_body& n break; } case TRule_lambda_stmt::ALT_NOT_SET: - Y_ABORT("SampleClause: does not correspond to grammar changes"); + Y_UNREACHABLE(); } } @@ -1713,7 +1710,7 @@ TNodePtr TSqlExpression::SubExpr(const TRule_con_subexpr& node, const TTrailingQ return expr ? expr->ApplyUnaryOp(Ctx_, pos, opName) : expr; } case TRule_con_subexpr::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return nullptr; } @@ -2035,9 +2032,7 @@ TNodePtr TSqlExpression::SubExpr(const TRule_xor_subexpr& node, const TTrailingQ return BinOpList(node.GetRule_eq_subexpr1(), getNode, alt.GetBlock1().begin(), alt.GetBlock1().end(), tail); } case TRule_cond_expr::ALT_NOT_SET: - Ctx_.IncrementMonCounter("sql_errors", "UnknownConditionExpr"); - AltNotImplemented("cond_expr", cond); - return nullptr; + Y_UNREACHABLE(); } } return res; @@ -2228,7 +2223,7 @@ TNodePtr TSqlExpression::BinOpList(const TRule_bit_subexpr& node, TGetNode getNo break; } case TRule_neq_subexpr_TBlock2_TBlock1::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } partialResult = BuildBinaryOp(Ctx_, Ctx_.Pos(), opName, partialResult, SubExpr(getNode(*begin), (begin + 1 == end) ? tail : TTrailingQuestions{})); @@ -2297,7 +2292,7 @@ TNodePtr TSqlExpression::BinOpList(const TRule_eq_subexpr& node, TGetNode getNod break; } case TRule_cond_expr::TAlt5::TBlock1::TBlock1::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } partialResult = BuildBinaryOp(Ctx_, Ctx_.Pos(), opName, partialResult, SubExpr(getNode(*begin), (begin + 1 == end) ? tail : TTrailingQuestions{})); @@ -2386,7 +2381,7 @@ TNodePtr TSqlExpression::SelectOrExpr(const TRule_select_or_expr& node) { case NSQLv1Generated::TRule_select_or_expr::kAltSelectOrExpr2: return TupleOrExpr(node.GetAlt_select_or_expr2().GetRule_tuple_or_expr1()); case NSQLv1Generated::TRule_select_or_expr::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -2469,7 +2464,7 @@ TNodePtr TSqlExpression::SmartParenthesis(const TRule_smart_parenthesis& node) { case NSQLv1Generated::TRule_smart_parenthesis_TBlock2::kAlt2: return EmptyTuple(); case NSQLv1Generated::TRule_smart_parenthesis_TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } diff --git a/yql/essentials/sql/v1/sql_group_by.cpp b/yql/essentials/sql/v1/sql_group_by.cpp index deca5b6e534..cce460d9746 100644 --- a/yql/essentials/sql/v1/sql_group_by.cpp +++ b/yql/essentials/sql/v1/sql_group_by.cpp @@ -275,7 +275,7 @@ bool TGroupByClause::GroupingElement(const TRule_grouping_element& node, EGroupB break; } case TRule_grouping_element::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return true; } @@ -435,8 +435,11 @@ bool TGroupByClause::AllowUnnamed(TPosition pos, EGroupByFeatures featureContext case EGroupByFeatures::GroupingSet: feature = "GROUPING SETS"; break; - default: + case EGroupByFeatures::Expression: + case EGroupByFeatures::Empty: + case EGroupByFeatures::End: YQL_ENSURE(false, "Unknown feature"); + break; } Ctx_.Error(pos) << "Unnamed expressions are not supported in " << feature << ". Please use '<expr> AS <name>'."; diff --git a/yql/essentials/sql/v1/sql_into_tables.cpp b/yql/essentials/sql/v1/sql_into_tables.cpp index 9ea8bd36f04..361e035828b 100644 --- a/yql/essentials/sql/v1/sql_into_tables.cpp +++ b/yql/essentials/sql/v1/sql_into_tables.cpp @@ -51,7 +51,7 @@ TNodePtr TSqlIntoTable::Build(const TRule_into_table_stmt& node) { modeTokens = {modeBlock.GetAlt6().GetToken1()}; break; case TRule_into_table_stmt_TBlock1::AltCase::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } TVector<TString> modeStrings; @@ -140,7 +140,7 @@ TNodePtr TSqlIntoTable::Build(const TRule_into_table_stmt& node) { break; } case TRule_simple_table_ref_core::AltCase::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } bool withTruncate = false; diff --git a/yql/essentials/sql/v1/sql_match_recognize.cpp b/yql/essentials/sql/v1/sql_match_recognize.cpp index d23d7911c9f..7a05223350e 100644 --- a/yql/essentials/sql/v1/sql_match_recognize.cpp +++ b/yql/essentials/sql/v1/sql_match_recognize.cpp @@ -178,7 +178,7 @@ TNodePtr TSqlMatchRecognizeClause::ParseRowsPerMatch(TPosition pos, const TRule_ return NYql::NMatchRecognize::ERowsPerMatch::AllRows; } case TRule_row_pattern_rows_per_match::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } }(); return BuildQuotedAtom(pos, "RowsPerMatch_" + ToString(result)); @@ -239,7 +239,7 @@ TNodePtr TSqlMatchRecognizeClause::ParseAfterMatchSkipTo(TPosition pos, const TR return NYql::NMatchRecognize::TAfterMatchSkipTo{NYql::NMatchRecognize::EAfterMatchSkipTo::To, std::move(var)}; } case TRule_row_pattern_skip_to::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } }(); if (!result) { @@ -327,7 +327,7 @@ TNodePtr TSqlMatchRecognizeClause::ParsePatternFactor(TPosition pos, const TRule return BuildPattern(pos, std::move(result)); } case TRule_row_pattern_primary::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } }(); if (!primary) { @@ -377,7 +377,7 @@ TNodePtr TSqlMatchRecognizeClause::ParsePatternFactor(TPosition pos, const TRule return std::tuple{quantity, quantity, true, output, false}; } case TRule_row_pattern_quantifier::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } }(); return BuildPatternFactor(pos, std::move(primary), std::move(quantifier)); diff --git a/yql/essentials/sql/v1/sql_match_recognize_ut.cpp b/yql/essentials/sql/v1/sql_match_recognize_ut.cpp index 95f83ea7ea2..da29331e4b2 100644 --- a/yql/essentials/sql/v1/sql_match_recognize_ut.cpp +++ b/yql/essentials/sql/v1/sql_match_recognize_ut.cpp @@ -1,4 +1,4 @@ -#include "sql_ut.h" +#include "sql_ut_antlr4.h" #include <yql/essentials/core/sql_types/match_recognize.h> #include <yql/essentials/providers/common/provider/yql_provider_names.h> diff --git a/yql/essentials/sql/v1/sql_query.cpp b/yql/essentials/sql/v1/sql_query.cpp index 5c2c9024d66..1fb53c2d553 100644 --- a/yql/essentials/sql/v1/sql_query.cpp +++ b/yql/essentials/sql/v1/sql_query.cpp @@ -17,7 +17,6 @@ namespace NSQLTranslationV1 { -using NALPDefault::SQLv1LexerTokens; using NALPDefaultAntlr4::SQLv1Antlr4Lexer; using namespace NSQLv1Generated; @@ -776,7 +775,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core& break; } case TRule_alter_user_stmt_TBlock4::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } AddStatementToBlocks(blocks, stmt); @@ -879,7 +878,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core& break; } case TRule_alter_group_stmt_TBlock4::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } AddStatementToBlocks(blocks, stmt); @@ -1365,8 +1364,9 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core& break; } case TRule_sql_stmt_core::kAltSqlStmtCore42: { - // create_view_stmt: CREATE VIEW (IF NOT EXISTS)? name (WITH (k = v, ...))? AS select_stmt; + // create_view_stmt: CREATE VIEW (IF NOT EXISTS)? name (WITH (k = v, ...))? AS (select_stmt | DO BEGIN define_action_or_subquery_body END DO) auto& node = core.GetAlt_sql_stmt_core42().GetRule_create_view_stmt1(); + Token(node.GetToken1()); TObjectOperatorContext context(Ctx_.Scoped); if (node.GetRule_object_ref4().HasBlock1()) { if (!ClusterExpr(node.GetRule_object_ref4().GetBlock1().GetRule_cluster_expr1(), @@ -1377,6 +1377,11 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core& } } + if (context.Cluster.Empty()) { + Error() << "No cluster name given and no default cluster is selected"; + return false; + } + const bool existingOk = node.HasBlock3(); std::map<TString, TDeferredAtom> features; @@ -1385,8 +1390,35 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core& return false; } } - if (!ParseViewQuery(features, node.GetRule_select_stmt7())) { - return false; + + switch (node.GetBlock7().GetAltCase()) { + case TRule_create_view_stmt_TBlock7::AltCase::kAlt1: { + if (context.ServiceId == YtProviderName) { + Error() << "CREATE VIEW ... AS SELECT syntax is not supported for " << context.ServiceId << " provider. " + << "Please use CREATE VIEW ... AS DO BEGIN ... END DO"; + return false; + } + if (!ParseViewQuery(features, node.GetBlock7().GetAlt1().GetRule_select_stmt1())) { + return false; + } + break; + } + case TRule_create_view_stmt_TBlock7::AltCase::kAlt2: { + if (context.ServiceId != YtProviderName) { + Error() << "CREATE VIEW ... AS DO BEGIN ... END DO syntax is not supported for " << context.ServiceId << " provider. " + << "Please use CREATE VIEW ... AS SELECT"; + return false; + } + auto& alt = node.GetBlock7().GetAlt2(); + if (!ParseViewQuery(features, alt.GetRule_define_action_or_subquery_body3(), + alt.GetToken2(), alt.GetToken4(), context.ServiceId, context.Cluster)) + { + return false; + } + break; + } + case TRule_create_view_stmt_TBlock7::AltCase::ALT_NOT_SET: + Y_ABORT("You should change implementation according to grammar changes"); } const TString objectId = Id(node.GetRule_object_ref4().GetRule_id_or_at2(), *this).second; @@ -1609,8 +1641,8 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core& } break; } - case TRule_alter_backup_collection_stmt_TBlock3::ALT_NOT_SET: { - } // do nothing + case TRule_alter_backup_collection_stmt_TBlock3::ALT_NOT_SET: + Y_UNREACHABLE(); } auto database = addDatabase ? TAlterBackupCollectionParameters::EDatabase::Add : dropDatabase ? TAlterBackupCollectionParameters::EDatabase::Drop @@ -1979,8 +2011,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core& break; } case TRule_alter_database_action::ALT_NOT_SET: - AltNotImplemented("alter_database_action", action); - return false; + Y_UNREACHABLE(); } const TPosition pos = Ctx_.Pos(); @@ -2224,9 +2255,7 @@ bool TSqlQuery::Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core& break; } case TRule_sql_stmt_core::ALT_NOT_SET: - Ctx_.IncrementMonCounter("sql_errors", "UnknownStatement" + internalStatementName); - AltNotImplemented("sql_stmt_core", core); - return false; + Y_UNREACHABLE(); } Ctx_.IncrementMonCounter("sql_features", internalStatementName); @@ -2463,10 +2492,8 @@ bool TSqlQuery::AlterTableAction(const TRule_alter_table_action& node, TAlterTab break; } - case TRule_alter_table_action::ALT_NOT_SET: { - AltNotImplemented("alter_table_action", node); - return false; - } + case TRule_alter_table_action::ALT_NOT_SET: + Y_UNREACHABLE(); } return true; } @@ -2521,8 +2548,7 @@ bool TSqlQuery::AlterExternalTableAction(const TRule_alter_external_table_action } case TRule_alter_external_table_action::ALT_NOT_SET: - AltNotImplemented("alter_external_table_action", node); - return false; + Y_UNREACHABLE(); } return true; } @@ -2737,8 +2763,7 @@ bool TSqlQuery::AlterTableAlterIndex(const TRule_alter_table_alter_index& node, break; } case TRule_alter_table_alter_index_action::ALT_NOT_SET: - AltNotImplemented("alter_table_alter_index_action", action); - return false; + Y_UNREACHABLE(); } return true; @@ -2795,7 +2820,7 @@ bool TSqlQuery::AlterSequenceAction(const TRule_alter_sequence_action& node, TSe break; } case TRule_alter_sequence_action::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return true; @@ -2841,8 +2866,7 @@ bool TSqlQuery::AlterTableAlterChangefeed(const TRule_alter_table_alter_changefe } case TRule_changefeed_alter_settings::ALT_NOT_SET: - AltNotImplemented("changefeed_alter_settings", alter); - return false; + Y_UNREACHABLE(); } return true; @@ -3189,8 +3213,6 @@ THashMap<TString, TPragmaDescr> PragmaDescrs{ case TWarningRule::EParseResult::PARSE_ACTION_FAIL: ctx.Error() << parseError; return {}; - default: - Y_ENSURE(false, "Unknown parse result"); } ctx.WarningPolicy.AddRule(rule); @@ -3354,6 +3376,16 @@ THashMap<TString, TPragmaDescr> PragmaDescrs{ ctx.Scoped->WarnUntypedStringLiterals = false; return TNodePtr{}; }), + TableElemExt("SimplePg", [](CB_SIG) -> TMaybe<TNodePtr> { + auto& ctx = query.Context(); + ctx.Scoped->SimplePgByDefault = true; + return TNodePtr{}; + }), + TableElemExt("DisableSimplePg", [](CB_SIG) -> TMaybe<TNodePtr> { + auto& ctx = query.Context(); + ctx.Scoped->SimplePgByDefault = false; + return TNodePtr{}; + }), // END TODO TableElemExt("DataWatermarks", [](CB_SIG) -> TMaybe<TNodePtr> { @@ -3592,6 +3624,8 @@ TMaybe<TNodePtr> TSqlQuery::PragmaStatement(const TRule_pragma_stmt& stmt) { "disableunicodeliterals", "warnuntypedstringliterals", "disablewarnuntypedstringliterals", + "simplepg", + "disablesimplepg", }; const bool hasLexicalScope = withConfigure || lexicalScopePragmas.contains(normalizedPragma); const bool withFileAlias = normalizedPragma == "file" || normalizedPragma == "folder" || normalizedPragma == "library" || normalizedPragma == "udf"; @@ -3849,7 +3883,7 @@ TNodePtr TSqlQuery::Build(const TRule_delete_stmt& stmt) { } case TRule_delete_stmt_TBlock5::ALT_NOT_SET: - return nullptr; + Y_UNREACHABLE(); } } @@ -3927,7 +3961,7 @@ TNodePtr TSqlQuery::Build(const TRule_update_stmt& stmt) { } case TRule_update_stmt_TBlock4::ALT_NOT_SET: - return nullptr; + Y_UNREACHABLE(); } } @@ -3938,8 +3972,7 @@ TSourcePtr TSqlQuery::Build(const TRule_set_clause_choice& stmt) { case TRule_set_clause_choice::kAltSetClauseChoice2: return Build(stmt.GetAlt_set_clause_choice2().GetRule_multiple_column_assignment1()); case TRule_set_clause_choice::ALT_NOT_SET: - AltNotImplemented("set_clause_choice", stmt); - return nullptr; + Y_UNREACHABLE(); } } @@ -4036,23 +4069,10 @@ TNodePtr TSqlQuery::Build(const TSQLv1ParserAST& ast) { } } - ui32 topLevelSelects = 0; - bool hasTailOps = false; - for (auto& block : blocks) { - if (block->SubqueryAlias()) { - continue; - } - - if (block->HasSelectResult()) { - ++topLevelSelects; - } else if (topLevelSelects) { - hasTailOps = true; - } - } - - if ((Mode_ == NSQLTranslation::ESqlMode::SUBQUERY || Mode_ == NSQLTranslation::ESqlMode::LIMITED_VIEW) && (topLevelSelects != 1 || hasTailOps)) { - Error() << "Strictly one select/process/reduce statement is expected at the end of " - << (Mode_ == NSQLTranslation::ESqlMode::LIMITED_VIEW ? "view" : "subquery"); + if ((Mode_ == NSQLTranslation::ESqlMode::SUBQUERY || + Mode_ == NSQLTranslation::ESqlMode::LIMITED_VIEW) && + !ValidateSubqueryOrViewBody(blocks)) + { return nullptr; } @@ -4110,23 +4130,10 @@ TNodePtr TSqlQuery::Build(const std::vector<::NSQLv1Generated::TRule_sql_stmt_co } } - ui32 topLevelSelects = 0; - bool hasTailOps = false; - for (auto& block : blocks) { - if (block->SubqueryAlias()) { - continue; - } - - if (block->HasSelectResult()) { - ++topLevelSelects; - } else if (topLevelSelects) { - hasTailOps = true; - } - } - - if ((Mode_ == NSQLTranslation::ESqlMode::SUBQUERY || Mode_ == NSQLTranslation::ESqlMode::LIMITED_VIEW) && (topLevelSelects != 1 || hasTailOps)) { - Error() << "Strictly one select/process/reduce statement is expected at the end of " - << (Mode_ == NSQLTranslation::ESqlMode::LIMITED_VIEW ? "view" : "subquery"); + if ((Mode_ == NSQLTranslation::ESqlMode::SUBQUERY || + Mode_ == NSQLTranslation::ESqlMode::LIMITED_VIEW) && + !ValidateSubqueryOrViewBody(blocks)) + { return nullptr; } @@ -4167,7 +4174,7 @@ static bool BuildColumnFeatures(std::map<TString, TDeferredAtom>& result, const case TRule_type_name_or_bind::kAltTypeNameOrBind2: return false; case TRule_type_name_or_bind::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } result["NAME"] = TDeferredAtom(pos, columnName); @@ -4203,7 +4210,7 @@ bool TSqlQuery::ParseTableStoreFeatures(std::map<TString, TDeferredAtom>& result break; } case TRule_alter_table_store_action::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return true; } diff --git a/yql/essentials/sql/v1/sql_query.h b/yql/essentials/sql/v1/sql_query.h index 67237557c35..201a0268ae5 100644 --- a/yql/essentials/sql/v1/sql_query.h +++ b/yql/essentials/sql/v1/sql_query.h @@ -2,7 +2,7 @@ #include "sql_translation.h" -#include <yql/essentials/parser/proto_ast/gen/v1_proto_split/SQLv1Parser.pb.main.h> +#include <yql/essentials/parser/proto_ast/gen/v1_proto_split_antlr4/SQLv1Antlr4Parser.pb.main.h> #include <util/string/split.h> namespace NSQLTranslationV1 { diff --git a/yql/essentials/sql/v1/sql_select.cpp b/yql/essentials/sql/v1/sql_select.cpp index b07b0ed7ab4..ac84e237782 100644 --- a/yql/essentials/sql/v1/sql_select.cpp +++ b/yql/essentials/sql/v1/sql_select.cpp @@ -124,9 +124,7 @@ bool TSqlSelect::JoinOp(ISource* join, const TRule_join_source::TBlock3& block, joinOp = Token(block.GetAlt4().GetToken1()); break; case TRule_join_op_TAlt2_TBlock2_TAlt1_TBlock1::ALT_NOT_SET: - Ctx_.IncrementMonCounter("sql_errors", "UnknownJoinOperation"); - AltNotImplemented("join_op", node); - return false; + Y_UNREACHABLE(); } } if (alt.GetBlock2().GetAlt1().HasBlock2()) { @@ -148,18 +146,14 @@ bool TSqlSelect::JoinOp(ISource* join, const TRule_join_source::TBlock3& block, joinOp = Token(alt.GetBlock2().GetAlt3().GetToken1()); break; case TRule_join_op::TAlt2::TBlock2::ALT_NOT_SET: - Ctx_.IncrementMonCounter("sql_errors", "UnknownJoinOperation"); - AltNotImplemented("join_op", node); - return false; + Y_UNREACHABLE(); } Ctx_.IncrementMonCounter("sql_features", "Join"); Ctx_.IncrementMonCounter("sql_join_operations", joinOp); break; } case TRule_join_op::ALT_NOT_SET: - Ctx_.IncrementMonCounter("sql_errors", "UnknownJoinOperation2"); - AltNotImplemented("join_op", node); - return false; + Y_UNREACHABLE(); } joinOp = NormalizeJoinOp(joinOp); if (linkSettings.Strategy != TJoinLinkSettings::EStrategy::Default && joinOp == "Cross") { @@ -226,9 +220,7 @@ TNodePtr TSqlSelect::JoinExpr(ISource* join, const TRule_join_constraint& node) return join->GetJoin()->BuildJoinKeys(Ctx_, names); } case TRule_join_constraint::ALT_NOT_SET: - Ctx_.IncrementMonCounter("sql_errors", "UnknownJoinConstraint"); - AltNotImplemented("join_constraint", node); - break; + Y_UNREACHABLE(); } return nullptr; } @@ -309,9 +301,7 @@ bool TSqlSelect::FlattenByArg(const TString& sourceLabel, TVector<TNodePtr>& fla break; } case TRule_flatten_by_arg::ALT_NOT_SET: - Ctx_.IncrementMonCounter("sql_errors", "UnknownFlattenByArg"); - AltNotImplemented("flatten_by_arg", node); - return false; + Y_UNREACHABLE(); } return true; } @@ -356,8 +346,7 @@ TSourcePtr TSqlSelect::FlattenSource(const TRule_flatten_source& node) { } case TRule_flatten_source::TBlock2::TBlock2::ALT_NOT_SET: - Ctx_.IncrementMonCounter("sql_errors", "UnknownOrdinaryNamedColumn"); - AltNotImplemented("flatten_source", flatten2); + Y_UNREACHABLE(); } } return source; @@ -455,7 +444,7 @@ bool TSqlSelect::SelectTerm(TVector<TNodePtr>& terms, const TRule_result_column& implicitLabel = true; break; case TRule_result_column_TAlt2_TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } term->SetLabel(label, Ctx_.Pos()); term->MarkImplicitLabel(implicitLabel); @@ -464,9 +453,7 @@ bool TSqlSelect::SelectTerm(TVector<TNodePtr>& terms, const TRule_result_column& break; } case TRule_result_column::ALT_NOT_SET: - Ctx_.IncrementMonCounter("sql_errors", "UnknownResultColumn"); - AltNotImplemented("result_column", node); - return false; + Y_UNREACHABLE(); } return true; } @@ -555,9 +542,7 @@ TSourcePtr TSqlSelect::SingleSource(const TRule_single_source& node, const TVect return TSqlValues(Ctx_, Mode_).Build(alt.GetRule_values_stmt2(), pos, derivedColumns, derivedColumnsPos); } case TRule_single_source::ALT_NOT_SET: - AltNotImplemented("single_source", node); - Ctx_.IncrementMonCounter("sql_errors", "UnknownSingleSource"); - return nullptr; + Y_UNREACHABLE(); } } @@ -608,7 +593,7 @@ TSourcePtr TSqlSelect::NamedSingleSource(const TRule_named_single_source& node, } break; case TRule_named_single_source_TBlock3_TBlock1::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } singleSource->SetLabel(label); } @@ -662,7 +647,7 @@ TSourcePtr TSqlSelect::NamedSingleSource(const TRule_named_single_source& node, Ctx_.IncrementMonCounter("sql_features", "SampleClause"); } break; case TRule_named_single_source::TBlock4::ALT_NOT_SET: - Y_ABORT("SampleClause: does not corresond to grammar changes"); + Y_UNREACHABLE(); } if (!singleSource->SetSamplingOptions(Ctx_, pos, sampleClause, mode, samplingRateNode, samplingSeedNode)) { Ctx_.IncrementMonCounter("sql_errors", "IncorrectSampleClause"); @@ -699,7 +684,7 @@ bool TSqlSelect::ColumnName(TVector<TNodePtr>& keys, const TRule_without_column_ columnName = Id(node.GetAlt_without_column_name2().GetRule_an_id_without1(), *this); break; case TRule_without_column_name::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } if (columnName.empty()) { @@ -1341,7 +1326,7 @@ TSqlSelect::TSelectKindResult TSqlSelect::SelectKind(const TRule_select_kind& no break; } case TRule_select_kind_TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return res; @@ -1657,7 +1642,7 @@ TSqlSelect::TSelectKindResult TSqlSelect::BuildAtom( break; } case NSQLv1Generated::TRule_select_or_expr::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } else if (placement.IsFirstInSelectOp && placement.IsLastInSelectOp) { result = SelectKind(node, pos, /* placement = */ Nothing()); diff --git a/yql/essentials/sql/v1/sql_select.h b/yql/essentials/sql/v1/sql_select.h index 65b5c66f6bd..c953bc2430f 100644 --- a/yql/essentials/sql/v1/sql_select.h +++ b/yql/essentials/sql/v1/sql_select.h @@ -1,7 +1,7 @@ #pragma once #include "sql_translation.h" -#include <yql/essentials/parser/proto_ast/gen/v1_proto_split/SQLv1Parser.pb.main.h> +#include <yql/essentials/parser/proto_ast/gen/v1_proto_split_antlr4/SQLv1Antlr4Parser.pb.main.h> namespace NSQLTranslationV1 { diff --git a/yql/essentials/sql/v1/sql_select_yql.cpp b/yql/essentials/sql/v1/sql_select_yql.cpp index e1a4da6250e..4f12750cffc 100644 --- a/yql/essentials/sql/v1/sql_select_yql.cpp +++ b/yql/essentials/sql/v1/sql_select_yql.cpp @@ -57,7 +57,7 @@ private: case NSQLv1Generated::TRule_select_kind_TBlock2::kAlt3: return Build(block.GetAlt3().GetRule_select_core1()); case NSQLv1Generated::TRule_select_kind_TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -188,7 +188,7 @@ private: return expr; } break; case NSQLv1Generated::TRule_result_column::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -253,7 +253,7 @@ private: case NSQLv1Generated::TRule_single_source::kAltSingleSource3: return Build(rule.GetAlt_single_source3().GetRule_values_stmt2()); case NSQLv1Generated::TRule_single_source::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -303,7 +303,7 @@ private: case TRule_result_column_TAlt2_TBlock2::kAlt2: return Id(block.GetAlt2().GetRule_an_id_as_compat1(), *this); case TRule_result_column_TAlt2_TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -314,7 +314,7 @@ private: case NSQLv1Generated::TRule_select_kind_parenthesis::kAltSelectKindParenthesis2: return parenthesis.GetAlt_select_kind_parenthesis2().GetRule_select_kind_partial2(); case NSQLv1Generated::TRule_select_kind_parenthesis::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -325,7 +325,7 @@ private: case TRule_named_single_source_TBlock3_TBlock1::kAlt2: return Id(block.GetAlt2().GetRule_an_id_as_compat1(), *this); case TRule_named_single_source_TBlock3_TBlock1::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } diff --git a/yql/essentials/sql/v1/sql_select_yql.h b/yql/essentials/sql/v1/sql_select_yql.h index 367473707ed..61764fb3251 100644 --- a/yql/essentials/sql/v1/sql_select_yql.h +++ b/yql/essentials/sql/v1/sql_select_yql.h @@ -4,7 +4,7 @@ #include <yql/essentials/sql/settings/translation_settings.h> -#include <yql/essentials/parser/proto_ast/gen/v1_proto_split/SQLv1Parser.pb.main.h> +#include <yql/essentials/parser/proto_ast/gen/v1_proto_split_antlr4/SQLv1Antlr4Parser.pb.main.h> #include <expected> diff --git a/yql/essentials/sql/v1/sql_translation.cpp b/yql/essentials/sql/v1/sql_translation.cpp index 8b8f8211691..5b8b6d67689 100644 --- a/yql/essentials/sql/v1/sql_translation.cpp +++ b/yql/essentials/sql/v1/sql_translation.cpp @@ -107,7 +107,6 @@ TNodePtr BuildViewSelect(const TRule_select_stmt& selectStatement, TContext& con namespace NSQLTranslationV1 { -using NALPDefault::SQLv1LexerTokens; using NALPDefaultAntlr4::SQLv1Antlr4Lexer; using namespace NSQLv1Generated; @@ -141,7 +140,7 @@ TIdentifier GetKeywordId(TTranslation& ctx, const TRule_keyword& node) { case TRule_keyword::kAltKeyword8: return GetIdentifier(ctx, node.GetAlt_keyword8().GetRule_keyword_hint_uncompat1()); case TRule_keyword::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -153,7 +152,7 @@ TString Id(const TRule_id& node, TTranslation& ctx) { case TRule_id::kAltId2: return GetKeyword(ctx, node.GetAlt_id2().GetRule_keyword1()); case TRule_id::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -164,7 +163,7 @@ TString Id(const TRule_id_or_type& node, TTranslation& ctx) { case TRule_id_or_type::kAltIdOrType2: return ctx.Identifier(node.GetAlt_id_or_type2().GetRule_type_id1().GetToken1()); case TRule_id_or_type::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -175,7 +174,7 @@ TString Id(const TRule_id_as_compat& node, TTranslation& ctx) { case TRule_id_as_compat::kAltIdAsCompat2: return ctx.Token(node.GetAlt_id_as_compat2().GetRule_keyword_as_compat1().GetToken1()); case TRule_id_as_compat::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -186,7 +185,7 @@ TString Id(const TRule_an_id_as_compat& node, TTranslation& ctx) { case TRule_an_id_as_compat::kAltAnIdAsCompat2: return IdContentFromString(ctx.Context(), ctx.Token(node.GetAlt_an_id_as_compat2().GetToken1())); case TRule_an_id_as_compat::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -218,7 +217,7 @@ TString Id(const TRule_id_schema& node, TTranslation& ctx) { case TRule_id_schema::kAltIdSchema7: return GetKeyword(ctx, node.GetAlt_id_schema7().GetRule_keyword_hint_uncompat1()); case TRule_id_schema::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -230,7 +229,7 @@ TString Id(const TRule_an_id_or_type& node, TTranslation& ctx) { case TRule_an_id_or_type::kAltAnIdOrType2: return IdContentFromString(ctx.Context(), ctx.Token(node.GetAlt_an_id_or_type2().GetToken1())); case TRule_an_id_or_type::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -267,7 +266,7 @@ TString Id(const TRule_id_table& node, TTranslation& ctx) { case TRule_id_table::kAltIdTable7: return GetKeyword(ctx, node.GetAlt_id_table7().GetRule_keyword_hint_uncompat1()); case TRule_id_table::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -279,7 +278,7 @@ TString Id(const TRule_an_id_table& node, TTranslation& ctx) { case TRule_an_id_table::kAltAnIdTable2: return IdContentFromString(ctx.Context(), ctx.Token(node.GetAlt_an_id_table2().GetToken1())); case TRule_an_id_table::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -290,7 +289,7 @@ TString Id(const TRule_id_table_or_type& node, TTranslation& ctx) { case TRule_id_table_or_type::kAltIdTableOrType2: return ctx.Identifier(node.GetAlt_id_table_or_type2().GetRule_type_id1().GetToken1()); case TRule_id_table_or_type::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -320,7 +319,7 @@ TString Id(const TRule_id_expr& node, TTranslation& ctx) { case TRule_id_expr::kAltIdExpr6: return GetKeyword(ctx, node.GetAlt_id_expr6().GetRule_keyword_hint_uncompat1()); case TRule_id_expr::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -357,7 +356,7 @@ TString Id(const TRule_id_expr_in& node, TTranslation& ctx) { case TRule_id_expr_in::kAltIdExprIn5: return GetKeyword(ctx, node.GetAlt_id_expr_in5().GetRule_keyword_hint_uncompat1()); case TRule_id_expr_in::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -391,7 +390,7 @@ TString Id(const TRule_id_window& node, TTranslation& ctx) { case TRule_id_window::kAltIdWindow8: return GetKeyword(ctx, node.GetAlt_id_window8().GetRule_keyword_hint_uncompat1()); case TRule_id_window::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -423,7 +422,7 @@ TString Id(const TRule_id_without& node, TTranslation& ctx) { case TRule_id_without::kAltIdWithout7: return GetKeyword(ctx, node.GetAlt_id_without7().GetRule_keyword_hint_uncompat1()); case TRule_id_without::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -457,7 +456,7 @@ TString Id(const TRule_id_hint& node, TTranslation& ctx) { case TRule_id_hint::kAltIdHint8: return GetKeyword(ctx, node.GetAlt_id_hint8().GetRule_keyword_window_uncompat1()); case TRule_id_hint::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -469,7 +468,7 @@ TString Id(const TRule_an_id& node, TTranslation& ctx) { case TRule_an_id::kAltAnId2: return IdContentFromString(ctx.Context(), ctx.Token(node.GetAlt_an_id2().GetToken1())); case TRule_an_id::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -481,7 +480,7 @@ TString Id(const TRule_an_id_schema& node, TTranslation& ctx) { case TRule_an_id_schema::kAltAnIdSchema2: return IdContentFromString(ctx.Context(), ctx.Token(node.GetAlt_an_id_schema2().GetToken1())); case TRule_an_id_schema::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -493,7 +492,7 @@ TString Id(const TRule_an_id_expr& node, TTranslation& ctx) { case TRule_an_id_expr::kAltAnIdExpr2: return IdContentFromString(ctx.Context(), ctx.Token(node.GetAlt_an_id_expr2().GetToken1())); case TRule_an_id_expr::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -505,7 +504,7 @@ TString Id(const TRule_an_id_window& node, TTranslation& ctx) { case TRule_an_id_window::kAltAnIdWindow2: return IdContentFromString(ctx.Context(), ctx.Token(node.GetAlt_an_id_window2().GetToken1())); case TRule_an_id_window::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -517,7 +516,7 @@ TString Id(const TRule_an_id_without& node, TTranslation& ctx) { case TRule_an_id_without::kAltAnIdWithout2: return IdContentFromString(ctx.Context(), ctx.Token(node.GetAlt_an_id_without2().GetToken1())); case TRule_an_id_without::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -529,7 +528,7 @@ TString Id(const TRule_an_id_hint& node, TTranslation& ctx) { case TRule_an_id_hint::kAltAnIdHint2: return IdContentFromString(ctx.Context(), ctx.Token(node.GetAlt_an_id_hint2().GetToken1())); case TRule_an_id_hint::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -541,7 +540,7 @@ TString Id(const TRule_an_id_pure& node, TTranslation& ctx) { case TRule_an_id_pure::kAltAnIdPure2: return IdContentFromString(ctx.Context(), ctx.Token(node.GetAlt_an_id_pure2().GetToken1())); case TRule_an_id_pure::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -552,7 +551,7 @@ TViewDescription Id(const TRule_view_name& node, TTranslation& ctx) { case TRule_view_name::kAltViewName2: return {"", true}; case TRule_view_name::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -570,7 +569,7 @@ bool NamedNodeImpl(const TRule_bind_parameter& node, TString& name, TTranslation id = ctx.Token(node.GetBlock2().GetAlt3().GetToken1()); break; case TRule_bind_parameter::TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } auto dollar = ctx.Token(node.GetToken1()); if (id.empty()) { @@ -631,7 +630,7 @@ TDeferredAtom PureColumnOrNamed(const TRule_pure_column_or_named& node, TTransla case TRule_pure_column_or_named::kAltPureColumnOrNamed2: return TDeferredAtom(ctx.Context().Pos(), Id(node.GetAlt_pure_column_or_named2().GetRule_an_id1(), ctx)); case TRule_pure_column_or_named::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -671,7 +670,7 @@ bool TSqlTranslation::CreateTableIndex(const TRule_table_index& node, TVector<TI } else if (token == "async") { sync = false; } else { - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } if (sync) { @@ -693,7 +692,7 @@ bool TSqlTranslation::CreateTableIndex(const TRule_table_index& node, TVector<TI AltNotImplemented("local", indexType); return false; case TRule_table_index_type_TBlock1::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } if (node.GetRule_table_index_type3().HasBlock2()) { @@ -807,7 +806,7 @@ TNodePtr ParseDatabaseSettingValue(TContext& ctx, const TRule_database_setting_v return nullptr; } case TRule_database_setting_value::ALT_NOT_SET: - YQL_ENSURE(false, "You should change implementation according to grammar changes."); + Y_UNREACHABLE(); } } @@ -858,7 +857,7 @@ TString TSqlTranslation::GetIndexSettingStringValue(const TRule_index_setting_va case NSQLv1Generated::TRule_index_setting_value::kAltIndexSettingValue4: // bool_value return Token(node.GetAlt_index_setting_value4().GetRule_bool_value1().GetToken1()); case NSQLv1Generated::TRule_index_setting_value::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -1205,7 +1204,7 @@ bool TSqlTranslation::ClusterExpr(const TRule_cluster_expr& node, bool allowWild return true; } case TRule_cluster_expr::TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -1431,7 +1430,7 @@ bool TSqlTranslation::TableRefImpl(const TRule_table_ref& node, TTableRef& resul return true; } case TRule_table_ref::TBlock3::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } MergeHints(hints, tableHints); @@ -1549,9 +1548,8 @@ TMaybe<TColumnOptions> ColumnOptions(const TRule_column_schema& node, TTranslati break; } - case TRule_column_option_list::ALT_NOT_SET: { - Y_ABORT("You should change implementation according to grammar changes"); - } + case TRule_column_option_list::ALT_NOT_SET: + Y_UNREACHABLE(); } } @@ -1620,9 +1618,8 @@ TMaybe<TColumnOptions> ColumnOptions(const TRule_column_schema& node, TTranslati break; } - case TRule_column_option::ALT_NOT_SET: { - Y_ABORT("You should change implementation according to grammar changes"); - } + case TRule_column_option::ALT_NOT_SET: + Y_UNREACHABLE(); } } } @@ -1867,9 +1864,8 @@ bool TSqlTranslation::CreateTableEntry(const TRule_create_table_entry& node, TCr } break; } - default: - AltNotImplemented("table_constraint", constraint); - return false; + case NSQLv1Generated::TRule_table_constraint::ALT_NOT_SET: + Y_UNREACHABLE(); } break; } @@ -1916,9 +1912,8 @@ bool TSqlTranslation::CreateTableEntry(const TRule_create_table_entry& node, TCr params.Columns.push_back(TColumnSchema(pos, name, nullptr, true, {}, false, nullptr)); break; } - default: - AltNotImplemented("create_table_entry", node); - return false; + case NSQLv1Generated::TRule_create_table_entry::ALT_NOT_SET: + Y_UNREACHABLE(); } return true; } @@ -2113,7 +2108,7 @@ bool FillTierAction(const TRule_ttl_tier_action& from, std::optional<TIdentifier storageName.reset(); break; case TRule_ttl_tier_action::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return true; } @@ -2632,9 +2627,8 @@ bool TSqlTranslation::AlterTopicConsumerEntry( } return true; } - default: - Ctx_.Error() << "unknown alter consumer action"; - return false; + case NSQLv1Generated::TRule_alter_topic_alter_consumer_entry::ALT_NOT_SET: + Y_UNREACHABLE(); } return true; } @@ -2851,9 +2845,9 @@ bool TSqlTranslation::AlterTopicAction(const TRule_alter_topic_action& node, TAl } return true; } - default: - Ctx_.Error() << "unknown alter topic action"; - return false; + + case NSQLv1Generated::TRule_alter_topic_action::ALT_NOT_SET: + Y_UNREACHABLE(); } return true; } @@ -2904,7 +2898,7 @@ TNodePtr TSqlTranslation::IntegerOrBind(const TRule_integer_or_bind& node) { return atom.Build(); } case TRule_integer_or_bind::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -2938,7 +2932,7 @@ TNodePtr TSqlTranslation::TypeNameTag(const TRule_type_name_tag& node) { return atom.Build(); } case TRule_type_name_tag::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -3049,7 +3043,7 @@ TNodePtr TSqlTranslation::TypeNodeOrBind(const TRule_type_name_or_bind& node) { return GetNamedNode(bindName); } case TRule_type_name_or_bind::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -3078,7 +3072,7 @@ TNodePtr TSqlTranslation::TypeNode(const TRule_type_name& node) { break; } case TRule_type_name::TAlt2::TBlock1::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return AddOptionals(result, alt.GetBlock2().size()); @@ -3148,7 +3142,7 @@ TNodePtr TSqlTranslation::TypeNode(const TRule_type_name_composite& node) { case TRule_type_name_tuple::TBlock2::kAlt2: break; case TRule_type_name_tuple::TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } result = new TAstListNodeImpl(pos, items); @@ -3190,7 +3184,7 @@ TNodePtr TSqlTranslation::TypeNode(const TRule_type_name_composite& node) { case TRule_type_name_struct::TBlock2::kAlt2: break; case TRule_type_name_struct::TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } result = new TAstListNodeImpl(pos, items); @@ -3375,8 +3369,18 @@ TNodePtr TSqlTranslation::TypeNode(const TRule_type_name_composite& node) { result = new TAstListNodeImpl(pos, items); break; } + case TRule_type_name_composite_TBlock1::kAlt14: { + auto& linearType = block.GetAlt14().GetRule_type_name_linear1(); + result = wrapOneParamType(linearType.GetRule_type_name_or_bind3(), "LinearType"); + break; + } + case TRule_type_name_composite_TBlock1::kAlt15: { + auto& linearType = block.GetAlt15().GetRule_type_name_dynamiclinear1(); + result = wrapOneParamType(linearType.GetRule_type_name_or_bind3(), "DynamicLinearType"); + break; + } case TRule_type_name_composite_TBlock1::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return AddOptionals(result, node.GetBlock2().size()); @@ -3540,7 +3544,7 @@ bool TSqlTranslation::TableHintImpl(const TRule_table_hint& rule, TTableHints& h break; } case TRule_table_hint_TAlt1_TBlock2_TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } hints[id] = hint_val; @@ -3641,7 +3645,7 @@ bool TSqlTranslation::TableHintImpl(const TRule_table_hint& rule, TTableHints& h } case TRule_table_hint::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return true; @@ -3665,7 +3669,7 @@ TMaybe<TTableHints> TSqlTranslation::TableHintsImpl(const TRule_table_hints& nod break; } case TRule_table_hints::TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } if (hasErrors) { return Nothing(); @@ -3752,7 +3756,7 @@ bool TSqlTranslation::SimpleTableRefCoreImpl(const TRule_simple_table_ref_core& break; } case TRule_simple_table_ref_core::AltCase::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return result.Keys != nullptr; @@ -3815,9 +3819,7 @@ TNodePtr TSqlTranslation::NamedNode(const TRule_named_nodes_stmt& rule, TVector< } case TRule_named_nodes_stmt::TBlock3::ALT_NOT_SET: - AltNotImplemented("named_node", rule.GetBlock3()); - Ctx_.IncrementMonCounter("sql_errors", "UnknownNamedNode"); - return nullptr; + Y_UNREACHABLE(); } } @@ -3932,7 +3934,7 @@ bool TSqlTranslation::RoleNameClause(const TRule_role_name& node, TDeferredAtom& break; } case TRule_role_name::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } if (auto literalName = result.GetLiteral(); literalName && !allowSystemRoles) { @@ -3998,7 +4000,7 @@ void TSqlTranslation::LoginParameter(const TRule_login_option& loginOption, std: } else if (IS_TOKEN(Ctx_.Settings.Antlr4Parser, token, NOLOGIN)) { canLogin = false; } else { - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -4040,9 +4042,8 @@ bool TSqlTranslation::UserParameters(const std::vector<TRule_user_option>& optio break; } - case TRule_authentication_option::ALT_NOT_SET: { - Y_ABORT("You should change implementation according to grammar changes"); - } + case TRule_authentication_option::ALT_NOT_SET: + Y_UNREACHABLE(); } break; @@ -4059,9 +4060,8 @@ bool TSqlTranslation::UserParameters(const std::vector<TRule_user_option>& optio break; } - case TRule_user_option::ALT_NOT_SET: { - Y_ABORT("You should change implementation according to grammar changes"); - } + case TRule_user_option::ALT_NOT_SET: + Y_UNREACHABLE(); } return true; @@ -4179,7 +4179,7 @@ bool TSqlTranslation::PermissionNameClause(const TRule_permission_id& node, TDef break; } case TRule_permission_id::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return true; } @@ -4201,7 +4201,7 @@ bool TSqlTranslation::PermissionNameClause(const TRule_permission_name& node, TD break; } case TRule_permission_name::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return true; } @@ -4228,7 +4228,7 @@ bool TSqlTranslation::PermissionNameClause(const TRule_permission_name_target& n break; } case TRule_permission_name_target::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } if (withGrantOption) { result.emplace_back(Ctx_.Pos(), "grant"); @@ -4301,7 +4301,7 @@ bool TSqlTranslation::ParseBackupCollectionSettings(std::map<TString, TDeferredA return true; } case TRule_alter_backup_collection_action::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } }; @@ -4356,7 +4356,7 @@ bool TSqlTranslation::ParseBackupCollectionEntry( return true; } case TRule_alter_backup_collection_entry::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return true; } @@ -4394,7 +4394,7 @@ TString TSqlTranslation::FrameSettingsToString(EFrameSettings settings, bool isU case FrameFollowing: result = "FOLLOWING"; break; - default: + case FrameUndefined: Y_ABORT("Unexpected frame settings"); } @@ -4518,7 +4518,7 @@ bool TSqlTranslation::FrameBound(const TRule_window_frame_bound& rule, TFrameBou bound->Pos = GetPos(block.GetAlt2().GetToken1()); break; case TRule_window_frame_bound_TAlt2_TBlock1::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } const TString settingToken = to_lower(Token(rule.GetAlt_window_frame_bound2().GetToken2())); @@ -4527,12 +4527,12 @@ bool TSqlTranslation::FrameBound(const TRule_window_frame_bound& rule, TFrameBou } else if (settingToken == "following") { bound->Settings = FrameFollowing; } else { - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } break; } case TRule_window_frame_bound::ALT_NOT_SET: - Y_ABORT("FrameClause: frame bound not correspond to grammar changes"); + Y_UNREACHABLE(); } return true; } @@ -4577,7 +4577,7 @@ bool TSqlTranslation::FrameClause(const TRule_window_frame_clause& rule, TFrameS break; } case TRule_window_frame_extent::ALT_NOT_SET: - Y_ABORT("FrameClause: frame extent not correspond to grammar changes"); + Y_UNREACHABLE(); } YQL_ENSURE(frameSpec->FrameBegin); YQL_ENSURE(frameSpec->FrameEnd); @@ -4601,7 +4601,7 @@ bool TSqlTranslation::FrameClause(const TRule_window_frame_clause& rule, TFrameS frameSpec->FrameExclusion = FrameExclNone; break; case TRule_window_frame_exclusion::ALT_NOT_SET: - Y_ABORT("FrameClause: frame exclusion not correspond to grammar changes"); + Y_UNREACHABLE(); } } @@ -4747,9 +4747,7 @@ TNodePtr TSqlTranslation::DoStatement(const TRule_do_stmt& stmt, bool makeLambda action = BuildEmptyAction(Ctx_.Pos()); break; case TRule_call_action_TBlock1::ALT_NOT_SET: - Ctx_.IncrementMonCounter("sql_errors", "UnknownDoStmt"); - AltNotImplemented("do_stmt", callAction.GetBlock1()); - return nullptr; + Y_UNREACHABLE(); } TVector<TNodePtr> values; @@ -4816,7 +4814,7 @@ TNodePtr TSqlTranslation::DoStatement(const TRule_do_stmt& stmt, bool makeLambda return BuildLambda(Ctx_.Pos(), params, blockNode); } case TRule_do_stmt_TBlock2::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -4887,22 +4885,7 @@ bool TSqlTranslation::DefineActionOrSubqueryStatement(const TRule_define_action_ TBlocks innerBlocks; const bool hasValidBody = DefineActionOrSubqueryBody(query, innerBlocks, stmt.GetRule_define_action_or_subquery_body8()); - ui32 topLevelSelects = 0; - bool hasTailOps = false; - for (auto& block : innerBlocks) { - if (block->SubqueryAlias()) { - continue; - } - - if (block->HasSelectResult()) { - ++topLevelSelects; - } else if (topLevelSelects) { - hasTailOps = true; - } - } - - if (isSubquery && (topLevelSelects != 1 || hasTailOps)) { - Error() << "Strictly one select/process/reduce statement is expected at the end of subquery"; + if (isSubquery && !ValidateSubqueryOrViewBody(innerBlocks)) { return false; } @@ -5050,7 +5033,7 @@ bool TSqlTranslation::ObjectFeatureValueClause(const TRule_object_feature_value& break; } case TRule_object_feature_value::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } return true; } @@ -5167,7 +5150,7 @@ bool TSqlTranslation::ParseExternalDataSourceSettings(std::map<TString, TDeferre return true; } case TRule_alter_external_data_source_action::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -5372,6 +5355,30 @@ bool TSqlTranslation::ValidateExternalTable(const TCreateTableParameters& params return true; } +bool TSqlTranslation::ValidateSubqueryOrViewBody(const TBlocks& blocks) { + ui32 topLevelSelects = 0; + bool hasTailOps = false; + for (auto& block : blocks) { + if (block->SubqueryAlias()) { + continue; + } + + if (block->HasSelectResult()) { + ++topLevelSelects; + } else if (topLevelSelects) { + hasTailOps = true; + } + } + + if (topLevelSelects != 1 || hasTailOps) { + Error() << "Strictly one select/process/reduce statement is expected at the end of " + << (Mode_ == NSQLTranslation::ESqlMode::LIMITED_VIEW ? "view" : "subquery"); + return false; + } + + return true; +} + bool TSqlTranslation::ParseViewQuery( std::map<TString, TDeferredAtom>& features, const TRule_select_stmt& query) { @@ -5393,6 +5400,70 @@ bool TSqlTranslation::ParseViewQuery( return true; } +bool TSqlTranslation::ParseViewQuery( + std::map<TString, TDeferredAtom>& features, + const TRule_define_action_or_subquery_body& body, + const NSQLv1Generated::TToken& beforeToken, + const NSQLv1Generated::TToken& afterToken, + const TString& service, + const TDeferredAtom& cluster) +{ + if (!body.HasBlock2()) { + Error() << "Empty view body is not allowed"; + return false; + } + const auto saveScoped = Ctx_.Scoped; + const auto saveMode = Ctx_.Settings.Mode; + Ctx_.Scoped = Ctx_.CreateScopedState(); + Ctx_.AllScopes.push_back(Ctx_.Scoped); + Ctx_.Scoped->CurrCluster = cluster; + Ctx_.Scoped->CurrService = service; + Ctx_.Settings.Mode = ESqlMode::LIMITED_VIEW; + + Y_DEFER { + Ctx_.ScopeLevel--; + Ctx_.Scoped = saveScoped; + Ctx_.Settings.Mode = saveMode; + }; + + TSqlQuery query(Ctx_, Ctx_.Settings.Mode, /* topLevel */ false, /* allowTopLevelPragmas */ true); + TBlocks innerBlocks; + + TNodePtr clearWorldNode = new TAstListNodeImpl(Ctx_.Pos()); + clearWorldNode->Add("World"); + innerBlocks.push_back(clearWorldNode); + + if (!DefineActionOrSubqueryBody(query, innerBlocks, body)) { + return false; + } + + if (!ValidateSubqueryOrViewBody(innerBlocks)) { + return false; + } + + auto queryNode = BuildQuery(Ctx_.Pos(), innerBlocks, false, Ctx_.Scoped, Ctx_.SeqMode); + if (!queryNode) { + return false; + } + + if (!WarnUnusedNodes()) { + return false; + } + + TNodePtr blockNode = new TAstListNodeImpl(Ctx_.Pos()); + blockNode->Add("block", blockNode->Q(queryNode)); + features[TStreamingQuerySettings::QUERY_AST_FEATURE] = TDeferredAtom(blockNode, Ctx_); + + auto begin = GetQueryPosition(Ctx_.Query, beforeToken, Ctx_.Settings.Antlr4Parser); + auto end = GetQueryPosition(Ctx_.Query, afterToken, Ctx_.Settings.Antlr4Parser); + YQL_ENSURE(begin < Ctx_.Query.size() && end < Ctx_.Query.size()); + begin += beforeToken.value().size(); + YQL_ENSURE(begin < end); + features[TStreamingQuerySettings::QUERY_TEXT_FEATURE] = TDeferredAtom(Ctx_.Pos(), Ctx_.Query.substr(begin, end - begin)); + + return true; +} + namespace { static TString GetLambdaText(TTranslation& ctx, TContext& Ctx, const TRule_lambda_or_parameter& lambdaOrParameter) { @@ -5423,7 +5494,7 @@ static TString GetLambdaText(TTranslation& ctx, TContext& Ctx, const TRule_lambd endToken = &lambda.GetBlock2().GetBlock2().GetAlt2().GetToken3(); break; case TRule_lambda_TBlock2_TBlock2::AltCase::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } auto begin = GetQueryPosition(Ctx.Query, beginToken, Ctx.Settings.Antlr4Parser); @@ -5443,7 +5514,7 @@ static TString GetLambdaText(TTranslation& ctx, TContext& Ctx, const TRule_lambd return result; } case NSQLv1Generated::TRule_lambda_or_parameter::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -5612,7 +5683,7 @@ bool TSqlTranslation::ParseResourcePoolSettings(std::map<TString, TDeferredAtom> return true; } case TRule_alter_resource_pool_action::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -5683,7 +5754,7 @@ bool TSqlTranslation::ParseResourcePoolClassifierSettings(std::map<TString, TDef return true; } case TRule_alter_resource_pool_classifier_action::ALT_NOT_SET: - Y_ABORT("You should change implementation according to grammar changes"); + Y_UNREACHABLE(); } } @@ -5743,10 +5814,8 @@ bool TSqlTranslation::ParseStreamingQuerySetting(const TRule_streaming_query_set FromString<bool>(Ctx_.Token(valueNode.GetAlt_streaming_query_setting_value3().GetRule_bool_value1().GetToken1()))), Ctx_); break; } - case TRule_streaming_query_setting_value::ALT_NOT_SET: { - Y_ABORT("You should change implementation according to grammar changes"); - return false; - } + case TRule_streaming_query_setting_value::ALT_NOT_SET: + Y_UNREACHABLE(); } return true; @@ -5862,10 +5931,8 @@ bool TSqlTranslation::ParseAlterStreamingQueryAction(const TRule_alter_streaming break; } - case TRule_alter_streaming_query_action::ALT_NOT_SET: { - Y_ABORT("You should change implementation according to grammar changes"); - return false; - } + case TRule_alter_streaming_query_action::ALT_NOT_SET: + Y_UNREACHABLE(); } return true; diff --git a/yql/essentials/sql/v1/sql_translation.h b/yql/essentials/sql/v1/sql_translation.h index 5c56b2537f0..a5c2401ed3a 100644 --- a/yql/essentials/sql/v1/sql_translation.h +++ b/yql/essentials/sql/v1/sql_translation.h @@ -1,6 +1,6 @@ #pragma once #include "context.h" -#include <yql/essentials/parser/proto_ast/gen/v1_proto_split/SQLv1Parser.pb.main.h> +#include <yql/essentials/parser/proto_ast/gen/v1_proto_split_antlr4/SQLv1Antlr4Parser.pb.main.h> #include <library/cpp/charset/ci_string.h> namespace NSQLTranslationV1 { @@ -247,6 +247,12 @@ protected: [[nodiscard]] bool ParseSecretId(const TRule_id_or_at& node, TString& objectId); bool ParseViewOptions(std::map<TString, TDeferredAtom>& features, const TRule_with_table_settings& options); bool ParseViewQuery(std::map<TString, TDeferredAtom>& features, const TRule_select_stmt& query); + bool ParseViewQuery(std::map<TString, TDeferredAtom>& features, + const TRule_define_action_or_subquery_body& body, + const NSQLv1Generated::TToken& beforeToken, + const NSQLv1Generated::TToken& afterToken, + const TString& service, + const TDeferredAtom& cluster); bool ParseResourcePoolSettings(std::map<TString, TDeferredAtom>& result, const TRule_with_table_settings& settings); bool ParseResourcePoolSettings(std::map<TString, TDeferredAtom>& result, std::set<TString>& toReset, const TRule_alter_resource_pool_action& alterAction); bool ParseResourcePoolClassifierSettings(std::map<TString, TDeferredAtom>& result, const TRule_with_table_settings& settings); @@ -288,6 +294,7 @@ protected: bool ValidateAuthMethod(const std::map<TString, TDeferredAtom>& result); bool ValidateExternalTable(const TCreateTableParameters& params); + bool ValidateSubqueryOrViewBody(const TBlocks& blocks); TNodePtr ReturningList(const ::NSQLv1Generated::TRule_returning_columns_list& columns); diff --git a/yql/essentials/sql/v1/sql_ut.cpp b/yql/essentials/sql/v1/sql_ut.cpp deleted file mode 100644 index 8abf46bbb02..00000000000 --- a/yql/essentials/sql/v1/sql_ut.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include "sql_ut.h" -#include "sql_translation.h" -#include "format/sql_format.h" -#include "lexer/lexer.h" - -#include <yql/essentials/providers/common/provider/yql_provider_names.h> -#include <yql/essentials/sql/sql.h> -#include <yql/essentials/sql/v1/lexer/antlr3/lexer.h> -#include <util/generic/map.h> - -#include <library/cpp/testing/unittest/registar.h> - -#include <util/string/split.h> - -#include <format> - -using namespace NSQLTranslation; - -namespace { - -TParsedTokenList Tokenize(const TString& query) { - NSQLTranslationV1::TLexers lexers; - lexers.Antlr3 = NSQLTranslationV1::MakeAntlr3LexerFactory(); - auto lexer = NSQLTranslationV1::MakeLexer(lexers, false, false); - TParsedTokenList tokens; - NYql::TIssues issues; - UNIT_ASSERT_C(Tokenize(*lexer, query, "Query", tokens, issues, SQL_MAX_PARSER_ERRORS), - issues.ToString()); - - return tokens; -} - -} // namespace - -#define ANTLR_VER 3 -#include "sql_ut_common.h" - -Y_UNIT_TEST_SUITE(QuerySplit) { -Y_UNIT_TEST(Simple) { - TString query = R"( - ; - -- Comment 1 - SELECT * From Input; -- Comment 2 - -- Comment 3 - $a = "a"; - - -- Comment 9 - ; - - -- Comment 10 - - -- Comment 8 - - $b = ($x) -> { - -- comment 4 - return /* Comment 5 */ $x; - -- Comment 6 - }; - - // Comment 7 - - - - )"; - - google::protobuf::Arena Arena; - - NSQLTranslation::TTranslationSettings settings; - settings.AnsiLexer = false; - settings.Antlr4Parser = false; - settings.Arena = &Arena; - - TVector<TString> statements; - NYql::TIssues issues; - - NSQLTranslationV1::TLexers lexers; - lexers.Antlr3 = NSQLTranslationV1::MakeAntlr3LexerFactory(); - NSQLTranslationV1::TParsers parsers; - parsers.Antlr3 = NSQLTranslationV1::MakeAntlr3ParserFactory(); - - UNIT_ASSERT(NSQLTranslationV1::SplitQueryToStatements(lexers, parsers, query, statements, issues, settings)); - - UNIT_ASSERT_VALUES_EQUAL(statements.size(), 3); - - UNIT_ASSERT_VALUES_EQUAL(statements[0], "-- Comment 1\n SELECT * From Input; -- Comment 2\n"); - UNIT_ASSERT_VALUES_EQUAL(statements[1], R"(-- Comment 3 - $a = "a";)"); - UNIT_ASSERT_VALUES_EQUAL(statements[2], R"(-- Comment 10 - - -- Comment 8 - - $b = ($x) -> { - -- comment 4 - return /* Comment 5 */ $x; - -- Comment 6 - };)"); -} -} // Y_UNIT_TEST_SUITE(QuerySplit) diff --git a/yql/essentials/sql/v1/sql_ut.h b/yql/essentials/sql/v1/sql_ut.h deleted file mode 100644 index feb2403e39d..00000000000 --- a/yql/essentials/sql/v1/sql_ut.h +++ /dev/null @@ -1,254 +0,0 @@ -#pragma once - -#include <yql/essentials/providers/common/provider/yql_provider_names.h> -#include <yql/essentials/sql/sql.h> -#include <yql/essentials/sql/v1/sql.h> -#include <yql/essentials/sql/v1/lexer/antlr3/lexer.h> -#include <yql/essentials/sql/v1/lexer/antlr3_ansi/lexer.h> -#include <yql/essentials/sql/v1/proto_parser/antlr3/proto_parser.h> -#include <yql/essentials/sql/v1/proto_parser/antlr3_ansi/proto_parser.h> -#include <util/generic/map.h> - -#include <library/cpp/regex/pcre/pcre.h> -#include <library/cpp/testing/unittest/registar.h> - -#include <util/string/split.h> -#include <deque> -#include <unordered_set> -using namespace NSQLTranslation; - -enum class EDebugOutput { - None, - ToCerr, -}; - -const ui32 PRETTY_FLAGS = NYql::TAstPrintFlags::PerLine | NYql::TAstPrintFlags::ShortQuote | - NYql::TAstPrintFlags::AdaptArbitraryContent; - -inline TString Err2Str(const NYql::TAstParseResult& res, EDebugOutput debug = EDebugOutput::None) { - TStringStream s; - res.Issues.PrintTo(s); - - if (debug == EDebugOutput::ToCerr) { - Cerr << s.Str() << Endl; - } - return s.Str(); -} - -inline NYql::TAstParseResult SqlToYqlWithMode(const TString& query, NSQLTranslation::ESqlMode mode = NSQLTranslation::ESqlMode::QUERY, size_t maxErrors = 10, const TString& provider = {}, - EDebugOutput debug = EDebugOutput::None, bool ansiLexer = false, NSQLTranslation::TTranslationSettings settings = {}) -{ - google::protobuf::Arena arena; - const auto service = provider ? provider : TString(NYql::YtProviderName); - const TString cluster = "plato"; - settings.ClusterMapping[cluster] = service; - settings.ClusterMapping["hahn"] = NYql::YtProviderName; - settings.ClusterMapping["mon"] = NYql::SolomonProviderName; - settings.MaxErrors = maxErrors; - settings.Mode = mode; - settings.Arena = &arena; - settings.AnsiLexer = ansiLexer; - settings.Antlr4Parser = false; - settings.SyntaxVersion = 1; - - NSQLTranslationV1::TLexers lexers; - lexers.Antlr3 = NSQLTranslationV1::MakeAntlr3LexerFactory(); - lexers.Antlr3Ansi = NSQLTranslationV1::MakeAntlr3AnsiLexerFactory(); - NSQLTranslationV1::TParsers parsers; - parsers.Antlr3 = NSQLTranslationV1::MakeAntlr3ParserFactory(); - parsers.Antlr3Ansi = NSQLTranslationV1::MakeAntlr3AnsiParserFactory(); - - NSQLTranslation::TTranslators translators( - nullptr, - NSQLTranslationV1::MakeTranslator(lexers, parsers), - nullptr); - - auto res = SqlToYql(translators, query, settings); - if (debug == EDebugOutput::ToCerr) { - Err2Str(res, debug); - } - return res; -} - -inline NYql::TAstParseResult SqlToYql(const TString& query, size_t maxErrors = 10, const TString& provider = {}, EDebugOutput debug = EDebugOutput::None) { - return SqlToYqlWithMode(query, NSQLTranslation::ESqlMode::QUERY, maxErrors, provider, debug); -} - -inline NYql::TAstParseResult -SqlToYqlWithSettings(const TString& query, const NSQLTranslation::TTranslationSettings& settings) { - return SqlToYqlWithMode(query, NSQLTranslation::ESqlMode::QUERY, 10, {}, EDebugOutput::None, false, settings); -} - -inline void ExpectFailWithError(const TString& query, const TString& error) { - NYql::TAstParseResult res = SqlToYql(query); - - UNIT_ASSERT(!res.Root); - UNIT_ASSERT_NO_DIFF(Err2Str(res), error); -} - -inline void ExpectFailWithFuzzyError(const TString& query, const TString& errorRegex) { - NYql::TAstParseResult res = SqlToYql(query); - - UNIT_ASSERT(!res.Root); - UNIT_ASSERT(NPcre::TPcre<char>(errorRegex.c_str()).Matches(Err2Str(res))); -} - -inline NYql::TAstParseResult SqlToYqlWithAnsiLexer(const TString& query, size_t maxErrors = 10, const TString& provider = {}, EDebugOutput debug = EDebugOutput::None) { - bool ansiLexer = true; - return SqlToYqlWithMode(query, NSQLTranslation::ESqlMode::QUERY, maxErrors, provider, debug, ansiLexer); -} - -inline void ExpectFailWithErrorForAnsiLexer(const TString& query, const TString& error) { - NYql::TAstParseResult res = SqlToYqlWithAnsiLexer(query); - - UNIT_ASSERT(!res.Root); - UNIT_ASSERT_NO_DIFF(Err2Str(res), error); -} - -inline TString GetPrettyPrint(const NYql::TAstParseResult& res) { - TStringStream yqlProgram; - res.Root->PrettyPrintTo(yqlProgram, NYql::TAstPrintFlags::PerLine | NYql::TAstPrintFlags::ShortQuote); - return yqlProgram.Str(); -} - -inline TString Quote(const char* str) { - return TStringBuilder() << "'\"" << str << "\""; -} - -class TWordCountHive: public TMap<TString, unsigned> { -public: - TWordCountHive(std::initializer_list<TString> strings) { - for (auto& str : strings) { - emplace(str, 0); - } - } - - TWordCountHive(std::initializer_list<std::pair<const TString, unsigned>> list) - : TMap(list) - { - } -}; - -typedef std::function<void(const TString& word, const TString& line)> TVerifyLineFunc; - -inline TString VerifyProgram(const NYql::TAstParseResult& res, TWordCountHive& wordCounter, TVerifyLineFunc verifyLine = TVerifyLineFunc()) { - const auto program = GetPrettyPrint(res); - TVector<TString> yqlProgram; - Split(program, "\n", yqlProgram); - for (const auto& line : yqlProgram) { - for (auto& counterIter : wordCounter) { - const auto& word = counterIter.first; - auto pos = line.find(word); - while (pos != TString::npos) { - ++counterIter.second; - if (verifyLine) { - verifyLine(word, line); - } - pos = line.find(word, pos + word.length()); - } - } - } - return program; -} - -inline void VerifySqlInHints(const TString& query, const THashSet<TString>& expectedHints, TMaybe<bool> ansi) { - TString pragma; - if (ansi.Defined()) { - pragma = *ansi ? "PRAGMA AnsiInForEmptyOrNullableItemsCollections;" : "PRAGMA DisableAnsiInForEmptyOrNullableItemsCollections;"; - } - - NYql::TAstParseResult res = SqlToYql(pragma + query); - UNIT_ASSERT(res.Root); - - TVerifyLineFunc verifyLine = [&](const TString& word, const TString& line) { - Y_UNUSED(word); - if (!ansi.Defined()) { - UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("'('warnNoAnsi)")); - } else if (*ansi) { - UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find("'('ansi)")); - } - for (auto& hint : expectedHints) { - UNIT_ASSERT_VALUES_UNEQUAL(TString::npos, line.find(hint)); - } - }; - TWordCountHive elementStat = {{TString("SqlIn"), 0}}; - VerifyProgram(res, elementStat, verifyLine); -} - -inline void VerifySqlInHints(const TString& query, const THashSet<TString>& expectedHints) { - VerifySqlInHints(query, expectedHints, false); - VerifySqlInHints(query, expectedHints, true); -} - -inline NSQLTranslation::TTranslationSettings GetSettingsWithS3Binding(const TString& name) { - NSQLTranslation::TTranslationSettings settings; - NSQLTranslation::TTableBindingSettings bindSettings; - bindSettings.ClusterType = "s3"; - bindSettings.Settings["cluster"] = "cluster"; - bindSettings.Settings["path"] = "path"; - bindSettings.Settings["format"] = "format"; - bindSettings.Settings["compression"] = "ccompression"; - bindSettings.Settings["bar"] = "1"; - // schema is not validated in this test but should be valid YSON text - bindSettings.Settings["schema"] = R"__("[ - "StructType"; - [ - [ - "key"; - [ - "DataType"; - "String" - ] - ]; - [ - "subkey"; - [ - "DataType"; - "String" - ] - ]; - [ - "value"; - [ - "DataType"; - "String" - ] - ] - ]])__"; - bindSettings.Settings["partitioned_by"] = "[\"key\", \"subkey\"]"; - settings.Bindings[name] = bindSettings; - return settings; -} - -inline void AstBfs(NYql::TAstNode const* root, std::function<bool(NYql::TAstNode const*)> visitor) { - std::deque<NYql::TAstNode const*> wishList{root}; - std::unordered_set<NYql::TAstNode const*> visited; - while (!wishList.empty()) { - auto v = wishList.front(); - wishList.pop_front(); - if (!visitor(v)) { - return; - } - visited.insert(v); - if (v->IsList()) { - for (ui32 i = 0; i != v->GetChildrenCount(); ++i) { - auto child = v->GetChild(i); - if (visited.find(child) == visited.cend()) { - wishList.push_back(child); - } - } - } - } -} - -inline const NYql::TAstNode* FindNodeByChildAtomContent(const NYql::TAstNode* root, uint32_t childIndex, TStringBuf name) { - const NYql::TAstNode* result = nullptr; - AstBfs(root, [&result, childIndex, name](auto v) { - if (v->IsList() && v->GetChildrenCount() > childIndex && - v->GetChild(childIndex)->IsAtom() && v->GetChild(childIndex)->GetContent() == name) { - result = v; - return false; - } - return true; }); - return result; -} diff --git a/yql/essentials/sql/v1/sql_ut_antlr4.h b/yql/essentials/sql/v1/sql_ut_antlr4.h index 5bfee9a8913..ccc80e88fe9 100644 --- a/yql/essentials/sql/v1/sql_ut_antlr4.h +++ b/yql/essentials/sql/v1/sql_ut_antlr4.h @@ -44,6 +44,8 @@ inline NYql::TAstParseResult SqlToYqlWithMode(const TString& query, NSQLTranslat settings.ClusterMapping[cluster] = service; settings.ClusterMapping["hahn"] = NYql::YtProviderName; settings.ClusterMapping["mon"] = NYql::SolomonProviderName; + settings.ClusterMapping["rtmr"] = NYql::RtmrProviderName; + settings.ClusterMapping["ydb"] = NYql::YdbProviderName; settings.MaxErrors = maxErrors; settings.Mode = mode; settings.Arena = &arena; diff --git a/yql/essentials/sql/v1/sql_ut_common.h b/yql/essentials/sql/v1/sql_ut_common.h index 30f01e1c061..51246f468ea 100644 --- a/yql/essentials/sql/v1/sql_ut_common.h +++ b/yql/essentials/sql/v1/sql_ut_common.h @@ -4255,6 +4255,13 @@ Y_UNIT_TEST(AutoSampleWorksWithSubquery) { UNIT_ASSERT(SqlToYql("select * from (select * from plato.Input) sample 0.2").IsOk()); } +Y_UNIT_TEST(LinearAsColumnOrType) { + UNIT_ASSERT(SqlToYql("select FormatType(Linear<Int32>)").IsOk()); + UNIT_ASSERT(SqlToYql("select Linear<2 from (select 1 as Linear)").IsOk()); + UNIT_ASSERT(SqlToYql("select FormatType(DynamicLinear<Int32>)").IsOk()); + UNIT_ASSERT(SqlToYql("select DynamicLinear<2 from (select 1 as DynamicLinear)").IsOk()); +} + Y_UNIT_TEST(CreateTableTrailingComma) { UNIT_ASSERT(SqlToYql("USE plato; CREATE TABLE tableName (Key Uint32, PRIMARY KEY (Key),);").IsOk()); UNIT_ASSERT(SqlToYql("USE plato; CREATE TABLE tableName (Key Uint32,);").IsOk()); @@ -8623,7 +8630,7 @@ Y_UNIT_TEST(UnknownSetting) { Y_UNIT_TEST_SUITE(TViewSyntaxTest) { Y_UNIT_TEST(CreateViewSimple) { NYql::TAstParseResult res = SqlToYql(R"( - USE plato; + USE ydb; CREATE VIEW TheView WITH (security_invoker = TRUE) AS SELECT 1; )"); UNIT_ASSERT_C(res.Root, res.Issues.ToString()); @@ -8631,7 +8638,7 @@ Y_UNIT_TEST(CreateViewSimple) { Y_UNIT_TEST(CreateViewWithUdfs) { NYql::TAstParseResult res = SqlToYql(R"( - USE plato; + USE ydb; CREATE VIEW TheView WITH (security_invoker = TRUE) AS SELECT "bbb" LIKE Unwrap("aaa"); )"); UNIT_ASSERT_C(res.Root, res.Issues.ToString()); @@ -8640,7 +8647,7 @@ Y_UNIT_TEST(CreateViewWithUdfs) { Y_UNIT_TEST(CreateViewIfNotExists) { constexpr const char* name = "TheView"; NYql::TAstParseResult res = SqlToYql(std::format(R"( - USE plato; + USE ydb; CREATE VIEW IF NOT EXISTS {} AS SELECT 1; )", name)); UNIT_ASSERT_C(res.Root, res.Issues.ToString()); @@ -8665,7 +8672,7 @@ Y_UNIT_TEST(CreateViewFromTable) { )"; NYql::TAstParseResult res = SqlToYql(std::format(R"( - USE plato; + USE ydb; CREATE VIEW `{}` WITH (security_invoker = TRUE) AS {}; )", path, @@ -8691,7 +8698,7 @@ Y_UNIT_TEST(CheckReconstructedQuery) { )"; NYql::TAstParseResult res = SqlToYql(std::format(R"( - USE plato; + USE ydb; CREATE VIEW `{}` WITH (security_invoker = TRUE) AS {}; )", path, @@ -8713,7 +8720,7 @@ Y_UNIT_TEST(CheckReconstructedQuery) { Y_UNIT_TEST(DropView) { constexpr const char* path = "/PathPrefix/TheView"; NYql::TAstParseResult res = SqlToYql(std::format(R"( - USE plato; + USE ydb; DROP VIEW `{}`; )", path)); @@ -8734,7 +8741,7 @@ Y_UNIT_TEST(DropView) { Y_UNIT_TEST(DropViewIfExists) { constexpr const char* name = "TheView"; NYql::TAstParseResult res = SqlToYql(std::format(R"( - USE plato; + USE ydb; DROP VIEW IF EXISTS {}; )", name)); UNIT_ASSERT_C(res.Root, res.Issues.ToString()); @@ -8754,7 +8761,7 @@ Y_UNIT_TEST(DropViewIfExists) { Y_UNIT_TEST(CreateViewWithTablePrefix) { NYql::TAstParseResult res = SqlToYql(R"( - USE plato; + USE ydb; PRAGMA TablePathPrefix='/PathPrefix'; CREATE VIEW TheView WITH (security_invoker = TRUE) AS SELECT 1; )"); @@ -8775,7 +8782,7 @@ Y_UNIT_TEST(CreateViewWithTablePrefix) { Y_UNIT_TEST(DropViewWithTablePrefix) { NYql::TAstParseResult res = SqlToYql(R"( - USE plato; + USE ydb; PRAGMA TablePathPrefix='/PathPrefix'; DROP VIEW TheView; )"); @@ -9630,7 +9637,6 @@ Y_UNIT_TEST(Lambda) { const auto programm = GetPrettyPrint(res); - Cerr << ">>>>> Root " << programm << Endl; auto expected = R"('transformLambda 'use plato; -- befor comment $a = "А"; @@ -10804,3 +10810,84 @@ Y_UNIT_TEST(FromValues) { } } // Y_UNIT_TEST_SUITE(YqlSelect) + +Y_UNIT_TEST_SUITE(CreateViewNewSyntax) { + +Y_UNIT_TEST(Basic) { + NYql::TAstParseResult res = SqlToYql(R"sql( + CREATE VIEW plato.foo AS + DO BEGIN $foo = 1; select /* some hint */ $foo + 123; END DO; + )sql"); + UNIT_ASSERT_C(res.IsOk(), res.Issues.ToOneLineString()); + + TWordCountHive stat = { + {TString("__query_text"), 0}, + {TString("__query_ast"), 0}, + }; + VerifyProgram(res, stat, [](const TString& word, const TString& line) { + if (word == "__query_text") { + UNIT_ASSERT_STRING_CONTAINS(line, " $foo = 1; select /* some hint */ $foo + 123; "); + } + }); + UNIT_ASSERT_VALUES_EQUAL(stat["__query_text"], 1); + UNIT_ASSERT_VALUES_EQUAL(stat["__query_ast"], 1); +} + +Y_UNIT_TEST(NamedNodesAreNotVisibleInView) { + auto query = R"sql( + $foo = 1; + CREATE VIEW plato.foo AS + DO BEGIN + $bar = 2; + select $bar + $foo; + END DO; + )sql"; + + ExpectFailWithError(query, "<main>:6:27: Error: Unknown name: $foo\n"); +} + +Y_UNIT_TEST(ScopedPragmasDoNotAffectView) { + NYql::TAstParseResult res = SqlToYql(R"sql( + pragma CheckedOps = 'true'; + CREATE VIEW plato.foo AS + DO BEGIN + select 1 + 1; + END DO; + )sql"); + + TWordCountHive stat = { + {TString("+MayWarn"), 0}, + {TString("CheckedAdd"), 0}, + }; + VerifyProgram(res, stat); + UNIT_ASSERT_VALUES_EQUAL(stat["+MayWarn"], 1); + UNIT_ASSERT_VALUES_EQUAL(stat["CheckedAdd"], 0); +} + +Y_UNIT_TEST(NewSyntaxDoesntWorkOnYdb) { + ExpectFailWithError("create view ydb.foo as do begin select 1; end do", + "<main>:1:13: Error: CREATE VIEW ... AS DO BEGIN ... END DO syntax is not supported for ydb provider. Please use CREATE VIEW ... AS SELECT\n"); +} + +Y_UNIT_TEST(OldSyntaxDoesntWorkOnYt) { + ExpectFailWithError("create view plato.foo as select 1;", + "<main>:1:13: Error: CREATE VIEW ... AS SELECT syntax is not supported for yt provider. Please use CREATE VIEW ... AS DO BEGIN ... END DO\n"); +} + +Y_UNIT_TEST(EmptyViewBody) { + ExpectFailWithError("create view plato.foo as do begin end do", "<main>:1:13: Error: Empty view body is not allowed\n"); + ExpectFailWithError("create view plato.foo as do begin /*comment*/;; end do", "<main>:1:13: Error: Empty view body is not allowed\n"); +} + +Y_UNIT_TEST(MultiSelectsInViewOrStatementAfterSelect) { + ExpectFailWithError("create view plato.foo as do begin select 1; select 2; end do", + "<main>:1:52: Error: Strictly one select/process/reduce statement is expected at the end of subquery\n"); + ExpectFailWithError("create view plato.foo as do begin select 1; $foo = 2; end do", + "<main>:1:54: Error: Strictly one select/process/reduce statement is expected at the end of subquery\n"); +} + +Y_UNIT_TEST(ErrorOnMissingCluster) { + ExpectFailWithError("create view foo as do begin select 1; end do", "<main>:1:1: Error: No cluster name given and no default cluster is selected\n"); +} + +} // Y_UNIT_TEST_SUITE(CreateViewNewSyntax) diff --git a/yql/essentials/sql/v1/sql_values.cpp b/yql/essentials/sql/v1/sql_values.cpp index db4baacab29..1572c2314eb 100644 --- a/yql/essentials/sql/v1/sql_values.cpp +++ b/yql/essentials/sql/v1/sql_values.cpp @@ -110,10 +110,8 @@ TSourcePtr TSqlValues::ValuesSource(const TRule_values_source& node, const TVect } return BuildWriteValues(pos, "UPDATE", columnsHint, std::move(source)); } - default: - Ctx_.IncrementMonCounter("sql_errors", "UnknownValuesSource"); - AltNotImplemented("values_source", node); - return nullptr; + case NSQLv1Generated::TRule_values_source::ALT_NOT_SET: + Y_UNREACHABLE(); } } @@ -127,10 +125,12 @@ TSourcePtr TSqlIntoValues::Build(const TRule_into_values_source& node, const TSt } return ValuesSource(alt.GetRule_values_source2(), columnsHint, operationName); } - default: + case NSQLv1Generated::TRule_into_values_source::kAltIntoValuesSource2: Ctx_.IncrementMonCounter("sql_errors", "DefaultValuesOrOther"); AltNotImplemented("into_values_source", node); return nullptr; + case NSQLv1Generated::TRule_into_values_source::ALT_NOT_SET: + Y_UNREACHABLE(); } } @@ -144,10 +144,8 @@ TSourcePtr TSqlAsValues::Build(const TRule_values_source& node, const TString& o case TRule_values_source::kAltValuesSource2: { return ValuesSource(node, {}, operationName); } - default: - Ctx_.IncrementMonCounter("sql_errors", "UnknownValuesSource"); - AltNotImplemented("values_source", node); - return nullptr; + case NSQLv1Generated::TRule_values_source::ALT_NOT_SET: + Y_UNREACHABLE(); } } diff --git a/yql/essentials/sql/v1/sql_values.h b/yql/essentials/sql/v1/sql_values.h index eaf5529cd63..0e55072fd23 100644 --- a/yql/essentials/sql/v1/sql_values.h +++ b/yql/essentials/sql/v1/sql_values.h @@ -1,7 +1,7 @@ #pragma once #include "sql_translation.h" -#include <yql/essentials/parser/proto_ast/gen/v1_proto_split/SQLv1Parser.pb.main.h> +#include <yql/essentials/parser/proto_ast/gen/v1_proto_split_antlr4/SQLv1Antlr4Parser.pb.main.h> namespace NSQLTranslationV1 { diff --git a/yql/essentials/sql/v1/ut/ya.make b/yql/essentials/sql/v1/ut/ya.make deleted file mode 100644 index 7bb6f3d44bd..00000000000 --- a/yql/essentials/sql/v1/ut/ya.make +++ /dev/null @@ -1,25 +0,0 @@ -UNITTEST_FOR(yql/essentials/sql/v1) - -SRCS( - sql_ut.cpp - sql_match_recognize_ut.cpp -) - -PEERDIR( - library/cpp/regex/pcre - yql/essentials/public/udf/service/exception_policy - yql/essentials/core/sql_types - yql/essentials/sql - yql/essentials/sql/pg_dummy - yql/essentials/sql/v1/format - yql/essentials/sql/v1/lexer/antlr3 - yql/essentials/sql/v1/lexer/antlr3_ansi - yql/essentials/sql/v1/proto_parser/antlr3 - yql/essentials/sql/v1/proto_parser/antlr3_ansi -) - -TIMEOUT(300) - -SIZE(MEDIUM) - -END() diff --git a/yql/essentials/sql/v1/ut_antlr4/ya.make b/yql/essentials/sql/v1/ut_antlr4/ya.make index ab7d04eea71..5a6ebedcc8f 100644 --- a/yql/essentials/sql/v1/ut_antlr4/ya.make +++ b/yql/essentials/sql/v1/ut_antlr4/ya.make @@ -16,12 +16,6 @@ PEERDIR( yql/essentials/sql/v1/lexer/antlr4_ansi yql/essentials/sql/v1/proto_parser/antlr4 yql/essentials/sql/v1/proto_parser/antlr4_ansi - - #FIXME - switch sql_match_recognize_ut.cpp to antlr4 - yql/essentials/sql/v1/lexer/antlr3 - yql/essentials/sql/v1/lexer/antlr3_ansi - yql/essentials/sql/v1/proto_parser/antlr3 - yql/essentials/sql/v1/proto_parser/antlr3_ansi ) TIMEOUT(300) diff --git a/yql/essentials/sql/v1/ya.make b/yql/essentials/sql/v1/ya.make index 1c26bcede72..db84752407c 100644 --- a/yql/essentials/sql/v1/ya.make +++ b/yql/essentials/sql/v1/ya.make @@ -13,12 +13,11 @@ PEERDIR( yql/essentials/core/sql_types yql/essentials/parser/lexer_common yql/essentials/parser/proto_ast/collect_issues - yql/essentials/parser/proto_ast/gen/v1_proto_split + yql/essentials/parser/proto_ast/gen/v1_proto_split_antlr4 yql/essentials/parser/pg_catalog yql/essentials/sql/v1/lexer yql/essentials/sql/v1/proto_parser # for lexer tokens - yql/essentials/parser/proto_ast/gen/v1 yql/essentials/parser/proto_ast/gen/v1_antlr4 ) @@ -68,6 +67,5 @@ RECURSE( ) RECURSE_FOR_TESTS( - ut ut_antlr4 ) |