From 51be1d4a3a19eb0c30398efc35b5a209fe99d75b Mon Sep 17 00:00:00 2001 From: gvozdvmozgu Date: Fri, 26 Dec 2025 18:44:34 -0800 Subject: [PATCH 01/12] feat(dialects): update dialect definitions --- crates/lib-core/src/dialects/init.rs | 1 + crates/lib-dialects/src/ansi.rs | 7280 +++--- crates/lib-dialects/src/ansi_keywords.rs | 2 - crates/lib-dialects/src/athena.rs | 824 +- crates/lib-dialects/src/athena_keywords.rs | 4 +- crates/lib-dialects/src/bigquery.rs | 5032 ++-- crates/lib-dialects/src/bigquery_keywords.rs | 36 +- crates/lib-dialects/src/clickhouse.rs | 3665 +-- .../lib-dialects/src/clickhouse_keywords.rs | 169 +- crates/lib-dialects/src/databricks.rs | 2765 ++- .../lib-dialects/src/databricks_keywords.rs | 8 +- crates/lib-dialects/src/duckdb.rs | 1839 +- crates/lib-dialects/src/hive.rs | 1811 +- crates/lib-dialects/src/hive_keywords.rs | 340 + crates/lib-dialects/src/lib.rs | 6 + crates/lib-dialects/src/mysql.rs | 1198 +- crates/lib-dialects/src/mysql_keywords.rs | 782 + crates/lib-dialects/src/postgres.rs | 15509 +++++++----- crates/lib-dialects/src/postgres_keywords.rs | 37 +- crates/lib-dialects/src/redshift.rs | 2188 +- crates/lib-dialects/src/redshift_keywords.rs | 21 + crates/lib-dialects/src/snowflake.rs | 19710 ++++++++++------ crates/lib-dialects/src/snowflake_keywords.rs | 256 +- crates/lib-dialects/src/sparksql.rs | 4597 ++-- crates/lib-dialects/src/sparksql_keywords.rs | 19 +- crates/lib-dialects/src/sqlite.rs | 2453 +- crates/lib-dialects/src/sqlite_keywords.rs | 15 +- crates/lib-dialects/src/trino.rs | 1728 +- crates/lib-dialects/src/trino_keywords.rs | 1 + crates/lib-dialects/src/tsql.rs | 4123 ++-- crates/lib-dialects/src/tsql_keywords.rs | 1478 +- .../dialects/ansi/sqlfluff/alter_sequence.yml | 10 +- .../dialects/ansi/sqlfluff/arithmetic_a.yml | 12 +- .../sqlfluff/create_index_if_not_exists.yml | 2 +- .../ansi/sqlfluff/create_index_simple.yml | 4 +- .../ansi/sqlfluff/create_schema_a.yml | 5 +- .../sqlfluff/create_schema_if_not_exists.yml | 5 +- .../ansi/sqlfluff/create_sequence.yml | 16 +- .../ansi/sqlfluff/double_quote_escapes.sql | 10 + .../ansi/sqlfluff/double_quote_escapes.yml | 59 + .../ansi/sqlfluff/drop_index_if_exists.yml | 2 +- .../ansi/sqlfluff/drop_index_simple.yml | 2 +- .../dialects/ansi/sqlfluff/drop_schema.yml | 30 +- .../dialects/ansi/sqlfluff/drop_schema_a.sql | 1 - .../dialects/ansi/sqlfluff/drop_schema_a.yml | 8 - .../dialects/ansi/sqlfluff/drop_sequence.yml | 4 +- .../dialects/ansi/sqlfluff/escaped_quotes.yml | 6 +- .../dialects/ansi/sqlfluff/functions_a.yml | 6 +- .../dialects/ansi/sqlfluff/functions_b.yml | 3 +- .../ansi/sqlfluff/insert_using_subquery.yml | 9 +- .../dialects/ansi/sqlfluff/like_operators.yml | 6 +- .../dialects/ansi/sqlfluff/merge_into.sql | 2 +- .../dialects/ansi/sqlfluff/merge_into.yml | 6 +- .../dialects/ansi/sqlfluff/modulo.yml | 3 +- .../ansi/sqlfluff/multiple_semicolons.sql | 17 + .../ansi/sqlfluff/multiple_semicolons.yml | 127 + .../ansi/sqlfluff/naked_identifiers.yml | 12 +- .../fixtures/dialects/ansi/sqlfluff/obevo.sql | 13 + .../fixtures/dialects/ansi/sqlfluff/obevo.yml | 45 + .../sqlfluff/select_bitwise_operators.yml | 8 +- .../dialects/ansi/sqlfluff/select_case_a.yml | 3 +- .../dialects/ansi/sqlfluff/select_case_b.yml | 3 +- .../dialects/ansi/sqlfluff/select_case_c.yml | 9 +- .../ansi/sqlfluff/select_cross_join.yml | 9 +- .../dialects/ansi/sqlfluff/select_e.yml | 12 +- .../dialects/ansi/sqlfluff/select_f.yml | 3 +- .../dialects/ansi/sqlfluff/select_g.yml | 6 +- .../dialects/ansi/sqlfluff/select_g_fetch.yml | 6 +- .../dialects/ansi/sqlfluff/select_h.yml | 6 +- .../ansi/sqlfluff/select_many_join.sql | 44 +- .../ansi/sqlfluff/select_many_join.yml | 446 +- .../select_multiple_named_windows.yml | 3 +- .../dialects/ansi/sqlfluff/select_n.yml | 12 +- .../select_named_window_no_parentheses.yml | 3 +- .../select_named_window_with_parentheses.yml | 6 +- ...amed_windows_each_window_specification.yml | 3 +- .../ansi/sqlfluff/select_nested_join.yml | 54 +- .../dialects/ansi/sqlfluff/select_offset.sql | 3 + .../dialects/ansi/sqlfluff/select_offset.yml | 61 + .../dialects/ansi/sqlfluff/select_p.yml | 6 +- .../dialects/ansi/sqlfluff/select_q.yml | 3 +- .../dialects/ansi/sqlfluff/select_r.yml | 6 +- .../dialects/ansi/sqlfluff/select_s.yml | 3 +- .../select_sample_bernoulli_10_aliased.yml | 3 +- .../select_sample_system_10_aliased.yml | 3 +- .../ansi/sqlfluff/select_simple_e.yml | 6 +- .../ansi/sqlfluff/select_simple_h.yml | 3 +- .../ansi/sqlfluff/select_simple_i.yml | 12 +- .../dialects/ansi/sqlfluff/select_u.yml | 3 +- .../ansi/sqlfluff/select_union_bracketed.sql | 11 + .../ansi/sqlfluff/select_union_bracketed.yml | 73 + .../ansi/sqlfluff/select_with_brackets.yml | 19 +- .../select_with_where_clause_functions.yml | 3 +- .../dialects/ansi/sqlfluff/set_order_by.yml | 6 +- .../dialects/ansi/sqlfluff/set_schema_a.yml | 5 +- .../dialects/ansi/sqlfluff/shorthand_cast.yml | 6 +- .../ansi/sqlfluff/table_expression.yml | 6 +- .../ansi/sqlfluff/update_with_table_alias.yml | 3 +- .../dialects/athena/sqlfluff/alter_table.sql | 36 + .../dialects/athena/sqlfluff/alter_table.yml | 491 + .../athena/sqlfluff/create_array_table.yml | 2 +- .../sqlfluff/create_external_table_struct.yml | 4 +- .../dialects/athena/sqlfluff/create_view.yml | 6 +- .../dialects/athena/sqlfluff/element_at.yml | 9 +- .../dialects/athena/sqlfluff/listagg.yml | 168 +- .../sqlfluff/select_cast_withtimezone.yml | 12 +- .../athena/sqlfluff/select_group_by.yml | 15 +- .../athena/sqlfluff/select_map_function.yml | 3 +- .../athena/sqlfluff/select_map_type.yml | 3 +- .../dialects/athena/sqlfluff/select_row.sql | 1 - .../dialects/athena/sqlfluff/select_row.yml | 5 +- .../athena/sqlfluff/select_underscore.yml | 15 +- .../athena/sqlfluff/select_unnest.yml | 9 +- .../sqlfluff/select_widow_functions.yml | 6 +- .../dialects/athena/sqlfluff/values.yml | 6 +- .../bigquery/sqlfluff/alter_schema.sql | 11 + .../bigquery/sqlfluff/alter_schema.yml | 62 + .../sqlfluff/alter_table_add_column.yml | 6 +- .../bigquery/sqlfluff/alter_table_add_key.sql | 11 + .../bigquery/sqlfluff/alter_table_add_key.yml | 110 + .../sqlfluff/alter_table_drop_constraint.sql | 5 + .../sqlfluff/alter_table_drop_constraint.yml | 25 + .../sqlfluff/alter_table_drop_key.sql | 5 + .../sqlfluff/alter_table_drop_key.yml | 25 + .../alter_table_set_default_collate.sql | 2 + .../alter_table_set_default_collate.yml | 15 + .../sqlfluff/alter_various_resources.sql | 14 + .../sqlfluff/alter_various_resources.yml | 84 + .../sqlfluff/alter_view_alter_column.sql | 5 + .../sqlfluff/alter_view_alter_column.yml | 47 + .../bigquery/sqlfluff/any_value_having.yml | 6 +- .../array_agg_distinct_ignore_nulls.yml | 3 +- .../sqlfluff/array_agg_ignore_nulls.yml | 3 +- .../sqlfluff/array_agg_respect_nulls.yml | 3 +- .../dialects/bigquery/sqlfluff/assert.yml | 3 +- .../dialects/bigquery/sqlfluff/begin.sql | 45 + .../dialects/bigquery/sqlfluff/begin.yml | 233 + .../bigquery/sqlfluff/create_assignment.sql | 3 + .../bigquery/sqlfluff/create_assignment.yml | 22 + .../bigquery/sqlfluff/create_capacity.sql | 3 + .../bigquery/sqlfluff/create_capacity.yml | 17 + .../sqlfluff/create_external_table.sql | 2 +- .../sqlfluff/create_function_no_args.sql | 11 +- .../sqlfluff/create_function_no_args.yml | 84 +- .../sqlfluff/create_function_with_args.sql | 16 + .../sqlfluff/create_function_with_args.yml | 143 + .../bigquery/sqlfluff/create_index.sql | 15 + .../bigquery/sqlfluff/create_index.yml | 133 + .../create_js_function_complex_types.sql | 2 +- .../create_js_function_complex_types.yml | 18 +- ...eate_js_function_options_library_array.yml | 4 +- .../create_js_function_quoted_name.yml | 4 +- .../create_js_function_underscore_name.yml | 4 +- ...create_materialized_view_as_replica_of.sql | 6 + ...create_materialized_view_as_replica_of.yml | 52 + .../bigquery/sqlfluff/create_procedure.sql | 146 + .../bigquery/sqlfluff/create_procedure.yml | 469 +- .../bigquery/sqlfluff/create_reservation.sql | 3 + .../bigquery/sqlfluff/create_reservation.yml | 17 + .../sqlfluff/create_row_access_policy.sql | 27 + .../sqlfluff/create_row_access_policy.yml | 186 + .../bigquery/sqlfluff/create_schema.sql | 5 + .../bigquery/sqlfluff/create_schema.yml | 33 + .../sqlfluff/create_snapshot_table.sql | 12 + .../sqlfluff/create_snapshot_table.yml | 82 + .../sqlfluff/create_table_column_options.yml | 6 +- .../sqlfluff/create_table_default_collate.sql | 13 + .../sqlfluff/create_table_default_collate.yml | 89 + .../sqlfluff/create_table_function.sql | 9 + .../sqlfluff/create_table_function.yml | 85 + .../bigquery/sqlfluff/create_table_keys.sql | 26 + .../bigquery/sqlfluff/create_table_keys.yml | 152 + .../sqlfluff/create_table_like_copy_clone.sql | 5 + .../sqlfluff/create_table_like_copy_clone.yml | 39 + .../create_temp_function_with_select.yml | 6 +- .../sqlfluff/create_view_options_as.sql | 8 + .../sqlfluff/create_view_options_as.yml | 65 + .../dialects/bigquery/sqlfluff/dateparts.yml | 6 +- .../bigquery/sqlfluff/declare_variable.yml | 18 +- .../bigquery/sqlfluff/drop_function.sql | 2 + .../bigquery/sqlfluff/drop_function.yml | 24 + .../bigquery/sqlfluff/drop_procedure.sql | 2 + .../bigquery/sqlfluff/drop_procedure.yml | 23 + .../bigquery/sqlfluff/drop_schema.sql | 4 + .../bigquery/sqlfluff/drop_schema.yml | 38 + .../dialects/bigquery/sqlfluff/drop_table.sql | 3 + .../dialects/bigquery/sqlfluff/drop_table.yml | 32 + .../bigquery/sqlfluff/drop_table_function.sql | 2 + .../bigquery/sqlfluff/drop_table_function.yml | 23 + .../sqlfluff/drop_various_resources.sql | 11 + .../sqlfluff/drop_various_resources.yml | 67 + .../bigquery/sqlfluff/execute_immediate.sql | 34 + .../bigquery/sqlfluff/execute_immediate.yml | 292 + .../bigquery/sqlfluff/export_statement.sql | 8 + .../bigquery/sqlfluff/export_statement.yml | 84 +- .../dialects/bigquery/sqlfluff/for_in.yml | 3 +- .../bigquery/sqlfluff/handle_exception.sql | 48 + .../bigquery/sqlfluff/handle_exception.yml | 265 + .../bigquery/sqlfluff/interval_function.yml | 9 +- .../bigquery/sqlfluff/load_data_statement.sql | 119 + .../bigquery/sqlfluff/load_data_statement.yml | 554 + .../bigquery/sqlfluff/normalize_function.yml | 54 +- .../dialects/bigquery/sqlfluff/parameters.yml | 3 +- .../bigquery/sqlfluff/pipe_statement.sql | 165 + .../bigquery/sqlfluff/pipe_statement.yml | 1746 ++ .../dialects/bigquery/sqlfluff/select.sql | 1 + .../dialects/bigquery/sqlfluff/select.yml | 19 + .../bigquery/sqlfluff/select_case.yml | 3 +- .../bigquery/sqlfluff/select_datetime.yml | 6 +- .../bigquery/sqlfluff/select_example.yml | 9 +- .../bigquery/sqlfluff/select_except.sql | 2 +- .../bigquery/sqlfluff/select_except.yml | 22 +- .../sqlfluff/select_except_replace.yml | 32 +- .../bigquery/sqlfluff/select_extract.yml | 9 +- .../sqlfluff/select_for_system_time.yml | 110 +- .../select_function_object_fields.yml | 24 +- .../bigquery/sqlfluff/select_group_by.sql | 55 + .../bigquery/sqlfluff/select_group_by.yml | 383 + .../select_hyphenated_table_name_in_from.yml | 6 +- .../bigquery/sqlfluff/select_identifiers.yml | 3 +- .../dialects/bigquery/sqlfluff/select_if.yml | 9 +- .../select_mixture_of_array_literals.yml | 32 +- .../select_ml_predict_with_select.yml | 61 +- .../bigquery/sqlfluff/select_ml_weights.yml | 27 +- .../bigquery/sqlfluff/select_multi_except.yml | 6 +- .../bigquery/sqlfluff/select_quoting.sql | 2 +- .../bigquery/sqlfluff/select_quoting.yml | 3 +- .../bigquery/sqlfluff/select_replace.yml | 63 +- .../bigquery/sqlfluff/select_rows_between.yml | 3 +- .../sqlfluff/select_safe_function.yml | 6 +- .../sqlfluff/select_set_operators.sql | 9 + .../sqlfluff/select_set_operators.yml | 139 + .../bigquery/sqlfluff/select_struct.sql | 2 + .../bigquery/sqlfluff/select_struct.yml | 83 +- ...select_typeless_struct_inside_function.yml | 21 +- .../sqlfluff/select_udf_quote_everything.yml | 6 +- .../sqlfluff/select_udf_quote_nothing.sql | 2 - .../sqlfluff/select_udf_quote_nothing.yml | 6 +- ..._quote_project_and_datasetfunctionname.yml | 6 +- .../select_udf_quote_project_name.yml | 6 +- .../bigquery/sqlfluff/select_unpivot.yml | 51 +- .../bigquery/sqlfluff/select_with_cast.sql | 16 + .../bigquery/sqlfluff/select_with_cast.yml | 352 + ..._coercion_and_two_part_string_interval.yml | 3 +- .../bigquery/sqlfluff/select_with_offset.sql | 2 +- .../bigquery/sqlfluff/select_with_offset.yml | 9 +- .../sqlfluff/select_with_offset_3.yml | 3 +- .../bigquery/sqlfluff/select_with_qualify.yml | 21 +- .../select_with_union_and_qualify.yml | 6 +- .../bigquery/sqlfluff/select_with_window.yml | 15 +- .../bigquery/sqlfluff/set_variable_single.sql | 1 + .../bigquery/sqlfluff/set_variable_single.yml | 9 + .../bigquery/sqlfluff/string_literals.yml | 3 +- .../bigquery/sqlfluff/typeless_struct.yml | 30 +- .../clickhouse/sqlfluff/alter_table.yml | 12 +- .../sqlfluff/back_quoted_identifier.yml | 6 +- .../sqlfluff/complex_table_definition.yml | 24 +- .../clickhouse/sqlfluff/create_database.yml | 1629 +- .../sqlfluff/create_materialized_view.yml | 154 +- .../clickhouse/sqlfluff/create_table.yml | 217 +- .../clickhouse/sqlfluff/create_user.sql | 7 + .../clickhouse/sqlfluff/create_user.yml | 27 + .../clickhouse/sqlfluff/create_view.yml | 421 +- .../dialects/clickhouse/sqlfluff/cte.yml | 24 +- .../sqlfluff/datetime64_precision.yml | 15 +- .../clickhouse/sqlfluff/decimal_support.yml | 39 +- .../clickhouse/sqlfluff/drop_statement.yml | 6 +- .../dialects/clickhouse/sqlfluff/final.yml | 3 +- .../dialects/clickhouse/sqlfluff/format.yml | 39 +- .../clickhouse/sqlfluff/identifier.yml | 6 +- .../clickhouse/sqlfluff/in_table_cte.yml | 3 +- .../dialects/clickhouse/sqlfluff/interval.yml | 3 +- .../clickhouse/sqlfluff/into_outfile.yml | 46 +- .../dialects/clickhouse/sqlfluff/join.yml | 228 +- .../dialects/clickhouse/sqlfluff/limit_by.yml | 45 +- .../clickhouse/sqlfluff/limit_delimited.yml | 57 +- .../clickhouse/sqlfluff/match_support.yml | 9 +- .../sqlfluff/order_by_expression.yml | 28 +- .../sqlfluff/order_by_with_fill.yml | 102 +- .../parametric_aggregate_functions.sql | 55 + .../parametric_aggregate_functions.yml | 911 + .../dialects/clickhouse/sqlfluff/prewhere.yml | 25 +- .../sqlfluff/select_with_settings.yml | 33 +- .../clickhouse/sqlfluff/tuple_datatype.yml | 27 +- .../clickhouse/sqruff/alter_table.sql | 1 - .../clickhouse/sqruff/alter_table.yml | 17 - .../databricks/sqlfluff/alter_catalog.sql | 13 + .../databricks/sqlfluff/alter_catalog.yml | 158 +- .../databricks/sqlfluff/alter_database.sql | 27 + .../databricks/sqlfluff/alter_database.yml | 209 + .../databricks/sqlfluff/alter_table.sql | 106 + .../databricks/sqlfluff/alter_table.yml | 897 +- .../databricks/sqlfluff/alter_view.sql | 27 + .../databricks/sqlfluff/alter_view.yml | 257 +- .../databricks/sqlfluff/alter_volume.sql | 16 + .../databricks/sqlfluff/alter_volume.yml | 125 + .../sqlfluff/command_terminator.sql | 12 + .../sqlfluff/command_terminator.yml} | 48 +- .../databricks/sqlfluff/comment_on.sql | 4 + .../databricks/sqlfluff/comment_on.yml | 176 +- .../databricks/sqlfluff/create_catalog.yml | 43 +- .../databricks/sqlfluff/create_database.sql | 30 + .../databricks/sqlfluff/create_database.yml | 117 + .../databricks/sqlfluff/create_function.sql | 106 + .../databricks/sqlfluff/create_function.yml | 569 + .../create_private_materialized_view.sql | 19 + .../create_private_materialized_view.yml | 101 + .../databricks/sqlfluff/create_table.sql | 91 +- .../databricks/sqlfluff/create_table.yml | 824 +- .../databricks/sqlfluff/create_volume.sql | 27 + .../databricks/sqlfluff/create_volume.yml | 68 + .../sqlfluff/databricks_keywords.sql | 3 - .../databricks/sqlfluff/date_functions.yml | 40 +- .../sqlfluff/declare_or_replace_variable.yml | 85 +- .../databricks/sqlfluff/describe_volume.yml | 2 +- .../databricks/sqlfluff/drop_catalog.yml | 26 +- .../databricks/sqlfluff/drop_volume.yml | 22 +- .../databricks/sqlfluff/grant_permissions.sql | 9 + .../databricks/sqlfluff/grant_permissions.yml | 98 + .../databricks/sqlfluff/insert_by_name.sql | 5 - .../databricks/sqlfluff/insert_by_name.yml | 239 - .../databricks/sqlfluff/magic_line.sql | 24 + .../databricks/sqlfluff/magic_line.yml | 62 + .../databricks/sqlfluff/magic_single_line.sql | 11 + .../databricks/sqlfluff/magic_single_line.yml | 31 + .../databricks/sqlfluff/named_argument.sql | 7 + .../databricks/sqlfluff/named_argument.yml | 88 + .../dialects/databricks/sqlfluff/pivot.sql | 7 + .../dialects/databricks/sqlfluff/pivot.yml | 172 +- .../sqlfluff/revoke_permissions.sql | 7 + .../sqlfluff/revoke_permissions.yml | 85 + .../dialects/databricks/sqlfluff/select.yml | 38 +- .../sqlfluff/select_from_lateral_view.sql | 114 + .../sqlfluff/select_from_lateral_view.yml | 807 + .../sqlfluff/select_from_read_file.sql | 37 + .../sqlfluff/select_from_read_file.yml | 257 + .../databricks/sqlfluff/select_group_by.sql | 2 +- .../databricks/sqlfluff/select_group_by.yml | 91 +- .../databricks/sqlfluff/select_window.yml | 4 +- .../dialects/databricks/sqlfluff/set_tags.sql | 17 + .../dialects/databricks/sqlfluff/set_tags.yml | 198 + .../databricks/sqlfluff/set_time_zone.yml | 71 +- .../databricks/sqlfluff/set_variable.sql | 20 + .../databricks/sqlfluff/set_variable.yml | 164 + .../databricks/sqlfluff/show_databases.yml | 8 +- .../databricks/sqlfluff/show_functions.yml | 12 +- .../databricks/sqlfluff/show_tables.yml | 8 +- .../databricks/sqlfluff/show_views.yml | 8 +- .../databricks/sqlfluff/show_volumes.yml | 12 +- .../dialects/databricks/sqlfluff/unpivot.yml | 144 +- .../databricks/sqlfluff/use_catalog.yml | 45 +- .../databricks/sqlfluff/use_database.yml | 84 +- .../duckdb/sqlfluff/anti_semi_join.sql | 15 + .../duckdb/sqlfluff/anti_semi_join.yml | 157 + .../dialects/duckdb/sqlfluff/asof_join.sql | 40 + .../dialects/duckdb/sqlfluff/asof_join.yml | 445 + .../dialects/duckdb/sqlfluff/copy.sql | 86 + .../dialects/duckdb/sqlfluff/copy.yml | 522 + .../dialects/duckdb/sqlfluff/create_macro.sql | 45 + .../dialects/duckdb/sqlfluff/create_macro.yml | 487 + .../dialects/duckdb/sqlfluff/create_table.sql | 104 + .../dialects/duckdb/sqlfluff/create_table.yml | 788 + .../dialects/duckdb/sqlfluff/create_type.sql | 7 + .../dialects/duckdb/sqlfluff/create_type.yml | 108 + .../dialects/duckdb/sqlfluff/create_view.sql | 4 + .../dialects/duckdb/sqlfluff/create_view.yml | 72 + .../dialects/duckdb/sqlfluff/describe.sql | 3 - .../dialects/duckdb/sqlfluff/double_equal.sql | 7 + .../dialects/duckdb/sqlfluff/double_equal.yml | 97 + .../dialects/duckdb/sqlfluff/drop_macro.sql | 9 + .../dialects/duckdb/sqlfluff/drop_macro.yml | 74 + .../duckdb/sqlfluff/extract_temporal.sql | 13 + .../duckdb/sqlfluff/extract_temporal.yml | 131 + .../dialects/duckdb/sqlfluff/filter.sql | 12 + .../dialects/duckdb/sqlfluff/filter.yml | 172 + .../dialects/duckdb/sqlfluff/from_first.sql | 8 + .../dialects/duckdb/sqlfluff/from_first.yml | 80 + .../duckdb/sqlfluff/group_order_by_all.yml | 40 +- .../dialects/duckdb/sqlfluff/in_operator.sql | 12 + .../dialects/duckdb/sqlfluff/in_operator.yml | 164 + .../dialects/duckdb/sqlfluff/insert.sql | 50 + .../dialects/duckdb/sqlfluff/insert.yml | 374 + .../duckdb/sqlfluff/json_operators.sql | 10 + .../duckdb/sqlfluff/json_operators.yml | 57 + .../duckdb/sqlfluff/list_comprehension.sql | 5 + .../duckdb/sqlfluff/list_comprehension.yml | 128 + .../dialects/duckdb/sqlfluff/list_struct.sql | 1 - .../dialects/duckdb/sqlfluff/list_struct.yml | 18 +- .../duckdb/sqlfluff/load_statement.sql | 1 - .../duckdb/sqlfluff/load_statement.yml | 5 - .../dialects/duckdb/sqlfluff/macro.sql | 48 - .../dialects/duckdb/sqlfluff/macro.yml | 223 - .../dialects/duckdb/sqlfluff/pivot.sql | 70 + .../dialects/duckdb/sqlfluff/pivot.yml | 672 + .../duckdb/sqlfluff/positional_join.sql | 5 + .../duckdb/sqlfluff/positional_join.yml | 33 + .../dialects/duckdb/sqlfluff/qualify.sql | 47 + .../dialects/duckdb/sqlfluff/qualify.yml | 286 + .../duckdb/sqlfluff/select_columns.sql | 16 + .../duckdb/sqlfluff/select_columns.yml | 240 + .../duckdb/sqlfluff/select_exclude.yml | 45 +- .../sqlfluff/select_exclude_replace.sql | 6 + .../sqlfluff/select_exclude_replace.yml | 65 + .../duckdb/sqlfluff/select_lambda.sql | 16 + .../duckdb/sqlfluff/select_lambda.yml | 194 + .../duckdb/sqlfluff/select_replace.yml | 45 +- .../duckdb/sqlfluff/star_expression.sql | 42 + .../duckdb/sqlfluff/star_expression.yml | 419 + .../dialects/duckdb/sqlfluff/structs.sql | 3 + .../dialects/duckdb/sqlfluff/structs.yml | 49 + .../dialects/duckdb/sqlfluff/summarize.sql | 3 - .../dialects/duckdb/sqlfluff/unpivot.sql | 48 + .../dialects/duckdb/sqlfluff/unpivot.yml | 293 + .../sqlfluff/walrus_operator_function.sql | 11 + .../sqlfluff/walrus_operator_function.yml | 72 + .../fixtures/dialects/hive/sqlfluff/.sqlfluff | 2 + .../dialects/hive/sqlfluff/alter_database.sql | 5 + .../dialects/hive/sqlfluff/alter_database.yml | 43 + .../dialects/hive/sqlfluff/alter_schema.sql | 3 + .../dialects/hive/sqlfluff/alter_schema.yml | 22 + .../dialects/hive/sqlfluff/alter_table.sql | 5 + .../dialects/hive/sqlfluff/alter_table.yml | 52 + .../dialects/hive/sqlfluff/alter_view.sql | 3 + .../dialects/hive/sqlfluff/alter_view.yml | 47 + .../dialects/hive/sqlfluff/array_types.sql | 26 + .../dialects/hive/sqlfluff/array_types.yml | 218 + .../hive/sqlfluff/create_database.sql | 1 + .../hive/sqlfluff/create_database.yml | 24 + .../dialects/hive/sqlfluff/create_schema.sql | 1 + .../dialects/hive/sqlfluff/create_schema.yml | 15 + .../hive/sqlfluff/create_table_as_select.sql | 6 + .../hive/sqlfluff/create_table_as_select.yml | 57 + .../sqlfluff/create_table_clustered_by.sql | 5 + .../sqlfluff/create_table_clustered_by.yml | 43 + .../sqlfluff/create_table_constraints.sql | 37 + .../sqlfluff/create_table_constraints.yml | 220 + .../hive/sqlfluff/create_table_datatypes.sql | 10 + .../hive/sqlfluff/create_table_datatypes.yml | 133 + .../create_table_external_partitioned.sql | 6 + .../create_table_external_partitioned.yml | 44 + .../hive/sqlfluff/create_table_like.sql | 3 + .../hive/sqlfluff/create_table_like.yml | 21 + .../create_table_row_format_delimited.sql | 14 + .../create_table_row_format_delimited.yml | 75 + .../create_table_row_format_serde.sql | 11 + .../create_table_row_format_serde.yml | 57 + .../hive/sqlfluff/create_table_skewed_by.sql | 2 + .../hive/sqlfluff/create_table_skewed_by.yml | 73 + .../create_table_temporary_external.sql | 6 + .../create_table_temporary_external.yml | 45 + .../create_table_temporary_properties.sql | 5 + .../create_table_temporary_properties.yml | 36 + .../hive/sqlfluff/create_table_with.sql | 10 + .../hive/sqlfluff/create_table_with.yml | 47 + .../dialects/hive/sqlfluff/double_equals.sql | 6 + .../dialects/hive/sqlfluff/double_equals.yml | 29 + .../dialects/hive/sqlfluff/drop_database.sql | 3 + .../dialects/hive/sqlfluff/drop_database.yml | 16 + .../dialects/hive/sqlfluff/drop_schema.sql | 1 + .../dialects/hive/sqlfluff/drop_schema.yml | 11 + .../dialects/hive/sqlfluff/drop_table.sql | 3 + .../dialects/hive/sqlfluff/drop_table.yml | 18 + .../hive/sqlfluff/insert_into_table.sql | 5 + .../hive/sqlfluff/insert_into_table.yml | 50 + .../sqlfluff/insert_into_table_partition.sql | 3 + .../sqlfluff/insert_into_table_partition.yml | 49 + .../sqlfluff/insert_into_table_values.sql | 2 + .../sqlfluff/insert_into_table_values.yml | 24 + .../sqlfluff/insert_overwrite_directory.sql | 2 + .../sqlfluff/insert_overwrite_directory.yml | 26 + .../hive/sqlfluff/insert_overwrite_table.sql | 2 + .../hive/sqlfluff/insert_overwrite_table.yml | 26 + ...sert_overwrite_table_dynamic_partition.sql | 7 + ...sert_overwrite_table_dynamic_partition.yml | 87 + .../insert_overwrite_table_partition.sql | 3 + .../insert_overwrite_table_partition.yml | 52 + .../hive/sqlfluff/msck_repair_table.sql | 12 + .../hive/sqlfluff/msck_repair_table.yml | 57 + .../dialects/hive/sqlfluff/msck_table.sql | 12 + .../dialects/hive/sqlfluff/msck_table.yml | 51 + .../dialects/hive/sqlfluff/quoted_literal.sql | 5 + .../dialects/hive/sqlfluff/quoted_literal.yml | 37 + .../dialects/hive/sqlfluff/select_cast.sql | 6 + .../dialects/hive/sqlfluff/select_cast.yml | 85 + .../select_cluster_distribute_sort_by.sql | 13 + .../select_cluster_distribute_sort_by.yml | 204 + .../hive/sqlfluff/select_interval.sql | 37 + .../hive/sqlfluff/select_interval.yml | 210 + .../hive/sqlfluff/select_lateral_view.sql | 28 + .../hive/sqlfluff/select_lateral_view.yml | 465 + .../hive/sqlfluff/select_left_semi_join.sql | 2 + .../hive/sqlfluff/select_left_semi_join.yml | 47 + .../dialects/hive/sqlfluff/select_regexp.sql | 26 + .../sqlfluff/select_regexp.yml} | 103 +- .../hive/sqlfluff/select_sampling_table.sql | 13 + .../hive/sqlfluff/select_sampling_table.yml | 141 + .../fixtures/dialects/hive/sqlfluff/set.sql | 6 + .../fixtures/dialects/hive/sqlfluff/set.yml | 47 + .../dialects/hive/sqlfluff/truncate_table.sql | 3 + .../dialects/hive/sqlfluff/truncate_table.yml | 23 + .../fixtures/dialects/hive/sqlfluff/use.sql | 1 + .../fixtures/dialects/hive/sqlfluff/use.yml | 7 + .../mysql/sqlfluff/alter_database.sql | 26 + .../mysql/sqlfluff/alter_database.yml | 109 + .../dialects/mysql/sqlfluff/alter_event.sql | 23 + .../dialects/mysql/sqlfluff/alter_event.yml | 97 + .../dialects/mysql/sqlfluff/alter_table.sql | 109 + .../dialects/mysql/sqlfluff/alter_table.yml | 940 + .../dialects/mysql/sqlfluff/alter_view.sql | 15 + .../dialects/mysql/sqlfluff/alter_view.yml | 169 + .../dialects/mysql/sqlfluff/analyze_table.sql | 39 + .../dialects/mysql/sqlfluff/analyze_table.yml | 259 + .../dialects/mysql/sqlfluff/begin.sql | 3 + .../dialects/mysql/sqlfluff/begin.yml | 18 + .../mysql/sqlfluff/bit_value_literal.sql | 3 + .../mysql/sqlfluff/bit_value_literal.yml | 22 + .../mysql/sqlfluff/call_statement.sql | 6 + .../mysql/sqlfluff/call_statement.yml | 108 + .../mysql/sqlfluff/check_constraint.sql | 15 + .../mysql/sqlfluff/check_constraint.yml | 128 + .../dialects/mysql/sqlfluff/check_table.sql | 25 + .../dialects/mysql/sqlfluff/check_table.yml | 126 + .../mysql/sqlfluff/checksum_table.sql | 7 + .../mysql/sqlfluff/checksum_table.yml | 39 + .../dialects/mysql/sqlfluff/close.sql | 1 + .../dialects/mysql/sqlfluff/close.yml | 6 + .../mysql/sqlfluff/close_qualified.sql | 1 + .../mysql/sqlfluff/close_qualified.yml | 6 + .../dialects/mysql/sqlfluff/collate.sql | 1 + .../dialects/mysql/sqlfluff/collate.yml | 12 + .../dialects/mysql/sqlfluff/column_alias.sql | 4 + .../dialects/mysql/sqlfluff/column_alias.yml | 45 + .../mysql/sqlfluff/create_database.sql | 20 + .../mysql/sqlfluff/create_database.yml | 102 + .../dialects/mysql/sqlfluff/create_event.sql | 40 + .../dialects/mysql/sqlfluff/create_event.yml | 292 + .../dialects/mysql/sqlfluff/create_index.sql | 14 + .../dialects/mysql/sqlfluff/create_index.yml | 254 + .../mysql/sqlfluff/create_procedure.sql | 4 + .../mysql/sqlfluff/create_procedure.yml | 28 + .../dialects/mysql/sqlfluff/create_role.sql | 1 + .../dialects/mysql/sqlfluff/create_role.yml | 11 + .../dialects/mysql/sqlfluff/create_table.sql | 73 + .../dialects/mysql/sqlfluff/create_table.yml | 684 + .../sqlfluff/create_table_column_charset.sql | 27 + .../sqlfluff/create_table_column_charset.yml | 109 + .../create_table_constraint_unique.sql | 9 + .../create_table_constraint_unique.yml | 75 + .../mysql/sqlfluff/create_table_datetime.sql | 25 + .../mysql/sqlfluff/create_table_datetime.yml | 215 + .../sqlfluff/create_table_equals_optional.sql | 3 + .../sqlfluff/create_table_equals_optional.yml | 17 + .../create_table_generated_column.sql | 17 + .../create_table_generated_column.yml | 188 + .../mysql/sqlfluff/create_table_index.sql | 12 + .../mysql/sqlfluff/create_table_index.yml | 122 + .../sqlfluff/create_table_null_position.sql | 7 + .../sqlfluff/create_table_null_position.yml | 52 + .../create_table_primary_foreign_keys.sql | 49 + .../create_table_primary_foreign_keys.yml | 311 + .../sqlfluff/create_table_unique_key.sql | 3 + .../sqlfluff/create_table_unique_key.yml | 18 + .../mysql/sqlfluff/create_trigger.sql | 52 + .../mysql/sqlfluff/create_trigger.yml | 468 + .../dialects/mysql/sqlfluff/create_user.sql | 74 + .../dialects/mysql/sqlfluff/create_user.yml | 522 + .../dialects/mysql/sqlfluff/create_view.sql | 24 + .../dialects/mysql/sqlfluff/create_view.yml | 254 + .../mysql/sqlfluff/deallocate_prepare.sql | 1 + .../mysql/sqlfluff/deallocate_prepare.yml | 7 + .../mysql/sqlfluff/declare_condition.sql | 1 + .../mysql/sqlfluff/declare_condition.yml | 9 + .../declare_continue_handler_sqlexception.sql | 4 + .../declare_continue_handler_sqlexception.yml | 22 + .../mysql/sqlfluff/declare_cursor.sql | 1 + .../mysql/sqlfluff/declare_cursor.yml | 14 + .../sqlfluff/declare_default_numeric.sql | 1 + .../sqlfluff/declare_default_numeric.yml | 10 + .../declare_default_quotedliteral.sql | 1 + .../declare_default_quotedliteral.yml | 10 + .../declare_exit_handler_sqlexception.sql | 4 + .../declare_exit_handler_sqlexception.yml | 22 + .../mysql/sqlfluff/declare_local_variable.sql | 1 + .../mysql/sqlfluff/declare_local_variable.yml | 8 + .../declare_undo_handler_sqlexception.sql | 4 + .../declare_undo_handler_sqlexception.yml | 22 + .../mysql/sqlfluff/delete_multitable.sql | 32 + .../mysql/sqlfluff/delete_multitable.yml | 528 + .../mysql/sqlfluff/delimiter_function.sql | 11 + .../mysql/sqlfluff/delimiter_function.yml | 51 + .../mysql/sqlfluff/delimiter_procedure.sql | 10 + .../mysql/sqlfluff/delimiter_procedure.yml | 48 + .../mysql/sqlfluff/delimiter_select.sql | 3 + .../mysql/sqlfluff/delimiter_select.yml | 16 + .../mysql/sqlfluff/derived_tables.sql | 4 + .../mysql/sqlfluff/derived_tables.yml | 163 + .../dialects/mysql/sqlfluff/drop_event.sql | 3 + .../dialects/mysql/sqlfluff/drop_event.yml | 17 + .../dialects/mysql/sqlfluff/drop_function.sql | 1 + .../dialects/mysql/sqlfluff/drop_function.yml | 10 + .../dialects/mysql/sqlfluff/drop_index.sql | 1 + .../dialects/mysql/sqlfluff/drop_index.yml | 13 + .../sqlfluff/drop_index_with_algorithm.sql | 6 + .../sqlfluff/drop_index_with_algorithm.yml | 91 + .../mysql/sqlfluff/drop_index_with_lock.sql | 8 + .../mysql/sqlfluff/drop_index_with_lock.yml | 105 + .../dialects/mysql/sqlfluff/drop_prepare.sql | 1 + .../dialects/mysql/sqlfluff/drop_prepare.yml | 7 + .../mysql/sqlfluff/drop_procedure.sql | 1 + .../mysql/sqlfluff/drop_procedure.yml | 10 + .../dialects/mysql/sqlfluff/drop_table.sql | 7 + .../dialects/mysql/sqlfluff/drop_table.yml | 44 + .../dialects/mysql/sqlfluff/drop_trigger.sql | 5 + .../dialects/mysql/sqlfluff/drop_trigger.yml | 26 + .../mysql/sqlfluff/execute_prepared_stmt.sql | 1 + .../mysql/sqlfluff/execute_prepared_stmt.yml | 6 + .../sqlfluff/execute_prepared_stmt_using.sql | 1 + .../sqlfluff/execute_prepared_stmt_using.yml | 8 + ..._prepared_stmt_using_multiple_variable.sql | 1 + ..._prepared_stmt_using_multiple_variable.yml | 10 + .../dialects/mysql/sqlfluff/explain.sql | 7 + .../dialects/mysql/sqlfluff/explain.yml | 75 + .../dialects/mysql/sqlfluff/fetch.sql | 1 + .../dialects/mysql/sqlfluff/fetch.yml | 8 + .../dialects/mysql/sqlfluff/fetch_from.sql | 1 + .../dialects/mysql/sqlfluff/fetch_from.yml | 9 + .../mysql/sqlfluff/fetch_multiple.sql | 1 + .../mysql/sqlfluff/fetch_multiple.yml | 10 + .../mysql/sqlfluff/fetch_next_from.sql | 1 + .../mysql/sqlfluff/fetch_next_from.yml | 10 + .../dialects/mysql/sqlfluff/fetch_session.sql | 1 + .../dialects/mysql/sqlfluff/fetch_session.yml | 8 + .../mysql/sqlfluff/fetch_session_multiple.sql | 1 + .../mysql/sqlfluff/fetch_session_multiple.yml | 10 + .../dialects/mysql/sqlfluff/flush.sql | 10 + .../dialects/mysql/sqlfluff/flush.yml | 113 + .../dialects/mysql/sqlfluff/force_index.sql | 1 + .../sqlfluff/force_index.yml} | 25 +- .../sqlfluff/force_index_for_group_by.sql | 1 + .../sqlfluff/force_index_for_group_by.yml | 28 + .../mysql/sqlfluff/force_index_for_join.sql | 1 + .../sqlfluff/force_index_for_join.yml} | 27 +- .../sqlfluff/force_index_for_order_by.sql | 1 + .../sqlfluff/force_index_for_order_by.yml | 28 + .../mysql/sqlfluff/force_index_inner_join.sql | 1 + .../mysql/sqlfluff/force_index_inner_join.yml | 52 + .../mysql/sqlfluff/force_index_left_join.sql | 1 + .../mysql/sqlfluff/force_index_left_join.yml | 52 + .../dialects/mysql/sqlfluff/force_key.sql | 1 + .../dialects/mysql/sqlfluff/force_key.yml | 25 + .../mysql/sqlfluff/function_comment.sql | 6 + .../mysql/sqlfluff/function_comment.yml | 29 + .../mysql/sqlfluff/function_definer.sql | 6 + .../mysql/sqlfluff/function_definer.yml | 38 + .../mysql/sqlfluff/function_modifies_sql.sql | 7 + .../mysql/sqlfluff/function_modifies_sql.yml | 39 + .../mysql/sqlfluff/function_no_sql.sql | 7 + .../mysql/sqlfluff/function_no_sql.yml | 38 + .../sqlfluff/function_notdeterministic.sql | 6 + .../sqlfluff/function_notdeterministic.yml | 37 + .../mysql/sqlfluff/function_reads_sql.sql | 7 + .../mysql/sqlfluff/function_reads_sql.yml | 39 + .../mysql/sqlfluff/function_return.sql | 6 + .../mysql/sqlfluff/function_return.yml | 39 + .../function_sql_security_definer.sql | 7 + .../function_sql_security_definer.yml | 39 + .../function_sql_security_invoker.sql | 7 + .../function_sql_security_invoker.yml | 39 + ...gnostics_condition_info_local_variable.sql | 1 + ...gnostics_condition_info_local_variable.yml | 12 + ...stics_condition_info_multiple_variable.sql | 1 + ...stics_condition_info_multiple_variable.yml | 17 + ...ostics_condition_info_session_variable.sql | 1 + ...ostics_condition_info_session_variable.yml | 12 + ...t_diagnostics_condition_local_variable.sql | 1 + ...t_diagnostics_condition_local_variable.yml | 8 + .../get_diagnostics_condition_numeric.sql | 1 + .../get_diagnostics_condition_numeric.yml | 8 + ...diagnostics_condition_session_variable.sql | 1 + ...diagnostics_condition_session_variable.yml | 8 + .../mysql/sqlfluff/get_diagnostics_number.sql | 1 + .../mysql/sqlfluff/get_diagnostics_number.yml | 12 + .../sqlfluff/get_diagnostics_row_count.sql | 1 + .../sqlfluff/get_diagnostics_row_count.yml | 12 + .../dialects/mysql/sqlfluff/grant.sql | 11 + .../dialects/mysql/sqlfluff/grant.yml | 208 + .../mysql/sqlfluff/handler_condition_name.sql | 4 + .../mysql/sqlfluff/handler_condition_name.yml | 22 + .../handler_continue_sqlexception.yml | 22 + .../mysql/sqlfluff/handler_error_code.sql | 4 + .../mysql/sqlfluff/handler_error_code.yml | 22 + .../sqlfluff/handler_exit_sqlexception.yml | 22 + .../mysql/sqlfluff/handler_not_found.sql | 4 + .../mysql/sqlfluff/handler_not_found.yml | 23 + .../mysql/sqlfluff/handler_sqlstate.sql | 4 + .../mysql/sqlfluff/handler_sqlstate.yml | 23 + .../mysql/sqlfluff/handler_sqlstate_value.sql | 4 + .../mysql/sqlfluff/handler_sqlstate_value.yml | 24 + .../mysql/sqlfluff/handler_sqlwarning.sql | 4 + .../mysql/sqlfluff/handler_sqlwarning.yml | 22 + .../sqlfluff/handler_undo_sqlexception.yml | 22 + .../mysql/sqlfluff/help_statement.sql | 6 + .../mysql/sqlfluff/help_statement.yml | 31 + .../mysql/sqlfluff/hexadecimal_literal.sql | 6 + .../mysql/sqlfluff/hexadecimal_literal.yml | 43 + .../fixtures/dialects/mysql/sqlfluff/if.sql | 4 + .../fixtures/dialects/mysql/sqlfluff/if.yml | 35 + .../dialects/mysql/sqlfluff/if_else.sql | 5 + .../dialects/mysql/sqlfluff/if_else.yml | 38 + .../dialects/mysql/sqlfluff/if_elseif.sql | 8 + .../dialects/mysql/sqlfluff/if_elseif.yml | 67 + .../mysql/sqlfluff/if_multiple_expression.sql | 4 + .../mysql/sqlfluff/if_multiple_expression.yml | 62 + .../dialects/mysql/sqlfluff/if_nested.sql | 7 + .../dialects/mysql/sqlfluff/if_nested.yml | 61 + .../mysql/sqlfluff/if_session_variable.sql | 1 + .../mysql/sqlfluff/if_session_variable.yml | 34 + .../mysql/sqlfluff/if_subquery_expression.sql | 4 + .../mysql/sqlfluff/if_subquery_expression.yml | 56 + .../dialects/mysql/sqlfluff/ignore_index.sql | 1 + .../dialects/mysql/sqlfluff/ignore_index.yml | 25 + .../sqlfluff/ignore_index_for_group_by.sql | 1 + .../sqlfluff/ignore_index_for_group_by.yml | 28 + .../mysql/sqlfluff/ignore_index_for_join.sql | 1 + .../mysql/sqlfluff/ignore_index_for_join.yml | 27 + .../sqlfluff/ignore_index_for_order_by.sql | 1 + .../sqlfluff/ignore_index_for_order_by.yml | 28 + .../dialects/mysql/sqlfluff/ignore_key.sql | 1 + .../dialects/mysql/sqlfluff/ignore_key.yml | 25 + .../dialects/mysql/sqlfluff/insert.sql | 31 + .../dialects/mysql/sqlfluff/insert.yml | 578 + .../dialects/mysql/sqlfluff/interval.sql | 23 + .../dialects/mysql/sqlfluff/interval.yml | 232 + .../fixtures/dialects/mysql/sqlfluff/json.sql | 16 + .../fixtures/dialects/mysql/sqlfluff/json.yml | 169 + .../dialects/mysql/sqlfluff/load_data.sql | 31 + .../dialects/mysql/sqlfluff/load_data.yml | 280 + .../dialects/mysql/sqlfluff/loop_label.sql | 1 + .../dialects/mysql/sqlfluff/loop_label.yml | 29 + .../sqlfluff/loop_multiple_statements.sql | 1 + .../sqlfluff/loop_multiple_statements.yml | 32 + .../dialects/mysql/sqlfluff/loop_no_label.sql | 1 + .../dialects/mysql/sqlfluff/loop_no_label.yml | 16 + .../dialects/mysql/sqlfluff/nested_begin.sql | 5 + .../dialects/mysql/sqlfluff/nested_begin.yml | 29 + .../mysql/sqlfluff/null_safe_equal.sql | 3 + .../mysql/sqlfluff/null_safe_equal.yml | 48 + .../fixtures/dialects/mysql/sqlfluff/open.sql | 1 + .../fixtures/dialects/mysql/sqlfluff/open.yml | 6 + .../mysql/sqlfluff/open_qualified.sql | 1 + .../mysql/sqlfluff/open_qualified.yml | 6 + .../mysql/sqlfluff/optimize_table.sql | 11 + .../mysql/sqlfluff/optimize_table.yml | 56 + .../mysql/sqlfluff/prepare_local_variable.sql | 1 + .../mysql/sqlfluff/prepare_local_variable.yml | 8 + .../sqlfluff/prepare_session_variable.sql | 1 + .../sqlfluff/prepare_session_variable.yml | 8 + .../mysql/sqlfluff/prepare_statement.sql | 1 + .../mysql/sqlfluff/prepare_statement.yml | 8 + .../mysql/sqlfluff/procedure_definer.sql | 3 + .../mysql/sqlfluff/procedure_definer.yml | 26 + .../mysql/sqlfluff/procedure_in_param.sql | 3 + .../mysql/sqlfluff/procedure_in_param.yml | 22 + .../mysql/sqlfluff/procedure_inout_param.sql | 3 + .../mysql/sqlfluff/procedure_inout_param.yml | 22 + .../mysql/sqlfluff/procedure_out_param.sql | 3 + .../mysql/sqlfluff/procedure_out_param.yml | 22 + .../mysql/sqlfluff/purge_binary_logs.sql | 7 + .../mysql/sqlfluff/purge_binary_logs.yml | 47 + .../mysql/sqlfluff/quoted_literal.sql | 75 + .../mysql/sqlfluff/quoted_literal.yml | 241 + .../dialects/mysql/sqlfluff/rename_table.sql | 2 + .../dialects/mysql/sqlfluff/rename_table.yml | 27 + .../dialects/mysql/sqlfluff/repair_table.sql | 19 + .../dialects/mysql/sqlfluff/repair_table.yml | 90 + .../dialects/mysql/sqlfluff/repeat_label.sql | 1 + .../dialects/mysql/sqlfluff/repeat_label.yml | 29 + .../sqlfluff/repeat_multiple_statements.sql | 1 + .../sqlfluff/repeat_multiple_statements.yml | 39 + .../mysql/sqlfluff/repeat_no_label.sql | 1 + .../mysql/sqlfluff/repeat_no_label.yml | 26 + .../dialects/mysql/sqlfluff/replace.sql | 43 + .../dialects/mysql/sqlfluff/replace.yml | 400 + .../dialects/mysql/sqlfluff/reset_master.sql | 2 + .../dialects/mysql/sqlfluff/reset_master.yml | 13 + .../dialects/mysql/sqlfluff/resignal.sql | 1 + .../dialects/mysql/sqlfluff/resignal.yml | 5 + .../sqlfluff/resignal_condition_name.sql | 1 + .../sqlfluff/resignal_condition_name.yml | 6 + .../sqlfluff/resignal_condition_sqlstate.sql | 1 + .../sqlfluff/resignal_condition_sqlstate.yml | 7 + .../resignal_condition_sqlstate_value.sql | 1 + .../resignal_condition_sqlstate_value.yml | 8 + .../sqlfluff/resignal_set_signal_info.sql | 1 + .../sqlfluff/resignal_set_signal_info.yml | 10 + .../resignal_set_signal_info_multiple.sql | 1 + .../resignal_set_signal_info_multiple.yml | 15 + .../mysql/sqlfluff/select_distinctrow.sql | 1 + .../sqlfluff/select_distinctrow.yml} | 8 +- .../mysql/sqlfluff/select_for_share.sql | 1 + .../sqlfluff/select_for_share.yml} | 8 +- .../mysql/sqlfluff/select_for_update.sql | 1 + .../sqlfluff/select_for_update.yml} | 9 +- .../select_for_update_lock_in_share_mode.sql | 1 + .../select_for_update_lock_in_share_mode.yml} | 13 +- .../sqlfluff/select_for_update_nowait.sql | 1 + .../sqlfluff/select_for_update_nowait.yml | 19 + .../mysql/sqlfluff/select_for_update_of.sql | 1 + .../mysql/sqlfluff/select_for_update_of.yml | 20 + .../select_for_update_of_multiple.sql | 1 + .../select_for_update_of_multiple.yml | 22 + .../select_for_update_skip_locked.sql | 1 + .../select_for_update_skip_locked.yml | 20 + .../mysql/sqlfluff/select_high_priority.sql | 1 + .../sqlfluff/select_high_priority.yml} | 13 +- .../mysql/sqlfluff/select_into_dumpfile.sql | 1 + .../sqlfluff/select_into_dumpfile.yml} | 15 +- .../select_into_multiple_variable.sql | 1 + .../select_into_multiple_variable.yml | 49 + .../mysql/sqlfluff/select_into_outfile.sql | 1 + .../mysql/sqlfluff/select_into_outfile.yml | 21 + .../select_into_outfile_fields_enclosed.sql | 1 + .../select_into_outfile_fields_enclosed.yml | 25 + .../select_into_outfile_fields_escaped.sql | 1 + .../select_into_outfile_fields_escaped.yml | 25 + ...nto_outfile_fields_optionally_enclosed.sql | 1 + ...nto_outfile_fields_optionally_enclosed.yml | 26 + .../select_into_outfile_fields_terminated.sql | 1 + .../select_into_outfile_fields_terminated.yml | 25 + .../select_into_outfile_lines_starting.sql | 1 + .../select_into_outfile_lines_starting.yml | 25 + .../select_into_outfile_lines_terminated.sql | 1 + .../select_into_outfile_lines_terminated.yml | 25 + .../sqlfluff/select_into_session_variable.sql | 11 + .../sqlfluff/select_into_session_variable.yml | 70 + .../mysql/sqlfluff/select_local_variable.sql | 1 + .../mysql/sqlfluff/select_local_variable.yml | 9 + .../sqlfluff/select_lock_in_share_mode.sql | 1 + .../sqlfluff/select_lock_in_share_mode.yml | 20 + .../sqlfluff/select_multiple_partition.sql | 1 + .../sqlfluff/select_multiple_partition.yml | 27 + .../mysql/sqlfluff/select_operators.sql | 8 + .../mysql/sqlfluff/select_operators.yml | 93 +- .../mysql/sqlfluff/select_partition.sql | 1 + .../mysql/sqlfluff/select_partition.yml | 24 + .../sqlfluff/select_partition_left_join.sql | 1 + .../sqlfluff/select_partition_left_join.yml | 51 + .../sqlfluff/select_session_variable.sql | 1 + .../sqlfluff/select_session_variable.yml | 9 + .../mysql/sqlfluff/select_sql_big_result.sql | 1 + .../sqlfluff/select_sql_big_result.yml} | 12 +- .../sqlfluff/select_sql_buffer_result.sql | 1 + .../sqlfluff/select_sql_buffer_result.yml | 19 + .../mysql/sqlfluff/select_sql_cache.sql | 1 + .../mysql/sqlfluff/select_sql_cache.yml | 19 + .../sqlfluff/select_sql_calc_found_rows.sql | 1 + .../sqlfluff/select_sql_calc_found_rows.yml | 19 + .../mysql/sqlfluff/select_sql_no_cache.sql | 1 + .../mysql/sqlfluff/select_sql_no_cache.yml | 19 + .../sqlfluff/select_sql_small_result.sql | 1 + .../sqlfluff/select_sql_small_result.yml | 19 + .../mysql/sqlfluff/select_straight_join.sql | 1 + .../mysql/sqlfluff/select_straight_join.yml | 19 + .../select_with_date_part_function.sql | 7 + .../select_with_date_part_function.yml | 129 + .../mysql/sqlfluff/select_with_regexp.sql | 3 + .../mysql/sqlfluff/select_with_regexp.yml | 25 + .../fixtures/dialects/mysql/sqlfluff/set.sql | 40 + .../fixtures/dialects/mysql/sqlfluff/set.yml | 440 + .../dialects/mysql/sqlfluff/set_names.sql | 11 + .../dialects/mysql/sqlfluff/set_names.yml | 46 + .../mysql/sqlfluff/set_transaction.sql | 12 + .../mysql/sqlfluff/set_transaction.yml | 120 + .../dialects/mysql/sqlfluff/signal.sql | 1 + .../dialects/mysql/sqlfluff/signal.yml | 5 + .../mysql/sqlfluff/signal_condition_name.sql | 1 + .../mysql/sqlfluff/signal_condition_name.yml | 6 + .../sqlfluff/signal_condition_sqlstate.sql | 1 + .../sqlfluff/signal_condition_sqlstate.yml | 7 + .../signal_condition_sqlstate_value.sql | 1 + .../signal_condition_sqlstate_value.yml | 8 + .../mysql/sqlfluff/signal_set_signal_info.sql | 1 + .../mysql/sqlfluff/signal_set_signal_info.yml | 10 + .../signal_set_signal_info_multiple.sql | 1 + .../signal_set_signal_info_multiple.yml | 15 + .../mysql/sqlfluff/system_variables.sql | 5 + .../mysql/sqlfluff/system_variables.yml | 55 + .../dialects/mysql/sqlfluff/update.sql | 39 + .../dialects/mysql/sqlfluff/update.yml | 456 + .../dialects/mysql/sqlfluff/use_database.sql | 1 + .../dialects/mysql/sqlfluff/use_database.yml | 7 + .../dialects/mysql/sqlfluff/use_index.sql | 1 + .../dialects/mysql/sqlfluff/use_index.yml | 27 + .../mysql/sqlfluff/use_index_for_group_by.sql | 1 + .../mysql/sqlfluff/use_index_for_group_by.yml | 30 + .../mysql/sqlfluff/use_index_for_join.sql | 1 + .../mysql/sqlfluff/use_index_for_join.yml | 29 + .../mysql/sqlfluff/use_index_for_order_by.sql | 1 + .../mysql/sqlfluff/use_index_for_order_by.yml | 30 + .../dialects/mysql/sqlfluff/use_key.sql | 1 + .../dialects/mysql/sqlfluff/use_key.yml | 27 + .../dialects/mysql/sqlfluff/use_statement.sql | 1 + .../dialects/mysql/sqlfluff/use_statement.yml | 7 + .../mysql/sqlfluff/values_statement.sql | 5 + .../mysql/sqlfluff/values_statement.yml | 72 + .../mysql/sqlfluff/variable_assignment.sql | 7 + .../mysql/sqlfluff/variable_assignment.yml | 66 + .../dialects/mysql/sqlfluff/while_label.sql | 1 + .../dialects/mysql/sqlfluff/while_label.yml | 33 + .../mysql/sqlfluff/while_no_label.sql | 1 + .../mysql/sqlfluff/while_no_label.yml | 30 + .../postgres/sqlfluff/alter_aggregate.yml | 174 +- .../postgres/sqlfluff/alter_database.sql | 2 + .../postgres/sqlfluff/alter_database.yml | 22 + .../sqlfluff/alter_default_privileges.yml | 75 +- .../postgres/sqlfluff/alter_extension.sql | 5 + .../postgres/sqlfluff/alter_extension.yml | 63 + .../postgres/sqlfluff/alter_foreign_table.sql | 13 + .../postgres/sqlfluff/alter_foreign_table.yml | 126 + .../postgres/sqlfluff/alter_index.yml | 20 +- .../sqlfluff/alter_materialized_view.yml | 10 +- .../postgres/sqlfluff/alter_policy.sql | 5 + .../postgres/sqlfluff/alter_policy.yml | 45 +- .../postgres/sqlfluff/alter_procedure.yml | 5 +- .../postgres/sqlfluff/alter_publication.yml | 25 +- .../postgres/sqlfluff/alter_schema.yml | 15 +- .../postgres/sqlfluff/alter_sequence.sql | 2 + .../postgres/sqlfluff/alter_sequence.yml | 51 +- .../postgres/sqlfluff/alter_statistics.yml | 63 +- .../postgres/sqlfluff/alter_subscription.sql | 3 + .../postgres/sqlfluff/alter_subscription.yml | 20 + .../postgres/sqlfluff/alter_table.yml | 9 +- .../alter_text_search_configuration.sql | 8 + .../alter_text_search_configuration.yml | 127 + .../dialects/postgres/sqlfluff/alter_type.yml | 49 +- .../dialects/postgres/sqlfluff/alter_view.yml | 10 +- .../dialects/postgres/sqlfluff/array.yml | 67 +- .../postgres/sqlfluff/bare_functions.sql | 8 +- .../postgres/sqlfluff/bare_functions.yml | 57 +- .../dialects/postgres/sqlfluff/cluster.yml | 8 +- .../dialects/postgres/sqlfluff/comment_on.yml | 7 +- .../postgres/sqlfluff/composite_types.yml | 22 +- .../sqlfluff/composite_value_expansion.sql | 12 + .../sqlfluff/composite_value_expansion.yml | 279 + .../dialects/postgres/sqlfluff/copy.sql | 46 + .../dialects/postgres/sqlfluff/copy.yml | 626 + .../postgres/sqlfluff/create_aggregate.sql | 6 + .../postgres/sqlfluff/create_aggregate.yml | 48 + .../postgres/sqlfluff/create_domain.yml | 4 +- .../postgres/sqlfluff/create_extension.sql | 2 + .../postgres/sqlfluff/create_extension.yml | 26 +- .../sqlfluff/create_foreign_table.sql | 135 + .../sqlfluff/create_foreign_table.yml | 977 + .../sqlfluff/create_foreign_wrapper.sql | 3 + .../sqlfluff/create_foreign_wrapper.yml | 13 + .../postgres/sqlfluff/create_function.sql | 76 + .../postgres/sqlfluff/create_function.yml | 765 +- .../postgres/sqlfluff/create_index.sql | 2 + .../postgres/sqlfluff/create_index.yml | 58 +- .../sqlfluff/create_materialized_view.yml | 12 +- .../postgres/sqlfluff/create_operator.sql | 17 + .../postgres/sqlfluff/create_operator.yml | 92 + .../postgres/sqlfluff/create_policy.yml | 3 +- .../postgres/sqlfluff/create_procedure.sql | 13 + .../postgres/sqlfluff/create_procedure.yml | 63 + .../postgres/sqlfluff/create_publication.yml | 50 +- .../postgres/sqlfluff/create_role.sql | 1 + .../postgres/sqlfluff/create_role.yml | 11 + .../postgres/sqlfluff/create_schema.yml | 20 +- .../postgres/sqlfluff/create_sequence.sql | 2 + .../postgres/sqlfluff/create_sequence.yml | 43 +- .../postgres/sqlfluff/create_server.yml | 6 +- .../postgres/sqlfluff/create_statistics.yml | 213 +- .../postgres/sqlfluff/create_subscription.sql | 21 + .../postgres/sqlfluff/create_subscription.yml | 90 + .../postgres/sqlfluff/create_table.sql | 29 + .../postgres/sqlfluff/create_table.yml | 1753 +- .../create_text_search_configuration.sql | 9 + .../create_text_search_configuration.yml | 58 + .../postgres/sqlfluff/create_type.sql | 5 - .../postgres/sqlfluff/create_type.yml | 67 +- .../postgres/sqlfluff/create_user_mapping.yml | 12 +- .../postgres/sqlfluff/create_view.yml | 24 +- .../sqlfluff/cte_in_materialized_view.yml | 9 +- .../dialects/postgres/sqlfluff/datatypes.yml | 884 +- .../postgres/sqlfluff/datetime_units.sql | 51 + .../postgres/sqlfluff/datetime_units.yml | 407 +- .../dialects/postgres/sqlfluff/deallocate.sql | 7 + .../dialects/postgres/sqlfluff/deallocate.yml | 25 + .../dialects/postgres/sqlfluff/delete.sql | 5 + .../dialects/postgres/sqlfluff/delete.yml | 79 +- .../postgres/sqlfluff/drop_aggregate.sql | 5 + .../postgres/sqlfluff/drop_aggregate.yml | 52 + .../postgres/sqlfluff/drop_collation.sql | 7 + .../postgres/sqlfluff/drop_collation.yml | 33 + .../postgres/sqlfluff/drop_foreign_table.sql | 9 + .../postgres/sqlfluff/drop_foreign_table.yml | 52 + .../postgres/sqlfluff/drop_function.sql | 7 +- .../postgres/sqlfluff/drop_function.yml | 34 +- .../dialects/postgres/sqlfluff/drop_index.yml | 56 +- .../postgres/sqlfluff/drop_sequence.yml | 10 +- .../postgres/sqlfluff/drop_statistics.yml | 49 +- .../postgres/sqlfluff/drop_subscription.sql | 4 + .../postgres/sqlfluff/drop_subscription.yml | 33 + .../drop_text_search_configuration.sql | 4 + .../drop_text_search_configuration.yml | 43 + .../dialects/postgres/sqlfluff/execute.sql | 5 + .../dialects/postgres/sqlfluff/execute.yml | 32 + .../dialects/postgres/sqlfluff/filter.yml | 3 +- .../postgres/sqlfluff/full_text_search.sql | 31 + .../postgres/sqlfluff/full_text_search.yml | 316 + .../postgres/sqlfluff/grant_privileges.sql | 2 + .../postgres/sqlfluff/grant_privileges.yml | 63 + .../dialects/postgres/sqlfluff/grant_role.sql | 2 - .../dialects/postgres/sqlfluff/grant_role.yml | 25 - .../dialects/postgres/sqlfluff/group_by.yml | 36 +- .../sqlfluff/import_foreign_schema.yml | 34 +- .../dialects/postgres/sqlfluff/insert.sql | 33 + .../dialects/postgres/sqlfluff/insert.yml | 167 +- .../dialects/postgres/sqlfluff/is_json.sql | 51 + .../dialects/postgres/sqlfluff/is_json.yml | 455 + .../dialects/postgres/sqlfluff/is_unknown.sql | 3 + .../dialects/postgres/sqlfluff/is_unknown.yml | 22 + .../postgres/sqlfluff/join_lateral.sql | 21 +- .../postgres/sqlfluff/join_lateral.yml | 287 +- .../postgres/sqlfluff/json_operators.sql | 21 + .../postgres/sqlfluff/json_operators.yml | 192 +- .../postgres/sqlfluff/json_serialize.sql | 6 + .../postgres/sqlfluff/json_serialize.yml | 127 + .../dialects/postgres/sqlfluff/json_value.sql | 11 + .../dialects/postgres/sqlfluff/json_value.yml | 213 + .../sqlfluff/meta_commands_query_buffer.sql | 23 + .../sqlfluff/meta_commands_query_buffer.yml | 223 + .../postgres/sqlfluff/null_filters.yml | 12 +- .../postgres/sqlfluff/operator_qualified.sql | 69 + .../postgres/sqlfluff/operator_qualified.yml | 543 + .../dialects/postgres/sqlfluff/overlaps.sql | 38 + .../dialects/postgres/sqlfluff/overlaps.yml | 392 +- .../sqlfluff/pattern_match_expressions.yml | 9 +- .../dialects/postgres/sqlfluff/pg_trgm.sql | 32 + .../dialects/postgres/sqlfluff/pg_trgm.yml | 101 + .../dialects/postgres/sqlfluff/pgvector.sql | 3 + .../dialects/postgres/sqlfluff/pgvector.yml | 20 + .../dialects/postgres/sqlfluff/position.sql | 5 +- .../dialects/postgres/sqlfluff/position.yml | 40 +- .../dialects/postgres/sqlfluff/postgis.yml | 1000 +- .../sqlfluff/postgres_pgvector_operators.sql | 7 + .../sqlfluff/postgres_pgvector_operators.yml | 109 + .../sqlfluff/postgres_postgis_operators.sql | 149 + .../sqlfluff/postgres_postgis_operators.yml | 1776 ++ .../dialects/postgres/sqlfluff/prepare.sql | 27 + .../dialects/postgres/sqlfluff/prepare.yml | 255 + .../postgres/sqlfluff/psql_variable.yml | 6 +- .../postgres/sqlfluff/range_operators.yml | 7 +- .../dialects/postgres/sqlfluff/reindex.yml | 7 +- .../sqlfluff/reset_session_authorization.sql | 1 + .../sqlfluff/reset_session_authorization.yml | 7 + .../postgres/sqlfluff/security_label.sql | 6 + .../postgres/sqlfluff/security_label.yml | 88 + .../dialects/postgres/sqlfluff/select.sql | 19 +- .../dialects/postgres/sqlfluff/select.yml | 96 +- .../postgres/sqlfluff/select_case_cast.yml | 9 +- .../postgres/sqlfluff/select_frame_clause.yml | 13 +- .../postgres/sqlfluff/select_natural_join.sql | 31 + .../postgres/sqlfluff/select_natural_join.yml | 195 + .../postgres/sqlfluff/select_offset.sql | 5 + .../postgres/sqlfluff/select_offset.yml | 72 + .../sqlfluff/select_ordered_nested_sets.sql | 13 + .../sqlfluff/select_ordered_nested_sets.yml | 85 + .../postgres/sqlfluff/select_utf8.sql | 32 + .../postgres/sqlfluff/select_utf8.yml | 204 + .../postgres/sqlfluff/set_constraints.sql | 3 + .../postgres/sqlfluff/set_constraints.yml | 26 + .../sqlfluff/set_session_authorization.sql | 5 + .../sqlfluff/set_session_authorization.yml | 42 + .../dialects/postgres/sqlfluff/show.sql | 8 + .../dialects/postgres/sqlfluff/show.yml | 41 + .../postgres/sqlfluff/single_quote.sql | 39 + .../postgres/sqlfluff/single_quote.yml | 86 + .../sqlfluff/string_normalization.sql | 36 + .../sqlfluff/string_normalization.yml | 657 + .../dialects/postgres/sqlfluff/subquery.yml | 3 +- .../dialects/postgres/sqlfluff/substring.sql | 5 + .../dialects/postgres/sqlfluff/substring.yml | 139 + .../postgres/sqlfluff/table_functions.sql | 6 + .../postgres/sqlfluff/table_functions.yml | 106 +- .../sqlfluff/unicode_double_quote.yml | 6 +- .../postgres/sqlfluff/update_table.yml | 3 +- .../postgres/sqlfluff/values_alias.yml | 3 +- .../postgres/sqlfluff/values_in_subquery.yml | 6 +- .../dialects/postgres/sqlfluff/variadic.sql | 53 + .../dialects/postgres/sqlfluff/variadic.yml | 522 + .../dialects/postgres/sqlfluff/with.yml | 12 +- .../redshift/sqlfluff/alter_datashare.yml | 15 +- .../sqlfluff/alter_default_privileges.yml | 10 +- .../redshift/sqlfluff/alter_schema.yml | 25 +- .../redshift/sqlfluff/alter_table.sql | 8 + .../redshift/sqlfluff/alter_table.yml | 65 + .../dialects/redshift/sqlfluff/alter_user.yml | 14 +- .../sqlfluff/approximate_functions.yml | 80 +- .../redshift/sqlfluff/array_unnest.yml | 82 +- .../dialects/redshift/sqlfluff/call.yml | 74 +- .../redshift/sqlfluff/cast_conversion.sql | 3 + .../redshift/sqlfluff/cast_conversion.yml | 214 +- .../redshift/sqlfluff/create_database.sql | 77 + .../redshift/sqlfluff/create_database.yml | 457 + .../sqlfluff/create_external_schema.sql | 25 + .../sqlfluff/create_external_schema.yml | 106 +- .../sqlfluff/create_materialized_view.sql | 10 +- .../sqlfluff/create_materialized_view.yml | 19 +- .../redshift/sqlfluff/create_procedure.sql | 27 + .../redshift/sqlfluff/create_procedure.yml | 84 + .../redshift/sqlfluff/create_schema.yml | 60 +- .../redshift/sqlfluff/create_table.sql | 12 + .../redshift/sqlfluff/create_table.yml | 107 + .../redshift/sqlfluff/create_user.yml | 14 +- .../dialects/redshift/sqlfluff/dateparts.yml | 1521 +- .../redshift/sqlfluff/datetime_cast.yml | 36 +- .../dialects/redshift/sqlfluff/deallocate.sql | 3 + .../dialects/redshift/sqlfluff/deallocate.yml | 14 + .../dialects/redshift/sqlfluff/declare.yml | 3 +- .../dialects/redshift/sqlfluff/execute.sql | 5 + .../dialects/redshift/sqlfluff/execute.yml | 32 + .../dialects/redshift/sqlfluff/merge.sql | 9 + .../dialects/redshift/sqlfluff/merge.yml | 153 + .../redshift/sqlfluff/object_unpivot.yml | 60 +- .../sqlfluff/pattern_match_expressions.yml | 118 +- .../redshift/sqlfluff/percentile_cont.yml | 28 +- .../dialects/redshift/sqlfluff/pivot.yml | 76 +- .../dialects/redshift/sqlfluff/prepare.sql | 17 + .../dialects/redshift/sqlfluff/prepare.yml | 149 + .../dialects/redshift/sqlfluff/qualify.yml | 33 +- .../dialects/redshift/sqlfluff/select.sql | 4 + .../sqlfluff/select.yml} | 23 +- .../redshift/sqlfluff/select_dateadd.yml | 21 +- .../sqlfluff/select_datetime_functions.yml | 63 +- .../redshift/sqlfluff/select_exclude.sql | 7 + .../redshift/sqlfluff/select_exclude.yml | 89 + .../redshift/sqlfluff/select_first_value.yml | 20 +- .../redshift/sqlfluff/select_into.yml | 22 +- .../redshift/sqlfluff/select_keywords.yml | 59 +- .../redshift/sqlfluff/set_operators.sql | 19 + .../redshift/sqlfluff/set_operators.yml | 172 + .../redshift/sqlfluff/super_data_type.yml | 63 +- .../dialects/redshift/sqlfluff/unload.sql | 5 + .../dialects/redshift/sqlfluff/unload.yml | 19 + .../dialects/redshift/sqlfluff/unpivot.yml | 12 +- .../dialects/redshift/sqlfluff/update.yml | 3 +- .../redshift/sqlfluff/window_functions.yml | 19 +- .../snowflake/sqlfluff/alter_account.sql | 2 + .../snowflake/sqlfluff/alter_account.yml | 220 +- .../sqlfluff/alter_cortex_search_service.sql | 8 + .../sqlfluff/alter_cortex_search_service.yml | 114 + .../sqlfluff/alter_dynamic_table.sql | 135 + .../sqlfluff/alter_dynamic_table.yml | 1011 + .../sqlfluff/alter_external_volume.sql | 31 + .../sqlfluff/alter_external_volume.yml | 130 + .../snowflake/sqlfluff/alter_file_format.sql | 3 + .../snowflake/sqlfluff/alter_file_format.yml | 12 + .../snowflake/sqlfluff/alter_function.sql | 30 + .../snowflake/sqlfluff/alter_function.yml | 205 + .../sqlfluff/alter_masking_policy.yml | 228 +- .../sqlfluff/alter_network_policy.yml | 157 +- .../sqlfluff/alter_password_policy.sql | 9 + .../sqlfluff/alter_password_policy.yml | 74 + .../snowflake/sqlfluff/alter_pipe.sql | 1 + .../snowflake/sqlfluff/alter_pipe.yml | 13 + .../snowflake/sqlfluff/alter_procedure.sql | 25 + .../snowflake/sqlfluff/alter_procedure.yml | 129 + .../sqlfluff/alter_resource_monitor.sql | 73 +- .../sqlfluff/alter_resource_monitor.yml | 339 +- .../snowflake/sqlfluff/alter_role.yml | 18 +- .../sqlfluff/alter_row_access_policy.sql | 15 + .../sqlfluff/alter_row_access_policy.yml | 133 + .../snowflake/sqlfluff/alter_schema.yml | 50 +- .../snowflake/sqlfluff/alter_sequence.yml | 20 +- .../snowflake/sqlfluff/alter_share.sql | 1 + .../snowflake/sqlfluff/alter_share.yml | 56 +- .../snowflake/sqlfluff/alter_stage.yml | 6 +- .../sqlfluff/alter_storage_integration.sql | 3 +- .../sqlfluff/alter_storage_integration.yml | 49 +- .../snowflake/sqlfluff/alter_streamlit.sql | 16 + .../snowflake/sqlfluff/alter_streamlit.yml | 75 + .../snowflake/sqlfluff/alter_table.sql | 72 + .../snowflake/sqlfluff/alter_table.yml | 1006 +- .../snowflake/sqlfluff/alter_table_column.sql | 39 +- .../snowflake/sqlfluff/alter_table_column.yml | 439 +- .../dialects/snowflake/sqlfluff/alter_tag.sql | 21 + .../dialects/snowflake/sqlfluff/alter_tag.yml | 130 + .../sqlfluff/alter_task_add_after.sql | 2 + .../sqlfluff/alter_task_add_after.yml | 14 + .../sqlfluff/alter_task_remove_after.sql | 2 + .../sqlfluff/alter_task_remove_after.yml | 14 + .../sqlfluff/alter_user_set_values.sql | 4 +- .../sqlfluff/alter_user_set_values.yml | 48 + .../sqlfluff/alter_user_unset_values.sql | 2 +- .../sqlfluff/alter_user_unset_values.yml | 2 + .../snowflake/sqlfluff/alter_view.sql | 5 +- .../snowflake/sqlfluff/alter_view.yml | 30 + .../snowflake/sqlfluff/alter_warehouse.sql | 7 + .../snowflake/sqlfluff/alter_warehouse.yml | 43 + .../sqlfluff/at_before_time_travel.sql | 29 + .../sqlfluff/at_before_time_travel.yml | 409 + .../dialects/snowflake/sqlfluff/begin_end.sql | 8 +- .../dialects/snowflake/sqlfluff/begin_end.yml | 74 +- .../sqlfluff/cast_datatype_accessor.sql | 12 + .../sqlfluff/cast_datatype_accessor.yml | 165 +- .../snowflake/sqlfluff/changes_clause.sql | 5 + .../snowflake/sqlfluff/changes_clause.yml | 34 + .../snowflake/sqlfluff/col_position.yml | 6 +- .../snowflake/sqlfluff/connect_by.sql | 23 + .../snowflake/sqlfluff/connect_by.yml | 247 +- .../copy_files_into_location_statement.sql | 20 + .../copy_files_into_location_statement.yml | 90 + .../snowflake/sqlfluff/copy_into_location.sql | 30 +- .../snowflake/sqlfluff/copy_into_location.yml | 197 +- .../copy_into_location_Amazon_SC3.yml | 2 +- .../sqlfluff/copy_into_location_Azure.yml | 2 +- .../copy_into_location_GoogleCloud.yml | 2 +- .../copy_into_location_partitionby.yml | 9 +- .../snowflake/sqlfluff/copy_into_table.sql | 21 + .../snowflake/sqlfluff/copy_into_table.yml | 133 +- .../sqlfluff/create_api_integration.sql | 67 + .../sqlfluff/create_api_integration.yml | 317 + .../sqlfluff/create_authentication_policy.sql | 21 + .../sqlfluff/create_authentication_policy.yml | 139 + .../sqlfluff/create_catalog_integration.sql | 123 + .../sqlfluff/create_catalog_integration.yml | 470 + .../sqlfluff/create_cortex_search_service.sql | 35 + .../sqlfluff/create_cortex_search_service.yml | 182 + .../snowflake/sqlfluff/create_database.sql | 1 + .../snowflake/sqlfluff/create_database.yml | 9 + .../sqlfluff/create_database_role.sql | 2 + .../sqlfluff/create_database_role.yml | 16 + .../sqlfluff/create_dynamic_table.sql | 46 + .../sqlfluff/create_dynamic_table.yml | 329 + .../snowflake/sqlfluff/create_event_table.sql | 15 + .../snowflake/sqlfluff/create_event_table.yml | 116 + .../sqlfluff/create_external_table.sql | 11 + .../sqlfluff/create_external_table.yml | 77 + .../sqlfluff/create_external_volume.sql | 56 + .../sqlfluff/create_external_volume.yml | 219 + .../snowflake/sqlfluff/create_file_format.sql | 8 + .../snowflake/sqlfluff/create_file_format.yml | 32 + .../snowflake/sqlfluff/create_function.sql | 60 + .../snowflake/sqlfluff/create_function.yml | 199 + .../sqlfluff/create_masking_policy.yml | 199 +- .../sqlfluff/create_network_policy.sql | 10 + .../sqlfluff/create_network_policy.yml | 53 +- .../sqlfluff/create_network_rule.sql | 20 + .../sqlfluff/create_network_rule.yml | 107 + .../sqlfluff/create_password_policy.sql | 13 + .../sqlfluff/create_password_policy.yml | 59 + .../snowflake/sqlfluff/create_pipe.yml | 6 +- .../snowflake/sqlfluff/create_procedure.sql | 34 + .../snowflake/sqlfluff/create_procedure.yml | 243 +- .../sqlfluff/create_resource_monitor.sql | 67 +- .../sqlfluff/create_resource_monitor.yml | 464 +- .../snowflake/sqlfluff/create_role.sql | 3 +- .../snowflake/sqlfluff/create_role.yml | 19 +- .../sqlfluff/create_row_access_policy.sql | 29 + .../sqlfluff/create_row_access_policy.yml | 173 + .../snowflake/sqlfluff/create_schema.sql | 3 + .../snowflake/sqlfluff/create_schema.yml | 64 +- .../snowflake/sqlfluff/create_sequence.yml | 10 +- .../snowflake/sqlfluff/create_stage.sql | 56 + .../snowflake/sqlfluff/create_stage.yml | 299 +- .../sqlfluff/create_storage_integration.sql | 4 +- .../sqlfluff/create_storage_integration.yml | 5 + .../snowflake/sqlfluff/create_streamlit.sql | 34 + .../snowflake/sqlfluff/create_streamlit.yml | 146 + .../snowflake/sqlfluff/create_table.sql | 256 + .../snowflake/sqlfluff/create_table.yml | 1719 +- .../snowflake/sqlfluff/create_tag.yml | 9 +- .../snowflake/sqlfluff/create_task.sql | 23 + .../snowflake/sqlfluff/create_task.yml | 141 +- .../snowflake/sqlfluff/create_user.sql | 29 + .../snowflake/sqlfluff/create_user.yml | 139 + .../snowflake/sqlfluff/create_view.sql | 57 + .../snowflake/sqlfluff/create_view.yml | 311 + .../snowflake/sqlfluff/create_warehouse.sql | 15 + .../snowflake/sqlfluff/create_warehouse.yml | 55 + .../snowflake/sqlfluff/current_user.sql | 8 + .../snowflake/sqlfluff/current_user.yml | 95 + .../dialects/snowflake/sqlfluff/datatypes.sql | 25 + .../dialects/snowflake/sqlfluff/datatypes.yml | 180 + .../snowflake/sqlfluff/datetime_intervals.yml | 6 +- .../snowflake/sqlfluff/datetime_units.yml | 279 +- .../dialects/snowflake/sqlfluff/declare.sql | 30 + .../dialects/snowflake/sqlfluff/declare.yml | 228 + .../dialects/snowflake/sqlfluff/delete.yml | 30 +- .../sqlfluff/describe_statements.sql | 8 + .../sqlfluff/describe_statements.yml | 66 +- .../sqlfluff/double_quote_escapes.sql | 10 + .../sqlfluff/double_quote_escapes.yml | 59 + .../snowflake/sqlfluff/drop_dynamic_table.sql | 3 + .../snowflake/sqlfluff/drop_dynamic_table.yml | 19 + .../snowflake/sqlfluff/drop_iceberg_table.sql | 3 + .../snowflake/sqlfluff/drop_iceberg_table.yml | 19 + .../sqlfluff/drop_password_policy.sql | 1 + .../sqlfluff/drop_password_policy.yml | 9 + .../sqlfluff/drop_resource_monitor.sql | 1 + .../sqlfluff/drop_resource_monitor.yml | 11 + .../snowflake/sqlfluff/drop_statements.sql | 8 + .../snowflake/sqlfluff/drop_statements.yml | 55 +- .../dialects/snowflake/sqlfluff/escape.yml | 6 +- .../dialects/snowflake/sqlfluff/exception.sql | 47 + .../dialects/snowflake/sqlfluff/exception.yml | 320 + .../snowflake/sqlfluff/execute_immediate.sql | 4 + .../snowflake/sqlfluff/execute_immediate.yml | 19 +- .../sqlfluff/first_value_ignore_nulls.yml | 3 +- .../snowflake/sqlfluff/for_in_loop.sql | 18 + .../snowflake/sqlfluff/for_in_loop.yml | 119 + .../snowflake/sqlfluff/frame_clause.sql | 8 + .../snowflake/sqlfluff/frame_clause.yml | 58 +- .../snowflake/sqlfluff/grant_revoke.sql | 193 +- .../snowflake/sqlfluff/grant_revoke.yml | 1827 +- .../snowflake/sqlfluff/group_by_all.yml | 3 +- .../sqlfluff/identifier_pseudo_function.yml | 52 +- .../snowflake/sqlfluff/if_statement.sql | 15 + .../snowflake/sqlfluff/if_statement.yml | 104 + .../dialects/snowflake/sqlfluff/insert.yml | 9 +- .../sqlfluff/lateral_flatten_after_join.yml | 6 +- .../dialects/snowflake/sqlfluff/let.sql | 3 + .../dialects/snowflake/sqlfluff/let.yml | 291 +- .../dialects/snowflake/sqlfluff/limit.yml | 6 +- .../snowflake/sqlfluff/match_recognize.yml | 118 +- .../sqlfluff/multiple_shorthand_casts.yml | 3 +- .../dialects/snowflake/sqlfluff/pivot.sql | 73 + .../dialects/snowflake/sqlfluff/pivot.yml | 446 +- .../snowflake/sqlfluff/raise_statement.sql | 6 + .../snowflake/sqlfluff/raise_statement.yml | 24 + .../dialects/snowflake/sqlfluff/return.yml | 30 +- .../dialects/snowflake/sqlfluff/sample.yml | 3 +- .../dialects/snowflake/sqlfluff/select.sql | 18 + .../dialects/snowflake/sqlfluff/select.yml | 106 +- .../snowflake/sqlfluff/select_asof_join.yml | 16 +- .../snowflake/sqlfluff/select_except.sql | 2 +- .../sqlfluff/select_group_by_cube_rollup.yml | 6 +- .../sqlfluff/select_higher_order_function.sql | 13 + .../sqlfluff/select_higher_order_function.yml | 244 + .../snowflake/sqlfluff/select_into.sql | 3 + .../snowflake/sqlfluff/select_into.yml | 61 + .../sqlfluff/select_system_function.sql | 1 + .../sqlfluff/select_system_function.yml | 13 + .../snowflake/sqlfluff/select_union.sql | 11 + .../snowflake/sqlfluff/select_union.yml | 52 + .../snowflake/sqlfluff/semi_structured.yml | 24 +- .../snowflake/sqlfluff/semi_structured_2.yml | 6 +- .../snowflake/sqlfluff/semi_structured_3.yml | 9 +- .../snowflake/sqlfluff/semi_structured_4.sql | 9 + .../snowflake/sqlfluff/semi_structured_4.yml | 168 + .../snowflake/sqlfluff/set_command.sql | 7 + .../snowflake/sqlfluff/set_command.yml | 107 + .../dialects/snowflake/sqlfluff/show.sql | 3 + .../dialects/snowflake/sqlfluff/show.yml | 20 + .../dialects/snowflake/sqlfluff/undrop.sql | 1 + .../dialects/snowflake/sqlfluff/undrop.yml | 13 +- .../dialects/snowflake/sqlfluff/use.yml | 19 +- .../sqlfluff/window_function_ignore_nulls.yml | 3 +- .../snowflake/sqlfluff/within_group.yml | 9 +- .../dialects/sparksql/sqlfluff/add_file.sql | 3 +- .../dialects/sparksql/sqlfluff/add_file.yml | 10 + .../dialects/sparksql/sqlfluff/add_jar.yml | 19 +- .../sparksql/sqlfluff/bytes_literal.yml | 6 +- .../sparksql/sqlfluff/case_clause.yml | 3 +- .../create_table_complex_datatypes.sql | 9 + .../create_table_complex_datatypes.yml | 200 +- .../sqlfluff/create_table_datasource.sql | 12 + .../sqlfluff/create_table_datasource.yml | 115 +- .../sqlfluff/create_table_hiveformat.yml | 78 +- .../create_table_primitive_datatypes.yml | 9 +- .../sqlfluff/create_view_schema_evolution.sql | 3 + .../sqlfluff/create_view_schema_evolution.yml | 36 + .../sqlfluff/databricks_dlt_create_table.yml | 6 +- .../sqlfluff/databricks_dlt_create_view.sql | 38 + .../sqlfluff/databricks_dlt_create_view.yml | 206 +- .../databricks_operator_colon_sign.yml | 6 +- .../sparksql/sqlfluff/date_functions.yml | 31 +- .../sqlfluff/delta_change_data_feed.yml | 9 +- .../sparksql/sqlfluff/delta_create_table.yml | 170 +- .../sparksql/sqlfluff/delta_delete_from.yml | 3 +- .../sparksql/sqlfluff/delta_merge.yml | 15 +- .../sparksql/sqlfluff/delta_update_table.yml | 3 +- .../sparksql/sqlfluff/describe_query.yml | 6 +- .../sparksql/sqlfluff/division_operator.sql | 2 + .../sparksql/sqlfluff/division_operator.yml | 73 + .../sparksql/sqlfluff/drop_schema.yml | 20 +- .../sparksql/sqlfluff/exclamation_mark.sql | 6 + .../sparksql/sqlfluff/exclamation_mark.yml | 48 + .../dialects/sparksql/sqlfluff/explain.yml | 18 +- .../sparksql/sqlfluff/from_supported_tvf.yml | 3 +- .../sqlfluff/iceberg_create_table.yml | 27 +- .../sqlfluff/insert_overwrite_directory.yml | 11 - .../sparksql/sqlfluff/insert_table.sql | 28 + .../sparksql/sqlfluff/insert_table.yml | 183 + .../dialects/sparksql/sqlfluff/list_file.sql | 3 +- .../dialects/sparksql/sqlfluff/list_file.yml | 10 + .../dialects/sparksql/sqlfluff/literals.yml | 102 +- .../dialects/sparksql/sqlfluff/merge_into.yml | 3 +- .../sparksql/sqlfluff/parse_integer_type.yml | 6 +- .../sqlfluff/parse_timestamp_ltz_ntz_type.yml | 14 +- .../sparksql/sqlfluff/pivot_clause.yml | 129 +- .../sparksql/sqlfluff/raw_literal.sql | 4 + .../sparksql/sqlfluff/raw_literal.yml | 45 + .../sparksql/sqlfluff/select_cluster_by.yml | 3 +- .../sqlfluff/select_delimited_identifier.yml | 6 +- ...ited_identifier_with_escaped_backticks.yml | 9 +- .../sqlfluff/select_distribute_by.yml | 3 +- .../sqlfluff/select_from_lateral_view.yml | 578 +- .../sparksql/sqlfluff/select_from_values.yml | 12 +- .../sparksql/sqlfluff/select_group_by.yml | 54 +- .../sparksql/sqlfluff/select_having.yml | 18 +- .../sparksql/sqlfluff/select_hints.yml | 240 - .../select_lateral_view_supported_tvf.sql | 7 + .../select_lateral_view_supported_tvf.yml | 572 +- .../sparksql/sqlfluff/select_like_clause.yml | 51 +- .../sparksql/sqlfluff/select_qualify.yml | 24 +- .../sparksql/sqlfluff/select_reduce.yml | 3 +- .../sparksql/sqlfluff/select_sort_by.yml | 69 +- .../sparksql/sqlfluff/select_tablesample.yml | 9 +- .../sparksql/sqlfluff/select_union.yml | 3 +- .../sparksql/sqlfluff/set_variable.yml | 246 +- .../sparksql/sqlfluff/structure_accessor.sql | 4 + .../sparksql/sqlfluff/structure_accessor.yml | 55 + .../sparksql/sqlfluff/table_alias.yml | 12 +- .../sparksql/sqlfluff/unpivot_clause.yml | 300 +- .../sparksql/sqlfluff/values_with_alias.yml | 15 +- .../sparksql/sqlfluff/window_functions.yml | 240 +- .../dialects/sqlite/sqlfluff/alter.sql | 13 - .../dialects/sqlite/sqlfluff/alter_table.sql | 15 + .../sqlfluff/{alter.yml => alter_table.yml} | 64 +- .../sqlite/sqlfluff/arithmetric_a.yml | 12 +- .../sqlfluff/block_comment_end_of_input.sql | 4 + .../sqlfluff/block_comment_end_of_input.yml | 1 + .../sqlite/sqlfluff/conflict_clause.sql | 12 + .../sqlite/sqlfluff/conflict_clause.yml | 93 + .../dialects/sqlite/sqlfluff/create_index.yml | 18 +- .../dialects/sqlite/sqlfluff/create_table.sql | 13 + .../dialects/sqlite/sqlfluff/create_table.yml | 69 + .../create_table_constraint_generated.sql | 15 + .../create_table_constraint_generated.yml | 172 + .../sqlfluff/create_table_deferrable.sql | 12 +- .../sqlfluff/create_table_table_end.sql | 1 - .../sqlite/sqlfluff/create_table_unsigned.sql | 5 + .../sqlite/sqlfluff/create_table_unsigned.yml | 56 + .../sqlite/sqlfluff/create_trigger.sql | 11 + .../sqlite/sqlfluff/create_trigger.yml | 102 +- .../dialects/sqlite/sqlfluff/create_view.sql | 11 + .../dialects/sqlite/sqlfluff/create_view.yml | 91 + .../sqlfluff/create_virtual_table_check.sql | 21 + .../sqlfluff/create_virtual_table_check.yml | 113 + .../dialects/sqlite/sqlfluff/delete.sql | 9 +- .../dialects/sqlite/sqlfluff/delete.yml | 46 +- .../dialects/sqlite/sqlfluff/insert.sql | 15 +- .../dialects/sqlite/sqlfluff/insert.yml | 212 +- .../dialects/sqlite/sqlfluff/is_clause.sql | 19 + .../dialects/sqlite/sqlfluff/is_clause.yml | 156 + .../dialects/sqlite/sqlfluff/json_keys.sql | 1 + .../dialects/sqlite/sqlfluff/json_keys.yml | 71 + .../sqlite/sqlfluff/json_operators.sql | 20 + .../sqlite/sqlfluff/json_operators.yml | 226 + .../sqlite/sqlfluff/named_parameters.sql | 22 + .../sqlite/sqlfluff/named_parameters.yml | 145 + .../dialects/sqlite/sqlfluff/over_clause.sql | 79 + .../dialects/sqlite/sqlfluff/over_clause.yml | 1044 + .../sqlite/sqlfluff/pattern_matching.sql | 46 + .../sqlite/sqlfluff/pattern_matching.yml | 326 + .../sqlite/sqlfluff/quoted_identifiers.sql | 9 + .../sqlite/sqlfluff/quoted_identifiers.yml | 64 + .../sqlite/sqlfluff/raise_function.sql | 5 + .../sqlite/sqlfluff/raise_function.yml | 33 + .../dialects/sqlite/sqlfluff/select.yml | 18 +- .../dialects/sqlite/sqlfluff/update.sql | 14 +- .../dialects/sqlite/sqlfluff/update.yml | 263 +- .../dialects/sqlite/sqlfluff/upsert.sql | 19 + .../dialects/sqlite/sqlfluff/upsert.yml | 241 + .../dialects/sqlite/sqlfluff/window.sql | 10 - .../dialects/sqlite/sqlfluff/window.yml | 113 - .../dialects/trino/sqlfluff/alter_table.sql | 35 + .../dialects/trino/sqlfluff/alter_table.yml | 424 + .../dialects/trino/sqlfluff/analyze.yml | 52 +- .../dialects/trino/sqlfluff/array.yml | 66 +- .../trino/sqlfluff/bare_functions.yml | 15 +- .../dialects/trino/sqlfluff/comment_on.yml | 87 +- .../dialects/trino/sqlfluff/commit.sql | 3 + .../dialects/trino/sqlfluff/commit.yml | 10 + .../dialects/trino/sqlfluff/create_table.sql | 76 + .../dialects/trino/sqlfluff/create_table.yml | 471 + .../trino/sqlfluff/filter_aggregate.yml | 3 +- .../dialects/trino/sqlfluff/grouping_sets.yml | 3 +- .../dialects/trino/sqlfluff/insert.sql | 7 + .../dialects/trino/sqlfluff/insert.yml | 99 + .../dialects/trino/sqlfluff/integer_types.yml | 15 +- .../trino/sqlfluff/json_functions.yml | 16 +- .../dialects/trino/sqlfluff/range_offset.yml | 3 +- .../sqlfluff/regexp_replace_with_lambda.yml | 69 +- .../dialects/trino/sqlfluff/rollback.sql | 3 + .../dialects/trino/sqlfluff/rollback.yml | 10 + .../dialects/trino/sqlfluff/row_datatype.yml | 60 +- .../dialects/trino/sqlfluff/set_session.sql | 3 + .../dialects/trino/sqlfluff/set_session.yml | 23 + .../trino/sqlfluff/start_transaction.sql | 5 + .../trino/sqlfluff/start_transaction.yml | 45 + .../trino/sqlfluff/timestamp_resolutions.yml | 81 +- .../trino/sqlfluff/unnest_with_ordinality.yml | 47 +- .../dialects/trino/sqlfluff/within_group.yml | 150 +- .../fixtures/dialects/tsql/sqlfluff/.sqlfluff | 2 + .../dialects/tsql/sqlfluff/add_index.sql | 80 + .../dialects/tsql/sqlfluff/add_index.yml | 544 + .../sqlfluff/al05_alias_in_where_clause.sql | 15 - .../sqlfluff/al05_alias_in_where_clause.yml | 130 - .../tsql/sqlfluff/al05_exact_issue.sql | 5 - .../tsql/sqlfluff/al05_exact_issue.yml | 74 - .../tsql/sqlfluff/alias_equals_syntax.sql | 3 - .../tsql/sqlfluff/alias_standard_as.sql | 3 - .../dialects/tsql/sqlfluff/alter_and_drop.sql | 5 + .../dialects/tsql/sqlfluff/alter_and_drop.yml | 48 + .../dialects/tsql/sqlfluff/alter_database.sql | 110 + .../dialects/tsql/sqlfluff/alter_database.yml | 532 + .../dialects/tsql/sqlfluff/alter_index.sql | 75 + .../dialects/tsql/sqlfluff/alter_index.yml | 617 + .../dialects/tsql/sqlfluff/alter_table.sql | 163 + .../dialects/tsql/sqlfluff/alter_table.yml | 1194 + .../tsql/sqlfluff/alter_table_switch.sql | 17 + .../tsql/sqlfluff/alter_table_switch.yml | 133 + .../dialects/tsql/sqlfluff/apply_simple.sql | 1 - .../dialects/tsql/sqlfluff/apply_simple.yml | 24 - .../tsql/sqlfluff/apply_with_alias.sql | 14 - .../tsql/sqlfluff/apply_with_alias.yml | 96 - .../tsql/sqlfluff/arithmetic_operations.sql | 11 + .../tsql/sqlfluff/arithmetic_operations.yml | 128 + .../dialects/tsql/sqlfluff/begin_end.sql | 15 + .../dialects/tsql/sqlfluff/begin_end.yml | 50 + .../tsql/sqlfluff/begin_end_block.sql | 4 - .../tsql/sqlfluff/begin_end_block.yml | 34 - .../tsql/sqlfluff/begin_end_nested.sql | 5 + .../tsql/sqlfluff/begin_end_nested.yml | 18 + .../tsql/sqlfluff/begin_end_no_semicolon.sql | 3 + .../tsql/sqlfluff/begin_end_no_semicolon.yml | 12 + .../tsql/sqlfluff/binary_constants.sql | 17 + .../tsql/sqlfluff/binary_constants.yml | 74 + .../sqlfluff/binary_constants_functions.sql | 12 + .../sqlfluff/binary_constants_functions.yml | 134 + .../sqlfluff/binary_constants_variables.sql | 14 + .../sqlfluff/binary_constants_variables.yml | 90 + .../dialects/tsql/sqlfluff/bulk_insert.sql | 13 + .../dialects/tsql/sqlfluff/bulk_insert.yml | 52 + .../dialects/tsql/sqlfluff/cast_variable.sql | 7 + .../dialects/tsql/sqlfluff/cast_variable.yml | 123 + .../dialects/tsql/sqlfluff/collate.sql | 22 + .../dialects/tsql/sqlfluff/collate.yml | 145 + .../dialects/tsql/sqlfluff/comment_blocks.sql | 5 +- .../dialects/tsql/sqlfluff/comment_blocks.yml | 28 +- .../comprehensive_hash_identifiers.sql | 7 - .../comprehensive_hash_identifiers.yml | 40 - .../dialects/tsql/sqlfluff/convert.sql | 4 + .../dialects/tsql/sqlfluff/convert.yml | 56 + .../fixtures/dialects/tsql/sqlfluff/copy.sql | 53 + .../fixtures/dialects/tsql/sqlfluff/copy.yml | 272 + .../sqlfluff/create_columnstore_index.sql | 23 + .../sqlfluff/create_columnstore_index.yml | 195 + .../tsql/sqlfluff/create_database.sql | 154 + .../tsql/sqlfluff/create_database.yml | 889 + .../create_database_scoped_credential.sql | 4 + .../create_database_scoped_credential.yml | 35 + .../sqlfluff/create_external_data_source.sql | 20 + .../sqlfluff/create_external_data_source.yml | 89 + .../sqlfluff/create_external_file_format.sql | 54 + .../sqlfluff/create_external_file_format.yml | 202 + .../tsql/sqlfluff/create_external_table.sql | 46 + .../tsql/sqlfluff/create_external_table.yml | 341 + .../tsql/sqlfluff/create_fulltext_catalog.sql | 22 + .../tsql/sqlfluff/create_fulltext_catalog.yml | 107 + .../tsql/sqlfluff/create_fulltext_index.sql | 132 + .../tsql/sqlfluff/create_fulltext_index.yml | 692 + .../tsql/sqlfluff/create_function.sql | 62 + .../tsql/sqlfluff/create_function.yml | 535 + .../dialects/tsql/sqlfluff/create_login.sql | 35 + .../dialects/tsql/sqlfluff/create_login.yml | 171 + .../tsql/sqlfluff/create_master_key.sql | 19 + .../tsql/sqlfluff/create_master_key.yml | 98 + .../sqlfluff/create_partition_function.sql | 23 + .../sqlfluff/create_partition_function.yml | 166 + .../tsql/sqlfluff/create_partition_scheme.sql | 17 + .../tsql/sqlfluff/create_partition_scheme.yml | 79 + .../tsql/sqlfluff/create_procedure.yml | 1452 +- .../dialects/tsql/sqlfluff/create_role.sql | 2 + .../dialects/tsql/sqlfluff/create_role.yml | 19 + .../dialects/tsql/sqlfluff/create_schema.sql | 6 + .../dialects/tsql/sqlfluff/create_schema.yml | 23 + .../tsql/sqlfluff/create_security_policy.sql | 53 + .../tsql/sqlfluff/create_security_policy.yml | 301 + .../tsql/sqlfluff/create_server_role.sql | 3 + .../tsql/sqlfluff/create_server_role.yml | 21 + .../dialects/tsql/sqlfluff/create_table.sql | 39 + .../dialects/tsql/sqlfluff/create_table.yml | 292 + .../tsql/sqlfluff/create_table_as_select.sql | 55 + .../tsql/sqlfluff/create_table_as_select.yml | 383 + .../sqlfluff/create_table_constraints.sql | 43 + .../sqlfluff/create_table_constraints.yml | 354 + .../tsql/sqlfluff/create_table_graph.sql | 27 + .../tsql/sqlfluff/create_table_graph.yml | 134 + .../sqlfluff/create_table_on_filegroup.sql | 5 + .../sqlfluff/create_table_on_filegroup.yml | 51 + .../create_table_with_distribution.sql | 65 + .../create_table_with_distribution.yml | 538 + .../sqlfluff/create_table_with_sequence.sql | 7 + .../sqlfluff/create_table_with_sequence.yml | 69 + .../create_table_with_sequence_bracketed.sql | 61 + .../create_table_with_sequence_bracketed.yml | 664 + ...create_table_with_table_option_segment.sql | 53 + ...create_table_with_table_option_segment.yml | 294 + .../create_table_with_trailing_comma.sql | 3 + .../create_table_with_trailing_comma.yml | 22 + .../dialects/tsql/sqlfluff/create_type.sql | 7 + .../dialects/tsql/sqlfluff/create_type.yml | 44 + .../dialects/tsql/sqlfluff/create_user.sql | 32 + .../dialects/tsql/sqlfluff/create_user.yml | 168 + .../dialects/tsql/sqlfluff/create_view.sql | 57 + .../dialects/tsql/sqlfluff/create_view.yml | 521 + .../sqlfluff/create_view_with_columns.sql | 9 + .../sqlfluff/create_view_with_columns.yml | 35 + .../tsql/sqlfluff/create_view_with_cte.sql | 17 + .../tsql/sqlfluff/create_view_with_cte.yml | 137 + .../tsql/sqlfluff/create_view_with_pivot.sql | 15 + .../tsql/sqlfluff/create_view_with_pivot.yml | 113 + .../create_view_with_set_statements.sql | 36 + .../create_view_with_set_statements.yml | 215 + .../sqlfluff/create_view_with_unpivot.sql | 11 + .../sqlfluff/create_view_with_unpivot.yml | 98 + .../sqlfluff/cross_apply_with_function.sql | 10 - .../sqlfluff/cross_apply_with_function.yml | 63 - .../fixtures/dialects/tsql/sqlfluff/cte_s.sql | 10 + .../fixtures/dialects/tsql/sqlfluff/cte_s.yml | 83 + .../dialects/tsql/sqlfluff/cte_with_join.sql | 6 - .../dialects/tsql/sqlfluff/cte_with_join.yml | 64 - .../dialects/tsql/sqlfluff/cursor.sql | 18 + .../dialects/tsql/sqlfluff/cursor.yml | 82 + .../dialects/tsql/sqlfluff/data_types.sql | 187 + .../dialects/tsql/sqlfluff/data_types.yml | 1116 + .../dialects/tsql/sqlfluff/data_types_max.sql | 13 - .../dialects/tsql/sqlfluff/data_types_max.yml | 73 - .../dialects/tsql/sqlfluff/date_functions.sql | 21 + .../dialects/tsql/sqlfluff/date_functions.yml | 119 + .../dialects/tsql/sqlfluff/datepart.sql | 2 + .../dialects/tsql/sqlfluff/datepart.yml | 33 + .../dialects/tsql/sqlfluff/datetrunc.sql | 4 + .../dialects/tsql/sqlfluff/datetrunc.yml | 73 + .../tsql/sqlfluff/declare_table_type.sql | 18 +- .../tsql/sqlfluff/declare_table_type.yml | 137 +- .../declare_table_variable_complex.sql | 8 - .../declare_table_variable_complex.yml | 69 - .../tsql/sqlfluff/declare_variable.sql | 1 - .../tsql/sqlfluff/declare_variable.yml | 11 - .../declare_with_following_statements.sql | 24 + .../declare_with_following_statements.yml | 156 + .../dialects/tsql/sqlfluff/delete.sql | 107 + .../dialects/tsql/sqlfluff/delete.yml | 662 + .../delete_azure_synapse_analytics.sql | 35 + .../delete_azure_synapse_analytics.yml | 301 + .../tsql/sqlfluff/dml_as_derived_table.sql | 36 + .../tsql/sqlfluff/dml_as_derived_table.yml | 241 + .../tsql/sqlfluff/drop_external_table.sql | 7 + .../tsql/sqlfluff/drop_external_table.yml | 32 + .../dialects/tsql/sqlfluff/drop_function.sql | 2 + .../dialects/tsql/sqlfluff/drop_function.yml | 23 + .../dialects/tsql/sqlfluff/drop_procedure.yml | 67 +- .../dialects/tsql/sqlfluff/drop_table.sql | 11 + .../dialects/tsql/sqlfluff/drop_table.yml | 54 + .../dialects/tsql/sqlfluff/drop_user.sql | 3 + .../dialects/tsql/sqlfluff/drop_user.yml | 18 + .../dialects/tsql/sqlfluff/drop_view.sql | 11 + .../dialects/tsql/sqlfluff/drop_view.yml | 54 + .../dialects/tsql/sqlfluff/execute.sql | 139 + .../dialects/tsql/sqlfluff/execute.yml | 790 + .../tsql/sqlfluff/fetch_cursor_statement.sql | 98 + .../tsql/sqlfluff/fetch_cursor_statement.yml | 354 + .../tsql/sqlfluff/function_default_params.sql | 6 + .../tsql/sqlfluff/function_default_params.yml | 44 + .../tsql/sqlfluff/function_no_return.sql | 14 + .../tsql/sqlfluff/function_no_return.yml | 109 + .../tsql/sqlfluff/function_with_variable.sql | 8 + .../tsql/sqlfluff/function_with_variable.yml | 55 + .../dialects/tsql/sqlfluff/functions_a.sql | 47 + .../dialects/tsql/sqlfluff/functions_a.yml | 280 + .../dialects/tsql/sqlfluff/functions_agg.sql | 13 + .../dialects/tsql/sqlfluff/functions_agg.yml | 158 + .../dialects/tsql/sqlfluff/go_delimiters.sql | 8 + .../dialects/tsql/sqlfluff/go_delimiters.yml | 64 + .../dialects/tsql/sqlfluff/goto_statement.sql | 3 + .../dialects/tsql/sqlfluff/goto_statement.yml | 14 + .../tsql/sqlfluff/grant_deny_revoke.sql | 38 + .../tsql/sqlfluff/grant_deny_revoke.yml | 216 + .../dialects/tsql/sqlfluff/group_by.sql | 16 + .../dialects/tsql/sqlfluff/group_by.yml | 118 + .../fixtures/dialects/tsql/sqlfluff/hints.sql | 112 + .../fixtures/dialects/tsql/sqlfluff/hints.yml | 1023 + .../tsql/sqlfluff/identifier_hash_end.sql | 11 - .../sqlfluff/identifier_special_chars.sql | 30 + .../sqlfluff/identifier_special_chars.yml | 221 + .../dialects/tsql/sqlfluff/if_else.sql | 12 + .../dialects/tsql/sqlfluff/if_else.yml | 161 + .../tsql/sqlfluff/if_else_begin_end.sql | 12 + .../tsql/sqlfluff/if_else_begin_end.yml | 119 + .../dialects/tsql/sqlfluff/ignore_nulls.sql | 9 + .../dialects/tsql/sqlfluff/ignore_nulls.yml | 49 + .../tsql/sqlfluff/implicit_alias_test.sql | 3 - .../tsql/sqlfluff/inline_comments.sql | 5 - .../dialects/tsql/sqlfluff/insert_default.sql | 3 + .../dialects/tsql/sqlfluff/insert_default.yml | 11 + .../tsql/sqlfluff/insert_statement.sql | 57 + .../tsql/sqlfluff/insert_statement.yml | 461 + .../sqlfluff/insert_with_identity_insert.sql | 8 + .../sqlfluff/insert_with_identity_insert.yml | 41 + .../dialects/tsql/sqlfluff/join_hints.sql | 17 + .../dialects/tsql/sqlfluff/join_hints.yml | 117 + .../dialects/tsql/sqlfluff/json_functions.sql | 31 + .../dialects/tsql/sqlfluff/json_functions.yml | 500 + .../sqlfluff/keyword_identifier_usage.sql | 117 + .../sqlfluff/keyword_identifier_usage.yml | 753 + .../fixtures/dialects/tsql/sqlfluff/merge.sql | 202 + .../fixtures/dialects/tsql/sqlfluff/merge.yml | 1501 ++ .../tsql/sqlfluff/minimal_function.sql | 5 + .../tsql/sqlfluff/minimal_function.yml | 39 + .../sqlfluff/minimal_function_no_alter.sql | 7 + .../sqlfluff/minimal_function_no_alter.yml | 37 + .../tsql/sqlfluff/multi_statement.sql | 3 + .../tsql/sqlfluff/multi_statement.yml | 20 + .../multi_statement_without_semicolon.sql | 4 + .../multi_statement_without_semicolon.yml | 35 + .../tsql/sqlfluff/multiple_semicolons.sql | 17 + .../tsql/sqlfluff/multiple_semicolons.yml | 132 + .../dialects/tsql/sqlfluff/nested_joins.sql | 36 + .../dialects/tsql/sqlfluff/nested_joins.yml | 382 + .../dialects/tsql/sqlfluff/offset.sql | 16 + .../dialects/tsql/sqlfluff/offset.yml | 100 + .../tsql/sqlfluff/open_symmetric_key.sql | 20 + .../tsql/sqlfluff/open_symmetric_key.yml | 148 + .../dialects/tsql/sqlfluff/openjson.sql | 52 + .../dialects/tsql/sqlfluff/openjson.yml | 472 + .../dialects/tsql/sqlfluff/openquery.sql | 10 + .../dialects/tsql/sqlfluff/openquery.yml | 80 + .../dialects/tsql/sqlfluff/openrowset.sql | 74 + .../dialects/tsql/sqlfluff/openrowset.yml | 452 + .../dialects/tsql/sqlfluff/openxml.sql | 39 + .../dialects/tsql/sqlfluff/openxml.yml | 220 + .../dialects/tsql/sqlfluff/outer_apply.sql | 7 + .../dialects/tsql/sqlfluff/outer_apply.yml | 57 + .../dialects/tsql/sqlfluff/output_clause.sql | 165 + .../dialects/tsql/sqlfluff/output_clause.yml | 936 + .../fixtures/dialects/tsql/sqlfluff/print.sql | 8 + .../fixtures/dialects/tsql/sqlfluff/print.yml | 57 + .../dialects/tsql/sqlfluff/raiserror.sql | 42 + .../dialects/tsql/sqlfluff/raiserror.yml | 154 + .../dialects/tsql/sqlfluff/reconfigure.sql | 3 + .../dialects/tsql/sqlfluff/reconfigure.yml | 12 + .../dialects/tsql/sqlfluff/rename_table.sql | 2 + .../dialects/tsql/sqlfluff/rename_table.yml | 13 + .../dialects/tsql/sqlfluff/replicate.sql | 6 + .../dialects/tsql/sqlfluff/replicate.yml | 129 + .../dialects/tsql/sqlfluff/select.sql | 120 + .../dialects/tsql/sqlfluff/select.yml | 1001 +- .../tsql/sqlfluff/select_assign_parameter.sql | 38 + .../tsql/sqlfluff/select_assign_parameter.yml | 311 + .../tsql/sqlfluff/select_cross_apply.sql | 25 + .../tsql/sqlfluff/select_cross_apply.yml | 293 + .../tsql/sqlfluff/select_date_functions.sql | 26 + .../tsql/sqlfluff/select_date_functions.yml | 383 + .../dialects/tsql/sqlfluff/select_for.sql | 65 + .../dialects/tsql/sqlfluff/select_for.yml | 387 + .../dialects/tsql/sqlfluff/select_into.sql | 12 + .../dialects/tsql/sqlfluff/select_into.yml | 54 + .../tsql/sqlfluff/select_named_window.sql | 61 + .../tsql/sqlfluff/select_named_window.yml | 607 + .../tsql/sqlfluff/select_natural_join.sql | 7 + .../tsql/sqlfluff/select_natural_join.yml | 51 + .../dialects/tsql/sqlfluff/select_pivot.sql | 23 + .../dialects/tsql/sqlfluff/select_pivot.yml | 223 + .../dialects/tsql/sqlfluff/select_top.yml | 446 +- .../tsql/sqlfluff/select_top_percent.sql | 1 - .../dialects/tsql/sqlfluff/sequence.sql | 14 + .../dialects/tsql/sqlfluff/sequence.yml | 60 + .../tsql/sqlfluff/set_context_info.sql | 7 + .../tsql/sqlfluff/set_context_info.yml | 81 + .../dialects/tsql/sqlfluff/set_language.sql | 4 + .../dialects/tsql/sqlfluff/set_language.yml | 26 + .../tsql/sqlfluff/set_local_variable.sql | 97 + .../tsql/sqlfluff/set_local_variable.yml | 489 + .../dialects/tsql/sqlfluff/set_statements.sql | 3 + .../dialects/tsql/sqlfluff/set_statements.yml | 28 + .../dialects/tsql/sqlfluff/sqlcmd_command.sql | 13 + .../dialects/tsql/sqlfluff/sqlcmd_command.yml | 36 + .../sqlfluff/square_bracket_identifiers.sql | 1 - .../sqlfluff/square_bracket_identifiers.yml | 21 - .../sqlfluff/stored_procedure_begin_end.yml | 527 +- .../tsql/sqlfluff/stored_procedure_simple.yml | 40 +- .../stored_procedure_single_statement.yml | 563 +- .../stored_procedured_mixed_statements.yml | 271 +- .../tsql/sqlfluff/string_agg_within_group.sql | 46 - .../tsql/sqlfluff/string_agg_within_group.yml | 368 - .../dialects/tsql/sqlfluff/synonym.sql | 14 + .../dialects/tsql/sqlfluff/synonym.yml | 53 + .../tsql/sqlfluff/system-variables.sql | 19 + .../tsql/sqlfluff/system-variables.yml | 98 + .../tsql/sqlfluff/table_object_references.sql | 9 +- .../tsql/sqlfluff/table_object_references.yml | 95 +- .../tsql/sqlfluff/table_variable_simple.sql | 1 - .../tsql/sqlfluff/table_variables.sql | 7 +- .../tsql/sqlfluff/table_variables.yml | 80 +- .../table_variables_comprehensive.sql | 14 - .../dialects/tsql/sqlfluff/tablesample.sql | 11 + .../dialects/tsql/sqlfluff/tablesample.yml | 108 + .../dialects/tsql/sqlfluff/temp_tables.sql | 9 + .../dialects/tsql/sqlfluff/temp_tables.yml | 48 + .../tsql/sqlfluff/temporal_tables.sql | 153 + .../tsql/sqlfluff/temporal_tables.yml | 998 + .../dialects/tsql/sqlfluff/transaction.sql | 17 + .../dialects/tsql/sqlfluff/transaction.yml | 87 + .../dialects/tsql/sqlfluff/triggers.sql | 139 + .../dialects/tsql/sqlfluff/triggers.yml | 735 + .../dialects/tsql/sqlfluff/try_catch.sql | 21 + .../dialects/tsql/sqlfluff/try_catch.yml | 89 + .../tsql/sqlfluff/tsql_alias_column_ref.sql | 13 - .../tsql/sqlfluff/tsql_alias_column_ref.yml | 65 - .../tsql/sqlfluff/tsql_alias_simple.sql | 2 - .../dialects/tsql/sqlfluff/update.sql | 19 + .../dialects/tsql/sqlfluff/update.yml | 134 + .../dialects/tsql/sqlfluff/waitfor.sql | 14 + .../dialects/tsql/sqlfluff/waitfor.yml | 65 + .../tsql/sqlfluff/while_statement.sql | 9 + .../tsql/sqlfluff/while_statement.yml | 63 + .../tsql/sqlfluff/window_functions.sql | 24 + .../tsql/sqlfluff/window_functions.yml | 329 + 1834 files changed, 178124 insertions(+), 43672 deletions(-) create mode 100644 crates/lib-dialects/src/hive_keywords.rs create mode 100644 crates/lib-dialects/src/mysql_keywords.rs create mode 100644 crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/double_quote_escapes.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/double_quote_escapes.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_schema_a.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_schema_a.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/multiple_semicolons.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/multiple_semicolons.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/obevo.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/obevo.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_offset.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_offset.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_schema.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_schema.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_key.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_key.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_constraint.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_constraint.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_key.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_key.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_set_default_collate.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_set_default_collate.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_various_resources.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_various_resources.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_view_alter_column.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_view_alter_column.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/begin.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/begin.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_assignment.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_assignment.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_capacity.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_capacity.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_with_args.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_with_args.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_index.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_index.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_materialized_view_as_replica_of.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_materialized_view_as_replica_of.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_reservation.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_reservation.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_row_access_policy.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_row_access_policy.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_schema.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_schema.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_snapshot_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_snapshot_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_default_collate.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_default_collate.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_function.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_keys.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_keys.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_function.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_procedure.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_procedure.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_schema.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_schema.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table_function.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_various_resources.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_various_resources.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/execute_immediate.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/execute_immediate.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/handle_exception.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/handle_exception.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/load_data_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/load_data_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/pipe_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/pipe_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_group_by.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_group_by.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_cast.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_cast.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_user.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_user.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/parametric_aggregate_functions.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/parametric_aggregate_functions.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/clickhouse/sqruff/alter_table.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/clickhouse/sqruff/alter_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_database.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_database.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_volume.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_volume.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/command_terminator.sql rename crates/lib-dialects/test/fixtures/dialects/{tsql/sqlfluff/identifier_hash_end.yml => databricks/sqlfluff/command_terminator.yml} (57%) create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_database.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_database.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_function.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_private_materialized_view.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_private_materialized_view.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_volume.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_volume.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/databricks_keywords.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/grant_permissions.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/grant_permissions.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/insert_by_name.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/insert_by_name.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_line.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_line.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_single_line.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_single_line.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/named_argument.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/named_argument.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/revoke_permissions.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/revoke_permissions.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_lateral_view.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_lateral_view.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_read_file.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_read_file.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_tags.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_tags.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/anti_semi_join.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/anti_semi_join.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/asof_join.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/asof_join.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/copy.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/copy.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_macro.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_macro.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_type.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_type.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_view.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_view.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/describe.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/double_equal.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/double_equal.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/drop_macro.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/drop_macro.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/extract_temporal.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/extract_temporal.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/filter.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/filter.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/from_first.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/from_first.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/in_operator.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/in_operator.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/insert.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/insert.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/json_operators.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/json_operators.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_comprehension.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_comprehension.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/load_statement.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/load_statement.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/macro.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/macro.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/pivot.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/pivot.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/positional_join.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/positional_join.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/qualify.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/qualify.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_columns.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_columns.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_exclude_replace.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_exclude_replace.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_lambda.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_lambda.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/star_expression.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/star_expression.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/structs.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/structs.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/summarize.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/unpivot.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/unpivot.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/walrus_operator_function.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/walrus_operator_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/.sqlfluff create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_database.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_database.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_schema.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_schema.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_view.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_view.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/array_types.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/array_types.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_database.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_database.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_schema.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_schema.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_as_select.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_as_select.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_clustered_by.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_clustered_by.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_constraints.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_constraints.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_datatypes.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_datatypes.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_external_partitioned.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_external_partitioned.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_like.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_like.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_delimited.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_delimited.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_serde.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_serde.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_skewed_by.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_skewed_by.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_external.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_external.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_properties.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_properties.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_with.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_with.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/double_equals.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/double_equals.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_database.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_database.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_schema.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_schema.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_partition.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_partition.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_values.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_values.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_directory.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_directory.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_dynamic_partition.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_dynamic_partition.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_partition.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_partition.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_repair_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_repair_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/quoted_literal.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/quoted_literal.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cast.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cast.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cluster_distribute_sort_by.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cluster_distribute_sort_by.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_interval.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_interval.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_lateral_view.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_lateral_view.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_left_semi_join.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_left_semi_join.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_regexp.sql rename crates/lib-dialects/test/fixtures/dialects/{tsql/sqlfluff/table_variables_comprehensive.yml => hive/sqlfluff/select_regexp.yml} (52%) create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_sampling_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_sampling_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/set.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/set.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/truncate_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/truncate_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/use.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/use.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_database.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_database.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_event.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_event.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_view.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_view.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/analyze_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/analyze_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/begin.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/begin.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/bit_value_literal.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/bit_value_literal.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/call_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/call_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_constraint.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_constraint.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/checksum_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/checksum_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close_qualified.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close_qualified.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/collate.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/collate.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/column_alias.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/column_alias.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_database.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_database.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_event.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_event.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_index.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_index.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_procedure.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_procedure.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_role.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_role.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_column_charset.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_column_charset.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_constraint_unique.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_constraint_unique.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_datetime.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_datetime.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_equals_optional.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_equals_optional.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_generated_column.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_generated_column.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_index.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_index.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_null_position.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_null_position.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_primary_foreign_keys.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_primary_foreign_keys.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_unique_key.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_unique_key.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_trigger.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_trigger.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_user.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_user.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_view.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_view.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/deallocate_prepare.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/deallocate_prepare.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_condition.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_condition.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_continue_handler_sqlexception.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_continue_handler_sqlexception.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_cursor.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_cursor.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_numeric.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_numeric.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_quotedliteral.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_quotedliteral.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_exit_handler_sqlexception.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_exit_handler_sqlexception.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_local_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_local_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_undo_handler_sqlexception.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_undo_handler_sqlexception.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delete_multitable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delete_multitable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_function.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_procedure.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_procedure.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_select.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_select.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/derived_tables.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/derived_tables.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_event.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_event.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_function.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_algorithm.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_algorithm.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_lock.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_lock.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_prepare.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_prepare.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_procedure.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_procedure.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_trigger.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_trigger.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using_multiple_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using_multiple_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/explain.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/explain.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_from.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_from.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_multiple.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_multiple.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_next_from.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_next_from.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session_multiple.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session_multiple.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/flush.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/flush.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index.sql rename crates/lib-dialects/test/fixtures/dialects/{tsql/sqlfluff/implicit_alias_test.yml => mysql/sqlfluff/force_index.yml} (53%) create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_group_by.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_group_by.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_join.sql rename crates/lib-dialects/test/fixtures/dialects/{tsql/sqlfluff/alias_equals_syntax.yml => mysql/sqlfluff/force_index_for_join.yml} (53%) create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_order_by.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_order_by.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_inner_join.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_inner_join.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_left_join.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_left_join.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_key.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_key.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_comment.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_comment.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_definer.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_definer.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_modifies_sql.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_modifies_sql.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_no_sql.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_no_sql.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_notdeterministic.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_notdeterministic.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_reads_sql.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_reads_sql.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_return.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_return.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_definer.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_definer.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_invoker.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_invoker.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_local_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_local_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_multiple_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_multiple_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_session_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_session_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_local_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_local_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_numeric.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_numeric.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_session_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_session_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_number.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_number.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_row_count.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_row_count.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/grant.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/grant.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_condition_name.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_condition_name.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_continue_sqlexception.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_error_code.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_error_code.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_exit_sqlexception.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_not_found.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_not_found.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate_value.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate_value.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlwarning.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlwarning.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_undo_sqlexception.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/help_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/help_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/hexadecimal_literal.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/hexadecimal_literal.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_else.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_else.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_elseif.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_elseif.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_multiple_expression.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_multiple_expression.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_nested.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_nested.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_session_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_session_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_subquery_expression.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_subquery_expression.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_group_by.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_group_by.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_join.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_join.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_order_by.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_order_by.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_key.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_key.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/insert.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/insert.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/interval.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/interval.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/json.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/json.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/load_data.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/load_data.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_label.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_label.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_multiple_statements.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_multiple_statements.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_no_label.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_no_label.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/nested_begin.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/nested_begin.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/null_safe_equal.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/null_safe_equal.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open_qualified.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open_qualified.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/optimize_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/optimize_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_local_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_local_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_session_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_session_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_definer.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_definer.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_in_param.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_in_param.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_inout_param.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_inout_param.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_out_param.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_out_param.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/purge_binary_logs.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/purge_binary_logs.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/quoted_literal.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/quoted_literal.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/rename_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/rename_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repair_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repair_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_label.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_label.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_multiple_statements.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_multiple_statements.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_no_label.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_no_label.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/replace.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/replace.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/reset_master.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/reset_master.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_name.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_name.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate_value.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate_value.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info_multiple.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info_multiple.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_distinctrow.sql rename crates/lib-dialects/test/fixtures/dialects/{databricks/sqlfluff/databricks_keywords.yml => mysql/sqlfluff/select_distinctrow.yml} (72%) create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_share.sql rename crates/lib-dialects/test/fixtures/dialects/{tsql/sqlfluff/table_variable_simple.yml => mysql/sqlfluff/select_for_share.yml} (69%) create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update.sql rename crates/lib-dialects/test/fixtures/dialects/{tsql/sqlfluff/inline_comments.yml => mysql/sqlfluff/select_for_update.yml} (68%) create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_lock_in_share_mode.sql rename crates/lib-dialects/test/fixtures/dialects/{tsql/sqlfluff/tsql_alias_simple.yml => mysql/sqlfluff/select_for_update_lock_in_share_mode.yml} (58%) create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_nowait.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_nowait.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of_multiple.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of_multiple.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_skip_locked.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_skip_locked.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_high_priority.sql rename crates/lib-dialects/test/fixtures/dialects/{duckdb/sqlfluff/describe.yml => mysql/sqlfluff/select_high_priority.yml} (64%) create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_dumpfile.sql rename crates/lib-dialects/test/fixtures/dialects/{duckdb/sqlfluff/summarize.yml => mysql/sqlfluff/select_into_dumpfile.yml} (64%) create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_multiple_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_multiple_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_enclosed.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_enclosed.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_escaped.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_escaped.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_optionally_enclosed.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_optionally_enclosed.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_terminated.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_terminated.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_starting.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_starting.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_terminated.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_terminated.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_session_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_session_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_local_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_local_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_lock_in_share_mode.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_lock_in_share_mode.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_multiple_partition.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_multiple_partition.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition_left_join.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition_left_join.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_session_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_session_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_big_result.sql rename crates/lib-dialects/test/fixtures/dialects/{tsql/sqlfluff/select_top_percent.yml => mysql/sqlfluff/select_sql_big_result.yml} (62%) create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_buffer_result.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_buffer_result.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_cache.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_cache.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_calc_found_rows.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_calc_found_rows.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_no_cache.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_no_cache.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_small_result.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_small_result.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_straight_join.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_straight_join.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_date_part_function.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_date_part_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_regexp.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_regexp.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_names.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_names.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_transaction.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_transaction.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_name.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_name.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate_value.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate_value.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info_multiple.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info_multiple.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/system_variables.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/system_variables.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/update.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/update.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_database.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_database.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_group_by.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_group_by.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_join.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_join.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_order_by.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_order_by.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_key.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_key.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/values_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/values_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/variable_assignment.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/variable_assignment.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_label.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_label.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_no_label.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_no_label.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_extension.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_extension.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_foreign_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_foreign_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_subscription.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_subscription.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_text_search_configuration.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_text_search_configuration.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/composite_value_expansion.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/composite_value_expansion.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_aggregate.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_aggregate.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_wrapper.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_wrapper.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_operator.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_operator.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_subscription.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_subscription.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_text_search_configuration.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_text_search_configuration.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/deallocate.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/deallocate.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_aggregate.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_aggregate.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_collation.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_collation.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_foreign_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_foreign_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_subscription.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_subscription.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_text_search_configuration.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_text_search_configuration.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/execute.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/execute.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/full_text_search.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/full_text_search.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_role.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_role.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_json.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_json.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_unknown.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_unknown.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_serialize.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_serialize.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_value.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_value.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/meta_commands_query_buffer.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/meta_commands_query_buffer.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/operator_qualified.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/operator_qualified.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pg_trgm.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pg_trgm.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pgvector.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pgvector.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_pgvector_operators.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_pgvector_operators.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_postgis_operators.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_postgis_operators.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/prepare.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/prepare.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/reset_session_authorization.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/reset_session_authorization.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/security_label.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/security_label.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_natural_join.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_natural_join.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_offset.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_offset.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_ordered_nested_sets.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_ordered_nested_sets.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_utf8.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_utf8.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_constraints.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_constraints.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_session_authorization.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_session_authorization.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/show.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/show.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/string_normalization.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/string_normalization.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/substring.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/substring.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/variadic.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/variadic.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_database.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_database.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/deallocate.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/deallocate.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/execute.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/execute.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/merge.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/merge.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/prepare.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/prepare.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select.sql rename crates/lib-dialects/test/fixtures/dialects/{tsql/sqlfluff/alias_standard_as.yml => redshift/sqlfluff/select.yml} (55%) create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_exclude.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_exclude.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/set_operators.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/set_operators.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_cortex_search_service.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_cortex_search_service.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_dynamic_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_dynamic_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_external_volume.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_external_volume.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_password_policy.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_password_policy.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_row_access_policy.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_row_access_policy.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_streamlit.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_streamlit.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_tag.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_tag.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/at_before_time_travel.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/at_before_time_travel.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_files_into_location_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_files_into_location_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_api_integration.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_api_integration.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_authentication_policy.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_authentication_policy.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_catalog_integration.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_catalog_integration.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_cortex_search_service.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_cortex_search_service.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database_role.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database_role.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_dynamic_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_dynamic_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_event_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_event_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_volume.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_volume.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_rule.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_rule.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_password_policy.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_password_policy.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_row_access_policy.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_row_access_policy.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_streamlit.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_streamlit.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/current_user.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/current_user.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datatypes.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datatypes.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/declare.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/declare.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/double_quote_escapes.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/double_quote_escapes.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_dynamic_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_dynamic_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_iceberg_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_iceberg_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_password_policy.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_password_policy.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_resource_monitor.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_resource_monitor.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/exception.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/exception.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/for_in_loop.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/for_in_loop.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/if_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/if_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/raise_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/raise_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_higher_order_function.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_higher_order_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_into.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_into.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_4.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_4.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/show.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/show.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_view_schema_evolution.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_view_schema_evolution.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/division_operator.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/division_operator.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/exclamation_mark.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/exclamation_mark.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/raw_literal.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/raw_literal.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/structure_accessor.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/structure_accessor.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/alter.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/alter_table.sql rename crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/{alter.yml => alter_table.yml} (64%) create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/block_comment_end_of_input.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/block_comment_end_of_input.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/conflict_clause.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/conflict_clause.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_constraint_generated.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_constraint_generated.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_unsigned.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_unsigned.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_view.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_view.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_virtual_table_check.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_virtual_table_check.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/is_clause.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/is_clause.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_keys.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_keys.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_operators.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_operators.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/named_parameters.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/named_parameters.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/over_clause.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/over_clause.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/pattern_matching.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/pattern_matching.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/quoted_identifiers.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/quoted_identifiers.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/raise_function.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/raise_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/upsert.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/upsert.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/window.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/window.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/alter_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/alter_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/commit.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/commit.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/create_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/create_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/insert.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/insert.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/rollback.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/rollback.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/set_session.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/set_session.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/start_transaction.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/start_transaction.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/.sqlfluff create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/add_index.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/add_index.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_alias_in_where_clause.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_alias_in_where_clause.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_exact_issue.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_exact_issue.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alias_equals_syntax.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alias_standard_as.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_and_drop.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_and_drop.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_database.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_database.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_index.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_index.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table_switch.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table_switch.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_simple.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_simple.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_with_alias.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_with_alias.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/arithmetic_operations.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/arithmetic_operations.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_block.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_block.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_nested.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_nested.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_no_semicolon.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_no_semicolon.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_functions.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_functions.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_variables.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_variables.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/bulk_insert.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/bulk_insert.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cast_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cast_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/collate.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/collate.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comprehensive_hash_identifiers.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comprehensive_hash_identifiers.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/convert.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/convert.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/copy.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/copy.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_columnstore_index.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_columnstore_index.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database_scoped_credential.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database_scoped_credential.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_data_source.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_data_source.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_file_format.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_file_format.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_catalog.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_catalog.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_index.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_index.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_function.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_login.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_login.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_master_key.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_master_key.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_function.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_scheme.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_scheme.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_role.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_role.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_schema.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_schema.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_security_policy.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_security_policy.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_server_role.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_server_role.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_as_select.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_as_select.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_constraints.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_constraints.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_graph.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_graph.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_on_filegroup.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_on_filegroup.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_distribution.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_distribution.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence_bracketed.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence_bracketed.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_table_option_segment.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_table_option_segment.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_trailing_comma.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_trailing_comma.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_type.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_type.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_user.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_user.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_columns.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_columns.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_cte.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_cte.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_pivot.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_pivot.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_set_statements.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_set_statements.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_unpivot.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_unpivot.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cross_apply_with_function.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cross_apply_with_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_s.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_s.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_with_join.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_with_join.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cursor.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cursor.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types_max.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types_max.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/date_functions.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/date_functions.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datepart.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datepart.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datetrunc.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datetrunc.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_variable_complex.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_variable_complex.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_variable.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_with_following_statements.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_with_following_statements.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete_azure_synapse_analytics.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete_azure_synapse_analytics.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/dml_as_derived_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/dml_as_derived_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_external_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_external_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_function.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_user.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_user.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_view.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_view.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/execute.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/execute.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/fetch_cursor_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/fetch_cursor_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_default_params.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_default_params.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_no_return.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_no_return.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_with_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_with_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_a.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_a.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_agg.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_agg.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/go_delimiters.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/go_delimiters.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/goto_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/goto_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/grant_deny_revoke.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/grant_deny_revoke.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/group_by.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/group_by.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/hints.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/hints.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_hash_end.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_special_chars.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_special_chars.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else_begin_end.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else_begin_end.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/ignore_nulls.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/ignore_nulls.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/implicit_alias_test.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/inline_comments.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_default.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_default.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_with_identity_insert.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_with_identity_insert.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/join_hints.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/join_hints.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/json_functions.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/json_functions.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/keyword_identifier_usage.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/keyword_identifier_usage.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/merge.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/merge.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function_no_alter.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function_no_alter.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement_without_semicolon.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement_without_semicolon.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multiple_semicolons.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multiple_semicolons.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/nested_joins.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/nested_joins.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/offset.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/offset.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/open_symmetric_key.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/open_symmetric_key.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openjson.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openjson.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openquery.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openquery.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openrowset.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openrowset.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openxml.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openxml.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/outer_apply.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/outer_apply.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/output_clause.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/output_clause.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/print.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/print.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/raiserror.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/raiserror.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/reconfigure.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/reconfigure.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/rename_table.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/rename_table.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/replicate.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/replicate.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_assign_parameter.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_assign_parameter.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_cross_apply.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_cross_apply.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_date_functions.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_date_functions.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_for.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_for.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_into.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_into.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_named_window.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_named_window.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_natural_join.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_natural_join.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_pivot.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_pivot.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_top_percent.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sequence.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sequence.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_context_info.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_context_info.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_language.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_language.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_local_variable.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_local_variable.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_statements.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_statements.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sqlcmd_command.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sqlcmd_command.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/square_bracket_identifiers.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/square_bracket_identifiers.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/string_agg_within_group.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/string_agg_within_group.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/synonym.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/synonym.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/system-variables.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/system-variables.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variable_simple.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables_comprehensive.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tablesample.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tablesample.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temp_tables.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temp_tables.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temporal_tables.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temporal_tables.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/transaction.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/transaction.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/triggers.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/triggers.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/try_catch.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/try_catch.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_column_ref.sql delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_column_ref.yml delete mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_simple.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/update.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/update.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/waitfor.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/waitfor.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/while_statement.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/while_statement.yml create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/window_functions.sql create mode 100644 crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/window_functions.yml diff --git a/crates/lib-core/src/dialects/init.rs b/crates/lib-core/src/dialects/init.rs index f4c1faf2c..8541042f4 100644 --- a/crates/lib-core/src/dialects/init.rs +++ b/crates/lib-core/src/dialects/init.rs @@ -24,6 +24,7 @@ pub enum DialectKind { Clickhouse, Databricks, Duckdb, + Hive, Mysql, Postgres, Redshift, diff --git a/crates/lib-dialects/src/ansi.rs b/crates/lib-dialects/src/ansi.rs index c42b55f98..037c93954 100644 --- a/crates/lib-dialects/src/ansi.rs +++ b/crates/lib-dialects/src/ansi.rs @@ -7,11 +7,12 @@ use sqruff_lib_core::parser::grammar::conditional::Conditional; use sqruff_lib_core::parser::grammar::delimited::Delimited; use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence}; use sqruff_lib_core::parser::grammar::{Anything, Nothing, Ref}; -use sqruff_lib_core::parser::lexer::{Cursor, Matcher, Pattern}; -use sqruff_lib_core::parser::lookahead::LookaheadExclude; +use sqruff_lib_core::parser::lexer::{Matcher, Pattern}; use sqruff_lib_core::parser::matchable::{Matchable, MatchableTrait}; use sqruff_lib_core::parser::node_matcher::NodeMatcher; -use sqruff_lib_core::parser::parsers::{MultiStringParser, RegexParser, StringParser, TypedParser}; +use sqruff_lib_core::parser::parsers::{ + CodeParser, MultiStringParser, RegexParser, StringParser, TypedParser, +}; use sqruff_lib_core::parser::segments::bracketed::BracketedSegmentMatcher; use sqruff_lib_core::parser::segments::generator::SegmentGenerator; use sqruff_lib_core::parser::segments::meta::MetaSegment; @@ -28,14 +29,12 @@ pub fn raw_dialect() -> Dialect { ansi_dialect.set_lexer_matchers(lexer_matchers()); - // Set the bare functions ansi_dialect.sets_mut("bare_functions").extend([ "current_timestamp", "current_time", "current_date", ]); - // Set the datetime units ansi_dialect.sets_mut("datetime_units").extend([ "DAY", "DAYOFYEAR", @@ -54,18 +53,12 @@ pub fn raw_dialect() -> Dialect { .sets_mut("date_part_function_name") .extend(["DATEADD"]); - // Set Keywords ansi_dialect .update_keywords_set_from_multiline_string("unreserved_keywords", ANSI_UNRESERVED_KEYWORDS); + ansi_dialect .update_keywords_set_from_multiline_string("reserved_keywords", ANSI_RESERVED_KEYWORDS); - // Bracket pairs (a set of tuples). - // (name, startref, endref, persists) - // NOTE: The `persists` value controls whether this type - // of bracket is persisted during matching to speed up other - // parts of the matching process. Round brackets are the most - // common and match the largest areas and so are sufficient. ansi_dialect.update_bracket_sets( "bracket_pairs", vec![ @@ -85,42 +78,7 @@ pub fn raw_dialect() -> Dialect { ], ); - // Set the value table functions. These are functions that, if they appear as - // an item in "FROM", are treated as returning a COLUMN, not a TABLE. - // Apparently, among dialects supported by SQLFluff, only BigQuery has this - // concept, but this set is defined in the ANSI dialect because: - // - It impacts core linter rules (see AL04 and several other rules that - // subclass from it) and how they interpret the contents of table_expressions - // - At least one other database (DB2) has the same value table function, - // UNNEST(), as BigQuery. DB2 is not currently supported by SQLFluff. - ansi_dialect.sets_mut("value_table_functions"); - - ansi_dialect.add([ - ( - "ArrayTypeSchemaSegment".into(), - NodeMatcher::new(SyntaxKind::ArrayType, |_| Nothing::new().to_matchable()) - .to_matchable() - .into(), - ), - ( - "ObjectReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::ObjectReference, |_| { - Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .config(|this| { - this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); - this.disallow_gaps(); - this.terminators = - vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()]; - }) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ]); - ansi_dialect.add([ - // Real segments ( "DelimiterGrammar".into(), Ref::new("SemicolonSegment").to_matchable().into(), @@ -143,14 +101,18 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - // NOTE: The purpose of the colon_delimiter is that it has different layout rules. - // It assumes no whitespace on either side. ( "ColonDelimiterSegment".into(), StringParser::new(":", SyntaxKind::ColonDelimiter) .to_matchable() .into(), ), + ( + "ColonPrefixSegment".into(), + StringParser::new(":", SyntaxKind::ColonPrefix) + .to_matchable() + .into(), + ), ( "StartBracketSegment".into(), StringParser::new("(", SyntaxKind::StartBracket) @@ -289,9 +251,15 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), + ( + "GlobOperatorSegment".into(), + TypedParser::new(SyntaxKind::GlobOperator, SyntaxKind::GlobOperator) + .to_matchable() + .into(), + ), ( "LikeOperatorSegment".into(), - TypedParser::new(SyntaxKind::LikeOperator, SyntaxKind::ComparisonOperator) + TypedParser::new(SyntaxKind::LikeOperator, SyntaxKind::LikeOperator) .to_matchable() .into(), ), @@ -320,14 +288,13 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - // The following functions can be called without parentheses per ANSI specification "BareFunctionSegment".into(), SegmentGenerator::new(|dialect| { MultiStringParser::new( dialect .sets("bare_functions") - .into_iter() - .map_into() + .iter() + .map(|item| item.to_string()) .collect_vec(), SyntaxKind::BareFunction, ) @@ -335,17 +302,13 @@ pub fn raw_dialect() -> Dialect { }) .into(), ), - // The strange regex here it to make sure we don't accidentally match numeric - // literals. We also use a regex to explicitly exclude disallowed keywords. ( "NakedIdentifierSegment".into(), SegmentGenerator::new(|dialect| { - // Generate the anti template from the set of reserved keywords let reserved_keywords = dialect.sets("reserved_keywords"); let pattern = reserved_keywords.iter().join("|"); let anti_template = format!("^({pattern})$"); - - RegexParser::new("[A-Z0-9_]*[A-Z][A-Z0-9_]*", SyntaxKind::NakedIdentifier) + RegexParser::new(r#"[A-Z0-9_]*[A-Z][A-Z0-9_]*"#, SyntaxKind::NakedIdentifier) .anti_template(&anti_template) .to_matchable() }) @@ -363,17 +326,12 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - // Maybe data types should be more restrictive? ( "DatatypeIdentifierSegment".into(), SegmentGenerator::new(|_| { - // Generate the anti template from the set of reserved keywords - // TODO - this is a stopgap until we implement explicit data types - let anti_template = format!("^({})$", "NOT"); - one_of(vec![ - RegexParser::new("[A-Z_][A-Z0-9_]*", SyntaxKind::DataTypeIdentifier) - .anti_template(&anti_template) + RegexParser::new(r#"[A-Z_][A-Z0-9_]*"#, SyntaxKind::DataTypeIdentifier) + .anti_template("^(NOT)$") .to_matchable(), Ref::new("SingleIdentifierGrammar") .exclude(Ref::new("NakedIdentifierSegment")) @@ -383,15 +341,14 @@ pub fn raw_dialect() -> Dialect { }) .into(), ), - // Ansi Intervals ( "DatetimeUnitSegment".into(), SegmentGenerator::new(|dialect| { MultiStringParser::new( dialect .sets("datetime_units") - .into_iter() - .map_into() + .iter() + .map(|item| item.to_string()) .collect_vec(), SyntaxKind::DatePart, ) @@ -405,9 +362,9 @@ pub fn raw_dialect() -> Dialect { MultiStringParser::new( dialect .sets("date_part_function_name") - .into_iter() - .map_into() - .collect::>(), + .iter() + .map(|item| item.to_string()) + .collect_vec(), SyntaxKind::FunctionNameIdentifier, ) .to_matchable() @@ -438,8 +395,6 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - // NullSegment is defined separately to the keyword, so we can give it a different - // type ( "NullLiteralSegment".into(), StringParser::new("null", SyntaxKind::NullLiteral) @@ -452,6 +407,14 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), + ( + "UnknownLiteralSegment".into(), + Nothing::new().to_matchable().into(), + ), + ( + "NormalizedGrammar".into(), + Nothing::new().to_matchable().into(), + ), ( "TrueSegment".into(), StringParser::new("true", SyntaxKind::BooleanLiteral) @@ -464,14 +427,15 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - // We use a GRAMMAR here not a Segment. Otherwise, we get an unnecessary layer ( "SingleIdentifierGrammar".into(), one_of(vec![ Ref::new("NakedIdentifierSegment").to_matchable(), Ref::new("QuotedIdentifierSegment").to_matchable(), ]) - .config(|this| this.terminators = vec![Ref::new("DotSegment").to_matchable()]) + .config(|this| { + this.terminators = vec![Ref::new("DotSegment").to_matchable()]; + }) .to_matchable() .into(), ), @@ -484,8 +448,6 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - // We specifically define a group of arithmetic operators to make it easier to - // override this if some dialects have different available operators ( "ArithmeticBinaryOperatorGrammar".into(), one_of(vec![ @@ -527,6 +489,17 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), + ( + "IsDistinctFromGrammar".into(), + Sequence::new(vec![ + Ref::keyword("IS").to_matchable(), + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("DISTINCT").to_matchable(), + Ref::keyword("FROM").to_matchable(), + ]) + .to_matchable() + .into(), + ), ( "ComparisonOperatorGrammar".into(), one_of(vec![ @@ -537,27 +510,11 @@ pub fn raw_dialect() -> Dialect { Ref::new("LessThanOrEqualToSegment").to_matchable(), Ref::new("NotEqualToSegment").to_matchable(), Ref::new("LikeOperatorSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IS").to_matchable(), - Ref::keyword("DISTINCT").to_matchable(), - Ref::keyword("FROM").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("IS").to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("DISTINCT").to_matchable(), - Ref::keyword("FROM").to_matchable(), - ]) - .to_matchable(), + Ref::new("IsDistinctFromGrammar").to_matchable(), ]) .to_matchable() .into(), ), - // hookpoint for other dialects - // e.g. EXASOL str to date cast with DATE '2021-01-01' - // Give it a different type as needs to be single quotes and - // should not be changed by rules (e.g. rule CV10) ( "DateTimeLiteralGrammar".into(), Sequence::new(vec![ @@ -574,8 +531,6 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - // Hookpoint for other dialects - // e.g. INTO is optional in BIGQUERY ( "MergeIntoLiteralGrammar".into(), Sequence::new(vec![ @@ -592,8 +547,6 @@ pub fn raw_dialect() -> Dialect { Ref::new("NumericLiteralSegment").to_matchable(), Ref::new("BooleanLiteralGrammar").to_matchable(), Ref::new("QualifiedNumericLiteralSegment").to_matchable(), - // NB: Null is included in the literals, because it is a keyword which - // can otherwise be easily mistaken for an identifier. Ref::new("NullLiteralSegment").to_matchable(), Ref::new("DateTimeLiteralGrammar").to_matchable(), Ref::new("ArrayLiteralSegment").to_matchable(), @@ -622,7 +575,6 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - // This is a placeholder for other dialects. "PreTableFunctionKeywordsGrammar".into(), Nothing::new().to_matchable().into(), ), @@ -637,8 +589,6 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - // This pattern is used in a lot of places. - // Defined here to avoid repetition. ( "BracketedColumnReferenceListGrammar".into(), Bracketed::new(vec![ @@ -704,6 +654,31 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), + ( + "LikeExpressionGrammar".into(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::new("LikeGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("Expression_A_Grammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ESCAPE").to_matchable(), + Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "PatternMatchingGrammar".into(), + Nothing::new().to_matchable().into(), + ), ( "UnionGrammar".into(), Sequence::new(vec![ @@ -712,7 +687,9 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("DISTINCT").to_matchable(), Ref::keyword("ALL").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -723,7 +700,9 @@ pub fn raw_dialect() -> Dialect { one_of(vec![ Ref::new("NullLiteralSegment").to_matchable(), Ref::new("NanLiteralSegment").to_matchable(), + Ref::new("UnknownLiteralSegment").to_matchable(), Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::new("NormalizedGrammar").to_matchable(), ]) .to_matchable() .into(), @@ -742,7 +721,9 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|this| this.parse_mode(ParseMode::Greedy)) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) .to_matchable(), Ref::new("FunctionSegment").to_matchable(), ]) @@ -753,10 +734,22 @@ pub fn raw_dialect() -> Dialect { ), ( "SelectClauseTerminatorGrammar".into(), - one_of(select_clause_terminators()).to_matchable().into(), + one_of(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("WHERE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::new("LimitClauseSegment").to_matchable(), + Ref::keyword("OVERLAPS").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), + Ref::keyword("FETCH").to_matchable(), + ]) + .to_matchable() + .into(), ), - // Define these as grammars to allow child dialects to enable them (since they are - // non-standard keywords) ("IsNullGrammar".into(), Nothing::new().to_matchable().into()), ( "NotNullGrammar".into(), @@ -770,7 +763,7 @@ pub fn raw_dialect() -> Dialect { "FromClauseTerminatorGrammar".into(), one_of(vec![ Ref::keyword("WHERE").to_matchable(), - Ref::keyword("LIMIT").to_matchable(), + Ref::new("LimitClauseSegment").to_matchable(), Sequence::new(vec![ Ref::keyword("GROUP").to_matchable(), Ref::keyword("BY").to_matchable(), @@ -788,6 +781,7 @@ pub fn raw_dialect() -> Dialect { Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), Ref::new("WithDataClauseSegment").to_matchable(), Ref::keyword("FETCH").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), ]) .to_matchable() .into(), @@ -795,7 +789,7 @@ pub fn raw_dialect() -> Dialect { ( "WhereClauseTerminatorGrammar".into(), one_of(vec![ - Ref::keyword("LIMIT").to_matchable(), + Ref::new("LimitClauseSegment").to_matchable(), Sequence::new(vec![ Ref::keyword("GROUP").to_matchable(), Ref::keyword("BY").to_matchable(), @@ -823,7 +817,7 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("BY").to_matchable(), ]) .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), + Ref::new("LimitClauseSegment").to_matchable(), Ref::keyword("HAVING").to_matchable(), Ref::keyword("QUALIFY").to_matchable(), Ref::keyword("WINDOW").to_matchable(), @@ -840,7 +834,7 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("BY").to_matchable(), ]) .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), + Ref::new("LimitClauseSegment").to_matchable(), Ref::keyword("QUALIFY").to_matchable(), Ref::keyword("WINDOW").to_matchable(), Ref::keyword("FETCH").to_matchable(), @@ -851,7 +845,7 @@ pub fn raw_dialect() -> Dialect { ( "OrderByClauseTerminators".into(), one_of(vec![ - Ref::keyword("LIMIT").to_matchable(), + Ref::new("LimitClauseSegment").to_matchable(), Ref::keyword("HAVING").to_matchable(), Ref::keyword("QUALIFY").to_matchable(), Ref::keyword("WINDOW").to_matchable(), @@ -886,7 +880,10 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - // Odd syntax, but prevents eager parameters being confused for data types + ( + "NotEnforcedGrammar".into(), + Nothing::new().to_matchable().into(), + ), ( "FunctionParameterGrammar".into(), one_of(vec![ @@ -922,8 +919,6 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - // Base Expression element is the right thing to reference for everything - // which functions as an expression, but could include literals. ( "BaseExpressionElementGrammar".into(), one_of(vec![ @@ -940,13 +935,6 @@ pub fn raw_dialect() -> Dialect { .to_matchable(), ]) .config(|this| { - // These terminators allow better performance by giving a signal - // of a likely complete match if they come after a match. For - // example "123," only needs to match against the LiteralGrammar - // and because a comma follows, never be matched against - // ExpressionSegment or FunctionSegment, which are both much - // more complicated. - this.terminators = vec![ Ref::new("CommaSegment").to_matchable(), Ref::keyword("AS").to_matchable(), @@ -993,10 +981,13 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), + ( + "ConditionalCrossJoinKeywordsGrammar".into(), + Ref::keyword("CROSS").to_matchable().into(), + ), ( "JoinTypeKeywordsGrammar".into(), one_of(vec![ - Ref::keyword("CROSS").to_matchable(), Ref::keyword("INNER").to_matchable(), Sequence::new(vec![ one_of(vec![ @@ -1009,45 +1000,76 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable() .into(), ), ( - // It's as a sequence to allow to parametrize that in Postgres dialect with LATERAL + "NonStandardJoinTypeKeywordsGrammar".into(), + Nothing::new().to_matchable().into(), + ), + ( + "ConditionalJoinKeywordsGrammar".into(), + one_of(vec![ + Ref::new("JoinTypeKeywordsGrammar").to_matchable(), + Ref::new("ConditionalCrossJoinKeywordsGrammar").to_matchable(), + Ref::new("NonStandardJoinTypeKeywordsGrammar").to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "JoinUsingConditionGrammar".into(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + MetaSegment::indent().to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( "JoinKeywordsGrammar".into(), Sequence::new(vec![Ref::keyword("JOIN").to_matchable()]) .to_matchable() .into(), ), ( - // NATURAL joins are not supported in all dialects (e.g. not in Bigquery - // or T-SQL). So define here to allow override with Nothing() for those. "NaturalJoinKeywordsGrammar".into(), Sequence::new(vec![ Ref::keyword("NATURAL").to_matchable(), - one_of(vec![ - // Note: NATURAL joins do not support CROSS joins - Ref::keyword("INNER").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("LEFT").to_matchable(), - Ref::keyword("RIGHT").to_matchable(), - Ref::keyword("FULL").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("OUTER").optional().to_matchable(), - ]) - .config(|this| this.optional()) + Ref::new("JoinTypeKeywordsGrammar") + .optional() .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), ]) .to_matchable() .into(), ), - // This can be overwritten by dialects + ( + "UnconditionalCrossJoinKeywordsGrammar".into(), + Nothing::new().to_matchable().into(), + ), + ( + "HorizontalJoinKeywordsGrammar".into(), + Nothing::new().to_matchable().into(), + ), + ( + "UnconditionalJoinKeywordsGrammar".into(), + one_of(vec![ + Ref::new("NaturalJoinKeywordsGrammar").to_matchable(), + Ref::new("UnconditionalCrossJoinKeywordsGrammar").to_matchable(), + Ref::new("HorizontalJoinKeywordsGrammar").to_matchable(), + ]) + .to_matchable() + .into(), + ), ( "ExtendedNaturalJoinKeywordsGrammar".into(), Nothing::new().to_matchable().into(), @@ -1086,7 +1108,9 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("RESTRICT").to_matchable(), Ref::keyword("CASCADE").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable() .into(), ), @@ -1101,28 +1125,30 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), + ( + "ReferenceMatchGrammar".into(), + Sequence::new(vec![ + Ref::keyword("MATCH").to_matchable(), + one_of(vec![ + Ref::keyword("FULL").to_matchable(), + Ref::keyword("PARTIAL").to_matchable(), + Ref::keyword("SIMPLE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), ( "ReferenceDefinitionGrammar".into(), Sequence::new(vec![ Ref::keyword("REFERENCES").to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), - // Foreign columns making up FOREIGN KEY constraint Ref::new("BracketedColumnReferenceListGrammar") .optional() .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MATCH").to_matchable(), - one_of(vec![ - Ref::keyword("FULL").to_matchable(), - Ref::keyword("PARTIAL").to_matchable(), - Ref::keyword("SIMPLE").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::new("ReferenceMatchGrammar").optional().to_matchable(), AnyNumberOf::new(vec![ - // ON DELETE clause, e.g. ON DELETE NO ACTION Sequence::new(vec![ Ref::keyword("ON").to_matchable(), Ref::keyword("DELETE").to_matchable(), @@ -1136,6 +1162,9 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), ]) .to_matchable() @@ -1164,7 +1193,6 @@ pub fn raw_dialect() -> Dialect { "ObjectReferenceDelimiterGrammar".into(), one_of(vec![ Ref::new("DotSegment").to_matchable(), - // NOTE: The double dot syntax allows for default values. Sequence::new(vec![ Ref::new("DotSegment").to_matchable(), Ref::new("DotSegment").to_matchable(), @@ -1188,18 +1216,7 @@ pub fn raw_dialect() -> Dialect { Ref::new("ColonSegment").to_matchable(), Ref::new("DelimiterGrammar").to_matchable(), Ref::new("JoinLikeClauseGrammar").to_matchable(), - Bracketed::new(vec![]).to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "AlterTableDropColumnGrammar".into(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("BracketedSegment").to_matchable(), ]) .to_matchable() .into(), @@ -1207,7 +1224,6 @@ pub fn raw_dialect() -> Dialect { ( "AlterTableOptionsGrammar".into(), one_of(vec![ - // Table options Sequence::new(vec![ Ref::new("ParameterNameSegment").to_matchable(), Ref::new("EqualsSegment").optional().to_matchable(), @@ -1218,7 +1234,6 @@ pub fn raw_dialect() -> Dialect { .to_matchable(), ]) .to_matchable(), - // Add things Sequence::new(vec![ one_of(vec![ Ref::keyword("ADD").to_matchable(), @@ -1232,28 +1247,29 @@ pub fn raw_dialect() -> Dialect { one_of(vec![ Ref::keyword("FIRST").to_matchable(), Ref::keyword("AFTER").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - // Bracketed Version of the same - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), ]) .to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), ]) .to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - // Drop Column Ref::new("AlterTableDropColumnGrammar").to_matchable(), - // Rename Sequence::new(vec![ Ref::keyword("RENAME").to_matchable(), one_of(vec![ Ref::keyword("AS").to_matchable(), Ref::keyword("TO").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), ]) @@ -1262,181 +1278,124 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - ansi_dialect.add([ ( - "FileSegment".into(), - NodeMatcher::new(SyntaxKind::File, |_| { - Delimited::new(vec![Ref::new("StatementSegment").to_matchable()]) - .config(|this| { - this.allow_trailing(); - this.delimiter( - AnyNumberOf::new(vec![Ref::new("DelimiterGrammar").to_matchable()]) - .config(|config| config.min_times(1)), - ); - }) - .to_matchable() - }) + "AlterTableDropColumnGrammar".into(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) .to_matchable() .into(), ), ( - "ColumnReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::ColumnReference, |_| { - Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .config(|this| this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar"))) - .to_matchable() - }) + "OrderNoOrderGrammar".into(), + one_of(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("NOORDER").to_matchable(), + ]) .to_matchable() .into(), ), ( - "ExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::Expression, |_| { - Ref::new("Expression_A_Grammar").to_matchable() - }) - .to_matchable() - .into(), + "ColumnsExpressionNameGrammar".into(), + Nothing::new().to_matchable().into(), ), ( - "WildcardIdentifierSegment".into(), - NodeMatcher::new(SyntaxKind::WildcardIdentifier, |_| { - Sequence::new(vec![ - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("ObjectReferenceDelimiterGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("StarSegment").to_matchable(), - ]) - .allow_gaps(false) - .to_matchable() - }) - .to_matchable() - .into(), + "ColumnsExpressionGrammar".into(), + Nothing::new().to_matchable().into(), ), ( - "NamedWindowExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::NamedWindowExpression, |_| { + "ListComprehensionGrammar".into(), + Nothing::new().to_matchable().into(), + ), + ( + "TimeWithTZGrammar".into(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TIME").to_matchable(), + Ref::keyword("TIMESTAMP").to_matchable(), + ]) + .to_matchable(), + Ref::new("BracketedArguments").optional().to_matchable(), Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("AS").to_matchable(), one_of(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Bracketed::new(vec![Ref::new("WindowSpecificationSegment").to_matchable()]) - .config(|this| this.parse_mode(ParseMode::Greedy)) - .to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::keyword("WITHOUT").to_matchable(), ]) .to_matchable(), + Ref::keyword("TIME").to_matchable(), + Ref::keyword("ZONE").to_matchable(), ]) - .to_matchable() - }) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) .to_matchable() .into(), ), ( - // DateTimeFunctionContentsSegment(BaseSegment): - // """Datetime function contents.""" - // - // type = "function_contents" - // - // match_grammar = Sequence( - // Bracketed( - // Delimited( - // Ref("DatetimeUnitSegment"), - // Ref( - // "FunctionContentsGrammar", - // # The brackets might be empty for some functions... - // optional=True, - // ), - // ), - // ), - // ) - "DateTimeFunctionContentsSegment".into(), - NodeMatcher::new(SyntaxKind::FunctionContents, |_| { + "SequenceMinValueGrammar".into(), + one_of(vec![ Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("DatetimeUnitSegment").to_matchable(), - Ref::new("FunctionContentsGrammar") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("MINVALUE").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "FunctionSegment".into(), - NodeMatcher::new(SyntaxKind::Function, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::new("DatePartFunctionNameSegment").to_matchable(), - Ref::new("DateTimeFunctionContentsSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Sequence::new(vec![ - Ref::new("FunctionNameSegment") - .exclude(one_of(vec![ - Ref::new("DatePartFunctionNameSegment").to_matchable(), - Ref::new("ValuesClauseSegment").to_matchable(), - ])) - .to_matchable(), - Ref::new("FunctionContentsSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("PostFunctionGrammar").optional().to_matchable(), - ]) - .to_matchable(), + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("MINVALUE").to_matchable(), ]) - .to_matchable() - }) + .to_matchable(), + ]) .to_matchable() .into(), ), ( - "HavingClauseSegment".into(), - NodeMatcher::new(SyntaxKind::HavingClause, |_| { + "SequenceMaxValueGrammar".into(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("HAVING").to_matchable(), - MetaSegment::implicit_indent().to_matchable(), - optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), + Ref::keyword("MAXVALUE").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) - .to_matchable() - }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("MAXVALUE").to_matchable(), + ]) + .to_matchable(), + ]) .to_matchable() .into(), ), ( - "PathSegment".into(), - NodeMatcher::new(SyntaxKind::PathSegment, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::new("SlashSegment").to_matchable(), - Delimited::new(vec![ - TypedParser::new(SyntaxKind::Word, SyntaxKind::PathSegment) - .to_matchable(), - ]) + "ColumnGeneratedGrammar".into(), + Nothing::new().to_matchable().into(), + ), + ]); + + ansi_dialect.add([ + ( + "FileSegment".into(), + NodeMatcher::new(SyntaxKind::File, |_dialect| { + Sequence::new(vec![ + AnyNumberOf::new(vec![Ref::new("DelimiterGrammar").to_matchable()]) + .to_matchable(), + Delimited::new(vec![Ref::new("StatementSegment").to_matchable()]) .config(|this| { - this.allow_gaps = false; - this.delimiter(Ref::new("SlashSegment")); + this.allow_trailing(); + this.delimiter( + AnyNumberOf::new(vec![Ref::new("DelimiterGrammar").to_matchable()]) + .config(|this| { + this.min_times(1); + }), + ); }) .to_matchable(), - ]) - .to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + AnyNumberOf::new(vec![Ref::new("DelimiterGrammar").to_matchable()]) + .to_matchable(), ]) .to_matchable() }) @@ -1444,39 +1403,32 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "LimitClauseSegment".into(), - NodeMatcher::new(SyntaxKind::LimitClause, |_| { + "IntervalExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::IntervalExpression, |_dialect| { Sequence::new(vec![ - Ref::keyword("LIMIT").to_matchable(), - MetaSegment::indent().to_matchable(), - optionally_bracketed(vec![ - one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("ALL").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("INTERVAL").to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::keyword("OFFSET").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("DatetimeUnitSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), Sequence::new(vec![ - Ref::new("CommaSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("DatetimeUnitSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) @@ -1484,16 +1436,13 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "CubeRollupClauseSegment".into(), - NodeMatcher::new(SyntaxKind::CubeRollupClause, |_| { - Sequence::new(vec![ - one_of(vec![ - Ref::new("CubeFunctionNameSegment").to_matchable(), - Ref::new("RollupFunctionNameSegment").to_matchable(), + "TupleSegment".into(), + NodeMatcher::new(SyntaxKind::Tuple, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("BaseExpressionElementGrammar").to_matchable(), ]) .to_matchable(), - Bracketed::new(vec![Ref::new("GroupingExpressionList").to_matchable()]) - .to_matchable(), ]) .to_matchable() }) @@ -1501,58 +1450,85 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "RollupFunctionNameSegment".into(), - NodeMatcher::new(SyntaxKind::FunctionName, |_| { - StringParser::new("ROLLUP", SyntaxKind::FunctionNameIdentifier).to_matchable() + "ArrayTypeSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayType, |_dialect| { + Nothing::new().to_matchable() }) .to_matchable() .into(), ), ( - "CubeFunctionNameSegment".into(), - NodeMatcher::new(SyntaxKind::FunctionName, |_| { - StringParser::new("CUBE", SyntaxKind::FunctionNameIdentifier).to_matchable() + "SizedArrayTypeSegment".into(), + NodeMatcher::new(SyntaxKind::SizedArrayType, |_dialect| { + Sequence::new(vec![ + Ref::new("ArrayTypeSegment").to_matchable(), + Ref::new("ArrayAccessorSegment").to_matchable(), + ]) + .to_matchable() }) .to_matchable() .into(), ), ( - "GroupingSetsClauseSegment".into(), - NodeMatcher::new(SyntaxKind::GroupingSetsClause, |_| { - Sequence::new(vec![ - Ref::keyword("GROUPING").to_matchable(), - Ref::keyword("SETS").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("CubeRollupClauseSegment").to_matchable(), - Ref::new("GroupingExpressionList").to_matchable(), - ]) - .to_matchable(), + "ArrayLiteralSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayLiteral, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("BaseExpressionElementGrammar").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) + .config(|this| { + this.bracket_type("square"); + }) .to_matchable() }) .to_matchable() .into(), ), ( - "GroupingExpressionList".into(), - NodeMatcher::new(SyntaxKind::GroupingExpressionList, |_| { + "TypedArrayLiteralSegment".into(), + NodeMatcher::new(SyntaxKind::TypedArrayLiteral, |_dialect| { Sequence::new(vec![ - MetaSegment::indent().to_matchable(), + Ref::new("ArrayTypeSegment").to_matchable(), + Ref::new("ArrayLiteralSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StructTypeSegment".into(), + NodeMatcher::new(SyntaxKind::StructType, |_dialect| { + Nothing::new().to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MapTypeSegment".into(), + NodeMatcher::new(SyntaxKind::MapType, |_dialect| { + Nothing::new().to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StructLiteralSegment".into(), + NodeMatcher::new(SyntaxKind::StructLiteral, |_dialect| { + Bracketed::new(vec![ Delimited::new(vec![ - one_of(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - Bracketed::new(vec![]).to_matchable(), + Sequence::new(vec![ + Ref::new("BaseExpressionElementGrammar").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), ]) .to_matchable(), - Ref::new("GroupByClauseTerminatorGrammar").to_matchable(), ]) .to_matchable(), - MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) @@ -1560,21 +1536,11 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "SetClauseSegment".into(), - NodeMatcher::new(SyntaxKind::SetClause, |_| { + "TypedStructLiteralSegment".into(), + NodeMatcher::new(SyntaxKind::TypedStructLiteral, |_dialect| { Sequence::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("BareFunctionSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - Ref::new("ValuesClauseSegment").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - ]) - .to_matchable(), + Ref::new("StructTypeSegment").to_matchable(), + Ref::new("StructLiteralSegment").to_matchable(), ]) .to_matchable() }) @@ -1582,22 +1548,19 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "FetchClauseSegment".into(), - NodeMatcher::new(SyntaxKind::FetchClause, |_| { + "EmptyStructLiteralBracketsSegment".into(), + NodeMatcher::new(SyntaxKind::StructLiteral, |_dialect| { + Bracketed::new(vec![]).to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "EmptyStructLiteralSegment".into(), + NodeMatcher::new(SyntaxKind::TypedStructLiteral, |_dialect| { Sequence::new(vec![ - Ref::keyword("FETCH").to_matchable(), - one_of(vec![ - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("NEXT").to_matchable(), - ]) - .to_matchable(), - Ref::new("NumericLiteralSegment").optional().to_matchable(), - one_of(vec![ - Ref::keyword("ROW").to_matchable(), - Ref::keyword("ROWS").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("ONLY").to_matchable(), + Ref::new("StructTypeSegment").to_matchable(), + Ref::new("EmptyStructLiteralBracketsSegment").to_matchable(), ]) .to_matchable() }) @@ -1605,99 +1568,148 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "FunctionDefinitionGrammar".into(), - NodeMatcher::new(SyntaxKind::FunctionDefinition, |_| { - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("LANGUAGE").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + "ObjectLiteralSegment".into(), + NodeMatcher::new(SyntaxKind::ObjectLiteral, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ObjectLiteralElementSegment").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) + .config(|this| { + this.bracket_type("curly"); + }) .to_matchable() }) .to_matchable() .into(), ), ( - "AlterSequenceOptionsSegment".into(), - NodeMatcher::new(SyntaxKind::AlterSequenceOptionsSegment, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("INCREMENT").to_matchable(), - Ref::keyword("BY").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) + "ObjectLiteralElementSegment".into(), + NodeMatcher::new(SyntaxKind::ObjectLiteralElement, |_dialect| { + Sequence::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ColonSegment").to_matchable(), + Ref::new("BaseExpressionElementGrammar").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TimeZoneGrammar".into(), + NodeMatcher::new(SyntaxKind::TimeZoneGrammar, |_dialect| { + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("AT").to_matchable(), + Ref::keyword("TIME").to_matchable(), + Ref::keyword("ZONE").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("MINVALUE").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("MINVALUE").to_matchable(), - ]) + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "BracketedArguments".into(), + NodeMatcher::new(SyntaxKind::BracketedArguments, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("LiteralGrammar").to_matchable()]) + .config(|this| { + this.optional(); + }) .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DatatypeSegment".into(), + NodeMatcher::new(SyntaxKind::DataType, |_dialect| { + one_of(vec![ + Ref::new("TimeWithTZGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DOUBLE").to_matchable(), + Ref::keyword("PRECISION").to_matchable(), ]) .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("MAXVALUE").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("MAXVALUE").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("CHARACTER").to_matchable(), + Ref::keyword("BINARY").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("VARYING").to_matchable(), + Sequence::new(vec![ + Ref::keyword("LARGE").to_matchable(), + Ref::keyword("OBJECT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DotSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + this.disallow_gaps(); + }) + .to_matchable(), + Ref::new("DatatypeIdentifierSegment").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CACHE").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("BracketedArguments").optional().to_matchable(), + AnyNumberOf::new(vec![ + Ref::keyword("UNSIGNED").to_matchable(), + Ref::new("CharCharacterSetGrammar").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("NOCACHE").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("CYCLE").to_matchable(), - Ref::keyword("NOCYCLE").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("NOORDER").to_matchable(), ]) .to_matchable(), + Ref::new("ArrayTypeSegment").to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), + ]); + + ansi_dialect.add([( + "CharCharacterSetGrammar".into(), + Nothing::new().to_matchable().into(), + )]); + + ansi_dialect.add([ ( - "RoleReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::RoleReference, |_| { - Ref::new("SingleIdentifierGrammar").to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "TablespaceReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::TablespaceReference, |_| { + "ObjectReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::ObjectReference, |_dialect| { Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) .config(|this| { - this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); this.disallow_gaps(); + this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); this.terminators = vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()]; }) @@ -1707,105 +1719,62 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "ExtensionReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::ExtensionReference, |_| { - Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .config(|this| { - this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); - this.disallow_gaps(); - this.terminators = - vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()]; - }) - .to_matchable() + "TableReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::TableReference, |_dialect| { + _dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&_dialect) + .unwrap() }) .to_matchable() .into(), ), ( - "TagReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::TagReference, |_| { - Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .config(|this| { - this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); - this.disallow_gaps(); - this.terminators = - vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()]; - }) - .to_matchable() + "SchemaReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::SchemaReference, |_dialect| { + _dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&_dialect) + .unwrap() }) .to_matchable() .into(), ), ( - "ColumnDefinitionSegment".into(), - NodeMatcher::new(SyntaxKind::ColumnDefinition, |_| { - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), // Column name - Ref::new("DatatypeSegment").to_matchable(), // Column type, - Bracketed::new(vec![Anything::new().to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - AnyNumberOf::new(vec![Ref::new("ColumnConstraintSegment").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable() + "DatabaseReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::DatabaseReference, |_dialect| { + _dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&_dialect) + .unwrap() }) .to_matchable() .into(), ), ( - "ColumnConstraintSegment".into(), - NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_| { - Sequence::new(vec![ - Sequence::new(vec![ - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("NULL").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CHECK").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("ColumnConstraintDefaultGrammar").to_matchable(), - ]) - .to_matchable(), - Ref::new("PrimaryKeyGrammar").to_matchable(), - Ref::new("UniqueKeyGrammar").to_matchable(), // UNIQUE - Ref::new("AutoIncrementGrammar").to_matchable(), - Ref::new("ReferenceDefinitionGrammar").to_matchable(), /* REFERENCES reftable [ ( - * refcolumn) ] */ - Ref::new("CommentClauseSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLLATE").to_matchable(), - Ref::new("CollationReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() + "IndexReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::IndexReference, |_dialect| { + _dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&_dialect) + .unwrap() }) .to_matchable() .into(), ), ( - "CommentClauseSegment".into(), - NodeMatcher::new(SyntaxKind::CommentClause, |_| { - Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), + "CollationReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::CollationReference, |_dialect| { + one_of(vec![ Ref::new("QuotedLiteralSegment").to_matchable(), + Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) + .config(|this| { + this.disallow_gaps(); + this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); + this.terminators = + vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()]; + }) + .to_matchable(), ]) .to_matchable() }) @@ -1813,213 +1782,148 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "TableEndClauseSegment".into(), - NodeMatcher::new(SyntaxKind::TableEndClause, |_| { - Nothing::new().to_matchable() + "RoleReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::RoleReference, |_dialect| { + Ref::new("SingleIdentifierGrammar").to_matchable() }) .to_matchable() .into(), ), ( - "MergeMatchSegment".into(), - NodeMatcher::new(SyntaxKind::MergeMatch, |_| { - AnyNumberOf::new(vec![ - Ref::new("MergeMatchedClauseSegment").to_matchable(), - Ref::new("MergeNotMatchedClauseSegment").to_matchable(), - ]) - .config(|this| this.min_times(1)) - .to_matchable() + "TablespaceReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::TablespaceReference, |_dialect| { + _dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&_dialect) + .unwrap() }) .to_matchable() .into(), ), ( - "MergeMatchedClauseSegment".into(), - NodeMatcher::new(SyntaxKind::MergeWhenMatchedClause, |_| { - Sequence::new(vec![ - Ref::keyword("WHEN").to_matchable(), - Ref::keyword("MATCHED").to_matchable(), - Sequence::new(vec![ - Ref::keyword("AND").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("THEN").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ - Ref::new("MergeUpdateClauseSegment").to_matchable(), - Ref::new("MergeDeleteClauseSegment").to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable() + "ExtensionReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::ExtensionReference, |_dialect| { + _dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&_dialect) + .unwrap() }) .to_matchable() .into(), ), ( - "MergeNotMatchedClauseSegment".into(), - NodeMatcher::new(SyntaxKind::MergeWhenNotMatchedClause, |_| { - Sequence::new(vec![ - Ref::keyword("WHEN").to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("MATCHED").to_matchable(), - Sequence::new(vec![ - Ref::keyword("AND").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("THEN").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("MergeInsertClauseSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "MergeInsertClauseSegment".into(), - NodeMatcher::new(SyntaxKind::MergeInsertClause, |_| { - Sequence::new(vec![ - Ref::keyword("INSERT").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - MetaSegment::dedent().to_matchable(), - Ref::new("ValuesClauseSegment").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "MergeUpdateClauseSegment".into(), - NodeMatcher::new(SyntaxKind::MergeUpdateClause, |_| { - Sequence::new(vec![ - Ref::keyword("UPDATE").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("SetClauseListSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "MergeDeleteClauseSegment".into(), - NodeMatcher::new(SyntaxKind::MergeDeleteClause, |_| { - Ref::keyword("DELETE").to_matchable() + "ColumnReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnReference, |_dialect| { + _dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&_dialect) + .unwrap() }) .to_matchable() .into(), ), ( - "SetClauseListSegment".into(), - NodeMatcher::new(SyntaxKind::SetClauseList, |_| { - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("SetClauseSegment").to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("CommaSegment").to_matchable(), - Ref::new("SetClauseSegment").to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable() + "SequenceReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::SequenceReference, |_dialect| { + _dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&_dialect) + .unwrap() }) .to_matchable() .into(), ), ( - "TableReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::TableReference, |ansi_dialect| { - ansi_dialect + "TagReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::TagReference, |_dialect| { + _dialect .grammar("ObjectReferenceSegment") - .match_grammar(ansi_dialect) + .match_grammar(&_dialect) .unwrap() - .clone() }) .to_matchable() .into(), ), ( - "SchemaReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::TableReference, |_| { - Ref::new("ObjectReferenceSegment").to_matchable() + "TriggerReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::TriggerReference, |_dialect| { + _dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&_dialect) + .unwrap() }) .to_matchable() .into(), ), ( "SingleIdentifierListSegment".into(), - NodeMatcher::new(SyntaxKind::IdentifierList, |_| { + NodeMatcher::new(SyntaxKind::IdentifierList, |_dialect| { Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .config(|this| this.optional()) .to_matchable() }) .to_matchable() .into(), ), ( - "GroupByClauseSegment".into(), - NodeMatcher::new(SyntaxKind::GroupbyClause, |_| { - Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - one_of(vec![ - Ref::new("CubeRollupClauseSegment").to_matchable(), - Sequence::new(vec![ - MetaSegment::indent().to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.terminators = - vec![Ref::new("GroupByClauseTerminatorGrammar").to_matchable()]; - }) - .to_matchable(), - MetaSegment::dedent().to_matchable(), + "ArrayAccessorSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayAccessor, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.delimiter(Ref::new("SliceSegment")); + }) .to_matchable(), ]) + .config(|this| { + this.bracket_type("square"); + this.parse_mode(ParseMode::Greedy); + }) .to_matchable() }) .to_matchable() .into(), ), + ]); + + ansi_dialect.add([( + "AliasedTableReferenceGrammar".into(), + Sequence::new(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("AliasExpressionSegment").to_matchable(), + ]) + .to_matchable() + .into(), + )]); + + ansi_dialect.add([ ( - "FrameClauseSegment".into(), - NodeMatcher::new(SyntaxKind::FrameClause, |_| { + "AliasExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::AliasExpression, |_dialect| { Sequence::new(vec![ - Ref::new("FrameClauseUnitGrammar").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("AsAliasOperatorSegment").optional().to_matchable(), one_of(vec![ - frame_extent().to_matchable(), Sequence::new(vec![ - Ref::keyword("BETWEEN").to_matchable(), - frame_extent().to_matchable(), - Ref::keyword("AND").to_matchable(), - frame_extent().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Bracketed::new(vec![ + Ref::new("SingleIdentifierListSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), + Ref::new("SingleQuotedIdentifierSegment").to_matchable(), ]) .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) @@ -2027,49 +1931,34 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "WithCompoundStatementSegment".into(), - NodeMatcher::new(SyntaxKind::WithCompoundStatement, |_| { - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("RECURSIVE").optional().to_matchable(), - Conditional::new(MetaSegment::indent()) - .indented_ctes() - .to_matchable(), - Delimited::new(vec![Ref::new("CTEDefinitionSegment").to_matchable()]) - .config(|this| { - this.terminators = vec![Ref::keyword("SELECT").to_matchable()]; - this.allow_trailing(); - }) - .to_matchable(), - Conditional::new(MetaSegment::dedent()) - .indented_ctes() - .to_matchable(), - Ref::new("NonWithSelectableGrammar").to_matchable(), - ]) - .to_matchable() + "AsAliasOperatorSegment".into(), + NodeMatcher::new(SyntaxKind::AliasOperator, |_dialect| { + Sequence::new(vec![Ref::keyword("AS").to_matchable()]).to_matchable() }) .to_matchable() .into(), ), ( - "WithCompoundNonSelectStatementSegment".into(), - NodeMatcher::new(SyntaxKind::WithCompoundStatement, |_| { + "ShorthandCastSegment".into(), + NodeMatcher::new(SyntaxKind::CastExpression, |_dialect| { Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("RECURSIVE").optional().to_matchable(), - Conditional::new(MetaSegment::indent()) - .indented_ctes() - .to_matchable(), - Delimited::new(vec![Ref::new("CTEDefinitionSegment").to_matchable()]) - .config(|this| { - this.terminators = vec![Ref::keyword("SELECT").to_matchable()]; - this.allow_trailing(); - }) - .to_matchable(), - Conditional::new(MetaSegment::dedent()) - .indented_ctes() + one_of(vec![ + Ref::new("Expression_D_Grammar").to_matchable(), + Ref::new("CaseExpressionSegment").to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("CastOperatorSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Ref::new("TimeZoneGrammar").optional().to_matchable(), + ]) .to_matchable(), - Ref::new("NonWithNonSelectableGrammar").to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), ]) .to_matchable() }) @@ -2077,14 +1966,11 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "CTEDefinitionSegment".into(), - NodeMatcher::new(SyntaxKind::CommonTableExpression, |_| { + "QualifiedNumericLiteralSegment".into(), + NodeMatcher::new(SyntaxKind::NumericLiteral, |_dialect| { Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("CTEColumnList").optional().to_matchable(), - Ref::keyword("AS").optional().to_matchable(), - Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) - .to_matchable(), + Ref::new("SignedSegmentGrammar").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) .to_matchable() }) @@ -2092,150 +1978,106 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "CTEColumnList".into(), - NodeMatcher::new(SyntaxKind::CTEColumnList, |_| { - Bracketed::new(vec![Ref::new("SingleIdentifierListSegment").to_matchable()]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "SequenceReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::ColumnReference, |_| { - Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .config(|this| { - this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); - this.disallow_gaps(); - this.terminators = - vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()]; - }) - .to_matchable() + "AggregateOrderByClause".into(), + NodeMatcher::new(SyntaxKind::AggregateOrderByClause, |_dialect| { + Ref::new("OrderByClauseSegment").to_matchable() }) .to_matchable() .into(), ), + ]); + + ansi_dialect.add([ ( - "TriggerReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::TriggerReference, |_| { - Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .config(|this| { - this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); - this.disallow_gaps(); - this.terminators = - vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()]; - }) - .to_matchable() - }) - .to_matchable() - .into(), + "FunctionContentsExpressionGrammar".into(), + Ref::new("ExpressionSegment").to_matchable().into(), ), ( - "TableConstraintSegment".into(), - NodeMatcher::new(SyntaxKind::TableConstraint, |_| { + "FunctionContentsGrammar".into(), + AnyNumberOf::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), Sequence::new(vec![ - Sequence::new(vec![ - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("TrimParametersGrammar").to_matchable(), + Ref::new("ExpressionSegment") + .exclude(Ref::keyword("FROM")) + .optional() + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("DatetimeUnitSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("UNIQUE").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("PrimaryKeyGrammar").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("ForeignKeyGrammar").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - Ref::new("ReferenceDefinitionGrammar").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DISTINCT").optional().to_matchable(), + one_of(vec![ + Ref::new("StarSegment").to_matchable(), + Delimited::new(vec![ + Ref::new("FunctionContentsExpressionGrammar").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "JoinOnConditionSegment".into(), - NodeMatcher::new(SyntaxKind::JoinOnCondition, |_| { + .to_matchable(), + Ref::new("AggregateOrderByClause").to_matchable(), Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Conditional::new(MetaSegment::implicit_indent()) - .indented_on_contents() - .to_matchable(), - optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - Conditional::new(MetaSegment::dedent()) - .indented_on_contents() - .to_matchable(), + Ref::keyword("SEPARATOR").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "DatabaseReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::DatabaseReference, |_| { - Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .config(|this| { - this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); - this.disallow_gaps(); - this.terminators = - vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()]; - }) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "IndexReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::DatabaseReference, |_| { - Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .config(|this| { - this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); - this.disallow_gaps(); - this.terminators = - vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()]; - }) - .to_matchable() - }) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("IN").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("IgnoreRespectNullsGrammar").to_matchable(), + Ref::new("IndexColumnDefinitionSegment").to_matchable(), + Ref::new("EmptyStructLiteralSegment").to_matchable(), + ]) .to_matchable() .into(), ), ( - "CollationReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::CollationReference, |_| { - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .config(|this| { - this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); - this.terminators = - vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()]; - this.allow_gaps = false; - }) - .to_matchable(), - ]) - .to_matchable() - }) + "PostFunctionGrammar".into(), + one_of(vec![ + Ref::new("OverClauseSegment").to_matchable(), + Ref::new("FilterClauseGrammar").to_matchable(), + ]) .to_matchable() .into(), ), + ]); + + ansi_dialect.add([ ( "OverClauseSegment".into(), - NodeMatcher::new(SyntaxKind::OverClause, |_| { + NodeMatcher::new(SyntaxKind::OverClause, |_dialect| { Sequence::new(vec![ MetaSegment::indent().to_matchable(), Ref::new("IgnoreRespectNullsGrammar") @@ -2249,7 +2091,9 @@ pub fn raw_dialect() -> Dialect { .optional() .to_matchable(), ]) - .config(|this| this.parse_mode(ParseMode::Greedy)) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) .to_matchable(), ]) .to_matchable(), @@ -2260,122 +2104,75 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ( - "NamedWindowSegment".into(), - NodeMatcher::new(SyntaxKind::NamedWindow, |_| { - Sequence::new(vec![ - Ref::keyword("WINDOW").to_matchable(), - MetaSegment::indent().to_matchable(), - Delimited::new(vec![ - Ref::new("NamedWindowExpressionSegment").to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), ( "WindowSpecificationSegment".into(), - NodeMatcher::new(SyntaxKind::WindowSpecification, |_| { + NodeMatcher::new(SyntaxKind::WindowSpecification, |_dialect| { Sequence::new(vec![ Ref::new("SingleIdentifierGrammar") - .optional() .exclude(one_of(vec![ Ref::keyword("PARTITION").to_matchable(), Ref::keyword("ORDER").to_matchable(), ])) + .optional() .to_matchable(), Ref::new("PartitionClauseSegment").optional().to_matchable(), Ref::new("OrderByClauseSegment").optional().to_matchable(), Ref::new("FrameClauseSegment").optional().to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable() }) .to_matchable() .into(), ), ( - "PartitionClauseSegment".into(), - NodeMatcher::new(SyntaxKind::PartitionbyClause, |_| { + "FunctionNameSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionName, |_dialect| { Sequence::new(vec![ - Ref::keyword("PARTITION").to_matchable(), - Ref::keyword("BY").to_matchable(), - MetaSegment::indent().to_matchable(), - optionally_bracketed(vec![ - Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DotSegment").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.terminators = vec![Ref::new("BracketedSegment").to_matchable()]; + }) + .to_matchable(), + one_of(vec![ + Ref::new("FunctionNameIdentifierSegment").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), + ]) + .config(|this| { + this.terminators = vec![Ref::new("BracketedSegment").to_matchable()]; + }) .to_matchable(), - MetaSegment::dedent().to_matchable(), ]) + .config(|this| { + this.disallow_gaps(); + }) .to_matchable() }) .to_matchable() .into(), ), ( - "JoinClauseSegment".into(), - NodeMatcher::new(SyntaxKind::JoinClause, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::new("JoinTypeKeywordsGrammar") - .optional() - .to_matchable(), - Ref::new("JoinKeywordsGrammar").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("FromExpressionElementSegment").to_matchable(), - AnyNumberOf::new(vec![Ref::new("NestedJoinGrammar").to_matchable()]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - Sequence::new(vec![ - Conditional::new(MetaSegment::indent()) - .indented_using_on() - .to_matchable(), - one_of(vec![ - Ref::new("JoinOnConditionSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - MetaSegment::indent().to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.parse_mode = ParseMode::Greedy) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Conditional::new(MetaSegment::dedent()) - .indented_using_on() + "DateTimeFunctionContentsSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionContents, |_dialect| { + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("DatetimeUnitSegment").to_matchable(), + Ref::new("FunctionContentsGrammar") + .optional() .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::new("NaturalJoinKeywordsGrammar").to_matchable(), - Ref::new("JoinKeywordsGrammar").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("FromExpressionElementSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("ExtendedNaturalJoinKeywordsGrammar").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("FromExpressionElementSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), ]) .to_matchable() }) @@ -2383,13 +2180,15 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "DropTriggerStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropTriggerStatement, |_| { + "FunctionContentsSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionContents, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("TRIGGER").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("TriggerReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Ref::new("FunctionContentsGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) @@ -2397,23 +2196,29 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "SamplingExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::SampleExpression, |_| { - Sequence::new(vec![ - Ref::keyword("TABLESAMPLE").to_matchable(), - one_of(vec![ - Ref::keyword("BERNOULLI").to_matchable(), - Ref::keyword("SYSTEM").to_matchable(), + "FunctionSegment".into(), + NodeMatcher::new(SyntaxKind::Function, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::new("DatePartFunctionNameSegment").to_matchable(), + Ref::new("DateTimeFunctionContentsSegment").to_matchable(), ]) .to_matchable(), - Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) - .to_matchable(), + Ref::new("ColumnsExpressionGrammar").to_matchable(), Sequence::new(vec![ - Ref::keyword("REPEATABLE").to_matchable(), - Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) - .to_matchable(), + Sequence::new(vec![ + Ref::new("FunctionNameSegment") + .exclude(one_of(vec![ + Ref::new("DatePartFunctionNameSegment").to_matchable(), + Ref::new("ColumnsExpressionFunctionNameSegment").to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + ])) + .to_matchable(), + Ref::new("FunctionContentsSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("PostFunctionGrammar").optional().to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable() @@ -2422,56 +2227,34 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "TableExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::TableExpression, |_| { - one_of(vec![ - Ref::new("ValuesClauseSegment").to_matchable(), - Ref::new("BareFunctionSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) - .to_matchable(), - Bracketed::new(vec![Ref::new("MergeStatementSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable() + "ColumnsExpressionFunctionNameSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionName, |_dialect| { + Ref::new("ColumnsExpressionNameGrammar").to_matchable() }) .to_matchable() .into(), ), ( - "DropTriggerStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropTriggerStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("TRIGGER").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("TriggerReferenceSegment").to_matchable(), - ]) - .to_matchable() + "ColumnsExpressionFunctionContentsSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnsExpression, |_dialect| { + Nothing::new().to_matchable() }) .to_matchable() .into(), ), ( - "SamplingExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::SampleExpression, |_| { + "PartitionClauseSegment".into(), + NodeMatcher::new(SyntaxKind::PartitionbyClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("TABLESAMPLE").to_matchable(), - one_of(vec![ - Ref::keyword("BERNOULLI").to_matchable(), - Ref::keyword("SYSTEM").to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("REPEATABLE").to_matchable(), - Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) + Ref::keyword("PARTITION").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + optionally_bracketed(vec![ + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) @@ -2479,97 +2262,28 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "TableExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::TableExpression, |_| { - one_of(vec![ - Ref::new("ValuesClauseSegment").to_matchable(), - Ref::new("BareFunctionSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) - .to_matchable(), - Bracketed::new(vec![Ref::new("MergeStatementSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "CreateTriggerStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateTriggerStatement, |_| { + "FrameClauseSegment".into(), + NodeMatcher::new(SyntaxKind::FrameClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("TRIGGER").to_matchable(), - Ref::new("TriggerReferenceSegment").to_matchable(), + Ref::new("FrameClauseUnitGrammar").to_matchable(), one_of(vec![ - Ref::keyword("BEFORE").to_matchable(), - Ref::keyword("AFTER").to_matchable(), - Sequence::new(vec![ - Ref::keyword("INSTEAD").to_matchable(), - Ref::keyword("OF").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Delimited::new(vec![ - Ref::keyword("INSERT").to_matchable(), - Ref::keyword("DELETE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("UPDATE").to_matchable(), - Ref::keyword("OF").to_matchable(), - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - //.with_terminators(vec!["OR", "ON"]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.delimiter(Ref::keyword("OR")); - // .with_terminators(vec!["ON"]); - }) - .to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("REFERENCING").to_matchable(), - Ref::keyword("OLD").to_matchable(), - Ref::keyword("ROW").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - Ref::keyword("NEW").to_matchable(), - Ref::keyword("ROW").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("DEFERRABLE").to_matchable(), + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("DEFERRABLE").optional().to_matchable(), one_of(vec![ - Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("IMMEDIATE").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("DEFERRED").to_matchable(), - ]) - .to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("IntervalExpressionSegment").to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), ]) .to_matchable(), ]) @@ -2577,86 +2291,152 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("FOR").to_matchable(), - Ref::keyword("EACH").optional().to_matchable(), + Ref::keyword("BETWEEN").to_matchable(), one_of(vec![ - Ref::keyword("ROW").to_matchable(), - Ref::keyword("STATEMENT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("IntervalExpressionSegment").to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WHEN").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + Ref::keyword("AND").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("IntervalExpressionSegment").to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), + ]) .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("EXECUTE").to_matchable(), - Ref::keyword("PROCEDURE").to_matchable(), - Ref::new("FunctionNameIdentifierSegment").to_matchable(), - Ref::new("FunctionContentsSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "DropModelStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropModelStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("MODEL").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "DescribeStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DescribeStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DESCRIBE").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "UseStatementSegment".into(), - NodeMatcher::new(SyntaxKind::UseStatement, |_| { - Sequence::new(vec![ - Ref::keyword("USE").to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), + ]); + + ansi_dialect.add([( + "PostTableExpressionGrammar".into(), + Nothing::new().to_matchable().into(), + )]); + + ansi_dialect.add([ ( - "ExplainStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ExplainStatement, |_| { - Sequence::new(vec![ - Ref::keyword("EXPLAIN").to_matchable(), - one_of(vec![ - Ref::new("SelectableGrammar").to_matchable(), - Ref::new("InsertStatementSegment").to_matchable(), - Ref::new("UpdateStatementSegment").to_matchable(), - Ref::new("DeleteStatementSegment").to_matchable(), + "FromExpressionElementSegment".into(), + NodeMatcher::new(SyntaxKind::FromExpressionElement, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::new("PreTableFunctionKeywordsGrammar") + .optional() + .to_matchable(), + optionally_bracketed(vec![ + Ref::new("TableExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("TemporalQuerySegment").optional().to_matchable(), + Ref::new("AliasExpressionSegment") + .exclude(one_of(vec![ + Ref::new("FromClauseTerminatorGrammar").to_matchable(), + Ref::new("SamplingExpressionSegment").to_matchable(), + Ref::new("JoinLikeClauseGrammar").to_matchable(), + Ref::new("JoinClauseSegment").to_matchable(), + ])) + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), + Ref::new("AliasExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("SamplingExpressionSegment") + .optional() + .to_matchable(), + Ref::new("PostTableExpressionGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Sequence::new(vec![ + Ref::new("PreTableFunctionKeywordsGrammar") + .optional() + .to_matchable(), + optionally_bracketed(vec![ + Ref::new("TableExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("TemporalQuerySegment").optional().to_matchable(), + Ref::new("AliasExpressionSegment") + .exclude(one_of(vec![ + Ref::new("FromClauseTerminatorGrammar").to_matchable(), + Ref::new("SamplingExpressionSegment").to_matchable(), + Ref::new("JoinLikeClauseGrammar").to_matchable(), + Ref::new("JoinClauseSegment").to_matchable(), + ])) + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), + Ref::new("AliasExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("SamplingExpressionSegment") + .optional() + .to_matchable(), + Ref::new("PostTableExpressionGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![Ref::new("JoinClauseSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -2666,82 +2446,65 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "CreateSequenceStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateSequenceStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("SEQUENCE").to_matchable(), - Ref::new("SequenceReferenceSegment").to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("CreateSequenceOptionsSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "CreateSequenceOptionsSegment".into(), - NodeMatcher::new(SyntaxKind::CreateSequenceOptionsSegment, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("INCREMENT").to_matchable(), - Ref::keyword("BY").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), + "FromExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::FromExpression, |_dialect| { + optionally_bracketed(vec![ Sequence::new(vec![ - Ref::keyword("START").to_matchable(), - Ref::keyword("WITH").optional().to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("MINVALUE").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("MINVALUE").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("MAXVALUE").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("MAXVALUE").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::new("MLTableExpressionSegment").to_matchable(), + Ref::new("FromExpressionElementSegment").to_matchable(), + Bracketed::new(vec![Ref::new("FromExpressionSegment").to_matchable()]) + .to_matchable(), ]) + .config(|this| { + this.terminators = vec![ + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + ]; + }) .to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CACHE").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + MetaSegment::dedent().to_matchable(), + Conditional::new(MetaSegment::indent()) + .indented_joins() + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("JoinClauseSegment").to_matchable(), + Ref::new("JoinLikeClauseGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + this.terminators = vec![ + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + ]; + }) .to_matchable(), - Ref::keyword("NOCACHE").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("CYCLE").to_matchable(), - Ref::keyword("NOCYCLE").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("NOORDER").to_matchable(), + Conditional::new(MetaSegment::dedent()) + .indented_joins() + .to_matchable(), ]) .to_matchable(), ]) @@ -2751,13 +2514,16 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AlterSequenceStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterSequenceStatement, |_| { - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("SEQUENCE").to_matchable(), - Ref::new("SequenceReferenceSegment").to_matchable(), - AnyNumberOf::new(vec![Ref::new("AlterSequenceOptionsSegment").to_matchable()]) + "TableExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::TableExpression, |_dialect| { + one_of(vec![ + Ref::new("ValuesClauseSegment").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + Bracketed::new(vec![Ref::new("MergeStatementSegment").to_matchable()]) .to_matchable(), ]) .to_matchable() @@ -2766,69 +2532,54 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "DropSequenceStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropSequenceStatement, |_| { + "WildcardIdentifierSegment".into(), + NodeMatcher::new(SyntaxKind::WildcardIdentifier, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("SEQUENCE").to_matchable(), - Ref::new("SequenceReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ObjectReferenceDelimiterGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("StarSegment").to_matchable(), + Ref::new("DotSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("StarSegment").to_matchable(), ]) + .config(|this| { + this.disallow_gaps(); + }) .to_matchable() }) .to_matchable() .into(), ), ( - "DropCastStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropCastStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("CAST").to_matchable(), - Bracketed::new(vec![ - Ref::new("DatatypeSegment").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable() + "WildcardExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::WildcardExpression, |_dialect| { + Sequence::new(vec![Ref::new("WildcardIdentifierSegment").to_matchable()]) + .to_matchable() }) .to_matchable() .into(), ), ( - "CreateFunctionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateFunctionStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::new("TemporaryGrammar").optional().to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar").to_matchable(), + "SelectClauseElementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClauseElement, |_dialect| { + one_of(vec![ + Ref::new("WildcardExpressionSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("RETURNS").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), + Ref::new("BaseExpressionElementGrammar").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::new("FunctionDefinitionGrammar").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "DropFunctionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), ]) .to_matchable() }) @@ -2836,47 +2587,11 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "CreateModelStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateModelStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::keyword("MODEL").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OPTIONS").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), // Single value - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.bracket_type("square"); - this.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), + "SelectClauseModifierSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClauseModifier, |_dialect| { + one_of(vec![ + Ref::keyword("DISTINCT").to_matchable(), + Ref::keyword("ALL").to_matchable(), ]) .to_matchable() }) @@ -2884,107 +2599,88 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "CreateViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateViewStatement, |_| { + "SelectClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") + Ref::keyword("SELECT").to_matchable(), + Ref::new("SelectClauseModifierSegment") .optional() .to_matchable(), - Ref::keyword("AS").to_matchable(), - optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) - .to_matchable(), - Ref::new("WithNoSchemaBindingClauseSegment") - .optional() + MetaSegment::indent().to_matchable(), + Delimited::new(vec![Ref::new("SelectClauseElementSegment").to_matchable()]) + .config(|this| { + this.allow_trailing(); + }) .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) + .config(|this| { + this.parse_mode(ParseMode::GreedyOnceStarted); + this.terminators = + vec![Ref::new("SelectClauseTerminatorGrammar").to_matchable()]; + }) .to_matchable() }) .to_matchable() .into(), ), ( - "DeleteStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DeleteStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DELETE").to_matchable(), - Ref::new("FromClauseSegment").to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), - ]) - .to_matchable() + "MatchConditionSegment".into(), + NodeMatcher::new(SyntaxKind::MatchCondition, |_dialect| { + Nothing::new().to_matchable() }) .to_matchable() .into(), ), ( - "UpdateStatementSegment".into(), - NodeMatcher::new(SyntaxKind::UpdateStatement, |_| { - Sequence::new(vec![ - Ref::keyword("UPDATE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("AliasExpressionSegment") - .exclude(Ref::keyword("SET")) - .optional() - .to_matchable(), - Ref::new("SetClauseListSegment").to_matchable(), - Ref::new("FromClauseSegment").optional().to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "CreateCastStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateCastStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("CAST").to_matchable(), - Bracketed::new(vec![ - Ref::new("DatatypeSegment").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("WITH").to_matchable(), - Ref::keyword("SPECIFIC").optional().to_matchable(), - one_of(vec![ - Ref::keyword("ROUTINE").to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Ref::keyword("PROCEDURE").to_matchable(), + "JoinClauseSegment".into(), + NodeMatcher::new(SyntaxKind::JoinClause, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::new("ConditionalJoinKeywordsGrammar") + .optional() + .to_matchable(), + Ref::new("JoinKeywordsGrammar").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("FromExpressionElementSegment").to_matchable(), + AnyNumberOf::new(vec![Ref::new("NestedJoinGrammar").to_matchable()]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), Sequence::new(vec![ + Conditional::new(MetaSegment::indent()) + .indented_using_on() + .to_matchable(), + Ref::new("MatchConditionSegment").optional().to_matchable(), one_of(vec![ - Ref::keyword("INSTANCE").to_matchable(), - Ref::keyword("STATIC").to_matchable(), - Ref::keyword("CONSTRUCTOR").to_matchable(), + Ref::new("JoinOnConditionSegment").to_matchable(), + Ref::new("JoinUsingConditionGrammar").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::keyword("METHOD").to_matchable(), + Conditional::new(MetaSegment::dedent()) + .indented_using_on() + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar") - .optional() - .to_matchable(), Sequence::new(vec![ - Ref::keyword("FOR").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("UnconditionalJoinKeywordsGrammar").to_matchable(), + Ref::new("JoinKeywordsGrammar").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("FromExpressionElementSegment").to_matchable(), + Ref::new("MatchConditionSegment").optional().to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::keyword("ASSIGNMENT").to_matchable(), + Ref::new("ExtendedNaturalJoinKeywordsGrammar").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("FromExpressionElementSegment").to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable() @@ -2993,40 +2689,38 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "CreateRoleStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateRoleStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "DropRoleStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropRoleStatement, |_| { + "JoinOnConditionSegment".into(), + NodeMatcher::new(SyntaxKind::JoinOnCondition, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("ON").to_matchable(), + Conditional::new(MetaSegment::implicit_indent()) + .indented_on_contents() + .to_matchable(), + optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + Conditional::new(MetaSegment::dedent()) + .indented_on_contents() + .to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), + ]); + + ansi_dialect.add([( + "JoinLikeClauseGrammar".into(), + Nothing::new().to_matchable().into(), + )]); + + ansi_dialect.add([ ( - "AlterTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterTableStatement, |_| { + "FromClauseSegment".into(), + NodeMatcher::new(SyntaxKind::FromClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Delimited::new(vec![Ref::new("AlterTableOptionsGrammar").to_matchable()]) + Ref::keyword("FROM").to_matchable(), + Delimited::new(vec![Ref::new("FromExpressionSegment").to_matchable()]) .to_matchable(), ]) .to_matchable() @@ -3035,13 +2729,30 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "SetSchemaStatementSegment".into(), - NodeMatcher::new(SyntaxKind::SetSchemaStatement, |_| { + "WhenClauseSegment".into(), + NodeMatcher::new(SyntaxKind::WhenClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), + Ref::keyword("WHEN").to_matchable(), + Sequence::new(vec![ + MetaSegment::implicit_indent().to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable(), + Conditional::new(MetaSegment::indent()) + .indented_then() + .to_matchable(), + Ref::keyword("THEN").to_matchable(), + Conditional::new(MetaSegment::implicit_indent()) + .indented_then_contents() + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Conditional::new(MetaSegment::dedent()) + .indented_then_contents() + .to_matchable(), + Conditional::new(MetaSegment::dedent()) + .indented_then() + .to_matchable(), ]) .to_matchable() }) @@ -3049,14 +2760,13 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "DropSchemaStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropSchemaStatement, |_| { + "ElseClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ElseClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), + Ref::keyword("ELSE").to_matchable(), + MetaSegment::implicit_indent().to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) @@ -3064,531 +2774,1304 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "DropTypeStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropTypeStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("TYPE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), + "CaseExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::CaseExpression, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CASE").to_matchable(), + MetaSegment::implicit_indent().to_matchable(), + AnyNumberOf::new(vec![Ref::new("WhenClauseSegment").to_matchable()]) + .config(|this| { + this.reset_terminators = true; + this.terminators = vec![ + Ref::keyword("ELSE").to_matchable(), + Ref::keyword("END").to_matchable(), + ]; + }) + .to_matchable(), + Ref::new("ElseClauseSegment") + .optional() + .terminators(vec![Ref::keyword("END").to_matchable()]) + .reset_terminators() + .to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::keyword("END").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CASE").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + MetaSegment::implicit_indent().to_matchable(), + AnyNumberOf::new(vec![Ref::new("WhenClauseSegment").to_matchable()]) + .config(|this| { + this.reset_terminators = true; + this.terminators = vec![ + Ref::keyword("ELSE").to_matchable(), + Ref::keyword("END").to_matchable(), + ]; + }) + .to_matchable(), + Ref::new("ElseClauseSegment") + .optional() + .terminators(vec![Ref::keyword("END").to_matchable()]) + .reset_terminators() + .to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::keyword("END").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.terminators = vec![ + Ref::new("ComparisonOperatorGrammar").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("BinaryOperatorGrammar").to_matchable(), + ]; + }) .to_matchable() }) .to_matchable() .into(), ), + ]); + + ansi_dialect.add([ ( - "CreateDatabaseStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateDatabaseStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .to_matchable() - }) + "Expression_A_Unary_Operator_Grammar".into(), + one_of(vec![ + Ref::new("SignedSegmentGrammar") + .exclude(Sequence::new(vec![ + Ref::new("QualifiedNumericLiteralSegment").to_matchable(), + ])) + .to_matchable(), + Ref::new("TildeSegment").to_matchable(), + Ref::new("NotOperatorGrammar").to_matchable(), + Ref::keyword("PRIOR").to_matchable(), + ]) .to_matchable() .into(), ), ( - "DropDatabaseStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropDatabaseStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), + "Tail_Recurse_Expression_A_Grammar".into(), + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Ref::new("Expression_A_Unary_Operator_Grammar").to_matchable(), ]) - .to_matchable() - }) + .config(|this| { + this.terminators = vec![Ref::new("BinaryOperatorGrammar").to_matchable()]; + }) + .to_matchable(), + Ref::new("Expression_C_Grammar").to_matchable(), + ]) .to_matchable() .into(), ), ( - "FunctionParameterListGrammar".into(), - NodeMatcher::new(SyntaxKind::FunctionParameterList, |_| { - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("FunctionParameterGrammar").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "CreateIndexStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateIndexStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::keyword("UNIQUE").optional().to_matchable(), - Ref::keyword("INDEX").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("IndexReferenceSegment").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("IndexColumnDefinitionSegment").to_matchable(), + "Expression_A_Grammar".into(), + Sequence::new(vec![ + Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(), + AnyNumberOf::new(vec![ + one_of(vec![ + Ref::new("LikeExpressionGrammar").to_matchable(), + Sequence::new(vec![ + Ref::new("BinaryOperatorGrammar").to_matchable(), + Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("InOperatorGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("IS").to_matchable(), + Ref::keyword("NOT").optional().to_matchable(), + Ref::new("IsClauseGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("IsNullGrammar").to_matchable(), + Ref::new("NotNullGrammar").to_matchable(), + Ref::new("CollateGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("BETWEEN").to_matchable(), + Ref::new("Expression_B_Grammar").to_matchable(), + Ref::keyword("AND").to_matchable(), + Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("PatternMatchingGrammar").to_matchable(), + Ref::new("Expression_A_Grammar").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) - .to_matchable() - }) + .to_matchable(), + ]) .to_matchable() .into(), ), ( - "DropIndexStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropIndexStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("INDEX").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("IndexReferenceSegment").to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), + "Expression_B_Unary_Operator_Grammar".into(), + one_of(vec![ + Ref::new("SignedSegmentGrammar") + .exclude(Sequence::new(vec![ + Ref::new("QualifiedNumericLiteralSegment").to_matchable(), + ])) + .to_matchable(), + Ref::new("TildeSegment").to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "Tail_Recurse_Expression_B_Grammar".into(), + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Ref::new("Expression_B_Unary_Operator_Grammar").to_matchable(), ]) - .to_matchable() - }) + .to_matchable(), + Ref::new("Expression_C_Grammar").to_matchable(), + ]) .to_matchable() .into(), ), ( - "CreateTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateTableStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::new("TemporaryTransientGrammar") - .optional() - .to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), + "Expression_B_Grammar".into(), + Sequence::new(vec![ + Ref::new("Tail_Recurse_Expression_B_Grammar").to_matchable(), + AnyNumberOf::new(vec![ one_of(vec![ - // Columns and comment syntax - Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("TableConstraintSegment").to_matchable(), - Ref::new("ColumnDefinitionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("CommentClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - // Create AS syntax: Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - optionally_bracketed(vec![ - Ref::new("SelectableGrammar").to_matchable(), + one_of(vec![ + Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(), + Ref::new("StringBinaryOperatorGrammar").to_matchable(), + Ref::new("ComparisonOperatorGrammar").to_matchable(), ]) .to_matchable(), + Ref::new("Tail_Recurse_Expression_B_Grammar").to_matchable(), ]) .to_matchable(), - // Create LIKE syntax - Sequence::new(vec![ - Ref::keyword("LIKE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "Expression_C_Grammar".into(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("EXISTS").to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("Expression_D_Grammar").to_matchable(), + Ref::new("CaseExpressionSegment").to_matchable(), ]) .to_matchable(), - Ref::new("TableEndClauseSegment").optional().to_matchable(), + AnyNumberOf::new(vec![Ref::new("TimeZoneGrammar").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) - .to_matchable() + .to_matchable(), + Ref::new("ShorthandCastSegment").to_matchable(), + ]) + .config(|this| { + this.terminators = vec![Ref::new("CommaSegment").to_matchable()]; }) .to_matchable() .into(), ), ( - "AccessStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AccessStatement, |_| { - { - let global_permissions = one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - one_of(vec![ - Ref::keyword("ROLE").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::keyword("WAREHOUSE").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("INTEGRATION").to_matchable(), + "Expression_D_Potential_Select_Statement_Without_Brackets".into(), + one_of(vec![ + Ref::new("SelectStatementSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("IntervalExpressionSegment").to_matchable(), + Ref::new("TypedStructLiteralSegment").to_matchable(), + Ref::new("ArrayExpressionSegment").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("OverlapsClauseSegment").to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "Expression_D_Grammar".into(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + Delimited::new(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("LocalAliasSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("APPLY").to_matchable(), - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("EXECUTE").to_matchable(), - Ref::keyword("TASK").to_matchable(), - ]) + ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + Ref::new("Expression_D_Potential_Select_Statement_Without_Brackets") .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MANAGE").to_matchable(), - Ref::keyword("GRANTS").to_matchable(), + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ObjectReferenceDelimiterGrammar").to_matchable(), + Ref::new("StarSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("StructTypeSegment").to_matchable(), + Ref::new("MapTypeSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MONITOR").to_matchable(), - one_of(vec![ - Ref::keyword("EXECUTION").to_matchable(), - Ref::keyword("USAGE").to_matchable(), - ]) - .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), ]) .to_matchable(), - ]); - - let schema_object_types = one_of(vec![ - Ref::keyword("TABLE").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::keyword("STAGE").to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Ref::keyword("PROCEDURE").to_matchable(), - Ref::keyword("ROUTINE").to_matchable(), - Ref::keyword("SEQUENCE").to_matchable(), - Ref::keyword("STREAM").to_matchable(), - Ref::keyword("TASK").to_matchable(), - ]); - - let permissions = Sequence::new(vec![ + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("DatatypeSegment").to_matchable(), one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - one_of(vec![ - Ref::keyword("SCHEMA").to_matchable(), - Sequence::new(vec![ - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("PIPE").to_matchable(), - schema_object_types.clone().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("IMPORTED").to_matchable(), - Ref::keyword("PRIVILEGES").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("APPLY").to_matchable(), - Ref::keyword("CONNECT").to_matchable(), - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("DELETE").to_matchable(), - Ref::keyword("EXECUTE").to_matchable(), - Ref::keyword("INSERT").to_matchable(), - Ref::keyword("MODIFY").to_matchable(), - Ref::keyword("MONITOR").to_matchable(), - Ref::keyword("OPERATE").to_matchable(), - Ref::keyword("OWNERSHIP").to_matchable(), - Ref::keyword("READ").to_matchable(), - Ref::keyword("REFERENCE_USAGE").to_matchable(), - Ref::keyword("REFERENCES").to_matchable(), - Ref::keyword("SELECT").to_matchable(), - Ref::keyword("TEMP").to_matchable(), - Ref::keyword("TEMPORARY").to_matchable(), - Ref::keyword("TRIGGER").to_matchable(), - Ref::keyword("TRUNCATE").to_matchable(), - Ref::keyword("UPDATE").to_matchable(), - Ref::keyword("USAGE").to_matchable(), - Ref::keyword("USE_ANY_ROLE").to_matchable(), - Ref::keyword("WRITE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("PRIVILEGES").optional().to_matchable(), - ]) - .to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::new("NullLiteralSegment").to_matchable(), + Ref::new("DateTimeLiteralGrammar").to_matchable(), ]) .to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - ]); + ]) + .to_matchable(), + Ref::new("LocalAliasSegment").to_matchable(), + Ref::new("ListComprehensionGrammar").to_matchable(), + ]) + .config(|this| { + this.terminators = vec![Ref::new("CommaSegment").to_matchable()]; + }) + .to_matchable(), + Ref::new("AccessorGrammar").optional().to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "AccessorGrammar".into(), + AnyNumberOf::new(vec![Ref::new("ArrayAccessorSegment").to_matchable()]) + .to_matchable() + .into(), + ), + ]); - let objects = one_of(vec![ - Ref::keyword("ACCOUNT").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("RESOURCE").to_matchable(), - Ref::keyword("MONITOR").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("WAREHOUSE").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("DOMAIN").to_matchable(), - Ref::keyword("INTEGRATION").to_matchable(), - Ref::keyword("LANGUAGE").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Ref::keyword("TABLESPACE").to_matchable(), - Ref::keyword("TYPE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("FOREIGN").to_matchable(), - one_of(vec![ - Ref::keyword("SERVER").to_matchable(), - Sequence::new(vec![ - Ref::keyword("DATA").to_matchable(), - Ref::keyword("WRAPPER").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("SCHEMAS").to_matchable(), - Ref::keyword("IN").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FUTURE").to_matchable(), - Ref::keyword("SCHEMAS").to_matchable(), - Ref::keyword("IN").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - ]) - .to_matchable(), - schema_object_types.clone().to_matchable(), - Sequence::new(vec![ - Ref::keyword("ALL").to_matchable(), - one_of(vec![ - Ref::keyword("TABLES").to_matchable(), - Ref::keyword("VIEWS").to_matchable(), - Ref::keyword("STAGES").to_matchable(), - Ref::keyword("FUNCTIONS").to_matchable(), - Ref::keyword("PROCEDURES").to_matchable(), - Ref::keyword("ROUTINES").to_matchable(), - Ref::keyword("SEQUENCES").to_matchable(), - Ref::keyword("STREAMS").to_matchable(), - Ref::keyword("TASKS").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("IN").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FUTURE").to_matchable(), - Ref::keyword("IN").to_matchable(), - one_of(vec![ - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Delimited::new(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.terminators = vec![ - Ref::keyword("TO").to_matchable(), - Ref::keyword("FROM").to_matchable(), - ] - }) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LARGE").to_matchable(), - Ref::keyword("OBJECT").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) + ansi_dialect.add([ + ( + "EqualsSegment".into(), + NodeMatcher::new(SyntaxKind::ComparisonOperator, |_dialect| { + Ref::new("RawEqualsSegment").to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "GreaterThanSegment".into(), + NodeMatcher::new(SyntaxKind::ComparisonOperator, |_dialect| { + Ref::new("RawGreaterThanSegment").to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "LessThanSegment".into(), + NodeMatcher::new(SyntaxKind::ComparisonOperator, |_dialect| { + Ref::new("RawLessThanSegment").to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "GreaterThanOrEqualToSegment".into(), + NodeMatcher::new(SyntaxKind::ComparisonOperator, |_dialect| { + Sequence::new(vec![ + Ref::new("RawGreaterThanSegment").to_matchable(), + Ref::new("RawEqualsSegment").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "LessThanOrEqualToSegment".into(), + NodeMatcher::new(SyntaxKind::ComparisonOperator, |_dialect| { + Sequence::new(vec![ + Ref::new("RawLessThanSegment").to_matchable(), + Ref::new("RawEqualsSegment").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "NotEqualToSegment".into(), + NodeMatcher::new(SyntaxKind::ComparisonOperator, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::new("RawNotSegment").to_matchable(), + Ref::new("RawEqualsSegment").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::new("RawLessThanSegment").to_matchable(), + Ref::new("RawGreaterThanSegment").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ConcatSegment".into(), + NodeMatcher::new(SyntaxKind::BinaryOperator, |_dialect| { + Sequence::new(vec![ + Ref::new("PipeSegment").to_matchable(), + Ref::new("PipeSegment").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "BitwiseAndSegment".into(), + NodeMatcher::new(SyntaxKind::BinaryOperator, |_dialect| { + Ref::new("AmpersandSegment").to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "BitwiseOrSegment".into(), + NodeMatcher::new(SyntaxKind::BinaryOperator, |_dialect| { + Ref::new("PipeSegment").to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "BitwiseLShiftSegment".into(), + NodeMatcher::new(SyntaxKind::BinaryOperator, |_dialect| { + Sequence::new(vec![ + Ref::new("RawLessThanSegment").to_matchable(), + Ref::new("RawLessThanSegment").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "BitwiseRShiftSegment".into(), + NodeMatcher::new(SyntaxKind::BinaryOperator, |_dialect| { + Sequence::new(vec![ + Ref::new("RawGreaterThanSegment").to_matchable(), + Ref::new("RawGreaterThanSegment").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::Expression, |_dialect| { + Ref::new("Expression_A_Grammar").to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WhereClauseSegment".into(), + NodeMatcher::new(SyntaxKind::WhereClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("WHERE").to_matchable(), + MetaSegment::implicit_indent().to_matchable(), + optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) .to_matchable(), - ]); - - one_of(vec![ + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "OrderByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::OrderbyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ Sequence::new(vec![ - Ref::keyword("GRANT").to_matchable(), one_of(vec![ - Sequence::new(vec![ - Delimited::new(vec![ - one_of(vec![ - global_permissions.clone().to_matchable(), - permissions.clone().to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.terminators = vec![Ref::keyword("ON").to_matchable()] - }) - .to_matchable(), - Ref::keyword("ON").to_matchable(), - objects.clone().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ROLE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OWNERSHIP").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - Ref::keyword("TO").to_matchable(), one_of(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Ref::keyword("SHARE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Ref::new("RoleReferenceSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Ref::keyword("PUBLIC").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("ASC").to_matchable(), + Ref::keyword("DESC").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("AccessStatementSegmentGrantRoleWithOptionGrammar") - .optional() - .to_matchable(), Sequence::new(vec![ - Ref::keyword("GRANTED").to_matchable(), - Ref::keyword("BY").to_matchable(), + Ref::keyword("NULLS").to_matchable(), one_of(vec![ - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("LAST").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("WithFillSegment").optional().to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("REVOKE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("GRANT").to_matchable(), - Ref::keyword("OPTION").to_matchable(), - Ref::keyword("FOR").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Delimited::new(vec![ - one_of(vec![ - global_permissions.to_matchable(), - permissions.to_matchable(), - ]) - .config(|this| { - this.terminators = - vec![Ref::keyword("ON").to_matchable()] - }) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("ON").to_matchable(), - objects.to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ROLE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OWNERSHIP").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::new("LimitClauseSegment").to_matchable(), + Ref::new("FrameClauseUnitGrammar").to_matchable(), + ]; + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "RollupFunctionNameSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionName, |_dialect| { + StringParser::new("ROLLUP", SyntaxKind::FunctionNameIdentifier).to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CubeFunctionNameSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionName, |_dialect| { + StringParser::new("CUBE", SyntaxKind::FunctionNameIdentifier).to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "GroupingSetsClauseSegment".into(), + NodeMatcher::new(SyntaxKind::GroupingSetsClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("GROUPING").to_matchable(), + Ref::keyword("SETS").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("CubeRollupClauseSegment").to_matchable(), + Ref::new("GroupingExpressionList").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "GroupingExpressionList".into(), + NodeMatcher::new(SyntaxKind::GroupingExpressionList, |_dialect| { + Sequence::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Bracketed::new(vec![]).to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = + vec![Ref::new("GroupByClauseTerminatorGrammar").to_matchable()]; + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CubeRollupClauseSegment".into(), + NodeMatcher::new(SyntaxKind::CubeRollupClause, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::new("CubeFunctionNameSegment").to_matchable(), + Ref::new("RollupFunctionNameSegment").to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![Ref::new("GroupingExpressionList").to_matchable()]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "GroupByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::GroupbyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::new("GroupingSetsClauseSegment").to_matchable(), + Ref::new("CubeRollupClauseSegment").to_matchable(), + Sequence::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), ]) + .config(|this| { + this.terminators = + vec![Ref::new("GroupByClauseTerminatorGrammar").to_matchable()]; + }) .to_matchable(), - Ref::keyword("FROM").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "HavingClauseSegment".into(), + NodeMatcher::new(SyntaxKind::HavingClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("HAVING").to_matchable(), + MetaSegment::implicit_indent().to_matchable(), + optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "LimitClauseSegment".into(), + NodeMatcher::new(SyntaxKind::LimitClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("LIMIT").to_matchable(), + MetaSegment::indent().to_matchable(), + optionally_bracketed(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("OFFSET").to_matchable(), one_of(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Ref::keyword("SHARE").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) - .to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("CommaSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "OverlapsClauseSegment".into(), + NodeMatcher::new(SyntaxKind::OverlapsClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("OVERLAPS").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Bracketed::new(vec![ + Ref::new("DateTimeLiteralGrammar").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("DateTimeLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "NamedWindowSegment".into(), + NodeMatcher::new(SyntaxKind::NamedWindow, |_dialect| { + Sequence::new(vec![ + Ref::keyword("WINDOW").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Ref::new("NamedWindowExpressionSegment").to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FetchClauseSegment".into(), + NodeMatcher::new(SyntaxKind::FetchClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("FETCH").to_matchable(), + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("NEXT").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment") + .exclude(Ref::keyword("ROW")) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ROWS").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("ONLY").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("TIES").to_matchable(), ]) .to_matchable(), ]) - } + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "OffsetClauseSegment".into(), + NodeMatcher::new(SyntaxKind::OffsetClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("OFFSET").to_matchable(), + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment") + .exclude(Ref::keyword("ROW")) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ROWS").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "NamedWindowExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::NamedWindowExpression, |_dialect| { + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Bracketed::new(vec![Ref::new("WindowSpecificationSegment").to_matchable()]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ValuesClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ValuesClause, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("VALUE").to_matchable(), + Ref::keyword("VALUES").to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("ROW").optional().to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UnorderedSelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + Sequence::new(vec![ + Ref::new("SelectClauseSegment").to_matchable(), + Ref::new("FromClauseSegment").optional().to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + Ref::new("GroupByClauseSegment").optional().to_matchable(), + Ref::new("HavingClauseSegment").optional().to_matchable(), + Ref::new("OverlapsClauseSegment").optional().to_matchable(), + Ref::new("NamedWindowSegment").optional().to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::GreedyOnceStarted); + this.terminators = vec![ + Ref::new("SetOperatorSegment").to_matchable(), + Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), + Ref::new("WithDataClauseSegment").to_matchable(), + Ref::new("OrderByClauseSegment").to_matchable(), + Ref::new("LimitClauseSegment").to_matchable(), + ]; + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + get_unordered_select_statement_segment_grammar().copy( + Some(vec![ + Ref::new("OrderByClauseSegment").optional().to_matchable(), + Ref::new("OffsetClauseSegment").optional().to_matchable(), + Ref::new("FetchClauseSegment").optional().to_matchable(), + Ref::new("LimitClauseSegment").optional().to_matchable(), + Ref::new("NamedWindowSegment").optional().to_matchable(), + ]), + None, + None, + None, + vec![ + Ref::new("SetOperatorSegment").to_matchable(), + Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), + Ref::new("WithDataClauseSegment").to_matchable(), + ], + true, + ) + }) + .to_matchable() + .into(), + ), + ]); + + ansi_dialect.add([ + ( + "SelectableGrammar".into(), + one_of(vec![ + optionally_bracketed(vec![ + Ref::new("WithCompoundStatementSegment").to_matchable(), + ]) + .to_matchable(), + optionally_bracketed(vec![ + Ref::new("WithCompoundNonSelectStatementSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("NonWithSelectableGrammar").to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "NonWithSelectableGrammar".into(), + one_of(vec![ + Ref::new("SetExpressionSegment").to_matchable(), + optionally_bracketed(vec![Ref::new("SelectStatementSegment").to_matchable()]) + .to_matchable(), + Ref::new("NonSetSelectableGrammar").to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "NonWithNonSelectableGrammar".into(), + one_of(vec![ + Ref::new("UpdateStatementSegment").to_matchable(), + Ref::new("InsertStatementSegment").to_matchable(), + Ref::new("DeleteStatementSegment").to_matchable(), + Ref::new("MergeStatementSegment").to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "NonSetSelectableGrammar".into(), + one_of(vec![ + Ref::new("ValuesClauseSegment").to_matchable(), + Ref::new("UnorderedSelectStatementSegment").to_matchable(), + Bracketed::new(vec![Ref::new("SelectStatementSegment").to_matchable()]) + .to_matchable(), + Bracketed::new(vec![ + Ref::new("WithCompoundStatementSegment").to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![Ref::new("NonSetSelectableGrammar").to_matchable()]) + .to_matchable(), + Ref::new("BracketedSetExpressionGrammar").to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "BracketedSetExpressionGrammar".into(), + Bracketed::new(vec![ + Ref::new("UnorderedSetExpressionSegment").to_matchable(), + ]) + .to_matchable() + .into(), + ), + ]); + + ansi_dialect.add([ + ( + "CTEColumnList".into(), + NodeMatcher::new(SyntaxKind::CTEColumnList, |_dialect| { + Bracketed::new(vec![Ref::new("SingleIdentifierListSegment").to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CTEDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::CommonTableExpression, |_dialect| { + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("CTEColumnList").optional().to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WithCompoundStatementSegment".into(), + NodeMatcher::new(SyntaxKind::WithCompoundStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("RECURSIVE").optional().to_matchable(), + Conditional::new(MetaSegment::indent()) + .indented_ctes() + .to_matchable(), + Delimited::new(vec![Ref::new("CTEDefinitionSegment").to_matchable()]) + .config(|this| { + this.allow_trailing(); + this.terminators = vec![Ref::keyword("SELECT").to_matchable()]; + }) + .to_matchable(), + Conditional::new(MetaSegment::dedent()) + .indented_ctes() + .to_matchable(), + Ref::new("NonWithSelectableGrammar").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WithCompoundNonSelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::WithCompoundStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("RECURSIVE").optional().to_matchable(), + Conditional::new(MetaSegment::indent()) + .indented_ctes() + .to_matchable(), + Delimited::new(vec![Ref::new("CTEDefinitionSegment").to_matchable()]) + .config(|this| { + this.allow_trailing(); + this.terminators = vec![Ref::keyword("SELECT").to_matchable()]; + }) + .to_matchable(), + Conditional::new(MetaSegment::dedent()) + .indented_ctes() + .to_matchable(), + Ref::new("NonWithNonSelectableGrammar").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SetOperatorSegment".into(), + NodeMatcher::new(SyntaxKind::SetOperator, |_dialect| { + one_of(vec![ + Ref::new("UnionGrammar").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("INTERSECT").to_matchable(), + Ref::keyword("EXCEPT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("ALL").optional().to_matchable(), + ]) + .to_matchable(), + Ref::keyword("MINUS").to_matchable(), + ]) + .config(|this| { + this.exclude = Some( + Sequence::new(vec![ + Ref::keyword("EXCEPT").to_matchable(), + Bracketed::new(vec![Anything::new().to_matchable()]).to_matchable(), + ]) + .to_matchable(), + ); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UnorderedSetExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::SetExpression, |_dialect| { + Sequence::new(vec![ + Ref::new("NonSetSelectableGrammar").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("SetOperatorSegment").to_matchable(), + Ref::new("NonSetSelectableGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SetExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::SetExpression, |_dialect| { + get_unordered_set_expression_segment_grammar().copy( + Some(vec![ + Ref::new("OrderByClauseSegment").optional().to_matchable(), + Ref::new("LimitClauseSegment").optional().to_matchable(), + Ref::new("NamedWindowSegment").optional().to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "InsertStatementSegment".into(), + NodeMatcher::new(SyntaxKind::InsertStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("OVERWRITE").optional().to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Ref::new("SelectableGrammar").to_matchable(), + Sequence::new(vec![ + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("DefaultValuesGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MergeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::MergeStatement, |_dialect| { + Sequence::new(vec![ + Ref::new("MergeIntoLiteralGrammar").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("AliasedTableReferenceGrammar").to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::keyword("USING").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("AliasedTableReferenceGrammar").to_matchable(), + Sequence::new(vec![ + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + Conditional::new(MetaSegment::indent()) + .indented_using_on() + .to_matchable(), + Ref::new("JoinOnConditionSegment").to_matchable(), + Conditional::new(MetaSegment::dedent()) + .indented_using_on() + .to_matchable(), + Ref::new("MergeMatchSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MergeMatchSegment".into(), + NodeMatcher::new(SyntaxKind::MergeMatch, |_dialect| { + AnyNumberOf::new(vec![ + Ref::new("MergeMatchedClauseSegment").to_matchable(), + Ref::new("MergeNotMatchedClauseSegment").to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MergeMatchedClauseSegment".into(), + NodeMatcher::new(SyntaxKind::MergeWhenMatchedClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("WHEN").to_matchable(), + Ref::keyword("MATCHED").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AND").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("THEN").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::new("MergeUpdateClauseSegment").to_matchable(), + Ref::new("MergeDeleteClauseSegment").to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MergeNotMatchedClauseSegment".into(), + NodeMatcher::new(SyntaxKind::MergeWhenNotMatchedClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("WHEN").to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("MATCHED").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AND").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("THEN").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("MergeInsertClauseSegment").to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MergeUpdateClauseSegment".into(), + NodeMatcher::new(SyntaxKind::MergeUpdateClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("UPDATE").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("SetClauseListSegment").to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) .to_matchable() }) .to_matchable() .into(), ), ( - "InsertStatementSegment".into(), - NodeMatcher::new(SyntaxKind::InsertStatement, |_| { + "MergeInsertClauseSegment".into(), + NodeMatcher::new(SyntaxKind::MergeInsertClause, |_dialect| { Sequence::new(vec![ Ref::keyword("INSERT").to_matchable(), - Ref::keyword("OVERWRITE").optional().to_matchable(), - Ref::keyword("INTO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - one_of(vec![ - Ref::new("SelectableGrammar").to_matchable(), - Sequence::new(vec![ - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), - ]) + MetaSegment::indent().to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() .to_matchable(), - Ref::new("DefaultValuesGrammar").to_matchable(), - ]) - .to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::new("ValuesClauseSegment").optional().to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), + ( + "MergeDeleteClauseSegment".into(), + NodeMatcher::new(SyntaxKind::MergeDeleteClause, |_dialect| { + Ref::keyword("DELETE").to_matchable() + }) + .to_matchable() + .into(), + ), ( "TransactionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::TransactionStatement, |_| { + NodeMatcher::new(SyntaxKind::TransactionStatement, |_dialect| { Sequence::new(vec![ one_of(vec![ Ref::keyword("START").to_matchable(), @@ -3602,20 +4085,26 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("TRANSACTION").to_matchable(), Ref::keyword("WORK").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ Ref::keyword("NAME").to_matchable(), Ref::new("SingleIdentifierGrammar").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ Ref::keyword("AND").to_matchable(), Ref::keyword("NO").optional().to_matchable(), Ref::keyword("CHAIN").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -3624,44 +4113,55 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "DropTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropTableStatement, |_| { + "ColumnConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::new("TemporaryGrammar").optional().to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()]) + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) .to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "DropViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropViewStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "CreateUserStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateUserStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("CHECK").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("ColumnConstraintDefaultGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("PrimaryKeyGrammar").to_matchable(), + Ref::new("NotEnforcedGrammar").optional().to_matchable(), + ]) + .to_matchable(), + Ref::new("UniqueKeyGrammar").to_matchable(), + Ref::new("AutoIncrementGrammar").to_matchable(), + Sequence::new(vec![ + Ref::new("ReferenceDefinitionGrammar").to_matchable(), + Ref::new("NotEnforcedGrammar").optional().to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ColumnGeneratedGrammar").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) @@ -3669,34 +4169,21 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "DropUserStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropUserStatement, |_| { + "ColumnDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnDefinition, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "NotEqualToSegment".into(), - NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::new("RawNotSegment").to_matchable(), - Ref::new("RawEqualsSegment").to_matchable(), - ]) - .allow_gaps(false) - .to_matchable(), - Sequence::new(vec![ - Ref::new("RawLessThanSegment").to_matchable(), - Ref::new("RawGreaterThanSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Bracketed::new(vec![Anything::new().to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("ColumnConstraintSegment") + .optional() + .to_matchable(), ]) - .allow_gaps(false) .to_matchable(), ]) .to_matchable() @@ -3705,82 +4192,54 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "ConcatSegment".into(), - NodeMatcher::new(SyntaxKind::BinaryOperator, |_| { + "IndexColumnDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::IndexColumnDefinition, |_dialect| { Sequence::new(vec![ - Ref::new("PipeSegment").to_matchable(), - Ref::new("PipeSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + one_of(vec![ + Ref::keyword("ASC").to_matchable(), + Ref::keyword("DESC").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) - .allow_gaps(false) .to_matchable() }) .to_matchable() .into(), ), ( - "ArrayExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::ArrayExpression, |_| { - Nothing::new().to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "LocalAliasSegment".into(), - NodeMatcher::new(SyntaxKind::LocalAlias, |_| Nothing::new().to_matchable()) - .to_matchable() - .into(), - ), - ( - "MergeStatementSegment".into(), - NodeMatcher::new(SyntaxKind::MergeStatement, |_| { + "TableConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::TableConstraint, |_dialect| { Sequence::new(vec![ - Ref::new("MergeIntoLiteralGrammar").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("AliasedTableReferenceGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - MetaSegment::dedent().to_matchable(), - Ref::keyword("USING").to_matchable(), - MetaSegment::indent().to_matchable(), one_of(vec![ - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("AliasedTableReferenceGrammar").to_matchable(), Sequence::new(vec![ - Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) - .to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), + Ref::keyword("UNIQUE").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - Conditional::new(MetaSegment::indent()) - .indented_using_on() + Sequence::new(vec![ + Ref::new("PrimaryKeyGrammar").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + ]) .to_matchable(), - Ref::new("JoinOnConditionSegment").to_matchable(), - Conditional::new(MetaSegment::dedent()) - .indented_using_on() + Sequence::new(vec![ + Ref::new("ForeignKeyGrammar").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::new("ReferenceDefinitionGrammar").to_matchable(), + ]) .to_matchable(), - Ref::new("MergeMatchSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "IndexColumnDefinitionSegment".into(), - NodeMatcher::new(SyntaxKind::IndexColumnDefinition, |_| { - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), // Column name - one_of(vec![ - Ref::keyword("ASC").to_matchable(), - Ref::keyword("DESC").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable() @@ -3789,103 +4248,120 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "BitwiseAndSegment".into(), - NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| { - Ref::new("AmpersandSegment").to_matchable() + "TableEndClauseSegment".into(), + NodeMatcher::new(SyntaxKind::TableEndClauseSegment, |_dialect| { + Nothing::new().to_matchable() }) .to_matchable() .into(), ), ( - "BitwiseOrSegment".into(), - NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| { - Ref::new("PipeSegment").to_matchable() + "ArrayExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayExpression, |_dialect| { + Nothing::new().to_matchable() }) .to_matchable() .into(), ), ( - "BitwiseLShiftSegment".into(), - NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| { + "CreateTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTableStatement, |_dialect| { Sequence::new(vec![ - Ref::new("RawLessThanSegment").to_matchable(), - Ref::new("RawLessThanSegment").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::new("TemporaryTransientGrammar") + .optional() + .to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("TableConstraintSegment").to_matchable(), + Ref::new("ColumnDefinitionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![ + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("TableEndClauseSegment").optional().to_matchable(), ]) - .allow_gaps(false) .to_matchable() }) .to_matchable() .into(), ), ( - "BitwiseRShiftSegment".into(), - NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| { + "CommentClauseSegment".into(), + NodeMatcher::new(SyntaxKind::CommentClause, |_dialect| { Sequence::new(vec![ - Ref::new("RawGreaterThanSegment").to_matchable(), - Ref::new("RawGreaterThanSegment").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .allow_gaps(false) .to_matchable() }) .to_matchable() .into(), ), ( - "LessThanSegment".into(), - NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| { - Ref::new("RawLessThanSegment").to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "GreaterThanOrEqualToSegment".into(), - NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| { + "CreateSchemaStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateSchemaStatement, |_dialect| { Sequence::new(vec![ - Ref::new("RawGreaterThanSegment").to_matchable(), - Ref::new("RawEqualsSegment").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), ]) - .allow_gaps(false) .to_matchable() }) .to_matchable() .into(), ), ( - "LessThanOrEqualToSegment".into(), - NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| { + "SetSchemaStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SetSchemaStatement, |_dialect| { Sequence::new(vec![ - Ref::new("RawLessThanSegment").to_matchable(), - Ref::new("RawEqualsSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), ]) - .allow_gaps(false) .to_matchable() }) .to_matchable() .into(), ), ( - "EqualsSegment".into(), - NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| { - Ref::new("RawEqualsSegment").to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "GreaterThanSegment".into(), - NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| { - Ref::new("RawGreaterThanSegment").to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "QualifiedNumericLiteralSegment".into(), - NodeMatcher::new(SyntaxKind::NumericLiteral, |_| { + "DropSchemaStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropSchemaStatement, |_dialect| { Sequence::new(vec![ - Ref::new("SignedSegmentGrammar").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -3893,118 +4369,28 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AggregateOrderByClause".into(), - NodeMatcher::new(SyntaxKind::AggregateOrderByClause, |_| { - Ref::new("OrderByClauseSegment").to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "FunctionNameSegment".into(), - NodeMatcher::new(SyntaxKind::FunctionName, |_| { + "DropTypeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropTypeStatement, |_dialect| { Sequence::new(vec![ - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("DotSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.terminators = vec![Ref::new("BracketedSegment").to_matchable()] - }) - .to_matchable(), - one_of(vec![ - Ref::new("FunctionNameIdentifierSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .terminators(vec![Ref::new("BracketedSegment").to_matchable()]) - .allow_gaps(false) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "CaseExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::CaseExpression, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CASE").to_matchable(), - MetaSegment::implicit_indent().to_matchable(), - AnyNumberOf::new(vec![Ref::new("WhenClauseSegment").to_matchable()]) - .config(|this| { - this.reset_terminators = true; - this.terminators = vec![ - Ref::keyword("ELSE").to_matchable(), - Ref::keyword("END").to_matchable(), - ]; - }) - .to_matchable(), - Ref::new("ElseClauseSegment").optional().to_matchable(), - MetaSegment::dedent().to_matchable(), - Ref::keyword("END").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CASE").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - MetaSegment::implicit_indent().to_matchable(), - AnyNumberOf::new(vec![Ref::new("WhenClauseSegment").to_matchable()]) - .config(|this| { - this.reset_terminators = true; - this.terminators = vec![ - Ref::keyword("ELSE").to_matchable(), - Ref::keyword("END").to_matchable(), - ]; - }) - .to_matchable(), - Ref::new("ElseClauseSegment").optional().to_matchable(), - MetaSegment::dedent().to_matchable(), - Ref::keyword("END").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) - .config(|this| { - this.terminators = vec![ - Ref::new("ComparisonOperatorGrammar").to_matchable(), - Ref::new("CommaSegment").to_matchable(), - Ref::new("BinaryOperatorGrammar").to_matchable(), - ] - }) .to_matchable() }) .to_matchable() .into(), ), ( - "WhenClauseSegment".into(), - NodeMatcher::new(SyntaxKind::WhenClause, |_| { + "CreateDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateDatabaseStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("WHEN").to_matchable(), - Sequence::new(vec![ - MetaSegment::implicit_indent().to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - Conditional::new(MetaSegment::indent()) - .indented_then() - .to_matchable(), - Ref::keyword("THEN").to_matchable(), - Conditional::new(MetaSegment::implicit_indent()) - .indented_then_contents() - .to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - Conditional::new(MetaSegment::dedent()) - .indented_then_contents() - .to_matchable(), - Conditional::new(MetaSegment::dedent()) - .indented_then() - .to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), ]) .to_matchable() }) @@ -4012,13 +4398,14 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "ElseClauseSegment".into(), - NodeMatcher::new(SyntaxKind::ElseClause, |_| { + "DropDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropDatabaseStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("ELSE").to_matchable(), - MetaSegment::implicit_indent().to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -4026,14 +4413,27 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "WhereClauseSegment".into(), - NodeMatcher::new(SyntaxKind::WhereClause, |_| { + "CreateIndexStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateIndexStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("WHERE").to_matchable(), - MetaSegment::implicit_indent().to_matchable(), - optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("UNIQUE").optional().to_matchable(), + Ref::keyword("INDEX").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("IndexColumnDefinitionSegment").to_matchable(), + ]) + .to_matchable(), + ]) .to_matchable(), - MetaSegment::dedent().to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) @@ -4041,20 +4441,14 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "SetOperatorSegment".into(), - NodeMatcher::new(SyntaxKind::SetOperator, |_| { - one_of(vec![ - Ref::new("UnionGrammar").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("INTERSECT").to_matchable(), - Ref::keyword("EXCEPT").to_matchable(), - ]) + "AlterTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Delimited::new(vec![Ref::new("AlterTableOptionsGrammar").to_matchable()]) .to_matchable(), - Ref::keyword("ALL").optional().to_matchable(), - ]) - .to_matchable(), - Ref::keyword("MINUS").to_matchable(), ]) .to_matchable() }) @@ -4062,31 +4456,23 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "ValuesClauseSegment".into(), - NodeMatcher::new(SyntaxKind::ValuesClause, |_| { + "CreateViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateViewStatement, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Ref::keyword("VALUE").to_matchable(), - Ref::keyword("VALUES").to_matchable(), - ]) - .to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::keyword("ROW").optional().to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.parse_mode(ParseMode::Greedy)) - .to_matchable(), - ]) + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + Ref::new("WithNoSchemaBindingClauseSegment") + .optional() .to_matchable(), - ]) - .to_matchable(), ]) .to_matchable() }) @@ -4094,11 +4480,16 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "EmptyStructLiteralSegment".into(), - NodeMatcher::new(SyntaxKind::EmptyStructLiteral, |_| { + "DropTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropTableStatement, |_dialect| { Sequence::new(vec![ - Ref::new("StructTypeSegment").to_matchable(), - Ref::new("EmptyStructLiteralBracketsSegment").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()]) + .to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -4106,30 +4497,28 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "ObjectLiteralSegment".into(), - NodeMatcher::new(SyntaxKind::ObjectLiteral, |_| { - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ObjectLiteralElementSegment").to_matchable()]) - .config(|this| { - this.optional(); - }) - .to_matchable(), + "DropViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) - .config(|this| { - this.bracket_type("curly"); - }) .to_matchable() }) .to_matchable() .into(), ), ( - "ObjectLiteralElementSegment".into(), - NodeMatcher::new(SyntaxKind::ObjectLiteralElement, |_| { + "DropUserStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropUserStatement, |_dialect| { Sequence::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("ColonSegment").to_matchable(), - Ref::new("BaseExpressionElementGrammar").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), ]) .to_matchable() }) @@ -4137,16 +4526,12 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "TimeZoneGrammar".into(), - NodeMatcher::new(SyntaxKind::TimeZoneGrammar, |_| { - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("AT").to_matchable(), - Ref::keyword("TIME").to_matchable(), - Ref::keyword("ZONE").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), + "TruncateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::TruncateStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("TRUNCATE").to_matchable(), + Ref::keyword("TABLE").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), ]) .to_matchable() }) @@ -4154,14 +4539,14 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "BracketedArguments".into(), - NodeMatcher::new(SyntaxKind::BracketedArguments, |_| { - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("LiteralGrammar").to_matchable()]) - .config(|this| { - this.optional(); - }) - .to_matchable(), + "DropIndexStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropIndexStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("INDEX").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -4169,28 +4554,687 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "DatatypeSegment".into(), - NodeMatcher::new(SyntaxKind::DataType, |_| { + "AccessStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AccessStatement, |_dialect| { one_of(vec![ - Ref::new("TimeWithTZGrammar").to_matchable(), Sequence::new(vec![ - Ref::keyword("DOUBLE").to_matchable(), - Ref::keyword("PRECISION").to_matchable(), + Ref::keyword("GRANT").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Delimited::new(vec![ + one_of(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + one_of(vec![ + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPLY").to_matchable(), + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXECUTE").to_matchable(), + Ref::keyword("TASK").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MANAGE").to_matchable(), + Ref::keyword("GRANTS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MONITOR").to_matchable(), + one_of(vec![ + Ref::keyword("EXECUTION").to_matchable(), + Ref::keyword("USAGE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + one_of(vec![ + Ref::keyword("SCHEMA").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("PIPE").to_matchable(), + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::keyword("STAGE").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::keyword("PROCEDURE") + .to_matchable(), + Ref::keyword("ROUTINE").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::keyword("STREAM").to_matchable(), + Ref::keyword("TASK").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED") + .to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL") + .to_matchable(), + Ref::keyword("TABLE") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMAT") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USE").to_matchable(), + one_of(vec![ + Ref::keyword("SCHEMA").to_matchable(), + Ref::keyword("CATALOG").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IMPORTED").to_matchable(), + Ref::keyword("PRIVILEGES").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("APPLY").to_matchable(), + Ref::keyword("CONNECT").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("EXECUTE").to_matchable(), + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("MODIFY").to_matchable(), + Ref::keyword("MONITOR").to_matchable(), + Ref::keyword("OPERATE").to_matchable(), + Ref::keyword("OWNERSHIP").to_matchable(), + Ref::keyword("READ").to_matchable(), + Ref::keyword("REFERENCE_USAGE").to_matchable(), + Ref::keyword("REFERENCES").to_matchable(), + Ref::keyword("SELECT").to_matchable(), + Ref::keyword("TEMP").to_matchable(), + Ref::keyword("TEMPORARY").to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::keyword("TRUNCATE").to_matchable(), + Ref::keyword("UPDATE").to_matchable(), + Ref::keyword("USAGE").to_matchable(), + Ref::keyword("USE_ANY_ROLE").to_matchable(), + Ref::keyword("WRITE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("PRIVILEGES") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![Ref::keyword("ON").to_matchable()]; + }) + .to_matchable(), + Ref::keyword("ON").to_matchable(), + one_of(vec![ + Ref::keyword("ACCOUNT").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RESOURCE").to_matchable(), + Ref::keyword("MONITOR").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("DOMAIN").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + Ref::keyword("LANGUAGE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::keyword("CATALOG").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("TABLESPACE").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOREIGN").to_matchable(), + one_of(vec![ + Ref::keyword("SERVER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATA").to_matchable(), + Ref::keyword("WRAPPER").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("SCHEMAS").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FUTURE").to_matchable(), + Ref::keyword("SCHEMAS").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::keyword("STAGE").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::keyword("ROUTINE").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::keyword("STREAM").to_matchable(), + Ref::keyword("TASK").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMAT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + one_of(vec![ + Ref::keyword("TABLES").to_matchable(), + Ref::keyword("VIEWS").to_matchable(), + Ref::keyword("STAGES").to_matchable(), + Ref::keyword("FUNCTIONS").to_matchable(), + Ref::keyword("PROCEDURES").to_matchable(), + Ref::keyword("ROUTINES").to_matchable(), + Ref::keyword("SEQUENCES").to_matchable(), + Ref::keyword("STREAMS").to_matchable(), + Ref::keyword("TASKS").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FUTURE").to_matchable(), + one_of(vec![ + Ref::keyword("TABLES").to_matchable(), + Ref::keyword("VIEWS").to_matchable(), + Ref::keyword("STAGES").to_matchable(), + Ref::keyword("FUNCTIONS").to_matchable(), + Ref::keyword("PROCEDURES").to_matchable(), + Ref::keyword("ROUTINES").to_matchable(), + Ref::keyword("SEQUENCES").to_matchable(), + Ref::keyword("STREAMS").to_matchable(), + Ref::keyword("TASKS").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("IN").to_matchable(), + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Delimited::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Ref::new("WildcardIdentifierSegment").to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("TO").to_matchable(), + Ref::keyword("FROM").to_matchable(), + ]; + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LARGE").to_matchable(), + Ref::keyword("OBJECT").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROLE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNERSHIP").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Ref::new("RoleReferenceSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::keyword("PUBLIC").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("GRANT").to_matchable(), + Ref::keyword("OPTION").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("ADMIN").to_matchable(), + Ref::keyword("OPTION").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COPY").to_matchable(), + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("GRANTS").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("GRANTED").to_matchable(), + Ref::keyword("BY").to_matchable(), + one_of(vec![ + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ + Ref::keyword("REVOKE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("GRANT").to_matchable(), + Ref::keyword("OPTION").to_matchable(), + Ref::keyword("FOR").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), one_of(vec![ Sequence::new(vec![ - one_of(vec![ - Ref::keyword("CHARACTER").to_matchable(), - Ref::keyword("BINARY").to_matchable(), + Delimited::new(vec![ + one_of(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + one_of(vec![ + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPLY").to_matchable(), + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXECUTE").to_matchable(), + Ref::keyword("TASK").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MANAGE").to_matchable(), + Ref::keyword("GRANTS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MONITOR").to_matchable(), + one_of(vec![ + Ref::keyword("EXECUTION").to_matchable(), + Ref::keyword("USAGE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + one_of(vec![ + Ref::keyword("SCHEMA").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("PIPE").to_matchable(), + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::keyword("STAGE").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::keyword("PROCEDURE") + .to_matchable(), + Ref::keyword("ROUTINE").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::keyword("STREAM").to_matchable(), + Ref::keyword("TASK").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED") + .to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL") + .to_matchable(), + Ref::keyword("TABLE") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMAT") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USE").to_matchable(), + one_of(vec![ + Ref::keyword("SCHEMA").to_matchable(), + Ref::keyword("CATALOG").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IMPORTED").to_matchable(), + Ref::keyword("PRIVILEGES").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("APPLY").to_matchable(), + Ref::keyword("CONNECT").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("EXECUTE").to_matchable(), + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("MODIFY").to_matchable(), + Ref::keyword("MONITOR").to_matchable(), + Ref::keyword("OPERATE").to_matchable(), + Ref::keyword("OWNERSHIP").to_matchable(), + Ref::keyword("READ").to_matchable(), + Ref::keyword("REFERENCE_USAGE").to_matchable(), + Ref::keyword("REFERENCES").to_matchable(), + Ref::keyword("SELECT").to_matchable(), + Ref::keyword("TEMP").to_matchable(), + Ref::keyword("TEMPORARY").to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::keyword("TRUNCATE").to_matchable(), + Ref::keyword("UPDATE").to_matchable(), + Ref::keyword("USAGE").to_matchable(), + Ref::keyword("USE_ANY_ROLE").to_matchable(), + Ref::keyword("WRITE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("PRIVILEGES") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.terminators = vec![Ref::keyword("ON").to_matchable()]; + }) .to_matchable(), + Ref::keyword("ON").to_matchable(), one_of(vec![ - Ref::keyword("VARYING").to_matchable(), + Ref::keyword("ACCOUNT").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RESOURCE").to_matchable(), + Ref::keyword("MONITOR").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("DOMAIN").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + Ref::keyword("LANGUAGE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::keyword("CATALOG").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("TABLESPACE").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOREIGN").to_matchable(), + one_of(vec![ + Ref::keyword("SERVER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATA").to_matchable(), + Ref::keyword("WRAPPER").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("SCHEMAS").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FUTURE").to_matchable(), + Ref::keyword("SCHEMAS").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::keyword("STAGE").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::keyword("ROUTINE").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::keyword("STREAM").to_matchable(), + Ref::keyword("TASK").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMAT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + one_of(vec![ + Ref::keyword("TABLES").to_matchable(), + Ref::keyword("VIEWS").to_matchable(), + Ref::keyword("STAGES").to_matchable(), + Ref::keyword("FUNCTIONS").to_matchable(), + Ref::keyword("PROCEDURES").to_matchable(), + Ref::keyword("ROUTINES").to_matchable(), + Ref::keyword("SEQUENCES").to_matchable(), + Ref::keyword("STREAMS").to_matchable(), + Ref::keyword("TASKS").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FUTURE").to_matchable(), + one_of(vec![ + Ref::keyword("TABLES").to_matchable(), + Ref::keyword("VIEWS").to_matchable(), + Ref::keyword("STAGES").to_matchable(), + Ref::keyword("FUNCTIONS").to_matchable(), + Ref::keyword("PROCEDURES").to_matchable(), + Ref::keyword("ROUTINES").to_matchable(), + Ref::keyword("SEQUENCES").to_matchable(), + Ref::keyword("STREAMS").to_matchable(), + Ref::keyword("TASKS").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("IN").to_matchable(), + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Delimited::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Ref::new("WildcardIdentifierSegment").to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("TO").to_matchable(), + Ref::keyword("FROM").to_matchable(), + ]; + }) + .to_matchable(), + ]) + .to_matchable(), Sequence::new(vec![ Ref::keyword("LARGE").to_matchable(), Ref::keyword("OBJECT").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) .to_matchable(), ]) @@ -4198,192 +5242,34 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), Sequence::new(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("DotSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("DatatypeIdentifierSegment").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Ref::new("BracketedArguments").optional().to_matchable(), - one_of(vec![ - Ref::keyword("UNSIGNED").to_matchable(), - Ref::new("CharCharacterSetGrammar").to_matchable(), - ]) - .config(|config| config.optional()) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "AliasExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::AliasExpression, |_| { - Sequence::new(vec![ - MetaSegment::indent().to_matchable(), - Ref::keyword("AS").optional().to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Bracketed::new(vec![ - Ref::new("SingleIdentifierListSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNERSHIP").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), - Ref::new("SingleQuotedIdentifierSegment").to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "ShorthandCastSegment".into(), - NodeMatcher::new(SyntaxKind::CastExpression, |_| { - Sequence::new(vec![ - one_of(vec![ - Ref::new("Expression_D_Grammar").to_matchable(), - Ref::new("CaseExpressionSegment").to_matchable(), - ]) - .to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::new("CastOperatorSegment").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Ref::new("TimeZoneGrammar").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.min_times(1)) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "ArrayAccessorSegment".into(), - NodeMatcher::new(SyntaxKind::ArrayAccessor, |_| { - Bracketed::new(vec![ - Delimited::new(vec![ + Ref::keyword("FROM").to_matchable(), one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.delimiter(Ref::new("SliceSegment"))) - .to_matchable(), - ]) - .config(|this| { - this.bracket_type("square"); - this.parse_mode(ParseMode::Greedy); - }) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "ArrayLiteralSegment".into(), - NodeMatcher::new(SyntaxKind::ArrayLiteral, |_| { - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("BaseExpressionElementGrammar").to_matchable(), - ]) - .config(|this| { - this.delimiter(Ref::new("CommaSegment")); - this.optional(); - }) - .to_matchable(), - ]) - .config(|this| { - this.bracket_type("square"); - this.parse_mode(ParseMode::Greedy); - }) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "TypedArrayLiteralSegment".into(), - NodeMatcher::new(SyntaxKind::TypedArrayLiteral, |_| { - Sequence::new(vec![ - Ref::new("ArrayTypeSegment").to_matchable(), - Ref::new("ArrayLiteralSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "StructTypeSegment".into(), - NodeMatcher::new(SyntaxKind::StructType, |_| Nothing::new().to_matchable()) - .to_matchable() - .into(), - ), - ( - "StructLiteralSegment".into(), - NodeMatcher::new(SyntaxKind::StructLiteral, |_| { - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("BaseExpressionElementGrammar").to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("SHARE").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "TypedStructLiteralSegment".into(), - NodeMatcher::new(SyntaxKind::TypedStructLiteral, |_| { - Sequence::new(vec![ - Ref::new("StructTypeSegment").to_matchable(), - Ref::new("StructLiteralSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "IntervalExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::IntervalExpression, |_| { - Sequence::new(vec![ - Ref::keyword("INTERVAL").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("DatetimeUnitSegment").to_matchable(), - ]) + Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) .to_matchable(), - ]) - .to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable(), ]) @@ -4393,17 +5279,12 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "ArrayTypeSegment".into(), - NodeMatcher::new(SyntaxKind::ArrayType, |_| Nothing::new().to_matchable()) - .to_matchable() - .into(), - ), - ( - "SizedArrayTypeSegment".into(), - NodeMatcher::new(SyntaxKind::SizedArrayType, |_| { + "DeleteStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DeleteStatement, |_dialect| { Sequence::new(vec![ - Ref::new("ArrayTypeSegment").to_matchable(), - Ref::new("ArrayAccessorSegment").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + Ref::new("FromClauseSegment").to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), ]) .to_matchable() }) @@ -4411,73 +5292,35 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "UnorderedSelectStatementSegment".into(), - NodeMatcher::new(SyntaxKind::SelectStatement, |_| { + "UpdateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::UpdateStatement, |_dialect| { Sequence::new(vec![ - Ref::new("SelectClauseSegment").to_matchable(), + Ref::keyword("UPDATE").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("AliasExpressionSegment") + .exclude(Ref::keyword("SET")) + .optional() + .to_matchable(), MetaSegment::dedent().to_matchable(), + Ref::new("SetClauseListSegment").to_matchable(), Ref::new("FromClauseSegment").optional().to_matchable(), Ref::new("WhereClauseSegment").optional().to_matchable(), - Ref::new("GroupByClauseSegment").optional().to_matchable(), - Ref::new("HavingClauseSegment").optional().to_matchable(), - Ref::new("OverlapsClauseSegment").optional().to_matchable(), - Ref::new("NamedWindowSegment").optional().to_matchable(), - ]) - .terminators(vec![ - Ref::new("SetOperatorSegment").to_matchable(), - Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), - Ref::new("WithDataClauseSegment").to_matchable(), - Ref::new("OrderByClauseSegment").to_matchable(), - Ref::new("LimitClauseSegment").to_matchable(), ]) - .config(|this| { - this.parse_mode(ParseMode::GreedyOnceStarted); - }) .to_matchable() }) .to_matchable() .into(), ), ( - "OverlapsClauseSegment".into(), - NodeMatcher::new(SyntaxKind::OverlapsClause, |_| { + "SetClauseListSegment".into(), + NodeMatcher::new(SyntaxKind::SetClauseList, |_dialect| { Sequence::new(vec![ - Ref::keyword("OVERLAPS").to_matchable(), - one_of(vec![ - Bracketed::new(vec![ - Ref::new("DateTimeLiteralGrammar").to_matchable(), - Ref::new("CommaSegment").to_matchable(), - Ref::new("DateTimeLiteralGrammar").to_matchable(), - ]) + Ref::keyword("SET").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![Ref::new("SetClauseSegment").to_matchable()]) .to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ("SelectClauseSegment".into(), { - NodeMatcher::new(SyntaxKind::SelectClause, |_| select_clause_segment()) - .to_matchable() - .into() - }), - ( - "StatementSegment".into(), - NodeMatcher::new(SyntaxKind::Statement, |_| statement_segment()) - .to_matchable() - .into(), - ), - ( - "WithNoSchemaBindingClauseSegment".into(), - NodeMatcher::new(SyntaxKind::WithNoSchemaBindingClause, |_| { - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("NO").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::keyword("BINDING").to_matchable(), + MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) @@ -4485,14 +5328,21 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "WithDataClauseSegment".into(), - NodeMatcher::new(SyntaxKind::WithDataClause, |_| { + "SetClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SetClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Sequence::new(vec![Ref::keyword("NO").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("DATA").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) @@ -4500,22 +5350,58 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "SetExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::SetExpression, |_| { + "CreateCastStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateCastStatement, |_dialect| { Sequence::new(vec![ - Ref::new("NonSetSelectableGrammar").to_matchable(), - AnyNumberOf::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("CAST").to_matchable(), + Bracketed::new(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::keyword("SPECIFIC").optional().to_matchable(), + one_of(vec![ + Ref::keyword("ROUTINE").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), Sequence::new(vec![ - Ref::new("SetOperatorSegment").to_matchable(), - Ref::new("NonSetSelectableGrammar").to_matchable(), + one_of(vec![ + Ref::keyword("INSTANCE").to_matchable(), + Ref::keyword("STATIC").to_matchable(), + Ref::keyword("CONSTRUCTOR").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("METHOD").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.min_times(1)) .to_matchable(), - Ref::new("OrderByClauseSegment").optional().to_matchable(), - Ref::new("LimitClauseSegment").optional().to_matchable(), - Ref::new("NamedWindowSegment").optional().to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOR").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Ref::keyword("ASSIGNMENT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable() }) @@ -4523,12 +5409,18 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "FromClauseSegment".into(), - NodeMatcher::new(SyntaxKind::FromClause, |_| { + "DropCastStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropCastStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Delimited::new(vec![Ref::new("FromExpressionSegment").to_matchable()]) - .to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("CAST").to_matchable(), + Bracketed::new(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -4536,63 +5428,19 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "EmptyStructLiteralBracketsSegment".into(), - NodeMatcher::new(SyntaxKind::EmptyStructLiteralBrackets, |_| { - Bracketed::new(vec![]).to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "WildcardExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::WildcardExpression, |_| { - wildcard_expression_segment() - }) - .to_matchable() - .into(), - ), - ( - "OrderByClauseSegment".into(), - NodeMatcher::new(SyntaxKind::OrderbyClause, |_| { + "FunctionDefinitionGrammar".into(), + NodeMatcher::new(SyntaxKind::FunctionDefinition, |_dialect| { Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - MetaSegment::indent().to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("ASC").to_matchable(), - Ref::keyword("DESC").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NULLS").to_matchable(), - one_of(vec![ - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("LAST").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("LANGUAGE").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), ]) .config(|this| { - this.terminators = vec![ - Ref::keyword("LIMIT").to_matchable(), - Ref::new("FrameClauseUnitGrammar").to_matchable(), - ] + this.optional(); }) .to_matchable(), - MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) @@ -4600,12 +5448,25 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "TruncateStatementSegment".into(), - NodeMatcher::new(SyntaxKind::TruncateStatement, |_| { + "CreateFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateFunctionStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("TRUNCATE").to_matchable(), - Ref::keyword("TABLE").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURNS").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("FunctionDefinitionGrammar").to_matchable(), ]) .to_matchable() }) @@ -4613,66 +5474,14 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "FromExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::FromExpression, |_| { - optionally_bracketed(vec![ - Sequence::new(vec![ - MetaSegment::indent().to_matchable(), - one_of(vec![ - Ref::new("FromExpressionElementSegment").to_matchable(), - Bracketed::new(vec![Ref::new("FromExpressionSegment").to_matchable()]) - .to_matchable(), - ]) + "FunctionParameterListGrammar".into(), + NodeMatcher::new(SyntaxKind::FunctionParameterList, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("FunctionParameterGrammar").to_matchable()]) .config(|this| { - this.terminators = vec![ - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - ] + this.optional(); }) .to_matchable(), - MetaSegment::dedent().to_matchable(), - Conditional::new(MetaSegment::indent()) - .indented_joins() - .to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::new("JoinClauseSegment").to_matchable(), - Ref::new("JoinLikeClauseGrammar").to_matchable(), - ]) - .config(|this| { - this.optional(); - this.terminators = vec![ - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - ]; - }) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Conditional::new(MetaSegment::dedent()) - .indented_joins() - .to_matchable(), - ]) - .to_matchable(), ]) .to_matchable() }) @@ -4680,44 +5489,63 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "DatePartFunctionNameSegment".into(), - NodeMatcher::new(SyntaxKind::FunctionName, |_| { - Ref::new("DatePartFunctionName").to_matchable() + "DropFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .to_matchable() }) .to_matchable() .into(), ), ( - "FromExpressionElementSegment".into(), - NodeMatcher::new(SyntaxKind::FromExpressionElement, |_| { + "CreateModelStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateModelStatement, |_dialect| { Sequence::new(vec![ - Ref::new("PreTableFunctionKeywordsGrammar") - .optional() - .to_matchable(), - optionally_bracketed(vec![Ref::new("TableExpressionSegment").to_matchable()]) - .to_matchable(), - Ref::new("AliasExpressionSegment") - .exclude(one_of(vec![ - Ref::new("FromClauseTerminatorGrammar").to_matchable(), - Ref::new("SamplingExpressionSegment").to_matchable(), - Ref::new("JoinLikeClauseGrammar").to_matchable(), - LookaheadExclude::new("WITH", "(").to_matchable(), - ])) - .optional() - .to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("MODEL").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - Ref::new("AliasExpressionSegment").to_matchable(), + Ref::keyword("OPTIONS").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + this.bracket_type("square"); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("SamplingExpressionSegment") - .optional() - .to_matchable(), - Ref::new("PostTableExpressionGrammar") - .optional() - .to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), ]) .to_matchable() }) @@ -4725,19 +5553,26 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "SelectStatementSegment".into(), - NodeMatcher::new(SyntaxKind::SelectStatement, |_| select_statement()) + "CreateUserStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateUserStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) .to_matchable() - .into(), + }) + .to_matchable() + .into(), ), ( - "CreateSchemaStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateSchemaStatement, |_| { + "CreateRoleStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateRoleStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), + Ref::keyword("ROLE").to_matchable(), Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), ]) .to_matchable() }) @@ -4745,11 +5580,13 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "SelectClauseModifierSegment".into(), - NodeMatcher::new(SyntaxKind::SelectClauseModifier, |_| { - one_of(vec![ - Ref::keyword("DISTINCT").to_matchable(), - Ref::keyword("ALL").to_matchable(), + "DropRoleStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropRoleStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable() }) @@ -4757,658 +5594,536 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "SelectClauseElementSegment".into(), - NodeMatcher::new(SyntaxKind::SelectClauseElement, |_| select_clause_element()) - .to_matchable() - .into(), - ), - ]); - - // hookpoint - ansi_dialect.add([( - "CharCharacterSetGrammar".into(), - Nothing::new().to_matchable().into(), - )]); - - // This is a hook point to allow subclassing for other dialects - ansi_dialect.add([( - "AliasedTableReferenceGrammar".into(), - Sequence::new(vec![ - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("AliasExpressionSegment").to_matchable(), - ]) - .to_matchable() - .into(), - )]); - - ansi_dialect.add([ - ( - "FunctionContentsSegment".into(), - NodeMatcher::new(SyntaxKind::FunctionContents, |_| { + "DropModelStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropModelStatement, |_dialect| { Sequence::new(vec![ - Bracketed::new(vec![Ref::new("FunctionContentsGrammar").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("MODEL").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - // FunctionContentsExpressionGrammar intended as a hook to override in other dialects. - ( - "FunctionContentsExpressionGrammar".into(), - Ref::new("ExpressionSegment").to_matchable().into(), - ), ( - "FunctionContentsGrammar".into(), - AnyNumberOf::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - // A Cast-like function + "MLTableExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::MlTableExpression, |_dialect| { Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), - // Trim function - Sequence::new(vec![ - Ref::new("TrimParametersGrammar").to_matchable(), - Ref::new("ExpressionSegment") - .optional() - .exclude(Ref::keyword("FROM")) + Ref::keyword("ML").to_matchable(), + Ref::new("DotSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::keyword("MODEL").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) .to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - // An extract-like or substring-like function - Sequence::new(vec![ - one_of(vec![ - Ref::new("DatetimeUnitSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - // Allow an optional distinct keyword here. - Ref::keyword("DISTINCT").optional().to_matchable(), - one_of(vec![ - // For COUNT(*) or similar - Ref::new("StarSegment").to_matchable(), - Delimited::new(vec![ - Ref::new("FunctionContentsExpressionGrammar").to_matchable(), + Sequence::new(vec![ + Ref::new("CommaSegment").to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - Ref::new("AggregateOrderByClause").to_matchable(), // Used in various functions - Sequence::new(vec![ - Ref::keyword("SEPARATOR").to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), - ]) - .to_matchable(), - // Position-like function - Sequence::new(vec![ - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("IN").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("IgnoreRespectNullsGrammar").to_matchable(), - Ref::new("IndexColumnDefinitionSegment").to_matchable(), - Ref::new("EmptyStructLiteralSegment").to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - "PostFunctionGrammar".into(), - one_of(vec![ - Ref::new("OverClauseSegment").to_matchable(), - Ref::new("FilterClauseGrammar").to_matchable(), - ]) + "StatementSegment".into(), + NodeMatcher::new(SyntaxKind::Statement, |_dialect| { + one_of(vec![ + Ref::new("SelectableGrammar").to_matchable(), + Ref::new("MergeStatementSegment").to_matchable(), + Ref::new("InsertStatementSegment").to_matchable(), + Ref::new("TransactionStatementSegment").to_matchable(), + Ref::new("DropTableStatementSegment").to_matchable(), + Ref::new("DropViewStatementSegment").to_matchable(), + Ref::new("CreateUserStatementSegment").to_matchable(), + Ref::new("DropUserStatementSegment").to_matchable(), + Ref::new("TruncateStatementSegment").to_matchable(), + Ref::new("AccessStatementSegment").to_matchable(), + Ref::new("CreateTableStatementSegment").to_matchable(), + Ref::new("CreateRoleStatementSegment").to_matchable(), + Ref::new("DropRoleStatementSegment").to_matchable(), + Ref::new("AlterTableStatementSegment").to_matchable(), + Ref::new("CreateSchemaStatementSegment").to_matchable(), + Ref::new("SetSchemaStatementSegment").to_matchable(), + Ref::new("DropSchemaStatementSegment").to_matchable(), + Ref::new("DropTypeStatementSegment").to_matchable(), + Ref::new("CreateDatabaseStatementSegment").to_matchable(), + Ref::new("DropDatabaseStatementSegment").to_matchable(), + Ref::new("CreateIndexStatementSegment").to_matchable(), + Ref::new("DropIndexStatementSegment").to_matchable(), + Ref::new("CreateViewStatementSegment").to_matchable(), + Ref::new("DeleteStatementSegment").to_matchable(), + Ref::new("UpdateStatementSegment").to_matchable(), + Ref::new("CreateCastStatementSegment").to_matchable(), + Ref::new("DropCastStatementSegment").to_matchable(), + Ref::new("CreateFunctionStatementSegment").to_matchable(), + Ref::new("DropFunctionStatementSegment").to_matchable(), + Ref::new("CreateModelStatementSegment").to_matchable(), + Ref::new("DropModelStatementSegment").to_matchable(), + Ref::new("DescribeStatementSegment").to_matchable(), + Ref::new("UseStatementSegment").to_matchable(), + Ref::new("ExplainStatementSegment").to_matchable(), + Ref::new("CreateSequenceStatementSegment").to_matchable(), + Ref::new("AlterSequenceStatementSegment").to_matchable(), + Ref::new("DropSequenceStatementSegment").to_matchable(), + Ref::new("CreateTriggerStatementSegment").to_matchable(), + Ref::new("DropTriggerStatementSegment").to_matchable(), + ]) + .config(|this| { + this.terminators = vec![Ref::new("DelimiterGrammar").to_matchable()]; + }) + .to_matchable() + }) .to_matchable() .into(), ), - ]); - - // Assuming `ansi_dialect` is an instance of a struct representing a SQL dialect - // and `add_grammar` is a method to add a new grammar rule to the dialect. - ansi_dialect.add([( - "JoinLikeClauseGrammar".into(), - Nothing::new().to_matchable().into(), - )]); - - ansi_dialect.add([ ( - "AccessStatementSegmentGrantRoleWithOptionGrammar".into(), - one_of(vec![ + "WithNoSchemaBindingClauseSegment".into(), + NodeMatcher::new(SyntaxKind::WithNoSchemaBindingClause, |_dialect| { Sequence::new(vec![ Ref::keyword("WITH").to_matchable(), - Ref::keyword("GRANT").to_matchable(), - Ref::keyword("OPTION").to_matchable(), + Ref::keyword("NO").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::keyword("BINDING").to_matchable(), ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WithDataClauseSegment".into(), + NodeMatcher::new(SyntaxKind::WithDataClause, |_dialect| { Sequence::new(vec![ Ref::keyword("WITH").to_matchable(), - Ref::keyword("ADMIN").to_matchable(), - Ref::keyword("OPTION").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COPY").to_matchable(), - Ref::keyword("CURRENT").to_matchable(), - Ref::keyword("GRANTS").to_matchable(), + Sequence::new(vec![Ref::keyword("NO").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("DATA").to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - // Expression_A_Grammar - // https://www.cockroachlabs.com/docs/v20.2/sql-grammar.html#a_expr - // The upstream grammar is defined recursively, which if implemented naively - // will cause SQLFluff to overflow the stack from recursive function calls. - // To work around this, the a_expr grammar is reworked a bit into sub-grammars - // that effectively provide tail recursion. - "Expression_A_Unary_Operator_Grammar".into(), - one_of(vec![ - // This grammar corresponds to the unary operator portion of the initial - // recursive block on the Cockroach Labs a_expr grammar. - Ref::new("SignedSegmentGrammar") - .exclude(Sequence::new(vec![ - Ref::new("QualifiedNumericLiteralSegment").to_matchable(), - ])) - .to_matchable(), - Ref::new("TildeSegment").to_matchable(), - Ref::new("NotOperatorGrammar").to_matchable(), - // Used in CONNECT BY clauses (EXASOL, Snowflake, Postgres...) - Ref::keyword("PRIOR").to_matchable(), - ]) + "DescribeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DescribeStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DESCRIBE").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - "Tail_Recurse_Expression_A_Grammar".into(), - Sequence::new(vec![ - // This should be used instead of a recursive call to Expression_A_Grammar - // whenever the repeating element in Expression_A_Grammar makes a recursive - // call to itself at the _end_. - AnyNumberOf::new(vec![ - Ref::new("Expression_A_Unary_Operator_Grammar").to_matchable(), + "UseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::UseStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("USE").to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), ]) - .config(|this| { - this.terminators = vec![Ref::new("BinaryOperatorGrammar").to_matchable()] - }) - .to_matchable(), - Ref::new("Expression_C_Grammar").to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - "Expression_A_Grammar".into(), - Sequence::new(vec![ - Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(), - AnyNumberOf::new(vec![ + "ExplainStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ExplainStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("EXPLAIN").to_matchable(), one_of(vec![ - // Like grammar with NOT and optional ESCAPE - Sequence::new(vec![ - Sequence::new(vec![ - Ref::keyword("NOT").optional().to_matchable(), - Ref::new("LikeGrammar").to_matchable(), - ]) - .to_matchable(), - Ref::new("Expression_A_Grammar").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ESCAPE").to_matchable(), - Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - // Binary operator grammar - Sequence::new(vec![ - Ref::new("BinaryOperatorGrammar").to_matchable(), - Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(), - ]) - .to_matchable(), - // IN grammar - Ref::new("InOperatorGrammar").to_matchable(), - // IS grammar - Sequence::new(vec![ - Ref::keyword("IS").to_matchable(), - Ref::keyword("NOT").optional().to_matchable(), - Ref::new("IsClauseGrammar").to_matchable(), - ]) - .to_matchable(), - // IS NULL and NOT NULL grammars - Ref::new("IsNullGrammar").to_matchable(), - Ref::new("NotNullGrammar").to_matchable(), - // COLLATE grammar - Ref::new("CollateGrammar").to_matchable(), - // BETWEEN grammar - Sequence::new(vec![ - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("BETWEEN").to_matchable(), - Ref::new("Expression_B_Grammar").to_matchable(), - Ref::keyword("AND").to_matchable(), - Ref::new("Tail_Recurse_Expression_A_Grammar").to_matchable(), - ]) - .to_matchable(), - // Additional sequences and grammar rules can be added here + Ref::new("SelectableGrammar").to_matchable(), + Ref::new("InsertStatementSegment").to_matchable(), + Ref::new("UpdateStatementSegment").to_matchable(), + Ref::new("DeleteStatementSegment").to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), - // Expression_B_Grammar: Does not directly feed into Expression_A_Grammar - // but is used for a BETWEEN statement within Expression_A_Grammar. - // https://www.cockroachlabs.com/docs/v20.2/sql-grammar.htm#b_expr - // We use a similar trick as seen with Expression_A_Grammar to avoid recursion - // by using a tail recursion grammar. See the comments for a_expr to see how - // that works. ( - "Expression_B_Unary_Operator_Grammar".into(), - one_of(vec![ - Ref::new("SignedSegmentGrammar") - .exclude(Sequence::new(vec![ - Ref::new("QualifiedNumericLiteralSegment").to_matchable(), - ])) + "CreateSequenceOptionsSegment".into(), + NodeMatcher::new(SyntaxKind::CreateSequenceOptionsSegment, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("INCREMENT").to_matchable(), + Ref::keyword("BY").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) .to_matchable(), - Ref::new("TildeSegment").to_matchable(), - ]) + Sequence::new(vec![ + Ref::keyword("START").to_matchable(), + Ref::keyword("WITH").optional().to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("SequenceMinValueGrammar").to_matchable(), + Ref::new("SequenceMaxValueGrammar").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CACHE").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("NOCACHE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("CYCLE").to_matchable(), + Ref::keyword("NOCYCLE").to_matchable(), + ]) + .to_matchable(), + Ref::new("OrderNoOrderGrammar").to_matchable(), + ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - "Tail_Recurse_Expression_B_Grammar".into(), - Sequence::new(vec![ - // Only safe to use if the recursive call is at the END of the repeating - // element in the main b_expr portion. - AnyNumberOf::new(vec![ - Ref::new("Expression_B_Unary_Operator_Grammar").to_matchable(), + "CreateSequenceStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateSequenceStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::new("SequenceReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("CreateSequenceOptionsSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) - .to_matchable(), - Ref::new("Expression_C_Grammar").to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - "Expression_B_Grammar".into(), - Sequence::new(vec![ - // Always start with the tail recursion element - Ref::new("Tail_Recurse_Expression_B_Grammar").to_matchable(), - AnyNumberOf::new(vec![ + "AlterSequenceOptionsSegment".into(), + NodeMatcher::new(SyntaxKind::AlterSequenceOptionsSegment, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("INCREMENT").to_matchable(), + Ref::keyword("BY").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("SequenceMinValueGrammar").to_matchable(), + Ref::new("SequenceMaxValueGrammar").to_matchable(), one_of(vec![ - // Arithmetic, string, or comparison binary operators followed by tail - // recursion Sequence::new(vec![ - one_of(vec![ - Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(), - Ref::new("StringBinaryOperatorGrammar").to_matchable(), - Ref::new("ComparisonOperatorGrammar").to_matchable(), - ]) - .to_matchable(), - Ref::new("Tail_Recurse_Expression_B_Grammar").to_matchable(), + Ref::keyword("CACHE").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) .to_matchable(), - // Additional sequences and rules from b_expr can be added here + Ref::keyword("NOCACHE").to_matchable(), ]) .to_matchable(), + one_of(vec![ + Ref::keyword("CYCLE").to_matchable(), + Ref::keyword("NOCYCLE").to_matchable(), + ]) + .to_matchable(), + Ref::new("OrderNoOrderGrammar").to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - "Expression_C_Grammar".into(), - one_of(vec![ - // Sequence for "EXISTS" with a bracketed selectable grammar + "AlterSequenceStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterSequenceStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("EXISTS").to_matchable(), - Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::new("SequenceReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![Ref::new("AlterSequenceOptionsSegment").to_matchable()]) .to_matchable(), ]) - .to_matchable(), - // Sequence for Expression_D_Grammar or CaseExpressionSegment - // followed by any number of TimeZoneGrammar + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropSequenceStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropSequenceStatement, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Ref::new("Expression_D_Grammar").to_matchable(), - Ref::new("CaseExpressionSegment").to_matchable(), - ]) - .to_matchable(), - AnyNumberOf::new(vec![Ref::new("TimeZoneGrammar").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::new("SequenceReferenceSegment").to_matchable(), ]) - .to_matchable(), - Ref::new("ShorthandCastSegment").to_matchable(), - ]) - .config(|this| this.terminators = vec![Ref::new("CommaSegment").to_matchable()]) + .to_matchable() + }) .to_matchable() .into(), ), ( - "Expression_D_Grammar".into(), - Sequence::new(vec![ - one_of(vec![ - Ref::new("BareFunctionSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Bracketed::new(vec![ - one_of(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("LocalAliasSegment").to_matchable(), - ]) - .to_matchable(), + "DatePartFunctionNameSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionName, |_dialect| { + Ref::new("DatePartFunctionName").to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateTriggerStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTriggerStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::new("TriggerReferenceSegment").to_matchable(), + one_of(vec![ + Ref::keyword("BEFORE").to_matchable(), + Ref::keyword("AFTER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("INSTEAD").to_matchable(), + Ref::keyword("OF").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.parse_mode(ParseMode::Greedy)) - .to_matchable(), - Ref::new("SelectStatementSegment").to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("IntervalExpressionSegment").to_matchable(), - Ref::new("TypedStructLiteralSegment").to_matchable(), - Ref::new("ArrayExpressionSegment").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("ObjectReferenceDelimiterGrammar").to_matchable(), - Ref::new("StarSegment").to_matchable(), - ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::new("StructTypeSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + Delimited::new(vec![ + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("UPDATE").to_matchable(), + Ref::keyword("OF").to_matchable(), + Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("OR").to_matchable(), + Ref::keyword("ON").to_matchable(), + ]; + }) .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.delimiter(Ref::keyword("OR")); + this.terminators = vec![Ref::keyword("ON").to_matchable()]; + }) .to_matchable(), - Sequence::new(vec![ - Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("REFERENCING").to_matchable(), + Ref::keyword("OLD").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("NEW").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - Ref::new("NullLiteralSegment").to_matchable(), - Ref::new("DateTimeLiteralGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("DEFERRABLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFERRABLE").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("IMMEDIATE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("DEFERRED").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOR").to_matchable(), + Ref::keyword("EACH").optional().to_matchable(), + one_of(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("STATEMENT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WHEN").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Ref::new("LocalAliasSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXECUTE").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::new("FunctionNameIdentifierSegment").to_matchable(), + Ref::new("FunctionContentsSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) - .config(|this| this.terminators = vec![Ref::new("CommaSegment").to_matchable()]) - .to_matchable(), - Ref::new("AccessorGrammar").optional().to_matchable(), - ]) - .allow_gaps(true) + .to_matchable() + }) .to_matchable() .into(), ), ( - "AccessorGrammar".into(), - AnyNumberOf::new(vec![Ref::new("ArrayAccessorSegment").to_matchable()]) + "DropTriggerStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropTriggerStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TriggerReferenceSegment").to_matchable(), + ]) .to_matchable() - .into(), + }) + .to_matchable() + .into(), ), - ]); - - ansi_dialect.add([ ( - "SelectableGrammar".into(), - one_of(vec![ - optionally_bracketed(vec![ - Ref::new("WithCompoundStatementSegment").to_matchable(), - ]) - .to_matchable(), - optionally_bracketed(vec![ - Ref::new("WithCompoundNonSelectStatementSegment").to_matchable(), + "SamplingExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::SampleExpression, |_dialect| { + Sequence::new(vec![ + Ref::keyword("TABLESAMPLE").to_matchable(), + one_of(vec![ + Ref::keyword("BERNOULLI").to_matchable(), + Ref::keyword("SYSTEM").to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![Ref::keyword("REPEATABLE").to_matchable()]).to_matchable(), + Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) - .to_matchable(), - Ref::new("NonWithSelectableGrammar").to_matchable(), - Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - "NonWithSelectableGrammar".into(), - one_of(vec![ - Ref::new("SetExpressionSegment").to_matchable(), - optionally_bracketed(vec![Ref::new("SelectStatementSegment").to_matchable()]) - .to_matchable(), - Ref::new("NonSetSelectableGrammar").to_matchable(), - ]) + "TemporalQuerySegment".into(), + NodeMatcher::new(SyntaxKind::TemporalQuery, |_dialect| { + Nothing::new().to_matchable() + }) .to_matchable() .into(), ), ( - "NonWithNonSelectableGrammar".into(), - one_of(vec![ - Ref::new("UpdateStatementSegment").to_matchable(), - Ref::new("InsertStatementSegment").to_matchable(), - Ref::new("DeleteStatementSegment").to_matchable(), - Ref::new("MergeStatementSegment").to_matchable(), - ]) + "LocalAliasSegment".into(), + NodeMatcher::new(SyntaxKind::LocalAlias, |_dialect| { + Nothing::new().to_matchable() + }) .to_matchable() .into(), ), ( - "NonSetSelectableGrammar".into(), - one_of(vec![ - Ref::new("ValuesClauseSegment").to_matchable(), - Ref::new("UnorderedSelectStatementSegment").to_matchable(), - Bracketed::new(vec![Ref::new("SelectStatementSegment").to_matchable()]) + "PathSegment".into(), + NodeMatcher::new(SyntaxKind::PathSegment, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::new("SlashSegment").to_matchable(), + Delimited::new(vec![ + TypedParser::new(SyntaxKind::Word, SyntaxKind::PathSegment) + .to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + this.delimiter(Ref::new("SlashSegment")); + }) + .to_matchable(), + ]) .to_matchable(), - Bracketed::new(vec![ - Ref::new("WithCompoundStatementSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .to_matchable(), - Bracketed::new(vec![Ref::new("NonSetSelectableGrammar").to_matchable()]) - .to_matchable(), - ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WithFillSegment".into(), + NodeMatcher::new(SyntaxKind::WithFill, |_dialect| { + Nothing::new().to_matchable() + }) .to_matchable() .into(), ), ]); - // This is a hook point to allow subclassing for other dialects ansi_dialect.add([ - ( - "PostTableExpressionGrammar".into(), - Nothing::new().to_matchable().into(), - ), ( "BracketedSegment".into(), BracketedSegmentMatcher::new().to_matchable().into(), ), ( - "TimeWithTZGrammar".into(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("TIME").to_matchable(), - Ref::keyword("TIMESTAMP").to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("WITHOUT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("TIME").to_matchable(), - Ref::keyword("ZONE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable() - .into(), + "CodeSegment".into(), + CodeParser::new().to_matchable().into(), + ), + ( + "LiteralSegment".into(), + Ref::new("LiteralGrammar").to_matchable().into(), ), ]); ansi_dialect } -pub fn select_clause_element() -> Matchable { - one_of(vec![ - // *, blah.*, blah.blah.*, etc. - Ref::new("WildcardExpressionSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("BaseExpressionElementGrammar").to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() -} - -fn lexer_matchers() -> Vec { - vec![ - Matcher::regex("whitespace", r"[^\S\r\n]+", SyntaxKind::Whitespace), - Matcher::regex("inline_comment", r"(--|#)[^\n]*", SyntaxKind::InlineComment), - Matcher::native("block_comment", block_comment, SyntaxKind::BlockComment) - .subdivider(Pattern::legacy( - "newline", - |_| true, - r"\r\n|\n", - SyntaxKind::Newline, - )) - .post_subdivide(Pattern::legacy( - "whitespace", - |_| true, - r"[^\S\r\n]+", - SyntaxKind::Whitespace, - )), - Matcher::regex( - "single_quote", - r"'([^'\\]|\\.|'')*'", - SyntaxKind::SingleQuote, - ), - Matcher::regex( - "double_quote", - r#""([^"\\]|\\.)*""#, - SyntaxKind::DoubleQuote, - ), - Matcher::regex("back_quote", r"`[^`]*`", SyntaxKind::BackQuote), - Matcher::legacy( - "dollar_quote", - |s| s.starts_with("$"), - r"\$(\w*)\$[\s\S]*?\$\1\$", - SyntaxKind::DollarQuote, - ), - Matcher::native( - "numeric_literal", - numeric_literal, - SyntaxKind::NumericLiteral, - ), - Matcher::regex("like_operator", r"!?~~?\*?", SyntaxKind::LikeOperator), - Matcher::regex("newline", r"(\r\n|\n)", SyntaxKind::Newline), - Matcher::string("casting_operator", "::", SyntaxKind::CastingOperator), - Matcher::string("equals", "=", SyntaxKind::RawComparisonOperator), - Matcher::string("greater_than", ">", SyntaxKind::RawComparisonOperator), - Matcher::string("less_than", "<", SyntaxKind::RawComparisonOperator), - Matcher::string("not", "!", SyntaxKind::RawComparisonOperator), - Matcher::string("dot", ".", SyntaxKind::Dot), - Matcher::string("comma", ",", SyntaxKind::Comma), - Matcher::string("plus", "+", SyntaxKind::Plus), - Matcher::string("minus", "-", SyntaxKind::Minus), - Matcher::string("divide", "/", SyntaxKind::Divide), - Matcher::string("percent", "%", SyntaxKind::Percent), - Matcher::string("question", "?", SyntaxKind::Question), - Matcher::string("ampersand", "&", SyntaxKind::Ampersand), - Matcher::string("vertical_bar", "|", SyntaxKind::VerticalBar), - Matcher::string("caret", "^", SyntaxKind::Caret), - Matcher::string("star", "*", SyntaxKind::Star), - Matcher::string("start_bracket", "(", SyntaxKind::StartBracket), - Matcher::string("end_bracket", ")", SyntaxKind::EndBracket), - Matcher::string("start_square_bracket", "[", SyntaxKind::StartSquareBracket), - Matcher::string("end_square_bracket", "]", SyntaxKind::EndSquareBracket), - Matcher::string("start_curly_bracket", "{", SyntaxKind::StartCurlyBracket), - Matcher::string("end_curly_bracket", "}", SyntaxKind::EndCurlyBracket), - Matcher::string("colon", ":", SyntaxKind::Colon), - Matcher::string("semicolon", ";", SyntaxKind::Semicolon), - Matcher::regex("word", "[0-9a-zA-Z_]+", SyntaxKind::Word), - ] -} - -pub fn frame_extent() -> AnyNumberOf { - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CURRENT").to_matchable(), - Ref::keyword("ROW").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("INTERVAL").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("UNBOUNDED").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("PRECEDING").to_matchable(), - Ref::keyword("FOLLOWING").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) -} - -pub fn explainable_stmt() -> AnyNumberOf { - one_of(vec![ - Ref::new("SelectableGrammar").to_matchable(), - Ref::new("InsertStatementSegment").to_matchable(), - Ref::new("UpdateStatementSegment").to_matchable(), - Ref::new("DeleteStatementSegment").to_matchable(), - ]) -} - pub fn get_unordered_select_statement_segment_grammar() -> Matchable { Sequence::new(vec![ Ref::new("SelectClauseSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), Ref::new("FromClauseSegment").optional().to_matchable(), Ref::new("WhereClauseSegment").optional().to_matchable(), Ref::new("GroupByClauseSegment").optional().to_matchable(), @@ -5416,197 +6131,122 @@ pub fn get_unordered_select_statement_segment_grammar() -> Matchable { Ref::new("OverlapsClauseSegment").optional().to_matchable(), Ref::new("NamedWindowSegment").optional().to_matchable(), ]) - .terminators(vec![ - Ref::new("SetOperatorSegment").to_matchable(), - Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), - Ref::new("WithDataClauseSegment").to_matchable(), - Ref::new("OrderByClauseSegment").to_matchable(), - Ref::new("LimitClauseSegment").to_matchable(), - ]) .config(|this| { this.parse_mode(ParseMode::GreedyOnceStarted); - }) - .to_matchable() -} - -pub fn select_statement() -> Matchable { - get_unordered_select_statement_segment_grammar().copy( - Some(vec![ - Ref::new("OrderByClauseSegment").optional().to_matchable(), - Ref::new("FetchClauseSegment").optional().to_matchable(), - Ref::new("LimitClauseSegment").optional().to_matchable(), - Ref::new("NamedWindowSegment").optional().to_matchable(), - ]), - None, - None, - None, - vec![ + this.terminators = vec![ Ref::new("SetOperatorSegment").to_matchable(), Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), Ref::new("WithDataClauseSegment").to_matchable(), - ], - true, - ) -} - -pub fn select_clause_segment() -> Matchable { - Sequence::new(vec![ - Ref::keyword("SELECT").to_matchable(), - Ref::new("SelectClauseModifierSegment") - .optional() - .to_matchable(), - MetaSegment::indent().to_matchable(), - Delimited::new(vec![Ref::new("SelectClauseElementSegment").to_matchable()]) - .config(|this| this.allow_trailing()) - .to_matchable(), - ]) - .terminators(vec![ - Ref::new("SelectClauseTerminatorGrammar").to_matchable(), - ]) - .config(|this| { - this.parse_mode(ParseMode::GreedyOnceStarted); + Ref::new("OrderByClauseSegment").to_matchable(), + Ref::new("LimitClauseSegment").to_matchable(), + ]; }) .to_matchable() } -pub fn statement_segment() -> Matchable { - one_of(vec![ - Ref::new("SelectableGrammar").to_matchable(), - Ref::new("MergeStatementSegment").to_matchable(), - Ref::new("InsertStatementSegment").to_matchable(), - Ref::new("TransactionStatementSegment").to_matchable(), - Ref::new("DropTableStatementSegment").to_matchable(), - Ref::new("DropViewStatementSegment").to_matchable(), - Ref::new("CreateUserStatementSegment").to_matchable(), - Ref::new("DropUserStatementSegment").to_matchable(), - Ref::new("TruncateStatementSegment").to_matchable(), - Ref::new("AccessStatementSegment").to_matchable(), - Ref::new("CreateTableStatementSegment").to_matchable(), - Ref::new("CreateRoleStatementSegment").to_matchable(), - Ref::new("DropRoleStatementSegment").to_matchable(), - Ref::new("AlterTableStatementSegment").to_matchable(), - Ref::new("CreateSchemaStatementSegment").to_matchable(), - Ref::new("SetSchemaStatementSegment").to_matchable(), - Ref::new("DropSchemaStatementSegment").to_matchable(), - Ref::new("DropTypeStatementSegment").to_matchable(), - Ref::new("CreateDatabaseStatementSegment").to_matchable(), - Ref::new("DropDatabaseStatementSegment").to_matchable(), - Ref::new("CreateIndexStatementSegment").to_matchable(), - Ref::new("DropIndexStatementSegment").to_matchable(), - Ref::new("CreateViewStatementSegment").to_matchable(), - Ref::new("DeleteStatementSegment").to_matchable(), - Ref::new("UpdateStatementSegment").to_matchable(), - Ref::new("CreateCastStatementSegment").to_matchable(), - Ref::new("DropCastStatementSegment").to_matchable(), - Ref::new("CreateFunctionStatementSegment").to_matchable(), - Ref::new("DropFunctionStatementSegment").to_matchable(), - Ref::new("CreateModelStatementSegment").to_matchable(), - Ref::new("DropModelStatementSegment").to_matchable(), - Ref::new("DescribeStatementSegment").to_matchable(), - Ref::new("UseStatementSegment").to_matchable(), - Ref::new("ExplainStatementSegment").to_matchable(), - Ref::new("CreateSequenceStatementSegment").to_matchable(), - Ref::new("AlterSequenceStatementSegment").to_matchable(), - Ref::new("DropSequenceStatementSegment").to_matchable(), - Ref::new("CreateTriggerStatementSegment").to_matchable(), - Ref::new("DropTriggerStatementSegment").to_matchable(), +pub fn get_unordered_set_expression_segment_grammar() -> Matchable { + Sequence::new(vec![ + Ref::new("NonSetSelectableGrammar").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("SetOperatorSegment").to_matchable(), + Ref::new("NonSetSelectableGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), ]) - .config(|this| this.terminators = vec![Ref::new("DelimiterGrammar").to_matchable()]) .to_matchable() } -pub fn wildcard_expression_segment() -> Matchable { - Sequence::new(vec![Ref::new("WildcardIdentifierSegment").to_matchable()]).to_matchable() -} - -fn numeric_literal(cursor: &mut Cursor) -> bool { - let first_char = cursor.shift(); - match first_char { - '0'..='9' | '.' => { - let has_decimal = first_char == '.'; - - if has_decimal { - if cursor.peek().is_ascii_digit() { - cursor.shift_while(|c| c.is_ascii_digit()); - } else { - return false; - } - } else { - cursor.shift_while(|c| c.is_ascii_digit()); - if cursor.peek() == '.' { - cursor.shift(); - cursor.shift_while(|c| c.is_ascii_digit()); - } - } - - if let 'e' | 'E' = cursor.peek() { - cursor.shift(); - if let '+' | '-' = cursor.peek() { - cursor.shift(); - } - let mut exp_digits = false; - while cursor.peek().is_ascii_digit() { - cursor.shift(); - exp_digits = true; - } - if !exp_digits { - return false; - } - } - - let next_char = cursor.peek(); - if next_char == '.' || next_char.is_ascii_alphanumeric() || next_char == '_' { - return false; - } - - true - } - _ => false, - } -} - -fn block_comment(cursor: &mut Cursor) -> bool { - if cursor.shift() != '/' { - return false; - } - - if cursor.shift() != '*' { - return false; - } - - let mut depth = 1usize; - - loop { - match cursor.shift() { - '\0' => return false, - '/' if cursor.peek() == '*' => { - cursor.shift(); - depth += 1; - } - '*' if cursor.peek() == '/' => { - cursor.shift(); - depth -= 1; - if depth == 0 { - break true; - } - } - _ => {} - } - } -} - -pub(crate) fn select_clause_terminators() -> Vec { +fn lexer_matchers() -> Vec { vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("WHERE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("OVERLAPS").to_matchable(), - Ref::new("SetOperatorSegment").to_matchable(), - Ref::keyword("FETCH").to_matchable(), + Matcher::regex("whitespace", r#"[^\S\r\n]+"#, SyntaxKind::Whitespace), + Matcher::regex( + "inline_comment", + r#"(--|#)[^\n]*"#, + SyntaxKind::InlineComment, + ), + Matcher::legacy( + "block_comment", + |s| s.starts_with("/*"), + r#"\/\*([^\*]|\*(?!\/))*\*\/"#, + SyntaxKind::BlockComment, + ) + .subdivider(Pattern::legacy( + "newline", + |_| true, + r#"\r\n|\n"#, + SyntaxKind::Newline, + )) + .post_subdivide(Pattern::legacy( + "whitespace", + |_| true, + r#"[^\S\r\n]+"#, + SyntaxKind::Whitespace, + )), + Matcher::regex( + "single_quote", + r#"'([^'\\]|\\.|'')*'"#, + SyntaxKind::SingleQuote, + ), + Matcher::regex( + "double_quote", + r#""(""|[^"\\]|\\.)*""#, + SyntaxKind::DoubleQuote, + ), + Matcher::regex("back_quote", r#"`(?:[^`\\]|\\.)*`"#, SyntaxKind::BackQuote), + Matcher::legacy( + "dollar_quote", + |s| s.starts_with("$"), + r#"\$(\w*)\$([\s\S]*?)\$\1\$"#, + SyntaxKind::DollarQuote, + ), + Matcher::legacy( + "numeric_literal", + |_| true, + r#"(?>\d+\.\d+|\d+\.(?![\.\w])|\.\d+|\d+)(\.?[eE][+-]?\d+)?((?<=\.)|(?=\b))"#, + SyntaxKind::NumericLiteral, + ), + Matcher::regex( + "obevo_annotation", + r#"////\s*(CHANGE|BODY|METADATA)[^\n]*"#, + SyntaxKind::Comment, + ), + Matcher::string("glob_operator", r#"~~~"#, SyntaxKind::GlobOperator), + Matcher::regex("like_operator", r#"!?~~?\*?"#, SyntaxKind::LikeOperator), + Matcher::regex("newline", r#"\r\n|\n"#, SyntaxKind::Newline), + Matcher::string("casting_operator", r#"::"#, SyntaxKind::CastingOperator), + Matcher::string("equals", r#"="#, SyntaxKind::RawComparisonOperator), + Matcher::string("greater_than", r#">"#, SyntaxKind::RawComparisonOperator), + Matcher::string("less_than", r#"<"#, SyntaxKind::RawComparisonOperator), + Matcher::string("not", r#"!"#, SyntaxKind::RawComparisonOperator), + Matcher::string("dot", r#"."#, SyntaxKind::Dot), + Matcher::string("comma", r#","#, SyntaxKind::Comma), + Matcher::string("plus", r#"+"#, SyntaxKind::Plus), + Matcher::string("minus", r#"-"#, SyntaxKind::Minus), + Matcher::string("divide", r#"/"#, SyntaxKind::Divide), + Matcher::string("percent", r#"%"#, SyntaxKind::Percent), + Matcher::string("question", r#"?"#, SyntaxKind::Question), + Matcher::string("ampersand", r#"&"#, SyntaxKind::Ampersand), + Matcher::string("vertical_bar", r#"|"#, SyntaxKind::VerticalBar), + Matcher::string("caret", r#"^"#, SyntaxKind::Caret), + Matcher::string("star", r#"*"#, SyntaxKind::Star), + Matcher::string("start_bracket", r#"("#, SyntaxKind::StartBracket), + Matcher::string("end_bracket", r#")"#, SyntaxKind::EndBracket), + Matcher::string( + "start_square_bracket", + r#"["#, + SyntaxKind::StartSquareBracket, + ), + Matcher::string("end_square_bracket", r#"]"#, SyntaxKind::EndSquareBracket), + Matcher::string("start_curly_bracket", r#"{"#, SyntaxKind::StartCurlyBracket), + Matcher::string("end_curly_bracket", r#"}"#, SyntaxKind::EndCurlyBracket), + Matcher::string("colon", r#":"#, SyntaxKind::Colon), + Matcher::string("semicolon", r#";"#, SyntaxKind::Semicolon), + Matcher::regex("word", r#"[0-9a-zA-Z_]+"#, SyntaxKind::Word), ] } diff --git a/crates/lib-dialects/src/ansi_keywords.rs b/crates/lib-dialects/src/ansi_keywords.rs index 0893b4d37..cd1918114 100644 --- a/crates/lib-dialects/src/ansi_keywords.rs +++ b/crates/lib-dialects/src/ansi_keywords.rs @@ -1,5 +1,3 @@ -//! A list of all SQL keywords. - pub(crate) const ANSI_RESERVED_KEYWORDS: &str = "SELECT JOIN ON diff --git a/crates/lib-dialects/src/athena.rs b/crates/lib-dialects/src/athena.rs index 23297a609..cc73be003 100644 --- a/crates/lib-dialects/src/athena.rs +++ b/crates/lib-dialects/src/athena.rs @@ -1,6 +1,3 @@ -// The AWS Athena dialect. -// https://docs.aws.amazon.com/athena/latest/ug/what-is.html - use itertools::Itertools; use sqruff_lib_core::dialects::Dialect; use sqruff_lib_core::dialects::init::DialectKind; @@ -17,34 +14,45 @@ use sqruff_lib_core::parser::parsers::{RegexParser, StringParser, TypedParser}; use sqruff_lib_core::parser::segments::generator::SegmentGenerator; use sqruff_lib_core::parser::segments::meta::MetaSegment; +use super::athena_keywords::{ATHENA_RESERVED_KEYWORDS, ATHENA_UNRESERVED_KEYWORDS}; + pub fn dialect() -> Dialect { - let ansi_dialect = super::ansi::dialect(); - let mut dialect = super::ansi::raw_dialect(); - dialect.name = DialectKind::Athena; + raw_dialect().config(|this| this.expand()) +} - dialect +pub fn raw_dialect() -> Dialect { + let ansi_dialect = super::ansi::raw_dialect(); + let mut athena_dialect = ansi_dialect.clone(); + athena_dialect.name = DialectKind::Athena; + + athena_dialect .sets_mut("unreserved_keywords") - .extend(super::athena_keywords::ATHENA_UNRESERVED_KEYWORDS); - dialect + .extend(ATHENA_UNRESERVED_KEYWORDS); + + athena_dialect .sets_mut("reserved_keywords") - .extend(super::athena_keywords::ATHENA_RESERVED_KEYWORDS); + .extend(ATHENA_RESERVED_KEYWORDS); - dialect.insert_lexer_matchers( - // Array Operations: https://prestodb.io/docs/0.217/functions/array.html - vec![Matcher::string("right_arrow", "->", SyntaxKind::RightArrow)], + athena_dialect.insert_lexer_matchers( + vec![Matcher::string( + "right_arrow", + r#"->"#, + SyntaxKind::RightArrow, + )], "like_operator", ); - dialect - .bracket_sets_mut("angle_bracket_pairs") - .extend(vec![( + athena_dialect.update_bracket_sets( + "angle_bracket_pairs", + vec![( "angle", "StartAngleBracketSegment", "EndAngleBracketSegment", false, - )]); + )], + ); - dialect.add([ + athena_dialect.add([ ( "StartAngleBracketSegment".into(), StringParser::new("<", SyntaxKind::StartAngleBracket) @@ -76,25 +84,25 @@ pub fn dialect() -> Dialect { .into(), ), ( - "ORC".into(), + "ORCFILE".into(), StringParser::new("ORCFILE", SyntaxKind::FileFormat) .to_matchable() .into(), ), ( - "PARQUET".into(), + "PARQUETFILE".into(), StringParser::new("PARQUETFILE", SyntaxKind::FileFormat) .to_matchable() .into(), ), ( - "AVRO".into(), + "AVROFILE".into(), StringParser::new("AVROFILE", SyntaxKind::FileFormat) .to_matchable() .into(), ), ( - "ION".into(), + "IONFILE".into(), StringParser::new("IONFILE", SyntaxKind::FileFormat) .to_matchable() .into(), @@ -177,7 +185,6 @@ pub fn dialect() -> Dialect { Ref::keyword("FIELD_DELIMITER").to_matchable(), Ref::keyword("IS_EXTERNAL").to_matchable(), Ref::keyword("TABLE_TYPE").to_matchable(), - // Iceberg-specific properties Ref::keyword("LOCATION").to_matchable(), Ref::keyword("PARTITIONING").to_matchable(), Ref::keyword("VACUUM_MAX_SNAPSHOT_AGE_SECONDS").to_matchable(), @@ -268,11 +275,11 @@ pub fn dialect() -> Dialect { Ref::keyword("SEQUENCEFILE").to_matchable(), Ref::keyword("TEXTFILE").to_matchable(), Ref::keyword("RCFILE").to_matchable(), - Ref::keyword("ORC").to_matchable(), - Ref::keyword("PARQUET").to_matchable(), - Ref::keyword("AVRO").to_matchable(), + Ref::keyword("ORCFILE").to_matchable(), + Ref::keyword("PARQUETFILE").to_matchable(), + Ref::keyword("AVROFILE").to_matchable(), Ref::keyword("JSONFILE").to_matchable(), - Ref::keyword("ION").to_matchable(), + Ref::keyword("IONFILE").to_matchable(), Sequence::new(vec![ Ref::keyword("INPUTFORMAT").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), @@ -339,8 +346,8 @@ pub fn dialect() -> Dialect { Ref::new("EqualsSegment").to_matchable(), Ref::new("LiteralGrammar").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -361,227 +368,194 @@ pub fn dialect() -> Dialect { ), ]); - dialect.add([ - ( - "LiteralGrammar".into(), - ansi_dialect - .grammar("LiteralGrammar") - .copy( - Some(vec![Ref::new("ParameterSegment").to_matchable()]), - None, - None, - None, - Vec::new(), - false, - ) - .into(), + athena_dialect.add([( + "NakedIdentifierSegment".into(), + SegmentGenerator::new(|dialect| { + let reserved_keywords = dialect.sets("reserved_keywords"); + let pattern = reserved_keywords.iter().join("|"); + let anti_template = format!("^({pattern})$"); + RegexParser::new(r#"[A-Z0-9_]*[A-Z_][A-Z0-9_]*"#, SyntaxKind::NakedIdentifier) + .anti_template(&anti_template) + .to_matchable() + }) + .into(), + )]); + + athena_dialect.replace_grammar( + "LiteralGrammar", + ansi_dialect.grammar("LiteralGrammar").copy( + Some(vec![Ref::new("ParameterSegment").to_matchable()]), + None, + None, + None, + vec![], + false, ), - ( - "AccessorGrammar".into(), - Sequence::new(vec![ - AnyNumberOf::new(vec![Ref::new("ArrayAccessorSegment").to_matchable()]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::new("ObjectReferenceDelimiterGrammar").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|config| { - config.optional(); + ); + + athena_dialect.replace_grammar( + "AccessorGrammar", + Sequence::new(vec![ + AnyNumberOf::new(vec![Ref::new("ArrayAccessorSegment").to_matchable()]) + .config(|this| { + this.optional(); }) .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("ObjectReferenceDelimiterGrammar").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "QuotedLiteralSegment".into(), - one_of(vec![ - TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral).to_matchable(), - TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedLiteral).to_matchable(), - TypedParser::new(SyntaxKind::BackQuote, SyntaxKind::QuotedLiteral).to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "TrimParametersGrammar".into(), - Nothing::new().to_matchable().into(), - ), - ( - "NakedIdentifierSegment".into(), - SegmentGenerator::new(|dialect| { - let reserved_keywords = dialect.sets("reserved_keywords"); - let pattern = reserved_keywords.iter().join("|"); - let anti_template = format!("^({pattern})$"); - - RegexParser::new("[A-Z0-9_]*[A-Z_][A-Z0-9_]*", SyntaxKind::NakedIdentifier) - .anti_template(&anti_template) - .to_matchable() + .config(|this| { + this.optional(); }) - .into(), - ), - ( - "SingleIdentifierGrammar".into(), - ansi_dialect - .grammar("SingleIdentifierGrammar") - .copy( - Some(vec![Ref::new("BackQuotedIdentifierSegment").to_matchable()]), - None, - None, - None, - Vec::new(), - false, - ) - .into(), - ), - ( - "BinaryOperatorGrammar".into(), - one_of(vec![ - Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(), - Ref::new("StringBinaryOperatorGrammar").to_matchable(), - Ref::new("BooleanBinaryOperatorGrammar").to_matchable(), - Ref::new("ComparisonOperatorGrammar").to_matchable(), - Ref::new("RightArrowOperator").to_matchable(), - ]) - .to_matchable() - .into(), + .to_matchable(), + ]) + .to_matchable(), + ); + + athena_dialect.replace_grammar( + "QuotedLiteralSegment", + one_of(vec![ + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral).to_matchable(), + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedLiteral).to_matchable(), + TypedParser::new(SyntaxKind::BackQuote, SyntaxKind::QuotedLiteral).to_matchable(), + ]) + .to_matchable(), + ); + + athena_dialect.replace_grammar("TrimParametersGrammar", Nothing::new().to_matchable()); + + athena_dialect.replace_grammar( + "QuotedIdentifierSegment", + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedIdentifier).to_matchable(), + ); + + athena_dialect.replace_grammar( + "SingleIdentifierGrammar", + ansi_dialect.grammar("SingleIdentifierGrammar").copy( + Some(vec![Ref::new("BackQuotedIdentifierSegment").to_matchable()]), + None, + None, + None, + vec![], + false, ), - ( - "PostFunctionGrammar".into(), - ansi_dialect - .grammar("PostFunctionGrammar") - .copy( - Some(vec![ - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("ORDINALITY").to_matchable(), - ]) - .config(|config| config.optional()) - .to_matchable(), - Ref::new("WithinGroupClauseSegment").to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ) - .into(), + ); + + athena_dialect.replace_grammar( + "BinaryOperatorGrammar", + one_of(vec![ + Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(), + Ref::new("StringBinaryOperatorGrammar").to_matchable(), + Ref::new("BooleanBinaryOperatorGrammar").to_matchable(), + Ref::new("ComparisonOperatorGrammar").to_matchable(), + Ref::new("RightArrowOperator").to_matchable(), + ]) + .to_matchable(), + ); + + athena_dialect.replace_grammar( + "PostFunctionGrammar", + ansi_dialect.grammar("PostFunctionGrammar").copy( + Some(vec![ + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("ORDINALITY").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("WithinGroupClauseSegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, ), - ( - "FunctionContentsGrammar".into(), - ansi_dialect - .grammar("FunctionContentsGrammar") - .copy( - Some(vec![ - Ref::new("ListaggOverflowClauseSegment").to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ) - .into(), + ); + + athena_dialect.replace_grammar( + "FunctionContentsGrammar", + ansi_dialect.grammar("FunctionContentsGrammar").copy( + Some(vec![ + Ref::new("ListaggOverflowClauseSegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, ), - ]); + ); - // Add support for WITHIN GROUP and LISTAGG overflow clauses - dialect.add([ + athena_dialect.replace_grammar( + "AlterTableDropColumnGrammar", + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ); + + athena_dialect.add([ ( "WithinGroupClauseSegment".into(), - Sequence::new(vec![ - Ref::keyword("WITHIN").to_matchable(), - Ref::keyword("GROUP").to_matchable(), - Bracketed::new(vec![Ref::new("OrderByClauseSegment").to_matchable()]) - .to_matchable(), - Ref::new("FilterClauseGrammar").optional().to_matchable(), - ]) + NodeMatcher::new(SyntaxKind::WithingroupClause, |_dialect| { + let dialect = super::trino::raw_dialect(); + dialect + .grammar("WithinGroupClauseSegment") + .match_grammar(&dialect) + .unwrap() + }) .to_matchable() .into(), ), ( "ListaggOverflowClauseSegment".into(), - Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("OVERFLOW").to_matchable(), - one_of(vec![ - Ref::keyword("ERROR").to_matchable(), - Sequence::new(vec![ - Ref::keyword("TRUNCATE").to_matchable(), - Ref::new("QuotedLiteralSegment").optional().to_matchable(), - one_of(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("WITHOUT").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Ref::keyword("COUNT").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) + NodeMatcher::new(SyntaxKind::ListaggOverflowClause, |_dialect| { + let dialect = super::trino::raw_dialect(); + dialect + .grammar("ListaggOverflowClauseSegment") + .match_grammar(&dialect) + .unwrap() + }) .to_matchable() .into(), ), ( - "ValuesClauseSegment".into(), - NodeMatcher::new(SyntaxKind::ValuesClause, |_| { + "ArrayTypeSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayType, |_dialect| { Sequence::new(vec![ - Ref::keyword("VALUES").to_matchable(), - Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), + Ref::keyword("ARRAY").to_matchable(), + Ref::new("ArrayTypeSchemaSegment").optional().to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - dialect.replace_grammar( - "ArrayTypeSegment", - Sequence::new(vec![ - Ref::keyword("ARRAY").to_matchable(), - Ref::new("ArrayTypeSchemaSegment").optional().to_matchable(), - ]) - .to_matchable(), - ); - - dialect.replace_grammar( - "ArrayTypeSchemaSegment", - Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) - .config(|config| { - config.bracket_pairs_set = "angle_bracket_pairs"; - config.bracket_type = "angle"; + ( + "ArrayTypeSchemaSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayTypeSchema, |_dialect| { + Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .config(|this| { + this.bracket_type("angle"); + this.bracket_pairs_set = "angle_bracket_pairs"; + }) + .to_matchable() }) - .to_matchable(), - ); - - dialect.replace_grammar( - "StructTypeSegment", - Sequence::new(vec![ - Ref::keyword("STRUCT").to_matchable(), - Ref::new("StructTypeSchemaSegment") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ); - - dialect.add([ + .to_matchable() + .into(), + ), ( "MapTypeSegment".into(), - NodeMatcher::new(SyntaxKind::MapType, |_| { + NodeMatcher::new(SyntaxKind::MapType, |_dialect| { Sequence::new(vec![ Ref::keyword("MAP").to_matchable(), Ref::new("MapTypeSchemaSegment").optional().to_matchable(), @@ -593,7 +567,7 @@ pub fn dialect() -> Dialect { ), ( "MapTypeSchemaSegment".into(), - NodeMatcher::new(SyntaxKind::MapTypeSchema, |_| { + NodeMatcher::new(SyntaxKind::MapTypeSchema, |_dialect| { Bracketed::new(vec![ Sequence::new(vec![ Ref::new("PrimitiveTypeSegment").to_matchable(), @@ -602,45 +576,32 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.bracket_pairs_set = "angle_bracket_pairs"; - config.bracket_type = "angle"; + .config(|this| { + this.bracket_type("angle"); + this.bracket_pairs_set = "angle_bracket_pairs"; }) .to_matchable() }) .to_matchable() .into(), ), - ]); - - dialect.replace_grammar( - "StatementSegment", - super::ansi::statement_segment().copy( - Some(vec![ - Ref::new("MsckRepairTableStatementSegment").to_matchable(), - Ref::new("UnloadStatementSegment").to_matchable(), - Ref::new("PrepareStatementSegment").to_matchable(), - Ref::new("ExecuteStatementSegment").to_matchable(), - Ref::new("ShowStatementSegment").to_matchable(), - ]), - None, - None, - Some(vec![ - Ref::new("TransactionStatementSegment").to_matchable(), - Ref::new("CreateSchemaStatementSegment").to_matchable(), - Ref::new("SetSchemaStatementSegment").to_matchable(), - Ref::new("CreateModelStatementSegment").to_matchable(), - Ref::new("DropModelStatementSegment").to_matchable(), - ]), - Vec::new(), - false, + ( + "StructTypeSegment".into(), + NodeMatcher::new(SyntaxKind::StructType, |_dialect| { + Sequence::new(vec![ + Ref::keyword("STRUCT").to_matchable(), + Ref::new("StructTypeSchemaSegment") + .optional() + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), ), - ); - - dialect.add([ ( "StructTypeSchemaSegment".into(), - NodeMatcher::new(SyntaxKind::StructTypeSchema, |_| { + NodeMatcher::new(SyntaxKind::StructTypeSchema, |_dialect| { Bracketed::new(vec![ Delimited::new(vec![ Sequence::new(vec![ @@ -653,9 +614,9 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.bracket_pairs_set = "angle_bracket_pairs"; - config.bracket_type = "angle"; + .config(|this| { + this.bracket_type("angle"); + this.bracket_pairs_set = "angle_bracket_pairs"; }) .to_matchable() }) @@ -664,7 +625,7 @@ pub fn dialect() -> Dialect { ), ( "PrimitiveTypeSegment".into(), - NodeMatcher::new(SyntaxKind::PrimitiveType, |_| { + NodeMatcher::new(SyntaxKind::PrimitiveType, |_dialect| { one_of(vec![ Ref::keyword("BOOLEAN").to_matchable(), Ref::keyword("TINYINT").to_matchable(), @@ -703,7 +664,7 @@ pub fn dialect() -> Dialect { ), ( "DatatypeSegment".into(), - NodeMatcher::new(SyntaxKind::DataType, |_| { + NodeMatcher::new(SyntaxKind::DataType, |_dialect| { one_of(vec![ Ref::new("PrimitiveTypeSegment").to_matchable(), Ref::new("StructTypeSegment").to_matchable(), @@ -735,34 +696,43 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - dialect.replace_grammar( - "GroupByClauseSegment", - Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - MetaSegment::indent().to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Ref::new("CubeRollupClauseSegment").to_matchable(), - Ref::new("GroupingSetsClauseSegment").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - ); - - dialect.add([ + ( + "StatementSegment".into(), + NodeMatcher::new(SyntaxKind::Statement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("StatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("MsckRepairTableStatementSegment").to_matchable(), + Ref::new("UnloadStatementSegment").to_matchable(), + Ref::new("PrepareStatementSegment").to_matchable(), + Ref::new("ExecuteStatementSegment").to_matchable(), + Ref::new("ShowStatementSegment").to_matchable(), + ]), + None, + None, + Some(vec![ + Ref::new("TransactionStatementSegment").to_matchable(), + Ref::new("CreateSchemaStatementSegment").to_matchable(), + Ref::new("SetSchemaStatementSegment").to_matchable(), + Ref::new("CreateModelStatementSegment").to_matchable(), + Ref::new("DropModelStatementSegment").to_matchable(), + ]), + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), ( "CreateTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateTableStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateTableStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::keyword("EXTERNAL").optional().to_matchable(), @@ -787,8 +757,8 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Ref::new("CommentGrammar").optional().to_matchable(), @@ -800,11 +770,8 @@ pub fn dialect() -> Dialect { Delimited::new(vec![ Sequence::new(vec![ one_of(vec![ - // External tables expect types... Ref::new("ColumnDefinitionSegment").to_matchable(), - // Iceberg tables don't expect types. Ref::new("SingleIdentifierGrammar").to_matchable(), - // Iceberg tables also allow partition transforms Ref::new("FunctionSegment").to_matchable(), ]) .to_matchable(), @@ -816,8 +783,8 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Sequence::new(vec![ @@ -828,8 +795,8 @@ pub fn dialect() -> Dialect { Ref::new("NumericLiteralSegment").to_matchable(), Ref::keyword("BUCKETS").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Ref::new("StoredAsGrammar").optional().to_matchable(), @@ -844,8 +811,8 @@ pub fn dialect() -> Dialect { Ref::keyword("WITH").to_matchable(), Ref::new("BracketedCTASPropertyGrammar").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Ref::keyword("AS").to_matchable(), @@ -858,8 +825,8 @@ pub fn dialect() -> Dialect { Ref::keyword("NO").to_matchable(), Ref::keyword("DATA").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -874,7 +841,7 @@ pub fn dialect() -> Dialect { ), ( "MsckRepairTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::MsckRepairTableStatement, |_| { + NodeMatcher::new(SyntaxKind::MsckRepairTableStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("MSCK").to_matchable(), Ref::keyword("REPAIR").to_matchable(), @@ -888,7 +855,7 @@ pub fn dialect() -> Dialect { ), ( "RowFormatClauseSegment".into(), - NodeMatcher::new(SyntaxKind::RowFormatClause, |_| { + NodeMatcher::new(SyntaxKind::RowFormatClause, |_dialect| { Sequence::new(vec![ Ref::keyword("ROW").to_matchable(), Ref::keyword("FORMAT").to_matchable(), @@ -903,13 +870,13 @@ pub fn dialect() -> Dialect { Ref::keyword("BY").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Sequence::new(vec![ @@ -917,8 +884,8 @@ pub fn dialect() -> Dialect { Ref::keyword("ITEMS").to_matchable(), Ref::new("TerminatedByGrammar").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Sequence::new(vec![ @@ -926,16 +893,16 @@ pub fn dialect() -> Dialect { Ref::keyword("KEYS").to_matchable(), Ref::new("TerminatedByGrammar").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Sequence::new(vec![ Ref::keyword("LINES").to_matchable(), Ref::new("TerminatedByGrammar").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Sequence::new(vec![ @@ -944,8 +911,8 @@ pub fn dialect() -> Dialect { Ref::keyword("AS").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -964,9 +931,22 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), + ( + "ValuesClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ValuesClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("VALUES").to_matchable(), + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), ( "InsertStatementSegment".into(), - NodeMatcher::new(SyntaxKind::InsertStatement, |_| { + NodeMatcher::new(SyntaxKind::InsertStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("INSERT").to_matchable(), Ref::keyword("INTO").to_matchable(), @@ -1003,7 +983,7 @@ pub fn dialect() -> Dialect { ), ( "UnloadStatementSegment".into(), - NodeMatcher::new(SyntaxKind::UnloadStatement, |_| { + NodeMatcher::new(SyntaxKind::UnloadStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("UNLOAD").to_matchable(), Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) @@ -1014,8 +994,8 @@ pub fn dialect() -> Dialect { Ref::keyword("WITH").to_matchable(), Ref::new("BracketedUnloadPropertyGrammar").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -1026,7 +1006,7 @@ pub fn dialect() -> Dialect { ), ( "PrepareStatementSegment".into(), - NodeMatcher::new(SyntaxKind::PrepareStatement, |_| { + NodeMatcher::new(SyntaxKind::PrepareStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("PREPARE").to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), @@ -1048,7 +1028,7 @@ pub fn dialect() -> Dialect { ), ( "ExecuteStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ExecuteStatement, |_| { + NodeMatcher::new(SyntaxKind::ExecuteStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("EXECUTE").to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), @@ -1060,8 +1040,8 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -1072,7 +1052,7 @@ pub fn dialect() -> Dialect { ), ( "IntervalExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::IntervalExpression, |_| { + NodeMatcher::new(SyntaxKind::IntervalExpression, |_dialect| { Sequence::new(vec![ Ref::keyword("INTERVAL").optional().to_matchable(), one_of(vec![ @@ -1089,8 +1069,8 @@ pub fn dialect() -> Dialect { Ref::keyword("TO").to_matchable(), Ref::new("DatetimeUnitSegment").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -1103,22 +1083,180 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - dialect.add([ ( - "AlterTableDropColumnGrammar".into(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) + "GroupByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::GroupbyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Ref::new("CubeRollupClauseSegment").to_matchable(), + Ref::new("GroupingSetsClauseSegment").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), + ]; + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Delimited::new(vec![Ref::new("AlterTableOptionsGrammar").to_matchable()]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("PartitionSpecGrammar").optional().to_matchable(), + Ref::keyword("ADD").to_matchable(), + Ref::keyword("COLUMNS").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnDefinitionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("PartitionSpecGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("LOCATION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CHANGE").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMMENT").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AFTER").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![Ref::new("PartitionSpecGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("PartitionSpecGrammar").to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("PartitionSpecGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("PartitionSpecGrammar").optional().to_matchable(), + Ref::keyword("REPLACE").to_matchable(), + Ref::keyword("COLUMNS").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnDefinitionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("PartitionSpecGrammar").optional().to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("LOCATION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("TBLPROPERTIES").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) .to_matchable() .into(), ), ( "ShowStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ShowStatement, |_| { + NodeMatcher::new(SyntaxKind::ShowStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("SHOW").to_matchable(), one_of(vec![ @@ -1145,8 +1283,8 @@ pub fn dialect() -> Dialect { .to_matchable(), Ref::new("DatabaseReferenceSegment").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -1175,8 +1313,8 @@ pub fn dialect() -> Dialect { Ref::keyword("LIKE").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -1192,8 +1330,8 @@ pub fn dialect() -> Dialect { Ref::keyword("IN").to_matchable(), Ref::new("DatabaseReferenceSegment").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Ref::new("QuotedLiteralSegment").optional().to_matchable(), @@ -1203,8 +1341,8 @@ pub fn dialect() -> Dialect { Ref::keyword("TBLPROPERTIES").to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), Bracketed::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -1215,16 +1353,16 @@ pub fn dialect() -> Dialect { Ref::keyword("IN").to_matchable(), Ref::new("DatabaseReferenceSegment").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Sequence::new(vec![ Ref::keyword("LIKE").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -1239,5 +1377,5 @@ pub fn dialect() -> Dialect { ), ]); - dialect.config(|this| this.expand()) + athena_dialect } diff --git a/crates/lib-dialects/src/athena_keywords.rs b/crates/lib-dialects/src/athena_keywords.rs index 1f6823a33..4a3baa244 100644 --- a/crates/lib-dialects/src/athena_keywords.rs +++ b/crates/lib-dialects/src/athena_keywords.rs @@ -1,4 +1,4 @@ -pub(crate) const ATHENA_RESERVED_KEYWORDS: &[&str] = &[ +pub(crate) const ATHENA_RESERVED_KEYWORDS: [&str; 130] = [ "ALL", "ALTER", "AND", @@ -131,7 +131,7 @@ pub(crate) const ATHENA_RESERVED_KEYWORDS: &[&str] = &[ "WITH", ]; -pub(crate) const ATHENA_UNRESERVED_KEYWORDS: &[&str] = &[ +pub(crate) const ATHENA_UNRESERVED_KEYWORDS: [&str; 200] = [ "ABORT", "ADD", "ADMIN", diff --git a/crates/lib-dialects/src/bigquery.rs b/crates/lib-dialects/src/bigquery.rs index 8cc5b9421..07e40a5c4 100644 --- a/crates/lib-dialects/src/bigquery.rs +++ b/crates/lib-dialects/src/bigquery.rs @@ -15,42 +15,42 @@ use sqruff_lib_core::parser::segments::generator::SegmentGenerator; use sqruff_lib_core::parser::segments::meta::MetaSegment; use sqruff_lib_core::parser::types::ParseMode; -use super::ansi::{self, raw_dialect}; use super::bigquery_keywords::{BIGQUERY_RESERVED_KEYWORDS, BIGQUERY_UNRESERVED_KEYWORDS}; pub fn dialect() -> Dialect { - let mut dialect = raw_dialect(); - dialect.name = DialectKind::Bigquery; + raw_dialect().config(|this| this.expand()) +} + +pub fn raw_dialect() -> Dialect { + let ansi_dialect = super::ansi::raw_dialect(); + let mut bigquery_dialect = ansi_dialect.clone(); + bigquery_dialect.name = DialectKind::Bigquery; - dialect.insert_lexer_matchers( + bigquery_dialect.insert_lexer_matchers( vec![ - Matcher::string("right_arrow", "=>", SyntaxKind::RightArrow), - Matcher::string("question_mark", "?", SyntaxKind::QuestionMark), + Matcher::string("right_arrow", r#"=>"#, SyntaxKind::RightArrow), + Matcher::string("question_mark", r#"?"#, SyntaxKind::QuestionMark), Matcher::regex( "at_sign_literal", - r"@[a-zA-Z_][\w]*", + r#"@[a-zA-Z_][\w]*"#, SyntaxKind::AtSignLiteral, ), + Matcher::regex( + "double_at_sign_literal", + r#"@@[a-zA-Z_][\w\.]*"#, + SyntaxKind::DoubleAtSignLiteral, + ), + Matcher::string("pipe_operator", r#"|>"#, SyntaxKind::PipeOperator), ], "equals", ); - dialect.patch_lexer_matchers(vec![ - Matcher::legacy( - "single_quote", - |s| s.starts_with(['\'', 'R', 'r', 'B', 'b'].as_ref()), - r"([rR]?[bB]?|[bB]?[rR]?)?('''((? Dialect { .into(), ), ( - "SingleIdentifierFullGrammar".into(), - one_of(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), - Ref::new("NakedIdentifierFullSegment").to_matchable(), - ]) - .to_matchable() - .into(), + "PipeOperatorSegment".into(), + StringParser::new("|>", SyntaxKind::PipeOperator) + .to_matchable() + .into(), + ), + ( + "SelectClauseElementListGrammar".into(), + Delimited::new(vec![Ref::new("SelectClauseElementSegment").to_matchable()]) + .config(|this| { + this.allow_trailing(); + }) + .to_matchable() + .into(), ), ( "QuestionMarkSegment".into(), @@ -121,6 +126,73 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), + ( + "DoubleAtSignLiteralSegment".into(), + TypedParser::new( + SyntaxKind::DoubleAtSignLiteral, + SyntaxKind::DoubleAtSignLiteral, + ) + .to_matchable() + .into(), + ), + ( + "NakedIdentifierFullSegment".into(), + RegexParser::new(r#"[A-Z_][A-Z0-9_]*"#, SyntaxKind::NakedIdentifierAll) + .to_matchable() + .into(), + ), + ( + "NakedIdentifierPart".into(), + RegexParser::new(r#"[A-Z0-9_]+"#, SyntaxKind::NakedIdentifier) + .to_matchable() + .into(), + ), + ( + "NakedCSIdentifierPart".into(), + RegexParser::new(r#"[A-Z0-9_]+"#, SyntaxKind::NakedIdentifier) + .to_matchable() + .into(), + ), + ( + "NakedCSIdentifierSegment".into(), + SegmentGenerator::new(|dialect| { + let reserved_keywords = dialect.sets("reserved_keywords"); + let pattern = reserved_keywords.iter().join("|"); + let anti_template = format!("^({pattern})$"); + RegexParser::new(r#"[A-Z_][A-Z0-9_]*"#, SyntaxKind::NakedIdentifier) + .anti_template(&anti_template) + .to_matchable() + }) + .into(), + ), + ( + "QuotedCSIdentifierSegment".into(), + TypedParser::new(SyntaxKind::BackQuote, SyntaxKind::QuotedIdentifier) + .to_matchable() + .into(), + ), + ( + "SingleCSIdentifierGrammar".into(), + one_of(vec![ + Ref::new("NakedCSIdentifierSegment").to_matchable(), + Ref::new("QuotedCSIdentifierSegment").to_matchable(), + ]) + .config(|this| { + this.terminators = vec![Ref::new("DotSegment").to_matchable()]; + }) + .to_matchable() + .into(), + ), + ( + "SingleIdentifierFullGrammar".into(), + one_of(vec![ + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), + Ref::new("NakedIdentifierFullSegment").to_matchable(), + ]) + .to_matchable() + .into(), + ), ( "DefaultDeclareOptionsGrammar".into(), Sequence::new(vec![ @@ -149,8 +221,8 @@ pub fn dialect() -> Dialect { MultiStringParser::new( dialect .sets("extended_datetime_units") - .into_iter() - .map_into() + .iter() + .map(|item| item.to_string()) .collect_vec(), SyntaxKind::DatePart, ) @@ -158,25 +230,13 @@ pub fn dialect() -> Dialect { }) .into(), ), - ( - "NakedIdentifierFullSegment".into(), - RegexParser::new("[A-Z_][A-Z0-9_]*", SyntaxKind::NakedIdentifierAll) - .to_matchable() - .into(), - ), - ( - "NakedIdentifierPart".into(), - RegexParser::new("[A-Z0-9_]+", SyntaxKind::NakedIdentifier) - .to_matchable() - .into(), - ), ( "ProcedureNameIdentifierSegment".into(), one_of(vec![ - RegexParser::new("[A-Z_][A-Z0-9_]*", SyntaxKind::ProcedureNameIdentifier) + RegexParser::new(r#"[A-Z_][A-Z0-9_]*"#, SyntaxKind::ProcedureNameIdentifier) .anti_template("STRUCT") .to_matchable(), - RegexParser::new("`[^`]*`", SyntaxKind::ProcedureNameIdentifier).to_matchable(), + RegexParser::new(r#"`[^`]*`"#, SyntaxKind::ProcedureNameIdentifier).to_matchable(), ]) .to_matchable() .into(), @@ -190,7 +250,9 @@ pub fn dialect() -> Dialect { Ref::keyword("OUT").to_matchable(), Ref::keyword("INOUT").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Ref::new("ParameterNameSegment").optional().to_matchable(), one_of(vec![ @@ -219,304 +281,398 @@ pub fn dialect() -> Dialect { ), ]); - dialect.add([ + bigquery_dialect.add([ ( "NakedIdentifierSegment".into(), SegmentGenerator::new(|dialect| { - // Generate the anti template from the set of reserved keywords let reserved_keywords = dialect.sets("reserved_keywords"); let pattern = reserved_keywords.iter().join("|"); let anti_template = format!("^({pattern})$"); - - RegexParser::new("[A-Z_][A-Z0-9_]*", SyntaxKind::NakedIdentifier) + RegexParser::new(r#"[A-Z_][A-Z0-9_]*"#, SyntaxKind::NakedIdentifier) .anti_template(&anti_template) .to_matchable() }) .into(), ), ( - "FunctionContentsExpressionGrammar".into(), - one_of(vec![ - Ref::new("DatetimeUnitSegment").to_matchable(), - Ref::new("DatePartWeekSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("IGNORE").to_matchable(), - Ref::keyword("RESPECT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("NULLS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), + "DatatypeIdentifierSegment".into(), + SegmentGenerator::new(|_| { + MultiStringParser::new( + vec![ + "INT64", + "INT", + "SMALLINT", + "INTEGER", + "BIGINT", + "TINYINT", + "BYTEINT", + "FLOAT64", + "NUMERIC", + "DECIMAL", + "BIGNUMERIC", + "BIGDECIMAL", + "BOOL", + "BOOLEAN", + "STRING", + "BYTES", + "DATE", + "DATETIME", + "TIME", + "TIMESTAMP", + "GEOGRAPHY", + "INTERVAL", + "JSON", + "RANGE", + "ARRAY", + "STRUCT", + ] + .into_iter() + .map(String::from) + .collect::>(), + SyntaxKind::DataTypeIdentifier, + ) + .to_matchable() + }) + .into(), + ), + ]); + + bigquery_dialect.replace_grammar( + "FunctionContentsExpressionGrammar", + one_of(vec![ + Ref::new("DatetimeUnitSegment").to_matchable(), + Ref::new("DatePartWeekSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("HAVING").to_matchable(), one_of(vec![ - Ref::keyword("MIN").to_matchable(), - Ref::keyword("MAX").to_matchable(), + Ref::keyword("IGNORE").to_matchable(), + Ref::keyword("RESPECT").to_matchable(), ]) .to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("NULLS").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("NamedArgumentSegment").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "TrimParametersGrammar".into(), - Nothing::new().to_matchable().into(), - ), - ( - "ParameterNameSegment".into(), - one_of(vec![ - RegexParser::new("[A-Z_][A-Z0-9_]*", SyntaxKind::Parameter).to_matchable(), - RegexParser::new("`[^`]*`", SyntaxKind::Parameter).to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "DateTimeLiteralGrammar".into(), + .to_matchable(), Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("HAVING").to_matchable(), one_of(vec![ - Ref::keyword("DATE").to_matchable(), - Ref::keyword("DATETIME").to_matchable(), - Ref::keyword("TIME").to_matchable(), - Ref::keyword("TIMESTAMP").to_matchable(), + Ref::keyword("MIN").to_matchable(), + Ref::keyword("MAX").to_matchable(), ]) .to_matchable(), - TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::DateConstructorLiteral) - .to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "JoinLikeClauseGrammar".into(), - Sequence::new(vec![ - AnyNumberOf::new(vec![ - Ref::new("FromPivotExpressionSegment").to_matchable(), - Ref::new("FromUnpivotExpressionSegment").to_matchable(), + .to_matchable(), + Ref::new("NamedArgumentSegment").to_matchable(), + ]) + .to_matchable(), + ); + + bigquery_dialect.replace_grammar( + "FunctionContentsGrammar", + ansi_dialect.grammar("FunctionContentsGrammar").copy( + Some(vec![ + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("FORMAT").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("TimeZoneGrammar").optional().to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) - .config(|this| this.min_times = 1) .to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "NaturalJoinKeywordsGrammar".into(), - Nothing::new().to_matchable().into(), + ]), + None, + None, + None, + vec![], + false, ), - ( - "AccessorGrammar".into(), - AnyNumberOf::new(vec![ - Ref::new("ArrayAccessorSegment").to_matchable(), - Ref::new("SemiStructuredAccessorSegment").to_matchable(), + ); + + bigquery_dialect.replace_grammar("TrimParametersGrammar", Nothing::new().to_matchable()); + + bigquery_dialect.replace_grammar( + "ParameterNameSegment", + one_of(vec![ + RegexParser::new(r#"[A-Z_][A-Z0-9_]*"#, SyntaxKind::Parameter).to_matchable(), + RegexParser::new(r#"`[^`]*`"#, SyntaxKind::Parameter).to_matchable(), + ]) + .to_matchable(), + ); + + bigquery_dialect.replace_grammar( + "DateTimeLiteralGrammar", + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DATE").to_matchable(), + Ref::keyword("DATETIME").to_matchable(), + Ref::keyword("TIME").to_matchable(), + Ref::keyword("TIMESTAMP").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "MergeIntoLiteralGrammar".into(), - Sequence::new(vec![ - Ref::keyword("MERGE").to_matchable(), - Ref::keyword("INTO").optional().to_matchable(), + .to_matchable(), + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::DateConstructorLiteral) + .to_matchable(), + ]) + .to_matchable(), + ); + + bigquery_dialect.replace_grammar( + "JoinLikeClauseGrammar", + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Ref::new("FromPivotExpressionSegment").to_matchable(), + Ref::new("FromUnpivotExpressionSegment").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "PrimaryKeyGrammar".into(), - Nothing::new().to_matchable().into(), - ), - ( - "ForeignKeyGrammar".into(), - Nothing::new().to_matchable().into(), - ), - ]); + .config(|this| { + this.min_times(1); + }) + .to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ); - // Set Keywords - dialect.sets_mut("unreserved_keywords").clear(); - dialect.update_keywords_set_from_multiline_string( - "unreserved_keywords", - BIGQUERY_UNRESERVED_KEYWORDS, + bigquery_dialect.replace_grammar( + "ConditionalCrossJoinKeywordsGrammar", + Nothing::new().to_matchable(), ); - dialect.sets_mut("reserved_keywords").clear(); - dialect - .update_keywords_set_from_multiline_string("reserved_keywords", BIGQUERY_RESERVED_KEYWORDS); + bigquery_dialect.replace_grammar("NaturalJoinKeywordsGrammar", Nothing::new().to_matchable()); - // Add additional datetime units - // https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#extract - dialect.sets_mut("datetime_units").extend([ - "MICROSECOND", - "MILLISECOND", - "SECOND", - "MINUTE", - "HOUR", - "DAY", - "DAYOFWEEK", - "DAYOFYEAR", - "WEEK", - "ISOWEEK", - "MONTH", - "QUARTER", - "YEAR", - "ISOYEAR", - ]); + bigquery_dialect.replace_grammar( + "UnconditionalCrossJoinKeywordsGrammar", + Ref::keyword("CROSS").to_matchable(), + ); - // Add additional datetime units only recognised in some functions (e.g. - // extract) - dialect - .sets_mut("extended_datetime_units") - .extend(["DATE", "DATETIME", "TIME"]); + bigquery_dialect.replace_grammar( + "MergeIntoLiteralGrammar", + Sequence::new(vec![ + Ref::keyword("MERGE").to_matchable(), + Ref::keyword("INTO").optional().to_matchable(), + ]) + .to_matchable(), + ); - dialect.sets_mut("date_part_function_name").clear(); - dialect.sets_mut("date_part_function_name").extend([ - "DATE_DIFF", - "DATE_TRUNC", - "DATETIME_DIFF", - "DATETIME_TRUNC", - "EXTRACT", - "LAST_DAY", - "TIME_DIFF", - "TIME_TRUNC", - "TIMESTAMP_DIFF", - "TIMESTAMP_TRUNC", - ]); + bigquery_dialect.replace_grammar( + "AccessorGrammar", + AnyNumberOf::new(vec![ + Ref::new("ArrayAccessorSegment").to_matchable(), + Ref::new("SemiStructuredAccessorSegment").to_matchable(), + ]) + .to_matchable(), + ); - // Set value table functions - dialect.sets_mut("value_table_functions").extend(["UNNEST"]); + bigquery_dialect.replace_grammar( + "BracketedSetExpressionGrammar", + Bracketed::new(vec![Ref::new("SetExpressionSegment").to_matchable()]).to_matchable(), + ); - // Set angle bracket pairs - dialect.bracket_sets_mut("angle_bracket_pairs").extend([( - "angle", - "StartAngleBracketSegment", - "EndAngleBracketSegment", - false, - )]); + bigquery_dialect.replace_grammar( + "NotEnforcedGrammar", + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("ENFORCED").to_matchable(), + ]) + .to_matchable(), + ); - dialect.add([ - ( - "ProcedureParameterListSegment".into(), - NodeMatcher::new(SyntaxKind::ProcedureParameterList, |_| { - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ProcedureParameterGrammar").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "ProcedureStatements".into(), - NodeMatcher::new(SyntaxKind::ProcedureStatements, |_| { - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::new("StatementSegment").to_matchable(), - Ref::new("DelimiterGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.terminators = vec![Ref::keyword("END").to_matchable()]; - this.parse_mode = ParseMode::Greedy; - }) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "CreateProcedureStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateProcedureStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::keyword("PROCEDURE").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("ProcedureNameSegment").to_matchable(), - Ref::new("ProcedureParameterListSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OPTIONS").to_matchable(), - Ref::keyword("STRICT_MODE").to_matchable(), - StringParser::new("strict_mode", SyntaxKind::ProcedureOption) - .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").optional().to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("BEGIN").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("ProcedureStatements").to_matchable(), - MetaSegment::dedent().to_matchable(), - Ref::keyword("END").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), + bigquery_dialect.replace_grammar("ReferenceMatchGrammar", Nothing::new().to_matchable()); + + bigquery_dialect.replace_grammar( + "SelectClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("WHERE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("OVERLAPS").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), + Ref::keyword("FETCH").to_matchable(), + Ref::new("PipeOperatorSegment").to_matchable(), + ]) + .to_matchable(), + ); + + bigquery_dialect.replace_grammar( + "FromClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("WHERE").to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), + Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), + Ref::new("WithDataClauseSegment").to_matchable(), + Ref::keyword("FETCH").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), + Ref::new("PipeOperatorSegment").to_matchable(), + ]) + .to_matchable(), + ); + + bigquery_dialect.replace_grammar( + "WhereClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("LIMIT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::keyword("OVERLAPS").to_matchable(), + Ref::keyword("FETCH").to_matchable(), + Ref::new("PipeOperatorSegment").to_matchable(), + ]) + .to_matchable(), + ); + + bigquery_dialect.replace_grammar( + "GroupByClauseTerminatorGrammar", + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::keyword("FETCH").to_matchable(), + Ref::new("PipeOperatorSegment").to_matchable(), + Ref::keyword("ASC").to_matchable(), + Ref::keyword("DESC").to_matchable(), + ]) + .to_matchable(), + ); + + bigquery_dialect.replace_grammar( + "OrderByClauseTerminators", + one_of(vec![ + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::new("FrameClauseUnitGrammar").to_matchable(), + Ref::keyword("SEPARATOR").to_matchable(), + Ref::keyword("FETCH").to_matchable(), + Ref::new("PipeOperatorSegment").to_matchable(), + ]) + .to_matchable(), + ); + + bigquery_dialect.sets_mut("unreserved_keywords").clear(); + + bigquery_dialect.update_keywords_set_from_multiline_string( + "unreserved_keywords", + BIGQUERY_UNRESERVED_KEYWORDS, + ); + + bigquery_dialect.sets_mut("reserved_keywords").clear(); + + bigquery_dialect + .update_keywords_set_from_multiline_string("reserved_keywords", BIGQUERY_RESERVED_KEYWORDS); + + bigquery_dialect.sets_mut("datetime_units").extend([ + "MICROSECOND", + "MILLISECOND", + "SECOND", + "MINUTE", + "HOUR", + "DAY", + "DAYOFWEEK", + "DAYOFYEAR", + "WEEK", + "ISOWEEK", + "MONTH", + "QUARTER", + "YEAR", + "ISOYEAR", + ]); + + bigquery_dialect + .sets_mut("extended_datetime_units") + .extend(["DATE", "DATETIME", "TIME"]); + + bigquery_dialect.sets_mut("date_part_function_name").clear(); + + bigquery_dialect + .sets_mut("date_part_function_name") + .extend([ + "DATE_DIFF", + "DATE_TRUNC", + "DATETIME_DIFF", + "DATETIME_TRUNC", + "EXTRACT", + "LAST_DAY", + "TIME_DIFF", + "TIME_TRUNC", + "TIMESTAMP_DIFF", + "TIMESTAMP_TRUNC", + ]); + + bigquery_dialect + .sets_mut("value_table_functions") + .extend(["UNNEST"]); + + bigquery_dialect.update_bracket_sets( + "angle_bracket_pairs", + vec![( + "angle", + "StartAngleBracketSegment", + "EndAngleBracketSegment", + false, + )], + ); + + bigquery_dialect.add([ ( - "CallStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CallStatement, |_| { + "ArrayTypeSegment".into(), + NodeMatcher::new(SyntaxKind::DataType, |_dialect| { Sequence::new(vec![ - Ref::keyword("CALL").to_matchable(), - Ref::new("ProcedureNameSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "ReturnStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ReturnStatement, |_| { - Sequence::new(vec![Ref::keyword("RETURN").to_matchable()]).to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "BreakStatementSegment".into(), - NodeMatcher::new(SyntaxKind::BreakStatement, |_| { - Sequence::new(vec![Ref::keyword("BREAK").to_matchable()]).to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "LeaveStatementSegment".into(), - NodeMatcher::new(SyntaxKind::LeaveStatement, |_| { - Sequence::new(vec![Ref::keyword("LEAVE").to_matchable()]).to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "ContinueStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ContinueStatement, |_| { - one_of(vec![ - Ref::keyword("CONTINUE").to_matchable(), - Ref::keyword("ITERATE").to_matchable(), + Ref::keyword("ARRAY").to_matchable(), + Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .config(|this| { + this.optional(); + this.bracket_type("angle"); + this.bracket_pairs_set = "angle_bracket_pairs"; + }) + .to_matchable(), ]) .to_matchable() }) @@ -524,47 +680,34 @@ pub fn dialect() -> Dialect { .into(), ), ( - "RaiseStatementSegment".into(), - NodeMatcher::new(SyntaxKind::RaiseStatement, |_| { + "ForSystemTimeAsOfSegment".into(), + NodeMatcher::new(SyntaxKind::ForSystemTimeAsOfSegment, |_dialect| { Sequence::new(vec![ - Ref::keyword("RAISE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Ref::keyword("MESSAGE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("ExpressionSegment").optional().to_matchable(), + Ref::keyword("FOR").to_matchable(), + one_of(vec![ + Ref::keyword("SYSTEM_TIME").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SYSTEM").to_matchable(), + Ref::keyword("TIME").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::keyword("OF").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - dialect.replace_grammar( - "ArrayTypeSegment", - Sequence::new(vec![ - Ref::keyword("ARRAY").to_matchable(), - Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) - .config(|this| { - this.bracket_type = "angle"; - this.bracket_pairs_set = "angle_bracket_pairs"; - }) - .to_matchable(), - ]) - .to_matchable(), - ); - - dialect.add([ ( "QualifyClauseSegment".into(), - NodeMatcher::new(SyntaxKind::QualifyClause, |_| { + NodeMatcher::new(SyntaxKind::QualifyClause, |_dialect| { Sequence::new(vec![ Ref::keyword("QUALIFY").to_matchable(), - MetaSegment::indent().to_matchable(), + MetaSegment::implicit_indent().to_matchable(), optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) .to_matchable(), MetaSegment::dedent().to_matchable(), @@ -576,7 +719,7 @@ pub fn dialect() -> Dialect { ), ( "SetOperatorSegment".into(), - NodeMatcher::new(SyntaxKind::SetOperator, |_| { + NodeMatcher::new(SyntaxKind::SetOperator, |_dialect| { one_of(vec![ Sequence::new(vec![ Ref::keyword("UNION").to_matchable(), @@ -597,216 +740,324 @@ pub fn dialect() -> Dialect { Ref::keyword("DISTINCT").to_matchable(), ]) .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("INNER").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("FULL").to_matchable(), + Ref::keyword("LEFT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("OUTER").optional().to_matchable(), + ]) + .to_matchable(), + Ref::keyword("OUTER").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("UNION").to_matchable(), + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("DISTINCT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INTERSECT").to_matchable(), + Ref::keyword("DISTINCT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXCEPT").to_matchable(), + Ref::keyword("DISTINCT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("BY").to_matchable(), + Ref::keyword("NAME").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STRICT").optional().to_matchable(), + Ref::keyword("CORRESPONDING").to_matchable(), + Sequence::new(vec![ + Ref::keyword("BY").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - dialect.replace_grammar("SetExpressionSegment", { - Sequence::new(vec![ - one_of(vec![ - Ref::new("NonSetSelectableGrammar").to_matchable(), - Bracketed::new(vec![Ref::new("SetExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::new("SetOperatorSegment").to_matchable(), - one_of(vec![ - Ref::new("NonSetSelectableGrammar").to_matchable(), - Bracketed::new(vec![Ref::new("SetExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.min_times = 1) - .to_matchable(), - Ref::new("OrderByClauseSegment").optional().to_matchable(), - Ref::new("LimitClauseSegment").optional().to_matchable(), - Ref::new("NamedWindowSegment").optional().to_matchable(), - ]) - .to_matchable() - }); - - dialect.replace_grammar("SelectStatementSegment", { - ansi::select_statement().copy( - Some(vec![ - Ref::new("QualifyClauseSegment").optional().to_matchable(), - ]), - None, - Some(Ref::new("OrderByClauseSegment").optional().to_matchable()), - None, - Vec::new(), - false, - ) - }); - - dialect.replace_grammar( - "UnorderedSelectStatementSegment", - ansi::get_unordered_select_statement_segment_grammar().copy( - Some(vec![ - Ref::new("QualifyClauseSegment").optional().to_matchable(), - ]), - None, - Some(Ref::new("OverlapsClauseSegment").optional().to_matchable()), - None, - Vec::new(), - false, - ), - ); - - dialect.add([( - "MultiStatementSegment".into(), - NodeMatcher::new(SyntaxKind::MultiStatementSegment, |_| { - one_of(vec![ - Ref::new("ForInStatementSegment").to_matchable(), - Ref::new("RepeatStatementSegment").to_matchable(), - Ref::new("WhileStatementSegment").to_matchable(), - Ref::new("LoopStatementSegment").to_matchable(), - Ref::new("IfStatementSegment").to_matchable(), - Ref::new("CreateProcedureStatementSegment").to_matchable(), - ]) + ( + "SelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("SelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("QualifyClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("OrderByClauseSegment").optional().to_matchable()), + None, + vec![Ref::new("PipeOperatorSegment").to_matchable()], + false, + ) + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - dialect.replace_grammar( - "FileSegment", - Sequence::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::new("MultiStatementSegment").to_matchable(), - Ref::new("StatementSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("DelimiterGrammar").to_matchable(), + .into(), + ), + ( + "UnorderedSelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("UnorderedSelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("QualifyClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("OverlapsClauseSegment").optional().to_matchable()), + None, + vec![Ref::new("PipeOperatorSegment").to_matchable()], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "MultiStatementSegment".into(), + NodeMatcher::new(SyntaxKind::MultiStatementSegment, |_dialect| { one_of(vec![ - Ref::new("MultiStatementSegment").to_matchable(), - Ref::new("StatementSegment").to_matchable(), + Ref::new("ForInStatementSegment").to_matchable(), + Ref::new("RepeatStatementSegment").to_matchable(), + Ref::new("WhileStatementSegment").to_matchable(), + Ref::new("LoopStatementSegment").to_matchable(), + Ref::new("IfStatementSegment").to_matchable(), + Ref::new("CreateProcedureStatementSegment").to_matchable(), + Ref::new("BeginStatementSegment").to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("DelimiterGrammar").optional().to_matchable(), - ]) - .to_matchable(), - ); - - dialect.replace_grammar( - "StatementSegment", - ansi::statement_segment().copy( - Some(vec![ - Ref::new("DeclareStatementSegment").to_matchable(), - Ref::new("SetStatementSegment").to_matchable(), - Ref::new("ExportStatementSegment").to_matchable(), - Ref::new("CreateExternalTableStatementSegment").to_matchable(), - Ref::new("AssertStatementSegment").to_matchable(), - Ref::new("CallStatementSegment").to_matchable(), - Ref::new("ReturnStatementSegment").to_matchable(), - Ref::new("BreakStatementSegment").to_matchable(), - Ref::new("LeaveStatementSegment").to_matchable(), - Ref::new("ContinueStatementSegment").to_matchable(), - Ref::new("RaiseStatementSegment").to_matchable(), - Ref::new("AlterViewStatementSegment").to_matchable(), - Ref::new("CreateMaterializedViewStatementSegment").to_matchable(), - Ref::new("AlterMaterializedViewStatementSegment").to_matchable(), - Ref::new("DropMaterializedViewStatementSegment").to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, + .to_matchable() + }) + .to_matchable() + .into(), ), - ); - - dialect.add([( - "AssertStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AssertStatement, |_| { - Sequence::new(vec![ - Ref::keyword("ASSERT").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + ( + "FileSegment".into(), + NodeMatcher::new(SyntaxKind::File, |_dialect| { Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + AnyNumberOf::new(vec![Ref::new("DelimiterGrammar").to_matchable()]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("MultiStatementSegment").to_matchable(), + Ref::new("StatementSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("DelimiterGrammar").to_matchable(), + one_of(vec![ + Ref::new("MultiStatementSegment").to_matchable(), + Ref::new("StatementSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![Ref::new("DelimiterGrammar").to_matchable()]) + .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - dialect.add([( - "ForInStatementsSegment".into(), - NodeMatcher::new(SyntaxKind::ForInStatements, |_| { - AnyNumberOf::new(vec![ + .into(), + ), + ( + "StatementSegment".into(), + NodeMatcher::new(SyntaxKind::Statement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("StatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("DeclareStatementSegment").to_matchable(), + Ref::new("SetStatementSegment").to_matchable(), + Ref::new("ExportStatementSegment").to_matchable(), + Ref::new("LoadDataStatementSegment").to_matchable(), + Ref::new("CreateExternalTableStatementSegment").to_matchable(), + Ref::new("CreateSnapshotTableStatementSegment").to_matchable(), + Ref::new("ExecuteImmediateSegment").to_matchable(), + Ref::new("AssertStatementSegment").to_matchable(), + Ref::new("CallStatementSegment").to_matchable(), + Ref::new("ReturnStatementSegment").to_matchable(), + Ref::new("BreakStatementSegment").to_matchable(), + Ref::new("LeaveStatementSegment").to_matchable(), + Ref::new("ContinueStatementSegment").to_matchable(), + Ref::new("RaiseStatementSegment").to_matchable(), + Ref::new("AlterViewStatementSegment").to_matchable(), + Ref::new("AlterSchemaStatementSegment").to_matchable(), + Ref::new("CreateMaterializedViewStatementSegment").to_matchable(), + Ref::new("CreateMaterializedViewAsReplicaOfStatementSegment") + .to_matchable(), + Ref::new("AlterMaterializedViewStatementSegment").to_matchable(), + Ref::new("DropMaterializedViewStatementSegment").to_matchable(), + Ref::new("DropProcedureStatementSegment").to_matchable(), + Ref::new("UndropSchemaStatementSegment").to_matchable(), + Ref::new("AlterOrganizationStatementSegment").to_matchable(), + Ref::new("AlterProjectStatementSegment").to_matchable(), + Ref::new("CreateSearchIndexStatementSegment").to_matchable(), + Ref::new("DropSearchIndexStatementSegment").to_matchable(), + Ref::new("CreateVectorIndexStatementSegment").to_matchable(), + Ref::new("DropVectorIndexStatementSegment").to_matchable(), + Ref::new("CreateRowAccessPolicyStatementSegment").to_matchable(), + Ref::new("DropRowAccessPolicyStatementSegment").to_matchable(), + Ref::new("AlterBiCapacityStatementSegment").to_matchable(), + Ref::new("CreateCapacityStatementSegment").to_matchable(), + Ref::new("AlterCapacityStatementSegment").to_matchable(), + Ref::new("DropCapacityStatementSegment").to_matchable(), + Ref::new("CreateReservationStatementSegment").to_matchable(), + Ref::new("AlterReservationStatementSegment").to_matchable(), + Ref::new("DropReservationStatementSegment").to_matchable(), + Ref::new("CreateAssignmentStatementSegment").to_matchable(), + Ref::new("DropAssignmentStatementSegment").to_matchable(), + Ref::new("DropTableFunctionStatementSegment").to_matchable(), + Ref::new("CreateTableFunctionStatementSegment").to_matchable(), + Ref::new("PipeStatementSegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "AssertStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AssertStatement, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Ref::new("StatementSegment").to_matchable(), - Ref::new("MultiStatementSegment").to_matchable(), + Ref::keyword("ASSERT").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("DelimiterGrammar").to_matchable(), ]) - .to_matchable(), - ]) - .config(|this| { - this.terminators = vec![ + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ForInStatementsSegment".into(), + NodeMatcher::new(SyntaxKind::ForInStatements, |_dialect| { + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::keyword("END").to_matchable(), - Ref::keyword("FOR").to_matchable(), + one_of(vec![ + Ref::new("StatementSegment").to_matchable(), + Ref::new("MultiStatementSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("DelimiterGrammar").to_matchable(), ]) .to_matchable(), - ]; - this.parse_mode = ParseMode::Greedy; + ]) + .config(|this| { + this.reset_terminators = true; + this.terminators = vec![ + Sequence::new(vec![ + Ref::keyword("END").to_matchable(), + Ref::keyword("FOR").to_matchable(), + ]) + .to_matchable(), + ]; + }) + .to_matchable() }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - dialect.add([( - "ForInStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ForInStatement, |_| { - Sequence::new(vec![ - Ref::keyword("FOR").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("IN").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), - MetaSegment::dedent().to_matchable(), - Ref::keyword("DO").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("ForInStatementsSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - Ref::keyword("END").to_matchable(), - Ref::keyword("FOR").to_matchable(), - ]) + .into(), + ), + ( + "ForInStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ForInStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("FOR").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("IN").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::keyword("DO").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("ForInStatementsSegment").to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::keyword("END").to_matchable(), + Ref::keyword("FOR").to_matchable(), + ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - dialect.add([ + .into(), + ), ( "RepeatStatementsSegment".into(), - NodeMatcher::new(SyntaxKind::RepeatStatements, |_| { + NodeMatcher::new(SyntaxKind::RepeatStatements, |_dialect| { AnyNumberOf::new(vec![ Sequence::new(vec![ one_of(vec![ @@ -819,8 +1070,8 @@ pub fn dialect() -> Dialect { .to_matchable(), ]) .config(|this| { + this.reset_terminators = true; this.terminators = vec![Ref::keyword("UNTIL").to_matchable()]; - this.parse_mode = ParseMode::Greedy; }) .to_matchable() }) @@ -829,7 +1080,7 @@ pub fn dialect() -> Dialect { ), ( "RepeatStatementSegment".into(), - NodeMatcher::new(SyntaxKind::RepeatStatement, |_| { + NodeMatcher::new(SyntaxKind::RepeatStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("REPEAT").to_matchable(), MetaSegment::indent().to_matchable(), @@ -847,7 +1098,7 @@ pub fn dialect() -> Dialect { ), ( "IfStatementsSegment".into(), - NodeMatcher::new(SyntaxKind::IfStatements, |_| { + NodeMatcher::new(SyntaxKind::IfStatements, |_dialect| { AnyNumberOf::new(vec![ Sequence::new(vec![ one_of(vec![ @@ -860,6 +1111,7 @@ pub fn dialect() -> Dialect { .to_matchable(), ]) .config(|this| { + this.reset_terminators = true; this.terminators = vec![ Ref::keyword("ELSE").to_matchable(), Ref::keyword("ELSEIF").to_matchable(), @@ -869,7 +1121,6 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]; - this.parse_mode = ParseMode::Greedy; }) .to_matchable() }) @@ -878,7 +1129,7 @@ pub fn dialect() -> Dialect { ), ( "IfStatementSegment".into(), - NodeMatcher::new(SyntaxKind::IfStatement, |_| { + NodeMatcher::new(SyntaxKind::IfStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("IF").to_matchable(), Ref::new("ExpressionSegment").to_matchable(), @@ -904,7 +1155,9 @@ pub fn dialect() -> Dialect { Ref::new("IfStatementsSegment").to_matchable(), MetaSegment::dedent().to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Ref::keyword("END").to_matchable(), Ref::keyword("IF").to_matchable(), @@ -916,7 +1169,7 @@ pub fn dialect() -> Dialect { ), ( "LoopStatementsSegment".into(), - NodeMatcher::new(SyntaxKind::LoopStatements, |_| { + NodeMatcher::new(SyntaxKind::LoopStatements, |_dialect| { AnyNumberOf::new(vec![ Sequence::new(vec![ one_of(vec![ @@ -929,6 +1182,7 @@ pub fn dialect() -> Dialect { .to_matchable(), ]) .config(|this| { + this.reset_terminators = true; this.terminators = vec![ Sequence::new(vec![ Ref::keyword("END").to_matchable(), @@ -936,7 +1190,6 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]; - this.parse_mode = ParseMode::Greedy; }) .to_matchable() }) @@ -945,7 +1198,7 @@ pub fn dialect() -> Dialect { ), ( "LoopStatementSegment".into(), - NodeMatcher::new(SyntaxKind::LoopStatement, |_| { + NodeMatcher::new(SyntaxKind::LoopStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("LOOP").to_matchable(), MetaSegment::indent().to_matchable(), @@ -961,7 +1214,7 @@ pub fn dialect() -> Dialect { ), ( "WhileStatementsSegment".into(), - NodeMatcher::new(SyntaxKind::WhileStatements, |_| { + NodeMatcher::new(SyntaxKind::WhileStatements, |_dialect| { AnyNumberOf::new(vec![ Sequence::new(vec![ Ref::new("StatementSegment").to_matchable(), @@ -970,6 +1223,7 @@ pub fn dialect() -> Dialect { .to_matchable(), ]) .config(|this| { + this.reset_terminators = true; this.terminators = vec![ Sequence::new(vec![ Ref::keyword("END").to_matchable(), @@ -977,7 +1231,6 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]; - this.parse_mode = ParseMode::Greedy; }) .to_matchable() }) @@ -986,7 +1239,7 @@ pub fn dialect() -> Dialect { ), ( "WhileStatementSegment".into(), - NodeMatcher::new(SyntaxKind::WhileStatement, |_| { + NodeMatcher::new(SyntaxKind::WhileStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("WHILE").to_matchable(), Ref::new("ExpressionSegment").to_matchable(), @@ -1002,102 +1255,29 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - dialect.replace_grammar( - "SelectClauseModifierSegment", - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DISTINCT").to_matchable(), - Ref::keyword("ALL").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - one_of(vec![ - Ref::keyword("STRUCT").to_matchable(), - Ref::keyword("VALUE").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - dialect.replace_grammar( - "IntervalExpressionSegment", - Sequence::new(vec![ - Ref::keyword("INTERVAL").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("DatetimeUnitSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("DatetimeUnitSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("DatetimeUnitSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - dialect.add([ - ( - "DateTimeFunctionContentsSegment".into(), - NodeMatcher::new(SyntaxKind::FunctionContents, |_| { - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("DatetimeUnitSegment").to_matchable(), - Ref::new("DatePartWeekSegment").to_matchable(), - Ref::new("FunctionContentsGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), ( - "ExtractFunctionContentsSegment".into(), - NodeMatcher::new(SyntaxKind::FunctionContents, |_| { - Bracketed::new(vec![ + "SelectClauseModifierSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClauseModifier, |_dialect| { + Sequence::new(vec![ one_of(vec![ - Ref::new("DatetimeUnitSegment").to_matchable(), - Ref::new("DatePartWeekSegment").to_matchable(), - Ref::new("ExtendedDatetimeUnitSegment").to_matchable(), + Ref::keyword("DISTINCT").to_matchable(), + Ref::keyword("ALL").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "NormalizeFunctionContentsSegment".into(), - NodeMatcher::new(SyntaxKind::FunctionContents, |_| { - Bracketed::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), Sequence::new(vec![ - Ref::new("CommaSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), one_of(vec![ - Ref::keyword("NFC").to_matchable(), - Ref::keyword("NFKC").to_matchable(), - Ref::keyword("NFD").to_matchable(), - Ref::keyword("NFKD").to_matchable(), + Ref::keyword("STRUCT").to_matchable(), + Ref::keyword("VALUE").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -1106,35 +1286,18 @@ pub fn dialect() -> Dialect { .into(), ), ( - "ExtractFunctionNameSegment".into(), - NodeMatcher::new(SyntaxKind::FunctionName, |_| { - StringParser::new("EXTRACT", SyntaxKind::FunctionNameIdentifier).to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "ArrayFunctionNameSegment".into(), - NodeMatcher::new(SyntaxKind::FunctionName, |_| { - StringParser::new("ARRAY", SyntaxKind::FunctionNameIdentifier).to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "DatePartWeekSegment".into(), - NodeMatcher::new(SyntaxKind::DatePartWeek, |_| { + "IntervalExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::IntervalExpression, |_dialect| { Sequence::new(vec![ - Ref::keyword("WEEK").to_matchable(), - Bracketed::new(vec![ - one_of(vec![ - Ref::keyword("SUNDAY").to_matchable(), - Ref::keyword("MONDAY").to_matchable(), - Ref::keyword("TUESDAY").to_matchable(), - Ref::keyword("WEDNESDAY").to_matchable(), - Ref::keyword("THURSDAY").to_matchable(), - Ref::keyword("FRIDAY").to_matchable(), - Ref::keyword("SATURDAY").to_matchable(), + Ref::keyword("INTERVAL").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("DatetimeUnitSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("DatetimeUnitSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("DatetimeUnitSegment").to_matchable(), ]) .to_matchable(), ]) @@ -1145,188 +1308,182 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - ( - "NormalizeFunctionNameSegment".into(), - NodeMatcher::new(SyntaxKind::FunctionName, |_| { - one_of(vec![ - StringParser::new("NORMALIZE", SyntaxKind::FunctionNameIdentifier) - .to_matchable(), - StringParser::new("NORMALIZE_AND_CASEFOLD", SyntaxKind::FunctionNameIdentifier) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), ]); - dialect.replace_grammar( - "FunctionNameSegment", - Sequence::new(vec![ - // AnyNumberOf to handle project names, schemas, or the SAFE keyword - AnyNumberOf::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("SAFE").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - Ref::new("DotSegment").to_matchable(), - ]) - .terminators(vec![Ref::new("BracketedSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - // Base function name - one_of(vec![ - Ref::new("FunctionNameIdentifierSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), - ]) - .config(|this| this.terminators = vec![Ref::new("BracketedSegment").to_matchable()]) - .to_matchable(), + bigquery_dialect.replace_grammar( + "QuotedIdentifierSegment", + TypedParser::new(SyntaxKind::BackQuote, SyntaxKind::QuotedIdentifier).to_matchable(), + ); + + bigquery_dialect.replace_grammar( + "NumericLiteralSegment", + one_of(vec![ + TypedParser::new(SyntaxKind::NumericLiteral, SyntaxKind::NumericLiteral).to_matchable(), + Ref::new("ParameterizedSegment").to_matchable(), + ]) + .to_matchable(), + ); + + bigquery_dialect.replace_grammar( + "QuotedLiteralSegment", + one_of(vec![ + Ref::new("SingleQuotedLiteralSegment").to_matchable(), + Ref::new("DoubleQuotedLiteralSegment").to_matchable(), ]) - .allow_gaps(true) .to_matchable(), ); - dialect.replace_grammar( - "FunctionSegment", + bigquery_dialect.replace_grammar( + "LiteralGrammar", + ansi_dialect.grammar("LiteralGrammar").copy( + Some(vec![ + Ref::new("ParameterizedSegment").to_matchable(), + Ref::new("SystemVariableSegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ), + ); + + bigquery_dialect.replace_grammar( + "PostTableExpressionGrammar", Sequence::new(vec![ - one_of(vec![ - Sequence::new(vec![ - // BigQuery EXTRACT allows optional TimeZone - Ref::new("ExtractFunctionNameSegment").to_matchable(), - Ref::new("ExtractFunctionContentsSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - // BigQuery NORMALIZE allows optional normalization_mode - Ref::new("NormalizeFunctionNameSegment").to_matchable(), - Ref::new("NormalizeFunctionContentsSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - // Treat functions which take date parts separately - Ref::new("DatePartFunctionNameSegment") - .exclude(Ref::new("ExtractFunctionNameSegment")) - .to_matchable(), - Ref::new("DateTimeFunctionContentsSegment").to_matchable(), - ]) + Ref::new("ForSystemTimeAsOfSegment") + .optional() .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), Sequence::new(vec![ - Sequence::new(vec![ - Ref::new("FunctionNameSegment") - .exclude(one_of(vec![ - Ref::new("DatePartFunctionNameSegment").to_matchable(), - Ref::new("NormalizeFunctionNameSegment").to_matchable(), - Ref::new("ValuesClauseSegment").to_matchable(), - ])) - .to_matchable(), - Ref::new("FunctionContentsSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("ArrayAccessorSegment").optional().to_matchable(), - Ref::new("SemiStructuredAccessorSegment") - .optional() - .to_matchable(), - Ref::new("PostFunctionGrammar").optional().to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .config(|this| this.allow_gaps = false) .to_matchable(), ); - dialect.replace_grammar( - "FunctionDefinitionGrammar", - Sequence::new(vec![ - AnyNumberOf::new(vec![ + bigquery_dialect.replace_grammar( + "FunctionNameIdentifierSegment", + one_of(vec![ + RegexParser::new(r#"[A-Z_][A-Z0-9_]*"#, SyntaxKind::FunctionNameIdentifier) + .anti_template("^(STRUCT|ARRAY)$") + .to_matchable(), + RegexParser::new(r#"`[^`]*`"#, SyntaxKind::FunctionNameIdentifier).to_matchable(), + ]) + .to_matchable(), + ); + + bigquery_dialect.add([ + ( + "ExtractFunctionNameSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionName, |_dialect| { + StringParser::new("EXTRACT", SyntaxKind::FunctionNameIdentifier).to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ArrayFunctionNameSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionName, |_dialect| { + StringParser::new("ARRAY", SyntaxKind::FunctionNameIdentifier).to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DatePartWeekSegment".into(), + NodeMatcher::new(SyntaxKind::DatePartWeek, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DETERMINISTIC").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("DETERMINISTIC").to_matchable(), + Ref::keyword("WEEK").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::keyword("SUNDAY").to_matchable(), + Ref::keyword("MONDAY").to_matchable(), + Ref::keyword("TUESDAY").to_matchable(), + Ref::keyword("WEDNESDAY").to_matchable(), + Ref::keyword("THURSDAY").to_matchable(), + Ref::keyword("FRIDAY").to_matchable(), + Ref::keyword("SATURDAY").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LANGUAGE").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OPTIONS").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Anything::new().to_matchable(), - ]) - .to_matchable(), - Ref::new("CommaSegment").to_matchable(), - ]) - .to_matchable(), - ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "NormalizeFunctionNameSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionName, |_dialect| { + one_of(vec![ + StringParser::new("NORMALIZE", SyntaxKind::FunctionNameIdentifier) + .to_matchable(), + StringParser::new("NORMALIZE_AND_CASEFOLD", SyntaxKind::FunctionNameIdentifier) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FunctionNameSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionName, |_dialect| { Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - one_of(vec![ - Ref::new("DoubleQuotedUDFBody").to_matchable(), - Ref::new("SingleQuotedUDFBody").to_matchable(), - Bracketed::new(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ one_of(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::new("SelectStatementSegment").to_matchable(), + Ref::keyword("SAFE").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), + Ref::new("DotSegment").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.terminators = vec![Ref::new("BracketedSegment").to_matchable()]; + }) + .to_matchable(), + one_of(vec![ + Ref::new("FunctionNameIdentifierSegment").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), + ]) + .config(|this| { + this.terminators = vec![Ref::new("BracketedSegment").to_matchable()]; + }) .to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - dialect.replace_grammar( - "WildcardExpressionSegment", - ansi::wildcard_expression_segment().copy( - Some(vec![ - Ref::new("ExceptClauseSegment").optional().to_matchable(), - Ref::new("ReplaceClauseSegment").optional().to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, + .to_matchable() + }) + .to_matchable() + .into(), ), - ); - - dialect.add([ ( - "ExceptClauseSegment".into(), - NodeMatcher::new(SyntaxKind::SelectExceptClause, |_| { + "DateTimeFunctionContentsSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionContents, |_dialect| { Sequence::new(vec![ - Ref::keyword("EXCEPT").to_matchable(), Bracketed::new(vec![ - Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .to_matchable(), + Delimited::new(vec![ + Ref::new("DatetimeUnitSegment").to_matchable(), + Ref::new("DatePartWeekSegment").to_matchable(), + Ref::new("FunctionContentsGrammar").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -1336,13 +1493,18 @@ pub fn dialect() -> Dialect { .into(), ), ( - "ReplaceClauseSegment".into(), - NodeMatcher::new(SyntaxKind::SelectReplaceClause, |_| { + "ExtractFunctionContentsSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionContents, |_dialect| { Sequence::new(vec![ - Ref::keyword("REPLACE").to_matchable(), Bracketed::new(vec![ - Delimited::new(vec![Ref::new("SelectClauseElementSegment").to_matchable()]) - .to_matchable(), + one_of(vec![ + Ref::new("DatetimeUnitSegment").to_matchable(), + Ref::new("DatePartWeekSegment").to_matchable(), + Ref::new("ExtendedDatetimeUnitSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), ]) @@ -1351,289 +1513,287 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - dialect.replace_grammar("DatatypeSegment", { - one_of(vec![ - Sequence::new(vec![ - Ref::new("DatatypeIdentifierSegment").to_matchable(), - Ref::new("BracketedArguments").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ANY").to_matchable(), - Ref::keyword("TYPE").to_matchable(), - ]) - .to_matchable(), - Ref::new("ArrayTypeSegment").to_matchable(), - Ref::new("StructTypeSegment").to_matchable(), - ]) - .to_matchable() - }); - - dialect.replace_grammar( - "StructTypeSegment", - Sequence::new(vec![ - Ref::keyword("STRUCT").to_matchable(), - Ref::new("StructTypeSchemaSegment") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ); - - dialect.add([( - "StructTypeSchemaSegment".into(), - NodeMatcher::new(SyntaxKind::StructTypeSchema, |_| { - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::new("DatatypeSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), + ( + "NormalizeFunctionContentsSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionContents, |_dialect| { + Sequence::new(vec![ + Bracketed::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("CommaSegment").to_matchable(), + one_of(vec![ + Ref::keyword("NFC").to_matchable(), + Ref::keyword("NFKC").to_matchable(), + Ref::keyword("NFD").to_matchable(), + Ref::keyword("NFKD").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - AnyNumberOf::new(vec![Ref::new("ColumnConstraintSegment").to_matchable()]) - .to_matchable(), - Ref::new("OptionsSegment").optional().to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - ]) - .config(|this| { - this.bracket_type = "angle"; - this.bracket_pairs_set = "angle_bracket_pairs"; + .to_matchable() }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - dialect.add([( - "ArrayFunctionContentsSegment".into(), - NodeMatcher::new(SyntaxKind::FunctionContents, |_| { - Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable() - }) - .to_matchable() - .into(), - )]); - - dialect.replace_grammar( - "ArrayExpressionSegment", - Sequence::new(vec![ - Ref::new("ArrayFunctionNameSegment").to_matchable(), - Ref::new("ArrayFunctionContentsSegment").to_matchable(), - ]) - .to_matchable(), - ); - - dialect.add([ + .into(), + ), ( - "TupleSegment".into(), - NodeMatcher::new(SyntaxKind::Tuple, |_| { - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("BaseExpressionElementGrammar").to_matchable(), + "FunctionSegment".into(), + NodeMatcher::new(SyntaxKind::Function, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::new("ExtractFunctionNameSegment").to_matchable(), + Ref::new("ExtractFunctionContentsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("NormalizeFunctionNameSegment").to_matchable(), + Ref::new("NormalizeFunctionContentsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("DatePartFunctionNameSegment") + .exclude(Ref::new("ExtractFunctionNameSegment")) + .to_matchable(), + Ref::new("DateTimeFunctionContentsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::new("FunctionNameSegment") + .exclude(one_of(vec![ + Ref::new("DatePartFunctionNameSegment").to_matchable(), + Ref::new("NormalizeFunctionNameSegment").to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + ])) + .to_matchable(), + Ref::new("FunctionContentsSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ArrayAccessorSegment").optional().to_matchable(), + Ref::new("SemiStructuredAccessorSegment") + .optional() + .to_matchable(), + Ref::new("PostFunctionGrammar").optional().to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.disallow_gaps(); + }) .to_matchable() }) .to_matchable() .into(), ), ( - "NamedArgumentSegment".into(), - NodeMatcher::new(SyntaxKind::NamedArgument, |_| { + "FunctionDefinitionGrammar".into(), + NodeMatcher::new(SyntaxKind::FunctionDefinition, |_dialect| { Sequence::new(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("RightArrowSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DETERMINISTIC").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("DETERMINISTIC").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LANGUAGE").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("OPTIONS").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Anything::new().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Ref::new("DoubleQuotedUDFBody").to_matchable(), + Ref::new("SingleQuotedUDFBody").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("SelectStatementSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("OptionsSegment").optional().to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - dialect.add([( - "SemiStructuredAccessorSegment".into(), - NodeMatcher::new(SyntaxKind::SemiStructuredExpression, |_| { - Sequence::new(vec![ - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::new("DotSegment").to_matchable(), - one_of(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("StarSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.allow_gaps = true) - .to_matchable(), - Ref::new("ArrayAccessorSegment").optional().to_matchable(), - ]) - .config(|this| { - this.allow_gaps = true; - this.min_times = 1; - }) - .to_matchable(), - ]) - .config(|this| this.allow_gaps = true) + ( + "WildcardExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::WildcardExpression, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("WildcardExpressionSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("ExceptClauseSegment").optional().to_matchable(), + Ref::new("ReplaceClauseSegment").optional().to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - dialect.replace_grammar( - "ColumnReferenceSegment", - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Sequence::new(vec![ - Ref::new("ObjectReferenceDelimiterGrammar").to_matchable(), - Delimited::new(vec![Ref::new("SingleIdentifierFullGrammar").to_matchable()]) - .config(|this| { - this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); - this.terminators = vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::keyword("USING").to_matchable(), - Ref::new("CommaSegment").to_matchable(), - Ref::new("CastOperatorSegment").to_matchable(), - Ref::new("StartSquareBracketSegment").to_matchable(), - Ref::new("StartBracketSegment").to_matchable(), - Ref::new("BinaryOperatorGrammar").to_matchable(), - Ref::new("ColonSegment").to_matchable(), - Ref::new("DelimiterGrammar").to_matchable(), - Ref::new("BracketedSegment").to_matchable(), - ]; - this.allow_gaps = false; - }) - .to_matchable(), - ]) - .allow_gaps(false) - .config(|this| this.optional()) - .to_matchable(), - ]) - .allow_gaps(false) - .to_matchable(), - ); - - dialect.replace_grammar("TableReferenceSegment", { - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::new("DashSegment").to_matchable(), - Ref::new("NakedIdentifierPart").to_matchable(), + .into(), + ), + ( + "ExceptClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SelectExceptClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("EXCEPT").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) + .to_matchable(), ]) - .config(|this| this.allow_gaps = false) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .config(|this| this.allow_gaps = false) - .to_matchable(), - ]) - .config(|this| { - this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); - this.terminators = vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::keyword("USING").to_matchable(), - Ref::new("CommaSegment").to_matchable(), - Ref::new("CastOperatorSegment").to_matchable(), - Ref::new("StartSquareBracketSegment").to_matchable(), - Ref::new("StartBracketSegment").to_matchable(), - Ref::new("ColonSegment").to_matchable(), - Ref::new("DelimiterGrammar").to_matchable(), - Ref::new("JoinLikeClauseGrammar").to_matchable(), - Ref::new("BracketedSegment").to_matchable(), - ]; - this.allow_gaps = false; - }) - .to_matchable() - }); - - dialect.add([ + .to_matchable() + }) + .to_matchable() + .into(), + ), ( - "DeclareStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DeclareSegment, |_| { + "TransactionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::TransactionStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("DECLARE").to_matchable(), - Delimited::new(vec![Ref::new("SingleIdentifierFullGrammar").to_matchable()]) - .to_matchable(), one_of(vec![ - Ref::new("DefaultDeclareOptionsGrammar").to_matchable(), - Sequence::new(vec![ - Ref::new("DatatypeSegment").to_matchable(), - Ref::new("DefaultDeclareOptionsGrammar") - .optional() - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("BEGIN").to_matchable(), + Ref::keyword("COMMIT").to_matchable(), + Ref::keyword("ROLLBACK").to_matchable(), ]) .to_matchable(), + Ref::keyword("TRANSACTION").optional().to_matchable(), ]) + .config(|this| { + this.terminators = vec![Ref::new("DelimiterGrammar").to_matchable()]; + }) .to_matchable() }) .to_matchable() .into(), ), ( - "SetStatementSegment".into(), - NodeMatcher::new(SyntaxKind::SetSegment, |_| { + "BeginStatementSegment".into(), + NodeMatcher::new(SyntaxKind::BeginStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - one_of(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("NakedIdentifierSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), + Sequence::new(vec![ + Ref::new("SingleIdentifierFullGrammar").to_matchable(), + Ref::new("ColonSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Bracketed::new(vec![Ref::new("SelectStatementSegment").to_matchable()]) + Ref::keyword("BEGIN").to_matchable(), + Sequence::new(vec![ + MetaSegment::indent().to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("StatementSegment").to_matchable(), + Ref::new("MultiStatementSegment").to_matchable(), + ]) .to_matchable(), - Ref::new("BareFunctionSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ + Ref::new("DelimiterGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.min_times(1); + this.reset_terminators = true; + this.terminators = vec![Ref::keyword("EXCEPTION").to_matchable()]; + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXCEPTION").to_matchable(), + Ref::keyword("WHEN").to_matchable(), + Ref::keyword("ERROR").to_matchable(), + Ref::keyword("THEN").to_matchable(), + MetaSegment::indent().to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Bracketed::new(vec![ - Ref::new("SelectStatementSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("BareFunctionSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), + Ref::new("StatementSegment").to_matchable(), + Ref::new("MultiStatementSegment").to_matchable(), ]) .to_matchable(), + Ref::new("DelimiterGrammar").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.min_times(1); + this.reset_terminators = true; + }) .to_matchable(), - Ref::new("ArrayLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + MetaSegment::dedent().to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::keyword("END").to_matchable(), + Ref::new("SingleIdentifierFullGrammar") + .optional() + .to_matchable(), ]) .to_matchable() }) @@ -1641,12 +1801,22 @@ pub fn dialect() -> Dialect { .into(), ), ( - "PartitionBySegment".into(), - NodeMatcher::new(SyntaxKind::PartitionBySegment, |_| { + "ReplaceClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SelectReplaceClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("PARTITION").to_matchable(), - Ref::keyword("BY").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("REPLACE").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("BaseExpressionElementGrammar").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) @@ -1654,12 +1824,34 @@ pub fn dialect() -> Dialect { .into(), ), ( - "ClusterBySegment".into(), - NodeMatcher::new(SyntaxKind::ClusterBySegment, |_| { + "DatatypeSegment".into(), + NodeMatcher::new(SyntaxKind::DataType, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::new("DatatypeIdentifierSegment").to_matchable(), + Ref::new("BracketedArguments").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ANY").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + ]) + .to_matchable(), + Ref::new("ArrayTypeSegment").to_matchable(), + Ref::new("StructTypeSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StructTypeSegment".into(), + NodeMatcher::new(SyntaxKind::DataType, |_dialect| { Sequence::new(vec![ - Ref::keyword("CLUSTER").to_matchable(), - Ref::keyword("BY").to_matchable(), - Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + Ref::keyword("STRUCT").to_matchable(), + Ref::new("StructTypeSchemaSegment") + .optional() .to_matchable(), ]) .to_matchable() @@ -1668,355 +1860,1956 @@ pub fn dialect() -> Dialect { .into(), ), ( - "OptionsSegment".into(), - NodeMatcher::new(SyntaxKind::OptionsSegment, |_| { - Sequence::new(vec![ - Ref::keyword("OPTIONS").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BaseExpressionElementGrammar").to_matchable(), + "StructTypeSchemaSegment".into(), + NodeMatcher::new(SyntaxKind::StructTypeSchema, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("ColumnConstraintSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("OptionsSegment").optional().to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.bracket_type("angle"); + this.bracket_pairs_set = "angle_bracket_pairs"; + }) .to_matchable() }) .to_matchable() .into(), ), - ]); - - dialect.replace_grammar( - "ColumnDefinitionSegment", - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), // Column name - Ref::new("DatatypeSegment").to_matchable(), // Column type - AnyNumberOf::new(vec![Ref::new("ColumnConstraintSegment").to_matchable()]) - .to_matchable(), - Ref::new("OptionsSegment").optional().to_matchable(), - ]) - .to_matchable(), - ); - - dialect.replace_grammar( - "CreateTableStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::new("TemporaryTransientGrammar") - .optional() - .to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("COPY").to_matchable(), - Ref::keyword("LIKE").to_matchable(), - Ref::keyword("CLONE").to_matchable(), - ]) - .to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ColumnDefinitionSegment").to_matchable()]) - .config(|this| this.allow_trailing()) + ( + "ArrayFunctionContentsSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionContents, |_dialect| { + Sequence::new(vec![ + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) .to_matchable(), ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("PartitionBySegment").optional().to_matchable(), - Ref::new("ClusterBySegment").optional().to_matchable(), - Ref::new("OptionsSegment").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - dialect.replace_grammar( - "AlterTableStatementSegment", - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - one_of(vec![ - // SET OPTIONS + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ArrayExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayExpression, |_dialect| { Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("OptionsSegment").to_matchable(), + Ref::new("ArrayFunctionNameSegment").to_matchable(), + Ref::new("ArrayFunctionContentsSegment").to_matchable(), ]) - .to_matchable(), - // ADD COLUMN - Delimited::new(vec![ - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("ColumnDefinitionSegment").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "NamedArgumentSegment".into(), + NodeMatcher::new(SyntaxKind::NamedArgument, |_dialect| { + Sequence::new(vec![ + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("RightArrowSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SemiStructuredAccessorSegment".into(), + NodeMatcher::new(SyntaxKind::SemiStructuredExpression, |_dialect| { + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("DotSegment").to_matchable(), + one_of(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("StarSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("ArrayAccessorSegment").optional().to_matchable(), ]) + .config(|this| { + this.min_times(1); + }) .to_matchable(), ]) - .config(|this| this.allow_trailing = true) - .to_matchable(), - // RENAME TO + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SplittableObjectReferenceGrammar".into(), + NodeMatcher::new(SyntaxKind::ObjectReference, |_dialect| { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "ColumnReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnReference, |_dialect| { Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - // RENAME COLUMN - Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ObjectReferenceDelimiterGrammar").to_matchable(), + Delimited::new(vec![ + Ref::new("SingleIdentifierFullGrammar").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); + this.terminators = vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::keyword("USING").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("CastOperatorSegment").to_matchable(), + Ref::new("StartSquareBracketSegment").to_matchable(), + Ref::new("StartBracketSegment").to_matchable(), + Ref::new("BinaryOperatorGrammar").to_matchable(), + Ref::new("ColonSegment").to_matchable(), + Ref::new("DelimiterGrammar").to_matchable(), + Ref::new("BracketedSegment").to_matchable(), + ]; + }) + .to_matchable(), ]) + .config(|this| { + this.optional(); + this.disallow_gaps(); + }) .to_matchable(), ]) - .config(|this| this.allow_trailing = true) - .to_matchable(), - // DROP COLUMN + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::TableReference, |_dialect| { Delimited::new(vec![ Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("SingleCSIdentifierGrammar").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("DashSegment").to_matchable(), + Ref::new("NakedCSIdentifierPart").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) + .config(|this| { + this.disallow_gaps(); + }) .to_matchable(), ]) - .to_matchable(), - // ALTER COLUMN SET OPTIONS - Delimited::new(vec![ - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + .config(|this| { + this.disallow_gaps(); + this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); + this.terminators = vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::keyword("USING").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("CastOperatorSegment").to_matchable(), + Ref::new("StartSquareBracketSegment").to_matchable(), + Ref::new("StartBracketSegment").to_matchable(), + Ref::new("ColonSegment").to_matchable(), + Ref::new("DelimiterGrammar").to_matchable(), + Ref::new("JoinLikeClauseGrammar").to_matchable(), + Ref::new("BracketedSegment").to_matchable(), + ]; + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SystemVariableSegment".into(), + NodeMatcher::new(SyntaxKind::SystemVariable, |_dialect| { + Ref::new("DoubleAtSignLiteralSegment").to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DeclareStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DeclareSegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DECLARE").to_matchable(), + Delimited::new(vec![Ref::new("SingleIdentifierFullGrammar").to_matchable()]) + .to_matchable(), + one_of(vec![ + Ref::new("DefaultDeclareOptionsGrammar").to_matchable(), + Sequence::new(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Ref::new("DefaultDeclareOptionsGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SetStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SetSegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Ref::new("NakedIdentifierSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("NakedIdentifierSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("SystemVariableSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Delimited::new(vec![ one_of(vec![ - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - one_of(vec![ - Ref::new("OptionsSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("DATA").to_matchable(), - Ref::keyword("TYPE").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + Bracketed::new(vec![Ref::new("SelectStatementSegment").to_matchable()]) + .to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Bracketed::new(vec![ + Ref::new("SelectStatementSegment").to_matchable(), ]) .to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Ref::new("ArrayLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ExecuteImmediateSegment".into(), + NodeMatcher::new(SyntaxKind::ExecuteImmediate, |_dialect| { + Sequence::new(vec![ + Ref::keyword("EXECUTE").to_matchable(), + Ref::keyword("IMMEDIATE").to_matchable(), + optionally_bracketed(vec![ + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("SingleIdentifierFullGrammar").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("CaseExpressionSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INTO").to_matchable(), + Delimited::new(vec![ + Ref::new("SingleIdentifierFullGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Delimited::new(vec![ Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - one_of(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("NULL").to_matchable(), - ]) - .to_matchable(), + Ref::new("BaseExpressionElementGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Ref::new("SingleIdentifierFullGrammar").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - dialect.add([( - "CreateExternalTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateExternalTableStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "PartitionBySegment".into(), + NodeMatcher::new(SyntaxKind::PartitionBySegment, |_dialect| { Sequence::new(vec![ - Ref::keyword("OR").optional().to_matchable(), - Ref::keyword("REPLACE").optional().to_matchable(), + Ref::keyword("PARTITION").to_matchable(), + Ref::keyword("BY").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("TABLE").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ClusterBySegment".into(), + NodeMatcher::new(SyntaxKind::ClusterBySegment, |_dialect| { Sequence::new(vec![ - Ref::keyword("IF").optional().to_matchable(), - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("EXISTS").optional().to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ColumnDefinitionSegment").to_matchable()]) - .config(|this| this.allow_trailing = true) + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("BY").to_matchable(), + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("CONNECTION").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DefaultCollateSegment".into(), + NodeMatcher::new(SyntaxKind::DefaultCollate, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("COLLATE").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "GrantToSegment".into(), + NodeMatcher::new(SyntaxKind::GrantToSegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("GRANT").to_matchable(), + Ref::keyword("TO").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "OptionsSegment".into(), + NodeMatcher::new(SyntaxKind::OptionsSegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("OPTIONS").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BaseExpressionElementGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::TableConstraint, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::new("PrimaryKeyGrammar").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("ENFORCED").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("ForeignKeyGrammar").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::keyword("REFERENCES").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("ENFORCED").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ColumnDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnDefinition, |_dialect| { + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + AnyNumberOf::new(vec![Ref::new("ColumnConstraintSegment").to_matchable()]) + .to_matchable(), + Ref::new("OptionsSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ViewColumnDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnDefinition, |_dialect| { + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("OptionsSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateSchemaStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateSchemaStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("DefaultCollateSegment").optional().to_matchable(), + Ref::new("OptionsSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateTableFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTableFunctionStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnDefinitionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + this.allow_trailing(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURNS").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.bracket_type("angle"); + this.bracket_pairs_set = "angle_bracket_pairs"; + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropTableFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropTableFunctionStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::new("TemporaryTransientGrammar") + .optional() + .to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("COPY").to_matchable(), + Ref::keyword("LIKE").to_matchable(), + Ref::keyword("CLONE").to_matchable(), + ]) + .to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("ForSystemTimeAsOfSegment") + .optional() + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("ColumnDefinitionSegment").to_matchable(), + Ref::new("TableConstraintSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.allow_trailing(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("DefaultCollateSegment").optional().to_matchable(), + Ref::new("PartitionBySegment").optional().to_matchable(), + Ref::new("ClusterBySegment").optional().to_matchable(), + Ref::new("OptionsSegment").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Ref::new("OptionsSegment").to_matchable(), + Ref::new("DefaultCollateSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ColumnDefinitionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.allow_trailing(); + }) + .to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("FOREIGN").to_matchable(), + Ref::keyword("KEY").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("REFERENCES").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("ENFORCED").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("PRIMARY").to_matchable(), + Ref::keyword("KEY").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("ENFORCED").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.allow_trailing(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.allow_trailing(); + }) + .to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("PRIMARY").to_matchable(), + Ref::keyword("KEY").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Ref::new("OptionsSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATA").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterSchemaStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterSchemaStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Ref::new("DefaultCollateSegment").to_matchable(), + Ref::new("OptionsSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("REPLICA").to_matchable(), + Ref::new("BaseExpressionElementGrammar").to_matchable(), + Ref::new("OptionsSegment").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("REPLICA").to_matchable(), + Ref::new("BaseExpressionElementGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateExternalTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateExternalTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ColumnDefinitionSegment").to_matchable()]) + .config(|this| { + this.allow_trailing(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("CONNECTION").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("PARTITION").to_matchable(), + Ref::keyword("COLUMNS").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnDefinitionSegment").to_matchable(), + ]) + .config(|this| { + this.allow_trailing(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("OptionsSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateSnapshotTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateSnapshotTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("SNAPSHOT").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("CLONE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("ForSystemTimeAsOfSegment") + .optional() + .to_matchable(), + Ref::new("OptionsSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ViewColumnDefinitionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("OptionsSegment").optional().to_matchable(), + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("OptionsSegment").to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("OptionsSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateMaterializedViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateMaterializedViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("PartitionBySegment").optional().to_matchable(), + Ref::new("ClusterBySegment").optional().to_matchable(), + Ref::new("OptionsSegment").optional().to_matchable(), + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateMaterializedViewAsReplicaOfStatementSegment".into(), + NodeMatcher::new( + SyntaxKind::CreateMaterializedViewAsReplicaOfStatement, + |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("OptionsSegment").optional().to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::keyword("REPLICA").to_matchable(), + Ref::keyword("OF").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable() + }, + ) + .to_matchable() + .into(), + ), + ( + "AlterMaterializedViewStatementSegment".into(), + NodeMatcher::new( + SyntaxKind::AlterMaterializedViewSetOptionsStatement, + |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("OptionsSegment").to_matchable(), + ]) + .to_matchable() + }, + ) + .to_matchable() + .into(), + ), + ( + "DropTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + one_of(vec![ + Ref::keyword("SNAPSHOT").to_matchable(), + Ref::keyword("EXTERNAL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Sequence::new(vec![Ref::keyword("TABLE").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropProcedureStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropProcedureStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ProcedureNameSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UndropSchemaStatementSegment".into(), + NodeMatcher::new(SyntaxKind::UndropSchemaStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("UNDROP").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropMaterializedViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropMaterializedViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ParameterizedSegment".into(), + NodeMatcher::new(SyntaxKind::ParameterizedExpression, |_dialect| { + one_of(vec![ + Ref::new("AtSignLiteralSegment").to_matchable(), + Ref::new("QuestionMarkSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "PivotForClauseSegment".into(), + NodeMatcher::new(SyntaxKind::PivotForClause, |_dialect| { + Sequence::new(vec![ + Ref::new("BaseExpressionElementGrammar").to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + this.terminators = vec![Ref::keyword("IN").to_matchable()]; + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FromPivotExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::FromPivotExpression, |_dialect| { + Sequence::new(vec![ + Ref::keyword("PIVOT").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("FunctionSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FOR").to_matchable(), + Ref::new("PivotForClauseSegment").to_matchable(), + Ref::keyword("IN").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UnpivotAliasExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::AliasExpression, |_dialect| { + Sequence::new(vec![ + MetaSegment::indent().to_matchable(), + Ref::new("AsAliasOperatorSegment").optional().to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FromUnpivotExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::FromUnpivotExpression, |_dialect| { + Sequence::new(vec![ + Ref::keyword("UNPIVOT").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("INCLUDE").to_matchable(), + Ref::keyword("EXCLUDE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("NULLS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("FOR").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("IN").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("UnpivotAliasExpressionSegment") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FOR").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("IN").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("UnpivotAliasExpressionSegment") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "InsertStatementSegment".into(), + NodeMatcher::new(SyntaxKind::InsertStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("INTO").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SamplingExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::SampleExpression, |_dialect| { + Sequence::new(vec![ + Ref::keyword("TABLESAMPLE").to_matchable(), + Ref::keyword("SYSTEM").to_matchable(), + Bracketed::new(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("PERCENT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MergeMatchSegment".into(), + NodeMatcher::new(SyntaxKind::MergeMatch, |_dialect| { + AnyNumberOf::new(vec![ + Ref::new("MergeMatchedClauseSegment").to_matchable(), + Ref::new("MergeNotMatchedByTargetClauseSegment").to_matchable(), + Ref::new("MergeNotMatchedBySourceClauseSegment").to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MergeNotMatchedByTargetClauseSegment".into(), + NodeMatcher::new(SyntaxKind::NotMatchedByTargetClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("WHEN").to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("MATCHED").to_matchable(), + Sequence::new(vec![ + Ref::keyword("BY").to_matchable(), + Ref::keyword("TARGET").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AND").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("THEN").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("MergeInsertClauseSegment").to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MergeNotMatchedBySourceClauseSegment".into(), + NodeMatcher::new(SyntaxKind::MergeWhenMatchedClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("WHEN").to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("MATCHED").to_matchable(), + Ref::keyword("BY").to_matchable(), + Ref::keyword("SOURCE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AND").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("THEN").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::new("MergeUpdateClauseSegment").to_matchable(), + Ref::new("MergeDeleteClauseSegment").to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MergeInsertClauseSegment".into(), + NodeMatcher::new(SyntaxKind::MergeInsertClause, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("INSERT").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::new("ValuesClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DeleteStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DeleteStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("FROM").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ExportStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ExportStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("EXPORT").to_matchable(), + Ref::keyword("DATA").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("CONNECTION").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("OPTIONS").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + StringParser::new("compression", SyntaxKind::ExportOption) + .to_matchable(), + StringParser::new("field_delimiter", SyntaxKind::ExportOption) + .to_matchable(), + StringParser::new("format", SyntaxKind::ExportOption) + .to_matchable(), + StringParser::new("header", SyntaxKind::ExportOption) + .to_matchable(), + StringParser::new("overwrite", SyntaxKind::ExportOption) + .to_matchable(), + StringParser::new("uri", SyntaxKind::ExportOption) + .to_matchable(), + StringParser::new( + "use_avro_logical_types", + SyntaxKind::ExportOption, + ) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BaseExpressionElementGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + StringParser::new("header", SyntaxKind::ExportOption) + .to_matchable(), + StringParser::new("overwrite", SyntaxKind::ExportOption) + .to_matchable(), + StringParser::new( + "use_avro_logical_types", + SyntaxKind::ExportOption, + ) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("TRUE").to_matchable(), + Ref::keyword("FALSE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "LoadDataStatementSegment".into(), + NodeMatcher::new(SyntaxKind::LoadDataStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("LOAD").to_matchable(), + Ref::keyword("DATA").to_matchable(), + one_of(vec![ + Ref::keyword("INTO").to_matchable(), + Ref::keyword("OVERWRITE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("TemporaryGrammar").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnDefinitionSegment").to_matchable(), + Ref::new("TableConstraintSegment").to_matchable(), + ]) + .config(|this| { + this.allow_trailing(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![Ref::keyword("OVERWRITE").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("PARTITIONS").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BaseExpressionElementGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("PartitionBySegment").optional().to_matchable(), + Ref::new("ClusterBySegment").optional().to_matchable(), + Ref::new("OptionsSegment").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("FILES").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BaseExpressionElementGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ Ref::keyword("WITH").to_matchable(), Ref::keyword("PARTITION").to_matchable(), Ref::keyword("COLUMNS").to_matchable(), Bracketed::new(vec![ Delimited::new(vec![ - Ref::new("ColumnDefinitionSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.allow_trailing(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("CONNECTION").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ProcedureNameSegment".into(), + NodeMatcher::new(SyntaxKind::ProcedureName, |_dialect| { + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DotSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::new("ProcedureNameIdentifierSegment").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ProcedureParameterListSegment".into(), + NodeMatcher::new(SyntaxKind::ProcedureParameterList, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ProcedureParameterGrammar").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateProcedureStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateProcedureStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ProcedureNameSegment").to_matchable(), + Ref::new("ProcedureParameterListSegment").to_matchable(), + Ref::new("OptionsSegment").optional().to_matchable(), + Ref::new("BeginStatementSegment") + .reset_terminators() + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CallStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CallStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CALL").to_matchable(), + Ref::new("ProcedureNameSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ReturnStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ReturnStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("RETURN").to_matchable()]).to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "BreakStatementSegment".into(), + NodeMatcher::new(SyntaxKind::BreakStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("BREAK").to_matchable()]).to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "LeaveStatementSegment".into(), + NodeMatcher::new(SyntaxKind::LeaveStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("LEAVE").to_matchable()]).to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ContinueStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ContinueStatement, |_dialect| { + one_of(vec![ + Ref::keyword("CONTINUE").to_matchable(), + Ref::keyword("ITERATE").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "RaiseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::RaiseStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("RAISE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Ref::keyword("MESSAGE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterOrganizationStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterOrganizationStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("ORGANIZATION").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("OptionsSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterProjectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterProjectStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("PROJECT").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("OptionsSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateSearchIndexStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateSearchIndexStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("INDEX").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("COLUMNS").to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Ref::new("IndexColumnDefinitionSegment").to_matchable(), ]) - .config(|this| this.allow_trailing = true) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Ref::new("OptionsSegment").optional().to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - dialect.add([( - "CreateExternalTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateExternalTableStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), + .into(), + ), + ( + "DropSearchIndexStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropSearchIndexStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("OR").optional().to_matchable(), - Ref::keyword("REPLACE").optional().to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("INDEX").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("TABLE").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateVectorIndexStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateVectorIndexStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("IF").optional().to_matchable(), - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("EXISTS").optional().to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ColumnDefinitionSegment").to_matchable()]) - .config(|this| this.allow_trailing = true) + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("VECTOR").to_matchable(), + Ref::keyword("INDEX").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("IndexColumnDefinitionSegment").to_matchable(), + ]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("CONNECTION").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("PARTITION").to_matchable(), - Ref::keyword("COLUMNS").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnDefinitionSegment").to_matchable(), - ]) - .config(|this| this.allow_trailing = true) + Ref::new("StoringSegment").optional().to_matchable(), + Ref::new("OptionsSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StoringSegment".into(), + NodeMatcher::new(SyntaxKind::StoringSegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("STORING").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::new("OptionsSegment").optional().to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - dialect.replace_grammar( - "CreateViewStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - Ref::new("OptionsSegment").optional().to_matchable(), - Ref::keyword("AS").to_matchable(), - optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable(), - ]) - .to_matchable(), - ); - - dialect.add([ + .into(), + ), ( - "AlterViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterViewStatement, |_| { + "DropVectorIndexStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropVectorIndexStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("VIEW").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("VECTOR").to_matchable(), + Ref::keyword("INDEX").to_matchable(), Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), - Ref::keyword("SET").to_matchable(), - Ref::new("OptionsSegment").to_matchable(), ]) .to_matchable() }) @@ -2024,20 +3817,22 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CreateMaterializedViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateMaterializedViewStatement, |_| { + "CreateRowAccessPolicyStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateRowAccessPolicyStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("PartitionBySegment").optional().to_matchable(), - Ref::new("ClusterBySegment").optional().to_matchable(), - Ref::new("OptionsSegment").optional().to_matchable(), - Ref::keyword("AS").to_matchable(), - optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + Ref::new("GrantToSegment").optional().to_matchable(), + Ref::keyword("FILTER").to_matchable(), + Ref::keyword("USING").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) .to_matchable(), ]) .to_matchable() @@ -2046,16 +3841,17 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterMaterializedViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterMaterializedViewSetOptionsStatement, |_| { + "DropRowAccessPolicyStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropRowAccessPolicyStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), - Ref::keyword("SET").to_matchable(), - Ref::new("OptionsSegment").to_matchable(), ]) .to_matchable() }) @@ -2063,14 +3859,14 @@ pub fn dialect() -> Dialect { .into(), ), ( - "DropMaterializedViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropMaterializedViewStatement, |_| { + "AlterBiCapacityStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterBiCapacityStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("BI_CAPACITY").to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("OptionsSegment").to_matchable(), ]) .to_matchable() }) @@ -2078,11 +3874,13 @@ pub fn dialect() -> Dialect { .into(), ), ( - "ParameterizedSegment".into(), - NodeMatcher::new(SyntaxKind::ParameterizedExpression, |_| { - one_of(vec![ - Ref::new("AtSignLiteralSegment").to_matchable(), - Ref::new("QuestionMarkSegment").to_matchable(), + "CreateCapacityStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateCapacityStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("CAPACITY").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("OptionsSegment").to_matchable(), ]) .to_matchable() }) @@ -2090,50 +3888,28 @@ pub fn dialect() -> Dialect { .into(), ), ( - "PivotForClauseSegment".into(), - NodeMatcher::new(SyntaxKind::PivotForClause, |_| { + "AlterCapacityStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterCapacityStatement, |_dialect| { Sequence::new(vec![ - Ref::new("BaseExpressionElementGrammar").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("CAPACITY").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("OptionsSegment").to_matchable(), ]) - .config(|this| { - this.terminators = vec![Ref::keyword("IN").to_matchable()]; - this.parse_mode(ParseMode::Greedy); - }) .to_matchable() }) .to_matchable() .into(), ), ( - "FromPivotExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::FromPivotExpression, |_| { + "DropCapacityStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropCapacityStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("PIVOT").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("FunctionSegment").to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("FOR").to_matchable(), - Ref::new("PivotForClauseSegment").to_matchable(), - Ref::keyword("IN").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("CAPACITY").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), ]) .to_matchable() }) @@ -2141,121 +3917,42 @@ pub fn dialect() -> Dialect { .into(), ), ( - "UnpivotAliasExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::AliasExpression, |_| { + "CreateReservationStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateReservationStatement, |_dialect| { Sequence::new(vec![ - MetaSegment::indent().to_matchable(), - Ref::keyword("AS").optional().to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("RESERVATION").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("OptionsSegment").to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - dialect.add([( - "FromUnpivotExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::FromUnpivotExpression, |_| { - Sequence::new(vec![ - Ref::keyword("UNPIVOT").to_matchable(), + ( + "AlterReservationStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterReservationStatement, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Ref::keyword("INCLUDE").to_matchable(), - Ref::keyword("EXCLUDE").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("NULLS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - // single column unpivot - Bracketed::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("FOR").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("IN").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Delimited::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - Ref::new("UnpivotAliasExpressionSegment") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - // multi column unpivot - Bracketed::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .config(|this| this.min_delimiters = 1) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("FOR").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("IN").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .config(|this| this.min_delimiters = 1) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("UnpivotAliasExpressionSegment") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("RESERVATION").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("OptionsSegment").to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - dialect.add([ + .into(), + ), ( - "InsertStatementSegment".into(), - NodeMatcher::new(SyntaxKind::InsertStatement, |_| { + "DropReservationStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropReservationStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("INSERT").to_matchable(), - Ref::keyword("INTO").optional().to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("RESERVATION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), ]) .to_matchable() }) @@ -2263,16 +3960,13 @@ pub fn dialect() -> Dialect { .into(), ), ( - "SamplingExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::SampleExpression, |_| { + "CreateAssignmentStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateAssignmentStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("TABLESAMPLE").to_matchable(), - Ref::keyword("SYSTEM").to_matchable(), - Bracketed::new(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::keyword("PERCENT").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("ASSIGNMENT").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("OptionsSegment").to_matchable(), ]) .to_matchable() }) @@ -2280,42 +3974,43 @@ pub fn dialect() -> Dialect { .into(), ), ( - "MergeMatchSegment".into(), - NodeMatcher::new(SyntaxKind::MergeMatch, |_| { - AnyNumberOf::new(vec![ - Ref::new("MergeMatchedClauseSegment").to_matchable(), - Ref::new("MergeNotMatchedByTargetClauseSegment").to_matchable(), - Ref::new("MergeNotMatchedBySourceClauseSegment").to_matchable(), + "DropAssignmentStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropAssignmentStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("ASSIGNMENT").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), ]) - .config(|this| this.min_times = 1) .to_matchable() }) .to_matchable() .into(), ), ( - "MergeNotMatchedByTargetClauseSegment".into(), - NodeMatcher::new(SyntaxKind::NotMatchedByTargetClause, |_| { - Sequence::new(vec![ - Ref::keyword("WHEN").to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("MATCHED").to_matchable(), + "PipeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::PipeStatement, |_dialect| { + one_of(vec![ Sequence::new(vec![ - Ref::keyword("BY").to_matchable(), - Ref::keyword("TARGET").to_matchable(), + Ref::new("FromClauseSegment").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("PipeOperatorClauseSegment").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Sequence::new(vec![ - Ref::keyword("AND").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("PipeOperatorClauseSegment").to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::keyword("THEN").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("MergeInsertClauseSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) @@ -2323,28 +4018,29 @@ pub fn dialect() -> Dialect { .into(), ), ( - "MergeNotMatchedBySourceClauseSegment".into(), - NodeMatcher::new(SyntaxKind::MergeWhenMatchedClause, |_| { + "PipeOperatorClauseSegment".into(), + NodeMatcher::new(SyntaxKind::PipeOperatorClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("WHEN").to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("MATCHED").to_matchable(), - Ref::keyword("BY").to_matchable(), - Ref::keyword("SOURCE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("AND").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("THEN").to_matchable(), - MetaSegment::indent().to_matchable(), + Ref::new("PipeOperatorSegment").to_matchable(), one_of(vec![ - Ref::new("MergeUpdateClauseSegment").to_matchable(), - Ref::new("MergeDeleteClauseSegment").to_matchable(), + Ref::new("SelectClauseSegment").to_matchable(), + Ref::new("ExtendClauseSegment").to_matchable(), + Ref::new("SetClauseListSegment").to_matchable(), + Ref::new("DropColumnClauseSegment").to_matchable(), + Ref::new("RenameColumnClauseSegment").to_matchable(), + Ref::new("AliasExpressionSegment").to_matchable(), + Ref::new("WhereClauseSegment").to_matchable(), + Ref::new("LimitClauseSegment").to_matchable(), + Ref::new("OrderByClauseSegment").to_matchable(), + Ref::new("AggregateClauseSegment").to_matchable(), + Ref::new("SetOperatorClauseSegment").to_matchable(), + Ref::new("JoinClauseSegment").to_matchable(), + Ref::new("CallOperatorSegment").to_matchable(), + Ref::new("SamplingExpressionSegment").to_matchable(), + Ref::new("PivotOperatorSegment").to_matchable(), + Ref::new("UnpivotOperatorSegment").to_matchable(), ]) .to_matchable(), - MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) @@ -2352,22 +4048,16 @@ pub fn dialect() -> Dialect { .into(), ), ( - "MergeInsertClauseSegment".into(), - NodeMatcher::new(SyntaxKind::MergeInsertClause, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("INSERT").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - MetaSegment::dedent().to_matchable(), - Ref::new("ValuesClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INSERT").to_matchable(), - Ref::keyword("ROW").to_matchable(), + "ExtendClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ExtendClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("EXTEND").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("BaseExpressionElementGrammar").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -2376,18 +4066,13 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - dialect.add([ ( - "DeleteStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DeleteStatement, |_| { + "DropColumnClauseSegment".into(), + NodeMatcher::new(SyntaxKind::DropColumnClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("DELETE").to_matchable(), - Ref::keyword("FROM").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), + Ref::keyword("DROP").to_matchable(), + Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + .to_matchable(), ]) .to_matchable() }) @@ -2395,64 +4080,136 @@ pub fn dialect() -> Dialect { .into(), ), ( - "ExportStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ExportStatement, |_| { + "RenameColumnClauseSegment".into(), + NodeMatcher::new(SyntaxKind::RenameColumnClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("EXPORT").to_matchable(), - Ref::keyword("DATA").to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("AliasExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "GroupAndOrderByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::GroupAndOrderbyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("CONNECTION").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("AND").to_matchable(), + Ref::keyword("ORDER").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("OPTIONS").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - one_of(vec![ - StringParser::new("compression", SyntaxKind::ExportOption) - .to_matchable(), - StringParser::new("field_delimiter", SyntaxKind::ExportOption) - .to_matchable(), - StringParser::new("format", SyntaxKind::ExportOption) + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::new("GroupingSetsClauseSegment").to_matchable(), + Ref::new("CubeRollupClauseSegment").to_matchable(), + Sequence::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::new("GroupByClauseTerminatorGrammar") + .to_matchable(), + ]; + }) + .to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ASC").to_matchable(), + Ref::keyword("DESC").to_matchable(), + ]) .to_matchable(), - StringParser::new("uri", SyntaxKind::ExportOption) + Sequence::new(vec![ + Ref::keyword("NULLS").to_matchable(), + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("LAST").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AggregateClauseSegment".into(), + NodeMatcher::new(SyntaxKind::AggregateClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("AGGREGATE").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("BaseExpressionElementGrammar").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), Sequence::new(vec![ one_of(vec![ - StringParser::new("header", SyntaxKind::ExportOption) - .to_matchable(), - StringParser::new("overwrite", SyntaxKind::ExportOption) - .to_matchable(), - StringParser::new( - "use_avro_logical_types", - SyntaxKind::ExportOption, - ) - .to_matchable(), + Ref::keyword("ASC").to_matchable(), + Ref::keyword("DESC").to_matchable(), ]) .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("TRUE").to_matchable(), - Ref::keyword("FALSE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULLS").to_matchable(), + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("LAST").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), + Ref::new("GroupAndOrderByClauseSegment") + .optional() + .to_matchable(), ]) .to_matchable() }) @@ -2460,120 +4217,79 @@ pub fn dialect() -> Dialect { .into(), ), ( - "ProcedureNameSegment".into(), - NodeMatcher::new(SyntaxKind::ProcedureName, |_| { + "SetOperatorClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SetOperatorClause, |_dialect| { Sequence::new(vec![ - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("DotSegment").to_matchable(), - ]) + Ref::new("SetOperatorSegment").to_matchable(), + Delimited::new(vec![Ref::new("NonSetSelectableGrammar").to_matchable()]) .to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::new("ProcedureNameIdentifierSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), - ]) - .to_matchable(), ]) - .config(|this| this.allow_gaps = false) .to_matchable() }) .to_matchable() .into(), ), - ]); - - dialect.add([ ( - "QuotedIdentifierSegment".into(), - TypedParser::new(SyntaxKind::BackQuote, SyntaxKind::QuotedIdentifier) + "CallOperatorSegment".into(), + NodeMatcher::new(SyntaxKind::CallOperator, |_dialect| { + Sequence::new(vec![ + Ref::new("CallStatementSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) .to_matchable() - .into(), - ), - ( - "NumericLiteralSegment".into(), - one_of(vec![ - TypedParser::new(SyntaxKind::NumericLiteral, SyntaxKind::NumericLiteral) - .to_matchable(), - Ref::new("ParameterizedSegment").to_matchable(), - ]) + }) .to_matchable() .into(), ), ( - "QuotedLiteralSegment".into(), - one_of(vec![ - Ref::new("SingleQuotedLiteralSegment").to_matchable(), - Ref::new("DoubleQuotedLiteralSegment").to_matchable(), - ]) + "PivotOperatorSegment".into(), + NodeMatcher::new(SyntaxKind::PivotOperator, |_dialect| { + Sequence::new(vec![ + Ref::new("FromPivotExpressionSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - "LiteralGrammar".into(), - dialect - .grammar("LiteralGrammar") - .copy( - Some(vec![Ref::new("ParameterizedSegment").to_matchable()]), - None, - None, - None, - Vec::new(), - false, - ) - .into(), + "UnpivotOperatorSegment".into(), + NodeMatcher::new(SyntaxKind::UnpivotOperator, |_dialect| { + Sequence::new(vec![ + Ref::new("FromUnpivotExpressionSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), ), ( - "PostTableExpressionGrammar".into(), - Sequence::new(vec![ + "CTEDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::CommonTableExpression, |_dialect| { Sequence::new(vec![ - Ref::keyword("FOR").to_matchable(), - one_of(vec![ - Ref::keyword("SYSTEM_TIME").to_matchable(), - Sequence::new(vec![ - Ref::keyword("SYSTEM").to_matchable(), - Ref::keyword("TIME").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("CTEColumnList").optional().to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("SelectableGrammar").to_matchable(), + Ref::new("PipeStatementSegment").to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::keyword("OF").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .config(|this| this.optional()) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "FunctionNameIdentifierSegment".into(), - one_of(vec![ - RegexParser::new("[A-Z_][A-Z0-9_]*", SyntaxKind::FunctionNameIdentifier) - .anti_template("^(STRUCT|ARRAY)$") - .to_matchable(), - RegexParser::new("`[^`]*`", SyntaxKind::FunctionNameIdentifier).to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), ]); - dialect.expand(); - dialect + bigquery_dialect } diff --git a/crates/lib-dialects/src/bigquery_keywords.rs b/crates/lib-dialects/src/bigquery_keywords.rs index 7cfa6dc95..ccc71b161 100644 --- a/crates/lib-dialects/src/bigquery_keywords.rs +++ b/crates/lib-dialects/src/bigquery_keywords.rs @@ -1,4 +1,5 @@ -pub(crate) const BIGQUERY_RESERVED_KEYWORDS: &str = r#"ALL +pub(crate) const BIGQUERY_RESERVED_KEYWORDS: &str = "AGGREGATE +ALL AND ANY ARRAY @@ -10,8 +11,10 @@ BETWEEN BY CASE CAST +CLONE COLLATE CONTAINS +CORRESPONDING CREATE CROSS CUBE @@ -27,6 +30,7 @@ ESCAPE EXCEPT EXCLUDE EXISTS +EXTEND FALSE FETCH FOLLOWING @@ -68,6 +72,7 @@ OVER PARTITION PIVOT PRECEDING +PRIMARY PROTO RANGE RECURSIVE @@ -93,23 +98,27 @@ WHEN WHERE WINDOW WITH -WITHIN"#; +WITHIN"; -pub(crate) const BIGQUERY_UNRESERVED_KEYWORDS: &str = r#"ACCOUNT +pub(crate) const BIGQUERY_UNRESERVED_KEYWORDS: &str = "ACCESS +ACCOUNT ADD ADMIN AFTER ALTER APPLY +ASSIGNMENT ASSERT AUTO_INCREMENT BEGIN BERNOULLI +BI_CAPACITY BINARY BINDING BREAK CACHE CALL +CAPACITY CASCADE CHAIN CHARACTER @@ -141,6 +150,9 @@ DOMAIN DOUBLE DROP ELSEIF +ENFORCED +ERROR +EXCEPTION EXECUTE EXECUTION EXPLAIN @@ -148,6 +160,7 @@ EXPORT EXTENSION EXTERNAL FILE +FILES FILTER FIRST FOREIGN @@ -160,6 +173,7 @@ GRANTED GRANTS HOUR ILIKE +IMMEDIATE IMPORTED IN INCREMENT @@ -167,11 +181,13 @@ INDEX INOUT INSERT INTEGRATION +KEY ITERATE LANGUAGE LARGE LAST LEAVE +LOAD LOOP MANAGE MASKING @@ -203,10 +219,12 @@ OPERATE OPTION OPTIONS ORDINAL +ORGANIZATION OUT OVERLAPS OVERWRITE OWNERSHIP +PARTITIONS PERCENT PIPE POLICY @@ -215,6 +233,7 @@ PRIMARY PRIOR PRIVILEGES PROCEDURE +PROJECT PUBLIC QUALIFY QUARTER @@ -226,6 +245,8 @@ RENAME REPEAT REPEATABLE REPLACE +REPLICA +RESERVATION RESOURCE RESTRICT RETURN @@ -240,16 +261,21 @@ SAFE SATURDAY SCHEMA SCHEMAS +SEARCH SECOND SEPARATOR SERVER SEQUENCE SESSION_USER +SETS SHARE +SNAPSHOT SOURCE STAGE START +STORING STREAM +STRICT SUNDAY SYSTEM SYSTEM_TIME @@ -268,6 +294,7 @@ TRIGGER TRUNCATE TUESDAY TYPE +UNDROP UNIQUE UNSIGNED UNTIL @@ -279,6 +306,7 @@ USER VALUE VALUES VARYING +VECTOR VERSION VIEW WAREHOUSE @@ -289,4 +317,4 @@ WITHOUT WORK WRAPPER WRITE -ZONE"#; +ZONE"; diff --git a/crates/lib-dialects/src/clickhouse.rs b/crates/lib-dialects/src/clickhouse.rs index a64acae7a..00b483791 100644 --- a/crates/lib-dialects/src/clickhouse.rs +++ b/crates/lib-dialects/src/clickhouse.rs @@ -1,14 +1,13 @@ +use itertools::Itertools; use sqruff_lib_core::dialects::Dialect; use sqruff_lib_core::dialects::init::DialectKind; use sqruff_lib_core::dialects::syntax::SyntaxKind; use sqruff_lib_core::helpers::{Config, ToMatchable}; -use sqruff_lib_core::parser::grammar::anyof::{ - AnyNumberOf, any_set_of, one_of, optionally_bracketed, -}; +use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed}; use sqruff_lib_core::parser::grammar::conditional::Conditional; use sqruff_lib_core::parser::grammar::delimited::Delimited; use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence}; -use sqruff_lib_core::parser::grammar::{Anything, Ref}; +use sqruff_lib_core::parser::grammar::{Nothing, Ref}; use sqruff_lib_core::parser::lexer::Matcher; use sqruff_lib_core::parser::matchable::MatchableTrait; use sqruff_lib_core::parser::node_matcher::NodeMatcher; @@ -17,21 +16,396 @@ use sqruff_lib_core::parser::segments::generator::SegmentGenerator; use sqruff_lib_core::parser::segments::meta::MetaSegment; use sqruff_lib_core::parser::types::ParseMode; -use super::ansi::{self, raw_dialect}; -use crate::clickhouse_keywords::UNRESERVED_KEYWORDS; +use super::clickhouse_keywords::UNRESERVED_KEYWORDS; pub fn dialect() -> Dialect { - let ansi_dialect = raw_dialect(); + raw_dialect().config(|this| this.expand()) +} - let mut clickhouse_dialect = raw_dialect(); +pub fn raw_dialect() -> Dialect { + let ansi_dialect = super::ansi::raw_dialect(); + let mut clickhouse_dialect = ansi_dialect.clone(); clickhouse_dialect.name = DialectKind::Clickhouse; + clickhouse_dialect .sets_mut("unreserved_keywords") .extend(UNRESERVED_KEYWORDS); + clickhouse_dialect.insert_lexer_matchers( + vec![Matcher::string("lambda", r#"->"#, SyntaxKind::Lambda)], + "newline", + ); + + clickhouse_dialect.patch_lexer_matchers(vec![ + Matcher::regex( + "double_quote", + r#""([^"\\]|""|\\.)*""#, + SyntaxKind::DoubleQuote, + ), + Matcher::regex( + "back_quote", + r#"`(?:[^`\\]|``|\\.)*`"#, + SyntaxKind::BackQuote, + ), + ]); + + clickhouse_dialect.add([ + ( + "BackQuotedIdentifierSegment".into(), + TypedParser::new(SyntaxKind::BackQuote, SyntaxKind::QuotedIdentifier) + .to_matchable() + .into(), + ), + ( + "LambdaFunctionSegment".into(), + TypedParser::new(SyntaxKind::Lambda, SyntaxKind::Lambda) + .to_matchable() + .into(), + ), + ]); + + clickhouse_dialect.add([( + "NakedIdentifierSegment".into(), + SegmentGenerator::new(|dialect| { + let reserved_keywords = dialect.sets("reserved_keywords"); + let pattern = reserved_keywords.iter().join("|"); + let anti_template = format!("^({pattern})$"); + RegexParser::new(r#"[a-zA-Z_][0-9a-zA-Z_]*"#, SyntaxKind::NakedIdentifier) + .anti_template(&anti_template) + .to_matchable() + }) + .into(), + )]); + + clickhouse_dialect.replace_grammar( + "BinaryOperatorGrammar", + one_of(vec![ + Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(), + Ref::new("StringBinaryOperatorGrammar").to_matchable(), + Ref::new("BooleanBinaryOperatorGrammar").to_matchable(), + Ref::new("ComparisonOperatorGrammar").to_matchable(), + Ref::new("LambdaFunctionSegment").to_matchable(), + ]) + .to_matchable(), + ); + + clickhouse_dialect.replace_grammar( + "JoinTypeKeywordsGrammar", + Sequence::new(vec![ + Ref::keyword("GLOBAL").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("INNER").to_matchable(), + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("ANY").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("ANY").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("INNER").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FULL").to_matchable(), + Ref::keyword("ALL").optional().to_matchable(), + Ref::keyword("OUTER").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").optional().to_matchable(), + Ref::keyword("FULL").to_matchable(), + Ref::keyword("OUTER").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LEFT").to_matchable(), + one_of(vec![ + Ref::keyword("ANTI").to_matchable(), + Ref::keyword("SEMI").to_matchable(), + one_of(vec![ + Ref::keyword("ANY").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("ASOF").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("OUTER").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ANTI").to_matchable(), + Ref::keyword("SEMI").to_matchable(), + one_of(vec![ + Ref::keyword("ANY").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("ASOF").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("LEFT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RIGHT").to_matchable(), + one_of(vec![ + Ref::keyword("OUTER").to_matchable(), + Ref::keyword("ANTI").to_matchable(), + Ref::keyword("SEMI").to_matchable(), + one_of(vec![ + Ref::keyword("ANY").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("OUTER").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ANTI").to_matchable(), + Ref::keyword("SEMI").to_matchable(), + one_of(vec![ + Ref::keyword("ANY").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("RIGHT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("ASOF").to_matchable(), + Ref::keyword("ANY").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ); + + clickhouse_dialect.replace_grammar( + "JoinUsingConditionGrammar", + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Conditional::new(MetaSegment::indent()).to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Conditional::new(MetaSegment::dedent()).to_matchable(), + ]) + .to_matchable(), + ); + + clickhouse_dialect.replace_grammar( + "ConditionalCrossJoinKeywordsGrammar", + Nothing::new().to_matchable(), + ); + + clickhouse_dialect.replace_grammar( + "UnconditionalCrossJoinKeywordsGrammar", + Sequence::new(vec![ + Ref::keyword("GLOBAL").optional().to_matchable(), + Ref::keyword("CROSS").to_matchable(), + ]) + .to_matchable(), + ); + + clickhouse_dialect.replace_grammar( + "HorizontalJoinKeywordsGrammar", + Sequence::new(vec![ + Ref::keyword("GLOBAL").optional().to_matchable(), + Ref::keyword("PASTE").to_matchable(), + ]) + .to_matchable(), + ); + + clickhouse_dialect.replace_grammar("NaturalJoinKeywordsGrammar", Nothing::new().to_matchable()); + + clickhouse_dialect.replace_grammar( + "JoinLikeClauseGrammar", + Sequence::new(vec![ + AnyNumberOf::new(vec![Ref::new("ArrayJoinClauseSegment").to_matchable()]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ); + + clickhouse_dialect.replace_grammar( + "QuotedLiteralSegment", + one_of(vec![ + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral).to_matchable(), + TypedParser::new(SyntaxKind::DollarQuote, SyntaxKind::QuotedLiteral).to_matchable(), + ]) + .to_matchable(), + ); + + clickhouse_dialect.replace_grammar( + "SingleIdentifierGrammar", + one_of(vec![ + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), + Ref::new("SingleQuotedIdentifierSegment").to_matchable(), + Ref::new("BackQuotedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + ); + + clickhouse_dialect.replace_grammar( + "InOperatorGrammar", + Sequence::new(vec![ + Ref::keyword("GLOBAL").optional().to_matchable(), + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("IN").to_matchable(), + one_of(vec![ + Ref::new("FunctionSegment").to_matchable(), + Ref::new("ArrayLiteralSegment").to_matchable(), + Ref::new("TupleSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Delimited::new(vec![Ref::new("Expression_A_Grammar").to_matchable()]) + .to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ); + + clickhouse_dialect.replace_grammar( + "SelectClauseTerminatorGrammar", + ansi_dialect.grammar("SelectClauseTerminatorGrammar").copy( + Some(vec![ + Ref::keyword("PREWHERE").to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::keyword("FORMAT").to_matchable(), + ]), + None, + Some(Ref::keyword("WHERE").to_matchable()), + None, + vec![], + false, + ), + ); + + clickhouse_dialect.replace_grammar( + "FromClauseTerminatorGrammar", + ansi_dialect + .grammar("FromClauseTerminatorGrammar") + .copy( + Some(vec![ + Ref::keyword("PREWHERE").to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::keyword("FORMAT").to_matchable(), + ]), + None, + Some(Ref::keyword("WHERE").to_matchable()), + None, + vec![], + false, + ) + .copy( + Some(vec![Ref::new("SettingsClauseSegment").to_matchable()]), + None, + None, + None, + vec![], + false, + ), + ); + + clickhouse_dialect.replace_grammar( + "DateTimeLiteralGrammar", + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DATE").to_matchable(), + Ref::keyword("TIME").to_matchable(), + Ref::keyword("TIMESTAMP").to_matchable(), + ]) + .to_matchable(), + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::DateConstructorLiteral) + .to_matchable(), + ]) + .to_matchable(), + ); + + clickhouse_dialect.replace_grammar( + "AlterTableDropColumnGrammar", + Sequence::new(vec![ + Ref::new("OnClusterClauseSegment").optional().to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ); + clickhouse_dialect.sets_mut("datetime_units").clear(); + clickhouse_dialect.sets_mut("datetime_units").extend([ - // https://github.com/ClickHouse/ClickHouse/blob/1cdccd527f0cbf5629b21d29970e28d5156003dc/src/Parsers/parseIntervalKind.cpp#L8 "NANOSECOND", "NANOSECONDS", "SQL_TSI_NANOSECOND", @@ -88,310 +462,209 @@ pub fn dialect() -> Dialect { clickhouse_dialect.add([ ( - "SelectClauseTerminatorGrammar".into(), - clickhouse_dialect - .grammar("SelectClauseTerminatorGrammar") - .copy( - Some(vec![ - Ref::keyword("PREWHERE").to_matchable(), - Ref::keyword("INTO").to_matchable(), - Ref::keyword("FORMAT").to_matchable(), - ]), - None, - Some(Ref::keyword("WHERE").to_matchable()), - None, - Vec::new(), - false, - ) - .into(), - ), - ( - "FromClauseTerminatorGrammar".into(), - clickhouse_dialect - .grammar("FromClauseTerminatorGrammar") - .copy( - Some(vec![ - Ref::keyword("PREWHERE").to_matchable(), - Ref::keyword("INTO").to_matchable(), - Ref::keyword("FORMAT").to_matchable(), - ]), - None, - Some(Ref::keyword("WHERE").to_matchable()), - None, - Vec::new(), - false, - ) - .copy( - Some(vec![Ref::new("SettingsClauseSegment").to_matchable()]), - None, - None, - None, - Vec::new(), - false, - ) - .into(), - ), - ( - "DateTimeLiteralGrammar".into(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DATE").to_matchable(), - Ref::keyword("TIME").to_matchable(), - Ref::keyword("TIMESTAMP").to_matchable(), + "IntoOutfileClauseSegment".into(), + NodeMatcher::new(SyntaxKind::IntoOutfileClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("INTO").to_matchable(), + Ref::keyword("OUTFILE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("FormatClauseSegment").optional().to_matchable(), ]) - .to_matchable(), - TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::DateConstructorLiteral) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), - ]); - - // Disambiguate wildcard EXCEPT from set operator EXCEPT. - // Exclude patterns like `EXCEPT ( ... )` and `EXCEPT identifier` from - // being parsed as a set operator to allow wildcard `* EXCEPT ...` to bind. - clickhouse_dialect.replace_grammar( - "SetOperatorSegment", - one_of(vec![ - Ref::new("UnionGrammar").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("INTERSECT").to_matchable(), - Ref::keyword("EXCEPT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("ALL").optional().to_matchable(), - ]) - .to_matchable(), - Ref::keyword("MINUS").to_matchable(), - ]) - .config(|config| { - config.exclude = Some( - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("EXCEPT").to_matchable(), - Bracketed::new(vec![Anything::new().to_matchable()]).to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("EXCEPT").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) + ( + "FormatClauseSegment".into(), + NodeMatcher::new(SyntaxKind::FormatClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("FORMAT").to_matchable(), + one_of( + super::clickhouse_keywords::FORMAT_KEYWORDS + .iter() + .map(|item| Ref::keyword(*item).to_matchable()) + .collect_vec(), + ) .to_matchable(), + Ref::new("SettingsClauseSegment").optional().to_matchable(), ]) - .to_matchable(), - ); - }) - .to_matchable(), - ); - - clickhouse_dialect.replace_grammar( - "FromExpressionElementSegment", - Sequence::new(vec![ - Ref::new("PreTableFunctionKeywordsGrammar") - .optional() - .to_matchable(), - optionally_bracketed(vec![Ref::new("TableExpressionSegment").to_matchable()]) - .to_matchable(), - Ref::new("AliasExpressionSegment") - .exclude(one_of(vec![ - Ref::new("FromClauseTerminatorGrammar").to_matchable(), - Ref::new("SamplingExpressionSegment").to_matchable(), - Ref::new("JoinLikeClauseGrammar").to_matchable(), - Ref::keyword("FINAL").to_matchable(), - Ref::new("JoinClauseSegment").to_matchable(), - ])) - .optional() - .to_matchable(), - Ref::keyword("FINAL").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - Ref::new("AliasExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("SamplingExpressionSegment") - .optional() - .to_matchable(), - Ref::new("PostTableExpressionGrammar") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.replace_grammar( - "JoinClauseSegment", - one_of(vec![ - Sequence::new(vec![ - Ref::new("JoinTypeKeywords").optional().to_matchable(), - Ref::new("JoinKeywordsGrammar").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("FromExpressionElementSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - Conditional::new(MetaSegment::indent()) - .indented_using_on() - .to_matchable(), - one_of(vec![ - Ref::new("JoinOnConditionSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Conditional::new(MetaSegment::indent()) - .indented_using_on() - .to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.parse_mode(ParseMode::Greedy)) - .to_matchable(), - Delimited::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MergeTreesOrderByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::MergeTreeOrderByClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("TUPLE").to_matchable(), + Bracketed::new(vec![]).to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Conditional::new(MetaSegment::dedent()) - .indented_using_on() - .to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Conditional::new(MetaSegment::dedent()) - .indented_using_on() - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.replace_grammar( - "SelectClauseModifierSegment", - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("DISTINCT").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "PreWhereClauseSegment".into(), + NodeMatcher::new(SyntaxKind::PrewhereClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("PREWHERE").to_matchable(), + MetaSegment::implicit_indent().to_matchable(), + optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("ALL").to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.replace_grammar( - "OrderByClauseSegment", - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - MetaSegment::indent().to_matchable(), - Delimited::new(vec![ + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SettingsClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SettingsClause, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("ASC").to_matchable(), - Ref::keyword("DESC").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NULLS").to_matchable(), - one_of(vec![ - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("LAST").to_matchable(), + Ref::keyword("SETTINGS").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::new("WithFillSegment").optional().to_matchable(), ]) - .to_matchable(), - ]) - .config(|this| { - this.terminators = vec![ - Ref::keyword("LIMIT").to_matchable(), - Ref::new("FrameClauseUnitGrammar").to_matchable(), - ] - }) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.add([ - ( - "NakedIdentifierSegment".into(), - SegmentGenerator::new(|dialect| { - // Generate the anti template from the set of reserved keywords - let reserved_keywords = dialect.sets("reserved_keywords"); - let pattern = reserved_keywords.into_iter().collect::>().join("|"); - let anti_template = format!("^({pattern})$"); - RegexParser::new("[a-zA-Z_][0-9a-zA-Z_]*", SyntaxKind::NakedIdentifier) - .anti_template(&anti_template) - .to_matchable() + .config(|this| { + this.optional(); + }) + .to_matchable() }) + .to_matchable() .into(), ), ( - "BackQuotedIdentifierSegment".into(), - TypedParser::new(SyntaxKind::BackQuote, SyntaxKind::QuotedIdentifier) - .to_matchable() - .into(), + "SelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("SelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("PreWhereClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("WhereClauseSegment").optional().to_matchable()), + None, + vec![], + false, + ) + .copy( + Some(vec![ + Ref::new("FormatClauseSegment").optional().to_matchable(), + Ref::new("IntoOutfileClauseSegment") + .optional() + .to_matchable(), + Ref::new("SettingsClauseSegment").optional().to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), ), ( - "SingleIdentifierGrammar".into(), - one_of(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), - Ref::new("SingleQuotedIdentifierSegment").to_matchable(), - Ref::new("BackQuotedIdentifierSegment").to_matchable(), - ]) + "UnorderedSelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("UnorderedSelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("PreWhereClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("WhereClauseSegment").optional().to_matchable()), + None, + vec![], + false, + ) + }) .to_matchable() .into(), ), - // A Clickhouse SELECT EXCEPT clause. - // https://clickhouse.com/docs/en/sql-reference/statements/select#except ( - "ExceptClauseSegment".into(), - NodeMatcher::new(SyntaxKind::SelectExceptClause, |_| { + "WithFillSegment".into(), + NodeMatcher::new(SyntaxKind::WithFill, |_dialect| { Sequence::new(vec![ - Ref::keyword("EXCEPT").to_matchable(), - one_of(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::keyword("FILL").to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TO").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STEP").to_matchable(), + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("IntervalExpressionSegment").to_matchable(), ]) .to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -400,21 +673,15 @@ pub fn dialect() -> Dialect { .into(), ), ( - "QuotedLiteralSegment".into(), - one_of(vec![ - TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral).to_matchable(), - TypedParser::new(SyntaxKind::DollarQuote, SyntaxKind::QuotedLiteral).to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "TupleSegment".into(), - NodeMatcher::new(SyntaxKind::Tuple, |_| { + "BracketedArguments".into(), + NodeMatcher::new(SyntaxKind::BracketedArguments, |_dialect| { Bracketed::new(vec![ Delimited::new(vec![ - Ref::new("BaseExpressionElementGrammar").to_matchable(), + one_of(vec![Ref::new("DatatypeSegment").to_matchable()]).to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -422,719 +689,455 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - clickhouse_dialect.replace_grammar( - "WildcardExpressionSegment", - ansi::wildcard_expression_segment().copy( - Some(vec![ - Ref::new("ExceptClauseSegment").optional().to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ), - ); - - clickhouse_dialect.add([( - "SettingsClauseSegment".into(), - Sequence::new(vec![ - Ref::keyword("SETTINGS").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + ( + "DatatypeSegment".into(), + NodeMatcher::new(SyntaxKind::DataType, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + StringParser::new("NULLABLE", SyntaxKind::DataTypeIdentifier) + .to_matchable(), + Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .to_matchable(), ]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable() - .into(), - )]); - - clickhouse_dialect.add([ - ( - // https://clickhouse.com/docs/interfaces/formats - "FormatValueSegment".into(), - RegexParser::new("[a-zA-Z]*", SyntaxKind::Word) - .to_matchable() - .into(), - ), - ( - "IntoOutfileClauseSegment".into(), - Sequence::new(vec![ - Ref::keyword("INTO").to_matchable(), - Ref::keyword("OUTFILE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("FormatClauseSegment").optional().to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "FormatClauseSegment".into(), - Sequence::new(vec![ - Ref::keyword("FORMAT").to_matchable(), - Ref::new("FormatValueSegment").to_matchable(), - Ref::new("SettingsClauseSegment").optional().to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "MergeTreesOrderByClauseSegment".into(), - NodeMatcher::new(SyntaxKind::MergeTreeOrderByClause, |_| { - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("TUPLE").to_matchable(), - Bracketed::new(vec![]).to_matchable(), - ]) - .to_matchable(), + Sequence::new(vec![ + StringParser::new("LOWCARDINALITY", SyntaxKind::DataTypeIdentifier) + .to_matchable(), + Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + StringParser::new("DATETIME64", SyntaxKind::DataTypeIdentifier) + .to_matchable(), Bracketed::new(vec![ Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + this.delimiter(Ref::new("CommaSegment")); + }) .to_matchable(), ]) .to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ]); - - clickhouse_dialect.insert_lexer_matchers( - vec![Matcher::string("lambda", "->", SyntaxKind::Lambda)], - "newline", - ); - - clickhouse_dialect.add(vec![ - ( - "JoinTypeKeywords".into(), - Sequence::new(vec![ - Ref::keyword("GLOBAL").optional().to_matchable(), - one_of(vec![ - // This case INNER [ANY,ALL] JOIN Sequence::new(vec![ - Ref::keyword("INNER").to_matchable(), - one_of(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("ANY").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + StringParser::new("DATETIME", SyntaxKind::DataTypeIdentifier) + .to_matchable(), + Bracketed::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), - // This case [ANY,ALL] INNER JOIN Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("ANY").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("INNER").to_matchable(), + StringParser::new("FIXEDSTRING", SyntaxKind::DataTypeIdentifier) + .to_matchable(), + Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) + .to_matchable(), ]) .to_matchable(), - // This case FULL ALL OUTER JOIN Sequence::new(vec![ - Ref::keyword("FULL").to_matchable(), - Ref::keyword("ALL").optional().to_matchable(), - Ref::keyword("OUTER").optional().to_matchable(), + StringParser::new("ARRAY", SyntaxKind::DataTypeIdentifier).to_matchable(), + Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .to_matchable(), ]) .to_matchable(), - // This case ALL FULL OUTER JOIN Sequence::new(vec![ - Ref::keyword("ALL").optional().to_matchable(), - Ref::keyword("FULL").to_matchable(), - Ref::keyword("OUTER").optional().to_matchable(), + StringParser::new("MAP", SyntaxKind::DataTypeIdentifier).to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .config(|this| { + this.delimiter(Ref::new("CommaSegment")); + }) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - // This case LEFT [OUTER,ANTI,SEMI,ANY,ASOF] JOIN Sequence::new(vec![ - Ref::keyword("LEFT").to_matchable(), - one_of(vec![ - Ref::keyword("ANTI").to_matchable(), - Ref::keyword("SEMI").to_matchable(), - one_of(vec![ - Ref::keyword("ANY").to_matchable(), - Ref::keyword("ALL").to_matchable(), + StringParser::new("TUPLE", SyntaxKind::DataTypeIdentifier).to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.delimiter(Ref::new("CommaSegment")); + }) .to_matchable(), - Ref::keyword("ASOF").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::keyword("OUTER").optional().to_matchable(), ]) .to_matchable(), - // This case [ANTI,SEMI,ANY,ASOF] LEFT JOIN Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ANTI").to_matchable(), - Ref::keyword("SEMI").to_matchable(), - one_of(vec![ - Ref::keyword("ANY").to_matchable(), - Ref::keyword("ALL").to_matchable(), + StringParser::new("NESTED", SyntaxKind::DataTypeIdentifier).to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.delimiter(Ref::new("CommaSegment")); + }) .to_matchable(), - Ref::keyword("ASOF").to_matchable(), ]) .to_matchable(), - Ref::keyword("LEFT").to_matchable(), ]) .to_matchable(), - // This case RIGHT [OUTER,ANTI,SEMI,ANY,ASOF] JOIN + StringParser::new("JSON", SyntaxKind::DataTypeIdentifier).to_matchable(), Sequence::new(vec![ - Ref::keyword("RIGHT").to_matchable(), one_of(vec![ - Ref::keyword("OUTER").to_matchable(), - Ref::keyword("ANTI").to_matchable(), - Ref::keyword("SEMI").to_matchable(), - one_of(vec![ - Ref::keyword("ANY").to_matchable(), - Ref::keyword("ALL").to_matchable(), + StringParser::new("ENUM8", SyntaxKind::DataTypeIdentifier) + .to_matchable(), + StringParser::new("ENUM16", SyntaxKind::DataTypeIdentifier) + .to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.delimiter(Ref::new("CommaSegment")); + }) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::keyword("OUTER").optional().to_matchable(), ]) .to_matchable(), - // This case [OUTER,ANTI,SEMI,ANY] RIGHT JOIN Sequence::new(vec![ one_of(vec![ - Ref::keyword("ANTI").to_matchable(), - Ref::keyword("SEMI").to_matchable(), - one_of(vec![ - Ref::keyword("ANY").to_matchable(), - Ref::keyword("ALL").to_matchable(), + StringParser::new("DECIMAL", SyntaxKind::DataTypeIdentifier) + .to_matchable(), + StringParser::new("NUMERIC", SyntaxKind::DataTypeIdentifier) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("BracketedArguments").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + StringParser::new("DECIMAL32", SyntaxKind::DataTypeIdentifier) + .to_matchable(), + StringParser::new("DECIMAL64", SyntaxKind::DataTypeIdentifier) + .to_matchable(), + StringParser::new("DECIMAL128", SyntaxKind::DataTypeIdentifier) + .to_matchable(), + StringParser::new("DECIMAL256", SyntaxKind::DataTypeIdentifier) + .to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("TupleTypeSegment").to_matchable(), + Ref::new("DatatypeIdentifierSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Sequence::new(vec![ + StringParser::new("DATETIME64", SyntaxKind::DataTypeIdentifier) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").optional().to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("RIGHT").to_matchable(), ]) .to_matchable(), - // This case CROSS JOIN - Ref::keyword("CROSS").to_matchable(), - // This case PASTE JOIN - Ref::keyword("PASTE").to_matchable(), - // This case ASOF JOIN - Ref::keyword("ASOF").to_matchable(), - // This case ANY JOIN - Ref::keyword("ANY").to_matchable(), - // This case ALL JOIN - Ref::keyword("ALL").to_matchable(), + Sequence::new(vec![ + StringParser::new("ARRAY", SyntaxKind::DataTypeIdentifier).to_matchable(), + Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - "LambdaFunctionSegment".into(), - TypedParser::new(SyntaxKind::Lambda, SyntaxKind::Lambda) + "TupleTypeSegment".into(), + NodeMatcher::new(SyntaxKind::StructType, |_dialect| { + Sequence::new(vec![ + Ref::keyword("TUPLE").to_matchable(), + Ref::new("TupleTypeSchemaSegment").to_matchable(), + ]) .to_matchable() - .into(), + }) + .to_matchable() + .into(), ), - ]); - - clickhouse_dialect.add(vec![( - "BinaryOperatorGrammar".into(), - one_of(vec![ - Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(), - Ref::new("StringBinaryOperatorGrammar").to_matchable(), - Ref::new("BooleanBinaryOperatorGrammar").to_matchable(), - Ref::new("ComparisonOperatorGrammar").to_matchable(), - // Add Lambda Function - Ref::new("LambdaFunctionSegment").to_matchable(), - ]) - .to_matchable() - .into(), - )]); - - clickhouse_dialect.add([ ( - "JoinLikeClauseGrammar".into(), - Sequence::new(vec![ - AnyNumberOf::new(vec![Ref::new("ArrayJoinClauseSegment").to_matchable()]) - .config(|this| this.min_times(1)) + "TupleTypeSchemaSegment".into(), + NodeMatcher::new(SyntaxKind::TupleTypeSchema, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + ]) .to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - ]) + ]) + .config(|this| { + this.bracket_type("round"); + this.bracket_pairs_set = "bracket_pairs"; + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ArrayJoinClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayJoinClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("LEFT").optional().to_matchable(), + Ref::keyword("ARRAY").to_matchable(), + Ref::new("JoinKeywordsGrammar").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![Ref::new("SelectClauseElementSegment").to_matchable()]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - "InOperatorGrammar".into(), - Sequence::new(vec![ - Ref::keyword("GLOBAL").optional().to_matchable(), - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("IN").to_matchable(), + "CTEDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::CommonTableExpression, |_dialect| { one_of(vec![ - Ref::new("FunctionSegment").to_matchable(), // IN tuple(1, 2) - Ref::new("ArrayLiteralSegment").to_matchable(), // IN [1, 2] - Ref::new("TupleSegment").to_matchable(), // IN (1, 2) - Ref::new("SingleIdentifierGrammar").to_matchable(), // IN TABLE, IN CTE - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("Expression_A_Grammar").to_matchable()]) + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("CTEColumnList").optional().to_matchable(), + Ref::keyword("AS").to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) .to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), ]) - .config(|this| this.parse_mode(ParseMode::Greedy)) + .to_matchable(), + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) .to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), - ]); - - clickhouse_dialect.add([( - "PreWhereClauseSegment".into(), - NodeMatcher::new(SyntaxKind::PreWhereClause, |_| { - Sequence::new(vec![ - Ref::keyword("PREWHERE").to_matchable(), - // NOTE: The indent here is implicit to allow - // constructions like: - // - // PREWHERE a - // AND b - // - // to be valid without forcing an indent between - // "PREWHERE" and "a". - MetaSegment::implicit_indent().to_matchable(), - optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) + ( + "AliasExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::AliasExpression, |_dialect| { + Sequence::new(vec![ + MetaSegment::indent().to_matchable(), + Ref::new("AsAliasOperatorSegment").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Bracketed::new(vec![ + Ref::new("SingleIdentifierListSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("SingleQuotedIdentifierSegment").to_matchable(), + ]) + .config(|this| { + this.exclude = Some( + one_of(vec![ + Ref::keyword("LATERAL").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::keyword("KEYS").to_matchable(), + ]) + .to_matchable(), + ); + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - // We need to replace the UnorderedSelectStatementSegment to include PREWHERE - clickhouse_dialect.replace_grammar( - "UnorderedSelectStatementSegment", - ansi_dialect - .grammar("UnorderedSelectStatementSegment") - .match_grammar(&ansi_dialect) - .unwrap() - .copy( - Some(vec![ - Ref::new("PreWhereClauseSegment").optional().to_matchable(), - ]), - None, - Some(Ref::new("WhereClauseSegment").optional().to_matchable()), - None, - Vec::new(), - false, - ), - ); - - clickhouse_dialect.replace_grammar( - "SelectStatementSegment", - ansi::select_statement() - .copy( - Some(vec![ - Ref::new("PreWhereClauseSegment").optional().to_matchable(), - ]), - None, - Some(Ref::new("WhereClauseSegment").optional().to_matchable()), - None, - Vec::new(), - false, - ) - .copy( - Some(vec![ - Ref::new("FormatClauseSegment").optional().to_matchable(), - Ref::new("IntoOutfileClauseSegment") - .optional() - .to_matchable(), - Ref::new("SettingsClauseSegment").optional().to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ), - ); - - clickhouse_dialect.add([( - "WithFillSegment".into(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("FILL").to_matchable(), - Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TO").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("STEP").to_matchable(), - one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("IntervalExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable() - .into(), - )]); - - clickhouse_dialect.replace_grammar( - "DatatypeSegment", - one_of(vec![ - // Nullable(Type) - Sequence::new(vec![ - StringParser::new("NULLABLE", SyntaxKind::DataTypeIdentifier).to_matchable(), - Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]).to_matchable(), - ]) - .to_matchable(), - // LowCardinality(Type) - Sequence::new(vec![ - StringParser::new("LOWCARDINALITY", SyntaxKind::DataTypeIdentifier).to_matchable(), - Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]).to_matchable(), - ]) - .to_matchable(), - // DateTime64(precision, 'timezone') - Sequence::new(vec![ - StringParser::new("DATETIME64", SyntaxKind::DataTypeIdentifier).to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), // precision - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - // DateTime('timezone') - Sequence::new(vec![ - StringParser::new("DATETIME", SyntaxKind::DataTypeIdentifier).to_matchable(), - Bracketed::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - // FixedString(length) - Sequence::new(vec![ - StringParser::new("FIXEDSTRING", SyntaxKind::DataTypeIdentifier).to_matchable(), - Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - // Array(Type) - Sequence::new(vec![ - StringParser::new("ARRAY", SyntaxKind::DataTypeIdentifier).to_matchable(), - Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]).to_matchable(), - ]) - .to_matchable(), - // Map(KeyType, ValueType) - Sequence::new(vec![ - StringParser::new("MAP", SyntaxKind::DataTypeIdentifier).to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()]).to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - // Tuple(Type1, Type2) or Tuple(name1 Type1, ...) - Sequence::new(vec![ - StringParser::new("TUPLE", SyntaxKind::DataTypeIdentifier).to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - // Named tuple element: name Type - Sequence::new(vec![ - one_of(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), + .into(), + ), + ( + "WildcardExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::WildcardExpression, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("WildcardExpressionSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("ExceptClauseSegment").optional().to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "ExceptClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SelectExceptClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("EXCEPT").to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), - // Regular tuple element: just Type - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - // Nested(name1 Type1, name2 Type2) - Sequence::new(vec![ - StringParser::new("NESTED", SyntaxKind::DataTypeIdentifier).to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), ]) .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - // JSON data type - StringParser::new("JSON", SyntaxKind::DataTypeIdentifier).to_matchable(), - // Enum8('val1' = 1, 'val2' = 2) - Sequence::new(vec![ + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SelectClauseModifierSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClauseModifier, |_dialect| { one_of(vec![ - StringParser::new("ENUM8", SyntaxKind::DataTypeIdentifier).to_matchable(), - StringParser::new("ENUM16", SyntaxKind::DataTypeIdentifier).to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("DISTINCT").to_matchable(), Sequence::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), + Ref::keyword("ALL").to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - // double args - Sequence::new(vec![ - one_of(vec![ - StringParser::new("DECIMAL", SyntaxKind::DataTypeIdentifier).to_matchable(), - StringParser::new("NUMERIC", SyntaxKind::DataTypeIdentifier).to_matchable(), - ]) - .to_matchable(), - Ref::new("BracketedArguments").optional().to_matchable(), - ]) - .to_matchable(), - // single args - Sequence::new(vec![ - one_of(vec![ - StringParser::new("DECIMAL32", SyntaxKind::DataTypeIdentifier).to_matchable(), - StringParser::new("DECIMAL64", SyntaxKind::DataTypeIdentifier).to_matchable(), - StringParser::new("DECIMAL128", SyntaxKind::DataTypeIdentifier).to_matchable(), - StringParser::new("DECIMAL256", SyntaxKind::DataTypeIdentifier).to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("TupleTypeSegment").to_matchable(), - Ref::new("DatatypeIdentifierSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Sequence::new(vec![ - StringParser::new("DATETIME64", SyntaxKind::DataTypeIdentifier).to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), // precision - Ref::new("QuotedLiteralSegment").optional().to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FromExpressionElementSegment".into(), + NodeMatcher::new(SyntaxKind::FromExpressionElement, |_dialect| { + Sequence::new(vec![ + Ref::new("PreTableFunctionKeywordsGrammar") + .optional() + .to_matchable(), + optionally_bracketed(vec![Ref::new("TableExpressionSegment").to_matchable()]) + .to_matchable(), + Ref::new("AliasExpressionSegment") + .exclude(one_of(vec![ + Ref::new("FromClauseTerminatorGrammar").to_matchable(), + Ref::new("SamplingExpressionSegment").to_matchable(), + Ref::new("JoinLikeClauseGrammar").to_matchable(), + Ref::keyword("FINAL").to_matchable(), + Ref::new("JoinClauseSegment").to_matchable(), + ])) + .optional() + .to_matchable(), + Ref::keyword("FINAL").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), + Ref::new("AliasExpressionSegment").to_matchable(), ]) - // The brackets might be empty as well .config(|this| { this.optional(); }) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - StringParser::new("ARRAY", SyntaxKind::DataTypeIdentifier).to_matchable(), - Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]).to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.add([( - "TupleTypeSegment".into(), - Sequence::new(vec![ - Ref::keyword("TUPLE").to_matchable(), - Ref::new("TupleTypeSchemaSegment").to_matchable(), - ]) - .to_matchable() - .into(), - )]); - - clickhouse_dialect.add([( - "TupleTypeSchemaSegment".into(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - .into(), - )]); - - clickhouse_dialect.replace_grammar( - "BracketedArguments", - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("DatatypeIdentifierSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.add([( - "ArrayJoinClauseSegment".into(), - NodeMatcher::new(SyntaxKind::ArrayJoinClause, |_| { - Sequence::new(vec![ - Ref::keyword("LEFT").optional().to_matchable(), - Ref::keyword("ARRAY").to_matchable(), - Ref::new("JoinKeywordsGrammar").to_matchable(), - MetaSegment::indent().to_matchable(), - Delimited::new(vec![Ref::new("SelectClauseElementSegment").to_matchable()]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - )]); - - clickhouse_dialect.replace_grammar( - "CTEDefinitionSegment", - one_of(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("CTEColumnList").optional().to_matchable(), - Ref::keyword("AS").to_matchable(), - Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) - .config(|this| this.parse_mode(ParseMode::Greedy)) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.replace_grammar( - "AliasExpressionSegment", - Sequence::new(vec![ - MetaSegment::indent().to_matchable(), - Ref::keyword("AS").optional().to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Bracketed::new(vec![Ref::new("SingleIdentifierListSegment").to_matchable()]) - .config(|this| this.optional()) + Ref::new("SamplingExpressionSegment") + .optional() + .to_matchable(), + Ref::new("PostTableExpressionGrammar") + .optional() .to_matchable(), - ]) - .to_matchable(), - Ref::new("SingleQuotedIdentifierSegment").to_matchable(), - ]) - .config(|this| { - this.exclude = one_of(vec![ - Ref::keyword("LATERAL").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::keyword("KEYS").to_matchable(), ]) .to_matchable() - .into() }) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.add([ + .to_matchable() + .into(), + ), ( - "TableEngineFunctionSegment".into(), - NodeMatcher::new(SyntaxKind::TableEngineFunction, |_| { - Sequence::new(vec![ - Ref::new("FunctionNameSegment") - .exclude(one_of(vec![ - Ref::new("DatePartFunctionNameSegment").to_matchable(), - Ref::new("ValuesClauseSegment").to_matchable(), - ])) - .to_matchable(), - Bracketed::new(vec![ - Ref::new("FunctionContentsGrammar") + "TableEngineFunctionSegment".into(), + NodeMatcher::new(SyntaxKind::TableEngineFunction, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![ + Ref::new("FunctionNameSegment") + .exclude(one_of(vec![ + Ref::new("DatePartFunctionNameSegment").to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + ])) + .to_matchable(), + Ref::new("FunctionContentsSegment") .optional() .to_matchable(), ]) - .config(|this| { - this.optional(); - this.parse_mode(ParseMode::Greedy) - }) .to_matchable(), ]) .to_matchable() @@ -1144,13 +1147,12 @@ pub fn dialect() -> Dialect { ), ( "OnClusterClauseSegment".into(), - NodeMatcher::new(SyntaxKind::OnClusterClause, |_| { + NodeMatcher::new(SyntaxKind::OnClusterClause, |_dialect| { Sequence::new(vec![ Ref::keyword("ON").to_matchable(), Ref::keyword("CLUSTER").to_matchable(), one_of(vec![ Ref::new("SingleIdentifierGrammar").to_matchable(), - // Support for placeholders like '{cluster}' Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), @@ -1162,13 +1164,13 @@ pub fn dialect() -> Dialect { ), ( "TableEngineSegment".into(), - NodeMatcher::new(SyntaxKind::Engine, |_| { + NodeMatcher::new(SyntaxKind::Engine, |_dialect| { Sequence::new(vec![ Ref::keyword("ENGINE").to_matchable(), Ref::new("EqualsSegment").optional().to_matchable(), Sequence::new(vec![ Ref::new("TableEngineFunctionSegment").to_matchable(), - any_set_of(vec![ + AnyNumberOf::new(vec![ Ref::new("MergeTreesOrderByClauseSegment").to_matchable(), Sequence::new(vec![ Ref::keyword("PARTITION").to_matchable(), @@ -1188,9 +1190,12 @@ pub fn dialect() -> Dialect { Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - Ref::new("SettingsClauseSegment").optional().to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), + Ref::new("SettingsClauseSegment").optional().to_matchable(), ]) .to_matchable(), ]) @@ -1201,28 +1206,24 @@ pub fn dialect() -> Dialect { ), ( "DatabaseEngineFunctionSegment".into(), - NodeMatcher::new(SyntaxKind::EngineFunction, |_| { + NodeMatcher::new(SyntaxKind::EngineFunction, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ATOMIC").to_matchable(), - Ref::keyword("MYSQL").to_matchable(), - Ref::keyword("MATERIALIZEDMYSQL").to_matchable(), - Ref::keyword("LAZY").to_matchable(), - Ref::keyword("POSTGRESQL").to_matchable(), - Ref::keyword("MATERIALIZEDPOSTGRESQL").to_matchable(), - Ref::keyword("REPLICATED").to_matchable(), - Ref::keyword("SQLITE").to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![ - Ref::new("FunctionContentsGrammar") + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ATOMIC").to_matchable(), + Ref::keyword("MYSQL").to_matchable(), + Ref::keyword("MATERIALIZEDMYSQL").to_matchable(), + Ref::keyword("LAZY").to_matchable(), + Ref::keyword("POSTGRESQL").to_matchable(), + Ref::keyword("MATERIALIZEDPOSTGRESQL").to_matchable(), + Ref::keyword("REPLICATED").to_matchable(), + Ref::keyword("SQLITE").to_matchable(), + ]) + .to_matchable(), + Ref::new("FunctionContentsSegment") .optional() .to_matchable(), ]) - .config(|this| { - this.parse_mode(ParseMode::Greedy); - this.optional(); - }) .to_matchable(), ]) .to_matchable() @@ -1232,38 +1233,47 @@ pub fn dialect() -> Dialect { ), ( "DatabaseEngineSegment".into(), - NodeMatcher::new(SyntaxKind::DatabaseEngine, |_| { + NodeMatcher::new(SyntaxKind::DatabaseEngine, |_dialect| { Sequence::new(vec![ Ref::keyword("ENGINE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), Sequence::new(vec![ Ref::new("DatabaseEngineFunctionSegment").to_matchable(), - any_set_of(vec![ + AnyNumberOf::new(vec![ Ref::new("MergeTreesOrderByClauseSegment").to_matchable(), Sequence::new(vec![ Ref::keyword("PARTITION").to_matchable(), Ref::keyword("BY").to_matchable(), Ref::new("ExpressionSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ Ref::keyword("PRIMARY").to_matchable(), Ref::keyword("KEY").to_matchable(), Ref::new("ExpressionSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ Ref::keyword("SAMPLE").to_matchable(), Ref::keyword("BY").to_matchable(), Ref::new("ExpressionSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("SettingsClauseSegment").optional().to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), + Ref::new("SettingsClauseSegment").optional().to_matchable(), ]) .to_matchable(), ]) @@ -1274,7 +1284,7 @@ pub fn dialect() -> Dialect { ), ( "ColumnTTLSegment".into(), - NodeMatcher::new(SyntaxKind::ColumnTtlSegment, |_| { + NodeMatcher::new(SyntaxKind::ColumnTtlSegment, |_dialect| { Sequence::new(vec![ Ref::keyword("TTL").to_matchable(), Ref::new("ExpressionSegment").to_matchable(), @@ -1286,7 +1296,7 @@ pub fn dialect() -> Dialect { ), ( "TableTTLSegment".into(), - NodeMatcher::new(SyntaxKind::TableTtlSegment, |_| { + NodeMatcher::new(SyntaxKind::TableTtlSegment, |_dialect| { Sequence::new(vec![ Ref::keyword("TTL").to_matchable(), Delimited::new(vec![ @@ -1307,7 +1317,9 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Ref::new("WhereClauseSegment").optional().to_matchable(), Ref::new("GroupByClauseSegment").optional().to_matchable(), @@ -1323,14 +1335,16 @@ pub fn dialect() -> Dialect { ), ( "ColumnConstraintSegment".into(), - NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_| { - any_set_of(vec![ + NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_dialect| { + AnyNumberOf::new(vec![ Sequence::new(vec![ Sequence::new(vec![ Ref::keyword("CONSTRAINT").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), one_of(vec![ Sequence::new(vec![ @@ -1366,7 +1380,9 @@ pub fn dialect() -> Dialect { Ref::new("FunctionSegment").to_matchable(), Ref::new("BareFunctionSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), @@ -1375,7 +1391,9 @@ pub fn dialect() -> Dialect { Ref::keyword("CODEC").to_matchable(), Ref::new("FunctionContentsGrammar").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Ref::new("ColumnTTLSegment").to_matchable(), ]) @@ -1383,401 +1401,468 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable() }) .to_matchable() .into(), ), - ]); - - clickhouse_dialect.replace_grammar( - "CreateDatabaseStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - any_set_of(vec![ - Ref::new("OnClusterClauseSegment").optional().to_matchable(), - Ref::new("DatabaseEngineSegment").optional().to_matchable(), + ( + "CreateDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateDatabaseStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - AnyNumberOf::new(vec![ - Ref::keyword("TABLE").to_matchable(), - Ref::keyword("OVERRIDE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("TableConstraintSegment").to_matchable(), - Ref::new("ColumnDefinitionSegment").to_matchable(), - Ref::new("ColumnConstraintSegment").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("OnClusterClauseSegment").optional().to_matchable(), + Ref::new("DatabaseEngineSegment").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMMENT").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - // https://clickhouse.com/docs/sql-reference/statements/rename - clickhouse_dialect.add([( - "RenameStatementSegment".into(), - NodeMatcher::new(SyntaxKind::RenameTableStatement, |_| { - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - one_of(vec![ - Sequence::new(vec![ + AnyNumberOf::new(vec![ Ref::keyword("TABLE").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("TableReferenceSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("OVERRIDE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("TableConstraintSegment").to_matchable(), + Ref::new("ColumnDefinitionSegment").to_matchable(), + Ref::new("ColumnConstraintSegment").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DATABASE").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("DatabaseReferenceSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "RenameStatementSegment".into(), + NodeMatcher::new(SyntaxKind::RenameTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DICTIONARY").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATABASE").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("DatabaseReferenceSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DICTIONARY").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Ref::new("OnClusterClauseSegment").optional().to_matchable(), ]) - .to_matchable(), - Ref::new("OnClusterClauseSegment").optional().to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - clickhouse_dialect.replace_grammar( - "CreateTableStatementSegment", - one_of(vec![ - // Regular CREATE TABLE statement - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("OnClusterClauseSegment").optional().to_matchable(), + .into(), + ), + ( + "CreateTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTableStatement, |_dialect| { one_of(vec![ - // CREATE TABLE (...): Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("TableConstraintSegment").to_matchable(), - Ref::new("ColumnDefinitionSegment").to_matchable(), - Ref::new("ColumnConstraintSegment").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("OnClusterClauseSegment").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("TableConstraintSegment").to_matchable(), + Ref::new("ColumnDefinitionSegment").to_matchable(), + Ref::new("ColumnConstraintSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("TableEngineSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("TableEngineSegment").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::new("TableEngineSegment").to_matchable(), - // CREATE TABLE (...) AS SELECT: - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("COMMENT").to_matchable(), + one_of(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("TableTTLSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.max_times_per_element = Some(1); + this.optional(); + }) .to_matchable(), + Ref::new("TableEndClauseSegment").optional().to_matchable(), ]) .to_matchable(), - // CREATE TABLE AS other_table: Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("TEMPORARY").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("TableEngineSegment").optional().to_matchable(), - ]) - .to_matchable(), - // CREATE TABLE AS table_function(): - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), one_of(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("TableConstraintSegment").to_matchable(), + Ref::new("ColumnDefinitionSegment").to_matchable(), + Ref::new("ColumnConstraintSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("TableEngineSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("TableEngineSegment").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Ref::new("TableTTLSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("TableEndClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - // CREATE TEMPORARY TABLE statement - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("TEMPORARY").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - one_of(vec![ - // CREATE TEMPORARY TABLE (...): - Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("COMMENT").to_matchable(), one_of(vec![ - Ref::new("TableConstraintSegment").to_matchable(), - Ref::new("ColumnDefinitionSegment").to_matchable(), - Ref::new("ColumnConstraintSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Ref::new("TableTTLSegment").to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("TableEngineSegment").to_matchable(), - // CREATE TEMPORARY TABLE (...) AS SELECT: - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), - ]) - .config(|this| this.optional()) + .config(|this| { + this.max_times_per_element = Some(1); + this.optional(); + }) .to_matchable(), - ]) - .to_matchable(), - // CREATE TEMPORARY TABLE AS other_table: - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("TableEngineSegment").optional().to_matchable(), - ]) - .to_matchable(), - // CREATE TEMPORARY TABLE AS table_function(): - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - ]) - .to_matchable(), - // CREATE TEMPORARY TABLE AS SELECT (without column definitions) - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), + Ref::new("TableEndClauseSegment").optional().to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - one_of(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("OnClusterClauseSegment").optional().to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + Ref::new("TableEndClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateMaterializedViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateMaterializedViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("OnClusterClauseSegment").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("TableEngineSegment").optional().to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Ref::new("TableTTLSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("TableEndClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.replace_grammar( - "CreateViewStatementSegment", - NodeMatcher::new(SyntaxKind::CreateViewStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("OnClusterClauseSegment").optional().to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), - Ref::new("TableEndClauseSegment").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable(), - ); - - clickhouse_dialect.add([( - "CreateMaterializedViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateMaterializedViewStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("OnClusterClauseSegment").optional().to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("TO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - // Add support for column list in TO clause - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), + Sequence::new(vec![ + Ref::new("TableEngineSegment").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("PARTITION").to_matchable(), + Ref::keyword("BY").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("MergeTreesOrderByClauseSegment") + .optional() + .to_matchable(), + Ref::new("TableTTLSegment").optional().to_matchable(), + Ref::new("SettingsClauseSegment").optional().to_matchable(), + Sequence::new(vec![Ref::keyword("POPULATE").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::new("TableEngineSegment").optional().to_matchable(), ]) .to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + Ref::new("TableEndClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("TEMPORARY").optional().to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("OnClusterClauseSegment").optional().to_matchable(), + Ref::keyword("SYNC").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropDatabaseStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + Ref::new("OnClusterClauseSegment").optional().to_matchable(), + Ref::keyword("SYNC").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropDictionaryStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropDictionaryStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("DICTIONARY").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("SYNC").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropUserStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropUserStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("OnClusterClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateUserStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateUserStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("OnClusterClauseSegment").optional().to_matchable(), Sequence::new(vec![ - Ref::new("TableEngineSegment").optional().to_matchable(), - // Add support for PARTITION BY clause + Ref::keyword("IDENTIFIED").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), Sequence::new(vec![ - Ref::keyword("PARTITION").to_matchable(), Ref::keyword("BY").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - // Add support for ORDER BY clause - Ref::new("MergeTreesOrderByClauseSegment") - .optional() - .to_matchable(), - // Add support for TTL clause - Ref::new("TableTTLSegment").optional().to_matchable(), - // Add support for SETTINGS clause - Ref::new("SettingsClauseSegment").optional().to_matchable(), - Ref::keyword("POPULATE").optional().to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), - Ref::new("TableEndClauseSegment").optional().to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - clickhouse_dialect.replace_grammar( - "DropTableStatementSegment", - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("TEMPORARY").optional().to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("OnClusterClauseSegment").optional().to_matchable(), - Ref::keyword("SYNC").optional().to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.replace_grammar( - "DropDatabaseStatementSegment", - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - Ref::new("OnClusterClauseSegment").optional().to_matchable(), - Ref::keyword("SYNC").optional().to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.add([( - "DropDictionaryStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropDictionaryStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("DICTIONARY").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("SYNC").optional().to_matchable(), - ]) + .into(), + ), + ( + "DropRoleStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropUserStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("OnClusterClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - clickhouse_dialect.replace_grammar( - "DropUserStatementSegment", - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("OnClusterClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.replace_grammar( - "DropRoleStatementSegment", - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("OnClusterClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.add([ + .into(), + ), ( "DropQuotaStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropQuotaStatement, |_| { + NodeMatcher::new(SyntaxKind::DropQuotaStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("DROP").to_matchable(), Ref::keyword("QUOTA").to_matchable(), @@ -1792,11 +1877,10 @@ pub fn dialect() -> Dialect { ), ( "DropSettingProfileStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropSettingProfileStatement, |_| { + NodeMatcher::new(SyntaxKind::DropSettingProfileStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("DROP").to_matchable(), Delimited::new(vec![Ref::new("NakedIdentifierSegment").to_matchable()]) - .config(|this| this.min_delimiters = 0) .to_matchable(), Ref::keyword("PROFILE").to_matchable(), Ref::new("IfExistsGrammar").optional().to_matchable(), @@ -1808,37 +1892,40 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - clickhouse_dialect.replace_grammar( - "DropViewStatementSegment", - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("OnClusterClauseSegment").optional().to_matchable(), - Ref::keyword("SYNC").optional().to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.replace_grammar( - "DropFunctionStatementSegment", - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("OnClusterClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.add([ + ( + "DropViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("OnClusterClauseSegment").optional().to_matchable(), + Ref::keyword("SYNC").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("OnClusterClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), ( "SystemMergesSegment".into(), - NodeMatcher::new(SyntaxKind::SystemMergesSegment, |_| { + NodeMatcher::new(SyntaxKind::SystemMergesSegment, |_dialect| { Sequence::new(vec![ one_of(vec![ Ref::keyword("START").to_matchable(), @@ -1864,7 +1951,7 @@ pub fn dialect() -> Dialect { ), ( "SystemTTLMergesSegment".into(), - NodeMatcher::new(SyntaxKind::SystemTtlMergesSegment, |_| { + NodeMatcher::new(SyntaxKind::SystemTtlMergesSegment, |_dialect| { Sequence::new(vec![ one_of(vec![ Ref::keyword("START").to_matchable(), @@ -1882,7 +1969,7 @@ pub fn dialect() -> Dialect { ), ( "SystemMovesSegment".into(), - NodeMatcher::new(SyntaxKind::SystemMovesSegment, |_| { + NodeMatcher::new(SyntaxKind::SystemMovesSegment, |_dialect| { Sequence::new(vec![ one_of(vec![ Ref::keyword("START").to_matchable(), @@ -1899,14 +1986,18 @@ pub fn dialect() -> Dialect { ), ( "SystemReplicaSegment".into(), - NodeMatcher::new(SyntaxKind::SystemReplicaSegment, |_| { + NodeMatcher::new(SyntaxKind::SystemReplicaSegment, |_dialect| { one_of(vec![ Sequence::new(vec![ Ref::keyword("SYNC").to_matchable(), Ref::keyword("REPLICA").to_matchable(), Ref::new("OnClusterClauseSegment").optional().to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), - Ref::keyword("STRICT").optional().to_matchable(), + Sequence::new(vec![Ref::keyword("STRICT").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ @@ -1934,7 +2025,9 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), @@ -1959,7 +2052,7 @@ pub fn dialect() -> Dialect { ), ( "SystemFilesystemSegment".into(), - NodeMatcher::new(SyntaxKind::SystemFilesystemSegment, |_| { + NodeMatcher::new(SyntaxKind::SystemFilesystemSegment, |_dialect| { Sequence::new(vec![ Ref::keyword("DROP").to_matchable(), Ref::keyword("FILESYSTEM").to_matchable(), @@ -1972,7 +2065,7 @@ pub fn dialect() -> Dialect { ), ( "SystemReplicatedSegment".into(), - NodeMatcher::new(SyntaxKind::SystemReplicatedSegment, |_| { + NodeMatcher::new(SyntaxKind::SystemReplicatedSegment, |_dialect| { Sequence::new(vec![ one_of(vec![ Ref::keyword("START").to_matchable(), @@ -1990,7 +2083,7 @@ pub fn dialect() -> Dialect { ), ( "SystemReplicationSegment".into(), - NodeMatcher::new(SyntaxKind::SystemReplicationSegment, |_| { + NodeMatcher::new(SyntaxKind::SystemReplicationSegment, |_dialect| { Sequence::new(vec![ one_of(vec![ Ref::keyword("START").to_matchable(), @@ -2008,7 +2101,7 @@ pub fn dialect() -> Dialect { ), ( "SystemFetchesSegment".into(), - NodeMatcher::new(SyntaxKind::SystemFetchesSegment, |_| { + NodeMatcher::new(SyntaxKind::SystemFetchesSegment, |_dialect| { Sequence::new(vec![ one_of(vec![ Ref::keyword("START").to_matchable(), @@ -2025,7 +2118,7 @@ pub fn dialect() -> Dialect { ), ( "SystemDistributedSegment".into(), - NodeMatcher::new(SyntaxKind::SystemDistributedSegment, |_| { + NodeMatcher::new(SyntaxKind::SystemDistributedSegment, |_dialect| { Sequence::new(vec![ one_of(vec![ Sequence::new(vec![ @@ -2055,7 +2148,7 @@ pub fn dialect() -> Dialect { ), ( "SystemModelSegment".into(), - NodeMatcher::new(SyntaxKind::SystemModelSegment, |_| { + NodeMatcher::new(SyntaxKind::SystemModelSegment, |_dialect| { Sequence::new(vec![ Ref::keyword("RELOAD").to_matchable(), one_of(vec![ @@ -2066,10 +2159,13 @@ pub fn dialect() -> Dialect { .to_matchable(), Sequence::new(vec![ Ref::keyword("MODEL").to_matchable(), - any_set_of(vec![ + AnyNumberOf::new(vec![ Ref::new("OnClusterClauseSegment").optional().to_matchable(), Ref::new("PathSegment").to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), ]) .to_matchable(), @@ -2083,7 +2179,7 @@ pub fn dialect() -> Dialect { ), ( "SystemFileSegment".into(), - NodeMatcher::new(SyntaxKind::SystemFileSegment, |_| { + NodeMatcher::new(SyntaxKind::SystemFileSegment, |_dialect| { Sequence::new(vec![ Ref::keyword("SYNC").to_matchable(), Ref::keyword("FILE").to_matchable(), @@ -2096,7 +2192,7 @@ pub fn dialect() -> Dialect { ), ( "SystemUnfreezeSegment".into(), - NodeMatcher::new(SyntaxKind::SystemUnfreezeSegment, |_| { + NodeMatcher::new(SyntaxKind::SystemUnfreezeSegment, |_dialect| { Sequence::new(vec![ Ref::keyword("UNFREEZE").to_matchable(), Ref::keyword("WITH").to_matchable(), @@ -2110,7 +2206,7 @@ pub fn dialect() -> Dialect { ), ( "SystemStatementSegment".into(), - NodeMatcher::new(SyntaxKind::SystemStatement, |_| { + NodeMatcher::new(SyntaxKind::SystemStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("SYSTEM").to_matchable(), one_of(vec![ @@ -2134,555 +2230,616 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - // https://clickhouse.com/docs/sql-reference/statements/alter - clickhouse_dialect.replace_grammar( - "AlterTableStatementSegment", - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("OnClusterClauseSegment").optional().to_matchable(), - one_of(vec![ - // ALTER TABLE ... DROP COLUMN [IF EXISTS] name + ( + "AlterTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTableStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("TABLE").to_matchable(), Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - // ALTER TABLE ... ADD COLUMN [IF NOT EXISTS] name [type] - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("OnClusterClauseSegment").optional().to_matchable(), one_of(vec![ - // Regular column with type Sequence::new(vec![ - Ref::new("DatatypeSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CODEC").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("FunctionSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CODEC").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("FunctionSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), + Sequence::new(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("ALIAS").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALIAS").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("AFTER").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FIRST").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - // Alias column with type Sequence::new(vec![ - Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("ADD").to_matchable(), Ref::keyword("ALIAS").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("FOR").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), - // Alias column without type Sequence::new(vec![ - Ref::keyword("ALIAS").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), - // Default could also be used without type Sequence::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), - // Materialized could also be used without type Sequence::new(vec![ - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ Sequence::new(vec![ - Ref::keyword("AFTER").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("MODIFY").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), - Ref::keyword("FIRST").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - // ALTER TABLE ... ADD ALIAS name FOR column_name - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("ALIAS").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("FOR").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - // ALTER TABLE ... RENAME COLUMN [IF EXISTS] name to new_name - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - // ALTER TABLE ... COMMENT COLUMN [IF EXISTS] name 'Text comment' - Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - // ALTER TABLE ... COMMENT 'Text comment' - Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - // ALTER TABLE ... MODIFY COMMENT 'Text comment' - Sequence::new(vec![ - Ref::keyword("MODIFY").to_matchable(), - Ref::keyword("COMMENT").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - // ALTER TABLE ... MODIFY COLUMN [IF EXISTS] name [TYPE] [type] - Sequence::new(vec![ - Ref::keyword("MODIFY").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - one_of(vec![ - // Type modification with explicit TYPE keyword Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CODEC").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("FunctionSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("MODIFY").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALIAS").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CODEC").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("FunctionSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar") + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.delimiter(Ref::new("CommaSegment")); + }) + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - // Type modification without TYPE keyword - Sequence::new(vec![ - Ref::new("DatatypeSegment").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ALIAS").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CODEC").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("FunctionSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Sequence::new(vec![ + Ref::new("DatatypeSegment").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALIAS").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CODEC").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("FunctionSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar") + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.delimiter(Ref::new("CommaSegment")); + }) + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALIAS").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REMOVE").to_matchable(), + Ref::keyword("ALIAS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REMOVE").to_matchable(), + one_of(vec![ + Ref::keyword("ALIAS").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("CODEC").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("TTL").to_matchable(), + ]) .to_matchable(), ]) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MODIFY").to_matchable(), + Ref::keyword("SETTING").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESET").to_matchable(), + Ref::keyword("SETTING").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable(), - // Alias modification - Sequence::new(vec![ - Ref::keyword("ALIAS").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - // Remove alias - Sequence::new(vec![ - Ref::keyword("REMOVE").to_matchable(), - Ref::new("ALIAS").to_matchable(), - ]) - .to_matchable(), - // Remove property - Sequence::new(vec![ - Ref::keyword("REMOVE").to_matchable(), one_of(vec![ - Ref::keyword("ALIAS").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("CODEC").to_matchable(), - Ref::keyword("COMMENT").to_matchable(), - Ref::keyword("TTL").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AFTER").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FIRST").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - // Modify setting - Sequence::new(vec![ - Ref::keyword("MODIFY").to_matchable(), - Ref::keyword("SETTING").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), - ]) - .to_matchable(), - // Reset setting Sequence::new(vec![ - Ref::keyword("RESET").to_matchable(), - Ref::keyword("SETTING").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), Ref::new("SingleIdentifierGrammar").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("AFTER").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FIRST").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ Sequence::new(vec![ - Ref::keyword("AFTER").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("REMOVE").to_matchable(), + Ref::keyword("TTL").to_matchable(), ]) .to_matchable(), - Ref::keyword("FIRST").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - // ALTER TABLE ... ALTER COLUMN name [TYPE] [type] - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - one_of(vec![ - // With TYPE keyword Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("MODIFY").to_matchable(), + Ref::keyword("TTL").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), - // Without TYPE keyword - one_of(vec![ Sequence::new(vec![ - Ref::keyword("AFTER").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("FIRST").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - // ALTER TABLE ... REMOVE TTL - Sequence::new(vec![ - Ref::keyword("REMOVE").to_matchable(), - Ref::keyword("TTL").to_matchable(), - ]) - .to_matchable(), - // ALTER TABLE ... MODIFY TTL expression - Sequence::new(vec![ - Ref::keyword("MODIFY").to_matchable(), - Ref::keyword("TTL").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - // ALTER TABLE ... MODIFY QUERY select_statement - Sequence::new(vec![ - Ref::keyword("MODIFY").to_matchable(), - Ref::keyword("QUERY").to_matchable(), - Ref::new("SelectStatementSegment").to_matchable(), - ]) - .to_matchable(), - // ALTER TABLE ... MATERIALIZE COLUMN col - Sequence::new(vec![ - Ref::keyword("MATERIALIZE").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - one_of(vec![ + Ref::keyword("MODIFY").to_matchable(), + Ref::keyword("QUERY").to_matchable(), + Ref::new("SelectStatementSegment").to_matchable(), + ]) + .to_matchable(), Sequence::new(vec![ - Ref::keyword("IN").to_matchable(), - Ref::keyword("PARTITION").to_matchable(), + Ref::keyword("MATERIALIZE").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("IN").to_matchable(), + Ref::keyword("PARTITION").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IN").to_matchable(), + Ref::keyword("PARTITION").to_matchable(), + Ref::keyword("ID").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + one_of(vec![ + Ref::keyword("PARTITION").to_matchable(), + Ref::keyword("PART").to_matchable(), + ]) + .to_matchable(), Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("IN").to_matchable(), + Ref::keyword("REPLACE").to_matchable(), Ref::keyword("PARTITION").to_matchable(), - Ref::keyword("ID").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) - .to_matchable(), - // ALTER TABLE ... DROP PARTITION|PART partition_expr - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StatementSegment".into(), + NodeMatcher::new(SyntaxKind::Statement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("StatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("CreateUserStatementSegment").to_matchable(), + Ref::new("CreateMaterializedViewStatementSegment").to_matchable(), + Ref::new("DropDictionaryStatementSegment").to_matchable(), + Ref::new("DropQuotaStatementSegment").to_matchable(), + Ref::new("DropSettingProfileStatementSegment").to_matchable(), + Ref::new("SystemStatementSegment").to_matchable(), + Ref::new("RenameStatementSegment").to_matchable(), + Ref::new("AlterTableStatementSegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "LimitClauseComponentSegment".into(), + NodeMatcher::new(SyntaxKind::LimitClauseComponent, |_dialect| { + optionally_bracketed(vec![ one_of(vec![ - Ref::keyword("PARTITION").to_matchable(), - Ref::keyword("PART").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - // ALTER TABLE ... REPLACE PARTITION partition_expr FROM table1 - Sequence::new(vec![ - Ref::keyword("REPLACE").to_matchable(), - Ref::keyword("PARTITION").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.replace_grammar( - "StatementSegment", - ansi::statement_segment().copy( - Some(vec![ - Ref::new("CreateMaterializedViewStatementSegment").to_matchable(), - Ref::new("DropDictionaryStatementSegment").to_matchable(), - Ref::new("DropQuotaStatementSegment").to_matchable(), - Ref::new("DropSettingProfileStatementSegment").to_matchable(), - Ref::new("SystemStatementSegment").to_matchable(), - Ref::new("RenameStatementSegment").to_matchable(), - Ref::new("AlterTableStatementSegment").to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, + .to_matchable() + }) + .to_matchable() + .into(), ), - ); - - clickhouse_dialect.add([( - "LimitClauseComponentSegment".into(), - optionally_bracketed(vec![ - one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - .into(), - )]); - - clickhouse_dialect.replace_grammar( - "LimitClauseSegment", - Sequence::new(vec![ - Ref::keyword("LIMIT").to_matchable(), - MetaSegment::indent().to_matchable(), - Sequence::new(vec![ - Ref::new("LimitClauseComponentSegment").to_matchable(), - one_of(vec![ + ( + "LimitClauseSegment".into(), + NodeMatcher::new(SyntaxKind::LimitClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("LIMIT").to_matchable(), + MetaSegment::indent().to_matchable(), Sequence::new(vec![ - Ref::keyword("OFFSET").to_matchable(), Ref::new("LimitClauseComponentSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("OFFSET").to_matchable(), + Ref::new("LimitClauseComponentSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("CommaSegment").to_matchable(), + Ref::new("LimitClauseComponentSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BY").to_matchable(), + one_of(vec![ + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FunctionContentsSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionContents, |_dialect| { + one_of(vec![ Sequence::new(vec![ - // LIMIT 1,2 only accepts constants - // and can't be bracketed like that LIMIT (1, 2) - // but can be bracketed like that LIMIT (1), (2) - Ref::new("CommaSegment").to_matchable(), - Ref::new("LimitClauseComponentSegment").to_matchable(), + Bracketed::new(vec![Ref::new("FunctionContentsGrammar").to_matchable()]) + .to_matchable(), + Bracketed::new(vec![Ref::new("FunctionContentsGrammar").to_matchable()]) + .to_matchable(), ]) .to_matchable(), + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("FunctionContentsSegment") + .match_grammar(&dialect) + .unwrap() + }, ]) - .config(|this| this.optional()) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "IntervalExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::IntervalExpression, |_dialect| { Sequence::new(vec![ - Ref::keyword("BY").to_matchable(), + Ref::keyword("INTERVAL").to_matchable(), one_of(vec![ - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - ); - - // https://clickhouse.com/docs/sql-reference/data-types/special-data-types/interval - // https://clickhouse.com/docs/sql-reference/operators#interval - clickhouse_dialect.replace_grammar( - "IntervalExpressionSegment", - Sequence::new(vec![ - Ref::keyword("INTERVAL").to_matchable(), - one_of(vec![ - // The Numeric Version - Sequence::new(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("DatetimeUnitSegment").to_matchable(), - ]) - .to_matchable(), - // The String version - Ref::new("QuotedLiteralSegment").to_matchable(), - // Combine version - Sequence::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("DatetimeUnitSegment").to_matchable(), - ]) - .to_matchable(), - // With expression as value - Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::new("DatetimeUnitSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - clickhouse_dialect.replace_grammar( - "ColumnDefinitionSegment", - Sequence::new(vec![ - one_of(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - AnyNumberOf::new(vec![ - one_of(vec![ - // DEFAULT expression - Sequence::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("DatetimeUnitSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("DatetimeUnitSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ Ref::new("ExpressionSegment").to_matchable(), + Ref::new("DatetimeUnitSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - // ALIAS expression - Sequence::new(vec![ - Ref::keyword("ALIAS").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - // MATERIALIZED expression - Sequence::new(vec![ - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ColumnDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnDefinition, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), ]) .to_matchable(), - // CODEC(...) - Sequence::new(vec![ - Ref::keyword("CODEC").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("FunctionSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + AnyNumberOf::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALIAS").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CODEC").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("FunctionSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.delimiter(Ref::new("CommaSegment")); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMMENT").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), + Ref::new("ColumnConstraintSegment").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - // COMMENT 'text' - Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - // Column constraint - Ref::new("ColumnConstraintSegment").to_matchable(), ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); + .to_matchable() + }) + .to_matchable() + .into(), + ), + ]); - clickhouse_dialect.expand(); clickhouse_dialect } diff --git a/crates/lib-dialects/src/clickhouse_keywords.rs b/crates/lib-dialects/src/clickhouse_keywords.rs index 3c96e7b6d..d722f263f 100644 --- a/crates/lib-dialects/src/clickhouse_keywords.rs +++ b/crates/lib-dialects/src/clickhouse_keywords.rs @@ -1,4 +1,88 @@ -pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ +pub(crate) const FORMAT_KEYWORDS: [&str; 81] = [ + "TABSEPARATED", + "TABSEPARATEDRAW", + "TABSEPARATEDWITHNAMES", + "TABSEPARATEDWITHNAMESANDTYPES", + "TABSEPARATEDRAWWITHNAMES", + "TABSEPARATEDRAWWITHNAMESANDTYPES", + "TEMPLATE", + "TEMPLATEIGNORESPACES", + "CSV", + "CSVWITHNAMES", + "CSVWITHNAMESANDTYPES", + "CUSTOMSEPARATED", + "CUSTOMSEPARATEDWITHNAMES", + "CUSTOMSEPARATEDWITHNAMESANDTYPES", + "SQLINSERT", + "VALUES", + "VERTICAL", + "JSON", + "JSONASSTRING", + "JSONASOBJECT", + "JSONSTRINGS", + "JSONCOLUMNS", + "JSONCOLUMNSWITHMETADATA", + "JSONCOMPACT", + "JSONCOMPACTSTRINGS", + "JSONCOMPACTCOLUMNS", + "JSONEACHROW", + "PRETTYJSONEACHROW", + "JSONEACHROWWITHPROGRESS", + "JSONSTRINGSEACHROW", + "JSONSTRINGSEACHROWWITHPROGRESS", + "JSONCOMPACTEACHROW", + "JSONCOMPACTEACHROWWITHNAMES", + "JSONCOMPACTEACHROWWITHNAMESANDTYPES", + "JSONCOMPACTSTRINGSEACHROW", + "JSONCOMPACTSTRINGSEACHROWWITHNAMES", + "JSONCOMPACTSTRINGSEACHROWWITHNAMESANDTYPES", + "JSONOBJECTEACHROW", + "BSONEACHROW", + "TSKV", + "PRETTY", + "PRETTYNOESCAPES", + "PRETTYMONOBLOCK", + "PRETTYNOESCAPESMONOBLOCK", + "PRETTYCOMPACT", + "PRETTYCOMPACTNOESCAPES", + "PRETTYCOMPACTMONOBLOCK", + "PRETTYCOMPACTNOESCAPESMONOBLOCK", + "PRETTYSPACE", + "PRETTYSPACENOESCAPES", + "PRETTYSPACEMONOBLOCK", + "PRETTYSPACENOESCAPESMONOBLOCK", + "PROMETHEUS", + "PROTOBUF", + "PROTOBUFSINGLE", + "PROTOBUFLIST", + "AVRO", + "AVROCONFLUENT", + "PARQUET", + "PARQUETMETADATA", + "ARROW", + "ARROWSTREAM", + "ORC", + "ONE", + "NPY", + "ROWBINARY", + "ROWBINARYWITHNAMES", + "ROWBINARYWITHNAMESANDTYPES", + "ROWBINARYWITHDEFAULTS", + "NATIVE", + "NULL", + "XML", + "CAPNPROTO", + "LINEASSTRING", + "REGEXP", + "RAWBLOB", + "MSGPACK", + "MYSQLDUMP", + "DWARF", + "MARKDOWN", + "FORM", +]; + +pub(crate) const UNRESERVED_KEYWORDS: [&str; 277] = [ "ADD", "AFTER", "ALIAS", @@ -77,6 +161,7 @@ pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ "HIERARCHICAL", "HOUR", "ID", + "IDENTIFIED", "IF", "ILIKE", "IN", @@ -152,7 +237,6 @@ pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ "SEMI", "SEND", "SENDS", - "SETTING", "SETTINGS", "SHOW", "SOURCE", @@ -195,4 +279,85 @@ pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ "WITH", "YEAR", "ZKPATH", + "TABSEPARATED", + "TABSEPARATEDRAW", + "TABSEPARATEDWITHNAMES", + "TABSEPARATEDWITHNAMESANDTYPES", + "TABSEPARATEDRAWWITHNAMES", + "TABSEPARATEDRAWWITHNAMESANDTYPES", + "TEMPLATE", + "TEMPLATEIGNORESPACES", + "CSV", + "CSVWITHNAMES", + "CSVWITHNAMESANDTYPES", + "CUSTOMSEPARATED", + "CUSTOMSEPARATEDWITHNAMES", + "CUSTOMSEPARATEDWITHNAMESANDTYPES", + "SQLINSERT", + "VALUES", + "VERTICAL", + "JSON", + "JSONASSTRING", + "JSONASOBJECT", + "JSONSTRINGS", + "JSONCOLUMNS", + "JSONCOLUMNSWITHMETADATA", + "JSONCOMPACT", + "JSONCOMPACTSTRINGS", + "JSONCOMPACTCOLUMNS", + "JSONEACHROW", + "PRETTYJSONEACHROW", + "JSONEACHROWWITHPROGRESS", + "JSONSTRINGSEACHROW", + "JSONSTRINGSEACHROWWITHPROGRESS", + "JSONCOMPACTEACHROW", + "JSONCOMPACTEACHROWWITHNAMES", + "JSONCOMPACTEACHROWWITHNAMESANDTYPES", + "JSONCOMPACTSTRINGSEACHROW", + "JSONCOMPACTSTRINGSEACHROWWITHNAMES", + "JSONCOMPACTSTRINGSEACHROWWITHNAMESANDTYPES", + "JSONOBJECTEACHROW", + "BSONEACHROW", + "TSKV", + "PRETTY", + "PRETTYNOESCAPES", + "PRETTYMONOBLOCK", + "PRETTYNOESCAPESMONOBLOCK", + "PRETTYCOMPACT", + "PRETTYCOMPACTNOESCAPES", + "PRETTYCOMPACTMONOBLOCK", + "PRETTYCOMPACTNOESCAPESMONOBLOCK", + "PRETTYSPACE", + "PRETTYSPACENOESCAPES", + "PRETTYSPACEMONOBLOCK", + "PRETTYSPACENOESCAPESMONOBLOCK", + "PROMETHEUS", + "PROTOBUF", + "PROTOBUFSINGLE", + "PROTOBUFLIST", + "AVRO", + "AVROCONFLUENT", + "PARQUET", + "PARQUETMETADATA", + "ARROW", + "ARROWSTREAM", + "ORC", + "ONE", + "NPY", + "ROWBINARY", + "ROWBINARYWITHNAMES", + "ROWBINARYWITHNAMESANDTYPES", + "ROWBINARYWITHDEFAULTS", + "NATIVE", + "NULL", + "XML", + "CAPNPROTO", + "LINEASSTRING", + "REGEXP", + "RAWBLOB", + "MSGPACK", + "MYSQLDUMP", + "DWARF", + "MARKDOWN", + "FORM", ]; diff --git a/crates/lib-dialects/src/databricks.rs b/crates/lib-dialects/src/databricks.rs index f8659039a..75cb34b5f 100644 --- a/crates/lib-dialects/src/databricks.rs +++ b/crates/lib-dialects/src/databricks.rs @@ -1,42 +1,125 @@ -use crate::databricks_keywords::{RESERVED_KEYWORDS, UNRESERVED_KEYWORDS}; -use crate::sparksql; -use sqruff_lib_core::helpers::Config; -use sqruff_lib_core::parser::grammar::anyof::one_of; +use sqruff_lib_core::dialects::Dialect; +use sqruff_lib_core::dialects::init::DialectKind; +use sqruff_lib_core::dialects::syntax::SyntaxKind; +use sqruff_lib_core::helpers::{Config, ToMatchable}; +use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed}; use sqruff_lib_core::parser::grammar::delimited::Delimited; -use sqruff_lib_core::parser::grammar::sequence::Bracketed; +use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence}; +use sqruff_lib_core::parser::grammar::{Anything, Ref}; +use sqruff_lib_core::parser::lexer::Matcher; use sqruff_lib_core::parser::matchable::MatchableTrait; +use sqruff_lib_core::parser::node_matcher::NodeMatcher; +use sqruff_lib_core::parser::parsers::{RegexParser, StringParser, TypedParser}; use sqruff_lib_core::parser::segments::meta::MetaSegment; -use sqruff_lib_core::{ - dialects::{Dialect, init::DialectKind}, - helpers::ToMatchable, - parser::grammar::{Ref, sequence::Sequence}, -}; + +use super::databricks_keywords::{RESERVED_KEYWORDS, UNRESERVED_KEYWORDS}; pub fn dialect() -> Dialect { - let raw_sparksql = sparksql::raw_dialect(); + raw_dialect().config(|this| this.expand()) +} - let mut databricks = sparksql::raw_dialect(); - databricks.name = DialectKind::Databricks; +pub fn raw_dialect() -> Dialect { + let sparksql_dialect = super::sparksql::raw_dialect(); + let mut databricks_dialect = sparksql_dialect.clone(); + databricks_dialect.name = DialectKind::Databricks; - databricks + databricks_dialect .sets_mut("unreserved_keywords") .extend(UNRESERVED_KEYWORDS); - databricks + + databricks_dialect .sets_mut("unreserved_keywords") - .extend(raw_sparksql.sets("reserved_keywords")); - databricks + .extend(sparksql_dialect.sets("reserved_keywords")); + + databricks_dialect .sets_mut("unreserved_keywords") - .retain(|x| !RESERVED_KEYWORDS.contains(x)); - databricks.sets_mut("reserved_keywords").clear(); - databricks + .retain(|item| !RESERVED_KEYWORDS.contains(item)); + + databricks_dialect.sets_mut("reserved_keywords").clear(); + + databricks_dialect .sets_mut("reserved_keywords") .extend(RESERVED_KEYWORDS); - databricks + databricks_dialect .sets_mut("date_part_function_name") .extend(["TIMEDIFF"]); - databricks.add([ + databricks_dialect.insert_lexer_matchers( + vec![Matcher::string( + "right_arrow", + r#"=>"#, + SyntaxKind::RightArrow, + )], + "equals", + ); + + databricks_dialect.insert_lexer_matchers( + vec![Matcher::regex( + "command", + r#"(\r?\n){2}-- COMMAND ----------(\r?\n)"#, + SyntaxKind::Command, + )], + "newline", + ); + + databricks_dialect.insert_lexer_matchers( + vec![ + Matcher::regex( + "notebook_start", + r#"-- Databricks notebook source(\r?\n){1}"#, + SyntaxKind::NotebookStart, + ), + Matcher::regex( + "magic_single_line", + r#"(-- MAGIC %)([^\n]{2,})( [^%]{1})([^\n]*)"#, + SyntaxKind::MagicSingleLine, + ), + Matcher::regex( + "magic_line", + r#"(-- MAGIC)( [^%]{1})([^\n]*)"#, + SyntaxKind::MagicLine, + ), + Matcher::regex( + "magic_start", + r#"(-- MAGIC %)([^\n]{2,})(\r?\n)"#, + SyntaxKind::MagicStart, + ), + ], + "inline_comment", + ); + + databricks_dialect.add([ + ( + "CommandCellSegment".into(), + TypedParser::new(SyntaxKind::Command, SyntaxKind::StatementTerminator) + .to_matchable() + .into(), + ), + ( + "DoubleQuotedUDFBody".into(), + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::UdfBody) + .to_matchable() + .into(), + ), + ( + "SingleQuotedUDFBody".into(), + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::UdfBody) + .to_matchable() + .into(), + ), + ( + "DollarQuotedUDFBody".into(), + TypedParser::new(SyntaxKind::DollarQuote, SyntaxKind::UdfBody) + .to_matchable() + .into(), + ), + ( + "RightArrowSegment".into(), + StringParser::new("=>", SyntaxKind::RightArrow) + .to_matchable() + .into(), + ), ( "PrincipalIdentifierSegment".into(), one_of(vec![ @@ -46,6 +129,21 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), + ( + "PredictiveOptimizationGrammar".into(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("DISABLE").to_matchable(), + Ref::keyword("INHERIT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("PREDICTIVE").to_matchable(), + Ref::keyword("OPTIMIZATION").to_matchable(), + ]) + .to_matchable() + .into(), + ), ( "SetOwnerGrammar".into(), Sequence::new(vec![ @@ -57,643 +155,2310 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - // A reference to a catalog. - // https://docs.databricks.com/data-governance/unity-catalog/create-catalogs.html ( - "CatalogReferenceSegment".into(), - Ref::new("ObjectReferenceSegment").to_matchable().into(), - ), - // An `ALTER CATALOG` statement. - // https://docs.databricks.com/sql/language-manual/sql-ref-syntax-ddl-alter-catalog.html - ( - "AlterCatalogStatementSegment".into(), + "SetTagOnGrammar".into(), Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("CATALOG").to_matchable(), - Ref::new("CatalogReferenceSegment").to_matchable(), - Ref::new("SetOwnerGrammar").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Ref::keyword("ON").to_matchable(), ]) .to_matchable() .into(), ), - // A `CREATE CATALOG` statement. - // https://docs.databricks.com/sql/language-manual/sql-ref-syntax-ddl-create-catalog.html ( - "CreateCatalogStatementSegment".into(), + "UnsetTagOnGrammar".into(), Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("CATALOG").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("CatalogReferenceSegment").to_matchable(), - Ref::new("CommentGrammar").optional().to_matchable(), + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Ref::keyword("ON").to_matchable(), ]) .to_matchable() .into(), ), - // A `DROP CATALOG` statement. - // https://docs.databricks.com/sql/language-manual/sql-ref-syntax-ddl-drop-catalog.html ( - "DropCatalogStatementSegment".into(), + "SetTagsGrammar".into(), Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("CATALOG").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("CatalogReferenceSegment").to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("TAGS").to_matchable(), + Ref::new("BracketedPropertyListGrammar").to_matchable(), ]) .to_matchable() .into(), ), - // A `USE CATALOG` statement. - // https://docs.databricks.com/sql/language-manual/sql-ref-syntax-ddl-use-catalog.html ( - "UseCatalogStatementSegment".into(), + "UnsetTagsGrammar".into(), Sequence::new(vec![ - Ref::keyword("USE").to_matchable(), - Ref::keyword("CATALOG").to_matchable(), - Ref::new("CatalogReferenceSegment").to_matchable(), + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("TAGS").to_matchable(), + Ref::new("BracketedPropertyNameListGrammar").to_matchable(), ]) .to_matchable() .into(), ), - // A `USE DATABASE` statement. - // https://docs.databricks.com/sql/language-manual/sql-ref-syntax-ddl-usedb.html ( - "UseDatabaseStatementSegment".into(), + "ColumnDefaultGrammar".into(), Sequence::new(vec![ - Ref::keyword("USE").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), one_of(vec![ - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), ]) .to_matchable() .into(), ), - // A `SET TIME ZONE` statement. - // https://docs.databricks.com/sql/language-manual/sql-ref-syntax-aux-conf-mgmt-set-timezone.html ( - "SetTimeZoneStatementSegment".into(), + "ConstraintOptionGrammar".into(), Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("TIME").to_matchable(), - Ref::keyword("ZONE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("NOVALIDATE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("ENFORCED").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![Ref::keyword("DEFERRABLE").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("DEFERRED").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), one_of(vec![ - Ref::keyword("LOCAL").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("IntervalExpressionSegment").to_matchable(), + Ref::keyword("NORELY").to_matchable(), + Ref::keyword("RELY").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() .into(), ), - // An `OPTIMIZE` statement. - // https://docs.databricks.com/en/sql/language-manual/delta-optimize.html ( - "OptimizeTableStatementSegment".into(), + "ForeignKeyOptionGrammar".into(), Sequence::new(vec![ - Ref::keyword("OPTIMIZE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("WHERE").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("MATCH").to_matchable(), + Ref::keyword("FULL").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("ZORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("UPDATE").to_matchable(), + Ref::keyword("NO").to_matchable(), + Ref::keyword("ACTION").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - // A reference to a database. - "DatabaseReferenceSegment".into(), - Ref::new("ObjectReferenceSegment").to_matchable().into(), - ), - ( - // A reference to an table, CTE, subquery or alias. - "TableReferenceSegment".into(), - Ref::new("ObjectReferenceSegment").to_matchable().into(), - ), - ( - // A reference to a schema. - "SchemaReferenceSegment".into(), - Ref::new("ObjectReferenceSegment").to_matchable().into(), - ), - ( - "IdentifierClauseSegment".into(), - Sequence::new(vec![ - Ref::keyword("IDENTIFIER").to_matchable(), - Bracketed::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - // Drop Volume Statement. - // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-ddl-drop-volume.html - "DropVolumeStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("VOLUME").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("VolumeReferenceSegment").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "VolumeReferenceSegment".into(), - Ref::new("ObjectReferenceSegment").to_matchable().into(), - ), - ( - // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-aux-describe-volume.html - "DescribeObjectGrammar".into(), - sparksql::dialect() - .grammar("DescribeObjectGrammar") - .copy( - Some(vec![ - Sequence::new(vec![ - Ref::keyword("VOLUME").to_matchable(), - Ref::new("VolumeReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]), - Some(0), - None, - None, - Vec::new(), - false, - ) - .into(), - ), - ( - // A `DECLARE [OR REPLACE] VARIABLE` statement. - // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-ddl-declare-variable.html - "DeclareOrReplaceVariableStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("DECLARE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::keyword("VARIABLE").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("DatatypeSegment").optional().to_matchable(), Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("NO").to_matchable(), + Ref::keyword("ACTION").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) .to_matchable() .into(), ), - // `COMMENT ON` statement. - // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-ddl-comment.html ( - "CommentOnStatementSegment".into(), + "DropConstraintGrammar".into(), Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::keyword("ON").to_matchable(), + Ref::keyword("DROP").to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::keyword("CATALOG").to_matchable(), - Ref::new("CatalogReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ + Ref::new("PrimaryKeyGrammar").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), one_of(vec![ - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), + Ref::keyword("RESTRICT").to_matchable(), + Ref::keyword("CASCADE").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TABLE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("VOLUME").to_matchable(), - Ref::new("VolumeReferenceSegment").to_matchable(), + Ref::new("ForeignKeyGrammar").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - // TODO Split out individual items if they have references Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), one_of(vec![ - Ref::keyword("CONNECTION").to_matchable(), - Ref::keyword("PROVIDER").to_matchable(), - Ref::keyword("RECIPIENT").to_matchable(), - Ref::keyword("SHARE").to_matchable(), + Ref::keyword("RESTRICT").to_matchable(), + Ref::keyword("CASCADE").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("IS").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::keyword("NULL").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), - // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-aux-show-schemas.html - // Differences between this and the SparkSQL version: - // - Support for `FROM`|`IN` at the catalog level - // - `LIKE` keyword is optional - ( - "ShowDatabasesSchemasGrammar".into(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DATABASES").to_matchable(), - Ref::keyword("SCHEMAS").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("IN").to_matchable(), ]) .to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LIKE").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), ]) .to_matchable() .into(), ), - // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-aux-show-schemas.html - // Differences between this and the SparkSQL version: - // - Support for `FROM`|`IN` at the catalog level - // - `LIKE` keyword is optional ( - "ShowDatabasesSchemasGrammar".into(), + "AlterPartitionGrammar".into(), Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DATABASES").to_matchable(), - Ref::keyword("SCHEMAS").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("IN").to_matchable(), + Ref::keyword("PARTITION").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + AnyNumberOf::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("SetClauseSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), ]) .to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LIKE").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) .to_matchable(), ]) .to_matchable() .into(), ), - // Show Functions Statement - // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-aux-show-functions.html - // - // Represents the grammar part after the show - // - // Differences between this and the SparkSQL version: - // - Support for `FROM`|`IN` at the schema level - // - `LIKE` keyword is optional ( - "ShowFunctionsGrammar".into(), + "RowFilterClauseGrammar".into(), Sequence::new(vec![ - one_of(vec![ - Ref::keyword("USER").to_matchable(), - Ref::keyword("SYSTEM").to_matchable(), - Ref::keyword("ALL").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Ref::keyword("FUNCTIONS").to_matchable(), - Sequence::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("IN").to_matchable(), - ]) - .to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LIKE").optional().to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("FILTER").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ one_of(vec![ - // qualified function from a database - Sequence::new(vec![ - Ref::new("DatabaseReferenceSegment").to_matchable(), - Ref::new("DotSegment").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - ]) - .config(|config| { - config.disallow_gaps(); - }) - .to_matchable(), - // non-qualified function - Ref::new("FunctionNameSegment").to_matchable(), - // Regex/like string - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), ]) .to_matchable() .into(), ), - // # https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-aux-show-tables.html - // # Differences between this and the SparkSQL version: - // # - `LIKE` keyword is optional ( - "ShowTablesGrammar".into(), - Sequence::new(vec![ - Ref::keyword("TABLES").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("IN").to_matchable(), - ]) - .to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LIKE").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable() - .into(), + "PropertiesBackTickedIdentifierSegment".into(), + RegexParser::new(r#"`.+`"#, SyntaxKind::PropertiesNakedIdentifier) + .to_matchable() + .into(), ), - // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-aux-show-views.html - // Only difference between this and the SparkSQL version: - // - `LIKE` keyword is optional ( - "ShowViewsGrammar".into(), + "LocationWithCredentialGrammar".into(), Sequence::new(vec![ - Ref::keyword("VIEWS").to_matchable(), + Ref::keyword("LOCATION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), Sequence::new(vec![ - one_of(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("IN").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Bracketed::new(vec![ + Ref::keyword("CREDENTIAL").to_matchable(), + Ref::new("PrincipalIdentifierSegment").to_matchable(), ]) .to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LIKE").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) .to_matchable() .into(), ), - // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-aux-show-volumes.html ( - "ShowObjectGrammar".into(), - sparksql::raw_dialect() - .grammar("ShowObjectGrammar") - .copy( - Some(vec![ - Sequence::new(vec![ - Ref::keyword("VOLUMES").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("IN").to_matchable(), - ]) - .to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LIKE").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ) + "NotebookStart".into(), + TypedParser::new(SyntaxKind::NotebookStart, SyntaxKind::NotebookStart) + .to_matchable() + .into(), + ), + ( + "MagicSingleLineGrammar".into(), + TypedParser::new(SyntaxKind::MagicSingleLine, SyntaxKind::MagicSingleLine) + .to_matchable() + .into(), + ), + ( + "MagicLineGrammar".into(), + TypedParser::new(SyntaxKind::MagicLine, SyntaxKind::MagicLine) + .to_matchable() + .into(), + ), + ( + "MagicStartGrammar".into(), + TypedParser::new(SyntaxKind::MagicStart, SyntaxKind::MagicStart) + .to_matchable() .into(), ), - // https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-dml-insert-into#insert-using-the-by-name-clause ( - "InsertBracketedColumnReferenceListGrammar".into(), + "VariableNameIdentifierSegment".into(), one_of(vec![ - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - Sequence::new(vec![ - Ref::keyword("BY").to_matchable(), - Ref::keyword("NAME").to_matchable(), - ]) - .to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("BackQuotedIdentifierSegment").to_matchable(), ]) .to_matchable() .into(), ), ]); - // A reference to an object. - databricks.replace_grammar( - "ObjectReferenceSegment", - Delimited::new(vec![ + databricks_dialect.replace_grammar( + "DelimiterGrammar", + one_of(vec![ + Ref::new("SemicolonSegment").to_matchable(), + Ref::new("CommandCellSegment").to_matchable(), + ]) + .to_matchable(), + ); + + databricks_dialect.replace_grammar( + "DescribeObjectGrammar", + sparksql_dialect.grammar("DescribeObjectGrammar").copy( + Some(vec![ + Sequence::new(vec![ + Ref::keyword("VOLUME").to_matchable(), + Ref::new("VolumeReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]), + Some(0), + None, + None, + vec![], + false, + ), + ); + + databricks_dialect.replace_grammar( + "FunctionContentsExpressionGrammar", + one_of(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("NamedArgumentSegment").to_matchable(), + ]) + .to_matchable(), + ); + + databricks_dialect.replace_grammar( + "PropertiesNakedIdentifierSegment", + RegexParser::new(r#"[A-Z_][A-Z0-9_]*"#, SyntaxKind::PropertiesNakedIdentifier) + .to_matchable(), + ); + + databricks_dialect.replace_grammar( + "ShowDatabasesSchemasGrammar", + Sequence::new(vec![ one_of(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("IdentifierClauseSegment").to_matchable(), + Ref::keyword("DATABASES").to_matchable(), + Ref::keyword("SCHEMAS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("IN").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("ObjectReferenceDelimiterGrammar").to_matchable(), ]) - .config(|config| { - config.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); - config.terminators = vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()]; - config.disallow_gaps(); - }) .to_matchable(), ); - // The main table expression e.g. within a FROM clause. - // Enhance to allow for additional clauses allowed in Spark and Delta Lake. - databricks.replace_grammar( - "TableExpressionSegment", - sparksql::dialect() - .grammar("TableExpressionSegment") - .match_grammar(&databricks) - .unwrap() - .copy( - Some(vec![Ref::new("IdentifierClauseSegment").to_matchable()]), - None, - Some(Ref::new("ValuesClauseSegment").to_matchable()), - None, - Vec::new(), - false, - ), + databricks_dialect.replace_grammar( + "ShowFunctionsGrammar", + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("USER").to_matchable(), + Ref::keyword("SYSTEM").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("FUNCTIONS").to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("IN").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("DatabaseReferenceSegment").to_matchable(), + Ref::new("DotSegment").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), ); - // Override statement segment - databricks.replace_grammar( - "StatementSegment", - raw_sparksql - .grammar("StatementSegment") - .match_grammar(&databricks) - .unwrap() - .copy( - Some(vec![ - Ref::new("AlterCatalogStatementSegment").to_matchable(), - Ref::new("CreateCatalogStatementSegment").to_matchable(), - Ref::new("DropCatalogStatementSegment").to_matchable(), - Ref::new("UseCatalogStatementSegment").to_matchable(), - Ref::new("DropVolumeStatementSegment").to_matchable(), - Ref::new("SetTimeZoneStatementSegment").to_matchable(), - Ref::new("OptimizeTableStatementSegment").to_matchable(), - Ref::new("CommentOnStatementSegment").to_matchable(), - Ref::new("DeclareOrReplaceVariableStatementSegment").to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ), + databricks_dialect.replace_grammar( + "ShowTablesGrammar", + Sequence::new(vec![ + Ref::keyword("TABLES").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("IN").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), ); - // Enhance `GROUP BY` clause like in `SELECT` for `CUBE`, `ROLLUP`, and `ALL`. - // https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-select-groupby.html - databricks.replace_grammar( - "GroupByClauseSegment", + databricks_dialect.replace_grammar( + "ShowViewsGrammar", Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ - Ref::keyword("ALL").to_matchable(), - Delimited::new(vec![ - Ref::new("CubeRollupClauseSegment").to_matchable(), - Ref::new("GroupingSetsClauseSegment").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - // Can `GROUP BY 1` - Ref::new("NumericLiteralSegment").optional().to_matchable(), - // Can `GROUP BY coalesce(col, 1)` - Ref::new("ExpressionSegment").optional().to_matchable(), + Ref::keyword("VIEWS").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("IN").to_matchable(), ]) .to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ); + + databricks_dialect.replace_grammar( + "ShowObjectGrammar", + sparksql_dialect.grammar("ShowObjectGrammar").copy( + Some(vec![ Sequence::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - // Can `GROUP BY 1` - Ref::new("NumericLiteralSegment").optional().to_matchable(), - // Can `GROUP BY coalesce(col, 1)` - Ref::new("ExpressionSegment").optional().to_matchable(), + Ref::keyword("VOLUMES").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("IN").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + ]) + .to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ), + ); + + databricks_dialect.replace_grammar( + "NotNullGrammar", + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + ); + + databricks_dialect.replace_grammar( + "FunctionNameIdentifierSegment", + one_of(vec![ + TypedParser::new(SyntaxKind::Word, SyntaxKind::FunctionNameIdentifier).to_matchable(), + Ref::new("BackQuotedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + ); + + databricks_dialect.replace_grammar( + "PreTableFunctionKeywordsGrammar", + one_of(vec![Ref::keyword("STREAM").to_matchable()]).to_matchable(), + ); + + databricks_dialect.replace_grammar( + "ColumnGeneratedGrammar", + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("GENERATED").to_matchable(), + Ref::keyword("ALWAYS").to_matchable(), + Ref::keyword("AS").to_matchable(), + Bracketed::new(vec![ one_of(vec![ - Ref::new("WithCubeRollupClauseSegment").to_matchable(), - Ref::new("GroupingSetsClauseSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("GENERATED").to_matchable(), + one_of(vec![ + Ref::keyword("ALWAYS").to_matchable(), + Sequence::new(vec![ + Ref::keyword("BY").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::keyword("IDENTITY").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("START").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INCREMENT").to_matchable(), + Ref::keyword("BY").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - MetaSegment::dedent().to_matchable(), ]) .to_matchable(), ); - databricks.expand(); - databricks + databricks_dialect.add([ + ( + "IdentifierClauseSegment".into(), + NodeMatcher::new(SyntaxKind::IdentifierClauseSegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("IDENTIFIER").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ObjectReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::ObjectReference, |_dialect| { + Delimited::new(vec![ + one_of(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("IdentifierClauseSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + this.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); + this.terminators = + vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()]; + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DatabaseReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::DatabaseReference, |_dialect| { + _dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&_dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "TableReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::TableReference, |_dialect| { + _dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&_dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "SchemaReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::SchemaReference, |_dialect| { + _dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&_dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "TableExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::TableExpression, |_dialect| { + { + let dialect = super::sparksql::raw_dialect(); + dialect + .grammar("TableExpressionSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![Ref::new("IdentifierClauseSegment").to_matchable()]), + None, + Some(Ref::new("ValuesClauseSegment").to_matchable()), + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "CatalogReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::CatalogReference, |_dialect| { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "VolumeReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::VolumeReference, |_dialect| { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "AlterCatalogStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterCatalogStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("CATALOG").to_matchable(), + Ref::new("CatalogReferenceSegment").to_matchable(), + one_of(vec![ + Ref::new("SetOwnerGrammar").to_matchable(), + Ref::new("SetTagsGrammar").to_matchable(), + Ref::new("UnsetTagsGrammar").to_matchable(), + Ref::new("PredictiveOptimizationGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateCatalogStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateCatalogStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("CATALOG").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("CatalogReferenceSegment").to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropCatalogStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropCatalogStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("CATALOG").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("CatalogReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UseCatalogStatementSegment".into(), + NodeMatcher::new(SyntaxKind::UseCatalogStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("USE").to_matchable(), + Ref::keyword("CATALOG").to_matchable(), + Ref::new("CatalogReferenceSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UseDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::UseDatabaseStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("USE").to_matchable(), + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterDatabaseStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("DatabasePropertiesGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("SetOwnerGrammar").to_matchable(), + Ref::new("SetTagsGrammar").to_matchable(), + Ref::new("UnsetTagsGrammar").to_matchable(), + Ref::new("PredictiveOptimizationGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterVolumeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterVolumeStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("VOLUME").to_matchable(), + Ref::new("VolumeReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("VolumeReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("SetOwnerGrammar").to_matchable(), + Ref::new("SetTagsGrammar").to_matchable(), + Ref::new("UnsetTagsGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateVolumeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateVolumeStatement, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("VOLUME").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("VolumeReferenceSegment").to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("VOLUME").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("VolumeReferenceSegment").to_matchable(), + Ref::new("LocationGrammar").to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropVolumeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropVolumeStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("VOLUME").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("VolumeReferenceSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateDatabaseStatement, |_dialect| { + { + let dialect = super::sparksql::raw_dialect(); + dialect + .grammar("CreateDatabaseStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Sequence::new(vec![ + Ref::keyword("MANAGED").optional().to_matchable(), + Ref::keyword("LOCATION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]), + Some(5), + None, + Some(vec![Ref::new("LocationGrammar").optional().to_matchable()]), + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "CreateViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateViewStatement, |_dialect| { + { + let dialect = super::sparksql::raw_dialect(); + dialect + .grammar("CreateViewStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Sequence::new(vec![ + Ref::keyword("PRIVATE").optional().to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]), + None, + Some(Ref::keyword("MATERIALIZED").optional().to_matchable()), + Some(vec![Ref::keyword("MATERIALIZED").optional().to_matchable()]), + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "MaskStatementSegment".into(), + NodeMatcher::new(SyntaxKind::MaskStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("MASK").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Ref::keyword("COLUMNS").to_matchable(), + Bracketed::new(vec![ + AnyNumberOf::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ColumnFieldDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnDefinition, |_dialect| { + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Bracketed::new(vec![Anything::new().to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("ColumnPropertiesSegment").to_matchable(), + Ref::new("ColumnConstraintSegment").to_matchable(), + Ref::new("ColumnDefaultGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "PropertyNameSegment".into(), + NodeMatcher::new(SyntaxKind::PropertyNameIdentifier, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("PropertiesNakedIdentifierSegment").to_matchable(), + Ref::new("PropertiesBackTickedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + this.delimiter(Ref::new("DotSegment")); + }) + .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::TableConstraint, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("ObjectReferenceSegment").optional().to_matchable(), + Ref::new("PrimaryKeyGrammar").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("TIMESERIES").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("ConstraintOptionGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("ObjectReferenceSegment").optional().to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("ForeignKeyGrammar").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("REFERENCES").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + one_of(vec![ + Ref::new("ForeignKeyOptionGrammar").to_matchable(), + Ref::new("ConstraintOptionGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("CHECK").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + Ref::keyword("ENFORCED").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UnsetTagStatementSegment".into(), + NodeMatcher::new(SyntaxKind::TagStatement, |_dialect| { + Sequence::new(vec![ + Ref::new("UnsetTagOnGrammar").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CATALOG").to_matchable(), + Ref::new("CatalogReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("VOLUME").to_matchable(), + Ref::new("VolumeReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::new("BackQuotedIdentifierSegment").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TagStatementSegment".into(), + NodeMatcher::new(SyntaxKind::TagStatement, |_dialect| { + Sequence::new(vec![ + Ref::new("SetTagOnGrammar").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CATALOG").to_matchable(), + Ref::new("CatalogReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("VOLUME").to_matchable(), + Ref::new("VolumeReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::new("BackQuotedIdentifierSegment").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("BackQuotedIdentifierSegment").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + one_of(vec![ + Ref::keyword("COLUMNS").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + ]) + .to_matchable(), + MetaSegment::indent().to_matchable(), + optionally_bracketed(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnFieldDefinitionSegment").to_matchable(), + Ref::new("ColumnDefaultGrammar").optional().to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + Ref::new("FirstOrAfterGrammar").optional().to_matchable(), + Ref::new("MaskStatementSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("CHANGE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + one_of(vec![ + Ref::new("CommentGrammar").to_matchable(), + Ref::new("FirstOrAfterGrammar").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("DROP").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("ColumnDefaultGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SYNC").to_matchable(), + Ref::keyword("IDENTITY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("MaskStatementSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("MASK").to_matchable(), + ]) + .to_matchable(), + Ref::new("SetTagsGrammar").to_matchable(), + Ref::new("UnsetTagsGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + one_of(vec![ + Ref::keyword("COLUMN").to_matchable(), + Ref::keyword("COLUMNS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + optionally_bracketed(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::new("TableConstraintSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("DropConstraintGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("FEATURE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TRUNCATE").to_matchable(), + Ref::keyword("HISTORY").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("AlterPartitionGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("AlterPartitionGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("AlterPartitionGrammar").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("LocationGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("AlterPartitionGrammar").to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("AlterPartitionGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RECOVER").to_matchable(), + Ref::keyword("PARTITIONS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("RowFilterClauseGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("FILTER").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("TablePropertiesGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("UnsetTablePropertiesGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("SERDE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("SERDEPROPERTIES").to_matchable(), + Ref::new("BracketedPropertyListGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("LocationGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("SetOwnerGrammar").to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("SetTagsGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("UnsetTagsGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("TableClusterByClauseSegment").to_matchable(), + Ref::new("PredictiveOptimizationGrammar").to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("MATERIALIZED").optional().to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("TablePropertiesGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("UnsetTablePropertiesGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Ref::new("SelectStatementSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + one_of(vec![ + Ref::keyword("BINDING").to_matchable(), + Ref::keyword("COMPENSATION").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TYPE").optional().to_matchable(), + Ref::keyword("EVOLUTION").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("SetOwnerGrammar").to_matchable(), + Ref::new("SetTagsGrammar").to_matchable(), + Ref::new("UnsetTagsGrammar").to_matchable(), + Sequence::new(vec![ + MetaSegment::indent().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SCHEDULE").to_matchable(), + Ref::keyword("REFRESH").optional().to_matchable(), + Ref::keyword("CRON").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AT").to_matchable(), + Ref::keyword("TIME").to_matchable(), + Ref::keyword("ZONE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("SCHEDULE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SetTimeZoneStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SetTimezoneStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("TIME").to_matchable(), + Ref::keyword("ZONE").to_matchable(), + one_of(vec![ + Ref::keyword("LOCAL").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("IntervalExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableClusterByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::TableClusterByClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::keyword("AUTO").to_matchable(), + Ref::keyword("NONE").to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "OptimizeTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::OptimizeTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("OPTIMIZE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WHERE").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ZORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StatementSegment".into(), + NodeMatcher::new(SyntaxKind::Statement, |_dialect| { + { + let dialect = super::sparksql::raw_dialect(); + dialect + .grammar("StatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("AlterCatalogStatementSegment").to_matchable(), + Ref::new("CreateCatalogStatementSegment").to_matchable(), + Ref::new("DropCatalogStatementSegment").to_matchable(), + Ref::new("UseCatalogStatementSegment").to_matchable(), + Ref::new("AlterVolumeStatementSegment").to_matchable(), + Ref::new("CreateVolumeStatementSegment").to_matchable(), + Ref::new("DropVolumeStatementSegment").to_matchable(), + Ref::new("CreateDatabaseStatementSegment").to_matchable(), + Ref::new("SetTimeZoneStatementSegment").to_matchable(), + Ref::new("OptimizeTableStatementSegment").to_matchable(), + Ref::new("CreateDatabricksFunctionStatementSegment").to_matchable(), + Ref::new("FunctionParameterListGrammarWithComments").to_matchable(), + Ref::new("DeclareOrReplaceVariableStatementSegment").to_matchable(), + Ref::new("CommentOnStatementSegment").to_matchable(), + Ref::new("TagStatementSegment").to_matchable(), + Ref::new("UnsetTagStatementSegment").to_matchable(), + Ref::new("MagicCellStatementSegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "FunctionParameterListGrammarWithComments".into(), + NodeMatcher::new(SyntaxKind::FunctionParameterListWithComments, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("FunctionParameterGrammar").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("CommentClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FunctionDefinitionGrammar".into(), + NodeMatcher::new(SyntaxKind::FunctionDefinition, |_dialect| { + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("LANGUAGE").to_matchable(), + one_of(vec![ + Ref::keyword("SQL").to_matchable(), + Ref::keyword("PYTHON").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DETERMINISTIC").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("DETERMINISTIC").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("CommentClauseSegment").optional().to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CONTAINS").to_matchable(), + Ref::keyword("SQL").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("READS").to_matchable(), + Ref::keyword("SQL").to_matchable(), + Ref::keyword("DATA").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Ref::new("DoubleQuotedUDFBody").to_matchable(), + Ref::new("SingleQuotedUDFBody").to_matchable(), + Ref::new("DollarQuotedUDFBody").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("SelectStatementSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURN").to_matchable(), + one_of(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("SelectStatementSegment").to_matchable(), + Ref::new("WithCompoundStatementSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateDatabricksFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateSqlFunctionStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammarWithComments").to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURNS").to_matchable(), + one_of(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Ref::new("CommentGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("FunctionDefinitionGrammar").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "NamedArgumentSegment".into(), + NodeMatcher::new(SyntaxKind::NamedArgument, |_dialect| { + Sequence::new(vec![ + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("RightArrowSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AliasExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::AliasExpression, |_dialect| { + Sequence::new(vec![ + MetaSegment::indent().to_matchable(), + Ref::new("AsAliasOperatorSegment").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar") + .optional() + .to_matchable(), + Bracketed::new(vec![ + Ref::new("SingleIdentifierListSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .config(|this| { + this.exclude = Some( + one_of(vec![ + Ref::keyword("LATERAL").to_matchable(), + Ref::new("JoinTypeKeywords").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::keyword("PIVOT").to_matchable(), + Ref::keyword("KEYS").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::keyword("FOR").to_matchable(), + ]) + .to_matchable(), + ); + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "GroupByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::GroupbyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Delimited::new(vec![ + Ref::new("CubeRollupClauseSegment").to_matchable(), + Ref::new("GroupingSetsClauseSegment").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::new("WithCubeRollupClauseSegment").to_matchable(), + Ref::new("GroupingSetsClauseSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ColumnConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("PrimaryKeyGrammar").to_matchable(), + Ref::new("ConstraintOptionGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("ForeignKeyGrammar").optional().to_matchable(), + Ref::keyword("REFERENCES").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + one_of(vec![ + Ref::new("ForeignKeyOptionGrammar").to_matchable(), + Ref::new("ConstraintOptionGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateTableUsingStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTableUsingStatement, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("OR").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("REPLACE").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("EXTERNAL").optional().to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("TableSpecificationSegment") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Ref::new("DataSourceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![Ref::new("TableClausesSegment").to_matchable()]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Ref::new("SelectStatementSegment").to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableSpecificationSegment".into(), + NodeMatcher::new(SyntaxKind::TableSpecificationSegment, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("ColumnPropertiesSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ColumnPropertiesSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnPropertiesSegment, |_dialect| { + one_of(vec![ + Ref::new("NotNullGrammar").to_matchable(), + Ref::new("ColumnGeneratedGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("ColumnConstraintDefaultGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentGrammar").to_matchable(), + Ref::new("ColumnConstraintSegment").to_matchable(), + Ref::new("MaskStatementSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableClausesSegment".into(), + NodeMatcher::new(SyntaxKind::TableClausesSegment, |_dialect| { + one_of(vec![ + Ref::new("PartitionClauseSegment").to_matchable(), + Ref::new("TableClusterByClauseSegment").to_matchable(), + Ref::new("LocationWithCredentialGrammar").to_matchable(), + Ref::new("OptionsGrammar").to_matchable(), + Ref::new("CommentGrammar").to_matchable(), + Ref::new("TablePropertiesGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::new("RowFilterClauseGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DeclareOrReplaceVariableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DeclareOrReplaceVariableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DECLARE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("VARIABLE").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DatatypeSegment").optional().to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CommentOnStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CommentClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("ON").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CATALOG").to_matchable(), + Ref::new("CatalogReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("VOLUME").to_matchable(), + Ref::new("VolumeReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("CONNECTION").to_matchable(), + Ref::keyword("PROVIDER").to_matchable(), + Ref::keyword("RECIPIENT").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + ]) + .to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("IS").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FunctionNameSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionName, |_dialect| { + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DotSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![Ref::new("BracketedSegment").to_matchable()]; + }) + .to_matchable(), + Ref::new("FunctionNameIdentifierSegment") + .terminators(vec![Ref::new("BracketedSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MagicCellStatementSegment".into(), + NodeMatcher::new(SyntaxKind::MagicCellSegment, |_dialect| { + Sequence::new(vec![ + Ref::new("NotebookStart").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("MagicStartGrammar").optional().to_matchable(), + AnyNumberOf::new(vec![Ref::new("MagicLineGrammar").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("MagicSingleLineGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = + vec![Ref::new("CommandCellSegment").optional().to_matchable()]; + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SetVariableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SetVariableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Ref::keyword("VAR").to_matchable(), + Ref::keyword("VARIABLE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Delimited::new(vec![ + Ref::new("VariableNameIdentifierSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + optionally_bracketed(vec![ + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Bracketed::new(vec![ + Ref::new("VariableNameIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("SelectStatementSegment").to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ]); + + databricks_dialect } diff --git a/crates/lib-dialects/src/databricks_keywords.rs b/crates/lib-dialects/src/databricks_keywords.rs index cda1bf402..9e281d660 100644 --- a/crates/lib-dialects/src/databricks_keywords.rs +++ b/crates/lib-dialects/src/databricks_keywords.rs @@ -1,5 +1,4 @@ -/// Datbricks reserved keywords which can be found https://docs.databricks.com/sql/language-manual/sql-ref-reserved-words.html -pub(crate) const RESERVED_KEYWORDS: &[&str] = &[ +pub(crate) const RESERVED_KEYWORDS: [&str; 16] = [ "ANTI", "CROSS", "EXCEPT", @@ -18,7 +17,8 @@ pub(crate) const RESERVED_KEYWORDS: &[&str] = &[ "USING", ]; -pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ +pub(crate) const UNRESERVED_KEYWORDS: [&str; 27] = [ + "AUTO", "CATALOG", "COMPENSATION", "CRON", @@ -32,12 +32,14 @@ pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ "OPTIMIZATION", "OPTIMIZE", "PREDICTIVE", + "PRIVATE", "PROVIDER", "PYTHON", "RECIPIENT", "RELY", "SCHEDULE", "SQL", + "TAG", "TAGS", "TIMESERIES", "VOLUME", diff --git a/crates/lib-dialects/src/duckdb.rs b/crates/lib-dialects/src/duckdb.rs index c0ad023a2..56050f69a 100644 --- a/crates/lib-dialects/src/duckdb.rs +++ b/crates/lib-dialects/src/duckdb.rs @@ -2,298 +2,270 @@ use sqruff_lib_core::dialects::Dialect; use sqruff_lib_core::dialects::init::DialectKind; use sqruff_lib_core::dialects::syntax::SyntaxKind; use sqruff_lib_core::helpers::{Config, ToMatchable}; -use sqruff_lib_core::parser::grammar::Ref; -use sqruff_lib_core::parser::grammar::anyof::one_of; +use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed}; use sqruff_lib_core::parser::grammar::delimited::Delimited; use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence}; +use sqruff_lib_core::parser::grammar::{Nothing, Ref}; use sqruff_lib_core::parser::lexer::Matcher; use sqruff_lib_core::parser::matchable::MatchableTrait; -use sqruff_lib_core::parser::parsers::StringParser; +use sqruff_lib_core::parser::node_matcher::NodeMatcher; +use sqruff_lib_core::parser::parsers::{RegexParser, StringParser, TypedParser}; use sqruff_lib_core::parser::segments::meta::MetaSegment; - -use crate::{ansi, postgres}; +use sqruff_lib_core::parser::types::ParseMode; pub fn dialect() -> Dialect { - raw_dialect().config(|dialect| dialect.expand()) + raw_dialect().config(|this| this.expand()) } pub fn raw_dialect() -> Dialect { - let ansi_dialect = ansi::raw_dialect(); - let postgres_dialect = postgres::dialect(); - let mut duckdb_dialect = postgres_dialect; + let ansi_dialect = super::ansi::raw_dialect(); + let postgres_dialect = super::postgres::raw_dialect(); + let mut duckdb_dialect = postgres_dialect.clone(); duckdb_dialect.name = DialectKind::Duckdb; - duckdb_dialect.add_keyword_to_set("reserved_keywords", "SUMMARIZE"); - duckdb_dialect.add_keyword_to_set("reserved_keywords", "MACRO"); + duckdb_dialect.sets_mut("reserved_keywords").extend([ + "LAMBDA", + "PIVOT", + "PIVOT_LONGER", + "PIVOT_WIDER", + "UNPIVOT", + ]); + + duckdb_dialect.sets_mut("unreserved_keywords").extend([ + "ANTI", + "APPEND", + "ASOF", + "COMPRESSION", + "COMPRESSION_LEVEL", + "GLOB", + "MACRO", + "MAP", + "OVERWRITE", + "OVERWRITE_OR_IGNORE", + "PARQUET_VERSION", + "PARTITION_BY", + "POSITIONAL", + "PROGRAM", + "ROW_GROUP_SIZE", + "ROW_GROUP_SIZE_BYTES", + "SEMI", + "STRUCT", + "VIRTUAL", + "WRITE_PARTITION_COLUMNS", + ]); duckdb_dialect.add([ ( - "SingleIdentifierGrammar".into(), - one_of(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), - Ref::new("SingleQuotedIdentifierSegment").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "DivideSegment".into(), - one_of(vec![ - StringParser::new("//", SyntaxKind::BinaryOperator).to_matchable(), - StringParser::new("/", SyntaxKind::BinaryOperator).to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "UnionGrammar".into(), - ansi_dialect - .grammar("UnionGrammar") - .copy( - Some(vec![ - Sequence::new(vec![ - Ref::keyword("BY").to_matchable(), - Ref::keyword("NAME").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ) + "LambdaArrowSegment".into(), + StringParser::new("->", SyntaxKind::LambdaArrow) + .to_matchable() .into(), ), ( - "LoadStatementSegment".into(), + "OrIgnoreGrammar".into(), Sequence::new(vec![ - Ref::keyword("LOAD").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("OR").to_matchable(), + Ref::keyword("IGNORE").to_matchable(), ]) .to_matchable() .into(), ), ( - "SummarizeStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("SUMMARIZE").to_matchable(), - one_of(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("SelectStatementSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - .into(), + "EqualsSegment_a".into(), + StringParser::new("==", SyntaxKind::ComparisonOperator) + .to_matchable() + .into(), ), ( - "DescribeStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("DESCRIBE").to_matchable(), - one_of(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("SelectStatementSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - .into(), + "UnpackingOperatorSegment".into(), + TypedParser::new(SyntaxKind::Star, SyntaxKind::Symbol) + .to_matchable() + .into(), ), - ( - "CreateMacroStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - one_of(vec![ - Ref::keyword("TEMP").to_matchable(), - Ref::keyword("TEMPORARY").to_matchable(), - ]) - .config(|config| config.optional()) - .to_matchable(), - one_of(vec![ - Ref::keyword("MACRO").to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - ]) - .to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("BaseExpressionElementGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("AS").to_matchable(), - one_of(vec![ - Ref::new("SelectStatementSegment").to_matchable(), - Ref::new("BaseExpressionElementGrammar").to_matchable(), + ]); + + duckdb_dialect.replace_grammar( + "FunctionNameIdentifierSegment", + RegexParser::new(r#"[A-Z_][A-Z0-9_$]*"#, SyntaxKind::FunctionNameIdentifier) + .anti_template("^(STRUCT|UNION|ENUM)$") + .to_matchable(), + ); + + duckdb_dialect.replace_grammar( + "DivideSegment", + one_of(vec![ + StringParser::new("//", SyntaxKind::BinaryOperator).to_matchable(), + StringParser::new("/", SyntaxKind::BinaryOperator).to_matchable(), + ]) + .to_matchable(), + ); + + duckdb_dialect.replace_grammar( + "CreateTableAsStatementSegment", + Nothing::new().to_matchable(), + ); + + duckdb_dialect.replace_grammar( + "UnionGrammar", + ansi_dialect.grammar("UnionGrammar").copy( + Some(vec![ + Sequence::new(vec![ + Ref::keyword("BY").to_matchable(), + Ref::keyword("NAME").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable() - .into(), + ]), + None, + None, + None, + vec![], + false, ), - ]); + ); - duckdb_dialect.insert_lexer_matchers( - vec![Matcher::string( - "double_divide", - "//", - SyntaxKind::DoubleDivide, - )], - "divide", + duckdb_dialect.replace_grammar( + "JoinLikeClauseGrammar", + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Ref::new("FromPivotExpressionSegment").to_matchable(), + Ref::new("FromUnpivotExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ); + + duckdb_dialect.replace_grammar( + "NonSetSelectableGrammar", + postgres_dialect.grammar("NonSetSelectableGrammar").copy( + Some(vec![ + Ref::new("SimplifiedPivotExpressionSegment").to_matchable(), + Ref::new("SimplifiedUnpivotExpressionSegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ), ); duckdb_dialect.replace_grammar( - "SelectClauseElementSegment", + "NonStandardJoinTypeKeywordsGrammar", one_of(vec![ + Ref::keyword("ANTI").to_matchable(), + Ref::keyword("SEMI").to_matchable(), Sequence::new(vec![ - Ref::new("WildcardExpressionSegment").to_matchable(), + Ref::keyword("ASOF").to_matchable(), one_of(vec![ - Sequence::new(vec![ - Ref::keyword("EXCLUDE").to_matchable(), - one_of(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("REPLACE").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("BaseExpressionElementGrammar").to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::new("JoinTypeKeywordsGrammar").to_matchable(), + Ref::keyword("ANTI").to_matchable(), + Ref::keyword("SEMI").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::new("BaseExpressionElementGrammar").to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - ]) - .to_matchable(), ]) .to_matchable(), ); duckdb_dialect.replace_grammar( - "OrderByClauseSegment", + "HorizontalJoinKeywordsGrammar", + Ref::keyword("POSITIONAL").to_matchable(), + ); + + duckdb_dialect.replace_grammar( + "FunctionContentsExpressionGrammar", + one_of(vec![ + Ref::new("LambdaExpressionSegment").to_matchable(), + Ref::new("NamedArgumentSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ); + + duckdb_dialect.replace_grammar( + "ColumnsExpressionNameGrammar", Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - MetaSegment::indent().to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("ASC").to_matchable(), - Ref::keyword("DESC").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NULLS").to_matchable(), - one_of(vec![ - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("LAST").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) + Ref::new("UnpackingOperatorSegment") + .optional() .to_matchable(), - ]) - .config(|config| { - config.allow_trailing = true; - config.terminators = vec![Ref::new("OrderByClauseTerminators").to_matchable()]; - }) - .to_matchable(), - MetaSegment::dedent().to_matchable(), + Ref::keyword("COLUMNS").to_matchable(), ]) .to_matchable(), ); duckdb_dialect.replace_grammar( - "GroupByClauseSegment", + "ColumnsExpressionGrammar", Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - MetaSegment::indent().to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|config| { - config.allow_trailing = true; - config.terminators = - vec![Ref::new("GroupByClauseTerminatorGrammar").to_matchable()]; - }) - .to_matchable(), - MetaSegment::dedent().to_matchable(), + Ref::new("ColumnsExpressionFunctionNameSegment").to_matchable(), + Ref::new("ColumnsExpressionFunctionContentsSegment").to_matchable(), ]) .to_matchable(), ); duckdb_dialect.replace_grammar( - "ObjectLiteralElementSegment", + "QuotedIdentifierSegment", + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedIdentifier).to_matchable(), + ); + + duckdb_dialect.replace_grammar( + "SingleQuotedIdentifierSegment", + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedIdentifier).to_matchable(), + ); + + duckdb_dialect.replace_grammar( + "ListComprehensionGrammar", + Ref::new("ListComprehensionExpressionSegment").to_matchable(), + ); + + duckdb_dialect.replace_grammar( + "InOperatorGrammar", Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("IN").to_matchable(), one_of(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Delimited::new(vec![Ref::new("Expression_A_Grammar").to_matchable()]) + .config(|this| { + this.allow_trailing(); + }) + .to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("ArrayLiteralSegment").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), ]) .to_matchable(), - Ref::new("ColonSegment").to_matchable(), - Ref::new("BaseExpressionElementGrammar").to_matchable(), ]) .to_matchable(), ); duckdb_dialect.replace_grammar( - "StatementSegment", - postgres::statement_segment().copy( + "ComparisonOperatorGrammar", + ansi_dialect.grammar("ComparisonOperatorGrammar").copy( Some(vec![ - Ref::new("LoadStatementSegment").to_matchable(), - Ref::new("SummarizeStatementSegment").to_matchable(), - Ref::new("DescribeStatementSegment").to_matchable(), - Ref::new("CreateMacroStatementSegment").to_matchable(), + Ref::new("EqualsSegment_a").to_matchable(), + Ref::new("GlobOperatorSegment").to_matchable(), ]), None, None, @@ -303,5 +275,1430 @@ pub fn raw_dialect() -> Dialect { ), ); + duckdb_dialect.replace_grammar( + "LikeGrammar", + postgres_dialect.grammar("LikeGrammar").copy( + Some(vec![Ref::keyword("GLOB").to_matchable()]), + None, + None, + None, + vec![], + false, + ), + ); + + duckdb_dialect.replace_grammar( + "FilterClauseGrammar", + Sequence::new(vec![ + Ref::keyword("FILTER").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::keyword("WHERE").optional().to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ); + + duckdb_dialect.insert_lexer_matchers( + vec![Matcher::string( + "double_divide", + r#"//"#, + SyntaxKind::DoubleDivide, + )], + "divide", + ); + + duckdb_dialect.patch_lexer_matchers(vec![ + Matcher::regex("single_quote", r#"'([^']|'')*'"#, SyntaxKind::SingleQuote), + Matcher::regex("double_quote", r#""([^"]|"")*""#, SyntaxKind::DoubleQuote), + Matcher::regex("equals", r#"==?"#, SyntaxKind::RawComparisonOperator), + ]); + + duckdb_dialect.add([ + ( + "StructTypeSegment".into(), + NodeMatcher::new(SyntaxKind::StructType, |_dialect| { + Sequence::new(vec![ + Ref::keyword("STRUCT").to_matchable(), + Ref::new("StructTypeSchemaSegment") + .optional() + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StructTypeSchemaSegment".into(), + NodeMatcher::new(SyntaxKind::StructTypeSchema, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MapTypeSegment".into(), + NodeMatcher::new(SyntaxKind::MapType, |_dialect| { + Sequence::new(vec![ + Ref::keyword("MAP").to_matchable(), + Ref::new("MapTypeSchemaSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MapTypeSchemaSegment".into(), + NodeMatcher::new(SyntaxKind::MapTypeSchema, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()]).to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "InsertStatementSegment".into(), + NodeMatcher::new(SyntaxKind::InsertStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("INSERT").to_matchable(), + one_of(vec![ + Ref::new("OrReplaceGrammar").to_matchable(), + Ref::new("OrIgnoreGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("AsAliasExpressionSegment") + .optional() + .to_matchable(), + one_of(vec![ + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("BY").to_matchable(), + Ref::keyword("POSITION").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BY").to_matchable(), + Ref::keyword("NAME").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("VALUES").to_matchable(), + ]) + .to_matchable(), + Ref::new("SelectStatementSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + one_of(vec![ + Ref::new("ValuesClauseSegment").to_matchable(), + optionally_bracketed(vec![ + Ref::new("SelectStatementSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("CONFLICT").to_matchable(), + Ref::new("ConflictTargetSegment").optional().to_matchable(), + Ref::new("ConflictActionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURNING").to_matchable(), + one_of(vec![ + Ref::new("StarSegment").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("AsAliasExpressionSegment") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ColumnConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CHECK").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("UNIQUE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("PRIMARY").to_matchable(), + Ref::keyword("KEY").to_matchable(), + ]) + .to_matchable(), + Ref::new("ReferenceDefinitionGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![ + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("DatatypeSegment").to_matchable(), + AnyNumberOf::new(vec![ + one_of(vec![ + Ref::new("ColumnConstraintSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("DatatypeSegment") + .exclude(Ref::keyword("AS")) + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("GENERATED").to_matchable(), + Ref::keyword("ALWAYS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("AS").to_matchable(), + Bracketed::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("STORED").to_matchable(), + Ref::keyword("VIRTUAL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("TableConstraintSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WildcardExcludeExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::WildcardExclude, |_dialect| { + Sequence::new(vec![ + Ref::keyword("EXCLUDE").to_matchable(), + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + .config(|this| { + this.allow_trailing(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WildcardReplaceExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::WildcardReplace, |_dialect| { + Sequence::new(vec![ + Ref::keyword("REPLACE").to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("BaseExpressionElementGrammar").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.allow_trailing(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("BaseExpressionElementGrammar").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WildcardRenameExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::WildcardRename, |_dialect| { + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("BaseExpressionElementGrammar").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.allow_trailing(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("BaseExpressionElementGrammar").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WildcardPatternMatchingSegment".into(), + NodeMatcher::new(SyntaxKind::WildcardPatternMatching, |_dialect| { + one_of(vec![ + Ref::new("LikeExpressionGrammar").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("LikeOperatorSegment").to_matchable(), + Ref::new("GlobOperatorSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WildcardExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::WildcardExpression, |_dialect| { + Sequence::new(vec![ + Ref::new("WildcardIdentifierSegment").to_matchable(), + Ref::new("WildcardExcludeExpressionSegment") + .optional() + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("WildcardReplaceExpressionSegment") + .optional() + .to_matchable(), + Ref::new("WildcardRenameExpressionSegment") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Ref::new("WildcardPatternMatchingSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SelectClauseElementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClauseElement, |_dialect| { + one_of(vec![ + Sequence::new(vec![Ref::new("WildcardExpressionSegment").to_matchable()]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("BaseExpressionElementGrammar").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ColumnsExpressionFunctionContentsSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionContents, |_dialect| { + Sequence::new(vec![ + Bracketed::new(vec![ + one_of(vec![ + Ref::new("WildcardExpressionSegment").to_matchable(), + Ref::new("LambdaExpressionSegment").to_matchable(), + Ref::new("BaseExpressionElementGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "LambdaExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::LambdaFunction, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("LambdaArrowSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LAMBDA").to_matchable(), + one_of(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("ColonSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ListComprehensionExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::ListComprehension, |_dialect| { + Bracketed::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("FOR").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("IF").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.bracket_type("square"); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("SelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("QualifyClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("OrderByClauseSegment").optional().to_matchable()), + None, + vec![ + Ref::new("SetOperatorSegment").to_matchable(), + Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), + Ref::new("WithDataClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("CONFLICT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("RETURNING").to_matchable(), + Ref::new("WithCheckOptionSegment").to_matchable(), + Ref::new("MetaCommandQueryBufferSegment").to_matchable(), + ], + true, + ) + }) + .to_matchable() + .into(), + ), + ( + "UnorderedSelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::new("SelectClauseSegment").to_matchable(), + Ref::new("FromClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("FromClauseSegment").to_matchable(), + Ref::new("SelectClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + Ref::new("GroupByClauseSegment").optional().to_matchable(), + Ref::new("HavingClauseSegment").optional().to_matchable(), + Ref::new("NamedWindowSegment").optional().to_matchable(), + Ref::new("QualifyClauseSegment").optional().to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::new("SetOperatorSegment").to_matchable(), + Ref::new("OrderByClauseSegment").to_matchable(), + Ref::new("LimitClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("CONFLICT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("RETURNING").to_matchable(), + ]; + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::TableReference, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("SingleQuotedIdentifierSegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "AliasExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::AliasExpression, |_dialect| { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("AliasExpressionSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "OrderByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::OrderbyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("ASC").to_matchable(), + Ref::keyword("DESC").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULLS").to_matchable(), + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("LAST").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.allow_trailing(); + this.terminators = + vec![Ref::new("OrderByClauseTerminators").to_matchable()]; + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "GroupByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::GroupbyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.allow_trailing(); + this.terminators = + vec![Ref::new("GroupByClauseTerminatorGrammar").to_matchable()]; + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "QualifyClauseSegment".into(), + NodeMatcher::new(SyntaxKind::QualifyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("QUALIFY").to_matchable(), + MetaSegment::implicit_indent().to_matchable(), + optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ObjectLiteralElementSegment".into(), + NodeMatcher::new(SyntaxKind::ObjectLiteralElement, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ColonSegment").to_matchable(), + Ref::new("BaseExpressionElementGrammar").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StatementSegment".into(), + NodeMatcher::new(SyntaxKind::Statement, |_dialect| { + { + let dialect = super::postgres::raw_dialect(); + dialect + .grammar("StatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("SimplifiedPivotExpressionSegment").to_matchable(), + Ref::new("SimplifiedUnpivotExpressionSegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "FromPivotExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::FromPivotExpression, |_dialect| { + Sequence::new(vec![ + Ref::keyword("PIVOT").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("FunctionSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FOR").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("IN").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("LiteralGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("GroupByClauseSegment").optional().to_matchable(), + Ref::new("OrderByClauseSegment").optional().to_matchable(), + Ref::new("LimitClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SimplifiedPivotExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::SimplifiedPivot, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("PIVOT").to_matchable(), + Ref::keyword("PIVOT_WIDER").to_matchable(), + ]) + .to_matchable(), + Ref::new("TableExpressionSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IN").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("LiteralGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("FunctionSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("GroupByClauseSegment").optional().to_matchable(), + Ref::new("OrderByClauseSegment").optional().to_matchable(), + Ref::new("LimitClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FromUnpivotExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::FromUnpivotExpression, |_dialect| { + Sequence::new(vec![ + Ref::keyword("UNPIVOT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("INCLUDE").to_matchable(), + Ref::keyword("NULLS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FOR").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("IN").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + optionally_bracketed(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("AliasExpressionSegment") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Ref::new("ColumnsExpressionGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SimplifiedUnpivotExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::SimplifiedUnpivot, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("UNPIVOT").to_matchable(), + Ref::keyword("PIVOT_LONGER").to_matchable(), + ]) + .to_matchable(), + Ref::new("TableExpressionSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + Ref::new("ColumnsExpressionGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::keyword("NAME").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("VALUE").to_matchable(), + Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) + .to_matchable(), + Ref::new("OrderByClauseSegment").optional().to_matchable(), + Ref::new("LimitClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + Ref::keyword("AS").to_matchable(), + one_of(vec![ + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateFunctionStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + one_of(vec![ + Ref::keyword("MACRO").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + ]) + .to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar").to_matchable(), + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + one_of(vec![ + Ref::keyword("MACRO").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TABLE").optional().to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateTypeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTypeStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENUM").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("StructTypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNION").to_matchable(), + Ref::new("StructTypeSchemaSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CopyStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CopyStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("COPY").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").optional().to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("FORMAT").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OVERWRITE_OR_IGNORE").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OVERWRITE").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPEND").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PARTITION_BY").to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("ColumnReferenceSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WRITE_PARTITION_COLUMNS") + .to_matchable(), + Ref::new("BooleanLiteralGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMPRESSION").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMPRESSION_LEVEL").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROW_GROUP_SIZE_BYTES").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROW_GROUP_SIZE").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PARQUET_VERSION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").optional().to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("FORMAT").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FREEZE").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DELIMITER").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULL").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("HEADER").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("QUOTE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ESCAPE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FORCE_QUOTE").to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("StarSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FORCE_NOT_NULL").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FORCE_NULL").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENCODING").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ArrayLiteralSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayLiteral, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("BaseExpressionElementGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + this.allow_trailing(); + }) + .to_matchable(), + ]) + .config(|this| { + this.bracket_type("square"); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ]); + duckdb_dialect } diff --git a/crates/lib-dialects/src/hive.rs b/crates/lib-dialects/src/hive.rs index c5747b3df..0078d85ae 100644 --- a/crates/lib-dialects/src/hive.rs +++ b/crates/lib-dialects/src/hive.rs @@ -1,30 +1,120 @@ +use itertools::Itertools; use sqruff_lib_core::dialects::Dialect; +use sqruff_lib_core::dialects::init::DialectKind; use sqruff_lib_core::dialects::syntax::SyntaxKind; use sqruff_lib_core::helpers::{Config, ToMatchable}; -use sqruff_lib_core::parser::grammar::Ref; -use sqruff_lib_core::parser::grammar::anyof::one_of; +use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed}; use sqruff_lib_core::parser::grammar::delimited::Delimited; use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence}; +use sqruff_lib_core::parser::grammar::{Nothing, Ref}; +use sqruff_lib_core::parser::matchable::MatchableTrait; use sqruff_lib_core::parser::node_matcher::NodeMatcher; +use sqruff_lib_core::parser::parsers::{RegexParser, StringParser, TypedParser}; +use sqruff_lib_core::parser::segments::generator::SegmentGenerator; +use sqruff_lib_core::parser::segments::meta::MetaSegment; + +use super::hive_keywords::{RESERVED_KEYWORDS, UNRESERVED_KEYWORDS}; + +pub fn dialect() -> Dialect { + raw_dialect().config(|this| this.expand()) +} pub fn raw_dialect() -> Dialect { - let mut hive_dialect = super::ansi::dialect(); + let ansi_dialect = super::ansi::raw_dialect(); + let mut hive_dialect = ansi_dialect.clone(); + hive_dialect.name = DialectKind::Hive; + + hive_dialect + .sets_mut("unreserved_keywords") + .extend(UNRESERVED_KEYWORDS); + + hive_dialect + .sets_mut("reserved_keywords") + .extend(RESERVED_KEYWORDS); + + hive_dialect.update_bracket_sets( + "angle_bracket_pairs", + vec![( + "angle", + "StartAngleBracketSegment", + "EndAngleBracketSegment", + false, + )], + ); + + hive_dialect.sets_mut("datetime_units").extend([ + "NANO", "NANOS", "SECONDS", "MINUTES", "HOURS", "DAYS", "WEEKS", "MONTHS", "YEARS", + ]); hive_dialect.add([ ( - "CommentGrammar".into(), + "StartAngleBracketSegment".into(), + StringParser::new("<", SyntaxKind::StartAngleBracket) + .to_matchable() + .into(), + ), + ( + "EndAngleBracketSegment".into(), + StringParser::new(">", SyntaxKind::EndAngleBracket) + .to_matchable() + .into(), + ), + ( + "JSONFILE".into(), + StringParser::new("JSONFILE", SyntaxKind::FileFormat) + .to_matchable() + .into(), + ), + ( + "RCFILE".into(), + StringParser::new("RCFILE", SyntaxKind::FileFormat) + .to_matchable() + .into(), + ), + ( + "SEQUENCEFILE".into(), + StringParser::new("SEQUENCEFILE", SyntaxKind::FileFormat) + .to_matchable() + .into(), + ), + ( + "TEXTFILE".into(), + StringParser::new("TEXTFILE", SyntaxKind::FileFormat) + .to_matchable() + .into(), + ), + ( + "LocationGrammar".into(), Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("LOCATION").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable() .into(), ), ( - "LocationGrammar".into(), + "PropertyGrammar".into(), Sequence::new(vec![ - Ref::keyword("LOCATION").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "BracketedPropertyListGrammar".into(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("PropertyGrammar").to_matchable()]).to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "TablePropertiesGrammar".into(), + Sequence::new(vec![ + Ref::keyword("TBLPROPERTIES").to_matchable(), + Ref::new("BracketedPropertyListGrammar").to_matchable(), ]) .to_matchable() .into(), @@ -39,6 +129,37 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), + ( + "TerminatedByGrammar".into(), + Sequence::new(vec![ + Ref::keyword("TERMINATED").to_matchable(), + Ref::keyword("BY").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "FileFormatGrammar".into(), + one_of(vec![ + Ref::keyword("SEQUENCEFILE").to_matchable(), + Ref::keyword("TEXTFILE").to_matchable(), + Ref::keyword("RCFILE").to_matchable(), + Ref::keyword("ORC").to_matchable(), + Ref::keyword("PARQUET").to_matchable(), + Ref::keyword("AVRO").to_matchable(), + Ref::keyword("JSONFILE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("INPUTFORMAT").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("OUTPUTFORMAT").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), ( "StoredAsGrammar".into(), Sequence::new(vec![ @@ -74,212 +195,1548 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "TerminatedByGrammar".into(), + "CommentGrammar".into(), Sequence::new(vec![ - Ref::keyword("TERMINATED").to_matchable(), - Ref::keyword("BY").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable() .into(), ), ( - "MsckRepairTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::MsckRepairTableStatement, |_| { - Sequence::new(vec![ - Ref::keyword("MSCK").to_matchable(), - Ref::keyword("REPAIR").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("DROP").to_matchable(), - Ref::keyword("SYNC").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("PARTITIONS").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "RowFormatClauseSegment".into(), - NodeMatcher::new(SyntaxKind::RowFormatClause, |_| { - Sequence::new(vec![ - Ref::keyword("ROW").to_matchable(), - Ref::keyword("FORMAT").to_matchable(), - one_of(vec![ + "PartitionSpecGrammar".into(), + Sequence::new(vec![ + Ref::keyword("PARTITION").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ Sequence::new(vec![ - Ref::keyword("DELIMITED").to_matchable(), - Sequence::new(vec![ - Ref::keyword("FIELDS").to_matchable(), - Ref::new("TerminatedByGrammar").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ESCAPED").to_matchable(), - Ref::keyword("BY").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLLECTION").to_matchable(), - Ref::keyword("ITEMS").to_matchable(), - Ref::new("TerminatedByGrammar").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MAP").to_matchable(), - Ref::keyword("KEYS").to_matchable(), - Ref::new("TerminatedByGrammar").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LINES").to_matchable(), - Ref::new("TerminatedByGrammar").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("NULL").to_matchable(), - Ref::keyword("DEFINED").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SERDE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("SerdePropertiesGrammar").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "StructTypeSchemaSegment".into(), - NodeMatcher::new(SyntaxKind::StructTypeSchema, |_| { - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("ColonSegment").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Ref::new("CommentGrammar").optional().to_matchable(), - ]) - .to_matchable(), ]) - .config(|_config| { - // config.bracket_type = "angle_bracket_pairs"; - }) .to_matchable(), ]) - .config(|config| { - config.bracket_pairs_set = "angle_bracket_pairs"; - config.bracket_type = "angle"; - }) - .to_matchable() - }) + .to_matchable(), + ]) .to_matchable() .into(), ), ( - "SkewedByClauseSegment".into(), - NodeMatcher::new(SyntaxKind::SkewedByClause, |_| { - Sequence::new(vec![ - Ref::keyword("SKEWED").to_matchable(), - Ref::keyword("BY").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - Ref::keyword("ON").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("LiteralGrammar").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("STORED").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::keyword("DIRECTORIES").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) + "BackQuotedIdentifierSegment".into(), + TypedParser::new(SyntaxKind::BackQuote, SyntaxKind::QuotedIdentifier) .to_matchable() - }) - .to_matchable() - .into(), + .into(), ), ]); + hive_dialect.add([( + "NakedIdentifierSegment".into(), + SegmentGenerator::new(|dialect| { + let reserved_keywords = dialect.sets("reserved_keywords"); + let pattern = reserved_keywords.iter().join("|"); + let anti_template = format!("^({pattern})$"); + RegexParser::new(r#"[A-Z0-9_]*[A-Z][A-Z0-9_]*"#, SyntaxKind::NakedIdentifier) + .anti_template(&anti_template) + .to_matchable() + }) + .into(), + )]); + hive_dialect.replace_grammar( - "StructTypeSegment", + "JoinKeywordsGrammar", Sequence::new(vec![ - Ref::keyword("STRUCT").to_matchable(), - Ref::new("StructTypeSchemaSegment") - .optional() + Sequence::new(vec![Ref::keyword("SEMI").to_matchable()]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::keyword("JOIN").to_matchable(), ]) .to_matchable(), ); hive_dialect.replace_grammar( - "ArrayTypeSegment", - Sequence::new(vec![ - Ref::keyword("ARRAY").to_matchable(), - Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) - .config(|config| { - config.bracket_type = "angle"; - config.bracket_pairs_set = "angle_bracket_pairs"; - config.optional(); - }) - .to_matchable(), + "QuotedLiteralSegment", + one_of(vec![ + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral).to_matchable(), + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedLiteral).to_matchable(), + TypedParser::new(SyntaxKind::BackQuote, SyntaxKind::QuotedLiteral).to_matchable(), ]) .to_matchable(), ); + hive_dialect.replace_grammar("TrimParametersGrammar", Nothing::new().to_matchable()); + + hive_dialect.replace_grammar( + "SingleIdentifierGrammar", + ansi_dialect.grammar("SingleIdentifierGrammar").copy( + Some(vec![Ref::new("BackQuotedIdentifierSegment").to_matchable()]), + None, + None, + None, + vec![], + false, + ), + ); + + hive_dialect.replace_grammar( + "SelectClauseTerminatorGrammar", + ansi_dialect.grammar("SelectClauseTerminatorGrammar").copy( + Some(vec![ + Sequence::new(vec![ + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DISTRIBUTE").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SORT").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + ]), + None, + Some( + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + ), + None, + vec![], + false, + ), + ); + + hive_dialect.replace_grammar( + "FromClauseTerminatorGrammar", + ansi_dialect.grammar("FromClauseTerminatorGrammar").copy( + Some(vec![ + Sequence::new(vec![ + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DISTRIBUTE").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SORT").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + ]), + None, + Some( + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + ), + None, + vec![], + false, + ), + ); + + hive_dialect.replace_grammar( + "WhereClauseTerminatorGrammar", + ansi_dialect.grammar("WhereClauseTerminatorGrammar").copy( + Some(vec![ + Sequence::new(vec![ + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DISTRIBUTE").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SORT").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + ]), + None, + Some( + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + ), + None, + vec![], + false, + ), + ); + + hive_dialect.replace_grammar( + "GroupByClauseTerminatorGrammar", + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("DISTRIBUTE").to_matchable(), + Ref::keyword("SORT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + ]) + .to_matchable(), + ); + + hive_dialect.replace_grammar( + "HavingClauseTerminatorGrammar", + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("DISTRIBUTE").to_matchable(), + Ref::keyword("SORT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + ]) + .to_matchable(), + ); + + hive_dialect.replace_grammar( + "AlterTableOptionsGrammar", + ansi_dialect.grammar("AlterTableOptionsGrammar").copy( + Some(vec![ + Sequence::new(vec![ + Ref::keyword("EXCHANGE").to_matchable(), + Ref::new("PartitionSpecGrammar").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ), + ); + + hive_dialect.replace_grammar( + "LikeGrammar", + one_of(vec![ + Ref::keyword("LIKE").to_matchable(), + Ref::keyword("RLIKE").to_matchable(), + Ref::keyword("ILIKE").to_matchable(), + Ref::keyword("REGEXP").to_matchable(), + Ref::keyword("IREGEXP").to_matchable(), + ]) + .to_matchable(), + ); + + hive_dialect.add([ + ( + "ArrayTypeSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayType, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ARRAY").to_matchable(), + Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .config(|this| { + this.optional(); + this.bracket_type("angle"); + this.bracket_pairs_set = "angle_bracket_pairs"; + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "EqualsSegment".into(), + NodeMatcher::new(SyntaxKind::ComparisonOperator, |_dialect| { + Sequence::new(vec![ + Ref::new("RawEqualsSegment").to_matchable(), + Ref::new("RawEqualsSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StructTypeSegment".into(), + NodeMatcher::new(SyntaxKind::StructType, |_dialect| { + Sequence::new(vec![ + Ref::keyword("STRUCT").to_matchable(), + Ref::new("StructTypeSchemaSegment") + .optional() + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StructTypeSchemaSegment".into(), + NodeMatcher::new(SyntaxKind::StructTypeSchema, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ColonSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.bracket_type("angle"); + this.bracket_pairs_set = "angle_bracket_pairs"; + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateDatabaseStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + Ref::new("LocationGrammar").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("MANAGEDLOCATION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("DBPROPERTIES").to_matchable(), + Ref::new("BracketedPropertyListGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("TEMPORARY").optional().to_matchable(), + Ref::keyword("EXTERNAL").optional().to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("TableConstraintSegment") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::new("ColumnDefinitionSegment").to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + Ref::new("StoredAsGrammar").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("PARTITIONED").to_matchable(), + Ref::keyword("BY").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnDefinitionSegment").to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CLUSTERED").to_matchable(), + Ref::keyword("BY").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SORTED").to_matchable(), + Ref::keyword("BY").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + one_of(vec![ + Ref::keyword("ASC").to_matchable(), + Ref::keyword("DESC").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("BUCKETS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("StoredAsGrammar").optional().to_matchable(), + Ref::new("SkewedByClauseSegment").optional().to_matchable(), + Ref::new("StorageFormatGrammar").optional().to_matchable(), + Ref::new("LocationGrammar").optional().to_matchable(), + Ref::new("TablePropertiesGrammar").optional().to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![ + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("LocationGrammar").optional().to_matchable(), + Ref::new("TablePropertiesGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::TableConstraint, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("UNIQUE").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("PrimaryKeyGrammar").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DISABLE").to_matchable(), + Ref::keyword("NOVALIDATE").to_matchable(), + one_of(vec![ + Ref::keyword("RELY").to_matchable(), + Ref::keyword("NORELY").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("ForeignKeyGrammar").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::new("ReferenceDefinitionGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DISABLE").to_matchable(), + Ref::keyword("NOVALIDATE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FromExpressionElementSegment".into(), + NodeMatcher::new(SyntaxKind::FromExpressionElement, |_dialect| { + Sequence::new(vec![ + Ref::new("PreTableFunctionKeywordsGrammar") + .optional() + .to_matchable(), + optionally_bracketed(vec![Ref::new("TableExpressionSegment").to_matchable()]) + .to_matchable(), + Ref::new("TemporalQuerySegment").optional().to_matchable(), + Ref::new("AliasExpressionSegment") + .exclude(one_of(vec![ + Ref::new("FromClauseTerminatorGrammar").to_matchable(), + Ref::new("SamplingExpressionSegment").to_matchable(), + Ref::new("JoinLikeClauseGrammar").to_matchable(), + Ref::new("JoinClauseSegment").to_matchable(), + ])) + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), + Ref::new("AliasExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("SamplingExpressionSegment") + .optional() + .to_matchable(), + Ref::new("PostTableExpressionGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable() + .copy( + Some(vec![ + AnyNumberOf::new(vec![Ref::new("LateralViewClauseSegment").to_matchable()]) + .to_matchable(), + ]), + None, + Some( + Ref::new("PostTableExpressionGrammar") + .optional() + .to_matchable(), + ), + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "AliasExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::AliasExpression, |_dialect| { + Sequence::new(vec![ + MetaSegment::indent().to_matchable(), + Ref::new("AsAliasOperatorSegment").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar") + .optional() + .to_matchable(), + Bracketed::new(vec![ + Ref::new("SingleIdentifierListSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "LateralViewClauseSegment".into(), + NodeMatcher::new(SyntaxKind::LateralViewClause, |_dialect| { + Sequence::new(vec![ + MetaSegment::indent().to_matchable(), + Ref::keyword("LATERAL").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::keyword("OUTER").optional().to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "PrimitiveTypeSegment".into(), + NodeMatcher::new(SyntaxKind::PrimitiveType, |_dialect| { + one_of(vec![ + Ref::keyword("TINYINT").to_matchable(), + Ref::keyword("SMALLINT").to_matchable(), + Ref::keyword("INT").to_matchable(), + Ref::keyword("INTEGER").to_matchable(), + Ref::keyword("BIGINT").to_matchable(), + Ref::keyword("BOOLEAN").to_matchable(), + Ref::keyword("FLOAT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DOUBLE").to_matchable(), + Ref::keyword("PRECISION").optional().to_matchable(), + ]) + .to_matchable(), + Ref::keyword("STRING").to_matchable(), + Ref::keyword("BINARY").to_matchable(), + Ref::keyword("TIMESTAMP").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DECIMAL").to_matchable(), + Ref::keyword("DEC").to_matchable(), + Ref::keyword("NUMERIC").to_matchable(), + ]) + .to_matchable(), + Ref::new("BracketedArguments").optional().to_matchable(), + ]) + .to_matchable(), + Ref::keyword("DATE").to_matchable(), + Ref::keyword("VARCHAR").to_matchable(), + Ref::keyword("CHAR").to_matchable(), + Ref::keyword("JSON").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DatatypeSegment".into(), + NodeMatcher::new(SyntaxKind::DataType, |_dialect| { + one_of(vec![ + Ref::new("PrimitiveTypeSegment").to_matchable(), + Ref::new("ArrayTypeSegment").to_matchable(), + Ref::new("SizedArrayTypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MAP").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::new("PrimitiveTypeSegment").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.bracket_type("angle"); + this.bracket_pairs_set = "angle_bracket_pairs"; + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("StructTypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNIONTYPE").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.bracket_type("angle"); + this.bracket_pairs_set = "angle_bracket_pairs"; + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SkewedByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SkewedByClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("SKEWED").to_matchable(), + Ref::keyword("BY").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::keyword("ON").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("LiteralGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STORED").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::keyword("DIRECTORIES").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "RowFormatClauseSegment".into(), + NodeMatcher::new(SyntaxKind::RowFormatClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("FORMAT").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("DELIMITED").to_matchable(), + Sequence::new(vec![ + Ref::keyword("FIELDS").to_matchable(), + Ref::new("TerminatedByGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ESCAPED").to_matchable(), + Ref::keyword("BY").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLLECTION").to_matchable(), + Ref::keyword("ITEMS").to_matchable(), + Ref::new("TerminatedByGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MAP").to_matchable(), + Ref::keyword("KEYS").to_matchable(), + Ref::new("TerminatedByGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LINES").to_matchable(), + Ref::new("TerminatedByGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULL").to_matchable(), + Ref::keyword("DEFINED").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SERDE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("SerdePropertiesGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterDatabaseStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("DBPROPERTIES").to_matchable(), + Ref::new("BracketedPropertyListGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + one_of(vec![ + Ref::keyword("USER").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + ]) + .to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("LocationGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MANAGEDLOCATION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("PURGE").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TruncateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::TruncateStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("TRUNCATE").to_matchable(), + Ref::keyword("TABLE").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("PartitionSpecGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SetStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SetStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + StringParser::new("-", SyntaxKind::OptionIndicator).to_matchable(), + StringParser::new("v", SyntaxKind::Option).to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()]) + .config(|this| { + this.disallow_gaps(); + this.delimiter(one_of(vec![ + Ref::new("DotSegment").to_matchable(), + Ref::new("ColonDelimiterSegment").to_matchable(), + ])); + }) + .to_matchable(), + Ref::new("RawEqualsSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StatementSegment".into(), + NodeMatcher::new(SyntaxKind::Statement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("StatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("AlterDatabaseStatementSegment").to_matchable(), + Ref::new("MsckRepairTableStatementSegment").to_matchable(), + Ref::new("MsckTableStatementSegment").to_matchable(), + Ref::new("SetStatementSegment").to_matchable(), + Ref::new("AlterViewStatementSegment").to_matchable(), + ]), + None, + None, + Some(vec![ + Ref::new("TransactionStatementSegment").to_matchable(), + Ref::new("CreateSchemaStatementSegment").to_matchable(), + Ref::new("SetSchemaStatementSegment").to_matchable(), + Ref::new("CreateModelStatementSegment").to_matchable(), + Ref::new("DropModelStatementSegment").to_matchable(), + ]), + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "InsertStatementSegment".into(), + NodeMatcher::new(SyntaxKind::InsertStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("INSERT").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("OVERWRITE").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("PartitionSpecGrammar").optional().to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![Ref::keyword("LOCAL").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("DIRECTORY").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("RowFormatClauseSegment").optional().to_matchable(), + Ref::new("StoredAsGrammar").optional().to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INTO").to_matchable(), + Ref::keyword("TABLE").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("PartitionSpecGrammar").optional().to_matchable(), + one_of(vec![ + Ref::new("SelectableGrammar").to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "IntervalExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::IntervalExpression, |_dialect| { + Sequence::new(vec![ + Ref::keyword("INTERVAL").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("DatetimeUnitSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TO").to_matchable(), + Ref::new("DatetimeUnitSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MsckRepairTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::MsckRepairTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("MSCK").to_matchable(), + Ref::keyword("REPAIR").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("SYNC").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("PARTITIONS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MsckTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::MsckTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("MSCK").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("SYNC").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("PARTITIONS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "RowFunctionContentsSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionContents, |_dialect| { + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("BaseExpressionElementGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FunctionSegment".into(), + NodeMatcher::new(SyntaxKind::Function, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Sequence::new(vec![ + Ref::new("DatePartFunctionNameSegment").to_matchable(), + Ref::new("DateTimeFunctionContentsSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + StringParser::new("ROW", SyntaxKind::FunctionName).to_matchable(), + Ref::new("RowFunctionContentsSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DatatypeSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::new("FunctionNameSegment") + .exclude(one_of(vec![ + Ref::new("DatePartFunctionNameSegment").to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + ])) + .to_matchable(), + Ref::new("FunctionContentsSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("PostFunctionGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SamplingExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::SampleExpression, |_dialect| { + Sequence::new(vec![ + Ref::keyword("TABLESAMPLE").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("BUCKET").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("OUT").to_matchable(), + Ref::keyword("OF").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + one_of(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + one_of(vec![ + Ref::keyword("PERCENT").to_matchable(), + Ref::keyword("ROWS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + RegexParser::new(r#"\d+[bBkKmMgG]"#, SyntaxKind::ByteLengthLiteral) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UnorderedSelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("UnorderedSelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + None, + None, + None, + None, + vec![ + Ref::new("ClusterByClauseSegment").to_matchable(), + Ref::new("DistributeByClauseSegment").to_matchable(), + Ref::new("SortByClauseSegment").to_matchable(), + ], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "SelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("SelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("ClusterByClauseSegment").optional().to_matchable(), + Ref::new("DistributeByClauseSegment") + .optional() + .to_matchable(), + Ref::new("SortByClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("LimitClauseSegment").optional().to_matchable()), + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "SelectClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClause, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("SelectClauseSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + None, + None, + None, + None, + vec![ + Sequence::new(vec![ + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DISTRIBUTE").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SORT").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + ], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "SetExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::SetExpression, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("SetExpressionSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("ClusterByClauseSegment").optional().to_matchable(), + Ref::new("DistributeByClauseSegment") + .optional() + .to_matchable(), + Ref::new("SortByClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("LimitClauseSegment").optional().to_matchable()), + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "ClusterByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ClusterbyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("LIMIT").to_matchable(), + Ref::new("FrameClauseUnitGrammar").to_matchable(), + ]; + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DistributeByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::DistributebyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DISTRIBUTE").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("SORT").to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::new("FrameClauseUnitGrammar").to_matchable(), + Ref::keyword("SEPARATOR").to_matchable(), + ]; + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SortByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SortbyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("SORT").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("ASC").to_matchable(), + Ref::keyword("DESC").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULLS").to_matchable(), + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("LAST").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("LIMIT").to_matchable(), + Ref::new("FrameClauseUnitGrammar").to_matchable(), + ]; + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("TablePropertiesGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![ + Ref::new("SelectStatementSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ]); + hive_dialect } diff --git a/crates/lib-dialects/src/hive_keywords.rs b/crates/lib-dialects/src/hive_keywords.rs new file mode 100644 index 000000000..af0ea6c7c --- /dev/null +++ b/crates/lib-dialects/src/hive_keywords.rs @@ -0,0 +1,340 @@ +pub(crate) const RESERVED_KEYWORDS: [&str; 141] = [ + "ALL", + "ALTER", + "AND", + "ARRAY", + "AS", + "AUTHORIZATION", + "BETWEEN", + "BIGINT", + "BINARY", + "BOOLEAN", + "BOTH", + "BY", + "CASE", + "CAST", + "CHAR", + "COLUMN", + "CONF", + "CREATE", + "CROSS", + "CUBE", + "CURRENT", + "CURRENT_DATE", + "CURRENT_TIMESTAMP", + "CURSOR", + "DATABASE", + "DATE", + "DEC", + "DECIMAL", + "DELETE", + "DESCRIBE", + "DISTINCT", + "DOUBLE", + "DROP", + "ELSE", + "END", + "EXCHANGE", + "EXISTS", + "EXTENDED", + "EXTERNAL", + "FALSE", + "FETCH", + "FLOAT", + "FOLLOWING", + "FOR", + "FROM", + "FULL", + "FUNCTION", + "GRANT", + "GROUP", + "GROUPING", + "HAVING", + "IF", + "IMPORT", + "IN", + "INNER", + "INSERT", + "INT", + "INTEGER", + "INTERSECT", + "INTERVAL", + "INTO", + "IS", + "JOIN", + "LATERAL", + "LEFT", + "LESS", + "LIKE", + "LOCAL", + "MACRO", + "MAP", + "MORE", + "NONE", + "NOT", + "NULL", + "NUMERIC", + "OF", + "ON", + "OR", + "ORDER", + "OUT", + "OUTER", + "OVER", + "PARTIALSCAN", + "PARTITION", + "PERCENT", + "PRECEDING", + "PRESERVE", + "PROCEDURE", + "RANGE", + "READS", + "REDUCE", + "REVOKE", + "RIGHT", + "ROLLUP", + "ROW", + "ROWS", + "SELECT", + "SET", + "SMALLINT", + "TABLE", + "TABLESAMPLE", + "THEN", + "TIMESTAMP", + "TO", + "TRANSFORM", + "TRIGGER", + "TRUE", + "TRUNCATE", + "UNBOUNDED", + "UNION", + "UNIQUEJOIN", + "UPDATE", + "USER", + "USING", + "UTC_TMESTAMP", + "VALUES", + "VARCHAR", + "WHEN", + "WHERE", + "WINDOW", + "WITH", + "COMMIT", + "ONLY", + "REGEXP", + "RLIKE", + "ROLLBACK", + "START", + "CACHE", + "CONSTRAINT", + "FOREIGN", + "PRIMARY", + "REFERENCES", + "DAYOFWEEK", + "EXTRACT", + "FLOOR", + "INTEGER", + "PRECISION", + "VIEWS", + "TIME", + "NUMERIC", + "SYNC", +]; + +pub(crate) const UNRESERVED_KEYWORDS: [&str; 194] = [ + "ADD", + "ADMIN", + "AFTER", + "ANALYZE", + "ARCHIVE", + "ASC", + "BEFORE", + "BERNOULLI", + "BUCKET", + "BUCKETS", + "CASCADE", + "CHANGE", + "CLUSTER", + "CLUSTERED", + "CLUSTERSTATUS", + "COLLECTION", + "COLUMNS", + "COMMENT", + "COMPACT", + "COMPACTIONS", + "COMPUTE", + "CONCATENATE", + "CONTINUE", + "DATA", + "DATABASES", + "DATETIME", + "DAY", + "DBPROPERTIES", + "DEFERRED", + "DEFINED", + "DELIMITED", + "DEPENDENCY", + "DESC", + "DIRECTORIES", + "DIRECTORY", + "DISABLE", + "DISTRIBUTE", + "ELEM_TYPE", + "ENABLE", + "ESCAPED", + "EXCLUSIVE", + "EXPLAIN", + "EXPORT", + "FIELDS", + "FILE", + "FILEFORMAT", + "FIRST", + "FORMAT", + "FORMATTED", + "FUNCTIONS", + "HOLD_DDLTIME", + "HOUR", + "IDXPROPERTIES", + "IGNORE", + "INDEX", + "INDEXES", + "INPATH", + "INPUTDRIVER", + "INPUTFORMAT", + "IREGEXP", + "ITEMS", + "JAR", + "KEYS", + "KEY_TYPE", + "LIMIT", + "LINES", + "LOAD", + "LOCATION", + "LOCK", + "LOCKS", + "LOGICAL", + "LONG", + "MAPJOIN", + "MATERIALIZED", + "METADATA", + "MINUS", + "MINUTE", + "MONTH", + "MSCK", + "NOSCAN", + "NO_DROP", + "OFFLINE", + "OPTION", + "OUTPUTDRIVER", + "OUTPUTFORMAT", + "OVERWRITE", + "OWNER", + "PARTITIONED", + "PARTITIONS", + "PLUS", + "PRETTY", + "PRINCIPALS", + "PROTECTION", + "PURGE", + "READ", + "READONLY", + "REBUILD", + "RECORDREADER", + "RECORDWRITER", + "REGEXP", + "RELOAD", + "RENAME", + "REPAIR", + "REPEATABLE", + "REPLACE", + "REPLICATION", + "RESTRICT", + "REWRITE", + "RLIKE", + "ROLE", + "ROLES", + "SCHEMA", + "SCHEMAS", + "SECOND", + "SEMI", + "SERDE", + "SERDEPROPERTIES", + "SERVER", + "SETS", + "SHARED", + "SHOW", + "SHOW_DATABASE", + "SKEWED", + "SORT", + "SORTED", + "SSL", + "STATISTICS", + "STORED", + "STREAMTABLE", + "STRING", + "STRUCT", + "SYSTEM", + "TABLES", + "TBLPROPERTIES", + "TEMPORARY", + "TERMINATED", + "TINYINT", + "TOUCH", + "TRANSACTIONS", + "UNARCHIVE", + "UNDO", + "UNIONTYPE", + "UNLOCK", + "UNSET", + "UNSIGNED", + "URI", + "USE", + "UTC", + "UTCTIMESTAMP", + "VALUE_TYPE", + "VIEW", + "WHILE", + "YEAR", + "AUTOCOMMIT", + "ISOLATION", + "LEVEL", + "OFFSET", + "SNAPSHOT", + "TRANSACTION", + "WORK", + "WRITE", + "ABORT", + "KEY", + "LAST", + "NORELY", + "NOVALIDATE", + "NULLS", + "RELY", + "VALIDATE", + "DETAIL", + "DOW", + "EXPRESSION", + "OPERATOR", + "QUARTER", + "SUMMARY", + "VECTORIZATION", + "WEEK", + "YEARS", + "MONTHS", + "WEEKS", + "DAYS", + "HOURS", + "MINUTES", + "SECONDS", + "TIMESTAMPTZ", + "ZONE", + "SEQUENCEFILE", + "TEXTFILE", + "RCFILE", + "ORC", + "PARQUET", + "AVRO", + "JSONFILE", + "MANAGEDLOCATION", +]; diff --git a/crates/lib-dialects/src/lib.rs b/crates/lib-dialects/src/lib.rs index dd6f96548..b2e17df29 100644 --- a/crates/lib-dialects/src/lib.rs +++ b/crates/lib-dialects/src/lib.rs @@ -23,8 +23,12 @@ pub mod databricks_keywords; pub mod duckdb; #[cfg(feature = "hive")] pub mod hive; +#[cfg(feature = "hive")] +mod hive_keywords; #[cfg(feature = "mysql")] pub mod mysql; +#[cfg(feature = "mysql")] +mod mysql_keywords; #[cfg(feature = "postgres")] pub mod postgres; #[cfg(feature = "postgres")] @@ -69,6 +73,8 @@ pub fn kind_to_dialect(kind: &DialectKind) -> Option { #[cfg(feature = "duckdb")] DialectKind::Duckdb => duckdb::dialect(), #[cfg(feature = "mysql")] + #[cfg(feature = "hive")] + DialectKind::Hive => hive::dialect(), DialectKind::Mysql => mysql::dialect(), #[cfg(feature = "postgres")] DialectKind::Postgres => postgres::dialect(), diff --git a/crates/lib-dialects/src/mysql.rs b/crates/lib-dialects/src/mysql.rs index c8e16231b..43b1b793d 100644 --- a/crates/lib-dialects/src/mysql.rs +++ b/crates/lib-dialects/src/mysql.rs @@ -1,56 +1,1184 @@ +use itertools::Itertools; use sqruff_lib_core::dialects::Dialect; use sqruff_lib_core::dialects::init::DialectKind; use sqruff_lib_core::dialects::syntax::SyntaxKind; use sqruff_lib_core::helpers::{Config, ToMatchable}; -use sqruff_lib_core::parser::grammar::Ref; -use sqruff_lib_core::parser::grammar::anyof::one_of; +use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed}; +use sqruff_lib_core::parser::grammar::delimited::Delimited; +use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence}; +use sqruff_lib_core::parser::grammar::{Anything, Ref}; use sqruff_lib_core::parser::lexer::Matcher; +use sqruff_lib_core::parser::matchable::{Matchable, MatchableTrait}; use sqruff_lib_core::parser::node_matcher::NodeMatcher; +use sqruff_lib_core::parser::parsers::{RegexParser, StringParser, TypedParser}; +use sqruff_lib_core::parser::segments::generator::SegmentGenerator; +use sqruff_lib_core::parser::segments::meta::MetaSegment; +use sqruff_lib_core::parser::types::ParseMode; -use super::ansi; +use super::mysql_keywords::{MYSQL_RESERVED_KEYWORDS, MYSQL_UNRESERVED_KEYWORDS}; pub fn dialect() -> Dialect { - raw_dialect().config(|dialect| dialect.expand()) + raw_dialect().config(|this| this.expand()) } +#[rustfmt::skip] pub fn raw_dialect() -> Dialect { - let mut mysql = ansi::raw_dialect(); - mysql.name = DialectKind::Mysql; - - mysql.patch_lexer_matchers(vec![Matcher::regex( - "inline_comment", - r"(^--|-- |#)[^\n]*", - SyntaxKind::InlineComment, - )]); - - mysql.add([ + let ansi_dialect = super::ansi::raw_dialect(); + let mut mysql_dialect = ansi_dialect.clone(); + mysql_dialect.name = DialectKind::Mysql; + + mysql_dialect.patch_lexer_matchers(vec![ + Matcher::regex("inline_comment", r#"(^--|-- |#)[^\n]*"#, SyntaxKind::InlineComment), + Matcher::legacy("single_quote", |_| true, r#"(?s)('(?:\\'|''|\\\\|[^'])*'(?!'))"#, SyntaxKind::SingleQuote), + Matcher::legacy("double_quote", |_| true, r#"(?s)("(?:\\"|""|\\\\|[^"])*"(?!"))"#, SyntaxKind::DoubleQuote), + ]); + + mysql_dialect.insert_lexer_matchers(vec![ + Matcher::regex("hexadecimal_literal", r#"([xX]'([\da-fA-F][\da-fA-F])+'|0x[\da-fA-F]+)"#, SyntaxKind::NumericLiteral), + Matcher::regex("bit_value_literal", r#"([bB]'[01]+'|0b[01]+)"#, SyntaxKind::NumericLiteral), + ], "numeric_literal"); + + mysql_dialect.update_keywords_set_from_multiline_string("unreserved_keywords", MYSQL_UNRESERVED_KEYWORDS); + + mysql_dialect.sets_mut("reserved_keywords").clear(); + + mysql_dialect.update_keywords_set_from_multiline_string("reserved_keywords", MYSQL_RESERVED_KEYWORDS); + + mysql_dialect.sets_mut("datetime_units").clear(); + + mysql_dialect.sets_mut("datetime_units").extend(["DAY_HOUR", "DAY_MICROSECOND", "DAY_MINUTE", "DAY_SECOND", "HOUR_MICROSECOND", "HOUR_MINUTE", "HOUR_SECOND", "MINUTE_MICROSECOND", "MINUTE_SECOND", "SECOND_MICROSECOND", "YEAR_MONTH", "DAY", "WEEK", "HOUR", "MINUTE", "MONTH", "QUARTER", "SECOND", "MICROSECOND", "YEAR"]); + + mysql_dialect.sets_mut("date_part_function_name").clear(); + + mysql_dialect.sets_mut("date_part_function_name").extend(["EXTRACT", "TIMESTAMPADD", "TIMESTAMPDIFF"]); + + mysql_dialect.add([ ( - "DivBinaryOperatorSegment".into(), - NodeMatcher::new(SyntaxKind::BinaryOperator, |_| { - Ref::keyword("DIV").to_matchable() + "NakedIdentifierSegment".into(), + SegmentGenerator::new(|dialect| { + let reserved_keywords = dialect.sets("reserved_keywords"); + let pattern = reserved_keywords.iter().join("|"); + let anti_template = format!("^({pattern})$"); + RegexParser::new(r#"([A-Z0-9_]*[A-Z][A-Z0-9_]*)|_"#, SyntaxKind::NakedIdentifier) + .anti_template(&anti_template) + .to_matchable() + }) + .into() + ), + ]); + + mysql_dialect.replace_grammar( + "QuotedIdentifierSegment", + TypedParser::new(SyntaxKind::BackQuote, SyntaxKind::QuotedIdentifier) + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "LiteralGrammar", + ansi_dialect.grammar("LiteralGrammar").copy(Some(vec![Ref::new("DoubleQuotedLiteralSegment") .to_matchable(), Ref::new("SystemVariableSegment") .to_matchable()]), None, None, None, vec![], false) + ); + + mysql_dialect.replace_grammar( + "PostTableExpressionGrammar", + one_of(vec![Ref::new("IndexHintClauseSegment") .to_matchable(), Ref::new("SelectPartitionClauseSegment") .to_matchable()]) + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "FromClauseTerminatorGrammar", + ansi_dialect.grammar("FromClauseTerminatorGrammar").copy(Some(vec![Ref::new("ForClauseSegment") .to_matchable(), Ref::new("SetOperatorSegment") .to_matchable(), Ref::new("WithNoSchemaBindingClauseSegment") .to_matchable(), Ref::new("WithCheckOptionSegment") .to_matchable(), Ref::new("IntoClauseSegment") .to_matchable()]), None, None, None, vec![], false) + ); + + mysql_dialect.replace_grammar( + "WhereClauseTerminatorGrammar", + ansi_dialect.grammar("WhereClauseTerminatorGrammar").copy(Some(vec![Ref::new("IntoClauseSegment") .to_matchable()]), None, None, None, vec![], false) + ); + + mysql_dialect.replace_grammar( + "BaseExpressionElementGrammar", + ansi_dialect.grammar("BaseExpressionElementGrammar").copy(Some(vec![Ref::new("SessionVariableNameSegment") .to_matchable(), Ref::new("LocalVariableNameSegment") .to_matchable(), Ref::new("VariableAssignmentSegment") .to_matchable()]), None, None, None, vec![], false) + ); + + mysql_dialect.replace_grammar( + "Expression_D_Potential_Select_Statement_Without_Brackets", + ansi_dialect.grammar("Expression_D_Potential_Select_Statement_Without_Brackets").copy(Some(vec![Ref::new("SessionVariableNameSegment") .to_matchable()]), Some(0), None, None, vec![], false) + ); + + mysql_dialect.replace_grammar( + "BinaryOperatorGrammar", + ansi_dialect.grammar("BinaryOperatorGrammar").copy(Some(vec![Ref::new("ColumnPathOperatorSegment") .to_matchable(), Ref::new("InlinePathOperatorSegment") .to_matchable()]), None, None, None, vec![], false) + ); + + mysql_dialect.replace_grammar( + "ArithmeticBinaryOperatorGrammar", + ansi_dialect.grammar("ArithmeticBinaryOperatorGrammar").copy(Some(vec![Ref::new("DivOperatorSegment") .to_matchable(), Ref::new("ModOperatorSegment") .to_matchable()]), None, None, None, vec![], false) + ); + + mysql_dialect.replace_grammar( + "DateTimeLiteralGrammar", + Sequence::new(vec![one_of(vec![Ref::keyword("DATE") .to_matchable(), Ref::keyword("TIME") .to_matchable(), Ref::keyword("TIMESTAMP") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), one_of(vec![TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::DateConstructorLiteral) .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable()]) .to_matchable()]) + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "QuotedLiteralSegment", + AnyNumberOf::new(vec![TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral) .to_matchable(), Ref::new("DoubleQuotedLiteralSegment") .to_matchable()]) + .config(|this| { + this.min_times(1); }) .to_matchable() - .into(), + ); + + mysql_dialect.replace_grammar( + "UniqueKeyGrammar", + Sequence::new(vec![Ref::keyword("UNIQUE") .to_matchable(), Ref::keyword("KEY") .optional() .to_matchable()]) + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "CharCharacterSetGrammar", + Ref::keyword("BINARY") + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "DelimiterGrammar", + one_of(vec![Ref::new("SemicolonSegment") .to_matchable(), Ref::new("TildeSegment") .to_matchable()]) + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "TildeSegment", + StringParser::new("~", SyntaxKind::StatementTerminator) + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "ParameterNameSegment", + RegexParser::new(r#"`?[A-Za-z0-9_]*`?"#, SyntaxKind::Parameter) + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "SingleIdentifierGrammar", + ansi_dialect.grammar("SingleIdentifierGrammar").copy(Some(vec![Ref::new("SessionVariableNameSegment") .to_matchable()]), None, None, None, vec![], false) + ); + + mysql_dialect.replace_grammar( + "AndOperatorGrammar", + one_of(vec![StringParser::new("AND", SyntaxKind::BinaryOperator) .to_matchable(), StringParser::new("&&", SyntaxKind::BinaryOperator) .to_matchable()]) + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "OrOperatorGrammar", + one_of(vec![StringParser::new("OR", SyntaxKind::BinaryOperator) .to_matchable(), StringParser::new("||", SyntaxKind::BinaryOperator) .to_matchable(), StringParser::new("XOR", SyntaxKind::BinaryOperator) .to_matchable()]) + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "NotOperatorGrammar", + one_of(vec![StringParser::new("NOT", SyntaxKind::Keyword) .to_matchable(), StringParser::new("!", SyntaxKind::NotOperator) .to_matchable()]) + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "Expression_C_Grammar", + Sequence::new(vec![Sequence::new(vec![Ref::new("SessionVariableNameSegment") .to_matchable(), Ref::new("WalrusOperatorSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), ansi_dialect.grammar("Expression_C_Grammar")]) + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "ColumnConstraintDefaultGrammar", + one_of(vec![Bracketed::new(vec![ansi_dialect.grammar("ColumnConstraintDefaultGrammar")]) .to_matchable(), ansi_dialect.grammar("ColumnConstraintDefaultGrammar")]) + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "LikeGrammar", + one_of(vec![Ref::keyword("LIKE") .to_matchable(), Ref::keyword("RLIKE") .to_matchable(), Ref::keyword("REGEXP") .to_matchable()]) + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "CollateGrammar", + Sequence::new(vec![Ref::keyword("COLLATE") .to_matchable(), Ref::new("CollationReferenceSegment") .to_matchable()]) + .to_matchable() + ); + + mysql_dialect.replace_grammar( + "ComparisonOperatorGrammar", + ansi_dialect.grammar("ComparisonOperatorGrammar").copy(Some(vec![Ref::new("NullSafeEqualsSegment") .to_matchable()]), None, None, None, vec![], false) + ); + + mysql_dialect.add([ + ( + "DoubleQuotedLiteralSegment".into(), + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedLiteral) + .to_matchable() + .into() ), ( - "ArithmeticBinaryOperatorGrammar".into(), - one_of(vec![ - Ref::new("PlusSegment").to_matchable(), - Ref::new("MinusSegment").to_matchable(), - Ref::new("DivideSegment").to_matchable(), - Ref::new("MultiplySegment").to_matchable(), - Ref::new("ModuloSegment").to_matchable(), - Ref::new("BitwiseAndSegment").to_matchable(), - Ref::new("BitwiseOrSegment").to_matchable(), - Ref::new("BitwiseXorSegment").to_matchable(), - Ref::new("BitwiseLShiftSegment").to_matchable(), - Ref::new("BitwiseRShiftSegment").to_matchable(), - Ref::new("DivBinaryOperatorSegment").to_matchable(), - ]) - .to_matchable() - .into(), + "DoubleQuotedIdentifierSegment".into(), + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedIdentifier) + .to_matchable() + .into() + ), + ( + "AtSignLiteralSegment".into(), + TypedParser::new(SyntaxKind::AtSignLiteral, SyntaxKind::AtSignLiteral) + .to_matchable() + .into() + ), + ( + "SystemVariableSegment".into(), + RegexParser::new(r#"@@((session|global|local|persist|persist_only)\.)?[A-Za-z0-9_]+"#, SyntaxKind::SystemVariable) + .to_matchable() + .into() + ), + ( + "DivOperatorSegment".into(), + StringParser::new("DIV", SyntaxKind::BinaryOperator) + .to_matchable() + .into() + ), + ( + "ModOperatorSegment".into(), + StringParser::new("MOD", SyntaxKind::BinaryOperator) + .to_matchable() + .into() + ), + ( + "DoubleQuotedJSONPath".into(), + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::JsonPath) + .to_matchable() + .into() + ), + ( + "SingleQuotedJSONPath".into(), + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::JsonPath) + .to_matchable() + .into() + ), + ]); + + mysql_dialect.add([ + ( + "AliasExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::AliasExpression, |_dialect| { + Sequence::new(vec![MetaSegment::indent() .to_matchable(), Ref::new("AsAliasOperatorSegment") .optional() .to_matchable(), one_of(vec![Sequence::new(vec![Ref::new("SingleIdentifierGrammar") .to_matchable(), Bracketed::new(vec![Ref::new("SingleIdentifierListSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable(), Ref::new("SingleQuotedIdentifierSegment") .to_matchable(), Ref::new("DoubleQuotedIdentifierSegment") .to_matchable()]) .to_matchable(), MetaSegment::dedent() .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "ColumnDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnDefinition, |_dialect| { + Sequence::new(vec![Ref::new("SingleIdentifierGrammar") .to_matchable(), one_of(vec![Ref::new("DatatypeSegment") .exclude(one_of(vec![Ref::keyword("DATETIME") .to_matchable(), Ref::keyword("TIMESTAMP") .to_matchable()])) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("DATETIME") .to_matchable(), Ref::keyword("TIMESTAMP") .to_matchable()]) .to_matchable(), Ref::new("BracketedArguments") .optional() .to_matchable(), AnyNumberOf::new(vec![Sequence::new(vec![Sequence::new(vec![Ref::keyword("NOT") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("NULL") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("DEFAULT") .to_matchable(), one_of(vec![Sequence::new(vec![one_of(vec![Ref::keyword("CURRENT_TIMESTAMP") .to_matchable(), Ref::keyword("NOW") .to_matchable()]) .to_matchable(), Bracketed::new(vec![Ref::new("NumericLiteralSegment") .optional() .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable(), Ref::keyword("NULL") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("ON") .to_matchable(), Ref::keyword("UPDATE") .to_matchable(), one_of(vec![Ref::keyword("CURRENT_TIMESTAMP") .to_matchable(), Ref::keyword("NOW") .to_matchable(), Bracketed::new(vec![Ref::new("NumericLiteralSegment") .optional() .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable()]) .to_matchable(), Bracketed::new(vec![Anything::new() .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), AnyNumberOf::new(vec![Ref::new("ColumnConstraintSegment") .optional() .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CreateTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTableStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("CREATE") .to_matchable(), Ref::new("OrReplaceGrammar") .optional() .to_matchable(), Ref::new("TemporaryTransientGrammar") .optional() .to_matchable(), Ref::keyword("TABLE") .to_matchable(), Ref::new("IfNotExistsGrammar") .optional() .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable(), one_of(vec![Sequence::new(vec![Bracketed::new(vec![Delimited::new(vec![one_of(vec![Ref::new("TableConstraintSegment") .to_matchable(), Ref::new("ColumnDefinitionSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("AS") .optional() .to_matchable(), optionally_bracketed(vec![Ref::new("SelectableGrammar") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::new("CommentClauseSegment") .optional() .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("AS") .optional() .to_matchable(), optionally_bracketed(vec![Ref::new("SelectableGrammar") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("LIKE") .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Ref::new("TableEndClauseSegment") .optional() .to_matchable(), AnyNumberOf::new(vec![Sequence::new(vec![Ref::keyword("DEFAULT") .optional() .to_matchable(), one_of(vec![Ref::new("ParameterNameSegment") .to_matchable(), Sequence::new(vec![Ref::keyword("CHARACTER") .to_matchable(), Ref::keyword("SET") .to_matchable()]) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("DATA") .to_matchable(), Ref::keyword("INDEX") .to_matchable()]) .to_matchable(), Ref::keyword("DIRECTORY") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("WITH") .to_matchable(), Ref::keyword("SYSTEM") .to_matchable()]) .to_matchable()]) .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), one_of(vec![Ref::new("LiteralGrammar") .to_matchable(), Ref::new("ParameterNameSegment") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable(), Ref::new("SingleQuotedIdentifierSegment") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable(), Bracketed::new(vec![Delimited::new(vec![Ref::new("TableReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("PARTITION") .to_matchable(), Ref::keyword("BY") .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("LINEAR") .optional() .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("HASH") .to_matchable(), Ref::new("ExpressionSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("KEY") .to_matchable(), Sequence::new(vec![Ref::keyword("ALGORITHM") .to_matchable(), Ref::new("EqualsSegment") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Delimited::new(vec![Ref::new("ColumnReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("RANGE") .to_matchable(), Ref::keyword("LIST") .to_matchable()]) .to_matchable(), one_of(vec![Ref::new("ExpressionSegment") .to_matchable(), Bracketed::new(vec![Delimited::new(vec![Ref::new("ColumnReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("PARTITIONS") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("SUBPARTITION") .to_matchable(), Ref::keyword("BY") .to_matchable(), Sequence::new(vec![Ref::keyword("LINEAR") .optional() .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("HASH") .to_matchable(), Ref::new("ExpressionSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("KEY") .to_matchable(), Sequence::new(vec![Ref::keyword("ALGORITHM") .to_matchable(), Ref::new("EqualsSegment") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Bracketed::new(vec![Ref::new("ColumnReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("SUBPARTITIONS") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), AnyNumberOf::new(vec![Bracketed::new(vec![Delimited::new(vec![Sequence::new(vec![Ref::keyword("PARTITION") .to_matchable(), Ref::new("ColumnReferenceSegment") .to_matchable(), AnyNumberOf::new(vec![Sequence::new(vec![Ref::keyword("VALUES") .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("LESS") .to_matchable(), Ref::keyword("THAN") .to_matchable(), one_of(vec![Ref::keyword("MAXVALUE") .to_matchable(), Bracketed::new(vec![one_of(vec![Ref::new("ExpressionSegment") .to_matchable(), Ref::new("ColumnReferenceSegment") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable(), Ref::new("LiteralGrammar") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("IN") .to_matchable(), Bracketed::new(vec![Ref::new("ObjectReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::new("ParameterNameSegment") .to_matchable(), Sequence::new(vec![Ref::keyword("CHARACTER") .to_matchable(), Ref::keyword("SET") .to_matchable()]) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("DATA") .to_matchable(), Ref::keyword("INDEX") .to_matchable()]) .to_matchable(), Ref::keyword("DIRECTORY") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("WITH") .to_matchable(), Ref::keyword("SYSTEM") .to_matchable()]) .to_matchable()]) .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), one_of(vec![Ref::new("LiteralGrammar") .to_matchable(), Ref::new("ParameterNameSegment") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable(), Ref::new("SingleQuotedIdentifierSegment") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable(), Bracketed::new(vec![Delimited::new(vec![Ref::new("TableReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("SUBPARTITION") .optional() .to_matchable(), Ref::new("LiteralGrammar") .to_matchable(), AnyNumberOf::new(vec![Sequence::new(vec![Ref::keyword("VALUES") .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("LESS") .to_matchable(), Ref::keyword("THAN") .to_matchable(), one_of(vec![Ref::keyword("MAXVALUE") .to_matchable(), Bracketed::new(vec![Ref::new("ExpressionSegment") .to_matchable()]) .to_matchable(), Bracketed::new(vec![Ref::new("ColumnReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("IN") .to_matchable(), Bracketed::new(vec![Ref::new("ObjectReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::new("ParameterNameSegment") .to_matchable(), Sequence::new(vec![Ref::keyword("CHARACTER") .to_matchable(), Ref::keyword("SET") .to_matchable()]) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("DATA") .to_matchable(), Ref::keyword("INDEX") .to_matchable()]) .to_matchable(), Ref::keyword("DIRECTORY") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("WITH") .to_matchable(), Ref::keyword("SYSTEM") .to_matchable()]) .to_matchable()]) .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), one_of(vec![Ref::new("LiteralGrammar") .to_matchable(), Ref::new("ParameterNameSegment") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable(), Ref::new("SingleQuotedIdentifierSegment") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable(), Bracketed::new(vec![Delimited::new(vec![Ref::new("TableReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CreateUserStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateUserStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("CREATE") .to_matchable(), Ref::keyword("USER") .to_matchable(), Ref::new("IfNotExistsGrammar") .optional() .to_matchable(), Delimited::new(vec![Sequence::new(vec![Ref::new("RoleReferenceSegment") .to_matchable(), Sequence::new(vec![Delimited::new(vec![Sequence::new(vec![Ref::keyword("IDENTIFIED") .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("BY") .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("RANDOM") .to_matchable(), Ref::keyword("PASSWORD") .to_matchable()]) .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("WITH") .to_matchable(), Ref::new("ObjectReferenceSegment") .to_matchable(), Sequence::new(vec![one_of(vec![Sequence::new(vec![Ref::keyword("BY") .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("RANDOM") .to_matchable(), Ref::keyword("PASSWORD") .to_matchable()]) .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("AS") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("INITIAL") .to_matchable(), Ref::keyword("AUTHENTICATION") .to_matchable(), Ref::keyword("IDENTIFIED") .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("BY") .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("RANDOM") .to_matchable(), Ref::keyword("PASSWORD") .to_matchable()]) .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("WITH") .to_matchable(), Ref::new("ObjectReferenceSegment") .to_matchable(), Ref::keyword("AS") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.delimiter(Ref::keyword("AND")); }) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("DEFAULT") .to_matchable(), Ref::keyword("ROLE") .to_matchable(), Delimited::new(vec![Ref::new("RoleReferenceSegment") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("REQUIRE") .to_matchable(), one_of(vec![Ref::keyword("NONE") .to_matchable(), Delimited::new(vec![one_of(vec![Ref::keyword("SSL") .to_matchable(), Ref::keyword("X509") .to_matchable(), Sequence::new(vec![Ref::keyword("CIPHER") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("ISSUER") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("SUBJECT") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.delimiter(Ref::keyword("AND")); }) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("WITH") .to_matchable(), AnyNumberOf::new(vec![Sequence::new(vec![one_of(vec![Ref::keyword("MAX_QUERIES_PER_HOUR") .to_matchable(), Ref::keyword("MAX_UPDATES_PER_HOUR") .to_matchable(), Ref::keyword("MAX_CONNECTIONS_PER_HOUR") .to_matchable(), Ref::keyword("MAX_USER_CONNECTIONS") .to_matchable()]) .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![AnyNumberOf::new(vec![Sequence::new(vec![Ref::keyword("PASSWORD") .to_matchable(), Ref::keyword("EXPIRE") .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("DEFAULT") .to_matchable(), Ref::keyword("NEVER") .to_matchable(), Sequence::new(vec![Ref::keyword("INTERVAL") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable(), Ref::keyword("DAY") .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("PASSWORD") .to_matchable(), Ref::keyword("HISTORY") .to_matchable(), one_of(vec![Ref::keyword("DEFAULT") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("PASSWORD") .to_matchable(), Ref::keyword("REUSE") .to_matchable(), Ref::keyword("INTERVAL") .to_matchable(), one_of(vec![Ref::keyword("DEFAULT") .to_matchable(), Sequence::new(vec![Ref::new("NumericLiteralSegment") .to_matchable(), Ref::keyword("DAY") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("PASSWORD") .to_matchable(), Ref::keyword("REQUIRE") .to_matchable(), Ref::keyword("CURRENT") .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("DEFAULT") .to_matchable(), Ref::keyword("OPTIONAL") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("FAILED_LOGIN_ATTEMPTS") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("PASSWORD_LOCK_TIME") .to_matchable(), one_of(vec![Ref::new("NumericLiteralSegment") .to_matchable(), Ref::keyword("UNBOUNDED") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("ACCOUNT") .to_matchable(), one_of(vec![Ref::keyword("UNLOCK") .to_matchable(), Ref::keyword("LOCK") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("COMMENT") .to_matchable(), Ref::keyword("ATTRIBUTE") .to_matchable()]) .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "UpsertClauseListSegment".into(), + NodeMatcher::new(SyntaxKind::UpsertClauseList, |_dialect| { + Sequence::new(vec![Ref::keyword("ON") .to_matchable(), Ref::keyword("DUPLICATE") .to_matchable(), Ref::keyword("KEY") .to_matchable(), Ref::keyword("UPDATE") .to_matchable(), Delimited::new(vec![Ref::new("SetClauseSegment") .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "InsertRowAliasSegment".into(), + NodeMatcher::new(SyntaxKind::InsertRowAlias, |_dialect| { + Sequence::new(vec![Ref::keyword("AS") .to_matchable(), Ref::new("SingleIdentifierGrammar") .to_matchable(), Bracketed::new(vec![Ref::new("SingleIdentifierListSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "InsertStatementSegment".into(), + NodeMatcher::new(SyntaxKind::InsertStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("INSERT") .to_matchable(), one_of(vec![Ref::keyword("LOW_PRIORITY") .to_matchable(), Ref::keyword("DELAYED") .to_matchable(), Ref::keyword("HIGH_PRIORITY") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("IGNORE") .optional() .to_matchable(), Ref::keyword("INTO") .optional() .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable(), Sequence::new(vec![Ref::keyword("PARTITION") .to_matchable(), Bracketed::new(vec![Ref::new("SingleIdentifierListSegment") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::new("BracketedColumnReferenceListGrammar") .optional() .to_matchable(), AnyNumberOf::new(vec![one_of(vec![Ref::new("ValuesClauseSegment") .to_matchable(), Ref::new("SetClauseListSegment") .to_matchable(), Sequence::new(vec![one_of(vec![Ref::new("SelectableGrammar") .to_matchable(), Sequence::new(vec![Ref::keyword("TABLE") .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Ref::new("InsertRowAliasSegment") .optional() .to_matchable(), Ref::new("UpsertClauseListSegment") .optional() .to_matchable()]) .config(|this| { this.max_times_per_element = Some(1); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "DeleteTargetTableSegment".into(), + NodeMatcher::new(SyntaxKind::DeleteTargetTable, |_dialect| { + Sequence::new(vec![Ref::new("TableReferenceSegment") .to_matchable(), Sequence::new(vec![Ref::new("DotSegment") .to_matchable(), Ref::new("StarSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "DeleteUsingClauseSegment".into(), + NodeMatcher::new(SyntaxKind::UsingClause, |_dialect| { + Sequence::new(vec![Ref::keyword("USING") .to_matchable(), Delimited::new(vec![Ref::new("FromExpressionSegment") .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "DeleteStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DeleteStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("DELETE") .to_matchable(), Ref::keyword("LOW_PRIORITY") .optional() .to_matchable(), Ref::keyword("QUICK") .optional() .to_matchable(), Ref::keyword("IGNORE") .optional() .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("FROM") .to_matchable(), Delimited::new(vec![Ref::new("DeleteTargetTableSegment") .to_matchable()]) .config(|this| { this.terminators = vec![Ref::keyword("USING") .to_matchable()]; }) .to_matchable(), Ref::new("DeleteUsingClauseSegment") .to_matchable(), Ref::new("WhereClauseSegment") .optional() .to_matchable()]) .to_matchable(), Sequence::new(vec![Delimited::new(vec![Ref::new("DeleteTargetTableSegment") .to_matchable()]) .config(|this| { this.terminators = vec![Ref::keyword("FROM") .to_matchable()]; }) .to_matchable(), Ref::new("FromClauseSegment") .to_matchable(), Ref::new("WhereClauseSegment") .optional() .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::new("FromClauseSegment") .to_matchable(), Ref::new("SelectPartitionClauseSegment") .optional() .to_matchable(), Ref::new("WhereClauseSegment") .optional() .to_matchable(), Ref::new("OrderByClauseSegment") .optional() .to_matchable(), Ref::new("LimitClauseSegment") .optional() .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "ColumnConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_dialect| { + one_of(vec![{ let dialect = super::ansi::raw_dialect(); dialect.grammar("ColumnConstraintSegment").match_grammar(&dialect).unwrap() }, Sequence::new(vec![Ref::keyword("CHARACTER") .to_matchable(), Ref::keyword("SET") .to_matchable(), one_of(vec![Ref::new("SingleIdentifierGrammar") .to_matchable(), Ref::new("SingleQuotedIdentifierSegment") .to_matchable(), Ref::new("DoubleQuotedIdentifierSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Ref::new("CollateGrammar") .to_matchable(), Sequence::new(vec![Sequence::new(vec![Ref::keyword("GENERATED") .to_matchable(), Ref::keyword("ALWAYS") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("AS") .to_matchable(), Bracketed::new(vec![Ref::new("ExpressionSegment") .to_matchable()]) .to_matchable(), one_of(vec![Ref::keyword("STORED") .to_matchable(), Ref::keyword("VIRTUAL") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("SRID") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable()]) .to_matchable(), one_of(vec![Ref::keyword("INVISIBLE") .to_matchable(), Ref::keyword("VISIBLE") .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "IndexTypeGrammar".into(), + NodeMatcher::new(SyntaxKind::IndexType, |_dialect| { + Sequence::new(vec![Ref::keyword("USING") .to_matchable(), one_of(vec![Ref::keyword("BTREE") .to_matchable(), Ref::keyword("HASH") .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "IndexOptionsSegment".into(), + NodeMatcher::new(SyntaxKind::IndexOption, |_dialect| { + AnyNumberOf::new(vec![Sequence::new(vec![Ref::keyword("KEY_BLOCK_SIZE") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable()]) .to_matchable(), Ref::new("IndexTypeGrammar") .to_matchable(), Sequence::new(vec![Ref::keyword("WITH") .to_matchable(), Ref::keyword("PARSER") .to_matchable(), Ref::new("ObjectReferenceSegment") .to_matchable()]) .to_matchable(), Ref::new("CommentClauseSegment") .to_matchable(), one_of(vec![Ref::keyword("VISIBLE") .to_matchable(), Ref::keyword("INVISIBLE") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("ENGINE_ATTRIBUTE") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("SECONDARY_ENGINE_ATTRIBUTE") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable()]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "TableConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::TableConstraint, |_dialect| { + one_of(vec![Sequence::new(vec![Sequence::new(vec![Ref::keyword("CONSTRAINT") .to_matchable(), Ref::new("ObjectReferenceSegment") .optional() .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("UNIQUE") .to_matchable(), one_of(vec![Ref::keyword("INDEX") .to_matchable(), Ref::keyword("KEY") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::new("IndexReferenceSegment") .optional() .to_matchable(), Ref::new("IndexTypeGrammar") .optional() .to_matchable(), Ref::new("BracketedKeyPartListGrammar") .to_matchable(), Ref::new("IndexOptionsSegment") .optional() .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::new("PrimaryKeyGrammar") .to_matchable(), Ref::new("IndexTypeGrammar") .optional() .to_matchable(), Ref::new("BracketedKeyPartListGrammar") .to_matchable(), Ref::new("IndexOptionsSegment") .optional() .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::new("ForeignKeyGrammar") .to_matchable(), Ref::new("IndexReferenceSegment") .optional() .to_matchable(), Ref::new("BracketedColumnReferenceListGrammar") .to_matchable(), Ref::keyword("REFERENCES") .to_matchable(), Ref::new("ColumnReferenceSegment") .to_matchable(), Ref::new("BracketedColumnReferenceListGrammar") .to_matchable(), AnyNumberOf::new(vec![Sequence::new(vec![Ref::keyword("ON") .to_matchable(), one_of(vec![Ref::keyword("DELETE") .to_matchable(), Ref::keyword("UPDATE") .to_matchable()]) .to_matchable(), one_of(vec![Ref::keyword("RESTRICT") .to_matchable(), Ref::keyword("CASCADE") .to_matchable(), Sequence::new(vec![Ref::keyword("SET") .to_matchable(), Ref::keyword("NULL") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("NO") .to_matchable(), Ref::keyword("ACTION") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("SET") .to_matchable(), Ref::keyword("DEFAULT") .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("CHECK") .to_matchable(), Bracketed::new(vec![Ref::new("ExpressionSegment") .to_matchable()]) .to_matchable(), one_of(vec![Ref::keyword("ENFORCED") .to_matchable(), Sequence::new(vec![Ref::keyword("NOT") .to_matchable(), Ref::keyword("ENFORCED") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("INDEX") .to_matchable(), Ref::keyword("KEY") .to_matchable()]) .to_matchable(), Ref::new("IndexReferenceSegment") .optional() .to_matchable(), Ref::new("IndexTypeGrammar") .optional() .to_matchable(), Ref::new("BracketedKeyPartListGrammar") .to_matchable(), Ref::new("IndexOptionsSegment") .optional() .to_matchable()]) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("FULLTEXT") .to_matchable(), Ref::keyword("SPATIAL") .to_matchable()]) .to_matchable(), one_of(vec![Ref::keyword("INDEX") .to_matchable(), Ref::keyword("KEY") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::new("IndexReferenceSegment") .optional() .to_matchable(), Ref::new("BracketedKeyPartListGrammar") .to_matchable(), Ref::new("IndexOptionsSegment") .optional() .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CreateIndexStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateIndexStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("CREATE") .to_matchable(), one_of(vec![Ref::keyword("UNIQUE") .to_matchable(), Ref::keyword("FULLTEXT") .to_matchable(), Ref::keyword("SPATIAL") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("INDEX") .to_matchable(), Ref::new("IndexReferenceSegment") .to_matchable(), Ref::new("IndexTypeGrammar") .optional() .to_matchable(), Ref::keyword("ON") .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable(), Ref::new("BracketedKeyPartListGrammar") .to_matchable(), Ref::new("IndexOptionsSegment") .optional() .to_matchable(), AnyNumberOf::new(vec![Sequence::new(vec![Ref::keyword("ALGORITHM") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), one_of(vec![Ref::keyword("DEFAULT") .to_matchable(), Ref::keyword("INPLACE") .to_matchable(), Ref::keyword("COPY") .to_matchable(), Ref::keyword("NOCOPY") .to_matchable(), Ref::keyword("INSTANT") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("LOCK") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), one_of(vec![Ref::keyword("DEFAULT") .to_matchable(), Ref::keyword("NONE") .to_matchable(), Ref::keyword("SHARED") .to_matchable(), Ref::keyword("EXCLUSIVE") .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.max_times_per_element = Some(1); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "IntervalExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::IntervalExpression, |_dialect| { + Sequence::new(vec![Ref::keyword("INTERVAL") .to_matchable(), one_of(vec![Ref::new("DatetimeUnitSegment") .to_matchable(), Sequence::new(vec![Ref::new("ExpressionSegment") .to_matchable(), Ref::new("DatetimeUnitSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ]); + + mysql_dialect.add([ + ( + "OutputParameterSegment".into(), + StringParser::new("OUT", SyntaxKind::ParameterDirection) + .to_matchable() + .into() + ), + ( + "InputParameterSegment".into(), + StringParser::new("IN", SyntaxKind::ParameterDirection) + .to_matchable() + .into() + ), + ( + "InputOutputParameterSegment".into(), + StringParser::new("INOUT", SyntaxKind::ParameterDirection) + .to_matchable() + .into() + ), + ( + "ProcedureParameterGrammar".into(), + one_of(vec![Sequence::new(vec![one_of(vec![Ref::new("OutputParameterSegment") .to_matchable(), Ref::new("InputParameterSegment") .to_matchable(), Ref::new("InputOutputParameterSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::new("ParameterNameSegment") .optional() .to_matchable(), Ref::new("DatatypeSegment") .to_matchable()]) .to_matchable(), Ref::new("DatatypeSegment") .to_matchable()]) + .to_matchable() + .into() + ), + ( + "LocalVariableNameSegment".into(), + RegexParser::new(r#"`?[a-zA-Z0-9_$]*`?"#, SyntaxKind::Variable) + .to_matchable() + .into() + ), + ( + "SessionVariableNameSegment".into(), + RegexParser::new(r#"[@][a-zA-Z0-9_$]*"#, SyntaxKind::Variable) + .to_matchable() + .into() + ), + ( + "WalrusOperatorSegment".into(), + StringParser::new(":=", SyntaxKind::AssignmentOperator) + .to_matchable() + .into() + ), + ( + "VariableAssignmentSegment".into(), + Sequence::new(vec![Ref::new("SessionVariableNameSegment") .to_matchable(), Ref::new("WalrusOperatorSegment") .to_matchable(), Ref::new("BaseExpressionElementGrammar") .to_matchable()]) + .to_matchable() + .into() + ), + ( + "ColumnPathOperatorSegment".into(), + StringParser::new("->", SyntaxKind::ColumnPathOperator) + .to_matchable() + .into() + ), + ( + "InlinePathOperatorSegment".into(), + StringParser::new("->>", SyntaxKind::ColumnPathOperator) + .to_matchable() + .into() + ), + ( + "BooleanDynamicSystemVariablesGrammar".into(), + one_of(vec![one_of(vec![Ref::keyword("ON") .to_matchable(), Ref::keyword("OFF") .to_matchable()]) .to_matchable(), one_of(vec![Ref::keyword("TRUE") .to_matchable(), Ref::keyword("FALSE") .to_matchable()]) .to_matchable()]) + .to_matchable() + .into() + ), + ( + "BracketedKeyPartListGrammar".into(), + Bracketed::new(vec![Delimited::new(vec![Sequence::new(vec![one_of(vec![Ref::new("ColumnReferenceSegment") .to_matchable(), Sequence::new(vec![Ref::new("ColumnReferenceSegment") .to_matchable(), Bracketed::new(vec![Ref::new("NumericLiteralSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Bracketed::new(vec![Ref::new("ExpressionSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), one_of(vec![Ref::keyword("ASC") .to_matchable(), Ref::keyword("DESC") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + .into() + ), + ]); + + mysql_dialect.insert_lexer_matchers(vec![ + Matcher::regex("at_sign", r#"@@?[a-zA-Z0-9_$]*(\.[a-zA-Z0-9_$]+)?"#, SyntaxKind::AtSignLiteral), + ], "word"); + + mysql_dialect.insert_lexer_matchers(vec![ + Matcher::string("double_ampersand", r#"&&"#, SyntaxKind::DoubleAmpersand), + ], "ampersand"); + + mysql_dialect.insert_lexer_matchers(vec![ + Matcher::string("double_vertical_bar", r#"||"#, SyntaxKind::DoubleVerticalBar), + ], "vertical_bar"); + + mysql_dialect.insert_lexer_matchers(vec![ + Matcher::string("walrus_operator", r#":="#, SyntaxKind::WalrusOperator), + ], "equals"); + + mysql_dialect.insert_lexer_matchers(vec![ + Matcher::string("inline_path_operator", r#"->>"#, SyntaxKind::InlinePathOperator), + Matcher::string("column_path_operator", r#"->"#, SyntaxKind::ColumnPathOperator), + ], "greater_than"); + + mysql_dialect.add([ + ( + "RoleReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::RoleReference, |_dialect| { + one_of(vec![Sequence::new(vec![one_of(vec![Ref::new("NakedIdentifierSegment") .to_matchable(), Ref::new("QuotedIdentifierSegment") .to_matchable(), Ref::new("SingleQuotedIdentifierSegment") .to_matchable(), Ref::new("DoubleQuotedLiteralSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::new("AtSignLiteralSegment") .to_matchable(), one_of(vec![Ref::new("NakedIdentifierSegment") .to_matchable(), Ref::new("QuotedIdentifierSegment") .to_matchable(), Ref::new("SingleQuotedIdentifierSegment") .to_matchable(), Ref::new("DoubleQuotedLiteralSegment") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); this.disallow_gaps(); }) .to_matchable()]) .to_matchable(), Ref::keyword("CURRENT_USER") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "DeclareStatement".into(), + NodeMatcher::new(SyntaxKind::DeclareStatement, |_dialect| { + one_of(vec![Sequence::new(vec![Ref::keyword("DECLARE") .to_matchable(), Ref::new("NakedIdentifierSegment") .to_matchable(), Ref::keyword("CURSOR") .to_matchable(), Ref::keyword("FOR") .to_matchable(), Ref::new("StatementSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("DECLARE") .to_matchable(), one_of(vec![Ref::keyword("CONTINUE") .to_matchable(), Ref::keyword("EXIT") .to_matchable(), Ref::keyword("UNDO") .to_matchable()]) .to_matchable(), Ref::keyword("HANDLER") .to_matchable(), Ref::keyword("FOR") .to_matchable(), one_of(vec![Ref::keyword("SQLEXCEPTION") .to_matchable(), Ref::keyword("SQLWARNING") .to_matchable(), Sequence::new(vec![Ref::keyword("NOT") .to_matchable(), Ref::keyword("FOUND") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("SQLSTATE") .to_matchable(), Ref::keyword("VALUE") .optional() .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable(), one_of(vec![Ref::new("QuotedLiteralSegment") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable(), Ref::new("NakedIdentifierSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::new("StatementSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("DECLARE") .to_matchable(), Ref::new("NakedIdentifierSegment") .to_matchable(), Ref::keyword("CONDITION") .to_matchable(), Ref::keyword("FOR") .to_matchable(), one_of(vec![Ref::new("QuotedLiteralSegment") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("DECLARE") .to_matchable(), Ref::new("LocalVariableNameSegment") .to_matchable(), Ref::new("DatatypeSegment") .to_matchable(), Sequence::new(vec![Ref::keyword("DEFAULT") .to_matchable(), one_of(vec![Ref::new("QuotedLiteralSegment") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable(), Ref::new("FunctionSegment") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "StatementSegment".into(), + NodeMatcher::new(SyntaxKind::Statement, |_dialect| { + { let dialect = super::ansi::raw_dialect(); dialect.grammar("StatementSegment").match_grammar(&dialect).unwrap() }.copy(Some(vec![Ref::new("DelimiterStatement") .to_matchable(), Ref::new("CreateProcedureStatementSegment") .to_matchable(), Ref::new("DeclareStatement") .to_matchable(), Ref::new("SetTransactionStatementSegment") .to_matchable(), Ref::new("SetAssignmentStatementSegment") .to_matchable(), Ref::new("IfExpressionStatement") .to_matchable(), Ref::new("WhileStatementSegment") .to_matchable(), Ref::new("IterateStatementSegment") .to_matchable(), Ref::new("RepeatStatementSegment") .to_matchable(), Ref::new("LoopStatementSegment") .to_matchable(), Ref::new("CallStoredProcedureSegment") .to_matchable(), Ref::new("PrepareSegment") .to_matchable(), Ref::new("ExecuteSegment") .to_matchable(), Ref::new("DeallocateSegment") .to_matchable(), Ref::new("GetDiagnosticsSegment") .to_matchable(), Ref::new("ResignalSegment") .to_matchable(), Ref::new("CursorOpenCloseSegment") .to_matchable(), Ref::new("CursorFetchSegment") .to_matchable(), Ref::new("DropProcedureStatementSegment") .to_matchable(), Ref::new("AlterTableStatementSegment") .to_matchable(), Ref::new("AlterViewStatementSegment") .to_matchable(), Ref::new("CreateViewStatementSegment") .to_matchable(), Ref::new("RenameTableStatementSegment") .to_matchable(), Ref::new("ResetMasterStatementSegment") .to_matchable(), Ref::new("PurgeBinaryLogsStatementSegment") .to_matchable(), Ref::new("HelpStatementSegment") .to_matchable(), Ref::new("CheckTableStatementSegment") .to_matchable(), Ref::new("ChecksumTableStatementSegment") .to_matchable(), Ref::new("AnalyzeTableStatementSegment") .to_matchable(), Ref::new("RepairTableStatementSegment") .to_matchable(), Ref::new("OptimizeTableStatementSegment") .to_matchable(), Ref::new("UpsertClauseListSegment") .to_matchable(), Ref::new("InsertRowAliasSegment") .to_matchable(), Ref::new("FlushStatementSegment") .to_matchable(), Ref::new("LoadDataSegment") .to_matchable(), Ref::new("ReplaceSegment") .to_matchable(), Ref::new("AlterDatabaseStatementSegment") .to_matchable(), Ref::new("ReturnStatementSegment") .to_matchable(), Ref::new("SetNamesStatementSegment") .to_matchable(), Ref::new("CreateEventStatementSegment") .to_matchable(), Ref::new("AlterEventStatementSegment") .to_matchable(), Ref::new("DropEventStatementSegment") .to_matchable()]), None, None, Some(vec![Ref::new("CreateSchemaStatementSegment") .to_matchable()]), vec![], false) + }) + .to_matchable() + .into() + ), + ( + "DelimiterStatement".into(), + NodeMatcher::new(SyntaxKind::DelimiterStatement, |_dialect| { + Ref::keyword("DELIMITER") + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CreateProcedureStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateProcedureStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("CREATE") .to_matchable(), Ref::new("DefinerSegment") .optional() .to_matchable(), Ref::keyword("PROCEDURE") .to_matchable(), Ref::new("IfNotExistsGrammar") .optional() .to_matchable(), Ref::new("FunctionNameSegment") .to_matchable(), Ref::new("ProcedureParameterListGrammar") .optional() .to_matchable(), Ref::new("CommentClauseSegment") .optional() .to_matchable(), Ref::new("CharacteristicStatement") .optional() .to_matchable(), Ref::new("FunctionDefinitionGrammar") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "FunctionDefinitionGrammar".into(), + NodeMatcher::new(SyntaxKind::FunctionDefinition, |_dialect| { + Ref::new("TransactionStatementSegment") + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CharacteristicStatement".into(), + NodeMatcher::new(SyntaxKind::CharacteristicStatement, |_dialect| { + Sequence::new(vec![one_of(vec![Ref::keyword("DETERMINISTIC") .to_matchable(), Sequence::new(vec![Ref::keyword("NOT") .to_matchable(), Ref::keyword("DETERMINISTIC") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("LANGUAGE") .to_matchable(), Ref::keyword("SQL") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("CONTAINS") .to_matchable(), Ref::keyword("SQL") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("NO") .to_matchable(), Ref::keyword("SQL") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("READS") .to_matchable(), Ref::keyword("SQL") .to_matchable(), Ref::keyword("DATA") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("MODIFIES") .to_matchable(), Ref::keyword("SQL") .to_matchable(), Ref::keyword("DATA") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("SQL") .to_matchable(), Ref::keyword("SECURITY") .to_matchable(), one_of(vec![Ref::keyword("DEFINER") .to_matchable(), Ref::keyword("INVOKER") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CreateFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateFunctionStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("CREATE") .to_matchable(), Ref::new("DefinerSegment") .optional() .to_matchable(), Ref::keyword("FUNCTION") .to_matchable(), Ref::new("FunctionNameSegment") .to_matchable(), Ref::new("FunctionParameterListGrammar") .optional() .to_matchable(), Sequence::new(vec![Ref::keyword("RETURNS") .to_matchable(), Ref::new("DatatypeSegment") .to_matchable()]) .to_matchable(), Ref::new("CommentClauseSegment") .optional() .to_matchable(), Ref::new("CharacteristicStatement") .to_matchable(), Ref::new("FunctionDefinitionGrammar") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "AlterTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTableStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("ALTER") .to_matchable(), Ref::keyword("TABLE") .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable(), Delimited::new(vec![one_of(vec![Sequence::new(vec![Ref::new("ParameterNameSegment") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), one_of(vec![Ref::new("LiteralGrammar") .to_matchable(), Ref::new("NakedIdentifierSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("ADD") .to_matchable(), Ref::keyword("COLUMN") .optional() .to_matchable(), Ref::new("IfNotExistsGrammar") .optional() .to_matchable(), Ref::new("ColumnDefinitionSegment") .to_matchable(), one_of(vec![Ref::keyword("FIRST") .to_matchable(), Sequence::new(vec![Ref::keyword("AFTER") .to_matchable(), Ref::new("ColumnReferenceSegment") .to_matchable()]) .to_matchable(), Ref::new("BracketedColumnReferenceListGrammar") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("ALTER") .to_matchable(), Ref::keyword("COLUMN") .optional() .to_matchable(), Ref::new("SingleIdentifierGrammar") .to_matchable(), AnyNumberOf::new(vec![one_of(vec![Sequence::new(vec![Ref::keyword("SET") .to_matchable(), Ref::keyword("DEFAULT") .to_matchable(), one_of(vec![Ref::new("LiteralGrammar") .to_matchable(), Ref::new("ExpressionSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("DROP") .to_matchable(), Ref::keyword("DEFAULT") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("SET") .to_matchable(), one_of(vec![Ref::keyword("INVISIBLE") .to_matchable(), Ref::keyword("VISIBLE") .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.max_times_per_element = Some(1); this.min_times(1); }) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("MODIFY") .to_matchable(), Ref::keyword("COLUMN") .optional() .to_matchable(), Ref::new("ColumnDefinitionSegment") .to_matchable(), one_of(vec![Ref::keyword("FIRST") .to_matchable(), Sequence::new(vec![Ref::keyword("AFTER") .to_matchable(), Ref::new("ColumnReferenceSegment") .to_matchable()]) .to_matchable(), Ref::new("BracketedColumnReferenceListGrammar") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("ADD") .to_matchable(), Ref::new("TableConstraintSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("CHANGE") .to_matchable(), Ref::keyword("COLUMN") .optional() .to_matchable(), Ref::new("ColumnReferenceSegment") .to_matchable(), Ref::new("ColumnDefinitionSegment") .to_matchable(), one_of(vec![Sequence::new(vec![one_of(vec![Ref::keyword("FIRST") .to_matchable(), Sequence::new(vec![Ref::keyword("AFTER") .to_matchable(), Ref::new("ColumnReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("DROP") .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("COLUMN") .optional() .to_matchable(), Ref::new("ColumnReferenceSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("INDEX") .to_matchable(), Ref::keyword("KEY") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::new("IndexReferenceSegment") .to_matchable()]) .to_matchable(), Ref::new("PrimaryKeyGrammar") .to_matchable(), Sequence::new(vec![Ref::new("ForeignKeyGrammar") .to_matchable(), Ref::new("ObjectReferenceSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("CHECK") .to_matchable(), Ref::keyword("CONSTRAINT") .to_matchable()]) .to_matchable(), Ref::new("ObjectReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("ALTER") .to_matchable(), one_of(vec![Ref::keyword("CHECK") .to_matchable(), Ref::keyword("CONSTRAINT") .to_matchable()]) .to_matchable(), Ref::new("ObjectReferenceSegment") .to_matchable(), one_of(vec![Ref::keyword("ENFORCED") .to_matchable(), Sequence::new(vec![Ref::keyword("NOT") .to_matchable(), Ref::keyword("ENFORCED") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("ALTER") .to_matchable(), Ref::keyword("INDEX") .to_matchable(), Ref::new("IndexReferenceSegment") .to_matchable(), one_of(vec![Ref::keyword("VISIBLE") .to_matchable(), Ref::keyword("INVISIBLE") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("RENAME") .to_matchable(), one_of(vec![Sequence::new(vec![one_of(vec![Ref::keyword("AS") .to_matchable(), Ref::keyword("TO") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("INDEX") .to_matchable(), Ref::keyword("KEY") .to_matchable()]) .to_matchable(), Ref::new("IndexReferenceSegment") .to_matchable(), Ref::keyword("TO") .to_matchable(), Ref::new("IndexReferenceSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("COLUMN") .to_matchable(), Ref::new("ColumnReferenceSegment") .to_matchable(), Ref::keyword("TO") .to_matchable(), Ref::new("ColumnReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("DISABLE") .to_matchable(), Ref::keyword("ENABLE") .to_matchable()]) .to_matchable(), Ref::keyword("KEYS") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("CONVERT") .to_matchable(), Ref::keyword("TO") .to_matchable(), AnyNumberOf::new(vec![Ref::new("AlterOptionSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("ADD") .to_matchable(), Ref::keyword("DROP") .to_matchable(), Ref::keyword("DISCARD") .to_matchable(), Ref::keyword("IMPORT") .to_matchable(), Ref::keyword("TRUNCATE") .to_matchable(), Ref::keyword("COALESCE") .to_matchable(), Ref::keyword("REORGANIZE") .to_matchable(), Ref::keyword("EXCHANGE") .to_matchable(), Ref::keyword("ANALYZE") .to_matchable(), Ref::keyword("CHECK") .to_matchable(), Ref::keyword("OPTIMIZE") .to_matchable(), Ref::keyword("REBUILD") .to_matchable(), Ref::keyword("REPAIR") .to_matchable(), Ref::keyword("REMOVE") .to_matchable()]) .to_matchable(), one_of(vec![Ref::keyword("PARTITION") .to_matchable(), Ref::keyword("PARTITIONING") .to_matchable()]) .to_matchable(), one_of(vec![Ref::new("SingleIdentifierGrammar") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable(), Ref::keyword("ALL") .to_matchable(), Bracketed::new(vec![Delimited::new(vec![Ref::new("ObjectReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Ref::keyword("TABLESPACE") .optional() .to_matchable(), Sequence::new(vec![Ref::keyword("WITH") .to_matchable(), Ref::keyword("TABLE") .to_matchable(), Ref::new("TableReference") .to_matchable(), one_of(vec![Ref::keyword("WITH") .to_matchable(), Ref::keyword("WITHOUT") .to_matchable()]) .to_matchable(), Ref::keyword("VALIDATION") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("INTO") .to_matchable(), Bracketed::new(vec![Delimited::new(vec![Ref::new("ObjectReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "WithCheckOptionSegment".into(), + NodeMatcher::new(SyntaxKind::WithCheckOptions, |_dialect| { + Sequence::new(vec![Ref::keyword("WITH") .to_matchable(), one_of(vec![Ref::keyword("CASCADED") .to_matchable(), Ref::keyword("LOCAL") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("CHECK") .to_matchable(), Ref::keyword("OPTION") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "AlterViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterViewStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("ALTER") .to_matchable(), Sequence::new(vec![Ref::keyword("ALGORITHM") .to_matchable(), Ref::new("EqualsSegment") .to_matchable(), one_of(vec![Ref::keyword("UNDEFINED") .to_matchable(), Ref::keyword("MERGE") .to_matchable(), Ref::keyword("TEMPTABLE") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::new("DefinerSegment") .optional() .to_matchable(), Sequence::new(vec![Ref::keyword("SQL") .to_matchable(), Ref::keyword("SECURITY") .to_matchable(), one_of(vec![Ref::keyword("DEFINER") .to_matchable(), Ref::keyword("INVOKER") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("VIEW") .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable(), Ref::new("BracketedColumnReferenceListGrammar") .optional() .to_matchable(), Ref::keyword("AS") .to_matchable(), optionally_bracketed(vec![Ref::new("SelectableGrammar") .to_matchable()]) .to_matchable(), Ref::new("WithCheckOptionSegment") .optional() .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CreateViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateViewStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("CREATE") .to_matchable(), Ref::new("OrReplaceGrammar") .optional() .to_matchable(), Sequence::new(vec![Ref::keyword("ALGORITHM") .to_matchable(), Ref::new("EqualsSegment") .to_matchable(), one_of(vec![Ref::keyword("UNDEFINED") .to_matchable(), Ref::keyword("MERGE") .to_matchable(), Ref::keyword("TEMPTABLE") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::new("DefinerSegment") .optional() .to_matchable(), Sequence::new(vec![Ref::keyword("SQL") .to_matchable(), Ref::keyword("SECURITY") .to_matchable(), one_of(vec![Ref::keyword("DEFINER") .to_matchable(), Ref::keyword("INVOKER") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("VIEW") .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable(), Ref::new("BracketedColumnReferenceListGrammar") .optional() .to_matchable(), Ref::keyword("AS") .to_matchable(), optionally_bracketed(vec![Ref::new("SelectableGrammar") .to_matchable()]) .to_matchable(), Ref::new("WithCheckOptionSegment") .optional() .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "ProcedureParameterListGrammar".into(), + NodeMatcher::new(SyntaxKind::ProcedureParameterList, |_dialect| { + Bracketed::new(vec![Delimited::new(vec![Ref::new("ProcedureParameterGrammar") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "SetAssignmentStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SetStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("SET") .to_matchable(), Delimited::new(vec![Sequence::new(vec![Sequence::new(vec![one_of(vec![Ref::keyword("NEW") .to_matchable(), Ref::keyword("OLD") .to_matchable()]) .to_matchable(), Ref::new("DotSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), one_of(vec![Ref::keyword("GLOBAL") .to_matchable(), Ref::keyword("PERSIST") .to_matchable(), Ref::keyword("PERSIST_ONLY") .to_matchable(), Ref::keyword("SESSION") .to_matchable(), Ref::keyword("LOCAL") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), one_of(vec![Ref::new("SessionVariableNameSegment") .to_matchable(), Ref::new("LocalVariableNameSegment") .to_matchable(), Ref::new("SystemVariableSegment") .to_matchable()]) .to_matchable(), one_of(vec![Ref::new("EqualsSegment") .to_matchable(), Ref::new("WalrusOperatorSegment") .to_matchable()]) .to_matchable(), AnyNumberOf::new(vec![Ref::new("NumericLiteralSegment") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable(), Ref::new("DoubleQuotedLiteralSegment") .to_matchable(), Ref::new("SessionVariableNameSegment") .to_matchable(), Ref::new("SystemVariableSegment") .to_matchable(), Ref::new("BooleanDynamicSystemVariablesGrammar") .to_matchable(), Ref::new("LocalVariableNameSegment") .to_matchable(), Ref::new("FunctionSegment") .to_matchable(), Ref::new("ArithmeticBinaryOperatorGrammar") .to_matchable(), Ref::new("ExpressionSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "TransactionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::TransactionStatement, |_dialect| { + one_of(vec![Sequence::new(vec![Ref::keyword("START") .to_matchable(), Ref::keyword("TRANSACTION") .to_matchable()]) .to_matchable(), Sequence::new(vec![Sequence::new(vec![Ref::new("SingleIdentifierGrammar") .to_matchable(), Ref::new("ColonSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("BEGIN") .to_matchable(), Ref::keyword("WORK") .optional() .to_matchable(), Ref::new("StatementSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("LEAVE") .to_matchable(), Ref::new("SingleIdentifierGrammar") .optional() .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("COMMIT") .to_matchable(), Ref::keyword("WORK") .optional() .to_matchable(), Sequence::new(vec![Ref::keyword("AND") .to_matchable(), Ref::keyword("NO") .optional() .to_matchable(), Ref::keyword("CHAIN") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("ROLLBACK") .to_matchable(), Ref::keyword("WORK") .optional() .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("END") .to_matchable(), Ref::new("SingleIdentifierGrammar") .optional() .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "IfExpressionStatement".into(), + NodeMatcher::new(SyntaxKind::IfThenStatement, |_dialect| { + AnyNumberOf::new(vec![Sequence::new(vec![Ref::keyword("IF") .to_matchable(), Ref::new("ExpressionSegment") .to_matchable(), Ref::keyword("THEN") .to_matchable(), Ref::new("StatementSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("ELSEIF") .to_matchable(), Ref::new("ExpressionSegment") .to_matchable(), Ref::keyword("THEN") .to_matchable(), Ref::new("StatementSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("ELSE") .to_matchable(), Ref::new("StatementSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("END") .to_matchable(), Ref::keyword("IF") .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "DefinerSegment".into(), + NodeMatcher::new(SyntaxKind::DefinerSegment, |_dialect| { + Sequence::new(vec![Ref::keyword("DEFINER") .to_matchable(), Ref::new("EqualsSegment") .to_matchable(), Ref::new("RoleReferenceSegment") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "SelectClauseModifierSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClauseModifier, |_dialect| { + Sequence::new(vec![one_of(vec![Ref::keyword("DISTINCT") .to_matchable(), Ref::keyword("ALL") .to_matchable(), Ref::keyword("DISTINCTROW") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("HIGH_PRIORITY") .optional() .to_matchable(), Ref::keyword("STRAIGHT_JOIN") .optional() .to_matchable(), Ref::keyword("SQL_SMALL_RESULT") .optional() .to_matchable(), Ref::keyword("SQL_BIG_RESULT") .optional() .to_matchable(), Ref::keyword("SQL_BUFFER_RESULT") .optional() .to_matchable(), Ref::keyword("SQL_CACHE") .optional() .to_matchable(), Ref::keyword("SQL_NO_CACHE") .optional() .to_matchable(), Ref::keyword("SQL_CALC_FOUND_ROWS") .optional() .to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "IntoClauseSegment".into(), + NodeMatcher::new(SyntaxKind::IntoClause, |_dialect| { + Sequence::new(vec![Ref::keyword("INTO") .to_matchable(), one_of(vec![Delimited::new(vec![AnyNumberOf::new(vec![Ref::new("SessionVariableNameSegment") .to_matchable(), Ref::new("LocalVariableNameSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("DUMPFILE") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("OUTFILE") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable(), Sequence::new(vec![Ref::keyword("CHARACTER") .to_matchable(), Ref::keyword("SET") .to_matchable(), Ref::new("NakedIdentifierSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("FIELDS") .to_matchable(), Ref::keyword("COLUMNS") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("TERMINATED") .to_matchable(), Ref::keyword("BY") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("OPTIONALLY") .optional() .to_matchable(), Ref::keyword("ENCLOSED") .to_matchable(), Ref::keyword("BY") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("ESCAPED") .to_matchable(), Ref::keyword("BY") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("LINES") .to_matchable(), Sequence::new(vec![Ref::keyword("STARTING") .to_matchable(), Ref::keyword("BY") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("TERMINATED") .to_matchable(), Ref::keyword("BY") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) + .config(|this| { + this.parse_mode(ParseMode::GreedyOnceStarted); + this.terminators = vec![Ref::new("SelectClauseTerminatorGrammar") .to_matchable()]; + }) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "UnorderedSelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { let dialect = super::ansi::raw_dialect(); dialect.grammar("UnorderedSelectStatementSegment").match_grammar(&dialect).unwrap() }.copy(Some(vec![Ref::new("IntoClauseSegment") .optional() .to_matchable()]), None, Some(Ref::new("FromClauseSegment") .optional() .to_matchable()), None, vec![], false).copy(Some(vec![Ref::new("ForClauseSegment") .optional() .to_matchable()]), None, None, None, vec![], false).copy(Some(vec![Ref::new("IndexHintClauseSegment") .optional() .to_matchable()]), None, Some(Ref::new("WhereClauseSegment") .optional() .to_matchable()), None, vec![], false).copy(Some(vec![Ref::new("SelectPartitionClauseSegment") .optional() .to_matchable()]), None, Some(Ref::new("WhereClauseSegment") .optional() .to_matchable()), None, vec![Ref::new("IntoClauseSegment") .to_matchable(), Ref::new("ForClauseSegment") .to_matchable(), Ref::new("IndexHintClauseSegment") .to_matchable(), Ref::new("WithCheckOptionSegment") .to_matchable(), Ref::new("SelectPartitionClauseSegment") .to_matchable(), Ref::new("UpsertClauseListSegment") .to_matchable()], false) + }) + .to_matchable() + .into() + ), + ( + "SelectClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClause, |_dialect| { + { let dialect = super::ansi::raw_dialect(); dialect.grammar("SelectClauseSegment").match_grammar(&dialect).unwrap() }.copy(None, None, None, None, vec![Ref::keyword("INTO") .to_matchable()], false) + }) + .to_matchable() + .into() + ), + ( + "SelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + get_unordered_select_statement_segment_grammar().copy(Some(vec![Ref::new("OrderByClauseSegment") .optional() .to_matchable(), Ref::new("LimitClauseSegment") .optional() .to_matchable(), Ref::new("NamedWindowSegment") .optional() .to_matchable(), Ref::new("IntoClauseSegment") .optional() .to_matchable()]), None, None, None, vec![Ref::new("SetOperatorSegment") .to_matchable(), Ref::new("UpsertClauseListSegment") .to_matchable(), Ref::new("WithCheckOptionSegment") .to_matchable()], true) + }) + .to_matchable() + .into() + ), + ( + "ForClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ForClause, |_dialect| { + one_of(vec![Sequence::new(vec![Sequence::new(vec![Ref::keyword("FOR") .to_matchable(), one_of(vec![Ref::keyword("UPDATE") .to_matchable(), Ref::keyword("SHARE") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("OF") .to_matchable(), Delimited::new(vec![Ref::new("NakedIdentifierSegment") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), one_of(vec![Ref::keyword("NOWAIT") .to_matchable(), Sequence::new(vec![Ref::keyword("SKIP") .to_matchable(), Ref::keyword("LOCKED") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("LOCK") .to_matchable(), Ref::keyword("IN") .to_matchable(), Ref::keyword("SHARE") .to_matchable(), Ref::keyword("MODE") .to_matchable()]) .to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "IndexHintClauseSegment".into(), + NodeMatcher::new(SyntaxKind::IndexHintClause, |_dialect| { + Sequence::new(vec![one_of(vec![Ref::keyword("USE") .to_matchable(), Ref::keyword("IGNORE") .to_matchable(), Ref::keyword("FORCE") .to_matchable()]) .to_matchable(), one_of(vec![Ref::keyword("INDEX") .to_matchable(), Ref::keyword("KEY") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("FOR") .to_matchable(), one_of(vec![Ref::keyword("JOIN") .to_matchable(), Sequence::new(vec![Ref::keyword("ORDER") .to_matchable(), Ref::keyword("BY") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("GROUP") .to_matchable(), Ref::keyword("BY") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Bracketed::new(vec![Ref::new("ObjectReferenceSegment") .to_matchable()]) .to_matchable(), Ref::new("JoinOnConditionSegment") .optional() .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CallStoredProcedureSegment".into(), + NodeMatcher::new(SyntaxKind::CallStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("CALL") .to_matchable(), Ref::new("FunctionSegment") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "SelectPartitionClauseSegment".into(), + NodeMatcher::new(SyntaxKind::PartitionClause, |_dialect| { + Sequence::new(vec![Ref::keyword("PARTITION") .to_matchable(), Bracketed::new(vec![Delimited::new(vec![Ref::new("ObjectReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "WhileStatementSegment".into(), + NodeMatcher::new(SyntaxKind::WhileStatement, |_dialect| { + one_of(vec![Sequence::new(vec![Sequence::new(vec![Ref::new("SingleIdentifierGrammar") .to_matchable(), Ref::new("ColonSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("WHILE") .to_matchable(), Ref::new("ExpressionSegment") .to_matchable(), Ref::keyword("DO") .to_matchable(), AnyNumberOf::new(vec![Ref::new("StatementSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("END") .to_matchable(), Ref::keyword("WHILE") .to_matchable(), Ref::new("SingleIdentifierGrammar") .optional() .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "PrepareSegment".into(), + NodeMatcher::new(SyntaxKind::PrepareSegment, |_dialect| { + Sequence::new(vec![Ref::keyword("PREPARE") .to_matchable(), Ref::new("NakedIdentifierSegment") .to_matchable(), Ref::keyword("FROM") .to_matchable(), one_of(vec![Ref::new("QuotedLiteralSegment") .to_matchable(), Ref::new("SessionVariableNameSegment") .to_matchable(), Ref::new("LocalVariableNameSegment") .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "GetDiagnosticsSegment".into(), + NodeMatcher::new(SyntaxKind::GetDiagnosticsSegment, |_dialect| { + Sequence::new(vec![Ref::keyword("GET") .to_matchable(), Sequence::new(vec![Ref::keyword("CURRENT") .to_matchable(), Ref::keyword("STACKED") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("DIAGNOSTICS") .to_matchable(), Delimited::new(vec![Sequence::new(vec![one_of(vec![Ref::new("SessionVariableNameSegment") .to_matchable(), Ref::new("LocalVariableNameSegment") .to_matchable()]) .to_matchable(), Ref::new("EqualsSegment") .to_matchable(), one_of(vec![Ref::keyword("NUMBER") .to_matchable(), Ref::keyword("ROW_COUNT") .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("CONDITION") .to_matchable(), one_of(vec![Ref::new("SessionVariableNameSegment") .to_matchable(), Ref::new("LocalVariableNameSegment") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable()]) .to_matchable(), Delimited::new(vec![Sequence::new(vec![one_of(vec![Ref::new("SessionVariableNameSegment") .to_matchable(), Ref::new("LocalVariableNameSegment") .to_matchable()]) .to_matchable(), Ref::new("EqualsSegment") .to_matchable(), one_of(vec![Ref::keyword("CLASS_ORIGIN") .to_matchable(), Ref::keyword("SUBCLASS_ORIGIN") .to_matchable(), Ref::keyword("RETURNED_SQLSTATE") .to_matchable(), Ref::keyword("MESSAGE_TEXT") .to_matchable(), Ref::keyword("MYSQL_ERRNO") .to_matchable(), Ref::keyword("CONSTRAINT_CATALOG") .to_matchable(), Ref::keyword("CONSTRAINT_SCHEMA") .to_matchable(), Ref::keyword("CONSTRAINT_NAME") .to_matchable(), Ref::keyword("CATALOG_NAME") .to_matchable(), Ref::keyword("SCHEMA_NAME") .to_matchable(), Ref::keyword("TABLE_NAME") .to_matchable(), Ref::keyword("COLUMN_NAME") .to_matchable(), Ref::keyword("CURSOR_NAME") .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "LoopStatementSegment".into(), + NodeMatcher::new(SyntaxKind::LoopStatement, |_dialect| { + one_of(vec![Sequence::new(vec![Sequence::new(vec![Ref::new("SingleIdentifierGrammar") .to_matchable(), Ref::new("ColonSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("LOOP") .to_matchable(), Delimited::new(vec![Ref::new("StatementSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("END") .to_matchable(), Ref::keyword("LOOP") .to_matchable(), Ref::new("SingleIdentifierGrammar") .optional() .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CursorOpenCloseSegment".into(), + NodeMatcher::new(SyntaxKind::CursorOpenCloseSegment, |_dialect| { + Sequence::new(vec![one_of(vec![Ref::keyword("CLOSE") .to_matchable(), Ref::keyword("OPEN") .to_matchable()]) .to_matchable(), one_of(vec![Ref::new("SingleIdentifierGrammar") .to_matchable(), Ref::new("QuotedIdentifierSegment") .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "IterateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::IterateStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("ITERATE") .to_matchable(), Ref::new("SingleIdentifierGrammar") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "ExecuteSegment".into(), + NodeMatcher::new(SyntaxKind::ExecuteSegment, |_dialect| { + Sequence::new(vec![Ref::keyword("EXECUTE") .to_matchable(), Ref::new("NakedIdentifierSegment") .to_matchable(), Sequence::new(vec![Ref::keyword("USING") .to_matchable(), Delimited::new(vec![Ref::new("SessionVariableNameSegment") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "RepeatStatementSegment".into(), + NodeMatcher::new(SyntaxKind::RepeatStatement, |_dialect| { + one_of(vec![Sequence::new(vec![Sequence::new(vec![Ref::new("SingleIdentifierGrammar") .to_matchable(), Ref::new("ColonSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("REPEAT") .to_matchable(), AnyNumberOf::new(vec![Ref::new("StatementSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("UNTIL") .to_matchable(), Ref::new("ExpressionSegment") .to_matchable(), Sequence::new(vec![Ref::keyword("END") .to_matchable(), Ref::keyword("REPEAT") .to_matchable(), Ref::new("SingleIdentifierGrammar") .optional() .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "DeallocateSegment".into(), + NodeMatcher::new(SyntaxKind::DeallocateSegment, |_dialect| { + Sequence::new(vec![Sequence::new(vec![one_of(vec![Ref::keyword("DEALLOCATE") .to_matchable(), Ref::keyword("DROP") .to_matchable()]) .to_matchable(), Ref::keyword("PREPARE") .to_matchable()]) .to_matchable(), Ref::new("NakedIdentifierSegment") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "ResignalSegment".into(), + NodeMatcher::new(SyntaxKind::ResignalSegment, |_dialect| { + Sequence::new(vec![one_of(vec![Ref::keyword("SIGNAL") .to_matchable(), Ref::keyword("RESIGNAL") .to_matchable()]) .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("SQLSTATE") .to_matchable(), Ref::keyword("VALUE") .optional() .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable(), Ref::new("NakedIdentifierSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("SET") .to_matchable(), Delimited::new(vec![Sequence::new(vec![one_of(vec![Ref::keyword("CLASS_ORIGIN") .to_matchable(), Ref::keyword("SUBCLASS_ORIGIN") .to_matchable(), Ref::keyword("RETURNED_SQLSTATE") .to_matchable(), Ref::keyword("MESSAGE_TEXT") .to_matchable(), Ref::keyword("MYSQL_ERRNO") .to_matchable(), Ref::keyword("CONSTRAINT_CATALOG") .to_matchable(), Ref::keyword("CONSTRAINT_SCHEMA") .to_matchable(), Ref::keyword("CONSTRAINT_NAME") .to_matchable(), Ref::keyword("CATALOG_NAME") .to_matchable(), Ref::keyword("SCHEMA_NAME") .to_matchable(), Ref::keyword("TABLE_NAME") .to_matchable(), Ref::keyword("COLUMN_NAME") .to_matchable(), Ref::keyword("CURSOR_NAME") .to_matchable()]) .to_matchable(), Ref::new("EqualsSegment") .to_matchable(), one_of(vec![Ref::new("SessionVariableNameSegment") .to_matchable(), Ref::new("LocalVariableNameSegment") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CursorFetchSegment".into(), + NodeMatcher::new(SyntaxKind::CursorFetchSegment, |_dialect| { + Sequence::new(vec![Ref::keyword("FETCH") .to_matchable(), Sequence::new(vec![Ref::keyword("NEXT") .optional() .to_matchable(), Ref::keyword("FROM") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::new("NakedIdentifierSegment") .to_matchable(), Ref::keyword("INTO") .to_matchable(), Delimited::new(vec![Ref::new("SessionVariableNameSegment") .to_matchable(), Ref::new("LocalVariableNameSegment") .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "DropIndexStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropIndexStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("DROP") .to_matchable(), Ref::keyword("INDEX") .to_matchable(), Ref::new("IndexReferenceSegment") .to_matchable(), Ref::keyword("ON") .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("ALGORITHM") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), one_of(vec![Ref::keyword("DEFAULT") .to_matchable(), Ref::keyword("INPLACE") .to_matchable(), Ref::keyword("COPY") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("LOCK") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), one_of(vec![Ref::keyword("DEFAULT") .to_matchable(), Ref::keyword("NONE") .to_matchable(), Ref::keyword("SHARED") .to_matchable(), Ref::keyword("EXCLUSIVE") .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "DropProcedureStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropProcedureStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("DROP") .to_matchable(), one_of(vec![Ref::keyword("PROCEDURE") .to_matchable(), Ref::keyword("FUNCTION") .to_matchable()]) .to_matchable(), Ref::new("IfExistsGrammar") .optional() .to_matchable(), Ref::new("ObjectReferenceSegment") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "DropFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("DROP") .to_matchable(), Ref::keyword("FUNCTION") .to_matchable(), Ref::new("IfExistsGrammar") .optional() .to_matchable(), Ref::new("FunctionNameSegment") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "RenameTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::RenameTableStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("RENAME") .to_matchable(), Ref::keyword("TABLE") .to_matchable(), Delimited::new(vec![Sequence::new(vec![Ref::new("TableReferenceSegment") .to_matchable(), Ref::keyword("TO") .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "ResetMasterStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ResetMasterStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("RESET") .to_matchable(), Ref::keyword("MASTER") .to_matchable(), Sequence::new(vec![Ref::keyword("TO") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "PurgeBinaryLogsStatementSegment".into(), + NodeMatcher::new(SyntaxKind::PurgeBinaryLogsStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("PURGE") .to_matchable(), one_of(vec![Ref::keyword("BINARY") .to_matchable(), Ref::keyword("MASTER") .to_matchable()]) .to_matchable(), Ref::keyword("LOGS") .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("TO") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("BEFORE") .to_matchable(), one_of(vec![Ref::new("ExpressionSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "HelpStatementSegment".into(), + NodeMatcher::new(SyntaxKind::HelpStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("HELP") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CheckTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CheckTableStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("CHECK") .to_matchable(), Ref::keyword("TABLE") .to_matchable(), Delimited::new(vec![Ref::new("TableReferenceSegment") .to_matchable()]) .to_matchable(), AnyNumberOf::new(vec![Sequence::new(vec![Ref::keyword("FOR") .to_matchable(), Ref::keyword("UPGRADE") .to_matchable()]) .to_matchable(), Ref::keyword("QUICK") .to_matchable(), Ref::keyword("FAST") .to_matchable(), Ref::keyword("MEDIUM") .to_matchable(), Ref::keyword("EXTENDED") .to_matchable(), Ref::keyword("CHANGED") .to_matchable()]) .config(|this| { this.min_times(1); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "ChecksumTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ChecksumTableStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("CHECKSUM") .to_matchable(), Ref::keyword("TABLE") .to_matchable(), Delimited::new(vec![Ref::new("TableReferenceSegment") .to_matchable()]) .to_matchable(), one_of(vec![Ref::keyword("QUICK") .to_matchable(), Ref::keyword("EXTENDED") .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "AnalyzeTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AnalyzeTableStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("ANALYZE") .to_matchable(), one_of(vec![Ref::keyword("NO_WRITE_TO_BINLOG") .to_matchable(), Ref::keyword("LOCAL") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("TABLE") .to_matchable(), one_of(vec![Sequence::new(vec![Delimited::new(vec![Ref::new("TableReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::new("TableReferenceSegment") .to_matchable(), Ref::keyword("UPDATE") .to_matchable(), Ref::keyword("HISTOGRAM") .to_matchable(), Ref::keyword("ON") .to_matchable(), Delimited::new(vec![Ref::new("ColumnReferenceSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("WITH") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable(), Ref::keyword("BUCKETS") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::new("TableReferenceSegment") .to_matchable(), Ref::keyword("DROP") .to_matchable(), Ref::keyword("HISTOGRAM") .to_matchable(), Ref::keyword("ON") .to_matchable(), Delimited::new(vec![Ref::new("ColumnReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "RepairTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::RepairTableStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("REPAIR") .to_matchable(), one_of(vec![Ref::keyword("NO_WRITE_TO_BINLOG") .to_matchable(), Ref::keyword("LOCAL") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("TABLE") .to_matchable(), Delimited::new(vec![Ref::new("TableReferenceSegment") .to_matchable()]) .to_matchable(), AnyNumberOf::new(vec![Ref::keyword("QUICK") .to_matchable(), Ref::keyword("EXTENDED") .to_matchable(), Ref::keyword("USE_FRM") .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "OptimizeTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::OptimizeTableStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("OPTIMIZE") .to_matchable(), one_of(vec![Ref::keyword("NO_WRITE_TO_BINLOG") .to_matchable(), Ref::keyword("LOCAL") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("TABLE") .to_matchable(), Delimited::new(vec![Ref::new("TableReferenceSegment") .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "UpdateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::UpdateStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("UPDATE") .to_matchable(), Ref::keyword("LOW_PRIORITY") .optional() .to_matchable(), Ref::keyword("IGNORE") .optional() .to_matchable(), MetaSegment::indent() .to_matchable(), Delimited::new(vec![Ref::new("TableReferenceSegment") .to_matchable(), Ref::new("FromExpressionSegment") .to_matchable()]) .to_matchable(), MetaSegment::dedent() .to_matchable(), Ref::new("SetClauseListSegment") .to_matchable(), Ref::new("WhereClauseSegment") .optional() .to_matchable(), Ref::new("OrderByClauseSegment") .optional() .to_matchable(), Ref::new("LimitClauseSegment") .optional() .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "FlushStatementSegment".into(), + NodeMatcher::new(SyntaxKind::FlushStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("FLUSH") .to_matchable(), one_of(vec![Ref::keyword("NO_WRITE_TO_BINLOG") .to_matchable(), Ref::keyword("LOCAL") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), one_of(vec![Delimited::new(vec![Sequence::new(vec![Ref::keyword("BINARY") .to_matchable(), Ref::keyword("LOGS") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("ENGINE") .to_matchable(), Ref::keyword("LOGS") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("ERROR") .to_matchable(), Ref::keyword("LOGS") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("GENERAL") .to_matchable(), Ref::keyword("LOGS") .to_matchable()]) .to_matchable(), Ref::keyword("HOSTS") .to_matchable(), Ref::keyword("LOGS") .to_matchable(), Ref::keyword("PRIVILEGES") .to_matchable(), Ref::keyword("OPTIMIZER_COSTS") .to_matchable(), Sequence::new(vec![Ref::keyword("RELAY") .to_matchable(), Ref::keyword("LOGS") .to_matchable(), Sequence::new(vec![Ref::keyword("FOR") .to_matchable(), Ref::keyword("CHANNEL") .to_matchable(), Ref::new("ObjectReferenceSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("SLOW") .to_matchable(), Ref::keyword("LOGS") .to_matchable()]) .to_matchable(), Ref::keyword("STATUS") .to_matchable(), Ref::keyword("USER_RESOURCES") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("TABLES") .to_matchable(), Sequence::new(vec![Delimited::new(vec![Ref::new("TableReferenceSegment") .to_matchable()]) .config(|this| { this.terminators = vec![Ref::keyword("WITH") .to_matchable()]; }) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("WITH") .to_matchable(), Ref::keyword("READ") .to_matchable(), Ref::keyword("LOCK") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("TABLES") .to_matchable(), Sequence::new(vec![Delimited::new(vec![Ref::new("TableReferenceSegment") .to_matchable()]) .config(|this| { this.terminators = vec![Ref::keyword("FOR") .to_matchable()]; }) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("FOR") .to_matchable(), Ref::keyword("EXPORT") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "LoadDataSegment".into(), + NodeMatcher::new(SyntaxKind::LoadDataStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("LOAD") .to_matchable(), Ref::keyword("DATA") .to_matchable(), one_of(vec![Ref::keyword("LOW_PRIORITY") .to_matchable(), Ref::keyword("CONCURRENT") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("LOCAL") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("INFILE") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable(), one_of(vec![Ref::keyword("REPLACE") .to_matchable(), Ref::keyword("IGNORE") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("INTO") .to_matchable(), Ref::keyword("TABLE") .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable(), Ref::new("SelectPartitionClauseSegment") .optional() .to_matchable(), Sequence::new(vec![Ref::keyword("CHARACTER") .to_matchable(), Ref::keyword("SET") .to_matchable(), Ref::new("NakedIdentifierSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("FIELDS") .to_matchable(), Ref::keyword("COLUMNS") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("TERMINATED") .to_matchable(), Ref::keyword("BY") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Sequence::new(vec![Ref::keyword("OPTIONALLY") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("ENCLOSED") .to_matchable(), Ref::keyword("BY") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("ESCAPED") .to_matchable(), Ref::keyword("BY") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("LINES") .to_matchable(), Sequence::new(vec![Ref::keyword("STARTING") .to_matchable(), Ref::keyword("BY") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("TERMINATED") .to_matchable(), Ref::keyword("BY") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("IGNORE") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable(), one_of(vec![Ref::keyword("LINES") .to_matchable(), Ref::keyword("ROWS") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Bracketed::new(vec![Delimited::new(vec![Ref::new("ColumnReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("SET") .to_matchable(), Ref::new("Expression_B_Grammar") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "ReplaceSegment".into(), + NodeMatcher::new(SyntaxKind::ReplaceStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("REPLACE") .to_matchable(), one_of(vec![Ref::keyword("LOW_PRIORITY") .to_matchable(), Ref::keyword("DELAYED") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("INTO") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable(), Ref::new("SelectPartitionClauseSegment") .optional() .to_matchable(), one_of(vec![Sequence::new(vec![Ref::new("BracketedColumnReferenceListGrammar") .optional() .to_matchable(), Ref::new("ValuesClauseSegment") .to_matchable()]) .to_matchable(), Ref::new("SetClauseListSegment") .to_matchable(), Sequence::new(vec![Ref::new("BracketedColumnReferenceListGrammar") .optional() .to_matchable(), one_of(vec![Ref::new("SelectableGrammar") .to_matchable(), Sequence::new(vec![Ref::keyword("TABLE") .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CreateTriggerStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTriggerStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("CREATE") .to_matchable(), Ref::new("DefinerSegment") .optional() .to_matchable(), Ref::keyword("TRIGGER") .to_matchable(), Ref::new("IfNotExistsGrammar") .optional() .to_matchable(), Ref::new("TriggerReferenceSegment") .to_matchable(), one_of(vec![Ref::keyword("BEFORE") .to_matchable(), Ref::keyword("AFTER") .to_matchable()]) .to_matchable(), one_of(vec![Ref::keyword("INSERT") .to_matchable(), Ref::keyword("UPDATE") .to_matchable(), Ref::keyword("DELETE") .to_matchable()]) .to_matchable(), Ref::keyword("ON") .to_matchable(), Ref::new("TableReferenceSegment") .to_matchable(), Sequence::new(vec![Ref::keyword("FOR") .to_matchable(), Ref::keyword("EACH") .to_matchable(), Ref::keyword("ROW") .to_matchable()]) .to_matchable(), Sequence::new(vec![one_of(vec![Ref::keyword("FOLLOWS") .to_matchable(), Ref::keyword("PRECEDES") .to_matchable()]) .to_matchable(), Ref::new("SingleIdentifierGrammar") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), one_of(vec![Ref::new("StatementSegment") .to_matchable(), Sequence::new(vec![Ref::keyword("BEGIN") .to_matchable(), Ref::new("StatementSegment") .to_matchable(), Ref::keyword("END") .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "DropTriggerStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropTriggerStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("DROP") .to_matchable(), Ref::keyword("TRIGGER") .to_matchable(), Ref::new("IfExistsGrammar") .optional() .to_matchable(), Ref::new("TriggerReferenceSegment") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CreateDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateDatabaseStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("CREATE") .to_matchable(), one_of(vec![Ref::keyword("DATABASE") .to_matchable(), Ref::keyword("SCHEMA") .to_matchable()]) .to_matchable(), Ref::new("IfNotExistsGrammar") .optional() .to_matchable(), Ref::new("DatabaseReferenceSegment") .to_matchable(), AnyNumberOf::new(vec![Ref::new("CreateOptionSegment") .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CreateOptionSegment".into(), + NodeMatcher::new(SyntaxKind::CreateOptionSegment, |_dialect| { + Sequence::new(vec![Ref::keyword("DEFAULT") .optional() .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("CHARACTER") .to_matchable(), Ref::keyword("SET") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), one_of(vec![Ref::new("NakedIdentifierSegment") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("COLLATE") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), Ref::new("CollationReferenceSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("ENCRYPTION") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "AlterDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterDatabaseStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("ALTER") .to_matchable(), one_of(vec![Ref::keyword("DATABASE") .to_matchable(), Ref::keyword("SCHEMA") .to_matchable()]) .to_matchable(), Ref::new("DatabaseReferenceSegment") .optional() .to_matchable(), AnyNumberOf::new(vec![Ref::new("AlterOptionSegment") .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "AlterOptionSegment".into(), + NodeMatcher::new(SyntaxKind::AlterOptionSegment, |_dialect| { + Sequence::new(vec![one_of(vec![Sequence::new(vec![Ref::keyword("DEFAULT") .optional() .to_matchable(), Ref::keyword("CHARACTER") .to_matchable(), Ref::keyword("SET") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), one_of(vec![Ref::new("SingleIdentifierGrammar") .to_matchable(), Ref::new("SingleQuotedIdentifierSegment") .to_matchable(), Ref::new("DoubleQuotedIdentifierSegment") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("DEFAULT") .optional() .to_matchable(), Ref::keyword("COLLATE") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), Ref::new("CollationReferenceSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("DEFAULT") .optional() .to_matchable(), Ref::keyword("ENCRYPTION") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("READ") .to_matchable(), Ref::keyword("ONLY") .to_matchable(), Ref::new("EqualsSegment") .optional() .to_matchable(), one_of(vec![Ref::keyword("DEFAULT") .to_matchable(), Ref::new("NumericLiteralSegment") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "ReturnStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ReturnStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("RETURN") .to_matchable(), Ref::new("ExpressionSegment") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "SetTransactionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SetTransactionStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("SET") .to_matchable(), one_of(vec![Ref::keyword("GLOBAL") .to_matchable(), Ref::keyword("SESSION") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::keyword("TRANSACTION") .to_matchable(), Delimited::new(vec![Sequence::new(vec![Ref::keyword("ISOLATION") .to_matchable(), Ref::keyword("LEVEL") .to_matchable(), one_of(vec![Sequence::new(vec![Ref::keyword("READ") .to_matchable(), one_of(vec![Ref::keyword("COMMITTED") .to_matchable(), Ref::keyword("UNCOMMITTED") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("REPEATABLE") .to_matchable(), Ref::keyword("READ") .to_matchable()]) .to_matchable(), Ref::keyword("SERIALIZABLE") .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("READ") .to_matchable(), one_of(vec![Ref::keyword("WRITE") .to_matchable(), Ref::keyword("ONLY") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "SetNamesStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SetNamesStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("SET") .to_matchable(), Ref::keyword("NAMES") .to_matchable(), one_of(vec![Ref::keyword("DEFAULT") .to_matchable(), Ref::new("QuotedLiteralSegment") .to_matchable(), Ref::new("NakedIdentifierSegment") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("COLLATE") .to_matchable(), Ref::new("CollationReferenceSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "CreateEventStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateEventStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("CREATE") .to_matchable(), Ref::new("DefinerSegment") .optional() .to_matchable(), Ref::keyword("EVENT") .to_matchable(), Ref::new("IfNotExistsGrammar") .optional() .to_matchable(), Ref::new("ObjectReferenceSegment") .to_matchable(), Ref::keyword("ON") .to_matchable(), Ref::keyword("SCHEDULE") .to_matchable(), one_of(vec![Ref::keyword("AT") .to_matchable(), Ref::keyword("EVERY") .to_matchable()]) .to_matchable(), Ref::new("ExpressionSegment") .to_matchable(), one_of(vec![Ref::new("DatetimeUnitSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), AnyNumberOf::new(vec![Sequence::new(vec![one_of(vec![Ref::keyword("STARTS") .to_matchable(), Ref::keyword("ENDS") .to_matchable()]) .to_matchable(), Ref::new("ExpressionSegment") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("ON") .to_matchable(), Ref::keyword("COMPLETION") .to_matchable(), Ref::keyword("NOT") .optional() .to_matchable(), Ref::keyword("PRESERVE") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), one_of(vec![Ref::keyword("ENABLE") .to_matchable(), Ref::keyword("DISABLE") .to_matchable(), Sequence::new(vec![Ref::keyword("DISABLE") .to_matchable(), Ref::keyword("ON") .to_matchable(), one_of(vec![Ref::keyword("REPLICA") .to_matchable(), Ref::keyword("SLAVE") .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::new("CommentClauseSegment") .optional() .to_matchable(), Ref::keyword("DO") .to_matchable(), Ref::new("StatementSegment") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "AlterEventStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterEventStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("ALTER") .to_matchable(), Ref::new("DefinerSegment") .optional() .to_matchable(), Ref::keyword("EVENT") .to_matchable(), Ref::new("ObjectReferenceSegment") .to_matchable(), Sequence::new(vec![Ref::keyword("ON") .to_matchable(), Ref::keyword("SCHEDULE") .to_matchable(), one_of(vec![Ref::keyword("AT") .to_matchable(), Ref::keyword("EVERY") .to_matchable()]) .to_matchable(), Ref::new("ExpressionSegment") .to_matchable(), one_of(vec![Ref::new("DatetimeUnitSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), AnyNumberOf::new(vec![Sequence::new(vec![one_of(vec![Ref::keyword("STARTS") .to_matchable(), Ref::keyword("ENDS") .to_matchable()]) .to_matchable(), Ref::new("ExpressionSegment") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("ON") .to_matchable(), Ref::keyword("COMPLETION") .to_matchable(), Ref::keyword("NOT") .optional() .to_matchable(), Ref::keyword("PRESERVE") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Sequence::new(vec![Ref::keyword("RENAME") .to_matchable(), Ref::keyword("TO") .to_matchable(), Ref::new("ObjectReferenceSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), one_of(vec![Ref::keyword("ENABLE") .to_matchable(), Ref::keyword("DISABLE") .to_matchable(), Sequence::new(vec![Ref::keyword("DISABLE") .to_matchable(), Ref::keyword("ON") .to_matchable(), one_of(vec![Ref::keyword("REPLICA") .to_matchable(), Ref::keyword("SLAVE") .to_matchable()]) .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable(), Ref::new("CommentClauseSegment") .optional() .to_matchable(), Sequence::new(vec![Ref::keyword("DO") .to_matchable(), Ref::new("StatementSegment") .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "DropEventStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropEventStatement, |_dialect| { + Sequence::new(vec![Ref::keyword("DROP") .to_matchable(), Ref::keyword("EVENT") .to_matchable(), Ref::new("IfExistsGrammar") .optional() .to_matchable(), Ref::new("ObjectReferenceSegment") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "DatatypeSegment".into(), + NodeMatcher::new(SyntaxKind::DataType, |_dialect| { + one_of(vec![Ref::new("TimeWithTZGrammar") .to_matchable(), Sequence::new(vec![Ref::keyword("DOUBLE") .to_matchable(), Ref::keyword("PRECISION") .to_matchable()]) .to_matchable(), Sequence::new(vec![one_of(vec![Sequence::new(vec![one_of(vec![Ref::keyword("CHARACTER") .to_matchable(), Ref::keyword("BINARY") .to_matchable()]) .to_matchable(), one_of(vec![Ref::keyword("VARYING") .to_matchable(), Sequence::new(vec![Ref::keyword("LARGE") .to_matchable(), Ref::keyword("OBJECT") .to_matchable()]) .to_matchable()]) .to_matchable()]) .to_matchable(), Sequence::new(vec![Sequence::new(vec![Ref::new("SingleIdentifierGrammar") .to_matchable(), Ref::new("DotSegment") .to_matchable()]) .config(|this| { this.optional(); this.disallow_gaps(); }) .to_matchable(), Ref::new("DatatypeIdentifierSegment") .to_matchable()]) .config(|this| { this.disallow_gaps(); }) .to_matchable()]) .to_matchable(), Ref::new("BracketedArguments") .optional() .to_matchable(), one_of(vec![Ref::new("CharCharacterSetGrammar") .to_matchable(), Ref::keyword("SIGNED") .to_matchable(), Ref::keyword("UNSIGNED") .to_matchable(), Ref::keyword("ZEROFILL") .to_matchable(), Sequence::new(vec![Ref::keyword("ZEROFILL") .to_matchable(), Ref::keyword("UNSIGNED") .to_matchable()]) .to_matchable(), Sequence::new(vec![Ref::keyword("UNSIGNED") .to_matchable(), Ref::keyword("ZEROFILL") .to_matchable()]) .to_matchable()]) .config(|this| { this.optional(); }) .to_matchable()]) .to_matchable(), Ref::new("ArrayTypeSegment") .to_matchable()]) + .to_matchable() + }) + .to_matchable() + .into() + ), + ( + "NullSafeEqualsSegment".into(), + NodeMatcher::new(SyntaxKind::ComparisonOperator, |_dialect| { + Sequence::new(vec![Ref::new("RawLessThanSegment") .to_matchable(), Ref::new("RawEqualsSegment") .to_matchable(), Ref::new("RawGreaterThanSegment") .to_matchable()]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + }) + .to_matchable() + .into() ), ]); + + mysql_dialect +} - mysql +pub fn get_unordered_select_statement_segment_grammar() -> Matchable { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("UnorderedSelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("IntoClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("FromClauseSegment").optional().to_matchable()), + None, + vec![], + false, + ) + .copy( + Some(vec![Ref::new("ForClauseSegment").optional().to_matchable()]), + None, + None, + None, + vec![], + false, + ) + .copy( + Some(vec![ + Ref::new("IndexHintClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("WhereClauseSegment").optional().to_matchable()), + None, + vec![], + false, + ) + .copy( + Some(vec![ + Ref::new("SelectPartitionClauseSegment") + .optional() + .to_matchable(), + ]), + None, + Some(Ref::new("WhereClauseSegment").optional().to_matchable()), + None, + vec![ + Ref::new("IntoClauseSegment").to_matchable(), + Ref::new("ForClauseSegment").to_matchable(), + Ref::new("IndexHintClauseSegment").to_matchable(), + Ref::new("WithCheckOptionSegment").to_matchable(), + Ref::new("SelectPartitionClauseSegment").to_matchable(), + Ref::new("UpsertClauseListSegment").to_matchable(), + ], + false, + ) } diff --git a/crates/lib-dialects/src/mysql_keywords.rs b/crates/lib-dialects/src/mysql_keywords.rs new file mode 100644 index 000000000..8534dcfd7 --- /dev/null +++ b/crates/lib-dialects/src/mysql_keywords.rs @@ -0,0 +1,782 @@ +pub(crate) const MYSQL_RESERVED_KEYWORDS: &str = "ACCESSIBLE +ADD +ALL +ALTER +ANALYZE +AND +AS +ASC +ASENSITIVE +BEFORE +BETWEEN +BIGINT +BINARY +BLOB +BOTH +BY +CALL +CASCADE +CASE +CHANGE +CHAR +CHARACTER +CHECK +COLLATE +COLUMN +CONDITION +CONSTRAINT +CONTINUE +CONVERT +CREATE +CROSS +CUME_DIST +CURRENT_DATE +CURRENT_TIME +CURRENT_TIMESTAMP +CURRENT_USER +CURSOR +DATABASE +DATABASES +DAY_HOUR +DAY_MICROSECOND +DAY_MINUTE +DAY_SECOND +DEC +DECIMAL +DECLARE +DEFAULT +DELAYED +DELETE +DENSE_RANK +DESC +DESCRIBE +DETERMINISTIC +DISTINCT +DISTINCTROW +DIV +DOUBLE +DROP +DUAL +EACH +ELSE +ELSEIF +EMPTY +ENCLOSED +ESCAPED +EXCEPT +EXISTS +EXIT +EXPLAIN +FALSE +FETCH +FIRST_VALUE +FLOAT +FLOAT4 +FLOAT8 +FOR +FORCE +FOREIGN +FROM +FULLTEXT +GENERATED +GET +GRANT +GROUP +GROUPING +GROUPS +HAVING +HIGH_PRIORITY +HOUR_MICROSECOND +HOUR_MINUTE +HOUR_SECOND +IF +IGNORE +IN +INDEX +INFILE +INNER +INOUT +INSENSITIVE +INSERT +INT +INT1 +INT2 +INT3 +INT4 +INT8 +INTEGER +INTERSECT +INTERVAL +INTO +IO_AFTER_GTIDS +IO_BEFORE_GTIDS +IS +ITERATE +JOIN +JSON_TABLE +KEY +KEYS +KILL +LAG +LAST_VALUE +LATERAL +LEAD +LEADING +LEAVE +LEFT +LIKE +LIMIT +LINEAR +LINES +LOAD +LOCALTIME +LOCALTIMESTAMP +LOCK +LONG +LONGBLOB +LONGTEXT +LOOP +LOW_PRIORITY +MASTER_BIND +MASTER_SSL_VERIFY_SERVER_CERT +MATCH +MAXVALUE +MEDIUMBLOB +MEDIUMINT +MEDIUMTEXT +MIDDLEINT +MINUTE_MICROSECOND +MINUTE_SECOND +MOD +MODIFIES +NATURAL +NOT +NO_WRITE_TO_BINLOG +NTH_VALUE +NTILE +NULL +NUMERIC +OF +ON +OPTIMIZE +OPTIMIZER_COSTS +OPTION +OPTIONALLY +OR +ORDER +OUT +OUTER +OUTFILE +OVER +PARTITION +PERCENT_RANK +PRECISION +PRIMARY +PROCEDURE +PURGE +RANGE +RANK +READ +READS +READ_WRITE +REAL +RECURSIVE +REFERENCES +REGEXP +RELEASE +RENAME +REPEAT +REPLACE +REQUIRE +RESIGNAL +RESTRICT +RETURN +REVOKE +RIGHT +RLIKE +ROW_NUMBER +SCHEMA +SCHEMAS +SECOND_MICROSECOND +SELECT +SENSITIVE +SEPARATOR +SET +SHOW +SIGNAL +SMALLINT +SPATIAL +SPECIFIC +SQL +SQLEXCEPTION +SQLSTATE +SQLWARNING +SQL_BIG_RESULT +SQL_CALC_FOUND_ROWS +SQL_SMALL_RESULT +SSL +STARTING +STORED +STRAIGHT_JOIN +SYSTEM +TABLE +TERMINATED +THEN +TINYBLOB +TINYINT +TINYTEXT +TO +TRAILING +TRIGGER +TRUE +UNDO +UNION +UNIQUE +UNLOCK +UNSIGNED +UPDATE +USAGE +USE +USING +UTC_DATE +UTC_TIME +UTC_TIMESTAMP +VALUES +VARBINARY +VARCHAR +VARCHARACTER +VARYING +VIRTUAL +WHEN +WHERE +WHILE +WINDOW +WITH +WRITE +XOR +YEAR_MONTH +ZEROFILL +"; + +pub(crate) const MYSQL_UNRESERVED_KEYWORDS: &str = "ACCOUNT +ACTION +ACTIVE +ADMIN +AFTER +AGAINST +AGGREGATE +ALGORITHM +ALWAYS +ANALYSE +ANY +ARRAY +ASCII +AT +ATTRIBUTE +AUTHENTICATION +AUTOEXTEND_SIZE +AUTO_INCREMENT +AVG +AVG_ROW_LENGTH +BACKUP +BEGIN +BINLOG +BIT +BLOCK +BOOL +BOOLEAN +BTREE +BUCKETS +BYTE +CACHE +CASCADED +CATALOG_NAME +CHAIN +CHALLENGE_RESPONSE +CHANGED +CHANNEL +CHARSET +CHECKSUM +CIPHER +CLASS_ORIGIN +CLIENT +CLONE +CLOSE +COALESCE +CODE +COLLATION +COLUMNS +COLUMN_FORMAT +COLUMN_NAME +COMMENT +COMMIT +COMMITTED +COMPACT +COMPLETION +COMPONENT +COMPRESSED +COMPRESSION +CONCURRENT +CONNECTION +CONSISTENT +CONSTRAINT_CATALOG +CONSTRAINT_NAME +CONSTRAINT_SCHEMA +CONTAINS +CONTEXT +CPU +CUBE +CUME_DIST +CURRENT +CURSOR_NAME +DATA +DATAFILE +DATE +DATETIME +DAY +DEALLOCATE +DEFAULT_AUTH +DEFINER +DEFINITION +DELAY_KEY_WRITE +DENSE_RANK +DESCRIPTION +DES_KEY_FILE +DIAGNOSTICS +DIRECTORY +DISABLE +DISCARD +DISK +DO +DUMPFILE +DUPLICATE +DYNAMIC +EMPTY +ENABLE +ENCRYPTION +END +ENDS +ENFORCED +ENGINE +ENGINES +ENGINE_ATTRIBUTE +ENUM +ERROR +ERRORS +ESCAPE +EVENT +EVENTS +EVERY +EXCHANGE +EXCLUDE +EXECUTE +EXPANSION +EXPIRE +EXPORT +EXTENDED +EXTENT_SIZE +FACTOR +FAILED_LOGIN_ATTEMPTS +FAST +FAULTS +FIELDS +FILE +FILE_BLOCK_SIZE +FILTER +FINISH +FIRST +FIRST_VALUE +FIXED +FLUSH +FOLLOWING +FOLLOWS +FORMAT +FOUND +FULL +FUNCTION +GENERAL +GEOMCOLLECTION +GEOMETRY +GEOMETRYCOLLECTION +GET_FORMAT +GET_MASTER_PUBLIC_KEY +GET_SOURCE_PUBLIC_KEY +GLOBAL +GRANTS +GROUPING +GROUPS +GROUP_REPLICATION +GTID_ONLY +HANDLER +HASH +HELP +HISTOGRAM +HISTORY +HOST +HOSTS +HOUR +IDENTIFIED +IGNORE_SERVER_IDS +IMPORT +INACTIVE +INDEXES +INITIAL +INITIAL_SIZE +INITIATE +INSERT_METHOD +INSTALL +INSTANCE +INTERSECT +INVISIBLE +INVOKER +IO +IO_THREAD +IPC +ISOLATION +ISSUER +JSON +JSON_TABLE +JSON_VALUE +KEYRING +KEY_BLOCK_SIZE +LAG +LANGUAGE +LAST +LAST_VALUE +LATERAL +LEAD +LEAVES +LESS +LEVEL +LINESTRING +LIST +LOCAL +LOCKED +LOCKS +LOGFILE +LOGS +MASTER +MASTER_AUTO_POSITION +MASTER_COMPRESSION_ALGORITHMS +MASTER_CONNECT_RETRY +MASTER_DELAY +MASTER_HEARTBEAT_PERIOD +MASTER_HOST +MASTER_LOG_FILE +MASTER_LOG_POS +MASTER_PASSWORD +MASTER_PORT +MASTER_PUBLIC_KEY_PATH +MASTER_RETRY_COUNT +MASTER_SERVER_ID +MASTER_SSL +MASTER_SSL_CA +MASTER_SSL_CAPATH +MASTER_SSL_CERT +MASTER_SSL_CIPHER +MASTER_SSL_CRL +MASTER_SSL_CRLPATH +MASTER_SSL_KEY +MASTER_TLS_CIPHERSUITES +MASTER_TLS_VERSION +MASTER_USER +MASTER_ZSTD_COMPRESSION_LEVEL +MAX_CONNECTIONS_PER_HOUR +MAX_QUERIES_PER_HOUR +MAX_ROWS +MAX_SIZE +MAX_UPDATES_PER_HOUR +MAX_USER_CONNECTIONS +MEDIUM +MEMBER +MEMORY +MERGE +MESSAGE_TEXT +MICROSECOND +MIGRATE +MINUTE +MIN_ROWS +MODE +MODIFY +MONTH +MULTILINESTRING +MULTIPOINT +MULTIPOLYGON +MUTEX +MYSQL_ERRNO +NAME +NAMES +NATIONAL +NCHAR +NDB +NDBCLUSTER +NESTED +NETWORK_NAMESPACE +NEVER +NEW +NEXT +NO +NODEGROUP +NONE +NOWAIT +NO_WAIT +NTH_VALUE +NTILE +NULLS +NUMBER +NVARCHAR +OF +OFF +OFFSET +OJ +OLD +ONE +ONLY +OPEN +OPTIONAL +OPTIONS +ORDINALITY +ORGANIZATION +OTHERS +OVER +OWNER +PACK_KEYS +PAGE +PARSER +PARSE_GCOL_EXPR +PARTIAL +PARTITIONING +PARTITIONS +PASSWORD +PASSWORD_LOCK_TIME +PATH +PERCENT_RANK +PERSIST +PERSIST_ONLY +PHASE +PLUGIN +PLUGINS +PLUGIN_DIR +POINT +POLYGON +PORT +PRECEDES +PRECEDING +PREPARE +PRESERVE +PREV +PRIVILEGES +PRIVILEGE_CHECKS_USER +PROCESS +PROCESSLIST +PROFILE +PROFILES +PROXY +QUARTER +QUERY +QUICK +RANDOM +RANK +READ_ONLY +REBUILD +RECOVER +RECURSIVE +REDOFILE +REDO_BUFFER_SIZE +REDUNDANT +REFERENCE +REGISTRATION +RELAY +RELAYLOG +RELAY_LOG_FILE +RELAY_LOG_POS +RELAY_THREAD +RELOAD +REMOTE +REMOVE +REORGANIZE +REPAIR +REPEATABLE +REPLICA +REPLICAS +REPLICATE_DO_DB +REPLICATE_DO_TABLE +REPLICATE_IGNORE_DB +REPLICATE_IGNORE_TABLE +REPLICATE_REWRITE_DB +REPLICATE_WILD_DO_TABLE +REPLICATE_WILD_IGNORE_TABLE +REPLICATION +REQUIRE_ROW_FORMAT +RESET +RESOURCE +RESPECT +RESTART +RESTORE +RESUME +RETAIN +RETURNED_SQLSTATE +RETURNING +RETURNS +REUSE +REVERSE +ROLE +ROLLBACK +ROLLUP +ROTATE +ROUTINE +ROW +ROWS +ROW_COUNT +ROW_FORMAT +ROW_NUMBER +RTREE +SAVEPOINT +SCHEDULE +SCHEMA_NAME +SECOND +SECONDARY +SECONDARY_ENGINE +SECONDARY_ENGINE_ATTRIBUTE +SECONDARY_LOAD +SECONDARY_UNLOAD +SECURITY +SERIAL +SERIALIZABLE +SERVER +SESSION +SHARE +SHUTDOWN +SIGNED +SIMPLE +SKIP +SLAVE +SLOW +SNAPSHOT +SOCKET +SOME +SONAME +SOUNDS +SOURCE +SOURCE_AUTO_POSITION +SOURCE_BIND +SOURCE_COMPRESSION_ALGORITHMS +SOURCE_CONNECT_RETRY +SOURCE_DELAY +SOURCE_HEARTBEAT_PERIOD +SOURCE_HOST +SOURCE_LOG_FILE +SOURCE_LOG_POS +SOURCE_PASSWORD +SOURCE_PORT +SOURCE_PUBLIC_KEY_PATH +SOURCE_RETRY_COUNT +SOURCE_SSL +SOURCE_SSL_CA +SOURCE_SSL_CAPATH +SOURCE_SSL_CERT +SOURCE_SSL_CIPHER +SOURCE_SSL_CRL +SOURCE_SSL_CRLPATH +SOURCE_SSL_KEY +SOURCE_SSL_VERIFY_SERVER_CERT +SOURCE_TLS_CIPHERSUITES +SOURCE_TLS_VERSION +SOURCE_USER +SOURCE_ZSTD_COMPRESSION_LEVEL +SQL_AFTER_GTIDS +SQL_AFTER_MTS_GAPS +SQL_BEFORE_GTIDS +SQL_BUFFER_RESULT +SQL_CACHE +SQL_NO_CACHE +SQL_THREAD +SQL_TSI_DAY +SQL_TSI_HOUR +SQL_TSI_MINUTE +SQL_TSI_MONTH +SQL_TSI_QUARTER +SQL_TSI_SECOND +SQL_TSI_WEEK +SQL_TSI_YEAR +SRID +STACKED +START +STARTS +STATS_AUTO_RECALC +STATS_PERSISTENT +STATS_SAMPLE_PAGES +STATUS +STOP +STORAGE +STREAM +STRING +SUBCLASS_ORIGIN +SUBJECT +SUBPARTITION +SUBPARTITIONS +SUPER +SUSPEND +SWAPS +SWITCHES +SYSTEM +TABLES +TABLESPACE +TABLE_CHECKSUM +TABLE_NAME +TEMPORARY +TEMPTABLE +TEXT +THAN +THREAD_PRIORITY +TIES +TIME +TIMESTAMP +TIMESTAMPADD +TIMESTAMPDIFF +TLS +TRANSACTION +TRIGGERS +TRUNCATE +TYPE +TYPES +UNBOUNDED +UNCOMMITTED +UNDEFINED +UNDOFILE +UNDO_BUFFER_SIZE +UNICODE +UNINSTALL +UNKNOWN +UNREGISTER +UNTIL +UPGRADE +USER +USER_RESOURCES +USE_FRM +VALIDATION +VALUE +VARIABLES +VCPU +VIEW +VISIBLE +WAIT +WARNINGS +WEEK +WEIGHT_STRING +WINDOW +WITHOUT +WORK +WRAPPER +X509 +XA +XID +XML +YEAR +ZONE +NOW +SHARED +INPLACE +NOCOPY +INSTANT +"; diff --git a/crates/lib-dialects/src/postgres.rs b/crates/lib-dialects/src/postgres.rs index ecb80e9ac..b85fefbc4 100644 --- a/crates/lib-dialects/src/postgres.rs +++ b/crates/lib-dialects/src/postgres.rs @@ -3,13 +3,11 @@ use sqruff_lib_core::dialects::Dialect; use sqruff_lib_core::dialects::init::DialectKind; use sqruff_lib_core::dialects::syntax::SyntaxKind; use sqruff_lib_core::helpers::{Config, ToMatchable}; -use sqruff_lib_core::parser::grammar::anyof::{ - AnyNumberOf, any_set_of, one_of, optionally_bracketed, -}; +use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed}; use sqruff_lib_core::parser::grammar::delimited::Delimited; use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence}; -use sqruff_lib_core::parser::grammar::{Anything, Ref}; -use sqruff_lib_core::parser::lexer::Matcher; +use sqruff_lib_core::parser::grammar::{Anything, Nothing, Ref}; +use sqruff_lib_core::parser::lexer::{Matcher, Pattern}; use sqruff_lib_core::parser::matchable::{Matchable, MatchableTrait}; use sqruff_lib_core::parser::node_matcher::NodeMatcher; use sqruff_lib_core::parser::parsers::{RegexParser, StringParser, TypedParser}; @@ -17,106 +15,114 @@ use sqruff_lib_core::parser::segments::generator::SegmentGenerator; use sqruff_lib_core::parser::segments::meta::MetaSegment; use sqruff_lib_core::parser::types::ParseMode; -use super::ansi; -use super::postgres_keywords::POSTGRES_POSTGIS_DATATYPE_KEYWORDS; -use crate::postgres_keywords::{get_keywords, postgres_keywords}; +use super::postgres_keywords::{get_keywords, postgres_keywords}; pub fn dialect() -> Dialect { - raw_dialect().config(|dialect| dialect.expand()) + raw_dialect().config(|this| this.expand()) } pub fn raw_dialect() -> Dialect { - let mut postgres = ansi::raw_dialect(); - postgres.name = DialectKind::Postgres; + let ansi_dialect = super::ansi::raw_dialect(); + let mut postgres_dialect = ansi_dialect.clone(); + postgres_dialect.name = DialectKind::Postgres; - postgres.insert_lexer_matchers( - vec![Matcher::string("right_arrow", "=>", SyntaxKind::RightArrow)], + postgres_dialect.insert_lexer_matchers( + vec![Matcher::string( + "right_arrow", + r#"=>"#, + SyntaxKind::RightArrow, + )], "equals", ); - postgres.insert_lexer_matchers(vec![ - Matcher::legacy( - "unicode_single_quote", - |s| s.starts_with("U&'"), - r"(?s)U&(('')+?(?!')|('.*?(?>|#>>|->|#>|@>|<@|\?\|_|\?|\?&|#-"#, - SyntaxKind::JsonOperator - ), - Matcher::string( - "at", - "@", - SyntaxKind::At - ), - Matcher::regex( - "bit_string_literal", - r#"[bBxX]'[0-9a-fA-F]*'"#, - SyntaxKind::BitStringLiteral - ), + postgres_dialect.insert_lexer_matchers(vec![ + Matcher::regex("unicode_single_quote", r#"(?si)U&'([^']|'')*'(\s*UESCAPE\s*'[^0-9A-Fa-f'+\-\s)]')?"#, SyntaxKind::UnicodeSingleQuote), + Matcher::legacy("escaped_single_quote", |_| true, r#"(?si)E(('')+?(?!')|'.*?((?>?|#>>?|@[>@?]|<@|\?[|&]?|#-"#, SyntaxKind::JsonOperator), + Matcher::legacy("pg_trgm_operator", |_| true, r#"<<<->|<->>>|<->>|<<->(?!>)|<<%|%>>|<%|%>"#, SyntaxKind::PgTrgmOperator), + Matcher::regex("pgvector_operator", r#"<->|<#>|<=>|<\+>"#, SyntaxKind::PgvectorOperator), + Matcher::regex("postgis_operator", r#"\&\&\&|\&<\||<<\||@|\|\&>|\|>>|\~=|<\->|\|=\||<\#>|<<\->>|<<\#>>"#, SyntaxKind::PostgisOperator), + Matcher::string("at", r#"@"#, SyntaxKind::At), + Matcher::regex("bit_string_literal", r#"[bBxX]'[0-9a-fA-F]*'"#, SyntaxKind::BitStringLiteral), + Matcher::string("full_text_search_operator", r#"!!"#, SyntaxKind::FullTextSearchOperator), ], "like_operator"); - postgres.insert_lexer_matchers( + postgres_dialect.insert_lexer_matchers( vec![ Matcher::legacy( "meta_command", - |s| s.starts_with("\\"), - r"\\([^\\\r\n])+((\\\\)|(?=\n)|(?=\r\n))?", + |_| true, + r#"\\(?!gset|gexec)([^\\\r\n])+((\\\\)|(?=\n)|(?=\r\n))?"#, SyntaxKind::Comment, ), Matcher::regex( "dollar_numeric_literal", - r"\$\d+", + r#"\$\d+"#, SyntaxKind::DollarNumericLiteral, ), + Matcher::legacy( + "meta_command_query_buffer", + |_| true, + r#"\\([^\\\r\n])+((\\g(set|exec))|(?=\n)|(?=\r\n))?"#, + SyntaxKind::MetaCommandQueryBuffer, + ), ], "word", ); - postgres.patch_lexer_matchers(vec![ - Matcher::regex("inline_comment", r"(--)[^\n]*", SyntaxKind::InlineComment), - Matcher::legacy( - "single_quote", - |s| s.starts_with("'"), - r"(?s)('')+?(?!')|('.*?(? Dialect { "TIMEZONE_MINUTE", ]); - // Set the bare functions - postgres.sets_mut("bare_functions").extend([ + postgres_dialect.sets_mut("bare_functions").extend([ "CURRENT_TIMESTAMP", "CURRENT_TIME", "CURRENT_DATE", "LOCALTIME", "LOCALTIMESTAMP", + "CURRENT_CATALOG", + "CURRENT_ROLE", + "CURRENT_SCHEMA", + "CURRENT_USER", + "SESSION_USER", + "SYSTEM_USER", + "USER", ]); - // Postgres doesn't have a dateadd function - // Also according to https://www.postgresql.org/docs/14/functions-datetime.html - // It quotes dateparts. So don't need this. - postgres.sets_mut("date_part_function_name").clear(); + postgres_dialect.sets_mut("date_part_function_name").clear(); - // In Postgres, UNNEST() returns a "value table", similar to BigQuery - postgres + postgres_dialect .sets_mut("value_table_functions") .extend(["UNNEST", "GENERATE_SERIES"]); - postgres.add([ + postgres_dialect.add([ ( "JsonOperatorSegment".into(), TypedParser::new(SyntaxKind::JsonOperator, SyntaxKind::BinaryOperator) .to_matchable() .into(), ), + ( + "PostgisOperatorSegment".into(), + TypedParser::new(SyntaxKind::PostgisOperator, SyntaxKind::BinaryOperator) + .to_matchable() + .into(), + ), + ( + "PgvectorOperatorSegment".into(), + TypedParser::new(SyntaxKind::PgvectorOperator, SyntaxKind::BinaryOperator) + .to_matchable() + .into(), + ), + ( + "PgTrgmOperatorSegment".into(), + TypedParser::new(SyntaxKind::PgTrgmOperator, SyntaxKind::BinaryOperator) + .to_matchable() + .into(), + ), ( "SimpleGeometryGrammar".into(), AnyNumberOf::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) @@ -175,14 +201,13 @@ pub fn raw_dialect() -> Dialect { AnyNumberOf::new(vec![Ref::new("MultilineConcatenateNewline").to_matchable()]) .config(|this| { this.min_times(1); - this.disallow_gaps(); }) .to_matchable() .into(), ), ( "NakedIdentifierFullSegment".into(), - TypedParser::new(SyntaxKind::Word, SyntaxKind::NakedIdentifier) + TypedParser::new(SyntaxKind::Word, SyntaxKind::NakedIdentifierAll) .to_matchable() .into(), ), @@ -326,881 +351,743 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - postgres.add([ - ( - "LikeGrammar".into(), - one_of(vec![ - Ref::keyword("LIKE").to_matchable(), - Ref::keyword("ILIKE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("SIMILAR").to_matchable(), - Ref::keyword("TO").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), ( - "StringBinaryOperatorGrammar".into(), - one_of(vec![ - Ref::new("ConcatSegment").to_matchable(), - Ref::keyword("COLLATE").to_matchable(), + "CreateForeignTableGrammar".into(), + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("FOREIGN").to_matchable(), + Ref::keyword("TABLE").to_matchable(), ]) .to_matchable() .into(), ), ( - "ComparisonOperatorGrammar".into(), + "IntervalUnitsGrammar".into(), one_of(vec![ - Ref::new("EqualsSegment").to_matchable(), - Ref::new("GreaterThanSegment").to_matchable(), - Ref::new("LessThanSegment").to_matchable(), - Ref::new("GreaterThanOrEqualToSegment").to_matchable(), - Ref::new("LessThanOrEqualToSegment").to_matchable(), - Ref::new("NotEqualToSegment").to_matchable(), - Ref::new("LikeOperatorSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IS").to_matchable(), - Ref::keyword("DISTINCT").to_matchable(), - Ref::keyword("FROM").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("IS").to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("DISTINCT").to_matchable(), - Ref::keyword("FROM").to_matchable(), - ]) - .to_matchable(), - Ref::new("OverlapSegment").to_matchable(), - Ref::new("NotExtendRightSegment").to_matchable(), - Ref::new("NotExtendLeftSegment").to_matchable(), - Ref::new("AdjacentSegment").to_matchable(), + Ref::keyword("YEAR").to_matchable(), + Ref::keyword("MONTH").to_matchable(), + Ref::keyword("DAY").to_matchable(), + Ref::keyword("HOUR").to_matchable(), + Ref::keyword("MINUTE").to_matchable(), + Ref::keyword("SECOND").to_matchable(), ]) .to_matchable() .into(), ), ( - "NakedIdentifierSegment".into(), - SegmentGenerator::new(|dialect| { - // Generate the anti-template from the set of reserved keywords - let reserved_keywords = dialect.sets("reserved_keywords"); - let pattern = reserved_keywords.iter().join("|"); - let anti_template = format!("^({pattern})$"); - - RegexParser::new( - r"([A-Z_]+|[0-9]+[A-Z_$])[A-Z0-9_$]*", - SyntaxKind::NakedIdentifier, - ) - .anti_template(&anti_template) - .to_matchable() - }) - .into(), - ), - ( - "ParameterNameSegment".into(), - RegexParser::new(r#"[A-Z_][A-Z0-9_$]*|\"[^\"]*\""#, SyntaxKind::Parameter) + "WalrusOperatorSegment".into(), + StringParser::new(":=", SyntaxKind::AssignmentOperator) .to_matchable() .into(), ), ( - "FunctionNameIdentifierSegment".into(), - RegexParser::new(r"[A-Z_][A-Z0-9_$]*", SyntaxKind::FunctionNameIdentifier) + "MetaCommandQueryBufferSegment".into(), + TypedParser::new(SyntaxKind::MetaCommandQueryBuffer, SyntaxKind::MetaCommand) .to_matchable() .into(), ), ( - "FunctionContentsExpressionGrammar".into(), - one_of(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::new("NamedArgumentSegment").to_matchable(), - ]) + "FullTextSearchOperatorSegment".into(), + TypedParser::new( + SyntaxKind::FullTextSearchOperator, + SyntaxKind::FullTextSearchOperator, + ) .to_matchable() .into(), ), ( - "QuotedLiteralSegment".into(), + "JsonTypeGrammar".into(), one_of(vec![ - Sequence::new(vec![ - TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral) - .to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(), - TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - TypedParser::new(SyntaxKind::BitStringLiteral, SyntaxKind::QuotedLiteral) - .to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(), - TypedParser::new(SyntaxKind::BitStringLiteral, SyntaxKind::QuotedLiteral) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Delimited::new(vec![ - TypedParser::new(SyntaxKind::UnicodeSingleQuote, SyntaxKind::QuotedLiteral) - .to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(), - TypedParser::new(SyntaxKind::UnicodeSingleQuote, SyntaxKind::QuotedLiteral) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Delimited::new(vec![ - TypedParser::new(SyntaxKind::EscapedSingleQuote, SyntaxKind::QuotedLiteral) - .to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(), - TypedParser::new(SyntaxKind::EscapedSingleQuote, SyntaxKind::QuotedLiteral) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Delimited::new(vec![ - TypedParser::new(SyntaxKind::DollarQuote, SyntaxKind::QuotedLiteral) - .to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(), - TypedParser::new(SyntaxKind::DollarQuote, SyntaxKind::QuotedLiteral) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("VALUE").to_matchable(), + Ref::keyword("SCALAR").to_matchable(), + Ref::keyword("ARRAY").to_matchable(), + Ref::keyword("OBJECT").to_matchable(), ]) .to_matchable() .into(), ), ( - "QuotedIdentifierSegment".into(), - one_of(vec![ - TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedIdentifier) - .to_matchable(), - TypedParser::new(SyntaxKind::UnicodeDoubleQuote, SyntaxKind::QuotedLiteral) + "JsonUniqueKeysGrammar".into(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("WITHOUT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("UNIQUE").to_matchable(), + Sequence::new(vec![Ref::keyword("KEYS").to_matchable()]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() .into(), ), ( - "PostFunctionGrammar".into(), - AnyNumberOf::new(vec![ - Ref::new("WithinGroupClauseSegment").to_matchable(), - Ref::new("OverClauseSegment").to_matchable(), - Ref::new("FilterClauseGrammar").to_matchable(), + "JsonTestGrammar".into(), + Sequence::new(vec![ + Ref::keyword("JSON").to_matchable(), + Ref::new("JsonTypeGrammar").optional().to_matchable(), + Ref::new("JsonUniqueKeysGrammar").optional().to_matchable(), ]) .to_matchable() .into(), ), - ( - "BinaryOperatorGrammar".into(), + ]); + + postgres_dialect.add([( + "NakedIdentifierSegment".into(), + SegmentGenerator::new(|dialect| { + let reserved_keywords = dialect.sets("reserved_keywords"); + let pattern = reserved_keywords.iter().join("|"); + let anti_template = format!("^({pattern})$"); + RegexParser::new(r#"[\p{L}_][\p{L}\p{N}_$]*"#, SyntaxKind::NakedIdentifier) + .anti_template(&anti_template) + .to_matchable() + }) + .into(), + )]); + + postgres_dialect.replace_grammar( + "LikeGrammar", + one_of(vec![ + Ref::keyword("LIKE").to_matchable(), + Ref::keyword("ILIKE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SIMILAR").to_matchable(), + Ref::keyword("TO").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar( + "StringBinaryOperatorGrammar", + one_of(vec![ + Ref::new("ConcatSegment").to_matchable(), + Ref::keyword("COLLATE").to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar( + "BaseExpressionElementGrammar", + one_of(vec![ + ansi_dialect.grammar("BaseExpressionElementGrammar"), + Ref::new("CompositeValueExpansionSegment").to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar( + "IsClauseGrammar", + one_of(vec![ + Ref::new("NullLiteralSegment").to_matchable(), + Ref::new("NanLiteralSegment").to_matchable(), + Ref::new("UnknownLiteralSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::new("NormalizedGrammar").to_matchable(), + Ref::new("JsonTestGrammar").to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar( + "ComparisonOperatorGrammar", + one_of(vec![ + Ref::new("EqualsSegment").to_matchable(), + Ref::new("GreaterThanSegment").to_matchable(), + Ref::new("LessThanSegment").to_matchable(), + Ref::new("GreaterThanOrEqualToSegment").to_matchable(), + Ref::new("LessThanOrEqualToSegment").to_matchable(), + Ref::new("NotEqualToSegment").to_matchable(), + Ref::new("LikeOperatorSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("IS").to_matchable(), + Ref::keyword("DISTINCT").to_matchable(), + Ref::keyword("FROM").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IS").to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("DISTINCT").to_matchable(), + Ref::keyword("FROM").to_matchable(), + ]) + .to_matchable(), + Ref::new("OverlapSegment").to_matchable(), + Ref::new("NotExtendRightSegment").to_matchable(), + Ref::new("NotExtendLeftSegment").to_matchable(), + Ref::new("AdjacentSegment").to_matchable(), + Ref::new("PostgisOperatorSegment").to_matchable(), + Ref::new("PgvectorOperatorSegment").to_matchable(), + Ref::new("PgTrgmOperatorSegment").to_matchable(), + Ref::new("QualifiedOperatorSegment").to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar( + "Expression_C_Grammar", + Sequence::new(vec![ + Ref::new("WalrusOperatorSegment").optional().to_matchable(), one_of(vec![ - Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(), - Ref::new("StringBinaryOperatorGrammar").to_matchable(), - Ref::new("BooleanBinaryOperatorGrammar").to_matchable(), - Ref::new("ComparisonOperatorGrammar").to_matchable(), - Ref::new("JsonOperatorSegment").to_matchable(), + ansi_dialect.grammar("Expression_C_Grammar"), + Sequence::new(vec![ + Ref::new("FullTextSearchOperatorSegment") + .optional() + .to_matchable(), + Ref::new("ShorthandCastSegment").to_matchable(), + ]) + .to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "FunctionParameterGrammar".into(), + .to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar( + "ParameterNameSegment", + RegexParser::new(r#"[A-Z_][A-Z0-9_$]*|"[^"]*""#, SyntaxKind::Parameter).to_matchable(), + ); + + postgres_dialect.replace_grammar( + "FunctionNameIdentifierSegment", + RegexParser::new(r#"[A-Z_][A-Z0-9_$]*"#, SyntaxKind::FunctionNameIdentifier).to_matchable(), + ); + + postgres_dialect.replace_grammar( + "FunctionContentsExpressionGrammar", + one_of(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("NamedArgumentSegment").to_matchable(), Sequence::new(vec![ + Ref::keyword("VARIADIC").to_matchable(), one_of(vec![ - Ref::keyword("IN").to_matchable(), - Ref::keyword("OUT").to_matchable(), - Ref::keyword("INOUT").to_matchable(), - Ref::keyword("VARIADIC").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("NamedArgumentSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar( + "FunctionContentsGrammar", + AnyNumberOf::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + optionally_bracketed(vec![Ref::new("SetExpressionSegment").to_matchable()]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("TrimParametersGrammar").to_matchable(), + Ref::new("ExpressionSegment") + .exclude(Ref::keyword("FROM")) + .optional() + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ one_of(vec![ - Ref::new("DatatypeSegment").to_matchable(), + Ref::new("DatetimeUnitSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOR").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.max_times_per_element = Some(1); + this.optional(); + }) .to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "FrameClauseUnitGrammar".into(), - one_of(vec![ - Ref::keyword("RANGE").to_matchable(), - Ref::keyword("ROWS").to_matchable(), - Ref::keyword("GROUPS").to_matchable(), + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURNING").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "IsNullGrammar".into(), - Ref::keyword("ISNULL").to_matchable().into(), - ), - ( - "NotNullGrammar".into(), - Ref::keyword("NOTNULL").to_matchable().into(), - ), - ( - "JoinKeywordsGrammar".into(), + .to_matchable(), Sequence::new(vec![ - Ref::keyword("JOIN").to_matchable(), - Sequence::new(vec![Ref::keyword("LATERAL").to_matchable()]) - .config(|this| this.optional()) + Ref::keyword("DISTINCT").optional().to_matchable(), + one_of(vec![ + Ref::new("StarSegment").to_matchable(), + Delimited::new(vec![ + Ref::new("FunctionContentsExpressionGrammar").to_matchable(), + ]) .to_matchable(), + ]) + .to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "SelectClauseTerminatorGrammar".into(), - one_of(vec![ - Ref::keyword("INTO").to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::keyword("WHERE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), + .to_matchable(), + Ref::new("AggregateOrderByClause").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SEPARATOR").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("IN").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::new("CommaSegment").to_matchable(), - Ref::new("SetOperatorSegment").to_matchable(), ]) - .to_matchable() - .into(), - ), - // Assuming the existence of `ansi_dialect` in Rust and a way to manipulate its - // grammar: - ( - "LiteralGrammar".into(), - postgres - .grammar("LiteralGrammar") - .copy( - Some(vec![ - Ref::new("DollarNumericLiteralSegment").to_matchable(), - Ref::new("PsqlVariableGrammar").to_matchable(), - ]), - None, - Some(Ref::new("ArrayLiteralSegment").to_matchable()), - None, - Vec::new(), - false, - ) - .into(), - ), - ( - "FromClauseTerminatorGrammar".into(), - postgres - .grammar("FromClauseTerminatorGrammar") - .copy( - Some(vec![Ref::new("ForClauseSegment").to_matchable()]), - None, - None, - None, - Vec::new(), - false, - ) - .into(), - ), - ( - "WhereClauseTerminatorGrammar".into(), - one_of(vec![ - Ref::keyword("LIMIT").to_matchable(), + .to_matchable(), + Ref::new("IgnoreRespectNullsGrammar").to_matchable(), + Ref::new("IndexColumnDefinitionSegment").to_matchable(), + Ref::new("EmptyStructLiteralSegment").to_matchable(), + Delimited::new(vec![ Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + one_of(vec![ + Ref::keyword("VALUE").to_matchable(), + Ref::new("ColonSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar( + "QuotedLiteralSegment", + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral) + .to_matchable(), + TypedParser::new(SyntaxKind::EscapedSingleQuote, SyntaxKind::QuotedLiteral) + .to_matchable(), ]) .to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("QUALIFY").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::keyword("OVERLAPS").to_matchable(), - Ref::keyword("RETURNING").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("CONFLICT").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(), + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral) + .to_matchable(), ]) .to_matchable(), - Ref::new("ForClauseSegment").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "OrderByClauseTerminators".into(), - one_of(vec![ - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("QUALIFY").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::new("FrameClauseUnitGrammar").to_matchable(), - Ref::keyword("SEPARATOR").to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("DATA").to_matchable(), + .to_matchable(), + Sequence::new(vec![ + TypedParser::new(SyntaxKind::BitStringLiteral, SyntaxKind::QuotedLiteral) + .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(), + RegexParser::new(r#"(?i)'[0-9a-f]*'"#, SyntaxKind::QuotedLiteral) + .to_matchable(), ]) .to_matchable(), - Ref::new("ForClauseSegment").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "AccessorGrammar".into(), - AnyNumberOf::new(vec![ - Ref::new("ArrayAccessorSegment").to_matchable(), - Ref::new("SemiStructuredAccessorSegment").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "NonWithSelectableGrammar".into(), - one_of(vec![ - Ref::new("SetExpressionSegment").to_matchable(), - optionally_bracketed(vec![Ref::new("SelectStatementSegment").to_matchable()]) + .to_matchable(), + Sequence::new(vec![ + TypedParser::new(SyntaxKind::UnicodeSingleQuote, SyntaxKind::QuotedLiteral) .to_matchable(), - Ref::new("NonSetSelectableGrammar").to_matchable(), - Ref::new("UpdateStatementSegment").to_matchable(), - Ref::new("InsertStatementSegment").to_matchable(), - Ref::new("DeleteStatementSegment").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "NonWithNonSelectableGrammar".into(), - one_of(vec![]).to_matchable().into(), - ), - ]); - - postgres.add([ - ( - "OverlapSegment".into(), - NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| { - Sequence::new(vec![ - Ref::new("AmpersandSegment").to_matchable(), - Ref::new("AmpersandSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "NotExtendRightSegment".into(), - NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| { - Sequence::new(vec![ - Ref::new("AmpersandSegment").to_matchable(), - Ref::new("RawGreaterThanSegment").to_matchable(), - ]) - .allow_gaps(false) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "NotExtendLeftSegment".into(), - NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| { - Sequence::new(vec![ - Ref::new("AmpersandSegment").to_matchable(), - Ref::new("RawLessThanSegment").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(), + RegexParser::new(r#"'([^']|'')*'"#, SyntaxKind::QuotedLiteral).to_matchable(), ]) - .allow_gaps(false) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "AdjacentSegment".into(), - NodeMatcher::new(SyntaxKind::ComparisonOperator, |_| { + .to_matchable(), Sequence::new(vec![ - Ref::new("MinusSegment").to_matchable(), - Ref::new("PipeSegment").to_matchable(), - Ref::new("MinusSegment").to_matchable(), - ]) - .allow_gaps(false) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ]); - - postgres.add([( - "PsqlVariableGrammar".into(), - NodeMatcher::new(SyntaxKind::PsqlVariable, |_| { - Sequence::new(vec![ - optionally_bracketed(vec![ - Ref::new("ColonSegment").to_matchable(), - one_of(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("UESCAPE").to_matchable(), + RegexParser::new(r#"'[^0-9A-Fa-f'+\-\s)]'"#, SyntaxKind::Code).to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.replace_grammar( - "ArrayAccessorSegment", - Bracketed::new(vec![ - one_of(vec![ - // These three are for a single element access: [n] - Ref::new("QualifiedNumericLiteralSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - // This is for slice access: [n:m], [:m], [n:], and [:] - Sequence::new(vec![ - one_of(vec![ - Ref::new("QualifiedNumericLiteralSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("SliceSegment").to_matchable(), - one_of(vec![ - Ref::new("QualifiedNumericLiteralSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + .to_matchable(), + Delimited::new(vec![ + TypedParser::new(SyntaxKind::DollarQuote, SyntaxKind::QuotedLiteral).to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("MultilineConcatenateDelimiterGrammar").to_matchable(), + TypedParser::new(SyntaxKind::DollarQuote, SyntaxKind::QuotedLiteral) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) - .config(|this| { - this.bracket_type("square"); - }) .to_matchable(), ); - postgres.add([( - "DateTimeTypeIdentifier".into(), - NodeMatcher::new(SyntaxKind::DatetimeTypeIdentifier, |_| { + postgres_dialect.replace_grammar( + "QuotedIdentifierSegment", + one_of(vec![ + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedIdentifier).to_matchable(), + TypedParser::new(SyntaxKind::UnicodeDoubleQuote, SyntaxKind::QuotedIdentifier) + .to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar( + "PostFunctionGrammar", + AnyNumberOf::new(vec![ + Ref::new("WithinGroupClauseSegment").to_matchable(), + Ref::new("OverClauseSegment").to_matchable(), + Ref::new("FilterClauseGrammar").to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar( + "BinaryOperatorGrammar", + one_of(vec![ + Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(), + Ref::new("StringBinaryOperatorGrammar").to_matchable(), + Ref::new("BooleanBinaryOperatorGrammar").to_matchable(), + Ref::new("ComparisonOperatorGrammar").to_matchable(), + Ref::new("JsonOperatorSegment").to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar( + "FunctionParameterGrammar", + Sequence::new(vec![ one_of(vec![ - Ref::keyword("DATE").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("OUT").to_matchable(), + Ref::keyword("INOUT").to_matchable(), + Ref::keyword("VARIADIC").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Ref::new("DatatypeSegment").to_matchable(), Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), one_of(vec![ - Ref::keyword("TIME").to_matchable(), - Ref::keyword("TIMESTAMP").to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("WITHOUT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("TIME").to_matchable(), - Ref::keyword("ZONE").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("OUT").to_matchable(), + Ref::keyword("INOUT").to_matchable(), + Ref::keyword("VARIADIC").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ one_of(vec![ - Ref::keyword("INTERVAL").to_matchable(), - Ref::keyword("TIMETZ").to_matchable(), - Ref::keyword("TIMESTAMPTZ").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Ref::new("ColumnTypeReferenceSegment").to_matchable(), ]) .to_matchable(), - Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), ]) .to_matchable(), ]) - .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.add([( - "DateTimeLiteralGrammar".into(), - NodeMatcher::new(SyntaxKind::DatetimeLiteral, |_| { - Sequence::new(vec![ - Ref::new("DateTimeTypeIdentifier").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.replace_grammar( - "DatatypeSegment", - Sequence::new(vec![ + .to_matchable(), Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("DotSegment").to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("WalrusOperatorSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .config(|this| { - this.allow_gaps = false; this.optional(); }) .to_matchable(), - one_of(vec![ - Ref::new("WellKnownTextGeometrySegment").to_matchable(), - Ref::new("DateTimeTypeIdentifier").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("SMALLINT").to_matchable(), - Ref::keyword("INTEGER").to_matchable(), - Ref::keyword("INT").to_matchable(), - Ref::keyword("INT2").to_matchable(), - Ref::keyword("INT4").to_matchable(), - Ref::keyword("INT8").to_matchable(), - Ref::keyword("BIGINT").to_matchable(), - Ref::keyword("FLOAT4").to_matchable(), - Ref::keyword("FLOAT8").to_matchable(), - Ref::keyword("REAL").to_matchable(), - Sequence::new(vec![ - Ref::keyword("DOUBLE").to_matchable(), - Ref::keyword("PRECISION").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("SMALLSERIAL").to_matchable(), - Ref::keyword("SERIAL").to_matchable(), - Ref::keyword("SERIAL2").to_matchable(), - Ref::keyword("SERIAL4").to_matchable(), - Ref::keyword("SERIAL8").to_matchable(), - Ref::keyword("BIGSERIAL").to_matchable(), - // Numeric types [(precision)] - Sequence::new(vec![ - one_of(vec![Ref::keyword("FLOAT").to_matchable()]).to_matchable(), - Ref::new("BracketedArguments").optional().to_matchable(), - ]) - .to_matchable(), - // Numeric types [precision ["," scale])] - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DECIMAL").to_matchable(), - Ref::keyword("NUMERIC").to_matchable(), - ]) - .to_matchable(), - Ref::new("BracketedArguments").optional().to_matchable(), - ]) - .to_matchable(), - // Monetary type - Ref::keyword("MONEY").to_matchable(), - // Character types - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("BPCHAR").to_matchable(), - Ref::keyword("CHAR").to_matchable(), - Sequence::new(vec![ - Ref::keyword("CHAR").to_matchable(), - Ref::keyword("VARYING").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("CHARACTER").to_matchable(), - Sequence::new(vec![ - Ref::keyword("CHARACTER").to_matchable(), - Ref::keyword("VARYING").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("VARCHAR").to_matchable(), - ]) - .to_matchable(), - Ref::new("BracketedArguments").optional().to_matchable(), - ]) - .to_matchable(), - Ref::keyword("TEXT").to_matchable(), - ]) - .to_matchable(), - // Binary type - Ref::keyword("BYTEA").to_matchable(), - // Boolean types - one_of(vec![ - Ref::keyword("BOOLEAN").to_matchable(), - Ref::keyword("BOOL").to_matchable(), - ]) - .to_matchable(), - // Geometric types - one_of(vec![ - Ref::keyword("POINT").to_matchable(), - Ref::keyword("LINE").to_matchable(), - Ref::keyword("LSEG").to_matchable(), - Ref::keyword("BOX").to_matchable(), - Ref::keyword("PATH").to_matchable(), - Ref::keyword("POLYGON").to_matchable(), - Ref::keyword("CIRCLE").to_matchable(), - ]) - .to_matchable(), - // Network address types - one_of(vec![ - Ref::keyword("CIDR").to_matchable(), - Ref::keyword("INET").to_matchable(), - Ref::keyword("MACADDR").to_matchable(), - Ref::keyword("MACADDR8").to_matchable(), - ]) - .to_matchable(), - // Text search types - one_of(vec![ - Ref::keyword("TSVECTOR").to_matchable(), - Ref::keyword("TSQUERY").to_matchable(), - ]) - .to_matchable(), - // Bit string types - Sequence::new(vec![ - Ref::keyword("BIT").to_matchable(), - one_of(vec![Ref::keyword("VARYING").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("BracketedArguments").optional().to_matchable(), - ]) - .to_matchable(), - // UUID type - Ref::keyword("UUID").to_matchable(), - // XML type - Ref::keyword("XML").to_matchable(), - // JSON types - one_of(vec![ - Ref::keyword("JSON").to_matchable(), - Ref::keyword("JSONB").to_matchable(), - ]) - .to_matchable(), - // Range types - Ref::keyword("INT4RANGE").to_matchable(), - Ref::keyword("INT8RANGE").to_matchable(), - Ref::keyword("NUMRANGE").to_matchable(), - Ref::keyword("TSRANGE").to_matchable(), - Ref::keyword("TSTZRANGE").to_matchable(), - Ref::keyword("DATERANGE").to_matchable(), - // pg_lsn type - Ref::keyword("PG_LSN").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("DatatypeIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar( + "FrameClauseUnitGrammar", + one_of(vec![ + Ref::keyword("RANGE").to_matchable(), + Ref::keyword("ROWS").to_matchable(), + Ref::keyword("GROUPS").to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar("IsNullGrammar", Ref::keyword("ISNULL").to_matchable()); + + postgres_dialect.replace_grammar("NotNullGrammar", Ref::keyword("NOTNULL").to_matchable()); + + postgres_dialect.replace_grammar( + "PreTableFunctionKeywordsGrammar", + one_of(vec![Ref::keyword("LATERAL").to_matchable()]).to_matchable(), + ); + + postgres_dialect.replace_grammar( + "ConditionalCrossJoinKeywordsGrammar", + Nothing::new().to_matchable(), + ); + + postgres_dialect.replace_grammar( + "UnconditionalCrossJoinKeywordsGrammar", + Ref::keyword("CROSS").to_matchable(), + ); + + postgres_dialect.replace_grammar( + "SelectClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("INTO").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::keyword("WHERE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) .to_matchable(), - one_of(vec![ - AnyNumberOf::new(vec![ - Bracketed::new(vec![ - Ref::new("ExpressionSegment").optional().to_matchable(), - ]) - .config(|this| this.bracket_type("square")) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("ArrayTypeSegment").to_matchable(), - Ref::new("SizedArrayTypeSegment").to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("RETURNING").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), + Ref::new("MetaCommandQueryBufferSegment").to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar( + "LiteralGrammar", + ansi_dialect.grammar("LiteralGrammar").copy( + Some(vec![ + Ref::new("DollarNumericLiteralSegment").to_matchable(), + Ref::new("PsqlVariableGrammar").to_matchable(), + ]), + None, + Some(Ref::new("ArrayLiteralSegment").to_matchable()), + None, + vec![], + false, + ), + ); + + postgres_dialect.replace_grammar( + "FromClauseTerminatorGrammar", + ansi_dialect.grammar("FromClauseTerminatorGrammar").copy( + Some(vec![Ref::new("ForClauseSegment").to_matchable()]), + None, + None, + None, + vec![], + false, + ), + ); + + postgres_dialect.replace_grammar( + "WhereClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("LIMIT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::keyword("OVERLAPS").to_matchable(), + Ref::keyword("RETURNING").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("CONFLICT").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + Ref::new("ForClauseSegment").to_matchable(), ]) .to_matchable(), ); - postgres.replace_grammar("ArrayTypeSegment", Ref::keyword("ARRAY").to_matchable()); + postgres_dialect.replace_grammar( + "OrderByClauseTerminators", + one_of(vec![ + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::new("FrameClauseUnitGrammar").to_matchable(), + Ref::keyword("SEPARATOR").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("DATA").to_matchable(), + ]) + .to_matchable(), + Ref::new("ForClauseSegment").to_matchable(), + ]) + .to_matchable(), + ); - postgres.add([( - "IndexAccessMethodSegment".into(), - NodeMatcher::new(SyntaxKind::IndexAccessMethod, |_| { - Ref::new("SingleIdentifierGrammar").to_matchable() - }) - .to_matchable() - .into(), - )]); + postgres_dialect.replace_grammar( + "AccessorGrammar", + AnyNumberOf::new(vec![ + Ref::new("ArrayAccessorSegment").to_matchable(), + Ref::new("SemiStructuredAccessorSegment").to_matchable(), + ]) + .to_matchable(), + ); - postgres.add([( - "OperatorClassReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::OperatorClassReference, |postgres| { - postgres - .grammar("ObjectReferenceSegment") - .match_grammar(postgres) - .unwrap() - }) - .to_matchable() - .into(), - )]); + postgres_dialect.replace_grammar( + "NonWithSelectableGrammar", + one_of(vec![ + Ref::new("SetExpressionSegment").to_matchable(), + optionally_bracketed(vec![Ref::new("SelectStatementSegment").to_matchable()]) + .to_matchable(), + Ref::new("NonSetSelectableGrammar").to_matchable(), + Ref::new("UpdateStatementSegment").to_matchable(), + Ref::new("InsertStatementSegment").to_matchable(), + Ref::new("DeleteStatementSegment").to_matchable(), + ]) + .to_matchable(), + ); - postgres.add([ - ( - "DefinitionParameterSegment".into(), - NodeMatcher::new(SyntaxKind::DefinitionParameter, |_| { - Sequence::new(vec![ - Ref::new("PropertiesNakedIdentifierSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("EqualsSegment").to_matchable(), - Ref::new("DefinitionArgumentValueGrammar") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "DefinitionParametersSegment".into(), - NodeMatcher::new(SyntaxKind::DefinitionParameters, |_| { - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("DefinitionParameterSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ]); + postgres_dialect.replace_grammar("NonWithNonSelectableGrammar", one_of(vec![]).to_matchable()); - postgres.replace_grammar( - "CreateCastStatementSegment", + postgres_dialect.replace_grammar( + "DateTimeLiteralGrammar", Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("CAST").to_matchable(), - Bracketed::new(vec![ - Sequence::new(vec![ - Ref::new("DatatypeSegment").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), + one_of(vec![ + Ref::keyword("DATE").to_matchable(), + Ref::keyword("TIME").to_matchable(), + Ref::keyword("TIMESTAMP").to_matchable(), + Ref::keyword("INTERVAL").to_matchable(), ]) .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar") - .optional() - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITHOUT").to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - ]) + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::DateConstructorLiteral) .to_matchable(), + Sequence::new(vec![ + Ref::new("IntervalUnitsGrammar").to_matchable(), Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("INOUT").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("IntervalUnitsGrammar").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::keyword("ASSIGNMENT").to_matchable(), + ]) + .to_matchable(), + ); + + postgres_dialect.replace_grammar( + "BracketedSetExpressionGrammar", + Bracketed::new(vec![Ref::new("SetExpressionSegment").to_matchable()]).to_matchable(), + ); + + postgres_dialect.replace_grammar( + "ReferentialActionGrammar", + one_of(vec![ + Ref::keyword("CASCADE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("NULL").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::keyword("IMPLICIT").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .config(|this| this.optional()) + .to_matchable(), + Ref::keyword("RESTRICT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("ACTION").to_matchable(), + ]) .to_matchable(), ]) .to_matchable(), ); - postgres.replace_grammar( - "DropCastStatementSegment", + postgres_dialect.replace_grammar( + "UnknownLiteralSegment", + StringParser::new("UNKNOWN", SyntaxKind::NullLiteral).to_matchable(), + ); + + postgres_dialect.replace_grammar( + "NormalizedGrammar", Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("CAST").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Bracketed::new(vec![ - Sequence::new(vec![ - Ref::new("DatatypeSegment").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), + one_of(vec![ + Ref::keyword("NFC").to_matchable(), + Ref::keyword("NFD").to_matchable(), + Ref::keyword("NFKC").to_matchable(), + Ref::keyword("NFKD").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), + Ref::keyword("NORMALIZED").to_matchable(), ]) .to_matchable(), ); - postgres.add([ + postgres_dialect.add([ ( - "RelationOptionSegment".into(), - NodeMatcher::new(SyntaxKind::RelationOption, |_| { + "QualifiedOperatorSegment".into(), + NodeMatcher::new(SyntaxKind::QualifiedOperator, |_dialect| { Sequence::new(vec![ - Ref::new("PropertiesNakedIdentifierSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("DotSegment").to_matchable(), - Ref::new("PropertiesNakedIdentifierSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::new("EqualsSegment").to_matchable(), - Ref::new("DefinitionArgumentValueGrammar") - .optional() + Ref::keyword("OPERATOR").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("DotSegment").to_matchable(), + AnyNumberOf::new(vec![ + RegexParser::new(r#"[!<>=~@#%^&|`?+\-*/]+"#, SyntaxKind::Operator) + .to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) .to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable() @@ -1209,93 +1096,146 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "RelationOptionsSegment".into(), - NodeMatcher::new(SyntaxKind::RelationOptions, |_| { - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("RelationOptionSegment").to_matchable()]) + "OverlapSegment".into(), + NodeMatcher::new(SyntaxKind::ComparisonOperator, |_dialect| { + Sequence::new(vec![ + Ref::new("AmpersandSegment").to_matchable(), + Ref::new("AmpersandSegment").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "NotExtendRightSegment".into(), + NodeMatcher::new(SyntaxKind::ComparisonOperator, |_dialect| { + Sequence::new(vec![ + Ref::new("AmpersandSegment").to_matchable(), + Ref::new("RawGreaterThanSegment").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "NotExtendLeftSegment".into(), + NodeMatcher::new(SyntaxKind::ComparisonOperator, |_dialect| { + Sequence::new(vec![ + Ref::new("AmpersandSegment").to_matchable(), + Ref::new("RawLessThanSegment").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AdjacentSegment".into(), + NodeMatcher::new(SyntaxKind::ComparisonOperator, |_dialect| { + Sequence::new(vec![ + Ref::new("MinusSegment").to_matchable(), + Ref::new("PipeSegment").to_matchable(), + Ref::new("MinusSegment").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "PsqlVariableGrammar".into(), + NodeMatcher::new(SyntaxKind::PsqlVariable, |_dialect| { + Sequence::new(vec![ + optionally_bracketed(vec![ + Ref::new("ColonSegment").to_matchable(), + one_of(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - postgres.replace_grammar( - "CreateFunctionStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("TemporaryGrammar").optional().to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar").to_matchable(), - Sequence::new(vec![ - Ref::keyword("RETURNS").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("TABLE").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("DatatypeSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + ( + "ArrayAccessorSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayAccessor, |_dialect| { + Bracketed::new(vec![ + one_of(vec![ + Ref::new("QualifiedNumericLiteralSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("QualifiedNumericLiteralSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("SliceSegment").to_matchable(), + one_of(vec![ + Ref::new("QualifiedNumericLiteralSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SETOF").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("FunctionDefinitionGrammar").to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([ + .config(|this| { + this.bracket_type("square"); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), ( - "DropFunctionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar") - .optional() - .to_matchable(), + "DateTimeTypeIdentifier".into(), + NodeMatcher::new(SyntaxKind::DatetimeTypeIdentifier, |_dialect| { + one_of(vec![ + Ref::keyword("DATE").to_matchable(), + Ref::new("TimeWithTZGrammar").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("INTERVAL").to_matchable(), + Ref::keyword("TIMETZ").to_matchable(), + Ref::keyword("TIMESTAMPTZ").to_matchable(), ]) .to_matchable(), + Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -1303,62 +1243,180 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AlterFunctionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterFunctionStatement, |_| { + "DateTimeLiteralGrammar".into(), + NodeMatcher::new(SyntaxKind::DatetimeLiteral, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar") - .optional() - .to_matchable(), - ]) - .to_matchable(), + Ref::new("DateTimeTypeIdentifier").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DatatypeSegment".into(), + NodeMatcher::new(SyntaxKind::DataType, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DotSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + this.disallow_gaps(); + }) .to_matchable(), one_of(vec![ - Ref::new("AlterFunctionActionSegment") - .optional() - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), + Ref::new("WellKnownTextGeometrySegment").to_matchable(), + Ref::new("DateTimeTypeIdentifier").to_matchable(), + Ref::new("StructTypeSegment").to_matchable(), + Ref::new("MapTypeSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("OWNER").to_matchable(), - Ref::keyword("TO").to_matchable(), one_of(vec![ + Ref::keyword("SMALLINT").to_matchable(), + Ref::keyword("INTEGER").to_matchable(), + Ref::keyword("INT").to_matchable(), + Ref::keyword("INT2").to_matchable(), + Ref::keyword("INT4").to_matchable(), + Ref::keyword("INT8").to_matchable(), + Ref::keyword("BIGINT").to_matchable(), + Ref::keyword("FLOAT4").to_matchable(), + Ref::keyword("FLOAT8").to_matchable(), + Ref::keyword("REAL").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DOUBLE").to_matchable(), + Ref::keyword("PRECISION").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SMALLSERIAL").to_matchable(), + Ref::keyword("SERIAL").to_matchable(), + Ref::keyword("SERIAL2").to_matchable(), + Ref::keyword("SERIAL4").to_matchable(), + Ref::keyword("SERIAL8").to_matchable(), + Ref::keyword("BIGSERIAL").to_matchable(), + Sequence::new(vec![ + one_of(vec![Ref::keyword("FLOAT").to_matchable()]) + .to_matchable(), + Ref::new("BracketedArguments").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DECIMAL").to_matchable(), + Ref::keyword("NUMERIC").to_matchable(), + ]) + .to_matchable(), + Ref::new("BracketedArguments").optional().to_matchable(), + ]) + .to_matchable(), + Ref::keyword("MONEY").to_matchable(), one_of(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("BPCHAR").to_matchable(), + Ref::keyword("CHAR").to_matchable(), + Sequence::new(vec![ + Ref::keyword("CHAR").to_matchable(), + Ref::keyword("VARYING").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("CHARACTER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("CHARACTER").to_matchable(), + Ref::keyword("VARYING").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("VARCHAR").to_matchable(), + ]) + .to_matchable(), + Ref::new("BracketedArguments").optional().to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TEXT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("BYTEA").to_matchable(), + one_of(vec![ + Ref::keyword("BOOLEAN").to_matchable(), + Ref::keyword("BOOL").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("POINT").to_matchable(), + Ref::keyword("LINE").to_matchable(), + Ref::keyword("LSEG").to_matchable(), + Ref::keyword("BOX").to_matchable(), + Ref::keyword("PATH").to_matchable(), + Ref::keyword("POLYGON").to_matchable(), + Ref::keyword("CIRCLE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("CIDR").to_matchable(), + Ref::keyword("INET").to_matchable(), + Ref::keyword("MACADDR").to_matchable(), + Ref::keyword("MACADDR8").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("TSVECTOR").to_matchable(), + Ref::keyword("TSQUERY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BIT").to_matchable(), + one_of(vec![Ref::keyword("VARYING").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("BracketedArguments").optional().to_matchable(), + ]) + .to_matchable(), + Ref::keyword("UUID").to_matchable(), + Ref::keyword("XML").to_matchable(), + one_of(vec![ + Ref::keyword("JSON").to_matchable(), + Ref::keyword("JSONB").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("INT4RANGE").to_matchable(), + Ref::keyword("INT8RANGE").to_matchable(), + Ref::keyword("NUMRANGE").to_matchable(), + Ref::keyword("TSRANGE").to_matchable(), + Ref::keyword("TSTZRANGE").to_matchable(), + Ref::keyword("DATERANGE").to_matchable(), + Ref::keyword("PG_LSN").to_matchable(), + Sequence::new(vec![ + Ref::keyword("VECTOR").to_matchable(), + Ref::new("BracketedArguments").optional().to_matchable(), ]) .to_matchable(), - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").optional().to_matchable(), - Ref::keyword("DEPENDS").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("EXTENSION").to_matchable(), - Ref::new("ExtensionReferenceSegment").to_matchable(), + Ref::new("DatatypeIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + AnyNumberOf::new(vec![ + Bracketed::new(vec![ + Ref::new("ExpressionSegment").optional().to_matchable(), + ]) + .config(|this| { + this.bracket_type("square"); + }) + .to_matchable(), ]) .to_matchable(), + Ref::new("ArrayTypeSegment").to_matchable(), + Ref::new("SizedArrayTypeSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -1367,114 +1425,120 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AlterFunctionActionSegment".into(), - NodeMatcher::new(SyntaxKind::AlterFunctionActionSegment, |_| { + "ArrayTypeSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayType, |_dialect| { + Ref::keyword("ARRAY").to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "IndexAccessMethodSegment".into(), + NodeMatcher::new(SyntaxKind::IndexAccessMethod, |_dialect| { + Ref::new("SingleIdentifierGrammar").to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "OperatorClassReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::OperatorClassReference, |_dialect| { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "DefinitionParameterSegment".into(), + NodeMatcher::new(SyntaxKind::DefinitionParameter, |_dialect| { Sequence::new(vec![ - one_of(vec![ - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CALLED").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::keyword("INPUT").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RETURNS").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::keyword("INPUT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("STRICT").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("IMMUTABLE").to_matchable(), - Ref::keyword("STABLE").to_matchable(), - Ref::keyword("VOLATILE").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("LEAKPROOF").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("EXTERNAL").optional().to_matchable(), - Ref::keyword("SECURITY").to_matchable(), - one_of(vec![ - Ref::keyword("DEFINER").to_matchable(), - Ref::keyword("INVOKER").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("PARALLEL").to_matchable(), - one_of(vec![ - Ref::keyword("UNSAFE").to_matchable(), - Ref::keyword("RESTRICTED").to_matchable(), - Ref::keyword("SAFE").to_matchable(), - ]) - .to_matchable(), - ]) + Ref::new("PropertiesNakedIdentifierSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("EqualsSegment").to_matchable(), + Ref::new("DefinitionArgumentValueGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DefinitionParametersSegment".into(), + NodeMatcher::new(SyntaxKind::DefinitionParameters, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("DefinitionParameterSegment").to_matchable()]) .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateCastStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateCastStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("CAST").to_matchable(), + Bracketed::new(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("COST").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar") + .optional() + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("ROWS").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("WITHOUT").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SUPPORT").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::keyword("INOUT").to_matchable(), ]) .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("TO").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("CURRENT").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::keyword("ASSIGNMENT").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("RESET").to_matchable(), - one_of(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::keyword("IMPLICIT").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("RESTRICT").optional().to_matchable(), ]) .to_matchable() }) @@ -1482,59 +1546,46 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AlterProcedureActionSegment".into(), - NodeMatcher::new(SyntaxKind::AlterProcedureActionSegment, |_| { + "DropCastStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropCastStatement, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("EXTERNAL").optional().to_matchable(), - Ref::keyword("SECURITY").to_matchable(), - one_of(vec![ - Ref::keyword("DEFINER").to_matchable(), - Ref::keyword("INVOKER").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("TO").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("CURRENT").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("CAST").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Bracketed::new(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropAggregateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropAggregateStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("AGGREGATE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![ Sequence::new(vec![ - Ref::keyword("RESET").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), one_of(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar").to_matchable(), + Anything::new().to_matchable(), + Ref::new("StarSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Ref::keyword("RESTRICT").optional().to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -1542,88 +1593,60 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AlterProcedureStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterProcedureStatement, |_| { + "CreateAggregateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateAggregateStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("AGGREGATE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Bracketed::new(vec![Anything::new().to_matchable()]).to_matchable(), + Ref::new("FunctionParameterListGrammar").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterAggregateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterAggregateStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ALTER").to_matchable(), - Ref::keyword("PROCEDURE").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar") - .optional() - .to_matchable(), + Ref::keyword("AGGREGATE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("FunctionParameterListGrammar").to_matchable(), + Anything::new().to_matchable(), + Ref::new("StarSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), one_of(vec![ - Ref::new("AlterProcedureActionSegment") - .optional() - .to_matchable(), Sequence::new(vec![ Ref::keyword("RENAME").to_matchable(), Ref::keyword("TO").to_matchable(), Ref::new("FunctionNameSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("TO").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - ]) - .to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("CURRENT").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), Sequence::new(vec![ Ref::keyword("OWNER").to_matchable(), Ref::keyword("TO").to_matchable(), one_of(vec![ - one_of(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), - ]) - .to_matchable(), Ref::keyword("CURRENT_ROLE").to_matchable(), Ref::keyword("CURRENT_USER").to_matchable(), Ref::keyword("SESSION_USER").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("NO").optional().to_matchable(), - Ref::keyword("DEPENDS").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("EXTENSION").to_matchable(), - Ref::new("ExtensionReferenceSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), ]) .to_matchable(), ]) @@ -1635,20 +1658,26 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "CreateProcedureStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateProcedureStatement, |_| { + "RelationOptionSegment".into(), + NodeMatcher::new(SyntaxKind::RelationOption, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), + Ref::new("PropertiesNakedIdentifierSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("DotSegment").to_matchable(), + Ref::new("PropertiesNakedIdentifierSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("DefinitionArgumentValueGrammar").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("PROCEDURE").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar").to_matchable(), - Ref::new("FunctionDefinitionGrammar").to_matchable(), ]) .to_matchable() }) @@ -1656,28 +1685,11 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "DropProcedureStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropProcedureStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("PROCEDURE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar") - .optional() - .to_matchable(), - ]) + "RelationOptionsSegment".into(), + NodeMatcher::new(SyntaxKind::RelationOptions, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("RelationOptionSegment").to_matchable()]) .to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("CASCADE").to_matchable(), - Ref::keyword("RESTRICT").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), ]) .to_matchable() }) @@ -1685,37 +1697,28 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "WellKnownTextGeometrySegment".into(), - NodeMatcher::new(SyntaxKind::WktGeometryType, |_| { - let geometry_type_keywords = POSTGRES_POSTGIS_DATATYPE_KEYWORDS - .iter() - .map(|(kw, _)| Ref::keyword(*kw).to_matchable()) - .collect_vec(); - - let mut geometry_type_keywords0 = geometry_type_keywords.clone(); - geometry_type_keywords0.extend( - ["GEOMETRY", "GEOGRAPHY"] - .into_iter() - .map(|it| Ref::keyword(it).to_matchable()), - ); - - one_of(vec![ + "CreateFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateFunctionStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar").to_matchable(), Sequence::new(vec![ - one_of(geometry_type_keywords.clone()).to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - optionally_bracketed(vec![ - Delimited::new(vec![ - Ref::new("SimpleGeometryGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("RETURNS").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), Bracketed::new(vec![ Delimited::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("SimpleGeometryGrammar").to_matchable(), + one_of(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), ]) .to_matchable(), ]) @@ -1724,30 +1727,25 @@ pub fn raw_dialect() -> Dialect { .to_matchable(), ]) .to_matchable(), - Ref::new("WellKnownTextGeometrySegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("GEOMETRY").to_matchable(), - Ref::keyword("GEOGRAPHY").to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![ Sequence::new(vec![ - one_of(geometry_type_keywords0).to_matchable(), - Ref::new("CommaSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("SETOF").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), ]) .to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("FunctionDefinitionGrammar").to_matchable(), ]) .to_matchable() }) @@ -1755,181 +1753,202 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "SemiStructuredAccessorSegment".into(), - NodeMatcher::new(SyntaxKind::SemiStructuredExpression, |_| { + "DropFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_dialect| { Sequence::new(vec![ - Ref::new("DotSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("ArrayAccessorSegment").optional().to_matchable(), - AnyNumberOf::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![ Sequence::new(vec![ - Ref::new("DotSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar") + .optional() + .to_matchable(), ]) .to_matchable(), - Ref::new("ArrayAccessorSegment").optional().to_matchable(), ]) .to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - postgres.replace_grammar( - "FunctionDefinitionGrammar", - Sequence::new(vec![ - AnyNumberOf::new(vec![ - Ref::new("LanguageClauseSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("TRANSFORM").to_matchable(), - Ref::keyword("FOR").to_matchable(), - Ref::keyword("TYPE").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - one_of(vec![ - Ref::keyword("IMMUTABLE").to_matchable(), - Ref::keyword("STABLE").to_matchable(), - Ref::keyword("VOLATILE").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("LEAKPROOF").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CALLED").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::keyword("INPUT").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RETURNS").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::keyword("INPUT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("STRICT").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("EXTERNAL").optional().to_matchable(), - Ref::keyword("SECURITY").to_matchable(), - one_of(vec![ - Ref::keyword("INVOKER").to_matchable(), - Ref::keyword("DEFINER").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + ( + "AlterFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterFunctionStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("PARALLEL").to_matchable(), - one_of(vec![ - Ref::keyword("UNSAFE").to_matchable(), - Ref::keyword("RESTRICTED").to_matchable(), - Ref::keyword("SAFE").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COST").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ROWS").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SUPPORT").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), one_of(vec![ + Ref::new("AlterFunctionActionSegment") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), one_of(vec![ - Ref::keyword("TO").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - ]) - .to_matchable(), - Delimited::new(vec![ one_of(vec![ Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), ]) .to_matchable(), + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("NO").optional().to_matchable(), + Ref::keyword("DEPENDS").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("EXTENSION").to_matchable(), + Ref::new("ExtensionReferenceSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterFunctionActionSegment".into(), + NodeMatcher::new(SyntaxKind::AlterFunctionActionSegment, |_dialect| { + Sequence::new(vec![ one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CALLED").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("INPUT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURNS").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("INPUT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("STRICT").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("IMMUTABLE").to_matchable(), + Ref::keyword("STABLE").to_matchable(), + Ref::keyword("VOLATILE").to_matchable(), + ]) + .to_matchable(), Sequence::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("CommaSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("LEAKPROOF").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()]) + Sequence::new(vec![ + Ref::keyword("EXTERNAL").optional().to_matchable(), + Ref::keyword("SECURITY").to_matchable(), + one_of(vec![ + Ref::keyword("DEFINER").to_matchable(), + Ref::keyword("INVOKER").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PARALLEL").to_matchable(), + one_of(vec![ + Ref::keyword("UNSAFE").to_matchable(), + Ref::keyword("RESTRICTED").to_matchable(), + Ref::keyword("SAFE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COST").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROWS").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SUPPORT").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TO").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("CURRENT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESET").to_matchable(), + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([ - ( - "IntoClauseSegment".into(), - NodeMatcher::new(SyntaxKind::IntoClause, |_| { - Sequence::new(vec![ - Ref::keyword("INTO").to_matchable(), - one_of(vec![ - Ref::keyword("TEMPORARY").to_matchable(), - Ref::keyword("TEMP").to_matchable(), - Ref::keyword("UNLOGGED").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::keyword("TABLE").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("RESTRICT").optional().to_matchable(), ]) .to_matchable() }) @@ -1937,192 +1956,170 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "ForClauseSegment".into(), - NodeMatcher::new(SyntaxKind::ForClause, |_| { + "AlterProcedureActionSegment".into(), + NodeMatcher::new(SyntaxKind::AlterProcedureActionSegment, |_dialect| { Sequence::new(vec![ - Ref::keyword("FOR").to_matchable(), one_of(vec![ - Ref::keyword("UPDATE").to_matchable(), Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("KEY").to_matchable(), - Ref::keyword("UPDATE").to_matchable(), + Ref::keyword("EXTERNAL").optional().to_matchable(), + Ref::keyword("SECURITY").to_matchable(), + one_of(vec![ + Ref::keyword("DEFINER").to_matchable(), + Ref::keyword("INVOKER").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Ref::keyword("SHARE").to_matchable(), Sequence::new(vec![ - Ref::keyword("KEY").to_matchable(), - Ref::keyword("SHARE").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TO").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("CURRENT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OF").to_matchable(), - Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Ref::keyword("NOWAIT").to_matchable(), Sequence::new(vec![ - Ref::keyword("SKIP").to_matchable(), - Ref::keyword("LOCKED").to_matchable(), + Ref::keyword("RESET").to_matchable(), + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + Ref::keyword("RESTRICT").optional().to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - postgres.replace_grammar( - "UnorderedSelectStatementSegment", - ansi::get_unordered_select_statement_segment_grammar().copy( - Some(vec![ - Ref::new("IntoClauseSegment").optional().to_matchable(), - ]), - None, - Some(Ref::new("FromClauseSegment").optional().to_matchable()), - None, - vec![ - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("NO").optional().to_matchable(), - Ref::keyword("DATA").to_matchable(), - ]) - .to_matchable(), + ( + "AlterProcedureStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterProcedureStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("CONFLICT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("RETURNING").to_matchable(), - Ref::new("WithCheckOptionSegment").to_matchable(), - ], - false, - ), - ); - - postgres.replace_grammar( - "SelectStatementSegment", - postgres - .grammar("UnorderedSelectStatementSegment") - .match_grammar(&postgres) - .unwrap() - .copy( - Some(vec![ - Ref::new("OrderByClauseSegment").optional().to_matchable(), - Ref::new("LimitClauseSegment").optional().to_matchable(), - Ref::new("NamedWindowSegment").optional().to_matchable(), - ]), - None, - None, - None, - vec![], - false, - ) - .copy( - Some(vec![Ref::new("ForClauseSegment").optional().to_matchable()]), - None, - Some(Ref::new("LimitClauseSegment").optional().to_matchable()), - None, - vec![ - Ref::new("SetOperatorSegment").to_matchable(), - Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), - Ref::new("WithDataClauseSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("CONFLICT").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Ref::keyword("RETURNING").to_matchable(), - Ref::new("WithCheckOptionSegment").to_matchable(), - ], - true, - ), - ); - - postgres.replace_grammar( - "SelectClauseSegment", - Sequence::new(vec![ - Ref::keyword("SELECT").to_matchable(), - Ref::new("SelectClauseModifierSegment") - .optional() - .to_matchable(), - MetaSegment::indent().to_matchable(), - Delimited::new(vec![Ref::new("SelectClauseElementSegment").to_matchable()]) - .config(|this| { - this.optional(); - this.allow_trailing = true; - }) - .to_matchable(), - ]) - .config(|this| { - this.terminators = vec![ - Ref::keyword("INTO").to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::keyword("WHERE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("OVERLAPS").to_matchable(), - Ref::new("SetOperatorSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("NO").optional().to_matchable(), - Ref::keyword("DATA").to_matchable(), - ]) - .to_matchable(), - Ref::new("WithCheckOptionSegment").to_matchable(), - ]; - this.parse_mode(ParseMode::GreedyOnceStarted); - }) - .to_matchable(), - ); - - postgres.replace_grammar( - "SelectClauseModifierSegment", - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("DISTINCT").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + one_of(vec![ + Ref::new("AlterProcedureActionSegment") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TO").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("CURRENT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + one_of(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + ]) .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").optional().to_matchable(), + Ref::keyword("DEPENDS").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("EXTENSION").to_matchable(), + Ref::new("ExtensionReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("ALL").to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([ + .to_matchable() + }) + .to_matchable() + .into(), + ), ( - "WithinGroupClauseSegment".into(), - NodeMatcher::new(SyntaxKind::WithingroupClause, |_| { + "OffsetClauseSegment".into(), + NodeMatcher::new(SyntaxKind::OffsetClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("WITHIN").to_matchable(), - Ref::keyword("GROUP").to_matchable(), - Bracketed::new(vec![ - Ref::new("OrderByClauseSegment").optional().to_matchable(), + Ref::keyword("OFFSET").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) @@ -2130,1312 +2127,1212 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "GroupByClauseSegment".into(), - NodeMatcher::new(SyntaxKind::GroupbyClause, |_| { + "CreateProcedureStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateProcedureStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - MetaSegment::indent().to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar").to_matchable(), + Ref::new("FunctionDefinitionGrammar").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropProcedureStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropProcedureStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), Delimited::new(vec![ - one_of(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("CubeRollupClauseSegment").to_matchable(), - Ref::new("GroupingSetsClauseSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - Bracketed::new(vec![]).to_matchable(), + Sequence::new(vec![ + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar") + .optional() + .to_matchable(), ]) .to_matchable(), ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("CASCADE").to_matchable(), + Ref::keyword("RESTRICT").to_matchable(), + ]) .config(|this| { - this.terminators = vec![ - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("QUALIFY").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::new("SetOperatorSegment").to_matchable(), - ]; + this.optional(); }) .to_matchable(), - MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - postgres.replace_grammar( - "CreateRoleStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - one_of(vec![ - Ref::keyword("ROLE").to_matchable(), - Ref::keyword("USER").to_matchable(), - ]) - .to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").optional().to_matchable(), - any_set_of(vec![ - one_of(vec![ - Ref::keyword("SUPERUSER").to_matchable(), - Ref::keyword("NOSUPERUSER").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("CREATEDB").to_matchable(), - Ref::keyword("NOCREATEDB").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("CREATEROLE").to_matchable(), - Ref::keyword("NOCREATEROLE").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("INHERIT").to_matchable(), - Ref::keyword("NOINHERIT").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("LOGIN").to_matchable(), - Ref::keyword("NOLOGIN").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("REPLICATION").to_matchable(), - Ref::keyword("NOREPLICATION").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("BYPASSRLS").to_matchable(), - Ref::keyword("NOBYPASSRLS").to_matchable(), - ]) - .to_matchable(), + ( + "WellKnownTextGeometrySegment".into(), + NodeMatcher::new(SyntaxKind::WktGeometryType, |_dialect| { + one_of(vec![ Sequence::new(vec![ - Ref::keyword("CONNECTION").to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + one_of(vec![ + Ref::keyword("POINT").to_matchable(), + Ref::keyword("LINESTRING").to_matchable(), + Ref::keyword("POLYGON").to_matchable(), + Ref::keyword("MULTIPOINT").to_matchable(), + Ref::keyword("MULTILINESTRING").to_matchable(), + Ref::keyword("MULTIPOLYGON").to_matchable(), + Ref::keyword("GEOMETRYCOLLECTION").to_matchable(), + Ref::keyword("POINTZ").to_matchable(), + Ref::keyword("LINESTRINGZ").to_matchable(), + Ref::keyword("POLYGONZ").to_matchable(), + Ref::keyword("MULTIPOINTZ").to_matchable(), + Ref::keyword("MULTILINESTRINGZ").to_matchable(), + Ref::keyword("MULTIPOLYGONZ").to_matchable(), + Ref::keyword("GEOMETRYCOLLECTIONZ").to_matchable(), + Ref::keyword("POINTM").to_matchable(), + Ref::keyword("LINESTRINGM").to_matchable(), + Ref::keyword("POLYGONM").to_matchable(), + Ref::keyword("MULTIPOINTM").to_matchable(), + Ref::keyword("MULTILINESTRINGM").to_matchable(), + Ref::keyword("MULTIPOLYGONM").to_matchable(), + Ref::keyword("GEOMETRYCOLLECTIONM").to_matchable(), + Ref::keyword("POINTZM").to_matchable(), + Ref::keyword("LINESTRINGZM").to_matchable(), + Ref::keyword("POLYGONZM").to_matchable(), + Ref::keyword("MULTIPOINTZM").to_matchable(), + Ref::keyword("MULTILINESTRINGZM").to_matchable(), + Ref::keyword("MULTIPOLYGONZM").to_matchable(), + Ref::keyword("GEOMETRYCOLLECTIONZM").to_matchable(), + Ref::keyword("CIRCULARSTRING").to_matchable(), + Ref::keyword("COMPOUNDCURVE").to_matchable(), + Ref::keyword("CURVEPOLYGON").to_matchable(), + Ref::keyword("MULTICURVE").to_matchable(), + Ref::keyword("MULTISURFACE").to_matchable(), + Ref::keyword("POLYHEDRALSURFACE").to_matchable(), + Ref::keyword("TRIANGLE").to_matchable(), + Ref::keyword("TIN").to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + optionally_bracketed(vec![ + Delimited::new(vec![ + Ref::new("SimpleGeometryGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SimpleGeometryGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("WellKnownTextGeometrySegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("PASSWORD").to_matchable(), one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::keyword("NULL").to_matchable(), + Ref::keyword("GEOMETRY").to_matchable(), + Ref::keyword("GEOGRAPHY").to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("POINT").to_matchable(), + Ref::keyword("LINESTRING").to_matchable(), + Ref::keyword("POLYGON").to_matchable(), + Ref::keyword("MULTIPOINT").to_matchable(), + Ref::keyword("MULTILINESTRING").to_matchable(), + Ref::keyword("MULTIPOLYGON").to_matchable(), + Ref::keyword("GEOMETRYCOLLECTION").to_matchable(), + Ref::keyword("POINTZ").to_matchable(), + Ref::keyword("LINESTRINGZ").to_matchable(), + Ref::keyword("POLYGONZ").to_matchable(), + Ref::keyword("MULTIPOINTZ").to_matchable(), + Ref::keyword("MULTILINESTRINGZ").to_matchable(), + Ref::keyword("MULTIPOLYGONZ").to_matchable(), + Ref::keyword("GEOMETRYCOLLECTIONZ").to_matchable(), + Ref::keyword("POINTM").to_matchable(), + Ref::keyword("LINESTRINGM").to_matchable(), + Ref::keyword("POLYGONM").to_matchable(), + Ref::keyword("MULTIPOINTM").to_matchable(), + Ref::keyword("MULTILINESTRINGM").to_matchable(), + Ref::keyword("MULTIPOLYGONM").to_matchable(), + Ref::keyword("GEOMETRYCOLLECTIONM").to_matchable(), + Ref::keyword("POINTZM").to_matchable(), + Ref::keyword("LINESTRINGZM").to_matchable(), + Ref::keyword("POLYGONZM").to_matchable(), + Ref::keyword("MULTIPOINTZM").to_matchable(), + Ref::keyword("MULTILINESTRINGZM").to_matchable(), + Ref::keyword("MULTIPOLYGONZM").to_matchable(), + Ref::keyword("GEOMETRYCOLLECTIONZM").to_matchable(), + Ref::keyword("CIRCULARSTRING").to_matchable(), + Ref::keyword("COMPOUNDCURVE").to_matchable(), + Ref::keyword("CURVEPOLYGON").to_matchable(), + Ref::keyword("MULTICURVE").to_matchable(), + Ref::keyword("MULTISURFACE").to_matchable(), + Ref::keyword("POLYHEDRALSURFACE").to_matchable(), + Ref::keyword("TRIANGLE").to_matchable(), + Ref::keyword("TIN").to_matchable(), + Ref::keyword("GEOMETRY").to_matchable(), + Ref::keyword("GEOGRAPHY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("CommaSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("VALID").to_matchable(), - Ref::keyword("UNTIL").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SemiStructuredAccessorSegment".into(), + NodeMatcher::new(SyntaxKind::SemiStructuredExpression, |_dialect| { + Sequence::new(vec![ + Ref::new("DotSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ArrayAccessorSegment").optional().to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("DotSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("ArrayAccessorSegment").optional().to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("IN").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("IN").to_matchable(), - Ref::keyword("GROUP").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ROLE").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ADMIN").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("USER").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SYSID").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([( - "AlterRoleStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterRoleStatement, |_| { - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - one_of(vec![ - Ref::keyword("ROLE").to_matchable(), - Ref::keyword("USER").to_matchable(), ]) - .to_matchable(), - one_of(vec![ - // role_specification - Sequence::new(vec![ + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FunctionDefinitionGrammar".into(), + NodeMatcher::new(SyntaxKind::FunctionDefinition, |_dialect| { + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Ref::new("LanguageClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TRANSFORM").to_matchable(), + Ref::keyword("FOR").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("WINDOW").to_matchable(), one_of(vec![ - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), + Ref::keyword("IMMUTABLE").to_matchable(), + Ref::keyword("STABLE").to_matchable(), + Ref::keyword("VOLATILE").to_matchable(), ]) .to_matchable(), - Ref::keyword("WITH").optional().to_matchable(), - any_set_of(vec![ - one_of(vec![ - Ref::keyword("SUPERUSER").to_matchable(), - Ref::keyword("NOSUPERUSER").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("CREATEDB").to_matchable(), - Ref::keyword("NOCREATEDB").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("CREATEROLE").to_matchable(), - Ref::keyword("NOCREATEROLE").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("INHERIT").to_matchable(), - Ref::keyword("NOINHERIT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("LEAKPROOF").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CALLED").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("INPUT").to_matchable(), ]) .to_matchable(), - one_of(vec![ - Ref::keyword("LOGIN").to_matchable(), - Ref::keyword("NOLOGIN").to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURNS").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("INPUT").to_matchable(), ]) .to_matchable(), + Ref::keyword("STRICT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").optional().to_matchable(), + Ref::keyword("SECURITY").to_matchable(), one_of(vec![ - Ref::keyword("REPLICATION").to_matchable(), - Ref::keyword("NOREPLICATION").to_matchable(), + Ref::keyword("INVOKER").to_matchable(), + Ref::keyword("DEFINER").to_matchable(), ]) .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PARALLEL").to_matchable(), one_of(vec![ - Ref::keyword("BYPASSRLS").to_matchable(), - Ref::keyword("NOBYPASSRLS").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CONNECTION").to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ENCRYPTED").optional().to_matchable(), - Ref::keyword("PASSWORD").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::keyword("NULL").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("VALID").to_matchable(), - Ref::keyword("UNTIL").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("UNSAFE").to_matchable(), + Ref::keyword("RESTRICTED").to_matchable(), + Ref::keyword("SAFE").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - // name only - Sequence::new(vec![ - Ref::new("RoleReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), + Ref::keyword("COST").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - // role_specification | all - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), - Ref::keyword("ALL").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROWS").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("IN").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), + Ref::keyword("SUPPORT").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("TO").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - ]) - .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TO").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ one_of(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Delimited::new(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("OnKeywordAsIdentifierSegment") - .to_matchable(), - ]) - .to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("CURRENT").to_matchable(), - ]) - .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("CURRENT").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RESET").to_matchable(), - one_of(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::keyword("ALL").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURN").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BEGIN").to_matchable(), + Ref::keyword("ATOMIC").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("InsertStatementSegment").to_matchable(), + Ref::new("SemicolonSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("UpdateStatementSegment").to_matchable(), + Ref::new("SemicolonSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("WithCompoundStatementSegment").to_matchable(), + Ref::new("SelectStatementSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("SemicolonSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURN").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("SemicolonSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Ref::keyword("END").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()]) + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.replace_grammar( - "ExplainStatementSegment", - Sequence::new(vec![ - Ref::keyword("EXPLAIN").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ANALYZE").optional().to_matchable(), - Ref::keyword("ANALYSE").optional().to_matchable(), - ]) - .to_matchable(), - Ref::keyword("VERBOSE").optional().to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ExplainOptionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ansi::explainable_stmt().to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([( - "ExplainOptionSegment".into(), - NodeMatcher::new(SyntaxKind::ExplainOption, |_| { - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ANALYZE").to_matchable(), - Ref::keyword("ANALYSE").to_matchable(), - Ref::keyword("VERBOSE").to_matchable(), - Ref::keyword("COSTS").to_matchable(), - Ref::keyword("SETTINGS").to_matchable(), - Ref::keyword("BUFFERS").to_matchable(), - Ref::keyword("WAL").to_matchable(), - Ref::keyword("TIMING").to_matchable(), - Ref::keyword("SUMMARY").to_matchable(), - ]) - .to_matchable(), - Ref::new("BooleanLiteralGrammar").optional().to_matchable(), - ]) - .to_matchable(), + .into(), + ), + ( + "IntoClauseSegment".into(), + NodeMatcher::new(SyntaxKind::IntoClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("FORMAT").to_matchable(), + Ref::keyword("INTO").to_matchable(), one_of(vec![ - Ref::keyword("TEXT").to_matchable(), - Ref::keyword("XML").to_matchable(), - Ref::keyword("JSON").to_matchable(), - Ref::keyword("YAML").to_matchable(), + Ref::keyword("TEMPORARY").to_matchable(), + Ref::keyword("TEMP").to_matchable(), + Ref::keyword("UNLOGGED").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::keyword("TABLE").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.replace_grammar( - "CreateSchemaStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::new("SchemaReferenceSegment").optional().to_matchable(), - Ref::keyword("AUTHORIZATION").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.replace_grammar( - "CreateTableStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - one_of(vec![ + .into(), + ), + ( + "ForClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ForClause, |_dialect| { Sequence::new(vec![ + Ref::keyword("FOR").to_matchable(), one_of(vec![ - Ref::keyword("GLOBAL").to_matchable(), - Ref::keyword("LOCAL").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("TemporaryGrammar").optional().to_matchable(), - ]) - .to_matchable(), - Ref::keyword("UNLOGGED").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Sequence::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - AnyNumberOf::new(vec![ - one_of(vec![ - Ref::new("ColumnConstraintSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLLATE").to_matchable(), - Ref::new("CollationReferenceSegment") - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("TableConstraintSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("LIKE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("LikeOptionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INHERITS").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()]) - .to_matchable(), + Ref::keyword("UPDATE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("KEY").to_matchable(), + Ref::keyword("UPDATE").to_matchable(), ]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OF").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("OPTIONS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("ColumnConstraintSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("TableConstraintSegment").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("KEY").to_matchable(), + Ref::keyword("SHARE").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("PARTITION").to_matchable(), - Ref::keyword("OF").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("OPTIONS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("ColumnConstraintSegment").to_matchable(), - ]) - .to_matchable(), - ]) + Sequence::new(vec![ + Ref::keyword("OF").to_matchable(), + Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()]) .to_matchable(), - Ref::new("TableConstraintSegment").to_matchable(), - ]) - .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), one_of(vec![ + Ref::keyword("NOWAIT").to_matchable(), Sequence::new(vec![ - Ref::keyword("FOR").to_matchable(), - Ref::keyword("VALUES").to_matchable(), - Ref::new("PartitionBoundSpecSegment").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("PARTITION").to_matchable(), - Ref::keyword("BY").to_matchable(), - one_of(vec![ - Ref::keyword("RANGE").to_matchable(), - Ref::keyword("LIST").to_matchable(), - Ref::keyword("HASH").to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![ - AnyNumberOf::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - ]) - .to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("COLLATE").to_matchable(), - Ref::new("CollationReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("ParameterNameSegment").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("SKIP").to_matchable(), + Ref::keyword("LOCKED").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::new("RelationOptionsSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITHOUT").to_matchable(), - Ref::keyword("OIDS").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("COMMIT").to_matchable(), - one_of(vec![ + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UnorderedSelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("UnorderedSelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("IntoClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("FromClauseSegment").optional().to_matchable()), + None, + vec![ Sequence::new(vec![ - Ref::keyword("PRESERVE").to_matchable(), - Ref::keyword("ROWS").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::keyword("NO").optional().to_matchable(), + Ref::keyword("DATA").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("DELETE").to_matchable(), - Ref::keyword("ROWS").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("CONFLICT").to_matchable(), ]) .to_matchable(), - Ref::keyword("DROP").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TABLESPACE").to_matchable(), - Ref::new("TablespaceReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([( - "CreateTableAsStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateTableAsStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("GLOBAL").to_matchable(), - Ref::keyword("LOCAL").to_matchable(), + Ref::keyword("RETURNING").to_matchable(), + Ref::new("WithCheckOptionSegment").to_matchable(), + Ref::new("MetaCommandQueryBufferSegment").to_matchable(), + ], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "SelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + get_unordered_select_statement_segment_grammar().copy( + Some(vec![ + Ref::new("NamedWindowSegment").optional().to_matchable(), + Ref::new("OrderByClauseSegment").optional().to_matchable(), + Ref::new("LimitClauseSegment").optional().to_matchable(), + Ref::new("OffsetClauseSegment").optional().to_matchable(), + Ref::new("FetchClauseSegment").optional().to_matchable(), + Ref::new("ForClauseSegment").optional().to_matchable(), + ]), + None, + None, + None, + vec![ + Ref::new("SetOperatorSegment").to_matchable(), + Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), + Ref::new("WithDataClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("CONFLICT").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::new("TemporaryGrammar").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("UNLOGGED").to_matchable(), + Ref::keyword("RETURNING").to_matchable(), + Ref::new("WithCheckOptionSegment").to_matchable(), + Ref::new("MetaCommandQueryBufferSegment").to_matchable(), + ], + true, + ) + }) + .to_matchable() + .into(), + ), + ( + "SelectClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("SELECT").to_matchable(), + Ref::new("SelectClauseModifierSegment") + .optional() + .to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![Ref::new("SelectClauseElementSegment").to_matchable()]) + .config(|this| { + this.optional(); + this.allow_trailing(); + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .to_matchable(), + .config(|this| { + this.parse_mode(ParseMode::GreedyOnceStarted); + this.terminators = vec![ + Ref::keyword("INTO").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::keyword("WHERE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("CONFLICT").to_matchable(), ]) .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("RETURNING").to_matchable(), + Ref::keyword("OVERLAPS").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("WITHOUT").to_matchable(), - Ref::keyword("OIDS").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::keyword("NO").optional().to_matchable(), + Ref::keyword("DATA").to_matchable(), ]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::new("WithCheckOptionSegment").to_matchable(), + Ref::new("MetaCommandQueryBufferSegment").to_matchable(), + ]; + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SelectClauseModifierSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClauseModifier, |_dialect| { + one_of(vec![ Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("COMMIT").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("PRESERVE").to_matchable(), - Ref::keyword("ROWS").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DELETE").to_matchable(), - Ref::keyword("ROWS").to_matchable(), + Ref::keyword("DISTINCT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), ]) .to_matchable(), - Ref::keyword("DROP").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TABLESPACE").to_matchable(), - Ref::new("TablespaceReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) .to_matchable(), + Ref::keyword("ALL").to_matchable(), ]) - .to_matchable(), - Ref::keyword("AS").to_matchable(), - one_of(vec![ - optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) - .to_matchable(), - optionally_bracketed(vec![ - Sequence::new(vec![ - Ref::keyword("TABLE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WithinGroupClauseSegment".into(), + NodeMatcher::new(SyntaxKind::WithingroupClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("WITHIN").to_matchable(), + Ref::keyword("GROUP").to_matchable(), + Bracketed::new(vec![ + Ref::new("OrderByClauseSegment").optional().to_matchable(), ]) .to_matchable(), - Ref::new("ValuesClauseSegment").to_matchable(), - optionally_bracketed(vec![ - Sequence::new(vec![ - Ref::keyword("EXECUTE").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "GroupByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::GroupbyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("CubeRollupClauseSegment").to_matchable(), + Ref::new("GroupingSetsClauseSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Bracketed::new(vec![]).to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.terminators = vec![ + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), + ]; + }) .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .to_matchable(), - Ref::new("WithDataClauseSegment").optional().to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - // A `ALTER AGGREGATE` statement. - // https://www.postgresql.org/docs/current/sql-alteraggregate.html - postgres.add([( - "AlterAggregateStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("AGGREGATE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Bracketed::new(vec![ - one_of(vec![ - Ref::new("FunctionParameterListGrammar").to_matchable(), - Anything::new().to_matchable(), - Ref::new("StarSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - one_of(vec![ + .into(), + ), + ( + "CompositeValueExpansionSegment".into(), + NodeMatcher::new(SyntaxKind::CompositeValueExpansion, |_dialect| { Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + Ref::new("DotSegment").to_matchable(), + Ref::new("StarSegment").to_matchable(), ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateRoleStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateRoleStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("OWNER").to_matchable(), - Ref::keyword("TO").to_matchable(), + Ref::keyword("CREATE").to_matchable(), one_of(vec![ - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("USER").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - .into(), - )]); - - postgres.replace_grammar( - "AlterTableStatementSegment", - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::keyword("ONLY").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("StarSegment").optional().to_matchable(), - one_of(vec![ - Delimited::new(vec![Ref::new("AlterTableActionSegment").to_matchable()]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ATTACH").to_matchable(), - Ref::keyword("PARTITION").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").optional().to_matchable(), + AnyNumberOf::new(vec![ one_of(vec![ - Sequence::new(vec![ - Ref::keyword("FOR").to_matchable(), - Ref::keyword("VALUES").to_matchable(), - Ref::new("PartitionBoundSpecSegment").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("SUPERUSER").to_matchable(), + Ref::keyword("NOSUPERUSER").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DETACH").to_matchable(), - Ref::keyword("PARTITION").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - Ref::keyword("CONCURRENTLY").optional().to_matchable(), - Ref::keyword("FINALIZE").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("IN").to_matchable(), - Ref::keyword("TABLESPACE").to_matchable(), - Ref::new("TablespaceReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OWNED").to_matchable(), - Ref::keyword("BY").to_matchable(), - Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) - .config(|this| this.optional()) + one_of(vec![ + Ref::keyword("CREATEDB").to_matchable(), + Ref::keyword("NOCREATEDB").to_matchable(), + ]) .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("SET").to_matchable(), - Ref::keyword("TABLESPACE").to_matchable(), - Ref::new("TablespaceReferenceSegment").to_matchable(), - Ref::keyword("NOWAIT").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([ - ( - "AlterTableActionSegment".into(), - NodeMatcher::new(SyntaxKind::AlterTableActionSegment, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLLATE").to_matchable(), - Ref::new("CollationReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - AnyNumberOf::new(vec![Ref::new("ColumnConstraintSegment").to_matchable()]) + one_of(vec![ + Ref::keyword("CREATEROLE").to_matchable(), + Ref::keyword("NOCREATEROLE").to_matchable(), + ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("DATA").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("TYPE").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLLATE").to_matchable(), - Ref::new("CollationReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - one_of(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + one_of(vec![ + Ref::keyword("INHERIT").to_matchable(), + Ref::keyword("NOINHERIT").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Ref::new("BareFunctionSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), + one_of(vec![ + Ref::keyword("LOGIN").to_matchable(), + Ref::keyword("NOLOGIN").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), + one_of(vec![ + Ref::keyword("REPLICATION").to_matchable(), + Ref::keyword("NOREPLICATION").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("DROP").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("NULL").to_matchable(), + one_of(vec![ + Ref::keyword("BYPASSRLS").to_matchable(), + Ref::keyword("NOBYPASSRLS").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("EXPRESSION").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::keyword("CONNECTION").to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("GENERATED").to_matchable(), + Ref::keyword("ENCRYPTED").optional().to_matchable(), + Ref::keyword("PASSWORD").to_matchable(), one_of(vec![ - Ref::keyword("ALWAYS").to_matchable(), - Sequence::new(vec![ - Ref::keyword("BY").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::keyword("IDENTITY").to_matchable(), - Bracketed::new(vec![ - AnyNumberOf::new(vec![ - Ref::new("AlterSequenceOptionsSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("NULL").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("GENERATED").to_matchable(), - one_of(vec![ - Ref::keyword("ALWAYS").to_matchable(), - Sequence::new(vec![ - Ref::keyword("BY").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("AlterSequenceOptionsSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RESTART").to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("VALID").to_matchable(), + Ref::keyword("UNTIL").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("IDENTITY").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("STATISTICS").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("GROUP").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("RelationOptionsSegment").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("RESET").to_matchable(), - Ref::new("RelationOptionsSegment").to_matchable(), + Ref::keyword("ADMIN").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("STORAGE").to_matchable(), - one_of(vec![ - Ref::keyword("PLAIN").to_matchable(), - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("EXTENDED").to_matchable(), - Ref::keyword("MAIN").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), ]) .to_matchable(), - ]) + Sequence::new(vec![ + Ref::keyword("SYSID").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::new("TableConstraintSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::new("TableConstraintUsingIndexSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterRoleStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterRoleStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + one_of(vec![ + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("USER").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - one_of(vec![ - Ref::keyword("DEFERRABLE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("DEFERRABLE").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("WITH").optional().to_matchable(), + AnyNumberOf::new(vec![ + one_of(vec![ + Ref::keyword("SUPERUSER").to_matchable(), + Ref::keyword("NOSUPERUSER").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("CREATEDB").to_matchable(), + Ref::keyword("NOCREATEDB").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("CREATEROLE").to_matchable(), + Ref::keyword("NOCREATEROLE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("INHERIT").to_matchable(), + Ref::keyword("NOINHERIT").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("LOGIN").to_matchable(), + Ref::keyword("NOLOGIN").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("REPLICATION").to_matchable(), + Ref::keyword("NOREPLICATION").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("BYPASSRLS").to_matchable(), + Ref::keyword("NOBYPASSRLS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONNECTION").to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENCRYPTED").optional().to_matchable(), + Ref::keyword("PASSWORD").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("VALID").to_matchable(), + Ref::keyword("UNTIL").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - one_of(vec![ + Sequence::new(vec![ + Ref::new("RoleReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("DEFERRED").to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + Ref::keyword("ALL").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("IMMEDIATE").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TO").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Delimited::new(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("NakedIdentifierSegment") + .to_matchable(), + Ref::new("OnKeywordAsIdentifierSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("CURRENT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESET").to_matchable(), + one_of(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("VALIDATE").to_matchable(), - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ENABLE").to_matchable(), - Ref::keyword("DISABLE").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ExplainStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ExplainStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("EXPLAIN").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ANALYZE").to_matchable(), + Ref::keyword("ANALYSE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("VERBOSE").optional().to_matchable(), ]) .to_matchable(), - Ref::keyword("TRIGGER").to_matchable(), - one_of(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::keyword("ALL").to_matchable(), - Ref::keyword("USER").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ExplainOptionSegment").to_matchable()]) + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ENABLE").to_matchable(), - one_of(vec![ - Ref::keyword("REPLICA").to_matchable(), - Ref::keyword("ALWAYS").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("TRIGGER").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), + one_of(vec![ + Ref::new("SelectableGrammar").to_matchable(), + Ref::new("InsertStatementSegment").to_matchable(), + Ref::new("UpdateStatementSegment").to_matchable(), + Ref::new("DeleteStatementSegment").to_matchable(), ]) .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ExplainOptionSegment".into(), + NodeMatcher::new(SyntaxKind::ExplainOption, |_dialect| { + one_of(vec![ Sequence::new(vec![ one_of(vec![ - Ref::keyword("ENABLE").to_matchable(), - Ref::keyword("DISABLE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ENABLE").to_matchable(), - Ref::keyword("REPLICA").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ENABLE").to_matchable(), - Ref::keyword("RULE").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("ANALYZE").to_matchable(), + Ref::keyword("ANALYSE").to_matchable(), + Ref::keyword("VERBOSE").to_matchable(), + Ref::keyword("COSTS").to_matchable(), + Ref::keyword("SETTINGS").to_matchable(), + Ref::keyword("BUFFERS").to_matchable(), + Ref::keyword("WAL").to_matchable(), + Ref::keyword("TIMING").to_matchable(), + Ref::keyword("SUMMARY").to_matchable(), ]) .to_matchable(), - Ref::keyword("RULE").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").optional().to_matchable(), ]) .to_matchable(), Sequence::new(vec![ + Ref::keyword("FORMAT").to_matchable(), one_of(vec![ - Ref::keyword("DISABLE").to_matchable(), - Ref::keyword("ENABLE").to_matchable(), - Ref::keyword("FORCE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("FORCE").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("TEXT").to_matchable(), + Ref::keyword("XML").to_matchable(), + Ref::keyword("JSON").to_matchable(), + Ref::keyword("YAML").to_matchable(), ]) .to_matchable(), - Ref::keyword("ROW").to_matchable(), - Ref::keyword("LEVEL").to_matchable(), - Ref::keyword("SECURITY").to_matchable(), ]) .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SecurityLabelStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SecurityLabelStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("SECURITY").to_matchable(), + Ref::keyword("LABEL").to_matchable(), Sequence::new(vec![ - Ref::keyword("CLUSTER").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("FOR").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("WITHOUT").to_matchable(), - one_of(vec![ - Ref::keyword("CLUSTER").to_matchable(), - Ref::keyword("OIDS").to_matchable(), + Ref::keyword("ON").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("TABLESPACE").to_matchable(), - Ref::new("TablespaceReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - one_of(vec![ - Ref::keyword("LOGGED").to_matchable(), - Ref::keyword("UNLOGGED").to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("RelationOptionsSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RESET").to_matchable(), - Ref::new("RelationOptionsSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").optional().to_matchable(), - Ref::keyword("INHERIT").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OF").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("OF").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OWNER").to_matchable(), - Ref::keyword("TO").to_matchable(), - one_of(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AGGREGATE").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Bracketed::new(vec![ + Ref::new("FunctionParameterListGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("REPLICA").to_matchable(), - Ref::keyword("IDENTITY").to_matchable(), - one_of(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Ref::keyword("INDEX").to_matchable(), - Ref::new("IndexReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DOMAIN").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EVENT").to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOREIGN").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + optionally_bracketed(vec![ + Ref::new("FunctionParameterGrammar") + .optional() + .to_matchable(), ]) .to_matchable(), - Ref::keyword("FULL").to_matchable(), - Ref::keyword("NOTHING").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LARGE").to_matchable(), + Ref::keyword("OBJECT").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PROCEDURAL").optional().to_matchable(), + Ref::keyword("LANGUAGE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PROCEDURE").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + optionally_bracketed(vec![ + Ref::new("FunctionParameterGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PUBLICATION").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROLE").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROUTINE").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + optionally_bracketed(vec![ + Ref::new("FunctionParameterGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SEQUENCE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SUBSCRIPTION").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("VIEW").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Ref::keyword("IS").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) @@ -3443,59 +3340,22 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "VersionIdentifierSegment".into(), - NodeMatcher::new(SyntaxKind::VersionIdentifier, |_| { - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "CreateExtensionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateExtensionStatement, |_| { + "CreateSchemaStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateSchemaStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), - Ref::keyword("EXTENSION").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("ExtensionReferenceSegment").to_matchable(), - Ref::keyword("WITH").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("SCHEMA").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("SchemaReferenceSegment").optional().to_matchable(), + Ref::keyword("AUTHORIZATION").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), Ref::new("SchemaReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("VERSION").to_matchable(), - Ref::new("VersionIdentifierSegment").to_matchable(), - ]) - .config(|this| this.optional()) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::new("VersionIdentifierSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "DropExtensionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropExtensionStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("EXTENSION").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ExtensionReferenceSegment").to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -3503,182 +3363,237 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "PublicationReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::PublicationReference, |_| { - Ref::new("SingleIdentifierGrammar").to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "PublicationTableSegment".into(), - NodeMatcher::new(SyntaxKind::PublicationTable, |_| { + "CreateTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTableStatement, |_dialect| { Sequence::new(vec![ - Ref::new("ExtendedTableReferenceGrammar").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WHERE").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + Ref::keyword("CREATE").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("GLOBAL").to_matchable(), + Ref::keyword("LOCAL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + ]) + .to_matchable(), + Ref::keyword("UNLOGGED").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "PublicationObjectsSegment".into(), - NodeMatcher::new(SyntaxKind::PublicationObjects, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("TABLE").to_matchable(), - Delimited::new(vec![Ref::new("PublicationTableSegment").to_matchable()]) - .config(|this| { - this.terminators = vec![ - Sequence::new(vec![ - Ref::new("CommaSegment").to_matchable(), - one_of(vec![ - Ref::keyword("TABLE").to_matchable(), - Ref::keyword("TABLES").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("ColumnDefinitionSegment").to_matchable(), + Ref::new("TableConstraintSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("LikeOptionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]; - }) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TABLES").to_matchable(), - Ref::keyword("IN").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Ref::new("SchemaReferenceSegment").to_matchable(), - Ref::keyword("CURRENT_SCHEMA").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), - ]) - .config(|this| { - this.terminators = vec![ - Sequence::new(vec![ - Ref::new("CommaSegment").to_matchable(), - one_of(vec![ - Ref::keyword("TABLE").to_matchable(), - Ref::keyword("TABLES").to_matchable(), + Sequence::new(vec![ + Ref::keyword("INHERITS").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("TableReferenceSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]; - }) + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "CreatePublicationStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreatePublicationStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("PUBLICATION").to_matchable(), - Ref::new("PublicationReferenceSegment").to_matchable(), - one_of(vec![ Sequence::new(vec![ - Ref::keyword("FOR").to_matchable(), - Ref::keyword("ALL").to_matchable(), - Ref::keyword("TABLES").to_matchable(), + Ref::keyword("OF").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("OPTIONS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("ColumnConstraintSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("TableConstraintSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("FOR").to_matchable(), - Delimited::new(vec![ - Ref::new("PublicationObjectsSegment").to_matchable(), + Ref::keyword("PARTITION").to_matchable(), + Ref::keyword("OF").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("OPTIONS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("ColumnConstraintSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("TableConstraintSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("FOR").to_matchable(), + Ref::keyword("VALUES").to_matchable(), + Ref::new("PartitionBoundSpecSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::new("DefinitionParametersSegment").to_matchable(), - ]) - .config(|this| this.optional()) .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "AlterPublicationStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterPublicationStatement, |_| { - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("PUBLICATION").to_matchable(), - Ref::new("PublicationReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("DefinitionParametersSegment").to_matchable(), - ]) - .to_matchable(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Delimited::new(vec![ - Ref::new("PublicationObjectsSegment").to_matchable(), + Ref::keyword("PARTITION").to_matchable(), + Ref::keyword("BY").to_matchable(), + one_of(vec![ + Ref::keyword("RANGE").to_matchable(), + Ref::keyword("LIST").to_matchable(), + Ref::keyword("HASH").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Delimited::new(vec![ - Ref::new("PublicationObjectsSegment").to_matchable(), + Bracketed::new(vec![ + AnyNumberOf::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment") + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("ParameterNameSegment") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Delimited::new(vec![ - Ref::new("PublicationObjectsSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("USING").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("PublicationReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::new("RelationOptionsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITHOUT").to_matchable(), + Ref::keyword("OIDS").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("OWNER").to_matchable(), - Ref::keyword("TO").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("COMMIT").to_matchable(), one_of(vec![ - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("PRESERVE").to_matchable(), + Ref::keyword("ROWS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("ROWS").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("DROP").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("TablespaceReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -3687,55 +3602,119 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - postgres.add([ - ( - "DropPublicationStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropPublicationStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("PUBLICATION").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Delimited::new(vec![Ref::new("PublicationReferenceSegment").to_matchable()]) - .to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), ( - "CreateMaterializedViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateMaterializedViewStatement, |_| { + "CreateTableAsStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTableAsStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("GLOBAL").to_matchable(), + Ref::keyword("LOCAL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("TemporaryGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("UNLOGGED").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("TABLE").to_matchable(), Ref::new("IfNotExistsGrammar").optional().to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() + AnyNumberOf::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("NakedIdentifierSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITHOUT").to_matchable(), + Ref::keyword("OIDS").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("COMMIT").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("PRESERVE").to_matchable(), + Ref::keyword("ROWS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("ROWS").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("DROP").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("TablespaceReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::new("RelationOptionsSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TABLESPACE").to_matchable(), - Ref::new("TablespaceReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Ref::keyword("AS").to_matchable(), one_of(vec![ @@ -3768,31 +3747,46 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AlterMaterializedViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterMaterializedViewStatement, |_| { + "AlterTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTableStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ALTER").to_matchable(), - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), + Ref::keyword("TABLE").to_matchable(), one_of(vec![ Sequence::new(vec![ Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::keyword("ONLY").optional().to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("StarSegment").optional().to_matchable(), one_of(vec![ Delimited::new(vec![ - Ref::new("AlterMaterializedViewActionSegment").to_matchable(), + Ref::new("AlterTableActionSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ Ref::keyword("RENAME").to_matchable(), - Sequence::new(vec![Ref::keyword("COLUMN").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), Ref::new("ColumnReferenceSegment").to_matchable(), Ref::keyword("TO").to_matchable(), Ref::new("ColumnReferenceSegment").to_matchable(), ]) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ Sequence::new(vec![ Ref::keyword("RENAME").to_matchable(), Ref::keyword("TO").to_matchable(), @@ -3805,19 +3799,34 @@ pub fn raw_dialect() -> Dialect { Ref::new("SchemaReferenceSegment").to_matchable(), ]) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ATTACH").to_matchable(), + Ref::keyword("PARTITION").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("FOR").to_matchable(), + Ref::keyword("VALUES").to_matchable(), + Ref::new("PartitionBoundSpecSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DETACH").to_matchable(), + Ref::keyword("PARTITION").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("CONCURRENTLY").optional().to_matchable(), + Ref::keyword("FINALIZE").optional().to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::new("TableReferenceSegment").to_matchable(), - Ref::keyword("NO").optional().to_matchable(), - Ref::keyword("DEPENDS").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("EXTENSION").to_matchable(), - Ref::new("ExtensionReferenceSegment").to_matchable(), - ]) - .to_matchable(), Sequence::new(vec![ Ref::keyword("ALL").to_matchable(), Ref::keyword("IN").to_matchable(), @@ -3831,14 +3840,14 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Ref::keyword("SET").to_matchable(), Ref::keyword("TABLESPACE").to_matchable(), Ref::new("TablespaceReferenceSegment").to_matchable(), - Sequence::new(vec![Ref::keyword("NOWAIT").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("NOWAIT").optional().to_matchable(), ]) .to_matchable(), ]) @@ -3850,30 +3859,79 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AlterMaterializedViewActionSegment".into(), - NodeMatcher::new(SyntaxKind::AlterMaterializedViewActionSegment, |_| { + "AlterTableActionSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTableActionSegment, |_dialect| { one_of(vec![ + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![Ref::new("ColumnConstraintSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable(), Sequence::new(vec![ Ref::keyword("ALTER").to_matchable(), Ref::keyword("COLUMN").optional().to_matchable(), Ref::new("ColumnReferenceSegment").to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("STATISTICS").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("DATA").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + one_of(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ Ref::keyword("SET").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + one_of(vec![ + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), ]) @@ -3881,504 +3939,260 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("RESET").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("STORAGE").to_matchable(), one_of(vec![ - Ref::keyword("PLAIN").to_matchable(), - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("EXTENDED").to_matchable(), - Ref::keyword("MAIN").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("DROP").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("COMPRESSION").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("EXPRESSION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CLUSTER").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("WITHOUT").to_matchable(), - Ref::keyword("CLUSTER").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("GENERATED").to_matchable(), + one_of(vec![ + Ref::keyword("ALWAYS").to_matchable(), Sequence::new(vec![ - Ref::new("EqualsSegment").to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), + Ref::keyword("BY").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RESET").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()]) + Ref::keyword("AS").to_matchable(), + Ref::keyword("IDENTITY").to_matchable(), + Bracketed::new(vec![ + AnyNumberOf::new(vec![ + Ref::new("AlterSequenceOptionsSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("GENERATED").to_matchable(), + one_of(vec![ + Ref::keyword("ALWAYS").to_matchable(), + Sequence::new(vec![ + Ref::keyword("BY").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("AlterSequenceOptionsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESTART").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("IDENTITY").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("STATISTICS").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("RelationOptionsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESET").to_matchable(), + Ref::new("RelationOptionsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("STORAGE").to_matchable(), + one_of(vec![ + Ref::keyword("PLAIN").to_matchable(), + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("EXTENDED").to_matchable(), + Ref::keyword("MAIN").to_matchable(), + ]) .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("OWNER").to_matchable(), - Ref::keyword("TO").to_matchable(), - one_of(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("ADD").to_matchable(), + Ref::new("TableConstraintSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "RefreshMaterializedViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::RefreshMaterializedViewStatement, |_| { - Sequence::new(vec![ - Ref::keyword("REFRESH").to_matchable(), - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::keyword("CONCURRENTLY").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("WithDataClauseSegment").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "DropMaterializedViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropMaterializedViewStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()]) - .to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "WithCheckOptionSegment".into(), - NodeMatcher::new(SyntaxKind::WithCheckOption, |_| { - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - one_of(vec![ - Ref::keyword("CASCADED").to_matchable(), - Ref::keyword("LOCAL").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::new("TableConstraintUsingIndexSegment").to_matchable(), ]) .to_matchable(), - Ref::keyword("CHECK").to_matchable(), - Ref::keyword("OPTION").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "AlterPolicyStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterPolicyStatement, |_| { - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TO").to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Ref::new("RoleReferenceSegment").to_matchable(), - Ref::keyword("PUBLIC").to_matchable(), - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), - ]) - .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + one_of(vec![ + Ref::keyword("DEFERRABLE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("DEFERRABLE").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("CHECK").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("DEFERRED").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("IMMEDIATE").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ]); - - postgres.add([ - ( - "CreateViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateViewStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::new("TemporaryGrammar").optional().to_matchable(), - Ref::keyword("RECURSIVE").optional().to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::new("RelationOptionsSegment").to_matchable(), + Ref::keyword("VALIDATE").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::keyword("AS").to_matchable(), - one_of(vec![ - optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) - .to_matchable(), - Ref::new("ValuesClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable(), - Ref::new("WithCheckOptionSegment").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "AlterViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterViewStatement, |_| { - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Ref::new("BareFunctionSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OWNER").to_matchable(), - Ref::keyword("TO").to_matchable(), - one_of(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("EqualsSegment").to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("DISABLE").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RESET").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + one_of(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("ALL").to_matchable(), + Ref::keyword("USER").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ]); - - postgres.add([ - ( - "DropViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropViewStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()]) - .to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "CreateDatabaseStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateDatabaseStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - Ref::keyword("WITH").optional().to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("OWNER").to_matchable(), - Ref::new("EqualsSegment").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TEMPLATE").to_matchable(), - Ref::new("EqualsSegment").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ENCODING").to_matchable(), - Ref::new("EqualsSegment").optional().to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - ]) - .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENABLE").to_matchable(), + one_of(vec![ + Ref::keyword("REPLICA").to_matchable(), + Ref::keyword("ALWAYS").to_matchable(), ]) .to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ one_of(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("DISABLE").to_matchable(), Sequence::new(vec![ - Ref::keyword("LOCALE").to_matchable(), - Ref::new("EqualsSegment").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("LC_COLLATE").to_matchable(), - Ref::new("EqualsSegment").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LC_CTYPE").to_matchable(), - Ref::new("EqualsSegment").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("REPLICA").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TABLESPACE").to_matchable(), - Ref::new("EqualsSegment").optional().to_matchable(), - one_of(vec![ - Ref::new("TablespaceReferenceSegment").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("RULE").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ALLOW_CONNECTIONS").to_matchable(), - Ref::new("EqualsSegment").optional().to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CONNECTION").to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::new("EqualsSegment").optional().to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("IS_TEMPLATE").to_matchable(), - Ref::new("EqualsSegment").optional().to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("RULE").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ]); - - postgres.add([( - "AlterDatabaseStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterDatabaseStatement, |_| { - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - one_of(vec![ Sequence::new(vec![ - Ref::keyword("WITH").optional().to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("ALLOW_CONNECTIONS").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CONNECTION").to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), + one_of(vec![ + Ref::keyword("DISABLE").to_matchable(), + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("FORCE").to_matchable(), Sequence::new(vec![ - Ref::keyword("IS_TEMPLATE").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::keyword("NO").to_matchable(), + Ref::keyword("FORCE").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.min_times(1)) .to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("LEVEL").to_matchable(), + Ref::keyword("SECURITY").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("OWNER").to_matchable(), - Ref::keyword("TO").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("WITHOUT").to_matchable(), one_of(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("OIDS").to_matchable(), ]) .to_matchable(), ]) @@ -4391,128 +4205,67 @@ pub fn raw_dialect() -> Dialect { .to_matchable(), Sequence::new(vec![ Ref::keyword("SET").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("TO").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("CURRENT").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("LOGGED").to_matchable(), + Ref::keyword("UNLOGGED").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("RelationOptionsSegment").to_matchable(), + ]) + .to_matchable(), Sequence::new(vec![ Ref::keyword("RESET").to_matchable(), + Ref::new("RelationOptionsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").optional().to_matchable(), + Ref::keyword("INHERIT").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OF").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("OF").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), one_of(vec![ - Ref::keyword("ALL").to_matchable(), Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.replace_grammar( - "DropDatabaseStatementSegment", - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").optional().to_matchable(), - Bracketed::new(vec![Ref::keyword("FORCE").to_matchable()]).to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([ - ( - "VacuumStatementSegment".into(), - NodeMatcher::new(SyntaxKind::VacuumStatement, |_| { - Sequence::new(vec![ - Ref::keyword("VACUUM").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("FULL").optional().to_matchable(), - Ref::keyword("FREEZE").optional().to_matchable(), - Ref::keyword("VERBOSE").optional().to_matchable(), - one_of(vec![ - Ref::keyword("ANALYZE").to_matchable(), - Ref::keyword("ANALYSE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("FULL").to_matchable(), - Ref::keyword("FREEZE").to_matchable(), - Ref::keyword("VERBOSE").to_matchable(), - Ref::keyword("ANALYZE").to_matchable(), - Ref::keyword("ANALYSE").to_matchable(), - Ref::keyword("DISABLE_PAGE_SKIPPING").to_matchable(), - Ref::keyword("SKIP_LOCKED").to_matchable(), - Ref::keyword("INDEX_CLEANUP").to_matchable(), - Ref::keyword("PROCESS_TOAST").to_matchable(), - Ref::keyword("TRUNCATE").to_matchable(), - Ref::keyword("PARALLEL").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("OnKeywordAsIdentifierSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REPLICA").to_matchable(), + Ref::keyword("IDENTITY").to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Ref::keyword("INDEX").to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), ]) .to_matchable(), + Ref::keyword("FULL").to_matchable(), + Ref::keyword("NOTHING").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable() @@ -4521,213 +4274,261 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "LikeOptionSegment".into(), - NodeMatcher::new(SyntaxKind::LikeOptionSegment, |_| { - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("INCLUDING").to_matchable(), - Ref::keyword("EXCLUDING").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("COMMENTS").to_matchable(), - Ref::keyword("CONSTRAINTS").to_matchable(), - Ref::keyword("DEFAULTS").to_matchable(), - Ref::keyword("GENERATED").to_matchable(), - Ref::keyword("IDENTITY").to_matchable(), - Ref::keyword("INDEXES").to_matchable(), - Ref::keyword("STATISTICS").to_matchable(), - Ref::keyword("STORAGE").to_matchable(), - Ref::keyword("ALL").to_matchable(), - ]) - .to_matchable(), + "VersionIdentifierSegment".into(), + NodeMatcher::new(SyntaxKind::VersionIdentifier, |_dialect| { + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - postgres.replace_grammar( - "ColumnConstraintSegment", - Sequence::new(vec![ - Sequence::new(vec![ - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("NULL").to_matchable(), - ]) - .to_matchable(), + ( + "CreateExtensionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateExtensionStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("CHECK").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("EXTENSION").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ExtensionReferenceSegment").to_matchable(), + Ref::keyword("WITH").optional().to_matchable(), Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("INHERIT").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - one_of(vec![ - Ref::new("ShorthandCastSegment").to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Ref::new("BareFunctionSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("VERSION").to_matchable(), + Ref::new("VersionIdentifierSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::new("VersionIdentifierSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::keyword("CASCADE").optional().to_matchable(), ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropExtensionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropExtensionStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("GENERATED").to_matchable(), - Ref::keyword("ALWAYS").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("STORED").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("EXTENSION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ExtensionReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterExtensionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterExtensionStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("GENERATED").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("EXTENSION").to_matchable(), + Ref::new("ExtensionReferenceSegment").to_matchable(), one_of(vec![ - Ref::keyword("ALWAYS").to_matchable(), Sequence::new(vec![ - Ref::keyword("BY").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("UPDATE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TO").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::keyword("IDENTITY").to_matchable(), - Bracketed::new(vec![ - AnyNumberOf::new(vec![ - Ref::new("AlterSequenceOptionsSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + one_of(vec![ + Ref::new("SchemaReferenceSegment").to_matchable(), + Ref::keyword("CURRENT_SCHEMA").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNIQUE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NULLS").to_matchable(), - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("DISTINCT").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::new("DefinitionParametersSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Ref::keyword("INDEX").to_matchable(), - Ref::keyword("TABLESPACE").to_matchable(), - Ref::new("TablespaceReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("PRIMARY").to_matchable(), - Ref::keyword("KEY").to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::new("DefinitionParametersSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Ref::keyword("INDEX").to_matchable(), - Ref::keyword("TABLESPACE").to_matchable(), - Ref::new("TablespaceReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("ReferenceDefinitionGrammar").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("DEFERRABLE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("DEFERRABLE").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("DEFERRED").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("IMMEDIATE").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([( - "PartitionBoundSpecSegment".into(), - NodeMatcher::new(SyntaxKind::PartitionBoundSpec, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("IN").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ + Sequence::new(vec![ one_of(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("MINVALUE").to_matchable(), - Ref::keyword("MAXVALUE").to_matchable(), + Ref::keyword("ADD").to_matchable(), + Ref::keyword("DROP").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("TO").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ one_of(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("MINVALUE").to_matchable(), - Ref::keyword("MAXVALUE").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("METHOD").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("COLLATION").to_matchable(), + Ref::keyword("CONVERSION").to_matchable(), + Ref::keyword("DOMAIN").to_matchable(), + Sequence::new(vec![ + Ref::keyword("EVENT").to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOREIGN").to_matchable(), + Ref::keyword("DATA").to_matchable(), + Ref::keyword("WRAPPER").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOREIGN").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PROCEDURAL").optional().to_matchable(), + Ref::keyword("LANGUAGE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::keyword("SERVER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TEXT").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + one_of(vec![ + Ref::keyword("CONFIGURATION").to_matchable(), + Ref::keyword("DICTIONARY").to_matchable(), + Ref::keyword("PARSER").to_matchable(), + Ref::keyword("TEMPLATE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TYPE").to_matchable(), + ]) + .to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AGGREGATE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![Anything::new().to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CAST").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("FUNCTION").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::keyword("ROUTINE").to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OPERATOR").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("CLASS").to_matchable(), + Ref::keyword("FAMILY").to_matchable(), + ]) + .to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("USING").to_matchable(), + Ref::new("IndexAccessMethodSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TRANSFORM").to_matchable(), + Ref::keyword("FOR").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -4735,249 +4536,398 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateForeignDataWrapperStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateForeignDataWrapper, |_dialect| { Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Bracketed::new(vec![ - Sequence::new(vec![ - Ref::keyword("MODULUS").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("CommaSegment").to_matchable(), - Ref::keyword("REMAINDER").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::new("ForeignDataWrapperGrammar").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::keyword("HANDLER").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + MetaSegment::dedent().to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::keyword("VALIDATOR").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.add([( - "TableConstraintSegment".into(), - NodeMatcher::new(SyntaxKind::TableConstraint, |_| { - Sequence::new(vec![ + .into(), + ), + ( + "SubscriptionReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::SubscriptionReference, |_dialect| { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "PublicationReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::PublicationReference, |_dialect| { + Ref::new("SingleIdentifierGrammar").to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "PublicationTableSegment".into(), + NodeMatcher::new(SyntaxKind::PublicationTable, |_dialect| { Sequence::new(vec![ - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ + Ref::new("ExtendedTableReferenceGrammar").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), Sequence::new(vec![ - Ref::keyword("CHECK").to_matchable(), + Ref::keyword("WHERE").to_matchable(), Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("INHERIT").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNIQUE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NULLS").to_matchable(), - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("DISTINCT").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - Ref::new("IndexParametersSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "PublicationObjectsSegment".into(), + NodeMatcher::new(SyntaxKind::PublicationObjects, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Delimited::new(vec![Ref::new("PublicationTableSegment").to_matchable()]) + .config(|this| { + this.terminators = vec![ + Sequence::new(vec![ + Ref::new("CommaSegment").to_matchable(), + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("TABLES").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]; + }) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::new("PrimaryKeyGrammar").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - Ref::new("IndexParametersSegment").optional().to_matchable(), + Ref::keyword("TABLES").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Ref::new("SchemaReferenceSegment").to_matchable(), + Ref::keyword("CURRENT_SCHEMA").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Sequence::new(vec![ + Ref::new("CommaSegment").to_matchable(), + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("TABLES").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]; + }) + .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("EXCLUDE").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreatePublicationStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreatePublicationStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("PUBLICATION").to_matchable(), + Ref::new("PublicationReferenceSegment").to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Ref::new("IndexAccessMethodSegment").to_matchable(), + Ref::keyword("FOR").to_matchable(), + Ref::keyword("ALL").to_matchable(), + Ref::keyword("TABLES").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Bracketed::new(vec![ + Sequence::new(vec![ + Ref::keyword("FOR").to_matchable(), Delimited::new(vec![ - Ref::new("ExclusionConstraintElementSegment").to_matchable(), + Ref::new("PublicationObjectsSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Ref::new("IndexParametersSegment").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("WHERE").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("FOREIGN").to_matchable(), - Ref::keyword("KEY").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - Ref::new("ReferenceDefinitionGrammar").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("DefinitionParametersSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .to_matchable(), - AnyNumberOf::new(vec![ + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterPublicationStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterPublicationStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("PUBLICATION").to_matchable(), + Ref::new("PublicationReferenceSegment").to_matchable(), one_of(vec![ - Ref::keyword("DEFERRABLE").to_matchable(), Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("DEFERRABLE").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("DefinitionParametersSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - one_of(vec![ Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("DEFERRED").to_matchable(), + Ref::keyword("ADD").to_matchable(), + Delimited::new(vec![ + Ref::new("PublicationObjectsSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("IMMEDIATE").to_matchable(), + Ref::keyword("SET").to_matchable(), + Delimited::new(vec![ + Ref::new("PublicationObjectsSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Delimited::new(vec![ + Ref::new("PublicationObjectsSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("PublicationReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("VALID").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("INHERIT").to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.add([( - "TableConstraintUsingIndexSegment".into(), - NodeMatcher::new(SyntaxKind::TableConstraint, |_| { - Sequence::new(vec![ - Sequence::new(vec![ - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + .into(), + ), + ( + "DropPublicationStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropPublicationStatement, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Ref::keyword("UNIQUE").to_matchable(), - Ref::new("PrimaryKeyGrammar").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("USING").to_matchable(), - Ref::keyword("INDEX").to_matchable(), - Ref::new("IndexReferenceSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("DEFERRABLE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("DEFERRABLE").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("DEFERRED").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("IMMEDIATE").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("PUBLICATION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![Ref::new("PublicationReferenceSegment").to_matchable()]) + .to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.add([ + .into(), + ), ( - "IndexParametersSegment".into(), - NodeMatcher::new(SyntaxKind::IndexParameters, |_| { + "CreateMaterializedViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateMaterializedViewStatement, |_dialect| { Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), Sequence::new(vec![ - Ref::keyword("INCLUDE").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::keyword("USING").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ Ref::keyword("WITH").to_matchable(), - Ref::new("DefinitionParametersSegment").to_matchable(), + Ref::new("RelationOptionsSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Ref::keyword("INDEX").to_matchable(), Ref::keyword("TABLESPACE").to_matchable(), Ref::new("TablespaceReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "ReferentialActionSegment".into(), - NodeMatcher::new(SyntaxKind::ReferentialActionSegment, |_| { - one_of(vec![ - Ref::keyword("CASCADE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("NULL").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("AS").to_matchable(), + one_of(vec![ + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + optionally_bracketed(vec![ + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + optionally_bracketed(vec![ + Sequence::new(vec![ + Ref::keyword("EXECUTE").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Ref::keyword("RESTRICT").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("ACTION").to_matchable(), + Ref::new("WithDataClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterMaterializedViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterMaterializedViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Delimited::new(vec![ + Ref::new("AlterMaterializedViewActionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Sequence::new(vec![Ref::keyword("COLUMN").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("NO").optional().to_matchable(), + Ref::keyword("DEPENDS").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("EXTENSION").to_matchable(), + Ref::new("ExtensionReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("TablespaceReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNED").to_matchable(), + Ref::keyword("BY").to_matchable(), + Delimited::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("TablespaceReferenceSegment").to_matchable(), + Sequence::new(vec![Ref::keyword("NOWAIT").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -4987,50 +4937,123 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "IndexElementOptionsSegment".into(), - NodeMatcher::new(SyntaxKind::IndexElementOptions, |_| { - Sequence::new(vec![ + "AlterMaterializedViewActionSegment".into(), + NodeMatcher::new(SyntaxKind::AlterMaterializedViewActionSegment, |_dialect| { + one_of(vec![ Sequence::new(vec![ - Ref::keyword("COLLATE").to_matchable(), - Ref::new("CollationReferenceSegment").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("STATISTICS").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESET").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("STORAGE").to_matchable(), + one_of(vec![ + Ref::keyword("PLAIN").to_matchable(), + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("EXTENDED").to_matchable(), + Ref::keyword("MAIN").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("COMPRESSION").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Sequence::new(vec![ - Ref::new("OperatorClassReferenceSegment") - .config(|this| { - this.exclude = Some( + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("WITHOUT").to_matchable(), + Ref::keyword("CLUSTER").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("NULLS").to_matchable(), - one_of(vec![ - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("LAST").to_matchable(), - ]) - .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ); - }) + ]) + .to_matchable(), + ]) .to_matchable(), - Ref::new("RelationOptionsSegment").optional().to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - one_of(vec![ - Ref::keyword("ASC").to_matchable(), - Ref::keyword("DESC").to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESET").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Sequence::new(vec![ - Ref::keyword("NULLS").to_matchable(), + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), one_of(vec![ - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("LAST").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable() @@ -5039,19 +5062,15 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "IndexElementSegment".into(), - NodeMatcher::new(SyntaxKind::IndexElement, |_| { + "RefreshMaterializedViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::RefreshMaterializedViewStatement, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("IndexElementOptionsSegment") - .optional() - .to_matchable(), + Ref::keyword("REFRESH").to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::keyword("CONCURRENTLY").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("WithDataClauseSegment").optional().to_matchable(), ]) .to_matchable() }) @@ -5059,12 +5078,16 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "ExclusionConstraintElementSegment".into(), - NodeMatcher::new(SyntaxKind::ExclusionConstraintElement, |_| { + "DropMaterializedViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropMaterializedViewStatement, |_dialect| { Sequence::new(vec![ - Ref::new("IndexElementSegment").to_matchable(), - Ref::keyword("WITH").to_matchable(), - Ref::new("ComparisonOperatorGrammar").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()]) + .to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -5072,50 +5095,17 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AlterDefaultPrivilegesStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesStatement, |_| { + "WithCheckOptionSegment".into(), + NodeMatcher::new(SyntaxKind::WithCheckOption, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - Ref::keyword("PRIVILEGES").to_matchable(), - Sequence::new(vec![ - Ref::keyword("FOR").to_matchable(), - one_of(vec![ - Ref::keyword("ROLE").to_matchable(), - Ref::keyword("USER").to_matchable(), - ]) - .to_matchable(), - Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) - .config(|this| { - this.terminators = vec![ - Ref::keyword("IN").to_matchable(), - Ref::keyword("GRANT").to_matchable(), - Ref::keyword("REVOKE").to_matchable(), - ]; - }) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("IN").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Delimited::new(vec![Ref::new("SchemaReferenceSegment").to_matchable()]) - .config(|this| { - this.terminators = vec![ - Ref::keyword("GRANT").to_matchable(), - Ref::keyword("REVOKE").to_matchable(), - ]; - }) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("WITH").to_matchable(), one_of(vec![ - Ref::new("AlterDefaultPrivilegesGrantSegment").to_matchable(), - Ref::new("AlterDefaultPrivilegesRevokeSegment").to_matchable(), + Ref::keyword("CASCADED").to_matchable(), + Ref::keyword("LOCAL").to_matchable(), ]) .to_matchable(), + Ref::keyword("CHECK").to_matchable(), + Ref::keyword("OPTION").to_matchable(), ]) .to_matchable() }) @@ -5123,29 +5113,57 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AlterDefaultPrivilegesObjectPrivilegesSegment".into(), - NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesObjectPrivilege, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("PRIVILEGES").optional().to_matchable(), - ]) - .to_matchable(), - Delimited::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("DELETE").to_matchable(), - Ref::keyword("EXECUTE").to_matchable(), - Ref::keyword("INSERT").to_matchable(), - Ref::keyword("REFERENCES").to_matchable(), - Ref::keyword("SELECT").to_matchable(), - Ref::keyword("TRIGGER").to_matchable(), - Ref::keyword("TRUNCATE").to_matchable(), - Ref::keyword("UPDATE").to_matchable(), - Ref::keyword("USAGE").to_matchable(), + "AlterPolicyStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterPolicyStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("TO").to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Ref::new("RoleReferenceSegment").to_matchable(), + Ref::keyword("PUBLIC").to_matchable(), + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("CHECK").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + this.min_times(1); + }) + .to_matchable(), ]) - .config(|this| { - this.terminators = vec![Ref::keyword("ON").to_matchable()]; - }) .to_matchable(), ]) .to_matchable() @@ -5154,15 +5172,34 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AlterDefaultPrivilegesSchemaObjectsSegment".into(), - NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesSchemaObject, |_| { - one_of(vec![ - Ref::keyword("TABLES").to_matchable(), - Ref::keyword("FUNCTIONS").to_matchable(), - Ref::keyword("ROUTINES").to_matchable(), - Ref::keyword("SEQUENCES").to_matchable(), - Ref::keyword("TYPES").to_matchable(), - Ref::keyword("SCHEMAS").to_matchable(), + "CreateViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + Ref::keyword("RECURSIVE").optional().to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::new("RelationOptionsSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("AS").to_matchable(), + one_of(vec![ + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("WithCheckOptionSegment").optional().to_matchable(), ]) .to_matchable() }) @@ -5170,15 +5207,107 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AlterDefaultPrivilegesToFromRolesSegment".into(), - NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesToFromRoles, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("GROUP").optional().to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), + "AlterViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("EqualsSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESET").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Ref::keyword("PUBLIC").to_matchable(), ]) .to_matchable() }) @@ -5186,28 +5315,15 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AlterDefaultPrivilegesGrantSegment".into(), - NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesGrant, |_| { + "DropViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropViewStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("GRANT").to_matchable(), - Ref::new("AlterDefaultPrivilegesObjectPrivilegesSegment").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::new("AlterDefaultPrivilegesSchemaObjectsSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Delimited::new(vec![ - Ref::new("AlterDefaultPrivilegesToFromRolesSegment").to_matchable(), - ]) - .config(|this| { - this.terminators = vec![Ref::keyword("WITH").to_matchable()]; - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("GRANT").to_matchable(), - Ref::keyword("OPTION").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()]) + .to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -5215,32 +5331,197 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AlterDefaultPrivilegesRevokeSegment".into(), - NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesRevoke, |_| { + "CreateDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateDatabaseStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("REVOKE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("GRANT").to_matchable(), - Ref::keyword("OPTION").to_matchable(), - Ref::keyword("FOR").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + Ref::keyword("WITH").optional().to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TEMPLATE").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENCODING").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("LOCALE").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("LC_COLLATE").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LC_CTYPE").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + one_of(vec![ + Ref::new("TablespaceReferenceSegment").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALLOW_CONNECTIONS").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONNECTION").to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IS_TEMPLATE").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::new("AlterDefaultPrivilegesObjectPrivilegesSegment").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::new("AlterDefaultPrivilegesSchemaObjectsSegment").to_matchable(), - Ref::keyword("FROM").to_matchable(), - Delimited::new(vec![ - Ref::new("AlterDefaultPrivilegesToFromRolesSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterDatabaseStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("WITH").optional().to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("ALLOW_CONNECTIONS").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONNECTION").to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IS_TEMPLATE").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("TablespaceReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TO").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("CURRENT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESET").to_matchable(), + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .config(|this| { - this.terminators = vec![ - Ref::keyword("RESTRICT").to_matchable(), - Ref::keyword("CASCADE").to_matchable(), - ]; + this.optional(); }) .to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -5248,23 +5529,21 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "DropOwnedStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropOwnedStatement, |_| { + "DropDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropDatabaseStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("DROP").to_matchable(), - Ref::keyword("OWNED").to_matchable(), - Ref::keyword("BY").to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").optional().to_matchable(), + Bracketed::new(vec![Ref::keyword("FORCE").to_matchable()]).to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -5272,29 +5551,24 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "ReassignOwnedStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ReassignOwnedStatement, |_| { + "CreateSubscriptionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateSubscription, |_dialect| { Sequence::new(vec![ - Ref::keyword("REASSIGN").to_matchable(), - Ref::keyword("OWNED").to_matchable(), - Ref::keyword("BY").to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - ]) + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("SUBSCRIPTION").to_matchable(), + Ref::new("SubscriptionReferenceSegment").to_matchable(), + Ref::keyword("CONNECTION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("PUBLICATION").to_matchable(), + Delimited::new(vec![Ref::new("PublicationReferenceSegment").to_matchable()]) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::new("DefinitionParametersSegment").to_matchable(), ]) - .to_matchable(), - Ref::keyword("TO").to_matchable(), - one_of(vec![ - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -5303,188 +5577,187 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "CommentOnStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CommentClause, |_| { + "AlterSubscriptionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterSubscription, |_dialect| { Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::keyword("ON").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("TABLE").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - ]) - .to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("SUBSCRIPTION").to_matchable(), + Ref::new("SubscriptionReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CONNECTION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("ADD").to_matchable(), + Ref::keyword("DROP").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CAST").to_matchable(), - Bracketed::new(vec![ - Sequence::new(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLUMN").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("DOMAIN").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("PUBLICATION").to_matchable(), + Delimited::new(vec![ + Ref::new("PublicationReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("DATABASE").to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("DefinitionParametersSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REFRESH").to_matchable(), + Ref::keyword("PUBLICATION").to_matchable(), Sequence::new(vec![ - Ref::keyword("EXTENSION").to_matchable(), - Ref::new("ExtensionReferenceSegment").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("DefinitionParametersSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FUNCTION").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("FunctionParameterListGrammar").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("DISABLE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("DefinitionParametersSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SKIP").to_matchable(), + Bracketed::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("RawEqualsSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INDEX").to_matchable(), - Ref::new("IndexReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("CURRENT_SESSION").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("SubscriptionReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropSubscriptionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropSubscription, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("SUBSCRIPTION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SubscriptionReferenceSegment").to_matchable(), + one_of(vec![ + Ref::keyword("CASCADE").to_matchable(), + Ref::keyword("RESTRICT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "VacuumStatementSegment".into(), + NodeMatcher::new(SyntaxKind::VacuumStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("VACUUM").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("FULL").optional().to_matchable(), + Ref::keyword("FREEZE").optional().to_matchable(), + Ref::keyword("VERBOSE").optional().to_matchable(), + one_of(vec![ + Ref::keyword("ANALYZE").to_matchable(), + Ref::keyword("ANALYSE").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("COLLATION").to_matchable(), - Ref::keyword("CONVERSION").to_matchable(), - Ref::keyword("DOMAIN").to_matchable(), - Ref::keyword("LANGUAGE").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::keyword("PUBLICATION").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Ref::keyword("RULE").to_matchable(), - Ref::keyword("SEQUENCE").to_matchable(), - Ref::keyword("SERVER").to_matchable(), - Ref::keyword("STATISTICS").to_matchable(), - Ref::keyword("SUBSCRIPTION").to_matchable(), - Ref::keyword("TABLESPACE").to_matchable(), - Ref::keyword("TRIGGER").to_matchable(), - Ref::keyword("TYPE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ACCESS").to_matchable(), - Ref::keyword("METHOD").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("EVENT").to_matchable(), - Ref::keyword("TRIGGER").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FOREIGN").to_matchable(), - Ref::keyword("DATA").to_matchable(), - Ref::keyword("WRAPPER").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FOREIGN").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TEXT").to_matchable(), - Ref::keyword("SEARCH").to_matchable(), - Ref::keyword("CONFIGURATION").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TEXT").to_matchable(), - Ref::keyword("SEARCH").to_matchable(), - Ref::keyword("DICTIONARY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TEXT").to_matchable(), - Ref::keyword("SEARCH").to_matchable(), - Ref::keyword("PARSER").to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("FULL").to_matchable(), + Ref::keyword("FREEZE").to_matchable(), + Ref::keyword("VERBOSE").to_matchable(), + Ref::keyword("ANALYZE").to_matchable(), + Ref::keyword("ANALYSE").to_matchable(), + Ref::keyword("DISABLE_PAGE_SKIPPING").to_matchable(), + Ref::keyword("SKIP_LOCKED").to_matchable(), + Ref::keyword("INDEX_CLEANUP").to_matchable(), + Ref::keyword("PROCESS_TOAST").to_matchable(), + Ref::keyword("TRUNCATE").to_matchable(), + Ref::keyword("PARALLEL").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TEXT").to_matchable(), - Ref::keyword("SEARCH").to_matchable(), - Ref::keyword("TEMPLATE").to_matchable(), + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("OnKeywordAsIdentifierSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("AGGREGATE").to_matchable(), - Ref::keyword("PROCEDURE").to_matchable(), - Ref::keyword("ROUTINE").to_matchable(), - ]) - .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Bracketed::new(vec![ - Sequence::new(vec![Anything::new().to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Delimited::new(vec![ Sequence::new(vec![ - Ref::keyword("IS").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::keyword("NULL").to_matchable(), - ]) - .to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -5492,901 +5765,3537 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - postgres.replace_grammar( - "CreateIndexStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("UNIQUE").optional().to_matchable(), - Ref::keyword("INDEX").to_matchable(), - Ref::keyword("CONCURRENTLY").optional().to_matchable(), - Sequence::new(vec![ - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("IndexReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("ONLY").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Ref::new("IndexAccessMethodSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("IndexElementSegment").to_matchable()]).to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INCLUDE").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("IndexElementSegment").to_matchable()]) - .to_matchable(), + ( + "LikeOptionSegment".into(), + NodeMatcher::new(SyntaxKind::LikeOptionSegment, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("INCLUDING").to_matchable(), + Ref::keyword("EXCLUDING").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("COMMENTS").to_matchable(), + Ref::keyword("CONSTRAINTS").to_matchable(), + Ref::keyword("DEFAULTS").to_matchable(), + Ref::keyword("GENERATED").to_matchable(), + Ref::keyword("IDENTITY").to_matchable(), + Ref::keyword("INDEXES").to_matchable(), + Ref::keyword("STATISTICS").to_matchable(), + Ref::keyword("STORAGE").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .to_matchable(), ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NULLS").to_matchable(), - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("DISTINCT").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::new("RelationOptionsSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TABLESPACE").to_matchable(), - Ref::new("TablespaceReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WHERE").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([( - "AlterIndexStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterIndexStatement, |_| { - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("INDEX").to_matchable(), - one_of(vec![ + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ColumnConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_dialect| { + Sequence::new(vec![ Sequence::new(vec![ - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("IndexReferenceSegment").to_matchable(), - one_of(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CHECK").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("IndexReferenceSegment").to_matchable(), + Ref::keyword("NO").to_matchable(), + Ref::keyword("INHERIT").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("TABLESPACE").to_matchable(), - Ref::new("TablespaceReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + one_of(vec![ + Ref::new("ShorthandCastSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("GENERATED").to_matchable(), + Ref::keyword("ALWAYS").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("STORED").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("GENERATED").to_matchable(), + one_of(vec![ + Ref::keyword("ALWAYS").to_matchable(), + Sequence::new(vec![ + Ref::keyword("BY").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::keyword("IDENTITY").to_matchable(), + Bracketed::new(vec![ + AnyNumberOf::new(vec![ + Ref::new("AlterSequenceOptionsSegment").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNIQUE").to_matchable(), Sequence::new(vec![ - Ref::keyword("ATTACH").to_matchable(), - Ref::keyword("PARTITION").to_matchable(), - Ref::new("IndexReferenceSegment").to_matchable(), + Ref::keyword("NULLS").to_matchable(), + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("DISTINCT").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("NO").optional().to_matchable(), - Ref::keyword("DEPENDS").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("EXTENSION").to_matchable(), - Ref::new("ExtensionReferenceSegment").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("DefinitionParametersSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("EqualsSegment").to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("USING").to_matchable(), + Ref::keyword("INDEX").to_matchable(), + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("TablespaceReferenceSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PRIMARY").to_matchable(), + Ref::keyword("KEY").to_matchable(), Sequence::new(vec![ - Ref::keyword("RESET").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("DefinitionParametersSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::keyword("SET").to_matchable(), - Ref::keyword("STATISTICS").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("USING").to_matchable(), + Ref::keyword("INDEX").to_matchable(), + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("TablespaceReferenceSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), + Ref::new("ReferenceDefinitionGrammar").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("IN").to_matchable(), - Ref::keyword("TABLESPACE").to_matchable(), - Ref::new("TablespaceReferenceSegment").to_matchable(), + one_of(vec![ + Ref::keyword("DEFERRABLE").to_matchable(), Sequence::new(vec![ - Ref::keyword("OWNED").to_matchable(), - Ref::keyword("BY").to_matchable(), - Delimited::new(vec![Ref::new("RoleReferenceSegment").to_matchable()]) - .to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("DEFERRABLE").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::keyword("SET").to_matchable(), - Ref::keyword("TABLESPACE").to_matchable(), - Ref::new("TablespaceReferenceSegment").to_matchable(), - Ref::keyword("NOWAIT").optional().to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.add([( - "ReindexStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ReindexStatementSegment, |_| { - Sequence::new(vec![ - Ref::keyword("REINDEX").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::keyword("CONCURRENTLY").to_matchable(), - Ref::new("BooleanLiteralGrammar").optional().to_matchable(), - ]) - .to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("TABLESPACE").to_matchable(), - Ref::new("TablespaceReferenceSegment").to_matchable(), + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("DEFERRED").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("VERBOSE").to_matchable(), - Ref::new("BooleanLiteralGrammar").optional().to_matchable(), + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("IMMEDIATE").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("INDEX").to_matchable(), - Ref::keyword("CONCURRENTLY").optional().to_matchable(), - Ref::new("IndexReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TABLE").to_matchable(), - Ref::keyword("CONCURRENTLY").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ForeignTableColumnConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_dialect| { + Sequence::new(vec![ Sequence::new(vec![ - Ref::keyword("SCHEMA").to_matchable(), - Ref::keyword("CONCURRENTLY").optional().to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("SYSTEM").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("CONCURRENTLY").optional().to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CHECK").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("INHERIT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + one_of(vec![ + Ref::new("ShorthandCastSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("GENERATED").to_matchable(), + Ref::keyword("ALWAYS").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("STORED").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.replace_grammar( - "DropIndexStatementSegment", - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("INDEX").to_matchable(), - Ref::keyword("CONCURRENTLY").optional().to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Delimited::new(vec![Ref::new("IndexReferenceSegment").to_matchable()]).to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable(), - ); - - postgres.replace_grammar( - "FrameClauseSegment", - { - let frame_extent = ansi::frame_extent(); - - let frame_exclusion = Sequence::new(vec![ - Ref::keyword("EXCLUDE").to_matchable(), + .into(), + ), + ( + "PartitionBoundSpecSegment".into(), + NodeMatcher::new(SyntaxKind::PartitionBoundSpec, |_dialect| { one_of(vec![ Sequence::new(vec![ - Ref::keyword("CURRENT").to_matchable(), - Ref::keyword("ROW").to_matchable(), + Ref::keyword("IN").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("TIES").to_matchable(), Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("OTHERS").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("MINVALUE").to_matchable(), + Ref::keyword("MAXVALUE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TO").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("MINVALUE").to_matchable(), + Ref::keyword("MAXVALUE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()); - - Sequence::new(vec![ - Ref::new("FrameClauseUnitGrammar").to_matchable(), - one_of(vec![ - frame_extent.clone().to_matchable(), Sequence::new(vec![ - Ref::keyword("BETWEEN").to_matchable(), - frame_extent.clone().to_matchable(), - Ref::keyword("AND").to_matchable(), - frame_extent.clone().to_matchable(), + Ref::keyword("WITH").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::keyword("MODULUS").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::keyword("REMAINDER").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - frame_exclusion.to_matchable(), - ]) - } - .to_matchable(), - ); - - postgres.replace_grammar( - "CreateSequenceOptionsSegment", - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INCREMENT").to_matchable(), - Ref::keyword("BY").optional().to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("MINVALUE").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("MINVALUE").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("MAXVALUE").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("MAXVALUE").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("START").to_matchable(), - Ref::keyword("WITH").optional().to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CACHE").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("CYCLE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("CYCLE").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OWNED").to_matchable(), - Ref::keyword("BY").to_matchable(), - one_of(vec![ - Ref::keyword("NONE").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([( - "CreateSequenceStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateSequenceStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("TemporaryGrammar").optional().to_matchable(), - Ref::keyword("SEQUENCE").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("SequenceReferenceSegment").to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("CreateSequenceOptionsSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.replace_grammar( - "AlterSequenceOptionsSegment", - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INCREMENT").to_matchable(), - Ref::keyword("BY").optional().to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("MINVALUE").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("MINVALUE").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("MAXVALUE").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").to_matchable(), - Ref::keyword("MAXVALUE").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SEQUENCE").to_matchable(), - Ref::keyword("NAME").to_matchable(), - Ref::new("SequenceReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("START").to_matchable(), - Ref::keyword("WITH").optional().to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RESTART").to_matchable(), - Ref::keyword("WITH").optional().to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CACHE").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").optional().to_matchable(), - Ref::keyword("CYCLE").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OWNED").to_matchable(), - Ref::keyword("BY").to_matchable(), - one_of(vec![ - Ref::keyword("NONE").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.replace_grammar( - "AlterSequenceStatementSegment", - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("SEQUENCE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SequenceReferenceSegment").to_matchable(), - one_of(vec![ - AnyNumberOf::new(vec![Ref::new("AlterSequenceOptionsSegment").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), + .into(), + ), + ( + "TableConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::TableConstraint, |_dialect| { Sequence::new(vec![ - Ref::keyword("OWNER").to_matchable(), - Ref::keyword("TO").to_matchable(), - one_of(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CHECK").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("INHERIT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNIQUE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULLS").to_matchable(), + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("DISTINCT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::new("IndexParametersSegment").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("PrimaryKeyGrammar").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::new("IndexParametersSegment").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXCLUDE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Ref::new("IndexAccessMethodSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ExclusionConstraintElementSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("IndexParametersSegment").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("WHERE").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOREIGN").to_matchable(), + Ref::keyword("KEY").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::new("ReferenceDefinitionGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + one_of(vec![ + Ref::keyword("DEFERRABLE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("DEFERRABLE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("DEFERRED").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("IMMEDIATE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("VALID").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("INHERIT").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("SequenceReferenceSegment").to_matchable(), - ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ForeignTableTableConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::TableConstraint, |_dialect| { Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CHECK").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("INHERIT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.replace_grammar( - "DropSequenceStatementSegment", - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("SEQUENCE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Delimited::new(vec![Ref::new("SequenceReferenceSegment").to_matchable()]) - .to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([( - "AnalyzeStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AnalyzeStatement, |_| { - { - let option = Sequence::new(vec![ + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableConstraintUsingIndexSegment".into(), + NodeMatcher::new(SyntaxKind::TableConstraint, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("UNIQUE").to_matchable(), + Ref::new("PrimaryKeyGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("USING").to_matchable(), + Ref::keyword("INDEX").to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + ]) + .to_matchable(), one_of(vec![ - Ref::keyword("VERBOSE").to_matchable(), - Ref::keyword("SKIP_LOCKED").to_matchable(), + Ref::keyword("DEFERRABLE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("DEFERRABLE").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("BooleanLiteralGrammar").optional().to_matchable(), - ]); - - let tables_and_columns = Sequence::new(vec![ - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("DEFERRED").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("IMMEDIATE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SetConstraintsStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SetConstraintStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("CONSTRAINTS").to_matchable(), + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - ]); - + one_of(vec![ + Ref::keyword("DEFERRED").to_matchable(), + Ref::keyword("IMMEDIATE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "IndexParametersSegment".into(), + NodeMatcher::new(SyntaxKind::IndexParameters, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("INCLUDE").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::new("DefinitionParametersSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Ref::keyword("INDEX").to_matchable(), + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("TablespaceReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "IndexElementOptionsSegment".into(), + NodeMatcher::new(SyntaxKind::IndexElementOptions, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::new("OperatorClassReferenceSegment") + .exclude(Sequence::new(vec![ + Ref::keyword("NULLS").to_matchable(), + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("LAST").to_matchable(), + ]) + .to_matchable(), + ])) + .to_matchable(), + Ref::new("RelationOptionsSegment").optional().to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Ref::keyword("ASC").to_matchable(), + Ref::keyword("DESC").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULLS").to_matchable(), + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("LAST").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "IndexElementSegment".into(), + NodeMatcher::new(SyntaxKind::IndexElement, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("IndexElementOptionsSegment") + .optional() + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ExclusionConstraintElementSegment".into(), + NodeMatcher::new(SyntaxKind::ExclusionConstraintElement, |_dialect| { + Sequence::new(vec![ + Ref::new("IndexElementSegment").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("ComparisonOperatorGrammar").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterDefaultPrivilegesStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("PRIVILEGES").to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOR").to_matchable(), + one_of(vec![ + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("USER").to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("IN").to_matchable(), + Ref::keyword("GRANT").to_matchable(), + Ref::keyword("REVOKE").to_matchable(), + ]; + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IN").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Delimited::new(vec![Ref::new("SchemaReferenceSegment").to_matchable()]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("GRANT").to_matchable(), + Ref::keyword("REVOKE").to_matchable(), + ]; + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Ref::new("AlterDefaultPrivilegesGrantSegment").to_matchable(), + Ref::new("AlterDefaultPrivilegesRevokeSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterDefaultPrivilegesObjectPrivilegesSegment".into(), + NodeMatcher::new( + SyntaxKind::AlterDefaultPrivilegesObjectPrivilege, + |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("PRIVILEGES").optional().to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("EXECUTE").to_matchable(), + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("REFERENCES").to_matchable(), + Ref::keyword("SELECT").to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::keyword("TRUNCATE").to_matchable(), + Ref::keyword("UPDATE").to_matchable(), + Ref::keyword("USAGE").to_matchable(), + ]) + .config(|this| { + this.terminators = vec![Ref::keyword("ON").to_matchable()]; + }) + .to_matchable(), + ]) + .to_matchable() + }, + ) + .to_matchable() + .into(), + ), + ( + "AlterDefaultPrivilegesSchemaObjectsSegment".into(), + NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesSchemaObject, |_dialect| { + one_of(vec![ + Ref::keyword("TABLES").to_matchable(), + Ref::keyword("FUNCTIONS").to_matchable(), + Ref::keyword("ROUTINES").to_matchable(), + Ref::keyword("SEQUENCES").to_matchable(), + Ref::keyword("TYPES").to_matchable(), + Ref::keyword("SCHEMAS").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterDefaultPrivilegesToFromRolesSegment".into(), + NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesToFromRoles, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("GROUP").optional().to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("PUBLIC").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterDefaultPrivilegesGrantSegment".into(), + NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesGrant, |_dialect| { + Sequence::new(vec![ + Ref::keyword("GRANT").to_matchable(), + Ref::new("AlterDefaultPrivilegesObjectPrivilegesSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("AlterDefaultPrivilegesSchemaObjectsSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Delimited::new(vec![ + Ref::new("AlterDefaultPrivilegesToFromRolesSegment").to_matchable(), + ]) + .config(|this| { + this.terminators = vec![Ref::keyword("WITH").to_matchable()]; + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("GRANT").to_matchable(), + Ref::keyword("OPTION").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterDefaultPrivilegesRevokeSegment".into(), + NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesRevoke, |_dialect| { + Sequence::new(vec![ + Ref::keyword("REVOKE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("GRANT").to_matchable(), + Ref::keyword("OPTION").to_matchable(), + Ref::keyword("FOR").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("AlterDefaultPrivilegesObjectPrivilegesSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("AlterDefaultPrivilegesSchemaObjectsSegment").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Delimited::new(vec![ + Ref::new("AlterDefaultPrivilegesToFromRolesSegment").to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("RESTRICT").to_matchable(), + Ref::keyword("CASCADE").to_matchable(), + ]; + }) + .to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropOwnedStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropOwnedStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("OWNED").to_matchable(), + Ref::keyword("BY").to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ReassignOwnedStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ReassignOwnedStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("REASSIGN").to_matchable(), + Ref::keyword("OWNED").to_matchable(), + Ref::keyword("BY").to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CommentOnStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CommentClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("ON").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CAST").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("DOMAIN").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTENSION").to_matchable(), + Ref::new("ExtensionReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("FunctionParameterListGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INDEX").to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("COLLATION").to_matchable(), + Ref::keyword("CONVERSION").to_matchable(), + Ref::keyword("DOMAIN").to_matchable(), + Ref::keyword("LANGUAGE").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::keyword("PUBLICATION").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("RULE").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::keyword("SERVER").to_matchable(), + Ref::keyword("STATISTICS").to_matchable(), + Ref::keyword("SUBSCRIPTION").to_matchable(), + Ref::keyword("TABLESPACE").to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("METHOD").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EVENT").to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOREIGN").to_matchable(), + Ref::keyword("DATA").to_matchable(), + Ref::keyword("WRAPPER").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOREIGN").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TEXT").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("CONFIGURATION").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TEXT").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("DICTIONARY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TEXT").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("PARSER").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TEXT").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("TEMPLATE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("AGGREGATE").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::keyword("ROUTINE").to_matchable(), + ]) + .to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![Anything::new().to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IS").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateIndexStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateIndexStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("UNIQUE").optional().to_matchable(), + Ref::keyword("INDEX").to_matchable(), + Ref::keyword("CONCURRENTLY").optional().to_matchable(), + Sequence::new(vec![ + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("ONLY").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Ref::new("IndexAccessMethodSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("IndexElementSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INCLUDE").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("IndexElementSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULLS").to_matchable(), + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("DISTINCT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::new("RelationOptionsSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("TablespaceReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WHERE").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterIndexStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterIndexStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("INDEX").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("TablespaceReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ATTACH").to_matchable(), + Ref::keyword("PARTITION").to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").optional().to_matchable(), + Ref::keyword("DEPENDS").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("EXTENSION").to_matchable(), + Ref::new("ExtensionReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("EqualsSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESET").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("STATISTICS").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("TablespaceReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNED").to_matchable(), + Ref::keyword("BY").to_matchable(), + Delimited::new(vec![ + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("TablespaceReferenceSegment").to_matchable(), + Ref::keyword("NOWAIT").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ReindexStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ReindexStatementSegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("REINDEX").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("CONCURRENTLY").to_matchable(), + Ref::new("BooleanLiteralGrammar").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("TablespaceReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("VERBOSE").to_matchable(), + Ref::new("BooleanLiteralGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("INDEX").to_matchable(), + Ref::keyword("CONCURRENTLY").optional().to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("CONCURRENTLY").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SCHEMA").to_matchable(), + Ref::keyword("CONCURRENTLY").optional().to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SYSTEM").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("CONCURRENTLY").optional().to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropIndexStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropIndexStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("INDEX").to_matchable(), + Ref::keyword("CONCURRENTLY").optional().to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![Ref::new("IndexReferenceSegment").to_matchable()]) + .to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FrameClauseSegment".into(), + NodeMatcher::new(SyntaxKind::FrameClause, |_dialect| { + Sequence::new(vec![ + Ref::new("FrameClauseUnitGrammar").to_matchable(), + one_of(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("IntervalExpressionSegment").to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BETWEEN").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("IntervalExpressionSegment").to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("AND").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("IntervalExpressionSegment").to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXCLUDE").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("TIES").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("OTHERS").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateSequenceOptionsSegment".into(), + NodeMatcher::new(SyntaxKind::CreateSequenceOptionsSegment, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INCREMENT").to_matchable(), + Ref::keyword("BY").optional().to_matchable(), + Ref::new("SignedSegmentGrammar").optional().to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("MINVALUE").to_matchable(), + Ref::new("SignedSegmentGrammar").optional().to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("MINVALUE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("MAXVALUE").to_matchable(), + Ref::new("SignedSegmentGrammar").optional().to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("MAXVALUE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("START").to_matchable(), + Ref::keyword("WITH").optional().to_matchable(), + Ref::new("SignedSegmentGrammar").optional().to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CACHE").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("CYCLE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("CYCLE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNED").to_matchable(), + Ref::keyword("BY").to_matchable(), + one_of(vec![ + Ref::keyword("NONE").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateSequenceStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateSequenceStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("SequenceReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("CreateSequenceOptionsSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterSequenceOptionsSegment".into(), + NodeMatcher::new(SyntaxKind::AlterSequenceOptionsSegment, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INCREMENT").to_matchable(), + Ref::keyword("BY").optional().to_matchable(), + Ref::new("SignedSegmentGrammar").optional().to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("MINVALUE").to_matchable(), + Ref::new("SignedSegmentGrammar").optional().to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("MINVALUE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("MAXVALUE").to_matchable(), + Ref::new("SignedSegmentGrammar").optional().to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("MAXVALUE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SEQUENCE").to_matchable(), + Ref::keyword("NAME").to_matchable(), + Ref::new("SequenceReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("START").to_matchable(), + Ref::keyword("WITH").optional().to_matchable(), + Ref::new("SignedSegmentGrammar").optional().to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESTART").to_matchable(), + Ref::keyword("WITH").optional().to_matchable(), + Ref::new("SignedSegmentGrammar").optional().to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CACHE").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").optional().to_matchable(), + Ref::keyword("CYCLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNED").to_matchable(), + Ref::keyword("BY").to_matchable(), + one_of(vec![ + Ref::keyword("NONE").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterSequenceStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterSequenceStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SequenceReferenceSegment").to_matchable(), + one_of(vec![ + AnyNumberOf::new(vec![ + Ref::new("AlterSequenceOptionsSegment") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("SequenceReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropSequenceStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropSequenceStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![Ref::new("SequenceReferenceSegment").to_matchable()]) + .to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StatisticsReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::StatisticsReference, |_dialect| { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "CreateStatisticsStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateStatisticsStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("STATISTICS").to_matchable(), + Sequence::new(vec![ + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("StatisticsReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::keyword("DEPENDENCIES").to_matchable(), + Ref::keyword("MCV").to_matchable(), + Ref::keyword("NDISTINCT").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("ON").to_matchable(), + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterStatisticsStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterStatisticsStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("STATISTICS").to_matchable(), + Ref::new("StatisticsReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + one_of(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("StatisticsReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STATISTICS").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropStatisticsStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropStatisticsStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("STATISTICS").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![Ref::new("StatisticsReferenceSegment").to_matchable()]) + .to_matchable(), + one_of(vec![ + Ref::keyword("CASCADE").to_matchable(), + Ref::keyword("RESTRICT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AnalyzeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AnalyzeStatement, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ANALYZE").to_matchable(), + Ref::keyword("ANALYSE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("VERBOSE").to_matchable(), + Ref::keyword("SKIP_LOCKED").to_matchable(), + ]) + .to_matchable(), + Ref::new("BooleanLiteralGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("VERBOSE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StatementSegment".into(), + NodeMatcher::new(SyntaxKind::Statement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("StatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("AlterDefaultPrivilegesStatementSegment").to_matchable(), + Ref::new("DropOwnedStatementSegment").to_matchable(), + Ref::new("ReassignOwnedStatementSegment").to_matchable(), + Ref::new("CommentOnStatementSegment").to_matchable(), + Ref::new("AnalyzeStatementSegment").to_matchable(), + Ref::new("CreateTableAsStatementSegment").to_matchable(), + Ref::new("AlterTriggerStatementSegment").to_matchable(), + Ref::new("SetStatementSegment").to_matchable(), + Ref::new("AlterPolicyStatementSegment").to_matchable(), + Ref::new("CreatePolicyStatementSegment").to_matchable(), + Ref::new("DropPolicyStatementSegment").to_matchable(), + Ref::new("CreateDomainStatementSegment").to_matchable(), + Ref::new("AlterDomainStatementSegment").to_matchable(), + Ref::new("DropDomainStatementSegment").to_matchable(), + Ref::new("CreateMaterializedViewStatementSegment").to_matchable(), + Ref::new("AlterMaterializedViewStatementSegment").to_matchable(), + Ref::new("DropMaterializedViewStatementSegment").to_matchable(), + Ref::new("RefreshMaterializedViewStatementSegment").to_matchable(), + Ref::new("AlterDatabaseStatementSegment").to_matchable(), + Ref::new("DropDatabaseStatementSegment").to_matchable(), + Ref::new("VacuumStatementSegment").to_matchable(), + Ref::new("AlterFunctionStatementSegment").to_matchable(), + Ref::new("CreateViewStatementSegment").to_matchable(), + Ref::new("AlterViewStatementSegment").to_matchable(), + Ref::new("ListenStatementSegment").to_matchable(), + Ref::new("NotifyStatementSegment").to_matchable(), + Ref::new("UnlistenStatementSegment").to_matchable(), + Ref::new("LoadStatementSegment").to_matchable(), + Ref::new("ResetStatementSegment").to_matchable(), + Ref::new("DiscardStatementSegment").to_matchable(), + Ref::new("AlterProcedureStatementSegment").to_matchable(), + Ref::new("CreateProcedureStatementSegment").to_matchable(), + Ref::new("DropProcedureStatementSegment").to_matchable(), + Ref::new("CopyStatementSegment").to_matchable(), + Ref::new("DoStatementSegment").to_matchable(), + Ref::new("AlterIndexStatementSegment").to_matchable(), + Ref::new("ReindexStatementSegment").to_matchable(), + Ref::new("AlterRoleStatementSegment").to_matchable(), + Ref::new("CreateExtensionStatementSegment").to_matchable(), + Ref::new("DropExtensionStatementSegment").to_matchable(), + Ref::new("AlterExtensionStatementSegment").to_matchable(), + Ref::new("CreateSubscriptionStatementSegment").to_matchable(), + Ref::new("AlterSubscriptionStatementSegment").to_matchable(), + Ref::new("DropSubscriptionStatementSegment").to_matchable(), + Ref::new("CreatePublicationStatementSegment").to_matchable(), + Ref::new("AlterPublicationStatementSegment").to_matchable(), + Ref::new("DropPublicationStatementSegment").to_matchable(), + Ref::new("CreateTypeStatementSegment").to_matchable(), + Ref::new("AlterTypeStatementSegment").to_matchable(), + Ref::new("CreateTextSearchConfigurationStatementSegment").to_matchable(), + Ref::new("AlterTextSearchConfigurationStatementSegment").to_matchable(), + Ref::new("DropTextSearchConfigurationStatementSegment").to_matchable(), + Ref::new("AlterSchemaStatementSegment").to_matchable(), + Ref::new("LockTableStatementSegment").to_matchable(), + Ref::new("ClusterStatementSegment").to_matchable(), + Ref::new("CreateCollationStatementSegment").to_matchable(), + Ref::new("DropCollationStatementSegment").to_matchable(), + Ref::new("CallStoredProcedureSegment").to_matchable(), + Ref::new("CreateServerStatementSegment").to_matchable(), + Ref::new("CreateUserMappingStatementSegment").to_matchable(), + Ref::new("ImportForeignSchemaStatementSegment").to_matchable(), + Ref::new("CreateForeignTableStatementSegment").to_matchable(), + Ref::new("DropAggregateStatementSegment").to_matchable(), + Ref::new("CreateAggregateStatementSegment").to_matchable(), + Ref::new("AlterAggregateStatementSegment").to_matchable(), + Ref::new("CreateStatisticsStatementSegment").to_matchable(), + Ref::new("AlterStatisticsStatementSegment").to_matchable(), + Ref::new("DropStatisticsStatementSegment").to_matchable(), + Ref::new("ShowStatementSegment").to_matchable(), + Ref::new("SetConstraintsStatementSegment").to_matchable(), + Ref::new("CreateForeignDataWrapperStatementSegment").to_matchable(), + Ref::new("MetaCommandQueryBufferStatement").to_matchable(), + Ref::new("DropForeignTableStatement").to_matchable(), + Ref::new("CreateOperatorStatementSegment").to_matchable(), + Ref::new("AlterForeignTableStatementSegment").to_matchable(), + Ref::new("SecurityLabelStatementSegment").to_matchable(), + Ref::new("PrepareStatementSegment").to_matchable(), + Ref::new("ExecuteStatementSegment").to_matchable(), + Ref::new("DeallocateStatementSegment").to_matchable(), + Ref::new("SetSessionAuthorizationStatementSegment").to_matchable(), + Ref::new("ResetSessionAuthorizationStatementSegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "CreateTriggerStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTriggerStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("CONSTRAINT").optional().to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::new("TriggerReferenceSegment").to_matchable(), + one_of(vec![ + Ref::keyword("BEFORE").to_matchable(), + Ref::keyword("AFTER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("INSTEAD").to_matchable(), + Ref::keyword("OF").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("TRUNCATE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("UPDATE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("OF").to_matchable(), + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("OR").to_matchable(), + Ref::keyword("ON").to_matchable(), + ]; + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.delimiter(Ref::keyword("OR")); + }) + .to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("DEFERRABLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFERRABLE").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("IMMEDIATE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("DEFERRED").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REFERENCING").to_matchable(), + one_of(vec![ + Ref::keyword("OLD").to_matchable(), + Ref::keyword("NEW").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("OLD").to_matchable(), + Ref::keyword("NEW").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOR").to_matchable(), + Ref::keyword("EACH").optional().to_matchable(), + one_of(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("STATEMENT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WHEN").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXECUTE").to_matchable(), + one_of(vec![ + Ref::keyword("FUNCTION").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + ]) + .to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterTriggerStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTrigger, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::new("TriggerReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TriggerReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").optional().to_matchable(), + Ref::keyword("DEPENDS").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("EXTENSION").to_matchable(), + Ref::new("ExtensionReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropTriggerStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropTriggerStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TriggerReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AliasExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::AliasExpression, |_dialect| { + Sequence::new(vec![ + MetaSegment::indent().to_matchable(), + Ref::new("AsAliasOperatorSegment").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Bracketed::new(vec![ + Ref::new("SingleIdentifierListSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar") + .optional() + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AsAliasExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::AliasExpression, |_dialect| { + Sequence::new(vec![ + MetaSegment::indent().to_matchable(), + Ref::new("AsAliasOperatorSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "OperationClassReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::OperationClassReference, |_dialect| { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "ConflictActionSegment".into(), + NodeMatcher::new(SyntaxKind::ConflictAction, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DO").to_matchable(), + one_of(vec![ + Ref::keyword("NOTHING").to_matchable(), + Sequence::new(vec![ + Ref::keyword("UPDATE").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::keyword("SET").to_matchable(), + MetaSegment::implicit_indent().to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::keyword("ROW").optional().to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + Sequence::new(vec![ + Ref::keyword("WHERE").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ConflictTargetSegment".into(), + NodeMatcher::new(SyntaxKind::ConflictTarget, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("OperationClassReferenceSegment") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WHERE").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "InsertStatementSegment".into(), + NodeMatcher::new(SyntaxKind::InsertStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("AsAliasExpressionSegment") + .optional() + .to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OVERRIDING").to_matchable(), + one_of(vec![ + Ref::keyword("SYSTEM").to_matchable(), + Ref::keyword("USER").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("VALUE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("VALUES").to_matchable(), + ]) + .to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("CONFLICT").to_matchable(), + Ref::new("ConflictTargetSegment").optional().to_matchable(), + Ref::new("ConflictActionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURNING").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::new("StarSegment").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("AsAliasExpressionSegment") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropTypeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropTypeStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()]).to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SetStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SetStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Ref::keyword("SESSION").to_matchable(), + Ref::keyword("LOCAL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + one_of(vec![ + Ref::keyword("TO").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Delimited::new(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), + Ref::new("OnKeywordAsIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TIME").to_matchable(), + Ref::keyword("ZONE").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("LOCAL").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROLE").to_matchable(), + one_of(vec![ + Ref::keyword("NONE").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreatePolicyStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreatePolicyStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Ref::keyword("PERMISSIVE").to_matchable(), + Ref::keyword("RESTRICTIVE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOR").to_matchable(), + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("SELECT").to_matchable(), + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("UPDATE").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TO").to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("PUBLIC").to_matchable(), + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("CHECK").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CallStoredProcedureSegment".into(), + NodeMatcher::new(SyntaxKind::CallStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CALL").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateDomainStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateDomainStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("DOMAIN").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Sequence::new(vec![Ref::keyword("AS").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CHECK").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterDomainStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterDomainStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("DOMAIN").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("DROP").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CHECK").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("VALID").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ + Ref::keyword("RESTRICT").to_matchable(), + Ref::keyword("CASCADE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("VALIDATE").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropDomainStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropDomainStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("DOMAIN").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) + .to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropPolicyStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropPolicyStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "LoadStatementSegment".into(), + NodeMatcher::new(SyntaxKind::LoadStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("LOAD").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ResetStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ResetStatement, |_dialect| { Sequence::new(vec![ + Ref::keyword("RESET").to_matchable(), one_of(vec![ - Ref::keyword("ANALYZE").to_matchable(), - Ref::keyword("ANALYSE").to_matchable(), + Ref::keyword("ALL").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), ]) .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DiscardStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DiscardStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DISCARD").to_matchable(), one_of(vec![ - Bracketed::new(vec![ - Delimited::new(vec![option.to_matchable()]).to_matchable(), - ]) - .to_matchable(), - Ref::keyword("VERBOSE").to_matchable(), + Ref::keyword("ALL").to_matchable(), + Ref::keyword("PLANS").to_matchable(), + Ref::keyword("SEQUENCES").to_matchable(), + Ref::keyword("TEMPORARY").to_matchable(), + Ref::keyword("TEMP").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Delimited::new(vec![tables_and_columns.to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), ]) - } + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.replace_grammar("StatementSegment", statement_segment()); - - postgres.replace_grammar( - "CreateTriggerStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("CONSTRAINT").optional().to_matchable(), - Ref::keyword("TRIGGER").to_matchable(), - Ref::new("TriggerReferenceSegment").to_matchable(), - one_of(vec![ - Ref::keyword("BEFORE").to_matchable(), - Ref::keyword("AFTER").to_matchable(), + .into(), + ), + ( + "ListenStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ListenStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("INSTEAD").to_matchable(), - Ref::keyword("OF").to_matchable(), + Ref::keyword("LISTEN").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - Delimited::new(vec![ - Ref::keyword("INSERT").to_matchable(), - Ref::keyword("DELETE").to_matchable(), - Ref::keyword("TRUNCATE").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "NotifyStatementSegment".into(), + NodeMatcher::new(SyntaxKind::NotifyStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("UPDATE").to_matchable(), + Ref::keyword("NOTIFY").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), Sequence::new(vec![ - Ref::keyword("OF").to_matchable(), - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .config(|this| { - this.terminators = vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("ON").to_matchable(), - ]; - this.optional(); - }) - .to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .to_matchable(), - ]) - .config(|this| this.delimiter(Ref::keyword("OR"))) - .to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - AnyNumberOf::new(vec![ + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UnlistenStatementSegment".into(), + NodeMatcher::new(SyntaxKind::UnlistenStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("DEFERRABLE").to_matchable(), + Ref::keyword("UNLISTEN").to_matchable(), + one_of(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("StarSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DEFERRABLE").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TruncateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::TruncateStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("TRUNCATE").to_matchable(), + Ref::keyword("TABLE").optional().to_matchable(), + Delimited::new(vec![ one_of(vec![ Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("IMMEDIATE").to_matchable(), + Ref::keyword("ONLY").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("DEFERRED").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("StarSegment").optional().to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("REFERENCING").to_matchable(), - one_of(vec![ - Ref::keyword("OLD").to_matchable(), - Ref::keyword("NEW").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), Sequence::new(vec![ one_of(vec![ - Ref::keyword("OLD").to_matchable(), - Ref::keyword("NEW").to_matchable(), + Ref::keyword("RESTART").to_matchable(), + Ref::keyword("CONTINUE").to_matchable(), ]) .to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FOR").to_matchable(), - Ref::keyword("EACH").optional().to_matchable(), - one_of(vec![ - Ref::keyword("ROW").to_matchable(), - Ref::keyword("STATEMENT").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WHEN").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("EXECUTE").to_matchable(), - one_of(vec![ - Ref::keyword("FUNCTION").to_matchable(), - Ref::keyword("PROCEDURE").to_matchable(), - ]) - .to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([( - "AlterTriggerStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterTrigger, |_| { - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("TRIGGER").to_matchable(), - Ref::new("TriggerReferenceSegment").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("TriggerReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NO").optional().to_matchable(), - Ref::keyword("DEPENDS").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("EXTENSION").to_matchable(), - Ref::new("ExtensionReferenceSegment").to_matchable(), + Ref::keyword("IDENTITY").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.replace_grammar( - "DropTriggerStatementSegment", - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("TRIGGER").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("TriggerReferenceSegment").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable(), - ); - - postgres.replace_grammar( - "AliasExpressionSegment", - Sequence::new(vec![ - Ref::keyword("AS").optional().to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Bracketed::new(vec![Ref::new("SingleIdentifierListSegment").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), + .into(), + ), + ( + "CopyStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CopyStatement, |_dialect| { Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar") - .optional() - .to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ + Ref::keyword("COPY").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Sequence::new(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + one_of(vec![ + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("PROGRAM").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![Ref::keyword("STDIN").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").optional().to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("FORMAT").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FREEZE").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DELIMITER").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULL").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("HEADER").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("QUOTE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ESCAPE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FORCE_QUOTE").to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("StarSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FORCE_NOT_NULL").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FORCE_NULL").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENCODING").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("WHERE").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([( - "AsAliasExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::AliasExpression, |_| { - Sequence::new(vec![ - MetaSegment::indent().to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.add([( - "OperationClassReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::OperationClassReference, |postgres| { - postgres - .grammar("ObjectReferenceSegment") - .match_grammar(postgres) - .unwrap() - }) - .to_matchable() - .into(), - )]); - - postgres.add([ - ( - "ConflictActionSegment".into(), - NodeMatcher::new(SyntaxKind::ConflictAction, |_| { - Sequence::new(vec![ - Ref::keyword("DO").to_matchable(), - one_of(vec![ - Ref::keyword("NOTHING").to_matchable(), Sequence::new(vec![ - Ref::keyword("UPDATE").to_matchable(), - Ref::keyword("SET").to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Sequence::new(vec![ + Sequence::new(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - ]) + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![Ref::keyword("STDIN").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").optional().to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![Ref::keyword("BINARY").to_matchable()]) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DELIMITER").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CSV").to_matchable(), + one_of(vec![ + Ref::keyword("HEADER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("QUOTE").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ESCAPE").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FORCE").to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::keyword("ROW").optional().to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("PROGRAM").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![Ref::keyword("STDOUT").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").optional().to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("FORMAT").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FREEZE").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DELIMITER").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULL").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("HEADER").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("QUOTE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ESCAPE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FORCE_QUOTE").to_matchable(), one_of(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("StarSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FORCE_NOT_NULL").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FORCE_NULL").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENCODING").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![Ref::keyword("STDOUT").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").optional().to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![Ref::keyword("BINARY").to_matchable()]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DELIMITER").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) .to_matchable(), Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CSV").to_matchable(), + one_of(vec![ + Ref::keyword("HEADER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("QUOTE").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ESCAPE").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FORCE").to_matchable(), + Ref::keyword("QUOTE").to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("StarSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Ref::new("SelectableGrammar").to_matchable(), - ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + this.optional(); + }) .to_matchable(), ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WHERE").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), @@ -6399,49 +9308,93 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "ConflictTargetSegment".into(), - NodeMatcher::new(SyntaxKind::ConflictTarget, |_| { - one_of(vec![ - Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Bracketed::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLLATE").to_matchable(), - Ref::new("CollationReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("OperationClassReferenceSegment") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + "LanguageClauseSegment".into(), + NodeMatcher::new(SyntaxKind::LanguageClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("LANGUAGE").to_matchable(), + one_of(vec![ + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("SingleQuotedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DoStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DoStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DO").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("LanguageClauseSegment").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("WHERE").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("LanguageClauseSegment").optional().to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CTEDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::CommonTableExpression, |_dialect| { + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("CTEColumnList").optional().to_matchable(), + Ref::keyword("AS").to_matchable(), Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SEARCH").to_matchable(), + one_of(vec![ + Ref::keyword("BREADTH").to_matchable(), + Ref::keyword("DEPTH").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("BY").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CYCLE").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("USING").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -6449,139 +9402,158 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - postgres.replace_grammar( - "InsertStatementSegment", - Sequence::new(vec![ - Ref::keyword("INSERT").to_matchable(), - Ref::keyword("INTO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("AsAliasExpressionSegment") - .optional() - .to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OVERRIDING").to_matchable(), - one_of(vec![ - Ref::keyword("SYSTEM").to_matchable(), - Ref::keyword("USER").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("VALUE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ + ( + "ValuesClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ValuesClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), Ref::keyword("VALUES").to_matchable(), - ]) - .to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("CONFLICT").to_matchable(), - Ref::new("ConflictTargetSegment").optional().to_matchable(), - Ref::new("ConflictActionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RETURNING").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ - Ref::new("StarSegment").to_matchable(), Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::new("AsAliasExpressionSegment") - .optional() - .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) .to_matchable(), ]) .to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + Ref::new("OrderByClauseSegment").optional().to_matchable(), + Ref::new("LimitClauseSegment").optional().to_matchable(), ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.replace_grammar( - "DropTypeStatementSegment", - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("TYPE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()]).to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([ + .to_matchable() + }) + .to_matchable() + .into(), + ), ( - "SetStatementSegment".into(), - NodeMatcher::new(SyntaxKind::SetStatement, |_| { + "DeleteStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DeleteStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - one_of(vec![ - Ref::keyword("SESSION").to_matchable(), - Ref::keyword("LOCAL").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::keyword("ONLY").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("StarSegment").optional().to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("TableExpressionSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("JoinClauseSegment").optional().to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - one_of(vec![ - Ref::keyword("TO").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Delimited::new(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), - Ref::new("OnKeywordAsIdentifierSegment").to_matchable(), + Ref::keyword("WHERE").to_matchable(), + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("OF").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("WhereClauseSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURNING").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::new("StarSegment").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SetClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SetClause, |_dialect| { + Sequence::new(vec![ + one_of(vec![ Sequence::new(vec![ - Ref::keyword("TIME").to_matchable(), - Ref::keyword("ZONE").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ArrayAccessorSegment").optional().to_matchable(), + Ref::new("EqualsSegment").to_matchable(), one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::keyword("LOCAL").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), Ref::keyword("DEFAULT").to_matchable(), ]) .to_matchable(), + AnyNumberOf::new(vec![Ref::new("ShorthandCastSegment").to_matchable()]) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ROLE").to_matchable(), - one_of(vec![ - Ref::keyword("NONE").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("SelectableGrammar").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("ShorthandCastSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -6595,67 +9567,54 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "CreatePolicyStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreatePolicyStatement, |_| { + "UpdateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::UpdateStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("ON").to_matchable(), + Ref::keyword("UPDATE").to_matchable(), + Ref::keyword("ONLY").optional().to_matchable(), + MetaSegment::indent().to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - one_of(vec![ - Ref::keyword("PERMISSIVE").to_matchable(), - Ref::keyword("RESTRICTIVE").to_matchable(), - ]) + Ref::new("AliasExpressionSegment") + .exclude(Ref::keyword("SET")) + .optional() .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FOR").to_matchable(), - one_of(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("SELECT").to_matchable(), - Ref::keyword("INSERT").to_matchable(), - Ref::keyword("UPDATE").to_matchable(), - Ref::keyword("DELETE").to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::new("SetClauseListSegment").to_matchable(), + Ref::new("FromClauseSegment").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("WHERE").to_matchable(), + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("OF").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), + Ref::new("WhereClauseSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("TO").to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("PUBLIC").to_matchable(), - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), + Ref::keyword("RETURNING").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::new("StarSegment").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("CHECK").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -6664,11 +9623,38 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "CallStoredProcedureSegment".into(), - NodeMatcher::new(SyntaxKind::CallStatement, |_| { + "CreateTypeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTypeStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("CALL").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Ref::keyword("ENUM").to_matchable(), + Ref::keyword("RANGE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Anything::new().to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable() }) @@ -6676,168 +9662,290 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "CreateDomainStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateDomainStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("DOMAIN").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Sequence::new(vec![Ref::keyword("AS").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), + "CreateTextSearchConfigurationStatementSegment".into(), + NodeMatcher::new( + SyntaxKind::CreateTextSearchConfigurationStatement, + |_dialect| { Sequence::new(vec![ - Ref::keyword("COLLATE").to_matchable(), - Ref::new("CollationReferenceSegment").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("TEXT").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("CONFIGURATION").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("PARSER").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COPY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), + .to_matchable() + }, + ) + .to_matchable() + .into(), + ), + ( + "AlterTextSearchConfigurationStatementSegment".into(), + NodeMatcher::new( + SyntaxKind::AlterTextSearchConfigurationStatement, + |_dialect| { Sequence::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("TEXT").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("CONFIGURATION").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("CONSTRAINT").to_matchable(), + Ref::keyword("ADD").to_matchable(), + Ref::keyword("MAPPING").to_matchable(), + Ref::keyword("FOR").to_matchable(), + Delimited::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("WITH").to_matchable(), + Delimited::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("MAPPING").to_matchable(), + Ref::keyword("FOR").to_matchable(), + Delimited::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("WITH").to_matchable(), + Delimited::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("MAPPING").to_matchable(), + Ref::keyword("REPLACE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("WITH").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("NULL").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("MAPPING").to_matchable(), + Ref::keyword("FOR").to_matchable(), + Delimited::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CHECK").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("REPLACE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("MAPPING").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::keyword("FOR").to_matchable(), + Delimited::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable() - }) + .to_matchable() + }, + ) .to_matchable() .into(), ), ( - "AlterDomainStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterDomainStatement, |_| { + "DropTextSearchConfigurationStatementSegment".into(), + NodeMatcher::new( + SyntaxKind::DropTextSearchConfigurationStatement, + |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("TEXT").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("CONFIGURATION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable() + }, + ) + .to_matchable() + .into(), + ), + ( + "AlterTypeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTypeStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ALTER").to_matchable(), - Ref::keyword("DOMAIN").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("VALUE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - one_of(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("DROP").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("NULL").to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ Sequence::new(vec![ - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("ADD").to_matchable(), + Ref::keyword("ATTRIBUTE").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("CascadeRestrictGrammar").optional().to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - one_of(vec![ + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("ATTRIBUTE").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("NULL").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("DATA").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("CHECK").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("CascadeRestrictGrammar").optional().to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("VALID").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("ATTRIBUTE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("CascadeRestrictGrammar").optional().to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - one_of(vec![ - Ref::keyword("RESTRICT").to_matchable(), - Ref::keyword("CASCADE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("ATTRIBUTE").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("CascadeRestrictGrammar").optional().to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("VALIDATE").to_matchable(), - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OWNER").to_matchable(), - Ref::keyword("TO").to_matchable(), - one_of(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), + Ref::keyword("ADD").to_matchable(), + Ref::keyword("VALUE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("BEFORE").to_matchable(), + Ref::keyword("AFTER").to_matchable(), + ]) + .to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), ]) .to_matchable(), ]) @@ -6847,59 +9955,65 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "DropDomainStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropDomainStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("DOMAIN").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) - .to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "DropPolicyStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropPolicyStatement, |_| { + "CreateCollationStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateCollationStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("COLLATION").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "LoadStatementSegment".into(), - NodeMatcher::new(SyntaxKind::LoadStatement, |_| { - Sequence::new(vec![ - Ref::keyword("LOAD").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "ResetStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ResetStatement, |_| { - Sequence::new(vec![ - Ref::keyword("RESET").to_matchable(), one_of(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("LOCALE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LC_COLLATE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LC_CTYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PROVIDER").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("ICU").to_matchable(), + Ref::keyword("LIBC").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DETERMINISTIC").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("VERSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -6909,18 +10023,14 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "DiscardStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DiscardStatement, |_| { + "DropCollationStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropCollationStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("DISCARD").to_matchable(), - one_of(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("PLANS").to_matchable(), - Ref::keyword("SEQUENCES").to_matchable(), - Ref::keyword("TEMPORARY").to_matchable(), - Ref::keyword("TEMP").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("COLLATION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -6928,11 +10038,27 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "ListenStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ListenStatement, |_| { + "AlterSchemaStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterSchemaStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("LISTEN").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) @@ -6940,17 +10066,64 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "NotifyStatementSegment".into(), - NodeMatcher::new(SyntaxKind::NotifyStatement, |_| { + "LockTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::LockTableStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("NOTIFY").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("LOCK").to_matchable(), + Ref::keyword("TABLE").optional().to_matchable(), + Ref::keyword("ONLY").optional().to_matchable(), + one_of(vec![ + Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()]) + .to_matchable(), + Ref::new("StarSegment").to_matchable(), + ]) + .to_matchable(), Sequence::new(vec![ - Ref::new("CommaSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("IN").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("EXCLUSIVE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SHARE").to_matchable(), + Ref::keyword("UPDATE").to_matchable(), + Ref::keyword("EXCLUSIVE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SHARE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SHARE").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("EXCLUSIVE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("EXCLUSIVE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("EXCLUSIVE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("MODE").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::keyword("NOWAIT").optional().to_matchable(), ]) .to_matchable() }) @@ -6958,14 +10131,34 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "UnlistenStatementSegment".into(), - NodeMatcher::new(SyntaxKind::UnlistenStatement, |_| { + "ClusterStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ClusterStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("UNLISTEN").to_matchable(), + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("VERBOSE").optional().to_matchable(), one_of(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("StarSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("IndexReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -6973,226 +10166,151 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - postgres.replace_grammar( - "TruncateStatementSegment", - Sequence::new(vec![ - Ref::keyword("TRUNCATE").to_matchable(), - Ref::keyword("TABLE").optional().to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("ONLY").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("StarSegment").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("RESTART").to_matchable(), - Ref::keyword("CONTINUE").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("IDENTITY").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([ ( - "CopyStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CopyStatement, |_| { - let _target_subset = one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("PROGRAM").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]); - - let _table_definition = Sequence::new(vec![ - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]); - - let _option = Sequence::new(vec![ - Ref::keyword("WITH").optional().to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("FORMAT").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FREEZE").to_matchable(), - Ref::new("BooleanLiteralGrammar").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DELIMITER").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NULL").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("HEADER").to_matchable(), - Ref::new("BooleanLiteralGrammar").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("QUOTE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ESCAPE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FORCE_QUOTE").to_matchable(), - one_of(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("StarSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FORCE_NOT_NULL").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FORCE_NULL").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ENCODING").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()); - - Sequence::new(vec![ - Ref::keyword("COPY").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - _table_definition.clone().to_matchable(), - Ref::keyword("FROM").to_matchable(), - one_of(vec![ - _target_subset.clone().to_matchable(), - Ref::keyword("STDIN").to_matchable(), - ]) - .to_matchable(), - _option.clone().to_matchable(), + "ColumnReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnReference, |_dialect| { + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("DotSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("WHERE").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::new("DotSegment").to_matchable(), + Ref::new("DotSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - _table_definition.clone().to_matchable(), - Bracketed::new(vec![ - Ref::new("UnorderedSelectStatementSegment").to_matchable(), + Delimited::new(vec![ + Ref::new("SingleIdentifierFullGrammar").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + this.delimiter(one_of(vec![ + Ref::new("DotSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("DotSegment").to_matchable(), + Ref::new("DotSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("TO").to_matchable(), - one_of(vec![ - _target_subset.to_matchable(), - Ref::keyword("STDOUT").to_matchable(), - ]) - .to_matchable(), - _option.to_matchable(), - ]) + ])); + this.terminators = vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::keyword("USING").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("CastOperatorSegment").to_matchable(), + Ref::new("StartSquareBracketSegment").to_matchable(), + Ref::new("StartBracketSegment").to_matchable(), + Ref::new("BinaryOperatorGrammar").to_matchable(), + Ref::new("ColonSegment").to_matchable(), + Ref::new("DelimiterGrammar").to_matchable(), + Ref::new("JoinLikeClauseGrammar").to_matchable(), + Ref::new("BracketedSegment").to_matchable(), + ]; + }) .to_matchable(), ]) + .config(|this| { + this.optional(); + this.disallow_gaps(); + }) .to_matchable(), ]) + .config(|this| { + this.disallow_gaps(); + }) .to_matchable() }) .to_matchable() .into(), ), ( - "AlterSchemaStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterSchemaStatement, |_| { + "NamedArgumentSegment".into(), + NodeMatcher::new(SyntaxKind::NamedArgument, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), one_of(vec![ + Ref::new("RightArrowSegment").to_matchable(), + Ref::new("WalrusOperatorSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::TableExpression, |_dialect| { + one_of(vec![ + Ref::new("ValuesClauseSegment").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("FunctionSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::keyword("ORDINALITY").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OWNER").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - ]) + ]) + .to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) .to_matchable(), + Bracketed::new(vec![Ref::new("MergeStatementSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ServerReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::ServerReference, |_dialect| { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "CreateServerStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateServerStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("SERVER").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ServerReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("VERSION").to_matchable(), + Ref::new("VersionIdentifierSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("ForeignDataWrapperGrammar").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("OptionsGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -7200,62 +10318,188 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "LockTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::LockTableStatement, |_| { + "CreateUserMappingStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateUserMappingStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("LOCK").to_matchable(), - Ref::keyword("TABLE").optional().to_matchable(), - Ref::keyword("ONLY").optional().to_matchable(), + Ref::new("CreateUserMappingGrammar").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::keyword("FOR").to_matchable(), one_of(vec![ - Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()]) - .to_matchable(), - Ref::new("StarSegment").to_matchable(), + Ref::keyword("PUBLIC").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("SessionInformationUserFunctionsGrammar").to_matchable(), ]) .to_matchable(), + Ref::keyword("SERVER").to_matchable(), + Ref::new("ServerReferenceSegment").to_matchable(), + Ref::new("OptionsGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ImportForeignSchemaStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ImportForeignSchemaStatement, |_dialect| { + Sequence::new(vec![ + Ref::new("ImportForeignSchemaGrammar").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("IN").to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::keyword("ACCESS").to_matchable(), - Ref::keyword("SHARE").to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("TO").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ROW").to_matchable(), - Ref::keyword("SHARE").to_matchable(), + Ref::keyword("EXCEPT").to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("NakedIdentifierFullSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ROW").to_matchable(), - Ref::keyword("EXCLUSIVE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::keyword("SERVER").to_matchable(), + Ref::new("ServerReferenceSegment").to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + Ref::new("OptionsGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateForeignTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateForeignTableStatement, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::new("CreateForeignTableGrammar").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Ref::new("OptionsGrammar").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("ForeignTableColumnConstraintSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("ForeignTableTableConstraintSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SHARE").to_matchable(), - Ref::keyword("UPDATE").to_matchable(), - Ref::keyword("EXCLUSIVE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INHERITS").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Ref::keyword("SHARE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("SHARE").to_matchable(), - Ref::keyword("ROW").to_matchable(), - Ref::keyword("EXCLUSIVE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SERVER").to_matchable(), + Ref::new("ServerReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("OptionsGrammar").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("CreateForeignTableGrammar").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("PARTITION").to_matchable(), + Ref::keyword("OF").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("OPTIONS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("ForeignTableColumnConstraintSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("ForeignTableTableConstraintSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("EXCLUSIVE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ACCESS").to_matchable(), - Ref::keyword("EXCLUSIVE").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("FOR").to_matchable(), + Ref::keyword("VALUES").to_matchable(), + Ref::new("PartitionBoundSpecSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Ref::keyword("MODE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SERVER").to_matchable(), + Ref::new("ServerReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("OptionsGrammar").optional().to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::keyword("NOWAIT").optional().to_matchable(), ]) .to_matchable() }) @@ -7263,30 +10507,59 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "ClusterStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ClusterStatement, |_| { + "OverlapsClauseSegment".into(), + NodeMatcher::new(SyntaxKind::OverlapsClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("CLUSTER").to_matchable(), - Ref::keyword("VERBOSE").optional().to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::new("TableReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Ref::new("IndexReferenceSegment").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DateTimeLiteralGrammar").to_matchable(), + Ref::new("ShorthandCastSegment").to_matchable(), + Ref::new("FunctionContentsExpressionGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("CommaSegment").to_matchable(), + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DateTimeLiteralGrammar").to_matchable(), + Ref::new("ShorthandCastSegment").to_matchable(), + Ref::new("FunctionContentsExpressionGrammar").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("OVERLAPS").to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::new("IndexReferenceSegment").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DateTimeLiteralGrammar").to_matchable(), + Ref::new("ShorthandCastSegment").to_matchable(), + Ref::new("FunctionContentsExpressionGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("CommaSegment").to_matchable(), + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DateTimeLiteralGrammar").to_matchable(), + Ref::new("ShorthandCastSegment").to_matchable(), + Ref::new("FunctionContentsExpressionGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable() @@ -7295,13 +10568,18 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "LanguageClauseSegment".into(), - NodeMatcher::new(SyntaxKind::LanguageClause, |_| { + "ShowStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ShowStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("LANGUAGE").to_matchable(), + Ref::keyword("SHOW").to_matchable(), one_of(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("SingleQuotedIdentifierSegment").to_matchable(), + Ref::keyword("ALL").to_matchable(), + Ref::keyword("IS_SUPERUSER").to_matchable(), + Ref::keyword("LC_COLLATE").to_matchable(), + Ref::keyword("LC_CTYPE").to_matchable(), + Ref::keyword("SERVER_ENCODING").to_matchable(), + Ref::keyword("SERVER_VERSION").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), ]) .to_matchable(), ]) @@ -7311,19 +10589,15 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "DoStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DoStatement, |_| { + "MetaCommandQueryBufferStatement".into(), + NodeMatcher::new(SyntaxKind::MetaCommandStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("DO").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::new("LanguageClauseSegment").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("LanguageClauseSegment").optional().to_matchable(), + Ref::new("SelectStatementSegment").to_matchable(), + Ref::new("MetaCommandQueryBufferSegment") + .optional() + .to_matchable(), ]) .to_matchable(), ]) @@ -7334,188 +10608,195 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - postgres.replace_grammar( - "CTEDefinitionSegment", - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("CTEColumnList").optional().to_matchable(), - Ref::keyword("AS").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("MATERIALIZED").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) - .config(|this| this.parse_mode = ParseMode::Greedy) - .to_matchable(), - one_of(vec![ + ( + "DropForeignTableStatement".into(), + NodeMatcher::new(SyntaxKind::DropForeignTableStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("SEARCH").to_matchable(), - one_of(vec![ - Ref::keyword("BREADTH").to_matchable(), - Ref::keyword("DEPTH").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("BY").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::keyword("SET").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("FOREIGN").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Delimited::new(vec![Ref::new("TableReferenceSegment").to_matchable()]) + .to_matchable(), + Ref::new("CascadeRestrictGrammar").optional().to_matchable(), ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ColumnTypeReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnTypeReference, |_dialect| { Sequence::new(vec![ - Ref::keyword("CYCLE").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::keyword("SET").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::keyword("USING").to_matchable(), Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ModuloSegment").to_matchable(), + Ref::keyword("TYPE").to_matchable(), ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.replace_grammar( - "ValuesClauseSegment", - Sequence::new(vec![ - Ref::keyword("VALUES").to_matchable(), - Delimited::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateOperatorStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateOperatorStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("OPERATOR").to_matchable(), + AnyNumberOf::new(vec![ + RegexParser::new(r#"^[+\-*/<>=~!@#%^&|`?]+$"#, SyntaxKind::Symbol) + .to_matchable(), ]) - .config(|this| this.parse_mode = ParseMode::Greedy) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - Ref::new("OrderByClauseSegment").optional().to_matchable(), - Ref::new("LimitClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - ); - - postgres.replace_grammar( - "DeleteStatementSegment", - Sequence::new(vec![ - Ref::keyword("DELETE").to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::keyword("ONLY").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("StarSegment").optional().to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - MetaSegment::indent().to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("TableExpressionSegment").to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("LEFTARG").to_matchable(), + Ref::keyword("RIGHTARG").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMMUTATOR").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + AnyNumberOf::new(vec![ + RegexParser::new( + r#"^[+\-*/<>=~!@#%^&|`?]+$"#, + SyntaxKind::Symbol, + ) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NEGATOR").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + AnyNumberOf::new(vec![ + RegexParser::new( + r#"^[+\-*/<>=~!@#%^&|`?]+$"#, + SyntaxKind::Symbol, + ) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("RESTRICT").to_matchable(), + Ref::keyword("JOIN").to_matchable(), + one_of(vec![ + Ref::keyword("PROCEDURE").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("HASHES").optional().to_matchable(), + Ref::keyword("MERGES").optional().to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterForeignTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterForeignTableStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("WHERE").to_matchable(), - Ref::keyword("CURRENT").to_matchable(), - Ref::keyword("OF").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("WhereClauseSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RETURNING").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ - Ref::new("StarSegment").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("FOREIGN").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Sequence::new(vec![ + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::keyword("ONLY").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("StarSegment").optional().to_matchable(), + one_of(vec![ + Delimited::new(vec![ + Ref::new("AlterForeignTableActionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - postgres.add([ + .to_matchable() + }) + .to_matchable() + .into(), + ), ( - "SetClauseSegment".into(), - NodeMatcher::new(SyntaxKind::SetClause, |_| { - Sequence::new(vec![ - one_of(vec![ - Sequence::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("ArrayAccessorSegment").optional().to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("BareFunctionSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), + "AlterForeignTableActionSegment".into(), + NodeMatcher::new(SyntaxKind::AlterForeignTableActionSegment, |_dialect| { + get_alter_table_action_segment_grammar().copy( + Some(vec![ + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::new("COLUMN").optional().to_matchable(), Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - AnyNumberOf::new(vec![Ref::new("ShorthandCastSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ + Ref::keyword("OPTIONS").to_matchable(), Bracketed::new(vec![ Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - one_of(vec![ - Ref::new("SelectableGrammar").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("BareFunctionSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - ]) - .to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("ShorthandCastSegment").to_matchable(), - ]) - .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("DROP").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("QuotedLiteralSegment").optional().to_matchable(), ]) .to_matchable(), ]) @@ -7524,57 +10805,36 @@ pub fn raw_dialect() -> Dialect { .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() + ]), + None, + None, + None, + vec![], + false, + ) }) .to_matchable() .into(), ), ( - "UpdateStatementSegment".into(), - NodeMatcher::new(SyntaxKind::UpdateStatement, |_| { + "PrepareStatementSegment".into(), + NodeMatcher::new(SyntaxKind::PrepareStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("UPDATE").to_matchable(), - Ref::keyword("ONLY").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("AliasExpressionSegment") - .exclude(Ref::keyword("SET")) - .optional() - .to_matchable(), - Ref::new("SetClauseListSegment").to_matchable(), - Ref::new("FromClauseSegment").optional().to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("WHERE").to_matchable(), - Ref::keyword("CURRENT").to_matchable(), - Ref::keyword("OF").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("WhereClauseSegment").to_matchable(), + Ref::keyword("PREPARE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RETURNING").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ - Ref::new("StarSegment").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Ref::new("SelectableGrammar").to_matchable(), + Ref::new("MergeStatementSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable() @@ -7583,45 +10843,18 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "CreateTypeStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateTypeStatement, |_| { + "ExecuteStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ExecuteStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("TYPE").to_matchable(), + Ref::keyword("EXECUTE").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - one_of(vec![ - Ref::keyword("ENUM").to_matchable(), - Ref::keyword("RANGE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Sequence::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLLATE").to_matchable(), - Ref::new("CollationReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Anything::new().to_matchable(), - ]) + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -7630,119 +10863,97 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "AlterTypeStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterTypeStatement, |_| { + "DeallocateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DeallocateStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("TYPE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("DEALLOCATE").to_matchable(), + Ref::keyword("PREPARE").optional().to_matchable(), one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TypedArrayLiteralSegment".into(), + NodeMatcher::new(SyntaxKind::TypedArrayLiteral, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("TypedArrayLiteralSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ Sequence::new(vec![ - Ref::keyword("OWNER").to_matchable(), - Ref::keyword("TO").to_matchable(), - one_of(vec![ - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("VARIADIC").to_matchable(), + Sequence::new(vec![ + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("WalrusOperatorSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + ]), + None, + Some(Ref::new("ArrayTypeSegment").to_matchable()), + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "SetSessionAuthorizationStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SetSessionAuthorizationStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("VALUE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("ATTRIBUTE").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLLATE").to_matchable(), - Ref::new("CollationReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("CascadeRestrictGrammar").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("ATTRIBUTE").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("DATA").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("TYPE").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLLATE").to_matchable(), - Ref::new("CollationReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("CascadeRestrictGrammar").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("ATTRIBUTE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("CascadeRestrictGrammar").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("ATTRIBUTE").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("CascadeRestrictGrammar").optional().to_matchable(), - ]) - .to_matchable(), + Ref::keyword("LOCAL").optional().to_matchable(), + Ref::keyword("SESSION").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("VALUE").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("BEFORE").to_matchable(), - Ref::keyword("AFTER").to_matchable(), - ]) - .to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("SESSION").optional().to_matchable(), + Ref::keyword("SESSION").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Ref::keyword("AUTHORIZATION").to_matchable(), + one_of(vec![ + Ref::new("RoleReferenceSegment").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ResetSessionAuthorizationStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ResetSessionAuthorizationStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("RESET").to_matchable(), + Ref::keyword("SESSION").to_matchable(), + Ref::keyword("AUTHORIZATION").to_matchable(), ]) .to_matchable() }) @@ -7750,63 +10961,16 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "CreateCollationStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateCollationStatement, |_| { + "ColumnDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnDefinition, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("COLLATION").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - one_of(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::keyword("LOCALE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LC_COLLATE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LC_CTYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("PROVIDER").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("ICU").to_matchable(), - Ref::keyword("LIBC").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DETERMINISTIC").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("VERSION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("ColumnConstraintSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), ]) .to_matchable(), ]) @@ -7819,277 +10983,161 @@ pub fn raw_dialect() -> Dialect { ), ]); - postgres.replace_grammar( - "ColumnReferenceSegment", + postgres_dialect +} + +pub fn get_alter_table_action_segment_grammar() -> Matchable { + one_of(vec![ Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("ADD").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), Sequence::new(vec![ - one_of(vec![ - Ref::new("DotSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("DotSegment").to_matchable(), - Ref::new("DotSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Delimited::new(vec![Ref::new("SingleIdentifierFullGrammar").to_matchable()]) - .config(|this| { - this.delimiter(one_of(vec![ - Ref::new("DotSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("DotSegment").to_matchable(), - Ref::new("DotSegment").to_matchable(), - ]) - .to_matchable(), - ])); - this.terminators = vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::keyword("USING").to_matchable(), - Ref::new("CommaSegment").to_matchable(), - Ref::new("CastOperatorSegment").to_matchable(), - Ref::new("StartSquareBracketSegment").to_matchable(), - Ref::new("StartBracketSegment").to_matchable(), - Ref::new("BinaryOperatorGrammar").to_matchable(), - Ref::new("ColonSegment").to_matchable(), - Ref::new("DelimiterGrammar").to_matchable(), - Ref::new("JoinLikeClauseGrammar").to_matchable(), - Bracketed::new(vec![]).to_matchable(), - ]; - this.allow_gaps = false; - }) - .to_matchable(), + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), ]) .config(|this| { this.optional(); - this.allow_gaps = false }) .to_matchable(), + AnyNumberOf::new(vec![Ref::new("ColumnConstraintSegment").to_matchable()]) + .to_matchable(), ]) - .config(|this| this.allow_gaps = false) .to_matchable(), - ); - - postgres.add([( - "NamedArgumentSegment".into(), - NodeMatcher::new(SyntaxKind::NamedArgument, |_| { - Sequence::new(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("RightArrowSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - )]); - - postgres.replace_grammar( - "TableExpressionSegment", - one_of(vec![ - Ref::new("ValuesClauseSegment").to_matchable(), - Ref::new("BareFunctionSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("FunctionSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("ORDINALITY").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable(), - Bracketed::new(vec![Ref::new("MergeStatementSegment").to_matchable()]).to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable(), - ); - - postgres.add([( - "ServerReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::ServerReference, |postgres| { - postgres - .grammar("ObjectReferenceSegment") - .match_grammar(postgres) - .unwrap() - }) - .to_matchable() - .into(), - )]); - - postgres.add([ - ( - "CreateServerStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateServerStatement, |_| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("SERVER").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("ServerReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("DATA").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("VERSION").to_matchable(), - Ref::new("VersionIdentifierSegment").to_matchable(), + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("ForeignDataWrapperGrammar").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::new("OptionsGrammar").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "CreateUserMappingStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateUserMappingStatement, |_| { - Sequence::new(vec![ - Ref::new("CreateUserMappingGrammar").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::keyword("FOR").to_matchable(), - one_of(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("SessionInformationUserFunctionsGrammar").to_matchable(), - Ref::keyword("PUBLIC").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + one_of(vec![Ref::new("ExpressionSegment").to_matchable()]).to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("SERVER").to_matchable(), - Ref::new("ServerReferenceSegment").to_matchable(), - Ref::new("OptionsGrammar").optional().to_matchable(), ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "ImportForeignSchemaStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ImportForeignSchemaStatement, |_| { + .to_matchable(), Sequence::new(vec![ - Ref::new("ImportForeignSchemaGrammar").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + one_of(vec![ one_of(vec![ - Sequence::new(vec![ - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("TO").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("EXCEPT").to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("NakedIdentifierFullSegment").to_matchable(), - ]) - .to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::keyword("SERVER").to_matchable(), - Ref::new("ServerReferenceSegment").to_matchable(), - Ref::keyword("INTO").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - Ref::new("OptionsGrammar").optional().to_matchable(), ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - // Statics Reference - "StatisticsReferenceSegment".into(), - Ref::new("ObjectReferenceSegment").to_matchable().into(), - ), - ( - // Create Statistics Segment. - // As specified in https://www.postgresql.org/docs/16/sql-createstatistics.html - "CreateStatisticsStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("STATISTICS").to_matchable(), + .to_matchable(), Sequence::new(vec![ - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("StatisticsReferenceSegment").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::keyword("DEPENDENCIES").to_matchable(), - Ref::keyword("MCV").to_matchable(), - Ref::keyword("NDISTINCT").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("DROP").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("EXPRESSION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("GENERATED").to_matchable(), + one_of(vec![ + Ref::keyword("ALWAYS").to_matchable(), + Sequence::new(vec![ + Ref::keyword("BY").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::keyword("IDENTITY").to_matchable(), + Bracketed::new(vec![ + AnyNumberOf::new(vec![ + Ref::new("AlterSequenceOptionsSegment").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("ON").to_matchable(), - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) .to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - // Alter Statistics Segment. - // As specified in https://www.postgresql.org/docs/16/sql-alterstatistics.html - "AlterStatisticsStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("STATISTICS").to_matchable(), - Ref::new("StatisticsReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("OWNER").to_matchable(), - Ref::keyword("TO").to_matchable(), - one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("GENERATED").to_matchable(), one_of(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), + Ref::keyword("ALWAYS").to_matchable(), + Sequence::new(vec![ + Ref::keyword("BY").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Ref::keyword("CURRENT_ROLE").to_matchable(), - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("StatisticsReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("AlterSequenceOptionsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESTART").to_matchable(), Sequence::new(vec![ - Ref::keyword("STATISTICS").to_matchable(), + Ref::keyword("WITH").to_matchable(), Ref::new("NumericLiteralSegment").to_matchable(), ]) .to_matchable(), @@ -8099,131 +11147,286 @@ pub fn raw_dialect() -> Dialect { .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - // Drop Statistics Segment. - // As specified in https://www.postgresql.org/docs/16/sql-dropstatistics.html - "DropStatisticsStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("STATISTICS").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Delimited::new(vec![Ref::new("StatisticsReferenceSegment").to_matchable()]) + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("IDENTITY").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("STATISTICS").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("RelationOptionsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESET").to_matchable(), + Ref::new("RelationOptionsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("STORAGE").to_matchable(), + one_of(vec![ + Ref::keyword("PLAIN").to_matchable(), + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("EXTENDED").to_matchable(), + Ref::keyword("MAIN").to_matchable(), + ]) .to_matchable(), - one_of(vec![ - Ref::keyword("CASCADE").to_matchable(), - Ref::keyword("RESTRICT").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "AccessStatementSegmentGrantRoleWithOptionGrammar".into(), + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::new("TableConstraintSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::new("TableConstraintUsingIndexSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), one_of(vec![ + Ref::keyword("DEFERRABLE").to_matchable(), Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("GRANT").to_matchable(), - Ref::keyword("OPTION").to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("DEFERRABLE").to_matchable(), ]) .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("ADMIN").to_matchable(), - Ref::keyword("OPTION").to_matchable(), + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("DEFERRED").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("ADMIN").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("IMMEDIATE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("VALIDATE").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("DISABLE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + one_of(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("ALL").to_matchable(), + Ref::keyword("USER").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENABLE").to_matchable(), + one_of(vec![ + Ref::keyword("REPLICA").to_matchable(), + Ref::keyword("ALWAYS").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("DISABLE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("REPLICA").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("COPY").to_matchable(), - Ref::keyword("CURRENT").to_matchable(), - Ref::keyword("GRANTS").to_matchable(), + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("RULE").to_matchable(), ]) .to_matchable(), ]) - .to_matchable() - .into(), - ), - ]); - - postgres + .to_matchable(), + Ref::keyword("RULE").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DISABLE").to_matchable(), + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("FORCE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("FORCE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("LEVEL").to_matchable(), + Ref::keyword("SECURITY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("WITHOUT").to_matchable(), + one_of(vec![ + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("OIDS").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("TABLESPACE").to_matchable(), + Ref::new("TablespaceReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Ref::keyword("LOGGED").to_matchable(), + Ref::keyword("UNLOGGED").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("RelationOptionsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESET").to_matchable(), + Ref::new("RelationOptionsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").optional().to_matchable(), + Ref::keyword("INHERIT").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OF").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("OF").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("CURRENT_ROLE").to_matchable(), + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REPLICA").to_matchable(), + Ref::keyword("IDENTITY").to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Ref::keyword("INDEX").to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FULL").to_matchable(), + Ref::keyword("NOTHING").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() } -pub fn statement_segment() -> Matchable { - ansi::statement_segment().copy( +pub fn get_unordered_select_statement_segment_grammar() -> Matchable { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("UnorderedSelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( Some(vec![ - Ref::new("CreateStatisticsStatementSegment").to_matchable(), - Ref::new("AlterStatisticsStatementSegment").to_matchable(), - Ref::new("DropStatisticsStatementSegment").to_matchable(), - Ref::new("AlterDefaultPrivilegesStatementSegment").to_matchable(), - Ref::new("DropOwnedStatementSegment").to_matchable(), - Ref::new("ReassignOwnedStatementSegment").to_matchable(), - Ref::new("CommentOnStatementSegment").to_matchable(), - Ref::new("AnalyzeStatementSegment").to_matchable(), - Ref::new("CreateTableAsStatementSegment").to_matchable(), - Ref::new("AlterTriggerStatementSegment").to_matchable(), - Ref::new("AlterAggregateStatementSegment").to_matchable(), - Ref::new("SetStatementSegment").to_matchable(), - Ref::new("AlterPolicyStatementSegment").to_matchable(), - Ref::new("CreatePolicyStatementSegment").to_matchable(), - Ref::new("DropPolicyStatementSegment").to_matchable(), - Ref::new("CreateDomainStatementSegment").to_matchable(), - Ref::new("AlterDomainStatementSegment").to_matchable(), - Ref::new("DropDomainStatementSegment").to_matchable(), - Ref::new("CreateMaterializedViewStatementSegment").to_matchable(), - Ref::new("AlterMaterializedViewStatementSegment").to_matchable(), - Ref::new("DropMaterializedViewStatementSegment").to_matchable(), - Ref::new("RefreshMaterializedViewStatementSegment").to_matchable(), - Ref::new("AlterDatabaseStatementSegment").to_matchable(), - Ref::new("DropDatabaseStatementSegment").to_matchable(), - Ref::new("VacuumStatementSegment").to_matchable(), - Ref::new("AlterFunctionStatementSegment").to_matchable(), - Ref::new("CreateViewStatementSegment").to_matchable(), - Ref::new("AlterViewStatementSegment").to_matchable(), - Ref::new("ListenStatementSegment").to_matchable(), - Ref::new("NotifyStatementSegment").to_matchable(), - Ref::new("UnlistenStatementSegment").to_matchable(), - Ref::new("LoadStatementSegment").to_matchable(), - Ref::new("ResetStatementSegment").to_matchable(), - Ref::new("DiscardStatementSegment").to_matchable(), - Ref::new("AlterProcedureStatementSegment").to_matchable(), - Ref::new("CreateProcedureStatementSegment").to_matchable(), - Ref::new("DropProcedureStatementSegment").to_matchable(), - Ref::new("CopyStatementSegment").to_matchable(), - Ref::new("DoStatementSegment").to_matchable(), - Ref::new("AlterIndexStatementSegment").to_matchable(), - Ref::new("ReindexStatementSegment").to_matchable(), - Ref::new("AlterRoleStatementSegment").to_matchable(), - Ref::new("CreateExtensionStatementSegment").to_matchable(), - Ref::new("DropExtensionStatementSegment").to_matchable(), - Ref::new("CreatePublicationStatementSegment").to_matchable(), - Ref::new("AlterPublicationStatementSegment").to_matchable(), - Ref::new("DropPublicationStatementSegment").to_matchable(), - Ref::new("CreateTypeStatementSegment").to_matchable(), - Ref::new("AlterTypeStatementSegment").to_matchable(), - Ref::new("AlterSchemaStatementSegment").to_matchable(), - Ref::new("LockTableStatementSegment").to_matchable(), - Ref::new("ClusterStatementSegment").to_matchable(), - Ref::new("CreateCollationStatementSegment").to_matchable(), - Ref::new("CallStoredProcedureSegment").to_matchable(), - Ref::new("CreateServerStatementSegment").to_matchable(), - Ref::new("CreateUserMappingStatementSegment").to_matchable(), - Ref::new("ImportForeignSchemaStatementSegment").to_matchable(), + Ref::new("IntoClauseSegment").optional().to_matchable(), ]), None, + Some(Ref::new("FromClauseSegment").optional().to_matchable()), None, - None, - vec![], + vec![ + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("NO").optional().to_matchable(), + Ref::keyword("DATA").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("CONFLICT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("RETURNING").to_matchable(), + Ref::new("WithCheckOptionSegment").to_matchable(), + Ref::new("MetaCommandQueryBufferSegment").to_matchable(), + ], false, ) } diff --git a/crates/lib-dialects/src/postgres_keywords.rs b/crates/lib-dialects/src/postgres_keywords.rs index 65f170618..4f4949fc1 100644 --- a/crates/lib-dialects/src/postgres_keywords.rs +++ b/crates/lib-dialects/src/postgres_keywords.rs @@ -77,7 +77,7 @@ const POSTGRES_DOCS_KEYWORDS: &[(&str, &str)] = &[ ("ASYMMETRIC", "reserved"), ("AT", "non-reserved"), ("ATAN", "not-keyword"), - ("ATOMIC", "not-keyword"), + ("ATOMIC", "non-reserved"), ("ATTACH", "non-reserved"), ("ATTRIBUTE", "non-reserved"), ("ATTRIBUTES", "not-keyword"), @@ -158,6 +158,7 @@ const POSTGRES_DOCS_KEYWORDS: &[(&str, &str)] = &[ ("COMMENTS", "non-reserved"), ("COMMIT", "non-reserved"), ("COMMITTED", "non-reserved"), + ("COMMUTATOR", "reserved-(can-be-function-or-type)"), ("COMPRESSION", "non-reserved"), ("CONCURRENTLY", "reserved-(can-be-function-or-type)"), ("CONDITION", "not-keyword"), @@ -347,6 +348,7 @@ const POSTGRES_DOCS_KEYWORDS: &[(&str, &str)] = &[ ("GROUPING", "non-reserved-(cannot-be-function-or-type)"), ("GROUPS", "non-reserved"), ("HANDLER", "non-reserved"), + ("HASHES", "reserved-(can-be-function-or-type)"), ("HAVING", "reserved"), ("HEADER", "non-reserved"), ("HEX", "not-keyword"), @@ -401,6 +403,7 @@ const POSTGRES_DOCS_KEYWORDS: &[(&str, &str)] = &[ ("INVOKER", "non-reserved"), ("IS", "reserved-(can-be-function-or-type)"), ("ISNULL", "reserved-(can-be-function-or-type)"), + ("IS_SUPERUSER", "non-reserved"), ("ISOLATION", "non-reserved"), ("JOIN", "reserved-(can-be-function-or-type)"), ("JSON", "not-keyword"), @@ -410,9 +413,14 @@ const POSTGRES_DOCS_KEYWORDS: &[(&str, &str)] = &[ ("JSON_OBJECT", "not-keyword"), ("JSON_OBJECTAGG", "not-keyword"), ("JSON_QUERY", "not-keyword"), + ("JSON_SERIALIZE", "not-keyword"), ("JSON_TABLE", "not-keyword"), ("JSON_TABLE_PRIMITIVE", "not-keyword"), ("JSON_VALUE", "not-keyword"), + ("JSONB_EACH", "not-keyword"), + ("JSONB_EACH_TEXT", "not-keyword"), + ("JSON_EACH", "not-keyword"), + ("JSON_EACH_TEXT", "not-keyword"), ("JSONB", "non-reserved-(cannot-be-function-or-type)"), ("K", "not-keyword"), ("KEEP", "not-keyword"), @@ -427,11 +435,14 @@ const POSTGRES_DOCS_KEYWORDS: &[(&str, &str)] = &[ ("LAST", "non-reserved"), ("LAST_VALUE", "not-keyword"), ("LATERAL", "reserved"), + ("LC_COLLATE", "non-reserved"), + ("LC_CTYPE", "non-reserved"), ("LEAD", "not-keyword"), ("LEADING", "reserved"), ("LEAKPROOF", "non-reserved"), ("LEAST", "non-reserved-(cannot-be-function-or-type)"), ("LEFT", "reserved-(can-be-function-or-type)"), + ("LEFTARG", "non-reserved-(cannot-be-function-or-type)"), ("LENGTH", "not-keyword"), ("LEVEL", "non-reserved"), ("LIBRARY", "not-keyword"), @@ -472,6 +483,7 @@ const POSTGRES_DOCS_KEYWORDS: &[(&str, &str)] = &[ ("MEASURES", "not-keyword"), ("MEMBER", "not-keyword"), ("MERGE", "non-reserved"), + ("MERGES", "reserved-(can-be-function-or-type)"), ("MESSAGE_LENGTH", "not-keyword"), ("MESSAGE_OCTET_LENGTH", "not-keyword"), ("MESSAGE_TEXT", "not-keyword"), @@ -496,6 +508,7 @@ const POSTGRES_DOCS_KEYWORDS: &[(&str, &str)] = &[ ("NATURAL", "reserved-(can-be-function-or-type)"), ("NCHAR", "non-reserved-(cannot-be-function-or-type)"), ("NCLOB", "not-keyword"), + ("NEGATOR", "reserved-(can-be-function-or-type)"), ("NESTED", "not-keyword"), ("NESTING", "not-keyword"), ("NEW", "non-reserved"), @@ -654,7 +667,8 @@ const POSTGRES_DOCS_KEYWORDS: &[(&str, &str)] = &[ ("RESTRICT", "non-reserved"), ("RESTRICTIVE", "non-reserved"), ("RESULT", "not-keyword"), - ("RETURN", "not-keyword"), + ("RETRIEVE", "non-reserved"), + ("RETURN", "non-reserved"), ("RETURNED_CARDINALITY", "not-keyword"), ("RETURNED_LENGTH", "not-keyword"), ("RETURNED_OCTET_LENGTH", "not-keyword"), @@ -663,6 +677,7 @@ const POSTGRES_DOCS_KEYWORDS: &[(&str, &str)] = &[ ("RETURNS", "non-reserved"), ("REVOKE", "non-reserved"), ("RIGHT", "reserved-(can-be-function-or-type)"), + ("RIGHTARG", "reserved-(can-be-function-or-type)"), ("ROLE", "non-reserved"), ("ROLLBACK", "non-reserved"), ("ROLLUP", "non-reserved"), @@ -705,7 +720,9 @@ const POSTGRES_DOCS_KEYWORDS: &[(&str, &str)] = &[ ("SERIAL8", "non-reserved-(cannot-be-function-or-type)"), ("SERIALIZABLE", "non-reserved"), ("SERVER", "non-reserved"), + ("SERVER_ENCODING", "non-reserved"), ("SERVER_NAME", "not-keyword"), + ("SERVER_VERSION", "non-reserved"), ("SESSION", "non-reserved"), ("SESSION_USER", "reserved"), ("SET", "non-reserved"), @@ -836,7 +853,7 @@ const POSTGRES_DOCS_KEYWORDS: &[(&str, &str)] = &[ ("UPPER", "not-keyword"), ("URI", "not-keyword"), ("USAGE", "not-keyword"), - ("USER", "reserved"), + ("USER", "non-reserved"), ("USER_DEFINED_TYPE_CATALOG", "not-keyword"), ("USER_DEFINED_TYPE_CODE", "not-keyword"), ("USER_DEFINED_TYPE_NAME", "not-keyword"), @@ -934,6 +951,7 @@ const POSTGRES_NONDOCS_KEYWORDS: &[(&str, &str)] = &[ ("INDEX_CLEANUP", "non-reserved"), ("IS_TEMPLATE", "non-reserved"), ("JSON", "non-reserved"), + ("KEYS", "non-reserved"), ("LC_COLLATE", "non-reserved"), ("LC_CTYPE", "non-reserved"), ("LIBC", "non-reserved"), @@ -960,6 +978,7 @@ const POSTGRES_NONDOCS_KEYWORDS: &[(&str, &str)] = &[ ("RESPECT", "non-reserved"), ("RESTRICTED", "non-reserved"), ("SAFE", "non-reserved"), + ("SCALAR", "non-reserved"), ("SETTINGS", "non-reserved"), ("SKIP_LOCKED", "non-reserved"), ("SUMMARY", "non-reserved"), @@ -972,7 +991,7 @@ const POSTGRES_NONDOCS_KEYWORDS: &[(&str, &str)] = &[ ("WAL", "non-reserved"), ]; -pub(crate) const POSTGRES_POSTGIS_DATATYPE_KEYWORDS: &[(&str, &str)] = &[ +const POSTGRES_POSTGIS_DATATYPE_KEYWORDS: &[(&str, &str)] = &[ ("POINT", "non-reserved"), ("LINESTRING", "non-reserved"), ("POLYGON", "non-reserved"), @@ -1017,12 +1036,15 @@ const POSTGRES_POSTGIS_OTHER_KEYWORDS: &[(&str, &str)] = &[ ("EMPTY", "non-reserved"), ]; +const POSTGRES_PGVECTOR_KEYWORDS: &[(&str, &str)] = &[("VECTOR", "non-reserved")]; + pub(crate) fn postgres_keywords() -> Vec<(&'static str, &'static str)> { priority_keyword_merge(&[ POSTGRES_DOCS_KEYWORDS, POSTGRES_NONDOCS_KEYWORDS, POSTGRES_POSTGIS_DATATYPE_KEYWORDS, POSTGRES_POSTGIS_OTHER_KEYWORDS, + POSTGRES_PGVECTOR_KEYWORDS, ]) } @@ -1060,14 +1082,15 @@ mod tests { assert_eq!(sorted(result_2), sorted(expected_result_2)); - let kw_list_3 = &[("B", "reserved")]; + let kw_list_3 = &[("A", "reserved"), ("D", "not-keyword")]; let result_3 = priority_keyword_merge(&[kw_list_2, kw_list_1, kw_list_3]); let expected_result_3 = vec![ - ("A", "not-keyword"), - ("B", "reserved"), + ("A", "reserved"), + ("B", "non-reserved"), ("C", "non-reserved"), + ("D", "not-keyword"), ]; assert_eq!(sorted(result_3), sorted(expected_result_3)); diff --git a/crates/lib-dialects/src/redshift.rs b/crates/lib-dialects/src/redshift.rs index 24aa66dd7..10e4d3e1a 100644 --- a/crates/lib-dialects/src/redshift.rs +++ b/crates/lib-dialects/src/redshift.rs @@ -3,21 +3,18 @@ use sqruff_lib_core::dialects::Dialect; use sqruff_lib_core::dialects::init::DialectKind; use sqruff_lib_core::dialects::syntax::SyntaxKind; use sqruff_lib_core::helpers::{Config, ToMatchable}; -use sqruff_lib_core::parser::grammar::anyof::{ - AnyNumberOf, any_set_of, one_of, optionally_bracketed, -}; +use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed}; use sqruff_lib_core::parser::grammar::delimited::Delimited; use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence}; use sqruff_lib_core::parser::grammar::{Anything, Nothing, Ref}; use sqruff_lib_core::parser::lexer::Matcher; use sqruff_lib_core::parser::matchable::MatchableTrait; use sqruff_lib_core::parser::node_matcher::NodeMatcher; -use sqruff_lib_core::parser::parsers::RegexParser; +use sqruff_lib_core::parser::parsers::{RegexParser, StringParser}; use sqruff_lib_core::parser::segments::generator::SegmentGenerator; use sqruff_lib_core::parser::segments::meta::MetaSegment; -use sqruff_lib_core::parser::types::ParseMode; -use crate::redshift_keywords::{REDSHIFT_RESERVED_KEYWORDS, REDSHIFT_UNRESERVED_KEYWORDS}; +use super::redshift_keywords::{REDSHIFT_RESERVED_KEYWORDS, REDSHIFT_UNRESERVED_KEYWORDS}; pub fn dialect() -> Dialect { raw_dialect().config(|this| this.expand()) @@ -30,14 +27,19 @@ pub fn raw_dialect() -> Dialect { redshift_dialect.name = DialectKind::Redshift; redshift_dialect.sets_mut("unreserved_keywords").clear(); + redshift_dialect.update_keywords_set_from_multiline_string( "unreserved_keywords", REDSHIFT_UNRESERVED_KEYWORDS, ); + redshift_dialect.sets_mut("reserved_keywords").clear(); + redshift_dialect .update_keywords_set_from_multiline_string("reserved_keywords", REDSHIFT_RESERVED_KEYWORDS); + redshift_dialect.sets_mut("bare_functions").clear(); + redshift_dialect.sets_mut("bare_functions").extend([ "current_date", "sysdate", @@ -49,9 +51,11 @@ pub fn raw_dialect() -> Dialect { "current_namespace", "current_user_id", ]); + redshift_dialect .sets_mut("date_part_function_name") .extend(["DATEADD", "DATEDIFF", "EXTRACT", "DATE_PART"]); + redshift_dialect.sets_mut("datetime_units").extend([ "MILLENNIUM", "MILLENNIA", @@ -133,49 +137,63 @@ pub fn raw_dialect() -> Dialect { "TIMEZONE_HOUR", "TIMEZONE_MINUTE", ]); - redshift_dialect.add([ - ( - "WellKnownTextGeometrySegment".into(), - Nothing::new().to_matchable().into(), - ), - ( - "JoinLikeClauseGrammar".into(), - Sequence::new(vec![ - any_set_of(vec![ - Ref::new("FromPivotExpressionSegment").to_matchable(), - Ref::new("FromUnpivotExpressionSegment").to_matchable(), - ]) - .config(|this| { - this.min_times = 1; - }) - .to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - ]) + + redshift_dialect.add([( + "NakedIdentifierSegment".into(), + SegmentGenerator::new(|dialect| { + let reserved_keywords = dialect.sets("reserved_keywords"); + let pattern = reserved_keywords.iter().join("|"); + let anti_template = format!("^({pattern})$"); + RegexParser::new( + r#"#?([A-Z_]+|[0-9]+[A-Z_$])[A-Z0-9_$]*"#, + SyntaxKind::NakedIdentifier, + ) + .anti_template(&anti_template) .to_matchable() - .into(), - ), - ( - "NakedIdentifierSegment".into(), - SegmentGenerator::new(|dialect| { - // Generate the anti template from the set of reserved keywords - let reserved_keywords = dialect.sets("reserved_keywords"); - let pattern = reserved_keywords.iter().join("|"); - let anti_template = format!("^({pattern})$"); + }) + .into(), + )]); - RegexParser::new( - "#?([A-Z_]+|[0-9]+[A-Z_$])[A-Z0-9_$]*", - SyntaxKind::NakedIdentifier, - ) - .anti_template(&anti_template) - .to_matchable() + redshift_dialect.replace_grammar( + "WellKnownTextGeometrySegment", + Nothing::new().to_matchable(), + ); + + redshift_dialect.replace_grammar( + "JoinLikeClauseGrammar", + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Ref::new("FromPivotExpressionSegment").to_matchable(), + Ref::new("FromUnpivotExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + this.min_times(1); }) - .into(), + .to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ); + + redshift_dialect.replace_grammar( + "LiteralGrammar", + ansi_dialect.grammar("LiteralGrammar").copy( + Some(vec![ + Ref::new("MaxLiteralSegment").to_matchable(), + Ref::new("DollarNumericLiteralSegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, ), - ]); + ); redshift_dialect.patch_lexer_matchers(vec![Matcher::regex( "word", - r"#?[0-9a-zA-Z_]+[0-9a-zA-Z_$]*", + r#"#?[0-9a-zA-Z_]+[0-9a-zA-Z_$]*"#, SyntaxKind::Word, )]); @@ -243,12 +261,269 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), + ( + "MaxLiteralSegment".into(), + StringParser::new("max", SyntaxKind::MaxLiteral) + .to_matchable() + .into(), + ), ]); redshift_dialect.add([ + ( + "FromIntegrationClauseSegment".into(), + NodeMatcher::new(SyntaxKind::FromIntegrationClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Ref::keyword("SET").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ACCEPTINVCHARS").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("QUERY_ALL_STATES").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REFRESH_INTERVAL").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TRUNCATECOLUMNS").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("HISTORY_MODE").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "IamRoleClauseSegment".into(), + NodeMatcher::new(SyntaxKind::IamRoleClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("IAM_ROLE").to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "IsolationLevelClauseSegment".into(), + NodeMatcher::new(SyntaxKind::IsolationLevelClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ISOLATION").to_matchable(), + Ref::keyword("LEVEL").to_matchable(), + one_of(vec![ + Ref::keyword("SERIALIZABLE").to_matchable(), + Ref::keyword("SNAPSHOT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CollationClauseSegment".into(), + NodeMatcher::new(SyntaxKind::CollationClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("COLLATE").to_matchable(), + one_of(vec![ + Ref::keyword("CASE_SENSITIVE").to_matchable(), + Ref::keyword("CS").to_matchable(), + Ref::keyword("CASE_INSENSITIVE").to_matchable(), + Ref::keyword("CI").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ConnectionLimitSegment".into(), + NodeMatcher::new(SyntaxKind::ConnectionLimitSegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CONNECTION").to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("UNLIMITED").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateDatabaseWithOptionsSegment".into(), + NodeMatcher::new(SyntaxKind::CreateDatabaseWithOptions, |_dialect| { + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("OWNER").to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ConnectionLimitSegment").to_matchable(), + Ref::new("CollationClauseSegment").to_matchable(), + Ref::new("IsolationLevelClauseSegment").to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FromDatashareClauseSegment".into(), + NodeMatcher::new(SyntaxKind::FromDatashareClause, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("PERMISSIONS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::keyword("DATASHARE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("OF").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ACCOUNT").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("NAMESPACE").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ArnCatalogSchemaSegment".into(), + NodeMatcher::new(SyntaxKind::ArnCatalogSchemaSegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("ARN").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("DATA").to_matchable(), + Ref::keyword("CATALOG").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("NO").to_matchable(), + Ref::keyword("DATA").to_matchable(), + Ref::keyword("CATALOG").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateDatabaseStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("FromIntegrationClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::new("CreateDatabaseWithOptionsSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ArnCatalogSchemaSegment").to_matchable(), + Ref::new("IamRoleClauseSegment").to_matchable(), + Ref::new("FromDatashareClauseSegment").to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), ( "FromUnpivotExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::FromUnpivotExpression, |_| { + NodeMatcher::new(SyntaxKind::FromUnpivotExpression, |_dialect| { Sequence::new(vec![ Ref::keyword("UNPIVOT").to_matchable(), Sequence::new(vec![ @@ -294,7 +569,7 @@ pub fn raw_dialect() -> Dialect { ), ( "FromPivotExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::FromPivotExpression, |_| { + NodeMatcher::new(SyntaxKind::FromPivotExpression, |_dialect| { Sequence::new(vec![ Ref::keyword("PIVOT").to_matchable(), Bracketed::new(vec![ @@ -330,31 +605,11 @@ pub fn raw_dialect() -> Dialect { ), ( "DateTimeTypeIdentifier".into(), - NodeMatcher::new(SyntaxKind::DatetimeTypeIdentifier, |_| { + NodeMatcher::new(SyntaxKind::DatetimeTypeIdentifier, |_dialect| { one_of(vec![ Ref::keyword("DATE").to_matchable(), Ref::keyword("DATETIME").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("TIME").to_matchable(), - Ref::keyword("TIMESTAMP").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("WITHOUT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("TIME").to_matchable(), - Ref::keyword("ZONE").to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), + Ref::new("TimeWithTZGrammar").to_matchable(), one_of(vec![ Ref::keyword("TIMETZ").to_matchable(), Ref::keyword("TIMESTAMPTZ").to_matchable(), @@ -366,29 +621,30 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - redshift_dialect.replace_grammar( - "BracketedArguments", - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::keyword("MAX").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), - ); - - redshift_dialect.add([ + ( + "BracketedArguments".into(), + NodeMatcher::new(SyntaxKind::BracketedArguments, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::keyword("MAX").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), ( "DatatypeSegment".into(), - NodeMatcher::new(SyntaxKind::DataType, |_| { + NodeMatcher::new(SyntaxKind::DataType, |_dialect| { one_of(vec![ Ref::keyword("SMALLINT").to_matchable(), Ref::keyword("INT2").to_matchable(), @@ -463,6 +719,15 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), Ref::keyword("ANYELEMENT").to_matchable(), + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DotSegment").to_matchable(), + Ref::new("DatatypeIdentifierSegment").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable(), ]) .to_matchable() }) @@ -471,7 +736,7 @@ pub fn raw_dialect() -> Dialect { ), ( "DataFormatSegment".into(), - NodeMatcher::new(SyntaxKind::DataFormatSegment, |_| { + NodeMatcher::new(SyntaxKind::DataFormatSegment, |_dialect| { Sequence::new(vec![ Sequence::new(vec![ Ref::keyword("FORMAT").to_matchable(), @@ -538,8 +803,8 @@ pub fn raw_dialect() -> Dialect { ), ( "AuthorizationSegment".into(), - NodeMatcher::new(SyntaxKind::AuthorizationSegment, |_| { - any_set_of(vec![ + NodeMatcher::new(SyntaxKind::AuthorizationSegment, |_dialect| { + AnyNumberOf::new(vec![ one_of(vec![ Sequence::new(vec![ Ref::keyword("IAM_ROLE").to_matchable(), @@ -591,6 +856,9 @@ pub fn raw_dialect() -> Dialect { }) .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable() }) .to_matchable() @@ -598,8 +866,8 @@ pub fn raw_dialect() -> Dialect { ), ( "ColumnAttributeSegment".into(), - NodeMatcher::new(SyntaxKind::ColumnAttributeSegment, |_| { - any_set_of(vec![ + NodeMatcher::new(SyntaxKind::ColumnAttributeSegment, |_dialect| { + AnyNumberOf::new(vec![ Sequence::new(vec![ Ref::keyword("DEFAULT").to_matchable(), Ref::new("ExpressionSegment").to_matchable(), @@ -650,6 +918,9 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable() }) .to_matchable() @@ -657,8 +928,8 @@ pub fn raw_dialect() -> Dialect { ), ( "ColumnConstraintSegment".into(), - NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_| { - any_set_of(vec![ + NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_dialect| { + AnyNumberOf::new(vec![ one_of(vec![ Sequence::new(vec![ Ref::keyword("NOT").to_matchable(), @@ -684,6 +955,9 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable() }) .to_matchable() @@ -691,7 +965,7 @@ pub fn raw_dialect() -> Dialect { ), ( "AlterTableActionSegment".into(), - NodeMatcher::new(SyntaxKind::AlterTableActionSegment, |_| { + NodeMatcher::new(SyntaxKind::AlterTableActionSegment, |_dialect| { one_of(vec![ Sequence::new(vec![ Ref::keyword("ADD").to_matchable(), @@ -838,6 +1112,14 @@ pub fn raw_dialect() -> Dialect { this.optional(); }) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENCODE").to_matchable(), + Ref::new("ColumnEncodingGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), Sequence::new(vec![ Ref::keyword("COLLATE").to_matchable(), Ref::new("CollationReferenceSegment").to_matchable(), @@ -857,6 +1139,20 @@ pub fn raw_dialect() -> Dialect { Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPEND").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("IGNOREEXTRA").optional().to_matchable(), + Ref::keyword("FILLTARGET").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("LOCATION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) @@ -865,8 +1161,8 @@ pub fn raw_dialect() -> Dialect { ), ( "TableAttributeSegment".into(), - NodeMatcher::new(SyntaxKind::TableConstraint, |_| { - any_set_of(vec![ + NodeMatcher::new(SyntaxKind::TableConstraint, |_dialect| { + AnyNumberOf::new(vec![ Sequence::new(vec![ Ref::keyword("DISTSTYLE").to_matchable(), one_of(vec![ @@ -929,6 +1225,9 @@ pub fn raw_dialect() -> Dialect { }) .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable() }) .to_matchable() @@ -936,7 +1235,7 @@ pub fn raw_dialect() -> Dialect { ), ( "TableConstraintSegment".into(), - NodeMatcher::new(SyntaxKind::TableConstraint, |_| { + NodeMatcher::new(SyntaxKind::TableConstraint, |_dialect| { Sequence::new(vec![ Sequence::new(vec![ Ref::keyword("CONSTRAINT").to_matchable(), @@ -982,8 +1281,8 @@ pub fn raw_dialect() -> Dialect { .to_matchable(), Ref::keyword("REFERENCES").to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), - Sequence::new(vec![ - Bracketed::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ Ref::new("ColumnReferenceSegment").to_matchable(), ]) .to_matchable(), @@ -1001,7 +1300,7 @@ pub fn raw_dialect() -> Dialect { ), ( "LikeOptionSegment".into(), - NodeMatcher::new(SyntaxKind::LikeOptionSegment, |_| { + NodeMatcher::new(SyntaxKind::LikeOptionSegment, |_dialect| { Sequence::new(vec![ one_of(vec![ Ref::keyword("INCLUDING").to_matchable(), @@ -1017,7 +1316,7 @@ pub fn raw_dialect() -> Dialect { ), ( "CreateTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateTableStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateTableStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::keyword("LOCAL").optional().to_matchable(), @@ -1027,7 +1326,7 @@ pub fn raw_dialect() -> Dialect { Ref::new("TableReferenceSegment").to_matchable(), Bracketed::new(vec![ Delimited::new(vec![ - AnyNumberOf::new(vec![ + one_of(vec![ Sequence::new(vec![ Ref::new("ColumnReferenceSegment").to_matchable(), Ref::new("DatatypeSegment").to_matchable(), @@ -1088,7 +1387,7 @@ pub fn raw_dialect() -> Dialect { ), ( "CreateTableAsStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateTableAsStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateTableAsStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Sequence::new(vec![ @@ -1137,7 +1436,7 @@ pub fn raw_dialect() -> Dialect { ), ( "CreateModelStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateModelStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateModelStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::keyword("MODEL").to_matchable(), @@ -1334,7 +1633,7 @@ pub fn raw_dialect() -> Dialect { ), ( "ShowModelStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ShowModelStatement, |_| { + NodeMatcher::new(SyntaxKind::ShowModelStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("SHOW").to_matchable(), Ref::keyword("MODEL").to_matchable(), @@ -1351,7 +1650,7 @@ pub fn raw_dialect() -> Dialect { ), ( "CreateExternalTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateExternalTableStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateExternalTableStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::keyword("EXTERNAL").to_matchable(), @@ -1458,7 +1757,7 @@ pub fn raw_dialect() -> Dialect { ), ( "CreateExternalTableAsStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateExternalTableStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateExternalTableStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::keyword("EXTERNAL").to_matchable(), @@ -1515,7 +1814,7 @@ pub fn raw_dialect() -> Dialect { ), ( "CreateExternalSchemaStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateExternalSchemaStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateExternalSchemaStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::keyword("EXTERNAL").to_matchable(), @@ -1537,10 +1836,12 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("POSTGRES").to_matchable(), Ref::keyword("MYSQL").to_matchable(), Ref::keyword("KINESIS").to_matchable(), + Ref::keyword("MSK").to_matchable(), Ref::keyword("REDSHIFT").to_matchable(), + Ref::keyword("KAFKA").to_matchable(), ]) .to_matchable(), - any_set_of(vec![ + AnyNumberOf::new(vec![ Sequence::new(vec![ Ref::keyword("DATABASE").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), @@ -1579,8 +1880,26 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SECRET_ARN").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("AUTHENTICATION").to_matchable(), + one_of(vec![ + Ref::keyword("NONE").to_matchable(), + Ref::keyword("IAM").to_matchable(), + Ref::keyword("MTLS").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("AUTHENTICATION_ARN").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SECRET_ARN").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ @@ -1599,6 +1918,7 @@ pub fn raw_dialect() -> Dialect { .to_matchable(), ]) .config(|this| { + this.max_times_per_element = Some(1); this.optional(); }) .to_matchable(), @@ -1610,7 +1930,7 @@ pub fn raw_dialect() -> Dialect { ), ( "CreateLibraryStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateLibraryStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateLibraryStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::new("OrReplaceGrammar").optional().to_matchable(), @@ -1620,7 +1940,7 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("PLPYTHONU").to_matchable(), Ref::keyword("FROM").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), - any_set_of(vec![ + AnyNumberOf::new(vec![ Ref::new("AuthorizationSegment").to_matchable(), Sequence::new(vec![ Ref::keyword("REGION").to_matchable(), @@ -1632,6 +1952,9 @@ pub fn raw_dialect() -> Dialect { }) .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), ]) .to_matchable() @@ -1641,14 +1964,14 @@ pub fn raw_dialect() -> Dialect { ), ( "UnloadStatementSegment".into(), - NodeMatcher::new(SyntaxKind::UnloadStatement, |_| { + NodeMatcher::new(SyntaxKind::UnloadStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("UNLOAD").to_matchable(), Bracketed::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) .to_matchable(), Ref::keyword("TO").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), - any_set_of(vec![ + AnyNumberOf::new(vec![ Ref::new("AuthorizationSegment").to_matchable(), Sequence::new(vec![ Ref::keyword("REGION").to_matchable(), @@ -1705,6 +2028,28 @@ pub fn raw_dialect() -> Dialect { this.optional(); }) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTENSION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("PARALLEL").to_matchable(), + one_of(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("OFF").to_matchable(), + Ref::keyword("TRUE").to_matchable(), + Ref::keyword("FALSE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), one_of(vec![ Sequence::new(vec![ Ref::keyword("DELIMITER").to_matchable(), @@ -1749,7 +2094,7 @@ pub fn raw_dialect() -> Dialect { this.optional(); }) .to_matchable(), - any_set_of(vec![ + AnyNumberOf::new(vec![ one_of(vec![ Ref::keyword("MAXFILESIZE").to_matchable(), Ref::keyword("ROWGROUPSIZE").to_matchable(), @@ -1764,6 +2109,7 @@ pub fn raw_dialect() -> Dialect { .to_matchable(), ]) .config(|this| { + this.max_times_per_element = Some(1); this.optional(); }) .to_matchable(), @@ -1781,6 +2127,9 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("ADDQUOTES").optional().to_matchable(), Ref::keyword("HEADER").optional().to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), ]) .to_matchable() @@ -1788,233 +2137,238 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - redshift_dialect.replace_grammar( - "CopyStatementSegment", - Sequence::new(vec![ - Ref::keyword("COPY").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - any_set_of(vec![ - Ref::new("AuthorizationSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("REGION").to_matchable(), - Ref::keyword("AS").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - Ref::new("CompressionTypeGrammar").optional().to_matchable(), - Ref::new("DataFormatSegment").optional().to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("DELIMITER").to_matchable(), - Ref::keyword("AS").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FIXEDWIDTH").to_matchable(), - Ref::keyword("AS").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ENCRYPTED").to_matchable(), - Ref::keyword("AUTO").optional().to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - Ref::keyword("MANIFEST").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("COMPROWS").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MAXERROR").to_matchable(), - Ref::keyword("AS").optional().to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COMPUPDATE").to_matchable(), - one_of(vec![ - Ref::keyword("PRESET").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("OFF").to_matchable(), - Ref::keyword("TRUE").to_matchable(), - Ref::keyword("FALSE").to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("STATUPDATE").to_matchable(), - one_of(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("OFF").to_matchable(), - Ref::keyword("TRUE").to_matchable(), - Ref::keyword("FALSE").to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - Ref::keyword("NOLOAD").optional().to_matchable(), - Ref::keyword("ACCEPTANYDATE").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("ACCEPTINVCHARS").to_matchable(), - Ref::keyword("AS").optional().to_matchable(), - Ref::new("QuotedLiteralSegment").optional().to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - Ref::keyword("BLANKSASNULL").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("DATEFORMAT").to_matchable(), - Ref::keyword("AS").optional().to_matchable(), - one_of(vec![ - Ref::keyword("AUTO").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - Ref::keyword("EMPTYASNULL").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("ENCODING").to_matchable(), - Ref::keyword("AS").optional().to_matchable(), - one_of(vec![ - Ref::keyword("UTF8").to_matchable(), - Ref::keyword("UTF16").to_matchable(), - Ref::keyword("UTF16BE").to_matchable(), - Ref::keyword("UTF16LE").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - Ref::keyword("ESCAPE").optional().to_matchable(), - Ref::keyword("EXPLICIT_IDS").optional().to_matchable(), - Ref::keyword("FILLRECORD").optional().to_matchable(), - Ref::keyword("IGNOREBLANKLINES").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("IGNOREHEADER").to_matchable(), - Ref::keyword("AS").optional().to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NULL").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("READRATIO").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - Ref::keyword("REMOVEQUOTES").optional().to_matchable(), - Ref::keyword("ROUNDEC").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("TIMEFORMAT").to_matchable(), - Ref::keyword("AS").optional().to_matchable(), - one_of(vec![ - Ref::keyword("AUTO").to_matchable(), - Ref::keyword("EPOCHSECS").to_matchable(), - Ref::keyword("EPOCHMILLISECS").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.optional(); - }) - .to_matchable(), - Ref::keyword("TRIMBLANKS").optional().to_matchable(), - Ref::keyword("TRUNCATECOLUMNS").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - redshift_dialect.add([ ( - "InsertStatementSegment".into(), - NodeMatcher::new(SyntaxKind::InsertStatement, |_| { + "CopyStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CopyStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("INSERT").to_matchable(), - Ref::keyword("INTO").to_matchable(), + Ref::keyword("COPY").to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), - one_of(vec![ - optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) - .to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("AuthorizationSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::keyword("VALUES").to_matchable(), + Ref::keyword("REGION").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - one_of(vec![ - Ref::new("ValuesClauseSegment").to_matchable(), - optionally_bracketed(vec![ - Ref::new("SelectableGrammar").to_matchable(), - ]) - .to_matchable(), + Ref::new("CompressionTypeGrammar").optional().to_matchable(), + Ref::new("DataFormatSegment").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("DELIMITER").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), - ]) + Sequence::new(vec![ + Ref::keyword("FIXEDWIDTH").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENCRYPTED").to_matchable(), + Ref::keyword("AUTO").optional().to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("MANIFEST").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMPROWS").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MAXERROR").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMPUPDATE").to_matchable(), + one_of(vec![ + Ref::keyword("PRESET").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("OFF").to_matchable(), + Ref::keyword("TRUE").to_matchable(), + Ref::keyword("FALSE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STATUPDATE").to_matchable(), + one_of(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("OFF").to_matchable(), + Ref::keyword("TRUE").to_matchable(), + Ref::keyword("FALSE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("NOLOAD").optional().to_matchable(), + Ref::keyword("ACCEPTANYDATE").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("ACCEPTINVCHARS").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Ref::new("QuotedLiteralSegment").optional().to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("BLANKSASNULL").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATEFORMAT").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + one_of(vec![ + Ref::keyword("AUTO").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("EMPTYASNULL").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENCODING").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + one_of(vec![ + Ref::keyword("UTF8").to_matchable(), + Ref::keyword("UTF16").to_matchable(), + Ref::keyword("UTF16BE").to_matchable(), + Ref::keyword("UTF16LE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("ESCAPE").optional().to_matchable(), + Ref::keyword("EXPLICIT_IDS").optional().to_matchable(), + Ref::keyword("FILLRECORD").optional().to_matchable(), + Ref::keyword("IGNOREBLANKLINES").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("IGNOREHEADER").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULL").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("READRATIO").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("REMOVEQUOTES").optional().to_matchable(), + Ref::keyword("ROUNDEC").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("TIMEFORMAT").to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + one_of(vec![ + Ref::keyword("AUTO").to_matchable(), + Ref::keyword("EPOCHSECS").to_matchable(), + Ref::keyword("EPOCHMILLISECS").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("TRIMBLANKS").optional().to_matchable(), + Ref::keyword("TRUNCATECOLUMNS").optional().to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "InsertStatementSegment".into(), + NodeMatcher::new(SyntaxKind::InsertStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("VALUES").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + one_of(vec![ + Ref::new("ValuesClauseSegment").to_matchable(), + optionally_bracketed(vec![ + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) .to_matchable(), ]) .to_matchable(), @@ -2026,7 +2380,7 @@ pub fn raw_dialect() -> Dialect { ), ( "CreateSchemaStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateSchemaStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateSchemaStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::keyword("SCHEMA").to_matchable(), @@ -2060,29 +2414,30 @@ pub fn raw_dialect() -> Dialect { ), ( "ProcedureParameterListSegment".into(), - NodeMatcher::new(SyntaxKind::ProcedureParameterList, |_| { - let param_type = one_of(vec![ - Ref::keyword("REFCURSOR").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]); + NodeMatcher::new(SyntaxKind::ProcedureParameterList, |_dialect| { Bracketed::new(vec![ Delimited::new(vec![ Sequence::new(vec![ AnyNumberOf::new(vec![ Ref::new("ParameterNameSegment") .exclude(one_of(vec![ - param_type.clone().to_matchable(), + one_of(vec![ + Ref::keyword("REFCURSOR").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), Ref::new("ArgModeGrammar").to_matchable(), ])) .optional() .to_matchable(), Ref::new("ArgModeGrammar").optional().to_matchable(), ]) - .config(|this| { - this.max_times_per_element = 1.into(); - }) .to_matchable(), - param_type.clone().to_matchable(), + one_of(vec![ + Ref::keyword("REFCURSOR").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -2098,13 +2453,14 @@ pub fn raw_dialect() -> Dialect { ), ( "CreateProcedureStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateProcedureStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateProcedureStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::new("OrReplaceGrammar").optional().to_matchable(), Ref::keyword("PROCEDURE").to_matchable(), Ref::new("FunctionNameSegment").to_matchable(), Ref::new("ProcedureParameterListSegment").to_matchable(), + Ref::keyword("NONATOMIC").optional().to_matchable(), Ref::new("FunctionDefinitionGrammar").to_matchable(), ]) .to_matchable() @@ -2114,7 +2470,7 @@ pub fn raw_dialect() -> Dialect { ), ( "AlterProcedureStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterProcedureStatement, |_| { + NodeMatcher::new(SyntaxKind::AlterProcedureStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ALTER").to_matchable(), Ref::keyword("PROCEDURE").to_matchable(), @@ -2154,7 +2510,7 @@ pub fn raw_dialect() -> Dialect { ), ( "DropProcedureStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropProcedureStatement, |_| { + NodeMatcher::new(SyntaxKind::DropProcedureStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("DROP").to_matchable(), Ref::keyword("PROCEDURE").to_matchable(), @@ -2175,30 +2531,34 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - redshift_dialect.replace_grammar( - "AlterDefaultPrivilegesSchemaObjectsSegment", - postgres_dialect - .grammar("AlterDefaultPrivilegesSchemaObjectsSegment") - .match_grammar(&postgres_dialect) - .unwrap() - .copy( - Some(vec![ - Sequence::new(vec![Ref::keyword("PROCEDURES").to_matchable()]).to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ), - ); - - redshift_dialect.add([ + ( + "AlterDefaultPrivilegesSchemaObjectsSegment".into(), + NodeMatcher::new(SyntaxKind::AlterDefaultPrivilegesSchemaObject, |_dialect| { + { + let dialect = super::postgres::raw_dialect(); + dialect + .grammar("AlterDefaultPrivilegesSchemaObjectsSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Sequence::new(vec![Ref::keyword("PROCEDURES").to_matchable()]) + .to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), ( "DeclareStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DeclareStatement, |_| { + NodeMatcher::new(SyntaxKind::DeclareStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("DECLARE").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), @@ -2213,7 +2573,7 @@ pub fn raw_dialect() -> Dialect { ), ( "FetchStatementSegment".into(), - NodeMatcher::new(SyntaxKind::FetchStatement, |_| { + NodeMatcher::new(SyntaxKind::FetchStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("FETCH").to_matchable(), one_of(vec![ @@ -2240,7 +2600,7 @@ pub fn raw_dialect() -> Dialect { ), ( "CloseStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CloseStatement, |_| { + NodeMatcher::new(SyntaxKind::CloseStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CLOSE").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), @@ -2252,7 +2612,7 @@ pub fn raw_dialect() -> Dialect { ), ( "AltereDatashareStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateDatashareStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateDatashareStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ALTER").to_matchable(), Ref::keyword("DATASHARE").to_matchable(), @@ -2340,7 +2700,7 @@ pub fn raw_dialect() -> Dialect { ), ( "CreateDatashareStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateDatashareStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateDatashareStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::keyword("DATASHARE").to_matchable(), @@ -2367,7 +2727,7 @@ pub fn raw_dialect() -> Dialect { ), ( "DescDatashareStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DescDatashareStatement, |_| { + NodeMatcher::new(SyntaxKind::DescDatashareStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("DESC").to_matchable(), Ref::keyword("DATASHARE").to_matchable(), @@ -2397,7 +2757,7 @@ pub fn raw_dialect() -> Dialect { ), ( "DropDatashareStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropDatashareStatement, |_| { + NodeMatcher::new(SyntaxKind::DropDatashareStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("DROP").to_matchable(), Ref::keyword("DATASHARE").to_matchable(), @@ -2410,7 +2770,7 @@ pub fn raw_dialect() -> Dialect { ), ( "ShowDatasharesStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ShowDatasharesStatement, |_| { + NodeMatcher::new(SyntaxKind::ShowDatasharesStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("SHOW").to_matchable(), Ref::keyword("DATASHARES").to_matchable(), @@ -2430,7 +2790,7 @@ pub fn raw_dialect() -> Dialect { ), ( "GrantUsageDatashareStatementSegment".into(), - NodeMatcher::new(SyntaxKind::GrantDatashareStatement, |_| { + NodeMatcher::new(SyntaxKind::GrantDatashareStatement, |_dialect| { Sequence::new(vec![ one_of(vec![ Ref::keyword("GRANT").to_matchable(), @@ -2479,7 +2839,7 @@ pub fn raw_dialect() -> Dialect { ), ( "CreateRlsPolicyStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateRlsPolicyStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateRlsPolicyStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::keyword("RLS").to_matchable(), @@ -2525,7 +2885,7 @@ pub fn raw_dialect() -> Dialect { ), ( "ManageRlsPolicyStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ManageRlsPolicyStatement, |_| { + NodeMatcher::new(SyntaxKind::ManageRlsPolicyStatement, |_dialect| { Sequence::new(vec![ one_of(vec![ Ref::keyword("ATTACH").to_matchable(), @@ -2564,7 +2924,7 @@ pub fn raw_dialect() -> Dialect { ), ( "DropRlsPolicyStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropRlsPolicyStatement, |_| { + NodeMatcher::new(SyntaxKind::DropRlsPolicyStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("DROP").to_matchable(), Ref::keyword("RLS").to_matchable(), @@ -2587,7 +2947,7 @@ pub fn raw_dialect() -> Dialect { ), ( "AnalyzeCompressionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AnalyzeCompressionStatement, |_| { + NodeMatcher::new(SyntaxKind::AnalyzeCompressionStatement, |_dialect| { Sequence::new(vec![ one_of(vec![ Ref::keyword("ANALYZE").to_matchable(), @@ -2624,94 +2984,99 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - redshift_dialect.replace_grammar( - "VacuumStatementSegment", - Sequence::new(vec![ - Ref::keyword("VACUUM").to_matchable(), - one_of(vec![ - Ref::keyword("FULL").to_matchable(), - Ref::keyword("REINDEX").to_matchable(), - Ref::keyword("RECLUSTER").to_matchable(), + ( + "VacuumStatementSegment".into(), + NodeMatcher::new(SyntaxKind::VacuumStatement, |_dialect| { Sequence::new(vec![ + Ref::keyword("VACUUM").to_matchable(), one_of(vec![ - Ref::keyword("SORT").to_matchable(), - Ref::keyword("DELETE").to_matchable(), + Ref::keyword("FULL").to_matchable(), + Ref::keyword("REINDEX").to_matchable(), + Ref::keyword("RECLUSTER").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("SORT").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("ONLY").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("TableReferenceSegment").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("TO").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("PERCENT").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("ONLY").to_matchable(), + Ref::keyword("BOOST").optional().to_matchable(), ]) - .to_matchable(), - ]) - .config(|this| { - this.optional(); + .to_matchable() }) - .to_matchable(), - Ref::new("TableReferenceSegment").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("TO").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::keyword("PERCENT").to_matchable(), - ]) - .config(|this| { - this.optional(); + .to_matchable() + .into(), + ), + ( + "StatementSegment".into(), + NodeMatcher::new(SyntaxKind::Statement, |_dialect| { + { + let dialect = super::postgres::raw_dialect(); + dialect + .grammar("StatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("CreateLibraryStatementSegment").to_matchable(), + Ref::new("CreateGroupStatementSegment").to_matchable(), + Ref::new("AlterUserStatementSegment").to_matchable(), + Ref::new("AlterGroupStatementSegment").to_matchable(), + Ref::new("CreateExternalTableAsStatementSegment").to_matchable(), + Ref::new("CreateExternalTableStatementSegment").to_matchable(), + Ref::new("CreateExternalSchemaStatementSegment").to_matchable(), + Ref::new("DataFormatSegment").to_matchable(), + Ref::new("UnloadStatementSegment").to_matchable(), + Ref::new("CopyStatementSegment").to_matchable(), + Ref::new("ShowModelStatementSegment").to_matchable(), + Ref::new("CreateDatashareStatementSegment").to_matchable(), + Ref::new("DescDatashareStatementSegment").to_matchable(), + Ref::new("DropDatashareStatementSegment").to_matchable(), + Ref::new("ShowDatasharesStatementSegment").to_matchable(), + Ref::new("AltereDatashareStatementSegment").to_matchable(), + Ref::new("DeclareStatementSegment").to_matchable(), + Ref::new("FetchStatementSegment").to_matchable(), + Ref::new("CloseStatementSegment").to_matchable(), + Ref::new("AnalyzeCompressionStatementSegment").to_matchable(), + Ref::new("AlterProcedureStatementSegment").to_matchable(), + Ref::new("CallStatementSegment").to_matchable(), + Ref::new("CreateRlsPolicyStatementSegment").to_matchable(), + Ref::new("ManageRlsPolicyStatementSegment").to_matchable(), + Ref::new("DropRlsPolicyStatementSegment").to_matchable(), + Ref::new("CreateExternalFunctionStatementSegment").to_matchable(), + Ref::new("GrantUsageDatashareStatementSegment").to_matchable(), + ]), + None, + None, + Some(vec![Ref::new("ShowStatementSegment").to_matchable()]), + vec![], + false, + ) }) - .to_matchable(), - Ref::keyword("BOOST").optional().to_matchable(), - ]) - .to_matchable(), - ); - - redshift_dialect.add([]); - - redshift_dialect.replace_grammar( - "StatementSegment", - postgres_dialect - .grammar("StatementSegment") - .match_grammar(&postgres_dialect) - .unwrap() - .copy( - Some(vec![ - Ref::new("CreateLibraryStatementSegment").to_matchable(), - Ref::new("CreateGroupStatementSegment").to_matchable(), - Ref::new("AlterUserStatementSegment").to_matchable(), - Ref::new("AlterGroupStatementSegment").to_matchable(), - Ref::new("CreateExternalTableAsStatementSegment").to_matchable(), - Ref::new("CreateExternalTableStatementSegment").to_matchable(), - Ref::new("CreateExternalSchemaStatementSegment").to_matchable(), - Ref::new("DataFormatSegment").to_matchable(), - Ref::new("UnloadStatementSegment").to_matchable(), - Ref::new("CopyStatementSegment").to_matchable(), - Ref::new("ShowModelStatementSegment").to_matchable(), - Ref::new("CreateDatashareStatementSegment").to_matchable(), - Ref::new("DescDatashareStatementSegment").to_matchable(), - Ref::new("DropDatashareStatementSegment").to_matchable(), - Ref::new("ShowDatasharesStatementSegment").to_matchable(), - Ref::new("AltereDatashareStatementSegment").to_matchable(), - Ref::new("DeclareStatementSegment").to_matchable(), - Ref::new("FetchStatementSegment").to_matchable(), - Ref::new("CloseStatementSegment").to_matchable(), - Ref::new("AnalyzeCompressionStatementSegment").to_matchable(), - Ref::new("AlterProcedureStatementSegment").to_matchable(), - Ref::new("CallStatementSegment").to_matchable(), - Ref::new("CreateRlsPolicyStatementSegment").to_matchable(), - Ref::new("ManageRlsPolicyStatementSegment").to_matchable(), - Ref::new("DropRlsPolicyStatementSegment").to_matchable(), - Ref::new("CreateExternalFunctionStatementSegment").to_matchable(), - Ref::new("GrantUsageDatashareStatementSegment").to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ), - ); - - redshift_dialect.add([ + .to_matchable() + .into(), + ), ( "PartitionedBySegment".into(), - NodeMatcher::new(SyntaxKind::PartitionedBySegment, |_| { + NodeMatcher::new(SyntaxKind::PartitionedBySegment, |_dialect| { Sequence::new(vec![ Ref::keyword("PARTITIONED").to_matchable(), Ref::keyword("BY").to_matchable(), @@ -2734,8 +3099,8 @@ pub fn raw_dialect() -> Dialect { ), ( "RowFormatDelimitedSegment".into(), - NodeMatcher::new(SyntaxKind::RowFormatDelimitedSegment, |_| { - any_set_of(vec![ + NodeMatcher::new(SyntaxKind::RowFormatDelimitedSegment, |_dialect| { + AnyNumberOf::new(vec![ Sequence::new(vec![ Ref::keyword("FIELDS").to_matchable(), Ref::keyword("TERMINATED").to_matchable(), @@ -2752,6 +3117,7 @@ pub fn raw_dialect() -> Dialect { .to_matchable(), ]) .config(|this| { + this.max_times_per_element = Some(1); this.optional(); }) .to_matchable() @@ -2759,80 +3125,75 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - redshift_dialect.replace_grammar( - "CreateUserStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - Ref::keyword("WITH").optional().to_matchable(), - Ref::keyword("PASSWORD").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::keyword("DISABLE").to_matchable(), - ]) - .to_matchable(), - any_set_of(vec![ - one_of(vec![ - Ref::keyword("CREATEDB").to_matchable(), - Ref::keyword("NOCREATEDB").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("CREATEUSER").to_matchable(), - Ref::keyword("NOCREATEUSER").to_matchable(), - ]) - .to_matchable(), + ( + "CreateUserStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateUserStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("SYSLOG").to_matchable(), - Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + Ref::keyword("WITH").optional().to_matchable(), + Ref::keyword("PASSWORD").to_matchable(), one_of(vec![ - Ref::keyword("RESTRICTED").to_matchable(), - Ref::keyword("UNRESTRICTED").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("DISABLE").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("IN").to_matchable(), - Ref::keyword("GROUP").to_matchable(), - Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) + AnyNumberOf::new(vec![ + one_of(vec![ + Ref::keyword("CREATEDB").to_matchable(), + Ref::keyword("NOCREATEDB").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("CREATEUSER").to_matchable(), + Ref::keyword("NOCREATEUSER").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SYSLOG").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + one_of(vec![ + Ref::keyword("RESTRICTED").to_matchable(), + Ref::keyword("UNRESTRICTED").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IN").to_matchable(), + Ref::keyword("GROUP").to_matchable(), + Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("VALID").to_matchable(), + Ref::keyword("UNTIL").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ConnectionLimitSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SESSION").to_matchable(), + Ref::keyword("TIMEOUT").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("VALID").to_matchable(), - Ref::keyword("UNTIL").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CONNECTION").to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::keyword("UNLIMITED").to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SESSION").to_matchable(), - Ref::keyword("TIMEOUT").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - redshift_dialect.add([ + .to_matchable() + }) + .to_matchable() + .into(), + ), ( "CreateGroupStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateGroup, |_| { + NodeMatcher::new(SyntaxKind::CreateGroup, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::keyword("GROUP").to_matchable(), @@ -2855,13 +3216,13 @@ pub fn raw_dialect() -> Dialect { ), ( "AlterUserStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterUserStatement, |_| { + NodeMatcher::new(SyntaxKind::AlterUserStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ALTER").to_matchable(), Ref::keyword("USER").to_matchable(), Ref::new("RoleReferenceSegment").to_matchable(), Ref::keyword("WITH").optional().to_matchable(), - any_set_of(vec![ + AnyNumberOf::new(vec![ one_of(vec![ Ref::keyword("CREATEDB").to_matchable(), Ref::keyword("NOCREATEDB").to_matchable(), @@ -2906,16 +3267,7 @@ pub fn raw_dialect() -> Dialect { Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CONNECTION").to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::keyword("UNLIMITED").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::new("ConnectionLimitSegment").to_matchable(), one_of(vec![ Sequence::new(vec![ Ref::keyword("SESSION").to_matchable(), @@ -2956,7 +3308,8 @@ pub fn raw_dialect() -> Dialect { .to_matchable(), ]) .config(|this| { - this.min_times = 1; + this.max_times_per_element = Some(1); + this.min_times(1); }) .to_matchable(), ]) @@ -2967,7 +3320,7 @@ pub fn raw_dialect() -> Dialect { ), ( "AlterGroupStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterGroup, |_| { + NodeMatcher::new(SyntaxKind::AlterGroup, |_dialect| { Sequence::new(vec![ Ref::keyword("ALTER").to_matchable(), Ref::keyword("GROUP").to_matchable(), @@ -3000,7 +3353,7 @@ pub fn raw_dialect() -> Dialect { ), ( "TransactionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::TransactionStatement, |_| { + NodeMatcher::new(SyntaxKind::TransactionStatement, |_dialect| { Sequence::new(vec![ one_of(vec![ Ref::keyword("BEGIN").to_matchable(), @@ -3070,7 +3423,7 @@ pub fn raw_dialect() -> Dialect { ), ( "AlterSchemaStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterSchemaStatement, |_| { + NodeMatcher::new(SyntaxKind::AlterSchemaStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ALTER").to_matchable(), Ref::keyword("SCHEMA").to_matchable(), @@ -3099,7 +3452,7 @@ pub fn raw_dialect() -> Dialect { ), ( "LockTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::LockTableStatement, |_| { + NodeMatcher::new(SyntaxKind::LockTableStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("LOCK").to_matchable(), Ref::keyword("TABLE").optional().to_matchable(), @@ -3111,69 +3464,74 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - redshift_dialect.replace_grammar( - "TableExpressionSegment", - ansi_dialect - .grammar("TableExpressionSegment") - .match_grammar(&ansi_dialect) - .unwrap() - .copy( - Some(vec![ - Ref::new("ObjectUnpivotSegment").optional().to_matchable(), - Ref::new("ArrayUnnestSegment").optional().to_matchable(), - ]), - None, - Some(Ref::new("TableReferenceSegment").to_matchable()), - None, - Vec::new(), - false, - ), - ); - - redshift_dialect.add([( - "ObjectUnpivotSegment".into(), - NodeMatcher::new(SyntaxKind::ObjectUnpivoting, |_| { - Sequence::new(vec![ - Ref::keyword("UNPIVOT").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("AT").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) + ( + "TableExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::TableExpression, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("TableExpressionSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("ObjectUnpivotSegment").optional().to_matchable(), + Ref::new("ArrayUnnestSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("TableReferenceSegment").to_matchable()), + None, + vec![], + false, + ) + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - redshift_dialect.replace_grammar( - "ArrayAccessorSegment", - Sequence::new(vec![ - AnyNumberOf::new(vec![ - Bracketed::new(vec![ - one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + .into(), + ), + ( + "ObjectUnpivotSegment".into(), + NodeMatcher::new(SyntaxKind::ObjectUnpivoting, |_dialect| { + Sequence::new(vec![ + Ref::keyword("UNPIVOT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("AT").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ArrayAccessorSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayAccessor, |_dialect| { + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Bracketed::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.bracket_type("square"); + }) + .to_matchable(), ]) .to_matchable(), ]) - .config(|this| { - this.bracket_type = "square"; - }) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - redshift_dialect.add([ + .to_matchable() + }) + .to_matchable() + .into(), + ), ( "ArrayUnnestSegment".into(), - NodeMatcher::new(SyntaxKind::ArrayUnnesting, |_| { + NodeMatcher::new(SyntaxKind::ArrayUnnesting, |_dialect| { Sequence::new(vec![ Ref::new("ObjectReferenceSegment").to_matchable(), Ref::keyword("AS").to_matchable(), @@ -3188,7 +3546,7 @@ pub fn raw_dialect() -> Dialect { ), ( "CallStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CallStatement, |_| { + NodeMatcher::new(SyntaxKind::CallStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CALL").to_matchable(), Ref::new("FunctionSegment").to_matchable(), @@ -3198,216 +3556,219 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - redshift_dialect.replace_grammar( - "SelectClauseModifierSegment", - postgres_dialect - .grammar("SelectClauseModifierSegment") - .match_grammar(&postgres_dialect) - .unwrap() - .copy( - Some(vec![ - Sequence::new(vec![ - Ref::keyword("TOP").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ), - ); - - redshift_dialect.add([( - "ConvertFunctionNameSegment".into(), - NodeMatcher::new(SyntaxKind::FunctionName, |_| { - Sequence::new(vec![Ref::keyword("CONVERT").to_matchable()]).to_matchable() - }) - .to_matchable() - .into(), - )]); - - redshift_dialect.replace_grammar( - "FunctionSegment", - one_of(vec![ - Sequence::new(vec![ - Sequence::new(vec![ - Ref::new("DatePartFunctionNameSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("DatetimeUnitSegment").to_matchable(), - Ref::new("FunctionContentsGrammar") - .optional() - .to_matchable(), + ( + "SelectClauseModifierSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClauseModifier, |_dialect| { + { + let dialect = super::postgres::raw_dialect(); + dialect + .grammar("SelectClauseModifierSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Sequence::new(vec![ + Ref::keyword("TOP").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "ConvertFunctionNameSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionName, |_dialect| { + Sequence::new(vec![Ref::keyword("CONVERT").to_matchable()]).to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FunctionSegment".into(), + NodeMatcher::new(SyntaxKind::Function, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Sequence::new(vec![ + Ref::new("DatePartFunctionNameSegment").to_matchable(), + Ref::new("DateTimeFunctionContentsSegment").to_matchable(), ]) .to_matchable(), ]) - .config(|this| { - this.parse_mode = ParseMode::Greedy; - }) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::new("FunctionNameSegment") - .exclude(one_of(vec![ - Ref::new("DatePartFunctionNameSegment").to_matchable(), - Ref::new("ValuesClauseSegment").to_matchable(), - Ref::new("ConvertFunctionNameSegment").to_matchable(), - ])) - .to_matchable(), + Sequence::new(vec![ Sequence::new(vec![ - Ref::keyword("APPROXIMATE").to_matchable(), - Ref::new("FunctionNameSegment") - .exclude(one_of(vec![ - Ref::new("DatePartFunctionNameSegment").to_matchable(), - Ref::new("ValuesClauseSegment").to_matchable(), - Ref::new("ConvertFunctionNameSegment").to_matchable(), - ])) + one_of(vec![ + Ref::new("FunctionNameSegment") + .exclude(one_of(vec![ + Ref::new("DatePartFunctionNameSegment").to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + Ref::new("ConvertFunctionNameSegment").to_matchable(), + ])) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPROXIMATE").to_matchable(), + Ref::new("FunctionNameSegment") + .exclude(one_of(vec![ + Ref::new("DatePartFunctionNameSegment").to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + Ref::new("ConvertFunctionNameSegment").to_matchable(), + ])) + .to_matchable(), + ]) .to_matchable(), + ]) + .to_matchable(), + Ref::new("FunctionContentsSegment").to_matchable(), ]) .to_matchable(), + Ref::new("PostFunctionGrammar").optional().to_matchable(), ]) .to_matchable(), - Bracketed::new(vec![ - Ref::new("FunctionContentsGrammar") - .optional() - .to_matchable(), + Sequence::new(vec![ + Ref::new("ConvertFunctionNameSegment").to_matchable(), + Ref::new("ConvertFunctionContentsSegment").to_matchable(), ]) - .config(|this| { - this.parse_mode = ParseMode::Greedy; - }) .to_matchable(), ]) - .to_matchable(), - Ref::new("PostFunctionGrammar").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("ConvertFunctionNameSegment").to_matchable(), - Bracketed::new(vec![ - Ref::new("DatatypeSegment").to_matchable(), - Ref::new("CommaSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - redshift_dialect.add([]); - - redshift_dialect.replace_grammar( - "FromClauseSegment", - Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Delimited::new(vec![ - optionally_bracketed(vec![Ref::new("FromExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - redshift_dialect.add([( - "CreateViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateViewStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - Ref::keyword("AS").to_matchable(), - optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) - .to_matchable(), - Ref::new("WithNoSchemaBindingClauseSegment") - .optional() + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ConvertFunctionContentsSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionContents, |_dialect| { + Sequence::new(vec![ + Bracketed::new(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) .to_matchable(), - ]) + ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - redshift_dialect.replace_grammar( - "CreateMaterializedViewStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("BACKUP").to_matchable(), - one_of(vec![ - Ref::keyword("YES").to_matchable(), - Ref::keyword("NO").to_matchable(), + .into(), + ), + ( + "FromClauseSegment".into(), + NodeMatcher::new(SyntaxKind::FromClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Delimited::new(vec![ + optionally_bracketed(vec![ + Ref::new("FromExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) - .to_matchable(), - ]) - .config(|this| { - this.optional(); + .to_matchable() }) - .to_matchable(), - Ref::new("TableAttributeSegment").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("AUTO").to_matchable(), - Ref::keyword("REFRESH").to_matchable(), - one_of(vec![ - Ref::keyword("YES").to_matchable(), - Ref::keyword("NO").to_matchable(), + .to_matchable() + .into(), + ), + ( + "CreateViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + Ref::new("WithNoSchemaBindingClauseSegment") + .optional() + .to_matchable(), ]) - .to_matchable(), - ]) - .config(|this| { - this.optional(); + .to_matchable() }) - .to_matchable(), - Ref::keyword("AS").to_matchable(), - one_of(vec![ - optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) - .to_matchable(), - optionally_bracketed(vec![ + .to_matchable() + .into(), + ), + ( + "CreateMaterializedViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateMaterializedViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("TABLE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("BACKUP").to_matchable(), + one_of(vec![ + Ref::keyword("YES").to_matchable(), + Ref::keyword("NO").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable(), - Ref::new("ValuesClauseSegment").to_matchable(), - optionally_bracketed(vec![ + Ref::new("TableAttributeSegment").optional().to_matchable(), Sequence::new(vec![ - Ref::keyword("EXECUTE").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), + Ref::keyword("AUTO").to_matchable(), + Ref::keyword("REFRESH").to_matchable(), + one_of(vec![ + Ref::keyword("YES").to_matchable(), + Ref::keyword("NO").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::keyword("AS").to_matchable(), + one_of(vec![ + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + optionally_bracketed(vec![ + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + optionally_bracketed(vec![ + Sequence::new(vec![ + Ref::keyword("EXECUTE").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("WithDataClauseSegment").optional().to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("WithDataClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - ); - redshift_dialect.add([ + .to_matchable() + }) + .to_matchable() + .into(), + ), ( "CreateExternalFunctionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateExternalFunctionStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateExternalFunctionStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::new("OrReplaceGrammar").optional().to_matchable(), @@ -3458,10 +3819,10 @@ pub fn raw_dialect() -> Dialect { ), ( "QualifyClauseSegment".into(), - NodeMatcher::new(SyntaxKind::QualifyClause, |_| { + NodeMatcher::new(SyntaxKind::QualifyClause, |_dialect| { Sequence::new(vec![ Ref::keyword("QUALIFY").to_matchable(), - MetaSegment::indent().to_matchable(), + MetaSegment::implicit_indent().to_matchable(), Ref::new("ExpressionSegment").to_matchable(), MetaSegment::dedent().to_matchable(), ]) @@ -3470,42 +3831,223 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), + ( + "SelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { + let dialect = super::postgres::raw_dialect(); + dialect + .grammar("SelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("QualifyClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("OrderByClauseSegment").optional().to_matchable()), + None, + vec![Ref::new("SetOperatorSegment").to_matchable()], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "UnorderedSelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("UnorderedSelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("QualifyClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("OverlapsClauseSegment").optional().to_matchable()), + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "WildcardExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::WildcardExpression, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("WildcardExpressionSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("ExcludeClauseSegment").optional().to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "ExcludeClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SelectExcludeClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("EXCLUDE").to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "GroupByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::GroupbyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("CubeRollupClauseSegment").to_matchable(), + Ref::new("GroupingSetsClauseSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Bracketed::new(vec![]).to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), + ]; + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MergeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::MergeStatement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("MergeStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + one_of(vec![ + Ref::new("MergeMatchSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("REMOVE").to_matchable(), + Ref::keyword("DUPLICATES").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]), + None, + None, + Some(vec![Ref::new("MergeMatchSegment").to_matchable()]), + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "SetOperatorSegment".into(), + NodeMatcher::new(SyntaxKind::SetOperator, |_dialect| { + one_of(vec![ + Ref::new("UnionGrammar").to_matchable(), + Ref::keyword("INTERSECT").to_matchable(), + Ref::keyword("EXCEPT").to_matchable(), + Ref::keyword("MINUS").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "PrepareStatementSegment".into(), + NodeMatcher::new(SyntaxKind::PrepareStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("PREPARE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DeallocateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DeallocateStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DEALLOCATE").to_matchable(), + Ref::keyword("PREPARE").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), ]); - redshift_dialect.replace_grammar( - "SelectStatementSegment", - postgres_dialect - .grammar("SelectStatementSegment") - .match_grammar(&postgres_dialect) - .unwrap() - .copy( - Some(vec![ - Ref::new("QualifyClauseSegment").optional().to_matchable(), - ]), - None, - Some(Ref::new("OrderByClauseSegment").optional().to_matchable()), - None, - vec![Ref::new("SetOperatorSegment").to_matchable()], - false, - ), - ); - redshift_dialect.add([]); - redshift_dialect.replace_grammar( - "UnorderedSelectStatementSegment", - ansi_dialect - .grammar("UnorderedSelectStatementSegment") - .match_grammar(&ansi_dialect) - .unwrap() - .copy( - Some(vec![ - Ref::new("QualifyClauseSegment").optional().to_matchable(), - ]), - None, - Some(Ref::new("OverlapsClauseSegment").optional().to_matchable()), - None, - Vec::new(), - false, - ), - ); redshift_dialect } diff --git a/crates/lib-dialects/src/redshift_keywords.rs b/crates/lib-dialects/src/redshift_keywords.rs index 4d096b6c5..333d00355 100644 --- a/crates/lib-dialects/src/redshift_keywords.rs +++ b/crates/lib-dialects/src/redshift_keywords.rs @@ -6,6 +6,7 @@ ANALYSE ANALYZE AND ANY +APPEND ARRAY AS ASC @@ -182,6 +183,7 @@ ANYELEMENT APPLY APPROXIMATE ARE +ARN ARRAY_AGG ARRAY_MAX_CARDINALITY ASENSITIVE @@ -195,6 +197,8 @@ ATOMIC ATTACH ATTRIBUTE ATTRIBUTES +AUTHENTICATION +AUTHENTICATION_ARN AUTO AUTO_INCREMENT AVG @@ -251,6 +255,7 @@ CHARACTER_SET_NAME CHARACTER_SET_SCHEMA CHAR_LENGTH CHECKPOINT +CI CLASS CLASSIFIER CLASS_ORIGIN @@ -283,6 +288,7 @@ CONFIGURATION CONFLICT CONNECT CONNECTION +CONNECTION_LIMIT CONNECTION_NAME CONSTRAINTS CONSTRAINT_CATALOG @@ -308,6 +314,7 @@ COVAR_SAMP CREATEDB CREATEUSER CREATEROLE +CS CSV CUBE CUME_DIST @@ -324,6 +331,7 @@ CURSOR_NAME CYCLE DATA DATABASE +DATA_CATALOG_SCHEMA DATALINK DATASHARE DATASHARES @@ -334,6 +342,7 @@ DATETIME_INTERVAL_PRECISION DAY DAYOFYEAR DB +DBUSER DEALLOCATE DEC DECFLOAT @@ -380,6 +389,7 @@ DOCUMENT DOMAIN DOUBLE DROP +DUPLICATES DYNAMIC DYNAMIC_FUNCTION DYNAMIC_FUNCTION_CODE @@ -423,6 +433,7 @@ FAMILY FETCH FIELDS FILE +FILLTARGET FILTER FINAL FINALIZE @@ -470,14 +481,17 @@ HASH HEADER HEX HIERARCHY +HISTORY_MODE HIVE HLLSKETCH HOLD HOUR HYPERPARAMETERS +IAM IAM_ROLE ID IF +IGNOREEXTRA IMMEDIATE IMMEDIATELY IMMUTABLE @@ -528,6 +542,7 @@ JSON_TABLE JSON_TABLE_PRIMITIVE JSON_VALUE K +KAFKA KEEP KEY KEYS @@ -616,6 +631,8 @@ MONITOR MONTH MORE MOVE +MSK +MTLS MULTICLASS_CLASSIFICATION MULTISET MYSQL @@ -648,6 +665,7 @@ NOLOGIN NOREPLICATION NOSUPERUSER NONE +NONATOMIC NOORDER NORMALIZE OUTPUTFORMAT @@ -755,6 +773,7 @@ PUBLICATION PLPYTHONU QUALIFY QUARTER +QUERY_ALL_STATES QUOTA QUOTE QUOTES @@ -776,6 +795,7 @@ REFCURSOR REFERENCE_USAGE REFERENCING REFRESH +REFRESH_INTERVAL REGION REGR_AVGX REGR_AVGY @@ -1015,6 +1035,7 @@ USER_DEFINED_TYPE_CATALOG USER_DEFINED_TYPE_CODE USER_DEFINED_TYPE_NAME USER_DEFINED_TYPE_SCHEMA +USER_LIMIT UTF16 UTF16BE UTF16LE diff --git a/crates/lib-dialects/src/snowflake.rs b/crates/lib-dialects/src/snowflake.rs index 7f252c1c6..79318acdb 100644 --- a/crates/lib-dialects/src/snowflake.rs +++ b/crates/lib-dialects/src/snowflake.rs @@ -3,227 +3,81 @@ use sqruff_lib_core::dialects::Dialect; use sqruff_lib_core::dialects::init::DialectKind; use sqruff_lib_core::dialects::syntax::SyntaxKind; use sqruff_lib_core::helpers::{Config, ToMatchable}; -use sqruff_lib_core::parser::grammar::anyof::{ - AnyNumberOf, any_set_of, one_of, optionally_bracketed, -}; -use sqruff_lib_core::parser::grammar::conditional::Conditional; +use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed}; use sqruff_lib_core::parser::grammar::delimited::Delimited; use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence}; -use sqruff_lib_core::parser::grammar::{Nothing, Ref}; +use sqruff_lib_core::parser::grammar::{Anything, Nothing, Ref}; use sqruff_lib_core::parser::lexer::Matcher; -use sqruff_lib_core::parser::matchable::{Matchable, MatchableTrait}; +use sqruff_lib_core::parser::matchable::MatchableTrait; use sqruff_lib_core::parser::node_matcher::NodeMatcher; use sqruff_lib_core::parser::parsers::{MultiStringParser, RegexParser, StringParser, TypedParser}; use sqruff_lib_core::parser::segments::generator::SegmentGenerator; use sqruff_lib_core::parser::segments::meta::MetaSegment; use sqruff_lib_core::parser::types::ParseMode; -use super::ansi::{self, raw_dialect}; use super::snowflake_keywords::{SNOWFLAKE_RESERVED_KEYWORDS, SNOWFLAKE_UNRESERVED_KEYWORDS}; pub fn dialect() -> Dialect { - let mut snowflake_dialect = raw_dialect(); - snowflake_dialect.name = DialectKind::Snowflake; - - snowflake_dialect.replace_grammar( - "SelectClauseElementSegment", - ansi::select_clause_element().copy( - Some(vec![ - Sequence::new(vec![ - Ref::new("SystemFunctionName").to_matchable(), - Bracketed::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - ]), - None, - Some(Ref::new("WildcardExpressionSegment").to_matchable()), - None, - Vec::new(), - false, - ), - ); - - snowflake_dialect.replace_grammar( - "FromExpressionElementSegment", - Sequence::new(vec![ - Ref::new("PreTableFunctionKeywordsGrammar") - .optional() - .to_matchable(), - optionally_bracketed(vec![Ref::new("TableExpressionSegment").to_matchable()]) - .to_matchable(), - Ref::new("AliasExpressionSegment") - .exclude(one_of(vec![ - Ref::new("FromClauseTerminatorGrammar").to_matchable(), - Ref::new("SamplingExpressionSegment").to_matchable(), - Ref::new("ChangesClauseSegment").to_matchable(), - Ref::new("JoinLikeClauseGrammar").to_matchable(), - Ref::keyword("CROSS").to_matchable(), - ])) - .optional() - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - Ref::new("AliasExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("SamplingExpressionSegment") - .optional() - .to_matchable(), - Ref::new("PostTableExpressionGrammar") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ); + raw_dialect().config(|this| this.expand()) +} - snowflake_dialect.replace_grammar( - "JoinClauseSegment", - one_of(vec![ - Sequence::new(vec![ - Ref::new("JoinTypeKeywordsGrammar") - .optional() - .to_matchable(), - Ref::new("JoinKeywordsGrammar").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("FromExpressionElementSegment").to_matchable(), - AnyNumberOf::new(vec![Ref::new("NestedJoinGrammar").to_matchable()]).to_matchable(), - MetaSegment::dedent().to_matchable(), - Sequence::new(vec![ - Conditional::new(MetaSegment::indent()) - .indented_using_on() - .to_matchable(), - one_of(vec![ - Ref::new("JoinOnConditionSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - MetaSegment::indent().to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.parse_mode = ParseMode::Greedy) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Conditional::new(MetaSegment::dedent()) - .indented_using_on() - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("NaturalJoinKeywordsGrammar").to_matchable(), - Ref::new("JoinKeywordsGrammar").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("FromExpressionElementSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("ExtendedNaturalJoinKeywordsGrammar").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("FromExpressionElementSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ASOF").to_matchable(), - Ref::keyword("JOIN").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("FromExpressionElementSegment").to_matchable(), - AnyNumberOf::new(vec![Ref::new("NestedJoinGrammar").to_matchable()]).to_matchable(), - MetaSegment::dedent().to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("MatchConditionSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - Sequence::new(vec![ - Conditional::new(MetaSegment::indent()) - .indented_using_on() - .to_matchable(), - one_of(vec![ - Ref::new("JoinOnConditionSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - MetaSegment::indent().to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.parse_mode = ParseMode::Greedy) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Conditional::new(MetaSegment::dedent()) - .indented_using_on() - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); +pub fn raw_dialect() -> Dialect { + let ansi_dialect = super::ansi::raw_dialect(); + let mut snowflake_dialect = ansi_dialect.clone(); + snowflake_dialect.name = DialectKind::Snowflake; snowflake_dialect.patch_lexer_matchers(vec![ Matcher::regex( "single_quote", - r"'([^'\\]|\\.|'')*'", + r#"'([^'\\]|\\.|'')*'"#, SyntaxKind::SingleQuote, ), Matcher::regex( "inline_comment", - r"(--|#|//)[^\n]*", + r#"(--|#|//)[^\n]*"#, SyntaxKind::InlineComment, ), ]); snowflake_dialect.insert_lexer_matchers( vec![ - Matcher::string("parameter_assigner", "=>", SyntaxKind::ParameterAssigner), - Matcher::string("function_assigner", "->", SyntaxKind::FunctionAssigner), + Matcher::string("parameter_assigner", r#"=>"#, SyntaxKind::ParameterAssigner), + Matcher::string("right_arrow", r#"->"#, SyntaxKind::RightArrow), Matcher::regex( "stage_path", - r"(?:@[^\s;)]+|'@[^']+')", + r#"(?:@[^\s;)]+|'@[^']+')"#, SyntaxKind::StagePath, ), - Matcher::regex("column_selector", r"\$[0-9]+", SyntaxKind::ColumnSelector), - Matcher::regex("dollar_quote", r"\$\$.*\$\$", SyntaxKind::DollarQuote), + Matcher::regex("column_selector", r#"\$[0-9]+"#, SyntaxKind::ColumnSelector), + Matcher::regex( + "dollar_quote", + r#"\$\$[\s\S]*?\$\$"#, + SyntaxKind::DollarQuote, + ), Matcher::regex( "dollar_literal", - r"[$][a-zA-Z0-9_.]*", + r#"[$][a-zA-Z0-9_.]*"#, SyntaxKind::DollarLiteral, ), Matcher::regex( "inline_dollar_sign", - r"[a-zA-Z_][a-zA-Z0-9_$]*\$[a-zA-Z0-9_$]*", - SyntaxKind::Raw, + r#"[a-zA-Z_][a-zA-Z0-9_$]*\$[a-zA-Z0-9_$]*"#, + SyntaxKind::InlineDollarSign, ), Matcher::regex( "unquoted_file_path", - r"file://(?:[a-zA-Z]+:|/)+(?:[0-9a-zA-Z\\/_*?-]+)(?:\.[0-9a-zA-Z]+)?", + r#"file://(?:[a-zA-Z]+:|/)+(?:[0-9a-zA-Z\\/_*?-]+)(?:\.[0-9a-zA-Z]+)?"#, SyntaxKind::UnquotedFilePath, ), - Matcher::string("question_mark", "?", SyntaxKind::QuestionMark), - Matcher::string("exclude_bracket_open", "{-", SyntaxKind::ExcludeBracketOpen), + Matcher::string("question_mark", r#"?"#, SyntaxKind::QuestionMark), + Matcher::string( + "exclude_bracket_open", + r#"{-"#, + SyntaxKind::ExcludeBracketOpen, + ), Matcher::string( "exclude_bracket_close", - "-}", + r#"-}"#, SyntaxKind::ExcludeBracketClose, ), ], @@ -233,20 +87,24 @@ pub fn dialect() -> Dialect { snowflake_dialect.insert_lexer_matchers( vec![Matcher::string( "walrus_operator", - ":=", + r#":="#, SyntaxKind::WalrusOperator, )], "equals", ); - snowflake_dialect.bracket_sets_mut("bracket_pairs").insert(( - "exclude", - "StartExcludeBracketSegment", - "EndExcludeBracketSegment", - true, - )); + snowflake_dialect.update_bracket_sets( + "bracket_pairs", + vec![( + "exclude", + "StartExcludeBracketSegment", + "EndExcludeBracketSegment", + true, + )], + ); snowflake_dialect.sets_mut("bare_functions").clear(); + snowflake_dialect.sets_mut("bare_functions").extend([ "CURRENT_DATE", "CURRENT_TIME", @@ -257,6 +115,7 @@ pub fn dialect() -> Dialect { ]); snowflake_dialect.sets_mut("compression_types").clear(); + snowflake_dialect.sets_mut("compression_types").extend([ "AUTO", "AUTO_DETECT", @@ -272,110 +131,135 @@ pub fn dialect() -> Dialect { ]); snowflake_dialect.sets_mut("files_types").clear(); + snowflake_dialect .sets_mut("files_types") .extend(["CSV", "JSON", "AVRO", "ORC", "PARQUET", "XML"]); snowflake_dialect.sets_mut("warehouse_types").clear(); + snowflake_dialect .sets_mut("warehouse_types") .extend(["STANDARD", "SNOWPARK-OPTIMIZED"]); snowflake_dialect.sets_mut("warehouse_sizes").clear(); + snowflake_dialect.sets_mut("warehouse_sizes").extend([ "XSMALL", "SMALL", "MEDIUM", "LARGE", "XLARGE", "XXLARGE", "X2LARGE", "XXXLARGE", "X3LARGE", "X4LARGE", "X5LARGE", "X6LARGE", "X-SMALL", "X-LARGE", "2X-LARGE", "3X-LARGE", "4X-LARGE", "5X-LARGE", "6X-LARGE", ]); + snowflake_dialect.sets_mut("resource_constraints").clear(); + + snowflake_dialect.sets_mut("resource_constraints").extend([ + "STANDARD_GEN_1", + "STANDARD_GEN_2", + "MEMORY_1X", + "MEMORY_1X_x86", + "MEMORY_16X", + "MEMORY_16X_x86", + "MEMORY_64X", + "MEMORY_64X_x86", + "MEMORY_256X", + "MEMORY_256X_x86", + ]); + snowflake_dialect .sets_mut("warehouse_scaling_policies") .clear(); + snowflake_dialect .sets_mut("warehouse_scaling_policies") .extend(["STANDARD", "ECONOMY"]); + snowflake_dialect.sets_mut("refreshmode_types").clear(); + + snowflake_dialect + .sets_mut("refreshmode_types") + .extend(["AUTO", "FULL", "INCREMENTAL"]); + + snowflake_dialect.sets_mut("initialize_types").clear(); + + snowflake_dialect + .sets_mut("initialize_types") + .extend(["ON_CREATE", "ON_SCHEDULE"]); + snowflake_dialect.add([ ( "ParameterAssignerSegment".into(), - StringParser::new( - "=>", - SyntaxKind::ParameterAssigner - ) - .to_matchable() - .into(), + StringParser::new("=>", SyntaxKind::ParameterAssigner) + .to_matchable() + .into(), + ), + ( + "LambdaArrowSegment".into(), + StringParser::new("->", SyntaxKind::LambdaArrow) + .to_matchable() + .into(), ), ( "FunctionAssignerSegment".into(), - StringParser::new( - "->", - SyntaxKind::FunctionAssigner - ) - .to_matchable() - .into(), + StringParser::new("->", SyntaxKind::FunctionAssigner) + .to_matchable() + .into(), ), ( "WalrusOperatorSegment".into(), - StringParser::new( - ":=", - SyntaxKind::AssignmentOperator - ) - .to_matchable() - .into(), + StringParser::new(":=", SyntaxKind::AssignmentOperator) + .to_matchable() + .into(), ), ( "QuotedStarSegment".into(), - StringParser::new( - "'*'", - SyntaxKind::QuotedStar - ) - .to_matchable() - .into(), + StringParser::new("'*'", SyntaxKind::QuotedStar) + .to_matchable() + .into(), ), ( "NakedSemiStructuredElementSegment".into(), RegexParser::new( - "[A-Z0-9_]*", - SyntaxKind::SemiStructuredElement + r#"[a-zA-Z_][a-zA-Z0-9_$]*"#, + SyntaxKind::SemiStructuredElement, ) .to_matchable() .into(), ), ( "QuotedSemiStructuredElementSegment".into(), - TypedParser::new( - SyntaxKind::DoubleQuote, - SyntaxKind::SemiStructuredElement, - ) - .to_matchable() - .into(), + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::SemiStructuredElement) + .to_matchable() + .into(), + ), + ( + "DoubleQuotedLiteralSegment".into(), + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedLiteral) + .to_matchable() + .into(), ), ( "ColumnIndexIdentifierSegment".into(), - RegexParser::new( - r"\$[0-9]+", - SyntaxKind::ColumnIndexIdentifierSegment - ) - .to_matchable() - .into(), + RegexParser::new(r#"\$[0-9]+"#, SyntaxKind::ColumnIndexIdentifierSegment) + .to_matchable() + .into(), ), ( "LocalVariableNameSegment".into(), - RegexParser::new( - r"[a-zA-Z0-9_]*", - SyntaxKind::Variable - ) - .to_matchable() - .into(), + RegexParser::new(r#"[a-zA-Z0-9_]*"#, SyntaxKind::Variable) + .to_matchable() + .into(), + ), + ( + "SnowflakeVariableNameSegment".into(), + RegexParser::new(r#":[a-zA-Z0-9_]*"#, SyntaxKind::Variable) + .to_matchable() + .into(), ), ( "ReferencedVariableNameSegment".into(), - RegexParser::new( - r"\$[A-Z_][A-Z0-9_]*", - SyntaxKind::Variable - ) - .to_matchable() - .into(), + RegexParser::new(r#"\$[A-Z_][A-Z0-9_]*"#, SyntaxKind::Variable) + .to_matchable() + .into(), ), ( "WarehouseType".into(), @@ -383,20 +267,22 @@ pub fn dialect() -> Dialect { MultiStringParser::new( snowflake_dialect .sets("warehouse_types") - .into_iter() - .filter(|it| !it.contains('-')) - .map_into() + .iter() + .filter(|item| !item.contains("-")) + .map(|item| item.to_string()) .collect_vec(), - SyntaxKind::WarehouseSize - ).to_matchable(), + SyntaxKind::WarehouseSize, + ) + .to_matchable(), MultiStringParser::new( snowflake_dialect .sets("warehouse_types") - .into_iter() - .map(|it| format!("'{it}'")) + .iter() + .map(|item| format!("'{}'", item)) .collect_vec(), - SyntaxKind::WarehouseSize - ).to_matchable() + SyntaxKind::WarehouseSize, + ) + .to_matchable(), ]) .to_matchable() .into(), @@ -407,20 +293,80 @@ pub fn dialect() -> Dialect { MultiStringParser::new( snowflake_dialect .sets("warehouse_sizes") - .into_iter() - .filter(|it| !it.contains('-')) - .map_into() + .iter() + .filter(|item| !item.contains("-")) + .map(|item| item.to_string()) .collect_vec(), - SyntaxKind::WarehouseSize - ).to_matchable(), + SyntaxKind::WarehouseSize, + ) + .to_matchable(), MultiStringParser::new( snowflake_dialect .sets("warehouse_sizes") - .into_iter() - .map(|it| format!("'{it}'")) + .iter() + .map(|item| format!("'{}'", item)) + .collect_vec(), + SyntaxKind::WarehouseSize, + ) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "ResourceConstraint".into(), + one_of(vec![ + MultiStringParser::new( + snowflake_dialect + .sets("resource_constraints") + .iter() + .filter(|item| !item.contains("-")) + .map(|item| item.to_string()) + .collect_vec(), + SyntaxKind::ResourceConstraint, + ) + .to_matchable(), + MultiStringParser::new( + snowflake_dialect + .sets("resource_constraints") + .iter() + .map(|item| format!("'{}'", item)) + .collect_vec(), + SyntaxKind::ResourceConstraint, + ) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "RefreshModeType".into(), + one_of(vec![ + MultiStringParser::new( + snowflake_dialect + .sets("refreshmode_types") + .iter() + .map(|item| item.to_string()) + .collect_vec(), + SyntaxKind::Keyword, + ) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "InitializeType".into(), + one_of(vec![ + MultiStringParser::new( + snowflake_dialect + .sets("initialize_types") + .iter() + .map(|item| item.to_string()) .collect_vec(), - SyntaxKind::WarehouseSize - ).to_matchable() + SyntaxKind::InitializeType, + ) + .to_matchable(), ]) .to_matchable() .into(), @@ -431,20 +377,21 @@ pub fn dialect() -> Dialect { MultiStringParser::new( snowflake_dialect .sets("compression_types") - .into_iter() - .map_into() + .iter() + .map(|item| item.to_string()) .collect_vec(), - SyntaxKind::CompressionType - - ).to_matchable(), + SyntaxKind::CompressionType, + ) + .to_matchable(), MultiStringParser::new( snowflake_dialect .sets("compression_types") - .into_iter() - .map(|it| format!("'{it}'")) + .iter() + .map(|item| format!("'{}'", item)) .collect_vec(), - SyntaxKind::CompressionType - ).to_matchable() + SyntaxKind::CompressionType, + ) + .to_matchable(), ]) .to_matchable() .into(), @@ -455,20 +402,21 @@ pub fn dialect() -> Dialect { MultiStringParser::new( snowflake_dialect .sets("warehouse_scaling_policies") - .into_iter() - .filter(|it| !it.contains('-')) - .map_into() + .iter() + .map(|item| item.to_string()) .collect_vec(), - SyntaxKind::ScalingPolicy - ).to_matchable(), + SyntaxKind::ScalingPolicy, + ) + .to_matchable(), MultiStringParser::new( snowflake_dialect .sets("warehouse_scaling_policies") - .into_iter() - .map(|it| format!("'{it}'")) + .iter() + .map(|item| format!("'{}'", item)) .collect_vec(), - SyntaxKind::ScalingPolicy - ).to_matchable() + SyntaxKind::ScalingPolicy, + ) + .to_matchable(), ]) .to_matchable() .into(), @@ -476,8 +424,8 @@ pub fn dialect() -> Dialect { ( "ValidationModeOptionSegment".into(), RegexParser::new( - r"'?RETURN_(?:\d+_ROWS|ERRORS|ALL_ERRORS)'?", - SyntaxKind::ValidationModeOption + r#"'?RETURN_(?:\d+_ROWS|ERRORS|ALL_ERRORS)'?"#, + SyntaxKind::ValidationModeOption, ) .to_matchable() .into(), @@ -485,111 +433,110 @@ pub fn dialect() -> Dialect { ( "CopyOptionOnErrorSegment".into(), RegexParser::new( - r"'?CONTINUE'?|'?SKIP_FILE(?:_[0-9]+%?)?'?|'?ABORT_STATEMENT'?", - SyntaxKind::CopyOnErrorOption + r#"'?CONTINUE'?|'?SKIP_FILE(?:_[0-9]+%?)?'?|'?ABORT_STATEMENT'?"#, + SyntaxKind::CopyOnErrorOption, ) .to_matchable() .into(), ), ( - "DoubleQuotedUDFBody".into(), - TypedParser::new( - SyntaxKind::DoubleQuote, - SyntaxKind::UdfBody, + "DynamicTableLagIntervalSegment".into(), + RegexParser::new( + r#"DYNAMIC|'.*'"#, + SyntaxKind::DynamicTableLagIntervalSegment, ) .to_matchable() .into(), ), + ( + "DoubleQuotedUDFBody".into(), + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::UdfBody) + .to_matchable() + .into(), + ), ( "SingleQuotedUDFBody".into(), - TypedParser::new( - SyntaxKind::SingleQuote, - SyntaxKind::UdfBody, - ) - .to_matchable() - .into(), + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::UdfBody) + .to_matchable() + .into(), ), ( "DollarQuotedUDFBody".into(), - TypedParser::new( - SyntaxKind::DollarQuote, - SyntaxKind::UdfBody, - ) - .to_matchable() - .into(), + TypedParser::new(SyntaxKind::DollarQuote, SyntaxKind::UdfBody) + .to_matchable() + .into(), ), ( "StagePath".into(), - RegexParser::new( - r"(?:@[^\s;)]+|'@[^']+')", - SyntaxKind::StagePath - ) - .to_matchable() - .into(), + RegexParser::new(r#"(?:@[^\s;)]+|'@[^']+')"#, SyntaxKind::StagePath) + .to_matchable() + .into(), ), ( "S3Path".into(), - RegexParser::new( - r"'s3://[a-z0-9][a-z0-9\.-]{1,61}[a-z0-9](?:/.*)?'", - SyntaxKind::BucketPath - ) - .to_matchable() - .into(), + RegexParser::new(r#"'s3://.*'"#, SyntaxKind::BucketPath) + .to_matchable() + .into(), ), ( "GCSPath".into(), - RegexParser::new( - r"'gcs://[a-z0-9][\w\.-]{1,61}[a-z0-9](?:/.+)?'", - SyntaxKind::BucketPath - ) - .to_matchable() - .into(), + RegexParser::new(r#"'gcs://.*"#, SyntaxKind::BucketPath) + .to_matchable() + .into(), ), ( "AzureBlobStoragePath".into(), - RegexParser::new( - r"'azure://[a-z0-9][a-z0-9-]{1,61}[a-z0-9]\.blob\.core\.windows\.net/[a-z0-9][a-z0-9\.-]{1,61}[a-z0-9](?:/.+)?'", - SyntaxKind::BucketPath - ) - .to_matchable() - .into(), + RegexParser::new(r#"'azure://.*"#, SyntaxKind::BucketPath) + .to_matchable() + .into(), ), ( "UnquotedFilePath".into(), - TypedParser::new( - SyntaxKind::UnquotedFilePath, - SyntaxKind::UnquotedFilePath, - ) - .to_matchable() - .into(), + TypedParser::new(SyntaxKind::UnquotedFilePath, SyntaxKind::UnquotedFilePath) + .to_matchable() + .into(), ), ( "SnowflakeEncryptionOption".into(), MultiStringParser::new( - vec!["'SNOWFLAKE_FULL'".into(), "'SNOWFLAKE_SSE'".into()], - SyntaxKind::StageEncryptionOption - ).to_matchable().into(), + vec!["'SNOWFLAKE_FULL'", "'SNOWFLAKE_SSE'"] + .into_iter() + .map(String::from) + .collect::>(), + SyntaxKind::StageEncryptionOption, + ) + .to_matchable() + .into(), ), ( "S3EncryptionOption".into(), MultiStringParser::new( - vec!["'AWS_CSE'".into(), "'AWS_SSE_S3'".into(), "'AWS_SSE_KMS'".into()], - SyntaxKind::StageEncryptionOption - ).to_matchable().into(), + vec!["'AWS_CSE'", "'AWS_SSE_S3'", "'AWS_SSE_KMS'", "'NONE'"] + .into_iter() + .map(String::from) + .collect::>(), + SyntaxKind::StageEncryptionOption, + ) + .to_matchable() + .into(), ), ( "GCSEncryptionOption".into(), MultiStringParser::new( - vec!["'GCS_SSE_KMS'".into()], - SyntaxKind::StageEncryptionOption - ).to_matchable().into(), + vec!["'GCS_SSE_KMS'", "'NONE'"] + .into_iter() + .map(String::from) + .collect::>(), + SyntaxKind::StageEncryptionOption, + ) + .to_matchable() + .into(), ), ( "AzureBlobStorageEncryptionOption".into(), - MultiStringParser::new( - vec!["'AZURE_CSE'".into()], - SyntaxKind::StageEncryptionOption - ).to_matchable().into(), + StringParser::new("'AZURE_CSE'", SyntaxKind::StageEncryptionOption) + .to_matchable() + .into(), ), ( "FileType".into(), @@ -597,111 +544,101 @@ pub fn dialect() -> Dialect { MultiStringParser::new( snowflake_dialect .sets("file_types") - .into_iter() - .filter(|it| !it.contains('-')) - .map_into() + .iter() + .map(|item| item.to_string()) .collect_vec(), - SyntaxKind::FileType - ).to_matchable(), + SyntaxKind::FileType, + ) + .to_matchable(), MultiStringParser::new( snowflake_dialect .sets("file_types") - .into_iter() - .map(|it| format!("'{it}'")) + .iter() + .map(|item| format!("'{}'", item)) .collect_vec(), - SyntaxKind::FileType - ).to_matchable() + SyntaxKind::FileType, + ) + .to_matchable(), ]) .to_matchable() .into(), ), ( "IntegerSegment".into(), - RegexParser::new( - r"[0-9]+", - SyntaxKind::IntegerLiteral - ) - .to_matchable() - .into(), + RegexParser::new(r#"[0-9]+"#, SyntaxKind::IntegerLiteral) + .to_matchable() + .into(), ), ( "SystemFunctionName".into(), - RegexParser::new( - r"SYSTEM\$([A-Za-z0-9_]*)", - SyntaxKind::SystemFunctionName - ) - .to_matchable() - .into(), + RegexParser::new(r#"SYSTEM\$([A-Za-z0-9_]*)"#, SyntaxKind::SystemFunctionName) + .to_matchable() + .into(), ), ( "GroupByContentsGrammar".into(), Delimited::new(vec![ one_of(vec![ Ref::new("ColumnReferenceSegment").to_matchable(), - // Can `GROUP BY 1` Ref::new("NumericLiteralSegment").to_matchable(), - // Can `GROUP BY coalesce(col, 1)` - Ref::new("ExpressionSegment").to_matchable(),]).to_matchable(),]).config(|this|this.terminators = vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("FETCH").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("QUALIFY").to_matchable(), - Ref::keyword("WINDOW").to_matchable(),]).to_matchable().into() + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![Ref::new("GroupByClauseTerminatorGrammar").to_matchable()]; + }) + .to_matchable() + .into(), ), ( "LimitLiteralGrammar".into(), one_of(vec![ Ref::new("NumericLiteralSegment").to_matchable(), Ref::keyword("NULL").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable() - ]).to_matchable().into() + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable() + .into(), ), ( - "StartExcludeBracketSegment".into(), - StringParser::new( - "{-", - SyntaxKind::StartExcludeBracket - ) + "DynamicTableTargetLagSegment".into(), + one_of(vec![ + Ref::new("DynamicTableLagIntervalSegment").to_matchable(), + Ref::keyword("DOWNSTREAM").to_matchable(), + ]) .to_matchable() .into(), ), + ( + "StartExcludeBracketSegment".into(), + StringParser::new("{-", SyntaxKind::StartExcludeBracket) + .to_matchable() + .into(), + ), ( "EndExcludeBracketSegment".into(), - StringParser::new( - "-}", - SyntaxKind::EndExcludeBracket - ) - .to_matchable() - .into(), + StringParser::new("-}", SyntaxKind::EndExcludeBracket) + .to_matchable() + .into(), ), ( "QuestionMarkSegment".into(), - StringParser::new( - "?", - SyntaxKind::QuestionMark - ) - .to_matchable() - .into(), + StringParser::new("?", SyntaxKind::QuestionMark) + .to_matchable() + .into(), ), ( "CaretSegment".into(), - StringParser::new( - "^", - SyntaxKind::Caret - ) - .to_matchable() - .into(), + StringParser::new("^", SyntaxKind::Caret) + .to_matchable() + .into(), ), ( "DollarSegment".into(), - StringParser::new( - "$", - SyntaxKind::Dollar - ) - .to_matchable() - .into(), + StringParser::new("$", SyntaxKind::Dollar) + .to_matchable() + .into(), ), ( "PatternQuantifierGrammar".into(), @@ -715,31 +652,51 @@ pub fn dialect() -> Dialect { Ref::new("NumericLiteralSegment").to_matchable(), Sequence::new(vec![ Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("CommaSegment").to_matchable(),]).to_matchable(), + Ref::new("CommaSegment").to_matchable(), + ]) + .to_matchable(), Sequence::new(vec![ Ref::new("CommaSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(),]).to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), Sequence::new(vec![ Ref::new("NumericLiteralSegment").to_matchable(), Ref::new("CommaSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(),]).to_matchable(),]).to_matchable(),]).config(|this| { - this.bracket_type = "curly"; + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.bracket_type("curly"); this.bracket_pairs_set = "bracket_pairs"; - }).to_matchable() - ]).to_matchable(), - Ref::new("QuestionMarkSegment").optional().to_matchable() - ]).config(|this| { - this.allow_gaps = false; - }).to_matchable().into() + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("QuestionMarkSegment").optional().to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + .into(), ), ( "PatternSymbolGrammar".into(), Sequence::new(vec![ Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("PatternQuantifierGrammar").optional().to_matchable() - ]).config(|this| { - this.allow_gaps = false; - }).to_matchable().into() + Ref::new("PatternQuantifierGrammar") + .optional() + .to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable() + .into(), ), ( "PatternOperatorGrammar".into(), @@ -749,33 +706,66 @@ pub fn dialect() -> Dialect { one_of(vec![ Bracketed::new(vec![ one_of(vec![ - AnyNumberOf::new(vec![Ref::new("PatternOperatorGrammar").to_matchable(),]).to_matchable(), - Delimited::new( - vec![ - Ref::new("PatternOperatorGrammar").to_matchable(),] - ) - .config(|this|this.delimiter(Ref::new("BitwiseOrSegment"))).to_matchable(),]).to_matchable(),]).config(|this| { - this.bracket_type = "exclude"; + AnyNumberOf::new(vec![ + Ref::new("PatternOperatorGrammar").to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Ref::new("PatternOperatorGrammar").to_matchable(), + ]) + .config(|this| { + this.delimiter(Ref::new("BitwiseOrSegment")); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.bracket_type("exclude"); this.bracket_pairs_set = "bracket_pairs"; - }).to_matchable(), + }) + .to_matchable(), Bracketed::new(vec![ one_of(vec![ - AnyNumberOf::new(vec![Ref::new("PatternOperatorGrammar").to_matchable(),]).to_matchable(), - Delimited::new( - vec![ - Ref::new("PatternOperatorGrammar").to_matchable(),] - ) - .config(|this|this.delimiter(Ref::new("BitwiseOrSegment"))).to_matchable(),]).to_matchable(),]).to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("PatternOperatorGrammar").to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Ref::new("PatternOperatorGrammar").to_matchable(), + ]) + .config(|this| { + this.delimiter(Ref::new("BitwiseOrSegment")); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), Sequence::new(vec![ Ref::keyword("PERMUTE").to_matchable(), - Bracketed::new(vec![Delimited::new( - vec![ - Ref::new("PatternSymbolGrammar").to_matchable(),] - ).to_matchable(),]).to_matchable(),]).to_matchable(),]).to_matchable(), - Ref::new("PatternQuantifierGrammar").optional().to_matchable() - ]).config(|this| { - this.allow_gaps = false; - }).to_matchable(),]).to_matchable().into() + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("PatternSymbolGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("PatternQuantifierGrammar") + .optional() + .to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable(), + ]) + .to_matchable() + .into(), ), ( "ContextHeadersGrammar".into(), @@ -800,116 +790,103 @@ pub fn dialect() -> Dialect { Ref::keyword("LAST_QUERY_ID").to_matchable(), Ref::keyword("LAST_TRANSACTION").to_matchable(), Ref::keyword("LOCALTIME").to_matchable(), - Ref::keyword("LOCALTIMESTAMP").to_matchable(),]).to_matchable().into() - ) - ]); - - snowflake_dialect.add([ - ( - "NakedIdentifierSegment".into(), - SegmentGenerator::new(|dialect| { - // Generate the anti template from the set of reserved keywords - let reserved_keywords = dialect.sets("reserved_keywords"); - let pattern = reserved_keywords.iter().join("|"); - let anti_template = format!("^({pattern})$"); - - RegexParser::new("[a-zA-Z_][a-zA-Z0-9_$]*", SyntaxKind::NakedIdentifier) - .anti_template(&anti_template) - .to_matchable() - }) + Ref::keyword("LOCALTIMESTAMP").to_matchable(), + ]) + .to_matchable() .into(), ), ( - "LiteralGrammar".into(), - snowflake_dialect - .grammar("LiteralGrammar") - .copy( - Some(vec![ - Ref::new("ReferencedVariableNameSegment").to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ) - .into(), - ), - ( - "AccessorGrammar".into(), - AnyNumberOf::new(vec![ - Ref::new("ArrayAccessorSegment").to_matchable(), - Ref::new("SemiStructuredAccessorSegment").to_matchable(), + "ExceptionCodeSegment".into(), + Sequence::new(vec![ + Ref::new("NegativeSegment").to_matchable(), + RegexParser::new(r#"20[0-9]{3}"#, SyntaxKind::ExceptionCode).to_matchable(), ]) .to_matchable() .into(), ), ( - "PreTableFunctionKeywordsGrammar".into(), - one_of(vec![Ref::keyword("LATERAL").to_matchable()]) - .to_matchable() - .into(), - ), - ( - "FunctionContentsExpressionGrammar".into(), - one_of(vec![ - Ref::new("DatetimeUnitSegment").to_matchable(), - Ref::new("NamedParameterExpressionSegment").to_matchable(), - Ref::new("ReferencedVariableNameSegment").to_matchable(), + "InlineConstraintGrammar".into(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("IGNORE").to_matchable(), - Ref::keyword("RESPECT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("NULLS").to_matchable(), + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("ENFORCED").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("DEFERRABLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + one_of(vec![ + Ref::keyword("DEFERRED").to_matchable(), + Ref::keyword("IMMEDIATE").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), + one_of(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("DISABLE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("VALIDATE").to_matchable(), + Ref::keyword("NOVALIDATE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("RELY").to_matchable(), + Ref::keyword("NORELY").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable() .into(), ), ( - "JoinLikeClauseGrammar".into(), - Sequence::new(vec![ - any_set_of(vec![ - Ref::new("MatchRecognizeClauseSegment").to_matchable(), - Ref::new("ChangesClauseSegment").to_matchable(), - Ref::new("ConnectByClauseSegment").to_matchable(), - Ref::new("FromBeforeExpressionSegment").to_matchable(), - Ref::new("FromPivotExpressionSegment").to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("FromUnpivotExpressionSegment").to_matchable(), + "ForeignKeyConstraintGrammar".into(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("MATCH").to_matchable(), + one_of(vec![ + Ref::keyword("FULL").to_matchable(), + Ref::keyword("SIMPLE").to_matchable(), + Ref::keyword("PARTIAL").to_matchable(), ]) .to_matchable(), - Ref::new("SamplingExpressionSegment").to_matchable(), ]) - .config(|this| this.min_times = 1) .to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "SingleIdentifierGrammar".into(), - one_of(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), - Ref::new("ColumnIndexIdentifierSegment").to_matchable(), - Ref::new("ReferencedVariableNameSegment").to_matchable(), - Ref::new("StagePath").to_matchable(), Sequence::new(vec![ - Ref::keyword("IDENTIFIER").to_matchable(), - Bracketed::new(vec![ + AnyNumberOf::new(vec![ + Ref::keyword("ON").to_matchable(), one_of(vec![ - Ref::new("SingleQuotedIdentifierSegment").to_matchable(), - Ref::new("ReferencedVariableNameSegment").to_matchable(), + Ref::keyword("UPDATE").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("CASCADE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("RESTRICT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("ACTION").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -917,268 +894,504 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable() .into(), ), ( - "PostFunctionGrammar".into(), - Sequence::new(vec![ - Ref::new("WithinGroupClauseSegment") - .optional() - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("IGNORE").to_matchable(), - Ref::keyword("RESPECT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("NULLS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("OverClauseSegment").optional().to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "TemporaryGrammar".into(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("LOCAL").to_matchable(), - Ref::keyword("GLOBAL").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Ref::keyword("TEMP").to_matchable(), - Ref::keyword("TEMPORARY").to_matchable(), + "AlterOrReplaceGrammar".into(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("OR").to_matchable(), + Ref::keyword("ALTER").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Sequence::new(vec![Ref::keyword("VOLATILE").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), + Ref::new("OrReplaceGrammar").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable() .into(), ), ( - "TemporaryTransientGrammar".into(), + "SearchMethodGrammar".into(), one_of(vec![ - Ref::new("TemporaryGrammar").to_matchable(), - Ref::keyword("TRANSIENT").to_matchable(), + Ref::keyword("GEO").to_matchable(), + Ref::keyword("SUBSTRING").to_matchable(), + Ref::keyword("EQUALITY").to_matchable(), ]) .to_matchable() .into(), ), ( - "BaseExpressionElementGrammar".into(), - snowflake_dialect - .grammar("BaseExpressionElementGrammar") - .copy( - Some(vec![ - Sequence::new(vec![ - Ref::keyword("CONNECT_BY_ROOT").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), + "SearchMethodWithTargetGrammar".into(), + Sequence::new(vec![ + Ref::new("SearchMethodGrammar").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![Ref::new("AccessorGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - ]), - None, - Some(Ref::new("LiteralGrammar").to_matchable()), - None, - Vec::new(), - false, - ) - .into(), - ), - ( - "QuotedLiteralSegment".into(), - one_of(vec![ - TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral).to_matchable(), - TypedParser::new(SyntaxKind::DollarQuote, SyntaxKind::QuotedLiteral).to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "LikeGrammar".into(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("LIKE").to_matchable(), - one_of(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("ANY").to_matchable(), + Ref::new("StarSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), - Ref::keyword("RLIKE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ILIKE").to_matchable(), - Ref::keyword("ANY").optional().to_matchable(), - ]) - .to_matchable(), - Ref::keyword("REGEXP").to_matchable(), ]) .to_matchable() .into(), ), ( - "SelectClauseTerminatorGrammar".into(), + "PurposeGrammar".into(), one_of(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("WHERE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("FETCH").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - Ref::new("SetOperatorSegment").to_matchable(), + Ref::keyword("STEWARD").to_matchable(), + Ref::keyword("SUPPORT").to_matchable(), + Ref::keyword("ACCESS_APPROVAL").to_matchable(), ]) .to_matchable() .into(), ), - ( - "FromClauseTerminatorGrammar".into(), - one_of(vec![ - Ref::keyword("WHERE").to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("FETCH").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), + ]); + + snowflake_dialect.add([( + "NakedIdentifierSegment".into(), + SegmentGenerator::new(|dialect| { + let reserved_keywords = dialect.sets("reserved_keywords"); + let pattern = reserved_keywords.iter().join("|"); + let anti_template = format!("^({pattern})$"); + RegexParser::new(r#"[a-zA-Z_][a-zA-Z0-9_$]*"#, SyntaxKind::NakedIdentifier) + .anti_template(&anti_template) + .to_matchable() + }) + .into(), + )]); + + snowflake_dialect.replace_grammar( + "LiteralGrammar", + ansi_dialect.grammar("LiteralGrammar").copy( + Some(vec![ + Ref::new("ReferencedVariableNameSegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ), + ); + + snowflake_dialect.replace_grammar( + "AccessorGrammar", + AnyNumberOf::new(vec![ + Ref::new("ArrayAccessorSegment").to_matchable(), + Ref::new("SemiStructuredAccessorSegment").to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "PreTableFunctionKeywordsGrammar", + one_of(vec![Ref::keyword("LATERAL").to_matchable()]).to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "FunctionContentsExpressionGrammar", + one_of(vec![ + Ref::new("DatetimeUnitSegment").to_matchable(), + Ref::new("NamedParameterExpressionSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + Ref::new("LambdaExpressionSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), + one_of(vec![ + Ref::keyword("IGNORE").to_matchable(), + Ref::keyword("RESPECT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("NULLS").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "JoinLikeClauseGrammar", + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Ref::new("MatchRecognizeClauseSegment").to_matchable(), + Ref::new("ChangesClauseSegment").to_matchable(), + Ref::new("ConnectByClauseSegment").to_matchable(), + Ref::new("FromAtExpressionSegment").to_matchable(), + Ref::new("FromBeforeExpressionSegment").to_matchable(), + Ref::new("FromPivotExpressionSegment").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("FromUnpivotExpressionSegment").to_matchable(), ]) .to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("QUALIFY").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::new("SetOperatorSegment").to_matchable(), - Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), - Ref::new("WithDataClauseSegment").to_matchable(), + Ref::new("SamplingExpressionSegment").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "WhereClauseTerminatorGrammar".into(), - one_of(vec![ - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("FETCH").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), + .config(|this| { + this.max_times_per_element = Some(1); + this.min_times(1); + }) + .to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "SingleIdentifierGrammar", + one_of(vec![ + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), + Ref::new("ColumnIndexIdentifierSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + Ref::new("StagePath").to_matchable(), + Sequence::new(vec![ + Ref::keyword("IDENTIFIER").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("SingleQuotedIdentifierSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + Ref::new("BindVariableSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "PostFunctionGrammar", + Sequence::new(vec![ + Ref::new("WithinGroupClauseSegment") + .optional() + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("IGNORE").to_matchable(), + Ref::keyword("RESPECT").to_matchable(), ]) .to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("QUALIFY").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::keyword("OVERLAPS").to_matchable(), + Ref::keyword("NULLS").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "OrderByClauseTerminators".into(), + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("OverClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "TemporaryGrammar", + Sequence::new(vec![ one_of(vec![ - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("QUALIFY").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::new("FrameClauseUnitGrammar").to_matchable(), - Ref::keyword("SEPARATOR").to_matchable(), - Ref::keyword("FETCH").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - Ref::keyword("MEASURES").to_matchable(), + Ref::keyword("LOCAL").to_matchable(), + Ref::keyword("GLOBAL").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "TrimParametersGrammar".into(), - Nothing::new().to_matchable().into(), - ), - ( - "GroupByClauseTerminatorGrammar".into(), + .config(|this| { + this.optional(); + }) + .to_matchable(), one_of(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("FETCH").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("QUALIFY").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), + Ref::keyword("TEMP").to_matchable(), + Ref::keyword("TEMPORARY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "HavingClauseTerminatorGrammar".into(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![Ref::keyword("VOLATILE").to_matchable()]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("QUALIFY").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::keyword("FETCH").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ]); + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ); - snowflake_dialect.sets_mut("unreserved_keywords").clear(); - snowflake_dialect.update_keywords_set_from_multiline_string( - "unreserved_keywords", - SNOWFLAKE_UNRESERVED_KEYWORDS, + snowflake_dialect.replace_grammar( + "BaseExpressionElementGrammar", + ansi_dialect + .grammar("BaseExpressionElementGrammar") + .copy( + Some(vec![ + Sequence::new(vec![ + Ref::keyword("CONNECT_BY_ROOT").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PRIOR").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]), + None, + Some(Ref::new("LiteralGrammar").to_matchable()), + None, + vec![], + false, + ) + .copy( + Some(vec![ + Ref::new("SnowflakeVariableNameSegment").to_matchable(), + ]), + None, + Some(Ref::new("LiteralGrammar").to_matchable()), + None, + vec![], + false, + ), ); - snowflake_dialect.sets_mut("reserved_keywords").clear(); - snowflake_dialect.update_keywords_set_from_multiline_string( - "reserved_keywords", - SNOWFLAKE_RESERVED_KEYWORDS, + snowflake_dialect.replace_grammar( + "QuotedLiteralSegment", + one_of(vec![ + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral).to_matchable(), + TypedParser::new(SyntaxKind::DollarQuote, SyntaxKind::QuotedLiteral).to_matchable(), + ]) + .to_matchable(), ); - snowflake_dialect.sets_mut("datetime_units").clear(); - snowflake_dialect.sets_mut("datetime_units").extend([ - "YEAR", - "Y", - "YY", - "YYY", - "YYYY", - "YR", - "YEARS", - "YRS", - "MONTH", - "MM", - "MON", - "MONS", - "MONTHS", - "DAY", - "D", - "DD", - "DAYS", + snowflake_dialect.replace_grammar( + "LikeGrammar", + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("LIKE").to_matchable(), + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("ANY").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("RLIKE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ILIKE").to_matchable(), + Ref::keyword("ANY").optional().to_matchable(), + ]) + .to_matchable(), + Ref::keyword("REGEXP").to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "SelectClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("INTO").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::keyword("WHERE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::new("LimitClauseSegment").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "FromClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("WHERE").to_matchable(), + Ref::new("LimitClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), + Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), + Ref::new("WithDataClauseSegment").to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "WhereClauseTerminatorGrammar", + one_of(vec![ + Ref::new("LimitClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::keyword("OVERLAPS").to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "OrderByClauseTerminators", + one_of(vec![ + Ref::new("LimitClauseSegment").to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::new("FrameClauseUnitGrammar").to_matchable(), + Ref::keyword("SEPARATOR").to_matchable(), + Ref::keyword("MEASURES").to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.replace_grammar("TrimParametersGrammar", Nothing::new().to_matchable()); + + snowflake_dialect.replace_grammar( + "GroupByClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::new("LimitClauseSegment").to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "HavingClauseTerminatorGrammar", + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::new("LimitClauseSegment").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "NonStandardJoinTypeKeywordsGrammar", + one_of(vec![Ref::keyword("ASOF").to_matchable()]).to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "UnconditionalJoinKeywordsGrammar", + one_of(vec![ + Ref::new("NaturalJoinKeywordsGrammar").to_matchable(), + Ref::new("UnconditionalCrossJoinKeywordsGrammar").to_matchable(), + Ref::new("HorizontalJoinKeywordsGrammar").to_matchable(), + Ref::new("NonStandardJoinTypeKeywordsGrammar").to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "FunctionParameterGrammar", + Sequence::new(vec![ + one_of(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.replace_grammar( + "CollateGrammar", + Sequence::new(vec![ + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ); + + snowflake_dialect.sets_mut("unreserved_keywords").clear(); + + snowflake_dialect.update_keywords_set_from_multiline_string( + "unreserved_keywords", + SNOWFLAKE_UNRESERVED_KEYWORDS, + ); + + snowflake_dialect.sets_mut("reserved_keywords").clear(); + + snowflake_dialect.update_keywords_set_from_multiline_string( + "reserved_keywords", + SNOWFLAKE_RESERVED_KEYWORDS, + ); + + snowflake_dialect.sets_mut("datetime_units").clear(); + + snowflake_dialect.sets_mut("datetime_units").extend([ + "YEAR", + "Y", + "YY", + "YYY", + "YYYY", + "YR", + "YEARS", + "YRS", + "MONTH", + "MM", + "MON", + "MONS", + "MONTHS", + "DAY", + "D", + "DD", + "DAYS", "DAYOFMONTH", "DAYOFWEEK", "WEEKDAY", @@ -1257,345 +1470,62 @@ pub fn dialect() -> Dialect { "TZM", ]); - snowflake_dialect.replace_grammar( - "FunctionNameSegment", - Sequence::new(vec![ - // Project name, schema identifier, etc. - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("DotSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.terminators = vec![Ref::new("BracketedSegment").to_matchable()]; - }) - .to_matchable(), - // Base function name - one_of(vec![ - Ref::new("FunctionNameIdentifierSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), - // Snowflake's IDENTIFIER pseudo-function + snowflake_dialect.add([ + ( + "FunctionNameSegment".into(), + NodeMatcher::new(SyntaxKind::FunctionName, |_dialect| { Sequence::new(vec![ - Ref::keyword("IDENTIFIER").to_matchable(), - Bracketed::new(vec![ - one_of(vec![ - Ref::new("SingleQuotedIdentifierSegment").to_matchable(), - Ref::new("ReferencedVariableNameSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DotSegment").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.terminators = vec![Ref::new("BracketedSegment").to_matchable()]; + }) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.allow_gaps = false; - }) - .to_matchable(), - ); - - snowflake_dialect.add([( - "ConnectByClauseSegment".into(), - NodeMatcher::new(SyntaxKind::ConnectbyClause, |_| { - Sequence::new(vec![ - Ref::keyword("START").to_matchable(), - Ref::keyword("WITH").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("CONNECT").to_matchable(), - Ref::keyword("BY").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::keyword("PRIOR").optional().to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::keyword("PRIOR").optional().to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - )]); - - snowflake_dialect.replace_grammar( - "GroupByClauseSegment", - Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ - Sequence::new(vec![ one_of(vec![ - Ref::keyword("CUBE").to_matchable(), - Ref::keyword("ROLLUP").to_matchable(), + Ref::new("FunctionNameIdentifierSegment").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("GROUPING").to_matchable(), - Ref::keyword("SETS").to_matchable(), + Ref::keyword("IDENTIFIER").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("SingleQuotedIdentifierSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Bracketed::new(vec![Ref::new("GroupByContentsGrammar").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("ALL").to_matchable(), - Ref::new("GroupByContentsGrammar").to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.replace_grammar( - "ValuesClauseSegment", - Sequence::new(vec![ - Ref::keyword("VALUES").to_matchable(), - Delimited::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), ]) .config(|this| { - this.parse_mode = ParseMode::Greedy; + this.disallow_gaps(); }) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.add([( - "InsertStatementSegment".into(), - NodeMatcher::new(SyntaxKind::InsertStatement, |_| { - Sequence::new(vec![ - Ref::keyword("INSERT").to_matchable(), - Ref::keyword("OVERWRITE").optional().to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DatabaseRoleReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::DatabaseRoleReference, |_dialect| { one_of(vec![ - // Single table INSERT INTO Sequence::new(vec![ - Ref::keyword("INTO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), - ]) - .to_matchable(), - // Unconditional multi-table INSERT INTO - Sequence::new(vec![ - Ref::keyword("ALL").to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("INTO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - Ref::new("ValuesClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.min_times = 1; - }) - .to_matchable(), - Ref::new("SelectStatementSegment").to_matchable(), - ]) - .to_matchable(), - // Conditional multi-table INSERT INTO - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("ALL").to_matchable(), - ]) - .to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("WHEN").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("THEN").to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("INTO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - Ref::new("ValuesClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.min_times = 1; - }) - .to_matchable(), - ]) - .to_matchable(), + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DotSegment").to_matchable(), ]) .config(|this| { - this.min_times = 1; + this.optional(); }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ELSE").to_matchable(), - Ref::keyword("INTO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - Ref::new("ValuesClauseSegment").optional().to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("SelectStatementSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - )]); - - snowflake_dialect.replace_grammar( - "FunctionDefinitionGrammar", - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("LANGUAGE").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.replace_grammar( - "StatementSegment", - ansi::statement_segment().copy( - Some(vec![ - Ref::new("AccessStatementSegment").to_matchable(), - Ref::new("CreateStatementSegment").to_matchable(), - Ref::new("CreateTaskSegment").to_matchable(), - Ref::new("CreateUserSegment").to_matchable(), - Ref::new("CreateCloneStatementSegment").to_matchable(), - Ref::new("CreateProcedureStatementSegment").to_matchable(), - Ref::new("AlterProcedureStatementSegment").to_matchable(), - Ref::new("ScriptingBlockStatementSegment").to_matchable(), - Ref::new("ScriptingLetStatementSegment").to_matchable(), - Ref::new("ReturnStatementSegment").to_matchable(), - Ref::new("ShowStatementSegment").to_matchable(), - Ref::new("AlterAccountStatementSegment").to_matchable(), - Ref::new("AlterUserStatementSegment").to_matchable(), - Ref::new("AlterSessionStatementSegment").to_matchable(), - Ref::new("AlterTaskStatementSegment").to_matchable(), - Ref::new("SetAssignmentStatementSegment").to_matchable(), - Ref::new("CallStoredProcedureSegment").to_matchable(), - Ref::new("MergeStatementSegment").to_matchable(), - Ref::new("CopyIntoTableStatementSegment").to_matchable(), - Ref::new("CopyIntoLocationStatementSegment").to_matchable(), - Ref::new("FormatTypeOptions").to_matchable(), - Ref::new("AlterWarehouseStatementSegment").to_matchable(), - Ref::new("AlterShareStatementSegment").to_matchable(), - Ref::new("CreateExternalTableSegment").to_matchable(), - Ref::new("AlterExternalTableStatementSegment").to_matchable(), - Ref::new("CreateSchemaStatementSegment").to_matchable(), - Ref::new("AlterSchemaStatementSegment").to_matchable(), - Ref::new("CreateFunctionStatementSegment").to_matchable(), - Ref::new("AlterFunctionStatementSegment").to_matchable(), - Ref::new("CreateExternalFunctionStatementSegment").to_matchable(), - Ref::new("CreateStageSegment").to_matchable(), - Ref::new("AlterStageSegment").to_matchable(), - Ref::new("CreateStreamStatementSegment").to_matchable(), - Ref::new("AlterStreamStatementSegment").to_matchable(), - Ref::new("UnsetStatementSegment").to_matchable(), - Ref::new("UndropStatementSegment").to_matchable(), - Ref::new("CommentStatementSegment").to_matchable(), - Ref::new("CallStatementSegment").to_matchable(), - Ref::new("AlterViewStatementSegment").to_matchable(), - Ref::new("AlterMaterializedViewStatementSegment").to_matchable(), - Ref::new("DropProcedureStatementSegment").to_matchable(), - Ref::new("DropExternalTableStatementSegment").to_matchable(), - Ref::new("DropMaterializedViewStatementSegment").to_matchable(), - Ref::new("DropObjectStatementSegment").to_matchable(), - Ref::new("CreateFileFormatSegment").to_matchable(), - Ref::new("AlterFileFormatSegment").to_matchable(), - Ref::new("AlterPipeSegment").to_matchable(), - Ref::new("ListStatementSegment").to_matchable(), - Ref::new("GetStatementSegment").to_matchable(), - Ref::new("PutStatementSegment").to_matchable(), - Ref::new("RemoveStatementSegment").to_matchable(), - Ref::new("CreateDatabaseFromShareStatementSegment").to_matchable(), - Ref::new("AlterRoleStatementSegment").to_matchable(), - Ref::new("AlterStorageIntegrationSegment").to_matchable(), - Ref::new("ExecuteImmediateClauseSegment").to_matchable(), - Ref::new("ExecuteTaskClauseSegment").to_matchable(), - Ref::new("CreateSequenceStatementSegment").to_matchable(), - Ref::new("AlterSequenceStatementSegment").to_matchable(), - Ref::new("CreateResourceMonitorStatementSegment").to_matchable(), - Ref::new("AlterResourceMonitorStatementSegment").to_matchable(), - Ref::new("DropResourceMonitorStatementSegment").to_matchable(), - Ref::new("AlterDatabaseSegment").to_matchable(), - Ref::new("AlterMaskingPolicySegment").to_matchable(), - Ref::new("AlterNetworkPolicyStatementSegment").to_matchable(), - ]), - None, - None, - Some(vec![ - Ref::new("CreateIndexStatementSegment").to_matchable(), - Ref::new("DropIndexStatementSegment").to_matchable(), - ]), - Vec::new(), - false, - ), - ); - - snowflake_dialect.add([ - ( - "SetAssignmentStatementSegment".into(), - NodeMatcher::new(SyntaxKind::SetStatement, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("LocalVariableNameSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("LocalVariableNameSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), ]) @@ -1605,50 +1535,26 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CallStoredProcedureSegment".into(), - NodeMatcher::new(SyntaxKind::CallSegment, |_| { - Sequence::new(vec![ - Ref::keyword("CALL").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "WithinGroupClauseSegment".into(), - NodeMatcher::new(SyntaxKind::WithingroupClause, |_| { - Sequence::new(vec![ - Ref::keyword("WITHIN").to_matchable(), - Ref::keyword("GROUP").to_matchable(), - Bracketed::new(vec![ - Ref::new("OrderByClauseSegment").optional().to_matchable(), - ]) - .config(|this| { - this.parse_mode = ParseMode::Greedy; - }) - .to_matchable(), - ]) - .to_matchable() + "ExternalVolumeReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::ExternalVolumeReference, |_dialect| { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() }) .to_matchable() .into(), ), ( - "PatternSegment".into(), - NodeMatcher::new(SyntaxKind::PatternExpression, |_| { + "DropExternalVolumeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropExternalVolumeStatement, |_dialect| { Sequence::new(vec![ - Ref::new("CaretSegment").optional().to_matchable(), - one_of(vec![ - AnyNumberOf::new(vec![Ref::new("PatternOperatorGrammar").to_matchable()]) - .to_matchable(), - Delimited::new(vec![Ref::new("PatternOperatorGrammar").to_matchable()]) - .config(|this| this.delimiter(Ref::new("BitwiseOrSegment"))) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("DollarSegment").optional().to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("VOLUME").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ExternalVolumeReferenceSegment").to_matchable(), ]) .to_matchable() }) @@ -1656,119 +1562,108 @@ pub fn dialect() -> Dialect { .into(), ), ( - "MatchRecognizeClauseSegment".into(), - NodeMatcher::new(SyntaxKind::MatchRecognizeClause, |_| { + "CreateExternalVolumeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateExternalVolumeStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("MATCH_RECOGNIZE").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("VOLUME").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ExternalVolumeReferenceSegment").to_matchable(), + Ref::keyword("STORAGE_LOCATIONS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), Bracketed::new(vec![ - Ref::new("PartitionClauseSegment").optional().to_matchable(), - Ref::new("OrderByClauseSegment").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("MEASURES").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("FINAL").to_matchable(), - Ref::keyword("RUNNING").to_matchable(), + Delimited::new(vec![ + Bracketed::new(vec![ + Ref::keyword("NAME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("STORAGE_PROVIDER").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("S3").to_matchable(), + Ref::keyword("AZURE").to_matchable(), + Ref::keyword("GCS").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - Ref::new("AliasExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("ONE").to_matchable(), - Ref::keyword("ROW").to_matchable(), - Ref::keyword("PER").to_matchable(), - Ref::keyword("MATCH").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("ROWS").to_matchable(), - Ref::keyword("PER").to_matchable(), - Ref::keyword("MATCH").to_matchable(), - one_of(vec![ Sequence::new(vec![ - Ref::keyword("SHOW").to_matchable(), - Ref::keyword("EMPTY").to_matchable(), - Ref::keyword("MATCHES").to_matchable(), + Ref::keyword("STORAGE_AWS_ROLE_ARN").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("OMIT").to_matchable(), - Ref::keyword("EMPTY").to_matchable(), - Ref::keyword("MATCHES").to_matchable(), + Ref::keyword("STORAGE_BASE_URL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("UNMATCHED").to_matchable(), - Ref::keyword("ROWS").to_matchable(), + Ref::keyword("STORAGE_AWS_EXTERNAL_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AZURE_TENANT_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENCRYPTION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("S3EncryptionOption").to_matchable(), + Ref::new("GCSEncryptionOption").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("KMS_KEY_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::keyword("AFTER").to_matchable(), - Ref::keyword("MATCH").to_matchable(), - Ref::keyword("SKIP").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("PAST").to_matchable(), - Ref::keyword("LAST").to_matchable(), - Ref::keyword("ROW").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TO").to_matchable(), - Ref::keyword("NEXT").to_matchable(), - Ref::keyword("ROW").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TO").to_matchable(), - one_of(vec![ - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("LAST").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("PATTERN").to_matchable(), - Bracketed::new(vec![Ref::new("PatternSegment").to_matchable()]) - .to_matchable(), - Ref::keyword("DEFINE").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("ALLOW_WRITES").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -1777,63 +1672,112 @@ pub fn dialect() -> Dialect { .into(), ), ( - "ChangesClauseSegment".into(), - NodeMatcher::new(SyntaxKind::ChangesClause, |_| { + "AlterExternalVolumeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterExternalVolumeStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("CHANGES").to_matchable(), - Bracketed::new(vec![ - Ref::keyword("INFORMATION").to_matchable(), - Ref::new("ParameterAssignerSegment").to_matchable(), - one_of(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::keyword("APPEND_ONLY").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("VOLUME").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ExternalVolumeReferenceSegment").to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::keyword("AT").to_matchable(), + Ref::keyword("ADD").to_matchable(), + Ref::keyword("STORAGE_LOCATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), Bracketed::new(vec![ - one_of(vec![ - Ref::keyword("TIMESTAMP").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - Ref::keyword("STATEMENT").to_matchable(), + Ref::keyword("NAME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("STORAGE_PROVIDER").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("S3").to_matchable(), + Ref::keyword("AZURE").to_matchable(), + Ref::keyword("GCS").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STORAGE_AWS_ROLE_ARN").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STORAGE_BASE_URL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STORAGE_AWS_EXTERNAL_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AZURE_TENANT_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENCRYPTION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("S3EncryptionOption").to_matchable(), + Ref::new("GCSEncryptionOption").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("KMS_KEY_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), - Ref::new("ParameterAssignerSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("BEFORE").to_matchable(), - Bracketed::new(vec![ - Ref::keyword("STATEMENT").to_matchable(), - Ref::new("ParameterAssignerSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("REMOVE").to_matchable(), + Ref::keyword("STORAGE_LOCATION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("END").to_matchable(), - Bracketed::new(vec![ - one_of(vec![ - Ref::keyword("TIMESTAMP").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - Ref::keyword("STATEMENT").to_matchable(), - ]) - .to_matchable(), - Ref::new("ParameterAssignerSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("ALLOW_WRITES").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable() @@ -1842,58 +1786,39 @@ pub fn dialect() -> Dialect { .into(), ), ( - "MatchConditionSegment".into(), - NodeMatcher::new(SyntaxKind::MatchConditionClause, |_| { - Sequence::new(vec![ - Ref::keyword("MATCH_CONDITION").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "FromAtExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::FromAtExpression, |_| { - Sequence::new(vec![ - Ref::keyword("AT").to_matchable(), - Bracketed::new(vec![ - one_of(vec![ - Ref::keyword("TIMESTAMP").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - Ref::keyword("STATEMENT").to_matchable(), + "ConnectByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ConnectbyClause, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("START").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("CONNECT").to_matchable(), + Ref::keyword("BY").to_matchable(), + Delimited::new(vec![ + optionally_bracketed(vec![ + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Ref::new("ParameterAssignerSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "FromBeforeExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::FromBeforeExpression, |_| { - Sequence::new(vec![ - Ref::keyword("BEFORE").to_matchable(), - Bracketed::new(vec![ - one_of(vec![ - Ref::keyword("TIMESTAMP").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - Ref::keyword("STATEMENT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONNECT").to_matchable(), + Ref::keyword("BY").to_matchable(), + optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("START").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("ParameterAssignerSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), ]) - .config(|this| { - this.parse_mode = ParseMode::Greedy; - }) .to_matchable(), ]) .to_matchable() @@ -1902,22 +1827,33 @@ pub fn dialect() -> Dialect { .into(), ), ( - "FromPivotExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::FromPivotExpression, |_| { + "GroupByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::GroupbyClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("PIVOT").to_matchable(), - Bracketed::new(vec![ - Ref::new("FunctionSegment").to_matchable(), - Ref::keyword("FOR").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("IN").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("LiteralGrammar").to_matchable()]) + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("CUBE").to_matchable(), + Ref::keyword("ROLLUP").to_matchable(), + Sequence::new(vec![ + Ref::keyword("GROUPING").to_matchable(), + Ref::keyword("SETS").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![Ref::new("GroupByContentsGrammar").to_matchable()]) .to_matchable(), ]) .to_matchable(), + Ref::keyword("ALL").to_matchable(), + Ref::new("GroupByContentsGrammar").to_matchable(), ]) .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) @@ -1925,21 +1861,22 @@ pub fn dialect() -> Dialect { .into(), ), ( - "FromUnpivotExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::FromUnpivotExpression, |_| { + "ValuesClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ValuesClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("UNPIVOT").to_matchable(), - Bracketed::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("FOR").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("IN").to_matchable(), + Ref::keyword("VALUES").to_matchable(), + Delimited::new(vec![ Bracketed::new(vec![ Delimited::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) .to_matchable(), ]) .to_matchable(), @@ -1949,59 +1886,93 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - snowflake_dialect.replace_grammar( - "SamplingExpressionSegment", - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("SAMPLE").to_matchable(), - Ref::keyword("TABLESAMPLE").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("BERNOULLI").to_matchable(), - Ref::keyword("ROW").to_matchable(), - Ref::keyword("SYSTEM").to_matchable(), - Ref::keyword("BLOCK").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Bracketed::new(vec![ - one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ReferencedVariableNameSegment").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("ROWS").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("REPEATABLE").to_matchable(), - Ref::keyword("SEED").to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.add([ ( - "NamedParameterExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::SnowflakeKeywordExpression, |_| { + "InsertStatementSegment".into(), + NodeMatcher::new(SyntaxKind::InsertStatement, |_dialect| { Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("ParameterAssignerSegment").to_matchable(), + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("OVERWRITE").optional().to_matchable(), one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("INTO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("INTO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + Ref::new("ValuesClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), + Ref::new("SelectStatementSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("WHEN").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("THEN").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("INTO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + Ref::new("ValuesClauseSegment") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ELSE").to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + Ref::new("ValuesClauseSegment").optional().to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("SelectStatementSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -2011,120 +1982,260 @@ pub fn dialect() -> Dialect { .into(), ), ( - "SemiStructuredAccessorSegment".into(), - NodeMatcher::new(SyntaxKind::SemiStructuredExpression, |_| { + "FunctionDefinitionGrammar".into(), + NodeMatcher::new(SyntaxKind::FunctionDefinition, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Ref::new("DotSegment").to_matchable(), - Ref::new("ColonSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("LANGUAGE").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - one_of(vec![ - Ref::new("NakedSemiStructuredElementSegment").to_matchable(), - Ref::new("QuotedSemiStructuredElementSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StatementSegment".into(), + NodeMatcher::new(SyntaxKind::Statement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("StatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("ScriptingBlockStatementSegment").to_matchable(), + ]), + None, + Some(Ref::new("TransactionStatementSegment").to_matchable()), + None, + vec![], + false, + ) + .copy( + Some(vec![ + Ref::new("AccessStatementSegment").to_matchable(), + Ref::new("CreateStatementSegment").to_matchable(), + Ref::new("CreateTaskSegment").to_matchable(), + Ref::new("CreateUserSegment").to_matchable(), + Ref::new("CreateCloneStatementSegment").to_matchable(), + Ref::new("CreateProcedureStatementSegment").to_matchable(), + Ref::new("AlterProcedureStatementSegment").to_matchable(), + Ref::new("ScriptingLetStatementSegment").to_matchable(), + Ref::new("ScriptingDeclareStatementSegment").to_matchable(), + Ref::new("ReturnStatementSegment").to_matchable(), + Ref::new("ShowStatementSegment").to_matchable(), + Ref::new("AlterAccountStatementSegment").to_matchable(), + Ref::new("AlterUserStatementSegment").to_matchable(), + Ref::new("AlterSessionStatementSegment").to_matchable(), + Ref::new("AlterTaskStatementSegment").to_matchable(), + Ref::new("SetAssignmentStatementSegment").to_matchable(), + Ref::new("CallStoredProcedureSegment").to_matchable(), + Ref::new("MergeStatementSegment").to_matchable(), + Ref::new("CopyIntoTableStatementSegment").to_matchable(), + Ref::new("CopyIntoLocationStatementSegment").to_matchable(), + Ref::new("CopyFilesIntoLocationStatementSegment").to_matchable(), + Ref::new("FormatTypeOptions").to_matchable(), + Ref::new("AlterWarehouseStatementSegment").to_matchable(), + Ref::new("AlterShareStatementSegment").to_matchable(), + Ref::new("CreateExternalTableSegment").to_matchable(), + Ref::new("AlterExternalTableStatementSegment").to_matchable(), + Ref::new("CreateSchemaStatementSegment").to_matchable(), + Ref::new("AlterSchemaStatementSegment").to_matchable(), + Ref::new("CreateFunctionStatementSegment").to_matchable(), + Ref::new("AlterFunctionStatementSegment").to_matchable(), + Ref::new("CreateExternalFunctionStatementSegment").to_matchable(), + Ref::new("CreateStageSegment").to_matchable(), + Ref::new("AlterStageSegment").to_matchable(), + Ref::new("CreateStreamStatementSegment").to_matchable(), + Ref::new("CreateStreamlitStatementSegment").to_matchable(), + Ref::new("CreateCortexSearchServiceStatementSegment").to_matchable(), + Ref::new("AlterStreamStatementSegment").to_matchable(), + Ref::new("AlterStreamlitStatementSegment").to_matchable(), + Ref::new("AlterCortexSearchServiceStatementSegment").to_matchable(), + Ref::new("UnsetStatementSegment").to_matchable(), + Ref::new("UndropStatementSegment").to_matchable(), + Ref::new("CommentStatementSegment").to_matchable(), + Ref::new("CallStatementSegment").to_matchable(), + Ref::new("AlterViewStatementSegment").to_matchable(), + Ref::new("AlterMaterializedViewStatementSegment").to_matchable(), + Ref::new("DropProcedureStatementSegment").to_matchable(), + Ref::new("DropExternalTableStatementSegment").to_matchable(), + Ref::new("DropMaterializedViewStatementSegment").to_matchable(), + Ref::new("DropObjectStatementSegment").to_matchable(), + Ref::new("CreateFileFormatSegment").to_matchable(), + Ref::new("AlterFileFormatSegment").to_matchable(), + Ref::new("AlterPipeSegment").to_matchable(), + Ref::new("ListStatementSegment").to_matchable(), + Ref::new("GetStatementSegment").to_matchable(), + Ref::new("PutStatementSegment").to_matchable(), + Ref::new("RemoveStatementSegment").to_matchable(), + Ref::new("CreateDatabaseFromShareStatementSegment").to_matchable(), + Ref::new("CreateDatabaseRoleStatementSegment").to_matchable(), + Ref::new("AlterRoleStatementSegment").to_matchable(), + Ref::new("AlterStorageIntegrationSegment").to_matchable(), + Ref::new("ExecuteImmediateClauseSegment").to_matchable(), + Ref::new("ExecuteTaskClauseSegment").to_matchable(), + Ref::new("CreateResourceMonitorStatementSegment").to_matchable(), + Ref::new("AlterResourceMonitorStatementSegment").to_matchable(), + Ref::new("CreateSequenceStatementSegment").to_matchable(), + Ref::new("AlterSequenceStatementSegment").to_matchable(), + Ref::new("AlterDatabaseSegment").to_matchable(), + Ref::new("AlterMaskingPolicySegment").to_matchable(), + Ref::new("AlterNetworkPolicyStatementSegment").to_matchable(), + Ref::new("CreateExternalVolumeStatementSegment").to_matchable(), + Ref::new("DropExternalVolumeStatementSegment").to_matchable(), + Ref::new("AlterExternalVolumeStatementSegment").to_matchable(), + Ref::new("ForInLoopSegment").to_matchable(), + Ref::new("CreateEventTableStatementSegment").to_matchable(), + Ref::new("CreatePasswordPolicyStatementSegment").to_matchable(), + Ref::new("AlterPasswordPolicyStatementSegment").to_matchable(), + Ref::new("DropPasswordPolicyStatementSegment").to_matchable(), + Ref::new("CreateRowAccessPolicyStatementSegment").to_matchable(), + Ref::new("AlterRowAccessPolicyStatmentSegment").to_matchable(), + Ref::new("AlterTagStatementSegment").to_matchable(), + Ref::new("ExceptionBlockStatementSegment").to_matchable(), + Ref::new("AlterDynamicTableStatementSegment").to_matchable(), + Ref::new("DropDynamicTableSegment").to_matchable(), + Ref::new("DropIcebergTableStatementSegment").to_matchable(), + Ref::new("CreateAuthenticationPolicySegment").to_matchable(), + Ref::new("DropResourceMonitorStatementSegment").to_matchable(), + Ref::new("ScriptingIfStatementSegment").to_matchable(), + Ref::new("ScriptingRaiseStatementSegment").to_matchable(), + ]), + None, + None, + Some(vec![ + Ref::new("CreateIndexStatementSegment").to_matchable(), + Ref::new("DropIndexStatementSegment").to_matchable(), + ]), + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "SetAssignmentStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SetStatement, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("LocalVariableNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - Ref::new("ArrayAccessorSegment").optional().to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::new("DotSegment").to_matchable(), - Ref::new("ColonSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("LocalVariableNameSegment").to_matchable(), ]) .to_matchable(), - one_of(vec![ - Ref::new("NakedSemiStructuredElementSegment").to_matchable(), - Ref::new("QuotedSemiStructuredElementSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), ]) .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) - .config(|this| { - this.allow_gaps = true; - }) .to_matchable(), - Ref::new("ArrayAccessorSegment").optional().to_matchable(), ]) - .config(|this| { - this.allow_gaps = true; - }) .to_matchable(), ]) - .config(|this| { - this.allow_gaps = true; - }) .to_matchable() }) .to_matchable() .into(), ), ( - "QualifyClauseSegment".into(), - NodeMatcher::new(SyntaxKind::QualifyClause, |_| { + "CallStoredProcedureSegment".into(), + NodeMatcher::new(SyntaxKind::CallSegment, |_dialect| { Sequence::new(vec![ - Ref::keyword("QUALIFY").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("CALL").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WithinGroupClauseSegment".into(), + NodeMatcher::new(SyntaxKind::WithingroupClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("WITHIN").to_matchable(), + Ref::keyword("GROUP").to_matchable(), + Bracketed::new(vec![ + Ref::new("OrderByClauseSegment").optional().to_matchable(), ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) .to_matchable(), - MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - snowflake_dialect.replace_grammar( - "SelectStatementSegment", - ansi::select_statement().copy( - Some(vec![ - Ref::new("QualifyClauseSegment").optional().to_matchable(), - ]), - None, - Some(Ref::new("OrderByClauseSegment").optional().to_matchable()), - None, - Vec::new(), - false, - ), - ); - - snowflake_dialect.replace_grammar( - "WildcardExpressionSegment", - ansi::wildcard_expression_segment().copy( - Some(vec![ - Ref::new("ExcludeClauseSegment").optional().to_matchable(), - Ref::new("ReplaceClauseSegment").optional().to_matchable(), - Ref::new("RenameClauseSegment").optional().to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ), - ); - - snowflake_dialect.add([ ( - "ExcludeClauseSegment".into(), - NodeMatcher::new(SyntaxKind::SelectExcludeClause, |_| { + "FromExpressionElementSegment".into(), + NodeMatcher::new(SyntaxKind::FromExpressionElement, |_dialect| { Sequence::new(vec![ - Ref::keyword("EXCLUDE").to_matchable(), + Ref::new("PreTableFunctionKeywordsGrammar") + .optional() + .to_matchable(), + optionally_bracketed(vec![Ref::new("TableExpressionSegment").to_matchable()]) + .to_matchable(), one_of(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - ]) + Ref::new("FromAtExpressionSegment").to_matchable(), + Ref::new("FromBeforeExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("AliasExpressionSegment") + .exclude(one_of(vec![ + Ref::new("FromClauseTerminatorGrammar").to_matchable(), + Ref::new("SamplingExpressionSegment").to_matchable(), + Ref::new("ChangesClauseSegment").to_matchable(), + Ref::new("JoinLikeClauseGrammar").to_matchable(), + Ref::keyword("CROSS").to_matchable(), + ])) + .optional() .to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), + Ref::new("AliasExpressionSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("SamplingExpressionSegment") + .optional() + .to_matchable(), + Ref::new("PostTableExpressionGrammar") + .optional() + .to_matchable(), ]) .to_matchable() }) @@ -2132,31 +2243,12 @@ pub fn dialect() -> Dialect { .into(), ), ( - "RenameClauseSegment".into(), - NodeMatcher::new(SyntaxKind::SelectRenameClause, |_| { + "MatchConditionSegment".into(), + NodeMatcher::new(SyntaxKind::MatchCondition, |_dialect| { Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) + Ref::keyword("MATCH_CONDITION").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) .to_matchable(), - ]) - .to_matchable(), ]) .to_matchable() }) @@ -2164,365 +2256,151 @@ pub fn dialect() -> Dialect { .into(), ), ( - "ReplaceClauseSegment".into(), - NodeMatcher::new(SyntaxKind::SelectReplaceClause, |_| { + "PatternSegment".into(), + NodeMatcher::new(SyntaxKind::PatternExpression, |_dialect| { Sequence::new(vec![ - Ref::keyword("REPLACE").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) + Ref::new("CaretSegment").optional().to_matchable(), + one_of(vec![ + AnyNumberOf::new(vec![Ref::new("PatternOperatorGrammar").to_matchable()]) + .to_matchable(), + Delimited::new(vec![Ref::new("PatternOperatorGrammar").to_matchable()]) + .config(|this| { + this.delimiter(Ref::new("BitwiseOrSegment")); + }) .to_matchable(), - ]) - .to_matchable(), ]) .to_matchable(), + Ref::new("DollarSegment").optional().to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - snowflake_dialect.replace_grammar( - "SelectClauseModifierSegment", - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DISTINCT").to_matchable(), - Ref::keyword("ALL").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TOP").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.replace_grammar( - "AlterTableStatementSegment", - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - one_of(vec![ - // Rename - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - // Swap With - Sequence::new(vec![ - Ref::keyword("SWAP").to_matchable(), - Ref::keyword("WITH").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - // searchOptimizationAction - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("DROP").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("SEARCH").to_matchable(), - Ref::keyword("OPTIMIZATION").to_matchable(), - ]) - .to_matchable(), - Ref::new("AlterTableClusteringActionSegment").to_matchable(), - Ref::new("AlterTableConstraintActionSegment").to_matchable(), - // SET Table options - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - one_of(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::keyword("COMMENT").to_matchable(), - ]) - .to_matchable(), - Ref::new("EqualsSegment").optional().to_matchable(), - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - // Drop primary key - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::new("PrimaryKeyGrammar").to_matchable(), - ]) - .to_matchable(), - // Add primary key + ( + "MatchRecognizeClauseSegment".into(), + NodeMatcher::new(SyntaxKind::MatchRecognizeClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::new("PrimaryKeyGrammar").to_matchable(), + Ref::keyword("MATCH_RECOGNIZE").to_matchable(), Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .config(|this| this.optional()) + Ref::new("PartitionClauseSegment").optional().to_matchable(), + Ref::new("OrderByClauseSegment").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("MEASURES").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("FINAL").to_matchable(), + Ref::keyword("RUNNING").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("AliasExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("AlterTableTableColumnActionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.add([ - ( - "AlterTableTableColumnActionSegment".into(), - NodeMatcher::new(SyntaxKind::AlterTableTableColumnAction, |_| { - one_of(vec![ - // Add Column - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - Delimited::new(vec![ + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("ONE").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("PER").to_matchable(), + Ref::keyword("MATCH").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("ROWS").to_matchable(), + Ref::keyword("PER").to_matchable(), + Ref::keyword("MATCH").to_matchable(), one_of(vec![ - // Default Sequence::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("SHOW").to_matchable(), + Ref::keyword("EMPTY").to_matchable(), + Ref::keyword("MATCHES").to_matchable(), ]) .to_matchable(), - // Auto-increment/identity column Sequence::new(vec![ - one_of(vec![ - Ref::keyword("AUTOINCREMENT").to_matchable(), - Ref::keyword("IDENTITY").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - // ( , ) - Bracketed::new(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("CommaSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - // START INCREMENT - Sequence::new(vec![ - Ref::keyword("START").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::keyword("INCREMENT").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("OMIT").to_matchable(), + Ref::keyword("EMPTY").to_matchable(), + Ref::keyword("MATCHES").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - // Masking Policy - Sequence::new(vec![ - Ref::keyword("WITH").optional().to_matchable(), - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("ColumnReferenceSegment") - .to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::keyword("UNMATCHED").to_matchable(), + Ref::keyword("ROWS").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("CommentClauseSegment").optional().to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable(), - // Rename column - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - // Alter/Modify column(s) - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("MODIFY").to_matchable(), - ]) - .to_matchable(), - optionally_bracketed(vec![ - Delimited::new(vec![ - // Add things + Sequence::new(vec![ + Ref::keyword("AFTER").to_matchable(), + Ref::keyword("MATCH").to_matchable(), + Ref::keyword("SKIP").to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("COLUMN").optional().to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("DotSegment").to_matchable(), - Ref::keyword("NEXTVAL").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("DROP").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("NULL").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Sequence::new(vec![ - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("DATA").optional().to_matchable(), - ]) - .to_matchable(), - Ref::keyword("TYPE").optional().to_matchable(), - ]) - .to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("CommentClauseSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("PAST").to_matchable(), + Ref::keyword("LAST").to_matchable(), + Ref::keyword("ROW").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("COLUMN").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::keyword("SET").to_matchable(), - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("ColumnReferenceSegment") - .to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::keyword("NEXT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TO").to_matchable(), + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("LAST").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLUMN").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::keyword("UNSET").to_matchable(), - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLUMN").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::keyword("SET").to_matchable(), - Ref::keyword("TAG").to_matchable(), - Ref::new("TagReferenceSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLUMN").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::keyword("UNSET").to_matchable(), - Ref::keyword("TAG").to_matchable(), - Ref::new("TagReferenceSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable(), - // Drop column - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + Ref::keyword("PATTERN").to_matchable(), + Bracketed::new(vec![Ref::new("PatternSegment").to_matchable()]) .to_matchable(), - ]) - .to_matchable(), - // Add or Modify column - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("MODIFY").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - Ref::new("ColumnDefinitionSegment").to_matchable(), - one_of(vec![ + Ref::keyword("DEFINE").to_matchable(), + Delimited::new(vec![ Sequence::new(vec![ - one_of(vec![ - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("AFTER").to_matchable(), - ]) - .to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - // Bracketed Version of the same - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), @@ -2533,49 +2411,125 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterTableClusteringActionSegment".into(), - NodeMatcher::new(SyntaxKind::AlterTableClusteringAction, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CLUSTER").to_matchable(), - Ref::keyword("BY").to_matchable(), + "ChangesClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ChangesClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CHANGES").to_matchable(), + Bracketed::new(vec![ + Ref::keyword("INFORMATION").to_matchable(), + Ref::new("ParameterAssignerSegment").to_matchable(), one_of(vec![ - Ref::new("FunctionSegment").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("APPEND_ONLY").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("AT").to_matchable(), Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), + one_of(vec![ + Ref::keyword("TIMESTAMP").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), + Ref::keyword("STATEMENT").to_matchable(), + Ref::keyword("STREAM").to_matchable(), + ]) + .to_matchable(), + Ref::new("ParameterAssignerSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BEFORE").to_matchable(), + Bracketed::new(vec![ + Ref::keyword("STATEMENT").to_matchable(), + Ref::new("ParameterAssignerSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("RECLUSTER").to_matchable(), - Sequence::new(vec![ - Ref::keyword("MAX_SIZE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("END").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::keyword("TIMESTAMP").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), + Ref::keyword("STATEMENT").to_matchable(), + ]) + .to_matchable(), + Ref::new("ParameterAssignerSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) .to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FromAtExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::FromAtExpression, |_dialect| { + Sequence::new(vec![ + Ref::keyword("AT").to_matchable(), + Bracketed::new(vec![ one_of(vec![ - Ref::keyword("SUSPEND").to_matchable(), - Ref::keyword("RESUME").to_matchable(), + Ref::keyword("TIMESTAMP").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), + Ref::keyword("STATEMENT").to_matchable(), ]) .to_matchable(), - Ref::keyword("RECLUSTER").to_matchable(), + Ref::new("ParameterAssignerSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("CLUSTERING").to_matchable(), - Ref::keyword("KEY").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FromBeforeExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::FromBeforeExpression, |_dialect| { + Sequence::new(vec![ + Ref::keyword("BEFORE").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::keyword("TIMESTAMP").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), + Ref::keyword("STATEMENT").to_matchable(), + ]) + .to_matchable(), + Ref::new("ParameterAssignerSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) .to_matchable(), ]) .to_matchable() @@ -2584,95 +2538,48 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterTableConstraintActionSegment".into(), - NodeMatcher::new(SyntaxKind::AlterTableConstraintAction, |_| { - one_of(vec![ - // Add Column - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Sequence::new(vec![ - Ref::keyword("CONSTRAINT").to_matchable(), + "FromPivotExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::FromPivotExpression, |_dialect| { + Sequence::new(vec![ + Ref::keyword("PIVOT").to_matchable(), + Bracketed::new(vec![ + Ref::new("FunctionSegment").to_matchable(), + Ref::keyword("FOR").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("IN").to_matchable(), + Bracketed::new(vec![ one_of(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::new("PrimaryKeyGrammar").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("AliasExpressionSegment") + .optional() + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ Sequence::new(vec![ - Ref::new("ForeignKeyGrammar").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("REFERENCES").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNIQUE").to_matchable(), - Bracketed::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("ANY").to_matchable(), + Ref::new("OrderByClauseSegment").optional().to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + Ref::new("SelectStatementSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), Sequence::new(vec![ - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Ref::new("PrimaryKeyGrammar").to_matchable(), - Ref::new("ForeignKeyGrammar").to_matchable(), - Ref::keyword("UNIQUE").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Bracketed::new(vec![Ref::new("LiteralGrammar").to_matchable()]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), ]) .to_matchable(), ]) @@ -2682,89 +2589,137 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterWarehouseStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterWarehouseStatement, |_| { + "FromUnpivotExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::FromUnpivotExpression, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("WAREHOUSE").to_matchable(), + Ref::keyword("UNPIVOT").to_matchable(), Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), + one_of(vec![ + Ref::keyword("INCLUDE").to_matchable(), + Ref::keyword("EXCLUDE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("NULLS").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::new("ObjectReferenceSegment").optional().to_matchable(), - one_of(vec![ - Ref::keyword("SUSPEND").to_matchable(), - Sequence::new(vec![ - Ref::keyword("RESUME").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("SUSPENDED").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), + Bracketed::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("FOR").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("IN").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::new("ObjectReferenceSegment").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("ABORT").to_matchable(), - Ref::keyword("ALL").to_matchable(), - Ref::keyword("QUERIES").to_matchable(), - ]) - .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SamplingExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::SampleExpression, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("SAMPLE").to_matchable(), + Ref::keyword("TABLESAMPLE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("BERNOULLI").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("SYSTEM").to_matchable(), + Ref::keyword("BLOCK").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("ROWS").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("REPEATABLE").to_matchable(), + Ref::keyword("SEED").to_matchable(), ]) .to_matchable(), + Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "NamedParameterExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::SnowflakeKeywordExpression, |_dialect| { + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("ParameterAssignerSegment").to_matchable(), + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SemiStructuredAccessorSegment".into(), + NodeMatcher::new(SyntaxKind::SemiStructuredExpression, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::new("DotSegment").to_matchable(), + Ref::new("ColonSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::new("NakedSemiStructuredElementSegment").to_matchable(), + Ref::new("QuotedSemiStructuredElementSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ArrayAccessorSegment").optional().to_matchable(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::new("ObjectReferenceSegment").optional().to_matchable(), - Ref::keyword("SET").to_matchable(), one_of(vec![ - AnyNumberOf::new(vec![ - Ref::new("CommaSegment").optional().to_matchable(), - Ref::new("WarehouseObjectPropertiesSegment").to_matchable(), - Ref::new("CommentEqualsClauseSegment").to_matchable(), - Ref::new("WarehouseObjectParamsSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("TagEqualsSegment").to_matchable(), + Ref::new("DotSegment").to_matchable(), + Ref::new("ColonSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("UNSET").to_matchable(), one_of(vec![ - Delimited::new(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TAG").to_matchable(), - Delimited::new(vec![ - Ref::new("TagReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::new("NakedSemiStructuredElementSegment").to_matchable(), + Ref::new("QuotedSemiStructuredElementSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Ref::new("ArrayAccessorSegment").optional().to_matchable(), ]) .to_matchable(), ]) @@ -2774,71 +2729,130 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterShareStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterShareStatement, |_| { + "QualifyClauseSegment".into(), + NodeMatcher::new(SyntaxKind::QualifyClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("SHARE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + MetaSegment::implicit_indent().to_matchable(), + one_of(vec![ + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - one_of(vec![ + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("SelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("QualifyClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("OrderByClauseSegment").optional().to_matchable()), + None, + vec![], + false, + ) + .copy( + Some(vec![ + Ref::new("IntoClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("FromClauseSegment").optional().to_matchable()), + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "SelectClauseElementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClauseElement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("SelectClauseElementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("REMOVE").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("ACCOUNTS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Delimited::new(vec![Ref::new("NakedIdentifierSegment").to_matchable()]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SHARE_RESTRICTIONS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::new("SystemFunctionName").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("LiteralGrammar").to_matchable()]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("ACCOUNTS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Delimited::new(vec![Ref::new("NakedIdentifierSegment").to_matchable()]) - .to_matchable(), - Ref::new("CommentEqualsClauseSegment") - .optional() - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("TagEqualsSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Ref::keyword("TAG").to_matchable(), - Ref::new("TagReferenceSegment").to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("CommaSegment").to_matchable(), - Ref::new("TagReferenceSegment").to_matchable(), + ]), + None, + Some(Ref::new("WildcardExpressionSegment").to_matchable()), + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "WildcardExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::WildcardExpression, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("WildcardExpressionSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("ExcludeClauseSegment").optional().to_matchable(), + Ref::new("ReplaceClauseSegment").optional().to_matchable(), + Ref::new("RenameClauseSegment").optional().to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "ExcludeClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SelectExcludeClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("EXCLUDE").to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Ref::keyword("COMMENT").to_matchable(), - ]) - .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), ]) @@ -2848,123 +2862,48 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterStorageIntegrationSegment".into(), - NodeMatcher::new(SyntaxKind::AlterStorageIntegrationStatement, |_| { + "RenameClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SelectRenameClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("STORAGE").optional().to_matchable(), - Ref::keyword("INTEGRATION").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("RENAME").to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - one_of(vec![ - Ref::new("TagEqualsSegment").optional().to_matchable(), - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ENABLED").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("STORAGE_AWS_ROLE_ARN").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("STORAGE_AWS_OBJECT_ACL") - .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("AZURE_TENANT_ID").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("STORAGE_ALLOWED_LOCATIONS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("S3Path").to_matchable(), - Ref::new("GCSPath").to_matchable(), - Ref::new("AzureBlobStoragePath") - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![ - Ref::new("QuotedStarSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("STORAGE_BLOCKED_LOCATIONS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("S3Path").to_matchable(), - Ref::new("GCSPath").to_matchable(), - Ref::new("AzureBlobStoragePath").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("TAG").to_matchable(), - Delimited::new(vec![ - Ref::new("TagReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("COMMENT").to_matchable(), - Ref::keyword("ENABLED").to_matchable(), - Ref::keyword("STORAGE_BLOCKED_LOCATIONS").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ReplaceClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SelectReplaceClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("REPLACE").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), ]) @@ -2978,118 +2917,114 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterExternalTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterExternalTableStatement, |_| { + "SelectClauseModifierSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClauseModifier, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DISTINCT").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TOP").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTableStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ALTER").to_matchable(), - Ref::keyword("EXTERNAL").to_matchable(), Ref::keyword("TABLE").to_matchable(), Ref::new("IfExistsGrammar").optional().to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::keyword("REFRESH").to_matchable(), - Ref::new("QuotedLiteralSegment").optional().to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SWAP").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ one_of(vec![ Ref::keyword("ADD").to_matchable(), - Ref::keyword("REMOVE").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("FILES").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("DROP").to_matchable(), ]) .to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("OPTIMIZATION").to_matchable(), ]) .to_matchable(), + Ref::new("AlterTableClusteringActionSegment").to_matchable(), + Ref::new("AlterTableConstraintActionSegment").to_matchable(), Sequence::new(vec![ Ref::keyword("SET").to_matchable(), - Sequence::new(vec![ - Ref::keyword("AUTO_REFRESH").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + one_of(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::new("TagEqualsSegment").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Ref::new("TagEqualsSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ Ref::keyword("DROP").to_matchable(), - Ref::keyword("PARTITION").to_matchable(), - Ref::keyword("LOCATION").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("PrimaryKeyGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ Ref::keyword("ADD").to_matchable(), - Ref::keyword("PARTITION").to_matchable(), + Ref::new("PrimaryKeyGrammar").to_matchable(), Bracketed::new(vec![ Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - Ref::keyword("LOCATION").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "CommentEqualsClauseSegment".into(), - NodeMatcher::new(SyntaxKind::CommentEqualsClause, |_| { - Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "TagBracketedEqualsSegment".into(), - NodeMatcher::new(SyntaxKind::TagBracketedEquals, |_| { - Sequence::new(vec![ - Sequence::new(vec![Ref::keyword("WITH").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("TAG").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("TagReferenceSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("AlterTableTableColumnActionSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Ref::new("DataGovernancePolicyTagActionSegment").to_matchable(), ]) .to_matchable(), ]) @@ -3099,536 +3034,463 @@ pub fn dialect() -> Dialect { .into(), ), ( - "TagEqualsSegment".into(), - NodeMatcher::new(SyntaxKind::TagEquals, |_| { - Sequence::new(vec![ - Ref::keyword("TAG").to_matchable(), - Delimited::new(vec![ + "DataGovernancePolicyTagActionSegment".into(), + NodeMatcher::new( + SyntaxKind::DataGovernancePolicyTagActionSegment, + |_dialect| { + one_of(vec![ Sequence::new(vec![ - Ref::new("TagReferenceSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) + Ref::keyword("SET").to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), + ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ]); - - snowflake_dialect.replace_grammar( - "UnorderedSelectStatementSegment", - ansi::get_unordered_select_statement_segment_grammar().copy( - Some(vec![ - Ref::new("QualifyClauseSegment").optional().to_matchable(), - ]), - None, - Some(Ref::new("OverlapsClauseSegment").optional().to_matchable()), - None, - Vec::new(), - false, - ), - ); - - snowflake_dialect.add([ - ( - "AccessStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AccessStatement, |_| { - let global_permissions = one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - one_of(vec![ - Ref::keyword("ACCOUNT").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::keyword("WAREHOUSE").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("INTEGRATION").to_matchable(), - Ref::keyword("SHARE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("DATA").to_matchable(), - Ref::keyword("EXCHANGE").to_matchable(), - Ref::keyword("LISTING").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NETWORK").to_matchable(), - Ref::keyword("POLICY").to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![Ref::new("TagReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("APPLY").to_matchable(), - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("APPLY").to_matchable(), - Ref::keyword("ROW").to_matchable(), - Ref::keyword("ACCESS").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("APPLY").to_matchable(), - Ref::keyword("SESSION").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("APPLY").to_matchable(), - Ref::keyword("TAG").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ATTACH").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("EXECUTE").to_matchable(), - Ref::keyword("TASK").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("IMPORT").to_matchable(), - Ref::keyword("SHARE").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MANAGE").to_matchable(), - one_of(vec![ - Ref::keyword("GRANTS").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ACCOUNT").to_matchable(), - Ref::keyword("ORGANIZATION").to_matchable(), - Ref::keyword("USER").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::keyword("ADD").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Ref::keyword("SUPPORT").to_matchable(), - Ref::keyword("CASES").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MONITOR").to_matchable(), - one_of(vec![ - Ref::keyword("EXECUTION").to_matchable(), - Ref::keyword("USAGE").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OVERRIDE").to_matchable(), - Ref::keyword("SHARE").to_matchable(), - Ref::keyword("RESTRICTIONS").to_matchable(), - ]) - .to_matchable(), - ]); - - let schema_object_names = [ - "TABLE", - "VIEW", - "STAGE", - "FUNCTION", - "PROCEDURE", - "ROUTINE", - "SEQUENCE", - "STREAM", - "TASK", - "PIPE", - ]; - - let schema_object_names_keywrods: Vec = schema_object_names - .iter() - .map(|name| Ref::keyword(*name).to_matchable()) - .collect(); - - let mut schema_object_types = schema_object_names_keywrods.clone(); - schema_object_types.append(&mut vec![ - Sequence::new(vec![ - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("TEMP").to_matchable(), - Ref::keyword("TEMPORARY").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("ALL").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICIES").to_matchable(), ]) .to_matchable(), - Ref::keyword("TABLE").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FILE").to_matchable(), - Ref::keyword("FORMAT").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SESSION").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ROW").to_matchable(), - Ref::keyword("ACCESS").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - ]) - .to_matchable(), - ]); - - let schema_object_types = one_of(schema_object_types); - - let schema_object_types_plural = one_of( - schema_object_names - .iter() - .map(|name| Ref::keyword(format!("{name}S")).to_matchable()) - .collect(), - ); - - let permissions = Sequence::new(vec![ - one_of(vec![ Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - one_of(vec![ - Ref::keyword("SCHEMA").to_matchable(), - schema_object_types.clone().to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("AGGREGATION").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENTITY").to_matchable(), + Ref::keyword("KEY").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Sequence::new(vec![Ref::keyword("FORCE").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("IMPORTED").to_matchable(), - Ref::keyword("PRIVILEGES").to_matchable(), + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("AGGREGATION").to_matchable(), + Ref::keyword("POLICY").to_matchable(), ]) .to_matchable(), - Ref::keyword("APPLY").to_matchable(), - Ref::keyword("CONNECT").to_matchable(), - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("DELETE").to_matchable(), - Ref::keyword("EXECUTE").to_matchable(), - Ref::keyword("INSERT").to_matchable(), - Ref::keyword("MODIFY").to_matchable(), - Ref::keyword("MONITOR").to_matchable(), - Ref::keyword("OPERATE").to_matchable(), - Ref::keyword("OWNERSHIP").to_matchable(), - Ref::keyword("READ").to_matchable(), - Ref::keyword("REFERENCE_USAGE").to_matchable(), - Ref::keyword("REFERENCES").to_matchable(), - Ref::keyword("SELECT").to_matchable(), - Ref::keyword("TEMP").to_matchable(), - Ref::keyword("TEMPORARY").to_matchable(), - Ref::keyword("TRIGGER").to_matchable(), - Ref::keyword("TRUNCATE").to_matchable(), - Ref::keyword("UPDATE").to_matchable(), - Ref::keyword("USAGE").to_matchable(), - Ref::keyword("USE_ANY_ROLE").to_matchable(), - Ref::keyword("WRITE").to_matchable(), Sequence::new(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("PRIVILEGES").optional().to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("JOIN").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Sequence::new(vec![Ref::keyword("FORCE").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("JOIN").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) .to_matchable(), - ]); - - let objects = one_of(vec![ - Ref::keyword("ACCOUNT").to_matchable(), + ]) + .to_matchable() + }, + ) + .to_matchable() + .into(), + ), + ( + "AlterTableTableColumnActionSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTableTableColumnAction, |_dialect| { + one_of(vec![ Sequence::new(vec![ - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("RESOURCE").to_matchable(), - Ref::keyword("MONITOR").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("WAREHOUSE").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("DOMAIN").to_matchable(), - Ref::keyword("INTEGRATION").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("SCHEMAS").to_matchable(), - Ref::keyword("IN").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FUTURE").to_matchable(), - Ref::keyword("SCHEMAS").to_matchable(), - Ref::keyword("IN").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - ]) - .to_matchable(), - schema_object_types.clone().to_matchable(), + Ref::keyword("ADD").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Delimited::new(vec![ Sequence::new(vec![ - Ref::keyword("ALL").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), one_of(vec![ - schema_object_types_plural.clone().to_matchable(), Sequence::new(vec![ - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEWS").to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("AS").to_matchable(), + ]) + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("TABLES").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FILE").to_matchable(), - Ref::keyword("FORMATS").to_matchable(), + one_of(vec![ + Ref::keyword("AUTOINCREMENT").to_matchable(), + Ref::keyword("IDENTITY").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("START").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("INCREMENT").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("IN").to_matchable(), - one_of(vec![ - Ref::keyword("SCHEMA").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").optional().to_matchable(), + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("CommentClauseSegment").optional().to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FUTURE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("MODIFY").to_matchable(), + ]) + .to_matchable(), + optionally_bracketed(vec![ + Delimited::new(vec![ one_of(vec![ - schema_object_types_plural.clone().to_matchable(), Sequence::new(vec![ - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEWS").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("DotSegment").to_matchable(), + Ref::keyword("NEXTVAL").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("DROP").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("DATA").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("TYPE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentClauseSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("TABLES").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + Ref::new("ExpressionSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("FORCE").optional().to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("FILE").to_matchable(), - Ref::keyword("FORMATS").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Ref::new("TagReferenceSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Ref::new("TagReferenceSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("IN").to_matchable(), - one_of(vec![ - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), Delimited::new(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar") - .optional() - .to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), ]) .to_matchable(), ]) - .config(|this| { - this.terminators = vec![ - Ref::keyword("TO").to_matchable(), - Ref::keyword("FROM").to_matchable(), - ] - }) .to_matchable(), ]) .to_matchable(), - ]); - - one_of(vec![ - // Grant statement Sequence::new(vec![ - Ref::keyword("GRANT").to_matchable(), one_of(vec![ - Sequence::new(vec![ - Delimited::new(vec![ - one_of(vec![ - global_permissions.clone().to_matchable(), - permissions.clone().to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.terminators = vec![Ref::keyword("ON").to_matchable()] - }) - .to_matchable(), - Ref::keyword("ON").to_matchable(), - objects.clone().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ROLE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OWNERSHIP").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("SEARCH").to_matchable(), - Ref::keyword("OPTIMIZATION").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::keyword("USER").optional().to_matchable(), - Ref::keyword("ROLE").optional().to_matchable(), - Ref::keyword("SHARE").optional().to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Ref::new("RoleReferenceSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Ref::keyword("PUBLIC").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("ADD").to_matchable(), + Ref::keyword("MODIFY").to_matchable(), ]) .to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("ColumnDefinitionSegment").to_matchable(), one_of(vec![ - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("GRANT").to_matchable(), - Ref::keyword("OPTION").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("ADMIN").to_matchable(), - Ref::keyword("OPTION").to_matchable(), - ]) - .to_matchable(), Sequence::new(vec![ one_of(vec![ - Ref::keyword("REVOKE").to_matchable(), - Ref::keyword("COPY").to_matchable(), + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("AFTER").to_matchable(), ]) .to_matchable(), - Ref::keyword("CURRENT").to_matchable(), - Ref::keyword("GRANTS").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("GRANTED").to_matchable(), - Ref::keyword("BY").to_matchable(), - one_of(vec![ - Ref::keyword("CURRENT_USER").to_matchable(), - Ref::keyword("SESSION_USER").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterTableClusteringActionSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTableClusteringAction, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("BY").to_matchable(), + one_of(vec![ + Ref::new("FunctionSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), - // Revoke statement Sequence::new(vec![ - Ref::keyword("REVOKE").to_matchable(), + Ref::keyword("RECLUSTER").to_matchable(), Sequence::new(vec![ - Ref::keyword("GRANT").to_matchable(), - Ref::keyword("OPTION").to_matchable(), - Ref::keyword("FOR").to_matchable(), + Ref::keyword("MAX_SIZE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ one_of(vec![ - Sequence::new(vec![ - Delimited::new(vec![ - one_of(vec![ - global_permissions.clone().to_matchable(), - permissions.clone().to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| { - this.terminators = vec![Ref::keyword("ON").to_matchable()]; - }) - .to_matchable(), - Ref::keyword("ON").to_matchable(), - objects.clone().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ROLE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("OWNERSHIP").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("SEARCH").to_matchable(), - Ref::keyword("OPTIMIZATION").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("SUSPEND").to_matchable(), + Ref::keyword("RESUME").to_matchable(), ]) .to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::keyword("USER").optional().to_matchable(), - Ref::keyword("ROLE").optional().to_matchable(), - Ref::keyword("SHARE").optional().to_matchable(), - Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) - .to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), + Ref::keyword("RECLUSTER").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("CLUSTERING").to_matchable(), + Ref::keyword("KEY").to_matchable(), ]) .to_matchable(), ]) @@ -3638,66 +3500,42 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CreateCloneStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateCloneStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), + "AlterTableConstraintActionSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTableConstraintAction, |_dialect| { + one_of(vec![ Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), + Ref::keyword("ADD").to_matchable(), + Ref::new("OutOfLineConstraintPropertiesSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - one_of(vec![ - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::keyword("SEQUENCE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), Sequence::new(vec![ - Ref::keyword("FILE").to_matchable(), - Ref::keyword("FORMAT").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("STAGE").to_matchable(), - Ref::keyword("STREAM").to_matchable(), - Ref::keyword("TASK").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("CLONE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - one_of(vec![ - Ref::new("FromAtExpressionSegment").to_matchable(), - Ref::new("FromBeforeExpressionSegment").to_matchable(), + one_of(vec![ + Ref::new("PrimaryKeyGrammar").to_matchable(), + Ref::new("ForeignKeyGrammar").to_matchable(), + Ref::new("UniqueKeyGrammar").to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "CreateDatabaseFromShareStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateDatabaseFromShareStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("SHARE").to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), ]) .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable() }) @@ -3705,162 +3543,61 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CreateProcedureStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateProcedureStatement, |_| { + "SearchOptimizationActionSegment".into(), + NodeMatcher::new(SyntaxKind::SearchOptimizationAction, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![Ref::keyword("SECURE").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("PROCEDURE").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar").to_matchable(), - Sequence::new(vec![ - Ref::keyword("COPY").to_matchable(), - Ref::keyword("GRANTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("RETURNS").to_matchable(), one_of(vec![ - Ref::new("DatatypeSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("TABLE").to_matchable(), - Bracketed::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("OPTIMIZATION").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), Delimited::new(vec![ - Ref::new("ColumnDefinitionSegment").to_matchable(), + Ref::new("SearchMethodWithTargetGrammar").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + Ref::keyword("EQUALITY").optional().to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("NULL").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), Sequence::new(vec![ - Ref::keyword("LANGUAGE").to_matchable(), one_of(vec![ - Ref::keyword("JAVA").to_matchable(), - Ref::keyword("JAVASCRIPT").to_matchable(), - Ref::keyword("PYTHON").to_matchable(), - Ref::keyword("SCALA").to_matchable(), - Ref::keyword("SQL").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CALLED").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::keyword("INPUT").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("SUSPEND").to_matchable(), + Ref::keyword("RESUME").to_matchable(), ]) .to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("OPTIMIZATION").to_matchable(), Sequence::new(vec![ - Ref::keyword("RETURNS").to_matchable(), - Ref::keyword("NULL").to_matchable(), Ref::keyword("ON").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::keyword("INPUT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("STRICT").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Ref::keyword("VOLATILE").to_matchable(), - Ref::keyword("IMMUTABLE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RUNTIME_VERSION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("CommentEqualsClauseSegment") - .optional() - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("IMPORTS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("PACKAGES").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ Delimited::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("SearchMethodWithTargetGrammar") + .to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("EQUALITY").optional().to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("HANDLER").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TARGET_PATH").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("EXECUTE").to_matchable(), - Ref::keyword("AS").to_matchable(), - one_of(vec![ - Ref::keyword("CALLER").to_matchable(), - Ref::keyword("OWNER").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("AS").to_matchable(), - one_of(vec![ - Ref::new("DoubleQuotedUDFBody").to_matchable(), - Ref::new("SingleQuotedUDFBody").to_matchable(), - Ref::new("DollarQuotedUDFBody").to_matchable(), - Ref::new("ScriptingBlockStatementSegment").to_matchable(), - ]) .to_matchable(), ]) .to_matchable() @@ -3869,52 +3606,28 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterProcedureStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterProcedureStatement, |_| { + "TableColumnCommentActionSegment".into(), + NodeMatcher::new(SyntaxKind::TableColumnCommentAction, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("PROCEDURE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar").to_matchable(), one_of(vec![ - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("EXECUTE").to_matchable(), - Ref::keyword("AS").to_matchable(), - one_of(vec![ - Ref::keyword("CALLER").to_matchable(), - Ref::keyword("OWNER").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - one_of(vec![ - Ref::new("TagEqualsSegment").to_matchable(), - Ref::new("CommentEqualsClauseSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("TAG").to_matchable(), - Delimited::new(vec![ - Ref::new("TagReferenceSegment").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("MODIFY").to_matchable(), + ]) + .to_matchable(), + optionally_bracketed(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + one_of(vec![ + Ref::new("CommentClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Ref::keyword("COMMENT").to_matchable(), ]) .to_matchable(), ]) @@ -3928,99 +3641,133 @@ pub fn dialect() -> Dialect { .into(), ), ( - "ReturnStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ReturnStatement, |_| { + "AlterDynamicTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterDynamicTableStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("RETURN").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "ScriptingBlockStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ScriptingBlockStatement, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("BEGIN").to_matchable(), - Delimited::new(vec![Ref::new("StatementSegment").to_matchable()]) + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("DYNAMIC").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Ref::keyword("SUSPEND").to_matchable(), + Ref::keyword("RESUME").to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SWAP").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REFRESH").to_matchable(), + Sequence::new(vec![ + Ref::keyword("COPY").to_matchable(), + Ref::keyword("SESSION").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![Ref::keyword("END").to_matchable()]).to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "ScriptingLetStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ScriptingLetStatement, |_| { - one_of(vec![ - // Initial declaration and assignment - Sequence::new(vec![ - Ref::keyword("LET").to_matchable(), - Ref::new("LocalVariableNameSegment").to_matchable(), - one_of(vec![ - // Variable assignment - one_of(vec![ + ]) + .to_matchable(), + Ref::new("AlterTableClusteringActionSegment").to_matchable(), + Ref::new("TableColumnCommentActionSegment").to_matchable(), + Ref::new("DataGovernancePolicyTagActionSegment").to_matchable(), + Ref::new("SearchOptimizationActionSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Delimited::new(vec![ + Ref::new("CommentEqualsClauseSegment").to_matchable(), Sequence::new(vec![ - Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("TARGET_LAG").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), one_of(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("WalrusOperatorSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("DOWNSTREAM").to_matchable(), ]) .to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), one_of(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("WalrusOperatorSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - // Cursor assignment - Sequence::new(vec![ - Ref::keyword("CURSOR").to_matchable(), - Ref::keyword("FOR").to_matchable(), - one_of(vec![ - Ref::new("LocalVariableNameSegment").to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATA_RETENTION_TIME_IN_DAYS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - // Resultset assignment - Sequence::new(vec![ - Ref::keyword("RESULTSET").to_matchable(), - Ref::new("WalrusOperatorSegment").to_matchable(), - Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + Sequence::new(vec![ + Ref::keyword("MAX_DATA_EXTENSION_TIME_IN_DAYS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT_DDL_COLLATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("LogLevelEqualsSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONTACT").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("PurposeGrammar").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IMMUTABLE").to_matchable(), + Ref::keyword("WHERE").to_matchable(), + Bracketed::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + ]) .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - // Subsequent assignment - Sequence::new(vec![ - Ref::new("LocalVariableNameSegment").to_matchable(), - Ref::new("WalrusOperatorSegment").to_matchable(), - one_of(vec![ - // Variable reassignment - Ref::new("ExpressionSegment").to_matchable(), - // Resultset reassignment - Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Delimited::new(vec![ + Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("DATA_RETENTION_TIME_IN_DAYS").to_matchable(), + Ref::keyword("MAX_DATA_EXTENSION_TIME_IN_DAYS").to_matchable(), + Ref::keyword("DEFAULT_DDL_COLLATION").to_matchable(), + Ref::keyword("LOG_LEVEL").to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONTACT").to_matchable(), + Ref::new("PurposeGrammar").to_matchable(), + ]) .to_matchable(), + Ref::keyword("IMMUTABLE").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -4032,151 +3779,160 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CreateFunctionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateFunctionStatement, |_| { + "AlterWarehouseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterWarehouseStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![Ref::keyword("SECURE").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar").to_matchable(), - Ref::keyword("RETURNS").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), one_of(vec![ - Ref::new("DatatypeSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("TABLE").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnDefinitionSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").optional().to_matchable(), + one_of(vec![ + Ref::keyword("SUSPEND").to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESUME").to_matchable(), + Sequence::new(vec![ + Ref::keyword("IF").to_matchable(), + Ref::keyword("SUSPENDED").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("NULL").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), Sequence::new(vec![ - Ref::keyword("LANGUAGE").to_matchable(), - one_of(vec![ - Ref::keyword("JAVASCRIPT").to_matchable(), - Ref::keyword("SQL").to_matchable(), - Ref::keyword("PYTHON").to_matchable(), - Ref::keyword("JAVA").to_matchable(), - Ref::keyword("SCALA").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CALLED").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::keyword("INPUT").to_matchable(), - ]) - .to_matchable(), + Ref::new("ObjectReferenceSegment").optional().to_matchable(), Sequence::new(vec![ - Ref::keyword("RETURNS").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::keyword("INPUT").to_matchable(), + Ref::keyword("ABORT").to_matchable(), + Ref::keyword("ALL").to_matchable(), + Ref::keyword("QUERIES").to_matchable(), ]) .to_matchable(), - Ref::keyword("STRICT").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - one_of(vec![ - Ref::keyword("VOLATILE").to_matchable(), - Ref::keyword("IMMUTABLE").to_matchable(), + Sequence::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Sequence::new(vec![ - Ref::keyword("RUNTIME_VERSION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").optional().to_matchable(), + Ref::keyword("SET").to_matchable(), + one_of(vec![ + AnyNumberOf::new(vec![ + Ref::new("CommaSegment").optional().to_matchable(), + Ref::new("WarehouseObjectPropertiesSegment").to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + Ref::new("WarehouseObjectParamsSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::new("CommentEqualsClauseSegment") - .optional() - .to_matchable(), Sequence::new(vec![ - Ref::keyword("IMPORTS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("UNSET").to_matchable(), + one_of(vec![ Delimited::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![ + Ref::new("TagReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterShareStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterShareStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("PACKAGES").to_matchable(), + one_of(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("REMOVE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("ACCOUNTS").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) + Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SHARE_RESTRICTIONS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Sequence::new(vec![ - Ref::keyword("HANDLER").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("ACCOUNTS").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Sequence::new(vec![ - Ref::keyword("TARGET_PATH").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - one_of(vec![ - // Either a foreign programming language UDF... - Ref::new("DoubleQuotedUDFBody").to_matchable(), - Ref::new("SingleQuotedUDFBody").to_matchable(), - Ref::new("DollarQuotedUDFBody").to_matchable(), - // ...or a SQL UDF - Ref::new("ScriptingBlockStatementSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Ref::new("TagReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("CommaSegment").to_matchable(), + Ref::new("TagReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable() @@ -4185,89 +3941,113 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterFunctionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterFunctionStatement, |_| { + "AlterStorageIntegrationSegment".into(), + NodeMatcher::new(SyntaxKind::AlterStorageIntegrationStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ALTER").to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar").to_matchable(), + Ref::keyword("STORAGE").optional().to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), one_of(vec![ - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - ]) - .to_matchable(), Sequence::new(vec![ Ref::keyword("SET").to_matchable(), one_of(vec![ - Ref::new("CommentEqualsClauseSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("API_INTEGRATION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("HEADERS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ + Ref::new("TagEqualsSegment").optional().to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("CommentEqualsClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENABLED").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USE_PRIVATELINK_ENDPOINT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::new("SingleQuotedIdentifierSegment") - .to_matchable(), + Ref::keyword("STORAGE_AWS_ROLE_ARN").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("SingleQuotedIdentifierSegment") + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STORAGE_AWS_OBJECT_ACL") .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("AZURE_TENANT_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CONTEXT_HEADERS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ContextHeadersGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("STORAGE_ALLOWED_LOCATIONS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("S3Path").to_matchable(), + Ref::new("GCSPath").to_matchable(), + Ref::new("AzureBlobStoragePath") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Ref::new("QuotedStarSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MAX_BATCH_ROWS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COMPRESSION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("CompressionType").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("SECURE").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("REQUEST_TRANSLATOR").to_matchable(), - Ref::keyword("RESPONSE_TRANSLATOR").to_matchable(), + Sequence::new(vec![ + Ref::keyword("STORAGE_BLOCKED_LOCATIONS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("S3Path").to_matchable(), + Ref::new("GCSPath").to_matchable(), + Ref::new("AzureBlobStoragePath").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), ]) .to_matchable(), @@ -4276,24 +4056,24 @@ pub fn dialect() -> Dialect { Sequence::new(vec![ Ref::keyword("UNSET").to_matchable(), one_of(vec![ + Sequence::new(vec![ + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![ + Ref::new("TagReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), Ref::keyword("COMMENT").to_matchable(), - Ref::keyword("HEADERS").to_matchable(), - Ref::keyword("CONTEXT_HEADERS").to_matchable(), - Ref::keyword("MAX_BATCH_ROWS").to_matchable(), - Ref::keyword("COMPRESSION").to_matchable(), - Ref::keyword("SECURE").to_matchable(), - Ref::keyword("REQUEST_TRANSLATOR").to_matchable(), - Ref::keyword("RESPONSE_TRANSLATOR").to_matchable(), + Ref::keyword("ENABLED").to_matchable(), + Ref::keyword("STORAGE_BLOCKED_LOCATIONS").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), ]) .to_matchable(), ]) @@ -4303,122 +4083,83 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CreateExternalFunctionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateExternalFunctionStatement, |_| { + "AlterExternalTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterExternalTableStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![Ref::keyword("SECURE").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("ALTER").to_matchable(), Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar").to_matchable(), - Ref::keyword("RETURNS").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("NULL").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::keyword("CALLED").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::keyword("INPUT").to_matchable(), + Ref::keyword("REFRESH").to_matchable(), + Ref::new("QuotedLiteralSegment").optional().to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("RETURNS").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::keyword("INPUT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("STRICT").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Ref::keyword("VOLATILE").to_matchable(), - Ref::keyword("IMMUTABLE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("CommentEqualsClauseSegment") - .optional() - .to_matchable(), - Ref::keyword("API_INTEGRATION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Sequence::new(vec![ - Ref::keyword("HEADERS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("SingleQuotedIdentifierSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("SingleQuotedIdentifierSegment").to_matchable(), + one_of(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("REMOVE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FILES").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CONTEXT_HEADERS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ContextHeadersGrammar").to_matchable()]) + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AUTO_REFRESH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("TagEqualsSegment").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("PARTITION").to_matchable(), + Ref::keyword("LOCATION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("PARTITION").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("LOCATION").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MAX_BATCH_ROWS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COMPRESSION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("CompressionType").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("REQUEST_TRANSLATOR").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RESPONSE_TRANSLATOR").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - ]) - .config(|this| this.optional()) .to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("SingleQuotedIdentifierSegment").to_matchable(), ]) .to_matchable() }) @@ -4426,73 +4167,48 @@ pub fn dialect() -> Dialect { .into(), ), ( - "WarehouseObjectPropertiesSegment".into(), - NodeMatcher::new(SyntaxKind::WarehouseObjectProperties, |_| { - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("WAREHOUSE_TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("WarehouseType").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WAREHOUSE_SIZE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("WarehouseSize").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WAIT_FOR_COMPLETION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MAX_CLUSTER_COUNT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MIN_CLUSTER_COUNT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SCALING_POLICY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("ScalingPolicy").to_matchable(), + "CommentEqualsClauseSegment".into(), + NodeMatcher::new(SyntaxKind::CommentEqualsClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("COMMENT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("DoubleQuotedLiteralSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("AUTO_SUSPEND").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TagBracketedEqualsSegment".into(), + NodeMatcher::new(SyntaxKind::TagBracketedEquals, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![Ref::keyword("WITH").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("TAG").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("TagReferenceSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("DoubleQuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("AUTO_RESUME").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INITIALLY_SUSPENDED").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RESOURCE_MONITOR").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - ]) - .to_matchable(), ]) .to_matchable() }) @@ -4500,25 +4216,19 @@ pub fn dialect() -> Dialect { .into(), ), ( - "WarehouseObjectParamsSegment".into(), - NodeMatcher::new(SyntaxKind::WarehouseObjectProperties, |_| { - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("MAX_CONCURRENCY_LEVEL").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("STATEMENT_QUEUED_TIMEOUT_IN_SECONDS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("STATEMENT_TIMEOUT_IN_SECONDS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + "LogLevelEqualsSegment".into(), + NodeMatcher::new(SyntaxKind::LogLevelEquals, |_dialect| { + Sequence::new(vec![ + Ref::keyword("LOG_LEVEL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("TRACE").to_matchable(), + Ref::keyword("DEBUG").to_matchable(), + Ref::keyword("INFO").to_matchable(), + Ref::keyword("WARN").to_matchable(), + Ref::keyword("ERROR").to_matchable(), + Ref::keyword("FATAL").to_matchable(), + Ref::keyword("OFF").to_matchable(), ]) .to_matchable(), ]) @@ -4528,71 +4238,15 @@ pub fn dialect() -> Dialect { .into(), ), ( - "ConstraintPropertiesSegment".into(), - NodeMatcher::new(SyntaxKind::ConstraintPropertiesSegment, |_| { + "TraceLevelEqualsSegment".into(), + NodeMatcher::new(SyntaxKind::TraceLevelEquals, |_dialect| { Sequence::new(vec![ - Sequence::new(vec![ - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("UNIQUE").to_matchable(), - Bracketed::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("PrimaryKeyGrammar").to_matchable(), - Bracketed::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Sequence::new(vec![ - Ref::new("ForeignKeyGrammar").to_matchable(), - Bracketed::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("REFERENCES").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - any_set_of(vec![ - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("ENFORCED").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("DEFERRABLE").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - one_of(vec![ - Ref::keyword("DEFERRED").to_matchable(), - Ref::keyword("IMMEDIATE").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("TRACE_LEVEL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("ALWAYS").to_matchable(), + Ref::keyword("ON_EVENT").to_matchable(), + Ref::keyword("OFF").to_matchable(), ]) .to_matchable(), ]) @@ -4601,62 +4255,27 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - snowflake_dialect.replace_grammar( - "ColumnConstraintSegment", - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("COLLATE").to_matchable(), - Ref::new("CollationReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("AUTOINCREMENT").to_matchable(), - Ref::keyword("IDENTITY").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("START").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::keyword("INCREMENT").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("NULL").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").optional().to_matchable(), - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), + ( + "ExternalAccessIntegrationsEqualsSegment".into(), + NodeMatcher::new(SyntaxKind::ExternalAccessIntegrationEquals, |_dialect| { Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), + Ref::keyword("EXTERNAL_ACCESS_INTEGRATIONS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), Bracketed::new(vec![ Delimited::new(vec![ - one_of(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DotSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), ]) @@ -4664,209 +4283,41 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("TagBracketedEqualsSegment") - .optional() - .to_matchable(), - Ref::new("ConstraintPropertiesSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("CHECK").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]).to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("REFERENCES").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.add([( - "CopyOptionsSegment".into(), - NodeMatcher::new(SyntaxKind::CopyOptions, |_| { - one_of(vec![ - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("ON_ERROR").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("CopyOptionOnErrorSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SIZE_LIMIT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("PURGE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RETURN_FAILED_ONLY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MATCH_BY_COLUMN_NAME").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("CASE_SENSITIVE").to_matchable(), - Ref::keyword("CASE_INSENSITIVE").to_matchable(), - Ref::keyword("NONE").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ENFORCE_LENGTH").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TRUNCATECOLUMNS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FORCE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("OVERWRITE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SINGLE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MAX_FILE_SIZE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INCLUDE_QUERY_ID").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DETAILED_OUTPUT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - snowflake_dialect.replace_grammar( - "CreateSchemaStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::new("TemporaryTransientGrammar") - .optional() - .to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("MANAGED").to_matchable(), - Ref::keyword("ACCESS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("SchemaObjectParamsSegment") - .optional() - .to_matchable(), - Ref::new("TagBracketedEqualsSegment") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.add([ + .into(), + ), ( - "AlterRoleStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterRoleStatement, |_| { + "SecretsEqualsSegment".into(), + NodeMatcher::new(SyntaxKind::ExternalAccessIntegrationEquals, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - one_of(vec![ + Ref::keyword("SECRETS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - one_of(vec![ - Ref::new("RoleReferenceSegment").to_matchable(), - Ref::new("TagEqualsSegment").to_matchable(), + Delimited::new(vec![ Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - one_of(vec![ - Ref::new("RoleReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("TAG").to_matchable(), - Delimited::new(vec![ - Ref::new("TagReferenceSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DotSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![Ref::keyword("COMMENT").to_matchable()]) - .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - one_of(vec![Ref::new("RoleReferenceSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), ]) .to_matchable(), ]) @@ -4876,71 +4327,17 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterSchemaStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterSchemaStatement, |_| { + "TagEqualsSegment".into(), + NodeMatcher::new(SyntaxKind::TagEquals, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SWAP").to_matchable(), - Ref::keyword("WITH").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - one_of(vec![ - Ref::new("SchemaObjectParamsSegment").to_matchable(), - Ref::new("TagEqualsSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - one_of(vec![ - Delimited::new(vec![ - Ref::keyword("DATA_RETENTION_TIME_IN_DAYS").to_matchable(), - Ref::keyword("MAX_DATA_EXTENSION_TIME_IN_DAYS").to_matchable(), - Ref::keyword("DEFAULT_DDL_COLLATION").to_matchable(), - Ref::keyword("COMMENT").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TAG").to_matchable(), - Delimited::new(vec![ - Ref::new("TagReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![ Sequence::new(vec![ + Ref::new("TagReferenceSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), one_of(vec![ - Ref::keyword("ENABLE").to_matchable(), - Ref::keyword("DISABLE").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MANAGED").to_matchable(), - Ref::keyword("ACCESS").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("DoubleQuotedLiteralSegment").to_matchable(), ]) .to_matchable(), ]) @@ -4954,250 +4351,5656 @@ pub fn dialect() -> Dialect { .into(), ), ( - "SchemaObjectParamsSegment".into(), - NodeMatcher::new(SyntaxKind::SchemaObjectProperties, |_| { - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("DATA_RETENTION_TIME_IN_DAYS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MAX_DATA_EXTENSION_TIME_IN_DAYS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DEFAULT_DDL_COLLATION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("CommentEqualsClauseSegment").to_matchable(), - ]) - .to_matchable() + "UnorderedSelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("UnorderedSelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("QualifyClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("OverlapsClauseSegment").optional().to_matchable()), + None, + vec![], + false, + ) + .copy( + Some(vec![ + Ref::new("IntoClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("FromClauseSegment").optional().to_matchable()), + None, + vec![], + false, + ) }) .to_matchable() .into(), ), - ]); - - snowflake_dialect.replace_grammar( - "CreateTableStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::new("TemporaryTransientGrammar") - .optional() - .to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - any_set_of(vec![ - Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::new("TableConstraintSegment").to_matchable(), - Ref::new("ColumnDefinitionSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - Ref::new("CommentClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CLUSTER").to_matchable(), - Ref::keyword("BY").to_matchable(), - one_of(vec![ - Ref::new("FunctionSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("STAGE_FILE_FORMAT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("FileFormatSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + ( + "IntoClauseSegment".into(), + NodeMatcher::new(SyntaxKind::IntoClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("STAGE_COPY_OPTIONS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![Ref::new("CopyOptionsSegment").to_matchable()]) + Ref::keyword("INTO").to_matchable(), + Delimited::new(vec![Ref::new("BindVariableSegment").to_matchable()]) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DATA_RETENTION_TIME_IN_DAYS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MAX_DATA_EXTENSION_TIME_IN_DAYS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CHANGE_TRACKING").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DEFAULT_DDL_COLLATION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralGrammar").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COPY").to_matchable(), - Ref::keyword("GRANTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").optional().to_matchable(), - Ref::keyword("ROW").to_matchable(), - Ref::keyword("ACCESS").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::keyword("ON").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("TagBracketedEqualsSegment") - .optional() - .to_matchable(), - Ref::new("CommentEqualsClauseSegment") - .optional() - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LIKE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CLONE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Ref::keyword("TEMPLATE").to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.add([ + .to_matchable() + }) + .to_matchable() + .into(), + ), ( - "CreateTaskSegment".into(), - NodeMatcher::new(SyntaxKind::CreateTaskStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("TASK").to_matchable(), + "AccessStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AccessStatement, |_dialect| { + one_of(vec![ Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - MetaSegment::indent().to_matchable(), - AnyNumberOf::new(vec![ + Ref::keyword("GRANT").to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::keyword("WAREHOUSE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE") - .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("WarehouseSize").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SCHEDULE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ + Delimited::new(vec![ + one_of(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + one_of(vec![ + Ref::keyword("ACCOUNT").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATA").to_matchable(), + Ref::keyword("EXCHANGE").to_matchable(), + Ref::keyword("LISTING").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NETWORK").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPLY").to_matchable(), + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPLY").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPLY").to_matchable(), + Ref::keyword("SESSION").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPLY").to_matchable(), + Ref::keyword("TAG").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ATTACH").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXECUTE").to_matchable(), + one_of(vec![ + Ref::keyword("ALERT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MANAGED") + .optional() + .to_matchable(), + Ref::keyword("TASK").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IMPORT").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MANAGE").to_matchable(), + one_of(vec![ + Ref::keyword("GRANTS").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ACCOUNT").to_matchable(), + Ref::keyword("ORGANIZATION") + .to_matchable(), + Ref::keyword("USER").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SUPPORT").to_matchable(), + Ref::keyword("CASES").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MONITOR").to_matchable(), + one_of(vec![ + Ref::keyword("EXECUTION").to_matchable(), + Ref::keyword("USAGE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OVERRIDE").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + Ref::keyword("RESTRICTIONS").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + one_of(vec![ + Ref::keyword("SCHEMA").to_matchable(), + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::keyword("STAGE").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::keyword("PROCEDURE") + .to_matchable(), + Ref::keyword("ROUTINE").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::keyword("STREAM").to_matchable(), + Ref::keyword("STREAMLIT") + .to_matchable(), + Ref::keyword("TASK").to_matchable(), + Ref::keyword("PIPE").to_matchable(), + Ref::keyword("NOTEBOOK").to_matchable(), + Ref::keyword("MODEL").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED") + .to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL") + .to_matchable(), + Ref::keyword("TABLE") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TEMP") + .to_matchable(), + Ref::keyword("TEMPORARY") + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TABLE") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMAT") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SESSION") + .to_matchable(), + Ref::keyword("POLICY") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MASKING") + .to_matchable(), + Ref::keyword("POLICY") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS") + .to_matchable(), + Ref::keyword("POLICY") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CORTEX") + .to_matchable(), + Ref::keyword("SEARCH") + .to_matchable(), + Ref::keyword("SERVICE") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IMPORTED").to_matchable(), + Ref::keyword("PRIVILEGES").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("APPLY").to_matchable(), + Ref::keyword("CONNECT").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("EXECUTE").to_matchable(), + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("MODIFY").to_matchable(), + Ref::keyword("MONITOR").to_matchable(), + Ref::keyword("OPERATE").to_matchable(), + Ref::keyword("OWNERSHIP").to_matchable(), + Ref::keyword("READ").to_matchable(), + Ref::keyword("REFERENCE_USAGE").to_matchable(), + Ref::keyword("REFERENCES").to_matchable(), + Ref::keyword("SELECT").to_matchable(), + Ref::keyword("TEMP").to_matchable(), + Ref::keyword("TEMPORARY").to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::keyword("TRUNCATE").to_matchable(), + Ref::keyword("UPDATE").to_matchable(), + Ref::keyword("USAGE").to_matchable(), + Ref::keyword("USE_ANY_ROLE").to_matchable(), + Ref::keyword("WRITE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("PRIVILEGES") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![Ref::keyword("ON").to_matchable()]; + }) + .to_matchable(), + Ref::keyword("ON").to_matchable(), + one_of(vec![ + Ref::keyword("ACCOUNT").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RESOURCE").to_matchable(), + Ref::keyword("MONITOR").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("VOLUME").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("DOMAIN").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("USER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("SCHEMAS").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FUTURE").to_matchable(), + Ref::keyword("SCHEMAS").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::keyword("STAGE").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::keyword("ROUTINE").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::keyword("STREAM").to_matchable(), + Ref::keyword("STREAMLIT").to_matchable(), + Ref::keyword("TASK").to_matchable(), + Ref::keyword("PIPE").to_matchable(), + Ref::keyword("NOTEBOOK").to_matchable(), + Ref::keyword("MODEL").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TEMP").to_matchable(), + Ref::keyword("TEMPORARY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TABLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMAT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SESSION").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CORTEX").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("SERVICE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("FUTURE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("DYNAMIC").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + one_of(vec![ + Ref::keyword("TABLES").to_matchable(), + Ref::keyword("VIEWS").to_matchable(), + Ref::keyword("STAGES").to_matchable(), + Ref::keyword("FUNCTIONS").to_matchable(), + Ref::keyword("PROCEDURES").to_matchable(), + Ref::keyword("ROUTINES").to_matchable(), + Ref::keyword("SEQUENCES").to_matchable(), + Ref::keyword("STREAMS").to_matchable(), + Ref::keyword("STREAMLITS").to_matchable(), + Ref::keyword("TASKS").to_matchable(), + Ref::keyword("PIPES").to_matchable(), + Ref::keyword("NOTEBOOKS").to_matchable(), + Ref::keyword("MODELS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEWS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("TABLES").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMATS").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("IN").to_matchable(), + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Delimited::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("TO").to_matchable(), + Ref::keyword("FROM").to_matchable(), + ]; + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROLE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::new("DatabaseRoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNERSHIP").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("OPTIMIZATION").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPLICATION").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![ + Ref::keyword("APPLICATION").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Ref::new("RoleReferenceSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("DatabaseRoleReferenceSegment").to_matchable(), + Ref::keyword("PUBLIC").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("GRANT").to_matchable(), + Ref::keyword("OPTION").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("ADMIN").to_matchable(), + Ref::keyword("OPTION").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("REVOKE").to_matchable(), + Ref::keyword("COPY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("GRANTS").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("GRANTED").to_matchable(), + Ref::keyword("BY").to_matchable(), + one_of(vec![ + Ref::keyword("CURRENT_USER").to_matchable(), + Ref::keyword("SESSION_USER").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REVOKE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("GRANT").to_matchable(), + Ref::keyword("OPTION").to_matchable(), + Ref::keyword("FOR").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Delimited::new(vec![ + one_of(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + one_of(vec![ + Ref::keyword("ACCOUNT").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATA").to_matchable(), + Ref::keyword("EXCHANGE").to_matchable(), + Ref::keyword("LISTING").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NETWORK").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPLY").to_matchable(), + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPLY").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPLY").to_matchable(), + Ref::keyword("SESSION").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPLY").to_matchable(), + Ref::keyword("TAG").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ATTACH").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXECUTE").to_matchable(), + one_of(vec![ + Ref::keyword("ALERT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MANAGED") + .optional() + .to_matchable(), + Ref::keyword("TASK").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IMPORT").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MANAGE").to_matchable(), + one_of(vec![ + Ref::keyword("GRANTS").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ACCOUNT").to_matchable(), + Ref::keyword("ORGANIZATION") + .to_matchable(), + Ref::keyword("USER").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SUPPORT").to_matchable(), + Ref::keyword("CASES").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MONITOR").to_matchable(), + one_of(vec![ + Ref::keyword("EXECUTION").to_matchable(), + Ref::keyword("USAGE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OVERRIDE").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + Ref::keyword("RESTRICTIONS").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + one_of(vec![ + Ref::keyword("SCHEMA").to_matchable(), + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::keyword("STAGE").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::keyword("PROCEDURE") + .to_matchable(), + Ref::keyword("ROUTINE").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::keyword("STREAM").to_matchable(), + Ref::keyword("STREAMLIT") + .to_matchable(), + Ref::keyword("TASK").to_matchable(), + Ref::keyword("PIPE").to_matchable(), + Ref::keyword("NOTEBOOK").to_matchable(), + Ref::keyword("MODEL").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED") + .to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL") + .to_matchable(), + Ref::keyword("TABLE") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TEMP") + .to_matchable(), + Ref::keyword("TEMPORARY") + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TABLE") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMAT") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SESSION") + .to_matchable(), + Ref::keyword("POLICY") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MASKING") + .to_matchable(), + Ref::keyword("POLICY") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS") + .to_matchable(), + Ref::keyword("POLICY") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CORTEX") + .to_matchable(), + Ref::keyword("SEARCH") + .to_matchable(), + Ref::keyword("SERVICE") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IMPORTED").to_matchable(), + Ref::keyword("PRIVILEGES").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("APPLY").to_matchable(), + Ref::keyword("CONNECT").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("EXECUTE").to_matchable(), + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("MODIFY").to_matchable(), + Ref::keyword("MONITOR").to_matchable(), + Ref::keyword("OPERATE").to_matchable(), + Ref::keyword("OWNERSHIP").to_matchable(), + Ref::keyword("READ").to_matchable(), + Ref::keyword("REFERENCE_USAGE").to_matchable(), + Ref::keyword("REFERENCES").to_matchable(), + Ref::keyword("SELECT").to_matchable(), + Ref::keyword("TEMP").to_matchable(), + Ref::keyword("TEMPORARY").to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::keyword("TRUNCATE").to_matchable(), + Ref::keyword("UPDATE").to_matchable(), + Ref::keyword("USAGE").to_matchable(), + Ref::keyword("USE_ANY_ROLE").to_matchable(), + Ref::keyword("WRITE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("PRIVILEGES") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![Ref::keyword("ON").to_matchable()]; + }) + .to_matchable(), + Ref::keyword("ON").to_matchable(), + one_of(vec![ + Ref::keyword("ACCOUNT").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RESOURCE").to_matchable(), + Ref::keyword("MONITOR").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("VOLUME").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("DOMAIN").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("USER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("SCHEMAS").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FUTURE").to_matchable(), + Ref::keyword("SCHEMAS").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::keyword("STAGE").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::keyword("ROUTINE").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::keyword("STREAM").to_matchable(), + Ref::keyword("STREAMLIT").to_matchable(), + Ref::keyword("TASK").to_matchable(), + Ref::keyword("PIPE").to_matchable(), + Ref::keyword("NOTEBOOK").to_matchable(), + Ref::keyword("MODEL").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TEMP").to_matchable(), + Ref::keyword("TEMPORARY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TABLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMAT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SESSION").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CORTEX").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("SERVICE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("FUTURE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("DYNAMIC").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + one_of(vec![ + Ref::keyword("TABLES").to_matchable(), + Ref::keyword("VIEWS").to_matchable(), + Ref::keyword("STAGES").to_matchable(), + Ref::keyword("FUNCTIONS").to_matchable(), + Ref::keyword("PROCEDURES").to_matchable(), + Ref::keyword("ROUTINES").to_matchable(), + Ref::keyword("SEQUENCES").to_matchable(), + Ref::keyword("STREAMS").to_matchable(), + Ref::keyword("STREAMLITS").to_matchable(), + Ref::keyword("TASKS").to_matchable(), + Ref::keyword("PIPES").to_matchable(), + Ref::keyword("NOTEBOOKS").to_matchable(), + Ref::keyword("MODELS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEWS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("TABLES").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMATS").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("IN").to_matchable(), + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Delimited::new(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("TO").to_matchable(), + Ref::keyword("FROM").to_matchable(), + ]; + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROLE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::new("DatabaseRoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OWNERSHIP").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + one_of(vec![ + Ref::keyword("USER").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) + .to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateCloneStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateCloneStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![Ref::keyword("DYNAMIC").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("TABLE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMAT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("STAGE").to_matchable(), + Ref::keyword("STREAM").to_matchable(), + Ref::keyword("TASK").to_matchable(), + ]) + .to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("CLONE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ + Ref::new("FromAtExpressionSegment").to_matchable(), + Ref::new("FromBeforeExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateDatabaseFromShareStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateDatabaseFromShareStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + ]) + .to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateProcedureStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateProcedureStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Sequence::new(vec![Ref::keyword("SECURE").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("COPY").to_matchable(), + Ref::keyword("GRANTS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("RETURNS").to_matchable(), + one_of(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnDefinitionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LANGUAGE").to_matchable(), + one_of(vec![ + Ref::keyword("JAVA").to_matchable(), + Ref::keyword("JAVASCRIPT").to_matchable(), + Ref::keyword("PYTHON").to_matchable(), + Ref::keyword("SCALA").to_matchable(), + Ref::keyword("SQL").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CALLED").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("INPUT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURNS").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("INPUT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("STRICT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Ref::keyword("VOLATILE").to_matchable(), + Ref::keyword("IMMUTABLE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RUNTIME_VERSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IMPORTS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SECRETS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar") + .to_matchable(), + Ref::new("DotSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL_ACCESS_INTEGRATIONS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DotSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PACKAGES").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("HANDLER").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TARGET_PATH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXECUTE").to_matchable(), + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Ref::keyword("CALLER").to_matchable(), + Ref::keyword("OWNER").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Ref::new("DoubleQuotedUDFBody").to_matchable(), + Ref::new("SingleQuotedUDFBody").to_matchable(), + Ref::new("DollarQuotedUDFBody").to_matchable(), + Ref::new("ScriptingBlockStatementSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterProcedureStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterProcedureStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXECUTE").to_matchable(), + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Ref::keyword("CALLER").to_matchable(), + Ref::keyword("OWNER").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Ref::new("TagEqualsSegment").optional().to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), + Ref::new("LogLevelEqualsSegment").optional().to_matchable(), + Ref::new("TraceLevelEqualsSegment") + .optional() + .to_matchable(), + Ref::new("ExternalAccessIntegrationsEqualsSegment") + .optional() + .to_matchable(), + Ref::new("SecretsEqualsSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Delimited::new(vec![ + AnyNumberOf::new(vec![ + Ref::new("TagEqualsSegment").optional().to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), + Ref::new("LogLevelEqualsSegment") + .optional() + .to_matchable(), + Ref::new("TraceLevelEqualsSegment") + .optional() + .to_matchable(), + Ref::new("ExternalAccessIntegrationsEqualsSegment") + .optional() + .to_matchable(), + Ref::new("SecretsEqualsSegment") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![ + Ref::new("TagReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterNetworkPolicyStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterNetworkPolicyStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("NETWORK").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("ALLOWED_NETWORK_RULE_LIST").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BLOCKED_NETWORK_RULE_LIST").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALLOWED_IP_LIST").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BLOCKED_IP_LIST").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("REMOVE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("ALLOWED_NETWORK_RULE_LIST").to_matchable(), + Ref::keyword("BLOCKED_NETWORK_RULE_LIST").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Ref::new("TagReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("CommaSegment").to_matchable(), + Ref::new("TagReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ReturnStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ReturnStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("RETURN").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ScriptingBlockStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ScriptingBlockStatement, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("BEGIN").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("StatementSegment").to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("DelimiterGrammar").to_matchable(), + Ref::new("StatementSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::new("DelimiterGrammar").to_matchable(), + Ref::keyword("END").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.exclude = Some( + Sequence::new(vec![ + Ref::new("DelimiterGrammar").to_matchable(), + Ref::keyword("END").to_matchable(), + Ref::keyword("FOR").to_matchable(), + ]) + .to_matchable(), + ); + }) + .to_matchable(), + ]; + }) + .to_matchable(), + Ref::new("DelimiterGrammar").to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::keyword("END").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ScriptingLetStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ScriptingLetStatement, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("LET").to_matchable(), + Ref::new("LocalVariableNameSegment").to_matchable(), + one_of(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::new("DatatypeSegment").to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("WalrusOperatorSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("WalrusOperatorSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CURSOR").to_matchable(), + Ref::keyword("FOR").to_matchable(), + one_of(vec![ + Ref::new("LocalVariableNameSegment").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESULTSET").to_matchable(), + Ref::new("WalrusOperatorSegment").to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("LocalVariableNameSegment").to_matchable(), + Ref::new("WalrusOperatorSegment").to_matchable(), + one_of(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateFunctionStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + one_of(vec![ + Ref::keyword("TEMP").to_matchable(), + Ref::keyword("TEMPORARY").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![Ref::keyword("SECURE").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![Ref::keyword("AGGREGATE").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("COPY").to_matchable(), + Ref::keyword("GRANTS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("RETURNS").to_matchable(), + one_of(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnDefinitionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LANGUAGE").to_matchable(), + one_of(vec![ + Ref::keyword("JAVASCRIPT").to_matchable(), + Ref::keyword("SQL").to_matchable(), + Ref::keyword("PYTHON").to_matchable(), + Ref::keyword("JAVA").to_matchable(), + Ref::keyword("SCALA").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CALLED").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("INPUT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURNS").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("INPUT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("STRICT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Ref::keyword("VOLATILE").to_matchable(), + Ref::keyword("IMMUTABLE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RUNTIME_VERSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IMPORTS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SECRETS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar") + .to_matchable(), + Ref::new("DotSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL_ACCESS_INTEGRATIONS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PACKAGES").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("HANDLER").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TARGET_PATH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Ref::new("DoubleQuotedUDFBody").to_matchable(), + Ref::new("SingleQuotedUDFBody").to_matchable(), + Ref::new("DollarQuotedUDFBody").to_matchable(), + Ref::new("ScriptingBlockStatementSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterFunctionStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("CommentEqualsClauseSegment").to_matchable(), + Ref::new("LogLevelEqualsSegment").optional().to_matchable(), + Ref::new("TraceLevelEqualsSegment") + .optional() + .to_matchable(), + Ref::new("ExternalAccessIntegrationsEqualsSegment") + .optional() + .to_matchable(), + Ref::new("SecretsEqualsSegment").optional().to_matchable(), + Ref::new("TagEqualsSegment").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("API_INTEGRATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("HEADERS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("SingleQuotedIdentifierSegment") + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("SingleQuotedIdentifierSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONTEXT_HEADERS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ContextHeadersGrammar") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MAX_BATCH_ROWS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMPRESSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("CompressionType").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SECURE").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("REQUEST_TRANSLATOR").to_matchable(), + Ref::keyword("RESPONSE_TRANSLATOR").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Delimited::new(vec![ + AnyNumberOf::new(vec![ + Ref::new("CommentEqualsClauseSegment").to_matchable(), + Ref::new("LogLevelEqualsSegment") + .optional() + .to_matchable(), + Ref::new("TraceLevelEqualsSegment") + .optional() + .to_matchable(), + Ref::new("ExternalAccessIntegrationsEqualsSegment") + .optional() + .to_matchable(), + Ref::new("SecretsEqualsSegment") + .optional() + .to_matchable(), + Ref::new("TagEqualsSegment").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("API_INTEGRATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("HEADERS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new( + "SingleQuotedIdentifierSegment", + ) + .to_matchable(), + Ref::new("EqualsSegment") + .to_matchable(), + Ref::new( + "SingleQuotedIdentifierSegment", + ) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONTEXT_HEADERS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ContextHeadersGrammar") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MAX_BATCH_ROWS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMPRESSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("CompressionType").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SECURE").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("REQUEST_TRANSLATOR") + .to_matchable(), + Ref::keyword("RESPONSE_TRANSLATOR") + .to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + one_of(vec![ + Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("HEADERS").to_matchable(), + Ref::keyword("CONTEXT_HEADERS").to_matchable(), + Ref::keyword("MAX_BATCH_ROWS").to_matchable(), + Ref::keyword("COMPRESSION").to_matchable(), + Ref::keyword("SECURE").to_matchable(), + Ref::keyword("REQUEST_TRANSLATOR").to_matchable(), + Ref::keyword("RESPONSE_TRANSLATOR").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TAG").to_matchable(), + Ref::new("TagReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("CommaSegment").to_matchable(), + Ref::new("TagReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateExternalFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateExternalFunctionStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Sequence::new(vec![Ref::keyword("SECURE").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar").to_matchable(), + Ref::keyword("RETURNS").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CALLED").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("INPUT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURNS").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::keyword("INPUT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("STRICT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Ref::keyword("VOLATILE").to_matchable(), + Ref::keyword("IMMUTABLE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), + Ref::keyword("API_INTEGRATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("HEADERS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("SingleQuotedIdentifierSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("SingleQuotedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CONTEXT_HEADERS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ContextHeadersGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MAX_BATCH_ROWS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMPRESSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("CompressionType").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REQUEST_TRANSLATOR").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESPONSE_TRANSLATOR").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("SingleQuotedIdentifierSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WarehouseObjectPropertiesSegment".into(), + NodeMatcher::new(SyntaxKind::WarehouseObjectProperties, |_dialect| { + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("WAREHOUSE_TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("WarehouseType").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WAREHOUSE_SIZE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("WarehouseSize").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESOURCE_CONSTRAINT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ResourceConstraint").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WAIT_FOR_COMPLETION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MAX_CLUSTER_COUNT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MIN_CLUSTER_COUNT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SCALING_POLICY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ScalingPolicy").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AUTO_SUSPEND").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AUTO_RESUME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INITIALLY_SUSPENDED").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESOURCE_MONITOR").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENABLE_QUERY_ACCELERATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("QUERY_ACCELERATION_MAX_SCALE_FACTOR").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WarehouseObjectParamsSegment".into(), + NodeMatcher::new(SyntaxKind::WarehouseObjectProperties, |_dialect| { + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("MAX_CONCURRENCY_LEVEL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STATEMENT_QUEUED_TIMEOUT_IN_SECONDS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STATEMENT_TIMEOUT_IN_SECONDS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "InlineConstraintPropertiesSegment".into(), + NodeMatcher::new(SyntaxKind::ConstraintPropertiesSegment, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("PrimaryKeyGrammar").to_matchable(), + Ref::new("UniqueKeyGrammar").to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![Ref::new("ForeignKeyGrammar").to_matchable()]) + .to_matchable(), + Ref::keyword("REFERENCES").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("ForeignKeyConstraintGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("InlineConstraintGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "OutOfLineConstraintPropertiesSegment".into(), + NodeMatcher::new(SyntaxKind::ConstraintPropertiesSegment, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("PrimaryKeyGrammar").to_matchable(), + Ref::new("UniqueKeyGrammar").to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::new("ForeignKeyGrammar").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("REFERENCES").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("ForeignKeyConstraintGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("InlineConstraintGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ColumnConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_dialect| { + AnyNumberOf::new(vec![ + Ref::new("CollateGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("AUTOINCREMENT").to_matchable(), + Ref::keyword("IDENTITY").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("START").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("INCREMENT").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("OrderNoOrderGrammar").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![Ref::keyword("WITH").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("TagBracketedEqualsSegment") + .optional() + .to_matchable(), + Ref::new("InlineConstraintPropertiesSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CHECK").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REFERENCES").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CopyOptionsSegment".into(), + NodeMatcher::new(SyntaxKind::CopyOptions, |_dialect| { + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("ON_ERROR").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("CopyOptionOnErrorSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SIZE_LIMIT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PURGE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RETURN_FAILED_ONLY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATCH_BY_COLUMN_NAME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("CASE_SENSITIVE").to_matchable(), + Ref::keyword("CASE_INSENSITIVE").to_matchable(), + Ref::keyword("NONE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INCLUDE_METADATA").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("METADATA$FILENAME").to_matchable(), + Ref::keyword("METADATA$FILE_ROW_NUMBER").to_matchable(), + Ref::keyword("METADATA$FILE_CONTENT_KEY").to_matchable(), + Ref::keyword("METADATA$FILE_LAST_MODIFIED").to_matchable(), + Ref::keyword("METADATA$START_SCAN_TIME").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENFORCE_LENGTH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TRUNCATECOLUMNS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FORCE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OVERWRITE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SINGLE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MAX_FILE_SIZE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INCLUDE_QUERY_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DETAILED_OUTPUT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LOAD_UNCERTAIN_FILES").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateSchemaStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateSchemaStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("AlterOrReplaceGrammar").optional().to_matchable(), + Ref::new("TemporaryTransientGrammar") + .optional() + .to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("MANAGED").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("SchemaObjectParamsSegment") + .optional() + .to_matchable(), + Ref::new("TagBracketedEqualsSegment") + .optional() + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterRoleStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterRoleStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Ref::new("RoleReferenceSegment").to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + one_of(vec![ + Ref::new("RoleReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![ + Ref::new("TagReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![Ref::keyword("COMMENT").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + one_of(vec![Ref::new("RoleReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateSequenceStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateSequenceStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("SequenceReferenceSegment").to_matchable(), + Sequence::new(vec![Ref::keyword("WITH").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("START").to_matchable(), + Sequence::new(vec![Ref::keyword("WITH").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("IntegerSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INCREMENT").to_matchable(), + Sequence::new(vec![Ref::keyword("BY").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("IntegerSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("OrderNoOrderGrammar").optional().to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterSequenceStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterSequenceStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SequenceReferenceSegment").to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![Ref::keyword("SET").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("INCREMENT").to_matchable(), + Sequence::new(vec![Ref::keyword("BY").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("EqualsSegment").optional().to_matchable(), + Ref::new("IntegerSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("OrderNoOrderGrammar").optional().to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("SequenceReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterSchemaStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterSchemaStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SWAP").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Ref::new("SchemaObjectParamsSegment").to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + one_of(vec![ + Delimited::new(vec![ + Ref::keyword("DATA_RETENTION_TIME_IN_DAYS").to_matchable(), + Ref::keyword("MAX_DATA_EXTENSION_TIME_IN_DAYS").to_matchable(), + Ref::keyword("DEFAULT_DDL_COLLATION").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![ + Ref::new("TagReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::keyword("DISABLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MANAGED").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SchemaObjectParamsSegment".into(), + NodeMatcher::new(SyntaxKind::SchemaObjectProperties, |_dialect| { + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("DATA_RETENTION_TIME_IN_DAYS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MAX_DATA_EXTENSION_TIME_IN_DAYS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT_DDL_COLLATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateEventTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateEventTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("EVENT").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + ]) + .to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("BY").to_matchable(), + one_of(vec![ + Ref::new("FunctionSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATA_RETENTION_TIME_IN_DAYS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MAX_DATA_EXTENSION_TIME_IN_DAYS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CHANGE_TRACKING").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT_DDL_COLLATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COPY").to_matchable(), + Ref::keyword("GRANTS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("TagBracketedEqualsSegment").to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DynamicTableOptionsSegment".into(), + NodeMatcher::new(SyntaxKind::DynamicTableOptions, |_dialect| { + Sequence::new(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("TARGET_LAG").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("DynamicTableTargetLagSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REFRESH_MODE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("RefreshModeType").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INITIALIZE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("InitializeType").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("BY").to_matchable(), + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BASE_LOCATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CATALOG").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL_VOLUME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATA_RETENTION_TIME_IN_DAYS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MAX_DATA_EXTENSION_TIME_IN_DAYS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").optional().to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("TagBracketedEqualsSegment") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REQUIRE").to_matchable(), + Ref::keyword("USER").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "IcebergTableOptionsSegment".into(), + NodeMatcher::new(SyntaxKind::IcebergTableOptions, |_dialect| { + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("EXTERNAL_VOLUME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CATALOG").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CATALOG_TABLE_NAME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CATALOG_NAMESPACE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REPLACE_INVALID_CHARACTERS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AUTO_REFRESH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("METADATA_FILE_PATH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BASE_LOCATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("AlterOrReplaceGrammar").optional().to_matchable(), + Ref::new("TemporaryTransientGrammar") + .optional() + .to_matchable(), + Ref::keyword("DYNAMIC").optional().to_matchable(), + Ref::keyword("HYBRID").optional().to_matchable(), + Ref::keyword("ICEBERG").optional().to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("OutOfLineConstraintPropertiesSegment") + .to_matchable(), + Ref::new("ColumnDefinitionSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Bracketed::new(vec![ + Anything::new().to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![ + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("BY").to_matchable(), + one_of(vec![ + Ref::new("FunctionSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STAGE_FILE_FORMAT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("FileFormatSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STAGE_COPY_OPTIONS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![Ref::new("CopyOptionsSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATA_RETENTION_TIME_IN_DAYS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MAX_DATA_EXTENSION_TIME_IN_DAYS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CHANGE_TRACKING").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT_DDL_COLLATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COPY").to_matchable(), + Ref::keyword("GRANTS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![Ref::keyword("WITH").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("IcebergTableOptionsSegment") + .optional() + .to_matchable(), + Ref::new("DynamicTableOptionsSegment") + .optional() + .to_matchable(), + Ref::new("TagBracketedEqualsSegment") + .optional() + .to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("DynamicTableOptionsSegment") + .optional() + .to_matchable(), + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![ + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CLONE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Ref::keyword("TEMPLATE").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateTaskSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTaskStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("AlterOrReplaceGrammar").optional().to_matchable(), + Ref::keyword("TASK").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + MetaSegment::indent().to_matchable(), + AnyNumberOf::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE") + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("WarehouseSize").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SCHEDULE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ Ref::keyword("ALLOW_OVERLAPPING_EXECUTION").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USER_TASK_TIMEOUT_MS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COPY").to_matchable(), + Ref::keyword("GRANTS").to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + Ref::new("LogLevelEqualsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AFTER").to_matchable(), + Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + Sequence::new(vec![ + Ref::keyword("WHEN").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("TaskExpressionSegment").to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("StatementSegment").to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TaskExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::SnowflakeTaskExpressionSegment, |_dialect| { + Sequence::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("SystemFunctionName").to_matchable(), + Bracketed::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.delimiter(one_of(vec![ + Ref::new("BooleanBinaryOperatorGrammar").to_matchable(), + ])); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("OrReplaceGrammar").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("NETWORK").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NETWORK").to_matchable(), + Ref::keyword("RULE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESOURCE").to_matchable(), + Ref::keyword("MONITOR").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SHARE").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Sequence::new(vec![ + Ref::keyword("API").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOTIFICATION").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SECURITY").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STORAGE").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CATALOG").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("PIPE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("AlterOrReplaceGrammar").optional().to_matchable(), + one_of(vec![ + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("API_PROVIDER").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("AWS_API_GATEWAY").to_matchable(), + Ref::keyword("AWS_PRIVATE_API_GATEWAY").to_matchable(), + Ref::keyword("AWS_GOV_API_GATEWAY").to_matchable(), + Ref::keyword("AWS_GOV_PRIVATE_API_GATEWAY").to_matchable(), + Ref::keyword("AZURE_API_MANAGEMENT").to_matchable(), + Ref::keyword("GOOGLE_API_GATEWAY").to_matchable(), + Ref::keyword("GIT_HTTPS_API").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("API_ALLOWED_PREFIXES").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("API_BLOCKED_PREFIXES").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("API_KEY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENABLED").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("API_AWS_ROLE_ARN").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AZURE_TENANT_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AZURE_AD_APPLICATION_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("GOOGLE_AUDIENCE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALLOWED_AUTHENTICATION_SECRETS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("NONE").to_matchable(), + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::keyword("QUEUE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENABLED").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOTIFICATION_PROVIDER").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("AWS_SNS").to_matchable(), + Ref::keyword("AZURE_EVENT_GRID").to_matchable(), + Ref::keyword("GCP_PUBSUB").to_matchable(), + Ref::keyword("AZURE_STORAGE_QUEUE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AWS_SNS_TOPIC_ARN").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AWS_SNS_ROLE_ARN").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AZURE_TENANT_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("AZURE_STORAGE_QUEUE_PRIMARY_URI").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AZURE_EVENT_GRID_TOPIC_ENDPOINT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("GCP_PUBSUB_SUBSCRIPTION_NAME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("GCP_PUBSUB_TOPIC_NAME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DIRECTION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::keyword("OUTBOUND").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALLOWED_VALUES").to_matchable(), + Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALLOWED_IP_LIST").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BLOCKED_IP_LIST").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALLOWED_NETWORK_RULE_LIST").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BLOCKED_NETWORK_RULE_LIST").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::keyword("EXTERNAL_STAGE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENABLED").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STORAGE_PROVIDER").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("S3").to_matchable(), + Ref::keyword("AZURE").to_matchable(), + Ref::keyword("GCS").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AZURE_TENANT_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STORAGE_AWS_ROLE_ARN").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STORAGE_AWS_OBJECT_ACL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + StringParser::new("'bucket-owner-full-control'", SyntaxKind::Literal) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STORAGE_ALLOWED_LOCATIONS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("S3Path").to_matchable(), + Ref::new("GCSPath").to_matchable(), + Ref::new("AzureBlobStoragePath").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![Ref::new("QuotedStarSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STORAGE_BLOCKED_LOCATIONS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("S3Path").to_matchable(), + Ref::new("GCSPath").to_matchable(), + Ref::new("AzureBlobStoragePath").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USE_PRIVATELINK_ENDPOINT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("CATALOG_SOURCE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("GLUE").to_matchable(), + Ref::keyword("POLARIS").to_matchable(), + Ref::keyword("ICEBERG_REST").to_matchable(), + Ref::keyword("OBJECT_STORE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLE_FORMAT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("ICEBERG").to_matchable(), + Ref::keyword("DELTA").to_matchable(), + Ref::keyword("ICEBERG_REST").to_matchable(), + Ref::keyword("OBJECT_STORE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CATALOG_NAMESPACE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENABLED").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REFRESH_INTERVAL_SECONDS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("LiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + Sequence::new(vec![ + one_of(vec![Ref::keyword("GLUE_AWS_ROLE_ARN").to_matchable()]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![Ref::keyword("GLUE_CATALOG_ID").to_matchable()]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![Ref::keyword("GLUE_REGION").to_matchable()]).to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REST_CONFIG").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("CATALOG_URI").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CATALOG_NAME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PREFIX").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CATALOG_API_TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("PUBLIC").to_matchable(), + Ref::keyword("AWS_API_GATEWAY").to_matchable(), + Ref::keyword("AWS_PRIVATE_API_GATEWAY").to_matchable(), + Ref::keyword("AWS_GLUE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REST_AUTHENTICATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::keyword("OAUTH").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OAUTH_TOKEN_URI").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OAUTH_CLIENT_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OAUTH_CLIENT_SECRET").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("OAUTH_ALLOWED_SCOPES").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::keyword("BEARER").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BEARER_TOKEN").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::keyword("SIGV4").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SIGV4_IAM_ROLE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SIGV4_SIGNING_REGION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SIGV4_EXTERNAL_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("AUTO_INGEST").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ERROR_INTEGRATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AWS_SNS_TOPIC").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INTEGRATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![Ref::keyword("WITH").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("WarehouseObjectPropertiesSegment").to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + Ref::new("WarehouseObjectParamsSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("TagBracketedEqualsSegment") + .optional() + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("IPV4").to_matchable(), + Ref::keyword("AWSVPCEID").to_matchable(), + Ref::keyword("AZURELINKID").to_matchable(), + Ref::keyword("HOST_PORT").to_matchable(), + Ref::keyword("PRIVATE_HOST_PORT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("VALUE_LIST").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MODE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("INGRESS").to_matchable(), + Ref::keyword("INTERNAL_STAGE").to_matchable(), + Ref::keyword("EGRESS").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), + Ref::keyword("AS").optional().to_matchable(), + one_of(vec![ + Ref::new("SelectStatementSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("FunctionContentsSegment").to_matchable(), + Ref::keyword("RETURNS").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Ref::new("FunctionAssignerSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("CopyIntoTableStatementSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateUserSegment".into(), + NodeMatcher::new(SyntaxKind::CreateUserStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + MetaSegment::indent().to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("PASSWORD").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LOGIN_NAME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DISPLAY_NAME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FIRST_NAME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MIDDLE_NAME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LAST_NAME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EMAIL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MUST_CHANGE_PASSWORD").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DISABLED").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DAYS_TO_EXPIRY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MINS_TO_UNLOCK").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT_WAREHOUSE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT_NAMESPACE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT_ROLE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT_SECONDARY_ROLES").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MINS_TO_BYPASS_MFA").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RSA_PUBLIC_KEY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RSA_PUBLIC_KEY_2").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("AlterOrReplaceGrammar").optional().to_matchable(), + AnyNumberOf::new(vec![ + Ref::keyword("SECURE").to_matchable(), + Ref::keyword("RECURSIVE").to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + Sequence::new(vec![Ref::keyword("MATERIALIZED").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").optional().to_matchable(), + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + Ref::new("ExpressionSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("TagBracketedEqualsSegment") + .optional() + .to_matchable(), + Ref::new("CommentClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").optional().to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("TagBracketedEqualsSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("COPY").to_matchable(), + Ref::keyword("GRANTS").to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("UNSET").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SECURE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![Ref::new("TagReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("MODIFY").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("COLUMN").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("FORCE").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![ + Ref::new("TagReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterMaterializedViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterMaterializedViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("BY").to_matchable(), + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("CLUSTERING").to_matchable(), + Ref::keyword("KEY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SUSPEND").to_matchable(), + Ref::keyword("RECLUSTER").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESUME").to_matchable(), + Ref::keyword("RECLUSTER").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SUSPEND").to_matchable(), + Ref::keyword("RESUME").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("UNSET").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("SECURE").to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateFileFormatSegment".into(), + NodeMatcher::new(SyntaxKind::CreateFileFormatSegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMAT").to_matchable(), + ]) + .to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ + Ref::new("CsvFileFormatTypeParameters").to_matchable(), + Ref::new("JsonFileFormatTypeParameters").to_matchable(), + Ref::new("AvroFileFormatTypeParameters").to_matchable(), + Ref::new("OrcFileFormatTypeParameters").to_matchable(), + Ref::new("ParquetFileFormatTypeParameters").to_matchable(), + Ref::new("XmlFileFormatTypeParameters").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("CommaSegment").optional().to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterFileFormatSegment".into(), + NodeMatcher::new(SyntaxKind::AlterFileFormatSegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMAT").to_matchable(), + ]) + .to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Ref::new("CsvFileFormatTypeParameters").to_matchable(), + Ref::new("JsonFileFormatTypeParameters").to_matchable(), + Ref::new("AvroFileFormatTypeParameters").to_matchable(), + Ref::new("OrcFileFormatTypeParameters").to_matchable(), + Ref::new("ParquetFileFormatTypeParameters").to_matchable(), + Ref::new("XmlFileFormatTypeParameters").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("CommaSegment").optional().to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CsvFileFormatTypeParameters".into(), + NodeMatcher::new(SyntaxKind::CsvFileFormatTypeParameters, |_dialect| { + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + StringParser::new("'CSV'", SyntaxKind::FileType).to_matchable(), + StringParser::new("CSV", SyntaxKind::FileType).to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMPRESSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("CompressionType").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MULTI_LINE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE_EXTENSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SKIP_HEADER").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("IntegerSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DATE_FORMAT").to_matchable(), + Ref::keyword("TIME_FORMAT").to_matchable(), + Ref::keyword("TIMESTAMP_FORMAT").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("AUTO").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BINARY_FORMAT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("HEX").to_matchable(), + Ref::keyword("BASE64").to_matchable(), + Ref::keyword("UTF8").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("RECORD_DELIMITER").to_matchable(), + Ref::keyword("FIELD_DELIMITER").to_matchable(), + Ref::keyword("ESCAPE").to_matchable(), + Ref::keyword("ESCAPE_UNENCLOSED_FIELD").to_matchable(), + Ref::keyword("FIELD_OPTIONALLY_ENCLOSED_BY").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("NONE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULL_IF").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("SKIP_BLANK_LINES").to_matchable(), + Ref::keyword("ERROR_ON_COLUMN_COUNT_MISMATCH").to_matchable(), + Ref::keyword("REPLACE_INVALID_CHARACTERS").to_matchable(), + Ref::keyword("VALIDATE_UTF8").to_matchable(), + Ref::keyword("EMPTY_FIELD_AS_NULL").to_matchable(), + Ref::keyword("SKIP_BYTE_ORDER_MARK").to_matchable(), + Ref::keyword("TRIM_SPACE").to_matchable(), + Ref::keyword("PARSE_HEADER").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ENCODING").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("UTF8").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional_delimiter(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "JsonFileFormatTypeParameters".into(), + NodeMatcher::new(SyntaxKind::JsonFileFormatTypeParameters, |_dialect| { + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + StringParser::new("'JSON'", SyntaxKind::FileType).to_matchable(), + StringParser::new("JSON", SyntaxKind::FileType).to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMPRESSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("CompressionType").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DATE_FORMAT").to_matchable(), + Ref::keyword("TIME_FORMAT").to_matchable(), + Ref::keyword("TIMESTAMP_FORMAT").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("AUTO").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BINARY_FORMAT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("HEX").to_matchable(), + Ref::keyword("BASE64").to_matchable(), + Ref::keyword("UTF8").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULL_IF").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE_EXTENSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TRIM_SPACE").to_matchable(), + Ref::keyword("ENABLE_OCTAL").to_matchable(), + Ref::keyword("ALLOW_DUPLICATE").to_matchable(), + Ref::keyword("STRIP_OUTER_ARRAY").to_matchable(), + Ref::keyword("STRIP_NULL_VALUES").to_matchable(), + Ref::keyword("REPLACE_INVALID_CHARACTERS").to_matchable(), + Ref::keyword("IGNORE_UTF8_ERRORS").to_matchable(), + Ref::keyword("SKIP_BYTE_ORDER_MARK").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional_delimiter(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AvroFileFormatTypeParameters".into(), + NodeMatcher::new(SyntaxKind::AvroFileFormatTypeParameters, |_dialect| { + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + StringParser::new("'AVRO'", SyntaxKind::FileType).to_matchable(), + StringParser::new("AVRO", SyntaxKind::FileType).to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMPRESSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("CompressionType").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TRIM_SPACE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULL_IF").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional_delimiter(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "OrcFileFormatTypeParameters".into(), + NodeMatcher::new(SyntaxKind::OrcFileFormatTypeParameters, |_dialect| { + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + StringParser::new("'ORC'", SyntaxKind::FileType).to_matchable(), + StringParser::new("ORC", SyntaxKind::FileType).to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TRIM_SPACE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULL_IF").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional_delimiter(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ParquetFileFormatTypeParameters".into(), + NodeMatcher::new(SyntaxKind::ParquetFileFormatTypeParameters, |_dialect| { + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + StringParser::new("'PARQUET'", SyntaxKind::FileType).to_matchable(), + StringParser::new("PARQUET", SyntaxKind::FileType).to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMPRESSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("CompressionType").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("SNAPPY_COMPRESSION").to_matchable(), + Ref::keyword("BINARY_AS_TEXT").to_matchable(), + Ref::keyword("USE_LOGICAL_TYPE").to_matchable(), + Ref::keyword("TRIM_SPACE").to_matchable(), + Ref::keyword("USE_VECTORIZED_SCANNER").to_matchable(), + Ref::keyword("REPLACE_INVALID_CHARACTERS").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULL_IF").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional_delimiter(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "XmlFileFormatTypeParameters".into(), + NodeMatcher::new(SyntaxKind::XmlFileFormatTypeParameters, |_dialect| { + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + StringParser::new("'XML'", SyntaxKind::FileType).to_matchable(), + StringParser::new("XML", SyntaxKind::FileType).to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMPRESSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("CompressionType").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("IGNORE_UTF8_ERRORS").to_matchable(), + Ref::keyword("PRESERVE_SPACE").to_matchable(), + Ref::keyword("STRIP_OUTER_ELEMENT").to_matchable(), + Ref::keyword("DISABLE_SNOWFLAKE_DATA").to_matchable(), + Ref::keyword("DISABLE_AUTO_CONVERT").to_matchable(), + Ref::keyword("SKIP_BYTE_ORDER_MARK").to_matchable(), ]) .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional_delimiter(); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterPipeSegment".into(), + NodeMatcher::new(SyntaxKind::AlterPipeSegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("PIPE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("USER_TASK_TIMEOUT_MS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("PIPE_EXECUTION_PAUSED").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ERROR_INTEGRATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + one_of(vec![ + Ref::keyword("PIPE_EXECUTION_PAUSED").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("BooleanLiteralGrammar").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![ + Ref::new("TagReferenceSegment").to_matchable(), ]) .to_matchable(), ]) @@ -5205,33 +10008,72 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("COPY").to_matchable(), - Ref::keyword("GRANTS").to_matchable(), + Ref::keyword("REFRESH").to_matchable(), + Sequence::new(vec![ + Ref::keyword("PREFIX").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MODIFIED_AFTER").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), - Ref::new("CommentEqualsClauseSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("AFTER").to_matchable(), + Ref::new("CommaSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FileFormatSegment".into(), + NodeMatcher::new(SyntaxKind::FileFormatSegment, |_dialect| { + one_of(vec![ + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - Sequence::new(vec![ - Ref::keyword("WHEN").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("TaskExpressionSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .config(|this| this.optional()) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("StatementSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("FORMAT_NAME").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::new("CsvFileFormatTypeParameters").to_matchable(), + Ref::new("JsonFileFormatTypeParameters").to_matchable(), + Ref::new("AvroFileFormatTypeParameters").to_matchable(), + Ref::new("OrcFileFormatTypeParameters").to_matchable(), + Ref::new("ParquetFileFormatTypeParameters").to_matchable(), + Ref::new("XmlFileFormatTypeParameters").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("FormatTypeOptions").optional().to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -5241,15 +10083,112 @@ pub fn dialect() -> Dialect { .into(), ), ( - "TaskExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::SnowflakeTaskExpressionSegment, |_| { - Sequence::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("SystemFunctionName").to_matchable(), - Bracketed::new(vec![ + "FormatTypeOptions".into(), + NodeMatcher::new(SyntaxKind::FormatTypeOptions, |_dialect| { + one_of(vec![ + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("COMPRESSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("CompressionType").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RECORD_DELIMITER").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("NONE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FIELD_DELIMITER").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("NONE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ESCAPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("NONE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ESCAPE_UNENCLOSED_FIELD").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("NONE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATA_FORMAT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("AUTO").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TIME_FORMAT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("NONE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TIMESTAMP_FORMAT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("NONE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BINARY_FORMAT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("HEX").to_matchable(), + Ref::keyword("BASE64").to_matchable(), + Ref::keyword("UTF8").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FIELD_OPTIONALITY_ENCLOSED_BY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("NONE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULL_IF").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), @@ -5257,13 +10196,28 @@ pub fn dialect() -> Dialect { .to_matchable(), ]) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EMPTY_FIELD_AS_NULL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SNAPPY_COMPRESSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), ]) .config(|this| { - this.delimiter(one_of(vec![ - Ref::new("BooleanBinaryOperatorGrammar").to_matchable(), - ])) + this.max_times_per_element = Some(1); }) .to_matchable(), + AnyNumberOf::new(vec![]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), ]) .to_matchable() }) @@ -5271,355 +10225,383 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CreateStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateStatement, |_| { + "CreateExternalTableSegment".into(), + NodeMatcher::new(SyntaxKind::CreateExternalTableStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::new("OrReplaceGrammar").optional().to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("NETWORK").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RESOURCE").to_matchable(), - Ref::keyword("MONITOR").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("SHARE").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::keyword("TAG").to_matchable(), - Ref::keyword("WAREHOUSE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOTIFICATION").to_matchable(), - Ref::keyword("INTEGRATION").to_matchable(), + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![ + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("InlineConstraintPropertiesSegment") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::keyword("SECURITY").to_matchable(), Ref::keyword("INTEGRATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("STORAGE").to_matchable(), - Ref::keyword("INTEGRATION").to_matchable(), + Ref::keyword("PARTITION").to_matchable(), + Ref::keyword("BY").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), + Sequence::new(vec![Ref::keyword("WITH").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("LOCATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("StagePath").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), + Ref::keyword("REFRESH_ON_CREATE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), - Ref::keyword("PIPE").to_matchable(), Sequence::new(vec![ - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), + Ref::keyword("AUTO_REFRESH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("SEQUENCE").to_matchable(), - ]) - .to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - any_set_of(vec![ Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), + Ref::keyword("PATTERN").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::keyword("QUEUE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("ENABLED").to_matchable(), + Ref::keyword("FILE_FORMAT").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::new("FileFormatSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("NOTIFICATION_PROVIDER").to_matchable(), + Ref::keyword("AWS_SNS_TOPIC").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("AWS_SNS").to_matchable(), - Ref::keyword("AZURE_EVENT_GRID").to_matchable(), - Ref::keyword("GCP_PUBSUB").to_matchable(), - Ref::keyword("AZURE_STORAGE_QUEUE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("AWS_SNS_TOPIC_ARN").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("COPY").to_matchable(), + Ref::keyword("GRANTS").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("AWS_SNS_ROLE_ARN").to_matchable(), + Ref::keyword("PARTITION_TYPE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("USER_SPECIFIED").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("AZURE_TENANT_ID").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![Ref::keyword("WITH").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("AZURE_STORAGE_QUEUE_PRIMARY_URI").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("AZURE_EVENT_GRID_TOPIC_ENDPOINT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("TagBracketedEqualsSegment").to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::TableExpression, |_dialect| { + one_of(vec![ + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("StagePath").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("FILE_FORMAT").to_matchable(), + Ref::new("ParameterAssignerSegment").to_matchable(), + Ref::new("FileFormatSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PATTERN").to_matchable(), + Ref::new("ParameterAssignerSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("GCP_PUBSUB_SUBSCRIPTION_NAME").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "PartitionBySegment".into(), + NodeMatcher::new(SyntaxKind::PartitionBySegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("PARTITION").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + optionally_bracketed(vec![ + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("GCP_PUBSUB_TOPIC_NAME").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CopyIntoLocationStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CopyIntoLocationStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("COPY").to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::new("StorageLocation").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + one_of(vec![ + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Ref::new("S3ExternalStageParameters").to_matchable(), + Ref::new("AzureBlobStorageExternalStageParameters").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("InternalStageParameters") + .optional() + .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("PartitionBySegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE_FORMAT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("FileFormatSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON_ERROR").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("CopyOptionOnErrorSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("DIRECTION").to_matchable(), + Ref::keyword("SIZE_LIMIT").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::keyword("OUTBOUND").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("PURGE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("ALLOWED_VALUES").to_matchable(), - Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) - .to_matchable(), + Ref::keyword("RETURN_FAILED_ONLY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("ALLOWED_IP_LIST").to_matchable(), + Ref::keyword("MATCH_BY_COLUMN_NAME").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + one_of(vec![ + Ref::keyword("CASE_SENSITIVE").to_matchable(), + Ref::keyword("CASE_INSENSITIVE").to_matchable(), + Ref::keyword("NONE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("BLOCKED_IP_LIST").to_matchable(), + Ref::keyword("INCLUDE_METADATA").to_matchable(), Ref::new("EqualsSegment").to_matchable(), Bracketed::new(vec![ Delimited::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("METADATA$FILENAME").to_matchable(), + Ref::keyword("METADATA$FILE_ROW_NUMBER").to_matchable(), + Ref::keyword("METADATA$FILE_CONTENT_KEY") + .to_matchable(), + Ref::keyword("METADATA$FILE_LAST_MODIFIED") + .to_matchable(), + Ref::keyword("METADATA$START_SCAN_TIME").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::keyword("EXTERNAL_STAGE").to_matchable(), - ]) - .to_matchable(), Sequence::new(vec![ - Ref::keyword("ENABLED").to_matchable(), + Ref::keyword("ENFORCE_LENGTH").to_matchable(), Ref::new("EqualsSegment").to_matchable(), Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("STORAGE_PROVIDER").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("S3").to_matchable(), - Ref::keyword("AZURE").to_matchable(), - Ref::keyword("GCS").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("AZURE_TENANT_ID").to_matchable(), + Ref::keyword("TRUNCATECOLUMNS").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("STORAGE_AWS_ROLE_ARN").to_matchable(), + Ref::keyword("FORCE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("STORAGE_AWS_OBJECT_ACL").to_matchable(), + Ref::keyword("OVERWRITE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - StringParser::new("'bucket-owner-full-control'", SyntaxKind::Literal) - .to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("STORAGE_ALLOWED_LOCATIONS").to_matchable(), + Ref::keyword("SINGLE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("S3Path").to_matchable(), - Ref::new("GCSPath").to_matchable(), - Ref::new("AzureBlobStoragePath").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![Ref::new("QuotedStarSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("STORAGE_BLOCKED_LOCATIONS").to_matchable(), + Ref::keyword("MAX_FILE_SIZE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("S3Path").to_matchable(), - Ref::new("GCSPath").to_matchable(), - Ref::new("AzureBlobStoragePath").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("INCLUDE_QUERY_ID").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ Sequence::new(vec![ - Ref::keyword("AUTO_INGEST").to_matchable(), + Ref::keyword("DETAILED_OUTPUT").to_matchable(), Ref::new("EqualsSegment").to_matchable(), Ref::new("BooleanLiteralGrammar").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Sequence::new(vec![ - Ref::keyword("ERROR_INTEGRATION").to_matchable(), + Ref::keyword("LOAD_UNCERTAIN_FILES").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Sequence::new(vec![ - Ref::keyword("AWS_SNS_TOPIC").to_matchable(), + Ref::keyword("VALIDATION_MODE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ValidationModeOptionSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Sequence::new(vec![ - Ref::keyword("INTEGRATION").to_matchable(), + Ref::keyword("HEADER").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Sequence::new(vec![Ref::keyword("WITH").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("WarehouseObjectPropertiesSegment").to_matchable(), - Ref::new("CommentEqualsClauseSegment").to_matchable(), - Ref::new("WarehouseObjectParamsSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("TagBracketedEqualsSegment") - .optional() - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("CommentEqualsClauseSegment") - .optional() - .to_matchable(), - Ref::keyword("AS").optional().to_matchable(), - one_of(vec![ - Ref::new("SelectStatementSegment").to_matchable(), - Sequence::new(vec![ - Bracketed::new(vec![ - Ref::new("FunctionContentsGrammar").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("RETURNS").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Ref::new("FunctionAssignerSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::new("CopyIntoTableStatementSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), ]) .to_matchable() @@ -5628,376 +10610,249 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CreateUserSegment".into(), - NodeMatcher::new(SyntaxKind::CreateUserStatement, |_| { + "CopyIntoTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CopyIntoTableStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), + Ref::keyword("COPY").to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("USER").to_matchable(), Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - MetaSegment::indent().to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("PASSWORD").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LOGIN_NAME").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DISPLAY_NAME").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FIRST_NAME").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("FROM").to_matchable(), + one_of(vec![ + Ref::new("StorageLocation").to_matchable(), + Bracketed::new(vec![Ref::new("SelectStatementSegment").to_matchable()]) + .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MIDDLE_NAME").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Ref::new("S3ExternalStageParameters").to_matchable(), + Ref::new("AzureBlobStorageExternalStageParameters").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("InternalStageParameters") + .optional() .to_matchable(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::keyword("LAST_NAME").to_matchable(), + Ref::keyword("FILES").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("EMAIL").to_matchable(), + Ref::keyword("PATTERN").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("MUST_CHANGE_PASSWORD").to_matchable(), + Ref::keyword("FILE_FORMAT").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::new("FileFormatSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("DISABLED").to_matchable(), + Ref::keyword("ON_ERROR").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::new("CopyOptionOnErrorSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("DAYS_TO_EXPIRY").to_matchable(), + Ref::keyword("SIZE_LIMIT").to_matchable(), Ref::new("EqualsSegment").to_matchable(), Ref::new("NumericLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("MINS_TO_UNLOCK").to_matchable(), + Ref::keyword("PURGE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("DEFAULT_WAREHOUSE").to_matchable(), + Ref::keyword("RETURN_FAILED_ONLY").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("DEFAULT_NAMESPACE").to_matchable(), + Ref::keyword("MATCH_BY_COLUMN_NAME").to_matchable(), Ref::new("EqualsSegment").to_matchable(), one_of(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("CASE_SENSITIVE").to_matchable(), + Ref::keyword("CASE_INSENSITIVE").to_matchable(), + Ref::keyword("NONE").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("DEFAULT_ROLE").to_matchable(), + Ref::keyword("INCLUDE_METADATA").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("METADATA$FILENAME").to_matchable(), + Ref::keyword("METADATA$FILE_ROW_NUMBER").to_matchable(), + Ref::keyword("METADATA$FILE_CONTENT_KEY") + .to_matchable(), + Ref::keyword("METADATA$FILE_LAST_MODIFIED") + .to_matchable(), + Ref::keyword("METADATA$START_SCAN_TIME").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("DEFAULT_SECONDARY_ROLES").to_matchable(), + Ref::keyword("ENFORCE_LENGTH").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) - .to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("MINS_TO_BYPASS_MFA").to_matchable(), + Ref::keyword("TRUNCATECOLUMNS").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("RSA_PUBLIC_KEY").to_matchable(), + Ref::keyword("FORCE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("RSA_PUBLIC_KEY_2").to_matchable(), + Ref::keyword("OVERWRITE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("CommentEqualsClauseSegment").to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ]); - - snowflake_dialect.replace_grammar( - "CreateViewStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - any_set_of(vec![ - Ref::keyword("SECURE").to_matchable(), - Ref::keyword("RECURSIVE").to_matchable(), - ]) - .to_matchable(), - Ref::new("TemporaryGrammar").optional().to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - any_set_of(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("CommentClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").optional().to_matchable(), - Ref::keyword("ROW").to_matchable(), - Ref::keyword("ACCESS").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::keyword("ON").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("TagBracketedEqualsSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("COPY").to_matchable(), - Ref::keyword("GRANTS").to_matchable(), - ]) - .to_matchable(), - Ref::new("CommentEqualsClauseSegment").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("AS").to_matchable(), - optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.add([ - ( - "AlterViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterViewStatement, |_| { - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("SINGLE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("MAX_FILE_SIZE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - one_of(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("UNSET").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("SECURE").to_matchable(), + Ref::keyword("INCLUDE_QUERY_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("TagEqualsSegment").to_matchable(), + Ref::keyword("DETAILED_OUTPUT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Ref::keyword("TAG").to_matchable(), - Delimited::new(vec![Ref::new("TagReferenceSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("ROW").to_matchable(), - Ref::keyword("ACCESS").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Ref::keyword("ON").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("ROW").to_matchable(), - Ref::keyword("ACCESS").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("LOAD_UNCERTAIN_FILES").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("VALIDATION_MODE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ValidationModeOptionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CopyFilesIntoLocationStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CopyFilesIntoLocationStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("COPY").to_matchable(), + Ref::keyword("FILES").to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::new("StorageLocation").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("StorageLocation").to_matchable(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("MODIFY").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ + Ref::keyword("FILES").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ Delimited::new(vec![ - Sequence::new(vec![ - Ref::keyword("COLUMN").optional().to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment") - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("TagEqualsSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLUMN").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::keyword("UNSET").to_matchable(), - Ref::keyword("TAG").to_matchable(), - Delimited::new(vec![ - Ref::new("TagReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PATTERN").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DETAILED_OUTPUT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -6006,61 +10861,13 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterMaterializedViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterMaterializedViewStatement, |_| { - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CLUSTER").to_matchable(), - Ref::keyword("BY").to_matchable(), - Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("CLUSTERING").to_matchable(), - Ref::keyword("KEY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SUSPEND").to_matchable(), - Ref::keyword("RECLUSTER").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RESUME").to_matchable(), - Ref::keyword("RECLUSTER").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("SUSPEND").to_matchable(), - Ref::keyword("RESUME").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("UNSET").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("SECURE").to_matchable(), - Ref::new("CommentEqualsClauseSegment").to_matchable(), - Ref::new("TagEqualsSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + "StorageLocation".into(), + NodeMatcher::new(SyntaxKind::StorageLocation, |_dialect| { + one_of(vec![ + Ref::new("StagePath").to_matchable(), + Ref::new("S3Path").to_matchable(), + Ref::new("GCSPath").to_matchable(), + Ref::new("AzureBlobStoragePath").to_matchable(), ]) .to_matchable() }) @@ -6068,32 +10875,22 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CreateFileFormatSegment".into(), - NodeMatcher::new(SyntaxKind::CreateFileFormatSegment, |_| { + "InternalStageParameters".into(), + NodeMatcher::new(SyntaxKind::StageParameters, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("FILE").to_matchable(), - Ref::keyword("FORMAT").to_matchable(), - ]) - .to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - one_of(vec![ - Ref::new("CsvFileFormatTypeParameters").to_matchable(), - Ref::new("JsonFileFormatTypeParameters").to_matchable(), - Ref::new("AvroFileFormatTypeParameters").to_matchable(), - Ref::new("OrcFileFormatTypeParameters").to_matchable(), - Ref::new("ParquetFileFormatTypeParameters").to_matchable(), - Ref::new("XmlFileFormatTypeParameters").to_matchable(), - ]) - .to_matchable(), Sequence::new(vec![ - Ref::new("CommaSegment").optional().to_matchable(), - Ref::new("CommentEqualsClauseSegment").to_matchable(), + Ref::keyword("ENCRYPTION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("SnowflakeEncryptionOption").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -6102,44 +10899,111 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterFileFormatSegment".into(), - NodeMatcher::new(SyntaxKind::AlterFileFormatSegment, |_| { + "S3ExternalStageParameters".into(), + NodeMatcher::new(SyntaxKind::StageParameters, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Sequence::new(vec![ - Ref::keyword("FILE").to_matchable(), - Ref::keyword("FORMAT").to_matchable(), - ]) - .to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), + Ref::keyword("STORAGE_INTEGRATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - one_of(vec![ - Ref::new("CsvFileFormatTypeParameters").to_matchable(), - Ref::new("JsonFileFormatTypeParameters").to_matchable(), - Ref::new("AvroFileFormatTypeParameters").to_matchable(), - Ref::new("OrcFileFormatTypeParameters").to_matchable(), - Ref::new("ParquetFileFormatTypeParameters").to_matchable(), - Ref::new("XmlFileFormatTypeParameters").to_matchable(), + Ref::keyword("CREDENTIALS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("AWS_KEY_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("AWS_SECRET_KEY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AWS_TOKEN").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AWS_ROLE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::new("CommaSegment").optional().to_matchable(), - Ref::new("CommentEqualsClauseSegment").to_matchable(), + Ref::keyword("ENCRYPTION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("S3EncryptionOption").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("MASTER_KEY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("S3EncryptionOption").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("S3EncryptionOption").to_matchable(), + Sequence::new(vec![ + Ref::keyword("KMS_KEY_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::keyword("NONE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -6148,215 +11012,505 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CsvFileFormatTypeParameters".into(), - NodeMatcher::new(SyntaxKind::CsvFileFormatTypeParameters, |_| { - let file_format_type_parameter = one_of(vec![ - Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - StringParser::new("'CSV'", SyntaxKind::FileType).to_matchable(), - StringParser::new("CSV", SyntaxKind::FileType).to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COMPRESSION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("CompressionType").to_matchable(), - ]) - .to_matchable(), + "GCSExternalStageParameters".into(), + NodeMatcher::new(SyntaxKind::StageParameters, |_dialect| { + Sequence::new(vec![ Sequence::new(vec![ - Ref::keyword("FILE_EXTENSION").to_matchable(), + Ref::keyword("STORAGE_INTEGRATION").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SKIP_HEADER").to_matchable(), + Ref::keyword("ENCRYPTION").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("IntegerSegment").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("GCSEncryptionOption").to_matchable(), + Sequence::new(vec![ + Ref::keyword("KMS_KEY_ID").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("NONE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DATE_FORMAT").to_matchable(), - Ref::keyword("TIME_FORMAT").to_matchable(), - Ref::keyword("TIMESTAMP_FORMAT").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AzureBlobStorageExternalStageParameters".into(), + NodeMatcher::new(SyntaxKind::StageParameters, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("STORAGE_INTEGRATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("AUTO").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("CREDENTIALS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![Ref::keyword("AZURE_SAS_TOKEN").to_matchable()]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("BINARY_FORMAT").to_matchable(), + Ref::keyword("ENCRYPTION").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("HEX").to_matchable(), - Ref::keyword("BASE64").to_matchable(), - Ref::keyword("UTF8").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("AzureBlobStorageEncryptionOption").to_matchable(), + Sequence::new(vec![ + Ref::keyword("MASTER_KEY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("NONE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("RECORD_DELIMITER").to_matchable(), - Ref::keyword("FIELD_DELIMITER").to_matchable(), - Ref::keyword("ESCAPE").to_matchable(), - Ref::keyword("ESCAPE_UNENCLOSED_FIELD").to_matchable(), - Ref::keyword("FIELD_OPTIONALLY_ENCLOSED_BY").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateStageSegment".into(), + NodeMatcher::new(SyntaxKind::CreateStageStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("AlterOrReplaceGrammar").optional().to_matchable(), + Ref::keyword("TEMPORARY").optional().to_matchable(), + Ref::keyword("STAGE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("InternalStageParameters") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DIRECTORY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), one_of(vec![ - Ref::keyword("NONE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NULL_IF").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) - .config(|this| this.optional()) + Sequence::new(vec![ + Ref::keyword("URL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("S3Path").to_matchable(), + Ref::new("GCSPath").to_matchable(), + Ref::new("AzureBlobStoragePath").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("S3ExternalStageParameters") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DIRECTORY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AUTO_REFRESH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("GCSExternalStageParameters") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DIRECTORY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AUTO_REFRESH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOTIFICATION_INTEGRATION") + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("NakedIdentifierSegment") + .to_matchable(), + Ref::new("QuotedLiteralSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("AzureBlobStorageExternalStageParameters") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DIRECTORY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AUTO_REFRESH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOTIFICATION_INTEGRATION") + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("NakedIdentifierSegment") + .to_matchable(), + Ref::new("QuotedLiteralSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::new("S3ExternalStageParameters") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DIRECTORY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AUTO_REFRESH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("GCSExternalStageParameters") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DIRECTORY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AUTO_REFRESH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOTIFICATION_INTEGRATION") + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("NakedIdentifierSegment") + .to_matchable(), + Ref::new("QuotedLiteralSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("AzureBlobStorageExternalStageParameters") + .optional() + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DIRECTORY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::keyword("ENABLE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AUTO_REFRESH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar") + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOTIFICATION_INTEGRATION") + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("NakedIdentifierSegment") + .to_matchable(), + Ref::new("QuotedLiteralSegment") + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("SKIP_BLANK_LINES").to_matchable(), - Ref::keyword("ERROR_ON_COLUMN_COUNT_MISMATCH").to_matchable(), - Ref::keyword("REPLACE_INVALID_CHARACTERS").to_matchable(), - Ref::keyword("VALIDATE_UTF8").to_matchable(), - Ref::keyword("EMPTY_FIELD_AS_NULL").to_matchable(), - Ref::keyword("SKIP_BYTE_ORDER_MARK").to_matchable(), - Ref::keyword("TRIM_SPACE").to_matchable(), - ]) - .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ENCODING").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("UTF8").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]); - - one_of(vec![ - Delimited::new(vec![file_format_type_parameter.clone().to_matchable()]) - .to_matchable(), - AnyNumberOf::new(vec![file_format_type_parameter.to_matchable()]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "JsonFileFormatTypeParameters".into(), - NodeMatcher::new(SyntaxKind::JsonFileFormatTypeParameters, |_| { - let file_format_type_parameter = one_of(vec![ - Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - StringParser::new("'JSON'", SyntaxKind::FileType).to_matchable(), - StringParser::new("JSON", SyntaxKind::FileType).to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COMPRESSION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("CompressionType").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DATE_FORMAT").to_matchable(), - Ref::keyword("TIME_FORMAT").to_matchable(), - Ref::keyword("TIMESTAMP_FORMAT").to_matchable(), - ]) - .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::keyword("AUTO").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("BINARY_FORMAT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("HEX").to_matchable(), - Ref::keyword("BASE64").to_matchable(), - Ref::keyword("UTF8").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NULL_IF").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) - .config(|this| this.optional()) + Ref::keyword("URL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("S3Path").to_matchable(), + Ref::new("GCSPath").to_matchable(), + Ref::new("AzureBlobStoragePath").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + ]) .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("FILE_EXTENSION").to_matchable(), + Ref::keyword("FILE_FORMAT").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("FileFormatSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - one_of(vec![ - Ref::keyword("TRIM_SPACE").to_matchable(), - Ref::keyword("ENABLE_OCTAL").to_matchable(), - Ref::keyword("ALLOW_DUPLICATE").to_matchable(), - Ref::keyword("STRIP_OUTER_ARRAY").to_matchable(), - Ref::keyword("STRIP_NULL_VALUES").to_matchable(), - Ref::keyword("REPLACE_INVALID_CHARACTERS").to_matchable(), - Ref::keyword("IGNORE_UTF8_ERRORS").to_matchable(), - Ref::keyword("SKIP_BYTE_ORDER_MARK").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("COPY_OPTIONS").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Bracketed::new(vec![Ref::new("CopyOptionsSegment").to_matchable()]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]); - - one_of(vec![ - Delimited::new(vec![file_format_type_parameter.clone().to_matchable()]) + Ref::new("TagBracketedEqualsSegment") + .optional() .to_matchable(), - AnyNumberOf::new(vec![file_format_type_parameter.to_matchable()]) + Ref::new("CommentEqualsClauseSegment") + .optional() .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) @@ -6364,49 +11518,124 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AvroFileFormatTypeParameters".into(), - NodeMatcher::new(SyntaxKind::AvroFileFormatTypeParameters, |_| { - let file_format_type_parameter = one_of(vec![ - Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - StringParser::new("'AVRO'", SyntaxKind::FileType).to_matchable(), - StringParser::new("AVRO", SyntaxKind::FileType).to_matchable(), + "AlterStageSegment".into(), + NodeMatcher::new(SyntaxKind::AlterStageStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("STAGE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COMPRESSION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("CompressionType").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TRIM_SPACE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NULL_IF").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) - .config(|this| this.optional()) + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("InternalStageParameters").to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("URL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("S3Path").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("S3ExternalStageParameters") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("URL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("GCSPath").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("GCSExternalStageParameters") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("URL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("AzureBlobStoragePath").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("AzureBlobStorageExternalStageParameters") + .optional() + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE_FORMAT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("FileFormatSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COPY_OPTIONS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Ref::new("CopyOptionsSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), + ]) .to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REFRESH").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SUBPATH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]); - - one_of(vec![ - Delimited::new(vec![file_format_type_parameter.clone().to_matchable()]) - .to_matchable(), - AnyNumberOf::new(vec![file_format_type_parameter.to_matchable()]) - .to_matchable(), ]) .to_matchable() }) @@ -6414,42 +11643,91 @@ pub fn dialect() -> Dialect { .into(), ), ( - "OrcFileFormatTypeParameters".into(), - NodeMatcher::new(SyntaxKind::OrcFileFormatTypeParameters, |_| { - let file_format_type_parameter = one_of(vec![ - Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - StringParser::new("'ORC'", SyntaxKind::FileType).to_matchable(), - StringParser::new("ORC", SyntaxKind::FileType).to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + "CreateStreamStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateStreamStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("STREAM").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("TRIM_SPACE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::keyword("COPY").to_matchable(), + Ref::keyword("GRANTS").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NULL_IF").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("ON").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ + Ref::new("FromAtExpressionSegment").to_matchable(), + Ref::new("FromBeforeExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPEND_ONLY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SHOW_INITIAL_ROWS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ + Ref::new("FromAtExpressionSegment").to_matchable(), + Ref::new("FromBeforeExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INSERT_ONLY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("TrueSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STAGE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]); - - one_of(vec![ - Delimited::new(vec![file_format_type_parameter.clone().to_matchable()]) - .to_matchable(), - AnyNumberOf::new(vec![file_format_type_parameter.to_matchable()]) + Ref::new("CommentEqualsClauseSegment") + .optional() .to_matchable(), ]) .to_matchable() @@ -6458,54 +11736,51 @@ pub fn dialect() -> Dialect { .into(), ), ( - "ParquetFileFormatTypeParameters".into(), - NodeMatcher::new(SyntaxKind::ParquetFileFormatTypeParameters, |_| { - let file_format_type_parameter = one_of(vec![ + "CreateStreamlitStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateStreamlitStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("STREAMLIT").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), + Ref::keyword("ROOT_LOCATION").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - StringParser::new("'PARQUET'", SyntaxKind::FileType).to_matchable(), - StringParser::new("PARQUET", SyntaxKind::FileType).to_matchable(), - ]) - .to_matchable(), + Ref::new("StagePath").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("COMPRESSION").to_matchable(), + Ref::keyword("MAIN_FILE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("CompressionType").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ + Ref::keyword("QUERY_WAREHOUSE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), one_of(vec![ - Ref::keyword("SNAPPY_COMPRESSION").to_matchable(), - Ref::keyword("BINARY_AS_TEXT").to_matchable(), - Ref::keyword("TRIM_SPACE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), Sequence::new(vec![ - Ref::keyword("NULL_IF").to_matchable(), + Ref::keyword("TITLE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]); - - one_of(vec![ - Delimited::new(vec![file_format_type_parameter.clone().to_matchable()]) - .to_matchable(), - AnyNumberOf::new(vec![file_format_type_parameter.to_matchable()]) - .to_matchable(), ]) .to_matchable() }) @@ -6513,46 +11788,67 @@ pub fn dialect() -> Dialect { .into(), ), ( - "XmlFileFormatTypeParameters".into(), - NodeMatcher::new(SyntaxKind::XmlFileFormatTypeParameters, |_| { - let file_format_type_parameter = one_of(vec![ + "CreateCortexSearchServiceStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateCortexSearchServiceStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), + Ref::keyword("CORTEX").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("SERVICE").to_matchable(), + ]) + .to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ATTRIBUTES").to_matchable(), + Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WAREHOUSE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), one_of(vec![ - StringParser::new("'XML'", SyntaxKind::FileType).to_matchable(), - StringParser::new("XML", SyntaxKind::FileType).to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("COMPRESSION").to_matchable(), + Ref::keyword("TARGET_LAG").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("CompressionType").to_matchable(), + Ref::new("DynamicTableTargetLagSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - one_of(vec![ - Ref::keyword("IGNORE_UTF8_ERRORS").to_matchable(), - Ref::keyword("PRESERVE_SPACE").to_matchable(), - Ref::keyword("STRIP_OUTER_ELEMENT").to_matchable(), - Ref::keyword("DISABLE_SNOWFLAKE_DATA").to_matchable(), - Ref::keyword("DISABLE_AUTO_CONVERT").to_matchable(), - Ref::keyword("SKIP_BYTE_ORDER_MARK").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("EMBEDDING_MODEL").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]); - - one_of(vec![ - Delimited::new(vec![file_format_type_parameter.clone().to_matchable()]) - .to_matchable(), - AnyNumberOf::new(vec![file_format_type_parameter.to_matchable()]) + Ref::new("CommentEqualsClauseSegment") + .optional() .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) @@ -6560,75 +11856,113 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterPipeSegment".into(), - NodeMatcher::new(SyntaxKind::AlterPipeSegment, |_| { + "AlterStreamStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterStreamStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ALTER").to_matchable(), - Ref::keyword("PIPE").to_matchable(), + Ref::keyword("STREAM").to_matchable(), Ref::new("IfExistsGrammar").optional().to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), one_of(vec![ Sequence::new(vec![ Ref::keyword("SET").to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("PIPE_EXECUTION_PAUSED").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Ref::new("CommentEqualsClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("APPEND_ONLY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INSERT_ONLY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("TrueSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("TagEqualsSegment").optional().to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ Ref::keyword("UNSET").to_matchable(), one_of(vec![ - Ref::keyword("PIPE_EXECUTION_PAUSED").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![ + Ref::new("TagReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), Ref::keyword("COMMENT").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterStreamlitStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterStreamlitStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("STREAMLIT").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("TagEqualsSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), + Ref::keyword("SET").to_matchable(), Sequence::new(vec![ - Ref::keyword("TAG").to_matchable(), - Delimited::new(vec![ - Ref::new("TagReferenceSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("ROOT_LOCATION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("StagePath").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("REFRESH").to_matchable(), Sequence::new(vec![ - Ref::keyword("PREFIX").to_matchable(), + Ref::keyword("MAIN_FILE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Sequence::new(vec![ - Ref::keyword("MODIFIED_AFTER").to_matchable(), + Ref::keyword("QUERY_WAREHOUSE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + one_of(vec![ + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Ref::new("CommaSegment").optional().to_matchable(), ]) .to_matchable() }) @@ -6636,39 +11970,71 @@ pub fn dialect() -> Dialect { .into(), ), ( - "FileFormatSegment".into(), - NodeMatcher::new(SyntaxKind::FileFormatSegment, |_| { - one_of(vec![ - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + "AlterCortexSearchServiceStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterStreamlitStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("CORTEX").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("SERVICE").to_matchable(), ]) .to_matchable(), - Bracketed::new(vec![ + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ Sequence::new(vec![ one_of(vec![ + Ref::keyword("SUSPEND").to_matchable(), + Ref::keyword("RESUME").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("INDEXING").to_matchable(), + Ref::keyword("SERVING").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::keyword("FORMAT_NAME").to_matchable(), + Ref::keyword("WAREHOUSE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - one_of(vec![ - Ref::new("CsvFileFormatTypeParameters").to_matchable(), - Ref::new("JsonFileFormatTypeParameters").to_matchable(), - Ref::new("AvroFileFormatTypeParameters").to_matchable(), - Ref::new("OrcFileFormatTypeParameters").to_matchable(), - Ref::new("ParquetFileFormatTypeParameters").to_matchable(), - Ref::new("XmlFileFormatTypeParameters").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TARGET_LAG").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("DynamicTableTargetLagSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), - Ref::new("FormatTypeOptions").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), ]) @@ -6680,137 +12046,223 @@ pub fn dialect() -> Dialect { .into(), ), ( - "FormatTypeOptions".into(), - NodeMatcher::new(SyntaxKind::FormatTypeOptions, |_| { - one_of(vec![ - // COPY INTO , open for extension - any_set_of(vec![ + "ShowStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ShowStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("SHOW").to_matchable(), + one_of(vec![Ref::keyword("TERSE").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Ref::keyword("PARAMETERS").to_matchable(), Sequence::new(vec![ - Ref::keyword("COMPRESSION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("CompressionType").to_matchable(), + Ref::keyword("GLOBAL").to_matchable(), + Ref::keyword("ACCOUNTS").to_matchable(), ]) .to_matchable(), + Ref::keyword("REGIONS").to_matchable(), Sequence::new(vec![ - Ref::keyword("RECORD_DELIMITER").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("NONE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("REPLICATION").to_matchable(), + Ref::keyword("ACCOUNTS").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("FIELD_DELIMITER").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("NONE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("REPLICATION").to_matchable(), + Ref::keyword("DATABASES").to_matchable(), ]) .to_matchable(), + Ref::keyword("PARAMETERS").to_matchable(), + Ref::keyword("VARIABLES").to_matchable(), + Ref::keyword("TRANSACTIONS").to_matchable(), + Ref::keyword("LOCKS").to_matchable(), + Ref::keyword("PARAMETERS").to_matchable(), + Ref::keyword("FUNCTIONS").to_matchable(), Sequence::new(vec![ - Ref::keyword("ESCAPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("NONE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("NETWORK").to_matchable(), + Ref::keyword("POLICIES").to_matchable(), ]) .to_matchable(), + Ref::keyword("SHARES").to_matchable(), + Ref::keyword("ROLES").to_matchable(), + Ref::keyword("GRANTS").to_matchable(), + Ref::keyword("USERS").to_matchable(), + Ref::keyword("WAREHOUSES").to_matchable(), + Ref::keyword("DATABASES").to_matchable(), Sequence::new(vec![ - Ref::keyword("ESCAPE_UNENCLOSED_FIELD").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), one_of(vec![ - Ref::keyword("NONE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("API").to_matchable(), + Ref::keyword("NOTIFICATION").to_matchable(), + Ref::keyword("SECURITY").to_matchable(), + Ref::keyword("STORAGE").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::keyword("INTEGRATIONS").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SCHEMAS").to_matchable(), + Ref::keyword("OBJECTS").to_matchable(), + Ref::keyword("TABLES").to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("TABLES").to_matchable(), ]) .to_matchable(), + Ref::keyword("VIEWS").to_matchable(), Sequence::new(vec![ - Ref::keyword("DATA_FORMAT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("AUTO").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEWS").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("TIME_FORMAT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("NONE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICIES").to_matchable(), ]) .to_matchable(), + Ref::keyword("COLUMNS").to_matchable(), Sequence::new(vec![ - Ref::keyword("TIMESTAMP_FORMAT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("NONE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMATS").to_matchable(), ]) .to_matchable(), + Ref::keyword("SEQUENCES").to_matchable(), + Ref::keyword("STAGES").to_matchable(), + Ref::keyword("PIPES").to_matchable(), + Ref::keyword("STREAMS").to_matchable(), + Ref::keyword("STREAMLITS").to_matchable(), + Ref::keyword("TASKS").to_matchable(), Sequence::new(vec![ - Ref::keyword("BINARY_FORMAT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("HEX").to_matchable(), - Ref::keyword("BASE64").to_matchable(), - Ref::keyword("UTF8").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::keyword("FUNCTIONS").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("FIELD_OPTIONALITY_ENCLOSED_BY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("NONE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("FUNCTIONS").to_matchable(), ]) .to_matchable(), + Ref::keyword("PROCEDURES").to_matchable(), Sequence::new(vec![ - Ref::keyword("NULL_IF").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("FUTURE").to_matchable(), + Ref::keyword("GRANTS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("VOLUMES").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PASSWORD").to_matchable(), + Ref::keyword("POLICIES").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CORTEX").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("SERVICES").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESOURCE").to_matchable(), + Ref::keyword("MONITORS").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![Ref::keyword("HISTORY").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::keyword("OF").to_matchable(), + Ref::keyword("IN").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ACCOUNT").to_matchable(), + Ref::keyword("SESSION").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("TASK").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Ref::new("ObjectReferenceSegment") + .optional() + .to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STARTS").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("PRIMARY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::new("LimitClauseSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("EMPTY_FIELD_AS_NULL").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SNAPPY_COMPRESSION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - // COPY INTO , open for extension - any_set_of(vec![]).to_matchable(), ]) .to_matchable() }) @@ -6818,44 +12270,47 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CreateExternalTableSegment".into(), - NodeMatcher::new(SyntaxKind::CreateExternalTableStatement, |_| { + "AlterAccountStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterAccountStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Ref::keyword("AS").to_matchable(), - optionally_bracketed(vec![ - Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::new("TableConstraintSegment") - .optional() - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").optional().to_matchable(), - Ref::keyword("NULL").optional().to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("ACCOUNT").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("RESOURCE_MONITOR").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Ref::keyword("PASSWORD").to_matchable(), + Ref::keyword("SESSION").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), ]) .to_matchable(), ]) @@ -6864,84 +12319,128 @@ pub fn dialect() -> Dialect { .to_matchable(), ]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - any_set_of(vec![ Sequence::new(vec![ - Ref::keyword("INTEGRATION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("UNSET").to_matchable(), + one_of(vec![ + Ref::keyword("PASSWORD").to_matchable(), + Ref::keyword("SESSION").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("POLICY").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("PARTITION").to_matchable(), - Ref::keyword("BY").to_matchable(), - Bracketed::new(vec![ + Ref::keyword("UNSET").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![ + Ref::new("TagReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), Delimited::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterUserStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterUserStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + one_of(vec![ Sequence::new(vec![ - Sequence::new(vec![Ref::keyword("WITH").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("LOCATION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("StagePath").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("REFRESH_ON_CREATE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("AUTO_REFRESH").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::keyword("RESET").to_matchable(), + Ref::keyword("PASSWORD").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("PATTERN").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("ABORT").to_matchable(), + Ref::keyword("ALL").to_matchable(), + Ref::keyword("QUERIES").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("FILE_FORMAT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("FileFormatSegment").to_matchable(), + Ref::keyword("ADD").to_matchable(), + Ref::keyword("DELEGATED").to_matchable(), + Ref::keyword("AUTHORIZATION").to_matchable(), + Ref::keyword("OF").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::keyword("SECURITY").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("AWS_SNS_TOPIC").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("REMOVE").to_matchable(), + Ref::keyword("DELEGATED").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("AUTHORIZATION").to_matchable(), + Ref::keyword("OF").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("AUTHORIZATIONS").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::keyword("SECURITY").to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("COPY").to_matchable(), - Ref::keyword("GRANTS").to_matchable(), + Ref::keyword("SET").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional_delimiter(); + }) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Sequence::new(vec![Ref::keyword("WITH").to_matchable()]) - .config(|this| this.optional()) + Ref::keyword("UNSET").to_matchable(), + Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()]) .to_matchable(), - Ref::keyword("ROW").to_matchable(), - Ref::keyword("ACCESS").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), ]) .to_matchable(), - Ref::new("TagBracketedEqualsSegment").to_matchable(), - Ref::new("CommentEqualsClauseSegment").to_matchable(), ]) .to_matchable(), ]) @@ -6950,57 +12449,37 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - snowflake_dialect.replace_grammar( - "TableExpressionSegment", - one_of(vec![ - Ref::new("BareFunctionSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable(), - Ref::new("ValuesClauseSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("StagePath").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::keyword("FILE_FORMAT").to_matchable(), - Ref::new("ParameterAssignerSegment").to_matchable(), - Ref::new("FileFormatSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("PATTERN").to_matchable(), - Ref::new("ParameterAssignerSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) + ( + "CreateRoleStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateRoleStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("AlterOrReplaceGrammar").optional().to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() .to_matchable(), - ]) - .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.add([ + .to_matchable() + }) + .to_matchable() + .into(), + ), ( - "PartitionBySegment".into(), - NodeMatcher::new(SyntaxKind::PartitionBySegment, |_| { + "CreateDatabaseRoleStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateDatabaseRoleStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("PARTITION").to_matchable(), - Ref::keyword("BY").to_matchable(), - MetaSegment::indent().to_matchable(), - optionally_bracketed(vec![ - Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::new("AlterOrReplaceGrammar").optional().to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("ROLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("DatabaseRoleReferenceSegment").to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), ]) .to_matchable() }) @@ -7008,139 +12487,116 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CopyIntoLocationStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CopyIntoLocationStatement, |_| { - Sequence::new(vec![ - Ref::keyword("COPY").to_matchable(), - Ref::keyword("INTO").to_matchable(), - Ref::new("StorageLocation").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .to_matchable(), + "ResourceMonitorOptionsSegment".into(), + NodeMatcher::new(SyntaxKind::ResourceMonitorOptions, |_dialect| { + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("CREDIT_QUOTA").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("IntegerSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), + Ref::keyword("FREQUENCY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), one_of(vec![ - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![Ref::new("SelectStatementSegment").to_matchable()]) - .to_matchable(), + Ref::keyword("MONTHLY").to_matchable(), + Ref::keyword("DAILY").to_matchable(), + Ref::keyword("WEEKLY").to_matchable(), + Ref::keyword("YEARLY").to_matchable(), + Ref::keyword("NEVER").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Ref::new("S3ExternalStageParameters").to_matchable(), - Ref::new("AzureBlobStorageExternalStageParameters").to_matchable(), - ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("InternalStageParameters") - .optional() - .to_matchable(), - any_set_of(vec![ - Ref::new("PartitionBySegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("FILE_FORMAT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("FileFormatSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("CopyOptionsSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("VALIDATION_MODE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("ValidationModeOptionSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("HEADER").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("START_TIMESTAMP").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("IMMEDIATELY").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "CopyIntoTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CopyIntoTableStatement, |_| { - Sequence::new(vec![ - Ref::keyword("COPY").to_matchable(), - Ref::keyword("INTO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .to_matchable(), + Sequence::new(vec![ + Ref::keyword("END_TIMESTAMP").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - one_of(vec![ - Ref::new("StorageLocation").to_matchable(), - Bracketed::new(vec![Ref::new("SelectStatementSegment").to_matchable()]) + Ref::keyword("NOTIFY_USERS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) .to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Ref::new("S3ExternalStageParameters").to_matchable(), - Ref::new("AzureBlobStorageExternalStageParameters").to_matchable(), - ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("InternalStageParameters") - .optional() - .to_matchable(), - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("FILES").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TRIGGERS").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::new("IntegerSegment").to_matchable(), + Ref::keyword("PERCENT").to_matchable(), + Ref::keyword("DO").to_matchable(), + one_of(vec![ + Ref::keyword("SUSPEND").to_matchable(), + Ref::keyword("SUSPEND_IMMEDIATE").to_matchable(), + Ref::keyword("NOTIFY").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("PATTERN").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("ReferencedVariableNameSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FILE_FORMAT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("FileFormatSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("CopyOptionsSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateResourceMonitorStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateResourceMonitorStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), Sequence::new(vec![ - Ref::keyword("VALIDATION_MODE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("ValidationModeOptionSegment").to_matchable(), + Ref::keyword("RESOURCE").to_matchable(), + Ref::keyword("MONITOR").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("ResourceMonitorOptionsSegment").to_matchable(), ]) .to_matchable() }) @@ -7148,13 +12604,19 @@ pub fn dialect() -> Dialect { .into(), ), ( - "StorageLocation".into(), - NodeMatcher::new(SyntaxKind::StorageLocation, |_| { - one_of(vec![ - Ref::new("StagePath").to_matchable(), - Ref::new("S3Path").to_matchable(), - Ref::new("GCSPath").to_matchable(), - Ref::new("AzureBlobStoragePath").to_matchable(), + "AlterResourceMonitorStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterResourceMonitorStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESOURCE").to_matchable(), + Ref::keyword("MONITOR").to_matchable(), + ]) + .to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("ResourceMonitorOptionsSegment").to_matchable(), ]) .to_matchable() }) @@ -7162,21 +12624,17 @@ pub fn dialect() -> Dialect { .into(), ), ( - "InternalStageParameters".into(), - NodeMatcher::new(SyntaxKind::StageParameters, |_| { + "DropResourceMonitorStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropResourceMonitorStatement, |_dialect| { Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), Sequence::new(vec![ - Ref::keyword("ENCRYPTION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("SnowflakeEncryptionOption").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("RESOURCE").to_matchable(), + Ref::keyword("MONITOR").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable() }) @@ -7184,101 +12642,29 @@ pub fn dialect() -> Dialect { .into(), ), ( - "S3ExternalStageParameters".into(), - NodeMatcher::new(SyntaxKind::S3ExternalStageParameters, |_| { + "ExplainStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ExplainStatement, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("STORAGE_INTEGRATION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CREDENTIALS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("AWS_KEY_ID").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::keyword("AWS_SECRET_KEY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("AWS_TOKEN").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("AWS_ROLE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("EXPLAIN").to_matchable(), Sequence::new(vec![ - Ref::keyword("ENCRYPTION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - one_of(vec![ - Sequence::new(vec![ - Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("S3EncryptionOption").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("MASTER_KEY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("S3EncryptionOption").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("S3EncryptionOption").to_matchable(), - Sequence::new(vec![ - Ref::keyword("KMS_KEY_ID").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::keyword("NONE").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("USING").to_matchable(), + one_of(vec![ + Ref::keyword("TABULAR").to_matchable(), + Ref::keyword("JSON").to_matchable(), + Ref::keyword("TEXT").to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Ref::new("SelectableGrammar").to_matchable(), + Ref::new("InsertStatementSegment").to_matchable(), + Ref::new("UpdateStatementSegment").to_matchable(), + Ref::new("DeleteStatementSegment").to_matchable(), + ]) .to_matchable(), ]) .to_matchable() @@ -7287,44 +12673,15 @@ pub fn dialect() -> Dialect { .into(), ), ( - "GCSExternalStageParameters".into(), - NodeMatcher::new(SyntaxKind::GcsExternalStageParameters, |_| { + "AlterSessionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterSessionStatement, |_dialect| { Sequence::new(vec![ - Sequence::new(vec![ - Ref::keyword("STORAGE_INTEGRATION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ENCRYPTION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::new("GCSEncryptionOption").to_matchable(), - Sequence::new(vec![ - Ref::keyword("KMS_KEY_ID").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("NONE").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("SESSION").to_matchable(), + one_of(vec![ + Ref::new("AlterSessionSetClauseSegment").to_matchable(), + Ref::new("AlterSessionUnsetClauseSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable() @@ -7333,62 +12690,31 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AzureBlobStorageExternalStageParameters".into(), - NodeMatcher::new(SyntaxKind::AzureBlobStorageExternalStageParameters, |_| { + "AlterSessionSetClauseSegment".into(), + NodeMatcher::new(SyntaxKind::AlterSessionSetStatement, |_dialect| { Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), one_of(vec![ - Sequence::new(vec![ - Ref::keyword("STORAGE_INTEGRATION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("CREDENTIALS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Sequence::new(vec![ - Ref::keyword("AZURE_SAS_TOKEN").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ENCRYPTION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::new("AzureBlobStorageEncryptionOption").to_matchable(), - Sequence::new(vec![ - Ref::keyword("MASTER_KEY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("NONE").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterSessionUnsetClauseSegment".into(), + NodeMatcher::new(SyntaxKind::AlterSessionUnsetClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), ]) .to_matchable() }) @@ -7396,193 +12722,53 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CreateStageSegment".into(), - NodeMatcher::new(SyntaxKind::CreateStageStatement, |_| { + "AlterTaskStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTaskStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("TEMPORARY").optional().to_matchable(), - Ref::keyword("STAGE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("TASK").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), - MetaSegment::indent().to_matchable(), one_of(vec![ - // Internal stages + Ref::keyword("RESUME").to_matchable(), + Ref::keyword("SUSPEND").to_matchable(), Sequence::new(vec![ - Ref::new("InternalStageParameters") - .optional() - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DIRECTORY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Sequence::new(vec![ - Ref::keyword("ENABLE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - ]) + Ref::keyword("REMOVE").to_matchable(), + Ref::keyword("AFTER").to_matchable(), + Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), ]) .to_matchable(), - // External S3 stage Sequence::new(vec![ - Ref::keyword("URL").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("S3Path").to_matchable(), - Ref::new("S3ExternalStageParameters") - .optional() - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DIRECTORY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Sequence::new(vec![ - Ref::keyword("ENABLE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("AUTO_REFRESH").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) + Ref::keyword("ADD").to_matchable(), + Ref::keyword("AFTER").to_matchable(), + Delimited::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), ]) .to_matchable(), - // External GCS stage + Ref::new("AlterTaskSpecialSetClauseSegment").to_matchable(), + Ref::new("AlterTaskSetClauseSegment").to_matchable(), + Ref::new("AlterTaskUnsetClauseSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("URL").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("GCSPath").to_matchable(), - Ref::new("GCSExternalStageParameters") - .optional() - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DIRECTORY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Sequence::new(vec![ - Ref::keyword("ENABLE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("AUTO_REFRESH").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOTIFICATION_INTEGRATION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("MODIFY").to_matchable(), + Ref::keyword("AS").to_matchable(), + one_of(vec![ + Ref::new("SelectableGrammar").to_matchable(), + Ref::new("InsertStatementSegment").to_matchable(), + Ref::new("UpdateStatementSegment").to_matchable(), + Ref::new("DeleteStatementSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), - // External Azure Blob Storage stage Sequence::new(vec![ - Ref::keyword("URL").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("AzureBlobStoragePath").to_matchable(), - Ref::new("AzureBlobStorageExternalStageParameters") - .optional() - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DIRECTORY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Sequence::new(vec![ - Ref::keyword("ENABLE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("AUTO_REFRESH").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOTIFICATION_INTEGRATION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FILE_FORMAT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("FileFormatSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COPY_OPTIONS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![Ref::new("CopyOptionsSegment").to_matchable()]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("TagBracketedEqualsSegment") - .optional() - .to_matchable(), - Ref::new("CommentEqualsClauseSegment") - .optional() + Ref::keyword("MODIFY").to_matchable(), + Ref::keyword("WHEN").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + ]) .to_matchable(), - MetaSegment::dedent().to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) @@ -7590,114 +12776,43 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterStageSegment".into(), - NodeMatcher::new(SyntaxKind::AlterStageStatement, |_| { + "AlterTaskSpecialSetClauseSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTaskSpecialSetClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("STAGE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - one_of(vec![ + Ref::keyword("SET").to_matchable(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::new("InternalStageParameters").to_matchable(), - Sequence::new(vec![ - Sequence::new(vec![ - Ref::keyword("URL").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("S3Path").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("S3ExternalStageParameters") - .optional() - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Sequence::new(vec![ - Ref::keyword("URL").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("GCSPath").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("GCSExternalStageParameters") - .optional() - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Sequence::new(vec![ - Ref::keyword("URL").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("AzureBlobStoragePath").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("AzureBlobStorageExternalStageParameters") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FILE_FORMAT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("FileFormatSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COPY_OPTIONS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Ref::new("CopyOptionsSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("CommentEqualsClauseSegment") - .optional() - .to_matchable(), - ]) - .to_matchable(), - Ref::new("TagEqualsSegment").to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), + Ref::keyword("SCHEDULE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("REFRESH").to_matchable(), - Sequence::new(vec![ - Ref::keyword("SUBPATH").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("ALLOW_OVERLAPPING_EXECUTION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + this.min_times(1); + }) .to_matchable(), ]) .to_matchable() @@ -7706,80 +12821,163 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CreateStreamStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateStreamStatement, |_| { + "AlterTaskSetClauseSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTaskSetClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::keyword("STREAM").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("COPY").to_matchable(), - Ref::keyword("GRANTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("ON").to_matchable(), - one_of(vec![ + Ref::keyword("SET").to_matchable(), + Delimited::new(vec![ Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), one_of(vec![ - Ref::keyword("TABLE").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - ]) - .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - one_of(vec![ - Ref::new("FromAtExpressionSegment").to_matchable(), - Ref::new("FromBeforeExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("APPEND_ONLY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SHOW_INITIAL_ROWS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterTaskUnsetClauseSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTaskUnsetClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ExecuteImmediateClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ExecuteImmediateClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("EXECUTE").to_matchable(), + Ref::keyword("IMMEDIATE").to_matchable(), + Ref::keyword("FROM").optional().to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + Ref::new("StorageLocation").to_matchable(), Sequence::new(vec![ - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - one_of(vec![ - Ref::new("FromAtExpressionSegment").to_matchable(), - Ref::new("FromBeforeExpressionSegment").to_matchable(), + Ref::new("ColonPrefixSegment").to_matchable(), + Ref::new("LocalVariableNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("LocalVariableNameSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ExecuteTaskClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ExecuteTaskClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("EXECUTE").to_matchable(), + Ref::keyword("TASK").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MergeUpdateClauseSegment".into(), + NodeMatcher::new(SyntaxKind::MergeUpdateClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("UPDATE").to_matchable(), + Ref::new("SetClauseListSegment").to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MergeDeleteClauseSegment".into(), + NodeMatcher::new(SyntaxKind::MergeDeleteClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DELETE").to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MergeInsertClauseSegment".into(), + NodeMatcher::new(SyntaxKind::MergeInsertClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("INSERT").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::new("ValuesClauseSegment").optional().to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DeleteStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DeleteStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ Sequence::new(vec![ - Ref::keyword("INSERT_ONLY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("TrueSegment").to_matchable(), + Ref::new("TableExpressionSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("STAGE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("CommentEqualsClauseSegment") - .optional() - .to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), ]) .to_matchable() }) @@ -7787,405 +12985,228 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterStreamStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterStreamStatement, |_| { + "DescribeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DescribeStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("STREAM").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ + Ref::keyword("DESCRIBE").to_matchable(), + Ref::keyword("DESC").to_matchable(), + ]) + .to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Sequence::new(vec![ - Ref::keyword("APPEND_ONLY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::keyword("RESULT").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("LAST_QUERY_ID").to_matchable(), + Bracketed::new(vec![]).to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NETWORK").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SHARE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("INSERT_ONLY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("TrueSegment").to_matchable(), + Ref::new("DotSegment").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("TagEqualsSegment").optional().to_matchable(), - Ref::new("CommentEqualsClauseSegment") - .optional() - .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ one_of(vec![ - Sequence::new(vec![ - Ref::keyword("TAG").to_matchable(), - Delimited::new(vec![ - Ref::new("TagReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("API").to_matchable(), + Ref::keyword("NOTIFICATION").to_matchable(), + Ref::keyword("SECURITY").to_matchable(), + Ref::keyword("STORAGE").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - // `ALTER ACCOUNT` statement. - // https://docs.snowflake.com/en/sql-reference/sql/alter-account - "AlterAccountStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("ACCOUNT").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("RESOURCE_MONITOR").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - one_of(vec![ - Ref::keyword("PASSWORD").to_matchable(), + Sequence::new(vec![ Ref::keyword("SESSION").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("TagEqualsSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), + Ref::keyword("TYPE").to_matchable(), Ref::new("EqualsSegment").to_matchable(), one_of(vec![ - Ref::new("BooleanLiteralGrammar").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::keyword("COLUMNS").to_matchable(), + Ref::keyword("STAGE").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - one_of(vec![ - Ref::keyword("PASSWORD").to_matchable(), - Ref::keyword("SESSION").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("POLICY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - one_of(vec![ + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("TAG").to_matchable(), - Delimited::new(vec![ - Ref::new("TagReferenceSegment").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("COLUMNS").to_matchable(), + Ref::keyword("STAGE").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Delimited::new(vec![Ref::new("NakedIdentifierSegment").to_matchable()]) - .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "ShowStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ShowStatement, |_| { - let object_types_plural = one_of(vec![ - Ref::keyword("PARAMETERS").to_matchable(), - Sequence::new(vec![ - Ref::keyword("GLOBAL").to_matchable(), - Ref::keyword("ACCOUNTS").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("REGIONS").to_matchable(), - Sequence::new(vec![ - Ref::keyword("REPLICATION").to_matchable(), - Ref::keyword("ACCOUNTS").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("REPLICATION").to_matchable(), - Ref::keyword("DATABASES").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("PARAMETERS").to_matchable(), - Ref::keyword("VARIABLES").to_matchable(), - Ref::keyword("TRANSACTIONS").to_matchable(), - Ref::keyword("LOCKS").to_matchable(), - Ref::keyword("PARAMETERS").to_matchable(), - Ref::keyword("FUNCTIONS").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NETWORK").to_matchable(), - Ref::keyword("POLICIES").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("SHARES").to_matchable(), - Ref::keyword("ROLES").to_matchable(), - Ref::keyword("GRANTS").to_matchable(), - Ref::keyword("USERS").to_matchable(), - Ref::keyword("WAREHOUSES").to_matchable(), - Ref::keyword("DATABASES").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("API").to_matchable(), - Ref::keyword("NOTIFICATION").to_matchable(), - Ref::keyword("SECURITY").to_matchable(), - Ref::keyword("STORAGE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("VOLUME").to_matchable(), + Ref::new("ExternalVolumeReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::keyword("INTEGRATIONS").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("SCHEMAS").to_matchable(), - Ref::keyword("OBJECTS").to_matchable(), - Ref::keyword("TABLES").to_matchable(), - Sequence::new(vec![ - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("TABLES").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("VIEWS").to_matchable(), - Sequence::new(vec![ - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEWS").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICIES").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("COLUMNS").to_matchable(), - Sequence::new(vec![ - Ref::keyword("FILE").to_matchable(), - Ref::keyword("FORMATS").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("SEQUENCES").to_matchable(), - Ref::keyword("STAGES").to_matchable(), - Ref::keyword("PIPES").to_matchable(), - Ref::keyword("STREAMS").to_matchable(), - Ref::keyword("TASKS").to_matchable(), - Sequence::new(vec![ - Ref::keyword("USER").to_matchable(), - Ref::keyword("FUNCTIONS").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("FUNCTIONS").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("PROCEDURES").to_matchable(), - Sequence::new(vec![ - Ref::keyword("FUTURE").to_matchable(), - Ref::keyword("GRANTS").to_matchable(), - ]) - .to_matchable(), - ]); - - let object_scope_types = one_of(vec![ - Ref::keyword("ACCOUNT").to_matchable(), - Ref::keyword("SESSION").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::keyword("SHARE").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::keyword("TASK").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::keyword("WAREHOUSE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("VIEW").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), Ref::keyword("VIEW").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), ]) .to_matchable(), - Ref::new("ObjectReferenceSegment").optional().to_matchable(), - ]) - .to_matchable(), - ]); - - Sequence::new(vec![ - Ref::keyword("SHOW").to_matchable(), - Ref::keyword("TERSE").optional().to_matchable(), - object_types_plural.to_matchable(), - Ref::keyword("HISTORY").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("LIKE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::keyword("OF").to_matchable(), - Ref::keyword("IN").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SEQUENCE").to_matchable(), + Ref::new("SequenceReferenceSegment").to_matchable(), ]) .to_matchable(), - one_of(vec![ - Sequence::new(vec![object_scope_types.to_matchable()]).to_matchable(), + Sequence::new(vec![ + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("STARTS").to_matchable(), - Ref::keyword("WITH").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("PRIMARY").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::new("LimitClauseSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "AlterUserStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterUserStatement, |_| { - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("USER").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - one_of(vec![ Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMAT").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("RESET").to_matchable(), - Ref::keyword("PASSWORD").to_matchable(), + Ref::keyword("STAGE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("ABORT").to_matchable(), - Ref::keyword("ALL").to_matchable(), - Ref::keyword("QUERIES").to_matchable(), + Ref::keyword("PIPE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("DELEGATED").to_matchable(), - Ref::keyword("AUTHORIZATION").to_matchable(), - Ref::keyword("OF").to_matchable(), - Ref::keyword("ROLE").to_matchable(), + Ref::keyword("STREAM").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::keyword("SECURITY").to_matchable(), - Ref::keyword("INTEGRATION").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("STREAMLIT").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("REMOVE").to_matchable(), - Ref::keyword("DELEGATED").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("AUTHORIZATION").to_matchable(), - Ref::keyword("OF").to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("AUTHORIZATIONS").to_matchable(), + Ref::keyword("TASK").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::keyword("SECURITY").to_matchable(), - Ref::keyword("INTEGRATION").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) + Ref::keyword("PROCEDURE").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()]) - .to_matchable(), + Ref::keyword("PASSWORD").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("PasswordPolicyReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CORTEX").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("SERVICE").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), ]) @@ -8196,68 +13217,122 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - snowflake_dialect.replace_grammar( - "CreateRoleStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("ROLE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("RoleReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.replace_grammar( - "ExplainStatementSegment", - Sequence::new(vec![ - Ref::keyword("EXPLAIN").to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), + ( + "TransactionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::TransactionStatement, |_dialect| { one_of(vec![ - Ref::keyword("TABULAR").to_matchable(), - Ref::keyword("JSON").to_matchable(), - Ref::keyword("TEXT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("BEGIN").to_matchable(), + one_of(vec![ + Ref::keyword("WORK").to_matchable(), + Ref::keyword("TRANSACTION").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NAME").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("START").to_matchable(), + Ref::keyword("TRANSACTION").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NAME").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COMMIT").to_matchable(), + Sequence::new(vec![Ref::keyword("WORK").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("ROLLBACK").to_matchable(), ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ansi::explainable_stmt().to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.add([ + .to_matchable() + }) + .to_matchable() + .into(), + ), ( - "AlterSessionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterSessionStatement, |_| { + "TruncateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::TruncateStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("SESSION").to_matchable(), + Ref::keyword("TRUNCATE").to_matchable(), + Ref::keyword("TABLE").optional().to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UnsetStatementSegment".into(), + NodeMatcher::new(SyntaxKind::UnsetStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), one_of(vec![ - Ref::new("AlterSessionSetClauseSegment").to_matchable(), - Ref::new("AlterSessionUnsetClauseSegment").to_matchable(), + Ref::new("LocalVariableNameSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("LocalVariableNameSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UndropStatementSegment".into(), + NodeMatcher::new(SyntaxKind::UndropStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("UNDROP").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SCHEMA").to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("VOLUME").to_matchable(), + Ref::new("ExternalVolumeReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -8267,18 +13342,81 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterSessionSetClauseSegment".into(), - NodeMatcher::new(SyntaxKind::AlterSessionSetStatement, |_| { + "CommentStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CommentStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::keyword("ON").to_matchable(), one_of(vec![ - Ref::new("BooleanLiteralGrammar").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("WAREHOUSE").to_matchable(), + Ref::keyword("USER").to_matchable(), + Ref::keyword("STAGE").to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::keyword("SHARE").to_matchable(), + Ref::keyword("PIPE").to_matchable(), + Ref::keyword("STREAM").to_matchable(), + Ref::keyword("STREAMLIT").to_matchable(), + Ref::keyword("TASK").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NETWORK").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("API").to_matchable(), + Ref::keyword("NOTIFICATION").to_matchable(), + Ref::keyword("SECURITY").to_matchable(), + Ref::keyword("STORAGE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SESSION").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMAT").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("IS").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable() }) @@ -8286,59 +13424,39 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterSessionUnsetClauseSegment".into(), - NodeMatcher::new(SyntaxKind::AlterSessionUnsetClause, |_| { - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "AlterTaskStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterTaskStatement, |_| { + "UseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::UseStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("TASK").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("USE").to_matchable(), one_of(vec![ - Ref::keyword("RESUME").to_matchable(), - Ref::keyword("SUSPEND").to_matchable(), Sequence::new(vec![ - Ref::keyword("REMOVE").to_matchable(), - Ref::keyword("AFTER").to_matchable(), + Ref::keyword("ROLE").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("AFTER").to_matchable(), + Ref::keyword("WAREHOUSE").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), - Ref::new("AlterTaskSpecialSetClauseSegment").to_matchable(), - Ref::new("AlterTaskSetClauseSegment").to_matchable(), - Ref::new("AlterTaskUnsetClauseSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("MODIFY").to_matchable(), - Ref::keyword("AS").to_matchable(), - ansi::explainable_stmt().to_matchable(), + Ref::keyword("DATABASE").optional().to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("MODIFY").to_matchable(), - Ref::keyword("WHEN").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::keyword("SCHEMA").optional().to_matchable(), + Ref::new("SchemaReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SECONDARY").to_matchable(), + Ref::keyword("ROLES").to_matchable(), + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("NONE").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -8350,34 +13468,83 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterTaskSpecialSetClauseSegment".into(), - NodeMatcher::new(SyntaxKind::AlterTaskSpecialSetClause, |_| { + "CallStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CallStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - any_set_of(vec![ + Ref::keyword("CALL").to_matchable(), + Sequence::new(vec![ + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionContentsSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "LimitClauseSegment".into(), + NodeMatcher::new(SyntaxKind::LimitClause, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("LIMIT").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("LimitLiteralGrammar").to_matchable(), + MetaSegment::dedent().to_matchable(), Sequence::new(vec![ - Ref::keyword("WAREHOUSE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("LimitLiteralGrammar").to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ Sequence::new(vec![ - Ref::keyword("SCHEDULE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("OFFSET").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("LimitLiteralGrammar").to_matchable(), + one_of(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ROWS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ALLOW_OVERLAPPING_EXECUTION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::keyword("FETCH").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("NEXT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("LimitLiteralGrammar").to_matchable(), + one_of(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ROWS").to_matchable(), ]) - .config(|this| this.optional()) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::keyword("ONLY").optional().to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .config(|this| this.min_times(1)) .to_matchable(), ]) .to_matchable() @@ -8386,24 +13553,52 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterTaskSetClauseSegment".into(), - NodeMatcher::new(SyntaxKind::AlterTaskSetClause, |_| { + "OrderByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::OrderbyClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), Delimited::new(vec![ Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), one_of(vec![ Ref::new("BooleanLiteralGrammar").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("ASC").to_matchable(), + Ref::keyword("DESC").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULLS").to_matchable(), + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("LAST").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.terminators = vec![ + Ref::new("LimitClauseSegment").to_matchable(), + Ref::new("FrameClauseUnitGrammar").to_matchable(), + ]; + }) .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) @@ -8411,47 +13606,98 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterTaskUnsetClauseSegment".into(), - NodeMatcher::new(SyntaxKind::AlterTaskUnsetClause, |_| { - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - //Snowflake's EXECUTE IMMEDIATE clause. - // https://docs.snowflake.com/en/sql-reference/sql/execute-immediate - "ExecuteImmediateClauseSegment".into(), - NodeMatcher::new(SyntaxKind::ExecuteImmediateClause, |_| { + "FrameClauseSegment".into(), + NodeMatcher::new(SyntaxKind::FrameClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("EXECUTE").to_matchable(), - Ref::keyword("IMMEDIATE").to_matchable(), + Ref::new("FrameClauseUnitGrammar").to_matchable(), one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("ReferencedVariableNameSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("ColonSegment").to_matchable(), - Ref::new("LocalVariableNameSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("INTERVAL").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("LocalVariableNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("BETWEEN").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("INTERVAL").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("AND").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("INTERVAL").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) .to_matchable() @@ -8460,12 +13706,14 @@ pub fn dialect() -> Dialect { .into(), ), ( - "ExecuteTaskClauseSegment".into(), - NodeMatcher::new(SyntaxKind::ExecuteTaskClause, |_| { + "DropProcedureStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropProcedureStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("EXECUTE").to_matchable(), - Ref::keyword("TASK").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("PROCEDURE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar").to_matchable(), ]) .to_matchable() }) @@ -8473,45 +13721,15 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CreateSequenceStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateSequenceStatement, |_| { + "DropExternalTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropExternalTableStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("SEQUENCE").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("SequenceReferenceSegment").to_matchable(), - Ref::keyword("WITH").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("START").to_matchable(), - Ref::keyword("WITH").optional().to_matchable(), - Ref::new("EqualsSegment").optional().to_matchable(), - Ref::new("IntegerSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INCREMENT").to_matchable(), - Ref::keyword("BY").optional().to_matchable(), - Ref::new("EqualsSegment").optional().to_matchable(), - Ref::new("IntegerSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("NOORDER").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("CommentEqualsClauseSegment") - .optional() - .to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("EXTERNAL").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -8519,115 +13737,30 @@ pub fn dialect() -> Dialect { .into(), ), ( - "AlterSequenceStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterSequenceStatement, |_| { + "DropFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("SEQUENCE").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("EXTERNAL").optional().to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SequenceReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").optional().to_matchable(), - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("INCREMENT").to_matchable(), - Ref::keyword("BY").optional().to_matchable(), - Ref::new("EqualsSegment").optional().to_matchable(), - Ref::new("IntegerSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("NOORDER").to_matchable(), - ]) - .to_matchable(), - Ref::new("CommentEqualsClauseSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Ref::keyword("COMMENT").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("SequenceReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Ref::new("FunctionParameterListGrammar").to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - snowflake_dialect.replace_grammar( - "MergeUpdateClauseSegment", - Sequence::new(vec![ - Ref::keyword("UPDATE").to_matchable(), - Ref::new("SetClauseListSegment").to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.replace_grammar( - "MergeDeleteClauseSegment", - Sequence::new(vec![ - Ref::keyword("DELETE").to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.replace_grammar( - "MergeInsertClauseSegment", - Sequence::new(vec![ - Ref::keyword("INSERT").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - MetaSegment::dedent().to_matchable(), - Ref::new("ValuesClauseSegment").optional().to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.add([ ( - "DeleteStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DeleteStatement, |_| { + "DropMaterializedViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropMaterializedViewStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("DELETE").to_matchable(), - Ref::keyword("FROM").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("MATERIALIZED").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - MetaSegment::indent().to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("TableExpressionSegment").to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), ]) .to_matchable() }) @@ -8635,192 +13768,119 @@ pub fn dialect() -> Dialect { .into(), ), ( - "DescribeStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DescribeStatement, |_| { + "DropObjectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropObjectStatement, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DESCRIBE").to_matchable(), - Ref::keyword("DESC").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("DROP").to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::keyword("RESULT").to_matchable(), one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("CONNECTION").to_matchable(), Sequence::new(vec![ - Ref::keyword("LAST_QUERY_ID").to_matchable(), - Bracketed::new(vec![]).to_matchable(), + Ref::keyword("CORTEX").to_matchable(), + Ref::keyword("SEARCH").to_matchable(), + Ref::keyword("SERVICE").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NETWORK").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SHARE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("DotSegment").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("USER").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WAREHOUSE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DATABASE").to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("API").to_matchable(), - Ref::keyword("NOTIFICATION").to_matchable(), - Ref::keyword("SECURITY").to_matchable(), - Ref::keyword("STORAGE").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("INTEGRATION").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SESSION").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TABLE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("COLUMNS").to_matchable(), - Ref::keyword("STAGE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("FILE").to_matchable(), + Ref::keyword("FORMAT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("API").to_matchable(), + Ref::keyword("NOTIFICATION").to_matchable(), + Ref::keyword("SECURITY").to_matchable(), + Ref::keyword("STORAGE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("INTEGRATION").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("PIPE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), ]) .to_matchable(), + Ref::keyword("STAGE").to_matchable(), + Ref::keyword("STREAM").to_matchable(), + Ref::keyword("STREAMLIT").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Ref::keyword("TASK").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("TYPE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("COLUMNS").to_matchable(), - Ref::keyword("STAGE").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RESOURCE").to_matchable(), + Ref::keyword("MONITOR").to_matchable(), ]) .to_matchable(), + Ref::keyword("SHARE").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("VIEW").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SEQUENCE").to_matchable(), - Ref::new("SequenceReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ROW").to_matchable(), - Ref::keyword("ACCESS").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FILE").to_matchable(), - Ref::keyword("FORMAT").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("STAGE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("PIPE").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("STREAM").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("MANAGED").to_matchable(), + Ref::keyword("ACCOUNT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("TASK").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("NETWORK").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("FUNCTION").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), + one_of(vec![ + Ref::keyword("WAREHOUSE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("SESSION").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("PROCEDURE").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("DatatypeSegment").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("SEQUENCE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable(), ]) @@ -8831,109 +13891,24 @@ pub fn dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - snowflake_dialect.replace_grammar( - "TransactionStatementSegment", - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("BEGIN").to_matchable(), - one_of(vec![ - Ref::keyword("WORK").to_matchable(), - Ref::keyword("TRANSACTION").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NAME").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("START").to_matchable(), - Ref::keyword("TRANSACTION").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NAME").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COMMIT").to_matchable(), - Ref::keyword("WORK").optional().to_matchable(), - ]) - .to_matchable(), - Ref::keyword("ROLLBACK").to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.replace_grammar( - "TruncateStatementSegment", - Sequence::new(vec![ - Ref::keyword("TRUNCATE").to_matchable(), - Ref::keyword("TABLE").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.add([ ( - "UnsetStatementSegment".into(), - NodeMatcher::new(SyntaxKind::UnsetStatement, |_| { + "ListStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ListStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), one_of(vec![ - Ref::new("LocalVariableNameSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("LocalVariableNameSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("LIST").to_matchable(), + Ref::keyword("LS").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "UndropStatementSegment".into(), - NodeMatcher::new(SyntaxKind::UndropStatement, |_| { - Sequence::new(vec![ - Ref::keyword("UNDROP").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("DATABASE").to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SCHEMA").to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TABLE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), + Ref::new("StagePath").to_matchable(), + Sequence::new(vec![ + Ref::keyword("PATTERN").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -8942,325 +13917,301 @@ pub fn dialect() -> Dialect { .into(), ), ( - "CommentStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CommentStatement, |_| { + "GetStatementSegment".into(), + NodeMatcher::new(SyntaxKind::GetStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IF").to_matchable(), - Ref::keyword("EXISTS").to_matchable(), + Ref::keyword("GET").to_matchable(), + Ref::new("StagePath").to_matchable(), + one_of(vec![ + Ref::new("UnquotedFilePath").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::keyword("ON").to_matchable(), - one_of(vec![ - Ref::keyword("COLUMN").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("WAREHOUSE").to_matchable(), - Ref::keyword("USER").to_matchable(), - Ref::keyword("STAGE").to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Ref::keyword("PROCEDURE").to_matchable(), - Ref::keyword("SEQUENCE").to_matchable(), - Ref::keyword("SHARE").to_matchable(), - Ref::keyword("PIPE").to_matchable(), - Ref::keyword("STREAM").to_matchable(), - Ref::keyword("TASK").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NETWORK").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("API").to_matchable(), - Ref::keyword("NOTIFICATION").to_matchable(), - Ref::keyword("SECURITY").to_matchable(), - Ref::keyword("STORAGE").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("INTEGRATION").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SESSION").to_matchable(), - Ref::keyword("POLICY").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("PARALLEL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("IntegerSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("TABLE").to_matchable(), + Ref::keyword("PATTERN").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "PutStatementSegment".into(), + NodeMatcher::new(SyntaxKind::PutStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("PUT").to_matchable(), + one_of(vec![ + Ref::new("UnquotedFilePath").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("StagePath").to_matchable(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), + Ref::keyword("PARALLEL").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("IntegerSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), + Ref::keyword("AUTO_COMPRESS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("ROW").to_matchable(), - Ref::keyword("ACCESS").to_matchable(), - Ref::keyword("POLICY").to_matchable(), + Ref::keyword("SOURCE_COMPRESSION").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("CompressionType").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("FILE").to_matchable(), - Ref::keyword("FORMAT").to_matchable(), + Ref::keyword("OVERWRITE").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("IS").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - snowflake_dialect.replace_grammar( - "UseStatementSegment", - Sequence::new(vec![ - Ref::keyword("USE").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("ROLE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WAREHOUSE").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DATABASE").optional().to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SCHEMA").optional().to_matchable(), - Ref::new("SchemaReferenceSegment").to_matchable(), - ]) - .to_matchable(), + ( + "RemoveStatementSegment".into(), + NodeMatcher::new(SyntaxKind::RemoveStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("SECONDARY").to_matchable(), - Ref::keyword("ROLES").to_matchable(), one_of(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("NONE").to_matchable(), + Ref::keyword("REMOVE").to_matchable(), + Ref::keyword("RM").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.add([( - "CallStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CallStatement, |_| { - Sequence::new(vec![ - Ref::keyword("CALL").to_matchable(), - Sequence::new(vec![ - Ref::new("FunctionNameSegment").to_matchable(), - Bracketed::new(vec![ - Ref::new("FunctionContentsGrammar") - .optional() - .to_matchable(), + Ref::new("StagePath").to_matchable(), + Sequence::new(vec![ + Ref::keyword("PATTERN").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ReferencedVariableNameSegment").to_matchable(), + ]) + .to_matchable(), ]) - .config(|this| this.parse_mode(ParseMode::Greedy)) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - snowflake_dialect.replace_grammar( - "LimitClauseSegment", - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("LIMIT").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("LimitLiteralGrammar").to_matchable(), - MetaSegment::dedent().to_matchable(), - Sequence::new(vec![ - Ref::keyword("OFFSET").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("LimitLiteralGrammar").to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Sequence::new(vec![ - Ref::keyword("OFFSET").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("LimitLiteralGrammar").to_matchable(), - one_of(vec![ - Ref::keyword("ROW").to_matchable(), - Ref::keyword("ROWS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("FETCH").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("NEXT").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::new("LimitLiteralGrammar").to_matchable(), - one_of(vec![ - Ref::keyword("ROW").to_matchable(), - Ref::keyword("ROWS").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - Ref::keyword("ONLY").optional().to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.replace_grammar( - "SelectClauseSegment", - ansi::select_clause_segment().copy( - None, - None, - None, - None, - vec![ - Ref::keyword("FETCH").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - ], - false, + .into(), ), - ); - - snowflake_dialect.replace_grammar( - "OrderByClauseSegment", - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - MetaSegment::indent().to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("ASC").to_matchable(), - Ref::keyword("DESC").to_matchable(), + ( + "SetOperatorSegment".into(), + NodeMatcher::new(SyntaxKind::SetOperator, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("UNION").to_matchable(), + one_of(vec![ + Ref::keyword("DISTINCT").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BY").to_matchable(), + Ref::keyword("NAME").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), Sequence::new(vec![ - Ref::keyword("NULLS").to_matchable(), one_of(vec![ - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("LAST").to_matchable(), + Ref::keyword("INTERSECT").to_matchable(), + Ref::keyword("EXCEPT").to_matchable(), ]) .to_matchable(), + Ref::keyword("ALL").optional().to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), + Ref::keyword("MINUS").to_matchable(), ]) - .to_matchable(), - ]) - .config(|this| { - this.terminators = vec![ - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("FETCH").to_matchable(), - Ref::keyword("OFFSET").to_matchable(), - Ref::new("FrameClauseUnitGrammar").to_matchable(), - ] + .to_matchable() }) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.replace_grammar("FrameClauseSegment", { - let frame_extent = one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CURRENT").to_matchable(), - Ref::keyword("ROW").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ReferencedVariableNameSegment").to_matchable(), - Ref::keyword("UNBOUNDED").to_matchable(), + .to_matchable() + .into(), + ), + ( + "ArrayTypeSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayType, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ARRAY").to_matchable(), + Ref::new("ArrayTypeSchemaSegment").optional().to_matchable(), ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("PRECEDING").to_matchable(), - Ref::keyword("FOLLOWING").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ArrayTypeSchemaSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayTypeSchema, |_dialect| { + Bracketed::new(vec![ + Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - ]); - - Sequence::new(vec![ - Ref::new("FrameClauseUnitGrammar").to_matchable(), - one_of(vec![ - frame_extent.clone().to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ShorthandCastSegment".into(), + NodeMatcher::new(SyntaxKind::CastExpression, |_dialect| { Sequence::new(vec![ - Ref::keyword("BETWEEN").to_matchable(), - frame_extent.clone().to_matchable(), - Ref::keyword("AND").to_matchable(), - frame_extent.to_matchable(), + one_of(vec![ + Ref::new("Expression_D_Grammar").to_matchable(), + Ref::new("CaseExpressionSegment").to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("CastOperatorSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + one_of(vec![ + Ref::new("TimeZoneGrammar").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("ArrayAccessorSegment").to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("SemiStructuredAccessorSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - }); - - snowflake_dialect.add([ + .to_matchable() + }) + .to_matchable() + .into(), + ), ( - "DropProcedureStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropProcedureStatement, |_| { + "AlterDatabaseSegment".into(), + NodeMatcher::new(SyntaxKind::AlterDatabaseStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("PROCEDURE").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("DATABASE").to_matchable(), Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SWAP").to_matchable(), + Ref::keyword("WITH").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Ref::new("TagEqualsSegment").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![Ref::new("TagReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Delimited::new(vec![ + AnyNumberOf::new(vec![ + Ref::keyword("DATA_RETENTION_TIME_IN_DAYS").to_matchable(), + Ref::keyword("MAX_DATA_EXTENSION_TIME_IN_DAYS").to_matchable(), + Ref::keyword("DEFAULT_DDL_COLLATION").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) @@ -9268,15 +14219,54 @@ pub fn dialect() -> Dialect { .into(), ), ( - "DropExternalTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropExternalTableStatement, |_| { + "AlterMaskingPolicySegment".into(), + NodeMatcher::new(SyntaxKind::AlterMaskingPolicy, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("EXTERNAL").to_matchable(), - Ref::keyword("TABLE").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("BODY").to_matchable(), + Ref::new("FunctionAssignerSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![Ref::new("TagReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) @@ -9284,15 +14274,41 @@ pub fn dialect() -> Dialect { .into(), ), ( - "DropFunctionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_| { + "ForInLoopSegment".into(), + NodeMatcher::new(SyntaxKind::ForInStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("EXTERNAL").optional().to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - Ref::new("FunctionParameterListGrammar").to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("FOR").to_matchable(), + Ref::new("LocalVariableNameSegment").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::new("LocalVariableNameSegment").to_matchable(), + Ref::keyword("DO").to_matchable(), + MetaSegment::indent().to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![Ref::new("StatementSegment").to_matchable()]) + .config(|this| { + this.delimiter(Ref::new("DelimiterGrammar")); + }) + .to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::GreedyOnceStarted); + this.terminators = vec![ + Sequence::new(vec![ + Ref::new("DelimiterGrammar").to_matchable(), + Ref::keyword("END").to_matchable(), + Ref::keyword("FOR").to_matchable(), + ]) + .to_matchable(), + ]; + }) + .to_matchable(), + Ref::new("DelimiterGrammar").to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::keyword("END").to_matchable(), + Ref::keyword("FOR").to_matchable(), ]) .to_matchable() }) @@ -9300,14 +14316,11 @@ pub fn dialect() -> Dialect { .into(), ), ( - "DropMaterializedViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropMaterializedViewStatement, |_| { + "BindVariableSegment".into(), + NodeMatcher::new(SyntaxKind::BindVariable, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("MATERIALIZED").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("ColonPrefixSegment").to_matchable(), + Ref::new("LocalVariableNameSegment").to_matchable(), ]) .to_matchable() }) @@ -9315,114 +14328,334 @@ pub fn dialect() -> Dialect { .into(), ), ( - "DropObjectStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropObjectStatement, |_| { + "ScriptingDeclareStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ScriptingDeclareStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - one_of(vec![ - Sequence::new(vec![ + Ref::keyword("DECLARE").to_matchable(), + MetaSegment::indent().to_matchable(), + Sequence::new(vec![ + Ref::new("LocalVariableNameSegment") + .exclude(Ref::keyword("BEGIN")) + .to_matchable(), + one_of(vec![ one_of(vec![ - Ref::keyword("CONNECTION").to_matchable(), Sequence::new(vec![ - Ref::keyword("FILE").to_matchable(), - Ref::keyword("FORMAT").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("WalrusOperatorSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("WalrusOperatorSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CURSOR").to_matchable(), + Ref::keyword("FOR").to_matchable(), + one_of(vec![ + Ref::new("LocalVariableNameSegment").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RESULTSET").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("WalrusOperatorSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![Ref::keyword("ASYNC").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Bracketed::new(vec![ + Ref::new("SelectClauseSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXCEPTION").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ExceptionCodeSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("DelimiterGrammar").to_matchable(), + Ref::new("LocalVariableNameSegment") + .exclude(Ref::keyword("BEGIN")) + .to_matchable(), + one_of(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::new("DatatypeSegment").to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("WalrusOperatorSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("WalrusOperatorSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ + Ref::keyword("CURSOR").to_matchable(), + Ref::keyword("FOR").to_matchable(), one_of(vec![ - Ref::keyword("API").to_matchable(), - Ref::keyword("NOTIFICATION").to_matchable(), - Ref::keyword("SECURITY").to_matchable(), - Ref::keyword("STORAGE").to_matchable(), + Ref::new("LocalVariableNameSegment").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - Ref::keyword("INTEGRATION").to_matchable(), ]) .to_matchable(), - Ref::keyword("PIPE").to_matchable(), Sequence::new(vec![ - Ref::keyword("ROW").to_matchable(), - Ref::keyword("ACCESS").to_matchable(), - Ref::keyword("POLICY").to_matchable(), + Ref::keyword("RESULTSET").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("WalrusOperatorSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![Ref::keyword("ASYNC").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Bracketed::new(vec![ + Ref::new("SelectClauseSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), - Ref::keyword("STAGE").to_matchable(), - Ref::keyword("STREAM").to_matchable(), - Ref::keyword("TAG").to_matchable(), - Ref::keyword("TASK").to_matchable(), - ]) - .to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ Sequence::new(vec![ - Ref::keyword("RESOURCE").to_matchable(), - Ref::keyword("MONITOR").to_matchable(), + Ref::keyword("EXCEPTION").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ExceptionCodeSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Ref::keyword("SHARE").to_matchable(), ]) .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - one_of(vec![ + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::new("ScriptingBlockStatementSegment") + .optional() + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ScriptingIfStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ScriptingIfStatement, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("IF").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + Ref::keyword("THEN").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("StatementSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("DelimiterGrammar").to_matchable(), + Ref::new("StatementSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("ELSEIF").to_matchable(), + Ref::keyword("ELSE").to_matchable(), Sequence::new(vec![ - Ref::keyword("MANAGED").to_matchable(), - Ref::keyword("ACCOUNT").to_matchable(), + Ref::keyword("END").to_matchable(), + Ref::keyword("IF").to_matchable(), ]) .to_matchable(), + ]; + }) + .to_matchable(), + Ref::new("DelimiterGrammar").to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("ELSEIF").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + Ref::keyword("THEN").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("StatementSegment").to_matchable(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), + Ref::new("DelimiterGrammar").to_matchable(), + Ref::new("StatementSegment").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("ELSEIF").to_matchable(), + Ref::keyword("ELSE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("END").to_matchable(), + Ref::keyword("IF").to_matchable(), + ]) + .to_matchable(), + ]; + }) .to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DelimiterGrammar").to_matchable(), + MetaSegment::dedent().to_matchable(), ]) .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::keyword("ELSE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("END").to_matchable(), + Ref::keyword("IF").to_matchable(), + ]) + .to_matchable(), + ]; + }) + .to_matchable(), + Sequence::new(vec![ Sequence::new(vec![ - one_of(vec![ + Ref::keyword("ELSE").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("StatementSegment").to_matchable(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::keyword("NETWORK").to_matchable(), - Ref::keyword("POLICY").to_matchable(), + Ref::new("DelimiterGrammar").to_matchable(), + Ref::new("StatementSegment").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.terminators = vec![ + Sequence::new(vec![ + Ref::keyword("END").to_matchable(), + Ref::keyword("IF").to_matchable(), + ]) + .to_matchable(), + ]; + }) .to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DelimiterGrammar").to_matchable(), + MetaSegment::dedent().to_matchable(), ]) .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("END").to_matchable(), + Ref::keyword("IF").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ScriptingRaiseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ScriptingRaiseStatement, |_dialect| { + Ref::keyword("RAISE").to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "LambdaExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::LambdaFunction, |_dialect| { + Sequence::new(vec![ + one_of(vec![ Sequence::new(vec![ - one_of(vec![ - Ref::keyword("WAREHOUSE").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("DatatypeSegment").optional().to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ Sequence::new(vec![ - Ref::keyword("SESSION").to_matchable(), - Ref::keyword("POLICY").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("DatatypeSegment").optional().to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SEQUENCE").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Ref::new("LambdaArrowSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable() }) @@ -9430,58 +14663,110 @@ pub fn dialect() -> Dialect { .into(), ), ( - "ListStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ListStatement, |_| { - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("LIST").to_matchable(), - Ref::keyword("LS").to_matchable(), + "PasswordPolicyReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::PasswordPolicyReference, |_dialect| { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "PasswordPolicyOptionsSegment".into(), + NodeMatcher::new(SyntaxKind::PasswordPolicyOptions, |_dialect| { + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("PASSWORD_MIN_LENGTH").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) .to_matchable(), - Ref::new("StagePath").to_matchable(), Sequence::new(vec![ - Ref::keyword("PATTERN").to_matchable(), + Ref::keyword("PASSWORD_MAX_LENGTH").to_matchable(), Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "GetStatementSegment".into(), - NodeMatcher::new(SyntaxKind::GetStatement, |_| { - Sequence::new(vec![ - Ref::keyword("GET").to_matchable(), - Ref::new("StagePath").to_matchable(), - one_of(vec![ - Ref::new("UnquotedFilePath").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("PASSWORD_MIN_UPPER_CASE_CHARS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), ]) .to_matchable(), - any_set_of(vec![ - Sequence::new(vec![ - Ref::keyword("PARALLEL").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("IntegerSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("PATTERN").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("ReferencedVariableNameSegment").to_matchable(), - ]) - .to_matchable(), - ]) + Sequence::new(vec![ + Ref::keyword("PASSWORD_MIN_LOWER_CASE_CHARS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PASSWORD_MIN_NUMERIC_CHARS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PASSWORD_MIN_SPECIAL_CHARS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PASSWORD_MIN_AGE_DAYS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PASSWORD_MAX_AGE_DAYS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PASSWORD_MAX_RETRIES").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PASSWORD_LOCKOUT_TIME_MINS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PASSWORD_HISTORY").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreatePasswordPolicyStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreatePasswordPolicyStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("PASSWORD").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("PasswordPolicyReferenceSegment").to_matchable(), + Ref::new("PasswordPolicyOptionsSegment") + .optional() .to_matchable(), - ]) - .to_matchable(), ]) .to_matchable() }) @@ -9489,39 +14774,58 @@ pub fn dialect() -> Dialect { .into(), ), ( - "PutStatementSegment".into(), - NodeMatcher::new(SyntaxKind::PutStatement, |_| { + "AlterPasswordPolicyStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterPasswordPolicyStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("PUT").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("PASSWORD").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("PasswordPolicyReferenceSegment").to_matchable(), one_of(vec![ - Ref::new("UnquotedFilePath").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("StagePath").to_matchable(), - any_set_of(vec![ Sequence::new(vec![ - Ref::keyword("PARALLEL").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("IntegerSegment").to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("PasswordPolicyReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("AUTO_COMPRESS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("PasswordPolicyOptionsSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SOURCE_COMPRESSION").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("CompressionType").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("OVERWRITE").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![Ref::new("TagReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + AnyNumberOf::new(vec![ + Ref::keyword("PASSWORD_MIN_LENGTH").to_matchable(), + Ref::keyword("PASSWORD_MAX_LENGTH").to_matchable(), + Ref::keyword("PASSWORD_MIN_UPPER_CASE_CHARS").to_matchable(), + Ref::keyword("PASSWORD_MIN_LOWER_CASE_CHARS").to_matchable(), + Ref::keyword("PASSWORD_MIN_NUMERIC_CHARS").to_matchable(), + Ref::keyword("PASSWORD_MIN_SPECIAL_CHARS").to_matchable(), + Ref::keyword("PASSWORD_MIN_AGE_DAYS").to_matchable(), + Ref::keyword("PASSWORD_MAX_AGE_DAYS").to_matchable(), + Ref::keyword("PASSWORD_MAX_RETRIES").to_matchable(), + Ref::keyword("PASSWORD_LOCKOUT_TIME_MINS").to_matchable(), + Ref::keyword("PASSWORD_HISTORY").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), ]) .to_matchable(), ]) @@ -9533,265 +14837,132 @@ pub fn dialect() -> Dialect { .into(), ), ( - "RemoveStatementSegment".into(), - NodeMatcher::new(SyntaxKind::RemoveStatement, |_| { + "DropPasswordPolicyStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropPasswordPolicyStatement, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Ref::keyword("REMOVE").to_matchable(), - Ref::keyword("RM").to_matchable(), - ]) - .to_matchable(), - Ref::new("StagePath").to_matchable(), - Sequence::new(vec![ - Ref::keyword("PATTERN").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("ReferencedVariableNameSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::keyword("PASSWORD").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("PasswordPolicyReferenceSegment").to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - snowflake_dialect.replace_grammar( - "SetOperatorSegment", - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("UNION").to_matchable(), - one_of(vec![ - Ref::keyword("DISTINCT").to_matchable(), - Ref::keyword("ALL").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("INTERSECT").to_matchable(), - Ref::keyword("EXCEPT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("ALL").optional().to_matchable(), - ]) - .to_matchable(), - Ref::keyword("MINUS").to_matchable(), - ]) - .to_matchable(), - ); - - snowflake_dialect.add([( - "ShorthandCastSegment".into(), - NodeMatcher::new(SyntaxKind::CastExpression, |_| { - Sequence::new(vec![ - one_of(vec![ - Ref::new("Expression_D_Grammar").to_matchable(), - Ref::new("CaseExpressionSegment").to_matchable(), - ]) - .to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::new("CastOperatorSegment").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - one_of(vec![ - Ref::new("TimeZoneGrammar").to_matchable(), - AnyNumberOf::new(vec![Ref::new("ArrayAccessorSegment").to_matchable()]) - .to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.min_times(1)) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - )]); - - // Resource Monitor statements - snowflake_dialect.add([ ( - // A `RESOURCE MONITOR` options statement. - // https://docs.snowflake.com/en/sql-reference/sql/create-resource-monitor - // https://docs.snowflake.com/en/sql-reference/sql/alter-resource-monitor - "ResourceMonitorOptionsSegment".into(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::keyword("CREDIT_QUOTA").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), + "CreateRowAccessPolicyStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateRowAccessPolicyStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("FREQUENCY").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), one_of(vec![ - Ref::keyword("DAILY").to_matchable(), - Ref::keyword("WEEKLY").to_matchable(), - Ref::keyword("MONTHLY").to_matchable(), - Ref::keyword("YEARLY").to_matchable(), - Ref::keyword("NEVER").to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), ]) .to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("FunctionParameterListGrammar").to_matchable(), + Ref::keyword("RETURNS").to_matchable(), + Ref::keyword("BOOLEAN").to_matchable(), + Ref::new("FunctionAssignerSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterRowAccessPolicyStatmentSegment".into(), + NodeMatcher::new(SyntaxKind::AlterRowAccessPolicyStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("START_TIMESTAMP").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("ROW").to_matchable(), + Ref::keyword("ACCESS").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::keyword("IMMEDIATELY").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("END_TIMESTAMP").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOTIFY_USERS").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TRIGGERS").to_matchable(), - AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::keyword("PERCENT").to_matchable(), - Ref::keyword("DO").to_matchable(), - one_of(vec![ - Ref::keyword("NOTIFY").to_matchable(), - Ref::keyword("SUSPEND").to_matchable(), - Ref::keyword("SUSPEND_IMMEDIATE").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("BODY").to_matchable(), + Ref::new("FunctionAssignerSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("TagEqualsSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("TAG").to_matchable(), + Delimited::new(vec![Ref::new("TagReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("COMMENT").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - // A `CREATE RESOURCE MONITOR` statement. - // https://docs.snowflake.com/en/sql-reference/sql/create-resource-monitor - "CreateResourceMonitorStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("OrReplaceGrammar").optional().to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("RESOURCE").to_matchable(), - Ref::keyword("MONITOR").to_matchable(), - ]) - .to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("WITH").to_matchable(), - Ref::new("ResourceMonitorOptionsSegment").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - // An `ALTER RESOURCE MONITOR` statement. - // https://docs.snowflake.com/en/sql-reference/sql/alter-resource-monitor - "AlterResourceMonitorStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Sequence::new(vec![ - Ref::keyword("RESOURCE").to_matchable(), - Ref::keyword("MONITOR").to_matchable(), - ]) - .to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - Ref::keyword("SET").to_matchable(), - Ref::new("ResourceMonitorOptionsSegment").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - // A `DROP RESOURCE MONITOR` statement. - // https://docs.snowflake.com/en/sql-reference/sql/drop-resource-monitor - "DropResourceMonitorStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Sequence::new(vec![ - Ref::keyword("RESOURCE").to_matchable(), - Ref::keyword("MONITOR").to_matchable(), - ]) - .to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - // An `ALTER DATABASE` statement. - // https://docs.snowflake.com/en/sql-reference/sql/alter-database - "AlterDatabaseSegment".into(), - NodeMatcher::new(SyntaxKind::AlterDatabaseStatement, |_| { + "AlterTagStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTagStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ALTER").to_matchable(), - Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("TAG").to_matchable(), Ref::new("IfExistsGrammar").optional().to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), one_of(vec![ Sequence::new(vec![ Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SWAP").to_matchable(), - Ref::keyword("WITH").to_matchable(), + Ref::keyword("TO").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), one_of(vec![ - Ref::new("TagEqualsSegment").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::new("BooleanLiteralGrammar").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("UNSET").to_matchable(), + ]) + .to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("MASKING").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), ]) .to_matchable(), ]) @@ -9799,24 +14970,29 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Ref::keyword("TAG").to_matchable(), - Delimited::new(vec![Ref::new("TagReferenceSegment").to_matchable()]) - .to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("CommentEqualsClauseSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ Ref::keyword("UNSET").to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Ref::keyword("DATA_RETENTION_TIME_IN_DAYS").to_matchable(), - Ref::keyword("MAX_DATA_EXTENSION_TIME_IN_DAYS").to_matchable(), - Ref::keyword("DEFAULT_DDL_COLLATION").to_matchable(), - Ref::keyword("COMMENT").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("COMMENT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("DROP").to_matchable(), ]) .to_matchable(), + Ref::keyword("ALLOWED_VALUES").to_matchable(), + Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSET").to_matchable(), + Ref::keyword("ALLOWED_VALUES").to_matchable(), ]) .to_matchable(), ]) @@ -9828,182 +15004,190 @@ pub fn dialect() -> Dialect { .into(), ), ( - // An `ALTER MASKING POLICY` statement. - // https://docs.snowflake.com/en/sql-reference/sql/alter-masking-policy - "AlterMaskingPolicySegment".into(), - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("MASKING").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("BODY").to_matchable(), - Ref::new("FunctionAssignerSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("TagEqualsSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Ref::keyword("TAG").to_matchable(), - Delimited::new(vec![Ref::new("TagReferenceSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("COMMENT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Ref::keyword("COMMENT").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - // An `ALTER NETWORK POLICY` statement. - // https://docs.snowflake.com/en/sql-reference/sql/alter-network-policy - "AlterNetworkPolicyStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("NETWORK").to_matchable(), - Ref::keyword("POLICY").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - one_of(vec![ + "ExceptionBlockStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ExceptionBlockStatement, |_dialect| { + Sequence::new(vec![ Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - any_set_of(vec![ + Ref::keyword("EXCEPTION").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("ALLOWED_NETWORK_RULE_LIST").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("WHEN").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("OR").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + Ref::keyword("THEN").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("BLOCKED_NETWORK_RULE_LIST").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("WHEN").to_matchable(), + Ref::keyword("OTHER").to_matchable(), + Ref::keyword("THEN").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ALLOWED_IP_LIST").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("StatementSegment").to_matchable(), + ]) + .to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("DelimiterGrammar").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("WHEN").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("OR").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), + Ref::keyword("THEN").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("BLOCKED_IP_LIST").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WHEN").to_matchable(), + Ref::keyword("OTHER").to_matchable(), + Ref::keyword("THEN").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), + Ref::new("StatementSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropIcebergTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropIcebergTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("ICEBERG").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DropDynamicTableSegment".into(), + NodeMatcher::new(SyntaxKind::DropDynamicTableSegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("DYNAMIC").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateAuthenticationPolicySegment".into(), + NodeMatcher::new(SyntaxKind::CreateAuthenticationPolicySegment, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("AUTHENTICATION").to_matchable(), + Ref::keyword("POLICY").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("AUTHENTICATION_METHODS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("REMOVE").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("ALLOWED_NETWORK_RULE_LIST").to_matchable(), - Ref::keyword("BLOCKED_NETWORK_RULE_LIST").to_matchable(), + Ref::keyword("MFA_AUTHENTICATION_METHODS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .to_matchable(), ]) .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("MFA_ENROLLMENT").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("REQUIRED").to_matchable(), + Ref::keyword("OPTIONAL").to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("TagEqualsSegment").to_matchable(), + Ref::keyword("CLIENT_TYPES").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("UNSET").to_matchable(), - Ref::keyword("TAG").to_matchable(), - Ref::new("TagReferenceSegment").to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("CommaSegment").to_matchable(), - Ref::new("TagReferenceSegment").to_matchable(), + Ref::keyword("SECURITY_INTEGRATIONS").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + .to_matchable(), ]) - .config(|this| this.optional()) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("CommentEqualsClauseSegment") + .optional() + .to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), ]); - snowflake_dialect.expand(); snowflake_dialect } diff --git a/crates/lib-dialects/src/snowflake_keywords.rs b/crates/lib-dialects/src/snowflake_keywords.rs index 95683c4e1..9d6a2ac97 100644 --- a/crates/lib-dialects/src/snowflake_keywords.rs +++ b/crates/lib-dialects/src/snowflake_keywords.rs @@ -3,6 +3,9 @@ ALTER AND ANY AS +ASOF +BEARER +BEARER_TOKEN BETWEEN BY CAST @@ -15,12 +18,12 @@ CURRENT CURRENT_DATE CURRENT_TIME CURRENT_TIMESTAMP -CURRENT_USER DELETE +DECLARE DISTINCT -DO DROP ELSE +ELSEIF EXISTS FOLLOWING FOR @@ -30,6 +33,7 @@ GRANT GROUP GSCLUSTER HAVING +HYBRID ILIKE IN INCREMENT @@ -40,18 +44,16 @@ INTERSECT INTO IS JOIN -ASOF LATERAL LEFT LIKE LOCALTIME LOCALTIMESTAMP -MATCH_RECOGNIZE MATCH_CONDITION +MATCH_RECOGNIZE MINUS NATURAL NOT -NOTIFY NULL NULL_IF OF @@ -59,6 +61,7 @@ ON OR ORDER QUALIFY +RAISE REGEXP REVOKE RIGHT @@ -76,52 +79,78 @@ TABLESAMPLE THEN TO TRIGGER -TRIGGERS TRY_CAST UNION UNIQUE -UPDATE UNPIVOT +UPDATE USING VALUES WHEN WHENEVER WHERE -WITH"; +WITH +"; -pub(crate) const SNOWFLAKE_UNRESERVED_KEYWORDS: &str = "ABORT +pub(crate) const SNOWFLAKE_UNRESERVED_KEYWORDS: &str = " +ABORT ABORT_STATEMENT ACCESS +ACCESS_APPROVAL ACCOUNT ACCOUNTS +ACTION ADD ADMIN AFTER +AGGREGATE +AGGREGATION +ALERT +ALLOW_DUPLICATE +ALLOW_OVERLAPPING_EXECUTION +ALLOW_WRITES +ALLOWED_AUTHENTICATION_SECRETS ALLOWED_IP_LIST ALLOWED_NETWORK_RULE_LIST ALLOWED_VALUES -ALLOW_DUPLICATE -ALLOW_OVERLAPPING_EXECUTION +ALWAYS API +API_ALLOWED_PREFIXES +API_AWS_ROLE_ARN +API_BLOCKED_PREFIXES API_INTEGRATION +API_KEY +API_PROVIDER APPEND_ONLY +APPLICATION APPLY ARRAY ASC +ASYNC AT ATTACH +ATTRIBUTES +AUTHENTICATION +AUTHENTICATION_METHODS AUTHORIZATION AUTHORIZATIONS AUTO -AUTOINCREMENT AUTO_COMPRESS AUTO_INCREMENT AUTO_INGEST AUTO_REFRESH AUTO_RESUME AUTO_SUSPEND +AUTOINCREMENT AVRO +AWSVPCEID +AWS_API_GATEWAY +AWS_GLUE +AWS_PRIVATE_API_GATEWAY +AWS_GOV_API_GATEWAY +AWS_GOV_PRIVATE_API_GATEWAY AWS_KEY_ID +AWS_PRIVATE_API_GATEWAY AWS_ROLE AWS_SECRET_KEY AWS_SNS @@ -130,12 +159,16 @@ AWS_SNS_TOPIC AWS_SNS_TOPIC_ARN AWS_TOKEN AZURE +AZURELINKID +AZURE_API_MANAGEMENT +AZURE_AD_APPLICATION_ID AZURE_EVENT_GRID AZURE_EVENT_GRID_TOPIC_ENDPOINT AZURE_SAS_TOKEN AZURE_STORAGE_QUEUE AZURE_STORAGE_QUEUE_PRIMARY_URI AZURE_TENANT_ID +BASE_LOCATION BASE64 BEFORE BEGIN @@ -148,6 +181,7 @@ BLOCK BLOCKED_IP_LIST BLOCKED_NETWORK_RULE_LIST BODY +BOOLEAN BROTLI BZ2 CACHE @@ -156,13 +190,21 @@ CALLED CALLER CASCADE CASE -CASES CASE_INSENSITIVE CASE_SENSITIVE +CASES +CATALOG +CATALOG_API_TYPE +CATALOG_NAME +CATALOG_NAMESPACE +CATALOG_SOURCE +CATALOG_TABLE_NAME +CATALOG_URI CHAIN -CHANGES CHANGE_TRACKING +CHANGES CHARACTER +CLIENT_TYPES CLONE CLUSTER CLUSTERING @@ -174,10 +216,12 @@ COMMIT COMPRESSION CONCURRENTLY CONNECT_BY_ROOT +CONTACT CONTEXT_HEADERS CONTINUE COPY COPY_OPTIONS +CORTEX CREDENTIALS CREDIT_QUOTA CROSS @@ -194,19 +238,21 @@ CURRENT_SCHEMAS CURRENT_SESSION CURRENT_STATEMENT CURRENT_TRANSACTION +CURRENT_USER CURRENT_VERSION CURRENT_WAREHOUSE CURSOR CYCLE +DAILY DATA -DATABASE -DATABASES DATA_FORMAT DATA_RETENTION_TIME_IN_DAYS +DATABASE +DATABASES DATE DATE_FORMAT -DAILY DAYS_TO_EXPIRY +DEBUG DEFAULT DEFAULT_DDL_COLLATION DEFAULT_NAMESPACE @@ -218,37 +264,49 @@ DEFERRED DEFINE DEFLATE DELEGATED +DELTA DESC DESCRIBE DETAILED_OUTPUT DIRECTION DIRECTORY DISABLE -DISABLED DISABLE_AUTO_CONVERT DISABLE_SNOWFLAKE_DATA +DISABLED DISPLAY_NAME +DO DOMAIN DOUBLE +DOWNSTREAM +DYNAMIC ECONOMY +EGRESS EMAIL +EMBEDDING_MODEL EMPTY EMPTY_FIELD_AS_NULL ENABLE -ENABLED ENABLE_OCTAL +ENABLE_QUERY_ACCELERATION +ENABLED ENCODING ENCRYPTION END END_TIMESTAMP -ENFORCED ENFORCE_LENGTH +ENFORCED +ENTITY ENUM +EQUALITY +ERROR ERROR_INTEGRATION ERROR_ON_COLUMN_COUNT_MISMATCH ESCAPE ESCAPE_UNENCLOSED_FIELD +EVENT EXCEPT +EXCEPTION EXCHANGE EXCLUDE EXECUTE @@ -256,14 +314,18 @@ EXECUTION EXPLAIN EXTENSION EXTERNAL +EXTERNAL_ACCESS_INTEGRATIONS EXTERNAL_STAGE +EXTERNAL_VOLUME +FATAL FETCH FIELD_DELIMITER +FIELD_OPTIONALITY_ENCLOSED_BY FIELD_OPTIONALLY_ENCLOSED_BY FILE -FILES FILE_EXTENSION FILE_FORMAT +FILES FILTER FINAL FIRST @@ -272,8 +334,8 @@ FOR FORCE FOREIGN FORMAT -FORMATS FORMAT_NAME +FORMATS FREQUENCY FUNCTION FUNCTIONS @@ -282,8 +344,16 @@ GCP_PUBSUB GCP_PUBSUB_SUBSCRIPTION_NAME GCP_PUBSUB_TOPIC_NAME GCS +GEO GET +GIT_HTTPS_API GLOBAL +GLUE +GLUE_AWS_ROLE_ARN +GLUE_CATALOG_ID +GLUE_REGION +GOOGLE_AUDIENCE +GOOGLE_API_GATEWAY GRANTED GRANTS GROUPING @@ -293,6 +363,9 @@ HEADER HEADERS HEX HISTORY +HOST_PORT +ICEBERG +ICEBERG_REST IDENTIFIER IDENTITY IF @@ -302,17 +375,25 @@ IMMEDIATE IMMEDIATELY IMMUTABLE IMPORT -IMPORTS IMPORTED +IMPORTS +INCLUDE +INCLUDE_METADATA INCLUDE_QUERY_ID INDEX +INDEXING +INFO INFORMATION +INGRESS +INITIALIZE INITIALLY INITIALLY_SUSPENDED INPUT INTEGRATION INTEGRATIONS +INTERNAL_STAGE INTERVAL +IPV4 ISSUE JAVA JAVASCRIPT @@ -329,73 +410,103 @@ LET LIMIT LIST LISTING +LOAD_UNCERTAIN_FILES LOCAL LOCATION LOCKS +LOG_LEVEL LOGIN_NAME LS LZO M +MAIN_FILE MANAGE MANAGED MASKING MASTER_KEY MATCH +MATCH_BY_COLUMN_NAME MATCHED MATCHES -MATCH_BY_COLUMN_NAME MATERIALIZED -MAXVALUE MAX_BATCH_ROWS MAX_CLUSTER_COUNT MAX_CONCURRENCY_LEVEL MAX_DATA_EXTENSION_TIME_IN_DAYS MAX_FILE_SIZE MAX_SIZE +MAXVALUE MEASURES MERGE +METADATA_FILE_PATH +METADATA$FILENAME +METADATA$FILE_ROW_NUMBER +METADATA$FILE_CONTENT_KEY +METADATA$FILE_LAST_MODIFIED +METADATA$START_SCAN_TIME +MFA_AUTHENTICATION_METHODS +MFA_ENROLLMENT MIDDLE_NAME +MIN_CLUSTER_COUNT MINS_TO_BYPASS_MFA MINS_TO_UNLOCK MINVALUE -MIN_CLUSTER_COUNT ML +MODE MODEL +MODELS MODIFIED_AFTER MODIFY MONITOR +MONITORS MONTHLY +MULTI_LINE MUST_CHANGE_PASSWORD NAME NAN NETWORK +NEVER NEXT NEXTVAL -NEVER NO NOCACHE NOCYCLE NONE NOORDER +NORELY +NOTEBOOK +NOTEBOOKS NOTIFICATION NOTIFICATION_INTEGRATION NOTIFICATION_PROVIDER +NOTIFY NOTIFY_USERS -NULLS +NOVALIDATE NULL_IF +NULLS +OAUTH +OAUTH_ALLOWED_SCOPES +OAUTH_CLIENT_ID +OAUTH_CLIENT_SECRET +OAUTH_TOKEN_URI OBJECT +OBJECT_STORE OBJECTS +OFF OFFSET OMIT +ON_ERROR +ON_EVENT ONE ONLY -ON_ERROR OPERATE OPTIMIZATION OPTION +OPTIONAL OPTIONS ORC ORGANIZATION +OTHER OUTBOUND OUTER OVER @@ -408,18 +519,32 @@ PACKAGES PARALLEL PARAMETERS PARQUET +PARSE_HEADER +PARTIAL PARTITION +PARTITION_TYPE PASSWORD +PASSWORD_HISTORY +PASSWORD_LOCKOUT_TIME_MINS +PASSWORD_MAX_AGE_DAYS +PASSWORD_MAX_LENGTH +PASSWORD_MAX_RETRIES +PASSWORD_MIN_AGE_DAYS +PASSWORD_MIN_LOWER_CASE_CHARS +PASSWORD_MIN_LENGTH +PASSWORD_MIN_NUMERIC_CHARS +PASSWORD_MIN_SPECIAL_CHARS +PASSWORD_MIN_UPPER_CASE_CHARS PAST PATTERN -FIELD_OPTIONALITY_ENCLOSED_BY PER PERCENT PERMUTE PIPE -PIPES PIPE_EXECUTION_PAUSED +PIPES PIVOT +POLARIS POLICIES POLICY PRECEDING @@ -428,6 +553,7 @@ PREFIX PRESERVE_SPACE PRIMARY PRIOR +PRIVATE_HOST_PORT PRIVILEGES PROCEDURE PROCEDURES @@ -436,6 +562,8 @@ PURGE PUT PYTHON QUERIES +QUERY_ACCELERATION_MAX_SCALE_FACTOR +QUERY_WAREHOUSE QUEUE RANGE RAW_DEFLATE @@ -443,11 +571,14 @@ READ RECLUSTER RECORD_DELIMITER RECURSIVE -REFERENCES REFERENCE_USAGE +REFERENCES REFRESH +REFRESH_INTERVAL_SECONDS +REFRESH_MODE REFRESH_ON_CREATE REGIONS +RELY REMOVE RENAME REPEATABLE @@ -455,31 +586,38 @@ REPLACE REPLACE_INVALID_CHARACTERS REPLICATION REQUEST_TRANSLATOR +REQUIRE +REQUIRED RESET RESOURCE +RESOURCE_CONSTRAINT RESOURCE_MONITOR RESPECT RESPONSE_TRANSLATOR RESTRICT RESTRICTIONS +REST_AUTHENTICATION +REST_CONFIG RESULT RESULTSET RESUME RETURN -RETURNS RETURN_ALL_ERRORS RETURN_ERRORS RETURN_FAILED_ONLY +RETURNS RM ROLE ROLES ROLLBACK ROLLUP +ROOT_LOCATION ROUTINE ROUTINES ROW RSA_PUBLIC_KEY RSA_PUBLIC_KEY_2 +RULE RUNNING RUNTIME_VERSION S3 @@ -490,21 +628,31 @@ SCHEMA SCHEMAS SEARCH SECONDARY +SECRETS SECURE SECURITY +SECURITY_INTEGRATIONS SEED SEPARATOR SEQUENCE SEQUENCES SERVER +SERVICE +SERVICES +SERVING SESSION SESSION_USER SETS SHARE -SHARES SHARE_RESTRICTIONS +SHARES SHOW SHOW_INITIAL_ROWS +SIGV4 +SIGV4_EXTERNAL_ID +SIGV4_IAM_ROLE +SIGV4_SIGNING_REGION +SIMPLE SINGLE SIZE_LIMIT SKIP @@ -519,39 +667,49 @@ SNOWFLAKE_SSE SOURCE_COMPRESSION SQL STAGE -STAGES STAGE_COPY_OPTIONS STAGE_FILE_FORMAT +STAGES STANDARD -STARTS START_TIMESTAMP +STARTS STATEMENT STATEMENT_QUEUED_TIMEOUT_IN_SECONDS STATEMENT_TIMEOUT_IN_SECONDS +STEWARD STORAGE STORAGE_ALLOWED_LOCATIONS +STORAGE_AWS_EXTERNAL_ID STORAGE_AWS_OBJECT_ACL STORAGE_AWS_ROLE_ARN +STORAGE_BASE_URL STORAGE_BLOCKED_LOCATIONS STORAGE_INTEGRATION +STORAGE_LOCATION +STORAGE_LOCATIONS STORAGE_PROVIDER STREAM +STREAMLIT +STREAMLITS STREAMS STRIP_NULL_VALUES STRIP_OUTER_ARRAY STRIP_OUTER_ELEMENT SUBPATH +SUBSTRING SUPPORT SUSPEND -SUSPENDED SUSPEND_IMMEDIATE +SUSPENDED SWAP SYSDATE SYSTEM TABLES TABLESPACE +TABLE_FORMAT TABULAR TAG +TARGET_LAG TARGET_PATH TASK TASKS @@ -561,13 +719,17 @@ TEMPORARY TERSE TEXT TIME +TIME_FORMAT TIMESTAMP TIMESTAMP_FORMAT -TIME_FORMAT +TITLE TOP +TRACE +TRACE_LEVEL TRANSACTION TRANSACTIONS TRANSIENT +TRIGGERS TRIM_SPACE TRUNCATE TRUNCATECOLUMNS @@ -581,15 +743,21 @@ URL US USAGE USE +USE_ANY_ROLE +USE_LOGICAL_TYPE +USE_PRIVATELINK_ENDPOINT +USE_VECTORIZED_SCANNER USER -USERS +USER_SPECIFIED USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE USER_TASK_TIMEOUT_MS -USE_ANY_ROLE +USERS UTF8 +VALIDATE VALIDATE_UTF8 VALIDATION_MODE VALUE +VALUE_LIST VARIABLES VARIANT VARYING @@ -597,11 +765,14 @@ VERSION VIEW VIEWS VOLATILE +VOLUME +VOLUMES WAIT_FOR_COMPLETION WAREHOUSE -WAREHOUSES WAREHOUSE_SIZE WAREHOUSE_TYPE +WAREHOUSES +WARN WEEKLY WINDOW WITH @@ -614,4 +785,5 @@ WRITE XML YEARLY ZONE -ZSTD"; +ZSTD +"; diff --git a/crates/lib-dialects/src/sparksql.rs b/crates/lib-dialects/src/sparksql.rs index d2c2bf2a2..f9425a680 100644 --- a/crates/lib-dialects/src/sparksql.rs +++ b/crates/lib-dialects/src/sparksql.rs @@ -2,9 +2,7 @@ use sqruff_lib_core::dialects::Dialect; use sqruff_lib_core::dialects::init::DialectKind; use sqruff_lib_core::dialects::syntax::SyntaxKind; use sqruff_lib_core::helpers::{Config, ToMatchable}; -use sqruff_lib_core::parser::grammar::anyof::{ - AnyNumberOf, any_set_of, one_of, optionally_bracketed, -}; +use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed}; use sqruff_lib_core::parser::grammar::conditional::Conditional; use sqruff_lib_core::parser::grammar::delimited::Delimited; use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence}; @@ -13,47 +11,43 @@ use sqruff_lib_core::parser::lexer::Matcher; use sqruff_lib_core::parser::matchable::MatchableTrait; use sqruff_lib_core::parser::node_matcher::NodeMatcher; use sqruff_lib_core::parser::parsers::{MultiStringParser, RegexParser, StringParser, TypedParser}; -use sqruff_lib_core::parser::segments::bracketed::BracketedSegmentMatcher; use sqruff_lib_core::parser::segments::meta::MetaSegment; use sqruff_lib_core::parser::types::ParseMode; use super::sparksql_keywords::{RESERVED_KEYWORDS, UNRESERVED_KEYWORDS}; -use crate::ansi; + +pub fn dialect() -> Dialect { + raw_dialect().config(|this| this.expand()) +} pub fn raw_dialect() -> Dialect { - let ansi_dialect = ansi::raw_dialect(); + let ansi_dialect = super::ansi::raw_dialect(); let hive_dialect = super::hive::raw_dialect(); - let mut sparksql_dialect = ansi_dialect; + let mut sparksql_dialect = ansi_dialect.clone(); sparksql_dialect.name = DialectKind::Sparksql; sparksql_dialect.patch_lexer_matchers(vec![ - Matcher::regex("inline_comment", r"(--)[^\n]*", SyntaxKind::InlineComment), - Matcher::regex("equals", r"==|<=>|=", SyntaxKind::RawComparisonOperator), - Matcher::regex("back_quote", r"`([^`]|``)*`", SyntaxKind::BackQuote), - Matcher::legacy("numeric_literal", |s| s.starts_with(|ch: char| ch == '.' || ch == '-' || ch.is_ascii_alphanumeric()), r#"(?>(?>\d+\.\d+|\d+\.|\.\d+)([eE][+-]?\d+)?([dDfF]|BD|bd)?|\d+[eE][+-]?\d+([dDfF]|BD|bd)?|\d+([dDfFlLsSyY]|BD|bd)?)((?<=\.)|(?=\b))"#, SyntaxKind::NumericLiteral), + Matcher::regex("inline_comment", r#"(--)[^\n]*"#, SyntaxKind::InlineComment), + Matcher::regex("equals", r#"==|<=>|="#, SyntaxKind::RawComparisonOperator), + Matcher::regex("back_quote", r#"`([^`]|``)*`"#, SyntaxKind::BackQuote), + Matcher::legacy("numeric_literal", |_| true, r#"(?>(?>\d+\.\d+|\d+\.|\.\d+)([eE][+-]?\d+)?([dDfF]|BD|bd)?|\d+[eE][+-]?\d+([dDfF]|BD|bd)?|\d+([dDfFlLsSyY]|BD|bd)?)((?<=\.)|(?=\b))"#, SyntaxKind::NumericLiteral), ]); sparksql_dialect.insert_lexer_matchers( vec![ Matcher::regex( - "bytes_single_quote", - r"X'([^'\\]|\\.)*'", - SyntaxKind::BytesSingleQuote, + "raw_single_quote", + r#"[rR]'([^'\\]|\\.)*'"#, + SyntaxKind::RawSingleQuote, ), Matcher::regex( - "bytes_double_quote", - r#"X"([^"\\]|\\.)*""#, - SyntaxKind::BytesDoubleQuote, + "raw_double_quote", + r#"[rR]"([^"\\]|\\.)*""#, + SyntaxKind::RawDoubleQuote, ), - ], - "single_quote", - ); - - sparksql_dialect.insert_lexer_matchers( - vec![ Matcher::regex( "bytes_single_quote", - r"X'([^'\\]|\\.)*'", + r#"X'([^'\\]|\\.)*'"#, SyntaxKind::BytesSingleQuote, ), Matcher::regex( @@ -68,20 +62,18 @@ pub fn raw_dialect() -> Dialect { sparksql_dialect.insert_lexer_matchers( vec![Matcher::regex( "at_sign_literal", - r"@\w*", + r#"@\w*"#, SyntaxKind::AtSignLiteral, )], "word", ); - sparksql_dialect.insert_lexer_matchers( - vec![ - Matcher::regex("file_literal", r#"[a-zA-Z0-9]*:?([a-zA-Z0-9\-_\.]*(/|\\)){2,}((([a-zA-Z0-9\-_\.]*(:|\?|=|&)[a-zA-Z0-9\-_\.]*)+)|([a-zA-Z0-9\-_\.]*\.[a-z]+))"#, SyntaxKind::FileLiteral), - ], - "newline", - ); + sparksql_dialect.insert_lexer_matchers(vec![ + Matcher::regex("file_literal", r#"[a-zA-Z0-9]+:([a-zA-Z0-9\-_\.]*(\/|\\)){2,}((([a-zA-Z0-9\-_\.]*(:|\?|=|&)[a-zA-Z0-9\-_\.]*)+)|([a-zA-Z0-9\-_\.]*\.[a-z]+))"#, SyntaxKind::FileLiteral), + ], "newline"); sparksql_dialect.sets_mut("bare_functions").clear(); + sparksql_dialect.sets_mut("bare_functions").extend([ "CURRENT_DATE", "CURRENT_TIMESTAMP", @@ -89,6 +81,7 @@ pub fn raw_dialect() -> Dialect { ]); sparksql_dialect.sets_mut("date_part_function_name").clear(); + sparksql_dialect .sets_mut("date_part_function_name") .extend([ @@ -101,6 +94,7 @@ pub fn raw_dialect() -> Dialect { ]); sparksql_dialect.sets_mut("datetime_units").clear(); + sparksql_dialect.sets_mut("datetime_units").extend([ "YEAR", "YEARS", @@ -117,6 +111,7 @@ pub fn raw_dialect() -> Dialect { "DAY", "DAYS", "DD", + "DAYOFYEAR", "HOUR", "HOURS", "MINUTE", @@ -132,6 +127,7 @@ pub fn raw_dialect() -> Dialect { sparksql_dialect .sets_mut("unreserved_keywords") .extend(UNRESERVED_KEYWORDS); + sparksql_dialect .sets_mut("reserved_keywords") .extend(RESERVED_KEYWORDS); @@ -146,82 +142,57 @@ pub fn raw_dialect() -> Dialect { )], ); - sparksql_dialect.add([ - ( - "SelectClauseTerminatorGrammar".into(), - ansi::raw_dialect() - .grammar("SelectClauseTerminatorGrammar") - .copy( - Some(vec![ - Sequence::new(vec![ - Ref::keyword("CLUSTER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DISTRIBUTE").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SORT").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("QUALIFY").to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ) - .into(), - ), - ( - "ComparisonOperatorGrammar".into(), + sparksql_dialect.replace_grammar( + "DateTimeLiteralGrammar", + Sequence::new(vec![ one_of(vec![ - Ref::new("EqualsSegment").to_matchable(), - Ref::new("EqualsSegment_a").to_matchable(), - Ref::new("EqualsSegment_b").to_matchable(), - Ref::new("GreaterThanSegment").to_matchable(), - Ref::new("LessThanSegment").to_matchable(), - Ref::new("GreaterThanOrEqualToSegment").to_matchable(), - Ref::new("LessThanOrEqualToSegment").to_matchable(), - Ref::new("NotEqualToSegment").to_matchable(), - Ref::new("LikeOperatorSegment").to_matchable(), - Sequence::new(vec![ - Ref::keyword("IS").to_matchable(), - Ref::keyword("DISTINCT").to_matchable(), - Ref::keyword("FROM").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("IS").to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("DISTINCT").to_matchable(), - Ref::keyword("FROM").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("DATE").to_matchable(), + Ref::keyword("TIME").to_matchable(), + Ref::keyword("TIMESTAMP").to_matchable(), + Ref::keyword("INTERVAL").to_matchable(), + Ref::keyword("TIMESTAMP_LTZ").to_matchable(), + Ref::keyword("TIMESTAMP_NTZ").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "FromClauseTerminatorGrammar".into(), - one_of(vec![ - Ref::keyword("WHERE").to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) + .to_matchable(), + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::DateConstructorLiteral) .to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "ComparisonOperatorGrammar", + one_of(vec![ + Ref::new("EqualsSegment").to_matchable(), + Ref::new("EqualsSegment_a").to_matchable(), + Ref::new("EqualsSegment_b").to_matchable(), + Ref::new("GreaterThanSegment").to_matchable(), + Ref::new("LessThanSegment").to_matchable(), + Ref::new("GreaterThanOrEqualToSegment").to_matchable(), + Ref::new("LessThanOrEqualToSegment").to_matchable(), + Ref::new("NotEqualToSegment").to_matchable(), + Ref::new("LikeOperatorSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("IS").to_matchable(), + Ref::keyword("DISTINCT").to_matchable(), + Ref::keyword("FROM").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IS").to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("DISTINCT").to_matchable(), + Ref::keyword("FROM").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "SelectClauseTerminatorGrammar", + ansi_dialect.grammar("SelectClauseTerminatorGrammar").copy( + Some(vec![ Sequence::new(vec![ Ref::keyword("CLUSTER").to_matchable(), Ref::keyword("BY").to_matchable(), @@ -237,265 +208,348 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("BY").to_matchable(), ]) .to_matchable(), - Ref::keyword("HAVING").to_matchable(), Ref::keyword("QUALIFY").to_matchable(), - Ref::new("SetOperatorSegment").to_matchable(), - Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), - Ref::new("WithDataClauseSegment").to_matchable(), - Ref::keyword("KEYS").to_matchable(), - ]) - .to_matchable() - .into(), + ]), + None, + None, + None, + vec![], + false, ), - ( - "TemporaryGrammar".into(), + ); + + sparksql_dialect.replace_grammar( + "FromClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("WHERE").to_matchable(), + Ref::keyword("LIMIT").to_matchable(), Sequence::new(vec![ - Sequence::new(vec![Ref::keyword("GLOBAL").to_matchable()]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - one_of(vec![ - Ref::keyword("TEMP").to_matchable(), - Ref::keyword("TEMPORARY").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "QuotedLiteralSegment".into(), - one_of(vec![ - TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral).to_matchable(), - TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedLiteral).to_matchable(), + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "LiteralGrammar".into(), - sparksql_dialect - .grammar("LiteralGrammar") - .copy( - Some(vec![Ref::new("BytesQuotedLiteralSegment").to_matchable()]), - None, - None, - None, - Vec::new(), - false, - ) - .into(), - ), - ( - "NaturalJoinKeywordsGrammar".into(), + .to_matchable(), Sequence::new(vec![ - Ref::keyword("NATURAL").to_matchable(), - Ref::new("JoinTypeKeywords").optional().to_matchable(), + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "LikeGrammar".into(), - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("LIKE").to_matchable(), - Ref::keyword("ILIKE").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::keyword("ANY").to_matchable(), - Ref::keyword("SOME").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("RLIKE").to_matchable(), - Ref::keyword("REGEXP").to_matchable(), + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DISTRIBUTE").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "SingleIdentifierGrammar".into(), + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SORT").to_matchable(), + Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), + Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), + Ref::new("WithDataClauseSegment").to_matchable(), + Ref::keyword("KEYS").to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "TemporaryGrammar", + Sequence::new(vec![ + Sequence::new(vec![Ref::keyword("GLOBAL").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), one_of(vec![ - Ref::new("NakedIdentifierSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), - Ref::new("SingleQuotedIdentifierSegment").to_matchable(), - Ref::new("BackQuotedIdentifierSegment").to_matchable(), + Ref::keyword("TEMP").to_matchable(), + Ref::keyword("TEMPORARY").to_matchable(), ]) - .to_matchable() - .into(), + .to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "QuotedLiteralSegment", + one_of(vec![ + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedLiteral).to_matchable(), + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedLiteral).to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "LiteralGrammar", + ansi_dialect.grammar("LiteralGrammar").copy( + Some(vec![ + Ref::new("RawQuotedLiteralSegment").to_matchable(), + Ref::new("BytesQuotedLiteralSegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, ), - ( - "WhereClauseTerminatorGrammar".into(), + ); + + sparksql_dialect.replace_grammar( + "NaturalJoinKeywordsGrammar", + Sequence::new(vec![ + Ref::keyword("NATURAL").to_matchable(), + Ref::new("JoinTypeKeywords").optional().to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "JoinLikeClauseGrammar", + Sequence::new(vec![ one_of(vec![ - Ref::keyword("LIMIT").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("CLUSTER").to_matchable(), - Ref::keyword("DISTRIBUTE").to_matchable(), - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("SORT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) + Ref::new("PivotClauseSegment").to_matchable(), + Ref::new("UnpivotClauseSegment").to_matchable(), + Ref::new("LateralViewClauseSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("AliasExpressionSegment") + .exclude(one_of(vec![ + Ref::new("FromClauseTerminatorGrammar").to_matchable(), + Ref::new("JoinLikeClauseGrammar").to_matchable(), + ])) + .optional() .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DISTRIBUTE").to_matchable(), - Ref::keyword("BY").to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "LikeGrammar", + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("LIKE").to_matchable(), + Ref::keyword("ILIKE").to_matchable(), ]) .to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("QUALIFY").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::keyword("OVERLAPS").to_matchable(), - Ref::keyword("APPLY").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "GroupByClauseTerminatorGrammar".into(), - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("DISTRIBUTE").to_matchable(), - Ref::keyword("CLUSTER").to_matchable(), - Ref::keyword("SORT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("BY").to_matchable(), + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::keyword("ANY").to_matchable(), + Ref::keyword("SOME").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "HavingClauseTerminatorGrammar".into(), - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("CLUSTER").to_matchable(), - Ref::keyword("DISTRIBUTE").to_matchable(), - Ref::keyword("SORT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("BY").to_matchable(), + .to_matchable(), + Ref::keyword("RLIKE").to_matchable(), + Ref::keyword("REGEXP").to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "NotOperatorGrammar", + one_of(vec![ + StringParser::new("NOT", SyntaxKind::Keyword).to_matchable(), + StringParser::new("!", SyntaxKind::NotOperator).to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "SingleIdentifierGrammar", + one_of(vec![ + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), + Ref::new("SingleQuotedIdentifierSegment").to_matchable(), + Ref::new("BackQuotedIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "WhereClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("LIMIT").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("DISTRIBUTE").to_matchable(), + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("SORT").to_matchable(), ]) .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("QUALIFY").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "ArithmeticBinaryOperatorGrammar".into(), - one_of(vec![ - Ref::new("PlusSegment").to_matchable(), - Ref::new("MinusSegment").to_matchable(), - Ref::new("DivideSegment").to_matchable(), - Ref::new("MultiplySegment").to_matchable(), - Ref::new("ModuloSegment").to_matchable(), - Ref::new("BitwiseAndSegment").to_matchable(), - Ref::new("BitwiseOrSegment").to_matchable(), - Ref::new("BitwiseXorSegment").to_matchable(), - Ref::new("BitwiseLShiftSegment").to_matchable(), - Ref::new("BitwiseRShiftSegment").to_matchable(), - Ref::new("DivBinaryOperatorSegment").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "BinaryOperatorGrammar".into(), - one_of(vec![ - Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(), - Ref::new("StringBinaryOperatorGrammar").to_matchable(), - Ref::new("BooleanBinaryOperatorGrammar").to_matchable(), - Ref::new("ComparisonOperatorGrammar").to_matchable(), - Ref::new("RightArrowOperator").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "AccessorGrammar".into(), - AnyNumberOf::new(vec![ - Ref::new("ArrayAccessorSegment").to_matchable(), - Ref::new("SemiStructuredAccessorSegment").to_matchable(), + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "ObjectReferenceTerminatorGrammar".into(), - one_of(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::keyword("USING").to_matchable(), - Ref::new("CommaSegment").to_matchable(), - Ref::new("CastOperatorSegment").to_matchable(), - Ref::new("StartSquareBracketSegment").to_matchable(), - Ref::new("StartBracketSegment").to_matchable(), - Ref::new("BinaryOperatorGrammar").to_matchable(), - Ref::new("DelimiterGrammar").to_matchable(), - Ref::new("JoinLikeClauseGrammar").to_matchable(), - BracketedSegmentMatcher::new().to_matchable(), + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DISTRIBUTE").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "FunctionContentsExpressionGrammar".into(), - one_of(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::new("StarSegment").to_matchable(), + .to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::keyword("OVERLAPS").to_matchable(), + Ref::keyword("APPLY").to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "GroupByClauseTerminatorGrammar", + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("DISTRIBUTE").to_matchable(), + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("SORT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - // An `IDENTIFIER` clause segment. - // https://docs.databricks.com/en/sql/language-manual/sql-ref-names-identifier-clause.html - "IdentifierClauseSegment".into(), + .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "HavingClauseTerminatorGrammar", + one_of(vec![ Sequence::new(vec![ - Ref::keyword("IDENTIFIER").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]).to_matchable(), + one_of(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("DISTRIBUTE").to_matchable(), + Ref::keyword("SORT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), + .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("QUALIFY").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "ArithmeticBinaryOperatorGrammar", + one_of(vec![ + Ref::new("PlusSegment").to_matchable(), + Ref::new("MinusSegment").to_matchable(), + Ref::new("DivideSegment").to_matchable(), + Ref::new("MultiplySegment").to_matchable(), + Ref::new("ModuloSegment").to_matchable(), + Ref::new("BitwiseAndSegment").to_matchable(), + Ref::new("BitwiseOrSegment").to_matchable(), + Ref::new("BitwiseXorSegment").to_matchable(), + Ref::new("BitwiseLShiftSegment").to_matchable(), + Ref::new("BitwiseRShiftSegment").to_matchable(), + Ref::new("DivBinaryOperatorSegment").to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "BinaryOperatorGrammar", + one_of(vec![ + Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(), + Ref::new("StringBinaryOperatorGrammar").to_matchable(), + Ref::new("BooleanBinaryOperatorGrammar").to_matchable(), + Ref::new("ComparisonOperatorGrammar").to_matchable(), + Ref::new("RightArrowOperator").to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "AccessorGrammar", + AnyNumberOf::new(vec![ + Ref::new("ArrayAccessorSegment").to_matchable(), + Ref::new("SemiStructuredAccessorSegment").to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "ObjectReferenceTerminatorGrammar", + one_of(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::keyword("USING").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("CastOperatorSegment").to_matchable(), + Ref::new("StartSquareBracketSegment").to_matchable(), + Ref::new("StartBracketSegment").to_matchable(), + Ref::new("BinaryOperatorGrammar").to_matchable(), + Ref::new("DelimiterGrammar").to_matchable(), + Ref::new("JoinLikeClauseGrammar").to_matchable(), + Ref::new("BracketedSegment").to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "FunctionContentsExpressionGrammar", + one_of(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("StarSegment").to_matchable(), + ]) + .to_matchable(), + ); + + sparksql_dialect.replace_grammar( + "NonWithNonSelectableGrammar", + ansi_dialect.grammar("NonWithNonSelectableGrammar").copy( + Some(vec![ + Ref::new("InsertOverwriteDirectorySegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, ), - ]); + ); + + sparksql_dialect.replace_grammar( + "ColumnGeneratedGrammar", + Sequence::new(vec![ + Ref::keyword("GENERATED").to_matchable(), + Ref::keyword("ALWAYS").to_matchable(), + Ref::keyword("AS").to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("FunctionSegment").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ); sparksql_dialect.add([ - ( - "FileLiteralSegment".into(), - TypedParser::new(SyntaxKind::FileLiteral, SyntaxKind::FileLiteral) - .to_matchable() - .into(), - ), ( "BackQuotedIdentifierSegment".into(), TypedParser::new(SyntaxKind::BackQuote, SyntaxKind::QuotedIdentifier) @@ -504,7 +558,7 @@ pub fn raw_dialect() -> Dialect { ), ( "NakedSemiStructuredElementSegment".into(), - RegexParser::new("[A-Z0-9_]*", SyntaxKind::SemiStructuredElement) + RegexParser::new(r#"[A-Z0-9_]*"#, SyntaxKind::SemiStructuredElement) .to_matchable() .into(), ), @@ -576,15 +630,27 @@ pub fn raw_dialect() -> Dialect { ), ( "FILE".into(), - MultiStringParser::new(vec!["FILE".into(), "FILES".into()], SyntaxKind::FileKeyword) - .to_matchable() - .into(), + MultiStringParser::new( + vec!["FILE", "FILES"] + .into_iter() + .map(String::from) + .collect::>(), + SyntaxKind::FileKeyword, + ) + .to_matchable() + .into(), ), ( "JAR".into(), - MultiStringParser::new(vec!["JAR".into(), "JARS".into()], SyntaxKind::FileKeyword) - .to_matchable() - .into(), + MultiStringParser::new( + vec!["JAR", "JARS"] + .into_iter() + .map(String::from) + .collect::>(), + SyntaxKind::FileKeyword, + ) + .to_matchable() + .into(), ), ( "NOSCAN".into(), @@ -633,12 +699,11 @@ pub fn raw_dialect() -> Dialect { Ref::new("EqualsSegment").optional().to_matchable(), one_of(vec![ Ref::new("LiteralGrammar").to_matchable(), - // when property value is Java Class Name Delimited::new(vec![ Ref::new("PropertiesNakedIdentifierSegment").to_matchable(), ]) - .config(|config| { - config.delimiter(Ref::new("DotSegment")); + .config(|this| { + this.delimiter(Ref::new("DotSegment")); }) .to_matchable(), ]) @@ -728,6 +793,92 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), + ( + "DescribeObjectGrammar".into(), + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("EXTENDED").optional().to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FUNCTION").to_matchable(), + Ref::keyword("EXTENDED").optional().to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLE").optional().to_matchable(), + Ref::keyword("EXTENDED").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("PartitionSpecGrammar").optional().to_matchable(), + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("DotSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + }) + .to_matchable(), + ]) + .config(|this| { + this.max_times(2); + }) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + this.disallow_gaps(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("QUERY").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("SELECT").to_matchable(), + Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + .to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + Ref::new("GroupByClauseSegment").optional().to_matchable(), + Ref::new("OrderByClauseSegment").optional().to_matchable(), + Ref::new("LimitClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + Ref::new("StatementSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.exclude = Some( + one_of(vec![ + Ref::keyword("HISTORY").to_matchable(), + Ref::keyword("DETAIL").to_matchable(), + ]) + .to_matchable(), + ); + }) + .to_matchable() + .into(), + ), ( "FileFormatGrammar".into(), one_of(vec![ @@ -774,6 +925,36 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), + ( + "InsertSourceGrammar".into(), + one_of(vec![ + AnyNumberOf::new(vec![Ref::new("ValuesClauseSegment").to_matchable()]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLE").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("SELECT").to_matchable(), + Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + .to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + Ref::new("GroupByClauseSegment").optional().to_matchable(), + Ref::new("OrderByClauseSegment").optional().to_matchable(), + Ref::new("LimitClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), ( "StartHintSegment".into(), StringParser::new("/*+", SyntaxKind::StartHint) @@ -864,16 +1045,16 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Sequence::new(vec![ Ref::keyword("AS").to_matchable(), Ref::new("NakedIdentifierSegment").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -883,7 +1064,7 @@ pub fn raw_dialect() -> Dialect { ( "PropertiesNakedIdentifierSegment".into(), RegexParser::new( - "[A-Z0-9]*[A-Z][A-Z0-9]*", + r#"[A-Z0-9]*[A-Z][A-Z0-9]*"#, SyntaxKind::PropertiesNakedIdentifier, ) .to_matchable() @@ -892,9 +1073,9 @@ pub fn raw_dialect() -> Dialect { ( "ResourceFileGrammar".into(), one_of(vec![ - Ref::new("JAR").to_matchable(), - Ref::new("WHL").to_matchable(), - Ref::new("FILE").to_matchable(), + Ref::keyword("JAR").to_matchable(), + Ref::keyword("WHL").to_matchable(), + Ref::keyword("FILE").to_matchable(), ]) .to_matchable() .into(), @@ -922,8 +1103,8 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("ASC").to_matchable(), Ref::keyword("DESC").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -933,8 +1114,8 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable() .into(), @@ -959,6 +1140,36 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), + ( + "CreateViewClausesGrammar".into(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + one_of(vec![ + Ref::keyword("BINDING").to_matchable(), + Ref::keyword("COMPENSATION").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TYPE").optional().to_matchable(), + Ref::keyword("EVOLUTION").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "RawQuotedLiteralSegment".into(), + one_of(vec![ + TypedParser::new(SyntaxKind::RawSingleQuote, SyntaxKind::RawQuotedLiteral) + .to_matchable(), + TypedParser::new(SyntaxKind::RawDoubleQuote, SyntaxKind::RawQuotedLiteral) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), ( "BytesQuotedLiteralSegment".into(), one_of(vec![ @@ -1027,7 +1238,7 @@ pub fn raw_dialect() -> Dialect { ), ( "WidgetNameIdentifierSegment".into(), - RegexParser::new("[A-Z][A-Z0-9_]*", SyntaxKind::WidgetNameIdentifier) + RegexParser::new(r#"[A-Z][A-Z0-9_]*"#, SyntaxKind::WidgetNameIdentifier) .to_matchable() .into(), ), @@ -1047,8 +1258,8 @@ pub fn raw_dialect() -> Dialect { Ref::new("OrReplaceGrammar").to_matchable(), Ref::new("OrRefreshGrammar").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Ref::new("TemporaryGrammar").optional().to_matchable(), @@ -1067,8 +1278,8 @@ pub fn raw_dialect() -> Dialect { Delimited::new(vec![ Sequence::new(vec![ one_of(vec![ - Ref::new("ColumnDefinitionSegment").to_matchable(), - Ref::new("GeneratedColumnDefinitionSegment").to_matchable(), + Ref::new("ColumnFieldDefinitionSegment").to_matchable(), + Ref::new("TableConstraintSegment").optional().to_matchable(), ]) .to_matchable(), Ref::new("CommentGrammar").optional().to_matchable(), @@ -1091,12 +1302,12 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Ref::new("UsingClauseSegment").optional().to_matchable(), - any_set_of(vec![ + AnyNumberOf::new(vec![ Ref::new("RowFormatClauseSegment").to_matchable(), Ref::new("StoredAsGrammar").to_matchable(), Ref::new("CommentGrammar").to_matchable(), @@ -1106,15 +1317,11 @@ pub fn raw_dialect() -> Dialect { Ref::new("LocationGrammar").to_matchable(), Ref::new("CommentGrammar").to_matchable(), Ref::new("TablePropertiesGrammar").to_matchable(), - Sequence::new(vec![ - Ref::keyword("CLUSTER").to_matchable(), - Ref::keyword("BY").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - ]) - .to_matchable(), + Ref::new("TableClusterByClauseSegment").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.max_times_per_element = Some(1); + this.optional(); }) .to_matchable(), Sequence::new(vec![ @@ -1122,46 +1329,253 @@ pub fn raw_dialect() -> Dialect { optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "FirstOrAfterGrammar".into(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AFTER").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "ShowDatabasesSchemasGrammar".into(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DATABASES").to_matchable(), + Ref::keyword("SCHEMAS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "ShowFunctionsGrammar".into(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("USER").to_matchable(), + Ref::keyword("SYSTEM").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("FUNCTIONS").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("DatabaseReferenceSegment").to_matchable(), + Ref::new("DotSegment").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + this.disallow_gaps(); + }) + .to_matchable(), + Ref::new("FunctionNameSegment").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "ShowTablesGrammar".into(), + Sequence::new(vec![ + Ref::keyword("TABLES").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("IN").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + .into(), + ), + ( + "ShowViewsGrammar".into(), + Sequence::new(vec![ + Ref::keyword("VIEWS").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("IN").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); }) .to_matchable(), ]) .to_matchable() .into(), ), + ( + "ShowObjectGrammar".into(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableExpressionSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + Ref::keyword("SERDE").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLUMNS").to_matchable(), + Ref::keyword("IN").to_matchable(), + Ref::new("TableExpressionSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("IN").to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("PARTITIONS").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("PartitionSpecGrammar").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("EXTENDED").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("IN").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("LIKE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("PartitionSpecGrammar").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TBLPROPERTIES").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedPropertyNameListGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable(), + Ref::new("ShowDatabasesSchemasGrammar").to_matchable(), + Ref::new("ShowFunctionsGrammar").to_matchable(), + Ref::new("ShowTablesGrammar").to_matchable(), + Ref::new("ShowViewsGrammar").to_matchable(), + ]) + .to_matchable() + .into(), + ), ]); sparksql_dialect.insert_lexer_matchers( - vec![Matcher::legacy( + vec![Matcher::string( "start_hint", - |s| s.starts_with("/*+"), - r"\/\*\+", + r#"/*+"#, SyntaxKind::StartHint, )], "block_comment", ); sparksql_dialect.insert_lexer_matchers( - vec![Matcher::regex("end_hint", r"\*\/", SyntaxKind::EndHint)], + vec![Matcher::string("end_hint", r#"*/"#, SyntaxKind::EndHint)], "single_quote", ); sparksql_dialect.insert_lexer_matchers( - vec![Matcher::string("end_hint", r"->", SyntaxKind::RightArrow)], + vec![Matcher::string( + "right_arrow", + r#"->"#, + SyntaxKind::RightArrow, + )], "like_operator", ); sparksql_dialect.add([ ( "SQLConfPropertiesSegment".into(), - NodeMatcher::new(SyntaxKind::SqlConfOption, |_| { + NodeMatcher::new(SyntaxKind::SqlConfOption, |_dialect| { Sequence::new(vec![ StringParser::new("-", SyntaxKind::Dash).to_matchable(), StringParser::new("v", SyntaxKind::SqlConfOption).to_matchable(), ]) - .config(|config| { - config.disallow_gaps(); + .config(|this| { + this.disallow_gaps(); }) .to_matchable() }) @@ -1170,7 +1584,7 @@ pub fn raw_dialect() -> Dialect { ), ( "DivBinaryOperatorSegment".into(), - NodeMatcher::new(SyntaxKind::BinaryOperator, |_| { + NodeMatcher::new(SyntaxKind::BinaryOperator, |_dialect| { Ref::keyword("DIV").to_matchable() }) .to_matchable() @@ -1178,10 +1592,10 @@ pub fn raw_dialect() -> Dialect { ), ( "QualifyClauseSegment".into(), - NodeMatcher::new(SyntaxKind::QualifyClause, |_| { + NodeMatcher::new(SyntaxKind::QualifyClause, |_dialect| { Sequence::new(vec![ Ref::keyword("QUALIFY").to_matchable(), - MetaSegment::indent().to_matchable(), + MetaSegment::implicit_indent().to_matchable(), optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) .to_matchable(), MetaSegment::dedent().to_matchable(), @@ -1191,12 +1605,33 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - sparksql_dialect.add([ + ( + "RowFormatClauseSegment".into(), + NodeMatcher::new(SyntaxKind::RowFormatClause, |_dialect| { + let dialect = super::hive::raw_dialect(); + dialect + .grammar("RowFormatClauseSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "SkewedByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SkewedByClause, |_dialect| { + let dialect = super::hive::raw_dialect(); + dialect + .grammar("SkewedByClauseSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), ( "PrimitiveTypeSegment".into(), - NodeMatcher::new(SyntaxKind::PrimitiveType, |_| { + NodeMatcher::new(SyntaxKind::PrimitiveType, |_dialect| { one_of(vec![ Ref::keyword("BOOLEAN").to_matchable(), Ref::keyword("TINYINT").to_matchable(), @@ -1237,33 +1672,70 @@ pub fn raw_dialect() -> Dialect { ), ( "ArrayTypeSegment".into(), - hive_dialect.grammar("ArrayTypeSegment").into(), + NodeMatcher::new(SyntaxKind::ArrayType, |_dialect| { + let dialect = super::hive::raw_dialect(); + dialect + .grammar("ArrayTypeSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), ), ( "StructTypeSegment".into(), - hive_dialect.grammar("StructTypeSegment").into(), + NodeMatcher::new(SyntaxKind::StructType, |_dialect| { + let dialect = super::hive::raw_dialect(); + dialect + .grammar("StructTypeSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), ), ( "StructTypeSchemaSegment".into(), - hive_dialect.grammar("StructTypeSchemaSegment").into(), - ), - ]); - - sparksql_dialect.add([ - ( - "SemiStructuredAccessorSegment".into(), - NodeMatcher::new(SyntaxKind::SemiStructuredExpression, |_| { - Sequence::new(vec![ - Ref::new("ColonSegment").to_matchable(), - one_of(vec![ - Ref::new("NakedSemiStructuredElementSegment").to_matchable(), - Bracketed::new(vec![ - Ref::new("QuotedSemiStructuredElementSegment").to_matchable(), - ]) - .config(|config| { - config.bracket_type = "square"; - }) - .to_matchable(), + NodeMatcher::new(SyntaxKind::StructTypeSchema, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ColonSegment").optional().to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.bracket_type("angle"); + this.bracket_pairs_set = "angle_bracket_pairs"; + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SemiStructuredAccessorSegment".into(), + NodeMatcher::new(SyntaxKind::SemiStructuredExpression, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::new("DotSegment").to_matchable(), + Ref::new("ColonSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::new("NakedSemiStructuredElementSegment").to_matchable(), + Bracketed::new(vec![ + Ref::new("QuotedSemiStructuredElementSegment").to_matchable(), + ]) + .config(|this| { + this.bracket_type("square"); + }) + .to_matchable(), ]) .to_matchable(), Ref::new("ArrayAccessorSegment").optional().to_matchable(), @@ -1279,8 +1751,8 @@ pub fn raw_dialect() -> Dialect { Bracketed::new(vec![ Ref::new("QuotedSemiStructuredElementSegment").to_matchable(), ]) - .config(|config| { - config.bracket_type = "square"; + .config(|this| { + this.bracket_type("square"); }) .to_matchable(), ]) @@ -1298,7 +1770,7 @@ pub fn raw_dialect() -> Dialect { ), ( "DatatypeSegment".into(), - NodeMatcher::new(SyntaxKind::DataType, |_| { + NodeMatcher::new(SyntaxKind::DataType, |_dialect| { one_of(vec![ Ref::new("PrimitiveTypeSegment").to_matchable(), Ref::new("ArrayTypeSegment").to_matchable(), @@ -1312,9 +1784,9 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.bracket_pairs_set = "angle_bracket_pairs"; - config.bracket_type = "angle"; + .config(|this| { + this.bracket_type("angle"); + this.bracket_pairs_set = "angle_bracket_pairs"; }) .to_matchable(), ]) @@ -1327,10 +1799,8 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - // An `ALTER DATABASE/SCHEMA` statement. - // http://spark.apache.org/docs/latest/sql-ref-syntax-ddl-alter-database.html "AlterDatabaseStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterDatabaseStatement, |_| { + NodeMatcher::new(SyntaxKind::AlterDatabaseStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ALTER").to_matchable(), one_of(vec![ @@ -1352,513 +1822,442 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - // A `SET VARIABLE` statement used to set session variables. - // https://spark.apache.org/docs/4.0.0-preview2/sql-ref-syntax-aux-set-var.html - "SetVariableStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - one_of(vec![ - Ref::keyword("VAR").to_matchable(), - Ref::keyword("VARIABLE").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - one_of(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .allow_gaps(true) - .to_matchable() - .into(), - ), - ]); - - sparksql_dialect.replace_grammar( - "AlterTableStatementSegment", - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ + "AlterTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTableStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("TABLE").to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("PartitionSpecGrammar").to_matchable(), - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("PartitionSpecGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - one_of(vec![ - Ref::keyword("COLUMNS").to_matchable(), - Ref::keyword("COLUMN").to_matchable(), - ]) - .to_matchable(), MetaSegment::indent().to_matchable(), - optionally_bracketed(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ColumnFieldDefinitionSegment").to_matchable(), - one_of(vec![ - Ref::keyword("FIRST").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("PartitionSpecGrammar").to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("PartitionSpecGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + one_of(vec![ + Ref::keyword("COLUMNS").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + ]) + .to_matchable(), + MetaSegment::indent().to_matchable(), + optionally_bracketed(vec![ + Delimited::new(vec![ Sequence::new(vec![ - Ref::keyword("AFTER").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ColumnFieldDefinitionSegment").to_matchable(), + Ref::new("FirstOrAfterGrammar").optional().to_matchable(), ]) .to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), ]) .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("CHANGE").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - MetaSegment::indent().to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("ColumnReferenceSegment") - .exclude(one_of(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::keyword("TYPE").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("AFTER").to_matchable(), - Ref::keyword("SET").to_matchable(), - Ref::keyword("DROP").to_matchable(), - ])) - .config(|config| { - config.exclude = one_of(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::keyword("TYPE").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("AFTER").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("CHANGE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("COLUMN").optional().to_matchable(), + MetaSegment::indent().to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("ColumnReferenceSegment") + .exclude(one_of(vec![ + Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("AFTER").to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("DROP").to_matchable(), + ])) + .to_matchable(), + ]) + .config(|this| { + this.max_times(2); + }) + .to_matchable(), + Ref::keyword("TYPE").optional().to_matchable(), + Ref::new("DatatypeSegment").optional().to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + Ref::new("FirstOrAfterGrammar").optional().to_matchable(), + Sequence::new(vec![ + one_of(vec![ Ref::keyword("SET").to_matchable(), Ref::keyword("DROP").to_matchable(), ]) - .to_matchable() - .into(); + .to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .config(|this| { + this.optional(); }) .to_matchable(), - ]) - .config(|config| { - config.max_times = Some(2); - }) - .to_matchable(), - Ref::keyword("TYPE").optional().to_matchable(), - Ref::new("DatatypeSegment").optional().to_matchable(), - Ref::new("CommentGrammar").optional().to_matchable(), - one_of(vec![ - Ref::keyword("FIRST").to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable(), Sequence::new(vec![ - Ref::keyword("AFTER").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("REPLACE").to_matchable(), + Ref::keyword("COLUMNS").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnDefinitionSegment").to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("SET").to_matchable(), + Sequence::new(vec![ Ref::keyword("DROP").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLUMNS").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + AnyNumberOf::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Ref::keyword("NOT").to_matchable(), - Ref::keyword("NULL").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("REPLACE").to_matchable(), - Ref::keyword("COLUMNS").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ColumnDefinitionSegment").to_matchable(), - Ref::new("CommentGrammar").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("PartitionSpecGrammar").to_matchable(), + Ref::new("PartitionFieldGrammar").to_matchable(), ]) + .config(|this| { + this.min_times(1); + }) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - one_of(vec![ Sequence::new(vec![ - Ref::keyword("COLUMN").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + one_of(vec![ + Ref::new("PartitionSpecGrammar").to_matchable(), + Ref::new("PartitionFieldGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![Ref::keyword("PURGE").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("COLUMNS").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - AnyNumberOf::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("REPLACE").to_matchable(), + Ref::new("PartitionFieldGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RECOVER").to_matchable(), + Ref::keyword("PARTITIONS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("TablePropertiesGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("UnsetTablePropertiesGrammar").to_matchable(), + Sequence::new(vec![ + Ref::new("PartitionSpecGrammar").optional().to_matchable(), + Ref::keyword("SET").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SERDEPROPERTIES").to_matchable(), + Ref::new("BracketedPropertyListGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SERDE").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("SerdePropertiesGrammar").optional().to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("PartitionSpecGrammar").to_matchable(), - Ref::new("PartitionFieldGrammar").to_matchable(), - ]) - .config(|config| { - config.min_times = 1; - }) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - one_of(vec![ - Ref::new("PartitionSpecGrammar").to_matchable(), - Ref::new("PartitionFieldGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![Ref::keyword("PURGE").to_matchable()]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("REPLACE").to_matchable(), - Ref::new("PartitionFieldGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RECOVER").to_matchable(), - Ref::keyword("PARTITIONS").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("TablePropertiesGrammar").to_matchable(), - ]) - .to_matchable(), - Ref::new("UnsetTablePropertiesGrammar").to_matchable(), - Sequence::new(vec![ - Ref::new("PartitionSpecGrammar").optional().to_matchable(), - Ref::keyword("SET").to_matchable(), - one_of(vec![ Sequence::new(vec![ - Ref::keyword("SERDEPROPERTIES").to_matchable(), - Ref::new("BracketedPropertyListGrammar").to_matchable(), + Ref::new("PartitionSpecGrammar").optional().to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::keyword("FILEFORMAT").to_matchable(), + Ref::new("DataSourceFormatSegment").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("SERDE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("SerdePropertiesGrammar").optional().to_matchable(), + Ref::new("PartitionSpecGrammar").optional().to_matchable(), + Ref::keyword("SET").to_matchable(), + Ref::new("LocationGrammar").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("PartitionSpecGrammar").optional().to_matchable(), - Ref::keyword("SET").to_matchable(), - Ref::keyword("FILEFORMAT").to_matchable(), - Ref::new("DataSourceFormatSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("PartitionSpecGrammar").optional().to_matchable(), - Ref::keyword("SET").to_matchable(), - Ref::new("LocationGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - MetaSegment::indent().to_matchable(), - one_of(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("DROP").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ColumnReferenceSegment") - .exclude(Ref::keyword("CHECK")) - .config(|config| { - config.exclude = Ref::keyword("CHECK").to_matchable().into(); - }) - .to_matchable(), - Ref::keyword("CHECK").optional().to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WRITE").to_matchable(), - AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::keyword("DISTRIBUTED").to_matchable(), - Ref::keyword("BY").to_matchable(), - Ref::keyword("PARTITION").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("DROP").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ColumnReferenceSegment") + .exclude(Ref::keyword("CHECK")) + .to_matchable(), + Ref::keyword("CHECK").optional().to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("LOCALLY").optional().to_matchable(), - Ref::keyword("ORDERED").to_matchable(), - Ref::keyword("BY").to_matchable(), - MetaSegment::indent().to_matchable(), - Delimited::new(vec![ + Ref::keyword("WRITE").to_matchable(), + AnyNumberOf::new(vec![ Sequence::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - one_of(vec![ - Ref::keyword("ASC").to_matchable(), - Ref::keyword("DESC").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("NULLS").to_matchable(), - one_of(vec![ - Ref::keyword("FIRST").to_matchable(), - Ref::keyword("LAST").to_matchable(), + Ref::keyword("DISTRIBUTED").to_matchable(), + Ref::keyword("BY").to_matchable(), + Ref::keyword("PARTITION").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("LOCALLY").optional().to_matchable(), + Ref::keyword("ORDERED").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + one_of(vec![ + Ref::keyword("ASC").to_matchable(), + Ref::keyword("DESC").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("NULLS").to_matchable(), + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("LAST").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.min_times(1); }) .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("IDENTIFIER").to_matchable(), + Ref::keyword("FIELDS").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("IDENTIFIER").to_matchable(), + Ref::keyword("FIELDS").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), MetaSegment::dedent().to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), ]) - .config(|config| { - config.min_times = 1; - config.max_times_per_element = Some(1); - }) .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ColumnFieldDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnDefinition, |_dialect| { Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::keyword("IDENTIFIER").to_matchable(), - Ref::keyword("FIELDS").to_matchable(), - MetaSegment::indent().to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Bracketed::new(vec![Anything::new().to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("ColumnConstraintSegment") + .optional() .to_matchable(), ]) .to_matchable(), - MetaSegment::dedent().to_matchable(), ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableClusterByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::TableClusterByClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("IDENTIFIER").to_matchable(), - Ref::keyword("FIELDS").to_matchable(), + Ref::keyword("CLUSTER").to_matchable(), + Ref::keyword("BY").to_matchable(), MetaSegment::indent().to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .to_matchable(), + one_of(vec![ + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::keyword("NONE").to_matchable(), ]) .to_matchable(), MetaSegment::dedent().to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - ); - - sparksql_dialect.add([( - "ColumnFieldDefinitionSegment".into(), - NodeMatcher::new(SyntaxKind::ColumnDefinition, |_| { - Sequence::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Bracketed::new(vec![Anything::new().to_matchable()]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("ColumnConstraintSegment") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - sparksql_dialect.add([( - "AlterViewStatementSegment".into(), - NodeMatcher::new(SyntaxKind::AlterViewStatement, |_| { - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("TablePropertiesGrammar").to_matchable(), - ]) - .to_matchable(), - Ref::new("UnsetTablePropertiesGrammar").to_matchable(), - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - optionally_bracketed(vec![ - Ref::new("SelectStatementSegment").to_matchable(), + .into(), + ), + ( + "AlterViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("TablePropertiesGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("UnsetTablePropertiesGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![ + Ref::new("SelectStatementSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - sparksql_dialect.add([( - "JoinLikeClauseGrammar".into(), - Sequence::new(vec![ - one_of(vec![ - Ref::new("PivotClauseSegment").to_matchable(), - Ref::new("UnpivotClauseSegment").to_matchable(), - Ref::new("LateralViewClauseSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), - ]) - .to_matchable() - .into(), - )]); - - sparksql_dialect.add([ - // An Unpivot segment. - // https://spark.apache.org/docs/latest/sql-ref-syntax-qry-select-unpivot.html + .into(), + ), ( - "UnpivotClauseSegment".into(), - NodeMatcher::new(SyntaxKind::UnpivotClause, |_| { + "CreateDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateDatabaseStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("UNPIVOT").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("INCLUDE").to_matchable(), - Ref::keyword("EXCLUDE").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("NULLS").to_matchable(), + Ref::keyword("CREATE").to_matchable(), + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), - MetaSegment::indent().to_matchable(), - Bracketed::new(vec![ - one_of(vec![ - Ref::new("SingleValueColumnUnpivotSegment").to_matchable(), - Ref::new("MultiValueColumnUnpivotSegment").to_matchable(), - ]) - .to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + Ref::new("LocationGrammar").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("DBPROPERTIES").to_matchable(), + Ref::new("BracketedPropertyListGrammar").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - MetaSegment::dedent().to_matchable(), ]) .to_matchable() }) @@ -1866,224 +2265,154 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "SingleValueColumnUnpivotSegment".into(), - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("FOR").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("IN").to_matchable(), + "FunctionParameterListGrammarWithComments".into(), + NodeMatcher::new(SyntaxKind::FunctionParameterListWithComments, |_dialect| { Bracketed::new(vec![ - MetaSegment::indent().to_matchable(), Delimited::new(vec![ Sequence::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), + Ref::new("FunctionParameterGrammar").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("CommentClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - MetaSegment::dedent().to_matchable(), ]) - .config(|config| { - config.parse_mode = ParseMode::Greedy; - }) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - "MultiValueColumnUnpivotSegment".into(), - Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) + "CreateFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateFunctionStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("FunctionNameIdentifierSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("ResourceLocationGrammar") + .optional() .to_matchable(), ]) - .to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::keyword("FOR").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::keyword("IN").to_matchable(), - Bracketed::new(vec![ - MetaSegment::indent().to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Bracketed::new(vec![ - MetaSegment::indent().to_matchable(), - Delimited::new(vec![ + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("TableDefinitionSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + one_of(vec![ + Ref::new("OrReplaceGrammar").to_matchable(), + Ref::new("OrRefreshGrammar").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + Ref::keyword("STREAMING").optional().to_matchable(), + Ref::keyword("LIVE").optional().to_matchable(), + Ref::keyword("MATERIALIZED").optional().to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("DatatypeSegment").optional().to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), ]) .to_matchable(), + Ref::new("ConstraintStatementSegment") + .optional() + .to_matchable(), ]) .to_matchable(), - Ref::new("AliasExpressionSegment").optional().to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - ]) - .config(|config| { - config.parse_mode = ParseMode::Greedy; - }) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable() - .into(), - ), - ]); - - sparksql_dialect.replace_grammar( - "CreateDatabaseStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - one_of(vec![ - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - ]) - .to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - Ref::new("CommentGrammar").optional().to_matchable(), - Ref::new("LocationGrammar").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("DBPROPERTIES").to_matchable(), - Ref::new("BracketedPropertyListGrammar").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), - ); - - sparksql_dialect.replace_grammar( - "CreateFunctionStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Ref::new("TemporaryGrammar").optional().to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("FunctionNameIdentifierSegment").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("ResourceLocationGrammar") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ); - - sparksql_dialect.replace_grammar( - "CreateTableStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("TableDefinitionSegment").to_matchable(), - ]) - .to_matchable(), - ); - - sparksql_dialect.add([( - "CreateHiveFormatTableStatementSegment".into(), - hive_dialect.grammar("CreateTableStatementSegment").into(), - )]); - - sparksql_dialect.add([( - "NonWithNonSelectableGrammar".into(), - ansi::raw_dialect() - .grammar("NonWithNonSelectableGrammar") - .copy( - Some(vec![ - Ref::new("InsertOverwriteDirectorySegment").to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ) - .into(), - )]); - - sparksql_dialect.replace_grammar( - "CreateViewStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - one_of(vec![ - Ref::new("OrReplaceGrammar").to_matchable(), - Ref::new("OrRefreshGrammar").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Ref::new("TemporaryGrammar").optional().to_matchable(), - Ref::keyword("STREAMING").optional().to_matchable(), - Ref::keyword("LIVE").optional().to_matchable(), - Ref::keyword("MATERIALIZED").optional().to_matchable(), - Ref::keyword("VIEW").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("CommentGrammar").optional().to_matchable(), - ]) + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Ref::new("DataSourceFormatSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("OptionsGrammar").optional().to_matchable(), + one_of(vec![ + Ref::new("PartitionSpecGrammar").to_matchable(), + Ref::new("TableClusterByClauseSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("CommentGrammar").optional().to_matchable(), + Ref::new("TablePropertiesGrammar").optional().to_matchable(), + Ref::new("CreateViewClausesGrammar") + .optional() .to_matchable(), - Ref::new("ConstraintStatementSegment") - .optional() + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::new("WithNoSchemaBindingClauseSegment") + .optional() + .to_matchable(), ]) - .to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Ref::new("DataSourceFormatSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Ref::new("OptionsGrammar").optional().to_matchable(), - Ref::new("CommentGrammar").optional().to_matchable(), - Ref::new("TablePropertiesGrammar").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) - .to_matchable(), - ]) - .config(|config| { - config.optional(); + .to_matchable() }) - .to_matchable(), - Ref::new("WithNoSchemaBindingClauseSegment") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ); - sparksql_dialect.add([ + .to_matchable() + .into(), + ), ( "CreateWidgetStatementSegment".into(), - NodeMatcher::new(SyntaxKind::CreateWidgetStatement, |_| { + NodeMatcher::new(SyntaxKind::CreateWidgetStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CREATE").to_matchable(), Ref::keyword("WIDGET").to_matchable(), @@ -2115,7 +2444,7 @@ pub fn raw_dialect() -> Dialect { ), ( "ReplaceTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ReplaceTableStatement, |_| { + NodeMatcher::new(SyntaxKind::ReplaceTableStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("REPLACE").to_matchable(), Ref::new("TableDefinitionSegment").to_matchable(), @@ -2127,7 +2456,7 @@ pub fn raw_dialect() -> Dialect { ), ( "RemoveWidgetStatementSegment".into(), - NodeMatcher::new(SyntaxKind::RemoveWidgetStatement, |_| { + NodeMatcher::new(SyntaxKind::RemoveWidgetStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("REMOVE").to_matchable(), Ref::keyword("WIDGET").to_matchable(), @@ -2138,63 +2467,60 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - sparksql_dialect.replace_grammar( - "DropDatabaseStatementSegment", - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - one_of(vec![ - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - ]) - .to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - Ref::new("DropBehaviorGrammar").optional().to_matchable(), - ]) - .to_matchable(), - ); - sparksql_dialect.add([( - "DropFunctionStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::new("TemporaryGrammar").optional().to_matchable(), - Ref::keyword("FUNCTION").to_matchable(), - Ref::new("IfExistsGrammar").optional().to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - ]) + ( + "DropDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropDatabaseStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + one_of(vec![ + Ref::keyword("DATABASE").to_matchable(), + Ref::keyword("SCHEMA").to_matchable(), + ]) + .to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + Ref::new("DropBehaviorGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - sparksql_dialect.add([( - "MsckRepairTableStatementSegment".into(), - hive_dialect - .grammar("MsckRepairTableStatementSegment") .into(), - )]); - - sparksql_dialect.replace_grammar( - "TruncateStatementSegment", - Sequence::new(vec![ - Ref::keyword("TRUNCATE").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("PartitionSpecGrammar").optional().to_matchable(), - ]) - .to_matchable(), - ); - sparksql_dialect.add([ + ), ( - "UseDatabaseStatementSegment".into(), - NodeMatcher::new(SyntaxKind::UseDatabaseStatement, |_| { + "DropFunctionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DropFunctionStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("USE").to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), + Ref::keyword("DROP").to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + Ref::keyword("FUNCTION").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MsckRepairTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::MsckRepairTableStatement, |_dialect| { + let dialect = super::hive::raw_dialect(); + dialect + .grammar("MsckRepairTableStatementSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "TruncateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::TruncateStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("TRUNCATE").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("PartitionSpecGrammar").optional().to_matchable(), ]) .to_matchable() }) @@ -2202,14 +2528,20 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "InsertBracketedColumnReferenceListGrammar".into(), - Ref::new("BracketedColumnReferenceListGrammar") + "UseDatabaseStatementSegment".into(), + NodeMatcher::new(SyntaxKind::UseDatabaseStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("USE").to_matchable(), + Ref::new("DatabaseReferenceSegment").to_matchable(), + ]) .to_matchable() - .into(), + }) + .to_matchable() + .into(), ), ( "InsertStatementSegment".into(), - NodeMatcher::new(SyntaxKind::InsertStatement, |_| { + NodeMatcher::new(SyntaxKind::InsertStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("INSERT").to_matchable(), one_of(vec![ @@ -2219,32 +2551,26 @@ pub fn raw_dialect() -> Dialect { .to_matchable(), Ref::keyword("TABLE").optional().to_matchable(), Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("PartitionSpecGrammar").optional().to_matchable(), - Ref::new("InsertBracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), one_of(vec![ - AnyNumberOf::new(vec![Ref::new("ValuesClauseSegment").to_matchable()]) - .config(|config| { - config.min_times = 1; - }) - .to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), Sequence::new(vec![ - Ref::keyword("TABLE").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("PartitionSpecGrammar").optional().to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + Ref::new("InsertSourceGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::keyword("SELECT").to_matchable(), - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), - Ref::new("GroupByClauseSegment").optional().to_matchable(), - Ref::new("OrderByClauseSegment").optional().to_matchable(), - Ref::new("LimitClauseSegment").optional().to_matchable(), + Ref::keyword("REPLACE").to_matchable(), + Ref::new("WhereClauseSegment").to_matchable(), + Ref::new("InsertSourceGrammar").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REPLACE").to_matchable(), + Ref::keyword("USING").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::new("InsertSourceGrammar").to_matchable(), ]) .to_matchable(), ]) @@ -2257,7 +2583,7 @@ pub fn raw_dialect() -> Dialect { ), ( "InsertOverwriteDirectorySegment".into(), - NodeMatcher::new(SyntaxKind::InsertOverwriteDirectoryStatement, |_| { + NodeMatcher::new(SyntaxKind::InsertOverwriteDirectoryStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("INSERT").to_matchable(), Ref::keyword("OVERWRITE").to_matchable(), @@ -2269,8 +2595,8 @@ pub fn raw_dialect() -> Dialect { Ref::new("OptionsGrammar").optional().to_matchable(), one_of(vec![ AnyNumberOf::new(vec![Ref::new("ValuesClauseSegment").to_matchable()]) - .config(|config| { - config.min_times = 1; + .config(|this| { + this.min_times(1); }) .to_matchable(), Ref::new("SelectableGrammar").to_matchable(), @@ -2284,33 +2610,36 @@ pub fn raw_dialect() -> Dialect { ), ( "InsertOverwriteDirectoryHiveFmtSegment".into(), - NodeMatcher::new(SyntaxKind::InsertOverwriteDirectoryHiveFmtStatement, |_| { - Sequence::new(vec![ - Ref::keyword("INSERT").to_matchable(), - Ref::keyword("OVERWRITE").to_matchable(), - Ref::keyword("LOCAL").optional().to_matchable(), - Ref::keyword("DIRECTORY").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("RowFormatClauseSegment").optional().to_matchable(), - Ref::new("StoredAsGrammar").optional().to_matchable(), - one_of(vec![ - AnyNumberOf::new(vec![Ref::new("ValuesClauseSegment").to_matchable()]) - .config(|config| { - config.min_times = 1; - }) - .to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), + NodeMatcher::new( + SyntaxKind::InsertOverwriteDirectoryHiveFmtStatement, + |_dialect| { + Sequence::new(vec![ + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("OVERWRITE").to_matchable(), + Ref::keyword("LOCAL").optional().to_matchable(), + Ref::keyword("DIRECTORY").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("RowFormatClauseSegment").optional().to_matchable(), + Ref::new("StoredAsGrammar").optional().to_matchable(), + one_of(vec![ + AnyNumberOf::new(vec![Ref::new("ValuesClauseSegment").to_matchable()]) + .config(|this| { + this.min_times(1); + }) + .to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable() - }) + .to_matchable() + }, + ) .to_matchable() .into(), ), ( "LoadDataSegment".into(), - NodeMatcher::new(SyntaxKind::LoadDataStatement, |_| { + NodeMatcher::new(SyntaxKind::LoadDataStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("LOAD").to_matchable(), Ref::keyword("DATA").to_matchable(), @@ -2330,7 +2659,7 @@ pub fn raw_dialect() -> Dialect { ), ( "ClusterByClauseSegment".into(), - NodeMatcher::new(SyntaxKind::ClusterByClause, |_| { + NodeMatcher::new(SyntaxKind::ClusterByClause, |_dialect| { Sequence::new(vec![ Ref::keyword("CLUSTER").to_matchable(), Ref::keyword("BY").to_matchable(), @@ -2346,8 +2675,8 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.terminators = vec![ + .config(|this| { + this.terminators = vec![ Ref::keyword("LIMIT").to_matchable(), Ref::keyword("HAVING").to_matchable(), Ref::keyword("WINDOW").to_matchable(), @@ -2365,7 +2694,7 @@ pub fn raw_dialect() -> Dialect { ), ( "DistributeByClauseSegment".into(), - NodeMatcher::new(SyntaxKind::DistributeByClause, |_| { + NodeMatcher::new(SyntaxKind::DistributeByClause, |_dialect| { Sequence::new(vec![ Ref::keyword("DISTRIBUTE").to_matchable(), Ref::keyword("BY").to_matchable(), @@ -2381,8 +2710,8 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.terminators = vec![ + .config(|this| { + this.terminators = vec![ Ref::keyword("SORT").to_matchable(), Ref::keyword("LIMIT").to_matchable(), Ref::keyword("HAVING").to_matchable(), @@ -2401,28 +2730,12 @@ pub fn raw_dialect() -> Dialect { ), ( "HintFunctionSegment".into(), - NodeMatcher::new(SyntaxKind::HintFunction, |_| { + NodeMatcher::new(SyntaxKind::HintFunction, |_dialect| { Sequence::new(vec![ Ref::new("FunctionNameSegment").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - AnyNumberOf::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .config(|config| { - config.min_times = 1; - }) - .to_matchable(), - ]) + Ref::new("FunctionContentsSegment") + .optional() .to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), ]) .to_matchable() }) @@ -2431,19 +2744,19 @@ pub fn raw_dialect() -> Dialect { ), ( "SelectHintSegment".into(), - NodeMatcher::new(SyntaxKind::SelectHint, |_| { + NodeMatcher::new(SyntaxKind::SelectHint, |_dialect| { Sequence::new(vec![ Sequence::new(vec![ Ref::new("StartHintSegment").to_matchable(), Delimited::new(vec![ AnyNumberOf::new(vec![Ref::new("HintFunctionSegment").to_matchable()]) - .config(|config| { - config.min_times = 1; + .config(|this| { + this.min_times(1); }) .to_matchable(), ]) - .config(|config| { - config.terminators = vec![Ref::new("EndHintSegment").to_matchable()]; + .config(|this| { + this.terminators = vec![Ref::new("EndHintSegment").to_matchable()]; }) .to_matchable(), Ref::new("EndHintSegment").to_matchable(), @@ -2455,172 +2768,199 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - sparksql_dialect.replace_grammar( - "LimitClauseSegment", - Sequence::new(vec![ - Ref::keyword("LIMIT").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::keyword("ALL").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - ); - - sparksql_dialect.replace_grammar( - "SetOperatorSegment", - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("EXCEPT").to_matchable(), - Ref::keyword("MINUS").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("ALL").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("UNION").to_matchable(), - Ref::keyword("INTERSECT").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("DISTINCT").to_matchable(), - Ref::keyword("ALL").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|config| { - config.exclude = Some( + ( + "LimitClauseSegment".into(), + NodeMatcher::new(SyntaxKind::LimitClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("EXCEPT").to_matchable(), - Bracketed::new(vec![Anything::new().to_matchable()]).to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("ALL").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .to_matchable(), - ) - }) - .to_matchable(), - ); - - sparksql_dialect.replace_grammar( - "SelectClauseModifierSegment", - Sequence::new(vec![ - Ref::new("SelectHintSegment").optional().to_matchable(), - one_of(vec![ - Ref::keyword("DISTINCT").to_matchable(), - Ref::keyword("ALL").to_matchable(), - ]) - .config(|config| { - config.optional(); + .to_matchable() }) - .to_matchable(), - ]) - .to_matchable(), - ); - - sparksql_dialect.replace_grammar( - "UnorderedSelectStatementSegment", - ansi::get_unordered_select_statement_segment_grammar().copy( - Some(vec![ - Ref::new("QualifyClauseSegment").optional().to_matchable(), - Ref::new("ClusterByClauseSegment").optional().to_matchable(), - Ref::new("DistributeByClauseSegment") - .optional() - .to_matchable(), - Ref::new("SortByClauseSegment").optional().to_matchable(), - ]), - None, - None, - Some(vec![ - Ref::new("OverlapsClauseSegment").optional().to_matchable(), - ]), - Vec::new(), - false, + .to_matchable() + .into(), ), - ); - - sparksql_dialect.replace_grammar( - "SelectStatementSegment", - ansi::select_statement() - .copy( - Some(vec![ - Ref::new("ClusterByClauseSegment").optional().to_matchable(), - Ref::new("DistributeByClauseSegment") - .optional() + ( + "SetOperatorSegment".into(), + NodeMatcher::new(SyntaxKind::SetOperator, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("EXCEPT").to_matchable(), + Ref::keyword("MINUS").to_matchable(), + ]) .to_matchable(), - Ref::new("SortByClauseSegment").optional().to_matchable(), - ]), - None, - Some(Ref::new("LimitClauseSegment").optional().to_matchable()), - None, - Vec::new(), - false, - ) - .copy( - Some(vec![ - Ref::new("QualifyClauseSegment").optional().to_matchable(), - ]), - None, - Some(Ref::new("OrderByClauseSegment").optional().to_matchable()), - None, - Vec::new(), - false, - ), - ); - - sparksql_dialect.replace_grammar( - // Enhance `GROUP BY` clause like in `SELECT` for 'CUBE' and 'ROLLUP`. - // https://spark.apache.org/docs/latest/sql-ref-syntax-qry-select-groupby.html - "GroupByClauseSegment", - Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ - Delimited::new(vec![ - Ref::new("CubeRollupClauseSegment").to_matchable(), - Ref::new("GroupingSetsClauseSegment").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("ALL").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("UNION").to_matchable(), + Ref::keyword("INTERSECT").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("DISTINCT").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), ]) - .to_matchable(), + .config(|this| { + this.exclude = Some( + Sequence::new(vec![ + Ref::keyword("EXCEPT").to_matchable(), + Bracketed::new(vec![Anything::new().to_matchable()]).to_matchable(), + ]) + .to_matchable(), + ); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SelectClauseModifierSegment".into(), + NodeMatcher::new(SyntaxKind::SelectClauseModifier, |_dialect| { Sequence::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::new("SelectHintSegment").optional().to_matchable(), + one_of(vec![ + Ref::keyword("DISTINCT").to_matchable(), + Ref::keyword("ALL").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UnorderedSelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("UnorderedSelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("QualifyClauseSegment").optional().to_matchable(), + Ref::new("ClusterByClauseSegment").optional().to_matchable(), + Ref::new("DistributeByClauseSegment") + .optional() + .to_matchable(), + Ref::new("SortByClauseSegment").optional().to_matchable(), + ]), + None, + None, + Some(vec![ + Ref::new("OverlapsClauseSegment").optional().to_matchable(), + ]), + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "SelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("SelectStatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("ClusterByClauseSegment").optional().to_matchable(), + Ref::new("DistributeByClauseSegment") + .optional() + .to_matchable(), + Ref::new("SortByClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("LimitClauseSegment").optional().to_matchable()), + None, + vec![], + false, + ) + .copy( + Some(vec![ + Ref::new("QualifyClauseSegment").optional().to_matchable(), + ]), + None, + Some(Ref::new("OrderByClauseSegment").optional().to_matchable()), + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "GroupByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::GroupbyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), one_of(vec![ - Ref::new("WithCubeRollupClauseSegment").to_matchable(), - Ref::new("GroupingSetsClauseSegment").to_matchable(), + Delimited::new(vec![ + Ref::new("CubeRollupClauseSegment").to_matchable(), + Ref::new("GroupingSetsClauseSegment").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::new("WithCubeRollupClauseSegment").to_matchable(), + Ref::new("GroupingSetsClauseSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - ); - sparksql_dialect.add([ + .to_matchable() + }) + .to_matchable() + .into(), + ), ( "WithCubeRollupClauseSegment".into(), - NodeMatcher::new(SyntaxKind::WithCubeRollupClause, |_| { + NodeMatcher::new(SyntaxKind::WithCubeRollupClause, |_dialect| { Sequence::new(vec![ Ref::keyword("WITH").to_matchable(), one_of(vec![ @@ -2636,7 +2976,7 @@ pub fn raw_dialect() -> Dialect { ), ( "SortByClauseSegment".into(), - NodeMatcher::new(SyntaxKind::SortByClause, |_| { + NodeMatcher::new(SyntaxKind::SortByClause, |_dialect| { Sequence::new(vec![ Ref::keyword("SORT").to_matchable(), Ref::keyword("BY").to_matchable(), @@ -2653,8 +2993,8 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("ASC").to_matchable(), Ref::keyword("DESC").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Sequence::new(vec![ @@ -2665,15 +3005,15 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) .to_matchable(), ]) - .config(|config| { - config.terminators = vec![ + .config(|this| { + this.terminators = vec![ Ref::keyword("LIMIT").to_matchable(), Ref::keyword("HAVING").to_matchable(), Ref::keyword("QUALIFY").to_matchable(), @@ -2690,46 +3030,45 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - // A `TABLESAMPLE` clause following a table identifier. - // https://spark.apache.org/docs/latest/sql-ref-syntax-qry-select-sampling.html - sparksql_dialect.replace_grammar( - "SamplingExpressionSegment", - Sequence::new(vec![ - Ref::keyword("TABLESAMPLE").to_matchable(), - one_of(vec![ - Bracketed::new(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), + ( + "SamplingExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::SampleExpression, |_dialect| { + Sequence::new(vec![ + Ref::keyword("TABLESAMPLE").to_matchable(), one_of(vec![ - Ref::keyword("PERCENT").to_matchable(), - Ref::keyword("ROWS").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![ - Ref::keyword("BUCKET").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::keyword("OUT").to_matchable(), - Ref::keyword("OF").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), + Bracketed::new(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + one_of(vec![ + Ref::keyword("PERCENT").to_matchable(), + Ref::keyword("ROWS").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![ + Ref::keyword("BUCKET").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("OUT").to_matchable(), + Ref::keyword("OF").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - sparksql_dialect.add([ + .to_matchable() + }) + .to_matchable() + .into(), + ), ( "LateralViewClauseSegment".into(), - NodeMatcher::new(SyntaxKind::LateralViewClause, |_| { + NodeMatcher::new(SyntaxKind::LateralViewClause, |_dialect| { Sequence::new(vec![ + Ref::new("CommaSegment").optional().to_matchable(), MetaSegment::indent().to_matchable(), Ref::keyword("LATERAL").to_matchable(), - Ref::keyword("VIEW").to_matchable(), + Ref::keyword("VIEW").optional().to_matchable(), Ref::keyword("OUTER").optional().to_matchable(), Ref::new("FunctionSegment").to_matchable(), one_of(vec![ @@ -2742,8 +3081,8 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -2767,7 +3106,7 @@ pub fn raw_dialect() -> Dialect { ), ( "PivotClauseSegment".into(), - NodeMatcher::new(SyntaxKind::PivotClause, |_| { + NodeMatcher::new(SyntaxKind::PivotClause, |_dialect| { Sequence::new(vec![ MetaSegment::indent().to_matchable(), Ref::keyword("PIVOT").to_matchable(), @@ -2804,8 +3143,8 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.parse_mode(ParseMode::Greedy); + .config(|this| { + this.parse_mode(ParseMode::Greedy); }) .to_matchable(), Delimited::new(vec![ @@ -2831,17 +3170,123 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), + ( + "UnpivotClauseSegment".into(), + NodeMatcher::new(SyntaxKind::UnpivotClause, |_dialect| { + Sequence::new(vec![ + MetaSegment::indent().to_matchable(), + Ref::keyword("UNPIVOT").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("INCLUDE").to_matchable(), + Ref::keyword("EXCLUDE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("NULLS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + MetaSegment::indent().to_matchable(), + Bracketed::new(vec![ + one_of(vec![ + Ref::new("SingleValueColumnUnpivotSegment").to_matchable(), + Ref::new("MultiValueColumnUnpivotSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SingleValueColumnUnpivotSegment".into(), + NodeMatcher::new(SyntaxKind::UnpivotSingleColumn, |_dialect| { + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("FOR").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("IN").to_matchable(), + Bracketed::new(vec![ + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MultiValueColumnUnpivotSegment".into(), + NodeMatcher::new(SyntaxKind::UnpivotMultiColumn, |_dialect| { + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::keyword("FOR").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::keyword("IN").to_matchable(), + Bracketed::new(vec![ + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Bracketed::new(vec![ + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), ( "TransformClauseSegment".into(), - NodeMatcher::new(SyntaxKind::TransformClause, |_| { + NodeMatcher::new(SyntaxKind::TransformClause, |_dialect| { Sequence::new(vec![ Ref::keyword("TRANSFORM").to_matchable(), Bracketed::new(vec![ Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) .to_matchable(), ]) - .config(|config| { - config.parse_mode(ParseMode::Greedy); + .config(|this| { + this.parse_mode(ParseMode::Greedy); }) .to_matchable(), MetaSegment::indent().to_matchable(), @@ -2862,8 +3307,8 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Ref::new("RowFormatClauseSegment").optional().to_matchable(), @@ -2874,43 +3319,68 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "RowFormatClauseSegment".into(), - hive_dialect.grammar("RowFormatClauseSegment").into(), - ), - ( - "SkewedByClauseSegment".into(), - hive_dialect.grammar("SkewedByClauseSegment").into(), - ), - ]); - - sparksql_dialect.replace_grammar( - "ExplainStatementSegment", - Sequence::new(vec![ - Ref::keyword("EXPLAIN").to_matchable(), - one_of(vec![ - Ref::keyword("EXTENDED").to_matchable(), - Ref::keyword("CODEGEN").to_matchable(), - Ref::keyword("COST").to_matchable(), - Ref::keyword("FORMATTED").to_matchable(), - ]) - .config(|config| { - config.optional(); + "ExplainStatementSegment".into(), + NodeMatcher::new(SyntaxKind::ExplainStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("EXPLAIN").to_matchable(), + one_of(vec![ + Ref::keyword("EXTENDED").to_matchable(), + Ref::keyword("CODEGEN").to_matchable(), + Ref::keyword("COST").to_matchable(), + Ref::keyword("FORMATTED").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("StatementSegment").to_matchable(), + ]) + .to_matchable() }) - .to_matchable(), - Ref::new("StatementSegment").to_matchable(), - ]) - .to_matchable(), - ); - - sparksql_dialect.add([ + .to_matchable() + .into(), + ), ( "AddFileSegment".into(), - NodeMatcher::new(SyntaxKind::AddFileStatement, |_| { + NodeMatcher::new(SyntaxKind::AddFileStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ADD").to_matchable(), Ref::keyword("FILE").to_matchable(), - AnyNumberOf::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) + AnyNumberOf::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("FileLiteralSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FileLiteralSegment".into(), + NodeMatcher::new(SyntaxKind::FileLiteral, |_dialect| { + one_of(vec![ + TypedParser::new(SyntaxKind::FileLiteral, SyntaxKind::Literal).to_matchable(), + Sequence::new(vec![ + Ref::new("SlashSegment").optional().to_matchable(), + Delimited::new(vec![ + Delimited::new(vec![ + TypedParser::new(SyntaxKind::Word, SyntaxKind::PathSegment) + .to_matchable(), + ]) + .config(|this| { + this.delimiter(Ref::new("DotSegment")); + }) + .to_matchable(), + ]) + .config(|this| { + this.disallow_gaps(); + this.delimiter(Ref::new("SlashSegment")); + }) .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) @@ -2919,7 +3389,7 @@ pub fn raw_dialect() -> Dialect { ), ( "AddJarSegment".into(), - NodeMatcher::new(SyntaxKind::AddJarStatement, |_| { + NodeMatcher::new(SyntaxKind::AddJarStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ADD").to_matchable(), Ref::keyword("JAR").to_matchable(), @@ -2936,7 +3406,7 @@ pub fn raw_dialect() -> Dialect { ), ( "AnalyzeTableSegment".into(), - NodeMatcher::new(SyntaxKind::AnalyzeTableStatement, |_| { + NodeMatcher::new(SyntaxKind::AnalyzeTableStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("ANALYZE").to_matchable(), one_of(vec![ @@ -2961,8 +3431,8 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -2977,8 +3447,8 @@ pub fn raw_dialect() -> Dialect { .to_matchable(), Ref::new("DatabaseReferenceSegment").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Ref::keyword("COMPUTE").to_matchable(), @@ -2996,7 +3466,7 @@ pub fn raw_dialect() -> Dialect { ), ( "CacheTableSegment".into(), - NodeMatcher::new(SyntaxKind::CacheTable, |_| { + NodeMatcher::new(SyntaxKind::CacheTable, |_dialect| { Sequence::new(vec![ Ref::keyword("CACHE").to_matchable(), Ref::keyword("LAZY").optional().to_matchable(), @@ -3007,8 +3477,8 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("AS").optional().to_matchable(), Ref::new("SelectableGrammar").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -3019,7 +3489,7 @@ pub fn raw_dialect() -> Dialect { ), ( "ClearCacheSegment".into(), - NodeMatcher::new(SyntaxKind::ClearCache, |_| { + NodeMatcher::new(SyntaxKind::ClearCache, |_dialect| { Sequence::new(vec![ Ref::keyword("CLEAR").to_matchable(), Ref::keyword("CACHE").to_matchable(), @@ -3030,127 +3500,32 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "DescribeObjectGrammar".into(), - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DATABASE").to_matchable(), - Ref::keyword("SCHEMA").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("EXTENDED").optional().to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FUNCTION").to_matchable(), - Ref::keyword("EXTENDED").optional().to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TABLE").optional().to_matchable(), - Ref::keyword("EXTENDED").optional().to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("PartitionSpecGrammar").optional().to_matchable(), - Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::new("DotSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .config(|config| { - config.disallow_gaps(); - }) - .to_matchable(), - ]) - .config(|config| { - config.max_times = Some(2); - config.disallow_gaps(); - }) - .to_matchable(), - ]) - .config(|config| { - config.optional(); - config.disallow_gaps(); - }) - .to_matchable(), - ]) - .to_matchable(), + "DescribeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DescribeStatement, |_dialect| { Sequence::new(vec![ - Ref::keyword("QUERY").optional().to_matchable(), one_of(vec![ - Sequence::new(vec![ - Ref::keyword("TABLE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::keyword("SELECT").to_matchable(), - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), - Ref::new("GroupByClauseSegment").optional().to_matchable(), - Ref::new("OrderByClauseSegment").optional().to_matchable(), - Ref::new("LimitClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - Ref::new("StatementSegment").to_matchable(), + Ref::keyword("DESCRIBE").to_matchable(), + Ref::keyword("DESC").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|config| { - config.exclude = one_of(vec![ - Ref::keyword("HISTORY").to_matchable(), - Ref::keyword("DETAIL").to_matchable(), + Ref::new("DescribeObjectGrammar").to_matchable(), ]) .to_matchable() - .into(); }) .to_matchable() .into(), ), - // A `DESCRIBE` statement. - // This class provides coverage for databases, tables, functions, and queries. - - // NB: These are similar enough that it makes sense to include them in a - // common class, especially since there wouldn't be any specific rules that - // would apply to one describe vs another, but they could be broken out to - // one class per describe statement type. - - // https://spark.apache.org/docs/latest/sql-ref-syntax-aux-describe-database.html - // https://spark.apache.org/docs/latest/sql-ref-syntax-aux-describe-function.html - // https://spark.apache.org/docs/latest/sql-ref-syntax-aux-describe-query.html - // https://spark.apache.org/docs/latest/sql-ref-syntax-aux-describe-table.html ( - "DescribeStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DescribeStatement, |_| { + "ListFileSegment".into(), + NodeMatcher::new(SyntaxKind::ListFileStatement, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DESCRIBE").to_matchable(), - Ref::keyword("DESC").to_matchable(), + Ref::keyword("LIST").to_matchable(), + Ref::keyword("FILE").to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("FileLiteralSegment").to_matchable(), ]) .to_matchable(), - Ref::new("DescribeObjectGrammar").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "ListFileSegment".into(), - NodeMatcher::new(SyntaxKind::ListFileStatement, |_| { - Sequence::new(vec![ - Ref::keyword("LIST").to_matchable(), - Ref::keyword("FILE").to_matchable(), - AnyNumberOf::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) - .to_matchable(), ]) .to_matchable() }) @@ -3159,12 +3534,15 @@ pub fn raw_dialect() -> Dialect { ), ( "ListJarSegment".into(), - NodeMatcher::new(SyntaxKind::ListJarStatement, |_| { + NodeMatcher::new(SyntaxKind::ListJarStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("LIST").to_matchable(), Ref::keyword("JAR").to_matchable(), - AnyNumberOf::new(vec![Ref::new("QuotedLiteralSegment").to_matchable()]) - .to_matchable(), + AnyNumberOf::new(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("FileLiteralSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable() }) @@ -3173,7 +3551,7 @@ pub fn raw_dialect() -> Dialect { ), ( "RefreshStatementSegment".into(), - NodeMatcher::new(SyntaxKind::RefreshStatement, |_| { + NodeMatcher::new(SyntaxKind::RefreshStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("REFRESH").to_matchable(), one_of(vec![ @@ -3198,13 +3576,13 @@ pub fn raw_dialect() -> Dialect { ), ( "ResetStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ResetStatement, |_| { + NodeMatcher::new(SyntaxKind::ResetStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("RESET").to_matchable(), Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) - .config(|config| { - config.delimiter(Ref::new("DotSegment")); - config.optional(); + .config(|this| { + this.optional(); + this.delimiter(Ref::new("DotSegment")); }) .to_matchable(), ]) @@ -3213,37 +3591,9 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ( - "ShowViewsGrammar".into(), - Sequence::new(vec![ - Ref::keyword("VIEWS").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("IN").to_matchable(), - ]) - .to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LIKE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), ( "SetStatementSegment".into(), - NodeMatcher::new(SyntaxKind::SetStatement, |_| { + NodeMatcher::new(SyntaxKind::SetStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("SET").to_matchable(), Ref::new("SQLConfPropertiesSegment") @@ -3253,8 +3603,8 @@ pub fn raw_dialect() -> Dialect { Ref::new("PropertyListGrammar").to_matchable(), Ref::new("PropertyNameSegment").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -3264,24 +3614,8 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - // Common class for `SHOW` statements. - // - // NB: These are similar enough that it makes sense to include them in a - // common class, especially since there wouldn't be any specific rules that - // would apply to one show vs another, but they could be broken out to - // one class per show statement type. - // - // https://spark.apache.org/docs/latest/sql-ref-syntax-aux-show-columns.html - // https://spark.apache.org/docs/latest/sql-ref-syntax-aux-show-create-table.html - // https://spark.apache.org/docs/latest/sql-ref-syntax-aux-show-databases.html - // https://spark.apache.org/docs/latest/sql-ref-syntax-aux-show-functions.html - // https://spark.apache.org/docs/latest/sql-ref-syntax-aux-show-partitions.html - // https://spark.apache.org/docs/latest/sql-ref-syntax-aux-show-table.html - // https://spark.apache.org/docs/latest/sql-ref-syntax-aux-show-tables.html - // https://spark.apache.org/docs/latest/sql-ref-syntax-aux-show-tblproperties.html - // https://spark.apache.org/docs/latest/sql-ref-syntax-aux-show-views.html "ShowStatement".into(), - NodeMatcher::new(SyntaxKind::ShowStatement, |_| { + NodeMatcher::new(SyntaxKind::ShowStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("SHOW").to_matchable(), Ref::new("ShowObjectGrammar").to_matchable(), @@ -3293,7 +3627,7 @@ pub fn raw_dialect() -> Dialect { ), ( "UncacheTableSegment".into(), - NodeMatcher::new(SyntaxKind::UncacheTable, |_| { + NodeMatcher::new(SyntaxKind::UncacheTable, |_dialect| { Sequence::new(vec![ Ref::keyword("UNCACHE").to_matchable(), Ref::keyword("TABLE").to_matchable(), @@ -3305,286 +3639,301 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - sparksql_dialect.replace_grammar( - "StatementSegment", - ansi::statement_segment().copy( - Some(vec![ - Ref::new("AlterDatabaseStatementSegment").to_matchable(), - Ref::new("AlterTableStatementSegment").to_matchable(), - Ref::new("AlterViewStatementSegment").to_matchable(), - Ref::new("CreateHiveFormatTableStatementSegment").to_matchable(), - Ref::new("MsckRepairTableStatementSegment").to_matchable(), - Ref::new("UseDatabaseStatementSegment").to_matchable(), - Ref::new("AddFileSegment").to_matchable(), - Ref::new("AddJarSegment").to_matchable(), - Ref::new("AnalyzeTableSegment").to_matchable(), - Ref::new("CacheTableSegment").to_matchable(), - Ref::new("ClearCacheSegment").to_matchable(), - Ref::new("ListFileSegment").to_matchable(), - Ref::new("ListJarSegment").to_matchable(), - Ref::new("RefreshStatementSegment").to_matchable(), - Ref::new("ResetStatementSegment").to_matchable(), - Ref::new("SetStatementSegment").to_matchable(), - Ref::new("ShowStatement").to_matchable(), - Ref::new("UncacheTableSegment").to_matchable(), - Ref::new("InsertOverwriteDirectorySegment").to_matchable(), - Ref::new("InsertOverwriteDirectoryHiveFmtSegment").to_matchable(), - Ref::new("LoadDataSegment").to_matchable(), - Ref::new("ClusterByClauseSegment").to_matchable(), - Ref::new("DistributeByClauseSegment").to_matchable(), - Ref::new("VacuumStatementSegment").to_matchable(), - Ref::new("DescribeHistoryStatementSegment").to_matchable(), - Ref::new("DescribeDetailStatementSegment").to_matchable(), - Ref::new("GenerateManifestFileStatementSegment").to_matchable(), - Ref::new("ConvertToDeltaStatementSegment").to_matchable(), - Ref::new("RestoreTableStatementSegment").to_matchable(), - Ref::new("ConstraintStatementSegment").to_matchable(), - Ref::new("ApplyChangesIntoStatementSegment").to_matchable(), - Ref::new("CreateWidgetStatementSegment").to_matchable(), - Ref::new("RemoveWidgetStatementSegment").to_matchable(), - Ref::new("ReplaceTableStatementSegment").to_matchable(), - Ref::new("SetVariableStatementSegment").to_matchable(), - ]), - None, - None, - Some(vec![ - Ref::new("TransactionStatementSegment").to_matchable(), - Ref::new("CreateSchemaStatementSegment").to_matchable(), - Ref::new("SetSchemaStatementSegment").to_matchable(), - Ref::new("CreateModelStatementSegment").to_matchable(), - Ref::new("DropModelStatementSegment").to_matchable(), - ]), - Vec::new(), - false, + ( + "StatementSegment".into(), + NodeMatcher::new(SyntaxKind::Statement, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("StatementSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("AlterDatabaseStatementSegment").to_matchable(), + Ref::new("AlterTableStatementSegment").to_matchable(), + Ref::new("AlterViewStatementSegment").to_matchable(), + Ref::new("CreateTableStatementSegment").to_matchable(), + Ref::new("MsckRepairTableStatementSegment").to_matchable(), + Ref::new("UseDatabaseStatementSegment").to_matchable(), + Ref::new("AddFileSegment").to_matchable(), + Ref::new("AddJarSegment").to_matchable(), + Ref::new("AnalyzeTableSegment").to_matchable(), + Ref::new("CacheTableSegment").to_matchable(), + Ref::new("ClearCacheSegment").to_matchable(), + Ref::new("ListFileSegment").to_matchable(), + Ref::new("ListJarSegment").to_matchable(), + Ref::new("RefreshStatementSegment").to_matchable(), + Ref::new("ResetStatementSegment").to_matchable(), + Ref::new("SetStatementSegment").to_matchable(), + Ref::new("ShowStatement").to_matchable(), + Ref::new("UncacheTableSegment").to_matchable(), + Ref::new("InsertOverwriteDirectorySegment").to_matchable(), + Ref::new("InsertOverwriteDirectoryHiveFmtSegment").to_matchable(), + Ref::new("LoadDataSegment").to_matchable(), + Ref::new("ClusterByClauseSegment").to_matchable(), + Ref::new("DistributeByClauseSegment").to_matchable(), + Ref::new("VacuumStatementSegment").to_matchable(), + Ref::new("DescribeHistoryStatementSegment").to_matchable(), + Ref::new("DescribeDetailStatementSegment").to_matchable(), + Ref::new("GenerateManifestFileStatementSegment").to_matchable(), + Ref::new("ConvertToDeltaStatementSegment").to_matchable(), + Ref::new("RestoreTableStatementSegment").to_matchable(), + Ref::new("ConstraintStatementSegment").to_matchable(), + Ref::new("ApplyChangesIntoStatementSegment").to_matchable(), + Ref::new("CreateWidgetStatementSegment").to_matchable(), + Ref::new("RemoveWidgetStatementSegment").to_matchable(), + Ref::new("ReplaceTableStatementSegment").to_matchable(), + Ref::new("SetVariableStatementSegment").to_matchable(), + ]), + None, + None, + Some(vec![ + Ref::new("TransactionStatementSegment").to_matchable(), + Ref::new("CreateSchemaStatementSegment").to_matchable(), + Ref::new("SetSchemaStatementSegment").to_matchable(), + Ref::new("CreateModelStatementSegment").to_matchable(), + Ref::new("DropModelStatementSegment").to_matchable(), + ]), + vec![], + false, + ) + }) + .to_matchable() + .into(), ), - ); - - sparksql_dialect.replace_grammar( - "JoinClauseSegment", - one_of(vec![ - Sequence::new(vec![ - Ref::new("JoinTypeKeywords").optional().to_matchable(), - Ref::new("JoinKeywordsGrammar").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("FromExpressionElementSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - Conditional::new(MetaSegment::indent()) - .indented_using_on() - .to_matchable(), + ( + "JoinClauseSegment".into(), + NodeMatcher::new(SyntaxKind::JoinClause, |_dialect| { one_of(vec![ - Ref::new("JoinOnConditionSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("USING").to_matchable(), - Conditional::new(MetaSegment::indent()).to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("JoinTypeKeywords").optional().to_matchable(), + Ref::new("JoinKeywordsGrammar").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("FromExpressionElementSegment").to_matchable(), + MetaSegment::dedent().to_matchable(), + Conditional::new(MetaSegment::indent()) + .indented_using_on() + .to_matchable(), + one_of(vec![ + Ref::new("JoinOnConditionSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USING").to_matchable(), + Conditional::new(MetaSegment::indent()).to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + Conditional::new(MetaSegment::dedent()).to_matchable(), ]) .to_matchable(), ]) - .config(|config| { - config.parse_mode(ParseMode::Greedy); + .config(|this| { + this.optional(); }) .to_matchable(), - Conditional::new(MetaSegment::dedent()).to_matchable(), + Conditional::new(MetaSegment::dedent()) + .indented_using_on() + .to_matchable(), ]) .to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Conditional::new(MetaSegment::dedent()) - .indented_using_on() + Sequence::new(vec![ + Ref::new("NaturalJoinKeywordsGrammar").to_matchable(), + Ref::new("JoinKeywordsGrammar").to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("FromExpressionElementSegment").to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("NaturalJoinKeywordsGrammar").to_matchable(), - Ref::new("JoinKeywordsGrammar").to_matchable(), - MetaSegment::indent().to_matchable(), - Ref::new("FromExpressionElementSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - sparksql_dialect.replace_grammar( - "AliasExpressionSegment", - Sequence::new(vec![ - Ref::keyword("AS").optional().to_matchable(), - one_of(vec![ + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AliasExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::AliasExpression, |_dialect| { Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar") - .optional() - .to_matchable(), - Bracketed::new(vec![Ref::new("SingleIdentifierListSegment").to_matchable()]) + MetaSegment::indent().to_matchable(), + Ref::new("AsAliasOperatorSegment").optional().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar") + .optional() + .to_matchable(), + Bracketed::new(vec![ + Ref::new("SingleIdentifierListSegment").to_matchable(), + ]) + .to_matchable(), + ]) .to_matchable(), - ]) - .to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .config(|config| { - config.exclude = one_of(vec![ - Ref::keyword("LATERAL").to_matchable(), - Ref::new("JoinTypeKeywords").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::keyword("PIVOT").to_matchable(), - Ref::keyword("KEYS").to_matchable(), - Ref::keyword("FROM").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .config(|this| { + this.exclude = Some( + one_of(vec![ + Ref::keyword("LATERAL").to_matchable(), + Ref::new("JoinTypeKeywords").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::keyword("PIVOT").to_matchable(), + Ref::keyword("KEYS").to_matchable(), + Ref::keyword("FROM").to_matchable(), + ]) + .to_matchable(), + ); + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) .to_matchable() - .into(); }) - .to_matchable(), - ]) - .to_matchable(), - ); - - sparksql_dialect.replace_grammar( - "ValuesClauseSegment", - Sequence::new(vec![ - Ref::keyword("VALUES").to_matchable(), - Delimited::new(vec![ - one_of(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ + .to_matchable() + .into(), + ), + ( + "ValuesClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ValuesClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("VALUES").to_matchable(), + Delimited::new(vec![ + one_of(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::keyword("NULL").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), Ref::keyword("NULL").to_matchable(), Ref::new("ExpressionSegment").to_matchable(), ]) + .config(|this| { + this.exclude = Some( + one_of(vec![Ref::keyword("VALUES").to_matchable()]).to_matchable(), + ); + }) .to_matchable(), ]) - .config(|config| { - config.parse_mode(ParseMode::Greedy); - }) .to_matchable(), - Ref::keyword("NULL").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|config| { - config.exclude = one_of(vec![Ref::keyword("VALUES").to_matchable()]) - .to_matchable() - .into(); - }) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("AliasExpressionSegment") - .exclude(one_of(vec![ - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("ORDER").to_matchable(), - ])) - .optional() - .config(|config| { - config.exclude = one_of(vec![ - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("ORDER").to_matchable(), - ]) - .to_matchable() - .into(); - }) - .to_matchable(), - Ref::new("OrderByClauseSegment").optional().to_matchable(), - Ref::new("LimitClauseSegment").optional().to_matchable(), - ]) - .to_matchable(), - ); - - sparksql_dialect.replace_grammar( - "TableExpressionSegment", - one_of(vec![ - Ref::new("ValuesClauseSegment").to_matchable(), - Ref::new("BareFunctionSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::new("FileReferenceSegment").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("AliasExpressionSegment") + .exclude(one_of(vec![ + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("ORDER").to_matchable(), + ])) + .optional() + .to_matchable(), + Ref::new("OrderByClauseSegment").optional().to_matchable(), + Ref::new("LimitClauseSegment").optional().to_matchable(), ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::TableExpression, |_dialect| { one_of(vec![ - Ref::new("AtSignLiteralSegment").to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), Sequence::new(vec![ - MetaSegment::indent().to_matchable(), one_of(vec![ - Ref::new("TimestampAsOfGrammar").to_matchable(), - Ref::new("VersionAsOfGrammar").to_matchable(), + Ref::new("FileReferenceSegment").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), ]) .to_matchable(), - MetaSegment::dedent().to_matchable(), + one_of(vec![ + Ref::new("AtSignLiteralSegment").to_matchable(), + Sequence::new(vec![ + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::new("TimestampAsOfGrammar").to_matchable(), + Ref::new("VersionAsOfGrammar").to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), ]) .to_matchable(), + Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![Ref::new("SelectableGrammar").to_matchable()]).to_matchable(), - ]) - .to_matchable(), - ); - sparksql_dialect.add([( - "FileReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::FileReference, |_| { - Sequence::new(vec![ - Ref::new("DataSourcesV2FileTypeGrammar").to_matchable(), - Ref::new("DotSegment").to_matchable(), - Ref::new("BackQuotedIdentifierSegment").to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - sparksql_dialect.replace_grammar( - "FromExpressionElementSegment", - Sequence::new(vec![ - Ref::new("PreTableFunctionKeywordsGrammar") - .optional() - .to_matchable(), - optionally_bracketed(vec![Ref::new("TableExpressionSegment").to_matchable()]) - .to_matchable(), - Ref::new("SamplingExpressionSegment") - .optional() - .to_matchable(), - Ref::new("AliasExpressionSegment") - .exclude(one_of(vec![ - Ref::new("FromClauseTerminatorGrammar").to_matchable(), - Ref::new("JoinLikeClauseGrammar").to_matchable(), - ])) - .optional() - .to_matchable(), - Ref::new("SamplingExpressionSegment") - .optional() - .to_matchable(), - AnyNumberOf::new(vec![Ref::new("LateralViewClauseSegment").to_matchable()]) - .to_matchable(), - Ref::new("NamedWindowSegment").optional().to_matchable(), - Ref::new("PostTableExpressionGrammar") - .optional() - .to_matchable(), - ]) - .to_matchable(), - ); - sparksql_dialect.add([ + .into(), + ), + ( + "FileReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::FileReference, |_dialect| { + Sequence::new(vec![ + Ref::new("DataSourcesV2FileTypeGrammar").to_matchable(), + Ref::new("DotSegment").to_matchable(), + Ref::new("BackQuotedIdentifierSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "FromExpressionElementSegment".into(), + NodeMatcher::new(SyntaxKind::FromExpressionElement, |_dialect| { + Sequence::new(vec![ + Ref::new("PreTableFunctionKeywordsGrammar") + .optional() + .to_matchable(), + optionally_bracketed(vec![Ref::new("TableExpressionSegment").to_matchable()]) + .to_matchable(), + Ref::new("SamplingExpressionSegment") + .optional() + .to_matchable(), + Ref::new("AliasExpressionSegment") + .exclude(one_of(vec![ + Ref::new("FromClauseTerminatorGrammar").to_matchable(), + Ref::new("JoinLikeClauseGrammar").to_matchable(), + ])) + .optional() + .to_matchable(), + Ref::new("PostTableExpressionGrammar") + .optional() + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), ( "PropertyNameSegment".into(), - NodeMatcher::new(SyntaxKind::PropertyNameIdentifier, |_| { + NodeMatcher::new(SyntaxKind::PropertyNameIdentifier, |_dialect| { Sequence::new(vec![ one_of(vec![ Delimited::new(vec![ Ref::new("PropertiesNakedIdentifierSegment").to_matchable(), ]) - .config(|config| { - config.delimiter(Ref::new("DotSegment")); - config.disallow_gaps(); + .config(|this| { + this.disallow_gaps(); + this.delimiter(Ref::new("DotSegment")); }) .to_matchable(), Ref::new("SingleIdentifierGrammar").to_matchable(), @@ -3597,143 +3946,115 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "GeneratedColumnDefinitionSegment".into(), - NodeMatcher::new(SyntaxKind::GeneratedColumnDefinition, |_| { + "MergeUpdateClauseSegment".into(), + NodeMatcher::new(SyntaxKind::MergeUpdateClause, |_dialect| { Sequence::new(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - Bracketed::new(vec![Anything::new().to_matchable()]) - .config(|config| { - config.optional(); - }) + Ref::keyword("UPDATE").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::new("WildcardIdentifierSegment").to_matchable(), + ]) .to_matchable(), - Sequence::new(vec![ - Ref::keyword("GENERATED").to_matchable(), - Ref::keyword("ALWAYS").to_matchable(), - Ref::keyword("AS").to_matchable(), - Bracketed::new(vec![ - one_of(vec![ - Ref::new("FunctionSegment").to_matchable(), - Ref::new("BareFunctionSegment").to_matchable(), - ]) - .to_matchable(), + Sequence::new(vec![ + MetaSegment::indent().to_matchable(), + Ref::new("SetClauseListSegment").to_matchable(), + MetaSegment::dedent().to_matchable(), ]) .to_matchable(), ]) .to_matchable(), - AnyNumberOf::new(vec![ - Ref::new("ColumnConstraintSegment") - .optional() - .to_matchable(), - ]) - .to_matchable(), ]) .to_matchable() }) .to_matchable() .into(), ), - ]); - - sparksql_dialect.replace_grammar( - "MergeUpdateClauseSegment", - Sequence::new(vec![ - Ref::keyword("UPDATE").to_matchable(), - one_of(vec![ + ( + "MergeInsertClauseSegment".into(), + NodeMatcher::new(SyntaxKind::MergeInsertClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - Ref::new("WildcardIdentifierSegment").to_matchable(), + Ref::keyword("INSERT").to_matchable(), + one_of(vec![ + Ref::new("WildcardIdentifierSegment").to_matchable(), + Sequence::new(vec![ + MetaSegment::indent().to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::new("ValuesClauseSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) - .to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UpdateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::UpdateStatement, |_dialect| { Sequence::new(vec![ + Ref::keyword("UPDATE").to_matchable(), MetaSegment::indent().to_matchable(), - Ref::new("SetClauseListSegment").to_matchable(), + one_of(vec![ + Ref::new("FileReferenceSegment").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("AliasExpressionSegment") + .exclude(Ref::keyword("SET")) + .optional() + .to_matchable(), MetaSegment::dedent().to_matchable(), + Ref::new("SetClauseListSegment").to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - sparksql_dialect.replace_grammar( - "MergeInsertClauseSegment", - Sequence::new(vec![ - Ref::keyword("INSERT").to_matchable(), - one_of(vec![ - Ref::new("WildcardIdentifierSegment").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "IntervalLiteralSegment".into(), + NodeMatcher::new(SyntaxKind::IntervalLiteral, |_dialect| { Sequence::new(vec![ - MetaSegment::indent().to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - MetaSegment::dedent().to_matchable(), - Ref::new("ValuesClauseSegment").to_matchable(), + Ref::new("SignedSegmentGrammar").optional().to_matchable(), + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("SignedQuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("DatetimeUnitSegment").to_matchable(), + Ref::keyword("TO").optional().to_matchable(), + Ref::new("DatetimeUnitSegment").optional().to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - sparksql_dialect.replace_grammar( - "UpdateStatementSegment", - Sequence::new(vec![ - Ref::keyword("UPDATE").to_matchable(), - one_of(vec![ - Ref::new("FileReferenceSegment").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("AliasExpressionSegment") - .exclude(Ref::keyword("SET")) - .optional() - .config(|config| { - config.exclude = Ref::keyword("SET").to_matchable().into(); - }) - .to_matchable(), - Ref::new("SetClauseListSegment").to_matchable(), - Ref::new("WhereClauseSegment").to_matchable(), - ]) - .to_matchable(), - ); - sparksql_dialect.add([( - "IntervalLiteralSegment".into(), - NodeMatcher::new(SyntaxKind::IntervalLiteral, |_| { - Sequence::new(vec![ - Ref::new("SignedSegmentGrammar").optional().to_matchable(), - one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("SignedQuotedLiteralSegment").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "IntervalExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::IntervalExpression, |_dialect| { + Sequence::new(vec![ + Ref::keyword("INTERVAL").to_matchable(), + one_of(vec![ + AnyNumberOf::new(vec![Ref::new("IntervalLiteralSegment").to_matchable()]) + .to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), ]) - .to_matchable(), - Ref::new("DatetimeUnitSegment").to_matchable(), - Ref::keyword("TO").optional().to_matchable(), - Ref::new("DatetimeUnitSegment").optional().to_matchable(), - ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); - - sparksql_dialect.replace_grammar( - "IntervalExpressionSegment", - Sequence::new(vec![ - Ref::keyword("INTERVAL").to_matchable(), - one_of(vec![ - AnyNumberOf::new(vec![Ref::new("IntervalLiteralSegment").to_matchable()]) - .to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - sparksql_dialect.add([ + .into(), + ), ( "VacuumStatementSegment".into(), - NodeMatcher::new(SyntaxKind::VacuumStatement, |_| { + NodeMatcher::new(SyntaxKind::VacuumStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("VACUUM").to_matchable(), one_of(vec![ @@ -3755,8 +4076,8 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -3767,7 +4088,7 @@ pub fn raw_dialect() -> Dialect { ), ( "DescribeHistoryStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DescribeHistoryStatement, |_| { + NodeMatcher::new(SyntaxKind::DescribeHistoryStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("DESCRIBE").to_matchable(), Ref::keyword("HISTORY").to_matchable(), @@ -3786,7 +4107,7 @@ pub fn raw_dialect() -> Dialect { ), ( "DescribeDetailStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DescribeDetailStatement, |_| { + NodeMatcher::new(SyntaxKind::DescribeDetailStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("DESCRIBE").to_matchable(), Ref::keyword("DETAIL").to_matchable(), @@ -3804,7 +4125,7 @@ pub fn raw_dialect() -> Dialect { ), ( "GenerateManifestFileStatementSegment".into(), - NodeMatcher::new(SyntaxKind::GenerateManifestFileStatement, |_| { + NodeMatcher::new(SyntaxKind::GenerateManifestFileStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("GENERATE").to_matchable(), StringParser::new("symlink_format_manifest", SyntaxKind::SymlinkFormatManifest) @@ -3825,7 +4146,7 @@ pub fn raw_dialect() -> Dialect { ), ( "ConvertToDeltaStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ConvertToDeltaStatement, |_| { + NodeMatcher::new(SyntaxKind::ConvertToDeltaStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CONVERT").to_matchable(), Ref::keyword("TO").to_matchable(), @@ -3835,8 +4156,8 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("NO").to_matchable(), Ref::keyword("STATISTICS").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Ref::new("PartitionSpecGrammar").optional().to_matchable(), @@ -3848,7 +4169,7 @@ pub fn raw_dialect() -> Dialect { ), ( "RestoreTableStatementSegment".into(), - NodeMatcher::new(SyntaxKind::RestoreTableStatement, |_| { + NodeMatcher::new(SyntaxKind::RestoreTableStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("RESTORE").to_matchable(), Ref::keyword("TABLE").to_matchable(), @@ -3872,7 +4193,7 @@ pub fn raw_dialect() -> Dialect { ), ( "ConstraintStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ConstraintStatement, |_| { + NodeMatcher::new(SyntaxKind::ConstraintStatement, |_dialect| { Sequence::new(vec![ Ref::keyword("CONSTRAINT").to_matchable(), Ref::new("ObjectReferenceSegment").to_matchable(), @@ -3883,8 +4204,8 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("ON").to_matchable(), Ref::keyword("VIOLATION").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), one_of(vec![ @@ -3899,8 +4220,8 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -3910,10 +4231,8 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - // A statement ingest CDC data a target table. - // https://docs.databricks.com/workflows/delta-live-tables/delta-live-tables-cdc.html#sql "ApplyChangesIntoStatementSegment".into(), - NodeMatcher::new(SyntaxKind::ApplyChangesIntoStatement, |_| { + NodeMatcher::new(SyntaxKind::ApplyChangesIntoStatement, |_dialect| { Sequence::new(vec![ Sequence::new(vec![ Ref::keyword("APPLY").to_matchable(), @@ -3937,8 +4256,8 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("NULL").to_matchable(), Ref::keyword("UPDATES").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Ref::new("WhereClauseSegment").optional().to_matchable(), @@ -3958,8 +4277,8 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.max_times = Some(2); + .config(|this| { + this.max_times(2); }) .to_matchable(), Sequence::new(vec![ @@ -3982,8 +4301,8 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Sequence::new(vec![ @@ -3993,8 +4312,8 @@ pub fn raw_dialect() -> Dialect { Ref::keyword("TYPE").to_matchable(), Ref::new("NumericLiteralSegment").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), Sequence::new(vec![ @@ -4013,8 +4332,8 @@ pub fn raw_dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -4023,45 +4342,33 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - sparksql_dialect.replace_grammar( - "WildcardExpressionSegment", - ansi::wildcard_expression_segment().copy( - Some(vec![ - Ref::new("ExceptClauseSegment").optional().to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, + ( + "WildcardExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::WildcardExpression, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("WildcardExpressionSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Ref::new("ExceptClauseSegment").optional().to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), ), - ); - - // A reference to an object. - // allow whitespace - sparksql_dialect.replace_grammar( - "ObjectReferenceSegment", - Delimited::new(vec![ - one_of(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("IdentifierClauseSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|config| { - config.delimiter(Ref::new("ObjectReferenceDelimiterGrammar")); - config.terminators = vec![Ref::new("ObjectReferenceTerminatorGrammar").to_matchable()]; - config.disallow_gaps(); - }) - .to_matchable(), - ); - - sparksql_dialect.add([ ( "ExceptClauseSegment".into(), - NodeMatcher::new(SyntaxKind::SelectExceptClause, |_| { + NodeMatcher::new(SyntaxKind::SelectExceptClause, |_dialect| { Sequence::new(vec![ Ref::keyword("EXCEPT").to_matchable(), Bracketed::new(vec![ @@ -4077,7 +4384,7 @@ pub fn raw_dialect() -> Dialect { ), ( "SelectClauseSegment".into(), - NodeMatcher::new(SyntaxKind::SelectClause, |_| { + NodeMatcher::new(SyntaxKind::SelectClause, |_dialect| { Sequence::new(vec![ Ref::keyword("SELECT").to_matchable(), one_of(vec![ @@ -4090,19 +4397,20 @@ pub fn raw_dialect() -> Dialect { Delimited::new(vec![ Ref::new("SelectClauseElementSegment").to_matchable(), ]) - .config(|config| { - config.allow_trailing = true; + .config(|this| { + this.allow_trailing(); }) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), + MetaSegment::dedent().to_matchable(), ]) - .config(|config| { - config.terminators = + .config(|this| { + this.parse_mode(ParseMode::GreedyOnceStarted); + this.terminators = vec![Ref::new("SelectClauseTerminatorGrammar").to_matchable()]; - config.parse_mode(ParseMode::GreedyOnceStarted); }) .to_matchable() }) @@ -4111,7 +4419,7 @@ pub fn raw_dialect() -> Dialect { ), ( "UsingClauseSegment".into(), - NodeMatcher::new(SyntaxKind::UsingClause, |_| { + NodeMatcher::new(SyntaxKind::UsingClause, |_dialect| { Sequence::new(vec![ Ref::keyword("USING").to_matchable(), Ref::new("DataSourceFormatSegment").to_matchable(), @@ -4123,7 +4431,7 @@ pub fn raw_dialect() -> Dialect { ), ( "DataSourceFormatSegment".into(), - NodeMatcher::new(SyntaxKind::DataSourceFormat, |_| { + NodeMatcher::new(SyntaxKind::DataSourceFormat, |_dialect| { one_of(vec![ Ref::new("FileFormatGrammar").to_matchable(), Ref::keyword("JDBC").to_matchable(), @@ -4136,7 +4444,7 @@ pub fn raw_dialect() -> Dialect { ), ( "IcebergTransformationSegment".into(), - NodeMatcher::new(SyntaxKind::IcebergTransformation, |_| { + NodeMatcher::new(SyntaxKind::IcebergTransformation, |_dialect| { one_of(vec![ Sequence::new(vec![ one_of(vec![ @@ -4175,287 +4483,120 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), - ]); - - sparksql_dialect.add([ - ( - // Show Functions - "ShowFunctionsGrammar".into(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("USER").to_matchable(), - Ref::keyword("SYSTEM").to_matchable(), - Ref::keyword("ALL").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Ref::keyword("FUNCTIONS").to_matchable(), - one_of(vec![ - // qualified function from a database - Sequence::new(vec![ - Ref::new("DatabaseReferenceSegment").to_matchable(), - Ref::new("DotSegment").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), - ]) - .config(|config| { - config.disallow_gaps(); - config.optional(); - }) - .to_matchable(), - // non-qualified function - Ref::new("FunctionNameSegment").optional().to_matchable(), - Sequence::new(vec![ - Ref::keyword("LIKE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "ShowTablesGrammar".into(), - Sequence::new(vec![ - Ref::keyword("TABLES").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("IN").to_matchable(), - ]) - .to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LIKE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "ShowDatabasesSchemasGrammar".into(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DATABASES").to_matchable(), - Ref::keyword("SCHEMAS").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LIKE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), ( - "ShowObjectGrammar".into(), - one_of(vec![ + "FrameClauseSegment".into(), + NodeMatcher::new(SyntaxKind::FrameClause, |_dialect| { Sequence::new(vec![ + Ref::new("FrameClauseUnitGrammar").to_matchable(), one_of(vec![ - Ref::new("ShowFunctionsGrammar").to_matchable(), - Ref::new("ShowViewsGrammar").to_matchable(), - Ref::new("ShowTablesGrammar").to_matchable(), - Ref::new("ShowDatabasesSchemasGrammar").to_matchable(), - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("TableExpressionSegment").to_matchable(), + one_of(vec![ Sequence::new(vec![ - Ref::keyword("AS").to_matchable(), - Ref::keyword("SERDE").to_matchable(), + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLUMNS").to_matchable(), - Ref::keyword("IN").to_matchable(), - Ref::new("TableExpressionSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("IN").to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + Ref::new("IntervalExpressionSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - one_of(vec![ - Ref::keyword("USER").to_matchable(), - Ref::keyword("SYSTEM").to_matchable(), - Ref::keyword("ALL").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Ref::keyword("FUNCTIONS").to_matchable(), + Ref::keyword("BETWEEN").to_matchable(), one_of(vec![ Sequence::new(vec![ - Ref::new("DatabaseReferenceSegment").to_matchable(), - Ref::new("DotSegment").to_matchable(), - Ref::new("FunctionNameSegment").to_matchable(), + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), ]) - .config(|config| { - config.disallow_gaps(); - config.optional(); - }) .to_matchable(), - Ref::new("FunctionNameSegment").optional().to_matchable(), Sequence::new(vec![ - Ref::keyword("LIKE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + Ref::new("IntervalExpressionSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("PARTITIONS").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("PartitionSpecGrammar").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TABLE").to_matchable(), - Ref::keyword("EXTENDED").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("IN").to_matchable(), - Ref::keyword("FROM").to_matchable(), + Ref::keyword("AND").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), ]) .to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Ref::keyword("LIKE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("PartitionSpecGrammar").optional().to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("TBLPROPERTIES").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("BracketedPropertyNameListGrammar") - .optional() - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("VIEWS").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("IN").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + Ref::new("IntervalExpressionSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), - Ref::new("DatabaseReferenceSegment").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("LIKE").to_matchable(), - Ref::new("QuotedLiteralSegment").to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), - ]); - - sparksql_dialect.replace_grammar( - "FrameClauseSegment", - { - let frame_extent = one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CURRENT").to_matchable(), - Ref::keyword("ROW").to_matchable(), - ]) - .to_matchable(), + ( + "SetVariableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SetVariableStatement, |_dialect| { Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::keyword("UNBOUNDED").to_matchable(), - Ref::new("IntervalExpressionSegment").to_matchable(), + Ref::keyword("VAR").to_matchable(), + Ref::keyword("VARIABLE").to_matchable(), ]) .to_matchable(), - one_of(vec![ - Ref::keyword("PRECEDING").to_matchable(), - Ref::keyword("FOLLOWING").to_matchable(), + optionally_bracketed(vec![ + Delimited::new(vec![Ref::new("SingleIdentifierGrammar").to_matchable()]) + .to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ]); - - Sequence::new(vec![ - Ref::new("FrameClauseUnitGrammar").to_matchable(), - one_of(vec![ - frame_extent.clone().to_matchable(), - Sequence::new(vec![ - Ref::keyword("BETWEEN").to_matchable(), - frame_extent.clone().to_matchable(), - Ref::keyword("AND").to_matchable(), - frame_extent.to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + one_of(vec![ + Ref::keyword("DEFAULT").to_matchable(), + optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - ]) - } - .to_matchable(), - ); - sparksql_dialect -} + .to_matchable() + }) + .to_matchable() + .into(), + ), + ]); -pub fn dialect() -> Dialect { - raw_dialect().config(|config| config.expand()) + sparksql_dialect } diff --git a/crates/lib-dialects/src/sparksql_keywords.rs b/crates/lib-dialects/src/sparksql_keywords.rs index d9fb37cf9..264e2bc78 100644 --- a/crates/lib-dialects/src/sparksql_keywords.rs +++ b/crates/lib-dialects/src/sparksql_keywords.rs @@ -1,4 +1,4 @@ -pub(crate) const RESERVED_KEYWORDS: &[&str] = &[ +pub(crate) const RESERVED_KEYWORDS: [&str; 67] = [ "ALL", "AND", "ANY", @@ -68,7 +68,7 @@ pub(crate) const RESERVED_KEYWORDS: &[&str] = &[ "WITH", ]; -pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ +pub(crate) const UNRESERVED_KEYWORDS: [&str; 248] = [ "ADD", "AFTER", "ALTER", @@ -80,6 +80,7 @@ pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ "AT", "BERNOULLI", "BETWEEN", + "BINDING", "BUCKET", "BUCKETS", "BY", @@ -96,6 +97,7 @@ pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ "COMMIT", "COMPACT", "COMPACTIONS", + "COMPENSATION", "COMPUTE", "CONCATENATE", "COST", @@ -123,6 +125,7 @@ pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ "DIV", "DROP", "ESCAPED", + "EVOLUTION", "EXCHANGE", "EXISTS", "EXPLAIN", @@ -273,9 +276,9 @@ pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ "UPDATE", "USE", "VALUES", - "VARIANT", "VAR", "VARIABLE", + "VARIANT", "VIEW", "VIEWS", "WRITE", @@ -283,26 +286,21 @@ pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ "YEAR", "YEARS", "ZONE", - // Spark Core Data Sources - // https://spark.apache.org/docs/latest/sql-data-sources.html "AVRO", "CSV", "JSON", "PARQUET", "ORC", "JDBC", - // Community Contributed Data Sources - "DELTA", // https://github.com/delta-io/delta - "XML", // https://github.com/databricks/spark-xml + "DELTA", + "XML", "ICEBERG", - // Delta Lake "DETAIL", "DRY", "GENERATE", "HISTORY", "RETAIN", "RUN", - // Databricks - Delta Live Tables "CHANGES", "DELETES", "EXPECT", @@ -314,7 +312,6 @@ pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ "VIOLATION", "TRACK", "HISTORY", - // Databricks widget "WIDGET", "DROPDOWN", "TEXT", diff --git a/crates/lib-dialects/src/sqlite.rs b/crates/lib-dialects/src/sqlite.rs index 1b5b40556..2b8457055 100644 --- a/crates/lib-dialects/src/sqlite.rs +++ b/crates/lib-dialects/src/sqlite.rs @@ -6,22 +6,22 @@ use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_br use sqruff_lib_core::parser::grammar::delimited::Delimited; use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence}; use sqruff_lib_core::parser::grammar::{Anything, Nothing, Ref}; -use sqruff_lib_core::parser::lexer::Matcher; -use sqruff_lib_core::parser::matchable::MatchableTrait; +use sqruff_lib_core::parser::lexer::{Matcher, Pattern}; +use sqruff_lib_core::parser::matchable::{Matchable, MatchableTrait}; use sqruff_lib_core::parser::node_matcher::NodeMatcher; -use sqruff_lib_core::parser::parsers::TypedParser; +use sqruff_lib_core::parser::parsers::{StringParser, TypedParser}; use sqruff_lib_core::parser::segments::meta::MetaSegment; use sqruff_lib_core::parser::types::ParseMode; -use crate::sqlite_keywords::{RESERVED_KEYWORDS, UNRESERVED_KEYWORDS}; +use super::sqlite_keywords::{RESERVED_KEYWORDS, UNRESERVED_KEYWORDS}; pub fn dialect() -> Dialect { - raw_dialect().config(|dialect| dialect.expand()) + raw_dialect().config(|this| this.expand()) } pub fn raw_dialect() -> Dialect { - let sqlite_dialect = super::ansi::raw_dialect(); - let mut sqlite_dialect = sqlite_dialect; + let ansi_dialect = super::ansi::raw_dialect(); + let mut sqlite_dialect = ansi_dialect.clone(); sqlite_dialect.name = DialectKind::Sqlite; // Add lexer matchers for SQLite blob literals (X'...' or x'...') @@ -36,14 +36,83 @@ pub fn raw_dialect() -> Dialect { ); sqlite_dialect.sets_mut("reserved_keywords").clear(); + sqlite_dialect .sets_mut("reserved_keywords") .extend(RESERVED_KEYWORDS); + sqlite_dialect.sets_mut("unreserved_keywords").clear(); + sqlite_dialect .sets_mut("unreserved_keywords") .extend(UNRESERVED_KEYWORDS); + sqlite_dialect.patch_lexer_matchers(vec![ + Matcher::legacy( + "block_comment", + |s| s.starts_with("/*"), + r#"\/\*([^\*]|\*(?!\/))*(\*\/|\Z)"#, + SyntaxKind::BlockComment, + ) + .subdivider(Pattern::legacy( + "newline", + |_| true, + r#"\r\n|\n"#, + SyntaxKind::Newline, + )) + .post_subdivide(Pattern::legacy( + "whitespace", + |_| true, + r#"[^\S\r\n]+"#, + SyntaxKind::Whitespace, + )), + Matcher::regex("single_quote", r#"'([^']|'')*'"#, SyntaxKind::SingleQuote), + Matcher::regex("double_quote", r#""([^"]|"")*""#, SyntaxKind::DoubleQuote), + Matcher::regex("back_quote", r#"`([^`]|``)*`"#, SyntaxKind::BackQuote), + ]); + + sqlite_dialect.insert_lexer_matchers( + vec![ + Matcher::regex( + "at_sign_literal", + r#"@[a-zA-Z0-9_]+"#, + SyntaxKind::AtSignLiteral, + ), + Matcher::regex( + "colon_literal", + r#":[a-zA-Z0-9_]+"#, + SyntaxKind::ColonLiteral, + ), + Matcher::regex( + "question_literal", + r#"\?[0-9]+"#, + SyntaxKind::QuestionLiteral, + ), + Matcher::regex( + "dollar_literal", + r#"\$[a-zA-Z0-9_]+"#, + SyntaxKind::DollarLiteral, + ), + ], + "question", + ); + + sqlite_dialect.insert_lexer_matchers( + vec![ + Matcher::string( + "inline_path_operator", + r#"->>"#, + SyntaxKind::InlinePathOperator, + ), + Matcher::string( + "column_path_operator", + r#"->"#, + SyntaxKind::ColumnPathOperator, + ), + ], + "greater_than", + ); + sqlite_dialect.add([ // SQLite blob literal segment (X'...' or x'...') ( @@ -58,7 +127,7 @@ pub fn raw_dialect() -> Dialect { sqlite_dialect .grammar("LiteralGrammar") .copy( - Some(vec![Ref::new("BytesQuotedLiteralSegment").to_matchable()]), + Some(vec_of_erased![Ref::new("BytesQuotedLiteralSegment")]), None, None, None, @@ -68,990 +137,1652 @@ pub fn raw_dialect() -> Dialect { .into(), ), ( - "ColumnConstraintDefaultGrammar".into(), - Ref::new("ExpressionSegment").to_matchable().into(), - ), - ( - "BooleanBinaryOperatorGrammar".into(), - one_of(vec![ - Ref::new("AndOperatorGrammar").to_matchable(), - Ref::new("OrOperatorGrammar").to_matchable(), - Ref::keyword("REGEXP").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "PrimaryKeyGrammar".into(), - Sequence::new(vec![ - Ref::keyword("PRIMARY").to_matchable(), - Ref::keyword("KEY").to_matchable(), - Sequence::new(vec![Ref::keyword("AUTOINCREMENT").to_matchable()]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "TemporaryTransientGrammar".into(), - Ref::new("TemporaryGrammar").to_matchable().into(), - ), - ( - "DateTimeLiteralGrammar".into(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DATE").to_matchable(), - Ref::keyword("DATETIME").to_matchable(), - ]) - .to_matchable(), - TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::DateConstructorLiteral) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "BaseExpressionElementGrammar".into(), - one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("BareFunctionSegment").to_matchable(), - Ref::new("FunctionSegment").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("DatatypeSegment").to_matchable(), - Ref::new("LiteralGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "AutoIncrementGrammar".into(), - Nothing::new().to_matchable().into(), - ), - ( - "CommentClauseSegment".into(), - Nothing::new().to_matchable().into(), - ), - ( - "IntervalExpressionSegment".into(), - Nothing::new().to_matchable().into(), - ), - ( - "TimeZoneGrammar".into(), - Nothing::new().to_matchable().into(), + "BackQuotedIdentifierSegment".into(), + TypedParser::new(SyntaxKind::BackQuote, SyntaxKind::QuotedIdentifier) + .to_matchable() + .into(), ), ( - "FetchClauseSegment".into(), - Nothing::new().to_matchable().into(), + "ColumnPathOperatorSegment".into(), + StringParser::new("->", SyntaxKind::ColumnPathOperator) + .to_matchable() + .into(), ), ( - "TrimParametersGrammar".into(), - Nothing::new().to_matchable().into(), + "InlinePathOperatorSegment".into(), + StringParser::new("->>", SyntaxKind::ColumnPathOperator) + .to_matchable() + .into(), ), ( - "LikeGrammar".into(), - Sequence::new(vec![Ref::keyword("LIKE").to_matchable()]) + "QuestionMarkSegment".into(), + StringParser::new("?", SyntaxKind::QuestionMark) .to_matchable() .into(), ), ( - "OverlapsClauseSegment".into(), - Nothing::new().to_matchable().into(), + "AtSignLiteralSegment".into(), + TypedParser::new(SyntaxKind::AtSignLiteral, SyntaxKind::AtSignLiteral) + .to_matchable() + .into(), ), ( - "MLTableExpressionSegment".into(), - Nothing::new().to_matchable().into(), + "ColonLiteralSegment".into(), + TypedParser::new(SyntaxKind::ColonLiteral, SyntaxKind::ColonLiteral) + .to_matchable() + .into(), ), ( - "MergeIntoLiteralGrammar".into(), - Nothing::new().to_matchable().into(), + "QuestionLiteralSegment".into(), + TypedParser::new(SyntaxKind::QuestionLiteral, SyntaxKind::QuestionLiteral) + .to_matchable() + .into(), ), ( - "SamplingExpressionSegment".into(), - Nothing::new().to_matchable().into(), + "DollarLiteralSegment".into(), + TypedParser::new(SyntaxKind::DollarLiteral, SyntaxKind::DollarLiteral) + .to_matchable() + .into(), ), - ( - "OrderByClauseTerminators".into(), + ]); + + sqlite_dialect.replace_grammar( + "PrimaryKeyGrammar", + Sequence::new(vec![ + Ref::keyword("PRIMARY").to_matchable(), + Ref::keyword("KEY").to_matchable(), one_of(vec![ - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::new("FrameClauseUnitGrammar").to_matchable(), + Ref::keyword("ASC").to_matchable(), + Ref::keyword("DESC").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "WhereClauseTerminatorGrammar".into(), - one_of(vec![ - Ref::keyword("LIMIT").to_matchable(), - Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("ConflictClauseSegment").optional().to_matchable(), + Sequence::new(vec![Ref::keyword("AUTOINCREMENT").to_matchable()]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - ]) - .to_matchable() - .into(), + ]) + .to_matchable(), + ); + + sqlite_dialect.replace_grammar( + "NumericLiteralSegment", + one_of(vec![ + TypedParser::new(SyntaxKind::NumericLiteral, SyntaxKind::NumericLiteral).to_matchable(), + Ref::new("ParameterizedSegment").to_matchable(), + ]) + .to_matchable(), + ); + + sqlite_dialect.replace_grammar( + "LiteralGrammar", + ansi_dialect.grammar("LiteralGrammar").copy( + Some(vec![Ref::new("ParameterizedSegment").to_matchable()]), + None, + None, + None, + vec![], + false, ), - ( - "FromClauseTerminatorGrammar".into(), + ); + + sqlite_dialect.replace_grammar( + "TemporaryTransientGrammar", + Ref::new("TemporaryGrammar").to_matchable(), + ); + + sqlite_dialect.replace_grammar( + "DateTimeLiteralGrammar", + Sequence::new(vec![ one_of(vec![ - Ref::keyword("WHERE").to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::new("SetOperatorSegment").to_matchable(), - Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), - Ref::new("WithDataClauseSegment").to_matchable(), + Ref::keyword("DATE").to_matchable(), + Ref::keyword("DATETIME").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "GroupByClauseTerminatorGrammar".into(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) + .to_matchable(), + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::DateConstructorLiteral) .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "PostFunctionGrammar".into(), + ]) + .to_matchable(), + ); + + sqlite_dialect.replace_grammar( + "BaseExpressionElementGrammar", + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), Sequence::new(vec![ - Ref::new("FilterClauseGrammar").optional().to_matchable(), - Ref::new("OverClauseSegment").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "IgnoreRespectNullsGrammar".into(), - Nothing::new().to_matchable().into(), - ), - ( - "SelectClauseTerminatorGrammar".into(), - one_of(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("WHERE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::new("SetOperatorSegment").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "FunctionContentsGrammar".into(), - AnyNumberOf::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("TrimParametersGrammar").to_matchable(), - Ref::new("ExpressionSegment") - .optional() - .exclude(Ref::keyword("FROM")) - .config(|config| { - config.exclude = Ref::keyword("FROM").to_matchable().into(); - }) - .to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::new("DatetimeUnitSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DISTINCT").optional().to_matchable(), - one_of(vec![ - Ref::new("StarSegment").to_matchable(), - Delimited::new(vec![ - Ref::new("FunctionContentsExpressionGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("OrderByClauseSegment").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("IN").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Ref::new("IndexColumnDefinitionSegment").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "Expression_A_Unary_Operator_Grammar".into(), - one_of(vec![ - Ref::new("SignedSegmentGrammar") - .exclude(Sequence::new(vec![ - Ref::new("QualifiedNumericLiteralSegment").to_matchable(), - ])) - .config(|config| { - config.exclude = Sequence::new(vec![ - Ref::new("QualifiedNumericLiteralSegment").to_matchable(), - ]) - .to_matchable() - .into(); - }) - .to_matchable(), - Ref::new("TildeSegment").to_matchable(), - Ref::new("NotOperatorGrammar").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "IsClauseGrammar".into(), - one_of(vec![ - Ref::keyword("NULL").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ]); - sqlite_dialect.add([( - "SetOperatorSegment".into(), - NodeMatcher::new(SyntaxKind::SetOperator, |_| { - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("UNION").to_matchable(), - one_of(vec![ - Ref::keyword("DISTINCT").to_matchable(), - Ref::keyword("ALL").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("INTERSECT").to_matchable(), - Ref::keyword("EXCEPT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("ALL").optional().to_matchable(), - ]) - .to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), ]) - .config(|config| { - config.exclude = Sequence::new(vec![ - Ref::keyword("EXCEPT").to_matchable(), - Bracketed::new(vec![Anything::new().to_matchable()]).to_matchable(), - ]) - .to_matchable() - .into(); - }) - .to_matchable() + .to_matchable(), + ]) + .config(|this| { + this.terminators = vec![ + Ref::new("CommaSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + ]; }) - .to_matchable() - .into(), - )]); + .to_matchable(), + ); sqlite_dialect.replace_grammar( - "DatatypeSegment", + "AlterTableOptionsGrammar", one_of(vec![ Sequence::new(vec![ - Ref::keyword("DOUBLE").to_matchable(), - Ref::keyword("PRECISION").to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - Ref::keyword("UNSIGNED").to_matchable(), - Ref::keyword("BIG").to_matchable(), - Ref::keyword("INT").to_matchable(), + Ref::keyword("RENAME").to_matchable(), + Sequence::new(vec![Ref::keyword("COLUMN").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) .to_matchable(), Sequence::new(vec![ - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("VARYING").to_matchable(), - Ref::keyword("NATIVE").to_matchable(), - ]) - .to_matchable(), - one_of(vec![Ref::keyword("CHARACTER").to_matchable()]).to_matchable(), - ]) + Ref::keyword("ADD").to_matchable(), + Sequence::new(vec![Ref::keyword("COLUMN").to_matchable()]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("DatatypeIdentifierSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("BracketedArguments").optional().to_matchable(), + Ref::new("ColumnDefinitionSegment").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - ); - sqlite_dialect.add([( - "TableEndClauseSegment".into(), - NodeMatcher::new(SyntaxKind::TableEndClauseSegment, |_| { - Delimited::new(vec![ - Sequence::new(vec![ - Ref::keyword("WITHOUT").to_matchable(), - Ref::keyword("ROWID").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("STRICT").to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - )]); - - sqlite_dialect.replace_grammar( - "ValuesClauseSegment", - Sequence::new(vec![ - Ref::keyword("VALUES").to_matchable(), - Delimited::new(vec![ - Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::keyword("DEFAULT").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|config| { - config.parse_mode(ParseMode::Greedy); + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Sequence::new(vec![Ref::keyword("COLUMN").to_matchable()]) + .config(|this| { + this.optional(); }) .to_matchable(), - ]) - .to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), ]) .to_matchable(), ]) .to_matchable(), ); - sqlite_dialect.add([ - ( - "IndexColumnDefinitionSegment".into(), - NodeMatcher::new(SyntaxKind::IndexColumnDefinition, |_| { - Sequence::new(vec![ - one_of(vec![ - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("ASC").to_matchable(), - Ref::keyword("DESC").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "InsertStatementSegment".into(), - NodeMatcher::new(SyntaxKind::InsertStatement, |_| { - Sequence::new(vec![ - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("INSERT").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OR").to_matchable(), - one_of(vec![ - Ref::keyword("ABORT").to_matchable(), - Ref::keyword("FAIL").to_matchable(), - Ref::keyword("IGNORE").to_matchable(), - Ref::keyword("REPLACE").to_matchable(), - Ref::keyword("ROLLBACK").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), - Ref::keyword("REPLACE").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("INTO").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar") - .optional() - .to_matchable(), - one_of(vec![ - Ref::new("ValuesClauseSegment").to_matchable(), - optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) - .to_matchable(), - Ref::new("DefaultValuesGrammar").to_matchable(), - ]) - .to_matchable(), - Ref::new("ReturningClauseSegment").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "DeleteStatementSegment".into(), - NodeMatcher::new(SyntaxKind::DeleteStatement, |_| { - Sequence::new(vec![ - Ref::keyword("DELETE").to_matchable(), - Ref::new("FromClauseSegment").to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), - Ref::new("ReturningClauseSegment").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ( - "UpdateStatementSegment".into(), - NodeMatcher::new(SyntaxKind::UpdateStatement, |_| { - Sequence::new(vec![ - Ref::keyword("UPDATE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Ref::new("AliasExpressionSegment") - .exclude(Ref::keyword("SET")) - .optional() - .to_matchable(), - Ref::new("SetClauseListSegment").to_matchable(), - Ref::new("FromClauseSegment").optional().to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), - Ref::new("ReturningClauseSegment").optional().to_matchable(), - ]) - .to_matchable() - }) - .to_matchable() - .into(), - ), - ]); - let column_constraint = sqlite_dialect - .grammar("ColumnConstraintSegment") - .match_grammar(&sqlite_dialect) - .unwrap() - .copy( + sqlite_dialect.replace_grammar("AutoIncrementGrammar", Nothing::new().to_matchable()); + + sqlite_dialect.replace_grammar("CommentClauseSegment", Nothing::new().to_matchable()); + + sqlite_dialect.replace_grammar("IntervalExpressionSegment", Nothing::new().to_matchable()); + + sqlite_dialect.replace_grammar("TimeZoneGrammar", Nothing::new().to_matchable()); + + sqlite_dialect.replace_grammar("FetchClauseSegment", Nothing::new().to_matchable()); + + sqlite_dialect.replace_grammar("TrimParametersGrammar", Nothing::new().to_matchable()); + + sqlite_dialect.replace_grammar( + "LikeGrammar", + Sequence::new(vec![Ref::keyword("LIKE").to_matchable()]).to_matchable(), + ); + + sqlite_dialect.replace_grammar("OverlapsClauseSegment", Nothing::new().to_matchable()); + + sqlite_dialect.replace_grammar("MLTableExpressionSegment", Nothing::new().to_matchable()); + + sqlite_dialect.replace_grammar("MergeIntoLiteralGrammar", Nothing::new().to_matchable()); + + sqlite_dialect.replace_grammar("SamplingExpressionSegment", Nothing::new().to_matchable()); + + sqlite_dialect.replace_grammar( + "BinaryOperatorGrammar", + ansi_dialect.grammar("BinaryOperatorGrammar").copy( Some(vec![ - one_of(vec![ - Ref::keyword("DEFERRABLE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("DEFERRABLE").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("DEFERRED").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("IMMEDIATE").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), + Ref::new("ColumnPathOperatorSegment").to_matchable(), + Ref::new("InlinePathOperatorSegment").to_matchable(), ]), None, None, None, - Vec::new(), + vec![], false, - ); - sqlite_dialect.replace_grammar("ColumnConstraintSegment", column_constraint); + ), + ); sqlite_dialect.replace_grammar( - "TableConstraintSegment", - Sequence::new(vec![ + "OrderByClauseTerminators", + one_of(vec![ + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::new("FrameClauseUnitGrammar").to_matchable(), + ]) + .to_matchable(), + ); + + sqlite_dialect.replace_grammar( + "WhereClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("LIMIT").to_matchable(), Sequence::new(vec![ - Ref::keyword("CONSTRAINT").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CHECK").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("UNIQUE").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("PrimaryKeyGrammar").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::new("ForeignKeyGrammar").to_matchable(), - Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), - Ref::new("ReferenceDefinitionGrammar").to_matchable(), - ]) - .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) .to_matchable(), - one_of(vec![ - Ref::keyword("DEFERRABLE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("NOT").to_matchable(), - Ref::keyword("DEFERRABLE").to_matchable(), - ]) - .to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + ]) + .to_matchable(), + ); + + sqlite_dialect.replace_grammar( + "FromClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("WHERE").to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("DEFERRED").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("INITIALLY").to_matchable(), - Ref::keyword("IMMEDIATE").to_matchable(), - ]) - .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), + Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), + Ref::new("WithDataClauseSegment").to_matchable(), ]) .to_matchable(), ); sqlite_dialect.replace_grammar( - "TransactionStatementSegment", - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("BEGIN").to_matchable(), - Ref::keyword("COMMIT").to_matchable(), - Ref::keyword("ROLLBACK").to_matchable(), - Ref::keyword("END").to_matchable(), - ]) - .to_matchable(), - one_of(vec![Ref::keyword("TRANSACTION").to_matchable()]) - .config(|config| { - config.optional(); - }) - .to_matchable(), + "GroupByClauseTerminatorGrammar", + one_of(vec![ Sequence::new(vec![ - Ref::keyword("TO").to_matchable(), - Ref::keyword("SAVEPOINT").to_matchable(), - Ref::new("ObjectReferenceSegment").to_matchable(), + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), ]) .to_matchable(), ); - sqlite_dialect.add([( - "PragmaReferenceSegment".into(), - NodeMatcher::new(SyntaxKind::PragmaReference, |sqlite_dialect| { - sqlite_dialect - .grammar("ObjectReferenceSegment") - .match_grammar(sqlite_dialect) - .unwrap() - }) - .to_matchable() - .into(), - )]); + sqlite_dialect.replace_grammar( + "PostFunctionGrammar", + Sequence::new(vec![ + Ref::new("FilterClauseGrammar").optional().to_matchable(), + Ref::new("OverClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + ); - sqlite_dialect.add([( - "PragmaStatementSegment".into(), - NodeMatcher::new(SyntaxKind::PragmaStatement, |_| { - let pragma_value = one_of(vec![ - Ref::new("LiteralGrammar").to_matchable(), - Ref::new("BooleanLiteralGrammar").to_matchable(), - Ref::keyword("YES").to_matchable(), - Ref::keyword("NO").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::keyword("OFF").to_matchable(), - Ref::keyword("NONE").to_matchable(), - Ref::keyword("FULL").to_matchable(), - Ref::keyword("INCREMENTAL").to_matchable(), - Ref::keyword("DELETE").to_matchable(), - Ref::keyword("TRUNCATE").to_matchable(), - Ref::keyword("PERSIST").to_matchable(), - Ref::keyword("MEMORY").to_matchable(), - Ref::keyword("WAL").to_matchable(), - Ref::keyword("NORMAL").to_matchable(), - Ref::keyword("EXCLUSIVE").to_matchable(), - Ref::keyword("FAST").to_matchable(), - Ref::keyword("EXTRA").to_matchable(), - Ref::keyword("DEFAULT").to_matchable(), - Ref::keyword("FILE").to_matchable(), - Ref::keyword("PASSIVE").to_matchable(), - Ref::keyword("RESTART").to_matchable(), - Ref::keyword("RESET").to_matchable(), - ]); + sqlite_dialect.replace_grammar("IgnoreRespectNullsGrammar", Nothing::new().to_matchable()); + sqlite_dialect.replace_grammar( + "SelectClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("WHERE").to_matchable(), Sequence::new(vec![ - Ref::keyword("PRAGMA").to_matchable(), - Ref::new("PragmaReferenceSegment").to_matchable(), - Bracketed::new(vec![pragma_value.clone().to_matchable()]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - Ref::new("EqualsSegment").to_matchable(), - optionally_bracketed(vec![pragma_value.to_matchable()]).to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - }) - .to_matchable() - .into(), - )]); + .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), + ]) + .to_matchable(), + ); sqlite_dialect.replace_grammar( - "CreateTriggerStatementSegment", - Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::new("TemporaryGrammar").optional().to_matchable(), - Ref::keyword("TRIGGER").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("TriggerReferenceSegment").to_matchable(), - one_of(vec![ - Ref::keyword("BEFORE").to_matchable(), - Ref::keyword("AFTER").to_matchable(), - Sequence::new(vec![ - Ref::keyword("INSTEAD").to_matchable(), - Ref::keyword("OF").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - one_of(vec![ - Ref::keyword("DELETE").to_matchable(), - Ref::keyword("INSERT").to_matchable(), - Sequence::new(vec![ - Ref::keyword("UPDATE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("OF").to_matchable(), - Delimited::new(vec![Ref::new("ColumnReferenceSegment").to_matchable()]) - .to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), + "FunctionContentsGrammar", + AnyNumberOf::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), ]) .to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), Sequence::new(vec![ - Ref::keyword("FOR").to_matchable(), - Ref::keyword("EACH").to_matchable(), - Ref::keyword("ROW").to_matchable(), + Ref::new("TrimParametersGrammar").to_matchable(), + Ref::new("ExpressionSegment") + .exclude(Ref::keyword("FROM")) + .optional() + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), Sequence::new(vec![ - Ref::keyword("WHEN").to_matchable(), - Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]).to_matchable(), + one_of(vec![ + Ref::new("DatetimeUnitSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), - Ref::keyword("BEGIN").to_matchable(), - Delimited::new(vec![ - Ref::new("UpdateStatementSegment").to_matchable(), - Ref::new("InsertStatementSegment").to_matchable(), - Ref::new("DeleteStatementSegment").to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), + Sequence::new(vec![ + Ref::keyword("DISTINCT").optional().to_matchable(), + one_of(vec![ + Ref::new("StarSegment").to_matchable(), + Delimited::new(vec![ + Ref::new("FunctionContentsExpressionGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("OrderByClauseSegment").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("IN").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("IndexColumnDefinitionSegment").to_matchable(), + one_of(vec![ + Ref::keyword("IGNORE").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("ABORT").to_matchable(), + Ref::keyword("FAIL").to_matchable(), + Ref::keyword("ROLLBACK").to_matchable(), + ]) + .to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("QuotedLiteralSegment").to_matchable(), + ]) + .to_matchable(), ]) - .config(|config| { - config.delimiter( - AnyNumberOf::new(vec![Ref::new("DelimiterGrammar").to_matchable()]).config( - |config| { - config.min_times = 1; - }, - ), - ); - config.allow_trailing = true; - }) .to_matchable(), - Ref::keyword("END").to_matchable(), ]) .to_matchable(), ); - sqlite_dialect.add([( - "UnorderedSelectStatementSegment".into(), - NodeMatcher::new(SyntaxKind::SelectStatement, |_| { + + sqlite_dialect.replace_grammar( + "Expression_A_Unary_Operator_Grammar", + one_of(vec![ + Ref::new("SignedSegmentGrammar") + .exclude(Sequence::new(vec![ + Ref::new("QualifiedNumericLiteralSegment").to_matchable(), + ])) + .to_matchable(), + Ref::new("TildeSegment").to_matchable(), + Ref::new("NotOperatorGrammar").to_matchable(), + ]) + .to_matchable(), + ); + + sqlite_dialect.replace_grammar( + "IsDistinctFromGrammar", + Sequence::new(vec![ + Ref::keyword("IS").to_matchable(), + Ref::keyword("NOT").optional().to_matchable(), Sequence::new(vec![ - Ref::new("SelectClauseSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - Ref::new("FromClauseSegment").optional().to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), - Ref::new("GroupByClauseSegment").optional().to_matchable(), - Ref::new("HavingClauseSegment").optional().to_matchable(), - Ref::new("OverlapsClauseSegment").optional().to_matchable(), - Ref::new("NamedWindowSegment").optional().to_matchable(), + Ref::keyword("DISTINCT").to_matchable(), + Ref::keyword("FROM").to_matchable(), ]) - .to_matchable() - }) - .to_matchable() - .into(), - )]); + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ); - sqlite_dialect.add([( - "SelectStatementSegment".into(), - NodeMatcher::new(SyntaxKind::SelectStatement, |sqlite_dialect| { - sqlite_dialect - .grammar("UnorderedSelectStatementSegment") - .match_grammar(sqlite_dialect) - .unwrap() - .copy( - Some(vec![ - Ref::new("OrderByClauseSegment").optional().to_matchable(), - Ref::new("FetchClauseSegment").optional().to_matchable(), - Ref::new("LimitClauseSegment").optional().to_matchable(), - Ref::new("NamedWindowSegment").optional().to_matchable(), - ]), - None, - None, - None, - Vec::new(), - false, - ) - }) - .to_matchable() - .into(), - )]); + sqlite_dialect.replace_grammar("NanLiteralSegment", Nothing::new().to_matchable()); sqlite_dialect.replace_grammar( - "CreateIndexStatementSegment", + "PatternMatchingGrammar", Sequence::new(vec![ - Ref::keyword("CREATE").to_matchable(), - Ref::keyword("UNIQUE").optional().to_matchable(), - Ref::keyword("INDEX").to_matchable(), - Ref::new("IfNotExistsGrammar").optional().to_matchable(), - Ref::new("IndexReferenceSegment").to_matchable(), - Ref::keyword("ON").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - Sequence::new(vec![ - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("IndexColumnDefinitionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + Ref::keyword("NOT").optional().to_matchable(), + one_of(vec![ + Ref::keyword("GLOB").to_matchable(), + Ref::keyword("REGEXP").to_matchable(), + Ref::keyword("MATCH").to_matchable(), ]) .to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), ]) .to_matchable(), ); sqlite_dialect.replace_grammar( - "StatementSegment", + "SingleIdentifierGrammar", one_of(vec![ - Ref::new("AlterTableStatementSegment").to_matchable(), - Ref::new("CreateIndexStatementSegment").to_matchable(), - Ref::new("CreateTableStatementSegment").to_matchable(), - Ref::new("CreateTriggerStatementSegment").to_matchable(), - Ref::new("CreateViewStatementSegment").to_matchable(), - Ref::new("DeleteStatementSegment").to_matchable(), - Ref::new("DropIndexStatementSegment").to_matchable(), - Ref::new("DropTableStatementSegment").to_matchable(), - Ref::new("DropTriggerStatementSegment").to_matchable(), - Ref::new("DropViewStatementSegment").to_matchable(), - Ref::new("ExplainStatementSegment").to_matchable(), - Ref::new("InsertStatementSegment").to_matchable(), - Ref::new("PragmaStatementSegment").to_matchable(), - Ref::new("SelectableGrammar").to_matchable(), - Ref::new("TransactionStatementSegment").to_matchable(), - Ref::new("UpdateStatementSegment").to_matchable(), - Bracketed::new(vec![Ref::new("StatementSegment").to_matchable()]).to_matchable(), + Ref::new("NakedIdentifierSegment").to_matchable(), + Ref::new("SingleQuotedIdentifierSegment").to_matchable(), + Ref::new("QuotedIdentifierSegment").to_matchable(), + Ref::new("BackQuotedIdentifierSegment").to_matchable(), ]) + .config(|this| { + this.terminators = vec![Ref::new("DotSegment").to_matchable()]; + }) .to_matchable(), ); sqlite_dialect.replace_grammar( - "AlterTableStatementSegment", - Sequence::new(vec![ - Ref::keyword("ALTER").to_matchable(), - Ref::keyword("TABLE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - one_of(vec![ + "QuotedIdentifierSegment", + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedIdentifier).to_matchable(), + ); + + sqlite_dialect.replace_grammar( + "SingleQuotedIdentifierSegment", + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::QuotedIdentifier).to_matchable(), + ); + + sqlite_dialect.replace_grammar( + "ColumnConstraintDefaultGrammar", + Ref::new("ExpressionSegment").to_matchable(), + ); + + sqlite_dialect.replace_grammar( + "FrameClauseUnitGrammar", + one_of(vec![ + Ref::keyword("ROWS").to_matchable(), + Ref::keyword("RANGE").to_matchable(), + Ref::keyword("GROUPS").to_matchable(), + ]) + .to_matchable(), + ); + + sqlite_dialect.add([ + ( + "FrameClauseSegment".into(), + NodeMatcher::new(SyntaxKind::FrameClause, |_dialect| { Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("TO").to_matchable(), + Ref::new("FrameClauseUnitGrammar").to_matchable(), one_of(vec![ + Sequence::new(vec![ + Ref::keyword("UNBOUNDED").to_matchable(), + Ref::keyword("PRECEDING").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("PRECEDING").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("BETWEEN").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("UNBOUNDED").to_matchable(), + Ref::keyword("PRECEDING").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("PRECEDING").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("AND").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("UNBOUNDED").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("PRECEDING").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXCLUDE").to_matchable(), one_of(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("QuotedIdentifierSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NO").to_matchable(), + Ref::keyword("OTHERS").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("TIES").to_matchable(), + Ref::keyword("GROUP").to_matchable(), ]) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("RENAME").to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - Ref::keyword("TO").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ADD").to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - Ref::new("ColumnDefinitionSegment").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ParameterizedSegment".into(), + NodeMatcher::new(SyntaxKind::ParameterizedExpression, |_dialect| { + one_of(vec![ + Ref::new("AtSignLiteralSegment").to_matchable(), + Ref::new("QuestionMarkSegment").to_matchable(), + Ref::new("ColonLiteralSegment").to_matchable(), + Ref::new("QuestionLiteralSegment").to_matchable(), + Ref::new("DollarLiteralSegment").to_matchable(), ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("DROP").to_matchable(), - Ref::keyword("COLUMN").optional().to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SetOperatorSegment".into(), + NodeMatcher::new(SyntaxKind::SetOperator, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("UNION").to_matchable(), + one_of(vec![ + Ref::keyword("DISTINCT").to_matchable(), + Ref::keyword("ALL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("INTERSECT").to_matchable(), + Ref::keyword("EXCEPT").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("ALL").optional().to_matchable(), + ]) + .to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - sqlite_dialect.add([( - "ReturningClauseSegment".into(), - Sequence::new(vec![ - Ref::keyword("RETURNING").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ - Ref::new("StarSegment").to_matchable(), - Delimited::new(vec![ + .config(|this| { + this.exclude = Some( + Sequence::new(vec![ + Ref::keyword("EXCEPT").to_matchable(), + Bracketed::new(vec![Anything::new().to_matchable()]).to_matchable(), + ]) + .to_matchable(), + ); + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ColumnReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnReference, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Sequence::new(vec![ + one_of(vec![ + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + None, + None, + None, + None, + vec![], + false, + ), + Ref::new("FunctionSegment").to_matchable(), + Ref::new("BareFunctionSegment").to_matchable(), + Ref::new("LiteralGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "TableReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::TableReference, |_dialect| { + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + Some(vec![ + Sequence::new(vec![ + { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + } + .copy( + None, + None, + None, + None, + vec![], + false, + ), + one_of(vec![ + Ref::new("ColumnPathOperatorSegment").to_matchable(), + Ref::new("InlinePathOperatorSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![Ref::new("LiteralGrammar").to_matchable()]).to_matchable(), + ]) + .to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "DatatypeSegment".into(), + NodeMatcher::new(SyntaxKind::DataType, |_dialect| { + one_of(vec![ Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::new("AsAliasExpressionSegment") - .optional() + Ref::keyword("DOUBLE").to_matchable(), + Ref::keyword("PRECISION").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNSIGNED").to_matchable(), + Ref::keyword("BIG").to_matchable(), + Ref::keyword("INT").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("VARYING").to_matchable(), + Ref::keyword("NATIVE").to_matchable(), + ]) + .to_matchable(), + one_of(vec![Ref::keyword("CHARACTER").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![Ref::keyword("CHARACTER").to_matchable()]) + .to_matchable(), + one_of(vec![ + Ref::keyword("VARYING").to_matchable(), + Ref::keyword("NATIVE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("DatatypeIdentifierSegment").to_matchable(), + ]) + .to_matchable(), + Ref::new("BracketedArguments").optional().to_matchable(), + one_of(vec![Ref::keyword("UNSIGNED").to_matchable()]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) - .to_matchable() - .into(), - )]); - - sqlite_dialect.add([( - "AsAliasExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::AliasExpression, |_| { - Sequence::new(vec![ - MetaSegment::indent().to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - MetaSegment::dedent().to_matchable(), - ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableEndClauseSegment".into(), + NodeMatcher::new(SyntaxKind::TableEndClauseSegment, |_dialect| { + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("WITHOUT").to_matchable(), + Ref::keyword("ROWID").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("STRICT").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ValuesClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ValuesClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("VALUES").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.parse_mode(ParseMode::Greedy); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "IndexColumnDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::IndexColumnDefinition, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("ASC").to_matchable(), + Ref::keyword("DESC").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ReturningClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ReturningClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("RETURNING").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Ref::new("WildcardExpressionSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ConflictTargetSegment".into(), + NodeMatcher::new(SyntaxKind::ConflictTarget, |_dialect| { + Sequence::new(vec![ + Delimited::new(vec![ + Ref::new("IndexColumnDefinitionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WHERE").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UpsertClauseSegment".into(), + NodeMatcher::new(SyntaxKind::UpsertClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("CONFLICT").to_matchable(), + Ref::new("ConflictTargetSegment").optional().to_matchable(), + Ref::keyword("DO").to_matchable(), + one_of(vec![ + Ref::keyword("NOTHING").to_matchable(), + Sequence::new(vec![ + Ref::keyword("UPDATE").to_matchable(), + Ref::keyword("SET").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + Sequence::new(vec![ + Ref::keyword("WHERE").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "InsertStatementSegment".into(), + NodeMatcher::new(SyntaxKind::InsertStatement, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("INSERT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("OR").to_matchable(), + one_of(vec![ + Ref::keyword("ABORT").to_matchable(), + Ref::keyword("FAIL").to_matchable(), + Ref::keyword("IGNORE").to_matchable(), + Ref::keyword("REPLACE").to_matchable(), + Ref::keyword("ROLLBACK").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("REPLACE").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::new("ValuesClauseSegment").to_matchable(), + Ref::new("UpsertClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + optionally_bracketed(vec![ + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("UpsertClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + Ref::new("DefaultValuesGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("ReturningClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ConflictClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ConflictClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("CONFLICT").to_matchable(), + one_of(vec![ + Ref::keyword("ROLLBACK").to_matchable(), + Ref::keyword("ABORT").to_matchable(), + Ref::keyword("FAIL").to_matchable(), + Ref::keyword("IGNORE").to_matchable(), + Ref::keyword("REPLACE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ColumnConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnConstraintSegment, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("NOT").optional().to_matchable(), + Ref::keyword("NULL").to_matchable(), + Ref::new("ConflictClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("CHECK").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DEFAULT").to_matchable(), + Ref::new("ColumnConstraintDefaultGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("PrimaryKeyGrammar").to_matchable(), + Sequence::new(vec![ + Ref::new("UniqueKeyGrammar").to_matchable(), + Ref::new("ConflictClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + Ref::new("AutoIncrementGrammar").to_matchable(), + Ref::new("ReferenceDefinitionGrammar").to_matchable(), + Ref::new("CommentClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLLATE").to_matchable(), + Ref::new("CollationReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("GENERATED").to_matchable(), + Ref::keyword("ALWAYS").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("AS").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + one_of(vec![ + Ref::keyword("STORED").to_matchable(), + Ref::keyword("VIRTUAL").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("DEFERRABLE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("DEFERRABLE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("DEFERRED").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("IMMEDIATE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TableConstraintSegment".into(), + NodeMatcher::new(SyntaxKind::TableConstraint, |_dialect| { + Sequence::new(vec![ + Sequence::new(vec![ + Ref::keyword("CONSTRAINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CHECK").to_matchable(), + Bracketed::new(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("UNIQUE").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::new("ConflictClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("PrimaryKeyGrammar").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::new("ConflictClauseSegment").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("ForeignKeyGrammar").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::new("ReferenceDefinitionGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("DEFERRABLE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("DEFERRABLE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("DEFERRED").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("INITIALLY").to_matchable(), + Ref::keyword("IMMEDIATE").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) .to_matchable() - }) - .to_matchable() - .into(), - )]); + .into(), + ), + ( + "TransactionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::TransactionStatement, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("BEGIN").to_matchable(), + Ref::keyword("COMMIT").to_matchable(), + Ref::keyword("ROLLBACK").to_matchable(), + Ref::keyword("END").to_matchable(), + ]) + .to_matchable(), + one_of(vec![Ref::keyword("TRANSACTION").to_matchable()]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("TO").to_matchable(), + Ref::keyword("SAVEPOINT").to_matchable(), + Ref::new("ObjectReferenceSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "PragmaReferenceSegment".into(), + NodeMatcher::new(SyntaxKind::PragmaReference, |_dialect| { + let dialect = super::ansi::raw_dialect(); + dialect + .grammar("ObjectReferenceSegment") + .match_grammar(&dialect) + .unwrap() + }) + .to_matchable() + .into(), + ), + ( + "PragmaStatementSegment".into(), + NodeMatcher::new(SyntaxKind::PragmaStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("PRAGMA").to_matchable(), + Ref::new("PragmaReferenceSegment").to_matchable(), + one_of(vec![ + Bracketed::new(vec![ + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::keyword("YES").to_matchable(), + Ref::keyword("NO").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("OFF").to_matchable(), + Ref::keyword("NONE").to_matchable(), + Ref::keyword("FULL").to_matchable(), + Ref::keyword("INCREMENTAL").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("TRUNCATE").to_matchable(), + Ref::keyword("PERSIST").to_matchable(), + Ref::keyword("MEMORY").to_matchable(), + Ref::keyword("WAL").to_matchable(), + Ref::keyword("NORMAL").to_matchable(), + Ref::keyword("EXCLUSIVE").to_matchable(), + Ref::keyword("FAST").to_matchable(), + Ref::keyword("EXTRA").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("FILE").to_matchable(), + Ref::keyword("PASSIVE").to_matchable(), + Ref::keyword("RESTART").to_matchable(), + Ref::keyword("RESET").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Bracketed::new(vec![Ref::new("ObjectReferenceSegment").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::new("EqualsSegment").to_matchable(), + optionally_bracketed(vec![ + one_of(vec![ + Ref::new("LiteralGrammar").to_matchable(), + Ref::new("BooleanLiteralGrammar").to_matchable(), + Ref::keyword("YES").to_matchable(), + Ref::keyword("NO").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::keyword("OFF").to_matchable(), + Ref::keyword("NONE").to_matchable(), + Ref::keyword("FULL").to_matchable(), + Ref::keyword("INCREMENTAL").to_matchable(), + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("TRUNCATE").to_matchable(), + Ref::keyword("PERSIST").to_matchable(), + Ref::keyword("MEMORY").to_matchable(), + Ref::keyword("WAL").to_matchable(), + Ref::keyword("NORMAL").to_matchable(), + Ref::keyword("EXCLUSIVE").to_matchable(), + Ref::keyword("FAST").to_matchable(), + Ref::keyword("EXTRA").to_matchable(), + Ref::keyword("DEFAULT").to_matchable(), + Ref::keyword("FILE").to_matchable(), + Ref::keyword("PASSIVE").to_matchable(), + Ref::keyword("RESTART").to_matchable(), + Ref::keyword("RESET").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateTriggerStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTriggerStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + Ref::keyword("TRIGGER").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TriggerReferenceSegment").to_matchable(), + one_of(vec![ + Ref::keyword("BEFORE").to_matchable(), + Ref::keyword("AFTER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("INSTEAD").to_matchable(), + Ref::keyword("OF").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + one_of(vec![ + Ref::keyword("DELETE").to_matchable(), + Ref::keyword("INSERT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("UPDATE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("OF").to_matchable(), + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("FOR").to_matchable(), + Ref::keyword("EACH").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WHEN").to_matchable(), + MetaSegment::indent().to_matchable(), + optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("BEGIN").to_matchable(), + MetaSegment::indent().to_matchable(), + Delimited::new(vec![ + Ref::new("UpdateStatementSegment").to_matchable(), + Ref::new("InsertStatementSegment").to_matchable(), + Ref::new("DeleteStatementSegment").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .config(|this| { + this.allow_trailing(); + this.delimiter( + AnyNumberOf::new(vec![Ref::new("DelimiterGrammar").to_matchable()]) + .config(|this| { + this.min_times(1); + }), + ); + }) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::keyword("END").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateViewStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateViewStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("TemporaryGrammar").optional().to_matchable(), + Ref::keyword("VIEW").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar") + .optional() + .to_matchable(), + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UnorderedSelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + Sequence::new(vec![ + Ref::new("SelectClauseSegment").to_matchable(), + Ref::new("FromClauseSegment").optional().to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + Ref::new("GroupByClauseSegment").optional().to_matchable(), + Ref::new("HavingClauseSegment").optional().to_matchable(), + Ref::new("OverlapsClauseSegment").optional().to_matchable(), + Ref::new("NamedWindowSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "DeleteStatementSegment".into(), + NodeMatcher::new(SyntaxKind::DeleteStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("DELETE").to_matchable(), + Ref::new("FromClauseSegment").to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + Ref::new("ReturningClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "UpdateStatementSegment".into(), + NodeMatcher::new(SyntaxKind::UpdateStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("UPDATE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("OR").to_matchable(), + one_of(vec![ + Ref::keyword("ABORT").to_matchable(), + Ref::keyword("FAIL").to_matchable(), + Ref::keyword("IGNORE").to_matchable(), + Ref::keyword("REPLACE").to_matchable(), + Ref::keyword("ROLLBACK").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + MetaSegment::indent().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::new("AliasExpressionSegment").optional().to_matchable(), + MetaSegment::dedent().to_matchable(), + Ref::new("SetClauseListSegment").to_matchable(), + Ref::new("FromClauseSegment").optional().to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + Ref::new("ReturningClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SetClauseSegment".into(), + NodeMatcher::new(SyntaxKind::SetClause, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + get_unordered_select_statement_segment_grammar().copy( + Some(vec![ + Ref::new("OrderByClauseSegment").optional().to_matchable(), + Ref::new("FetchClauseSegment").optional().to_matchable(), + Ref::new("LimitClauseSegment").optional().to_matchable(), + Ref::new("NamedWindowSegment").optional().to_matchable(), + ]), + None, + None, + None, + vec![], + false, + ) + }) + .to_matchable() + .into(), + ), + ( + "GroupingSetsClauseSegment".into(), + NodeMatcher::new(SyntaxKind::GroupingSetsClause, |_dialect| { + Nothing::new().to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateIndexStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateIndexStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("UNIQUE").optional().to_matchable(), + Ref::keyword("INDEX").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("IndexReferenceSegment").to_matchable(), + Ref::keyword("ON").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("IndexColumnDefinitionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateVirtualTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateVirtualTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::keyword("VIRTUAL").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Ref::keyword("USING").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "StatementSegment".into(), + NodeMatcher::new(SyntaxKind::Statement, |_dialect| { + one_of(vec![ + Ref::new("AlterTableStatementSegment").to_matchable(), + Ref::new("CreateIndexStatementSegment").to_matchable(), + Ref::new("CreateTableStatementSegment").to_matchable(), + Ref::new("CreateVirtualTableStatementSegment").to_matchable(), + Ref::new("CreateTriggerStatementSegment").to_matchable(), + Ref::new("CreateViewStatementSegment").to_matchable(), + Ref::new("DeleteStatementSegment").to_matchable(), + Ref::new("DropIndexStatementSegment").to_matchable(), + Ref::new("DropTableStatementSegment").to_matchable(), + Ref::new("DropTriggerStatementSegment").to_matchable(), + Ref::new("DropViewStatementSegment").to_matchable(), + Ref::new("ExplainStatementSegment").to_matchable(), + Ref::new("InsertStatementSegment").to_matchable(), + Ref::new("PragmaStatementSegment").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + Ref::new("TransactionStatementSegment").to_matchable(), + Ref::new("UpdateStatementSegment").to_matchable(), + Bracketed::new(vec![Ref::new("StatementSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ]); sqlite_dialect } + +pub fn get_unordered_select_statement_segment_grammar() -> Matchable { + Sequence::new(vec![ + Ref::new("SelectClauseSegment").to_matchable(), + Ref::new("FromClauseSegment").optional().to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + Ref::new("GroupByClauseSegment").optional().to_matchable(), + Ref::new("HavingClauseSegment").optional().to_matchable(), + Ref::new("OverlapsClauseSegment").optional().to_matchable(), + Ref::new("NamedWindowSegment").optional().to_matchable(), + ]) + .to_matchable() +} diff --git a/crates/lib-dialects/src/sqlite_keywords.rs b/crates/lib-dialects/src/sqlite_keywords.rs index c538b5b43..a44eebe84 100644 --- a/crates/lib-dialects/src/sqlite_keywords.rs +++ b/crates/lib-dialects/src/sqlite_keywords.rs @@ -1,10 +1,5 @@ -// A List of SQLite keywords. -// https://www.sqlite.org/lang_keywords.html -// Augmented with data types, and a couple of omitted keywords. - -pub(crate) const RESERVED_KEYWORDS: &[&str] = &[ +pub(crate) const RESERVED_KEYWORDS: [&str; 144] = [ "ABORT", - "ACTION", "ADD", "AFTER", "ALL", @@ -82,7 +77,6 @@ pub(crate) const RESERVED_KEYWORDS: &[&str] = &[ "IS", "ISNULL", "JOIN", - "KEY", "LAST", "LEFT", "LIKE", @@ -132,7 +126,6 @@ pub(crate) const RESERVED_KEYWORDS: &[&str] = &[ "TEMP", "TEMPORARY", "THEN", - "TIES", "TO", "TRANSACTION", "TRIGGER", @@ -152,7 +145,8 @@ pub(crate) const RESERVED_KEYWORDS: &[&str] = &[ "WITHOUT", ]; -pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ +pub(crate) const UNRESERVED_KEYWORDS: [&str; 52] = [ + "KEY", "INT", "INTEGER", "TINYINT", @@ -168,6 +162,7 @@ pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ "NCHAR", "NATIVE", "NVARCHAR", + "TIES", "TEXT", "CLOB", "BLOB", @@ -201,4 +196,6 @@ pub(crate) const UNRESERVED_KEYWORDS: &[&str] = &[ "BINARY", "NOCASE", "RTRIM", + "STORED", + "ACTION", ]; diff --git a/crates/lib-dialects/src/trino.rs b/crates/lib-dialects/src/trino.rs index 45dceda50..a9db20ec8 100644 --- a/crates/lib-dialects/src/trino.rs +++ b/crates/lib-dialects/src/trino.rs @@ -2,7 +2,7 @@ use sqruff_lib_core::dialects::Dialect; use sqruff_lib_core::dialects::init::DialectKind; use sqruff_lib_core::dialects::syntax::SyntaxKind; use sqruff_lib_core::helpers::{Config, ToMatchable}; -use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of}; +use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed}; use sqruff_lib_core::parser::grammar::delimited::Delimited; use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence}; use sqruff_lib_core::parser::grammar::{Anything, Nothing, Ref}; @@ -12,9 +12,15 @@ use sqruff_lib_core::parser::node_matcher::NodeMatcher; use sqruff_lib_core::parser::parsers::{StringParser, TypedParser}; use sqruff_lib_core::parser::segments::meta::MetaSegment; +use super::trino_keywords::{TRINO_RESERVED_KEYWORDS, TRINO_UNRESERVED_KEYWORDS}; + pub fn dialect() -> Dialect { + raw_dialect().config(|this| this.expand()) +} + +pub fn raw_dialect() -> Dialect { let ansi_dialect = super::ansi::raw_dialect(); - let mut trino_dialect = ansi_dialect; + let mut trino_dialect = ansi_dialect.clone(); trino_dialect.name = DialectKind::Trino; trino_dialect.sets_mut("bare_functions").extend([ @@ -26,20 +32,22 @@ pub fn dialect() -> Dialect { ]); trino_dialect.sets_mut("unreserved_keywords").clear(); + trino_dialect.update_keywords_set_from_multiline_string( "unreserved_keywords", - super::trino_keywords::TRINO_UNRESERVED_KEYWORDS, + TRINO_UNRESERVED_KEYWORDS, ); trino_dialect.sets_mut("reserved_keywords").clear(); - trino_dialect.update_keywords_set_from_multiline_string( - "reserved_keywords", - super::trino_keywords::TRINO_RESERVED_KEYWORDS, - ); + + trino_dialect + .update_keywords_set_from_multiline_string("reserved_keywords", TRINO_RESERVED_KEYWORDS); trino_dialect.insert_lexer_matchers( - // Regexp Replace w/ Lambda: https://trino.io/docs/422/functions/regexp.html - vec![Matcher::string("right_arrow", "->", SyntaxKind::RightArrow)], + vec![ + Matcher::string("right_arrow", r#"->"#, SyntaxKind::RightArrow), + Matcher::string("fat_right_arrow", r#"=>"#, SyntaxKind::FatRightArrow), + ], "like_operator", ); @@ -52,7 +60,13 @@ pub fn dialect() -> Dialect { ), ( "LambdaArrowSegment".into(), - StringParser::new("->", SyntaxKind::Symbol) + StringParser::new("->", SyntaxKind::LambdaArrow) + .to_matchable() + .into(), + ), + ( + "ExecuteArrowSegment".into(), + StringParser::new("=>", SyntaxKind::ExecuteArrow) .to_matchable() .into(), ), @@ -80,11 +94,11 @@ pub fn dialect() -> Dialect { Ref::keyword("UTF16").to_matchable(), Ref::keyword("UTF32").to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), ]) .to_matchable() @@ -102,380 +116,324 @@ pub fn dialect() -> Dialect { )], ); - trino_dialect.add([ - ( - "DateTimeLiteralGrammar".into(), - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("DATE").to_matchable(), - Ref::keyword("TIME").to_matchable(), - Ref::keyword("TIMESTAMP").to_matchable(), - ]) - .to_matchable(), - TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::DateConstructorLiteral) - .to_matchable(), + trino_dialect.patch_lexer_matchers(vec![Matcher::regex( + "double_quote", + r#""([^"]|"")*""#, + SyntaxKind::DoubleQuote, + )]); + + trino_dialect.replace_grammar( + "DateTimeLiteralGrammar", + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("DATE").to_matchable(), + Ref::keyword("TIME").to_matchable(), + Ref::keyword("TIMESTAMP").to_matchable(), ]) .to_matchable(), - Ref::new("IntervalExpressionSegment").to_matchable(), + TypedParser::new(SyntaxKind::SingleQuote, SyntaxKind::DateConstructorLiteral) + .to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "LikeGrammar".into(), - Sequence::new(vec![Ref::keyword("LIKE").to_matchable()]) - .to_matchable() - .into(), - ), - ( - "MLTableExpressionSegment".into(), - Nothing::new().to_matchable().into(), - ), - ( - "FromClauseTerminatorGrammar".into(), - one_of(vec![ - Ref::keyword("WHERE").to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::new("SetOperatorSegment").to_matchable(), - Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), - Ref::new("WithDataClauseSegment").to_matchable(), - Ref::keyword("FETCH").to_matchable(), + .to_matchable(), + Ref::new("IntervalExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ); + + trino_dialect.replace_grammar( + "LikeGrammar", + Sequence::new(vec![Ref::keyword("LIKE").to_matchable()]).to_matchable(), + ); + + trino_dialect.replace_grammar("MLTableExpressionSegment", Nothing::new().to_matchable()); + + trino_dialect.replace_grammar( + "FromClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("WHERE").to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "OrderByClauseTerminators".into(), - one_of(vec![ - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::new("FrameClauseUnitGrammar").to_matchable(), - Ref::keyword("FETCH").to_matchable(), + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "SelectClauseTerminatorGrammar".into(), - one_of(vec![ - Ref::keyword("FROM").to_matchable(), - Ref::keyword("WHERE").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::new("SetOperatorSegment").to_matchable(), - Ref::keyword("FETCH").to_matchable(), + .to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), + Ref::new("WithNoSchemaBindingClauseSegment").to_matchable(), + Ref::new("WithDataClauseSegment").to_matchable(), + Ref::keyword("FETCH").to_matchable(), + ]) + .to_matchable(), + ); + + trino_dialect.replace_grammar( + "OrderByClauseTerminators", + one_of(vec![ + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::new("FrameClauseUnitGrammar").to_matchable(), + Ref::keyword("FETCH").to_matchable(), + ]) + .to_matchable(), + ); + + trino_dialect.replace_grammar( + "SelectClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("FROM").to_matchable(), + Ref::keyword("WHERE").to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "WhereClauseTerminatorGrammar".into(), - one_of(vec![ - Ref::keyword("LIMIT").to_matchable(), - Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::keyword("FETCH").to_matchable(), + .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::new("SetOperatorSegment").to_matchable(), + Ref::keyword("FETCH").to_matchable(), + ]) + .to_matchable(), + ); + + trino_dialect.replace_grammar( + "WhereClauseTerminatorGrammar", + one_of(vec![ + Ref::keyword("LIMIT").to_matchable(), + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "HavingClauseTerminatorGrammar".into(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::keyword("FETCH").to_matchable(), + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "GroupByClauseTerminatorGrammar".into(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("ORDER").to_matchable(), - Ref::keyword("BY").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("LIMIT").to_matchable(), - Ref::keyword("HAVING").to_matchable(), - Ref::keyword("WINDOW").to_matchable(), - Ref::keyword("FETCH").to_matchable(), + .to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::keyword("FETCH").to_matchable(), + ]) + .to_matchable(), + ); + + trino_dialect.replace_grammar( + "HavingClauseTerminatorGrammar", + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "Expression_A_Unary_Operator_Grammar".into(), - one_of(vec![ - Ref::new("SignedSegmentGrammar") - .exclude(Sequence::new(vec![ - Ref::new("QualifiedNumericLiteralSegment").to_matchable(), - ])) - .to_matchable(), - Ref::new("TildeSegment").to_matchable(), - Ref::new("NotOperatorGrammar").to_matchable(), + .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::keyword("FETCH").to_matchable(), + ]) + .to_matchable(), + ); + + trino_dialect.replace_grammar( + "GroupByClauseTerminatorGrammar", + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("ORDER").to_matchable(), + Ref::keyword("BY").to_matchable(), ]) - .to_matchable() - .into(), + .to_matchable(), + Ref::keyword("LIMIT").to_matchable(), + Ref::keyword("HAVING").to_matchable(), + Ref::keyword("WINDOW").to_matchable(), + Ref::keyword("FETCH").to_matchable(), + ]) + .to_matchable(), + ); + + trino_dialect.replace_grammar( + "Expression_A_Unary_Operator_Grammar", + one_of(vec![ + Ref::new("SignedSegmentGrammar") + .exclude(Sequence::new(vec![ + Ref::new("QualifiedNumericLiteralSegment").to_matchable(), + ])) + .to_matchable(), + Ref::new("TildeSegment").to_matchable(), + Ref::new("NotOperatorGrammar").to_matchable(), + ]) + .to_matchable(), + ); + + trino_dialect.replace_grammar( + "PostFunctionGrammar", + ansi_dialect.grammar("PostFunctionGrammar").copy( + Some(vec![ + Ref::new("WithinGroupClauseSegment").to_matchable(), + Ref::new("WithOrdinalityClauseSegment").to_matchable(), + ]), + None, + None, + None, + vec![], + false, ), - ( - "FunctionContentsGrammar".into(), - AnyNumberOf::new(vec![ + ); + + trino_dialect.replace_grammar( + "FunctionContentsGrammar", + AnyNumberOf::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Sequence::new(vec![ Ref::new("ExpressionSegment").to_matchable(), - // A Cast-like function - Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::keyword("AS").to_matchable(), - Ref::new("DatatypeSegment").to_matchable(), - ]) - .to_matchable(), - // A Trim function - Sequence::new(vec![ - Ref::new("TrimParametersGrammar").to_matchable(), - Ref::new("ExpressionSegment") - .optional() - .exclude(Ref::keyword("FROM")) - .to_matchable(), - Ref::keyword("FROM").to_matchable(), + Ref::keyword("AS").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("TrimParametersGrammar").to_matchable(), + Ref::new("ExpressionSegment") + .exclude(Ref::keyword("FROM")) + .optional() + .to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("DatetimeUnitSegment").to_matchable(), Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - // An extract-like or substring-like function - Sequence::new(vec![ - one_of(vec![ - Ref::new("DatetimeUnitSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), + Ref::keyword("FROM").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DISTINCT").optional().to_matchable(), + one_of(vec![ + Ref::new("StarSegment").to_matchable(), + Delimited::new(vec![ + Ref::new("FunctionContentsExpressionGrammar").to_matchable(), ]) .to_matchable(), - Ref::keyword("FROM").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), - Sequence::new(vec![ - // Allow an optional DISTINCT keyword here. - Ref::keyword("DISTINCT").optional().to_matchable(), - one_of(vec![ - // Most functions will be using the delimiited route - // but for COUNT(*) or similar we allow the star segement - // here. - Ref::new("StarSegment").to_matchable(), - Delimited::new(vec![ - Ref::new("FunctionContentsExpressionGrammar").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), + ]) + .to_matchable(), + Ref::new("OrderByClauseSegment").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), ]) .to_matchable(), - Ref::new("OrderByClauseSegment").to_matchable(), - // # used by string_agg (postgres), group_concat (exasol),listagg (snowflake) - // # like a function call: POSITION ( 'QL' IN 'SQL') - Sequence::new(vec![ - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) + Ref::keyword("IN").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::new("ExpressionSegment").to_matchable(), + Ref::new("FormatJsonEncodingGrammar") + .optional() .to_matchable(), - Ref::keyword("IN").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("WITHOUT").to_matchable(), + Ref::keyword("ARRAY").optional().to_matchable(), + Ref::keyword("WRAPPER").to_matchable(), ]) .to_matchable(), - ]) - .to_matchable(), - // For JSON_QUERY function - // https://trino.io/docs/current/functions/json.html#json_query - Sequence::new(vec![ - Ref::new("ExpressionSegment").to_matchable(), - Ref::new("FormatJsonEncodingGrammar") - .optional() - .to_matchable(), - Ref::new("CommaSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - one_of(vec![ - Sequence::new(vec![ - Ref::keyword("WITHOUT").to_matchable(), - Ref::keyword("ARRAY").optional().to_matchable(), - Ref::keyword("WRAPPER").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - one_of(vec![ - Ref::keyword("CONDITIONAL").to_matchable(), - Ref::keyword("UNCONDITIONAL").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Ref::keyword("ARRAY").optional().to_matchable(), - Ref::keyword("WRAPPER").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + one_of(vec![ + Ref::keyword("CONDITIONAL").to_matchable(), + Ref::keyword("UNCONDITIONAL").to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), + Ref::keyword("ARRAY").optional().to_matchable(), + Ref::keyword("WRAPPER").to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), ]) + .config(|this| { + this.optional(); + }) .to_matchable(), - Ref::new("IgnoreRespectNullsGrammar").to_matchable(), - Ref::new("IndexColumnDefinitionSegment").to_matchable(), - Ref::new("EmptyStructLiteralSegment").to_matchable(), - Ref::new("ListaggOverflowClauseSegment").to_matchable(), ]) - .to_matchable() - .into(), - ), - ( - "FormatJsonEncodingGrammar".into(), - Sequence::new(vec![ - Ref::keyword("FORMAT").to_matchable(), - Ref::keyword("JSON").to_matchable(), - Sequence::new(vec![ - Ref::keyword("ENCODING").to_matchable(), - one_of(vec![ - Ref::keyword("UTF8").to_matchable(), - Ref::keyword("UTF16").to_matchable(), - Ref::keyword("UTF32").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ]); - trino_dialect.replace_grammar( - "UnorderedSelectStatementSegment", - Sequence::new(vec![ - Ref::new("SelectClauseSegment").to_matchable(), - MetaSegment::dedent().to_matchable(), - Ref::new("FromClauseSegment").optional().to_matchable(), - Ref::new("WhereClauseSegment").optional().to_matchable(), - Ref::new("GroupByClauseSegment").optional().to_matchable(), - Ref::new("HavingClauseSegment").optional().to_matchable(), - Ref::new("NamedWindowSegment").optional().to_matchable(), + .to_matchable(), + Ref::new("IgnoreRespectNullsGrammar").to_matchable(), + Ref::new("IndexColumnDefinitionSegment").to_matchable(), + Ref::new("EmptyStructLiteralSegment").to_matchable(), + Ref::new("ListaggOverflowClauseSegment").to_matchable(), ]) .to_matchable(), ); trino_dialect.replace_grammar( - "ArrayTypeSegment", - Sequence::new(vec![ - Ref::keyword("ARRAY").to_matchable(), - Ref::new("ArrayTypeSchemaSegment").optional().to_matchable(), + "BinaryOperatorGrammar", + one_of(vec![ + Ref::new("ArithmeticBinaryOperatorGrammar").to_matchable(), + Ref::new("StringBinaryOperatorGrammar").to_matchable(), + Ref::new("BooleanBinaryOperatorGrammar").to_matchable(), + Ref::new("ComparisonOperatorGrammar").to_matchable(), + Ref::new("RightArrowOperator").to_matchable(), ]) .to_matchable(), ); - trino_dialect.add([( - "ArrayTypeSchemaSegment".into(), - one_of(vec![ - Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) - .config(|config| { - config.bracket_pairs_set = "angle_bracket_pairs"; - config.bracket_type = "angle"; - }) - .to_matchable(), - Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) - .config(|config| { - config.bracket_type = "round"; - }) - .to_matchable(), + trino_dialect.replace_grammar( + "AccessorGrammar", + AnyNumberOf::new(vec![ + Ref::new("ArrayAccessorSegment").to_matchable(), + Ref::new("SemiStructuredAccessorSegment").to_matchable(), ]) - .to_matchable() - .into(), - )]); + .to_matchable(), + ); trino_dialect.replace_grammar( - "GroupByClauseSegment", - Sequence::new(vec![ - Ref::keyword("GROUP").to_matchable(), - Ref::keyword("BY").to_matchable(), - MetaSegment::indent().to_matchable(), - one_of(vec![ - Ref::keyword("ALL").to_matchable(), - Ref::new("CubeRollupClauseSegment").to_matchable(), - // Add GROUPING SETS support - Ref::new("GroupingSetsClauseSegment").to_matchable(), - Sequence::new(vec![ - Delimited::new(vec![ - Ref::new("ColumnReferenceSegment").to_matchable(), - // Can `GROUP BY 1` - Ref::new("NumericLiteralSegment").to_matchable(), - // Can `GROUP BY coalesce(col, 1)` - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|config| { - config.terminators = - vec![Ref::new("GroupByClauseTerminatorGrammar").to_matchable()] - }) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - MetaSegment::dedent().to_matchable(), + "QuotedIdentifierSegment", + TypedParser::new(SyntaxKind::DoubleQuote, SyntaxKind::QuotedIdentifier).to_matchable(), + ); + + trino_dialect.replace_grammar( + "FunctionContentsExpressionGrammar", + one_of(vec![ + Ref::new("LambdaExpressionSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), ]) .to_matchable(), ); + trino_dialect.replace_grammar("TemporaryTransientGrammar", Nothing::new().to_matchable()); + + trino_dialect.replace_grammar("PrimaryKeyGrammar", Nothing::new().to_matchable()); + + trino_dialect.replace_grammar("ForeignKeyGrammar", Nothing::new().to_matchable()); + + trino_dialect.replace_grammar("UniqueKeyGrammar", Nothing::new().to_matchable()); + + trino_dialect.replace_grammar("TemporaryGrammar", Nothing::new().to_matchable()); + trino_dialect.add([ ( - "FunctionContentsExpressionGrammar".into(), - one_of(vec![ - Ref::new("LambdaExpressionSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "DatatypeSegment".into(), - NodeMatcher::new(SyntaxKind::DataType, |_| { + "PrimitiveTypeSegment".into(), + NodeMatcher::new(SyntaxKind::PrimitiveType, |_dialect| { one_of(vec![ Ref::keyword("BOOLEAN").to_matchable(), Ref::keyword("TINYINT").to_matchable(), @@ -502,37 +460,7 @@ pub fn dialect() -> Dialect { Ref::keyword("VARBINARY").to_matchable(), Ref::keyword("JSON").to_matchable(), Ref::keyword("DATE").to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("TIME").to_matchable(), - Ref::keyword("TIMESTAMP").to_matchable(), - ]) - .to_matchable(), - Bracketed::new(vec![Ref::new("NumericLiteralSegment").to_matchable()]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("WITHOUT").to_matchable(), - ]) - .to_matchable(), - Ref::keyword("TIME").to_matchable(), - Ref::keyword("ZONE").to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable(), - // Structural - Ref::new("ArrayTypeSegment").to_matchable(), - Ref::keyword("MAP").to_matchable(), - Ref::new("RowTypeSegment").to_matchable(), - // Others + Ref::new("TimeWithTZGrammar").to_matchable(), Ref::keyword("IPADDRESS").to_matchable(), Ref::keyword("UUID").to_matchable(), ]) @@ -542,66 +470,44 @@ pub fn dialect() -> Dialect { .into(), ), ( - // Expression to construct a ROW datatype. - "RowTypeSegment".into(), - Sequence::new(vec![ - Ref::keyword("ROW").to_matchable(), - Ref::new("RowTypeSchemaSegment").optional().to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "AccessorGrammar".into(), - AnyNumberOf::new(vec![ - Ref::new("ArrayAccessorSegment").to_matchable(), - // Add in semi structured expressions - Ref::new("SemiStructuredAccessorSegment").to_matchable(), - ]) + "DatatypeSegment".into(), + NodeMatcher::new(SyntaxKind::DataType, |_dialect| { + one_of(vec![ + Ref::new("PrimitiveTypeSegment").to_matchable(), + Ref::new("ArrayTypeSegment").to_matchable(), + Ref::new("MapTypeSegment").to_matchable(), + Ref::new("RowTypeSegment").to_matchable(), + ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - // A semi-structured data accessor segment. - "SemiStructuredAccessorSegment".into(), - Sequence::new(vec![ - Ref::new("DotSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - Ref::new("ArrayAccessorSegment").optional().to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - Ref::new("DotSegment").to_matchable(), - Ref::new("SingleIdentifierGrammar").to_matchable(), - ]) - .config(|config| { - config.allow_gaps = true; - }) - .to_matchable(), - Ref::new("ArrayAccessorSegment").optional().to_matchable(), + "RowTypeSegment".into(), + NodeMatcher::new(SyntaxKind::StructType, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ROW").to_matchable(), + Ref::new("RowTypeSchemaSegment").optional().to_matchable(), ]) - .config(|config| { - config.allow_gaps = true; - }) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - // Expression to construct the schema of a ROW datatype. "RowTypeSchemaSegment".into(), - Bracketed::new(vec![ - Delimited::new(vec![ - // Comma-separated list of field names/types - Sequence::new(vec![ - one_of(vec![ - // ParameterNames can look like Datatypes so can't use - // Optional=True here and instead do a OneOf in order - // with DataType only first, followed by both. - Ref::new("DatatypeSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), + NodeMatcher::new(SyntaxKind::StructTypeSchema, |_dialect| { + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + one_of(vec![ Ref::new("DatatypeSegment").to_matchable(), + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -609,196 +515,73 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "OverlapsClauseSegment".into(), - NodeMatcher::new(SyntaxKind::OverlapsClause, |_| { - Nothing::new().to_matchable() + .to_matchable() }) .to_matchable() .into(), ), - ]); - - trino_dialect.replace_grammar( - "ValuesClauseSegment", - Sequence::new(vec![ - Ref::keyword("VALUES").to_matchable(), - Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]).to_matchable(), - ]) - .to_matchable(), - ); - - trino_dialect.replace_grammar( - "StatementSegment", - super::ansi::statement_segment().copy( - Some(vec![ - Ref::new("AnalyzeStatementSegment").to_matchable(), - Ref::new("CommentOnStatementSegment").to_matchable(), - ]), - None, - None, - Some(vec![Ref::new("TransactionStatementSegment").to_matchable()]), - Vec::new(), - false, - ), - ); - - trino_dialect.add([ - // An 'ANALYZE' statement. - // As per docs https://trino.io/docs/current/sql/analyze.html ( - "AnalyzeStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("ANALYZE").to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), + "SemiStructuredAccessorSegment".into(), + NodeMatcher::new(SyntaxKind::SemiStructuredExpression, |_dialect| { Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Ref::new("EqualsSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .config(|config| { - config.optional(); - }) - .to_matchable(), - ]) - .to_matchable() - .into(), - ), - ( - "PostFunctionGrammar".into(), - super::ansi::raw_dialect() - .grammar("PostFunctionGrammar") - .copy( - Some(vec![ - Ref::new("WithinGroupClauseSegment").to_matchable(), - Ref::new("WithOrdinalityClauseSegment").to_matchable(), - ]), - None, - None, - Some(vec![Ref::new("TransactionStatementSegment").to_matchable()]), - Vec::new(), - false, - ) - .into(), - ), - ( - // ON OVERFLOW clause of listagg function. - // https://trino.io/docs/current/functions/aggregate.html#array_agg - "ListaggOverflowClauseSegment".into(), - Sequence::new(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("OVERFLOW").to_matchable(), - one_of(vec![ - Ref::keyword("ERROR").to_matchable(), - Sequence::new(vec![ - Ref::keyword("TRUNCATE").to_matchable(), - Ref::new("SingleQuotedIdentifierSegment") - .optional() - .to_matchable(), - one_of(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("WITHOUT").to_matchable(), + Ref::new("DotSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("ArrayAccessorSegment").optional().to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::new("DotSegment").to_matchable(), + Ref::new("SingleIdentifierGrammar").to_matchable(), ]) - .config(|config| { - config.optional(); - }) .to_matchable(), - Ref::keyword("COUNT").optional().to_matchable(), + Ref::new("ArrayAccessorSegment").optional().to_matchable(), ]) .to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - // An WITHIN GROUP clause for window functions. - // https://trino.io/docs/current/functions/aggregate.html#array_agg - // Trino supports an optional FILTER during aggregation that comes - // immediately after the WITHIN GROUP clause. - // https://trino.io/docs/current/functions/aggregate.html#filtering-during-aggregation - "WithinGroupClauseSegment".into(), - Sequence::new(vec![ - Ref::keyword("WITHIN").to_matchable(), - Ref::keyword("GROUP").to_matchable(), - Bracketed::new(vec![Ref::new("OrderByClauseSegment").to_matchable()]) - .to_matchable(), - Ref::new("FilterClauseGrammar").optional().to_matchable(), - ]) + "OverlapsClauseSegment".into(), + NodeMatcher::new(SyntaxKind::OverlapsClause, |_dialect| { + Nothing::new().to_matchable() + }) .to_matchable() .into(), ), ( - // A WITH ORDINALITY clause for CROSS JOIN UNNEST(...). - // https://trino.io/docs/current/sql/select.html#unnest - // Trino supports an optional WITH ORDINALITY clause on UNNEST, which - // adds a numerical ordinality column to the UNNEST result. - "WithOrdinalityClauseSegment".into(), - Sequence::new(vec![ - Ref::keyword("WITH").to_matchable(), - Ref::keyword("ORDINALITY").to_matchable(), - ]) + "UnorderedSelectStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SelectStatement, |_dialect| { + Sequence::new(vec![ + Ref::new("SelectClauseSegment").to_matchable(), + Ref::new("FromClauseSegment").optional().to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + Ref::new("GroupByClauseSegment").optional().to_matchable(), + Ref::new("HavingClauseSegment").optional().to_matchable(), + Ref::new("NamedWindowSegment").optional().to_matchable(), + ]) + .to_matchable() + }) .to_matchable() .into(), ), ( - // `COMMENT ON` statement. - // https://trino.io/docs/current/sql/comment.html - "CommentOnStatementSegment".into(), - Sequence::new(vec![ - Ref::keyword("COMMENT").to_matchable(), - Ref::keyword("ON").to_matchable(), + "ValuesClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ValuesClause, |_dialect| { Sequence::new(vec![ - one_of(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("TABLE").to_matchable(), - // TODO: Create a ViewReferenceSegment - Ref::keyword("VIEW").to_matchable(), - ]) - .to_matchable(), - Ref::new("TableReferenceSegment").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("COLUMN").to_matchable(), - // TODO: Does this correctly emit a Table Reference? - Ref::new("ColumnReferenceSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - Ref::keyword("IS").to_matchable(), - one_of(vec![ - Ref::new("QuotedLiteralSegment").to_matchable(), - Ref::keyword("NULL").to_matchable(), - ]) + Ref::keyword("VALUES").to_matchable(), + Delimited::new(vec![Ref::new("ExpressionSegment").to_matchable()]) .to_matchable(), - ]) - .to_matchable(), ]) - .to_matchable(), - ]) + .to_matchable() + }) .to_matchable() .into(), ), ( "IntervalExpressionSegment".into(), - NodeMatcher::new(SyntaxKind::IntervalExpression, |_| { + NodeMatcher::new(SyntaxKind::IntervalExpression, |_dialect| { Sequence::new(vec![ Ref::keyword("INTERVAL").to_matchable(), Ref::new("QuotedLiteralSegment").to_matchable(), @@ -819,38 +602,79 @@ pub fn dialect() -> Dialect { ), ( "FrameClauseSegment".into(), - NodeMatcher::new(SyntaxKind::FrameClause, |_| { - let frame_extent = one_of(vec![ - Sequence::new(vec![ - Ref::keyword("CURRENT").to_matchable(), - Ref::keyword("ROW").to_matchable(), - ]) - .to_matchable(), - Sequence::new(vec![ - one_of(vec![ - Ref::new("NumericLiteralSegment").to_matchable(), - Ref::new("DateTimeLiteralGrammar").to_matchable(), - Ref::keyword("UNBOUNDED").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("PRECEDING").to_matchable(), - Ref::keyword("FOLLOWING").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]); - + NodeMatcher::new(SyntaxKind::FrameClause, |_dialect| { Sequence::new(vec![ Ref::new("FrameClauseUnitGrammar").to_matchable(), one_of(vec![ - frame_extent.clone().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("DateTimeLiteralGrammar").to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), Sequence::new(vec![ Ref::keyword("BETWEEN").to_matchable(), - frame_extent.clone().to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("DateTimeLiteralGrammar").to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), Ref::keyword("AND").to_matchable(), - frame_extent.to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("CURRENT").to_matchable(), + Ref::keyword("ROW").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("DateTimeLiteralGrammar").to_matchable(), + Ref::keyword("UNBOUNDED").to_matchable(), + ]) + .to_matchable(), + one_of(vec![ + Ref::keyword("PRECEDING").to_matchable(), + Ref::keyword("FOLLOWING").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), ]) .to_matchable(), ]) @@ -863,7 +687,7 @@ pub fn dialect() -> Dialect { ), ( "SetOperatorSegment".into(), - NodeMatcher::new(SyntaxKind::SetOperator, |_| { + NodeMatcher::new(SyntaxKind::SetOperator, |_dialect| { one_of(vec![ Sequence::new(vec![ Ref::keyword("UNION").to_matchable(), @@ -871,8 +695,8 @@ pub fn dialect() -> Dialect { Ref::keyword("DISTINCT").to_matchable(), Ref::keyword("ALL").to_matchable(), ]) - .config(|config| { - config.optional(); + .config(|this| { + this.optional(); }) .to_matchable(), ]) @@ -887,13 +711,14 @@ pub fn dialect() -> Dialect { ]) .to_matchable(), ]) - .config(|config| { - config.exclude = Sequence::new(vec![ - Ref::keyword("EXCEPT").to_matchable(), - Bracketed::new(vec![Anything::new().to_matchable()]).to_matchable(), - ]) - .to_matchable() - .into(); + .config(|this| { + this.exclude = Some( + Sequence::new(vec![ + Ref::keyword("EXCEPT").to_matchable(), + Bracketed::new(vec![Anything::new().to_matchable()]).to_matchable(), + ]) + .to_matchable(), + ); }) .to_matchable() }) @@ -901,21 +726,678 @@ pub fn dialect() -> Dialect { .into(), ), ( - "LambdaExpressionSegment".into(), - Sequence::new(vec![ + "StatementSegment".into(), + NodeMatcher::new(SyntaxKind::Statement, |_dialect| { one_of(vec![ - Ref::new("ParameterNameSegment").to_matchable(), - Bracketed::new(vec![Ref::new("ParameterNameSegment").to_matchable()]) - .to_matchable(), + Ref::new("AlterTableStatementSegment").to_matchable(), + Ref::new("AnalyzeStatementSegment").to_matchable(), + Ref::new("CommentOnStatementSegment").to_matchable(), + Ref::new("CreateFunctionStatementSegment").to_matchable(), + Ref::new("CreateRoleStatementSegment").to_matchable(), + Ref::new("CreateSchemaStatementSegment").to_matchable(), + Ref::new("CreateTableStatementSegment").to_matchable(), + Ref::new("CreateViewStatementSegment").to_matchable(), + Ref::new("DeleteStatementSegment").to_matchable(), + Ref::new("DescribeStatementSegment").to_matchable(), + Ref::new("DropFunctionStatementSegment").to_matchable(), + Ref::new("DropRoleStatementSegment").to_matchable(), + Ref::new("DropSchemaStatementSegment").to_matchable(), + Ref::new("DropTableStatementSegment").to_matchable(), + Ref::new("DropViewStatementSegment").to_matchable(), + Ref::new("ExplainStatementSegment").to_matchable(), + Ref::new("InsertStatementSegment").to_matchable(), + Ref::new("MergeStatementSegment").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + Ref::new("SetSchemaStatementSegment").to_matchable(), + Ref::new("TransactionStatementSegment").to_matchable(), + Ref::new("UpdateStatementSegment").to_matchable(), + Ref::new("UseStatementSegment").to_matchable(), + Ref::new("SetSessionStatementSegment").to_matchable(), ]) - .to_matchable(), - Ref::new("LambdaArrowSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) + .config(|this| { + this.terminators = vec![Ref::new("DelimiterGrammar").to_matchable()]; + }) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AnalyzeStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AnalyzeStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ANALYZE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WithOrdinalityClauseSegment".into(), + NodeMatcher::new(SyntaxKind::WithordinalityClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("ORDINALITY").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "WithinGroupClauseSegment".into(), + NodeMatcher::new(SyntaxKind::WithingroupClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("WITHIN").to_matchable(), + Ref::keyword("GROUP").to_matchable(), + Bracketed::new(vec![Ref::new("OrderByClauseSegment").to_matchable()]) + .to_matchable(), + Ref::new("FilterClauseGrammar").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ListaggOverflowClauseSegment".into(), + NodeMatcher::new(SyntaxKind::ListaggOverflowClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("OVERFLOW").to_matchable(), + one_of(vec![ + Ref::keyword("ERROR").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TRUNCATE").to_matchable(), + Ref::new("QuotedLiteralSegment").optional().to_matchable(), + one_of(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("WITHOUT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("COUNT").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ArrayTypeSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayType, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ARRAY").to_matchable(), + Ref::new("ArrayTypeSchemaSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ArrayTypeSchemaSegment".into(), + NodeMatcher::new(SyntaxKind::ArrayTypeSchema, |_dialect| { + one_of(vec![ + Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .config(|this| { + this.bracket_type("angle"); + this.bracket_pairs_set = "angle_bracket_pairs"; + }) + .to_matchable(), + Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) + .config(|this| { + this.bracket_type("round"); + this.bracket_pairs_set = "bracket_pairs"; + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "GroupByClauseSegment".into(), + NodeMatcher::new(SyntaxKind::GroupbyClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("GROUP").to_matchable(), + Ref::keyword("BY").to_matchable(), + MetaSegment::indent().to_matchable(), + one_of(vec![ + Ref::keyword("ALL").to_matchable(), + Ref::new("CubeRollupClauseSegment").to_matchable(), + Ref::new("GroupingSetsClauseSegment").to_matchable(), + Sequence::new(vec![ + Delimited::new(vec![ + one_of(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("NumericLiteralSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.terminators = + vec![Ref::new("GroupByClauseTerminatorGrammar").to_matchable()]; + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + MetaSegment::dedent().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CommentOnStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CommentClause, |_dialect| { + Sequence::new(vec![ + Ref::keyword("COMMENT").to_matchable(), + Ref::keyword("ON").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("TABLE").to_matchable(), + Ref::keyword("VIEW").to_matchable(), + ]) + .to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("IS").to_matchable(), + one_of(vec![ + Ref::new("QuotedLiteralSegment").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "LambdaExpressionSegment".into(), + NodeMatcher::new(SyntaxKind::LambdaFunction, |_dialect| { + Sequence::new(vec![ + one_of(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![Ref::new("ParameterNameSegment").to_matchable()]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Ref::new("LambdaArrowSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "CreateTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::CreateTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("CREATE").to_matchable(), + Ref::new("OrReplaceGrammar").optional().to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::new("ColumnDefinitionSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("LIKE").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + Sequence::new(vec![ + one_of(vec![ + Ref::keyword("INCLUDING").to_matchable(), + Ref::keyword("EXCLUDING").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("PROPERTIES").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("CommentClauseSegment").optional().to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("AS").to_matchable(), + optionally_bracketed(vec![Ref::new("SelectableGrammar").to_matchable()]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("NO").optional().to_matchable(), + Ref::keyword("DATA").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "ColumnDefinitionSegment".into(), + NodeMatcher::new(SyntaxKind::ColumnDefinition, |_dialect| { + Sequence::new(vec![ + Ref::new("SingleIdentifierGrammar").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + AnyNumberOf::new(vec![ + Sequence::new(vec![ + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + Ref::new("CommentClauseSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("WITH").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.max_times_per_element = Some(1); + }) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "TransactionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::TransactionStatement, |_dialect| { + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("COMMIT").to_matchable(), + Ref::keyword("WORK").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROLLBACK").to_matchable(), + Ref::keyword("WORK").optional().to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("START").to_matchable(), + Ref::keyword("TRANSACTION").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::keyword("ISOLATION").to_matchable(), + Ref::keyword("LEVEL").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("READ").to_matchable(), + Ref::keyword("UNCOMMITTED").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("READ").to_matchable(), + Ref::keyword("COMMITTED").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("REPEATABLE").to_matchable(), + Ref::keyword("READ").to_matchable(), + ]) + .to_matchable(), + Ref::keyword("SERIALIZABLE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("READ").to_matchable(), + one_of(vec![ + Ref::keyword("ONLY").to_matchable(), + Ref::keyword("WRITE").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "InsertStatementSegment".into(), + NodeMatcher::new(SyntaxKind::InsertStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("INSERT").to_matchable(), + Ref::keyword("INTO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Ref::new("SelectableGrammar").to_matchable(), + Sequence::new(vec![ + Ref::new("BracketedColumnReferenceListGrammar").to_matchable(), + Ref::new("SelectableGrammar").to_matchable(), + ]) + .to_matchable(), + Ref::new("DefaultValuesGrammar").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "SetSessionStatementSegment".into(), + NodeMatcher::new(SyntaxKind::SetSessionStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("SESSION").to_matchable(), + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("DotSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "AlterTableStatementSegment".into(), + NodeMatcher::new(SyntaxKind::AlterTableStatement, |_dialect| { + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("TABLE").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("TableReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ADD").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfNotExistsGrammar").optional().to_matchable(), + Ref::new("ColumnDefinitionSegment").to_matchable(), + one_of(vec![ + Ref::keyword("FIRST").to_matchable(), + Ref::keyword("LAST").to_matchable(), + Sequence::new(vec![ + Ref::keyword("AFTER").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("RENAME").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("IfExistsGrammar").optional().to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + Ref::keyword("TO").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ALTER").to_matchable(), + Ref::keyword("COLUMN").to_matchable(), + Ref::new("ColumnReferenceSegment").to_matchable(), + one_of(vec![ + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("DATA").to_matchable(), + Ref::keyword("TYPE").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("DROP").to_matchable(), + Ref::keyword("NOT").to_matchable(), + Ref::keyword("NULL").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("AUTHORIZATION").to_matchable(), + one_of(vec![ + Ref::new("RoleReferenceSegment").to_matchable(), + Sequence::new(vec![ + Ref::keyword("USER").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("ROLE").to_matchable(), + Ref::new("RoleReferenceSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("SET").to_matchable(), + Ref::keyword("PROPERTIES").to_matchable(), + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("EqualsSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("EXECUTE").to_matchable(), + Ref::new("FunctionNameSegment").to_matchable(), + Bracketed::new(vec![ + Delimited::new(vec![ + Sequence::new(vec![ + Ref::new("ParameterNameSegment").to_matchable(), + Ref::new("ExecuteArrowSegment").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Sequence::new(vec![ + Ref::keyword("WHERE").to_matchable(), + Ref::new("ExpressionSegment").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MapTypeSegment".into(), + NodeMatcher::new(SyntaxKind::MapType, |_dialect| { + Sequence::new(vec![ + Ref::keyword("MAP").to_matchable(), + Ref::new("MapTypeSchemaSegment").optional().to_matchable(), + ]) + .to_matchable() + }) + .to_matchable() + .into(), + ), + ( + "MapTypeSchemaSegment".into(), + NodeMatcher::new(SyntaxKind::MapTypeSchema, |_dialect| { + one_of(vec![ + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::new("PrimitiveTypeSegment").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.bracket_type("angle"); + this.bracket_pairs_set = "angle_bracket_pairs"; + }) + .to_matchable(), + Bracketed::new(vec![ + Sequence::new(vec![ + Ref::new("PrimitiveTypeSegment").to_matchable(), + Ref::new("CommaSegment").to_matchable(), + Ref::new("DatatypeSegment").to_matchable(), + ]) + .to_matchable(), + ]) + .config(|this| { + this.bracket_type("round"); + this.bracket_pairs_set = "bracket_pairs"; + }) + .to_matchable(), + ]) + .to_matchable() + }) .to_matchable() .into(), ), ]); - trino_dialect.config(|dialect| dialect.expand()) + trino_dialect } diff --git a/crates/lib-dialects/src/trino_keywords.rs b/crates/lib-dialects/src/trino_keywords.rs index 593877ecb..e21652e09 100644 --- a/crates/lib-dialects/src/trino_keywords.rs +++ b/crates/lib-dialects/src/trino_keywords.rs @@ -33,6 +33,7 @@ FALSE FOR FROM FULL +FUNCTION GROUP GROUPING HAVING diff --git a/crates/lib-dialects/src/tsql.rs b/crates/lib-dialects/src/tsql.rs index 75cb87e04..923abb596 100644 --- a/crates/lib-dialects/src/tsql.rs +++ b/crates/lib-dialects/src/tsql.rs @@ -1,1712 +1,2621 @@ -// T-SQL (Transact-SQL) dialect implementation for Microsoft SQL Server - use itertools::Itertools; use sqruff_lib_core::dialects::Dialect; use sqruff_lib_core::dialects::init::DialectKind; use sqruff_lib_core::dialects::syntax::SyntaxKind; use sqruff_lib_core::helpers::{Config, ToMatchable}; -use sqruff_lib_core::parser::grammar::Ref; use sqruff_lib_core::parser::grammar::anyof::{AnyNumberOf, one_of, optionally_bracketed}; use sqruff_lib_core::parser::grammar::conditional::Conditional; use sqruff_lib_core::parser::grammar::delimited::Delimited; use sqruff_lib_core::parser::grammar::sequence::{Bracketed, Sequence}; -use sqruff_lib_core::parser::lexer::Matcher; -use sqruff_lib_core::parser::lookahead::LookaheadExclude; +use sqruff_lib_core::parser::grammar::{Nothing, Ref}; +use sqruff_lib_core::parser::lexer::{Matcher, Pattern}; +use sqruff_lib_core::parser::matchable::{Matchable, MatchableTrait}; use sqruff_lib_core::parser::node_matcher::NodeMatcher; -use sqruff_lib_core::parser::parsers::{RegexParser, StringParser, TypedParser}; +use sqruff_lib_core::parser::parsers::{MultiStringParser, RegexParser, StringParser, TypedParser}; use sqruff_lib_core::parser::segments::generator::SegmentGenerator; use sqruff_lib_core::parser::segments::meta::MetaSegment; use sqruff_lib_core::parser::types::ParseMode; -use crate::{ansi, tsql_keywords}; +use super::tsql_keywords::{FUTURE_RESERVED_KEYWORDS, RESERVED_KEYWORDS, UNRESERVED_KEYWORDS}; pub fn dialect() -> Dialect { - raw_dialect().config(|dialect| dialect.expand()) + raw_dialect().config(|this| this.expand()) } +#[rustfmt::skip] pub fn raw_dialect() -> Dialect { - // Start with ANSI SQL as the base dialect and customize for T-SQL - let mut dialect = ansi::raw_dialect(); - dialect.name = DialectKind::Tsql; - - // Extend ANSI keywords with T-SQL specific keywords - // IMPORTANT: Don't clear ANSI keywords as they contain fundamental SQL keywords - dialect - .sets_mut("reserved_keywords") - .extend(tsql_keywords::tsql_additional_reserved_keywords()); - dialect - .sets_mut("unreserved_keywords") - .extend(tsql_keywords::tsql_additional_unreserved_keywords()); - - // Add table hint keywords to unreserved keywords - dialect.sets_mut("unreserved_keywords").extend([ - "NOLOCK", - "READUNCOMMITTED", - "READCOMMITTED", - "REPEATABLEREAD", - "SERIALIZABLE", - "READPAST", - "ROWLOCK", - "TABLOCK", - "TABLOCKX", - "UPDLOCK", - "XLOCK", - "NOEXPAND", - "INDEX", - "FORCESEEK", - "FORCESCAN", - "HOLDLOCK", - "SNAPSHOT", - ]); - - // T-SQL specific operators - dialect.sets_mut("operator_symbols").extend([ - "%=", "&=", "*=", "+=", "-=", "/=", "^=", "|=", // Compound assignment - "!<", "!>", // Special comparison operators + let ansi_dialect = super::ansi::raw_dialect(); + let mut tsql_dialect = ansi_dialect.clone(); + tsql_dialect.name = DialectKind::Tsql; + + tsql_dialect.sets_mut("reserved_keywords").clear(); + + tsql_dialect.sets_mut("unreserved_keywords").clear(); + + tsql_dialect.sets_mut("future_reserved_keywords").clear(); + + tsql_dialect.sets_mut("reserved_keywords").extend(RESERVED_KEYWORDS); + + tsql_dialect.sets_mut("unreserved_keywords").extend(UNRESERVED_KEYWORDS); + + tsql_dialect.sets_mut("future_reserved_keywords").extend(FUTURE_RESERVED_KEYWORDS); + + tsql_dialect.sets_mut("datetime_units").clear(); + + tsql_dialect.sets_mut("datetime_units").extend(["D", "DAY", "DAYS", "DAYOFYEAR", "DD", "DW", "DY", "HH", "HOUR", "ISO_WEEK", "ISOWK", "ISOWW", "INFINITE", "M", "MCS", "MI", "MICROSECOND", "MILLISECOND", "MINUTE", "MM", "MONTH", "MONTHS", "MS", "N", "NANOSECOND", "NS", "Q", "QQ", "QUARTER", "S", "SECOND", "SS", "TZ", "TZOFFSET", "W", "WEEK", "WEEKS", "WEEKDAY", "WK", "WW", "YEAR", "YEARS", "Y", "YY", "YYYY"]); + + tsql_dialect.sets_mut("date_part_function_name").clear(); + + tsql_dialect.sets_mut("date_part_function_name").extend(["DATEADD", "DATEDIFF", "DATEDIFF_BIG", "DATENAME", "DATEPART", "DATETRUNC"]); + + tsql_dialect.sets_mut("date_format").clear(); + + tsql_dialect.sets_mut("date_format").extend(["mdy", "dmy", "ymd", "myd", "dym"]); + + tsql_dialect.sets_mut("bare_functions").extend(["CURRENT_USER", "SESSION_USER", "SYSTEM_USER", "USER"]); + + tsql_dialect.sets_mut("sqlcmd_operators").clear(); + + tsql_dialect.sets_mut("sqlcmd_operators").extend(["r", "setvar"]); + + tsql_dialect.sets_mut("file_compression").clear(); + + tsql_dialect.sets_mut("file_compression").extend(["'org.apache.hadoop.io.compress.GzipCodec'", "'org.apache.hadoop.io.compress.DefaultCodec'", "'org.apache.hadoop.io.compress.SnappyCodec'"]); + + tsql_dialect.sets_mut("file_encoding").clear(); + + tsql_dialect.sets_mut("file_encoding").extend(["'UTF8'", "'UTF16'"]); + + tsql_dialect.sets_mut("serde_method").clear(); + + tsql_dialect.sets_mut("serde_method").extend(["'org.apache.hadoop.hive.serde2.columnar.LazyBinaryColumnarSerDe'", "'org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe'"]); + + tsql_dialect.insert_lexer_matchers(vec![ + Matcher::regex("atsign", r#"[@][a-zA-Z0-9_@$#]+"#, SyntaxKind::Atsign), + Matcher::regex("square_quote", r#"\[([^\[\]]*)*\]"#, SyntaxKind::SquareQuote), + Matcher::regex("single_quote_with_n", r#"N'([^']|'')*'"#, SyntaxKind::SingleQuoteWithN), + Matcher::regex("hash_prefix", r#"[#][#]?[a-zA-Z0-9_@$#]+"#, SyntaxKind::HashPrefix), + Matcher::legacy("unquoted_relative_sql_file_path", |_| true, r#"[.\w\\/#-]+\.[sS][qQ][lL]\b"#, SyntaxKind::UnquotedRelativeSqlFilePath), + ], "back_quote"); + + tsql_dialect.insert_lexer_matchers(vec![ + Matcher::regex("numeric_literal", r#"([xX]'([\da-fA-F][\da-fA-F])+'|0[xX][\da-fA-F]*)"#, SyntaxKind::NumericLiteral), + ], "word"); + + tsql_dialect.patch_lexer_matchers(vec![ + Matcher::regex("single_quote", r#"'([^']|'')*'"#, SyntaxKind::SingleQuote), + Matcher::regex("inline_comment", r#"(--)[^\n]*"#, SyntaxKind::InlineComment), + Matcher::native("block_comment", sqruff_lib_core::parser::lexer::nested_block_comment, SyntaxKind::BlockComment) + .subdivider(Pattern::legacy("newline", |_| true, r#"\r\n|\n"#, SyntaxKind::Newline)) + .post_subdivide(Pattern::legacy("whitespace", |_| true, r#"[^\S\r\n]+"#, SyntaxKind::Whitespace)), + Matcher::regex("word", r#"[0-9a-zA-Z_#@$\p{L}]+"#, SyntaxKind::Word), ]); - - // T-SQL supports square brackets for identifiers and @ for variables - // Insert square bracket identifier before individual bracket matchers to ensure it's matched first - dialect.insert_lexer_matchers( - vec![ - // Square brackets for identifiers: [Column Name] - Matcher::regex( - "tsql_square_bracket_identifier", - r"\[[^\]]*\]", - SyntaxKind::DoubleQuote, - ), - ], - "start_square_bracket", - ); - - // Insert other T-SQL specific matchers - dialect.insert_lexer_matchers( - vec![ - // Variables: @MyVar (local) or @@ROWCOUNT (global/system) - Matcher::regex( - "tsql_variable", - r"@@?[a-zA-Z_][a-zA-Z0-9_]*", - SyntaxKind::TsqlVariable, - ), - ], - "equals", - ); - - // T-SQL specific lexer patches: - // 1. T-SQL only uses -- for inline comments, not # (which is used in temp table names) - // 2. Update word pattern to allow # at the beginning (temp tables) and end (SQL Server 2017+ syntax) - dialect.patch_lexer_matchers(vec![ - Matcher::regex("inline_comment", r"--[^\n]*", SyntaxKind::InlineComment), - Matcher::regex( - "word", - r"##?[a-zA-Z0-9_]+|[0-9a-zA-Z_]+#?", - SyntaxKind::Word, + + tsql_dialect.add([ + ( + "PercentSegment".into(), + TypedParser::new(SyntaxKind::Percent, SyntaxKind::Percent) + .to_matchable() + .into() ), - ]); - - // Since T-SQL uses square brackets as quoted identifiers and the lexer - // already maps them to SyntaxKind::DoubleQuote, the ANSI QuotedIdentifierSegment - // should handle them correctly. No additional parser configuration needed. - - // Add T-SQL specific bare functions - dialect.sets_mut("bare_functions").extend([ - "CURRENT_TIMESTAMP", - "CURRENT_USER", - "SESSION_USER", - "SYSTEM_USER", - "USER", - ]); - - // Add aggregate and other functions - dialect - .sets_mut("aggregate_functions") - .extend(["STRING_AGG"]); - - dialect - .sets_mut("special_functions") - .extend(["COALESCE", "NULLIF", "ISNULL"]); - - // T-SQL datetime units - dialect.sets_mut("datetime_units").extend([ - "YEAR", - "YY", - "YYYY", - "QUARTER", - "QQ", - "Q", - "MONTH", - "MM", - "M", - "DAYOFYEAR", - "DY", - "Y", - "DAY", - "DD", - "D", - "WEEK", - "WK", - "WW", - "WEEKDAY", - "DW", - "HOUR", - "HH", - "MINUTE", - "MI", - "N", - "SECOND", - "SS", - "S", - "MILLISECOND", - "MS", - "MICROSECOND", - "MCS", - "NANOSECOND", - "NS", - ]); - - // Add T-SQL specific date functions - dialect.sets_mut("date_part_function_name").extend([ - "DATEADD", - "DATEDIFF", - "DATENAME", - "DATEPART", - "DAY", - "MONTH", - "YEAR", - "GETDATE", - "GETUTCDATE", - "SYSDATETIME", - "SYSUTCDATETIME", - "SYSDATETIMEOFFSET", - ]); - - // Add T-SQL string functions - dialect.sets_mut("scalar_functions").extend([ - "SUBSTRING", - "CHARINDEX", - "LEN", - "LEFT", - "RIGHT", - "LTRIM", - "RTRIM", - "REPLACE", - "STUFF", - "PATINDEX", - "QUOTENAME", - "REPLICATE", - "REVERSE", - "SPACE", - "STR", - "UNICODE", - ]); - - // T-SQL specific value table functions - dialect.sets_mut("value_table_functions").extend([ - "OPENROWSET", - "OPENQUERY", - "OPENDATASOURCE", - "OPENXML", - ]); - - // Add T-SQL specific grammar - - // TOP clause support (e.g., SELECT TOP 10, TOP (10) PERCENT, TOP 5 WITH TIES) - // T-SQL allows DISTINCT/ALL followed by TOP - dialect.replace_grammar( - "SelectClauseModifierSegment", - AnyNumberOf::new(vec![ - Ref::keyword("DISTINCT").to_matchable(), - Ref::keyword("ALL").to_matchable(), - // TOP alone - Sequence::new(vec![ - // https://docs.microsoft.com/en-us/sql/t-sql/queries/top-transact-sql - Ref::keyword("TOP").to_matchable(), - optionally_bracketed(vec![Ref::new("ExpressionSegment").to_matchable()]) - .to_matchable(), - Ref::keyword("PERCENT").optional().to_matchable(), - Ref::keyword("WITH").optional().to_matchable(), - Ref::keyword("TIES").optional().to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ); - - // Add T-SQL assignment operator segment - dialect.add([( - "AssignmentOperatorSegment".into(), - NodeMatcher::new(SyntaxKind::AssignmentOperator, |_| { - Ref::new("RawEqualsSegment").to_matchable() - }) - .to_matchable() - .into(), - )]); - - // Override NakedIdentifierSegment to support T-SQL identifiers with # at the end - // T-SQL allows temporary table names like #temp or ##global - dialect.add([( - "NakedIdentifierSegment".into(), - SegmentGenerator::new(|dialect| { - // Generate the anti template from the set of reserved keywords - let reserved_keywords = dialect.sets("reserved_keywords"); - let pattern = reserved_keywords.iter().join("|"); - let anti_template = format!("^({pattern})$"); - - // T-SQL pattern: supports both temp tables (#temp, ##global) and identifiers ending with # - // Pattern explanation: - // - ##?[A-Za-z][A-Za-z0-9_]* matches temp tables: #temp or ##global (case insensitive) - // - [A-Za-z0-9_]*[A-Za-z][A-Za-z0-9_]*#? matches regular identifiers with optional # at end - RegexParser::new( - r"(##?[A-Za-z][A-Za-z0-9_]*|[A-Za-z0-9_]*[A-Za-z][A-Za-z0-9_]*#?)", - SyntaxKind::NakedIdentifier, - ) - .anti_template(&anti_template) - .to_matchable() - }) - .into(), - )]); - - // DECLARE statement for variable declarations - // Syntax: DECLARE @var1 INT = 10, @var2 VARCHAR(50) = 'text' - dialect.add([ ( - "DeclareStatementSegment".into(), - Ref::new("DeclareStatementGrammar").to_matchable().into(), - ), - ( - "DeclareStatementGrammar".into(), - Sequence::new(vec![ - Ref::keyword("DECLARE").to_matchable(), - // Multiple variables can be declared with comma separation - Delimited::new(vec![ - Sequence::new(vec![ - Ref::new("TsqlVariableSegment").to_matchable(), - Sequence::new(vec![Ref::keyword("AS").to_matchable()]) - .config(|this| this.optional()) - .to_matchable(), - one_of(vec![ - // Regular variable declaration - Sequence::new(vec![ - Ref::new("DatatypeSegment").to_matchable(), - Sequence::new(vec![ - Ref::new("AssignmentOperatorSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .config(|this| this.optional()) - .to_matchable(), - ]) - .to_matchable(), - // Table variable declaration - Sequence::new(vec![ - Ref::keyword("TABLE").to_matchable(), - Bracketed::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::new("TableConstraintSegment").to_matchable(), - Ref::new("ColumnDefinitionSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .config(|this| this.allow_trailing()) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - .into(), + "BracketedIdentifierSegment".into(), + TypedParser::new(SyntaxKind::SquareQuote, SyntaxKind::QuotedIdentifier) + .to_matchable() + .into() ), - ]); - - // SET statement for variables - dialect.add([ - ( - "SetVariableStatementSegment".into(), - Ref::new("SetVariableStatementGrammar") - .to_matchable() - .into(), - ), - ( - "SetVariableStatementGrammar".into(), - Sequence::new(vec![ - Ref::keyword("SET").to_matchable(), - one_of(vec![ - // Variable assignment - Sequence::new(vec![ - Ref::new("TsqlVariableSegment").to_matchable(), - Ref::new("AssignmentOperatorSegment").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable(), - // SET DEADLOCK_PRIORITY - Sequence::new(vec![ - Ref::keyword("DEADLOCK_PRIORITY").to_matchable(), - one_of(vec![ - Ref::keyword("LOW").to_matchable(), - Ref::keyword("NORMAL").to_matchable(), - Ref::keyword("HIGH").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), // Positive numbers - Sequence::new(vec![ - // Negative numbers - Ref::new("MinusSegment").to_matchable(), - Ref::new("NumericLiteralSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("TsqlVariableSegment").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - // SET options - supports both individual and shared ON/OFF - one_of(vec![ - // Individual ON/OFF: SET NOCOUNT ON, XACT_ABORT OFF - Delimited::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::keyword("NOCOUNT").to_matchable(), - Ref::keyword("XACT_ABORT").to_matchable(), - Ref::keyword("QUOTED_IDENTIFIER").to_matchable(), - Ref::keyword("ANSI_NULLS").to_matchable(), - Ref::keyword("ANSI_PADDING").to_matchable(), - Ref::keyword("ANSI_WARNINGS").to_matchable(), - Ref::keyword("ARITHABORT").to_matchable(), - Ref::keyword("CONCAT_NULL_YIELDS_NULL").to_matchable(), - Ref::keyword("NUMERIC_ROUNDABORT").to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("OFF").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - // Shared ON/OFF: SET NOCOUNT, XACT_ABORT ON - Sequence::new(vec![ - Delimited::new(vec![ - one_of(vec![ - Ref::keyword("NOCOUNT").to_matchable(), - Ref::keyword("XACT_ABORT").to_matchable(), - Ref::keyword("QUOTED_IDENTIFIER").to_matchable(), - Ref::keyword("ANSI_NULLS").to_matchable(), - Ref::keyword("ANSI_PADDING").to_matchable(), - Ref::keyword("ANSI_WARNINGS").to_matchable(), - Ref::keyword("ARITHABORT").to_matchable(), - Ref::keyword("CONCAT_NULL_YIELDS_NULL").to_matchable(), - Ref::keyword("NUMERIC_ROUNDABORT").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - one_of(vec![ - Ref::keyword("ON").to_matchable(), - Ref::keyword("OFF").to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable(), - ]) - .to_matchable() - .into(), + ( + "HashIdentifierSegment".into(), + TypedParser::new(SyntaxKind::HashPrefix, SyntaxKind::HashIdentifier) + .to_matchable() + .into() ), - ]); - - // PRINT statement - dialect.add([ ( - "PrintStatementSegment".into(), - Ref::new("PrintStatementGrammar").to_matchable().into(), + "BatchDelimiterGrammar".into(), + Ref::new("GoStatementSegment") + .to_matchable() + .into() ), ( - "PrintStatementGrammar".into(), - Sequence::new(vec![ - Ref::keyword("PRINT").to_matchable(), - Ref::new("ExpressionSegment").to_matchable(), - ]) - .to_matchable() - .into(), + "QuotedLiteralSegmentWithN".into(), + TypedParser::new(SyntaxKind::SingleQuoteWithN, SyntaxKind::QuotedLiteral) + .to_matchable() + .into() ), - ]); - - // BEGIN...END blocks for grouping multiple statements - dialect.add([ - ( - "BeginEndBlockSegment".into(), - Sequence::new(vec![ - Ref::keyword("BEGIN").to_matchable(), - MetaSegment::indent().to_matchable(), - AnyNumberOf::new(vec![ - Sequence::new(vec![ - one_of(vec![ - Ref::new("SelectableGrammar").to_matchable(), - Ref::new("InsertStatementSegment").to_matchable(), - Ref::new("UpdateStatementSegment").to_matchable(), - Ref::new("DeleteStatementSegment").to_matchable(), - Ref::new("CreateTableStatementSegment").to_matchable(), - Ref::new("DropTableStatementSegment").to_matchable(), - Ref::new("DeclareStatementSegment").to_matchable(), - Ref::new("SetVariableStatementSegment").to_matchable(), - Ref::new("PrintStatementSegment").to_matchable(), - Ref::new("IfStatementSegment").to_matchable(), - Ref::new("WhileStatementSegment").to_matchable(), - Ref::new("TryBlockSegment").to_matchable(), - Ref::new("GotoStatementSegment").to_matchable(), - Ref::new("LabelSegment").to_matchable(), - Ref::new("BeginEndBlockSegment").to_matchable(), - ]) - .to_matchable(), - Ref::new("DelimiterGrammar").optional().to_matchable(), - ]) - .to_matchable(), - ]) + ( + "QuotedLiteralSegmentOptWithN".into(), + one_of(vec![Ref::new("QuotedLiteralSegment") .to_matchable(), Ref::new("QuotedLiteralSegmentWithN") .to_matchable()]) + .to_matchable() + .into() + ), + ( + "IntegerLiteralSegment".into(), + RegexParser::new(r#"(? Matchable { + Sequence::new(vec![ + Ref::new("LogicalFileNameSegment").optional().to_matchable(), + Ref::new("FileSpecFileNameSegment").to_matchable(), + Ref::new("FileSpecSizeSegment").optional().to_matchable(), + Ref::new("FileSpecMaxSizeSegment").optional().to_matchable(), + Ref::new("FileSpecFileGrowthSegment") + .optional() .to_matchable(), - ]) - .to_matchable() - .into(), - )]); - - // T-SQL uses + for both arithmetic and string concatenation - dialect.add([( - "StringBinaryOperatorGrammar".into(), - one_of(vec![ - Ref::new("ConcatSegment").to_matchable(), // Standard || operator - Ref::new("PlusSegment").to_matchable(), - ]) - .to_matchable() - .into(), - )]); - - // T-SQL specific data type identifier - allows case-insensitive user-defined types - dialect.add([( - "DatatypeIdentifierSegment".into(), - SegmentGenerator::new(|_| { - // Generate the anti template from the set of reserved keywords - let anti_template = format!("^({})$", "NOT"); - - one_of(vec![ - // Case-insensitive pattern for T-SQL data type identifiers (including UDTs) - RegexParser::new("[A-Za-z_][A-Za-z0-9_]*", SyntaxKind::DataTypeIdentifier) - .anti_template(&anti_template) - .to_matchable(), - Ref::new("SingleIdentifierGrammar") - .exclude(Ref::new("NakedIdentifierSegment")) - .to_matchable(), - ]) - .to_matchable() - }) - .into(), - )]); - - // expand() must be called after all grammar modifications + ]) + .to_matchable() +} - dialect +pub fn get_unordered_select_statement_segment_grammar() -> Matchable { + Sequence::new(vec![ + Ref::new("SelectClauseSegment").to_matchable(), + Ref::new("IntoTableSegment").optional().to_matchable(), + Ref::new("FromClauseSegment").optional().to_matchable(), + Ref::new("WhereClauseSegment").optional().to_matchable(), + Ref::new("GroupByClauseSegment").optional().to_matchable(), + Ref::new("HavingClauseSegment").optional().to_matchable(), + Ref::new("NamedWindowSegment").optional().to_matchable(), + ]) + .to_matchable() } diff --git a/crates/lib-dialects/src/tsql_keywords.rs b/crates/lib-dialects/src/tsql_keywords.rs index 44da1fc79..24a8c01d7 100644 --- a/crates/lib-dialects/src/tsql_keywords.rs +++ b/crates/lib-dialects/src/tsql_keywords.rs @@ -1,573 +1,909 @@ -use ahash::AHashSet; +pub(crate) const RESERVED_KEYWORDS: [&str; 186] = [ + "ADD", + "ALL", + "ALTER", + "AND", + "ANY", + "AS", + "ASC", + "AUTHORIZATION", + "BACKUP", + "BEGIN", + "BETWEEN", + "BREAK", + "BROWSE", + "BULK", + "BY", + "CASCADE", + "CASE", + "CHECK", + "CHECKPOINT", + "CLOSE", + "CLUSTERED", + "COALESCE", + "COLLATE", + "COLUMN", + "COMMIT", + "COMPUTE", + "CONSTRAINT", + "CONTAINS", + "CONTAINSTABLE", + "CONTINUE", + "CONVERT", + "CREATE", + "CROSS", + "CURRENT", + "CURRENT_DATE", + "CURRENT_TIME", + "CURRENT_TIMESTAMP", + "CURRENT_USER", + "CURSOR", + "DATABASE", + "DBCC", + "DEALLOCATE", + "DECLARE", + "DEFAULT", + "DELETE", + "DENY", + "DESC", + "DISK", + "DISTINCT", + "DISTRIBUTED", + "DOUBLE", + "DROP", + "DUMP", + "ELSE", + "END", + "ERRLVL", + "ESCAPE", + "EXCEPT", + "EXEC", + "EXECUTE", + "EXISTS", + "EXIT", + "EXTERNAL", + "FETCH", + "FILE", + "FILLFACTOR", + "FOR", + "FOREIGN", + "FREETEXT", + "FREETEXTTABLE", + "FROM", + "FULL", + "FUNCTION", + "GO", + "GOTO", + "GRANT", + "GROUP", + "HAVING", + "HOLDLOCK", + "IDENTITY", + "IDENTITY_INSERT", + "IDENTITYCOL", + "IF", + "IN", + "INDEX", + "INNER", + "INSERT", + "INTERSECT", + "INTO", + "IS", + "JOIN", + "KEY", + "KILL", + "LEFT", + "LIKE", + "LINENO", + "LOAD", + "MERGE", + "NATIONAL", + "NOCHECK", + "NONCLUSTERED", + "NOT", + "NULL", + "NULLIF", + "OF", + "OFF", + "OFFSETS", + "ON", + "OPEN", + "OPENDATASOURCE", + "OPENQUERY", + "OPENROWSET", + "OPENXML", + "OPTION", + "OR", + "ORDER", + "OUTER", + "OVER", + "PERCENT", + "PIVOT", + "PLAN", + "PRECISION", + "PRIMARY", + "PRINT", + "PROC", + "PROCEDURE", + "PUBLIC", + "RAISERROR", + "READ", + "READTEXT", + "RECONFIGURE", + "REFERENCES", + "REPLICATION", + "RESTORE", + "RESTRICT", + "RETURN", + "REVERT", + "REVOKE", + "RIGHT", + "ROLLBACK", + "ROWCOUNT", + "ROWGUIDCOL", + "RULE", + "SAVE", + "SCHEMA", + "SECURITYAUDIT", + "SELECT", + "SEMANTICKEYPHRASETABLE", + "SEMANTICSIMILARITYDETAILSTABLE", + "SEMANTICSIMILARITYTABLE", + "SESSION_USER", + "SET", + "SETUSER", + "SHUTDOWN", + "SOME", + "STATISTICS", + "SYSTEM_USER", + "TABLE", + "TABLESAMPLE", + "TEXTSIZE", + "THEN", + "TO", + "TOP", + "TRAN", + "TRANSACTION", + "TRIGGER", + "TRUNCATE", + "TRY_CONVERT", + "TSEQUAL", + "UNION", + "UNIQUE", + "UNPIVOT", + "UPDATE", + "UPDATETEXT", + "USE", + "USER", + "VALUES", + "VARYING", + "VIEW", + "WAITFOR", + "WHEN", + "WHERE", + "WHILE", + "WITH", + "WITHIN GROUP", + "WRITETEXT", +]; -use crate::ansi_keywords::{ANSI_RESERVED_KEYWORDS, ANSI_UNRESERVED_KEYWORDS}; +pub(crate) const FUTURE_RESERVED_KEYWORDS: [&str; 272] = [ + "ABSOLUTE", + "ACTION", + "ADMIN", + "AFTER", + "AGGREGATE", + "ALIAS", + "ALLOCATE", + "ARE", + "ARRAY", + "ASENSITIVE", + "ASSERTION", + "ASYMMETRIC", + "AT", + "ATOMIC", + "BEFORE", + "BINARY", + "BIT", + "BLOB", + "BOOLEAN", + "BOTH", + "BREADTH", + "CALL", + "CALLED", + "CARDINALITY", + "CASCADED", + "CAST", + "CATALOG", + "CHAR", + "CHARACTER", + "CLASS", + "CLOB", + "COLLATION", + "COLLECT", + "COMPLETION", + "CONDITION", + "CONNECT", + "CONNECTION", + "CONSTRAINTS", + "CONSTRUCTOR", + "CORR", + "CORRESPONDING", + "COVAR_POP", + "COVAR_SAMP", + "CUBE", + "CUME_DIST", + "CURRENT_CATALOG", + "CURRENT_DEFAULT_TRANSFORM_GROUP", + "CURRENT_PATH", + "CURRENT_ROLE", + "CURRENT_SCHEMA", + "CURRENT_TRANSFORM_GROUP_FOR_TYPE", + "CYCLE", + "DATA", + "DATE", + "DAY", + "DEC", + "DECIMAL", + "DEFERRABLE", + "DEFERRED", + "DEPTH", + "DEREF", + "DESCRIBE", + "DESCRIPTOR", + "DESTROY", + "DESTRUCTOR", + "DETERMINISTIC", + "DIAGNOSTICS", + "DICTIONARY", + "DISCONNECT", + "DOMAIN", + "DYNAMIC", + "EACH", + "ELEMENT", + "END-EXEC", + "EQUALS", + "EVERY", + "EXCEPTION", + "FALSE", + "FILTER", + "FIRST", + "FLOAT", + "FOUND", + "FREE", + "FULLTEXTTABLE", + "FUSION", + "GENERAL", + "GET", + "GLOBAL", + "GROUPING", + "HOLD", + "HOST", + "HOUR", + "IGNORE", + "IMMEDIATE", + "INDICATOR", + "INITIALIZE", + "INITIALLY", + "INOUT", + "INPUT", + "INT", + "INTEGER", + "INTERSECTION", + "INTERVAL", + "ISOLATION", + "ITERATE", + "LANGUAGE", + "LARGE", + "LAST", + "LATERAL", + "LEADING", + "LESS", + "LEVEL", + "LIKE_REGEX", + "LIMIT", + "LN", + "LOCAL", + "LOCALTIME", + "LOCALTIMESTAMP", + "LOCATOR", + "MAP", + "MATCH", + "MEMBER", + "METHOD", + "MINUTE", + "MOD", + "MODIFIES", + "MODIFY", + "MODULE", + "MONTH", + "MULTISET", + "NAMES", + "NATURAL", + "NCHAR", + "NCLOB", + "NEW", + "NEXT", + "NO", + "NONE", + "NORMALIZE", + "NUMERIC", + "OBJECT", + "OCCURRENCES_REGEX", + "OLD", + "ONLY", + "OPERATION", + "ORDINALITY", + "OUT", + "OUTPUT", + "OVERLAY", + "PAD", + "PARAMETER", + "PARAMETERS", + "PARTIAL", + "PARTITION", + "PATH", + "PERCENT_RANK", + "PERCENTILE_CONT", + "PERCENTILE_DISC", + "POSITION_REGEX", + "POSTFIX", + "PREFIX", + "PREORDER", + "PREPARE", + "PRESERVE", + "PRIOR", + "PRIVILEGES", + "RANGE", + "READS", + "REAL", + "RECURSIVE", + "REF", + "REFERENCING", + "REGR_AVGX", + "REGR_AVGY", + "REGR_COUNT", + "REGR_INTERCEPT", + "REGR_R2", + "REGR_SLOPE", + "REGR_SXX", + "REGR_SXY", + "REGR_SYY", + "RELATIVE", + "RELEASE", + "RESULT", + "RETURNS", + "ROLE", + "ROLLUP", + "ROUTINE", + "ROW", + "ROWS", + "SAVEPOINT", + "SCOPE", + "SCROLL", + "SEARCH", + "SECOND", + "SECTION", + "SENSITIVE", + "SEQUENCE", + "SESSION", + "SETS", + "SIMILAR", + "SIZE", + "SMALLINT", + "SPACE", + "SPECIFIC", + "SPECIFICTYPE", + "SQL", + "SQLEXCEPTION", + "SQLSTATE", + "SQLWARNING", + "START", + "STATE", + "STATEMENT", + "STATIC", + "STDDEV_POP", + "STDDEV_SAMP", + "STRUCTURE", + "SUBMULTISET", + "SUBSTRING_REGEX", + "SYMMETRIC", + "SYSTEM", + "TEMPORARY", + "TERMINATE", + "THAN", + "TIME", + "TIMESTAMP", + "TIMEZONE_HOUR", + "TIMEZONE_MINUTE", + "TRAILING", + "TRANSLATE_REGEX", + "TRANSLATION", + "TREAT", + "TRUE", + "UESCAPE", + "UNDER", + "UNKNOWN", + "UNNEST", + "USAGE", + "USING", + "VALUE", + "VAR_POP", + "VAR_SAMP", + "VARCHAR", + "VARIABLE", + "WHENEVER", + "WIDTH_BUCKET", + "WINDOW", + "WITHIN", + "WITHOUT", + "WORK", + "WRITE", + "XMLAGG", + "XMLATTRIBUTES", + "XMLBINARY", + "XMLCAST", + "XMLCOMMENT", + "XMLCONCAT", + "XMLDOCUMENT", + "XMLELEMENT", + "XMLEXISTS", + "XMLFOREST", + "XMLITERATE", + "XMLNAMESPACES", + "XMLPARSE", + "XMLPI", + "XMLQUERY", + "XMLSERIALIZE", + "XMLTABLE", + "XMLTEXT", + "XMLVALIDATE", + "YEAR", + "ZONE", +]; -/// T-SQL reserved keywords from Microsoft documentation -/// https://learn.microsoft.com/en-us/sql/t-sql/language-elements/reserved-keywords-transact-sql -/// T-SQL specific keywords (to be added to ANSI keywords, not replace them) -pub(crate) fn tsql_additional_reserved_keywords() -> AHashSet<&'static str> { - [ - // Current T-SQL Reserved Keywords (from Microsoft documentation) - "ADD", - "ALL", - "ALTER", - "AND", - "ANY", - "AS", - "ASC", - "AUTHORIZATION", - "BACKUP", - "BEGIN", - "BETWEEN", - "BREAK", - "BROWSE", - "BULK", - "BY", - "CASCADE", - "CASE", - "CATCH", - "CHECK", - "CHECKPOINT", - "CLOSE", - "CLUSTERED", - "COALESCE", - "COLLATE", - "COLUMN", - "COMMIT", - "COMPUTE", - "CONSTRAINT", - "CONTAINS", - "CONTAINSTABLE", - "CONTINUE", - "CONVERT", - "CREATE", - "CROSS", - "CURRENT", - "CURRENT_DATE", - "CURRENT_TIME", - "CURRENT_TIMESTAMP", - "CURRENT_USER", - "CURSOR", - "DATABASE", - "DBCC", - "DEALLOCATE", - "DECLARE", - "DEFAULT", - "DELETE", - "DENY", - "DESC", - "DISK", - "DISTINCT", - "DISTRIBUTED", - "DOUBLE", - "DROP", - "DUMP", - "ELSE", - "END", - "ERRLVL", - "ERROR_LINE", - "ERROR_MESSAGE", - "ERROR_NUMBER", - "ERROR_PROCEDURE", - "ERROR_SEVERITY", - "ERROR_STATE", - "ESCAPE", - "EXCEPT", - "EXEC", - "EXECUTE", - "EXISTS", - "EXIT", - "EXTERNAL", - "FETCH", - "FILE", - "FILLFACTOR", - "FOR", - "FOREIGN", - "FREETEXT", - "FREETEXTTABLE", - "FROM", - "FULL", - "FUNCTION", - "GOTO", - "GRANT", - "GROUP", - "HAVING", - "HOLDLOCK", - "IDENTITY", - "IDENTITY_INSERT", - "IDENTITYCOL", - "IF", - "IN", - "INDEX", - "INNER", - "INSERT", - "INTERSECT", - "INTO", - "IS", - "JOIN", - "KEY", - "KILL", - "LEFT", - "LIKE", - "LINENO", - "LOAD", - "MERGE", - "NATIONAL", - "NOCHECK", - "NONCLUSTERED", - "NOT", - "NULL", - "NULLIF", - "OF", - "OFF", - "OFFSETS", - "ON", - "OPEN", - "OPENDATASOURCE", - "OPENQUERY", - "OPENROWSET", - "OPENXML", - "OPTION", - "OR", - "ORDER", - "OUTER", - "OVER", - "PERCENT", - "PIVOT", - "PLAN", - "PRECISION", - "PRIMARY", - "PRINT", - "PROC", - "PROCEDURE", - "PUBLIC", - "RAISERROR", - "READ", - "READTEXT", - "RECONFIGURE", - "REFERENCES", - "REPLICATION", - "RESTORE", - "RESTRICT", - "RETURN", - "REVERT", - "REVOKE", - "RIGHT", - "ROLLBACK", - "ROWCOUNT", - "ROWGUIDCOL", - "RULE", - "SAVE", - "SCHEMA", - "SECURITYAUDIT", - "SELECT", - "SEMANTICKEYPHRASETABLE", - "SEMANTICSIMILARITYDETAILSTABLE", - "SEMANTICSIMILARITYTABLE", - "SESSION_USER", - "SET", - "SETUSER", - "SHUTDOWN", - "SOME", - "STATISTICS", - "SYSTEM_USER", - "TABLE", - "TABLESAMPLE", - "TEXTSIZE", - "THEN", - "TO", - "TOP", - "TRAN", - "TRANSACTION", - "TRIGGER", - "TRUNCATE", - "TRY", - "TRY_CONVERT", - "TSEQUAL", - "UNION", - "UNIQUE", - "UNPIVOT", - "UPDATE", - "UPDATETEXT", - "USE", - "USER", - "VALUES", - "VARYING", - "VIEW", - "WAITFOR", - "WHEN", - "WHERE", - "WHILE", - "WITH", - "WITHIN GROUP", - "WRITETEXT", - ] - .into_iter() - .collect() -} - -/// T-SQL future keywords from Microsoft documentation -/// These are potential reserved keywords in future versions -#[allow(dead_code)] -pub(crate) fn tsql_future_keywords() -> AHashSet<&'static str> { - [ - // Future Keywords (from Microsoft documentation) - "ABSOLUTE", - "ACTION", - "ADMIN", - "AFTER", - "AGGREGATE", - "ALIAS", - "ALLOCATE", - "ARE", - "ARRAY", - "ASENSITIVE", - "ASSERTION", - "ASYMMETRIC", - "AT", - "ATOMIC", - "BEFORE", - "BINARY", - "BIT", - "BLOB", - "BOOLEAN", - "BOTH", - "BREADTH", - "CALL", - "CALLED", - "CARDINALITY", - "CASCADED", - "CAST", - "CATALOG", - "CHAR", - "CHARACTER", - "CLASS", - "CLOB", - "COLLATION", - "COLLECT", - "COMPLETION", - "CONDITION", - "CONNECT", - "CONNECTION", - "CONSTRAINTS", - "CONSTRUCTOR", - "CORR", - "CORRESPONDING", - "COVAR_POP", - "COVAR_SAMP", - "CUBE", - "CUME_DIST", - "CURRENT_CATALOG", - "CURRENT_DEFAULT_TRANSFORM_GROUP", - "CURRENT_PATH", - "CURRENT_ROLE", - "CURRENT_SCHEMA", - "CURRENT_TRANSFORM_GROUP_FOR_TYPE", - "CYCLE", - "DATA", - "DATE", - "DAY", - "DEC", - "DECIMAL", - "DEFERRABLE", - "DEFERRED", - "DEPTH", - "DEREF", - "DESCRIBE", - "DESCRIPTOR", - "DESTROY", - "DESTRUCTOR", - "DETERMINISTIC", - "DIAGNOSTICS", - "DICTIONARY", - "DISCONNECT", - "DOMAIN", - "DYNAMIC", - "EACH", - "ELEMENT", - "END-EXEC", - "EQUALS", - "EVERY", - "EXCEPTION", - "FALSE", - "FILTER", - "FIRST", - "FLOAT", - "FOUND", - "FREE", - "FULLTEXTTABLE", - "FUSION", - "GENERAL", - "GET", - "GLOBAL", - "GO", - "GROUPING", - "HOLD", - "HOST", - "HOUR", - "IGNORE", - "IMMEDIATE", - "INDICATOR", - "INITIALIZE", - "INITIALLY", - "INOUT", - "INPUT", - "INT", - "INTEGER", - "INTERSECTION", - "INTERVAL", - "ISOLATION", - "ITERATE", - "LANGUAGE", - "LARGE", - "LAST", - "LATERAL", - "LEADING", - "LESS", - "LEVEL", - "LIKE_REGEX", - "LIMIT", - "LN", - "LOCAL", - "LOCALTIME", - "LOCALTIMESTAMP", - "LOCATOR", - "MAP", - "MATCH", - "MEMBER", - "METHOD", - "MINUTE", - "MOD", - "MODIFIES", - "MODIFY", - "MODULE", - "MONTH", - "MULTISET", - "NAMES", - "NATURAL", - "NCHAR", - "NCLOB", - "NEW", - "NEXT", - "NO", - "NONE", - "NORMALIZE", - "NUMERIC", - "OBJECT", - "OCCURRENCES_REGEX", - "OLD", - "ONLY", - "OPERATION", - "ORDINALITY", - "OUT", - "OUTPUT", - "OVERLAY", - "PAD", - "PARAMETER", - "PARAMETERS", - "PARTIAL", - "PARTITION", - "PATH", - "PERCENT_RANK", - "PERCENTILE_CONT", - "PERCENTILE_DISC", - "POSITION", - "POSITION_REGEX", - "POSTFIX", - "PREFIX", - "PREORDER", - "PREPARE", - "PRESERVE", - "PRIOR", - "PRIVILEGES", - "RANGE", - "READS", - "REAL", - "RECURSIVE", - "REF", - "REFERENCING", - "REGR_AVGX", - "REGR_AVGY", - "REGR_COUNT", - "REGR_INTERCEPT", - "REGR_R2", - "REGR_SLOPE", - "REGR_SXX", - "REGR_SXY", - "REGR_SYY", - "RELATIVE", - "RELEASE", - "RESULT", - "RETURNS", - "ROLE", - "ROLLUP", - "ROUTINE", - "ROW", - "ROWS", - "SAVEPOINT", - "SCOPE", - "SCROLL", - "SEARCH", - "SECOND", - "SECTION", - "SENSITIVE", - "SEQUENCE", - "SESSION", - "SETS", - "SIMILAR", - "SIZE", - "SMALLINT", - "SPACE", - "SPECIFIC", - "SPECIFICTYPE", - "SQL", - "SQLEXCEPTION", - "SQLSTATE", - "SQLWARNING", - "START", - "STATE", - "STATEMENT", - "STATIC", - "STDDEV_POP", - "STDDEV_SAMP", - "STRUCTURE", - "SUBMULTISET", - "SUBSTRING_REGEX", - "SYMMETRIC", - "SYSTEM", - "TEMPORARY", - "TERMINATE", - "THAN", - "TIME", - "TIMESTAMP", - "TIMEZONE_HOUR", - "TIMEZONE_MINUTE", - "TRAILING", - "TRANSLATE", - "TRANSLATE_REGEX", - "TRANSLATION", - "TREAT", - "TRUE", - "UESCAPE", - "UNDER", - "UNKNOWN", - "UNNEST", - "USAGE", - "USING", - // "VALUE", // Commented out to allow "value" as identifier in T-SQL alias equals syntax - "VAR_POP", - "VAR_SAMP", - "VARCHAR", - "VARIABLE", - "VARYING", - "WHEN", - "WHENEVER", - "WIDTH_BUCKET", - "WINDOW", - "WITHIN", - "WITHOUT", - "WORK", - "WRITE", - "XMLAGG", - "XMLATTRIBUTES", - "XMLBINARY", - "XMLCAST", - "XMLCOMMENT", - "XMLCONCAT", - "XMLDOCUMENT", - "XMLELEMENT", - "XMLEXISTS", - "XMLFOREST", - "XMLITERATE", - "XMLNAMESPACES", - "XMLPARSE", - "XMLPI", - "XMLQUERY", - "XMLSERIALIZE", - "XMLTABLE", - "XMLTEXT", - "XMLVALIDATE", - "YEAR", - "ZONE", - ] - .into_iter() - .collect() -} - -/// T-SQL unreserved keywords -/// These are keywords that can be used as identifiers without quoting -/// T-SQL additional unreserved keywords (to be added to ANSI keywords) -pub(crate) fn tsql_additional_unreserved_keywords() -> AHashSet<&'static str> { - [ - // T-SQL SET options that can be used as identifiers - "NOCOUNT", - "XACT_ABORT", - "QUOTED_IDENTIFIER", - "ANSI_NULLS", - "ANSI_PADDING", - "ANSI_WARNINGS", - "ARITHABORT", - "CONCAT_NULL_YIELDS_NULL", - "NUMERIC_ROUNDABORT", - "DEADLOCK_PRIORITY", - "DATEFIRST", - "DATEFORMAT", - "DELAYED_DURABILITY", - // Function names that can be used as identifiers - "NEWID", - // T-SQL priority and format values - "LOW", - "NORMAL", - "HIGH", - "MDY", - "DMY", - "YMD", - "YDM", - "MYD", - "DYM", - // Transaction isolation levels - "SERIALIZABLE", - "SNAPSHOT", - "ISOLATION", - "LEVEL", - // Azure Synapse Analytics keywords that can be identifiers - "DISTRIBUTION", - "ROUND_ROBIN", - "REPLICATE", - "HASH", - "HEAP", - "COLUMNSTORE", - "PARTITION", - "RANGE", - // Common T-SQL keywords that can be used as identifiers - "ATOMIC", - // Procedure parameter modifiers - "READONLY", - // CREATE PROCEDURE WITH clause options - "ENCRYPTION", - "RECOMPILE", - "NATIVE_COMPILATION", - "SCHEMABINDING", - "CALLER", - "OWNER", - ] - .into_iter() - .collect() -} - -/// Complete T-SQL reserved keywords (ANSI + T-SQL specific) - for backwards compatibility -#[allow(dead_code)] -pub(crate) fn tsql_reserved_keywords() -> AHashSet<&'static str> { - // Combine ANSI keywords with T-SQL specific reserved keywords - ANSI_RESERVED_KEYWORDS - .lines() - .chain(ANSI_UNRESERVED_KEYWORDS.lines()) - .chain(tsql_additional_reserved_keywords()) - .collect() -} - -/// Complete T-SQL unreserved keywords - for backwards compatibility -#[allow(dead_code)] -pub(crate) fn tsql_unreserved_keywords() -> AHashSet<&'static str> { - tsql_additional_unreserved_keywords() -} +pub(crate) const UNRESERVED_KEYWORDS: [&str; 443] = [ + "ABORT_AFTER_WAIT", + "ABORT", + "ABSENT", + "ACCELERATED_DATABASE_RECOVERY", + "ACCENT_SENSITIVITY", + "ALGORITHM", + "ALLOW_CONNECTIONS", + "ALLOW_ENCRYPTED_VALUE_MODIFICATIONS", + "ALLOW_PAGE_LOCKS", + "ALLOW_ROW_LOCKS", + "ALLOW_SNAPSHOT_ISOLATION", + "ALLOWED", + "ALWAYS", + "ANSI_DEFAULTS", + "ANSI_NULL_DEFAULT", + "ANSI_NULL_DFLT_OFF", + "ANSI_NULL_DFLT_ON", + "ANSI_NULLS", + "ANSI_PADDING", + "ANSI_WARNINGS", + "APPEND_ONLY", + "APPLY", + "ARITHABORT", + "ARITHIGNORE", + "ATTACH", + "ATTACH_REBUILD_LOG", + "AUTO_CLOSE", + "AUTO_CREATE_STATISTICS", + "AUTO_CREATE_TABLE", + "AUTO_SHRINK", + "AUTO_UPDATE_STATISTICS", + "AUTO_UPDATE_STATISTICS_ASYNC", + "AUTO", + "BACKUP_STORAGE_REDUNDANCY", + "BATCHSIZE", + "BERNOULLI", + "BLOCK", + "BLOCKERS", + "BULK_LOGGED", + "CACHE", + "CALLER", + "CATALOG_COLLATION", + "CATCH", + "CERTIFICATE", + "CHANGE_TRACKING", + "CHECK_CONSTRAINTS", + "CHECK_EXPIRATION", + "CHECK_POLICY", + "CODEPAGE", + "COLUMN_ENCRYPTION_KEY", + "COLUMNSTORE_ARCHIVE", + "COLUMNSTORE", + "COMMITTED", + "COMPATIBILITY_LEVEL", + "COMPRESS_ALL_ROW_GROUPS", + "COMPRESSION_DELAY", + "COMPRESSION", + "CONCAT_NULL_YIELDS_NULL", + "CONCAT", + "CONNECTION_OPTIONS", + "CONTAINED", + "CONTAINMENT", + "CONTEXT_INFO", + "CONTROL", + "COPY", + "CREDENTIAL", + "CURSOR_CLOSE_ON_COMMIT", + "CURSOR_DEFAULT", + "DATA_COMPRESSION", + "DATA_CONSISTENCY_CHECK", + "DATA_DELETION", + "DATA_SOURCE", + "DATABASE_DEFAULT", + "DATAFILETYPE", + "DATASOURCE", + "DATE_CORRELATION_OPTIMIZATION", + "DATE_FORMAT", + "DATEFIRST", + "DATEFORMAT", + "DAYS", + "DB_CHAINING", + "DEADLOCK_PRIORITY", + "DECRYPTION", + "DEFAULT_DATABASE", + "DEFAULT_FULLTEXT_LANGUAGE", + "DEFAULT_LANGUAGE", + "DEFAULT_SCHEMA", + "DELAY", + "DELAYED_DURABILITY", + "DELETED", + "DELIMITEDTEXT", + "DELTA", + "DENSE_RANK", + "DIRECTORY_NAME", + "DISABLE", + "DISABLED", + "DISTRIBUTION", + "DISABLE_BROKER", + "DROP_EXISTING", + "DURABILITY", + "EDGE", + "EDITION", + "ELASTIC_POOL", + "ELEMENTS", + "ENABLE_BROKER", + "ENCODING", + "ENCRYPTED", + "ENCRYPTION_TYPE", + "ENCRYPTION", + "ERROR_BROKER_CONVERSATIONS", + "ERRORFILE_CREDENTIAL", + "ERRORFILE_DATA_SOURCE", + "ERRORFILE", + "EXPAND", + "EXPLAIN", + "EXPLICIT", + "EXTERNALPUSHDOWN", + "FAILOVER", + "FAST", + "FAST_FORWARD", + "FIELD_TERMINATOR", + "FIELDQUOTE", + "FIELDTERMINATOR", + "FILE_FORMAT", + "FILE_TYPE", + "FILEGROUP", + "FILEGROWTH", + "FILENAME", + "FILESTREAM_ON", + "FILESTREAM", + "FILETABLE_COLLATE_FILENAME", + "FILETABLE_DIRECTORY", + "FILETABLE_FULLPATH_UNIQUE_CONSTRAINT_NAME", + "FILETABLE_PRIMARY_KEY_CONSTRAINT_NAME", + "FILETABLE_STREAMID_UNIQUE_CONSTRAINT_NAME", + "FILTER_COLUMN", + "FILTER_PREDICATE", + "FIPS_FLAGGER", + "FIRE_TRIGGERS", + "FIRST_ROW", + "FIRSTROW", + "FMTONLY", + "FOLLOWING", + "FORCE", + "FORCED", + "FORCE_FAILOVER_ALLOW_DATA_LOSS", + "FORCEPLAN", + "FORCESCAN", + "FORCESEEK", + "FORMAT_OPTIONS", + "FORMAT_TYPE", + "FORMAT", + "FORMATFILE_DATA_SOURCE", + "FORMATFILE", + "FORWARD_ONLY", + "FULLSCAN", + "FULLTEXT", + "GB", + "GENERATED", + "GEO", + "GEOZONE", + "HASH", + "HEAP", + "HIDDEN", + "HIGH", + "HINT", + "HISTORY_RETENTION_PERIOD", + "HISTORY_TABLE", + "HONOR_BROKER_PRIORITY", + "IGNORE_CONSTRAINTS", + "IGNORE_DUP_KEY", + "IGNORE_NONCLUSTERED_COLUMNSTORE_INDEX", + "IGNORE_TRIGGERS", + "IMPLICIT_TRANSACTIONS", + "INBOUND", + "INCLUDE_NULL_VALUES", + "INCLUDE", + "INCREMENT", + "INCREMENTAL", + "INFINITE", + "INLINE", + "INSENSITIVE", + "INSERTED", + "INSTEAD", + "IO", + "JSON", + "JSON_ARRAY", + "JSON_OBJECT", + "KB", + "KEEP", + "KEEPDEFAULTS", + "KEEPFIXED", + "KEEPIDENTITY", + "KEEPNULLS", + "KEYSET", + "KILOBYTES_PER_BATCH", + "LABEL", + "LASTROW", + "LEDGER_VIEW", + "LEDGER", + "LEGACY_CARDINALITY_ESTIMATION", + "LIST", + "LOB_COMPACTION", + "LOCATION", + "LOCK_TIMEOUT", + "LOG", + "LOGIN", + "LOOP", + "LOW", + "MANUAL", + "MANUAL_CUTOVER", + "MASKED", + "MASTER", + "MATCHED", + "MAX_DURATION", + "MAX_GRANT_PERCENT", + "MAX", + "MAXDOP", + "MAXERRORS", + "MAXRECURSION", + "MAXSIZE", + "MAXVALUE", + "MB", + "MEMORY_OPTIMIZED", + "MEMORY_OPTIMIZED_DATA", + "MIGRATION_STATE", + "MIN_GRANT_PERCENT", + "MINUTES", + "MINVALUE", + "MONTHS", + "MULTI_USER", + "MUST_CHANGE", + "NAME", + "NATIVE_COMPILATION", + "NESTED_TRIGGERS", + "NEWNAME", + "NEW_BROKER", + "NO_PERFORMANCE_SPOOL", + "NOCOUNT", + "NODE", + "NOEXEC", + "NOEXPAND", + "NOLOCK", + "NON_TRANSACTED_ACCESS", + "NORMAL", + "NOWAIT", + "NTILE", + "NULLS", + "NUMERIC_ROUNDABORT", + "OFFSET", + "ONLINE", + "OPENJSON", + "OPERATION_TYPE_COLUMN_NAME", + "OPERATION_TYPE_DESC_COLUMN_NAME", + "OPTIMISTIC", + "OPTIMIZE_FOR_SEQUENTIAL_KEY", + "OPTIMIZE", + "ORC", + "OUTBOUND", + "OVERRIDE", + "OWNER", + "PAD_INDEX", + "PAGE", + "PAGE_VERIFY", + "PAGLOCK", + "PARAMETERIZATION", + "PARQUET", + "PARSEONLY", + "PARSER_VERSION", + "PARTITIONS", + "PASSWORD", + "PAUSE", + "PAUSED", + "PERCENTAGE", + "PERFORM_CUTOVER", + "PERIOD", + "PERSISTED", + "PERSISTENT_LOG_BUFFER", + "PERSISTENT_VERSION_STORE_FILEGROUP", + "POLICY", + "POPULATION", + "PRECEDING", + "PREDICATE", + "PROFILE", + "PROPERTY", + "PROVIDER", + "PUSHDOWN", + "QUERY_GOVERNOR_COST_LIMIT", + "QUERY_STORE", + "QUERYTRACEON", + "QUOTED_IDENTIFIER", + "R", + "RANDOMIZED", + "RANK", + "RAW", + "RCFILE", + "READCOMMITTED", + "READCOMMITTEDLOCK", + "READONLY", + "READPAST", + "READ_COMMITTED_SNAPSHOT", + "READ_ONLY", + "READ_WRITE", + "READUNCOMMITTED", + "REBUILD", + "RECEIVE", + "RECOMPILE", + "RECOVERY", + "RECURSIVE_TRIGGERS", + "REGENERATE", + "REJECT_SAMPLE_VALUE", + "REJECT_TYPE", + "REJECT_VALUE", + "REJECTED_ROW_LOCATION", + "REMOTE_DATA_ARCHIVE", + "REMOTE_PROC_TRANSACTIONS", + "REMOVE", + "RENAME", + "REORGANIZE", + "REPEATABLE", + "REPEATABLEREAD", + "REPLACE", + "REPLICATE", + "RESAMPLE", + "RESPECT", + "RESULT_SET_CACHING", + "RESUMABLE", + "RESTRICTED_USER", + "RESUME", + "RETENTION_PERIOD", + "ROBUST", + "ROOT", + "ROUND_ROBIN", + "ROW_NUMBER", + "ROWLOCK", + "ROWS_PER_BATCH", + "ROWTERMINATOR", + "S", + "SCALEOUTEXECUTION", + "SCHEMA_AND_DATA", + "SCHEMA_ONLY", + "SCHEMABINDING", + "SCHEME", + "SCOPED", + "SCROLL_LOCKS", + "SECONDARY", + "SECRET", + "SECURITY", + "SELF", + "SEQUENCE_NUMBER_COLUMN_NAME", + "SEQUENCE_NUMBER", + "SERDE_METHOD", + "SERIALIZABLE", + "SERVER", + "SERVICE", + "SERVICE_OBJECTIVE", + "SETERROR", + "SETVAR", + "SHOWPLAN_ALL", + "SHOWPLAN_TEXT", + "SHOWPLAN_XML", + "SID", + "SIMPLE", + "SINGLE_BLOB", + "SINGLE_CLOB", + "SINGLE_NCLOB", + "SNAPSHOT", + "SORT_IN_TEMPDB", + "SOURCE", + "SPARSE", + "SPATIAL_WINDOW_MAX_CELLS", + "SPLIT", + "STATISTICAL_SEMANTICS", + "STATISTICS_INCREMENTAL", + "STATISTICS_NORECOMPUTE", + "STOPLIST", + "STRING_AGG", + "STRING_DELIMITER", + "SWITCH", + "SYNONYM", + "SYSTEM_TIME", + "SYSTEM_VERSIONING", + "TB", + "TABLOCK", + "TABLOCKX", + "TAKE", + "TARGET", + "TARGET_RECOVERY_TIME", + "TEXTIMAGE_ON", + "THROW", + "TIES", + "TIMEOUT", + "TRANSACTION_ID_COLUMN_NAME", + "TRANSACTION_ID", + "TRANSFORM_NOISE_WORDS", + "TRUNCATE_TARGET", + "TRUSTWORTHY", + "TRY", + "TYPE", + "TYPE_WARNING", + "TWO_DIGIT_YEAR_CUTOFF", + "UNBOUNDED", + "UNCOMMITTED", + "UNDEFINED", + "UNLIMITED", + "UPDLOCK", + "USE_TYPE_DEFAULT", + "USED", + "USER_DB", + "VIEW_METADATA", + "WAIT_AT_LOW_PRIORITY", + "WEEK", + "WEEKS", + "WINDOWS", + "WITHOUT_ARRAY_WRAPPER", + "XACT_ABORT", + "XLOCK", + "XML_COMPRESSION", + "XML", + "XMLDATA", + "XMLSCHEMA", + "XSINIL", + "YEARS", + "TINYINT", + "BIGINT", + "MONEY", + "SMALLMONEY", + "SMALLDATETIME", + "DATETIME", + "DATETIME2", + "DATETIMEOFFSET", + "TEXT", + "NVARCHAR", + "NTEXT", + "VARBINARY", + "IMAGE", + "SQL_VARIANT", + "ROWVERSION", + "UNIQUEIDENTIFIER", + "GEOGRAPHY", + "GEOMETRY", + "HIERARCHYID", + "VECTOR", +]; diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/alter_sequence.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/alter_sequence.yml index f51b4c191..89da4d252 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/alter_sequence.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/alter_sequence.yml @@ -3,7 +3,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - alter_sequence_options_segment: - keyword: INCREMENT @@ -14,7 +14,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - alter_sequence_options_segment: - keyword: MAXVALUE @@ -27,7 +27,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - alter_sequence_options_segment: - keyword: NOCACHE @@ -38,7 +38,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - alter_sequence_options_segment: - keyword: NOORDER @@ -52,7 +52,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - alter_sequence_options_segment: - keyword: ORDER diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/arithmetic_a.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/arithmetic_a.yml index 6163d1aba..35fcfd264 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/arithmetic_a.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/arithmetic_a.yml @@ -23,7 +23,8 @@ file: - binary_operator: + - numeric_literal: '13' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: val - statement_terminator: ; - statement: @@ -53,7 +54,8 @@ file: - binary_operator: + - numeric_literal: '13' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: val - statement_terminator: ; - statement: @@ -106,11 +108,11 @@ file: - select_clause_element: - expression: - numeric_literal: '4' - - comparison_operator: + - binary_operator: - ampersand: '&' - tilde: '~' - numeric_literal: '8' - - comparison_operator: + - binary_operator: - pipe: '|' - numeric_literal: '16' - statement_terminator: ; @@ -136,7 +138,7 @@ file: - select_clause_element: - expression: - numeric_literal: '8' - - comparison_operator: + - binary_operator: - pipe: '|' - tilde: '~' - tilde: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_index_if_not_exists.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_index_if_not_exists.yml index ec5263fdc..7eb1e842e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_index_if_not_exists.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_index_if_not_exists.yml @@ -6,7 +6,7 @@ file: - keyword: IF - keyword: NOT - keyword: EXISTS - - database_reference: + - index_reference: - naked_identifier: transaction_updated - keyword: ON - table_reference: diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_index_simple.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_index_simple.yml index b9f741271..b0954ad7c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_index_simple.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_index_simple.yml @@ -3,7 +3,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: transaction_updated - keyword: ON - table_reference: @@ -19,7 +19,7 @@ file: - keyword: CREATE - keyword: UNIQUE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: transaction_updated - keyword: ON - table_reference: diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_schema_a.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_schema_a.yml index cfa69f755..bf779b6ee 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_schema_a.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_schema_a.yml @@ -3,6 +3,5 @@ file: - create_schema_statement: - keyword: create - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_schema_if_not_exists.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_schema_if_not_exists.yml index ed495dd8a..f7bf3bbe5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_schema_if_not_exists.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_schema_if_not_exists.yml @@ -6,6 +6,5 @@ file: - keyword: if - keyword: not - keyword: exists - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_sequence.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_sequence.yml index 040198418..48aa07a4e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_sequence.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/create_sequence.yml @@ -3,14 +3,14 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - statement_terminator: ; - statement: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: INCREMENT @@ -21,7 +21,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: MINVALUE @@ -34,7 +34,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: NO @@ -47,7 +47,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: INCREMENT @@ -65,7 +65,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: NOCACHE @@ -74,7 +74,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: NOCYCLE @@ -85,7 +85,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: NOORDER diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/double_quote_escapes.sql b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/double_quote_escapes.sql new file mode 100644 index 000000000..f99b7de61 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/double_quote_escapes.sql @@ -0,0 +1,10 @@ +select + 1 as foo, + 2 as "foo", + 3 as """foo""", + 4 as """""foo""""", + bar, + "bar", + """bar""", + """""bar""""" +from """""a"""""."""""b"""""."""""c""""" diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/double_quote_escapes.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/double_quote_escapes.yml new file mode 100644 index 000000000..ff20e9fd2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/double_quote_escapes.yml @@ -0,0 +1,59 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: foo + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: as + - quoted_identifier: '"foo"' + - comma: ',' + - select_clause_element: + - numeric_literal: '3' + - alias_expression: + - alias_operator: + - keyword: as + - quoted_identifier: '"""foo"""' + - comma: ',' + - select_clause_element: + - numeric_literal: '4' + - alias_expression: + - alias_operator: + - keyword: as + - quoted_identifier: '"""""foo"""""' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: bar + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '"bar"' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '"""bar"""' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '"""""bar"""""' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '"""""a"""""' + - dot: . + - quoted_identifier: '"""""b"""""' + - dot: . + - quoted_identifier: '"""""c"""""' diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_index_if_exists.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_index_if_exists.yml index aeeef075b..f4c1db135 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_index_if_exists.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_index_if_exists.yml @@ -5,6 +5,6 @@ file: - keyword: INDEX - keyword: IF - keyword: EXISTS - - database_reference: + - index_reference: - naked_identifier: transaction_updated - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_index_simple.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_index_simple.yml index 285629a1e..0e6a4b46e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_index_simple.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_index_simple.yml @@ -3,6 +3,6 @@ file: - drop_index_statement: - keyword: DROP - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: transaction_updated - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_schema.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_schema.yml index fd30fbc05..a8d6dca21 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_schema.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_schema.yml @@ -3,26 +3,23 @@ file: - drop_schema_statement: - keyword: drop - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - statement_terminator: ; - statement: - drop_schema_statement: - keyword: drop - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - keyword: cascade - statement_terminator: ; - statement: - drop_schema_statement: - keyword: drop - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - keyword: restrict - statement_terminator: ; - statement: @@ -31,9 +28,8 @@ file: - keyword: schema - keyword: if - keyword: exists - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - statement_terminator: ; - statement: - drop_schema_statement: @@ -41,9 +37,8 @@ file: - keyword: schema - keyword: if - keyword: exists - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - keyword: cascade - statement_terminator: ; - statement: @@ -52,8 +47,7 @@ file: - keyword: schema - keyword: if - keyword: exists - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - keyword: restrict - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_schema_a.sql b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_schema_a.sql deleted file mode 100644 index 0dffbcddc..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_schema_a.sql +++ /dev/null @@ -1 +0,0 @@ -drop schema my_schema \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_schema_a.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_schema_a.yml deleted file mode 100644 index eb8296a8f..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_schema_a.yml +++ /dev/null @@ -1,8 +0,0 @@ -file: -- statement: - - drop_schema_statement: - - keyword: drop - - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: my_schema diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_sequence.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_sequence.yml index 6f4362e51..9de7ed086 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_sequence.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/drop_sequence.yml @@ -3,14 +3,14 @@ file: - drop_sequence_statement: - keyword: DROP - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - statement_terminator: ; - statement: - drop_sequence_statement: - keyword: DROP - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - dot: . - naked_identifier: foo diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/escaped_quotes.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/escaped_quotes.yml index eb5f3c5da..b02ff5360 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/escaped_quotes.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/escaped_quotes.yml @@ -19,7 +19,8 @@ file: - quoted_literal: '''boop''' - keyword: end - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: field - statement_terminator: ; - statement: @@ -29,6 +30,7 @@ file: - select_clause_element: - quoted_literal: '''This shouldn''''t fail''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: success - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/functions_a.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/functions_a.yml index d07c0e182..8e447f164 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/functions_a.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/functions_a.yml @@ -67,7 +67,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: compound - from_clause: - keyword: FROM @@ -92,6 +93,7 @@ file: - numeric_literal: '5' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: test_column - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/functions_b.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/functions_b.yml index 7069ad556..d90bc2681 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/functions_b.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/functions_b.yml @@ -26,7 +26,8 @@ file: - quoted_literal: ''' ''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: text - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/insert_using_subquery.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/insert_using_subquery.yml index 5ae7b5f12..4e6fcaeb9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/insert_using_subquery.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/insert_using_subquery.yml @@ -11,7 +11,8 @@ file: - select_clause_element: - numeric_literal: '0' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: bar - statement_terminator: ; - statement: @@ -28,7 +29,8 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: bar - end_bracket: ) - statement_terminator: ; @@ -48,7 +50,8 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: bar - end_bracket: ) - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/like_operators.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/like_operators.yml index ebcee5c98..46d8d513d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/like_operators.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/like_operators.yml @@ -19,12 +19,12 @@ file: - expression: - column_reference: - naked_identifier: a - - comparison_operator: '!~' + - like_operator: '!~' - quoted_literal: '''[a-z]''' - binary_operator: AND - column_reference: - naked_identifier: d - - comparison_operator: '!~~*' + - like_operator: '!~~*' - quoted_literal: '''[a-z]''' - binary_operator: AND - column_reference: @@ -34,5 +34,5 @@ file: - binary_operator: AND - column_reference: - naked_identifier: c - - comparison_operator: '!~*' + - like_operator: '!~*' - quoted_literal: '''^([0-9]){1,}(\.)([0-9]{1,})$''' diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/merge_into.sql b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/merge_into.sql index a0ecf96fc..09ad750ed 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/merge_into.sql +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/merge_into.sql @@ -35,4 +35,4 @@ MERGE INTO t USING source AS u ON (a = b) WHEN MATCHED THEN UPDATE SET a = b WHEN NOT MATCHED THEN -INSERT (b) VALUES (c); \ No newline at end of file +INSERT (b) VALUES (c); diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/merge_into.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/merge_into.yml index 79d0ad7b9..5cafad189 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/merge_into.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/merge_into.yml @@ -82,7 +82,8 @@ file: - naked_identifier: u - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: u - join_on_condition: - keyword: ON @@ -307,7 +308,8 @@ file: - table_reference: - naked_identifier: source - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: u - join_on_condition: - keyword: ON diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/modulo.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/modulo.yml index 275d28b5d..ef091da53 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/modulo.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/modulo.yml @@ -51,7 +51,8 @@ file: - boolean_literal: 'FALSE' - keyword: END - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: is_leap_year - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/multiple_semicolons.sql b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/multiple_semicolons.sql new file mode 100644 index 000000000..a9bc38d69 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/multiple_semicolons.sql @@ -0,0 +1,17 @@ +-- Leading double semicolons before first statement +;;SELECT col1 FROM tbl1; + +-- Statement with trailing double semicolons +SELECT col2 FROM tbl2;; + +-- Multiple semicolons separating statements +SELECT col3 FROM tbl3;;;;SELECT col4 FROM tbl4; + +-- Mixed whitespace and semicolons +; ; ;SELECT col5 FROM tbl5; ; ; + +-- Many semicolons at end +SELECT col6 FROM tbl6;;;;;; + +-- Many semicolons at end +SELECT col6 FROM tbl6;;;;;; diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/multiple_semicolons.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/multiple_semicolons.yml new file mode 100644 index 000000000..6cafbd83d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/multiple_semicolons.yml @@ -0,0 +1,127 @@ +file: +- statement_terminator: ; +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl2 +- statement_terminator: ; +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col3 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl3 +- statement_terminator: ; +- statement_terminator: ; +- statement_terminator: ; +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col4 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl4 +- statement_terminator: ; +- statement_terminator: ; +- statement_terminator: ; +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col5 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl5 +- statement_terminator: ; +- statement_terminator: ; +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col6 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl6 +- statement_terminator: ; +- statement_terminator: ; +- statement_terminator: ; +- statement_terminator: ; +- statement_terminator: ; +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col6 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl6 +- statement_terminator: ; +- statement_terminator: ; +- statement_terminator: ; +- statement_terminator: ; +- statement_terminator: ; +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/naked_identifiers.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/naked_identifiers.yml index fad625b53..a8d1e8e8d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/naked_identifiers.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/naked_identifiers.yml @@ -7,7 +7,8 @@ file: - column_reference: - quoted_identifier: '"a"' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: 0_is_a_legal_identifier - statement_terminator: ; - statement: @@ -18,7 +19,8 @@ file: - column_reference: - quoted_identifier: '"a"' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: 00_is_a_legal_identifier - statement_terminator: ; - statement: @@ -39,7 +41,8 @@ file: - column_reference: - quoted_identifier: '"a"' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: 0is_a_legal_identifier - statement_terminator: ; - statement: @@ -69,6 +72,7 @@ file: - column_reference: - quoted_identifier: '"a"' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: is_a_legal_identifier0 - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/obevo.sql b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/obevo.sql new file mode 100644 index 000000000..8608c3289 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/obevo.sql @@ -0,0 +1,13 @@ +//// CHANGE name=alter1 + +ALTER TABLE table1 ADD COLUMN colY NUMBER; + +ALTER TABLE table1 ADD COLUMN colZ NUMBER; + +//// METADATA test +//// CHANGE name="init" +CREATE TABLE OrigTable ( + Field1 int, + Field2 int +) +//// CHANGE name="dropOld" DROP_TABLE dependencies="OldToNewTableMigration.migration" diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/obevo.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/obevo.yml new file mode 100644 index 000000000..bc059932c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/obevo.yml @@ -0,0 +1,45 @@ +file: +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: colY + - data_type: + - data_type_identifier: NUMBER +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: colZ + - data_type: + - data_type_identifier: NUMBER +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: OrigTable + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: Field1 + - data_type: + - data_type_identifier: int + - comma: ',' + - column_definition: + - naked_identifier: Field2 + - data_type: + - data_type_identifier: int + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_bitwise_operators.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_bitwise_operators.yml index 6da50a4df..91a137ad9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_bitwise_operators.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_bitwise_operators.yml @@ -7,7 +7,7 @@ file: - expression: - column_reference: - naked_identifier: c1 - - comparison_operator: + - binary_operator: - ampersand: '&' - column_reference: - naked_identifier: c2 @@ -16,7 +16,7 @@ file: - expression: - column_reference: - naked_identifier: c3 - - comparison_operator: + - binary_operator: - pipe: '|' - column_reference: - naked_identifier: c4 @@ -33,7 +33,7 @@ file: - expression: - column_reference: - naked_identifier: c7 - - comparison_operator: + - binary_operator: - raw_comparison_operator: < - raw_comparison_operator: < - column_reference: @@ -43,7 +43,7 @@ file: - expression: - column_reference: - naked_identifier: c9 - - comparison_operator: + - binary_operator: - raw_comparison_operator: '>' - raw_comparison_operator: '>' - column_reference: diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_case_a.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_case_a.yml index 01b47b535..591bb6800 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_case_a.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_case_a.yml @@ -54,7 +54,8 @@ file: - quoted_identifier: '"boo"' - keyword: END - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: a_case_statement - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_case_b.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_case_b.yml index 75981c410..2019b40b3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_case_b.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_case_b.yml @@ -30,7 +30,8 @@ file: - numeric_literal: '0' - keyword: END - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: a_case_statement - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_case_c.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_case_c.yml index 57567bcce..e04356750 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_case_c.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_case_c.yml @@ -31,7 +31,8 @@ file: - data_type: - data_type_identifier: text - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: mycol - from_clause: - keyword: from @@ -76,7 +77,8 @@ file: - data_type: - data_type_identifier: float - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: mycol - from_clause: - keyword: from @@ -124,7 +126,8 @@ file: - data_type_identifier: text - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: mycol - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_cross_join.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_cross_join.yml index 41c46f68b..a14a01293 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_cross_join.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_cross_join.yml @@ -13,7 +13,8 @@ file: - select_clause_element: - numeric_literal: '8760' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: hours_per_year - end_bracket: ) - select_statement: @@ -43,7 +44,8 @@ file: - dot: . - naked_identifier: hours_per_year - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: some_value - from_clause: - keyword: FROM @@ -66,7 +68,8 @@ file: - table_reference: - naked_identifier: table2 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: foo - keyword: USING - bracketed: diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_e.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_e.yml index 69724da84..a93c8e5dc 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_e.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_e.yml @@ -8,7 +8,8 @@ file: - column_reference: - naked_identifier: col_a - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: foo - from_clause: - keyword: FROM @@ -26,7 +27,8 @@ file: - column_reference: - naked_identifier: col_b - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: foo - from_clause: - keyword: FROM @@ -45,7 +47,8 @@ file: - column_reference: - naked_identifier: col_c - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: foo - from_clause: - keyword: FROM @@ -63,7 +66,8 @@ file: - column_reference: - naked_identifier: col_d - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: foo - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_f.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_f.yml index 49c06cb20..e03b9bae6 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_f.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_f.yml @@ -33,7 +33,8 @@ file: - numeric_literal: '53' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: c2 - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_g.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_g.yml index 279af73cf..d7520d2c4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_g.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_g.yml @@ -11,7 +11,8 @@ file: - data_type: - data_type_identifier: INT - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: user_id - comma: ',' - select_clause_element: @@ -22,7 +23,8 @@ file: - data_type: - data_type_identifier: INT - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: is_paid - limit_clause: - keyword: LIMIT diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_g_fetch.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_g_fetch.yml index 0890f91c7..4d431ac46 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_g_fetch.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_g_fetch.yml @@ -11,7 +11,8 @@ file: - data_type: - data_type_identifier: INT - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: user_id - comma: ',' - select_clause_element: @@ -22,7 +23,8 @@ file: - data_type: - data_type_identifier: INT - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: is_paid - fetch_clause: - keyword: FETCH diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_h.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_h.yml index 8c811bca9..bd8642262 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_h.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_h.yml @@ -20,7 +20,8 @@ file: - quoted_literal: '''America/New_York''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: date - comma: ',' - select_clause_element: @@ -55,7 +56,8 @@ file: - keyword: END - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: tech_support - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_many_join.sql b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_many_join.sql index 11077a3bf..83794d025 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_many_join.sql +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_many_join.sql @@ -1,2 +1,44 @@ SELECT * -FROM a as foo JOIN b JOIN c as foobar JOIN d, e as bar JOIN f JOIN g('blah') as tbl_func JOIN h, baz as buzz \ No newline at end of file +FROM a as foo JOIN b JOIN c as foobar JOIN d, e as bar JOIN f JOIN g('blah') as tbl_func JOIN h, baz as buzz; + + +SELECT + c.f1 as f1 + , co.f2 as f2 + , po.f3 as f3 + , c2c.f4 as f4 + , c_ph.f5 as f5 +FROM t1 AS c +LEFT JOIN t2 AS co + ON c.f1 = co.f1 +LEFT JOIN t3 AS po + ON c.f1 = po.f1 +LEFT JOIN ( + SELECT t._tmp as _tmp + FROM (SELECT * FROM t4) AS t +) AS l_ccc + ON c.f1 = l_ccc._tmp +LEFT JOIN t5 AS cc + ON l_ccc._tmp = cc.f1 +LEFT JOIN ( + ( + SELECT t._tmp AS _tmp + FROM (SELECT * FROM t6) AS t + ) AS l_c2c_c + LEFT JOIN ( + SELECT a1._tmp AS _tmp + , h.id + , h.f1 + FROM ( + SELECT t.id + , t.f4 + + FROM (SELECT * FROM t7) AS t) AS h + LEFT JOIN (SELECT * FROM t8) AS a1 + ON a1.id = h.id + ) AS c2c + ON l_c2c_c._tmp = c2c.id +) +ON c.f1 = l_c2c_c._tmp +LEFT JOIN t9 AS c_ph + ON c.f1 = c_ph.f1; diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_many_join.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_many_join.yml index 3e600a01a..b167161c9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_many_join.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_many_join.yml @@ -15,7 +15,8 @@ file: - table_reference: - naked_identifier: a - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: foo - join_clause: - keyword: JOIN @@ -30,7 +31,8 @@ file: - table_reference: - naked_identifier: c - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: foobar - join_clause: - keyword: JOIN @@ -45,7 +47,8 @@ file: - table_reference: - naked_identifier: e - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: bar - join_clause: - keyword: JOIN @@ -67,7 +70,8 @@ file: - quoted_literal: '''blah''' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: tbl_func - join_clause: - keyword: JOIN @@ -82,5 +86,437 @@ file: - table_reference: - naked_identifier: baz - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: buzz +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: f1 + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: f1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: co + - dot: . + - naked_identifier: f2 + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: f2 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: po + - dot: . + - naked_identifier: f3 + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: f3 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: c2c + - dot: . + - naked_identifier: f4 + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: f4 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: c_ph + - dot: . + - naked_identifier: f5 + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: f5 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: c + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: co + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: f1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: co + - dot: . + - naked_identifier: f1 + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t3 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: po + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: f1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: po + - dot: . + - naked_identifier: f1 + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: _tmp + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: _tmp + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t4 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: l_ccc + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: f1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: l_ccc + - dot: . + - naked_identifier: _tmp + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t5 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: cc + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: l_ccc + - dot: . + - naked_identifier: _tmp + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: cc + - dot: . + - naked_identifier: f1 + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: _tmp + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: _tmp + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t6 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: l_c2c_c + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a1 + - dot: . + - naked_identifier: _tmp + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: _tmp + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: h + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: h + - dot: . + - naked_identifier: f1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: f4 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t7 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: h + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t8 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a1 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: a1 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: h + - dot: . + - naked_identifier: id + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: c2c + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: l_c2c_c + - dot: . + - naked_identifier: _tmp + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: c2c + - dot: . + - naked_identifier: id + - end_bracket: ) + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: f1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: l_c2c_c + - dot: . + - naked_identifier: _tmp + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t9 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: c_ph + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: f1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: c_ph + - dot: . + - naked_identifier: f1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_multiple_named_windows.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_multiple_named_windows.yml index e847a8c1e..df969d519 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_multiple_named_windows.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_multiple_named_windows.yml @@ -34,7 +34,8 @@ file: - naked_identifier: d - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: most_popular - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_n.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_n.yml index 2b35b364a..2e35688fc 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_n.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_n.yml @@ -9,7 +9,8 @@ file: - dot: . - naked_identifier: business_type - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: business_type_left - comma: ',' - select_clause_element: @@ -18,7 +19,8 @@ file: - dot: . - naked_identifier: business_type - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: business_type_right - from_clause: - keyword: FROM @@ -28,7 +30,8 @@ file: - table_reference: - naked_identifier: benchmark_summaries - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: exists_left - join_clause: - keyword: FULL @@ -38,7 +41,8 @@ file: - table_reference: - naked_identifier: business_types - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: exists_right - join_on_condition: - keyword: ON diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_named_window_no_parentheses.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_named_window_no_parentheses.yml index a53adb951..6c0ebd927 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_named_window_no_parentheses.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_named_window_no_parentheses.yml @@ -21,7 +21,8 @@ file: - keyword: OVER - naked_identifier: w1 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: baz - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_named_window_with_parentheses.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_named_window_with_parentheses.yml index 967bfef76..612c5e683 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_named_window_with_parentheses.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_named_window_with_parentheses.yml @@ -25,7 +25,8 @@ file: - naked_identifier: w1 - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: baz - comma: ',' - select_clause_element: @@ -48,7 +49,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: foo - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_named_windows_each_window_specification.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_named_windows_each_window_specification.yml index 2faf005b6..fc525a2c4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_named_windows_each_window_specification.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_named_windows_each_window_specification.yml @@ -34,7 +34,8 @@ file: - naked_identifier: c - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: most_popular - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_nested_join.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_nested_join.yml index 3db1efe6d..b5b7137be 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_nested_join.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_nested_join.yml @@ -9,7 +9,8 @@ file: - dot: . - naked_identifier: order_id - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: order_id - comma: ',' - select_clause_element: @@ -18,7 +19,8 @@ file: - dot: . - naked_identifier: email - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: email - from_clause: - keyword: from @@ -96,7 +98,8 @@ file: - dot: . - naked_identifier: order_id - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: order_id - comma: ',' - select_clause_element: @@ -105,7 +108,8 @@ file: - dot: . - naked_identifier: email - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: email - from_clause: - keyword: from @@ -186,7 +190,8 @@ file: - dot: . - naked_identifier: order_id - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: order_id - comma: ',' - select_clause_element: @@ -195,20 +200,20 @@ file: - dot: . - naked_identifier: email - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: email - from_clause: - keyword: from - from_expression: - bracketed: - start_bracket: ( - - bracketed: - - start_bracket: ( - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: orders + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - table_reference: + - naked_identifier: orders - join_clause: - keyword: join - from_expression_element: @@ -235,7 +240,7 @@ file: - naked_identifier: customer_id - end_bracket: ) - end_bracket: ) - - end_bracket: ) + - end_bracket: ) - join_clause: - keyword: join - from_expression_element: @@ -306,7 +311,8 @@ file: - dot: . - naked_identifier: order_id - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: order_id - comma: ',' - select_clause_element: @@ -315,7 +321,8 @@ file: - dot: . - naked_identifier: email - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: email - from_clause: - keyword: from @@ -325,13 +332,12 @@ file: - bracketed: - start_bracket: ( - from_expression: - - bracketed: - - start_bracket: ( - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: orders + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - table_reference: + - naked_identifier: orders - join_clause: - keyword: join - from_expression_element: @@ -358,7 +364,7 @@ file: - naked_identifier: customer_id - end_bracket: ) - end_bracket: ) - - end_bracket: ) + - end_bracket: ) - join_clause: - keyword: join - from_expression_element: diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_offset.sql b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_offset.sql new file mode 100644 index 000000000..3cd340f16 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_offset.sql @@ -0,0 +1,3 @@ +SELECT * FROM test OFFSET 10 ROWS FETCH FIRST 10 ROWS ONLY; + +SELECT Name, Address FROM Employees ORDER BY Salary OFFSET 2 ROWS FETCH FIRST 2 ROWS ONLY; diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_offset.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_offset.yml new file mode 100644 index 000000000..97520eccb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_offset.yml @@ -0,0 +1,61 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test + - offset_clause: + - keyword: OFFSET + - numeric_literal: '10' + - keyword: ROWS + - fetch_clause: + - keyword: FETCH + - keyword: FIRST + - numeric_literal: '10' + - keyword: ROWS + - keyword: ONLY +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: Name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Address + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Employees + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: Salary + - offset_clause: + - keyword: OFFSET + - numeric_literal: '2' + - keyword: ROWS + - fetch_clause: + - keyword: FETCH + - keyword: FIRST + - numeric_literal: '2' + - keyword: ROWS + - keyword: ONLY +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_p.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_p.yml index 05d8ea23f..b04d676fe 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_p.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_p.yml @@ -31,7 +31,8 @@ file: - data_type_identifier: STRING - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: age_label - comma: ',' - select_clause_element: @@ -48,7 +49,8 @@ file: - naked_identifier: end_time - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: day - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_q.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_q.yml index a94b815cc..f1d099daf 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_q.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_q.yml @@ -44,7 +44,8 @@ file: - dot: . - quoted_identifier: '"other_data"' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: od - join_on_condition: - keyword: ON diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_r.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_r.yml index 81ab73652..e7f15449f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_r.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_r.yml @@ -22,7 +22,8 @@ file: - table_reference: - naked_identifier: sales_eu - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: s - set_operator: - keyword: UNION @@ -41,7 +42,8 @@ file: - table_reference: - naked_identifier: sales_us - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: s2 - end_bracket: ) - select_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_s.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_s.yml index 2434c7358..bc9a779dd 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_s.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_s.yml @@ -134,7 +134,8 @@ file: - column_reference: - naked_identifier: audience_size - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: relative_abundance - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_sample_bernoulli_10_aliased.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_sample_bernoulli_10_aliased.yml index fcdf5b93e..3a404170e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_sample_bernoulli_10_aliased.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_sample_bernoulli_10_aliased.yml @@ -16,7 +16,8 @@ file: - table_reference: - naked_identifier: foo - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: f - sample_expression: - keyword: TABLESAMPLE diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_sample_system_10_aliased.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_sample_system_10_aliased.yml index 74c7d9fcc..017c71c85 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_sample_system_10_aliased.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_sample_system_10_aliased.yml @@ -16,7 +16,8 @@ file: - table_reference: - naked_identifier: foo - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: f - sample_expression: - keyword: TABLESAMPLE diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_simple_e.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_simple_e.yml index 9306cb070..082b64b0d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_simple_e.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_simple_e.yml @@ -12,7 +12,8 @@ file: - data_type: - data_type_identifier: date - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: casted_variable - comma: ',' - select_clause_element: @@ -23,7 +24,8 @@ file: - data_type: - data_type_identifier: bigint - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: another_casted_number - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_simple_h.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_simple_h.yml index 8e351b79a..f71436984 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_simple_h.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_simple_h.yml @@ -37,7 +37,8 @@ file: - quoted_literal: '''2014-01-01''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: dt - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_simple_i.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_simple_i.yml index 0f2d95f24..9ae1cff93 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_simple_i.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_simple_i.yml @@ -17,7 +17,8 @@ file: - column_reference: - naked_identifier: simple_explicit - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: aliased_column_1 - comma: ',' - select_clause_element: @@ -42,7 +43,8 @@ file: - column_reference: - naked_identifier: aliased - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: calculation - comma: ',' - select_clause_element: @@ -56,7 +58,8 @@ file: - sign_indicator: '-' - numeric_literal: '786' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: aliased_column3 - from_clause: - keyword: FROM @@ -72,7 +75,8 @@ file: - table_reference: - naked_identifier: aliased_1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: foo - join_clause: - keyword: JOIN diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_u.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_u.yml index d341fa114..09ca67f32 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_u.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_u.yml @@ -18,7 +18,8 @@ file: - quoted_literal: '''abc''' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: b - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_union_bracketed.sql b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_union_bracketed.sql index 77083e644..f7968df54 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_union_bracketed.sql +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_union_bracketed.sql @@ -2,3 +2,14 @@ ((SELECT 0)) UNION ((SELECT 1)); +( + SELECT * FROM tbl1 + EXCEPT + SELECT * FROM tbl2 +) +UNION +( + SELECT * FROM tbl2 + EXCEPT + SELECT * FROM tbl1 +); diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_union_bracketed.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_union_bracketed.yml index a542624d6..967287cbd 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_union_bracketed.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_union_bracketed.yml @@ -47,3 +47,76 @@ file: - end_bracket: ) - end_bracket: ) - statement_terminator: ; +- statement: + - set_expression: + - bracketed: + - start_bracket: ( + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 + - set_operator: + - keyword: EXCEPT + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl2 + - end_bracket: ) + - set_operator: + - keyword: UNION + - bracketed: + - start_bracket: ( + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl2 + - set_operator: + - keyword: EXCEPT + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_with_brackets.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_with_brackets.yml index 3718f1af6..468209851 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_with_brackets.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_with_brackets.yml @@ -52,16 +52,15 @@ file: - from_expression: - bracketed: - start_bracket: ( - - bracketed: - - start_bracket: ( - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: my_table - - alias_expression: - - naked_identifier: tt - - end_bracket: ) + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - table_reference: + - naked_identifier: my_table + - alias_expression: + - naked_identifier: tt + - end_bracket: ) - end_bracket: ) - statement_terminator: ; - statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_with_where_clause_functions.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_with_where_clause_functions.yml index c022fc6a7..dac604c54 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_with_where_clause_functions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/select_with_where_clause_functions.yml @@ -18,7 +18,8 @@ file: - dot: . - naked_identifier: table1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - where_clause: - keyword: where diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/set_order_by.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/set_order_by.yml index 09e73cab1..dd4a92f4d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/set_order_by.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/set_order_by.yml @@ -7,7 +7,8 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - set_operator: - keyword: UNION @@ -18,7 +19,8 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - orderby_clause: - keyword: ORDER diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/set_schema_a.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/set_schema_a.yml index 1cf50ad81..4ed7fa4ed 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/set_schema_a.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/set_schema_a.yml @@ -3,6 +3,5 @@ file: - set_schema_statement: - keyword: set - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/shorthand_cast.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/shorthand_cast.yml index b800edb42..06cf2120b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/shorthand_cast.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/shorthand_cast.yml @@ -11,7 +11,8 @@ file: - data_type: - data_type_identifier: INT - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: id1 - comma: ',' - select_clause_element: @@ -22,7 +23,8 @@ file: - data_type: - data_type_identifier: int - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: id2 - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/table_expression.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/table_expression.yml index 800e46121..3437a0ab2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/table_expression.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/table_expression.yml @@ -7,7 +7,8 @@ file: - column_reference: - naked_identifier: y - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: woy - from_clause: - keyword: FROM @@ -35,7 +36,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: y - statement_terminator: ; - statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/update_with_table_alias.yml b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/update_with_table_alias.yml index e71c9c0fb..c08322899 100644 --- a/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/update_with_table_alias.yml +++ b/crates/lib-dialects/test/fixtures/dialects/ansi/sqlfluff/update_with_table_alias.yml @@ -5,7 +5,8 @@ file: - table_reference: - naked_identifier: my_table - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: tttd - set_clause_list: - keyword: SET diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/alter_table.sql b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/alter_table.sql index 7cea26c0a..2555e70b9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/alter_table.sql +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/alter_table.sql @@ -1,2 +1,38 @@ +-- ANSI-inherited ALTER TABLE operations ALTER TABLE x DROP COLUMN y; ALTER TABLE x DROP y; + +-- ADD COLUMNS (basic and with PARTITION) +ALTER TABLE table_name ADD COLUMNS (col_name int); +ALTER TABLE table_name ADD COLUMNS (col1 varchar(50), col2 int, col3 boolean); +ALTER TABLE table_name PARTITION (partition_col1_name = 'value1') ADD COLUMNS (col_name int); +ALTER TABLE table_name PARTITION (partition_col1_name = 'value1', partition_col2_name = 'value2') ADD COLUMNS (col1 varchar(50), col2 int); + +-- ADD PARTITION +ALTER TABLE orders ADD PARTITION (dt = '2016-05-14', country = 'IN'); +ALTER TABLE orders ADD IF NOT EXISTS PARTITION (dt = '2016-05-31', country = 'IN') LOCATION 's3://amzn-s3-demo-bucket/path/to/INDIA_31_May_2016/'; +ALTER TABLE orders ADD PARTITION (dt = '2016-05-31', country = 'IN') PARTITION (dt = '2016-06-01', country = 'IN'); + +-- CHANGE COLUMN +ALTER TABLE example_table CHANGE COLUMN area zip int AFTER id; +ALTER TABLE example_table CHANGE zip zip int COMMENT 'USA zipcode'; +ALTER TABLE my_table CHANGE old_col new_col string FIRST; + +-- DROP PARTITION +ALTER TABLE orders DROP PARTITION (dt = '2014-05-14', country = 'IN'); +ALTER TABLE orders DROP IF EXISTS PARTITION (dt = '2014-05-14', country = 'IN'), PARTITION (dt = '2014-05-15', country = 'IN'); + +-- RENAME PARTITION +ALTER TABLE orders PARTITION (dt = '2014-05-14', country = 'IN') RENAME TO PARTITION (dt = '2014-05-15', country = 'IN'); + +-- REPLACE COLUMNS (basic and with PARTITION) +ALTER TABLE names_cities REPLACE COLUMNS (first_name string, last_name string, city string); +ALTER TABLE partitioned_table PARTITION (year = 2023) REPLACE COLUMNS (new_col1 int, new_col2 string); + +-- SET LOCATION (basic and with PARTITION) +ALTER TABLE my_table SET LOCATION 's3://my-bucket/new-location/'; +ALTER TABLE my_table PARTITION (dt = '2023-01-01') SET LOCATION 's3://my-bucket/partition-location/'; + +-- SET TBLPROPERTIES +ALTER TABLE my_table SET TBLPROPERTIES ('property_name' = 'property_value'); +ALTER TABLE my_table SET TBLPROPERTIES ('property_name' = 'property_value', 'another_prop' = 'another_value'); diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/alter_table.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/alter_table.yml index cf6af947e..de9635ee0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/alter_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/alter_table.yml @@ -18,3 +18,494 @@ file: - parameter: DROP - naked_identifier: y - statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table_name + - keyword: ADD + - keyword: COLUMNS + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col_name + - data_type: + - primitive_type: + - keyword: int + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table_name + - keyword: ADD + - keyword: COLUMNS + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '50' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - primitive_type: + - keyword: int + - comma: ',' + - column_definition: + - naked_identifier: col3 + - data_type: + - primitive_type: + - keyword: boolean + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table_name + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: partition_col1_name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value1''' + - end_bracket: ) + - keyword: ADD + - keyword: COLUMNS + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col_name + - data_type: + - primitive_type: + - keyword: int + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table_name + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: partition_col1_name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value1''' + - comma: ',' + - column_reference: + - naked_identifier: partition_col2_name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value2''' + - end_bracket: ) + - keyword: ADD + - keyword: COLUMNS + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '50' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - primitive_type: + - keyword: int + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: orders + - keyword: ADD + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: dt + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2016-05-14''' + - comma: ',' + - column_reference: + - naked_identifier: country + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''IN''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: orders + - keyword: ADD + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: dt + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2016-05-31''' + - comma: ',' + - column_reference: + - naked_identifier: country + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''IN''' + - end_bracket: ) + - keyword: LOCATION + - quoted_literal: '''s3://amzn-s3-demo-bucket/path/to/INDIA_31_May_2016/''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: orders + - keyword: ADD + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: dt + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2016-05-31''' + - comma: ',' + - column_reference: + - naked_identifier: country + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''IN''' + - end_bracket: ) + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: dt + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2016-06-01''' + - comma: ',' + - column_reference: + - naked_identifier: country + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''IN''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: example_table + - keyword: CHANGE + - keyword: COLUMN + - column_reference: + - naked_identifier: area + - column_reference: + - naked_identifier: zip + - data_type: + - primitive_type: + - keyword: int + - keyword: AFTER + - column_reference: + - naked_identifier: id +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: example_table + - keyword: CHANGE + - column_reference: + - naked_identifier: zip + - column_reference: + - naked_identifier: zip + - data_type: + - primitive_type: + - keyword: int + - keyword: COMMENT + - quoted_literal: '''USA zipcode''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: CHANGE + - column_reference: + - naked_identifier: old_col + - column_reference: + - naked_identifier: new_col + - data_type: + - primitive_type: + - keyword: string + - keyword: FIRST +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: orders + - keyword: DROP + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: dt + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2014-05-14''' + - comma: ',' + - column_reference: + - naked_identifier: country + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''IN''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: orders + - keyword: DROP + - keyword: IF + - keyword: EXISTS + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: dt + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2014-05-14''' + - comma: ',' + - column_reference: + - naked_identifier: country + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''IN''' + - end_bracket: ) + - comma: ',' + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: dt + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2014-05-15''' + - comma: ',' + - column_reference: + - naked_identifier: country + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''IN''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: orders + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: dt + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2014-05-14''' + - comma: ',' + - column_reference: + - naked_identifier: country + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''IN''' + - end_bracket: ) + - keyword: RENAME + - keyword: TO + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: dt + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2014-05-15''' + - comma: ',' + - column_reference: + - naked_identifier: country + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''IN''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: names_cities + - keyword: REPLACE + - keyword: COLUMNS + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: first_name + - data_type: + - primitive_type: + - keyword: string + - comma: ',' + - column_definition: + - naked_identifier: last_name + - data_type: + - primitive_type: + - keyword: string + - comma: ',' + - column_definition: + - naked_identifier: city + - data_type: + - primitive_type: + - keyword: string + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: partitioned_table + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: year + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2023' + - end_bracket: ) + - keyword: REPLACE + - keyword: COLUMNS + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: new_col1 + - data_type: + - primitive_type: + - keyword: int + - comma: ',' + - column_definition: + - naked_identifier: new_col2 + - data_type: + - primitive_type: + - keyword: string + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: SET + - keyword: LOCATION + - quoted_literal: '''s3://my-bucket/new-location/''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: dt + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2023-01-01''' + - end_bracket: ) + - keyword: SET + - keyword: LOCATION + - quoted_literal: '''s3://my-bucket/partition-location/''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: SET + - keyword: TBLPROPERTIES + - bracketed: + - start_bracket: ( + - quoted_literal: '''property_name''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''property_value''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: SET + - keyword: TBLPROPERTIES + - bracketed: + - start_bracket: ( + - quoted_literal: '''property_name''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''property_value''' + - comma: ',' + - quoted_literal: '''another_prop''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''another_value''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/create_array_table.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/create_array_table.yml index ff4b35fd2..f657876e6 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/create_array_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/create_array_table.yml @@ -12,7 +12,7 @@ file: - data_type: - array_type: - keyword: array - - array_type: + - array_type_schema: - start_angle_bracket: < - data_type: - primitive_type: diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/create_external_table_struct.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/create_external_table_struct.yml index ae9bd8db3..9c1e5adc5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/create_external_table_struct.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/create_external_table_struct.yml @@ -77,7 +77,7 @@ file: - data_type: - array_type: - keyword: array - - array_type: + - array_type_schema: - start_angle_bracket: < - data_type: - primitive_type: @@ -141,7 +141,7 @@ file: - data_type: - array_type: - keyword: array - - array_type: + - array_type_schema: - start_angle_bracket: < - data_type: - primitive_type: diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/create_view.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/create_view.yml index c4debd863..36f373bce 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/create_view.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/create_view.yml @@ -24,7 +24,8 @@ file: - binary_operator: / - numeric_literal: '2' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: half - from_clause: - keyword: FROM @@ -61,7 +62,8 @@ file: - binary_operator: / - numeric_literal: '4' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: quarter - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/element_at.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/element_at.yml index 2861148e3..524deb10a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/element_at.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/element_at.yml @@ -51,7 +51,8 @@ file: - naked_identifier: creator_id - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: part1 - comma: ',' - select_clause_element: @@ -75,7 +76,8 @@ file: - object_reference: - naked_identifier: id - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: part2 - comma: ',' - select_clause_element: @@ -99,6 +101,7 @@ file: - object_reference: - naked_identifier: id - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: part3 - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/listagg.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/listagg.yml index bae106b01..2ec5da03e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/listagg.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/listagg.yml @@ -9,7 +9,8 @@ file: - dot: . - naked_identifier: material_number - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: material_number_composition - comma: ',' - select_clause_element: @@ -27,23 +28,26 @@ file: - comma: ',' - expression: - quoted_literal: ''' || ''' - - keyword: ON - - keyword: OVERFLOW - - keyword: ERROR + - listagg_overflow_clause: + - keyword: ON + - keyword: OVERFLOW + - keyword: ERROR + - end_bracket: ) + - withingroup_clause: + - keyword: WITHIN + - keyword: GROUP + - bracketed: + - start_bracket: ( + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: composition + - keyword: ASC - end_bracket: ) - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: composition - - keyword: ASC - - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: composition - from_clause: - keyword: FROM @@ -53,7 +57,8 @@ file: - table_reference: - naked_identifier: article_composition - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: composition - groupby_clause: - keyword: GROUP @@ -85,32 +90,34 @@ file: - expression: - quoted_literal: ''',''' - end_bracket: ) - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: population - - keyword: DESC - - end_bracket: ) - - keyword: FILTER - - bracketed: - - start_bracket: ( - - keyword: WHERE - - expression: - - column_reference: - - naked_identifier: population - - comparison_operator: - - raw_comparison_operator: '>' - - raw_comparison_operator: = - - column_reference: - - naked_identifier: 10_000_000 - - end_bracket: ) + - withingroup_clause: + - keyword: WITHIN + - keyword: GROUP + - bracketed: + - start_bracket: ( + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: population + - keyword: DESC + - end_bracket: ) + - keyword: FILTER + - bracketed: + - start_bracket: ( + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: population + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - column_reference: + - naked_identifier: 10_000_000 + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: megacities - from_clause: - keyword: FROM @@ -177,7 +184,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t - bracketed: - start_bracket: ( @@ -216,23 +224,25 @@ file: - comma: ',' - expression: - quoted_literal: ''',''' - - keyword: ON - - keyword: OVERFLOW - - keyword: TRUNCATE - - quoted_literal: '''.....''' - - keyword: WITH - - keyword: COUNT + - listagg_overflow_clause: + - keyword: ON + - keyword: OVERFLOW + - keyword: TRUNCATE + - quoted_literal: '''.....''' + - keyword: WITH + - keyword: COUNT + - end_bracket: ) + - withingroup_clause: + - keyword: WITHIN + - keyword: GROUP + - bracketed: + - start_bracket: ( + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: value - end_bracket: ) - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: value - - end_bracket: ) - from_clause: - keyword: FROM - from_expression: @@ -252,7 +262,8 @@ file: - quoted_literal: '''c''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t - bracketed: - start_bracket: ( @@ -277,23 +288,25 @@ file: - comma: ',' - expression: - quoted_literal: ''',''' - - keyword: ON - - keyword: OVERFLOW - - keyword: TRUNCATE - - quoted_literal: '''.....''' - - keyword: WITHOUT - - keyword: COUNT + - listagg_overflow_clause: + - keyword: ON + - keyword: OVERFLOW + - keyword: TRUNCATE + - quoted_literal: '''.....''' + - keyword: WITHOUT + - keyword: COUNT + - end_bracket: ) + - withingroup_clause: + - keyword: WITHIN + - keyword: GROUP + - bracketed: + - start_bracket: ( + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: value - end_bracket: ) - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: value - - end_bracket: ) - from_clause: - keyword: FROM - from_expression: @@ -313,7 +326,8 @@ file: - quoted_literal: '''c''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t - bracketed: - start_bracket: ( diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_cast_withtimezone.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_cast_withtimezone.yml index 7dcb8af06..7b0ae48b6 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_cast_withtimezone.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_cast_withtimezone.yml @@ -51,16 +51,18 @@ file: - keyword: AS - data_type: - keyword: TIMESTAMP - - bracketed: - - start_bracket: ( - - numeric_literal: '6' - - end_bracket: ) + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '6' + - end_bracket: ) - keyword: WITH - keyword: TIME - keyword: ZONE - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: _log_time - comma: ',' - from_clause: diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_group_by.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_group_by.yml index 2feb70af7..4a1088ac2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_group_by.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_group_by.yml @@ -23,7 +23,8 @@ file: - naked_identifier: total_count - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: cnt - from_clause: - keyword: from @@ -74,7 +75,8 @@ file: - naked_identifier: total_count - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: cnt - from_clause: - keyword: from @@ -125,7 +127,8 @@ file: - naked_identifier: total_count - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: cnt - from_clause: - keyword: from @@ -176,7 +179,8 @@ file: - naked_identifier: total_count - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: cnt - from_clause: - keyword: from @@ -248,7 +252,8 @@ file: - naked_identifier: total_count - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: cnt - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_map_function.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_map_function.yml index 9213c1223..1adf64147 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_map_function.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_map_function.yml @@ -57,7 +57,8 @@ file: - end_square_bracket: ']' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a_map - end_bracket: ) - select_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_map_type.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_map_type.yml index 76a8ee6b7..d039e7b69 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_map_type.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_map_type.yml @@ -38,7 +38,8 @@ file: - end_angle_bracket: '>' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: json_map - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_row.sql b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_row.sql index 7d911359c..68f6f251f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_row.sql +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_row.sql @@ -18,4 +18,3 @@ SELECT approvalStatus varchar ) ) as test; - diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_row.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_row.yml index 9897d0172..ad3e4c06c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_row.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_row.yml @@ -199,7 +199,7 @@ file: - data_type: - array_type: - keyword: ARRAY - - array_type: + - array_type_schema: - start_angle_bracket: < - data_type: - keyword: ROW @@ -230,6 +230,7 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: test - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_underscore.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_underscore.yml index c9bc0a477..2c4655803 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_underscore.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_underscore.yml @@ -6,7 +6,8 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: _ - statement_terminator: ; - statement: @@ -16,7 +17,8 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: __ - statement_terminator: ; - statement: @@ -26,7 +28,8 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: __TEST - statement_terminator: ; - statement: @@ -60,7 +63,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: _ - bracketed: - start_bracket: ( @@ -99,7 +103,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: __ - bracketed: - start_bracket: ( diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_unnest.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_unnest.yml index a6f3616f6..70b039d78 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_unnest.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_unnest.yml @@ -37,7 +37,8 @@ file: - naked_identifier: array_field - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: my_unnested_table - bracketed: - start_bracket: ( @@ -102,7 +103,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: x - bracketed: - start_bracket: ( @@ -127,7 +129,8 @@ file: - keyword: WITH - keyword: ORDINALITY - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t - bracketed: - start_bracket: ( diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_widow_functions.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_widow_functions.yml index 9daef9849..5a222c48f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_widow_functions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/select_widow_functions.yml @@ -42,7 +42,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rnk - from_clause: - keyword: FROM @@ -109,7 +110,8 @@ file: - naked_identifier: orderdate - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rolling_sum - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/values.yml b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/values.yml index 32a1734d8..6c160296f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/values.yml +++ b/crates/lib-dialects/test/fixtures/dialects/athena/sqlfluff/values.yml @@ -80,7 +80,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t - bracketed: - start_bracket: ( @@ -138,7 +139,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t - bracketed: - start_bracket: ( diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_schema.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_schema.sql new file mode 100644 index 000000000..68eeff9d3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_schema.sql @@ -0,0 +1,11 @@ +ALTER SCHEMA example_dataset +SET DEFAULT COLLATE "und:ci"; + +ALTER SCHEMA example_dataset +SET OPTIONS(description=""); + +ALTER SCHEMA example_dataset +ADD REPLICA `EU` OPTIONS(location=`eu`); + +ALTER SCHEMA example_dataset +DROP REPLICA `EU`; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_schema.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_schema.yml new file mode 100644 index 000000000..1644f4537 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_schema.yml @@ -0,0 +1,62 @@ +file: +- statement: + - alter_schema_statement: + - keyword: ALTER + - keyword: SCHEMA + - table_reference: + - naked_identifier: example_dataset + - keyword: SET + - default_collate: + - keyword: DEFAULT + - keyword: COLLATE + - quoted_literal: '"und:ci"' +- statement_terminator: ; +- statement: + - alter_schema_statement: + - keyword: ALTER + - keyword: SCHEMA + - table_reference: + - naked_identifier: example_dataset + - keyword: SET + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '""' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_schema_statement: + - keyword: ALTER + - keyword: SCHEMA + - table_reference: + - naked_identifier: example_dataset + - keyword: ADD + - keyword: REPLICA + - column_reference: + - quoted_identifier: '`EU`' + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: location + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - quoted_identifier: '`eu`' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_schema_statement: + - keyword: ALTER + - keyword: SCHEMA + - table_reference: + - naked_identifier: example_dataset + - keyword: DROP + - keyword: REPLICA + - column_reference: + - quoted_identifier: '`EU`' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_column.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_column.yml index 855bd4184..deba0562f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_column.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_column.yml @@ -29,7 +29,7 @@ file: - column_definition: - naked_identifier: C - data_type: - - array_type: + - data_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -65,7 +65,7 @@ file: - column_definition: - naked_identifier: A - data_type: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -75,7 +75,7 @@ file: - comma: ',' - parameter: C - data_type: - - array_type: + - data_type: - keyword: ARRAY - start_angle_bracket: < - data_type: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_key.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_key.sql new file mode 100644 index 000000000..4e80168ff --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_key.sql @@ -0,0 +1,11 @@ +ALTER TABLE example_dataset.example_table2 +ADD CONSTRAINT my_fk_name FOREIGN KEY (x) +REFERENCES example_dataset.example_table(x) NOT ENFORCED; + +ALTER TABLE `example_dataset.example_table` +ADD PRIMARY KEY (`x`) NOT ENFORCED; + +ALTER TABLE fk_table +ADD PRIMARY KEY (x,y) NOT ENFORCED, +ADD CONSTRAINT fk FOREIGN KEY (u, v) REFERENCES pk_table(x, y) NOT ENFORCED, +ADD CONSTRAINT `fk2` FOREIGN KEY (`i`, `j`) REFERENCES `pk_table`(`x`, `y`) NOT ENFORCED; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_key.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_key.yml new file mode 100644 index 000000000..6a1a52a40 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_key.yml @@ -0,0 +1,110 @@ +file: +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table2 + - keyword: ADD + - keyword: CONSTRAINT + - naked_identifier: my_fk_name + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - naked_identifier: x + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - bracketed: + - start_bracket: ( + - naked_identifier: x + - end_bracket: ) + - keyword: NOT + - keyword: ENFORCED +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`example_dataset.example_table`' + - keyword: ADD + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - quoted_identifier: '`x`' + - end_bracket: ) + - keyword: NOT + - keyword: ENFORCED +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: fk_table + - keyword: ADD + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - naked_identifier: x + - comma: ',' + - naked_identifier: y + - end_bracket: ) + - keyword: NOT + - keyword: ENFORCED + - comma: ',' + - keyword: ADD + - keyword: CONSTRAINT + - naked_identifier: fk + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - naked_identifier: u + - comma: ',' + - naked_identifier: v + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: pk_table + - bracketed: + - start_bracket: ( + - naked_identifier: x + - comma: ',' + - naked_identifier: y + - end_bracket: ) + - keyword: NOT + - keyword: ENFORCED + - comma: ',' + - keyword: ADD + - keyword: CONSTRAINT + - quoted_identifier: '`fk2`' + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - quoted_identifier: '`i`' + - comma: ',' + - quoted_identifier: '`j`' + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - quoted_identifier: '`pk_table`' + - bracketed: + - start_bracket: ( + - quoted_identifier: '`x`' + - comma: ',' + - quoted_identifier: '`y`' + - end_bracket: ) + - keyword: NOT + - keyword: ENFORCED +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_constraint.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_constraint.sql new file mode 100644 index 000000000..e49ccb630 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_constraint.sql @@ -0,0 +1,5 @@ +ALTER TABLE example_dataset.example_table +DROP CONSTRAINT x; + +ALTER TABLE `example-project.example_dataset.example_table` +DROP CONSTRAINT IF EXISTS x; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_constraint.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_constraint.yml new file mode 100644 index 000000000..30031a448 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_constraint.yml @@ -0,0 +1,25 @@ +file: +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - keyword: DROP + - keyword: CONSTRAINT + - naked_identifier: x +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`example-project.example_dataset.example_table`' + - keyword: DROP + - keyword: CONSTRAINT + - keyword: IF + - keyword: EXISTS + - naked_identifier: x +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_key.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_key.sql new file mode 100644 index 000000000..488045be1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_key.sql @@ -0,0 +1,5 @@ +ALTER TABLE example_dataset.example_table +DROP PRIMARY KEY; + +ALTER TABLE `example-project.example_dataset.example_table` +DROP PRIMARY KEY IF EXISTS; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_key.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_key.yml new file mode 100644 index 000000000..427fb31f5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_drop_key.yml @@ -0,0 +1,25 @@ +file: +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - keyword: DROP + - keyword: PRIMARY + - keyword: KEY +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`example-project.example_dataset.example_table`' + - keyword: DROP + - keyword: PRIMARY + - keyword: KEY + - keyword: IF + - keyword: EXISTS +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_set_default_collate.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_set_default_collate.sql new file mode 100644 index 000000000..e3bcc29bb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_set_default_collate.sql @@ -0,0 +1,2 @@ +ALTER TABLE example_dataset.example_table +SET DEFAULT COLLATE "und:ci"; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_set_default_collate.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_set_default_collate.yml new file mode 100644 index 000000000..8c63b79cc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_set_default_collate.yml @@ -0,0 +1,15 @@ +file: +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - keyword: SET + - default_collate: + - keyword: DEFAULT + - keyword: COLLATE + - quoted_literal: '"und:ci"' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_various_resources.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_various_resources.sql new file mode 100644 index 000000000..3c0c8c29d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_various_resources.sql @@ -0,0 +1,14 @@ +ALTER ORGANIZATION +SET OPTIONS (`region-us.default_time_zone`="Asia/Tokyo"); + +ALTER PROJECT `example-project` +SET OPTIONS (`region-us.default_time_zone`="Asia/Tokyo"); + +ALTER BI_CAPACITY `example-project.region-us.default` +SET OPTIONS(size_gb = 250); + +ALTER CAPACITY `example-project.region-us.example_commitment` +SET OPTIONS (plan = "THREE_YEAR"); + +ALTER RESERVATION `example-project.region-us.example_reservation` +SET OPTIONS (slot_capacity=123); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_various_resources.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_various_resources.yml new file mode 100644 index 000000000..51c468e7f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_various_resources.yml @@ -0,0 +1,84 @@ +file: +- statement: + - alter_organization_statement: + - keyword: ALTER + - keyword: ORGANIZATION + - keyword: SET + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: '`region-us.default_time_zone`' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"Asia/Tokyo"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_project_statement: + - keyword: ALTER + - keyword: PROJECT + - table_reference: + - quoted_identifier: '`example-project`' + - keyword: SET + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: '`region-us.default_time_zone`' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"Asia/Tokyo"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_bi_capacity_statement: + - keyword: ALTER + - keyword: BI_CAPACITY + - table_reference: + - quoted_identifier: '`example-project.region-us.default`' + - keyword: SET + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: size_gb + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '250' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_capacity_statement: + - keyword: ALTER + - keyword: CAPACITY + - table_reference: + - quoted_identifier: '`example-project.region-us.example_commitment`' + - keyword: SET + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: plan + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"THREE_YEAR"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_reservation_statement: + - keyword: ALTER + - keyword: RESERVATION + - table_reference: + - quoted_identifier: '`example-project.region-us.example_reservation`' + - keyword: SET + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: slot_capacity + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '123' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_view_alter_column.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_view_alter_column.sql new file mode 100644 index 000000000..4186045db --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_view_alter_column.sql @@ -0,0 +1,5 @@ +ALTER VIEW example_dataset.example_view +ALTER COLUMN x SET OPTIONS(description="example"); + +ALTER VIEW IF EXISTS `example-project.example_dataset.example_view` +ALTER COLUMN IF EXISTS x SET OPTIONS(description="example"); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_view_alter_column.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_view_alter_column.yml new file mode 100644 index 000000000..fd8d8c2eb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_view_alter_column.yml @@ -0,0 +1,47 @@ +file: +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_view + - keyword: ALTER + - keyword: COLUMN + - naked_identifier: x + - keyword: SET + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"example"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - keyword: IF + - keyword: EXISTS + - table_reference: + - quoted_identifier: '`example-project.example_dataset.example_view`' + - keyword: ALTER + - keyword: COLUMN + - keyword: IF + - keyword: EXISTS + - naked_identifier: x + - keyword: SET + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"example"' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/any_value_having.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/any_value_having.yml index 1d92d539c..0f9e7f412 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/any_value_having.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/any_value_having.yml @@ -20,7 +20,8 @@ file: - naked_identifier: bar - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: any_value_having_min - comma: ',' - select_clause_element: @@ -40,7 +41,8 @@ file: - naked_identifier: bar - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: any_value_having_max - comma: ',' - from_clause: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/array_agg_distinct_ignore_nulls.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/array_agg_distinct_ignore_nulls.yml index 283af86e4..aaf276349 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/array_agg_distinct_ignore_nulls.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/array_agg_distinct_ignore_nulls.yml @@ -18,7 +18,8 @@ file: - keyword: NULLS - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: array_agg - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/array_agg_ignore_nulls.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/array_agg_ignore_nulls.yml index 2c68a0712..42ea680ba 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/array_agg_ignore_nulls.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/array_agg_ignore_nulls.yml @@ -17,7 +17,8 @@ file: - keyword: NULLS - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: array_agg - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/array_agg_respect_nulls.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/array_agg_respect_nulls.yml index cdd3383ea..a1988bff5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/array_agg_respect_nulls.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/array_agg_respect_nulls.yml @@ -17,7 +17,8 @@ file: - keyword: NULLS - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: array_agg - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/assert.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/assert.yml index 671468c8d..4498e7bc8 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/assert.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/assert.yml @@ -95,7 +95,8 @@ file: - end_square_bracket: ']' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: X - where_clause: - keyword: WHERE diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/begin.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/begin.sql new file mode 100644 index 000000000..19b683fbc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/begin.sql @@ -0,0 +1,45 @@ +BEGIN + BEGIN; + + INSERT INTO `my_project.my_dataset.my_table` + SELECT + col1, + col2, + CASE WHEN col1 > col2 THEN False ELSE True END AS col3, + FROM `my_project.my_dataset.my_other_table`; + + COMMIT TRANSACTION; +END; + +BEGIN + BEGIN TRANSACTION; + + INSERT INTO `my_project.my_dataset.my_table` + SELECT + col1, + col2, + CASE WHEN col1 > col2 THEN False ELSE True END AS col3, + FROM `my_project.my_dataset.my_other_table`; + + COMMIT TRANSACTION; +END; + +BEGIN + BEGIN; + + INSERT INTO `my_project.my_dataset.my_table` + SELECT + col1, + col2, + CASE WHEN col1 > col2 THEN 1 ELSE 2 END AS col3, + CASE WHEN x > 5 THEN 5 END; -- case with a statement delimiter after + + COMMIT; +END; + +mylabel: BEGIN + BEGIN; + INSERT INTO `my_project.my_dataset.my_table` + SELECT 1; + COMMIT; +END mylabel; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/begin.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/begin.yml new file mode 100644 index 000000000..2b0822f2d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/begin.yml @@ -0,0 +1,233 @@ +file: +- multi_statement_segment: + - begin_statement: + - keyword: BEGIN + - statement: + - transaction_statement: + - keyword: BEGIN + - statement_terminator: ; + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - quoted_identifier: '`my_project.my_dataset.my_table`' + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - comma: ',' + - select_clause_element: + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: '>' + - column_reference: + - naked_identifier: col2 + - keyword: THEN + - expression: + - boolean_literal: 'False' + - else_clause: + - keyword: ELSE + - expression: + - boolean_literal: 'True' + - keyword: END + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: col3 + - comma: ',' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '`my_project.my_dataset.my_other_table`' + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: COMMIT + - keyword: TRANSACTION + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- multi_statement_segment: + - begin_statement: + - keyword: BEGIN + - statement: + - transaction_statement: + - keyword: BEGIN + - keyword: TRANSACTION + - statement_terminator: ; + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - quoted_identifier: '`my_project.my_dataset.my_table`' + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - comma: ',' + - select_clause_element: + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: '>' + - column_reference: + - naked_identifier: col2 + - keyword: THEN + - expression: + - boolean_literal: 'False' + - else_clause: + - keyword: ELSE + - expression: + - boolean_literal: 'True' + - keyword: END + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: col3 + - comma: ',' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '`my_project.my_dataset.my_other_table`' + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: COMMIT + - keyword: TRANSACTION + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- multi_statement_segment: + - begin_statement: + - keyword: BEGIN + - statement: + - transaction_statement: + - keyword: BEGIN + - statement_terminator: ; + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - quoted_identifier: '`my_project.my_dataset.my_table`' + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - comma: ',' + - select_clause_element: + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: '>' + - column_reference: + - naked_identifier: col2 + - keyword: THEN + - expression: + - numeric_literal: '1' + - else_clause: + - keyword: ELSE + - expression: + - numeric_literal: '2' + - keyword: END + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: col3 + - comma: ',' + - select_clause_element: + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '5' + - keyword: THEN + - expression: + - numeric_literal: '5' + - keyword: END + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: COMMIT + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- multi_statement_segment: + - begin_statement: + - naked_identifier: mylabel + - colon: ':' + - keyword: BEGIN + - statement: + - transaction_statement: + - keyword: BEGIN + - statement_terminator: ; + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - quoted_identifier: '`my_project.my_dataset.my_table`' + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: COMMIT + - statement_terminator: ; + - keyword: END + - naked_identifier: mylabel +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_assignment.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_assignment.sql new file mode 100644 index 000000000..c400b4510 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_assignment.sql @@ -0,0 +1,3 @@ +CREATE ASSIGNMENT +`example_project.region-us.example-reservation.example-assignment` +OPTIONS (assignee = 'projects/my_project', job_type = 'QUERY'); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_assignment.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_assignment.yml new file mode 100644 index 000000000..c4381bcc3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_assignment.yml @@ -0,0 +1,22 @@ +file: +- statement: + - create_assignment_statement: + - keyword: CREATE + - keyword: ASSIGNMENT + - table_reference: + - quoted_identifier: '`example_project.region-us.example-reservation.example-assignment`' + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: assignee + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''projects/my_project''' + - comma: ',' + - parameter: job_type + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''QUERY''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_capacity.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_capacity.sql new file mode 100644 index 000000000..81580d9fe --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_capacity.sql @@ -0,0 +1,3 @@ +CREATE CAPACITY +`example_project.region-us.example-commitment` +OPTIONS (slot_count=123); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_capacity.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_capacity.yml new file mode 100644 index 000000000..2441cb771 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_capacity.yml @@ -0,0 +1,17 @@ +file: +- statement: + - create_capacity_statement: + - keyword: CREATE + - keyword: CAPACITY + - table_reference: + - quoted_identifier: '`example_project.region-us.example-commitment`' + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: slot_count + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '123' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_external_table.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_external_table.sql index fd58e21c5..4c588a086 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_external_table.sql +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_external_table.sql @@ -34,7 +34,7 @@ OPTIONS ( hive_partition_uri_prefix='gs://bucket/path' ); --- Test arbritary ordering of optional arguments +-- Test arbitary ordering of optional arguments CREATE EXTERNAL TABLE dataset.CustomHivePartitionedTable OPTIONS ( uris=['gs://bucket/path/*'], diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_no_args.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_no_args.sql index 6c7d07d33..4ead46aeb 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_no_args.sql +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_no_args.sql @@ -2,4 +2,13 @@ CREATE FUNCTION add() RETURNS integer AS 'select $1 + $2;' LANGUAGE SQL; -DROP FUNCTION myproject.mydataset.addfunc; +CREATE FUNCTION example_dataset.exampleFunction() RETURNS STRING +AS ("example") +OPTIONS(description="example"); + +CREATE TEMP FUNCTION exampleFunction() RETURNS FLOAT64 +AS (1.234 * 5.678); + +CREATE TEMPORARY FUNCTION exampleFunction() RETURNS BOOL +AS (TRUE) +OPTIONS(); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_no_args.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_no_args.yml index 751ed8183..775d19359 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_no_args.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_no_args.yml @@ -19,13 +19,85 @@ file: - naked_identifier: SQL - statement_terminator: ; - statement: - - drop_function_statement: - - keyword: DROP + - create_function_statement: + - keyword: CREATE - keyword: FUNCTION - function_name: - - naked_identifier: myproject - - dot: . - - naked_identifier: mydataset + - naked_identifier: example_dataset - dot: . - - function_name_identifier: addfunc + - function_name_identifier: exampleFunction + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: STRING + - function_definition: + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '"example"' + - end_bracket: ) + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"example"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: TEMP + - keyword: FUNCTION + - function_name: + - function_name_identifier: exampleFunction + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: FLOAT64 + - function_definition: + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1.234' + - binary_operator: '*' + - numeric_literal: '5.678' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: TEMPORARY + - keyword: FUNCTION + - function_name: + - function_name_identifier: exampleFunction + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: BOOL + - function_definition: + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - boolean_literal: 'TRUE' + - end_bracket: ) + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_with_args.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_with_args.sql new file mode 100644 index 000000000..e53d008a4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_with_args.sql @@ -0,0 +1,16 @@ +CREATE FUNCTION example_dataset.exampleFunction(x FLOAT64) +RETURNS FLOAT64 +AS (x * x); + +CREATE OR REPLACE FUNCTION `example-project.example_dataset.exampleFunction`(x INTEGER, y INTEGER) +RETURNS INTEGER +AS (x * y) +OPTIONS(description="foo"); + +CREATE TEMPORARY FUNCTION exampleFunction(x BIGNUMERIC) +AS (x + x); + +CREATE TEMP FUNCTION exampleFunction(x STRING) +RETURNS STRING +AS (CONCAT(x, x)) +OPTIONS(); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_with_args.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_with_args.yml new file mode 100644 index 000000000..68d51e3ac --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_function_with_args.yml @@ -0,0 +1,143 @@ +file: +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - naked_identifier: example_dataset + - dot: . + - function_name_identifier: exampleFunction + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: x + - data_type: + - data_type_identifier: FLOAT64 + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: FLOAT64 + - function_definition: + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - binary_operator: '*' + - column_reference: + - naked_identifier: x + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: FUNCTION + - function_name: + - function_name_identifier: '`example-project.example_dataset.exampleFunction`' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: x + - data_type: + - data_type_identifier: INTEGER + - comma: ',' + - parameter: y + - data_type: + - data_type_identifier: INTEGER + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: INTEGER + - function_definition: + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - binary_operator: '*' + - column_reference: + - naked_identifier: y + - end_bracket: ) + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"foo"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: TEMPORARY + - keyword: FUNCTION + - function_name: + - function_name_identifier: exampleFunction + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: x + - data_type: + - data_type_identifier: BIGNUMERIC + - end_bracket: ) + - function_definition: + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - binary_operator: + + - column_reference: + - naked_identifier: x + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: TEMP + - keyword: FUNCTION + - function_name: + - function_name_identifier: exampleFunction + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: x + - data_type: + - data_type_identifier: STRING + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: STRING + - function_definition: + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: CONCAT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - comma: ',' + - expression: + - column_reference: + - naked_identifier: x + - end_bracket: ) + - end_bracket: ) + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_index.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_index.sql new file mode 100644 index 000000000..8bca230ca --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_index.sql @@ -0,0 +1,15 @@ +CREATE SEARCH INDEX my_index +ON example_dataset.example_table(ALL COLUMNS); + +CREATE SEARCH INDEX IF NOT EXISTS my_index +ON example_dataset.example_table(x, y, z) +OPTIONS (analyzer = 'NO_OP_ANALYZER'); + +CREATE VECTOR INDEX my_index +ON example_dataset.example_table(example_column) +STORING(stored_column1, stored_column2) +OPTIONS(index_type = 'IVF'); + +CREATE OR REPLACE VECTOR INDEX IF NOT EXISTS my_index +ON example_dataset.example_table(x, y, z) +OPTIONS(index_type = 'IVF', distance_type = 'COSINE'); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_index.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_index.yml new file mode 100644 index 000000000..4f52f176c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_index.yml @@ -0,0 +1,133 @@ +file: +- statement: + - create_search_index_statement: + - keyword: CREATE + - keyword: SEARCH + - keyword: INDEX + - index_reference: + - naked_identifier: my_index + - keyword: ON + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - bracketed: + - start_bracket: ( + - keyword: ALL + - keyword: COLUMNS + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_search_index_statement: + - keyword: CREATE + - keyword: SEARCH + - keyword: INDEX + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - index_reference: + - naked_identifier: my_index + - keyword: ON + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: x + - comma: ',' + - index_column_definition: + - naked_identifier: y + - comma: ',' + - index_column_definition: + - naked_identifier: z + - end_bracket: ) + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: analyzer + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''NO_OP_ANALYZER''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_vector_index_statement: + - keyword: CREATE + - keyword: VECTOR + - keyword: INDEX + - index_reference: + - naked_identifier: my_index + - keyword: ON + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: example_column + - end_bracket: ) + - storing_segment: + - keyword: STORING + - bracketed: + - start_bracket: ( + - naked_identifier: stored_column1 + - comma: ',' + - naked_identifier: stored_column2 + - end_bracket: ) + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: index_type + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''IVF''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_vector_index_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: VECTOR + - keyword: INDEX + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - index_reference: + - naked_identifier: my_index + - keyword: ON + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: x + - comma: ',' + - index_column_definition: + - naked_identifier: y + - comma: ',' + - index_column_definition: + - naked_identifier: z + - end_bracket: ) + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: index_type + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''IVF''' + - comma: ',' + - parameter: distance_type + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''COSINE''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_complex_types.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_complex_types.sql index 29b1493c0..f82ba09c2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_complex_types.sql +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_complex_types.sql @@ -4,7 +4,7 @@ qs( foo2 ARRAY, foo3 STRUCT, foo4 STRUCT, - foo5 STRUCT, b STRUCT> + foo5 STRUCT, b STRUCT> ) RETURNS STRUCT> LANGUAGE js AS """ diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_complex_types.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_complex_types.yml index 81b624af7..509b17175 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_complex_types.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_complex_types.yml @@ -15,7 +15,7 @@ file: - comma: ',' - parameter: foo2 - data_type: - - array_type: + - data_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -24,7 +24,7 @@ file: - comma: ',' - parameter: foo3 - data_type: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -35,7 +35,7 @@ file: - comma: ',' - parameter: foo4 - data_type: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -50,22 +50,22 @@ file: - comma: ',' - parameter: foo5 - data_type: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < - parameter: a - data_type: - - array_type: + - data_type: - keyword: ARRAY - start_angle_bracket: < - data_type: - - data_type_identifier: FLOAT + - data_type_identifier: FLOAT64 - end_angle_bracket: '>' - comma: ',' - parameter: b - data_type: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -81,13 +81,13 @@ file: - end_bracket: ) - keyword: RETURNS - data_type: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < - parameter: product_id - data_type: - - array_type: + - data_type: - keyword: ARRAY - start_angle_bracket: < - data_type: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_options_library_array.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_options_library_array.yml index 127571feb..79b6d7b6e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_options_library_array.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_options_library_array.yml @@ -15,11 +15,11 @@ file: - end_bracket: ) - keyword: RETURNS - data_type: - - array_type: + - data_type: - keyword: ARRAY - start_angle_bracket: < - data_type: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_quoted_name.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_quoted_name.yml index d67cfeda2..1e533240c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_quoted_name.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_quoted_name.yml @@ -15,13 +15,13 @@ file: - end_bracket: ) - keyword: RETURNS - data_type: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < - parameter: '`$=`' - data_type: - - array_type: + - data_type: - keyword: ARRAY - start_angle_bracket: < - data_type: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_underscore_name.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_underscore_name.yml index 215607b6f..a026efa69 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_underscore_name.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_underscore_name.yml @@ -15,13 +15,13 @@ file: - end_bracket: ) - keyword: RETURNS - data_type: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < - parameter: _product_id - data_type: - - array_type: + - data_type: - keyword: ARRAY - start_angle_bracket: < - data_type: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_materialized_view_as_replica_of.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_materialized_view_as_replica_of.sql new file mode 100644 index 000000000..1480ddfd5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_materialized_view_as_replica_of.sql @@ -0,0 +1,6 @@ +CREATE MATERIALIZED VIEW mydataset.my_mv +AS REPLICA OF mydataset.my_original_mv; + +CREATE MATERIALIZED VIEW my-project.mydataset.my_mv +OPTIONS(replication_interval_seconds=900) +AS REPLICA OF my-project.mydataset.my_original_mv; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_materialized_view_as_replica_of.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_materialized_view_as_replica_of.yml new file mode 100644 index 000000000..a403805b0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_materialized_view_as_replica_of.yml @@ -0,0 +1,52 @@ +file: +- statement: + - create_materialized_view_as_replica_of_statement: + - keyword: CREATE + - keyword: MATERIALIZED + - keyword: VIEW + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: my_mv + - keyword: AS + - keyword: REPLICA + - keyword: OF + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: my_original_mv +- statement_terminator: ; +- statement: + - create_materialized_view_as_replica_of_statement: + - keyword: CREATE + - keyword: MATERIALIZED + - keyword: VIEW + - table_reference: + - naked_identifier: my + - dash: '-' + - naked_identifier: project + - dot: . + - naked_identifier: mydataset + - dot: . + - naked_identifier: my_mv + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: replication_interval_seconds + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '900' + - end_bracket: ) + - keyword: AS + - keyword: REPLICA + - keyword: OF + - table_reference: + - naked_identifier: my + - dash: '-' + - naked_identifier: project + - dot: . + - naked_identifier: mydataset + - dot: . + - naked_identifier: my_original_mv +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_procedure.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_procedure.sql index ff3aa37df..5cc7f54ab 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_procedure.sql +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_procedure.sql @@ -65,3 +65,149 @@ RAISE; RAISE USING MESSAGE = "Test"; RAISE USING MESSAGE = error_message; END; + +CREATE OR REPLACE PROCEDURE place_name.proc_name +( + _log STRUCT< + Process_ID STRING, + Debug INT64 + > +) + +BEGIN + +-- Declaration + + DECLARE _source_table STRING; + + CREATE OR REPLACE TEMP TABLE _session.__calendar_target_buffer + ( + some_id INT64 + ); + + --try + BEGIN + + SET _metric_id = 1001; + + -- define metric details + CALL some_place.some_name1 ( + _some_id + ); + + --end try + END; +END; + +CREATE OR REPLACE PROCEDURE place_name.proc_name +( + _log STRUCT< + Process_ID STRING, + Debug INT64 + > +) + +BEGIN + +-- Declaration + + DECLARE _source_table STRING; + + CREATE OR REPLACE TEMP TABLE _session.__calendar_target_buffer + ( + some_id INT64 + ); + + --try + BEGIN + + SET _metric_id = 1001; + + -- define metric details + CALL some_place.some_name1 ( + _some_id + ); + + FOR x IN + ( + SELECT 1 + ) + DO + FOR y IN + ( + SELECT x + ) + DO + BEGIN; + SELECT y; + COMMIT TRANSACTION; + END FOR; + END FOR; + + --end try + END; +END; + +CREATE OR REPLACE PROCEDURE place_name.proc_name +( + _log STRUCT< + Process_ID STRING, + Debug INT64 + > +) +OPTIONS +( + strict_mode = TRUE, + description = +''' +Author: +''' +) +BEGIN + +-- Declaration + + DECLARE _source_table STRING; + + CREATE OR REPLACE TEMP TABLE _session.__calendar_target_buffer + ( + some_id INT64 + ); + + --try + BEGIN + + -- Initialization: + + SET _metric_id = 1001; + -- define metric details + CALL some_place.some_name1 ( + _some_id + ); + + EXCEPTION WHEN ERROR THEN + RAISE; + --end try + END; +END; + +CREATE +OR REPLACE PROCEDURE `kkk.dynamic_table_creator` ( + IN table_suffix STRING, IN num_rows INT64 +) +BEGIN + DECLARE table_name STRING; + + SET + table_name = 'my_table_' || table_suffix; + + EXECUTE IMMEDIATE ''' + CREATE OR REPLACE TABLE `my_dataset.''' || table_name || '''` AS + SELECT + GENERATE_UUID() AS id, + RAND() AS random_value + FROM + UNNEST(GENERATE_ARRAY(1, ''' || num_rows || ''')) AS num + '''; + +END; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_procedure.yml index 7b4bd6c81..748fa9907 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_procedure.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_procedure.yml @@ -14,8 +14,8 @@ file: - data_type: - data_type_identifier: INT64 - end_bracket: ) - - keyword: BEGIN - - procedure_statements: + - begin_statement: + - keyword: BEGIN - statement: - select_statement: - select_clause: @@ -29,7 +29,7 @@ file: - start_bracket: ( - end_bracket: ) - statement_terminator: ; - - keyword: END + - keyword: END - statement_terminator: ; - multi_statement_segment: - create_procedure_statement: @@ -45,8 +45,8 @@ file: - bracketed: - start_bracket: ( - end_bracket: ) - - keyword: BEGIN - - procedure_statements: + - begin_statement: + - keyword: BEGIN - statement: - select_statement: - select_clause: @@ -65,7 +65,7 @@ file: - dot: . - naked_identifier: myTable - statement_terminator: ; - - keyword: END + - keyword: END - statement_terminator: ; - multi_statement_segment: - create_procedure_statement: @@ -87,8 +87,8 @@ file: - data_type: - data_type_identifier: INT64 - end_bracket: ) - - keyword: BEGIN - - procedure_statements: + - begin_statement: + - keyword: BEGIN - statement: - set_segment: - keyword: SET @@ -102,7 +102,7 @@ file: - column_reference: - naked_identifier: delta - statement_terminator: ; - - keyword: END + - keyword: END - statement_terminator: ; - multi_statement_segment: - create_procedure_statement: @@ -124,8 +124,8 @@ file: - data_type: - data_type_identifier: INT64 - end_bracket: ) - - keyword: BEGIN - - procedure_statements: + - begin_statement: + - keyword: BEGIN - statement: - create_table_statement: - keyword: CREATE @@ -164,7 +164,8 @@ file: - dot: . - naked_identifier: partitioned_table1 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t1 - join_clause: - keyword: JOIN @@ -175,7 +176,8 @@ file: - dot: . - naked_identifier: partitioned_table2 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t2 - join_on_condition: - keyword: ON @@ -274,7 +276,7 @@ file: - table_reference: - naked_identifier: DataForTargetDate - statement_terminator: ; - - keyword: END + - keyword: END - statement_terminator: ; - multi_statement_segment: - create_procedure_statement: @@ -290,8 +292,8 @@ file: - bracketed: - start_bracket: ( - end_bracket: ) - - keyword: BEGIN - - procedure_statements: + - begin_statement: + - keyword: BEGIN - statement: - declare_segment: - keyword: DECLARE @@ -354,7 +356,7 @@ file: - naked_identifier: id - end_bracket: ) - statement_terminator: ; - - keyword: END + - keyword: END - statement_terminator: ; - multi_statement_segment: - create_procedure_statement: @@ -373,8 +375,8 @@ file: - data_type: - data_type_identifier: STRING - end_bracket: ) - - keyword: BEGIN - - procedure_statements: + - begin_statement: + - keyword: BEGIN - statement: - declare_segment: - keyword: DECLARE @@ -448,7 +450,7 @@ file: - naked_identifier: name - end_bracket: ) - statement_terminator: ; - - keyword: END + - keyword: END - statement_terminator: ; - multi_statement_segment: - create_procedure_statement: @@ -472,8 +474,8 @@ file: - data_type: - data_type_identifier: STRING - end_bracket: ) - - keyword: BEGIN - - procedure_statements: + - begin_statement: + - keyword: BEGIN - statement: - set_segment: - keyword: SET @@ -540,7 +542,7 @@ file: - naked_identifier: name - end_bracket: ) - statement_terminator: ; - - keyword: END + - keyword: END - statement_terminator: ; - multi_statement_segment: - create_procedure_statement: @@ -559,8 +561,8 @@ file: - data_type: - data_type_identifier: STRING - end_bracket: ) - - keyword: BEGIN - - procedure_statements: + - begin_statement: + - keyword: BEGIN - statement: - return_statement: - keyword: RETURN @@ -590,5 +592,420 @@ file: - column_reference: - naked_identifier: error_message - statement_terminator: ; - - keyword: END + - keyword: END +- statement_terminator: ; +- multi_statement_segment: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: PROCEDURE + - procedure_name: + - naked_identifier: place_name + - dot: . + - procedure_name_identifier: proc_name + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: _log + - data_type: + - data_type: + - keyword: STRUCT + - struct_type_schema: + - start_angle_bracket: < + - parameter: Process_ID + - data_type: + - data_type_identifier: STRING + - comma: ',' + - parameter: Debug + - data_type: + - data_type_identifier: INT64 + - end_angle_bracket: '>' + - end_bracket: ) + - begin_statement: + - keyword: BEGIN + - statement: + - declare_segment: + - keyword: DECLARE + - naked_identifier: _source_table + - data_type: + - data_type_identifier: STRING + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: TEMP + - keyword: TABLE + - table_reference: + - naked_identifier: _session + - dot: . + - naked_identifier: __calendar_target_buffer + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: some_id + - data_type: + - data_type_identifier: INT64 + - end_bracket: ) + - statement_terminator: ; + - multi_statement_segment: + - begin_statement: + - keyword: BEGIN + - statement: + - set_segment: + - keyword: SET + - naked_identifier: _metric_id + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1001' + - statement_terminator: ; + - statement: + - call_statement: + - keyword: CALL + - procedure_name: + - naked_identifier: some_place + - dot: . + - procedure_name_identifier: some_name1 + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: _some_id + - end_bracket: ) + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- multi_statement_segment: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: PROCEDURE + - procedure_name: + - naked_identifier: place_name + - dot: . + - procedure_name_identifier: proc_name + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: _log + - data_type: + - data_type: + - keyword: STRUCT + - struct_type_schema: + - start_angle_bracket: < + - parameter: Process_ID + - data_type: + - data_type_identifier: STRING + - comma: ',' + - parameter: Debug + - data_type: + - data_type_identifier: INT64 + - end_angle_bracket: '>' + - end_bracket: ) + - begin_statement: + - keyword: BEGIN + - statement: + - declare_segment: + - keyword: DECLARE + - naked_identifier: _source_table + - data_type: + - data_type_identifier: STRING + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: TEMP + - keyword: TABLE + - table_reference: + - naked_identifier: _session + - dot: . + - naked_identifier: __calendar_target_buffer + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: some_id + - data_type: + - data_type_identifier: INT64 + - end_bracket: ) + - statement_terminator: ; + - multi_statement_segment: + - begin_statement: + - keyword: BEGIN + - statement: + - set_segment: + - keyword: SET + - naked_identifier: _metric_id + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1001' + - statement_terminator: ; + - statement: + - call_statement: + - keyword: CALL + - procedure_name: + - naked_identifier: some_place + - dot: . + - procedure_name_identifier: some_name1 + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: _some_id + - end_bracket: ) + - statement_terminator: ; + - multi_statement_segment: + - for_in_statement: + - keyword: FOR + - naked_identifier: x + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - end_bracket: ) + - keyword: DO + - for_in_statements: + - multi_statement_segment: + - for_in_statement: + - keyword: FOR + - naked_identifier: y + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: x + - end_bracket: ) + - keyword: DO + - for_in_statements: + - statement: + - transaction_statement: + - keyword: BEGIN + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: y + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: COMMIT + - keyword: TRANSACTION + - statement_terminator: ; + - keyword: END + - keyword: FOR + - statement_terminator: ; + - keyword: END + - keyword: FOR + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- multi_statement_segment: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: PROCEDURE + - procedure_name: + - naked_identifier: place_name + - dot: . + - procedure_name_identifier: proc_name + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: _log + - data_type: + - data_type: + - keyword: STRUCT + - struct_type_schema: + - start_angle_bracket: < + - parameter: Process_ID + - data_type: + - data_type_identifier: STRING + - comma: ',' + - parameter: Debug + - data_type: + - data_type_identifier: INT64 + - end_angle_bracket: '>' + - end_bracket: ) + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: strict_mode + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - comma: ',' + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: |- + ''' + Author: + ''' + - end_bracket: ) + - begin_statement: + - keyword: BEGIN + - statement: + - declare_segment: + - keyword: DECLARE + - naked_identifier: _source_table + - data_type: + - data_type_identifier: STRING + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: TEMP + - keyword: TABLE + - table_reference: + - naked_identifier: _session + - dot: . + - naked_identifier: __calendar_target_buffer + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: some_id + - data_type: + - data_type_identifier: INT64 + - end_bracket: ) + - statement_terminator: ; + - multi_statement_segment: + - begin_statement: + - keyword: BEGIN + - statement: + - set_segment: + - keyword: SET + - naked_identifier: _metric_id + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1001' + - statement_terminator: ; + - statement: + - call_statement: + - keyword: CALL + - procedure_name: + - naked_identifier: some_place + - dot: . + - procedure_name_identifier: some_name1 + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: _some_id + - end_bracket: ) + - statement_terminator: ; + - keyword: EXCEPTION + - keyword: WHEN + - keyword: ERROR + - keyword: THEN + - statement: + - raise_statement: + - keyword: RAISE + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- multi_statement_segment: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: PROCEDURE + - procedure_name: + - procedure_name_identifier: '`kkk.dynamic_table_creator`' + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - keyword: IN + - parameter: table_suffix + - data_type: + - data_type_identifier: STRING + - comma: ',' + - keyword: IN + - parameter: num_rows + - data_type: + - data_type_identifier: INT64 + - end_bracket: ) + - begin_statement: + - keyword: BEGIN + - statement: + - declare_segment: + - keyword: DECLARE + - naked_identifier: table_name + - data_type: + - data_type_identifier: STRING + - statement_terminator: ; + - statement: + - set_segment: + - keyword: SET + - naked_identifier: table_name + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''my_table_''' + - binary_operator: + - pipe: '|' + - pipe: '|' + - column_reference: + - naked_identifier: table_suffix + - statement_terminator: ; + - statement: + - execute_immediate: + - keyword: EXECUTE + - keyword: IMMEDIATE + - expression: + - quoted_literal: |- + ''' + CREATE OR REPLACE TABLE `my_dataset.''' + - binary_operator: + - pipe: '|' + - pipe: '|' + - column_reference: + - naked_identifier: table_name + - binary_operator: + - pipe: '|' + - pipe: '|' + - quoted_literal: |- + '''` AS + SELECT + GENERATE_UUID() AS id, + RAND() AS random_value + FROM + UNNEST(GENERATE_ARRAY(1, ''' + - binary_operator: + - pipe: '|' + - pipe: '|' + - column_reference: + - naked_identifier: num_rows + - binary_operator: + - pipe: '|' + - pipe: '|' + - quoted_literal: |- + ''')) AS num + ''' + - statement_terminator: ; + - keyword: END - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_reservation.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_reservation.sql new file mode 100644 index 000000000..4b46d215e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_reservation.sql @@ -0,0 +1,3 @@ +CREATE RESERVATION +`example_project.region-us.example-reservation` +OPTIONS (slot_capacity=123); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_reservation.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_reservation.yml new file mode 100644 index 000000000..15ccc343f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_reservation.yml @@ -0,0 +1,17 @@ +file: +- statement: + - create_reservation_statement: + - keyword: CREATE + - keyword: RESERVATION + - table_reference: + - quoted_identifier: '`example_project.region-us.example-reservation`' + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: slot_capacity + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '123' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_row_access_policy.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_row_access_policy.sql new file mode 100644 index 000000000..e711133d3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_row_access_policy.sql @@ -0,0 +1,27 @@ +CREATE ROW ACCESS POLICY +row_access_policy_name ON example_dataset.example_table +FILTER USING (TRUE); + +CREATE OR REPLACE ROW ACCESS POLICY +row_access_policy_name ON example_dataset.example_table +GRANT TO ("user:someone@example.com") +FILTER USING (x = y); + +CREATE ROW ACCESS POLICY IF NOT EXISTS +row_access_policy_name ON example_dataset.example_table +GRANT TO ( + "serviceAccount:example@example-project.iam.gserviceaccount.com", + "group:some_group@example.com", + "domain:example.com" +) +FILTER USING (email_column_name = SESSION_USER()); + +CREATE OR REPLACE ROW ACCESS POLICY IF NOT EXISTS +row_access_policy_name ON example_dataset.example_table +GRANT TO ("allAuthenticatedUsers") +FILTER USING (SESSION_USER() IN ("foo", "bar")); + +CREATE ROW ACCESS POLICY +row_access_policy_name ON example_dataset.example_table +GRANT TO ("allUsers") +FILTER USING (example_dataset.exampleFunction(x, y)); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_row_access_policy.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_row_access_policy.yml new file mode 100644 index 000000000..bda390f49 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_row_access_policy.yml @@ -0,0 +1,186 @@ +file: +- statement: + - create_row_access_policy_statement: + - keyword: CREATE + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - naked_identifier: row_access_policy_name + - keyword: ON + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - keyword: FILTER + - keyword: USING + - bracketed: + - start_bracket: ( + - expression: + - boolean_literal: 'TRUE' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_row_access_policy_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - naked_identifier: row_access_policy_name + - keyword: ON + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - grant_to_segment: + - keyword: GRANT + - keyword: TO + - bracketed: + - start_bracket: ( + - quoted_literal: '"user:someone@example.com"' + - end_bracket: ) + - keyword: FILTER + - keyword: USING + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: y + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_row_access_policy_statement: + - keyword: CREATE + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - naked_identifier: row_access_policy_name + - keyword: ON + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - grant_to_segment: + - keyword: GRANT + - keyword: TO + - bracketed: + - start_bracket: ( + - quoted_literal: '"serviceAccount:example@example-project.iam.gserviceaccount.com"' + - comma: ',' + - quoted_literal: '"group:some_group@example.com"' + - comma: ',' + - quoted_literal: '"domain:example.com"' + - end_bracket: ) + - keyword: FILTER + - keyword: USING + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: email_column_name + - comparison_operator: + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: SESSION_USER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_row_access_policy_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - naked_identifier: row_access_policy_name + - keyword: ON + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - grant_to_segment: + - keyword: GRANT + - keyword: TO + - bracketed: + - start_bracket: ( + - quoted_literal: '"allAuthenticatedUsers"' + - end_bracket: ) + - keyword: FILTER + - keyword: USING + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: SESSION_USER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: IN + - bracketed: + - start_bracket: ( + - quoted_literal: '"foo"' + - comma: ',' + - quoted_literal: '"bar"' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_row_access_policy_statement: + - keyword: CREATE + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - naked_identifier: row_access_policy_name + - keyword: ON + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - grant_to_segment: + - keyword: GRANT + - keyword: TO + - bracketed: + - start_bracket: ( + - quoted_literal: '"allUsers"' + - end_bracket: ) + - keyword: FILTER + - keyword: USING + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - naked_identifier: example_dataset + - dot: . + - function_name_identifier: exampleFunction + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - comma: ',' + - expression: + - column_reference: + - naked_identifier: y + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_schema.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_schema.sql new file mode 100644 index 000000000..489b25e63 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_schema.sql @@ -0,0 +1,5 @@ +CREATE SCHEMA dataset_name; + +CREATE SCHEMA IF NOT EXISTS project_name.dataset_name +DEFAULT COLLATE 'und:ci' +OPTIONS(description="example"); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_schema.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_schema.yml new file mode 100644 index 000000000..9a0b343e3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_schema.yml @@ -0,0 +1,33 @@ +file: +- statement: + - create_schema_statement: + - keyword: CREATE + - keyword: SCHEMA + - table_reference: + - naked_identifier: dataset_name +- statement_terminator: ; +- statement: + - create_schema_statement: + - keyword: CREATE + - keyword: SCHEMA + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: project_name + - dot: . + - naked_identifier: dataset_name + - default_collate: + - keyword: DEFAULT + - keyword: COLLATE + - quoted_literal: '''und:ci''' + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"example"' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_snapshot_table.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_snapshot_table.sql new file mode 100644 index 000000000..827456fd8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_snapshot_table.sql @@ -0,0 +1,12 @@ +CREATE SNAPSHOT TABLE `example-project.example_dataset.example_table_snapshot_20240101` +CLONE `example-project.example_dataset.example_table`; + +CREATE SNAPSHOT TABLE IF NOT EXISTS `example-project.example_dataset.example_table_snapshot_20240101` +CLONE `example-project.example_dataset.example_table` +FOR SYSTEM_TIME AS OF TIMESTAMP("2024-01-01 12:00:00") +OPTIONS ( + expiration_timestamp=TIMESTAMP("2024-02-01 12:00:00"), + friendly_name="my_table_snapshot", + description="example description", + labels=[("example_key", "example_value")] +); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_snapshot_table.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_snapshot_table.yml new file mode 100644 index 000000000..68ed72d3f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_snapshot_table.yml @@ -0,0 +1,82 @@ +file: +- statement: + - create_snapshot_table_statement: + - keyword: CREATE + - keyword: SNAPSHOT + - keyword: TABLE + - table_reference: + - quoted_identifier: '`example-project.example_dataset.example_table_snapshot_20240101`' + - keyword: CLONE + - table_reference: + - quoted_identifier: '`example-project.example_dataset.example_table`' +- statement_terminator: ; +- statement: + - create_snapshot_table_statement: + - keyword: CREATE + - keyword: SNAPSHOT + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - quoted_identifier: '`example-project.example_dataset.example_table_snapshot_20240101`' + - keyword: CLONE + - table_reference: + - quoted_identifier: '`example-project.example_dataset.example_table`' + - for_system_time_as_of_segment: + - keyword: FOR + - keyword: SYSTEM_TIME + - keyword: AS + - keyword: OF + - expression: + - function: + - function_name: + - function_name_identifier: TIMESTAMP + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '"2024-01-01 12:00:00"' + - end_bracket: ) + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: expiration_timestamp + - comparison_operator: + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: TIMESTAMP + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '"2024-02-01 12:00:00"' + - end_bracket: ) + - comma: ',' + - parameter: friendly_name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"my_table_snapshot"' + - comma: ',' + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"example description"' + - comma: ',' + - parameter: labels + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - expression: + - bracketed: + - start_bracket: ( + - quoted_literal: '"example_key"' + - comma: ',' + - quoted_literal: '"example_value"' + - end_bracket: ) + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_column_options.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_column_options.yml index 9504581eb..5ec47adb6 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_column_options.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_column_options.yml @@ -59,7 +59,7 @@ file: - column_definition: - naked_identifier: x - data_type: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -80,11 +80,11 @@ file: - column_definition: - naked_identifier: y - data_type: - - array_type: + - data_type: - keyword: ARRAY - start_angle_bracket: < - data_type: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_default_collate.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_default_collate.sql new file mode 100644 index 000000000..5751bb9c2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_default_collate.sql @@ -0,0 +1,13 @@ +CREATE TABLE example_dataset.example_table +(x INT64) +DEFAULT COLLATE 'und:ci'; + +CREATE OR REPLACE TABLE +example-project.example_dataset.example_table +( + x INT64 OPTIONS(description="example"), + y INT64 OPTIONS(description="example") +) +DEFAULT COLLATE 'und:ci' +CLUSTER BY x, y +OPTIONS(description="example"); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_default_collate.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_default_collate.yml new file mode 100644 index 000000000..8abc3fe61 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_default_collate.yml @@ -0,0 +1,89 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: x + - data_type: + - data_type_identifier: INT64 + - end_bracket: ) + - default_collate: + - keyword: DEFAULT + - keyword: COLLATE + - quoted_literal: '''und:ci''' +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: TABLE + - table_reference: + - naked_identifier: example + - dash: '-' + - naked_identifier: project + - dot: . + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: x + - data_type: + - data_type_identifier: INT64 + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"example"' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: y + - data_type: + - data_type_identifier: INT64 + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"example"' + - end_bracket: ) + - end_bracket: ) + - default_collate: + - keyword: DEFAULT + - keyword: COLLATE + - quoted_literal: '''und:ci''' + - cluster_by_segment: + - keyword: CLUSTER + - keyword: BY + - expression: + - column_reference: + - naked_identifier: x + - comma: ',' + - expression: + - column_reference: + - naked_identifier: y + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"example"' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_function.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_function.sql new file mode 100644 index 000000000..582ad5eb8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_function.sql @@ -0,0 +1,9 @@ +-- From BigQuery Docs: +-- https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_table_function_statement +CREATE OR REPLACE TABLE FUNCTION mydataset.names_by_year(y INT64) +RETURNS TABLE +AS + SELECT year, name, SUM(number) AS total + FROM `bigquery-public-data.usa_names.usa_1910_current` + WHERE year = y + GROUP BY year, name diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_function.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_function.yml new file mode 100644 index 000000000..99e96b07e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_function.yml @@ -0,0 +1,85 @@ +file: +- statement: + - create_table_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: TABLE + - keyword: FUNCTION + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: names_by_year + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: y + - data_type: + - data_type_identifier: INT64 + - end_bracket: ) + - keyword: RETURNS + - keyword: TABLE + - start_angle_bracket: < + - parameter: name + - data_type: + - data_type_identifier: STRING + - comma: ',' + - parameter: year + - data_type: + - data_type_identifier: INT64 + - comma: ',' + - parameter: total + - data_type: + - data_type_identifier: INT64 + - end_angle_bracket: '>' + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: year + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: name + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: number + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: total + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '`bigquery-public-data.usa_names.usa_1910_current`' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: year + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: y + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: year + - comma: ',' + - column_reference: + - naked_identifier: name diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_keys.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_keys.sql new file mode 100644 index 000000000..d73217583 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_keys.sql @@ -0,0 +1,26 @@ +CREATE TABLE t_table1 +( + x INT64, + PRIMARY KEY (x) NOT ENFORCED +) +; +CREATE TABLE t_table1 +( + y STRING, + FOREIGN KEY (y) REFERENCES t_table2(y) NOT ENFORCED, +) +; +CREATE TABLE t_table1 +( + x INT64, + PRIMARY KEY (x) NOT ENFORCED, + y STRING, + FOREIGN KEY (y) REFERENCES t_table2(y) NOT ENFORCED, + _other STRING +) +; + +CREATE TABLE `some_dataset.some_table` ( + id STRING NOT NULL PRIMARY KEY NOT ENFORCED, + other_field STRING REFERENCES other_table(other_field) NOT ENFORCED +); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_keys.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_keys.yml new file mode 100644 index 000000000..79036136e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_keys.yml @@ -0,0 +1,152 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t_table1 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: x + - data_type: + - data_type_identifier: INT64 + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: x + - end_bracket: ) + - keyword: NOT + - keyword: ENFORCED + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t_table1 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: y + - data_type: + - data_type_identifier: STRING + - comma: ',' + - table_constraint: + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: y + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: t_table2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: y + - end_bracket: ) + - keyword: NOT + - keyword: ENFORCED + - comma: ',' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t_table1 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: x + - data_type: + - data_type_identifier: INT64 + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: x + - end_bracket: ) + - keyword: NOT + - keyword: ENFORCED + - comma: ',' + - column_definition: + - naked_identifier: y + - data_type: + - data_type_identifier: STRING + - comma: ',' + - table_constraint: + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: y + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: t_table2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: y + - end_bracket: ) + - keyword: NOT + - keyword: ENFORCED + - comma: ',' + - column_definition: + - naked_identifier: _other + - data_type: + - data_type_identifier: STRING + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '`some_dataset.some_table`' + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: STRING + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - keyword: NOT + - keyword: ENFORCED + - comma: ',' + - column_definition: + - naked_identifier: other_field + - data_type: + - data_type_identifier: STRING + - column_constraint_segment: + - keyword: REFERENCES + - table_reference: + - naked_identifier: other_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: other_field + - end_bracket: ) + - keyword: NOT + - keyword: ENFORCED + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_like_copy_clone.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_like_copy_clone.sql index 1eed922ad..a811ba69d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_like_copy_clone.sql +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_like_copy_clone.sql @@ -14,3 +14,8 @@ COPY mydataset.sourcetable CREATE TABLE mydataset.newtable_clone CLONE mydataset.sourcetable ; + +CREATE TABLE IF NOT EXISTS mydataset.newtable_clone +CLONE mydataset.sourcetable FOR SYSTEM_TIME AS OF CURRENT_TIMESTAMP() +OPTIONS(description="example") +; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_like_copy_clone.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_like_copy_clone.yml index d2466667b..c9d5f36ca 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_like_copy_clone.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_like_copy_clone.yml @@ -72,3 +72,42 @@ file: - dot: . - naked_identifier: sourcetable - statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: newtable_clone + - keyword: CLONE + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: sourcetable + - for_system_time_as_of_segment: + - keyword: FOR + - keyword: SYSTEM_TIME + - keyword: AS + - keyword: OF + - expression: + - function: + - function_name: + - function_name_identifier: CURRENT_TIMESTAMP + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"example"' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_temp_function_with_select.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_temp_function_with_select.yml index 868043c72..0af475c16 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_temp_function_with_select.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_temp_function_with_select.yml @@ -56,12 +56,14 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: y - keyword: WITH - keyword: OFFSET - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: i - end_bracket: ) - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_view_options_as.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_view_options_as.sql index 05ec6de43..372ef62fc 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_view_options_as.sql +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_view_options_as.sql @@ -8,3 +8,11 @@ AS (SELECT * from bar); CREATE OR REPLACE VIEW IF NOT EXISTS foo OPTIONS (description = 'copy of bar') AS (SELECT * from bar); + +CREATE OR REPLACE VIEW foo +( + x OPTIONS (description = 'x'), + y OPTIONS (description = 'y') +) +OPTIONS (description = 'view_column_name_list') +AS (SELECT x, y from bar); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_view_options_as.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_view_options_as.yml index 853b2962c..32f7bd8fc 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_view_options_as.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_view_options_as.yml @@ -101,3 +101,68 @@ file: - naked_identifier: bar - end_bracket: ) - statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: VIEW + - table_reference: + - naked_identifier: foo + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: x + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''x''' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: y + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''y''' + - end_bracket: ) + - end_bracket: ) + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''view_column_name_list''' + - end_bracket: ) + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: x + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: y + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/dateparts.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/dateparts.yml index 26324389f..ba52d2571 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/dateparts.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/dateparts.yml @@ -236,7 +236,8 @@ file: - naked_identifier: col1 - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: week - comma: ',' - select_clause_element: @@ -253,7 +254,8 @@ file: - naked_identifier: col1 - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: week - comma: ',' - select_clause_element: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/declare_variable.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/declare_variable.yml index 0ad35ac6b..456f08010 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/declare_variable.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/declare_variable.yml @@ -65,7 +65,7 @@ file: - keyword: declare - naked_identifier: arr1 - data_type: - - array_type: + - data_type: - keyword: array - start_angle_bracket: < - data_type: @@ -98,7 +98,7 @@ file: - keyword: declare - naked_identifier: arr4 - data_type: - - array_type: + - data_type: - keyword: array - start_angle_bracket: < - data_type: @@ -117,7 +117,7 @@ file: - keyword: declare - naked_identifier: arr5 - data_type: - - array_type: + - data_type: - keyword: array - start_angle_bracket: < - data_type: @@ -134,7 +134,7 @@ file: - keyword: declare - naked_identifier: str1 - data_type: - - struct_type: + - data_type: - keyword: struct - struct_type_schema: - start_angle_bracket: < @@ -152,7 +152,7 @@ file: - keyword: declare - naked_identifier: str2 - data_type: - - struct_type: + - data_type: - keyword: struct - struct_type_schema: - start_angle_bracket: < @@ -167,7 +167,7 @@ file: - keyword: default - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: struct - struct_literal: - bracketed: @@ -184,7 +184,7 @@ file: - keyword: default - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: struct - struct_literal: - bracketed: @@ -199,7 +199,7 @@ file: - keyword: declare - naked_identifier: str4 - data_type: - - struct_type: + - data_type: - keyword: struct - struct_type_schema: - start_angle_bracket: < @@ -225,7 +225,7 @@ file: - keyword: declare - naked_identifier: str5 - data_type: - - struct_type: + - data_type: - keyword: struct - struct_type_schema: - start_angle_bracket: < diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_function.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_function.sql new file mode 100644 index 000000000..e7558ab06 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_function.sql @@ -0,0 +1,2 @@ +DROP FUNCTION myproject.mydataset.addfunc; +DROP TABLE FUNCTION IF EXISTS example_dataset.example_table_function; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_function.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_function.yml new file mode 100644 index 000000000..8ab4fab7b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_function.yml @@ -0,0 +1,24 @@ +file: +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: FUNCTION + - function_name: + - naked_identifier: myproject + - dot: . + - naked_identifier: mydataset + - dot: . + - function_name_identifier: addfunc +- statement_terminator: ; +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: TABLE + - keyword: FUNCTION + - keyword: IF + - keyword: EXISTS + - function_name: + - naked_identifier: example_dataset + - dot: . + - function_name_identifier: example_table_function +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_procedure.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_procedure.sql new file mode 100644 index 000000000..ee9e86193 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_procedure.sql @@ -0,0 +1,2 @@ +DROP PROCEDURE example_dataset.example_procedure; +DROP PROCEDURE IF EXISTS `other-project`.sample_dataset.myprocedure; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_procedure.yml new file mode 100644 index 000000000..f092e7a8f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_procedure.yml @@ -0,0 +1,23 @@ +file: +- statement: + - drop_procedure_statement: + - keyword: DROP + - keyword: PROCEDURE + - procedure_name: + - naked_identifier: example_dataset + - dot: . + - procedure_name_identifier: example_procedure +- statement_terminator: ; +- statement: + - drop_procedure_statement: + - keyword: DROP + - keyword: PROCEDURE + - keyword: IF + - keyword: EXISTS + - procedure_name: + - quoted_identifier: '`other-project`' + - dot: . + - naked_identifier: sample_dataset + - dot: . + - procedure_name_identifier: myprocedure +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_schema.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_schema.sql new file mode 100644 index 000000000..718fbc8a5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_schema.sql @@ -0,0 +1,4 @@ +DROP SCHEMA example_dataset; +DROP SCHEMA IF EXISTS example_project.example_dataset; +UNDROP SCHEMA example_dataset; +UNDROP SCHEMA IF NOT EXISTS example_project.example_dataset; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_schema.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_schema.yml new file mode 100644 index 000000000..1e2bb0ee9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_schema.yml @@ -0,0 +1,38 @@ +file: +- statement: + - drop_schema_statement: + - keyword: DROP + - keyword: SCHEMA + - schema_reference: + - naked_identifier: example_dataset +- statement_terminator: ; +- statement: + - drop_schema_statement: + - keyword: DROP + - keyword: SCHEMA + - keyword: IF + - keyword: EXISTS + - schema_reference: + - naked_identifier: example_project + - dot: . + - naked_identifier: example_dataset +- statement_terminator: ; +- statement: + - undrop_schema_statement: + - keyword: UNDROP + - keyword: SCHEMA + - schema_reference: + - naked_identifier: example_dataset +- statement_terminator: ; +- statement: + - undrop_schema_statement: + - keyword: UNDROP + - keyword: SCHEMA + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - schema_reference: + - naked_identifier: example_project + - dot: . + - naked_identifier: example_dataset +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table.sql new file mode 100644 index 000000000..8b8c4a61c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table.sql @@ -0,0 +1,3 @@ +DROP TABLE IF EXISTS example_dataset.example_table; +DROP SNAPSHOT TABLE example_dataset.example_snapshot_table; +DROP EXTERNAL TABLE example_dataset.example_external_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table.yml new file mode 100644 index 000000000..9dab8dc44 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table.yml @@ -0,0 +1,32 @@ +file: +- statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - keyword: IF + - keyword: EXISTS + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table +- statement_terminator: ; +- statement: + - drop_table_statement: + - keyword: DROP + - keyword: SNAPSHOT + - keyword: TABLE + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_snapshot_table +- statement_terminator: ; +- statement: + - drop_table_statement: + - keyword: DROP + - keyword: EXTERNAL + - keyword: TABLE + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_external_table +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table_function.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table_function.sql new file mode 100644 index 000000000..b1a7fb5d8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table_function.sql @@ -0,0 +1,2 @@ +DROP TABLE FUNCTION mydataset.my_table_function; +DROP TABLE FUNCTION IF EXISTS mydataset.my_table_function; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table_function.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table_function.yml new file mode 100644 index 000000000..4f3465361 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_table_function.yml @@ -0,0 +1,23 @@ +file: +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: TABLE + - keyword: FUNCTION + - function_name: + - naked_identifier: mydataset + - dot: . + - function_name_identifier: my_table_function +- statement_terminator: ; +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: TABLE + - keyword: FUNCTION + - keyword: IF + - keyword: EXISTS + - function_name: + - naked_identifier: mydataset + - dot: . + - function_name_identifier: my_table_function +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_various_resources.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_various_resources.sql new file mode 100644 index 000000000..9fa236e4b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_various_resources.sql @@ -0,0 +1,11 @@ +DROP ROW ACCESS POLICY IF EXISTS example_policy_name ON example_dataset.example_table; + +DROP CAPACITY `example-project.region-us.example_commitment`; + +DROP RESERVATION IF EXISTS `example-project.region-us.example_reservation`; + +DROP ASSIGNMENT `example-project.region-us.example_reservation.example_assignment`; + +DROP SEARCH INDEX IF EXISTS example_index ON example_dataset.example_table; + +DROP VECTOR INDEX example_index ON example_dataset.example_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_various_resources.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_various_resources.yml new file mode 100644 index 000000000..33933820a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/drop_various_resources.yml @@ -0,0 +1,67 @@ +file: +- statement: + - drop_row_access_policy_statement: + - keyword: DROP + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - keyword: IF + - keyword: EXISTS + - naked_identifier: example_policy_name + - keyword: ON + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table +- statement_terminator: ; +- statement: + - drop_capacity_statement: + - keyword: DROP + - keyword: CAPACITY + - table_reference: + - quoted_identifier: '`example-project.region-us.example_commitment`' +- statement_terminator: ; +- statement: + - drop_reservation_statement: + - keyword: DROP + - keyword: RESERVATION + - keyword: IF + - keyword: EXISTS + - table_reference: + - quoted_identifier: '`example-project.region-us.example_reservation`' +- statement_terminator: ; +- statement: + - drop_assignment_statement: + - keyword: DROP + - keyword: ASSIGNMENT + - table_reference: + - quoted_identifier: '`example-project.region-us.example_reservation.example_assignment`' +- statement_terminator: ; +- statement: + - drop_search_index_statement: + - keyword: DROP + - keyword: SEARCH + - keyword: INDEX + - keyword: IF + - keyword: EXISTS + - index_reference: + - naked_identifier: example_index + - keyword: ON + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table +- statement_terminator: ; +- statement: + - drop_vector_index_statement: + - keyword: DROP + - keyword: VECTOR + - keyword: INDEX + - index_reference: + - naked_identifier: example_index + - keyword: ON + - table_reference: + - naked_identifier: example_dataset + - dot: . + - naked_identifier: example_table +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/execute_immediate.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/execute_immediate.sql new file mode 100644 index 000000000..f9d9421d3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/execute_immediate.sql @@ -0,0 +1,34 @@ +declare var_1 string; +declare var_2 string; + +set var_1 = ''' +insert into project.data_set.table +select + "%s" as var_1, + count(*) as column_1 +from ( + select column_3 + from %s.column_2 + group by var_3 having count(var_3) > 1 +) +'''; + +create or replace table project.data_set.table (var_1 string, column_1 int64) +options ( + expiration_timestamp = timestamp_add(current_timestamp(), interval 3 hour) +); + +for m in (select var_1 from project.data_set.table) do + set var_1 = m[0]; + execute immediate 'select 1;'; + execute immediate var_1; + execute immediate format(var_2, var_1, var_1); + execute immediate case + when x then format(var_1, var_2) else format(var_1, m) + end; + execute immediate (select format(var_2, var_1, var_1)); + execute immediate 'SELECT 2 + 3' into y; + execute immediate 'SELECT 2 + 3, 6' into y, z; + execute immediate 'SELECT ? * (? + 2)' into y using 1, 3; + execute immediate 'SELECT @a * (@b + 2)' into y using 1 as a, x as b; +end for; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/execute_immediate.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/execute_immediate.yml new file mode 100644 index 000000000..ef7f02657 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/execute_immediate.yml @@ -0,0 +1,292 @@ +file: +- statement: + - declare_segment: + - keyword: declare + - naked_identifier: var_1 + - data_type: + - data_type_identifier: string +- statement_terminator: ; +- statement: + - declare_segment: + - keyword: declare + - naked_identifier: var_2 + - data_type: + - data_type_identifier: string +- statement_terminator: ; +- statement: + - set_segment: + - keyword: set + - naked_identifier: var_1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: |- + ''' + insert into project.data_set.table + select + "%s" as var_1, + count(*) as column_1 + from ( + select column_3 + from %s.column_2 + group by var_3 having count(var_3) > 1 + ) + ''' +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: create + - keyword: or + - keyword: replace + - keyword: table + - table_reference: + - naked_identifier: project + - dot: . + - naked_identifier: data_set + - dot: . + - naked_identifier: table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: var_1 + - data_type: + - data_type_identifier: string + - comma: ',' + - column_definition: + - naked_identifier: column_1 + - data_type: + - data_type_identifier: int64 + - end_bracket: ) + - options_segment: + - keyword: options + - bracketed: + - start_bracket: ( + - parameter: expiration_timestamp + - comparison_operator: + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: timestamp_add + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: current_timestamp + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - expression: + - interval_expression: + - keyword: interval + - expression: + - numeric_literal: '3' + - date_part: hour + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- multi_statement_segment: + - for_in_statement: + - keyword: for + - naked_identifier: m + - keyword: in + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: var_1 + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: project + - dot: . + - naked_identifier: data_set + - dot: . + - naked_identifier: table + - end_bracket: ) + - keyword: do + - for_in_statements: + - statement: + - set_segment: + - keyword: set + - naked_identifier: var_1 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: m + - array_accessor: + - start_square_bracket: '[' + - numeric_literal: '0' + - end_square_bracket: ']' + - statement_terminator: ; + - statement: + - execute_immediate: + - keyword: execute + - keyword: immediate + - quoted_literal: '''select 1;''' + - statement_terminator: ; + - statement: + - execute_immediate: + - keyword: execute + - keyword: immediate + - naked_identifier: var_1 + - statement_terminator: ; + - statement: + - execute_immediate: + - keyword: execute + - keyword: immediate + - function: + - function_name: + - function_name_identifier: format + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: var_2 + - comma: ',' + - expression: + - column_reference: + - naked_identifier: var_1 + - comma: ',' + - expression: + - column_reference: + - naked_identifier: var_1 + - end_bracket: ) + - statement_terminator: ; + - statement: + - execute_immediate: + - keyword: execute + - keyword: immediate + - case_expression: + - keyword: case + - when_clause: + - keyword: when + - expression: + - column_reference: + - naked_identifier: x + - keyword: then + - expression: + - function: + - function_name: + - function_name_identifier: format + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: var_1 + - comma: ',' + - expression: + - column_reference: + - naked_identifier: var_2 + - end_bracket: ) + - else_clause: + - keyword: else + - expression: + - function: + - function_name: + - function_name_identifier: format + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: var_1 + - comma: ',' + - expression: + - column_reference: + - naked_identifier: m + - end_bracket: ) + - keyword: end + - statement_terminator: ; + - statement: + - execute_immediate: + - keyword: execute + - keyword: immediate + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - function_name_identifier: format + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: var_2 + - comma: ',' + - expression: + - column_reference: + - naked_identifier: var_1 + - comma: ',' + - expression: + - column_reference: + - naked_identifier: var_1 + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - execute_immediate: + - keyword: execute + - keyword: immediate + - quoted_literal: '''SELECT 2 + 3''' + - keyword: into + - naked_identifier: y + - statement_terminator: ; + - statement: + - execute_immediate: + - keyword: execute + - keyword: immediate + - quoted_literal: '''SELECT 2 + 3, 6''' + - keyword: into + - naked_identifier: y + - comma: ',' + - naked_identifier: z + - statement_terminator: ; + - statement: + - execute_immediate: + - keyword: execute + - keyword: immediate + - quoted_literal: '''SELECT ? * (? + 2)''' + - keyword: into + - naked_identifier: y + - keyword: using + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '3' + - statement_terminator: ; + - statement: + - execute_immediate: + - keyword: execute + - keyword: immediate + - quoted_literal: '''SELECT @a * (@b + 2)''' + - keyword: into + - naked_identifier: y + - keyword: using + - numeric_literal: '1' + - keyword: as + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: x + - keyword: as + - naked_identifier: b + - statement_terminator: ; + - keyword: end + - keyword: for +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/export_statement.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/export_statement.sql index 7e46d0265..93c4f88a4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/export_statement.sql +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/export_statement.sql @@ -63,3 +63,11 @@ WITH cte AS ( ) SELECT * FROM cte; + +EXPORT DATA OPTIONS +(uri=CONCAT("gs://bucket/","/file_*.csv"), + format='CSV', + overwrite=true, + header=true, + field_delimiter=',') +as SELECT col1,col2 FROM thetable; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/export_statement.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/export_statement.yml index 12e8b93c6..f9d9eb4c9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/export_statement.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/export_statement.yml @@ -27,12 +27,12 @@ file: - export_option: overwrite - comparison_operator: - raw_comparison_operator: = - - keyword: 'true' + - boolean_literal: 'true' - comma: ',' - export_option: header - comparison_operator: - raw_comparison_operator: = - - keyword: 'true' + - boolean_literal: 'true' - comma: ',' - export_option: field_delimiter - comparison_operator: @@ -89,12 +89,12 @@ file: - export_option: overwrite - comparison_operator: - raw_comparison_operator: = - - keyword: 'true' + - boolean_literal: 'true' - comma: ',' - export_option: header - comparison_operator: - raw_comparison_operator: = - - keyword: 'true' + - boolean_literal: 'true' - comma: ',' - export_option: field_delimiter - comparison_operator: @@ -147,12 +147,12 @@ file: - export_option: overwrite - comparison_operator: - raw_comparison_operator: = - - keyword: 'true' + - boolean_literal: 'true' - comma: ',' - export_option: header - comparison_operator: - raw_comparison_operator: = - - keyword: 'true' + - boolean_literal: 'true' - comma: ',' - export_option: field_delimiter - comparison_operator: @@ -208,12 +208,12 @@ file: - export_option: overwrite - comparison_operator: - raw_comparison_operator: = - - keyword: 'true' + - boolean_literal: 'true' - comma: ',' - export_option: header - comparison_operator: - raw_comparison_operator: = - - keyword: 'true' + - boolean_literal: 'true' - comma: ',' - export_option: field_delimiter - comparison_operator: @@ -320,7 +320,7 @@ file: - export_option: overwrite - comparison_operator: - raw_comparison_operator: = - - keyword: 'true' + - boolean_literal: 'true' - end_bracket: ) - keyword: AS - select_statement: @@ -371,12 +371,12 @@ file: - export_option: overwrite - comparison_operator: - raw_comparison_operator: = - - keyword: 'true' + - boolean_literal: 'true' - comma: ',' - export_option: header - comparison_operator: - raw_comparison_operator: = - - keyword: 'true' + - boolean_literal: 'true' - comma: ',' - export_option: field_delimiter - comparison_operator: @@ -434,3 +434,65 @@ file: - table_reference: - naked_identifier: cte - statement_terminator: ; +- statement: + - export_statement: + - keyword: EXPORT + - keyword: DATA + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - export_option: uri + - comparison_operator: + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: CONCAT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '"gs://bucket/"' + - comma: ',' + - expression: + - quoted_literal: '"/file_*.csv"' + - end_bracket: ) + - comma: ',' + - export_option: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''CSV''' + - comma: ',' + - export_option: overwrite + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'true' + - comma: ',' + - export_option: header + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'true' + - comma: ',' + - export_option: field_delimiter + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: ''',''' + - end_bracket: ) + - keyword: as + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: thetable +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/for_in.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/for_in.yml index 53c7dc1f1..ad6995efd 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/for_in.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/for_in.yml @@ -169,7 +169,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: count - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/handle_exception.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/handle_exception.sql new file mode 100644 index 000000000..be5eebfcf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/handle_exception.sql @@ -0,0 +1,48 @@ +-- Basic block +BEGIN + SELECT * FROM one_table; +END; + +-- Block showcasing use of in-scope variables +DECLARE x INT64 DEFAULT 10; +BEGIN + DECLARE y INT64; + SET y = x; + SELECT y; +END; +SELECT x; + +-- Basic exception block +BEGIN + SELECT 1/0; +EXCEPTION WHEN ERROR THEN + RAISE USING MESSAGE = "An error happened"; +END; + +-- Exception block utilising @error +BEGIN + SELECT 100/0; +EXCEPTION WHEN ERROR THEN + RAISE USING MESSAGE = FORMAT("Something went wrong: %s", @@error.message); +END; + +-- More complicated block with multiple statements +BEGIN + EXPORT DATA OPTIONS( + uri='gs://bucket/folder/*.csv', + format='CSV', + overwrite=true, + header=true, + field_delimiter=';' + ) AS ( + SELECT field1, field2 FROM mydataset.table1 ORDER BY field1 LIMIT 10 + ); + + SELECT 1/0; +EXCEPTION WHEN ERROR THEN + DELETE FROM mydataset.table1 WHERE field1 = '1'; + + RAISE USING MESSAGE = FORMAT("Something went wrong: %s", @@error.message); + + RETURN; +END; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/handle_exception.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/handle_exception.yml new file mode 100644 index 000000000..8e7554568 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/handle_exception.yml @@ -0,0 +1,265 @@ +file: +- multi_statement_segment: + - begin_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: one_table + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- statement: + - declare_segment: + - keyword: DECLARE + - naked_identifier: x + - data_type: + - data_type_identifier: INT64 + - keyword: DEFAULT + - numeric_literal: '10' +- statement_terminator: ; +- multi_statement_segment: + - begin_statement: + - keyword: BEGIN + - statement: + - declare_segment: + - keyword: DECLARE + - naked_identifier: y + - data_type: + - data_type_identifier: INT64 + - statement_terminator: ; + - statement: + - set_segment: + - keyword: SET + - naked_identifier: y + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: x + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: y + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: x +- statement_terminator: ; +- multi_statement_segment: + - begin_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: / + - numeric_literal: '0' + - statement_terminator: ; + - keyword: EXCEPTION + - keyword: WHEN + - keyword: ERROR + - keyword: THEN + - statement: + - raise_statement: + - keyword: RAISE + - keyword: USING + - keyword: MESSAGE + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '"An error happened"' + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- multi_statement_segment: + - begin_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '100' + - binary_operator: / + - numeric_literal: '0' + - statement_terminator: ; + - keyword: EXCEPTION + - keyword: WHEN + - keyword: ERROR + - keyword: THEN + - statement: + - raise_statement: + - keyword: RAISE + - keyword: USING + - keyword: MESSAGE + - comparison_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: FORMAT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '"Something went wrong: %s"' + - comma: ',' + - expression: + - system_variable: + - double_at_sign_literal: '@@error.message' + - end_bracket: ) + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- multi_statement_segment: + - begin_statement: + - keyword: BEGIN + - statement: + - export_statement: + - keyword: EXPORT + - keyword: DATA + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - export_option: uri + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''gs://bucket/folder/*.csv''' + - comma: ',' + - export_option: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''CSV''' + - comma: ',' + - export_option: overwrite + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'true' + - comma: ',' + - export_option: header + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'true' + - comma: ',' + - export_option: field_delimiter + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: ''';''' + - end_bracket: ) + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: field1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: field2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: table1 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: field1 + - limit_clause: + - keyword: LIMIT + - numeric_literal: '10' + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: / + - numeric_literal: '0' + - statement_terminator: ; + - keyword: EXCEPTION + - keyword: WHEN + - keyword: ERROR + - keyword: THEN + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: field1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''1''' + - statement_terminator: ; + - statement: + - raise_statement: + - keyword: RAISE + - keyword: USING + - keyword: MESSAGE + - comparison_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: FORMAT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '"Something went wrong: %s"' + - comma: ',' + - expression: + - system_variable: + - double_at_sign_literal: '@@error.message' + - end_bracket: ) + - statement_terminator: ; + - statement: + - return_statement: + - keyword: RETURN + - statement_terminator: ; + - keyword: END +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/interval_function.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/interval_function.yml index 63eccd4b9..88f659dc9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/interval_function.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/interval_function.yml @@ -66,7 +66,8 @@ file: - date_part: HOUR - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: avgAtHour - comma: ',' - select_clause_element: @@ -88,7 +89,8 @@ file: - date_part: MINUTE - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: after - comma: ',' - select_clause_element: @@ -110,7 +112,8 @@ file: - date_part: YEAR - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: before - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/load_data_statement.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/load_data_statement.sql new file mode 100644 index 000000000..62f2e3278 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/load_data_statement.sql @@ -0,0 +1,119 @@ +LOAD DATA INTO mydataset.table1 + FROM FILES( + format='AVRO', + uris = ['gs://bucket/path/file.avro'] + ); + +LOAD DATA INTO `myproject.mydataset.table1` + FROM FILES( + format='CSV', + uris = ['gs://bucket/path/file1.csv', 'gs://bucket/path/file2.csv'] + ); + +LOAD DATA INTO mydataset.table1(x INT64, y STRING) + FROM FILES( + skip_leading_rows=1, + format='CSV', + uris = ['gs://bucket/path/file.csv'] + ); + +LOAD DATA INTO mydataset.table1 + OPTIONS( + description="my table", + expiration_timestamp="2025-01-01 00:00:00 UTC" + ) + FROM FILES( + format='AVRO', + uris = ['gs://bucket/path/file.avro'] + ); + +LOAD DATA OVERWRITE mydataset.table1 + FROM FILES( + format='AVRO', + uris = ['gs://bucket/path/file.avro'] + ); + +LOAD DATA INTO TEMP TABLE mydataset.table1 + FROM FILES( + format='AVRO', + uris = ['gs://bucket/path/file.avro'] + ); + +LOAD DATA INTO TEMP TABLE my_tmp_table + FROM FILES( + format='AVRO', + uris = ['gs://bucket/path/file.avro'] + ); + +LOAD DATA INTO mydataset.table1 + PARTITION BY transaction_date + CLUSTER BY customer_id + OPTIONS( + partition_expiration_days=3 + ) + FROM FILES( + format='AVRO', + uris = ['gs://bucket/path/file.avro'] + ); + +LOAD DATA INTO mydataset.table1 +PARTITIONS(_PARTITIONTIME = TIMESTAMP '2016-01-01') + PARTITION BY _PARTITIONTIME + FROM FILES( + format = 'AVRO', + uris = ['gs://bucket/path/file.avro'] + ) + +LOAD DATA INTO mydataset.table1 + FROM FILES( + format='AVRO', + uris = ['gs://bucket/path/*'], + hive_partition_uri_prefix='gs://bucket/path' + ) + WITH PARTITION COLUMNS( + field_1 STRING, -- column order must match the external path + field_2 INT64 + ) + +LOAD DATA INTO mydataset.table1 + FROM FILES( + format='AVRO', + uris = ['gs://bucket/path/*'], + hive_partition_uri_prefix='gs://bucket/path' + ) + WITH PARTITION COLUMNS + +-- This query returns an error in BigQuery. +LOAD DATA INTO mydataset.table1 + ( + x INT64, -- column_list is given but the partition column list is missing + y STRING + ) + FROM FILES( + format='AVRO', + uris = ['gs://bucket/path/*'], + hive_partition_uri_prefix='gs://bucket/path' + ) + WITH PARTITION COLUMNS + +LOAD DATA INTO mydataset.testparquet + FROM FILES ( + uris = ['s3://test-bucket/sample.parquet'], + format = 'PARQUET' + ) + WITH CONNECTION `aws-us-east-1.test-connection` + +LOAD DATA INTO mydataset.test_csv (Number INT64, Name STRING, Time DATE) + PARTITION BY Time + FROM FILES ( + format = 'CSV', uris = ['azure://test.blob.core.windows.net/container/sampled*'], + skip_leading_rows=1 + ) + WITH CONNECTION `azure-eastus2.test-connection` + +LOAD DATA OVERWRITE mydataset.testparquet + FROM FILES ( + uris = ['s3://test-bucket/sample.parquet'], + format = 'PARQUET' + ) + WITH CONNECTION `aws-us-east-1.test-connection` diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/load_data_statement.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/load_data_statement.yml new file mode 100644 index 000000000..c46d5a3fb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/load_data_statement.yml @@ -0,0 +1,554 @@ +file: +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INTO + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: table1 + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''AVRO''' + - comma: ',' + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''gs://bucket/path/file.avro''' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INTO + - table_reference: + - quoted_identifier: '`myproject.mydataset.table1`' + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''CSV''' + - comma: ',' + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''gs://bucket/path/file1.csv''' + - comma: ',' + - quoted_literal: '''gs://bucket/path/file2.csv''' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INTO + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: table1 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: x + - data_type: + - data_type_identifier: INT64 + - comma: ',' + - column_definition: + - naked_identifier: y + - data_type: + - data_type_identifier: STRING + - end_bracket: ) + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: skip_leading_rows + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''CSV''' + - comma: ',' + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''gs://bucket/path/file.csv''' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INTO + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: table1 + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: description + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"my table"' + - comma: ',' + - parameter: expiration_timestamp + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"2025-01-01 00:00:00 UTC"' + - end_bracket: ) + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''AVRO''' + - comma: ',' + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''gs://bucket/path/file.avro''' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: OVERWRITE + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: table1 + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''AVRO''' + - comma: ',' + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''gs://bucket/path/file.avro''' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INTO + - keyword: TEMP + - keyword: TABLE + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: table1 + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''AVRO''' + - comma: ',' + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''gs://bucket/path/file.avro''' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INTO + - keyword: TEMP + - keyword: TABLE + - table_reference: + - naked_identifier: my_tmp_table + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''AVRO''' + - comma: ',' + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''gs://bucket/path/file.avro''' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INTO + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: table1 + - partition_by_segment: + - keyword: PARTITION + - keyword: BY + - expression: + - column_reference: + - naked_identifier: transaction_date + - cluster_by_segment: + - keyword: CLUSTER + - keyword: BY + - expression: + - column_reference: + - naked_identifier: customer_id + - options_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - parameter: partition_expiration_days + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '3' + - end_bracket: ) + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''AVRO''' + - comma: ',' + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''gs://bucket/path/file.avro''' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INTO + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: table1 + - keyword: PARTITIONS + - bracketed: + - start_bracket: ( + - parameter: _PARTITIONTIME + - comparison_operator: + - raw_comparison_operator: = + - keyword: TIMESTAMP + - date_constructor_literal: '''2016-01-01''' + - end_bracket: ) + - partition_by_segment: + - keyword: PARTITION + - keyword: BY + - expression: + - column_reference: + - naked_identifier: _PARTITIONTIME + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''AVRO''' + - comma: ',' + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''gs://bucket/path/file.avro''' + - end_square_bracket: ']' + - end_bracket: ) +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INTO + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: table1 + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''AVRO''' + - comma: ',' + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''gs://bucket/path/*''' + - end_square_bracket: ']' + - comma: ',' + - parameter: hive_partition_uri_prefix + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''gs://bucket/path''' + - end_bracket: ) + - keyword: WITH + - keyword: PARTITION + - keyword: COLUMNS + - bracketed: + - start_bracket: ( + - naked_identifier: field_1 + - data_type: + - data_type_identifier: STRING + - comma: ',' + - naked_identifier: field_2 + - data_type: + - data_type_identifier: INT64 + - end_bracket: ) +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INTO + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: table1 + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''AVRO''' + - comma: ',' + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''gs://bucket/path/*''' + - end_square_bracket: ']' + - comma: ',' + - parameter: hive_partition_uri_prefix + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''gs://bucket/path''' + - end_bracket: ) + - keyword: WITH + - keyword: PARTITION + - keyword: COLUMNS +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INTO + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: table1 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: x + - data_type: + - data_type_identifier: INT64 + - comma: ',' + - column_definition: + - naked_identifier: y + - data_type: + - data_type_identifier: STRING + - end_bracket: ) + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''AVRO''' + - comma: ',' + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''gs://bucket/path/*''' + - end_square_bracket: ']' + - comma: ',' + - parameter: hive_partition_uri_prefix + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''gs://bucket/path''' + - end_bracket: ) + - keyword: WITH + - keyword: PARTITION + - keyword: COLUMNS +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INTO + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: testparquet + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''s3://test-bucket/sample.parquet''' + - end_square_bracket: ']' + - comma: ',' + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''PARQUET''' + - end_bracket: ) + - keyword: WITH + - keyword: CONNECTION + - object_reference: + - quoted_identifier: '`aws-us-east-1.test-connection`' +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INTO + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: test_csv + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: Number + - data_type: + - data_type_identifier: INT64 + - comma: ',' + - column_definition: + - naked_identifier: Name + - data_type: + - data_type_identifier: STRING + - comma: ',' + - column_definition: + - naked_identifier: Time + - data_type: + - data_type_identifier: DATE + - end_bracket: ) + - partition_by_segment: + - keyword: PARTITION + - keyword: BY + - expression: + - column_reference: + - naked_identifier: Time + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''CSV''' + - comma: ',' + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''azure://test.blob.core.windows.net/container/sampled*''' + - end_square_bracket: ']' + - comma: ',' + - parameter: skip_leading_rows + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - end_bracket: ) + - keyword: WITH + - keyword: CONNECTION + - object_reference: + - quoted_identifier: '`azure-eastus2.test-connection`' +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: OVERWRITE + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: testparquet + - keyword: FROM + - keyword: FILES + - bracketed: + - start_bracket: ( + - parameter: uris + - comparison_operator: + - raw_comparison_operator: = + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''s3://test-bucket/sample.parquet''' + - end_square_bracket: ']' + - comma: ',' + - parameter: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''PARQUET''' + - end_bracket: ) + - keyword: WITH + - keyword: CONNECTION + - object_reference: + - quoted_identifier: '`aws-us-east-1.test-connection`' diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/normalize_function.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/normalize_function.yml index 8a2ca47a3..7bbd1410e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/normalize_function.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/normalize_function.yml @@ -20,7 +20,8 @@ file: - keyword: NFD - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - comma: ',' - select_clause_element: @@ -36,7 +37,8 @@ file: - keyword: NFD - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: b - comma: ',' - select_clause_element: @@ -52,7 +54,8 @@ file: - keyword: NFD - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: c - comma: ',' - select_clause_element: @@ -68,7 +71,8 @@ file: - keyword: NFD - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: d - statement_terminator: ; - statement: @@ -92,7 +96,8 @@ file: - column_reference: - naked_identifier: b - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: normalized - from_clause: - keyword: FROM @@ -115,7 +120,8 @@ file: - quoted_literal: '''\u00ea''' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: a - comma: ',' - select_clause_element: @@ -129,7 +135,8 @@ file: - quoted_literal: '''\u0065\u0302''' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: b - end_bracket: ) - statement_terminator: ; @@ -173,7 +180,8 @@ file: - end_square_bracket: ']' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: name - end_bracket: ) - select_statement: @@ -193,7 +201,8 @@ file: - keyword: NFKC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: normalized_name - comma: ',' - select_clause_element: @@ -206,7 +215,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: name_count - from_clause: - keyword: FROM @@ -257,7 +267,8 @@ file: - naked_identifier: b - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: normalized - comma: ',' - select_clause_element: @@ -285,7 +296,8 @@ file: - naked_identifier: b - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: normalized_with_case_folding - from_clause: - keyword: FROM @@ -300,13 +312,15 @@ file: - select_clause_element: - quoted_literal: '''The red barn''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - comma: ',' - select_clause_element: - quoted_literal: '''The Red Barn''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: b - end_bracket: ) - statement_terminator: ; @@ -351,7 +365,8 @@ file: - keyword: NFD - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: nfd - comma: ',' - select_clause_element: @@ -383,7 +398,8 @@ file: - keyword: NFC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: nfc - comma: ',' - select_clause_element: @@ -415,7 +431,8 @@ file: - keyword: NFKD - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: nkfd - comma: ',' - select_clause_element: @@ -447,5 +464,6 @@ file: - keyword: NFKC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: nkfc diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/parameters.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/parameters.yml index 2bea14456..57b332ece 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/parameters.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/parameters.yml @@ -195,7 +195,8 @@ file: - keyword: ROW - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: some_sum - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/pipe_statement.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/pipe_statement.sql new file mode 100644 index 000000000..1a7db8826 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/pipe_statement.sql @@ -0,0 +1,165 @@ +FROM Produce; + +FROM (SELECT 'apples' AS item, 2 AS sales) +|> SELECT item AS fruit_name; + +FROM (SELECT 'apples' AS item, 2 AS sales) +|> EXTEND item IN ('carrots', 'oranges') AS is_orange; + +FROM (SELECT 2 AS x, 3 AS y) AS t +|> SET x = x * x, y = 8 +|> SELECT t.x AS original_x, x, y; + +FROM (SELECT 1 AS x, 2 AS y) AS t +|> DROP x +|> SELECT t.x AS original_x, y; + +FROM (SELECT 1 AS x, 2 AS y) AS t +|> RENAME y AS renamed_y +|> SELECT *, t.y AS t_y; + +FROM (SELECT 1 AS x, 2 AS y) +|> AS t +|> RENAME y AS renamed_y +|> SELECT *, t.y AS t_y; + +FROM foo +|> WHERE sales >= 3 +|> LIMIT 10 OFFSET 4 +|> ORDER BY sales DESC; + +FROM Produce +|> AGGREGATE SUM(sales) AS total_sales + GROUP AND ORDER BY category, item DESC; + +FROM Produce +|> AGGREGATE SUM(sales) AS total_sales + GROUP BY category, item +|> ORDER BY category, item DESC; + +FROM Produce +|> AGGREGATE SUM(sales) AS total_sales ASC + GROUP BY item, category DESC; + +FROM Produce +|> AGGREGATE SUM(sales) AS total_sales + GROUP BY item, category +|> ORDER BY category DESC, total_sales; + +FROM foo +|> UNION ALL + (SELECT 1), + (SELECT 2); + +FROM foo +|> UNION DISTINCT + (SELECT 1), + (SELECT 2); + +FROM foo +|> UNION ALL BY NAME + (SELECT 20 AS two_digit, 2 AS one_digit); + +FROM foo +|> INTERSECT DISTINCT + (SELECT 1), + (SELECT 2); + +FROM foo +|> INTERSECT DISTINCT + (SELECT * FROM UNNEST(ARRAY[2, 3, 3, 5]) AS number), + (SELECT * FROM UNNEST(ARRAY[3, 3, 4, 5]) AS number); + +FROM foo +|> EXCEPT DISTINCT + (SELECT 1), + (SELECT 2); + +FROM foo +|> EXCEPT DISTINCT + (SELECT * FROM UNNEST(ARRAY[1, 2]) AS number), + (SELECT * FROM UNNEST(ARRAY[1, 4]) AS number); + +FROM foo +|> EXCEPT DISTINCT BY NAME + (SELECT 10 AS two_digit, 1 AS one_digit); + +FROM foo +|> LEFT JOIN + ( + SELECT "apples" AS item, 123 AS id + ) AS produce_data + ON produce_sales.item = produce_data.item +|> SELECT produce_sales.item, sales, id; + +FROM input_table +|> CALL tvf1(arg1) +|> CALL tvf2(arg2, arg3); + +FROM mydataset.Produce +|> CALL APPENDS(NULL, NULL); + +FROM LargeTable +|> TABLESAMPLE SYSTEM (1 PERCENT); + +FROM foo +|> PIVOT(SUM(sales) FOR quarter IN ('Q1', 'Q2')); + +FROM foo +|> UNPIVOT(sales FOR quarter IN (Q1, Q2)); + +SELECT * FROM UNNEST(ARRAY[1, 2, 3]) AS number +|> UNION DISTINCT + (SELECT 1), + (SELECT 2); + +WITH + NumbersTable AS ( + SELECT 1 AS one_digit, 10 AS two_digit + UNION ALL + SELECT 2, 20 + UNION ALL + SELECT 3, 30 + ) +SELECT one_digit, two_digit FROM NumbersTable +|> INTERSECT DISTINCT BY NAME + (SELECT 10 AS two_digit, 1 AS one_digit); + +( + SELECT 'apples' AS item, 2 AS sales + UNION ALL + SELECT 'bananas' AS item, 5 AS sales + UNION ALL + SELECT 'apples' AS item, 7 AS sales +) +|> AGGREGATE COUNT(*) AS num_items, SUM(sales) AS total_sales; + +( + SELECT "000123" AS id, "apples" AS item, 2 AS sales + UNION ALL + SELECT "000456" AS id, "bananas" AS item, 5 AS sales +) AS sales_table +|> AGGREGATE SUM(sales) AS total_sales GROUP BY id, item +-- The sales_table alias is now out of scope. We must introduce a new one. +|> AS t1 +|> JOIN (SELECT 456 AS id, "yellow" AS color) AS t2 + ON CAST(t1.id AS INT64) = t2.id +|> SELECT t2.id, total_sales, color; + +SELECT 1 AS x, 2 AS y, 3 AS z +|> AS t +|> RENAME y AS renamed_y +|> SELECT *, t.y AS t_y; + +( + SELECT 'apples' AS item, 2 AS sales + UNION ALL + SELECT 'carrots' AS item, 8 AS sales +) +|> EXTEND item IN ('carrots', 'oranges') AS is_orange; + +WITH bar AS ( + FROM foo +) + +SELECT * FROM bar; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/pipe_statement.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/pipe_statement.yml new file mode 100644 index 000000000..908629bfb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/pipe_statement.yml @@ -0,0 +1,1746 @@ +file: +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Produce +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''apples''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: item + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sales + - end_bracket: ) + - pipe_operator_clause: + - pipe_operator: '|>' + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: item + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: fruit_name +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''apples''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: item + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sales + - end_bracket: ) + - pipe_operator_clause: + - pipe_operator: '|>' + - extend_clause: + - keyword: EXTEND + - expression: + - column_reference: + - naked_identifier: item + - keyword: IN + - bracketed: + - start_bracket: ( + - quoted_literal: '''carrots''' + - comma: ',' + - quoted_literal: '''oranges''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: is_orange +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: x + - comma: ',' + - select_clause_element: + - numeric_literal: '3' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: y + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - pipe_operator_clause: + - pipe_operator: '|>' + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: x + - binary_operator: '*' + - column_reference: + - naked_identifier: x + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: y + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '8' + - pipe_operator_clause: + - pipe_operator: '|>' + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: x + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: original_x + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: x + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: y +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: x + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: y + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - pipe_operator_clause: + - pipe_operator: '|>' + - drop_column_clause: + - keyword: DROP + - column_reference: + - naked_identifier: x + - pipe_operator_clause: + - pipe_operator: '|>' + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: x + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: original_x + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: y +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: x + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: y + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - pipe_operator_clause: + - pipe_operator: '|>' + - rename_column_clause: + - keyword: RENAME + - column_reference: + - naked_identifier: y + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: renamed_y + - pipe_operator_clause: + - pipe_operator: '|>' + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: y + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t_y +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: x + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: y + - end_bracket: ) + - pipe_operator_clause: + - pipe_operator: '|>' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - pipe_operator_clause: + - pipe_operator: '|>' + - rename_column_clause: + - keyword: RENAME + - column_reference: + - naked_identifier: y + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: renamed_y + - pipe_operator_clause: + - pipe_operator: '|>' + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: y + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t_y +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo + - pipe_operator_clause: + - pipe_operator: '|>' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: sales + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - numeric_literal: '3' + - pipe_operator_clause: + - pipe_operator: '|>' + - limit_clause: + - keyword: LIMIT + - numeric_literal: '10' + - keyword: OFFSET + - numeric_literal: '4' + - pipe_operator_clause: + - pipe_operator: '|>' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: sales + - keyword: DESC +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Produce + - pipe_operator_clause: + - pipe_operator: '|>' + - aggregate_clause: + - keyword: AGGREGATE + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: sales + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: total_sales + - group_and_orderby_clause: + - keyword: GROUP + - keyword: AND + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: category + - comma: ',' + - column_reference: + - naked_identifier: item + - keyword: DESC +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Produce + - pipe_operator_clause: + - pipe_operator: '|>' + - aggregate_clause: + - keyword: AGGREGATE + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: sales + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: total_sales + - group_and_orderby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: category + - comma: ',' + - column_reference: + - naked_identifier: item + - pipe_operator_clause: + - pipe_operator: '|>' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: category + - comma: ',' + - column_reference: + - naked_identifier: item + - keyword: DESC +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Produce + - pipe_operator_clause: + - pipe_operator: '|>' + - aggregate_clause: + - keyword: AGGREGATE + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: sales + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: total_sales + - keyword: ASC + - group_and_orderby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: item + - comma: ',' + - column_reference: + - naked_identifier: category + - keyword: DESC +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Produce + - pipe_operator_clause: + - pipe_operator: '|>' + - aggregate_clause: + - keyword: AGGREGATE + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: sales + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: total_sales + - group_and_orderby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: item + - comma: ',' + - column_reference: + - naked_identifier: category + - pipe_operator_clause: + - pipe_operator: '|>' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: category + - keyword: DESC + - comma: ',' + - column_reference: + - naked_identifier: total_sales +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo + - pipe_operator_clause: + - pipe_operator: '|>' + - set_operator_clause: + - set_operator: + - keyword: UNION + - keyword: ALL + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo + - pipe_operator_clause: + - pipe_operator: '|>' + - set_operator_clause: + - set_operator: + - keyword: UNION + - keyword: DISTINCT + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo + - pipe_operator_clause: + - pipe_operator: '|>' + - set_operator_clause: + - set_operator: + - keyword: UNION + - keyword: ALL + - keyword: BY + - keyword: NAME + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '20' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: two_digit + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: one_digit + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo + - pipe_operator_clause: + - pipe_operator: '|>' + - set_operator_clause: + - set_operator: + - keyword: INTERSECT + - keyword: DISTINCT + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo + - pipe_operator_clause: + - pipe_operator: '|>' + - set_operator_clause: + - set_operator: + - keyword: INTERSECT + - keyword: DISTINCT + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: UNNEST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - typed_array_literal: + - data_type: + - keyword: ARRAY + - start_angle_bracket: < + - data_type: + - data_type_identifier: INT64 + - end_angle_bracket: '>' + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - comma: ',' + - numeric_literal: '3' + - comma: ',' + - numeric_literal: '5' + - end_square_bracket: ']' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: number + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: UNNEST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - typed_array_literal: + - data_type: + - keyword: ARRAY + - start_angle_bracket: < + - data_type: + - data_type_identifier: INT64 + - end_angle_bracket: '>' + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '3' + - comma: ',' + - numeric_literal: '3' + - comma: ',' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '5' + - end_square_bracket: ']' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: number + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo + - pipe_operator_clause: + - pipe_operator: '|>' + - set_operator_clause: + - set_operator: + - keyword: EXCEPT + - keyword: DISTINCT + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo + - pipe_operator_clause: + - pipe_operator: '|>' + - set_operator_clause: + - set_operator: + - keyword: EXCEPT + - keyword: DISTINCT + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: UNNEST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - typed_array_literal: + - data_type: + - keyword: ARRAY + - start_angle_bracket: < + - data_type: + - data_type_identifier: INT64 + - end_angle_bracket: '>' + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_square_bracket: ']' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: number + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: UNNEST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - typed_array_literal: + - data_type: + - keyword: ARRAY + - start_angle_bracket: < + - data_type: + - data_type_identifier: INT64 + - end_angle_bracket: '>' + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '4' + - end_square_bracket: ']' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: number + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo + - pipe_operator_clause: + - pipe_operator: '|>' + - set_operator_clause: + - set_operator: + - keyword: EXCEPT + - keyword: DISTINCT + - keyword: BY + - keyword: NAME + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '10' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: two_digit + - comma: ',' + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: one_digit + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo + - pipe_operator_clause: + - pipe_operator: '|>' + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '"apples"' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: item + - comma: ',' + - select_clause_element: + - numeric_literal: '123' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: id + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: produce_data + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: produce_sales + - dot: . + - naked_identifier: item + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: produce_data + - dot: . + - naked_identifier: item + - pipe_operator_clause: + - pipe_operator: '|>' + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: produce_sales + - dot: . + - naked_identifier: item + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: sales + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: id +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: input_table + - pipe_operator_clause: + - pipe_operator: '|>' + - call_operator: + - call_statement: + - keyword: CALL + - procedure_name: + - procedure_name_identifier: tvf1 + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: arg1 + - end_bracket: ) + - pipe_operator_clause: + - pipe_operator: '|>' + - call_operator: + - call_statement: + - keyword: CALL + - procedure_name: + - procedure_name_identifier: tvf2 + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: arg2 + - comma: ',' + - expression: + - column_reference: + - naked_identifier: arg3 + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: mydataset + - dot: . + - naked_identifier: Produce + - pipe_operator_clause: + - pipe_operator: '|>' + - call_operator: + - call_statement: + - keyword: CALL + - procedure_name: + - procedure_name_identifier: APPENDS + - bracketed: + - start_bracket: ( + - expression: + - null_literal: 'NULL' + - comma: ',' + - expression: + - null_literal: 'NULL' + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: LargeTable + - pipe_operator_clause: + - pipe_operator: '|>' + - sample_expression: + - keyword: TABLESAMPLE + - keyword: SYSTEM + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - keyword: PERCENT + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo + - pipe_operator_clause: + - pipe_operator: '|>' + - pivot_operator: + - from_pivot_expression: + - keyword: PIVOT + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: sales + - end_bracket: ) + - keyword: FOR + - pivot_for_clause: + - column_reference: + - naked_identifier: quarter + - keyword: IN + - bracketed: + - start_bracket: ( + - quoted_literal: '''Q1''' + - comma: ',' + - quoted_literal: '''Q2''' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo + - pipe_operator_clause: + - pipe_operator: '|>' + - unpivot_operator: + - from_unpivot_expression: + - keyword: UNPIVOT + - bracketed: + - start_bracket: ( + - naked_identifier: sales + - keyword: FOR + - naked_identifier: quarter + - keyword: IN + - bracketed: + - start_bracket: ( + - naked_identifier: Q1 + - comma: ',' + - naked_identifier: Q2 + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: UNNEST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - typed_array_literal: + - data_type: + - keyword: ARRAY + - start_angle_bracket: < + - data_type: + - data_type_identifier: INT64 + - end_angle_bracket: '>' + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_square_bracket: ']' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: number + - pipe_operator_clause: + - pipe_operator: '|>' + - set_operator_clause: + - set_operator: + - keyword: UNION + - keyword: DISTINCT + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: NumbersTable + - keyword: AS + - bracketed: + - start_bracket: ( + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: one_digit + - comma: ',' + - select_clause_element: + - numeric_literal: '10' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: two_digit + - set_operator: + - keyword: UNION + - keyword: ALL + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' + - comma: ',' + - select_clause_element: + - numeric_literal: '20' + - set_operator: + - keyword: UNION + - keyword: ALL + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '3' + - comma: ',' + - select_clause_element: + - numeric_literal: '30' + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: one_digit + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: two_digit + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: NumbersTable + - pipe_operator_clause: + - pipe_operator: '|>' + - set_operator_clause: + - set_operator: + - keyword: INTERSECT + - keyword: DISTINCT + - keyword: BY + - keyword: NAME + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '10' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: two_digit + - comma: ',' + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: one_digit + - end_bracket: ) +- statement_terminator: ; +- statement: + - pipe_statement: + - bracketed: + - start_bracket: ( + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''apples''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: item + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sales + - set_operator: + - keyword: UNION + - keyword: ALL + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''bananas''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: item + - comma: ',' + - select_clause_element: + - numeric_literal: '5' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sales + - set_operator: + - keyword: UNION + - keyword: ALL + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''apples''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: item + - comma: ',' + - select_clause_element: + - numeric_literal: '7' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sales + - end_bracket: ) + - pipe_operator_clause: + - pipe_operator: '|>' + - aggregate_clause: + - keyword: AGGREGATE + - function: + - function_name: + - function_name_identifier: COUNT + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: num_items + - comma: ',' + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: sales + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: total_sales +- statement_terminator: ; +- statement: + - pipe_statement: + - bracketed: + - start_bracket: ( + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '"000123"' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: id + - comma: ',' + - select_clause_element: + - quoted_literal: '"apples"' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: item + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sales + - set_operator: + - keyword: UNION + - keyword: ALL + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '"000456"' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: id + - comma: ',' + - select_clause_element: + - quoted_literal: '"bananas"' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: item + - comma: ',' + - select_clause_element: + - numeric_literal: '5' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sales + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sales_table + - pipe_operator_clause: + - pipe_operator: '|>' + - aggregate_clause: + - keyword: AGGREGATE + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: sales + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: total_sales + - group_and_orderby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: id + - comma: ',' + - column_reference: + - naked_identifier: item + - pipe_operator_clause: + - pipe_operator: '|>' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t1 + - pipe_operator_clause: + - pipe_operator: '|>' + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '456' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: id + - comma: ',' + - select_clause_element: + - quoted_literal: '"yellow"' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: color + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t2 + - join_on_condition: + - keyword: ON + - expression: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: id + - keyword: AS + - data_type: + - data_type_identifier: INT64 + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: id + - pipe_operator_clause: + - pipe_operator: '|>' + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: total_sales + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: color +- statement_terminator: ; +- statement: + - pipe_statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: x + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: y + - comma: ',' + - select_clause_element: + - numeric_literal: '3' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: z + - pipe_operator_clause: + - pipe_operator: '|>' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - pipe_operator_clause: + - pipe_operator: '|>' + - rename_column_clause: + - keyword: RENAME + - column_reference: + - naked_identifier: y + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: renamed_y + - pipe_operator_clause: + - pipe_operator: '|>' + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: y + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t_y +- statement_terminator: ; +- statement: + - pipe_statement: + - bracketed: + - start_bracket: ( + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''apples''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: item + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sales + - set_operator: + - keyword: UNION + - keyword: ALL + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''carrots''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: item + - comma: ',' + - select_clause_element: + - numeric_literal: '8' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sales + - end_bracket: ) + - pipe_operator_clause: + - pipe_operator: '|>' + - extend_clause: + - keyword: EXTEND + - expression: + - column_reference: + - naked_identifier: item + - keyword: IN + - bracketed: + - start_bracket: ( + - quoted_literal: '''carrots''' + - comma: ',' + - quoted_literal: '''oranges''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: is_orange +- statement_terminator: ; +- statement: + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: bar + - keyword: AS + - bracketed: + - start_bracket: ( + - pipe_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select.sql new file mode 100644 index 000000000..9acaa6d14 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select.sql @@ -0,0 +1 @@ +SELECT 'metadata' AS key from foo; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select.yml new file mode 100644 index 000000000..82e762794 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select.yml @@ -0,0 +1,19 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''metadata''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: key + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_case.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_case.yml index 317a4801b..d09e584b5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_case.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_case.yml @@ -33,7 +33,8 @@ file: - quoted_literal: '''cashew''' - keyword: end - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: fruit - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_datetime.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_datetime.yml index 2f7d94937..4d3c5436b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_datetime.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_datetime.yml @@ -31,7 +31,8 @@ file: - naked_identifier: order_created_at - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: order_day - from_clause: - keyword: FROM @@ -41,7 +42,8 @@ file: - table_reference: - naked_identifier: my_table - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: gmv - where_clause: - keyword: WHERE diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_example.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_example.yml index 24737283f..77c24f9ec 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_example.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_example.yml @@ -74,11 +74,13 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: num - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: bits - comma: ',' - select_clause_element: @@ -228,7 +230,8 @@ file: - column_reference: - naked_identifier: audience_size - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: relative_abundance - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_except.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_except.sql index f740caa0c..b15fe33a8 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_except.sql +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_except.sql @@ -1,5 +1,5 @@ SELECT - * EXCEPT (seqnum) REPLACE (foo as bar, baz foobar) + * EXCEPT (seqnum) REPLACE (foo as bar, baz as foobar) FROM my_tbl; -- Catch potential bugs in unions diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_except.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_except.yml index 766345ab4..d5568d006 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_except.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_except.yml @@ -17,18 +17,15 @@ file: - keyword: REPLACE - bracketed: - start_bracket: ( - - select_clause_element: - - column_reference: - - naked_identifier: foo - - alias_expression: - - keyword: as - - naked_identifier: bar + - column_reference: + - naked_identifier: foo + - keyword: as + - naked_identifier: bar - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: baz - - alias_expression: - - naked_identifier: foobar + - column_reference: + - naked_identifier: baz + - keyword: as + - naked_identifier: foobar - end_bracket: ) - from_clause: - keyword: FROM @@ -88,7 +85,8 @@ file: - binary_operator: + - numeric_literal: '2' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: calculated - comma: ',' - select_clause_element: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_except_replace.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_except_replace.yml index e35d63645..cfa745fc2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_except_replace.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_except_replace.yml @@ -17,23 +17,21 @@ file: - keyword: replace - bracketed: - start_bracket: ( - - select_clause_element: - - function: - - function_name: - - function_name_identifier: concat - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: fruit - - comma: ',' - - expression: - - quoted_literal: '''berry''' - - end_bracket: ) - - alias_expression: - - keyword: as - - naked_identifier: fruit + - function: + - function_name: + - function_name_identifier: concat + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: fruit + - comma: ',' + - expression: + - quoted_literal: '''berry''' + - end_bracket: ) + - keyword: as + - naked_identifier: fruit - end_bracket: ) - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_extract.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_extract.yml index 739232092..fe8c65223 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_extract.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_extract.yml @@ -70,7 +70,8 @@ file: - quoted_literal: '"2008-12-25 05:30:00+00"' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: timestamp_value - end_bracket: ) - select_statement: @@ -96,7 +97,8 @@ file: - quoted_literal: '"UTC"' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: the_day_utc - comma: ',' - select_clause_element: @@ -119,7 +121,8 @@ file: - quoted_literal: '"America/Los_Angeles"' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: the_day_california - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_for_system_time.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_for_system_time.yml index 6916ea0a9..5e4bb67f9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_for_system_time.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_for_system_time.yml @@ -14,25 +14,27 @@ file: - table_reference: - naked_identifier: lists_emails - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: list_emails - - keyword: FOR - - keyword: SYSTEM_TIME - - keyword: AS - - keyword: OF - - expression: - - function: - - function_name: - - function_name_identifier: CAST - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''2019-12-02T20:52:34+00:00''' - - keyword: AS - - data_type: - - data_type_identifier: TIMESTAMP - - end_bracket: ) + - for_system_time_as_of_segment: + - keyword: FOR + - keyword: SYSTEM_TIME + - keyword: AS + - keyword: OF + - expression: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2019-12-02T20:52:34+00:00''' + - keyword: AS + - data_type: + - data_type_identifier: TIMESTAMP + - end_bracket: ) - statement_terminator: ; - statement: - select_statement: @@ -48,23 +50,24 @@ file: - table_expression: - table_reference: - quoted_identifier: '`project.dataset.table1`' - - keyword: FOR - - keyword: SYSTEM_TIME - - keyword: AS - - keyword: OF - - expression: - - function: - - function_name: - - function_name_identifier: CAST - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''2020-05-11T14:02:52+00:00''' - - keyword: AS - - data_type: - - data_type_identifier: TIMESTAMP - - end_bracket: ) + - for_system_time_as_of_segment: + - keyword: FOR + - keyword: SYSTEM_TIME + - keyword: AS + - keyword: OF + - expression: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2020-05-11T14:02:52+00:00''' + - keyword: AS + - data_type: + - data_type_identifier: TIMESTAMP + - end_bracket: ) - statement_terminator: ; - statement: - select_statement: @@ -80,21 +83,22 @@ file: - table_expression: - table_reference: - quoted_identifier: '`project.dataset.table1`' - - keyword: FOR - - keyword: SYSTEM - - keyword: TIME - - keyword: AS - - keyword: OF - - expression: - - function: - - function_name: - - function_name_identifier: CAST - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''2020-05-11T14:02:52+00:00''' - - keyword: AS - - data_type: - - data_type_identifier: TIMESTAMP - - end_bracket: ) + - for_system_time_as_of_segment: + - keyword: FOR + - keyword: SYSTEM + - keyword: TIME + - keyword: AS + - keyword: OF + - expression: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2020-05-11T14:02:52+00:00''' + - keyword: AS + - data_type: + - data_type_identifier: TIMESTAMP + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_function_object_fields.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_function_object_fields.yml index c55f466a1..9eaa6540e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_function_object_fields.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_function_object_fields.yml @@ -18,7 +18,8 @@ file: - dot: . - naked_identifier: b - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: field - comma: ',' - select_clause_element: @@ -36,7 +37,8 @@ file: - dot: . - star: '*' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: wildcard - comma: ',' - select_clause_element: @@ -56,7 +58,8 @@ file: - dot: . - naked_identifier: c - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: field_with_field - comma: ',' - select_clause_element: @@ -76,7 +79,8 @@ file: - dot: . - star: '*' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: field_with_wildcard - comma: ',' - select_clause_element: @@ -107,7 +111,8 @@ file: - dot: . - star: '*' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: field_with_offset_wildcard - comma: ',' - select_clause_element: @@ -138,7 +143,8 @@ file: - dot: . - star: '*' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: field_with_safe_offset_wildcard - comma: ',' - select_clause_element: @@ -169,7 +175,8 @@ file: - dot: . - star: '*' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: field_with_ordinal_wildcard - comma: ',' - select_clause_element: @@ -200,7 +207,8 @@ file: - dot: . - naked_identifier: a - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: field_with_ordinal_field - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_group_by.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_group_by.sql new file mode 100644 index 000000000..e41ca6f3f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_group_by.sql @@ -0,0 +1,55 @@ +select foo, count(*) from bar group by all; + +select + letter, + sum(num) as sum_num +from + table_test +group by grouping sets (1, ()); + +select + letter, + sum(num) as sum_num +from + table_test +group by grouping sets (letter, ()); + +select + product_type, + product_name, + sum(product_count) as product_sum +from products +group by + grouping sets ( + product_type, + rollup(product_type, product_name) + ) +order by product_type, product_name; + +select + product_type, + product_name, + sum(product_count) as product_sum +from products +group by + grouping sets ( + product_type, + cube(product_type, product_name) + ) +order by product_type, product_name; + +select + product_type, + product_name, + sum(product_count) as product_sum +from products +group by rollup (product_type, product_name) +order by product_type, product_name; + +select + product_type, + product_name, + sum(product_count) as product_sum +from products +group by cube (product_type, product_name) +order by product_type, product_name; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_group_by.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_group_by.yml new file mode 100644 index 000000000..bae755222 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_group_by.yml @@ -0,0 +1,383 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: foo + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: count + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar + - groupby_clause: + - keyword: group + - keyword: by + - keyword: all +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: letter + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: num + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: sum_num + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table_test + - groupby_clause: + - keyword: group + - keyword: by + - grouping_sets_clause: + - keyword: grouping + - keyword: sets + - bracketed: + - start_bracket: ( + - grouping_expression_list: + - numeric_literal: '1' + - comma: ',' + - expression: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: letter + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: num + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: sum_num + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table_test + - groupby_clause: + - keyword: group + - keyword: by + - grouping_sets_clause: + - keyword: grouping + - keyword: sets + - bracketed: + - start_bracket: ( + - grouping_expression_list: + - column_reference: + - naked_identifier: letter + - comma: ',' + - expression: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: product_type + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: product_name + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: product_count + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: product_sum + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: products + - groupby_clause: + - keyword: group + - keyword: by + - grouping_sets_clause: + - keyword: grouping + - keyword: sets + - bracketed: + - start_bracket: ( + - grouping_expression_list: + - column_reference: + - naked_identifier: product_type + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: rollup + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: product_type + - comma: ',' + - expression: + - column_reference: + - naked_identifier: product_name + - end_bracket: ) + - end_bracket: ) + - orderby_clause: + - keyword: order + - keyword: by + - column_reference: + - naked_identifier: product_type + - comma: ',' + - column_reference: + - naked_identifier: product_name +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: product_type + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: product_name + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: product_count + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: product_sum + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: products + - groupby_clause: + - keyword: group + - keyword: by + - grouping_sets_clause: + - keyword: grouping + - keyword: sets + - bracketed: + - start_bracket: ( + - grouping_expression_list: + - column_reference: + - naked_identifier: product_type + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: cube + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: product_type + - comma: ',' + - expression: + - column_reference: + - naked_identifier: product_name + - end_bracket: ) + - end_bracket: ) + - orderby_clause: + - keyword: order + - keyword: by + - column_reference: + - naked_identifier: product_type + - comma: ',' + - column_reference: + - naked_identifier: product_name +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: product_type + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: product_name + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: product_count + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: product_sum + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: products + - groupby_clause: + - keyword: group + - keyword: by + - cube_rollup_clause: + - function_name: + - function_name_identifier: rollup + - bracketed: + - start_bracket: ( + - grouping_expression_list: + - column_reference: + - naked_identifier: product_type + - comma: ',' + - column_reference: + - naked_identifier: product_name + - end_bracket: ) + - orderby_clause: + - keyword: order + - keyword: by + - column_reference: + - naked_identifier: product_type + - comma: ',' + - column_reference: + - naked_identifier: product_name +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: product_type + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: product_name + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: product_count + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: product_sum + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: products + - groupby_clause: + - keyword: group + - keyword: by + - cube_rollup_clause: + - function_name: + - function_name_identifier: cube + - bracketed: + - start_bracket: ( + - grouping_expression_list: + - column_reference: + - naked_identifier: product_type + - comma: ',' + - column_reference: + - naked_identifier: product_name + - end_bracket: ) + - orderby_clause: + - keyword: order + - keyword: by + - column_reference: + - naked_identifier: product_type + - comma: ',' + - column_reference: + - naked_identifier: product_name +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_hyphenated_table_name_in_from.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_hyphenated_table_name_in_from.yml index f24c8e47c..7d59f8b4c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_hyphenated_table_name_in_from.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_hyphenated_table_name_in_from.yml @@ -141,7 +141,8 @@ file: - column_reference: - naked_identifier: col2 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: newcol1 - comma: ',' - select_clause_element: @@ -152,7 +153,8 @@ file: - column_reference: - naked_identifier: col2 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: newcol2 - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_identifiers.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_identifiers.yml index a32fa8fa2..4301b6dfa 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_identifiers.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_identifiers.yml @@ -22,7 +22,8 @@ file: - column_reference: - naked_identifier: col_a - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: _ - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_if.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_if.yml index e99a7fc7c..d68fbdece 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_if.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_if.yml @@ -37,7 +37,8 @@ file: - quoted_literal: '''Origin''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: source - comma: ',' - select_clause_element: @@ -51,7 +52,8 @@ file: - numeric_literal: '0' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: total - from_clause: - keyword: FROM @@ -122,7 +124,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: vary - where_clause: - keyword: WHERE diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_mixture_of_array_literals.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_mixture_of_array_literals.yml index 774c057cf..81641a2cb 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_mixture_of_array_literals.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_mixture_of_array_literals.yml @@ -16,7 +16,7 @@ file: - comma: ',' - select_clause_element: - typed_array_literal: - - array_type: + - data_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -33,12 +33,13 @@ file: - quoted_literal: '''a''' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: strcol1 - comma: ',' - select_clause_element: - typed_array_literal: - - array_type: + - data_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -49,7 +50,8 @@ file: - quoted_literal: '''b''' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: strcol2 - comma: ',' - select_clause_element: @@ -58,12 +60,13 @@ file: - numeric_literal: '1.0' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: numcol1 - comma: ',' - select_clause_element: - typed_array_literal: - - array_type: + - data_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -74,7 +77,8 @@ file: - numeric_literal: '1.4' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: numcol2 - comma: ',' - select_clause_element: @@ -82,14 +86,15 @@ file: - start_square_bracket: '[' - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: STRUCT - struct_literal: - bracketed: - start_bracket: ( - quoted_literal: '"Rudisha"' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: name - comma: ',' - array_literal: @@ -103,12 +108,14 @@ file: - numeric_literal: '26.1' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: splits - end_bracket: ) - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: struct1 - comma: ',' - select_clause_element: @@ -134,5 +141,6 @@ file: - dot: . - naked_identifier: a - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: struct_safe_offset diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_ml_predict_with_select.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_ml_predict_with_select.yml index 41dea48cb..7927985e2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_ml_predict_with_select.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_ml_predict_with_select.yml @@ -10,39 +10,30 @@ file: - from_clause: - keyword: FROM - from_expression: - - from_expression_element: - - table_expression: - - function: - - function_name: - - naked_identifier: ML - - dot: . - - function_name_identifier: PREDICT - - function_contents: - - bracketed: - - start_bracket: ( - - expression: + - ml_table_expression: + - keyword: ML + - dot: . + - naked_identifier: PREDICT + - bracketed: + - start_bracket: ( + - keyword: MODEL + - object_reference: + - quoted_identifier: '`project.dataset.model`' + - comma: ',' + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: - column_reference: - - naked_identifier: MODEL - - expression: - - column_reference: - - quoted_identifier: '`project.dataset.model`' - - comma: ',' - - expression: - - bracketed: - - start_bracket: ( - - expression: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: user_id - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - quoted_identifier: '`project.dataset.stats`' - - end_bracket: ) - - end_bracket: ) + - naked_identifier: user_id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '`project.dataset.stats`' + - end_bracket: ) + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_ml_weights.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_ml_weights.yml index bc42ce414..48b03ab01 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_ml_weights.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_ml_weights.yml @@ -10,23 +10,16 @@ file: - from_clause: - keyword: FROM - from_expression: - - from_expression_element: - - table_expression: - - function: - - function_name: - - naked_identifier: ML - - dot: . - - function_name_identifier: WEIGHTS - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: MODEL - - expression: - - column_reference: - - quoted_identifier: '`project.dataset.model`' - - end_bracket: ) + - ml_table_expression: + - keyword: ML + - dot: . + - naked_identifier: WEIGHTS + - bracketed: + - start_bracket: ( + - keyword: MODEL + - object_reference: + - quoted_identifier: '`project.dataset.model`' + - end_bracket: ) - orderby_clause: - keyword: ORDER - keyword: BY diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_multi_except.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_multi_except.yml index 2e7e85e84..9db1ffb68 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_multi_except.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_multi_except.yml @@ -30,7 +30,8 @@ file: - table_reference: - naked_identifier: my_table - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: d - join_clause: - keyword: inner @@ -40,7 +41,8 @@ file: - table_reference: - naked_identifier: my_other_table - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: r - keyword: using - bracketed: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_quoting.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_quoting.sql index 301084857..0578296f9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_quoting.sql +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_quoting.sql @@ -5,4 +5,4 @@ FROM `database.schema.benchmark_user_map` WHERE list_id IS NULL - OR user_id IS NULL \ No newline at end of file + OR user_id IS NULL diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_quoting.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_quoting.yml index 72c64ebbf..825717b84 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_quoting.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_quoting.yml @@ -10,7 +10,8 @@ file: - select_clause_element: - quoted_literal: '"some string"' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: list_id - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_replace.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_replace.yml index 4305cc1d4..5b418df25 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_replace.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_replace.yml @@ -11,22 +11,20 @@ file: - keyword: REPLACE - bracketed: - start_bracket: ( - - select_clause_element: - - function: - - function_name: - - function_name_identifier: CAST - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '1' - - keyword: AS - - data_type: - - data_type_identifier: BOOLEAN - - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: foo + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - keyword: AS + - data_type: + - data_type_identifier: BOOLEAN + - end_bracket: ) + - keyword: AS + - naked_identifier: foo - end_bracket: ) - from_clause: - keyword: FROM @@ -41,7 +39,8 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: foo - end_bracket: ) - statement_terminator: ; @@ -57,11 +56,9 @@ file: - keyword: replace - bracketed: - start_bracket: ( - - select_clause_element: - - quoted_literal: '''thing''' - - alias_expression: - - keyword: as - - naked_identifier: foo + - quoted_literal: '''thing''' + - keyword: as + - naked_identifier: foo - end_bracket: ) - from_clause: - keyword: from @@ -83,21 +80,17 @@ file: - keyword: REPLACE - bracketed: - start_bracket: ( - - select_clause_element: - - expression: - - column_reference: - - naked_identifier: quantity - - binary_operator: / - - numeric_literal: '2' - - alias_expression: - - keyword: AS + - expression: + - column_reference: - naked_identifier: quantity + - binary_operator: / + - numeric_literal: '2' + - keyword: AS + - naked_identifier: quantity - comma: ',' - - select_clause_element: - - quoted_literal: '''thing''' - - alias_expression: - - keyword: as - - naked_identifier: foo + - quoted_literal: '''thing''' + - keyword: as + - naked_identifier: foo - end_bracket: ) - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_rows_between.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_rows_between.yml index 3e32e6625..8881df184 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_rows_between.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_rows_between.yml @@ -55,7 +55,8 @@ file: - keyword: ROW - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: cumulative_number_of_affected_accounts - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_safe_function.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_safe_function.yml index 667ab40b4..34e8894bf 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_safe_function.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_safe_function.yml @@ -6,7 +6,8 @@ file: - select_clause_element: - boolean_literal: 'TRUE' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col1 - comma: ',' - select_clause_element: @@ -30,7 +31,8 @@ file: - numeric_literal: '2' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col2 - comma: ',' - select_clause_element: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_set_operators.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_set_operators.sql index eaf81f6a1..ec758af72 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_set_operators.sql +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_set_operators.sql @@ -14,3 +14,12 @@ SELECT c FROM number1 UNION ALL (SELECT c FROM number2); (SELECT c FROM number1 UNION ALL SELECT c FROM number2) UNION ALL (SELECT c FROM number3 UNION ALL SELECT c FROM number4); + +-- UNION ALL BY NAME +(SELECT c FROM number1) UNION ALL BY NAME (SELECT c FROM number2); + +-- LEFT UNION ALL +(SELECT c FROM number1) LEFT UNION ALL BY NAME (SELECT c, d FROM number2); + +-- UNION ALL BY NAME ON COLUMNS +(SELECT c, d FROM number1) UNION ALL BY NAME ON (c) (SELECT c, e FROM number2); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_set_operators.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_set_operators.yml index 1ccb295c0..c9c96b7c8 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_set_operators.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_set_operators.yml @@ -214,3 +214,142 @@ file: - naked_identifier: number4 - end_bracket: ) - statement_terminator: ; +- statement: + - set_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: number1 + - end_bracket: ) + - set_operator: + - keyword: UNION + - keyword: ALL + - keyword: BY + - keyword: NAME + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: number2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - set_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: number1 + - end_bracket: ) + - set_operator: + - keyword: LEFT + - keyword: UNION + - keyword: ALL + - keyword: BY + - keyword: NAME + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: d + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: number2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - set_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: d + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: number1 + - end_bracket: ) + - set_operator: + - keyword: UNION + - keyword: ALL + - keyword: BY + - keyword: NAME + - keyword: ON + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c + - end_bracket: ) + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: number2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_struct.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_struct.sql index 9420cc3ab..4137cadbc 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_struct.sql +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_struct.sql @@ -55,3 +55,5 @@ FROM table; SELECT TO_JSON(STRUCT()) AS col FROM table; + +SELECT (1*1, 2) IN (STRUCT(1 AS a, 2 AS b)); diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_struct.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_struct.yml index 70e663b56..ad4811525 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_struct.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_struct.yml @@ -66,13 +66,15 @@ file: - select_clause_element: - quoted_literal: '''1''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: bb - comma: ',' - select_clause_element: - numeric_literal: '2' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: aa - statement_terminator: ; - statement: @@ -86,13 +88,15 @@ file: - select_clause_element: - quoted_literal: '''1''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: bb - comma: ',' - select_clause_element: - numeric_literal: '2' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: aa - statement_terminator: ; - statement: @@ -102,7 +106,7 @@ file: - select_clause_element: - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: struct - struct_literal: - bracketed: @@ -112,7 +116,8 @@ file: - dot: . - naked_identifier: bar_id - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: id - comma: ',' - column_reference: @@ -120,11 +125,13 @@ file: - dot: . - naked_identifier: bar_name - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: bar - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: bar - from_clause: - keyword: from @@ -178,11 +185,11 @@ file: - start_bracket: ( - expression: - typed_array_literal: - - array_type: + - data_type: - keyword: ARRAY - start_angle_bracket: < - data_type: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -222,7 +229,7 @@ file: - select_clause_element: - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -238,7 +245,7 @@ file: - select_clause_element: - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -254,7 +261,7 @@ file: - select_clause_element: - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -280,7 +287,7 @@ file: - select_clause_element: - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -301,7 +308,7 @@ file: - select_clause_element: - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: STRUCT - struct_literal: - bracketed: @@ -313,7 +320,8 @@ file: - naked_identifier: some_other_field - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - from_clause: - keyword: FROM @@ -336,7 +344,7 @@ file: - start_bracket: ( - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: STRUCT - struct_literal: - bracketed: @@ -344,7 +352,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - from_clause: - keyword: FROM @@ -354,3 +363,41 @@ file: - table_reference: - naked_identifier: table - statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - binary_operator: '*' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - keyword: IN + - bracketed: + - start_bracket: ( + - typed_struct_literal: + - data_type: + - keyword: STRUCT + - struct_literal: + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - comma: ',' + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: b + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_typeless_struct_inside_function.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_typeless_struct_inside_function.yml index 74f8b9e8b..d9d4f622e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_typeless_struct_inside_function.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_typeless_struct_inside_function.yml @@ -6,29 +6,32 @@ file: - select_clause_element: - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: STRUCT - struct_literal: - bracketed: - start_bracket: ( - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: STRUCT - struct_literal: - bracketed: - start_bracket: ( - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: b - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: foo - statement_terminator: ; - statement: @@ -44,7 +47,7 @@ file: - start_bracket: ( - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: STRUCT - struct_literal: - bracketed: @@ -52,13 +55,15 @@ file: - column_reference: - naked_identifier: a - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - comma: ',' - column_reference: - naked_identifier: b - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: b - end_bracket: ) - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_everything.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_everything.yml index 1f466a985..f3f0ada55 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_everything.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_everything.yml @@ -17,7 +17,8 @@ file: - naked_identifier: orderdate - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: orderdate - from_clause: - keyword: FROM @@ -27,5 +28,6 @@ file: - table_reference: - quoted_identifier: '`gcp-project.data.year_2021`' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: log_tbl diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_nothing.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_nothing.sql index a741ef4b7..257d93b73 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_nothing.sql +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_nothing.sql @@ -2,5 +2,3 @@ SELECT gcpproject.functions.timestamp_parsing(log_tbl.orderdate) AS orderdate FROM `gcp-project.data.year_2021` AS log_tbl - - diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_nothing.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_nothing.yml index e63751dbd..7b06903be 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_nothing.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_nothing.yml @@ -21,7 +21,8 @@ file: - naked_identifier: orderdate - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: orderdate - from_clause: - keyword: FROM @@ -31,5 +32,6 @@ file: - table_reference: - quoted_identifier: '`gcp-project.data.year_2021`' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: log_tbl diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_project_and_datasetfunctionname.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_project_and_datasetfunctionname.yml index 9dc997401..b49784cee 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_project_and_datasetfunctionname.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_project_and_datasetfunctionname.yml @@ -19,7 +19,8 @@ file: - naked_identifier: first_move - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: first_move - from_clause: - keyword: FROM @@ -29,5 +30,6 @@ file: - table_reference: - quoted_identifier: '`gcp-project.data.year_2021`' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: log_tbl diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_project_name.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_project_name.yml index e791c3637..744f1b727 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_project_name.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_udf_quote_project_name.yml @@ -21,7 +21,8 @@ file: - naked_identifier: first_move - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: first_move - from_clause: - keyword: FROM @@ -31,5 +32,6 @@ file: - table_reference: - quoted_identifier: '`gcp-project.data.year_2021`' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: log_tbl diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_unpivot.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_unpivot.yml index 2b6330ca0..c712e5090 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_unpivot.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_unpivot.yml @@ -14,31 +14,36 @@ file: - select_clause_element: - quoted_literal: '''Kale''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: product - comma: ',' - select_clause_element: - numeric_literal: '51' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: Q1 - comma: ',' - select_clause_element: - numeric_literal: '23' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: Q2 - comma: ',' - select_clause_element: - numeric_literal: '45' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: Q3 - comma: ',' - select_clause_element: - numeric_literal: '3' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: Q4 - set_operator: - keyword: UNION @@ -138,22 +143,26 @@ file: - start_bracket: ( - naked_identifier: Q1 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - numeric_literal: '1' - comma: ',' - naked_identifier: Q2 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - numeric_literal: '2' - comma: ',' - naked_identifier: Q3 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - numeric_literal: '3' - comma: ',' - naked_identifier: Q4 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - numeric_literal: '4' - end_bracket: ) - end_bracket: ) @@ -269,7 +278,8 @@ file: - naked_identifier: Q2 - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_literal: '''semester_1''' - comma: ',' - bracketed: @@ -279,7 +289,8 @@ file: - naked_identifier: Q4 - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_literal: '''semester_2''' - end_bracket: ) - end_bracket: ) @@ -292,7 +303,8 @@ file: - column_reference: - naked_identifier: a - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_identifier: '''barry''' - from_clause: - keyword: FROM @@ -323,7 +335,8 @@ file: - naked_identifier: D - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_literal: '"year_2011"' - comma: ',' - bracketed: @@ -333,7 +346,8 @@ file: - naked_identifier: F - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_literal: '"year_2012"' - end_bracket: ) - end_bracket: ) @@ -379,7 +393,8 @@ file: - naked_identifier: foo3 - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - numeric_literal: '1' - comma: ',' - bracketed: @@ -391,7 +406,8 @@ file: - naked_identifier: foo6 - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - numeric_literal: '2' - comma: ',' - bracketed: @@ -403,7 +419,8 @@ file: - naked_identifier: foo9 - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - numeric_literal: '3' - end_bracket: ) - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_cast.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_cast.sql new file mode 100644 index 000000000..e8fafa41a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_cast.sql @@ -0,0 +1,16 @@ +SELECT CAST(1 AS FLOAT64); +SELECT SAFE_CAST(1.0 AS INT64); +SELECT CAST(ARRAY["element1"] AS ARRAY); +SELECT CAST(b'\x48\x65\x6c\x6c\x6f' AS STRING FORMAT 'ASCII') AS bytes_to_string; +SELECT CAST( + TIMESTAMP '2008-12-25 00:00:00+00:00' + AS STRING FORMAT 'YYYY-MM-DD HH24:MI:SS TZH:TZM') AS date_time_to_string; +SELECT CAST('Hello' AS BYTES FORMAT 'ASCII') AS string_to_bytes; +SELECT CAST(DATE '2018-01-30' AS STRING FORMAT 'YYYY') AS date_time_to_string; +SELECT CAST(TIME '21:30:00' AS STRING FORMAT 'HH24') AS date_time_to_string; +SELECT CAST(TIMESTAMP '2008-12-25 00:00:00+00:00' AS STRING FORMAT 'TZH' AT TIME ZONE 'Asia/Kolkata'); +SELECT CAST('03:30 P.M.' AS TIME FORMAT 'HH:MI P.M.') AS string_to_date_time; +SELECT input, CAST(input AS STRING FORMAT '$999,999.999') AS output +FROM UNNEST([1.2, 12.3, 123.456, 1234.56, -12345.678, 1234567.89]) AS input; +SELECT CAST(12.5 AS STRING FORMAT '99.99') as a; +SELECT CAST(-123456 AS STRING FORMAT '9.999EEEE') as a; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_cast.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_cast.yml new file mode 100644 index 000000000..6e0a6ebc4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_cast.yml @@ -0,0 +1,352 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - keyword: AS + - data_type: + - data_type_identifier: FLOAT64 + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SAFE_CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1.0' + - keyword: AS + - data_type: + - data_type_identifier: INT64 + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - typed_array_literal: + - data_type: + - keyword: ARRAY + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '"element1"' + - end_square_bracket: ']' + - keyword: AS + - data_type: + - data_type: + - keyword: ARRAY + - start_angle_bracket: < + - data_type: + - data_type_identifier: STRING + - end_angle_bracket: '>' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: b'\x48\x65\x6c\x6c\x6f' + - keyword: AS + - data_type: + - data_type_identifier: STRING + - keyword: FORMAT + - quoted_literal: '''ASCII''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: bytes_to_string +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - keyword: TIMESTAMP + - date_constructor_literal: '''2008-12-25 00:00:00+00:00''' + - keyword: AS + - data_type: + - data_type_identifier: STRING + - keyword: FORMAT + - quoted_literal: '''YYYY-MM-DD HH24:MI:SS TZH:TZM''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: date_time_to_string +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''Hello''' + - keyword: AS + - data_type: + - data_type_identifier: BYTES + - keyword: FORMAT + - quoted_literal: '''ASCII''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: string_to_bytes +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - keyword: DATE + - date_constructor_literal: '''2018-01-30''' + - keyword: AS + - data_type: + - data_type_identifier: STRING + - keyword: FORMAT + - quoted_literal: '''YYYY''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: date_time_to_string +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - keyword: TIME + - date_constructor_literal: '''21:30:00''' + - keyword: AS + - data_type: + - data_type_identifier: STRING + - keyword: FORMAT + - quoted_literal: '''HH24''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: date_time_to_string +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - keyword: TIMESTAMP + - date_constructor_literal: '''2008-12-25 00:00:00+00:00''' + - keyword: AS + - data_type: + - data_type_identifier: STRING + - keyword: FORMAT + - quoted_literal: '''TZH''' + - time_zone_grammar: + - keyword: AT + - keyword: TIME + - keyword: ZONE + - expression: + - quoted_literal: '''Asia/Kolkata''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''03:30 P.M.''' + - keyword: AS + - data_type: + - data_type_identifier: TIME + - keyword: FORMAT + - quoted_literal: '''HH:MI P.M.''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: string_to_date_time +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: input + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: input + - keyword: AS + - data_type: + - data_type_identifier: STRING + - keyword: FORMAT + - quoted_literal: '''$999,999.999''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: output + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: UNNEST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '1.2' + - comma: ',' + - numeric_literal: '12.3' + - comma: ',' + - numeric_literal: '123.456' + - comma: ',' + - numeric_literal: '1234.56' + - comma: ',' + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '12345.678' + - comma: ',' + - numeric_literal: '1234567.89' + - end_square_bracket: ']' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: input +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '12.5' + - keyword: AS + - data_type: + - data_type_identifier: STRING + - keyword: FORMAT + - quoted_literal: '''99.99''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: a +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '123456' + - keyword: AS + - data_type: + - data_type_identifier: STRING + - keyword: FORMAT + - quoted_literal: '''9.999EEEE''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: a +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_date_literal_coercion_and_two_part_string_interval.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_date_literal_coercion_and_two_part_string_interval.yml index 3e0bf52f7..2601be369 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_date_literal_coercion_and_two_part_string_interval.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_date_literal_coercion_and_two_part_string_interval.yml @@ -26,5 +26,6 @@ file: - date_part: DAY - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: my_array diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_offset.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_offset.sql index 048f6765f..450a4ca47 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_offset.sql +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_offset.sql @@ -7,4 +7,4 @@ SELECT SUM(CASE WHEN value != previous_value THEN 1.0 ELSE 0.0 END) CASE WHEN ix != 0 THEN LAG(value) OVER (ORDER BY ix ASC) ELSE value END AS previous_value FROM UNNEST(sequence_validation_and_business_rules.sequence_validation_and_business_rules) AS value WITH OFFSET AS ix - ) \ No newline at end of file + ) diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_offset.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_offset.yml index 1c3c11c3e..b7815b059 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_offset.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_offset.yml @@ -90,7 +90,8 @@ file: - naked_identifier: value - keyword: END - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: previous_value - from_clause: - keyword: FROM @@ -110,11 +111,13 @@ file: - naked_identifier: sequence_validation_and_business_rules - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: value - keyword: WITH - keyword: OFFSET - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: ix - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_offset_3.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_offset_3.yml index ad280d449..3972bbed3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_offset_3.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_offset_3.yml @@ -32,7 +32,8 @@ file: - end_square_bracket: ']' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: i - keyword: WITH - keyword: OFFSET diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_qualify.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_qualify.yml index 2b53cbeee..7ba444c03 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_qualify.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_qualify.yml @@ -34,7 +34,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM @@ -98,7 +99,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM @@ -167,7 +169,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM @@ -234,7 +237,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM @@ -306,7 +310,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM @@ -373,7 +378,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM @@ -465,7 +471,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_union_and_qualify.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_union_and_qualify.yml index 7b50a1199..d9085aa34 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_union_and_qualify.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_union_and_qualify.yml @@ -35,7 +35,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM @@ -100,7 +101,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_window.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_window.yml index fd50d16f8..0c051c66a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_window.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_window.yml @@ -34,7 +34,8 @@ file: - naked_identifier: item_window - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: most_popular - from_clause: - keyword: FROM @@ -107,7 +108,8 @@ file: - naked_identifier: d - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: most_popular - from_clause: - keyword: FROM @@ -215,7 +217,8 @@ file: - keyword: FOLLOWING - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: most_popular - from_clause: - keyword: FROM @@ -288,7 +291,8 @@ file: - naked_identifier: window_z - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: max_x_over_z - from_clause: - keyword: from @@ -342,7 +346,8 @@ file: - naked_identifier: window_z - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: max_x_over_z - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/set_variable_single.sql b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/set_variable_single.sql index 2d7eebce0..990f37003 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/set_variable_single.sql +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/set_variable_single.sql @@ -1,2 +1,3 @@ set var1 = 5; set var1 = ['one', 'two']; +set @@query_label = 'text'; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/set_variable_single.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/set_variable_single.yml index 73b2d8a65..c1a18bf1b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/set_variable_single.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/set_variable_single.yml @@ -20,3 +20,12 @@ file: - quoted_literal: '''two''' - end_square_bracket: ']' - statement_terminator: ; +- statement: + - set_segment: + - keyword: set + - system_variable: + - double_at_sign_literal: '@@query_label' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''text''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/string_literals.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/string_literals.yml index c36f062ae..c22e0f7ee 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/string_literals.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/string_literals.yml @@ -84,7 +84,8 @@ file: - select_clause_element: - quoted_literal: B""" triple ''' quoted '' "" string are """ - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: hard - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/typeless_struct.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/typeless_struct.yml index 835422ad3..8e06bdec4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/typeless_struct.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/typeless_struct.yml @@ -15,42 +15,47 @@ file: - comma: ',' - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: STRUCT - struct_literal: - bracketed: - start_bracket: ( - quoted_literal: '''hello''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: greeting - comma: ',' - quoted_literal: '''world''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: subject - end_bracket: ) - comma: ',' - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: STRUCT - struct_literal: - bracketed: - start_bracket: ( - quoted_literal: '''hi''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: greeting - comma: ',' - quoted_literal: '''there''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: subject - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: salute - from_clause: - keyword: FROM @@ -91,7 +96,7 @@ file: - keyword: THEN - expression: - typed_struct_literal: - - struct_type: + - data_type: - keyword: STRUCT - struct_literal: - bracketed: @@ -101,7 +106,8 @@ file: - dot: . - naked_identifier: xxx - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: M - comma: ',' - column_reference: @@ -109,12 +115,14 @@ file: - dot: . - naked_identifier: xxx - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: N - end_bracket: ) - keyword: END - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: xxx - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/alter_table.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/alter_table.yml index 4ad793880..58424ebd6 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/alter_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/alter_table.yml @@ -1162,7 +1162,8 @@ file: - naked_identifier: value - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: total_value - from_clause: - keyword: FROM @@ -1195,7 +1196,8 @@ file: - keyword: DESC - limit_clause: - keyword: LIMIT - - numeric_literal: '10' + - limit_clause_component: + - numeric_literal: '10' - statement_terminator: ; - statement: - alter_table_statement: @@ -1233,7 +1235,8 @@ file: - table_reference: - naked_identifier: table1 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t1 - join_clause: - keyword: JOIN @@ -1242,7 +1245,8 @@ file: - table_reference: - naked_identifier: table2 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t2 - join_on_condition: - keyword: ON diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/back_quoted_identifier.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/back_quoted_identifier.yml index 62f2b5718..52755a1bf 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/back_quoted_identifier.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/back_quoted_identifier.yml @@ -25,7 +25,8 @@ file: - column_reference: - naked_identifier: bar - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_identifier: '`baz`' - from_clause: - keyword: FROM @@ -73,6 +74,7 @@ file: - dot: . - naked_identifier: bar - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_identifier: '`baz`' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/complex_table_definition.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/complex_table_definition.yml index 34e081013..fc804c9a4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/complex_table_definition.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/complex_table_definition.yml @@ -167,8 +167,7 @@ file: - column_reference: - naked_identifier: category - comma: ',' - - column_reference: - - quoted_identifier: '''CATEGORY''' + - quoted_literal: '''CATEGORY''' - end_bracket: ) - comma: ',' - expression: @@ -274,19 +273,21 @@ file: - table_engine_function: - function_name: - function_name_identifier: MergeTree - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - merge_tree_order_by_clause: - keyword: ORDER - keyword: BY - column_reference: - naked_identifier: id - - keyword: SETTINGS - - naked_identifier: index_granularity - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '8192' + - settings_clause: + - keyword: SETTINGS + - naked_identifier: index_granularity + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '8192' - statement_terminator: ; - statement: - alter_table_statement: @@ -667,8 +668,7 @@ file: - column_reference: - naked_identifier: category - comma: ',' - - column_reference: - - quoted_identifier: '''RESOURCE_TYPE''' + - quoted_literal: '''RESOURCE_TYPE''' - end_bracket: ) - comma: ',' - expression: diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_database.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_database.yml index b544a14ee..3ec298752 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_database.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_database.yml @@ -136,9 +136,10 @@ file: - raw_comparison_operator: = - engine_function: - keyword: Lazy - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - keyword: COMMENT - quoted_identifier: '''Comment''' - statement_terminator: ; @@ -154,9 +155,10 @@ file: - raw_comparison_operator: = - engine_function: - keyword: Lazy - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - keyword: COMMENT - quoted_identifier: '''The temporary database''' - statement_terminator: ; @@ -228,12 +230,13 @@ file: - raw_comparison_operator: = - engine_function: - keyword: Lazy - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: expiration_time_in_seconds - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: expiration_time_in_seconds + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -254,17 +257,18 @@ file: - raw_comparison_operator: = - engine_function: - keyword: Replicated - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''zoo_path''' - - comma: ',' - - expression: - - quoted_literal: '''shard_name''' - - comma: ',' - - expression: - - quoted_literal: '''replica_name''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''zoo_path''' + - comma: ',' + - expression: + - quoted_literal: '''shard_name''' + - comma: ',' + - expression: + - quoted_literal: '''replica_name''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -278,22 +282,24 @@ file: - raw_comparison_operator: = - engine_function: - keyword: Replicated - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''zoo_path''' - - comma: ',' - - expression: - - quoted_literal: '''shard_name''' - - comma: ',' - - expression: - - quoted_literal: '''replica_name''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: key1 - - comparison_operator: - - raw_comparison_operator: = - - naked_identifier: value1 + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''zoo_path''' + - comma: ',' + - expression: + - quoted_literal: '''shard_name''' + - comma: ',' + - expression: + - quoted_literal: '''replica_name''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: key1 + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: value1 - statement_terminator: ; - statement: - create_database_statement: @@ -307,27 +313,29 @@ file: - raw_comparison_operator: = - engine_function: - keyword: Replicated - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''zoo_path''' - - comma: ',' - - expression: - - quoted_literal: '''shard_name''' - - comma: ',' - - expression: - - quoted_literal: '''replica_name''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: key1 - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1' - - comma: ',' - - naked_identifier: key2 - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '2' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''zoo_path''' + - comma: ',' + - expression: + - quoted_literal: '''shard_name''' + - comma: ',' + - expression: + - quoted_literal: '''replica_name''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: key1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - naked_identifier: key2 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' - statement_terminator: ; - statement: - create_database_statement: @@ -341,17 +349,18 @@ file: - raw_comparison_operator: = - engine_function: - keyword: Replicated - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''some/path/r''' - - comma: ',' - - expression: - - quoted_literal: '''shard1''' - - comma: ',' - - expression: - - quoted_literal: '''replica1''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''some/path/r''' + - comma: ',' + - expression: + - quoted_literal: '''shard1''' + - comma: ',' + - expression: + - quoted_literal: '''replica1''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -365,17 +374,18 @@ file: - raw_comparison_operator: = - engine_function: - keyword: Replicated - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''some/path/r''' - - comma: ',' - - expression: - - quoted_literal: '''shard1''' - - comma: ',' - - expression: - - quoted_literal: '''other_replica''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''some/path/r''' + - comma: ',' + - expression: + - quoted_literal: '''shard1''' + - comma: ',' + - expression: + - quoted_literal: '''other_replica''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -389,17 +399,18 @@ file: - raw_comparison_operator: = - engine_function: - keyword: Replicated - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''some/path/r''' - - comma: ',' - - expression: - - quoted_literal: '''other_shard''' - - comma: ',' - - expression: - - quoted_literal: '''{replica}''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''some/path/r''' + - comma: ',' + - expression: + - quoted_literal: '''other_shard''' + - comma: ',' + - expression: + - quoted_literal: '''{replica}''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -413,17 +424,18 @@ file: - raw_comparison_operator: = - engine_function: - keyword: Replicated - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''some/path/r''' - - comma: ',' - - expression: - - quoted_literal: '''other_shard''' - - comma: ',' - - expression: - - quoted_literal: '''r2''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''some/path/r''' + - comma: ',' + - expression: + - quoted_literal: '''other_shard''' + - comma: ',' + - expression: + - quoted_literal: '''r2''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -437,17 +449,18 @@ file: - raw_comparison_operator: = - engine_function: - keyword: PostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''postgres1:5432''' - - comma: ',' - - expression: - - quoted_literal: '''test_database''' - - comma: ',' - - expression: - - quoted_literal: '''postgres''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''postgres1:5432''' + - comma: ',' + - expression: + - quoted_literal: '''test_database''' + - comma: ',' + - expression: + - quoted_literal: '''postgres''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -461,20 +474,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: PostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''postgres1:5432''' - - comma: ',' - - expression: - - quoted_literal: '''test_database''' - - comma: ',' - - expression: - - quoted_literal: '''postgres''' - - comma: ',' - - expression: - - quoted_literal: '''mysecretpassword''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''postgres1:5432''' + - comma: ',' + - expression: + - quoted_literal: '''test_database''' + - comma: ',' + - expression: + - quoted_literal: '''postgres''' + - comma: ',' + - expression: + - quoted_literal: '''mysecretpassword''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -488,23 +502,24 @@ file: - raw_comparison_operator: = - engine_function: - keyword: PostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''postgres1:5432''' - - comma: ',' - - expression: - - quoted_literal: '''test_database''' - - comma: ',' - - expression: - - quoted_literal: '''postgres''' - - comma: ',' - - expression: - - quoted_literal: '''mysecretpassword''' - - comma: ',' - - expression: - - quoted_literal: '''schema_name''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''postgres1:5432''' + - comma: ',' + - expression: + - quoted_literal: '''test_database''' + - comma: ',' + - expression: + - quoted_literal: '''postgres''' + - comma: ',' + - expression: + - quoted_literal: '''mysecretpassword''' + - comma: ',' + - expression: + - quoted_literal: '''schema_name''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -518,26 +533,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: PostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''postgres1:5432''' - - comma: ',' - - expression: - - quoted_literal: '''test_database''' - - comma: ',' - - expression: - - quoted_literal: '''postgres''' - - comma: ',' - - expression: - - quoted_literal: '''mysecretpassword''' - - comma: ',' - - expression: - - quoted_literal: '''schema_name''' - - comma: ',' - - expression: - - numeric_literal: '1' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''postgres1:5432''' + - comma: ',' + - expression: + - quoted_literal: '''test_database''' + - comma: ',' + - expression: + - quoted_literal: '''postgres''' + - comma: ',' + - expression: + - quoted_literal: '''mysecretpassword''' + - comma: ',' + - expression: + - quoted_literal: '''schema_name''' + - comma: ',' + - expression: + - numeric_literal: '1' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -554,20 +570,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''test''' - - comma: ',' - - expression: - - quoted_literal: '''my_user''' - - comma: ',' - - expression: - - quoted_literal: '''user_password''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''test''' + - comma: ',' + - expression: + - quoted_literal: '''my_user''' + - comma: ',' + - expression: + - quoted_literal: '''user_password''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -585,20 +602,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''test''' - - comma: ',' - - expression: - - quoted_literal: '''my_user''' - - comma: ',' - - expression: - - quoted_literal: '''user_password''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''test''' + - comma: ',' + - expression: + - quoted_literal: '''my_user''' + - comma: ',' + - expression: + - quoted_literal: '''user_password''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -612,17 +630,18 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''my_user''' - - comma: ',' - - expression: - - quoted_literal: '''user_password''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''my_user''' + - comma: ',' + - expression: + - quoted_literal: '''user_password''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -636,21 +655,22 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: test - - comma: ',' - - expression: - - quoted_literal: '''my_user''' - - comma: ',' - - expression: - - quoted_literal: '''user_password''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: test + - comma: ',' + - expression: + - quoted_literal: '''my_user''' + - comma: ',' + - expression: + - quoted_literal: '''user_password''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -664,20 +684,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''test''' - - comma: ',' - - expression: - - quoted_literal: '''my_user''' - - comma: ',' - - expression: - - quoted_literal: '''user_password''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''test''' + - comma: ',' + - expression: + - quoted_literal: '''my_user''' + - comma: ',' + - expression: + - quoted_literal: '''user_password''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -691,25 +712,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''test''' - - comma: ',' - - expression: - - quoted_literal: '''my_user''' - - comma: ',' - - expression: - - quoted_literal: '''user_password''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: read_write_timeout - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '10000' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''test''' + - comma: ',' + - expression: + - quoted_literal: '''my_user''' + - comma: ',' + - expression: + - quoted_literal: '''user_password''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: read_write_timeout + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10000' - statement_terminator: ; - statement: - create_database_statement: @@ -723,30 +746,32 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''test''' - - comma: ',' - - expression: - - quoted_literal: '''my_user''' - - comma: ',' - - expression: - - quoted_literal: '''user_password''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: read_write_timeout - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '10000' - - comma: ',' - - naked_identifier: connect_timeout - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '100' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''test''' + - comma: ',' + - expression: + - quoted_literal: '''my_user''' + - comma: ',' + - expression: + - quoted_literal: '''user_password''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: read_write_timeout + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10000' + - comma: ',' + - naked_identifier: connect_timeout + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '100' - statement_terminator: ; - statement: - create_database_statement: @@ -760,11 +785,12 @@ file: - raw_comparison_operator: = - engine_function: - keyword: SQLite - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''sqlite.db''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''sqlite.db''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -778,20 +804,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedPostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''postgres1:5432''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_database''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_user''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_password''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''postgres1:5432''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_database''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_user''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_password''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -805,25 +832,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedPostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''postgres1:5432''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_database''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_user''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_password''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_postgresql_schema - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''postgres_schema''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''postgres1:5432''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_database''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_user''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_password''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_postgresql_schema + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''postgres_schema''' - statement_terminator: ; - statement: - create_database_statement: @@ -837,30 +866,32 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedPostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''postgres1:5432''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_database''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_user''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_password''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_postgresql_tables_list - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''schema1.table1,schema2.table2,schema1.table3''' - - comma: ',' - - naked_identifier: materialized_postgresql_tables_list_with_schema - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''postgres1:5432''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_database''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_user''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_password''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_postgresql_tables_list + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''schema1.table1,schema2.table2,schema1.table3''' + - comma: ',' + - naked_identifier: materialized_postgresql_tables_list_with_schema + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' - statement_terminator: ; - statement: - create_database_statement: @@ -874,25 +905,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedPostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''postgres1:5432''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_database''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_user''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_password''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_postgresql_schema_list - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''schema1,schema2,schema3''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''postgres1:5432''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_database''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_user''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_password''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_postgresql_schema_list + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''schema1,schema2,schema3''' - statement_terminator: ; - statement: - create_database_statement: @@ -906,25 +939,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedPostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''postgres1:5432''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_database''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_user''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_password''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_postgresql_tables_list - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''table1,table2,table3''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''postgres1:5432''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_database''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_user''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_password''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_postgresql_tables_list + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''table1,table2,table3''' - statement_terminator: ; - statement: - create_database_statement: @@ -938,35 +973,37 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedPostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''postgres1:5432''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_database''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_user''' - - comma: ',' - - expression: - - quoted_literal: '''postgres_password''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_postgresql_replication_slot - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''clickhouse_sync''' - - comma: ',' - - naked_identifier: materialized_postgresql_snapshot - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''0000000A-0000023F-3''' - - comma: ',' - - naked_identifier: materialized_postgresql_tables_list - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''table1,table2,table3''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''postgres1:5432''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_database''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_user''' + - comma: ',' + - expression: + - quoted_literal: '''postgres_password''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_postgresql_replication_slot + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''clickhouse_sync''' + - comma: ',' + - naked_identifier: materialized_postgresql_snapshot + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''0000000A-0000023F-3''' + - comma: ',' + - naked_identifier: materialized_postgresql_tables_list + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''table1,table2,table3''' - statement_terminator: ; - statement: - create_database_statement: @@ -983,20 +1020,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedPostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''host:port''' - - comma: ',' - - expression: - - quoted_literal: '''database''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''password''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''host:port''' + - comma: ',' + - expression: + - quoted_literal: '''database''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''password''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -1014,20 +1052,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedPostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''host:port''' - - comma: ',' - - expression: - - quoted_literal: '''database''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''password''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''host:port''' + - comma: ',' + - expression: + - quoted_literal: '''database''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''password''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -1048,20 +1087,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedPostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''host:port''' - - comma: ',' - - expression: - - quoted_literal: '''database''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''password''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''host:port''' + - comma: ',' + - expression: + - quoted_literal: '''database''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''password''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -1078,25 +1118,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedPostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''host:port''' - - comma: ',' - - expression: - - quoted_literal: '''database''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''password''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_postgresql_schema - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''postgres_schema''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''host:port''' + - comma: ',' + - expression: + - quoted_literal: '''database''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''password''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_postgresql_schema + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''postgres_schema''' - statement_terminator: ; - statement: - create_database_statement: @@ -1114,25 +1156,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedPostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''host:port''' - - comma: ',' - - expression: - - quoted_literal: '''database''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''password''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_postgresql_schema - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''postgres_schema''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''host:port''' + - comma: ',' + - expression: + - quoted_literal: '''database''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''password''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_postgresql_schema + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''postgres_schema''' - statement_terminator: ; - statement: - create_database_statement: @@ -1153,25 +1197,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedPostgreSQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''host:port''' - - comma: ',' - - expression: - - quoted_literal: '''database''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''password''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_postgresql_schema - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''postgres_schema''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''host:port''' + - comma: ',' + - expression: + - quoted_literal: '''database''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''password''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_postgresql_schema + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''postgres_schema''' - statement_terminator: ; - statement: - create_database_statement: @@ -1188,20 +1234,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) - keyword: TABLE - keyword: OVERRIDE - table_reference: @@ -1236,20 +1283,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) - keyword: TABLE - keyword: OVERRIDE - table_reference: @@ -1298,20 +1346,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -1332,20 +1381,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -1366,20 +1416,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) - keyword: TABLE - keyword: OVERRIDE - table_reference: @@ -1432,25 +1483,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_mysql_database_engine - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''InnoDB''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_mysql_database_engine + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''InnoDB''' - statement_terminator: ; - statement: - create_database_statement: @@ -1471,25 +1524,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_mysql_database_engine - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''InnoDB''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_mysql_database_engine + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''InnoDB''' - keyword: TABLE - keyword: OVERRIDE - table_reference: @@ -1539,20 +1594,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) - statement_terminator: ; - statement: - create_database_statement: @@ -1570,20 +1626,21 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) - keyword: TABLE - keyword: OVERRIDE - table_reference: @@ -1633,25 +1690,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_mysql_database_engine - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''InnoDB''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_mysql_database_engine + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''InnoDB''' - statement_terminator: ; - statement: - create_database_statement: @@ -1669,25 +1728,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_mysql_database_engine - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''InnoDB''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_mysql_database_engine + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''InnoDB''' - keyword: TABLE - keyword: OVERRIDE - table_reference: @@ -1733,25 +1794,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_mysql_database_engine - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''InnoDB''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_mysql_database_engine + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''InnoDB''' - statement_terminator: ; - statement: - create_database_statement: @@ -1765,25 +1828,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_mysql_database_engine - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''InnoDB''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_mysql_database_engine + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''InnoDB''' - keyword: TABLE - keyword: OVERRIDE - table_reference: @@ -1833,25 +1898,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_mysql_database_engine - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''InnoDB''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_mysql_database_engine + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''InnoDB''' - statement_terminator: ; - statement: - create_database_statement: @@ -1869,25 +1936,27 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: materialized_mysql_database_engine - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''InnoDB''' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: materialized_mysql_database_engine + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''InnoDB''' - keyword: TABLE - keyword: OVERRIDE - table_reference: @@ -1933,28 +2002,30 @@ file: - raw_comparison_operator: = - engine_function: - keyword: MaterializedMySQL - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''localhost:3306''' - - comma: ',' - - expression: - - quoted_literal: '''db''' - - comma: ',' - - expression: - - quoted_literal: '''user''' - - comma: ',' - - expression: - - quoted_literal: '''***''' - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: allows_query_when_mysql_lost - - comparison_operator: - - raw_comparison_operator: = - - naked_identifier: 'true' - - comma: ',' - - naked_identifier: max_wait_time_when_mysql_unavailable - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '10000' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''localhost:3306''' + - comma: ',' + - expression: + - quoted_literal: '''db''' + - comma: ',' + - expression: + - quoted_literal: '''user''' + - comma: ',' + - expression: + - quoted_literal: '''***''' + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: allows_query_when_mysql_lost + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: 'true' + - comma: ',' + - naked_identifier: max_wait_time_when_mysql_unavailable + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10000' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_materialized_view.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_materialized_view.yml index 2406a9601..ef3199265 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_materialized_view.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_materialized_view.yml @@ -125,9 +125,10 @@ file: - table_engine_function: - function_name: - function_name_identifier: MergeTree - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - keyword: AS - select_statement: - select_clause: @@ -161,9 +162,10 @@ file: - table_engine_function: - function_name: - function_name_identifier: MergeTree - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - keyword: AS - select_statement: - select_clause: @@ -197,9 +199,10 @@ file: - table_engine_function: - function_name: - function_name_identifier: MergeTree - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - keyword: POPULATE - keyword: AS - select_statement: @@ -272,9 +275,10 @@ file: - table_engine_function: - function_name: - function_name_identifier: MergeTree - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - merge_tree_order_by_clause: - keyword: ORDER - keyword: BY @@ -316,9 +320,10 @@ file: - table_engine_function: - function_name: - function_name_identifier: MergeTree - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - merge_tree_order_by_clause: - keyword: ORDER - keyword: BY @@ -361,9 +366,10 @@ file: - table_engine_function: - function_name: - function_name_identifier: MergeTree - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - merge_tree_order_by_clause: - keyword: ORDER - keyword: BY @@ -406,9 +412,10 @@ file: - table_engine_function: - function_name: - function_name_identifier: MergeTree - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - merge_tree_order_by_clause: - keyword: ORDER - keyword: BY @@ -587,9 +594,10 @@ file: - table_engine_function: - function_name: - function_name_identifier: MergeTree - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - merge_tree_order_by_clause: - keyword: ORDER - keyword: BY @@ -629,14 +637,15 @@ file: - table_engine_function: - function_name: - function_name_identifier: ReplicatedReplacingMergeTree - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''/clickhouse/tables/{shard}/my_view_6''' - - comma: ',' - - expression: - - quoted_literal: '''{replica}''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''/clickhouse/tables/{shard}/my_view_6''' + - comma: ',' + - expression: + - quoted_literal: '''{replica}''' + - end_bracket: ) - keyword: PARTITION - keyword: BY - expression: @@ -671,11 +680,12 @@ file: - keyword: INTERVAL - numeric_literal: '1' - date_part: MONTH - - keyword: SETTINGS - - naked_identifier: index_granularity - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '8192' + - settings_clause: + - keyword: SETTINGS + - naked_identifier: index_granularity + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '8192' - keyword: AS - select_statement: - select_clause: @@ -745,9 +755,10 @@ file: - table_engine_function: - function_name: - function_name_identifier: SummingMergeTree - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - merge_tree_order_by_clause: - keyword: ORDER - keyword: BY @@ -783,7 +794,8 @@ file: - naked_identifier: value - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: total_value - comma: ',' - select_clause_element: @@ -795,7 +807,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: count - comma: ',' - select_clause_element: @@ -810,7 +823,8 @@ file: - naked_identifier: value - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: avg_value - from_clause: - keyword: FROM @@ -914,7 +928,8 @@ file: - column_reference: - naked_identifier: _timestamp_ms - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: processedAt - from_clause: - keyword: FROM @@ -959,7 +974,8 @@ file: - column_reference: - naked_identifier: _timestamp_ms - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: processedAt - comma: ',' - select_clause_element: @@ -968,7 +984,8 @@ file: - dot: . - naked_identifier: measuredAt - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: measuredAt - comma: ',' - select_clause_element: @@ -977,7 +994,8 @@ file: - dot: . - naked_identifier: value - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: value - comma: ',' - select_clause_element: @@ -986,7 +1004,8 @@ file: - dot: . - naked_identifier: name - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: name - from_clause: - keyword: FROM @@ -1037,7 +1056,8 @@ file: - column_reference: - naked_identifier: _ingestedAt - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: ingestedAt - comma: ',' - select_clause_element: @@ -1065,7 +1085,8 @@ file: - naked_identifier: ingestedAt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: _ingestedAt - comma: ',' - select_clause_element: @@ -1084,7 +1105,8 @@ file: - naked_identifier: objectIdentfier - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: objectList - from_clause: - keyword: FROM @@ -1138,7 +1160,8 @@ file: - column_reference: - naked_identifier: _ingestedAt - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: ingestedAt - comma: ',' - select_clause_element: @@ -1174,7 +1197,8 @@ file: - naked_identifier: ingestedAt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: _ingestedAt - comma: ',' - select_clause_element: @@ -1186,7 +1210,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: valueCount - comma: ',' - select_clause_element: @@ -1226,7 +1251,8 @@ file: - numeric_literal: '1000' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: cumulativeLagSeconds - from_clause: - keyword: FROM @@ -1276,21 +1302,24 @@ file: - column_reference: - naked_identifier: _topic - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: topic - comma: ',' - select_clause_element: - column_reference: - naked_identifier: _partition - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: kafka_partition - comma: ',' - select_clause_element: - column_reference: - naked_identifier: _offset - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: offset - comma: ',' - select_clause_element: @@ -1314,21 +1343,24 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: processedAt - comma: ',' - select_clause_element: - column_reference: - naked_identifier: _raw_message - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: raw_message - comma: ',' - select_clause_element: - column_reference: - naked_identifier: _error - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: error - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_table.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_table.yml index ea6d16d77..f4edf3f36 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_table.yml @@ -24,9 +24,10 @@ file: - table_engine_function: - function_name: - function_name_identifier: MergeTree - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - merge_tree_order_by_clause: - keyword: order - keyword: by @@ -69,9 +70,10 @@ file: - table_engine_function: - function_name: - function_name_identifier: MergeTree - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - merge_tree_order_by_clause: - keyword: ORDER - keyword: BY @@ -96,11 +98,12 @@ file: - column_reference: - naked_identifier: EventDate - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: index_granularity - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '8192' + - settings_clause: + - keyword: SETTINGS + - naked_identifier: index_granularity + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '8192' - statement_terminator: ; - statement: - create_table_statement: @@ -137,25 +140,26 @@ file: - table_engine_function: - function_name: - function_name_identifier: MergeTree - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: date - - comma: ',' - - expression: - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: UserId - - comma: ',' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: - column_reference: - - naked_identifier: EventType - - end_bracket: ) - - comma: ',' - - expression: - - numeric_literal: '8192' - - end_bracket: ) + - naked_identifier: date + - comma: ',' + - expression: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: UserId + - comma: ',' + - column_reference: + - naked_identifier: EventType + - end_bracket: ) + - comma: ',' + - expression: + - numeric_literal: '8192' + - end_bracket: ) - statement_terminator: ; - statement: - create_table_statement: @@ -208,11 +212,12 @@ file: - column_reference: - naked_identifier: EventType - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: index_granularity - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '8192' + - settings_clause: + - keyword: SETTINGS + - naked_identifier: index_granularity + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '8192' - statement_terminator: ; - statement: - create_table_statement: @@ -230,20 +235,21 @@ file: - table_engine_function: - function_name: - function_name_identifier: Merge - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: currentDatabase - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) - - comma: ',' - - expression: - - quoted_literal: '''^WatchLog''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: currentDatabase + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - expression: + - quoted_literal: '''^WatchLog''' + - end_bracket: ) - statement_terminator: ; - statement: - create_table_statement: @@ -261,20 +267,21 @@ file: - table_engine_function: - function_name: - function_name_identifier: Merge - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: currentDatabase - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) - - comma: ',' - - expression: - - quoted_literal: '''^WatchLog''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: currentDatabase + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - expression: + - quoted_literal: '''^WatchLog''' + - end_bracket: ) - statement_terminator: ; - statement: - create_table_statement: @@ -292,30 +299,32 @@ file: - table_engine_function: - function_name: - function_name_identifier: Distributed - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: logs - - comma: ',' - - expression: - - column_reference: - - naked_identifier: default - - comma: ',' - - expression: - - column_reference: - - naked_identifier: hits - - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: fsync_after_insert - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '0' - - comma: ',' - - naked_identifier: fsync_directories - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '0' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: logs + - comma: ',' + - expression: + - column_reference: + - naked_identifier: default + - comma: ',' + - expression: + - column_reference: + - naked_identifier: hits + - end_bracket: ) + - settings_clause: + - keyword: SETTINGS + - naked_identifier: fsync_after_insert + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - comma: ',' + - naked_identifier: fsync_directories + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' - statement_terminator: ; - statement: - create_table_statement: @@ -399,9 +408,10 @@ file: - table_engine_function: - function_name: - function_name_identifier: MergeTree - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - statement_terminator: ; - statement: - create_table_statement: @@ -568,20 +578,21 @@ file: - table_engine_function: - function_name: - function_name_identifier: Distributed - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: cluster - - comma: ',' - - expression: - - column_reference: - - naked_identifier: default - - comma: ',' - - expression: - - column_reference: - - naked_identifier: hits - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: cluster + - comma: ',' + - expression: + - column_reference: + - naked_identifier: default + - comma: ',' + - expression: + - column_reference: + - naked_identifier: hits + - end_bracket: ) - statement_terminator: ; - statement: - create_table_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_user.sql b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_user.sql new file mode 100644 index 000000000..dff3c07a5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_user.sql @@ -0,0 +1,7 @@ +-- This file tests CREATE USER with/without IDENTIFIED BY for ClickHouse dialect +-- sqlfluff:dialect:clickhouse + +CREATE USER new_user IDENTIFIED BY 'secret'; +CREATE USER another_user IDENTIFIED WITH sha256_password BY 'hash'; + +CREATE USER yet_another_user; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_user.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_user.yml new file mode 100644 index 000000000..34679bdcb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_user.yml @@ -0,0 +1,27 @@ +file: +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - naked_identifier: new_user + - keyword: IDENTIFIED + - keyword: BY + - quoted_literal: '''secret''' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - naked_identifier: another_user + - keyword: IDENTIFIED + - keyword: WITH + - naked_identifier: sha256_password + - keyword: BY + - quoted_literal: '''hash''' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - naked_identifier: yet_another_user +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_view.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_view.yml index ded8685e1..b631f70d4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_view.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/create_view.yml @@ -1,236 +1,229 @@ file: - statement: - create_view_statement: - - create_view_statement: - - keyword: CREATE - - keyword: VIEW - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: view_mv - - keyword: AS - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: column1 - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: column2 - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: table_kafka + - keyword: CREATE + - keyword: VIEW + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: view_mv + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: column2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: table_kafka - statement_terminator: ; - statement: - create_view_statement: - - create_view_statement: - - keyword: CREATE - - keyword: VIEW - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: view_mv - - on_cluster_clause: - - keyword: ON - - keyword: CLUSTER - - naked_identifier: mycluster - - keyword: AS - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: column1 - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: column2 - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: table_kafka + - keyword: CREATE + - keyword: VIEW + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: view_mv + - on_cluster_clause: + - keyword: ON + - keyword: CLUSTER + - naked_identifier: mycluster + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: column2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: table_kafka - statement_terminator: ; - statement: - create_view_statement: - - create_view_statement: - - keyword: CREATE - - keyword: OR - - keyword: REPLACE - - keyword: VIEW - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: view_mv - - keyword: AS - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: column1 - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: column2 - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: table_kafka + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: VIEW + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: view_mv + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: column2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: table_kafka - statement_terminator: ; - statement: - create_view_statement: - - create_view_statement: - - keyword: CREATE - - keyword: OR - - keyword: REPLACE - - keyword: VIEW - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: view_mv - - on_cluster_clause: - - keyword: ON - - keyword: CLUSTER - - naked_identifier: mycluster - - keyword: AS - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: column1 - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: column2 - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: table_kafka + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: VIEW + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: view_mv + - on_cluster_clause: + - keyword: ON + - keyword: CLUSTER + - naked_identifier: mycluster + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: column2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: table_kafka - statement_terminator: ; - statement: - create_view_statement: - - create_view_statement: - - keyword: CREATE - - keyword: VIEW - - keyword: IF - - keyword: NOT - - keyword: EXISTS - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: view_mv - - keyword: AS - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: column1 - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: column2 - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: table_kafka + - keyword: CREATE + - keyword: VIEW + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: view_mv + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: column2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: table_kafka - statement_terminator: ; - statement: - create_view_statement: - - create_view_statement: - - keyword: CREATE - - keyword: VIEW - - keyword: IF - - keyword: NOT - - keyword: EXISTS - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: view_mv - - keyword: AS - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: column1 - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: column2 - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: table_kafka + - keyword: CREATE + - keyword: VIEW + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: view_mv + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: column2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: table_kafka - statement_terminator: ; - statement: - create_view_statement: - - create_view_statement: - - keyword: CREATE - - keyword: VIEW - - keyword: IF - - keyword: NOT - - keyword: EXISTS - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: view_mv - - on_cluster_clause: - - keyword: ON - - keyword: CLUSTER - - naked_identifier: mycluster - - keyword: AS - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: column1 - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: column2 - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: table_kafka + - keyword: CREATE + - keyword: VIEW + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: view_mv + - on_cluster_clause: + - keyword: ON + - keyword: CLUSTER + - naked_identifier: mycluster + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: column2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: table_kafka - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/cte.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/cte.yml index 49c394ef9..5430c7333 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/cte.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/cte.yml @@ -13,7 +13,8 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: p - end_bracket: ) - keyword: as @@ -32,7 +33,8 @@ file: - numeric_literal: '1' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: Test_string - comma: ',' - select_clause_element: @@ -49,7 +51,8 @@ file: - numeric_literal: '3' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: Test_dateTime64 - comma: ',' - select_clause_element: @@ -66,7 +69,8 @@ file: - quoted_literal: '''TestNull''' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: testIf - comma: ',' - select_clause_element: @@ -83,14 +87,16 @@ file: - quoted_literal: '''abc''' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: testJSON - comma: ',' - select_clause_element: - column_reference: - naked_identifier: test_param - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: param - statement_terminator: ; - statement: @@ -260,7 +266,8 @@ file: - binary_operator: '*' - numeric_literal: '100' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: table_disk_usage - comma: ',' - select_clause_element: @@ -288,7 +295,8 @@ file: - keyword: DESC - limit_clause: - keyword: LIMIT - - numeric_literal: '10' + - limit_clause_component: + - numeric_literal: '10' - statement_terminator: ; - statement: - with_compound_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/datetime64_precision.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/datetime64_precision.yml index 750b5b544..3bfcf80de 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/datetime64_precision.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/datetime64_precision.yml @@ -11,7 +11,8 @@ file: - data_type: - data_type_identifier: DateTime64 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: datetime - statement_terminator: ; - statement: @@ -29,7 +30,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: datetime - statement_terminator: ; - statement: @@ -48,7 +50,8 @@ file: - numeric_literal: '3' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: datetime - statement_terminator: ; - statement: @@ -69,7 +72,8 @@ file: - quoted_literal: '''Europe/Paris''' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: datetime - statement_terminator: ; - statement: @@ -88,6 +92,7 @@ file: - numeric_literal: '6' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: datetime - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/decimal_support.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/decimal_support.yml index 36f97c91f..39f23ca81 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/decimal_support.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/decimal_support.yml @@ -17,13 +17,16 @@ file: - bracketed_arguments: - bracketed: - start_bracket: ( - - numeric_literal: '12' + - data_type: + - numeric_literal: '12' - comma: ',' - - numeric_literal: '0' + - data_type: + - numeric_literal: '0' - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_value - statement_terminator: ; - statement: @@ -47,7 +50,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_value - statement_terminator: ; - statement: @@ -71,7 +75,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_value - statement_terminator: ; - statement: @@ -95,7 +100,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_value - statement_terminator: ; - statement: @@ -119,7 +125,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_value - statement_terminator: ; - statement: @@ -136,12 +143,15 @@ file: - bracketed_arguments: - bracketed: - start_bracket: ( - - numeric_literal: '12' + - data_type: + - numeric_literal: '12' - comma: ',' - - numeric_literal: '0' + - data_type: + - numeric_literal: '0' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_value - statement_terminator: ; - statement: @@ -162,12 +172,15 @@ file: - bracketed_arguments: - bracketed: - start_bracket: ( - - numeric_literal: '12' + - data_type: + - numeric_literal: '12' - comma: ',' - - numeric_literal: '0' + - data_type: + - numeric_literal: '0' - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_value - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/drop_statement.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/drop_statement.yml index d46ca9c1b..eda0383d2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/drop_statement.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/drop_statement.yml @@ -132,13 +132,13 @@ file: - naked_identifier: cluster_name - statement_terminator: ; - statement: - - drop_role_statement: + - drop_user_statement: - keyword: DROP - keyword: ROLE - naked_identifier: role_name - statement_terminator: ; - statement: - - drop_role_statement: + - drop_user_statement: - keyword: DROP - keyword: ROLE - keyword: IF @@ -146,7 +146,7 @@ file: - naked_identifier: role_name - statement_terminator: ; - statement: - - drop_role_statement: + - drop_user_statement: - keyword: DROP - keyword: ROLE - naked_identifier: role_name diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/final.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/final.yml index 40f459eb6..c74bd966a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/final.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/final.yml @@ -48,7 +48,8 @@ file: - dot: . - naked_identifier: parts - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: table_alias - keyword: final - where_clause: diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/format.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/format.yml index dc828ef68..ce701d57e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/format.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/format.yml @@ -13,8 +13,9 @@ file: - table_expression: - table_reference: - naked_identifier: toto - - keyword: FORMAT - - word: CSV + - format_clause: + - keyword: FORMAT + - keyword: CSV - statement_terminator: ; - statement: - select_statement: @@ -22,8 +23,9 @@ file: - keyword: SELECT - select_clause_element: - numeric_literal: '1' - - keyword: FORMAT - - word: CSV + - format_clause: + - keyword: FORMAT + - keyword: CSV - statement_terminator: ; - statement: - select_statement: @@ -32,10 +34,12 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: test - - keyword: FORMAT - - word: CSV + - format_clause: + - keyword: FORMAT + - keyword: CSV - statement_terminator: ; - statement: - select_statement: @@ -59,8 +63,9 @@ file: - comparison_operator: - raw_comparison_operator: = - quoted_literal: '''1''' - - keyword: FORMAT - - word: CSV + - format_clause: + - keyword: FORMAT + - keyword: CSV - statement_terminator: ; - statement: - select_statement: @@ -84,11 +89,13 @@ file: - comparison_operator: - raw_comparison_operator: = - quoted_literal: '''1''' - - keyword: FORMAT - - word: CSV - - keyword: SETTINGS - - naked_identifier: format_csv_delimiter - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: ''',''' + - format_clause: + - keyword: FORMAT + - keyword: CSV + - settings_clause: + - keyword: SETTINGS + - naked_identifier: format_csv_delimiter + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: ''',''' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/identifier.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/identifier.yml index b3a619dfe..ef08f9748 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/identifier.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/identifier.yml @@ -43,7 +43,8 @@ file: - column_reference: - naked_identifier: bar - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: _1 - from_clause: - keyword: FROM @@ -91,6 +92,7 @@ file: - dot: . - naked_identifier: bar - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: _1 - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/in_table_cte.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/in_table_cte.yml index d276d6f8b..d8eb909d0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/in_table_cte.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/in_table_cte.yml @@ -164,7 +164,8 @@ file: - numeric_literal: '0' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: in_array_flag - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/interval.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/interval.yml index 2e4c882b3..88dfffab1 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/interval.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/interval.yml @@ -356,7 +356,8 @@ file: - dot: . - naked_identifier: tbl2 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: db2_tbl2 - join_on_condition: - keyword: on diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/into_outfile.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/into_outfile.yml index 6f004dabd..f238932ca 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/into_outfile.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/into_outfile.yml @@ -5,9 +5,10 @@ file: - keyword: SELECT - select_clause_element: - numeric_literal: '1' - - keyword: INTO - - keyword: OUTFILE - - quoted_literal: '''/tmp/test''' + - into_outfile_clause: + - keyword: INTO + - keyword: OUTFILE + - quoted_literal: '''/tmp/test''' - statement_terminator: ; - statement: - select_statement: @@ -16,13 +17,16 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: test - - keyword: INTO - - keyword: OUTFILE - - quoted_literal: '''/tmp/test''' - - keyword: FORMAT - - word: TabSeparated + - into_outfile_clause: + - keyword: INTO + - keyword: OUTFILE + - quoted_literal: '''/tmp/test''' + - format_clause: + - keyword: FORMAT + - keyword: TabSeparated - statement_terminator: ; - statement: - select_statement: @@ -46,11 +50,13 @@ file: - comparison_operator: - raw_comparison_operator: = - quoted_literal: '''1''' - - keyword: INTO - - keyword: OUTFILE - - quoted_literal: '''/tmp/test''' - - keyword: FORMAT - - word: TabSeparated + - into_outfile_clause: + - keyword: INTO + - keyword: OUTFILE + - quoted_literal: '''/tmp/test''' + - format_clause: + - keyword: FORMAT + - keyword: TabSeparated - statement_terminator: ; - statement: - select_statement: @@ -66,9 +72,11 @@ file: - table_expression: - table_reference: - naked_identifier: dual - - keyword: INTO - - keyword: OUTFILE - - quoted_literal: '''/tmp/test''' - - keyword: FORMAT - - word: CSV + - into_outfile_clause: + - keyword: INTO + - keyword: OUTFILE + - quoted_literal: '''/tmp/test''' + - format_clause: + - keyword: FORMAT + - keyword: CSV - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/join.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/join.yml index a2495efcc..3a703229a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/join.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/join.yml @@ -717,7 +717,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: LEFT @@ -748,7 +749,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: LEFT @@ -779,7 +781,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: LEFT @@ -810,7 +813,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: LEFT @@ -880,7 +884,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -912,7 +917,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -944,7 +950,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -976,7 +983,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -1046,7 +1054,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: SEMI @@ -1077,7 +1086,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: ANY @@ -1108,7 +1118,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: ALL @@ -1139,7 +1150,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: ASOF @@ -1212,7 +1224,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -1244,7 +1257,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -1276,7 +1290,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -1308,7 +1323,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -1343,7 +1359,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: LEFT @@ -1374,7 +1391,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: LEFT @@ -1445,7 +1463,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: LEFT @@ -1477,7 +1496,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: LEFT @@ -1509,7 +1529,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: LEFT @@ -1541,7 +1562,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: LEFT @@ -1573,7 +1595,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -1605,7 +1628,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -1678,7 +1702,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -1711,7 +1736,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -1744,7 +1770,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -1777,7 +1804,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -1921,7 +1949,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: RIGHT @@ -1952,7 +1981,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: RIGHT @@ -1983,7 +2013,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: RIGHT @@ -2053,7 +2084,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -2085,7 +2117,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -2117,7 +2150,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -2187,7 +2221,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: SEMI @@ -2218,7 +2253,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: ANY @@ -2249,7 +2285,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: ALL @@ -2319,7 +2356,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -2351,7 +2389,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -2383,7 +2422,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -2415,7 +2455,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: RIGHT @@ -2446,7 +2487,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: RIGHT @@ -2478,7 +2520,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: RIGHT @@ -2510,7 +2553,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: RIGHT @@ -2542,7 +2586,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: RIGHT @@ -2574,7 +2619,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -2606,7 +2652,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -2639,7 +2686,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -2672,7 +2720,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -2705,7 +2754,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -2860,7 +2910,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: FULL @@ -2891,7 +2942,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: FULL @@ -2921,7 +2973,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: FULL @@ -2953,7 +3006,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -2985,7 +3039,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -3016,7 +3071,8 @@ file: - table_reference: - naked_identifier: test1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t1 - join_clause: - keyword: GLOBAL @@ -3117,7 +3173,8 @@ file: - naked_identifier: test1 - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t2 - array_join_clause: - keyword: ARRAY @@ -3126,7 +3183,8 @@ file: - column_reference: - naked_identifier: arr - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -3154,11 +3212,13 @@ file: - numeric_literal: '2' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: arr - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t1 - array_join_clause: - keyword: LEFT @@ -3168,7 +3228,8 @@ file: - column_reference: - naked_identifier: arr - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -3197,11 +3258,13 @@ file: - numeric_literal: '2' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: arr - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t1 - array_join_clause: - keyword: ARRAY @@ -3236,11 +3299,13 @@ file: - numeric_literal: '2' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: arr - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t1 - array_join_clause: - keyword: LEFT @@ -3276,7 +3341,8 @@ file: - numeric_literal: '2' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: arr - comma: ',' - select_clause_element: @@ -3287,11 +3353,13 @@ file: - numeric_literal: '4' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: arr2 - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t1 - array_join_clause: - keyword: ARRAY @@ -3333,7 +3401,8 @@ file: - numeric_literal: '2' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: arr - comma: ',' - select_clause_element: @@ -3344,11 +3413,13 @@ file: - numeric_literal: '4' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: arr2 - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t1 - array_join_clause: - keyword: ARRAY @@ -3357,14 +3428,16 @@ file: - column_reference: - naked_identifier: arr - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: x - comma: ',' - select_clause_element: - column_reference: - naked_identifier: arr2 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: y - statement_terminator: ; - statement: @@ -3407,7 +3480,8 @@ file: - quoted_literal: '''2''' - end_square_bracket: ']' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: cg - comma: ',' - select_clause_element: @@ -3424,7 +3498,8 @@ file: - quoted_literal: '''1,2''' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: ch - statement_terminator: ; - statement: @@ -3456,7 +3531,8 @@ file: - naked_identifier: x - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t1 - array_join_clause: - keyword: ARRAY diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/limit_by.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/limit_by.yml index 23a979ea9..ab5b56552 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/limit_by.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/limit_by.yml @@ -13,13 +13,15 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: id - comma: ',' - select_clause_element: - quoted_literal: '''test''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: name - end_bracket: ) - select_statement: @@ -38,9 +40,11 @@ file: - naked_identifier: toto - limit_clause: - keyword: LIMIT - - numeric_literal: '1' + - limit_clause_component: + - numeric_literal: '1' - comma: ',' - - numeric_literal: '2' + - limit_clause_component: + - numeric_literal: '2' - keyword: by - column_reference: - naked_identifier: id @@ -59,13 +63,15 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: id - comma: ',' - select_clause_element: - quoted_literal: '''test''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: name - end_bracket: ) - select_statement: @@ -84,7 +90,8 @@ file: - naked_identifier: toto - limit_clause: - keyword: LIMIT - - numeric_literal: '1' + - limit_clause_component: + - numeric_literal: '1' - keyword: by - column_reference: - naked_identifier: id @@ -103,13 +110,15 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: id - comma: ',' - select_clause_element: - quoted_literal: '''test''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: name - end_bracket: ) - select_statement: @@ -128,9 +137,11 @@ file: - naked_identifier: toto - limit_clause: - keyword: LIMIT - - numeric_literal: '2' + - limit_clause_component: + - numeric_literal: '2' - keyword: OFFSET - - numeric_literal: '1' + - limit_clause_component: + - numeric_literal: '1' - keyword: by - column_reference: - naked_identifier: id @@ -149,13 +160,15 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: id - comma: ',' - select_clause_element: - quoted_literal: '''test''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: name - end_bracket: ) - select_statement: @@ -174,9 +187,11 @@ file: - naked_identifier: toto - limit_clause: - keyword: LIMIT - - numeric_literal: '2' + - limit_clause_component: + - numeric_literal: '2' - comma: ',' - - numeric_literal: '1' + - limit_clause_component: + - numeric_literal: '1' - keyword: by - bracketed: - start_bracket: ( diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/limit_delimited.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/limit_delimited.yml index d1447e8ff..236a89dc4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/limit_delimited.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/limit_delimited.yml @@ -13,13 +13,15 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: id - comma: ',' - select_clause_element: - quoted_literal: '''test''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: name - end_bracket: ) - select_statement: @@ -38,7 +40,8 @@ file: - naked_identifier: toto - limit_clause: - keyword: LIMIT - - numeric_literal: '1' + - limit_clause_component: + - numeric_literal: '1' - statement_terminator: ; - statement: - with_compound_statement: @@ -54,13 +57,15 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: id - comma: ',' - select_clause_element: - quoted_literal: '''test''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: name - end_bracket: ) - select_statement: @@ -79,9 +84,11 @@ file: - naked_identifier: toto - limit_clause: - keyword: LIMIT - - numeric_literal: '1' + - limit_clause_component: + - numeric_literal: '1' - keyword: OFFSET - - numeric_literal: '1' + - limit_clause_component: + - numeric_literal: '1' - statement_terminator: ; - statement: - with_compound_statement: @@ -97,13 +104,15 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: id - comma: ',' - select_clause_element: - quoted_literal: '''test''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: name - end_bracket: ) - select_statement: @@ -122,9 +131,11 @@ file: - naked_identifier: toto - limit_clause: - keyword: LIMIT - - numeric_literal: '1' + - limit_clause_component: + - numeric_literal: '1' - comma: ',' - - numeric_literal: '2' + - limit_clause_component: + - numeric_literal: '2' - statement_terminator: ; - statement: - with_compound_statement: @@ -140,13 +151,15 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: id - comma: ',' - select_clause_element: - quoted_literal: '''test''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: name - end_bracket: ) - select_statement: @@ -165,13 +178,15 @@ file: - naked_identifier: toto - limit_clause: - keyword: LIMIT - - bracketed: - - start_bracket: ( - - numeric_literal: '1' - - end_bracket: ) + - limit_clause_component: + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - end_bracket: ) - comma: ',' - - bracketed: - - start_bracket: ( - - numeric_literal: '2' - - end_bracket: ) + - limit_clause_component: + - bracketed: + - start_bracket: ( + - numeric_literal: '2' + - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/match_support.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/match_support.yml index eeecad2f6..cff230069 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/match_support.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/match_support.yml @@ -36,7 +36,8 @@ file: - select_clause_element: - quoted_literal: '''1''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: id - end_bracket: ) - select_statement: @@ -77,7 +78,8 @@ file: - end_bracket: ) - keyword: end - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: value_as_number - from_clause: - keyword: FROM @@ -101,7 +103,8 @@ file: - select_clause_element: - quoted_literal: '''1''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: id - end_bracket: ) - select_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/order_by_expression.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/order_by_expression.yml index 6d3712eaf..e5108476b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/order_by_expression.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/order_by_expression.yml @@ -45,14 +45,15 @@ file: - table_engine_function: - function_name: - function_name_identifier: ReplicatedMergeTree - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''/clickhouse/{cluster}/databases/{database}/all/tables/{table}''' - - comma: ',' - - expression: - - quoted_literal: '''{replica}''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''/clickhouse/{cluster}/databases/{database}/all/tables/{table}''' + - comma: ',' + - expression: + - quoted_literal: '''{replica}''' + - end_bracket: ) - merge_tree_order_by_clause: - keyword: ORDER - keyword: BY @@ -79,9 +80,10 @@ file: - column_reference: - naked_identifier: uuid - end_bracket: ) - - keyword: SETTINGS - - naked_identifier: index_granularity - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '8192' + - settings_clause: + - keyword: SETTINGS + - naked_identifier: index_granularity + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '8192' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/order_by_with_fill.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/order_by_with_fill.yml index 8eda6dfaf..a3cde6f11 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/order_by_with_fill.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/order_by_with_fill.yml @@ -34,13 +34,15 @@ file: - numeric_literal: '10' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: n - comma: ',' - select_clause_element: - quoted_literal: '''original''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: source - from_clause: - keyword: FROM @@ -72,16 +74,17 @@ file: - keyword: BY - column_reference: - naked_identifier: n - - keyword: WITH - - keyword: FILL - - keyword: FROM - - expression: - - numeric_literal: '0' - - keyword: TO - - expression: - - numeric_literal: '5.51' - - keyword: STEP - - numeric_literal: '0.5' + - with_fill: + - keyword: WITH + - keyword: FILL + - keyword: FROM + - expression: + - numeric_literal: '0' + - keyword: TO + - expression: + - numeric_literal: '5.51' + - keyword: STEP + - numeric_literal: '0.5' - statement_terminator: ; - statement: - select_statement: @@ -107,7 +110,8 @@ file: - numeric_literal: '86400' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: d1 - comma: ',' - select_clause_element: @@ -124,13 +128,15 @@ file: - numeric_literal: '86400' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: d2 - comma: ',' - select_clause_element: - quoted_literal: '''original''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: source - from_clause: - keyword: FROM @@ -165,15 +171,17 @@ file: - keyword: BY - column_reference: - naked_identifier: d2 - - keyword: WITH - - keyword: FILL + - with_fill: + - keyword: WITH + - keyword: FILL - comma: ',' - column_reference: - naked_identifier: d1 - - keyword: WITH - - keyword: FILL - - keyword: STEP - - numeric_literal: '5' + - with_fill: + - keyword: WITH + - keyword: FILL + - keyword: STEP + - numeric_literal: '5' - statement_terminator: ; - statement: - select_statement: @@ -199,7 +207,8 @@ file: - numeric_literal: '86400' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: d1 - comma: ',' - select_clause_element: @@ -216,13 +225,15 @@ file: - numeric_literal: '86400' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: d2 - comma: ',' - select_clause_element: - quoted_literal: '''original''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: source - from_clause: - keyword: FROM @@ -257,15 +268,17 @@ file: - keyword: BY - column_reference: - naked_identifier: d1 - - keyword: WITH - - keyword: FILL - - keyword: STEP - - numeric_literal: '5' + - with_fill: + - keyword: WITH + - keyword: FILL + - keyword: STEP + - numeric_literal: '5' - comma: ',' - column_reference: - naked_identifier: d2 - - keyword: WITH - - keyword: FILL + - with_fill: + - keyword: WITH + - keyword: FILL - statement_terminator: ; - statement: - select_statement: @@ -291,7 +304,8 @@ file: - numeric_literal: '86400' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: d1 - comma: ',' - select_clause_element: @@ -308,13 +322,15 @@ file: - numeric_literal: '86400' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: d2 - comma: ',' - select_clause_element: - quoted_literal: '''original''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: source - from_clause: - keyword: FROM @@ -349,16 +365,18 @@ file: - keyword: BY - column_reference: - naked_identifier: d1 - - keyword: WITH - - keyword: FILL - - keyword: STEP - - interval_expression: - - keyword: INTERVAL - - numeric_literal: '1' - - date_part: DAY + - with_fill: + - keyword: WITH + - keyword: FILL + - keyword: STEP + - interval_expression: + - keyword: INTERVAL + - numeric_literal: '1' + - date_part: DAY - comma: ',' - column_reference: - naked_identifier: d2 - - keyword: WITH - - keyword: FILL + - with_fill: + - keyword: WITH + - keyword: FILL - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/parametric_aggregate_functions.sql b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/parametric_aggregate_functions.sql new file mode 100644 index 000000000..d471230b6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/parametric_aggregate_functions.sql @@ -0,0 +1,55 @@ +SELECT histogram(5)(number + 1) FROM system.numbers LIMIT 20; + +SELECT histogram(10)(value) FROM data; + +SELECT median(value) FROM data; + +SELECT medianBFloat16(value) FROM data; + +SELECT quantile(0.95)(response_time) FROM metrics; + +SELECT quantile(0.5)(price) FROM sales; + +SELECT quantile(price) FROM sales; + +SELECT quantiles(0.25, 0.5, 0.75)(value) FROM data; + +SELECT quantiles(0.01, 0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95, 0.99, 0.999)(click) AS quantiles_click_size +FROM clickhouse_table; + +SELECT + quantiles(0.25, 0.5, 0.75)(col1) AS q1, + quantiles(0.1, 0.9)(col2) AS q2 +FROM table1; + +SELECT quantileBFloat16(0.75)(a), quantileBFloat16(0.75)(b) FROM example_table; + +SELECT quantileDD(0.5)(value) FROM data; + +SELECT quantileDeterministic(0.5)(value, id) FROM test_table; + +SELECT quantileDeterministic(value, 1) FROM test_table; + +SELECT quantilesDeterministic(0.25, 0.5, 0.75)(x, id) FROM test_table; + +SELECT quantileExact(0.95)(value) FROM data; + +SELECT quantilesExact(0.25, 0.5, 0.75, 0.9)(value) FROM data; + +SELECT retention(date = '2020-01-01', date = '2020-01-02', date = '2020-01-03') AS r FROM events; + +SELECT sequenceCount('(?1)(?2)')(timestamp, event_type = 1, event_type = 2) FROM user_events; + +SELECT sequenceMatch('(?1)(?2)')(timestamp, event_type = 1, event_type = 2) FROM user_events; + +SELECT studentTTest(sample_data, sample_index) FROM student_ttest; + +SELECT studentTTest(0.95)(sample_data, sample_index) FROM student_ttest; + +SELECT studentTTestOneSample()(value, 20.0) FROM student_ttest; + +SELECT studentTTestOneSample(value, 20.0) FROM student_ttest; + +SELECT studentTTestOneSample(0.95)(value, 20.0) FROM student_ttest; + +SELECT sumMapFilteredWithOverflow([1, 4, 8])(statusMap.status, statusMap.requests) as summap_overflow, toTypeName(summap_overflow) FROM sum_map; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/parametric_aggregate_functions.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/parametric_aggregate_functions.yml new file mode 100644 index 000000000..903b7dbed --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/parametric_aggregate_functions.yml @@ -0,0 +1,911 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: histogram + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '5' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: number + - binary_operator: + + - numeric_literal: '1' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: system + - dot: . + - naked_identifier: numbers + - limit_clause: + - keyword: LIMIT + - limit_clause_component: + - numeric_literal: '20' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: histogram + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '10' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: value + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: data +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: median + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: value + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: data +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: medianBFloat16 + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: value + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: data +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantile + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.95' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: response_time + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: metrics +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantile + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.5' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: price + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sales +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantile + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: price + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sales +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantiles + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.25' + - comma: ',' + - expression: + - numeric_literal: '0.5' + - comma: ',' + - expression: + - numeric_literal: '0.75' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: value + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: data +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantiles + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.01' + - comma: ',' + - expression: + - numeric_literal: '0.05' + - comma: ',' + - expression: + - numeric_literal: '0.1' + - comma: ',' + - expression: + - numeric_literal: '0.25' + - comma: ',' + - expression: + - numeric_literal: '0.5' + - comma: ',' + - expression: + - numeric_literal: '0.75' + - comma: ',' + - expression: + - numeric_literal: '0.9' + - comma: ',' + - expression: + - numeric_literal: '0.95' + - comma: ',' + - expression: + - numeric_literal: '0.99' + - comma: ',' + - expression: + - numeric_literal: '0.999' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: click + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: quantiles_click_size + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: clickhouse_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantiles + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.25' + - comma: ',' + - expression: + - numeric_literal: '0.5' + - comma: ',' + - expression: + - numeric_literal: '0.75' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: q1 + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantiles + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.1' + - comma: ',' + - expression: + - numeric_literal: '0.9' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: q2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantileBFloat16 + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.75' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: a + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantileBFloat16 + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.75' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: example_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantileDD + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.5' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: value + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: data +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantileDeterministic + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.5' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: value + - comma: ',' + - expression: + - column_reference: + - naked_identifier: id + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantileDeterministic + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: value + - comma: ',' + - expression: + - numeric_literal: '1' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantilesDeterministic + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.25' + - comma: ',' + - expression: + - numeric_literal: '0.5' + - comma: ',' + - expression: + - numeric_literal: '0.75' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - comma: ',' + - expression: + - column_reference: + - naked_identifier: id + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantileExact + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.95' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: value + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: data +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: quantilesExact + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.25' + - comma: ',' + - expression: + - numeric_literal: '0.5' + - comma: ',' + - expression: + - numeric_literal: '0.75' + - comma: ',' + - expression: + - numeric_literal: '0.9' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: value + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: data +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: retention + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: date + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2020-01-01''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: date + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2020-01-02''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: date + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2020-01-03''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: r + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: events +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sequenceCount + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''(?1)(?2)''' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: timestamp + - comma: ',' + - expression: + - column_reference: + - naked_identifier: event_type + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: event_type + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: user_events +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sequenceMatch + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''(?1)(?2)''' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: timestamp + - comma: ',' + - expression: + - column_reference: + - naked_identifier: event_type + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: event_type + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: user_events +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: studentTTest + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: sample_data + - comma: ',' + - expression: + - column_reference: + - naked_identifier: sample_index + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: student_ttest +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: studentTTest + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.95' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: sample_data + - comma: ',' + - expression: + - column_reference: + - naked_identifier: sample_index + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: student_ttest +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: studentTTestOneSample + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: value + - comma: ',' + - expression: + - numeric_literal: '20.0' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: student_ttest +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: studentTTestOneSample + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: value + - comma: ',' + - expression: + - numeric_literal: '20.0' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: student_ttest +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: studentTTestOneSample + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.95' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: value + - comma: ',' + - expression: + - numeric_literal: '20.0' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: student_ttest +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sumMapFilteredWithOverflow + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '8' + - end_square_bracket: ']' + - end_bracket: ) + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: statusMap + - dot: . + - naked_identifier: status + - comma: ',' + - expression: + - column_reference: + - naked_identifier: statusMap + - dot: . + - naked_identifier: requests + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: summap_overflow + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: toTypeName + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: summap_overflow + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sum_map +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/prewhere.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/prewhere.yml index 654191b26..0149cd443 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/prewhere.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/prewhere.yml @@ -15,9 +15,10 @@ file: - table_reference: - naked_identifier: table - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - - pre_where_clause: + - prewhere_clause: - keyword: PREWHERE - expression: - column_reference: @@ -42,9 +43,10 @@ file: - table_reference: - naked_identifier: table - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - - pre_where_clause: + - prewhere_clause: - keyword: PREWHERE - expression: - column_reference: @@ -74,9 +76,10 @@ file: - table_reference: - naked_identifier: table - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - - pre_where_clause: + - prewhere_clause: - keyword: PREWHERE - expression: - column_reference: @@ -112,9 +115,10 @@ file: - table_reference: - naked_identifier: table - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - - pre_where_clause: + - prewhere_clause: - keyword: PREWHERE - expression: - column_reference: @@ -158,9 +162,10 @@ file: - table_reference: - naked_identifier: table - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - - pre_where_clause: + - prewhere_clause: - keyword: PREWHERE - expression: - column_reference: diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/select_with_settings.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/select_with_settings.yml index 7b5aaed13..c989a383e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/select_with_settings.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/select_with_settings.yml @@ -14,11 +14,12 @@ file: - table_expression: - table_reference: - naked_identifier: test1 - - keyword: SETTINGS - - naked_identifier: allow_experimental_window_functions - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1' + - settings_clause: + - keyword: SETTINGS + - naked_identifier: allow_experimental_window_functions + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' - statement_terminator: ; - statement: - select_statement: @@ -43,11 +44,12 @@ file: - comparison_operator: - raw_comparison_operator: = - quoted_literal: '''''' - - keyword: SETTINGS - - naked_identifier: allow_experimental_window_functions - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1' + - settings_clause: + - keyword: SETTINGS + - naked_identifier: allow_experimental_window_functions + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' - statement_terminator: ; - statement: - select_statement: @@ -68,9 +70,10 @@ file: - keyword: ORDER - keyword: BY - numeric_literal: '2' - - keyword: SETTINGS - - naked_identifier: allow_experimental_window_functions - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1' + - settings_clause: + - keyword: SETTINGS + - naked_identifier: allow_experimental_window_functions + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/tuple_datatype.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/tuple_datatype.yml index 03b1426af..5eeb1b6ca 100644 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/tuple_datatype.yml +++ b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqlfluff/tuple_datatype.yml @@ -10,11 +10,9 @@ file: - start_bracket: ( - numeric_literal: '1' - comma: ',' - - column_reference: - - quoted_identifier: '''two''' + - quoted_literal: '''two''' - comma: ',' - - column_reference: - - quoted_identifier: '''2024-01-01''' + - quoted_literal: '''2024-01-01''' - end_bracket: ) - casting_operator: '::' - data_type: @@ -34,7 +32,8 @@ file: - data_type_identifier: Date32 - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: struct - statement_terminator: ; - statement: @@ -48,11 +47,9 @@ file: - start_bracket: ( - numeric_literal: '1' - comma: ',' - - column_reference: - - quoted_identifier: '''two''' + - quoted_literal: '''two''' - comma: ',' - - column_reference: - - quoted_identifier: '''2024-01-01''' + - quoted_literal: '''2024-01-01''' - end_bracket: ) - casting_operator: '::' - data_type: @@ -72,7 +69,8 @@ file: - data_type_identifier: Date32 - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: struct - statement_terminator: ; - statement: @@ -86,16 +84,15 @@ file: - start_bracket: ( - numeric_literal: '1' - comma: ',' - - column_reference: - - quoted_identifier: '''two''' + - quoted_literal: '''two''' - comma: ',' - - column_reference: - - quoted_identifier: '''2024-01-01''' + - quoted_literal: '''2024-01-01''' - end_bracket: ) - casting_operator: '::' - data_type: - quoted_identifier: '`Tuple(id Int64, name String, created_at Date32)`' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: struct - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqruff/alter_table.sql b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqruff/alter_table.sql deleted file mode 100644 index 94cc8f96b..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqruff/alter_table.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE x MODIFY COLUMN col MODIFY SETTING min_compress_block_size = 8192; diff --git a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqruff/alter_table.yml b/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqruff/alter_table.yml deleted file mode 100644 index 321711d2e..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/clickhouse/sqruff/alter_table.yml +++ /dev/null @@ -1,17 +0,0 @@ -file: -- statement: - - alter_table_statement: - - keyword: ALTER - - keyword: TABLE - - table_reference: - - naked_identifier: x - - keyword: MODIFY - - keyword: COLUMN - - naked_identifier: col - - keyword: MODIFY - - keyword: SETTING - - naked_identifier: min_compress_block_size - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '8192' -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_catalog.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_catalog.sql index ac28a8e80..816d7a7bd 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_catalog.sql +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_catalog.sql @@ -1,5 +1,18 @@ -- Transfer ownership of the catalog to another user ALTER CATALOG some_cat OWNER TO `alf@melmak.et`; +ALTER CATALOG some_cat OWNER TO my_group; -- SET is allowed as an optional keyword ALTER CATALOG some_cat SET OWNER TO `alf@melmak.et`; +ALTER CATALOG some_cat SET OWNER TO my_group; + +-- Set and unset catalog tags +ALTER CATALOG some_cat SET TAGS ('tag1'='value1'); +ALTER CATALOG some_cat SET TAGS ('tag2'='value2', 'tag3'='value3'); +ALTER CATALOG some_cat UNSET TAGS ('tag1'); +ALTER CATALOG some_cat UNSET TAGS ('tag2', 'tag3'); + +-- Enable/Inherit/Disable Predictive Optimization +ALTER CATALOG some_cat ENABLE PREDICTIVE OPTIMIZATION; +ALTER CATALOG some_cat INHERIT PREDICTIVE OPTIMIZATION; +ALTER CATALOG some_cat DISABLE PREDICTIVE OPTIMIZATION; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_catalog.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_catalog.yml index 98609c8f9..767cd2a00 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_catalog.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_catalog.yml @@ -1,20 +1,144 @@ file: - statement: - - keyword: ALTER - - keyword: CATALOG - - object_reference: - - naked_identifier: some_cat - - keyword: OWNER - - keyword: TO - - quoted_identifier: '`alf@melmak.et`' -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: CATALOG - - object_reference: - - naked_identifier: some_cat - - keyword: SET - - keyword: OWNER - - keyword: TO - - quoted_identifier: '`alf@melmak.et`' + - alter_catalog_statement: + - keyword: ALTER + - keyword: CATALOG + - catalog_reference: + - naked_identifier: some_cat + - keyword: OWNER + - keyword: TO + - quoted_identifier: '`alf@melmak.et`' +- statement_terminator: ; +- statement: + - alter_catalog_statement: + - keyword: ALTER + - keyword: CATALOG + - catalog_reference: + - naked_identifier: some_cat + - keyword: OWNER + - keyword: TO + - naked_identifier: my_group +- statement_terminator: ; +- statement: + - alter_catalog_statement: + - keyword: ALTER + - keyword: CATALOG + - catalog_reference: + - naked_identifier: some_cat + - keyword: SET + - keyword: OWNER + - keyword: TO + - quoted_identifier: '`alf@melmak.et`' +- statement_terminator: ; +- statement: + - alter_catalog_statement: + - keyword: ALTER + - keyword: CATALOG + - catalog_reference: + - naked_identifier: some_cat + - keyword: SET + - keyword: OWNER + - keyword: TO + - naked_identifier: my_group +- statement_terminator: ; +- statement: + - alter_catalog_statement: + - keyword: ALTER + - keyword: CATALOG + - catalog_reference: + - naked_identifier: some_cat + - keyword: SET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag1''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value1''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_catalog_statement: + - keyword: ALTER + - keyword: CATALOG + - catalog_reference: + - naked_identifier: some_cat + - keyword: SET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag2''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value2''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag3''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value3''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_catalog_statement: + - keyword: ALTER + - keyword: CATALOG + - catalog_reference: + - naked_identifier: some_cat + - keyword: UNSET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag1''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_catalog_statement: + - keyword: ALTER + - keyword: CATALOG + - catalog_reference: + - naked_identifier: some_cat + - keyword: UNSET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag2''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag3''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_catalog_statement: + - keyword: ALTER + - keyword: CATALOG + - catalog_reference: + - naked_identifier: some_cat + - keyword: ENABLE + - keyword: PREDICTIVE + - keyword: OPTIMIZATION +- statement_terminator: ; +- statement: + - alter_catalog_statement: + - keyword: ALTER + - keyword: CATALOG + - catalog_reference: + - naked_identifier: some_cat + - keyword: INHERIT + - keyword: PREDICTIVE + - keyword: OPTIMIZATION +- statement_terminator: ; +- statement: + - alter_catalog_statement: + - keyword: ALTER + - keyword: CATALOG + - catalog_reference: + - naked_identifier: some_cat + - keyword: DISABLE + - keyword: PREDICTIVE + - keyword: OPTIMIZATION - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_database.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_database.sql new file mode 100644 index 000000000..7351e47f6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_database.sql @@ -0,0 +1,27 @@ +-- Transfer ownership of the schema to another user +ALTER SCHEMA some_cat OWNER TO `alf@melmak.et`; +ALTER SCHEMA some_cat OWNER TO my_group; + +-- SET is allowed as an optional keyword +ALTER SCHEMA some_cat SET OWNER TO `alf@melmak.et`; +ALTER SCHEMA some_cat SET OWNER TO my_group; + +-- DATABASE IS ALLOWED INSTEAD OF SCHEMA +ALTER DATABASE some_cat OWNER TO `alf@melmak.et`; +ALTER DATABASE some_cat SET OWNER TO `alf@melmak.et`; +ALTER DATABASE some_cat OWNER TO my_group; +ALTER DATABASE some_cat SET OWNER TO my_group; + +-- Set and unset schema tags +ALTER SCHEMA some_cat SET TAGS ('tag1'='value1'); +ALTER DATABASE some_cat SET TAGS ('tag2'='value2', 'tag3'='value3'); +ALTER DATABASE some_cat UNSET TAGS ('tag1'); +ALTER SCHEMA some_cat UNSET TAGS ('tag2', 'tag3'); + +-- Enable/Inherit/Disable Predictive Optimization +ALTER SCHEMA some_cat ENABLE PREDICTIVE OPTIMIZATION; +ALTER DATABASE some_cat INHERIT PREDICTIVE OPTIMIZATION; +ALTER SCHEMA some_cat DISABLE PREDICTIVE OPTIMIZATION; + +-- -- Add some schema properties +ALTER SCHEMA some_cat SET DBPROPERTIES ('Edited-by'='John Doe', 'Edit-date'='2020-01-01'); diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_database.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_database.yml new file mode 100644 index 000000000..5b326887f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_database.yml @@ -0,0 +1,209 @@ +file: +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: SCHEMA + - database_reference: + - naked_identifier: some_cat + - keyword: OWNER + - keyword: TO + - quoted_identifier: '`alf@melmak.et`' +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: SCHEMA + - database_reference: + - naked_identifier: some_cat + - keyword: OWNER + - keyword: TO + - naked_identifier: my_group +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: SCHEMA + - database_reference: + - naked_identifier: some_cat + - keyword: SET + - keyword: OWNER + - keyword: TO + - quoted_identifier: '`alf@melmak.et`' +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: SCHEMA + - database_reference: + - naked_identifier: some_cat + - keyword: SET + - keyword: OWNER + - keyword: TO + - naked_identifier: my_group +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: some_cat + - keyword: OWNER + - keyword: TO + - quoted_identifier: '`alf@melmak.et`' +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: some_cat + - keyword: SET + - keyword: OWNER + - keyword: TO + - quoted_identifier: '`alf@melmak.et`' +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: some_cat + - keyword: OWNER + - keyword: TO + - naked_identifier: my_group +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: some_cat + - keyword: SET + - keyword: OWNER + - keyword: TO + - naked_identifier: my_group +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: SCHEMA + - database_reference: + - naked_identifier: some_cat + - keyword: SET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag1''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value1''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: some_cat + - keyword: SET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag2''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value2''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag3''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value3''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: some_cat + - keyword: UNSET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag1''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: SCHEMA + - database_reference: + - naked_identifier: some_cat + - keyword: UNSET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag2''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag3''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: SCHEMA + - database_reference: + - naked_identifier: some_cat + - keyword: ENABLE + - keyword: PREDICTIVE + - keyword: OPTIMIZATION +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: some_cat + - keyword: INHERIT + - keyword: PREDICTIVE + - keyword: OPTIMIZATION +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: SCHEMA + - database_reference: + - naked_identifier: some_cat + - keyword: DISABLE + - keyword: PREDICTIVE + - keyword: OPTIMIZATION +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: SCHEMA + - database_reference: + - naked_identifier: some_cat + - keyword: SET + - keyword: DBPROPERTIES + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''Edited-by''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''John Doe''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''Edit-date''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2020-01-01''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_table.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_table.sql index 1674b5e98..06e906c29 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_table.sql +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_table.sql @@ -3,3 +3,109 @@ ALTER TABLE Student RENAME TO StudentInfo; +ALTER TABLE default.StudentInfo PARTITION (age='10') RENAME TO PARTITION (age='15'); + +ALTER TABLE StudentInfo ADD columns (LastName string, DOB timestamp); + +ALTER TABLE StudentInfo ADD COLUMN col_name string; + +ALTER TABLE StudentInfo ADD COLUMN col_name2 string AFTER col_name; + +ALTER TABLE StudentInfo ADD COLUMN col_name3 string COMMENT 'This is a comment'; + +ALTER TABLE StudentInfo ADD COLUMN col_name4 string FIRST; + +ALTER TABLE StudentInfo ADD COLUMN col_name5 string COMMENT 'This is a comment' AFTER existing_col; + +ALTER TABLE StudentInfo ADD COLUMNS col1 string, col2 int; + +ALTER TABLE StudentInfo ADD COLUMN address.street string; + +ALTER TABLE StudentInfo ADD COLUMN complex_col STRUCT; + +ALTER TABLE StudentInfo DROP COLUMN (DOB); + +ALTER TABLE StudentInfo DROP COLUMNS IF EXISTS (LastName, DOB); + +ALTER TABLE StudentInfo ADD IF NOT EXISTS PARTITION (age=18); + +ALTER TABLE StudentInfo DROP IF EXISTS PARTITION (age=18); + +ALTER TABLE StudentInfo ADD IF NOT EXISTS PARTITION (age=18) PARTITION (age=20); + +ALTER TABLE StudentInfo RECOVER PARTITIONS; + +ALTER TABLE StudentInfo ALTER COLUMN name COMMENT "new comment"; + +ALTER TABLE StudentInfo RENAME COLUMN name TO FirstName; + +-- Change the file Location +ALTER TABLE dbx.tab1 PARTITION (a='1', b='2') SET LOCATION '/path/to/part/ways'; + +-- SET SERDE/ SERDE Properties (DBR only) +ALTER TABLE test_tab SET SERDE 'org.apache.hadoop.hive.serde2.columnar.LazyBinaryColumnarSerDe'; + +ALTER TABLE dbx.tab1 SET SERDE 'org.apache.hadoop' WITH SERDEPROPERTIES ('k' = 'v', 'kay' = 'vee'); + +-- SET TABLE PROPERTIES +ALTER TABLE dbx.tab1 SET TBLPROPERTIES ('winner' = 'loser'); + +-- DROP TABLE PROPERTIES +ALTER TABLE dbx.tab1 UNSET TBLPROPERTIES ('winner'); + +-- Drop the "deletion vectors" from a Delta table +ALTER TABLE my_table DROP FEATURE deletionVectors; + +-- 24 hours later +ALTER TABLE my_table DROP FEATURE deletionVectors TRUNCATE HISTORY; + +-- Applies three tags to the table named `test`. +ALTER TABLE test SET TAGS ('tag1' = 'val1', 'tag2' = 'val2', 'tag3' = 'val3'); + +-- Removes three tags from the table named `test`. +ALTER TABLE test UNSET TAGS ('tag1', 'tag2', 'tag3'); + +-- Applies three tags to table `main.schema1.test` column `col1`. +ALTER TABLE main.schema1.test ALTER COLUMN col1 SET TAGS ('tag1' = 'val1', 'tag2' = 'val2', 'tag3' = 'val3'); + +-- Removes three tags from table `main.schema1.test` column `col1`. +ALTER TABLE main.schema1.test ALTER COLUMN col1 UNSET TAGS ('tag1', 'tag2', 'tag3'); + +-- Enables predictive optimization for my_table +ALTER TABLE my_table ENABLE PREDICTIVE OPTIMIZATION; + +ALTER TABLE sales SET ROW FILTER us_filter ON (); + +ALTER TABLE sales SET ROW FILTER us_filter ON (region); + +ALTER TABLE sales DROP ROW FILTER; + +ALTER TABLE users ALTER COLUMN ssn SET MASK ssn_mask; + +ALTER TABLE users ALTER COLUMN ssn SET MASK ssn_mask USING COLUMNS (ssn_value); + +ALTER TABLE users ALTER COLUMN ssn DROP MASK; + +ALTER TABLE persons ADD CONSTRAINT persons_pk PRIMARY KEY(first_name, last_name); + +ALTER TABLE pets ADD CONSTRAINT pets_persons_fk + FOREIGN KEY(owner_first_name, owner_last_name) REFERENCES persons + NOT ENFORCED RELY; + +ALTER TABLE pets ADD CONSTRAINT pets_name_not_cute_chk CHECK (length(name) < 20); + +ALTER TABLE pets DROP CONSTRAINT pets_name_not_cute_chk; + +ALTER TABLE persons DROP CONSTRAINT persons_pk RESTRICT; + +ALTER TABLE pets DROP FOREIGN KEY IF EXISTS (owner_first_name, owner_last_name); + +ALTER TABLE persons DROP PRIMARY KEY CASCADE; + +ALTER TABLE rocks DROP COLUMN rock; + +ALTER TABLE rocks DROP COLUMN rock, loc; + +ALTER TABLE rocks DROP COLUMN IF EXISTS rock, loc; + +ALTER TABLE rocks DROP COLUMN IF EXISTS (rock, loc); diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_table.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_table.yml index a04c5a64a..bd7079b6f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_table.yml @@ -3,10 +3,903 @@ file: - alter_table_statement: - keyword: ALTER - keyword: TABLE - - object_reference: + - table_reference: - naked_identifier: Student - keyword: RENAME - keyword: TO - - object_reference: + - table_reference: + - naked_identifier: StudentInfo +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: default + - dot: . + - naked_identifier: StudentInfo + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - set_clause: + - column_reference: + - naked_identifier: age + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''10''' + - end_bracket: ) + - keyword: RENAME + - keyword: TO + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - set_clause: + - column_reference: + - naked_identifier: age + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''15''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: ADD + - keyword: columns + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: LastName + - data_type: + - primitive_type: + - keyword: string + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: DOB + - data_type: + - primitive_type: + - keyword: timestamp + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: ADD + - keyword: COLUMN + - column_definition: + - column_reference: + - naked_identifier: col_name + - data_type: + - primitive_type: + - keyword: string +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: ADD + - keyword: COLUMN + - column_definition: + - column_reference: + - naked_identifier: col_name2 + - data_type: + - primitive_type: + - keyword: string + - keyword: AFTER + - column_reference: + - naked_identifier: col_name +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: ADD + - keyword: COLUMN + - column_definition: + - column_reference: + - naked_identifier: col_name3 + - data_type: + - primitive_type: + - keyword: string + - column_properties_segment: + - keyword: COMMENT + - quoted_literal: '''This is a comment''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: ADD + - keyword: COLUMN + - column_definition: + - column_reference: + - naked_identifier: col_name4 + - data_type: + - primitive_type: + - keyword: string + - keyword: FIRST +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: ADD + - keyword: COLUMN + - column_definition: + - column_reference: + - naked_identifier: col_name5 + - data_type: + - primitive_type: + - keyword: string + - column_properties_segment: + - keyword: COMMENT + - quoted_literal: '''This is a comment''' + - keyword: AFTER + - column_reference: + - naked_identifier: existing_col +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: ADD + - keyword: COLUMNS + - column_definition: + - column_reference: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: string + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: col2 + - data_type: + - primitive_type: + - keyword: int +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: ADD + - keyword: COLUMN + - column_definition: + - column_reference: + - naked_identifier: address + - dot: . + - naked_identifier: street + - data_type: + - primitive_type: + - keyword: string +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: ADD + - keyword: COLUMN + - column_definition: + - column_reference: + - naked_identifier: complex_col + - data_type: + - struct_type: + - keyword: STRUCT + - struct_type_schema: + - start_angle_bracket: < + - naked_identifier: name + - colon: ':' + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - naked_identifier: age + - colon: ':' + - data_type: + - primitive_type: + - keyword: INT + - end_angle_bracket: '>' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: DROP + - keyword: COLUMN + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: DOB + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: DROP + - keyword: COLUMNS + - keyword: IF + - keyword: EXISTS + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: LastName + - comma: ',' + - column_reference: + - naked_identifier: DOB + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: ADD + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - set_clause: + - column_reference: + - naked_identifier: age + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '18' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: DROP + - keyword: IF + - keyword: EXISTS + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - set_clause: + - column_reference: + - naked_identifier: age + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '18' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: ADD + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - set_clause: + - column_reference: + - naked_identifier: age + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '18' + - end_bracket: ) + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - set_clause: + - column_reference: + - naked_identifier: age + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '20' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: RECOVER + - keyword: PARTITIONS +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: - naked_identifier: StudentInfo + - keyword: ALTER + - keyword: COLUMN + - column_reference: + - naked_identifier: name + - keyword: COMMENT + - quoted_literal: '"new comment"' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: StudentInfo + - keyword: RENAME + - keyword: COLUMN + - column_reference: + - naked_identifier: name + - keyword: TO + - column_reference: + - naked_identifier: FirstName +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: dbx + - dot: . + - naked_identifier: tab1 + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - set_clause: + - column_reference: + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''1''' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: b + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2''' + - end_bracket: ) + - keyword: SET + - keyword: LOCATION + - quoted_literal: '''/path/to/part/ways''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: test_tab + - keyword: SET + - keyword: SERDE + - quoted_literal: '''org.apache.hadoop.hive.serde2.columnar.LazyBinaryColumnarSerDe''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: dbx + - dot: . + - naked_identifier: tab1 + - keyword: SET + - keyword: SERDE + - quoted_literal: '''org.apache.hadoop''' + - keyword: WITH + - keyword: SERDEPROPERTIES + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''k''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''v''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''kay''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''vee''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: dbx + - dot: . + - naked_identifier: tab1 + - keyword: SET + - keyword: TBLPROPERTIES + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''winner''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''loser''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: dbx + - dot: . + - naked_identifier: tab1 + - keyword: UNSET + - keyword: TBLPROPERTIES + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''winner''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: DROP + - keyword: FEATURE + - object_reference: + - naked_identifier: deletionVectors +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: DROP + - keyword: FEATURE + - object_reference: + - naked_identifier: deletionVectors + - keyword: TRUNCATE + - keyword: HISTORY +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: test + - keyword: SET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag1''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''val1''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag2''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''val2''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag3''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''val3''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: test + - keyword: UNSET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag1''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag2''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag3''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: main + - dot: . + - naked_identifier: schema1 + - dot: . + - naked_identifier: test + - keyword: ALTER + - keyword: COLUMN + - column_reference: + - naked_identifier: col1 + - keyword: SET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag1''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''val1''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag2''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''val2''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag3''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''val3''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: main + - dot: . + - naked_identifier: schema1 + - dot: . + - naked_identifier: test + - keyword: ALTER + - keyword: COLUMN + - column_reference: + - naked_identifier: col1 + - keyword: UNSET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag1''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag2''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag3''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: ENABLE + - keyword: PREDICTIVE + - keyword: OPTIMIZATION +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: sales + - keyword: SET + - keyword: ROW + - keyword: FILTER + - object_reference: + - naked_identifier: us_filter + - keyword: ON + - bracketed: + - start_bracket: ( + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: sales + - keyword: SET + - keyword: ROW + - keyword: FILTER + - object_reference: + - naked_identifier: us_filter + - keyword: ON + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: region + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: sales + - keyword: DROP + - keyword: ROW + - keyword: FILTER +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: users + - keyword: ALTER + - keyword: COLUMN + - column_reference: + - naked_identifier: ssn + - keyword: SET + - mask_statement: + - keyword: MASK + - function_name: + - function_name_identifier: ssn_mask +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: users + - keyword: ALTER + - keyword: COLUMN + - column_reference: + - naked_identifier: ssn + - keyword: SET + - mask_statement: + - keyword: MASK + - function_name: + - function_name_identifier: ssn_mask + - keyword: USING + - keyword: COLUMNS + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: ssn_value + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: users + - keyword: ALTER + - keyword: COLUMN + - column_reference: + - naked_identifier: ssn + - keyword: DROP + - keyword: MASK +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: persons + - keyword: ADD + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: persons_pk + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: first_name + - comma: ',' + - column_reference: + - naked_identifier: last_name + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: pets + - keyword: ADD + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: pets_persons_fk + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: owner_first_name + - comma: ',' + - column_reference: + - naked_identifier: owner_last_name + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: persons + - keyword: NOT + - keyword: ENFORCED + - keyword: RELY +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: pets + - keyword: ADD + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: pets_name_not_cute_chk + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: length + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: name + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '20' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: pets + - keyword: DROP + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: pets_name_not_cute_chk +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: persons + - keyword: DROP + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: persons_pk + - keyword: RESTRICT +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: pets + - keyword: DROP + - keyword: FOREIGN + - keyword: KEY + - keyword: IF + - keyword: EXISTS + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: owner_first_name + - comma: ',' + - column_reference: + - naked_identifier: owner_last_name + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: persons + - keyword: DROP + - keyword: PRIMARY + - keyword: KEY + - keyword: CASCADE +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: rocks + - keyword: DROP + - keyword: COLUMN + - column_reference: + - naked_identifier: rock +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: rocks + - keyword: DROP + - keyword: COLUMN + - column_reference: + - naked_identifier: rock + - comma: ',' + - column_reference: + - naked_identifier: loc +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: rocks + - keyword: DROP + - keyword: COLUMN + - keyword: IF + - keyword: EXISTS + - column_reference: + - naked_identifier: rock + - comma: ',' + - column_reference: + - naked_identifier: loc +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: rocks + - keyword: DROP + - keyword: COLUMN + - keyword: IF + - keyword: EXISTS + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: rock + - comma: ',' + - column_reference: + - naked_identifier: loc + - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_view.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_view.sql index 371c96c0f..a4c57db08 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_view.sql +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_view.sql @@ -5,3 +5,30 @@ ALTER VIEW tempsc1.v1 RENAME TO tempsc1.v2; ALTER VIEW IDENTIFIER('tempsc1.v1') RENAME TO IDENTIFIER('tempsc1.v2'); +ALTER VIEW tempsc1.v2 SET TBLPROPERTIES ('created.by.user' = "John", 'created.date' = '01-01-2001' ); + +ALTER VIEW tempsc1.v2 UNSET TBLPROPERTIES (`created`.`by`.`user`, created.date); + +ALTER VIEW tempsc1.v2 AS SELECT * FROM tempsc1.v1; + +ALTER VIEW v1 OWNER TO `alf@melmak.et`; + +ALTER VIEW v1 SET OWNER TO `alf@melmak.et`; + +ALTER VIEW v1 WITH SCHEMA BINDING; +ALTER VIEW v1 WITH SCHEMA COMPENSATION; +ALTER VIEW v1 WITH SCHEMA TYPE EVOLUTION; +ALTER VIEW v1 WITH SCHEMA EVOLUTION; + +ALTER MATERIALIZED VIEW my_mv + ADD SCHEDULE CRON '0 0 0 * * ? *' AT TIME ZONE 'America/Los_Angeles'; + +ALTER MATERIALIZED VIEW my_mv + ALTER SCHEDULE CRON '0 0/15 * * * ? *'; + +ALTER MATERIALIZED VIEW my_mv + DROP SCHEDULE; + +ALTER VIEW test SET TAGS ('tag1' = 'val1', 'tag2' = 'val2', 'tag3' = 'val3'); + +ALTER VIEW test UNSET TAGS ('tag1', 'tag2', 'tag3'); diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_view.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_view.yml index 543ffafff..3d1d004a4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_view.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_view.yml @@ -3,13 +3,13 @@ file: - alter_view_statement: - keyword: ALTER - keyword: VIEW - - object_reference: + - table_reference: - naked_identifier: tempsc1 - dot: . - naked_identifier: v1 - keyword: RENAME - keyword: TO - - object_reference: + - table_reference: - naked_identifier: tempsc1 - dot: . - naked_identifier: v2 @@ -18,18 +18,247 @@ file: - alter_view_statement: - keyword: ALTER - keyword: VIEW - - object_reference: - - keyword: IDENTIFIER - - bracketed: - - start_bracket: ( - - quoted_identifier: '''tempsc1.v1''' - - end_bracket: ) + - table_reference: + - identifier_clause_segment: + - keyword: IDENTIFIER + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''tempsc1.v1''' + - end_bracket: ) - keyword: RENAME - keyword: TO - - object_reference: - - keyword: IDENTIFIER - - bracketed: - - start_bracket: ( - - quoted_identifier: '''tempsc1.v2''' - - end_bracket: ) + - table_reference: + - identifier_clause_segment: + - keyword: IDENTIFIER + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''tempsc1.v2''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: tempsc1 + - dot: . + - naked_identifier: v2 + - keyword: SET + - keyword: TBLPROPERTIES + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''created.by.user''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"John"' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''created.date''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''01-01-2001''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: tempsc1 + - dot: . + - naked_identifier: v2 + - keyword: UNSET + - keyword: TBLPROPERTIES + - bracketed: + - start_bracket: ( + - property_name_identifier: + - properties_naked_identifier: '`created`' + - dot: . + - properties_naked_identifier: '`by`' + - dot: . + - properties_naked_identifier: '`user`' + - comma: ',' + - property_name_identifier: + - properties_naked_identifier: created + - dot: . + - properties_naked_identifier: date + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: tempsc1 + - dot: . + - naked_identifier: v2 + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tempsc1 + - dot: . + - naked_identifier: v1 +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - keyword: OWNER + - keyword: TO + - quoted_identifier: '`alf@melmak.et`' +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - keyword: SET + - keyword: OWNER + - keyword: TO + - quoted_identifier: '`alf@melmak.et`' +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - keyword: WITH + - keyword: SCHEMA + - keyword: BINDING +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - keyword: WITH + - keyword: SCHEMA + - keyword: COMPENSATION +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - keyword: WITH + - keyword: SCHEMA + - keyword: TYPE + - keyword: EVOLUTION +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - keyword: WITH + - keyword: SCHEMA + - keyword: EVOLUTION +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: MATERIALIZED + - keyword: VIEW + - table_reference: + - naked_identifier: my_mv + - keyword: ADD + - keyword: SCHEDULE + - keyword: CRON + - quoted_literal: '''0 0 0 * * ? *''' + - keyword: AT + - keyword: TIME + - keyword: ZONE + - quoted_literal: '''America/Los_Angeles''' +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: MATERIALIZED + - keyword: VIEW + - table_reference: + - naked_identifier: my_mv + - keyword: ALTER + - keyword: SCHEDULE + - keyword: CRON + - quoted_literal: '''0 0/15 * * * ? *''' +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: MATERIALIZED + - keyword: VIEW + - table_reference: + - naked_identifier: my_mv + - keyword: DROP + - keyword: SCHEDULE +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: test + - keyword: SET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag1''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''val1''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag2''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''val2''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag3''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''val3''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: test + - keyword: UNSET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag1''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag2''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag3''' + - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_volume.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_volume.sql new file mode 100644 index 000000000..417e74ee1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_volume.sql @@ -0,0 +1,16 @@ +-- Rename a volume +ALTER VOLUME some_vol RENAME TO some_new_vol; + +-- Transfer ownership of the volume to another user +ALTER VOLUME some_vol OWNER TO `alf@melmak.et`; +ALTER VOLUME some_vol OWNER TO my_group; + +-- SET is allowed as an optional keyword +ALTER VOLUME some_vol SET OWNER TO `alf@melmak.et`; +ALTER VOLUME some_vol SET OWNER TO my_group; + +-- Set and unset volume tags +ALTER VOLUME some_vol SET TAGS ('tag1'='value1'); +ALTER VOLUME some_vol SET TAGS ('tag2'='value2', 'tag3'='value3'); +ALTER VOLUME some_vol UNSET TAGS ('tag1'); +ALTER VOLUME some_vol UNSET TAGS ('tag2', 'tag3'); diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_volume.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_volume.yml new file mode 100644 index 000000000..ae46b3504 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/alter_volume.yml @@ -0,0 +1,125 @@ +file: +- statement: + - alter_volume_statement: + - keyword: ALTER + - keyword: VOLUME + - volume_reference: + - naked_identifier: some_vol + - keyword: RENAME + - keyword: TO + - volume_reference: + - naked_identifier: some_new_vol +- statement_terminator: ; +- statement: + - alter_volume_statement: + - keyword: ALTER + - keyword: VOLUME + - volume_reference: + - naked_identifier: some_vol + - keyword: OWNER + - keyword: TO + - quoted_identifier: '`alf@melmak.et`' +- statement_terminator: ; +- statement: + - alter_volume_statement: + - keyword: ALTER + - keyword: VOLUME + - volume_reference: + - naked_identifier: some_vol + - keyword: OWNER + - keyword: TO + - naked_identifier: my_group +- statement_terminator: ; +- statement: + - alter_volume_statement: + - keyword: ALTER + - keyword: VOLUME + - volume_reference: + - naked_identifier: some_vol + - keyword: SET + - keyword: OWNER + - keyword: TO + - quoted_identifier: '`alf@melmak.et`' +- statement_terminator: ; +- statement: + - alter_volume_statement: + - keyword: ALTER + - keyword: VOLUME + - volume_reference: + - naked_identifier: some_vol + - keyword: SET + - keyword: OWNER + - keyword: TO + - naked_identifier: my_group +- statement_terminator: ; +- statement: + - alter_volume_statement: + - keyword: ALTER + - keyword: VOLUME + - volume_reference: + - naked_identifier: some_vol + - keyword: SET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag1''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value1''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_volume_statement: + - keyword: ALTER + - keyword: VOLUME + - volume_reference: + - naked_identifier: some_vol + - keyword: SET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag2''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value2''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag3''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value3''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_volume_statement: + - keyword: ALTER + - keyword: VOLUME + - volume_reference: + - naked_identifier: some_vol + - keyword: UNSET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag1''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_volume_statement: + - keyword: ALTER + - keyword: VOLUME + - volume_reference: + - naked_identifier: some_vol + - keyword: UNSET + - keyword: TAGS + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''tag2''' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '''tag3''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/command_terminator.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/command_terminator.sql new file mode 100644 index 000000000..ad6185285 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/command_terminator.sql @@ -0,0 +1,12 @@ +-- Databricks notebook source + +SELECT COL1 FROM TABLE1 + +-- COMMAND ---------- + +SELECT COL2 FROM TABLE2 + +-- COMMAND ---------- + +SELECT COL3 FROM TABLE3; +SELECT COL4 FROM TABLE4; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_hash_end.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/command_terminator.yml similarity index 57% rename from crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_hash_end.yml rename to crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/command_terminator.yml index 1f454dccb..fbaff4ccf 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_hash_end.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/command_terminator.yml @@ -5,38 +5,50 @@ file: - keyword: SELECT - select_clause_element: - column_reference: - - naked_identifier: orders# - - dot: . - - naked_identifier: id# + - naked_identifier: COL1 - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - table_reference: - - object_reference: - - naked_identifier: orders# -- statement_terminator: ; + - naked_identifier: TABLE1 +- statement_terminator: |2 + + + -- COMMAND ---------- +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: COL2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: TABLE2 +- statement_terminator: |2 + + + -- COMMAND ---------- - statement: - select_statement: - select_clause: - keyword: SELECT - select_clause_element: - column_reference: - - naked_identifier: o# - - dot: . - - naked_identifier: total# + - naked_identifier: COL3 - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - table_reference: - - object_reference: - - naked_identifier: orders# - - alias_expression: - - keyword: AS - - naked_identifier: o# + - naked_identifier: TABLE3 - statement_terminator: ; - statement: - select_statement: @@ -44,16 +56,12 @@ file: - keyword: SELECT - select_clause_element: - column_reference: - - naked_identifier: total - - alias_expression: - - keyword: AS - - naked_identifier: amount# + - naked_identifier: COL4 - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - table_reference: - - object_reference: - - naked_identifier: orders# + - naked_identifier: TABLE4 - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/comment_on.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/comment_on.sql index 3b91abfa8..dff1cc4d7 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/comment_on.sql +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/comment_on.sql @@ -17,3 +17,7 @@ COMMENT ON RECIPIENT my_recipient IS 'A good recipient'; COMMENT ON PROVIDER my_provider IS 'A good provider'; COMMENT ON VOLUME my_volume IS 'Huge volume'; + +COMMENT ON COLUMN my_catalog.my_schema.my_table.my_column IS 'This is my column in a catalog'; + +COMMENT ON COLUMN my_column IS 'This is my column'; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/comment_on.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/comment_on.yml index 54ec450be..59914d79e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/comment_on.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/comment_on.yml @@ -1,91 +1,127 @@ file: - statement: - - keyword: COMMENT - - keyword: ON - - keyword: CATALOG - - object_reference: - - naked_identifier: my_catalog - - keyword: IS - - quoted_literal: '''This is my catalog''' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: CATALOG + - catalog_reference: + - naked_identifier: my_catalog + - keyword: IS + - quoted_literal: '''This is my catalog''' - statement_terminator: ; - statement: - - keyword: COMMENT - - keyword: ON - - keyword: CONNECTION - - object_reference: - - naked_identifier: mysql_connection - - keyword: IS - - quoted_literal: '''this is a mysql connection''' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: CONNECTION + - object_reference: + - naked_identifier: mysql_connection + - keyword: IS + - quoted_literal: '''this is a mysql connection''' - statement_terminator: ; - statement: - - keyword: COMMENT - - keyword: ON - - keyword: SCHEMA - - object_reference: - - naked_identifier: my_schema - - keyword: IS - - quoted_literal: '''This is my schema''' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: SCHEMA + - database_reference: + - naked_identifier: my_schema + - keyword: IS + - quoted_literal: '''This is my schema''' - statement_terminator: ; - statement: - - keyword: COMMENT - - keyword: ON - - keyword: DATABASE - - object_reference: - - naked_identifier: my_other_schema - - keyword: IS - - quoted_literal: '''This is my other schema''' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: DATABASE + - database_reference: + - naked_identifier: my_other_schema + - keyword: IS + - quoted_literal: '''This is my other schema''' - statement_terminator: ; - statement: - - keyword: COMMENT - - keyword: ON - - keyword: TABLE - - object_reference: - - naked_identifier: my_table - - keyword: IS - - quoted_literal: '''This is my table''' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: IS + - quoted_literal: '''This is my table''' - statement_terminator: ; - statement: - - keyword: COMMENT - - keyword: ON - - keyword: TABLE - - object_reference: - - naked_identifier: my_table - - keyword: IS - - keyword: 'NULL' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: IS + - keyword: 'NULL' - statement_terminator: ; - statement: - - keyword: COMMENT - - keyword: ON - - keyword: SHARE - - object_reference: - - naked_identifier: my_share - - keyword: IS - - quoted_literal: '''A good share''' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: SHARE + - object_reference: + - naked_identifier: my_share + - keyword: IS + - quoted_literal: '''A good share''' - statement_terminator: ; - statement: - - keyword: COMMENT - - keyword: ON - - keyword: RECIPIENT - - object_reference: - - naked_identifier: my_recipient - - keyword: IS - - quoted_literal: '''A good recipient''' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: RECIPIENT + - object_reference: + - naked_identifier: my_recipient + - keyword: IS + - quoted_literal: '''A good recipient''' - statement_terminator: ; - statement: - - keyword: COMMENT - - keyword: ON - - keyword: PROVIDER - - object_reference: - - naked_identifier: my_provider - - keyword: IS - - quoted_literal: '''A good provider''' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: PROVIDER + - object_reference: + - naked_identifier: my_provider + - keyword: IS + - quoted_literal: '''A good provider''' - statement_terminator: ; - statement: - - keyword: COMMENT - - keyword: ON - - keyword: VOLUME - - object_reference: - - naked_identifier: my_volume - - keyword: IS - - quoted_literal: '''Huge volume''' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: VOLUME + - volume_reference: + - naked_identifier: my_volume + - keyword: IS + - quoted_literal: '''Huge volume''' +- statement_terminator: ; +- statement: + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: COLUMN + - column_reference: + - naked_identifier: my_catalog + - dot: . + - naked_identifier: my_schema + - dot: . + - naked_identifier: my_table + - dot: . + - naked_identifier: my_column + - keyword: IS + - quoted_literal: '''This is my column in a catalog''' +- statement_terminator: ; +- statement: + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: COLUMN + - column_reference: + - naked_identifier: my_column + - keyword: IS + - quoted_literal: '''This is my column''' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_catalog.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_catalog.yml index bd6cb1070..c1a6f77cd 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_catalog.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_catalog.yml @@ -1,27 +1,30 @@ file: - statement: - - keyword: CREATE - - keyword: CATALOG - - object_reference: - - naked_identifier: customer_cat + - create_catalog_statement: + - keyword: CREATE + - keyword: CATALOG + - catalog_reference: + - naked_identifier: customer_cat - statement_terminator: ; - statement: - - keyword: CREATE - - keyword: CATALOG - - keyword: IF - - keyword: NOT - - keyword: EXISTS - - object_reference: - - naked_identifier: customer_cat + - create_catalog_statement: + - keyword: CREATE + - keyword: CATALOG + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - catalog_reference: + - naked_identifier: customer_cat - statement_terminator: ; - statement: - - keyword: CREATE - - keyword: CATALOG - - keyword: IF - - keyword: NOT - - keyword: EXISTS - - object_reference: - - naked_identifier: customer_cat - - keyword: COMMENT - - quoted_literal: '''This is customer catalog''' + - create_catalog_statement: + - keyword: CREATE + - keyword: CATALOG + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - catalog_reference: + - naked_identifier: customer_cat + - keyword: COMMENT + - quoted_literal: '''This is customer catalog''' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_database.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_database.sql new file mode 100644 index 000000000..819f8efe9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_database.sql @@ -0,0 +1,30 @@ +-- Create database with all optional syntax +CREATE DATABASE IF NOT EXISTS database_name +COMMENT "database_comment" +LOCATION "root/database_directory" +WITH DBPROPERTIES ( "property_name" = "property_value"); + +-- Create schema with all optional syntax +CREATE SCHEMA IF NOT EXISTS database_name +COMMENT "database_comment" +LOCATION "root/database_directory" +WITH DBPROPERTIES ( "property_name" = "property_value" ); + +-- Create database `customer_db`. +CREATE DATABASE customer_db; + +-- Create database `customer_db` only if database with same name doesn't exist. +CREATE DATABASE IF NOT EXISTS customer_db; + +-- `Comments`,`Specific Location` and `Database properties`. +CREATE DATABASE IF NOT EXISTS customer_db +COMMENT 'This is customer database' LOCATION '/user' +WITH DBPROPERTIES ("ID" = "001", "Name" = 'John'); + +-- Create `inventory_db` Database +CREATE DATABASE inventory_db +COMMENT 'This database is used to maintain Inventory'; + +-- Create schema with a managed location +CREATE SCHEMA IF NOT EXISTS database_name +MANAGED LOCATION "s3://root_database_bucket/" diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_database.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_database.yml new file mode 100644 index 000000000..71b3b86df --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_database.yml @@ -0,0 +1,117 @@ +file: +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - database_reference: + - naked_identifier: database_name + - keyword: COMMENT + - quoted_literal: '"database_comment"' + - keyword: LOCATION + - quoted_literal: '"root/database_directory"' + - keyword: WITH + - keyword: DBPROPERTIES + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '"property_name"' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"property_value"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: SCHEMA + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - database_reference: + - naked_identifier: database_name + - keyword: COMMENT + - quoted_literal: '"database_comment"' + - keyword: LOCATION + - quoted_literal: '"root/database_directory"' + - keyword: WITH + - keyword: DBPROPERTIES + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '"property_name"' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"property_value"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: customer_db +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - database_reference: + - naked_identifier: customer_db +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - database_reference: + - naked_identifier: customer_db + - keyword: COMMENT + - quoted_literal: '''This is customer database''' + - keyword: LOCATION + - quoted_literal: '''/user''' + - keyword: WITH + - keyword: DBPROPERTIES + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '"ID"' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"001"' + - comma: ',' + - property_name_identifier: + - quoted_identifier: '"Name"' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''John''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: inventory_db + - keyword: COMMENT + - quoted_literal: '''This database is used to maintain Inventory''' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: SCHEMA + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - database_reference: + - naked_identifier: database_name + - keyword: MANAGED + - keyword: LOCATION + - quoted_literal: '"s3://root_database_bucket/"' diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_function.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_function.sql new file mode 100644 index 000000000..b84a5e451 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_function.sql @@ -0,0 +1,106 @@ +-- Create FUNCTION with all optional syntax +CREATE OR REPLACE TEMPORARY FUNCTION IF NOT EXISTS +function_name AS "class_name" USING FILE "resource_locations"; + +-- Create a permanent function called `simple_udf`. +CREATE FUNCTION simple_udf AS 'SimpleUdf' +USING JAR '/tmp/SimpleUdf.jar'; + +-- Created a temporary function. +CREATE TEMPORARY FUNCTION simple_temp_udf AS 'SimpleUdf' +USING JAR '/tmp/SimpleUdf.jar'; + +-- Replace the implementation of `simple_udf` +CREATE OR REPLACE FUNCTION simple_udf AS 'SimpleUdfR' +USING JAR '/tmp/SimpleUdfR.jar'; + +-- Create a permanent function `test_avg` +CREATE FUNCTION test_avg +AS 'org.apache.hadoop.hive.ql.udf.generic.GenericUDAFAverage'; + +---- Create Temporary function `test_avg` +CREATE TEMPORARY FUNCTION test_avg +AS 'org.apache.hadoop.hive.ql.udf.generic.GenericUDAFAverage'; + +-- Create a temporary function with no parameter +CREATE TEMPORARY FUNCTION hello() +RETURNS STRING RETURN 'Hello World!'; + +-- Create a temporary function with no parameter. +CREATE OR REPLACE TEMPORARY FUNCTION function_name() +RETURNS TIMESTAMP LANGUAGE SQL +RETURN SELECT MAX(time) AS time FROM my_table; + +-- Create a permanent function with parameters +CREATE FUNCTION area(x DOUBLE, y DOUBLE) +RETURNS DOUBLE +RETURN x * y; + +-- Compose SQL functions. +CREATE FUNCTION square(x DOUBLE) +RETURNS DOUBLE +RETURN area(x, x); + +-- Create a CTE function +CREATE FUNCTION cte_function(x INT) +RETURNS string +LANGUAGE SQL +RETURN +WITH cte AS (SELECT x AS y) +SELECT * FROM cte; + +-- Create a non-deterministic function +CREATE FUNCTION roll_dice() + RETURNS INT + NOT DETERMINISTIC + CONTAINS SQL + COMMENT 'Roll a single 6 sided die' + RETURN (rand() * 6)::INT + 1; + + +-- Create a non-deterministic function with parameters and defaults +CREATE FUNCTION roll_dice(num_dice INT DEFAULT 1 COMMENT 'number of dice to roll (Default: 1)', + num_sides INT DEFAULT 6 COMMENT 'number of sides per die (Default: 6)') + RETURNS INT + NOT DETERMINISTIC + CONTAINS SQL + COMMENT 'Roll a number of n-sided dice' + RETURN aggregate(sequence(1, roll_dice.num_dice, 1), + 0, + (acc, x) -> (rand() * roll_dice.num_sides)::int, + acc -> acc + roll_dice.num_dice); + +-- Create Python functions +CREATE FUNCTION main.default.greet(s STRING) + RETURNS STRING + LANGUAGE PYTHON + AS $$ + def greet(name): + return "Hello " + name + "!" + + return greet(s) if s else None + $$; + +-- Created Table Valued Function simple +CREATE FUNCTION return_table() +RETURNS TABLE +RETURN +SELECT time FROM my_table +; + +-- Created Table Valued Function with column spec + comment +CREATE FUNCTION return_table() +RETURNS TABLE (col_a string, col_b string comment "asdf") +RETURN +SELECT col_a, col_b FROM my_table +; + + +-- backticked identifier +create or replace function `catalog`.`schema`.`name` ( + param int +) +returns int +return +select param +; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_function.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_function.yml new file mode 100644 index 000000000..312fe101a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_function.yml @@ -0,0 +1,569 @@ +file: +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: TEMPORARY + - keyword: FUNCTION + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - function_name_identifier: function_name + - keyword: AS + - quoted_literal: '"class_name"' + - keyword: USING + - file_keyword: FILE + - quoted_literal: '"resource_locations"' +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name_identifier: simple_udf + - keyword: AS + - quoted_literal: '''SimpleUdf''' + - keyword: USING + - file_keyword: JAR + - quoted_literal: '''/tmp/SimpleUdf.jar''' +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: TEMPORARY + - keyword: FUNCTION + - function_name_identifier: simple_temp_udf + - keyword: AS + - quoted_literal: '''SimpleUdf''' + - keyword: USING + - file_keyword: JAR + - quoted_literal: '''/tmp/SimpleUdf.jar''' +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: FUNCTION + - function_name_identifier: simple_udf + - keyword: AS + - quoted_literal: '''SimpleUdfR''' + - keyword: USING + - file_keyword: JAR + - quoted_literal: '''/tmp/SimpleUdfR.jar''' +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name_identifier: test_avg + - keyword: AS + - quoted_literal: '''org.apache.hadoop.hive.ql.udf.generic.GenericUDAFAverage''' +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: TEMPORARY + - keyword: FUNCTION + - function_name_identifier: test_avg + - keyword: AS + - quoted_literal: '''org.apache.hadoop.hive.ql.udf.generic.GenericUDAFAverage''' +- statement_terminator: ; +- statement: + - create_sql_function_statement: + - keyword: CREATE + - keyword: TEMPORARY + - keyword: FUNCTION + - function_name: + - function_name_identifier: hello + - function_parameter_list_with_comments: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - data_type: + - primitive_type: + - keyword: STRING + - function_definition: + - keyword: RETURN + - expression: + - quoted_literal: '''Hello World!''' +- statement_terminator: ; +- statement: + - create_sql_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: TEMPORARY + - keyword: FUNCTION + - function_name: + - function_name_identifier: function_name + - function_parameter_list_with_comments: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - data_type: + - primitive_type: + - keyword: TIMESTAMP + - function_definition: + - keyword: LANGUAGE + - keyword: SQL + - keyword: RETURN + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: MAX + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: time + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: time + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table +- statement_terminator: ; +- statement: + - create_sql_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - function_name_identifier: area + - function_parameter_list_with_comments: + - bracketed: + - start_bracket: ( + - parameter: x + - data_type: + - primitive_type: + - keyword: DOUBLE + - comma: ',' + - parameter: y + - data_type: + - primitive_type: + - keyword: DOUBLE + - end_bracket: ) + - keyword: RETURNS + - data_type: + - primitive_type: + - keyword: DOUBLE + - function_definition: + - keyword: RETURN + - expression: + - column_reference: + - naked_identifier: x + - binary_operator: '*' + - column_reference: + - naked_identifier: y +- statement_terminator: ; +- statement: + - create_sql_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - function_name_identifier: square + - function_parameter_list_with_comments: + - bracketed: + - start_bracket: ( + - parameter: x + - data_type: + - primitive_type: + - keyword: DOUBLE + - end_bracket: ) + - keyword: RETURNS + - data_type: + - primitive_type: + - keyword: DOUBLE + - function_definition: + - keyword: RETURN + - expression: + - function: + - function_name: + - function_name_identifier: area + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - comma: ',' + - expression: + - column_reference: + - naked_identifier: x + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_sql_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - function_name_identifier: cte_function + - function_parameter_list_with_comments: + - bracketed: + - start_bracket: ( + - parameter: x + - data_type: + - primitive_type: + - keyword: INT + - end_bracket: ) + - keyword: RETURNS + - data_type: + - primitive_type: + - keyword: string + - function_definition: + - keyword: LANGUAGE + - keyword: SQL + - keyword: RETURN + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: cte + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: x + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: y + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: cte +- statement_terminator: ; +- statement: + - create_sql_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - function_name_identifier: roll_dice + - function_parameter_list_with_comments: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - data_type: + - primitive_type: + - keyword: INT + - function_definition: + - keyword: NOT + - keyword: DETERMINISTIC + - keyword: CONTAINS + - keyword: SQL + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''Roll a single 6 sided die''' + - keyword: RETURN + - expression: + - cast_expression: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: rand + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - binary_operator: '*' + - numeric_literal: '6' + - end_bracket: ) + - casting_operator: '::' + - data_type: + - primitive_type: + - keyword: INT + - binary_operator: + + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - create_sql_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - function_name_identifier: roll_dice + - function_parameter_list_with_comments: + - bracketed: + - start_bracket: ( + - parameter: num_dice + - data_type: + - primitive_type: + - keyword: INT + - keyword: DEFAULT + - numeric_literal: '1' + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''number of dice to roll (Default: 1)''' + - comma: ',' + - parameter: num_sides + - data_type: + - primitive_type: + - keyword: INT + - keyword: DEFAULT + - numeric_literal: '6' + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''number of sides per die (Default: 6)''' + - end_bracket: ) + - keyword: RETURNS + - data_type: + - primitive_type: + - keyword: INT + - function_definition: + - keyword: NOT + - keyword: DETERMINISTIC + - keyword: CONTAINS + - keyword: SQL + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''Roll a number of n-sided dice''' + - keyword: RETURN + - expression: + - function: + - function_name: + - function_name_identifier: aggregate + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: sequence + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: roll_dice + - dot: . + - naked_identifier: num_dice + - comma: ',' + - expression: + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - expression: + - numeric_literal: '0' + - comma: ',' + - expression: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: acc + - comma: ',' + - column_reference: + - naked_identifier: x + - end_bracket: ) + - binary_operator: -> + - cast_expression: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: rand + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - binary_operator: '*' + - column_reference: + - naked_identifier: roll_dice + - dot: . + - naked_identifier: num_sides + - end_bracket: ) + - casting_operator: '::' + - data_type: + - primitive_type: + - keyword: int + - comma: ',' + - expression: + - column_reference: + - naked_identifier: acc + - binary_operator: -> + - column_reference: + - naked_identifier: acc + - binary_operator: + + - column_reference: + - naked_identifier: roll_dice + - dot: . + - naked_identifier: num_dice + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_sql_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - naked_identifier: main + - dot: . + - naked_identifier: default + - dot: . + - function_name_identifier: greet + - function_parameter_list_with_comments: + - bracketed: + - start_bracket: ( + - parameter: s + - data_type: + - primitive_type: + - keyword: STRING + - end_bracket: ) + - keyword: RETURNS + - data_type: + - primitive_type: + - keyword: STRING + - function_definition: + - keyword: LANGUAGE + - keyword: PYTHON + - keyword: AS + - udf_body: |- + $$ + def greet(name): + return "Hello " + name + "!" + + return greet(s) if s else None + $$ +- statement_terminator: ; +- statement: + - create_sql_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - function_name_identifier: return_table + - function_parameter_list_with_comments: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - keyword: TABLE + - function_definition: + - keyword: RETURN + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: time + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table +- statement_terminator: ; +- statement: + - create_sql_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - function_name_identifier: return_table + - function_parameter_list_with_comments: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - keyword: TABLE + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col_a + - data_type: + - primitive_type: + - keyword: string + - comma: ',' + - column_reference: + - naked_identifier: col_b + - data_type: + - primitive_type: + - keyword: string + - keyword: comment + - quoted_literal: '"asdf"' + - end_bracket: ) + - function_definition: + - keyword: RETURN + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col_a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col_b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table +- statement_terminator: ; +- statement: + - create_sql_function_statement: + - keyword: create + - keyword: or + - keyword: replace + - keyword: function + - function_name: + - quoted_identifier: '`catalog`' + - dot: . + - quoted_identifier: '`schema`' + - dot: . + - quoted_identifier: '`name`' + - function_parameter_list_with_comments: + - bracketed: + - start_bracket: ( + - parameter: param + - data_type: + - primitive_type: + - keyword: int + - end_bracket: ) + - keyword: returns + - data_type: + - primitive_type: + - keyword: int + - function_definition: + - keyword: return + - expression: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: param +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_private_materialized_view.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_private_materialized_view.sql new file mode 100644 index 000000000..f78e55599 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_private_materialized_view.sql @@ -0,0 +1,19 @@ +CREATE PRIVATE MATERIALIZED VIEW dlt_private_mat_view ( + a STRING COMMENT 'a', + b TIMESTAMP COMMENT 'b' +) +COMMENT 'DLT private materialized view' +AS SELECT + a, + b +FROM live.dlt_bronze; + +CREATE OR REFRESH PRIVATE MATERIALIZED VIEW dlt_refresh_private_mat_view ( + a STRING COMMENT 'a', + b TIMESTAMP COMMENT 'b' +) +COMMENT 'DLT refreshed private materialized view' +AS SELECT + a, + b +FROM live.dlt_bronze; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_private_materialized_view.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_private_materialized_view.yml new file mode 100644 index 000000000..d82606352 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_private_materialized_view.yml @@ -0,0 +1,101 @@ +file: +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: PRIVATE + - keyword: MATERIALIZED + - keyword: VIEW + - table_reference: + - naked_identifier: dlt_private_mat_view + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - data_type: + - primitive_type: + - keyword: STRING + - keyword: COMMENT + - quoted_literal: '''a''' + - comma: ',' + - column_reference: + - naked_identifier: b + - data_type: + - primitive_type: + - keyword: TIMESTAMP + - keyword: COMMENT + - quoted_literal: '''b''' + - end_bracket: ) + - keyword: COMMENT + - quoted_literal: '''DLT private materialized view''' + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: live + - dot: . + - naked_identifier: dlt_bronze +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: REFRESH + - keyword: PRIVATE + - keyword: MATERIALIZED + - keyword: VIEW + - table_reference: + - naked_identifier: dlt_refresh_private_mat_view + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - data_type: + - primitive_type: + - keyword: STRING + - keyword: COMMENT + - quoted_literal: '''a''' + - comma: ',' + - column_reference: + - naked_identifier: b + - data_type: + - primitive_type: + - keyword: TIMESTAMP + - keyword: COMMENT + - quoted_literal: '''b''' + - end_bracket: ) + - keyword: COMMENT + - quoted_literal: '''DLT refreshed private materialized view''' + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: live + - dot: . + - naked_identifier: dlt_bronze +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_table.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_table.sql index 70cd61339..e8fe21a8d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_table.sql +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_table.sql @@ -1,7 +1,13 @@ CREATE TABLE tablename ( id_column INT, - othercolumn STRING + othercolumn STRING, + generated_always_as_expression DATE GENERATED ALWAYS AS (CAST(birth_date AS DATE)), + generated_by_default BIGINT GENERATED BY DEFAULT AS IDENTITY, + generated_always BIGINT GENERATED ALWAYS AS IDENTITY, + generated_column_start_with BIGINT GENERATED ALWAYS AS IDENTITY (START WITH 10), + generated_column_increment_by BIGINT GENERATED ALWAYS AS IDENTITY (INCREMENT BY 5), + generated_column_start_with_increment_by BIGINT GENERATED ALWAYS AS IDENTITY (START WITH 10 INCREMENT BY 5) ) USING DELTA LOCATION "s3://someplace" @@ -12,3 +18,86 @@ OPTIMIZE tablename; OPTIMIZE tablename WHERE date >= current_timestamp() - INTERVAL 1 day ZORDER BY (eventType, eventTime); + + +-- Creates a Delta table +CREATE TABLE student (id INT, name STRING, age INT); + +-- Use data from another table +CREATE TABLE student_copy AS SELECT * FROM student; + +-- Creates a CSV table from an external directory +CREATE TABLE student USING CSV LOCATION '/path/to/csv_files'; + +-- Specify table comment and properties +CREATE TABLE student (id INT, name STRING, age INT) + COMMENT 'this is a comment' + TBLPROPERTIES ('foo'='bar'); + +-- Specify table comment and properties with different clauses order +CREATE TABLE student (id INT, name STRING, age INT) + TBLPROPERTIES ('foo'='bar') + COMMENT 'this is a comment'; + +-- Create partitioned table +CREATE TABLE student (id INT, name STRING, age INT) + PARTITIONED BY (age); + +-- Create a table with a generated column +CREATE TABLE rectangles(a INT, b INT, + area INT GENERATED ALWAYS AS (a * b)); + +-- Create a table with a primary key +CREATE TABLE rectangles(a INT, b INT PRIMARY KEY); + +-- Create a table with a not null primary key +CREATE TABLE rectangles(a INT NOT NULL, b INT NOT NULL PRIMARY KEY); + +-- Create a table with a foreign key relation +CREATE OR REPLACE TABLE TABLE1 ( + DATE_VALUE DATE NOT NULL + CONSTRAINT DATE_CONSTRAINT + FOREIGN KEY REFERENCES TABLE2 +); + +-- Create a table with a column with default value +CREATE TABLE student (id INT, name STRING DEFAULT 'bobby tables', age INT); + +-- Create a table with non nullable column with default value +CREATE TABLE student (id INT, name STRING NOT NULL DEFAULT 'bobby tables', age INT); + +-- Create a table with a default timestamp +CREATE TABLE clock ( + which_time TIMESTAMP DEFAULT current_timestamp() +); + +-- Create a table with mixing default value and constraints +CREATE TABLE clock ( + which_time TIMESTAMP CONSTRAINT clock_pk PRIMARY KEY DEFAULT current_timestamp() NOT NULL +); + +-- Creates a table using identifier +CREATE TABLE IDENTIFIER('student') (id INT, name STRING, age INT); + +CREATE TABLE data_engineering.test_sqlfluff_generated +( + test_generated_always_as_id BIGINT GENERATED ALWAYS AS IDENTITY + , test_generated_default_as_id BIGINT GENERATED BY DEFAULT AS IDENTITY + , test_generated_always_as_id_not_null BIGINT GENERATED ALWAYS AS IDENTITY NOT NULL + , test_generated_default_as_id_not_null BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL + , test_not_null_generated_always_as_id BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY + , test_not_null_generated_default_as_id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY +) +USING DELTA; + +CREATE TABLE cluster_by_table_auto ( + col1 STRING +) +USING DELTA +CLUSTER BY AUTO; + +CREATE TABLE cluster_by_table_none ( + col1 STRING +) +USING DELTA +CLUSTER BY NONE; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_table.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_table.yml index 8e37d6e12..fb5204aea 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_table.yml @@ -3,21 +3,133 @@ file: - create_table_statement: - keyword: CREATE - keyword: TABLE - - object_reference: + - table_reference: - naked_identifier: tablename - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id_column + - column_reference: + - naked_identifier: id_column - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: othercolumn + - column_reference: + - naked_identifier: othercolumn - data_type: - primitive_type: - keyword: STRING + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: generated_always_as_expression + - data_type: + - primitive_type: + - keyword: DATE + - column_properties_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: birth_date + - keyword: AS + - data_type: + - primitive_type: + - keyword: DATE + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: generated_by_default + - data_type: + - primitive_type: + - keyword: BIGINT + - column_properties_segment: + - keyword: GENERATED + - keyword: BY + - keyword: DEFAULT + - keyword: AS + - keyword: IDENTITY + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: generated_always + - data_type: + - primitive_type: + - keyword: BIGINT + - column_properties_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - keyword: IDENTITY + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: generated_column_start_with + - data_type: + - primitive_type: + - keyword: BIGINT + - column_properties_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - keyword: IDENTITY + - bracketed: + - start_bracket: ( + - keyword: START + - keyword: WITH + - numeric_literal: '10' + - end_bracket: ) + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: generated_column_increment_by + - data_type: + - primitive_type: + - keyword: BIGINT + - column_properties_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - keyword: IDENTITY + - bracketed: + - start_bracket: ( + - keyword: INCREMENT + - keyword: BY + - numeric_literal: '5' + - end_bracket: ) + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: generated_column_start_with_increment_by + - data_type: + - primitive_type: + - keyword: BIGINT + - column_properties_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - keyword: IDENTITY + - bracketed: + - start_bracket: ( + - keyword: START + - keyword: WITH + - numeric_literal: '10' + - keyword: INCREMENT + - keyword: BY + - numeric_literal: '5' + - end_bracket: ) - end_bracket: ) - using_clause: - keyword: USING @@ -25,51 +137,687 @@ file: - keyword: DELTA - keyword: LOCATION - quoted_literal: '"s3://someplace"' - - keyword: CLUSTER + - table_cluster_by_clause: + - keyword: CLUSTER + - keyword: BY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id_column + - end_bracket: ) +- statement_terminator: ; +- statement: + - optimize_table_statement: + - keyword: OPTIMIZE + - table_reference: + - naked_identifier: tablename +- statement_terminator: ; +- statement: + - optimize_table_statement: + - keyword: OPTIMIZE + - table_reference: + - naked_identifier: tablename + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: date + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: current_timestamp + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - binary_operator: '-' + - interval_expression: + - keyword: INTERVAL + - interval_literal: + - numeric_literal: '1' + - date_part: day + - keyword: ZORDER + - keyword: BY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: eventType + - comma: ',' + - column_reference: + - naked_identifier: eventTime + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: student + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: id + - data_type: + - primitive_type: + - keyword: INT + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: name + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: age + - data_type: + - primitive_type: + - keyword: INT + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: student_copy + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: student +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: student + - using_clause: + - keyword: USING + - data_source_format: + - keyword: CSV + - keyword: LOCATION + - quoted_literal: '''/path/to/csv_files''' +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: student + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: id + - data_type: + - primitive_type: + - keyword: INT + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: name + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: age + - data_type: + - primitive_type: + - keyword: INT + - end_bracket: ) + - keyword: COMMENT + - quoted_literal: '''this is a comment''' + - keyword: TBLPROPERTIES + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''foo''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''bar''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: student + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: id + - data_type: + - primitive_type: + - keyword: INT + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: name + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: age + - data_type: + - primitive_type: + - keyword: INT + - end_bracket: ) + - keyword: TBLPROPERTIES + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''foo''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''bar''' + - end_bracket: ) + - keyword: COMMENT + - quoted_literal: '''this is a comment''' +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: student + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: id + - data_type: + - primitive_type: + - keyword: INT + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: name + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: age + - data_type: + - primitive_type: + - keyword: INT + - end_bracket: ) + - keyword: PARTITIONED - keyword: BY - bracketed: - start_bracket: ( - column_reference: - - naked_identifier: id_column + - naked_identifier: age + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: rectangles + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: a + - data_type: + - primitive_type: + - keyword: INT + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: b + - data_type: + - primitive_type: + - keyword: INT + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: area + - data_type: + - primitive_type: + - keyword: INT + - column_properties_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: a + - binary_operator: '*' + - column_reference: + - naked_identifier: b + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: rectangles + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: a + - data_type: + - primitive_type: + - keyword: INT + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: b + - data_type: + - primitive_type: + - keyword: INT + - column_properties_segment: + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: rectangles + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: a + - data_type: + - primitive_type: + - keyword: INT + - column_properties_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: b + - data_type: + - primitive_type: + - keyword: INT + - column_properties_segment: + - keyword: NOT + - keyword: 'NULL' + - column_properties_segment: + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: TABLE + - table_reference: + - naked_identifier: TABLE1 + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: DATE_VALUE + - data_type: + - primitive_type: + - keyword: DATE + - column_properties_segment: + - keyword: NOT + - keyword: 'NULL' + - column_properties_segment: + - column_constraint_segment: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: DATE_CONSTRAINT + - keyword: FOREIGN + - keyword: KEY + - keyword: REFERENCES + - table_reference: + - naked_identifier: TABLE2 - end_bracket: ) - statement_terminator: ; - statement: - - keyword: OPTIMIZE - - object_reference: - - naked_identifier: tablename + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: student + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: id + - data_type: + - primitive_type: + - keyword: INT + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: name + - data_type: + - primitive_type: + - keyword: STRING + - column_properties_segment: + - keyword: DEFAULT + - quoted_literal: '''bobby tables''' + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: age + - data_type: + - primitive_type: + - keyword: INT + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: student + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: id + - data_type: + - primitive_type: + - keyword: INT + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: name + - data_type: + - primitive_type: + - keyword: STRING + - column_properties_segment: + - keyword: NOT + - keyword: 'NULL' + - column_properties_segment: + - keyword: DEFAULT + - quoted_literal: '''bobby tables''' + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: age + - data_type: + - primitive_type: + - keyword: INT + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: clock + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: which_time + - data_type: + - primitive_type: + - keyword: TIMESTAMP + - column_properties_segment: + - keyword: DEFAULT + - function: + - function_name: + - function_name_identifier: current_timestamp + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: clock + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: which_time + - data_type: + - primitive_type: + - keyword: TIMESTAMP + - column_properties_segment: + - column_constraint_segment: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: clock_pk + - keyword: PRIMARY + - keyword: KEY + - column_properties_segment: + - keyword: DEFAULT + - function: + - function_name: + - function_name_identifier: current_timestamp + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - column_properties_segment: + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) - statement_terminator: ; - statement: - - keyword: OPTIMIZE - - object_reference: - - naked_identifier: tablename - - keyword: WHERE - - expression: - - column_reference: - - naked_identifier: date - - comparison_operator: - - raw_comparison_operator: '>' - - raw_comparison_operator: = - - function: - - function_name: - - function_name_identifier: current_timestamp - - function_contents: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - identifier_clause_segment: + - keyword: IDENTIFIER - bracketed: - start_bracket: ( + - expression: + - quoted_literal: '''student''' - end_bracket: ) - - binary_operator: '-' - - interval_expression: - - keyword: INTERVAL - - interval_literal: - - numeric_literal: '1' - - date_part: day - - keyword: ZORDER - - keyword: BY - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: eventType - - comma: ',' - - column_reference: - - naked_identifier: eventTime - - end_bracket: ) + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: id + - data_type: + - primitive_type: + - keyword: INT + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: name + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: age + - data_type: + - primitive_type: + - keyword: INT + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: data_engineering + - dot: . + - naked_identifier: test_sqlfluff_generated + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: test_generated_always_as_id + - data_type: + - primitive_type: + - keyword: BIGINT + - column_properties_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - keyword: IDENTITY + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: test_generated_default_as_id + - data_type: + - primitive_type: + - keyword: BIGINT + - column_properties_segment: + - keyword: GENERATED + - keyword: BY + - keyword: DEFAULT + - keyword: AS + - keyword: IDENTITY + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: test_generated_always_as_id_not_null + - data_type: + - primitive_type: + - keyword: BIGINT + - column_properties_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - keyword: IDENTITY + - column_properties_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: test_generated_default_as_id_not_null + - data_type: + - primitive_type: + - keyword: BIGINT + - column_properties_segment: + - keyword: GENERATED + - keyword: BY + - keyword: DEFAULT + - keyword: AS + - keyword: IDENTITY + - column_properties_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: test_not_null_generated_always_as_id + - data_type: + - primitive_type: + - keyword: BIGINT + - column_properties_segment: + - keyword: NOT + - keyword: 'NULL' + - column_properties_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - keyword: IDENTITY + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: test_not_null_generated_default_as_id + - data_type: + - primitive_type: + - keyword: BIGINT + - column_properties_segment: + - keyword: NOT + - keyword: 'NULL' + - column_properties_segment: + - keyword: GENERATED + - keyword: BY + - keyword: DEFAULT + - keyword: AS + - keyword: IDENTITY + - end_bracket: ) + - using_clause: + - keyword: USING + - data_source_format: + - keyword: DELTA +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: cluster_by_table_auto + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: STRING + - end_bracket: ) + - using_clause: + - keyword: USING + - data_source_format: + - keyword: DELTA + - table_cluster_by_clause: + - keyword: CLUSTER + - keyword: BY + - keyword: AUTO +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: cluster_by_table_none + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: STRING + - end_bracket: ) + - using_clause: + - keyword: USING + - data_source_format: + - keyword: DELTA + - table_cluster_by_clause: + - keyword: CLUSTER + - keyword: BY + - keyword: NONE - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_volume.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_volume.sql new file mode 100644 index 000000000..99f9939a9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_volume.sql @@ -0,0 +1,27 @@ +-- Create volume `customer_vol`. +-- This throws exception if volume with name customer_vol already exists. +CREATE VOLUME customer_vol; + +-- Create volume `customer_vol` only if volume with same name doesn't exist. +CREATE VOLUME IF NOT EXISTS customer_vol; + +-- Create volume `customer_vol` only if volume with same name doesn't exist, +-- with a comment. +CREATE VOLUME IF NOT EXISTS customer_vol COMMENT 'This is customer volume'; + +-- Create external volume `customer_vol_external` +-- This throws exception if volume with name customer_vol_external +-- already exists. +CREATE EXTERNAL VOLUME customer_vol_external +LOCATION 's3://s3-path/'; + +-- Create external volume `customer_vol_external` +-- only if volume with same name doesn't exist, with a location. +CREATE EXTERNAL VOLUME IF NOT EXISTS customer_vol_external +LOCATION 's3://s3-path/'; + +-- Create external volume `customer_vol_external` +-- only if volume with same name doesn't exist, with a location and a comment. +CREATE EXTERNAL VOLUME IF NOT EXISTS customer_vol_external +LOCATION 's3://s3-path/' +COMMENT 'This is customer volume'; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_volume.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_volume.yml new file mode 100644 index 000000000..c3f0d79bf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/create_volume.yml @@ -0,0 +1,68 @@ +file: +- statement: + - create_volume_statement: + - keyword: CREATE + - keyword: VOLUME + - volume_reference: + - naked_identifier: customer_vol +- statement_terminator: ; +- statement: + - create_volume_statement: + - keyword: CREATE + - keyword: VOLUME + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - volume_reference: + - naked_identifier: customer_vol +- statement_terminator: ; +- statement: + - create_volume_statement: + - keyword: CREATE + - keyword: VOLUME + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - volume_reference: + - naked_identifier: customer_vol + - keyword: COMMENT + - quoted_literal: '''This is customer volume''' +- statement_terminator: ; +- statement: + - create_volume_statement: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: VOLUME + - volume_reference: + - naked_identifier: customer_vol_external + - keyword: LOCATION + - quoted_literal: '''s3://s3-path/''' +- statement_terminator: ; +- statement: + - create_volume_statement: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: VOLUME + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - volume_reference: + - naked_identifier: customer_vol_external + - keyword: LOCATION + - quoted_literal: '''s3://s3-path/''' +- statement_terminator: ; +- statement: + - create_volume_statement: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: VOLUME + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - volume_reference: + - naked_identifier: customer_vol_external + - keyword: LOCATION + - quoted_literal: '''s3://s3-path/''' + - keyword: COMMENT + - quoted_literal: '''This is customer volume''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/databricks_keywords.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/databricks_keywords.sql deleted file mode 100644 index 81914e812..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/databricks_keywords.sql +++ /dev/null @@ -1,3 +0,0 @@ -select * -from shopify_cz.order -; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/date_functions.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/date_functions.yml index eda99b42f..a540a7b25 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/date_functions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/date_functions.yml @@ -19,14 +19,14 @@ file: - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: my_table - join_clause: - keyword: LEFT - keyword: JOIN - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: other_table - join_on_condition: - keyword: ON @@ -76,7 +76,8 @@ file: - naked_identifier: start_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: date_add_micro - comma: ',' - select_clause_element: @@ -97,7 +98,8 @@ file: - naked_identifier: end_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: datediff_milli - comma: ',' - select_clause_element: @@ -117,7 +119,8 @@ file: - naked_identifier: start_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: dateadd_min - comma: ',' - select_clause_element: @@ -138,7 +141,8 @@ file: - naked_identifier: end_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: datediff_hr - comma: ',' - select_clause_element: @@ -159,7 +163,8 @@ file: - naked_identifier: end_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: timediff_day - comma: ',' - select_clause_element: @@ -169,9 +174,7 @@ file: - function_contents: - bracketed: - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: DAYOFYEAR + - date_part: DAYOFYEAR - comma: ',' - expression: - numeric_literal: '5' @@ -181,7 +184,8 @@ file: - naked_identifier: start_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: ts_add_day_of_yr - comma: ',' - select_clause_element: @@ -202,7 +206,8 @@ file: - naked_identifier: end_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: ts_diff_week - comma: ',' - select_clause_element: @@ -222,7 +227,8 @@ file: - naked_identifier: start_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: date_add_month - comma: ',' - select_clause_element: @@ -242,7 +248,8 @@ file: - naked_identifier: start_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: date_add_quarter - comma: ',' - select_clause_element: @@ -262,13 +269,14 @@ file: - naked_identifier: start_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: date_add_year - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: my_table - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/declare_or_replace_variable.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/declare_or_replace_variable.yml index f7096aeb3..eadf333ff 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/declare_or_replace_variable.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/declare_or_replace_variable.yml @@ -1,54 +1,61 @@ file: - statement: - - keyword: DECLARE - - naked_identifier: var + - declare_or_replace_variable_statement: + - keyword: DECLARE + - naked_identifier: var - statement_terminator: ; - statement: - - keyword: DECLARE - - keyword: OR - - keyword: REPLACE - - naked_identifier: var + - declare_or_replace_variable_statement: + - keyword: DECLARE + - keyword: OR + - keyword: REPLACE + - naked_identifier: var - statement_terminator: ; - statement: - - keyword: DECLARE - - keyword: OR - - keyword: REPLACE - - keyword: VARIABLE - - naked_identifier: var + - declare_or_replace_variable_statement: + - keyword: DECLARE + - keyword: OR + - keyword: REPLACE + - keyword: VARIABLE + - naked_identifier: var - statement_terminator: ; - statement: - - keyword: DECLARE - - naked_identifier: var - - data_type: - - primitive_type: - - keyword: INT - - keyword: DEFAULT - - expression: - - numeric_literal: '5' + - declare_or_replace_variable_statement: + - keyword: DECLARE + - naked_identifier: var + - data_type: + - primitive_type: + - keyword: INT + - keyword: DEFAULT + - expression: + - numeric_literal: '5' - statement_terminator: ; - statement: - - keyword: DECLARE - - naked_identifier: var - - data_type: - - primitive_type: - - keyword: INT - - comparison_operator: - - raw_comparison_operator: = - - expression: - - numeric_literal: '5' + - declare_or_replace_variable_statement: + - keyword: DECLARE + - naked_identifier: var + - data_type: + - primitive_type: + - keyword: INT + - comparison_operator: + - raw_comparison_operator: = + - expression: + - numeric_literal: '5' - statement_terminator: ; - statement: - - keyword: DECLARE - - naked_identifier: var - - comparison_operator: - - raw_comparison_operator: = - - expression: - - numeric_literal: '5' + - declare_or_replace_variable_statement: + - keyword: DECLARE + - naked_identifier: var + - comparison_operator: + - raw_comparison_operator: = + - expression: + - numeric_literal: '5' - statement_terminator: ; - statement: - - keyword: DECLARE - - naked_identifier: var - - keyword: DEFAULT - - expression: - - numeric_literal: '5' + - declare_or_replace_variable_statement: + - keyword: DECLARE + - naked_identifier: var + - keyword: DEFAULT + - expression: + - numeric_literal: '5' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/describe_volume.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/describe_volume.yml index 72e7164b4..19cdedec3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/describe_volume.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/describe_volume.yml @@ -3,6 +3,6 @@ file: - describe_statement: - keyword: DESCRIBE - keyword: VOLUME - - object_reference: + - volume_reference: - naked_identifier: VACCINE_VOLUME - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/drop_catalog.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/drop_catalog.yml index ee3e98eb2..beda90a9b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/drop_catalog.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/drop_catalog.yml @@ -1,17 +1,19 @@ file: - statement: - - keyword: DROP - - keyword: CATALOG - - object_reference: - - naked_identifier: vaccine - - keyword: CASCADE + - drop_catalog_statement: + - keyword: DROP + - keyword: CATALOG + - catalog_reference: + - naked_identifier: vaccine + - keyword: CASCADE - statement_terminator: ; - statement: - - keyword: DROP - - keyword: CATALOG - - keyword: IF - - keyword: EXISTS - - object_reference: - - naked_identifier: vaccine - - keyword: RESTRICT + - drop_catalog_statement: + - keyword: DROP + - keyword: CATALOG + - keyword: IF + - keyword: EXISTS + - catalog_reference: + - naked_identifier: vaccine + - keyword: RESTRICT - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/drop_volume.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/drop_volume.yml index b21d0c759..18822f127 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/drop_volume.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/drop_volume.yml @@ -1,15 +1,17 @@ file: - statement: - - keyword: DROP - - keyword: VOLUME - - object_reference: - - naked_identifier: vaccine_volume + - drop_volume_statement: + - keyword: DROP + - keyword: VOLUME + - volume_reference: + - naked_identifier: vaccine_volume - statement_terminator: ; - statement: - - keyword: DROP - - keyword: VOLUME - - keyword: IF - - keyword: EXISTS - - object_reference: - - naked_identifier: vaccine_volume + - drop_volume_statement: + - keyword: DROP + - keyword: VOLUME + - keyword: IF + - keyword: EXISTS + - volume_reference: + - naked_identifier: vaccine_volume - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/grant_permissions.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/grant_permissions.sql new file mode 100644 index 000000000..24531bc88 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/grant_permissions.sql @@ -0,0 +1,9 @@ +-- Adding some permission examples from https://docs.databricks.com/aws/en/data-governance/unity-catalog/manage-privileges/?language=SQL + +GRANT CREATE TABLE ON SCHEMA main.default TO `finance-team`; +GRANT USE SCHEMA ON SCHEMA main.default TO `finance-team`; +GRANT USE CATALOG ON CATALOG main TO `finance-team`; +GRANT EXECUTE ON FUNCTION prod.ml_team.iris_model TO `ml-team-acme`; +GRANT READ ON METASTORE TO 'principal'; +GRANT SELECT ON VIEW schema.view TO `the_view_accessors`; +GRANT ALL PRIVILEGES ON CATALOG main TO `data-engineers`; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/grant_permissions.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/grant_permissions.yml new file mode 100644 index 000000000..4a1040706 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/grant_permissions.yml @@ -0,0 +1,98 @@ +file: +- statement: + - access_statement: + - keyword: GRANT + - keyword: CREATE + - keyword: TABLE + - keyword: ON + - keyword: SCHEMA + - object_reference: + - naked_identifier: main + - dot: . + - naked_identifier: default + - keyword: TO + - role_reference: + - quoted_identifier: '`finance-team`' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: USE + - keyword: SCHEMA + - keyword: ON + - keyword: SCHEMA + - object_reference: + - naked_identifier: main + - dot: . + - naked_identifier: default + - keyword: TO + - role_reference: + - quoted_identifier: '`finance-team`' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: USE + - keyword: CATALOG + - keyword: ON + - keyword: CATALOG + - object_reference: + - naked_identifier: main + - keyword: TO + - role_reference: + - quoted_identifier: '`finance-team`' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: EXECUTE + - keyword: ON + - keyword: FUNCTION + - object_reference: + - naked_identifier: prod + - dot: . + - naked_identifier: ml_team + - dot: . + - naked_identifier: iris_model + - keyword: TO + - role_reference: + - quoted_identifier: '`ml-team-acme`' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: READ + - keyword: ON + - object_reference: + - naked_identifier: METASTORE + - keyword: TO + - role_reference: + - quoted_identifier: '''principal''' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: SELECT + - keyword: ON + - keyword: VIEW + - object_reference: + - naked_identifier: schema + - dot: . + - naked_identifier: view + - keyword: TO + - role_reference: + - quoted_identifier: '`the_view_accessors`' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: ALL + - keyword: PRIVILEGES + - keyword: ON + - keyword: CATALOG + - object_reference: + - naked_identifier: main + - keyword: TO + - role_reference: + - quoted_identifier: '`data-engineers`' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/insert_by_name.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/insert_by_name.sql deleted file mode 100644 index 089df54ad..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/insert_by_name.sql +++ /dev/null @@ -1,5 +0,0 @@ -INSERT INTO target BY NAME SELECT named_struct('b', 2, 'a', 1) AS s, 0 AS n, 'data' AS text; -INSERT INTO target BY NAME SELECT array(named_struct('b', 2, 'a', 1)) AS arr, 0 AS n; -INSERT INTO target BY NAME SELECT array(named_struct('b', 2, 'a', 1)) AS arr; -INSERT INTO target BY NAME SELECT array(named_struct('b', 2, 'a', 1)) AS arr, 0 AS badname; -INSERT INTO target BY NAME SELECT array(named_struct('b', 2, 'a', 1)) AS arr, 0 AS n, 1 AS n; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/insert_by_name.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/insert_by_name.yml deleted file mode 100644 index b3037e560..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/insert_by_name.yml +++ /dev/null @@ -1,239 +0,0 @@ -file: -- statement: - - insert_statement: - - keyword: INSERT - - keyword: INTO - - object_reference: - - naked_identifier: target - - keyword: BY - - keyword: NAME - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - function: - - function_name: - - function_name_identifier: named_struct - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''b''' - - comma: ',' - - expression: - - numeric_literal: '2' - - comma: ',' - - expression: - - quoted_literal: '''a''' - - comma: ',' - - expression: - - numeric_literal: '1' - - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: s - - comma: ',' - - select_clause_element: - - numeric_literal: '0' - - alias_expression: - - keyword: AS - - naked_identifier: n - - comma: ',' - - select_clause_element: - - quoted_literal: '''data''' - - alias_expression: - - keyword: AS - - naked_identifier: text -- statement_terminator: ; -- statement: - - insert_statement: - - keyword: INSERT - - keyword: INTO - - object_reference: - - naked_identifier: target - - keyword: BY - - keyword: NAME - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - function: - - function_name: - - function_name_identifier: array - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: named_struct - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''b''' - - comma: ',' - - expression: - - numeric_literal: '2' - - comma: ',' - - expression: - - quoted_literal: '''a''' - - comma: ',' - - expression: - - numeric_literal: '1' - - end_bracket: ) - - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: arr - - comma: ',' - - select_clause_element: - - numeric_literal: '0' - - alias_expression: - - keyword: AS - - naked_identifier: n -- statement_terminator: ; -- statement: - - insert_statement: - - keyword: INSERT - - keyword: INTO - - object_reference: - - naked_identifier: target - - keyword: BY - - keyword: NAME - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - function: - - function_name: - - function_name_identifier: array - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: named_struct - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''b''' - - comma: ',' - - expression: - - numeric_literal: '2' - - comma: ',' - - expression: - - quoted_literal: '''a''' - - comma: ',' - - expression: - - numeric_literal: '1' - - end_bracket: ) - - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: arr -- statement_terminator: ; -- statement: - - insert_statement: - - keyword: INSERT - - keyword: INTO - - object_reference: - - naked_identifier: target - - keyword: BY - - keyword: NAME - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - function: - - function_name: - - function_name_identifier: array - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: named_struct - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''b''' - - comma: ',' - - expression: - - numeric_literal: '2' - - comma: ',' - - expression: - - quoted_literal: '''a''' - - comma: ',' - - expression: - - numeric_literal: '1' - - end_bracket: ) - - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: arr - - comma: ',' - - select_clause_element: - - numeric_literal: '0' - - alias_expression: - - keyword: AS - - naked_identifier: badname -- statement_terminator: ; -- statement: - - insert_statement: - - keyword: INSERT - - keyword: INTO - - object_reference: - - naked_identifier: target - - keyword: BY - - keyword: NAME - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - function: - - function_name: - - function_name_identifier: array - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: named_struct - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''b''' - - comma: ',' - - expression: - - numeric_literal: '2' - - comma: ',' - - expression: - - quoted_literal: '''a''' - - comma: ',' - - expression: - - numeric_literal: '1' - - end_bracket: ) - - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: arr - - comma: ',' - - select_clause_element: - - numeric_literal: '0' - - alias_expression: - - keyword: AS - - naked_identifier: n - - comma: ',' - - select_clause_element: - - numeric_literal: '1' - - alias_expression: - - keyword: AS - - naked_identifier: n -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_line.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_line.sql new file mode 100644 index 000000000..9fafcadb0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_line.sql @@ -0,0 +1,24 @@ +-- Databricks notebook source +-- MAGIC %md +-- MAGIC # Dummy Notebook + +-- COMMAND ---------- + +-- DBTITLE 1,Select Data + +SELECT x FROM y + +-- COMMAND ---------- + +-- MAGIC %python +-- MAGIC foo = 'bar' +-- MAGIC print(foo) + +-- COMMAND ---------- + +SELECT a FROM b; + +-- COMMAND ---------- + +-- MAGIC %sh +-- MAGIC echo heloworld diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_line.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_line.yml new file mode 100644 index 000000000..9322df661 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_line.yml @@ -0,0 +1,62 @@ +file: +- statement: + - magic_cell_segment: + - magic_start: | + -- MAGIC %md + - magic_line: '-- MAGIC # Dummy Notebook' +- statement_terminator: |2 + + + -- COMMAND ---------- +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: x + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: y +- statement_terminator: |2 + + + -- COMMAND ---------- +- statement: + - magic_cell_segment: + - magic_start: | + -- MAGIC %python + - magic_line: -- MAGIC foo = 'bar' + - magic_line: -- MAGIC print(foo) +- statement_terminator: |2 + + + -- COMMAND ---------- +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: b +- statement_terminator: ; +- statement_terminator: |2 + + + -- COMMAND ---------- +- statement: + - magic_cell_segment: + - magic_start: | + -- MAGIC %sh + - magic_line: -- MAGIC echo heloworld diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_single_line.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_single_line.sql new file mode 100644 index 000000000..35ff814ff --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_single_line.sql @@ -0,0 +1,11 @@ +-- Databricks notebook source +-- MAGIC %md +-- MAGIC # Dummy Notebook + +-- COMMAND ---------- + +-- MAGIC %run ./Notebook + +-- COMMAND ---------- + +SELECT a FROM b diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_single_line.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_single_line.yml new file mode 100644 index 000000000..3807d8f98 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/magic_single_line.yml @@ -0,0 +1,31 @@ +file: +- statement: + - magic_cell_segment: + - magic_start: | + -- MAGIC %md + - magic_line: '-- MAGIC # Dummy Notebook' +- statement_terminator: |2 + + + -- COMMAND ---------- +- statement: + - magic_cell_segment: + - magic_single_line: -- MAGIC %run ./Notebook +- statement_terminator: |2 + + + -- COMMAND ---------- +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: b diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/named_argument.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/named_argument.sql new file mode 100644 index 000000000..d59646f11 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/named_argument.sql @@ -0,0 +1,7 @@ +--https://docs.databricks.com/en/sql/language-manual/sql-ref-function-invocation.html#named-parameter-invocation + +select my_function(arg1 => 3, arg2 => 4) from dual; + +select my_function(3, arg2 => 4) from dual; + +select my_function(arg1 => 3, 4) from dual; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/named_argument.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/named_argument.yml new file mode 100644 index 000000000..82f99b005 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/named_argument.yml @@ -0,0 +1,88 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - function_name_identifier: my_function + - function_contents: + - bracketed: + - start_bracket: ( + - named_argument: + - naked_identifier: arg1 + - right_arrow: => + - expression: + - numeric_literal: '3' + - comma: ',' + - named_argument: + - naked_identifier: arg2 + - right_arrow: => + - expression: + - numeric_literal: '4' + - end_bracket: ) + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dual +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - function_name_identifier: my_function + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - named_argument: + - naked_identifier: arg2 + - right_arrow: => + - expression: + - numeric_literal: '4' + - end_bracket: ) + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dual +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - function_name_identifier: my_function + - function_contents: + - bracketed: + - start_bracket: ( + - named_argument: + - naked_identifier: arg1 + - right_arrow: => + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - numeric_literal: '4' + - end_bracket: ) + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dual +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/pivot.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/pivot.sql index 6aa805fab..6d4df77d7 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/pivot.sql +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/pivot.sql @@ -29,3 +29,10 @@ SELECT year, q1_total, q1_avg, q2_total, q2_avg, q3_total, q3_avg, q4_total, q4_ PIVOT (sum(sales) AS total, avg(sales) AS avg FOR quarter IN (1 AS q1, 2 AS q2, 3 AS q3, 4 AS q4)); + +-- A PIVOT with anonymous columns +SELECT year, region, q1, q2, q3, q4 +FROM sales +PIVOT (sum(sales) + FOR quarter + IN (1 AS q1, 2 AS q2, 3 AS q3, 4 AS q4)); diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/pivot.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/pivot.yml index 06cc4e730..ce28bb2c7 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/pivot.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/pivot.yml @@ -31,7 +31,7 @@ file: - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: sales - pivot_clause: - keyword: PIVOT @@ -48,7 +48,8 @@ file: - naked_identifier: sales - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sales - keyword: FOR - naked_identifier: quarter @@ -58,25 +59,29 @@ file: - expression: - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q1 - comma: ',' - expression: - numeric_literal: '2' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q2 - comma: ',' - expression: - numeric_literal: '3' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q3 - comma: ',' - expression: - numeric_literal: '4' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q4 - end_bracket: ) - end_bracket: ) @@ -125,7 +130,7 @@ file: - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: sales - pivot_clause: - keyword: PIVOT @@ -142,7 +147,8 @@ file: - naked_identifier: sales - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sales - keyword: FOR - bracketed: @@ -163,7 +169,8 @@ file: - quoted_literal: '''east''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q1_east - comma: ',' - bracketed: @@ -175,7 +182,8 @@ file: - quoted_literal: '''west''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q1_west - comma: ',' - bracketed: @@ -187,7 +195,8 @@ file: - quoted_literal: '''east''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q2_east - comma: ',' - bracketed: @@ -199,7 +208,8 @@ file: - quoted_literal: '''west''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q2_west - comma: ',' - bracketed: @@ -211,7 +221,8 @@ file: - quoted_literal: '''east''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q3_east - comma: ',' - bracketed: @@ -223,7 +234,8 @@ file: - quoted_literal: '''west''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q3_west - comma: ',' - bracketed: @@ -235,7 +247,8 @@ file: - quoted_literal: '''east''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q4_east - comma: ',' - bracketed: @@ -247,7 +260,8 @@ file: - quoted_literal: '''west''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q4_west - end_bracket: ) - end_bracket: ) @@ -301,11 +315,12 @@ file: - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: sales - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: s - pivot_clause: - keyword: PIVOT @@ -322,7 +337,8 @@ file: - naked_identifier: sales - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sales - keyword: FOR - naked_identifier: quarter @@ -332,25 +348,29 @@ file: - expression: - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q1 - comma: ',' - expression: - numeric_literal: '2' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q2 - comma: ',' - expression: - numeric_literal: '3' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q3 - comma: ',' - expression: - numeric_literal: '4' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q4 - end_bracket: ) - end_bracket: ) @@ -420,11 +440,12 @@ file: - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: sales - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: s - pivot_clause: - keyword: PIVOT @@ -441,7 +462,8 @@ file: - naked_identifier: sales - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: total - comma: ',' - function: @@ -455,7 +477,8 @@ file: - naked_identifier: sales - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: avg - keyword: FOR - naked_identifier: quarter @@ -465,25 +488,112 @@ file: - expression: - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q1 - comma: ',' - expression: - numeric_literal: '2' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q2 - comma: ',' - expression: - numeric_literal: '3' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q3 - comma: ',' - expression: - numeric_literal: '4' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS + - naked_identifier: q4 + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: year + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: region + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: q1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: q2 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: q3 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: q4 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sales + - pivot_clause: + - keyword: PIVOT + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: sales + - end_bracket: ) + - keyword: FOR + - naked_identifier: quarter + - keyword: IN + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: q1 + - comma: ',' + - expression: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: q2 + - comma: ',' + - expression: + - numeric_literal: '3' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: q3 + - comma: ',' + - expression: + - numeric_literal: '4' + - alias_expression: + - alias_operator: + - keyword: AS - naked_identifier: q4 - end_bracket: ) - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/revoke_permissions.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/revoke_permissions.sql new file mode 100644 index 000000000..9346ea2be --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/revoke_permissions.sql @@ -0,0 +1,7 @@ + +REVOKE CREATE TABLE ON SCHEMA main.default FROM `finance-team`; +REVOKE USE SCHEMA ON SCHEMA main.default FROM `finance-team`; +REVOKE USE CATALOG ON CATALOG main FROM `finance-team`; +REVOKE EXECUTE ON FUNCTION prod.ml_team.iris_model FROM `ml-team-acme`; +REVOKE READ ON METASTORE FROM 'principal'; +REVOKE SELECT ON VIEW schema.view FROM `the_view_accessors`; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/revoke_permissions.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/revoke_permissions.yml new file mode 100644 index 000000000..cd38916d5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/revoke_permissions.yml @@ -0,0 +1,85 @@ +file: +- statement: + - access_statement: + - keyword: REVOKE + - keyword: CREATE + - keyword: TABLE + - keyword: ON + - keyword: SCHEMA + - object_reference: + - naked_identifier: main + - dot: . + - naked_identifier: default + - keyword: FROM + - object_reference: + - quoted_identifier: '`finance-team`' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: REVOKE + - keyword: USE + - keyword: SCHEMA + - keyword: ON + - keyword: SCHEMA + - object_reference: + - naked_identifier: main + - dot: . + - naked_identifier: default + - keyword: FROM + - object_reference: + - quoted_identifier: '`finance-team`' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: REVOKE + - keyword: USE + - keyword: CATALOG + - keyword: ON + - keyword: CATALOG + - object_reference: + - naked_identifier: main + - keyword: FROM + - object_reference: + - quoted_identifier: '`finance-team`' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: REVOKE + - keyword: EXECUTE + - keyword: ON + - keyword: FUNCTION + - object_reference: + - naked_identifier: prod + - dot: . + - naked_identifier: ml_team + - dot: . + - naked_identifier: iris_model + - keyword: FROM + - object_reference: + - quoted_identifier: '`ml-team-acme`' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: REVOKE + - keyword: READ + - keyword: ON + - object_reference: + - naked_identifier: METASTORE + - keyword: FROM + - object_reference: + - quoted_identifier: '''principal''' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: REVOKE + - keyword: SELECT + - keyword: ON + - keyword: VIEW + - object_reference: + - naked_identifier: schema + - dot: . + - naked_identifier: view + - keyword: FROM + - object_reference: + - quoted_identifier: '`the_view_accessors`' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select.yml index eccecd454..d9f43f9eb 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select.yml @@ -12,7 +12,7 @@ file: - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: shopify_cz - dot: . - naked_identifier: order @@ -30,11 +30,13 @@ file: - from_expression: - from_expression_element: - table_expression: - - keyword: IDENTIFIER - - bracketed: - - start_bracket: ( - - quoted_identifier: '''table_name''' - - end_bracket: ) + - identifier_clause_segment: + - keyword: IDENTIFIER + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''table_name''' + - end_bracket: ) - statement_terminator: ; - statement: - select_statement: @@ -49,17 +51,15 @@ file: - from_expression: - from_expression_element: - table_expression: - - function: - - function_name: - - function_name_identifier: IDENTIFIER - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''schema_name''' - - binary_operator: - - pipe: '|' - - pipe: '|' - - quoted_literal: '''.table_name''' - - end_bracket: ) + - identifier_clause_segment: + - keyword: IDENTIFIER + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''schema_name''' + - binary_operator: + - pipe: '|' + - pipe: '|' + - quoted_literal: '''.table_name''' + - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_lateral_view.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_lateral_view.sql new file mode 100644 index 000000000..ab7643cb4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_lateral_view.sql @@ -0,0 +1,114 @@ +SELECT + id, + name, + age, + class, + address, + c_age, + d_age +FROM person + LATERAL VIEW EXPLODE(ARRAY(30, 60)) tbl_name AS c_age + LATERAL VIEW EXPLODE(ARRAY(40, 80)) AS d_age; + +SELECT + c_age, + COUNT(*) AS record_count +FROM person + LATERAL VIEW EXPLODE(ARRAY(30, 60)) AS c_age + LATERAL VIEW EXPLODE(ARRAY(40, 80)) AS d_age +GROUP BY c_age; + +SELECT + id, + name, + age, + class, + address, + c_age, + d_age +FROM person + LATERAL VIEW EXPLODE(ARRAY()) tbl_name AS c_age; + +SELECT + id, + name, + age, + class, + address, + time, + c_age +FROM person + LATERAL VIEW OUTER EXPLODE(ARRAY()) tbl_name AS c_age; + +SELECT + id, + name, + age, + class, + address, + time, + c_age +FROM person + LATERAL VIEW OUTER EXPLODE(ARRAY()) tbl_name c_age; + +SELECT + id, + name, + age, + class, + address, + time, + c_age +FROM person + LATERAL VIEW OUTER EXPLODE(ARRAY()) c_age; + +SELECT + person.id, + exploded_people.name, + exploded_people.age, + exploded_people.state +FROM person + LATERAL VIEW INLINE(array_of_structs) exploded_people AS name, age, state; + +SELECT + p.id, + exploded_people.name, + exploded_people.age, + exploded_people.state +FROM person AS p + LATERAL VIEW INLINE(array_of_structs) exploded_people AS name, age, state; + +SELECT + p.id, + exploded_people.name, + exploded_people.age, + exploded_people.state +FROM person AS p + LATERAL VIEW INLINE(array_of_structs) exploded_people; + +SELECT + p.id, + exploded_people.name, + exploded_people.age, + exploded_people.state +FROM person AS p + LATERAL VIEW INLINE(array_of_structs) exploded_people name, age, state; + +SELECT + p.id, + exploded_people.name, + exploded_people.age, + exploded_people.state +FROM person AS p + LATERAL VIEW INLINE(array_of_structs) AS name, age, state; + +SELECT + t1.column1, + CAST(GET_JSON_OBJECT(things, '$.percentage') AS DECIMAL(16, 8) + ) AS ptc +FROM table1 AS t1 +LEFT JOIN table2 AS t2 + ON + c.column1 = p.column1 + AND t2.type = 'SOMETHING' + LATERAL VIEW OUTER EXPLODE(t2.column2) AS things; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_lateral_view.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_lateral_view.yml new file mode 100644 index 000000000..cc5062e35 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_lateral_view.yml @@ -0,0 +1,807 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: age + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: class + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: address + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: c_age + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: d_age + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: person + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '30' + - comma: ',' + - expression: + - numeric_literal: '60' + - end_bracket: ) + - end_bracket: ) + - naked_identifier: tbl_name + - keyword: AS + - naked_identifier: c_age + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '40' + - comma: ',' + - expression: + - numeric_literal: '80' + - end_bracket: ) + - end_bracket: ) + - naked_identifier: AS + - naked_identifier: d_age +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c_age + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: COUNT + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: record_count + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: person + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '30' + - comma: ',' + - expression: + - numeric_literal: '60' + - end_bracket: ) + - end_bracket: ) + - naked_identifier: AS + - naked_identifier: c_age + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '40' + - comma: ',' + - expression: + - numeric_literal: '80' + - end_bracket: ) + - end_bracket: ) + - naked_identifier: AS + - naked_identifier: d_age + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: c_age +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: age + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: class + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: address + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: c_age + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: d_age + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: person + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - naked_identifier: tbl_name + - keyword: AS + - naked_identifier: c_age +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: age + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: class + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: address + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: time + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: c_age + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: person + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - keyword: OUTER + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - naked_identifier: tbl_name + - keyword: AS + - naked_identifier: c_age +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: age + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: class + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: address + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: time + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: c_age + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: person + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - keyword: OUTER + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - naked_identifier: tbl_name + - naked_identifier: c_age +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: age + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: class + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: address + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: time + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: c_age + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: person + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - keyword: OUTER + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - naked_identifier: c_age +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: person + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: age + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: state + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: person + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: INLINE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: array_of_structs + - end_bracket: ) + - naked_identifier: exploded_people + - keyword: AS + - naked_identifier: name + - comma: ',' + - naked_identifier: age + - comma: ',' + - naked_identifier: state +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: age + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: state + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: person + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: p + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: INLINE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: array_of_structs + - end_bracket: ) + - naked_identifier: exploded_people + - keyword: AS + - naked_identifier: name + - comma: ',' + - naked_identifier: age + - comma: ',' + - naked_identifier: state +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: age + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: state + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: person + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: p + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: INLINE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: array_of_structs + - end_bracket: ) + - naked_identifier: exploded_people +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: age + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: state + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: person + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: p + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: INLINE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: array_of_structs + - end_bracket: ) + - naked_identifier: exploded_people + - naked_identifier: name + - comma: ',' + - naked_identifier: age + - comma: ',' + - naked_identifier: state +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: age + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: exploded_people + - dot: . + - naked_identifier: state + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: person + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: p + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: INLINE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: array_of_structs + - end_bracket: ) + - naked_identifier: AS + - naked_identifier: name + - comma: ',' + - naked_identifier: age + - comma: ',' + - naked_identifier: state +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: GET_JSON_OBJECT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: things + - comma: ',' + - expression: + - quoted_literal: '''$.percentage''' + - end_bracket: ) + - keyword: AS + - data_type: + - primitive_type: + - keyword: DECIMAL + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '16' + - comma: ',' + - numeric_literal: '8' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: ptc + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t1 + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t2 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: column1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: column1 + - binary_operator: AND + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: type + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''SOMETHING''' + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - keyword: OUTER + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: column2 + - end_bracket: ) + - naked_identifier: AS + - naked_identifier: things +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_read_file.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_read_file.sql new file mode 100644 index 000000000..e4a345fb5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_read_file.sql @@ -0,0 +1,37 @@ +-- Taken from examples here: https://docs.databricks.com/aws/en/sql/language-manual/functions/read_files + +-- Reads the files available in the given path. Auto-detects the format and schema of the data. +SELECT * FROM read_files('abfss://container@storageAccount.dfs.core.windows.net/base/path'); + +SELECT * FROM read_files( + 's3://bucket/path', + format => 'csv', + schema => 'id int, ts timestamp, event string'); + +-- Infers the schema of CSV files with headers. Because the schema is not provided, +-- the CSV files are assumed to have headers. +SELECT * FROM read_files( + 's3://bucket/path', + format => 'csv'); + +-- Reads files that have a csv suffix. +SELECT * FROM read_files('s3://bucket/path/*.csv'); + +-- Reads a single JSON file +SELECT * FROM read_files( + 'abfss://container@storageAccount.dfs.core.windows.net/path/single.json'); + +-- Reads JSON files and overrides the data type of the column `id` to integer. +SELECT * FROM read_files( + 's3://bucket/path', + format => 'json', + schemaHints => 'id int'); + +-- Reads files that have been uploaded or modified yesterday. +SELECT * FROM read_files( + 'gs://my-bucket/avroData', + modifiedAfter => date_sub(current_date(), 1), + modifiedBefore => current_date()); + +-- Reads a streaming table +SELECT * FROM STREAM read_files('gs://my-bucket/avroData', includeExistingFiles => false); diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_read_file.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_read_file.yml new file mode 100644 index 000000000..a89ba167c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_from_read_file.yml @@ -0,0 +1,257 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: read_files + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''abfss://container@storageAccount.dfs.core.windows.net/base/path''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: read_files + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''s3://bucket/path''' + - comma: ',' + - named_argument: + - naked_identifier: format + - right_arrow: => + - expression: + - quoted_literal: '''csv''' + - comma: ',' + - named_argument: + - naked_identifier: schema + - right_arrow: => + - expression: + - quoted_literal: '''id int, ts timestamp, event string''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: read_files + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''s3://bucket/path''' + - comma: ',' + - named_argument: + - naked_identifier: format + - right_arrow: => + - expression: + - quoted_literal: '''csv''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: read_files + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''s3://bucket/path/*.csv''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: read_files + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''abfss://container@storageAccount.dfs.core.windows.net/path/single.json''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: read_files + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''s3://bucket/path''' + - comma: ',' + - named_argument: + - naked_identifier: format + - right_arrow: => + - expression: + - quoted_literal: '''json''' + - comma: ',' + - named_argument: + - naked_identifier: schemaHints + - right_arrow: => + - expression: + - quoted_literal: '''id int''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: read_files + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''gs://my-bucket/avroData''' + - comma: ',' + - named_argument: + - naked_identifier: modifiedAfter + - right_arrow: => + - expression: + - function: + - function_name: + - function_name_identifier: date_sub + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: current_date + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - expression: + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - named_argument: + - naked_identifier: modifiedBefore + - right_arrow: => + - expression: + - function: + - function_name: + - function_name_identifier: current_date + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - keyword: STREAM + - table_expression: + - function: + - function_name: + - function_name_identifier: read_files + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''gs://my-bucket/avroData''' + - comma: ',' + - named_argument: + - naked_identifier: includeExistingFiles + - right_arrow: => + - expression: + - boolean_literal: 'false' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_group_by.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_group_by.sql index 0ec8318aa..70c8590b5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_group_by.sql +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_group_by.sql @@ -137,4 +137,4 @@ SELECT age, count(*) AS record_count FROM people -GROUP BY ALL; \ No newline at end of file +GROUP BY ALL; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_group_by.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_group_by.yml index 0dba42a73..f381f5328 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_group_by.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_group_by.yml @@ -19,14 +19,15 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: dealer - groupby_clause: - keyword: GROUP @@ -59,14 +60,15 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: dealer - groupby_clause: - keyword: GROUP @@ -97,7 +99,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - comma: ',' - select_clause_element: @@ -112,14 +115,15 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: max_quantity - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: dealer - groupby_clause: - keyword: GROUP @@ -153,14 +157,15 @@ file: - naked_identifier: city - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: count_distinct_city - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: dealer - groupby_clause: - keyword: GROUP @@ -203,14 +208,15 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_identifier: '`sum(quantity)`' - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: dealer - groupby_clause: - keyword: GROUP @@ -247,14 +253,15 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: dealer - groupby_clause: - keyword: GROUP @@ -326,14 +333,15 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: dealer - groupby_clause: - keyword: GROUP @@ -410,14 +418,15 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: dealer - groupby_clause: - keyword: GROUP @@ -495,14 +504,15 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: dealer - groupby_clause: - keyword: GROUP @@ -548,14 +558,15 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: dealer - groupby_clause: - keyword: GROUP @@ -597,7 +608,7 @@ file: - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: person - statement_terminator: ; - statement: @@ -618,7 +629,8 @@ file: - keyword: NULLS - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: first_age - comma: ',' - select_clause_element: @@ -633,7 +645,8 @@ file: - naked_identifier: id - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: last_id - comma: ',' - select_clause_element: @@ -648,14 +661,15 @@ file: - naked_identifier: id - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_id - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: person - statement_terminator: ; - statement: @@ -680,14 +694,15 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: record_count - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: people - groupby_clause: - keyword: GROUP @@ -723,14 +738,15 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: record_count - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: people - groupby_clause: - keyword: GROUP @@ -767,14 +783,15 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: record_count - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: people - groupby_clause: - keyword: GROUP @@ -814,14 +831,15 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: record_count - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: people - groupby_clause: - keyword: GROUP @@ -861,14 +879,15 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: record_count - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: people - groupby_clause: - keyword: GROUP diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_window.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_window.yml index 45e6c9e25..44804648a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_window.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/select_window.yml @@ -30,7 +30,7 @@ file: - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: schema - dot: . - naked_identifier: test_table @@ -72,7 +72,7 @@ file: - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: schema - dot: . - naked_identifier: test_table diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_tags.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_tags.sql new file mode 100644 index 000000000..3a9a7d9ea --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_tags.sql @@ -0,0 +1,17 @@ +-- Setting tags according to https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-set-tag + +SET TAG ON CATALOG catalog `tag1`=`value1`; +SET TAG ON COLUMN catalog.schema.table.column `tag1`=`value1`; +SET TAG ON SCHEMA catalog.schema tag1=`value1`; +SET TAG ON DATABASE catalog.database `tag1`=value1; +SET TAG ON TABLE catalog.schema.table tag1=value1; +SET TAG ON VIEW catalog.schema.view `tag1`=`value1`; +SET TAG ON VOLUME volume `tag1`=`value1`; + +UNSET TAG ON CATALOG catalog `tag1`; +UNSET TAG ON COLUMN catalog.schema.table.column `tag1`; +UNSET TAG ON SCHEMA catalog.schema `tag1`; +UNSET TAG ON DATABASE catalog.database `tag1`; +UNSET TAG ON TABLE catalog.schema.table `tag1`; +UNSET TAG ON VIEW catalog.schema.view `tag1`; +UNSET TAG ON VOLUME volume `tag1`; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_tags.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_tags.yml new file mode 100644 index 000000000..7954e6d89 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_tags.yml @@ -0,0 +1,198 @@ +file: +- statement: + - tag_statement: + - keyword: SET + - keyword: TAG + - keyword: ON + - keyword: CATALOG + - catalog_reference: + - naked_identifier: catalog + - quoted_identifier: '`tag1`' + - comparison_operator: + - raw_comparison_operator: = + - quoted_identifier: '`value1`' +- statement_terminator: ; +- statement: + - tag_statement: + - keyword: SET + - keyword: TAG + - keyword: ON + - keyword: COLUMN + - column_reference: + - naked_identifier: catalog + - dot: . + - naked_identifier: schema + - dot: . + - naked_identifier: table + - dot: . + - naked_identifier: column + - quoted_identifier: '`tag1`' + - comparison_operator: + - raw_comparison_operator: = + - quoted_identifier: '`value1`' +- statement_terminator: ; +- statement: + - tag_statement: + - keyword: SET + - keyword: TAG + - keyword: ON + - keyword: SCHEMA + - database_reference: + - naked_identifier: catalog + - dot: . + - naked_identifier: schema + - naked_identifier: tag1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_identifier: '`value1`' +- statement_terminator: ; +- statement: + - tag_statement: + - keyword: SET + - keyword: TAG + - keyword: ON + - keyword: DATABASE + - database_reference: + - naked_identifier: catalog + - dot: . + - naked_identifier: database + - quoted_identifier: '`tag1`' + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: value1 +- statement_terminator: ; +- statement: + - tag_statement: + - keyword: SET + - keyword: TAG + - keyword: ON + - keyword: TABLE + - table_reference: + - naked_identifier: catalog + - dot: . + - naked_identifier: schema + - dot: . + - naked_identifier: table + - naked_identifier: tag1 + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: value1 +- statement_terminator: ; +- statement: + - tag_statement: + - keyword: SET + - keyword: TAG + - keyword: ON + - keyword: VIEW + - table_reference: + - naked_identifier: catalog + - dot: . + - naked_identifier: schema + - dot: . + - naked_identifier: view + - quoted_identifier: '`tag1`' + - comparison_operator: + - raw_comparison_operator: = + - quoted_identifier: '`value1`' +- statement_terminator: ; +- statement: + - tag_statement: + - keyword: SET + - keyword: TAG + - keyword: ON + - keyword: VOLUME + - volume_reference: + - naked_identifier: volume + - quoted_identifier: '`tag1`' + - comparison_operator: + - raw_comparison_operator: = + - quoted_identifier: '`value1`' +- statement_terminator: ; +- statement: + - tag_statement: + - keyword: UNSET + - keyword: TAG + - keyword: ON + - keyword: CATALOG + - catalog_reference: + - naked_identifier: catalog + - quoted_identifier: '`tag1`' +- statement_terminator: ; +- statement: + - tag_statement: + - keyword: UNSET + - keyword: TAG + - keyword: ON + - keyword: COLUMN + - column_reference: + - naked_identifier: catalog + - dot: . + - naked_identifier: schema + - dot: . + - naked_identifier: table + - dot: . + - naked_identifier: column + - quoted_identifier: '`tag1`' +- statement_terminator: ; +- statement: + - tag_statement: + - keyword: UNSET + - keyword: TAG + - keyword: ON + - keyword: SCHEMA + - database_reference: + - naked_identifier: catalog + - dot: . + - naked_identifier: schema + - quoted_identifier: '`tag1`' +- statement_terminator: ; +- statement: + - tag_statement: + - keyword: UNSET + - keyword: TAG + - keyword: ON + - keyword: DATABASE + - database_reference: + - naked_identifier: catalog + - dot: . + - naked_identifier: database + - quoted_identifier: '`tag1`' +- statement_terminator: ; +- statement: + - tag_statement: + - keyword: UNSET + - keyword: TAG + - keyword: ON + - keyword: TABLE + - table_reference: + - naked_identifier: catalog + - dot: . + - naked_identifier: schema + - dot: . + - naked_identifier: table + - quoted_identifier: '`tag1`' +- statement_terminator: ; +- statement: + - tag_statement: + - keyword: UNSET + - keyword: TAG + - keyword: ON + - keyword: VIEW + - table_reference: + - naked_identifier: catalog + - dot: . + - naked_identifier: schema + - dot: . + - naked_identifier: view + - quoted_identifier: '`tag1`' +- statement_terminator: ; +- statement: + - tag_statement: + - keyword: UNSET + - keyword: TAG + - keyword: ON + - keyword: VOLUME + - volume_reference: + - naked_identifier: volume + - quoted_identifier: '`tag1`' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_time_zone.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_time_zone.yml index c3af4484c..bfea9b4fa 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_time_zone.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_time_zone.yml @@ -1,44 +1,49 @@ file: - statement: - - keyword: SET - - keyword: TIME - - keyword: ZONE - - keyword: LOCAL + - set_timezone_statement: + - keyword: SET + - keyword: TIME + - keyword: ZONE + - keyword: LOCAL - statement_terminator: ; - statement: - - keyword: SET - - keyword: TIME - - keyword: ZONE - - quoted_literal: '''America/Los_Angeles''' + - set_timezone_statement: + - keyword: SET + - keyword: TIME + - keyword: ZONE + - quoted_literal: '''America/Los_Angeles''' - statement_terminator: ; - statement: - - keyword: SET - - keyword: TIME - - keyword: ZONE - - quoted_literal: '''+08:00''' + - set_timezone_statement: + - keyword: SET + - keyword: TIME + - keyword: ZONE + - quoted_literal: '''+08:00''' - statement_terminator: ; - statement: - - keyword: SET - - keyword: TIME - - keyword: ZONE - - interval_expression: - - keyword: INTERVAL - - interval_literal: - - numeric_literal: '1' - - date_part: HOUR - - interval_literal: - - numeric_literal: '30' - - date_part: MINUTES + - set_timezone_statement: + - keyword: SET + - keyword: TIME + - keyword: ZONE + - interval_expression: + - keyword: INTERVAL + - interval_literal: + - numeric_literal: '1' + - date_part: HOUR + - interval_literal: + - numeric_literal: '30' + - date_part: MINUTES - statement_terminator: ; - statement: - - keyword: SET - - keyword: TIME - - keyword: ZONE - - interval_expression: - - keyword: INTERVAL - - interval_literal: - - signed_quoted_literal: '''08:30:00''' - - date_part: HOUR - - keyword: TO - - date_part: SECOND + - set_timezone_statement: + - keyword: SET + - keyword: TIME + - keyword: ZONE + - interval_expression: + - keyword: INTERVAL + - interval_literal: + - signed_quoted_literal: '''08:30:00''' + - date_part: HOUR + - keyword: TO + - date_part: SECOND - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_variable.sql b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_variable.sql new file mode 100644 index 000000000..8142fbbdc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_variable.sql @@ -0,0 +1,20 @@ +-- simple assignment +SET VAR var1 = 5; + +-- A complex expression assignment +SET VARIABLE var1 = (SELECT max(c1) FROM VALUES(1), (2) AS t(c1)); + +-- resetting the variable to DEFAULT (set in declare) +SET VAR var1 = DEFAULT; + +-- A multi variable assignment +SET VAR (var1, var2, var3) = (VALUES(100,'x123',DEFAULT)); + +-- escpaed function name +SET VARIABLE `foo` = select 'bar'; + +-- function call +set var tz = current_timezone(); + +-- set multiple vars in one statement +set var x1 = 12, x2 = 'helloworld'; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_variable.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_variable.yml new file mode 100644 index 000000000..0c60a5ebe --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/set_variable.yml @@ -0,0 +1,164 @@ +file: +- statement: + - set_variable_statement: + - keyword: SET + - keyword: VAR + - expression: + - column_reference: + - naked_identifier: var1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '5' +- statement_terminator: ; +- statement: + - set_variable_statement: + - keyword: SET + - keyword: VARIABLE + - expression: + - column_reference: + - naked_identifier: var1 + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: max + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c1 + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: c1 + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - set_variable_statement: + - keyword: SET + - keyword: VAR + - expression: + - column_reference: + - naked_identifier: var1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: DEFAULT +- statement_terminator: ; +- statement: + - set_variable_statement: + - keyword: SET + - keyword: VAR + - expression: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: var1 + - comma: ',' + - column_reference: + - naked_identifier: var2 + - comma: ',' + - column_reference: + - naked_identifier: var3 + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '100' + - comma: ',' + - expression: + - quoted_literal: '''x123''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: DEFAULT + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - set_variable_statement: + - keyword: SET + - keyword: VARIABLE + - expression: + - column_reference: + - quoted_identifier: '`foo`' + - comparison_operator: + - raw_comparison_operator: = + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - quoted_literal: '''bar''' +- statement_terminator: ; +- statement: + - set_variable_statement: + - keyword: set + - keyword: var + - expression: + - column_reference: + - naked_identifier: tz + - comparison_operator: + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: current_timezone + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) +- statement_terminator: ; +- statement: + - set_variable_statement: + - keyword: set + - keyword: var + - expression: + - column_reference: + - naked_identifier: x1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '12' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: x2 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''helloworld''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_databases.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_databases.yml index 4843e9828..e75c4885f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_databases.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_databases.yml @@ -9,7 +9,7 @@ file: - keyword: SHOW - keyword: DATABASES - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: userdb - statement_terminator: ; - statement: @@ -17,7 +17,7 @@ file: - keyword: SHOW - keyword: DATABASES - keyword: IN - - object_reference: + - database_reference: - naked_identifier: userdb - statement_terminator: ; - statement: @@ -25,7 +25,7 @@ file: - keyword: SHOW - keyword: DATABASES - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: default - keyword: LIKE - quoted_literal: '''sam*''' @@ -35,7 +35,7 @@ file: - keyword: SHOW - keyword: DATABASES - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: default - quoted_literal: '''sam*''' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_functions.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_functions.yml index a312b8c8d..36ae6c5ad 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_functions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_functions.yml @@ -92,7 +92,7 @@ file: - keyword: SHOW - keyword: FUNCTIONS - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: default - statement_terminator: ; - statement: @@ -101,7 +101,7 @@ file: - keyword: USER - keyword: FUNCTIONS - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: default - statement_terminator: ; - statement: @@ -109,7 +109,7 @@ file: - keyword: SHOW - keyword: FUNCTIONS - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: default - keyword: LIKE - quoted_literal: '''t*''' @@ -119,7 +119,7 @@ file: - keyword: SHOW - keyword: FUNCTIONS - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: default - quoted_literal: '''t*''' - statement_terminator: ; @@ -129,7 +129,7 @@ file: - keyword: USER - keyword: FUNCTIONS - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: default - keyword: LIKE - quoted_literal: '''t*''' @@ -140,7 +140,7 @@ file: - keyword: USER - keyword: FUNCTIONS - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: default - quoted_literal: '''t*''' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_tables.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_tables.yml index 7c546fd6c..ec1e561b8 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_tables.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_tables.yml @@ -9,7 +9,7 @@ file: - keyword: SHOW - keyword: TABLES - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: userdb - statement_terminator: ; - statement: @@ -17,7 +17,7 @@ file: - keyword: SHOW - keyword: TABLES - keyword: IN - - object_reference: + - database_reference: - naked_identifier: userdb - statement_terminator: ; - statement: @@ -25,7 +25,7 @@ file: - keyword: SHOW - keyword: TABLES - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: default - keyword: LIKE - quoted_literal: '''sam*''' @@ -35,7 +35,7 @@ file: - keyword: SHOW - keyword: TABLES - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: default - quoted_literal: '''sam*''' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_views.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_views.yml index 1131c7bdc..514bd44c2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_views.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_views.yml @@ -9,7 +9,7 @@ file: - keyword: SHOW - keyword: VIEWS - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: userdb - statement_terminator: ; - statement: @@ -17,7 +17,7 @@ file: - keyword: SHOW - keyword: VIEWS - keyword: IN - - object_reference: + - database_reference: - naked_identifier: global_temp - statement_terminator: ; - statement: @@ -25,7 +25,7 @@ file: - keyword: SHOW - keyword: VIEWS - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: default - keyword: LIKE - quoted_literal: '''sam*''' @@ -42,7 +42,7 @@ file: - keyword: SHOW - keyword: VIEWS - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: default - quoted_literal: '''sam*''' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_volumes.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_volumes.yml index 5e2f6d32f..a1b696b73 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_volumes.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/show_volumes.yml @@ -9,7 +9,7 @@ file: - keyword: SHOW - keyword: VOLUMES - keyword: IN - - object_reference: + - database_reference: - naked_identifier: sampledb - statement_terminator: ; - statement: @@ -17,7 +17,7 @@ file: - keyword: SHOW - keyword: VOLUMES - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: sampledb - statement_terminator: ; - statement: @@ -38,7 +38,7 @@ file: - keyword: SHOW - keyword: VOLUMES - keyword: IN - - object_reference: + - database_reference: - naked_identifier: sampledb - keyword: LIKE - quoted_literal: '''regex*''' @@ -48,7 +48,7 @@ file: - keyword: SHOW - keyword: VOLUMES - keyword: IN - - object_reference: + - database_reference: - naked_identifier: sampledb - quoted_literal: '''regex*''' - statement_terminator: ; @@ -57,7 +57,7 @@ file: - keyword: SHOW - keyword: VOLUMES - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: sampledb - keyword: LIKE - quoted_literal: '''regex*''' @@ -67,7 +67,7 @@ file: - keyword: SHOW - keyword: VOLUMES - keyword: FROM - - object_reference: + - database_reference: - naked_identifier: sampledb - quoted_literal: '''regex*''' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/unpivot.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/unpivot.yml index db4e71b55..afba2a993 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/unpivot.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/unpivot.yml @@ -12,7 +12,7 @@ file: - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: sales - unpivot_clause: - keyword: UNPIVOT @@ -20,38 +20,43 @@ file: - keyword: NULLS - bracketed: - start_bracket: ( - - naked_identifier: sales - - keyword: FOR - - naked_identifier: quarter - - keyword: IN - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: q1 - - alias_expression: - - keyword: AS - - quoted_identifier: '`Jan-Mar`' - - comma: ',' - - column_reference: - - naked_identifier: q2 - - alias_expression: - - keyword: AS - - quoted_identifier: '`Apr-Jun`' - - comma: ',' - - column_reference: - - naked_identifier: q3 - - alias_expression: - - keyword: AS - - quoted_identifier: '`Jul-Sep`' - - comma: ',' - - column_reference: - - naked_identifier: sales - - dot: . - - naked_identifier: q4 - - alias_expression: - - keyword: AS - - quoted_identifier: '`Oct-Dec`' - - end_bracket: ) + - unpivot_single_column: + - naked_identifier: sales + - keyword: FOR + - naked_identifier: quarter + - keyword: IN + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: q1 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`Jan-Mar`' + - comma: ',' + - column_reference: + - naked_identifier: q2 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`Apr-Jun`' + - comma: ',' + - column_reference: + - naked_identifier: q3 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`Jul-Sep`' + - comma: ',' + - column_reference: + - naked_identifier: sales + - dot: . + - naked_identifier: q4 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`Oct-Dec`' + - end_bracket: ) - end_bracket: ) - statement_terminator: ; - statement: @@ -67,54 +72,57 @@ file: - from_expression: - from_expression_element: - table_expression: - - object_reference: + - table_reference: - naked_identifier: oncall - unpivot_clause: - keyword: UNPIVOT - bracketed: - start_bracket: ( - - bracketed: - - start_bracket: ( - - naked_identifier: name - - comma: ',' - - naked_identifier: email - - comma: ',' - - naked_identifier: phone - - end_bracket: ) - - keyword: FOR - - naked_identifier: precedence - - keyword: IN - - bracketed: - - start_bracket: ( + - unpivot_multi_column: - bracketed: - start_bracket: ( - - column_reference: - - naked_identifier: name1 + - naked_identifier: name - comma: ',' - - column_reference: - - naked_identifier: email1 + - naked_identifier: email - comma: ',' - - column_reference: - - naked_identifier: phone1 + - naked_identifier: phone - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: primary - - comma: ',' + - keyword: FOR + - naked_identifier: precedence + - keyword: IN - bracketed: - start_bracket: ( - - column_reference: - - naked_identifier: name2 - - comma: ',' - - column_reference: - - naked_identifier: email2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: name1 + - comma: ',' + - column_reference: + - naked_identifier: email1 + - comma: ',' + - column_reference: + - naked_identifier: phone1 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: primary - comma: ',' - - column_reference: - - naked_identifier: phone2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: name2 + - comma: ',' + - column_reference: + - naked_identifier: email2 + - comma: ',' + - column_reference: + - naked_identifier: phone2 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: secondary - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: secondary - - end_bracket: ) - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/use_catalog.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/use_catalog.yml index 8de3a04f8..9eb854734 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/use_catalog.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/use_catalog.yml @@ -1,31 +1,36 @@ file: - statement: - - keyword: USE - - keyword: CATALOG - - object_reference: - - naked_identifier: catalog_name + - use_catalog_statement: + - keyword: USE + - keyword: CATALOG + - catalog_reference: + - naked_identifier: catalog_name - statement_terminator: ; - statement: - - keyword: USE - - keyword: CATALOG - - object_reference: - - naked_identifier: hive_metastore + - use_catalog_statement: + - keyword: USE + - keyword: CATALOG + - catalog_reference: + - naked_identifier: hive_metastore - statement_terminator: ; - statement: - - keyword: USE - - keyword: CATALOG - - object_reference: - - quoted_identifier: '''hive_metastore''' + - use_catalog_statement: + - keyword: USE + - keyword: CATALOG + - catalog_reference: + - quoted_identifier: '''hive_metastore''' - statement_terminator: ; - statement: - - keyword: USE - - keyword: CATALOG - - object_reference: - - quoted_identifier: '`some_catalog`' + - use_catalog_statement: + - keyword: USE + - keyword: CATALOG + - catalog_reference: + - quoted_identifier: '`some_catalog`' - statement_terminator: ; - statement: - - keyword: USE - - keyword: CATALOG - - object_reference: - - naked_identifier: some_cat + - use_catalog_statement: + - keyword: USE + - keyword: CATALOG + - catalog_reference: + - naked_identifier: some_cat - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/use_database.yml b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/use_database.yml index 6b37b6b69..4a1519af2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/use_database.yml +++ b/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/use_database.yml @@ -2,60 +2,70 @@ file: - statement: - use_statement: - keyword: USE - - object_reference: + - database_reference: - naked_identifier: database_name - statement_terminator: ; - statement: - use_statement: - keyword: USE - - object_reference: + - database_reference: - naked_identifier: userdb - statement_terminator: ; - statement: - use_statement: - keyword: USE - - object_reference: + - database_reference: - naked_identifier: userdb1 - statement_terminator: ; - statement: - - keyword: USE - - keyword: DATABASE - - object_reference: - - naked_identifier: database_name + - use_database_statement: + - keyword: USE + - keyword: DATABASE + - database_reference: + - naked_identifier: database_name - statement_terminator: ; - statement: - - keyword: USE - - keyword: SCHEMA - - object_reference: - - naked_identifier: database_name + - use_database_statement: + - keyword: USE + - keyword: SCHEMA + - database_reference: + - naked_identifier: database_name - statement_terminator: ; - statement: - use_statement: - keyword: USE - - object_reference: - - keyword: IDENTIFIER - - bracketed: - - start_bracket: ( - - quoted_identifier: '''database_name''' - - end_bracket: ) -- statement_terminator: ; -- statement: - - keyword: USE - - keyword: DATABASE - - object_reference: - - keyword: IDENTIFIER - - bracketed: - - start_bracket: ( - - quoted_identifier: '''database_name''' - - end_bracket: ) -- statement_terminator: ; -- statement: - - keyword: USE - - keyword: SCHEMA - - object_reference: - - keyword: IDENTIFIER - - bracketed: - - start_bracket: ( - - quoted_identifier: '''database_name''' - - end_bracket: ) + - database_reference: + - identifier_clause_segment: + - keyword: IDENTIFIER + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''database_name''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - use_database_statement: + - keyword: USE + - keyword: DATABASE + - database_reference: + - identifier_clause_segment: + - keyword: IDENTIFIER + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''database_name''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - use_database_statement: + - keyword: USE + - keyword: SCHEMA + - database_reference: + - identifier_clause_segment: + - keyword: IDENTIFIER + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''database_name''' + - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/anti_semi_join.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/anti_semi_join.sql new file mode 100644 index 000000000..7dbf1b4f0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/anti_semi_join.sql @@ -0,0 +1,15 @@ +SELECT cars.name, cars.manufacturer +FROM cars SEMI JOIN region +ON cars.region = region.id; + +SELECT cars.name, cars.manufacturer +FROM cars ANTI JOIN safety_data +ON cars.safety_report_id = safety_data.report_id; + +SELECT cars.name, cars.manufacturer +FROM cars SEMI JOIN region +USING (region_id); + +SELECT cars.name, cars.manufacturer +FROM cars ANTI JOIN region +USING (region_id); diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/anti_semi_join.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/anti_semi_join.yml new file mode 100644 index 000000000..9b4d7836f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/anti_semi_join.yml @@ -0,0 +1,157 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: cars + - dot: . + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: cars + - dot: . + - naked_identifier: manufacturer + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: cars + - join_clause: + - keyword: SEMI + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: region + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: cars + - dot: . + - naked_identifier: region + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: region + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: cars + - dot: . + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: cars + - dot: . + - naked_identifier: manufacturer + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: cars + - join_clause: + - keyword: ANTI + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: safety_data + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: cars + - dot: . + - naked_identifier: safety_report_id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: safety_data + - dot: . + - naked_identifier: report_id +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: cars + - dot: . + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: cars + - dot: . + - naked_identifier: manufacturer + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: cars + - join_clause: + - keyword: SEMI + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: region + - keyword: USING + - bracketed: + - start_bracket: ( + - naked_identifier: region_id + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: cars + - dot: . + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: cars + - dot: . + - naked_identifier: manufacturer + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: cars + - join_clause: + - keyword: ANTI + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: region + - keyword: USING + - bracketed: + - start_bracket: ( + - naked_identifier: region_id + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/asof_join.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/asof_join.sql new file mode 100644 index 000000000..ea9c253fd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/asof_join.sql @@ -0,0 +1,40 @@ +SELECT + t.*, + p.price +FROM trades AS t ASOF JOIN prices AS p + ON t.symbol = p.symbol AND t.when >= p.when; + +SELECT * +FROM trades AS t ASOF LEFT JOIN prices AS p + ON t.symbol = p.symbol AND t.when >= p.when; + +SELECT * +FROM trades AS t ASOF RIGHT JOIN prices AS p + ON t.symbol = p.symbol AND t.when >= p.when; + +SELECT * +FROM trades AS t ASOF FULL OUTER JOIN prices AS p + ON t.symbol = p.symbol AND t.when >= p.when; + +SELECT * +FROM trades AS t ASOF ANTI JOIN prices AS p + ON t.symbol = p.symbol AND t.when >= p.when; + +SELECT * +FROM trades AS t ASOF SEMI JOIN prices AS p + ON t.symbol = p.symbol AND t.when >= p.when; + + +-- ASOF joins can also specify join conditions on matching column names with +-- the USING syntax, but the last attribute in the list must be the inequality, +-- which will be greater than or equal to (>=): +SELECT * +FROM trades ASOF JOIN prices USING (symbol, "when"); +-- Returns symbol, trades.when, price (but NOT prices.when) + +SELECT + t.symbol, + t.when AS trade_when, + p.when AS price_when, + price +FROM trades AS t ASOF LEFT JOIN prices AS p USING (symbol, "when"); diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/asof_join.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/asof_join.yml new file mode 100644 index 000000000..12568f593 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/asof_join.yml @@ -0,0 +1,445 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - naked_identifier: t + - dot: . + - star: '*' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: price + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: trades + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - join_clause: + - keyword: ASOF + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: prices + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: p + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: symbol + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: symbol + - binary_operator: AND + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier_all: when + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier_all: when +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: trades + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - join_clause: + - keyword: ASOF + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: prices + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: p + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: symbol + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: symbol + - binary_operator: AND + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier_all: when + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier_all: when +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: trades + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - join_clause: + - keyword: ASOF + - keyword: RIGHT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: prices + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: p + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: symbol + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: symbol + - binary_operator: AND + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier_all: when + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier_all: when +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: trades + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - join_clause: + - keyword: ASOF + - keyword: FULL + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: prices + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: p + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: symbol + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: symbol + - binary_operator: AND + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier_all: when + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier_all: when +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: trades + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - join_clause: + - keyword: ASOF + - keyword: ANTI + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: prices + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: p + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: symbol + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: symbol + - binary_operator: AND + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier_all: when + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier_all: when +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: trades + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - join_clause: + - keyword: ASOF + - keyword: SEMI + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: prices + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: p + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: symbol + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: symbol + - binary_operator: AND + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier_all: when + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier_all: when +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: trades + - join_clause: + - keyword: ASOF + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: prices + - keyword: USING + - bracketed: + - start_bracket: ( + - naked_identifier: symbol + - comma: ',' + - quoted_identifier: '"when"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: symbol + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier_all: when + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: trade_when + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier_all: when + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: price_when + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: price + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: trades + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - join_clause: + - keyword: ASOF + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: prices + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: p + - keyword: USING + - bracketed: + - start_bracket: ( + - naked_identifier: symbol + - comma: ',' + - quoted_identifier: '"when"' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/copy.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/copy.sql new file mode 100644 index 000000000..4e523a3ba --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/copy.sql @@ -0,0 +1,86 @@ +-- Basic COPY TO with FORMAT +COPY (SELECT * FROM tbl) TO 'output.parquet' (FORMAT parquet); + +-- COPY TO with WITH keyword +COPY (SELECT * FROM tbl) TO 'output.csv' WITH (FORMAT csv); + +-- COPY TO with COMPRESSION +COPY (SELECT NOW()) TO 'test.parquet' WITH (FORMAT parquet, COMPRESSION 'snappy'); + +-- COPY TO with COMPRESSION without quotes +COPY (SELECT * FROM data) TO 'output.parquet' (FORMAT parquet, COMPRESSION gzip); + +-- COPY TO with COMPRESSION_LEVEL +COPY (SELECT * FROM data) TO 'compressed.parquet' WITH ( + FORMAT parquet, + COMPRESSION 'zstd', + COMPRESSION_LEVEL 9 +); + +-- COPY TO with ROW_GROUP_SIZE +COPY (SELECT * FROM large_table) TO 'output.parquet' ( + FORMAT parquet, + ROW_GROUP_SIZE 100000 +); + +-- COPY TO with PARQUET_VERSION +COPY (SELECT * FROM data) TO 'output.parquet' ( + FORMAT parquet, + PARQUET_VERSION 'V2' +); + +-- COPY TO with PARTITION_BY single column +COPY (SELECT * FROM sales) TO 'partitioned' WITH ( + FORMAT parquet, + PARTITION_BY year +); + +-- COPY TO with PARTITION_BY multiple columns +COPY (SELECT * FROM sales) TO 'partitioned' ( + FORMAT parquet, + PARTITION_BY (year, month) +); + +-- COPY TO with WRITE_PARTITION_COLUMNS +COPY (SELECT * FROM sales) TO 'partitioned' WITH ( + FORMAT parquet, + PARTITION_BY (year, month), + WRITE_PARTITION_COLUMNS true +); + +-- COPY TO with OVERWRITE +COPY (SELECT * FROM data) TO 'output.parquet' ( + FORMAT parquet, + OVERWRITE true +); + +-- COPY TO with OVERWRITE_OR_IGNORE +COPY (SELECT * FROM data) TO 'output.parquet' WITH ( + FORMAT parquet, + OVERWRITE_OR_IGNORE true +); + +-- COPY TO with APPEND +COPY (SELECT * FROM new_data) TO 'existing.parquet' ( + FORMAT parquet, + APPEND true +); + +-- COPY TO with multiple options +COPY (SELECT * FROM sales) TO 'export.parquet' WITH ( + FORMAT parquet, + COMPRESSION 'zstd', + COMPRESSION_LEVEL 3, + ROW_GROUP_SIZE 50000, + PARTITION_BY region, + OVERWRITE true +); + +-- COPY TO from table reference +COPY my_table TO 'output.parquet' (FORMAT parquet); + +-- COPY TO from table with column list +COPY my_table (col1, col2, col3) TO 'output.csv' WITH (FORMAT csv); + +-- COPY FROM basic +COPY my_table FROM 'input.csv' WITH (FORMAT csv, HEADER true); diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/copy.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/copy.yml new file mode 100644 index 000000000..581a83cbb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/copy.yml @@ -0,0 +1,522 @@ +file: +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl + - end_bracket: ) + - keyword: TO + - quoted_literal: '''output.parquet''' + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: parquet + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl + - end_bracket: ) + - keyword: TO + - quoted_literal: '''output.csv''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: csv + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: NOW + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - keyword: TO + - quoted_literal: '''test.parquet''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: parquet + - comma: ',' + - keyword: COMPRESSION + - quoted_literal: '''snappy''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: data + - end_bracket: ) + - keyword: TO + - quoted_literal: '''output.parquet''' + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: parquet + - comma: ',' + - keyword: COMPRESSION + - naked_identifier: gzip + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: data + - end_bracket: ) + - keyword: TO + - quoted_literal: '''compressed.parquet''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: parquet + - comma: ',' + - keyword: COMPRESSION + - quoted_literal: '''zstd''' + - comma: ',' + - keyword: COMPRESSION_LEVEL + - numeric_literal: '9' + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: large_table + - end_bracket: ) + - keyword: TO + - quoted_literal: '''output.parquet''' + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: parquet + - comma: ',' + - keyword: ROW_GROUP_SIZE + - numeric_literal: '100000' + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: data + - end_bracket: ) + - keyword: TO + - quoted_literal: '''output.parquet''' + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: parquet + - comma: ',' + - keyword: PARQUET_VERSION + - quoted_literal: '''V2''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sales + - end_bracket: ) + - keyword: TO + - quoted_literal: '''partitioned''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: parquet + - comma: ',' + - keyword: PARTITION_BY + - column_reference: + - naked_identifier: year + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sales + - end_bracket: ) + - keyword: TO + - quoted_literal: '''partitioned''' + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: parquet + - comma: ',' + - keyword: PARTITION_BY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: year + - comma: ',' + - column_reference: + - naked_identifier: month + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sales + - end_bracket: ) + - keyword: TO + - quoted_literal: '''partitioned''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: parquet + - comma: ',' + - keyword: PARTITION_BY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: year + - comma: ',' + - column_reference: + - naked_identifier: month + - end_bracket: ) + - comma: ',' + - keyword: WRITE_PARTITION_COLUMNS + - boolean_literal: 'true' + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: data + - end_bracket: ) + - keyword: TO + - quoted_literal: '''output.parquet''' + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: parquet + - comma: ',' + - keyword: OVERWRITE + - boolean_literal: 'true' + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: data + - end_bracket: ) + - keyword: TO + - quoted_literal: '''output.parquet''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: parquet + - comma: ',' + - keyword: OVERWRITE_OR_IGNORE + - boolean_literal: 'true' + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: new_data + - end_bracket: ) + - keyword: TO + - quoted_literal: '''existing.parquet''' + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: parquet + - comma: ',' + - keyword: APPEND + - boolean_literal: 'true' + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sales + - end_bracket: ) + - keyword: TO + - quoted_literal: '''export.parquet''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: parquet + - comma: ',' + - keyword: COMPRESSION + - quoted_literal: '''zstd''' + - comma: ',' + - keyword: COMPRESSION_LEVEL + - numeric_literal: '3' + - comma: ',' + - keyword: ROW_GROUP_SIZE + - numeric_literal: '50000' + - comma: ',' + - keyword: PARTITION_BY + - column_reference: + - naked_identifier: region + - comma: ',' + - keyword: OVERWRITE + - boolean_literal: 'true' + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: TO + - quoted_literal: '''output.parquet''' + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: parquet + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - comma: ',' + - column_reference: + - naked_identifier: col3 + - end_bracket: ) + - keyword: TO + - quoted_literal: '''output.csv''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: csv + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - quoted_literal: '''input.csv''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: csv + - comma: ',' + - keyword: HEADER + - boolean_literal: 'true' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_macro.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_macro.sql new file mode 100644 index 000000000..77c934e2a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_macro.sql @@ -0,0 +1,45 @@ +CREATE MACRO add(a, b) AS a + b; +CREATE MACRO ifelse(a, b, c) AS CASE WHEN a THEN b ELSE c END; +CREATE MACRO one() AS (SELECT 1); +CREATE MACRO plus_one(a) AS ( + WITH cte AS (SELECT 1 AS a) + + SELECT cte.a + cte.a FROM cte +); +CREATE FUNCTION main.my_avg(x) AS sum(x) / count(x); +CREATE MACRO add_default(a, b := 5) AS a + b; +CREATE MACRO arr_append(l, e) AS list_concat(l, list_value(e)); + +CREATE MACRO static_table() AS TABLE + SELECT + 'Hello' AS column1, + 'World' AS column2; + +CREATE MACRO dynamic_table(col1_value, col2_value) AS TABLE + SELECT + col1_value AS column1, + col2_value AS column2; + +CREATE OR REPLACE TEMP MACRO dynamic_table(col1_value, col2_value) AS TABLE + SELECT + col1_value AS column1, + col2_value AS column2 + UNION ALL + SELECT + 'Hello' AS col1_value, + 456 AS col2_value; + +CREATE MACRO get_users(i) AS TABLE + SELECT * FROM users WHERE uid IN (SELECT unnest(i)); + +CREATE OR REPLACE MACRO list_builder( + col1, + col2 +) AS +CASE + WHEN col1 AND col2 THEN ['x', 'y'] + WHEN col1 THEN ['x'] + WHEN col2 THEN ['y'] + ELSE + [] +END; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_macro.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_macro.yml new file mode 100644 index 000000000..e0fee8587 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_macro.yml @@ -0,0 +1,487 @@ +file: +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: MACRO + - function_name: + - function_name_identifier: add + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: a + - comma: ',' + - data_type: + - data_type_identifier: b + - end_bracket: ) + - keyword: AS + - expression: + - column_reference: + - naked_identifier: a + - binary_operator: + + - column_reference: + - naked_identifier: b +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: MACRO + - function_name: + - function_name_identifier: ifelse + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: a + - comma: ',' + - data_type: + - data_type_identifier: b + - comma: ',' + - data_type: + - data_type_identifier: c + - end_bracket: ) + - keyword: AS + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: a + - keyword: THEN + - expression: + - column_reference: + - naked_identifier: b + - else_clause: + - keyword: ELSE + - expression: + - column_reference: + - naked_identifier: c + - keyword: END +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: MACRO + - function_name: + - function_name_identifier: one + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: AS + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: MACRO + - function_name: + - function_name_identifier: plus_one + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: a + - end_bracket: ) + - keyword: AS + - expression: + - bracketed: + - start_bracket: ( + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: cte + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: cte + - dot: . + - naked_identifier: a + - binary_operator: + + - column_reference: + - naked_identifier: cte + - dot: . + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: cte + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - naked_identifier: main + - dot: . + - function_name_identifier: my_avg + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: x + - end_bracket: ) + - keyword: AS + - expression: + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - end_bracket: ) + - binary_operator: / + - function: + - function_name: + - function_name_identifier: count + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: MACRO + - function_name: + - function_name_identifier: add_default + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: a + - comma: ',' + - data_type: + - data_type_identifier: b + - assignment_operator: := + - expression: + - numeric_literal: '5' + - end_bracket: ) + - keyword: AS + - expression: + - column_reference: + - naked_identifier: a + - binary_operator: + + - column_reference: + - naked_identifier: b +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: MACRO + - function_name: + - function_name_identifier: arr_append + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: l + - comma: ',' + - data_type: + - data_type_identifier: e + - end_bracket: ) + - keyword: AS + - expression: + - function: + - function_name: + - function_name_identifier: list_concat + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: l + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: list_value + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: e + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: MACRO + - function_name: + - function_name_identifier: static_table + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: AS + - keyword: TABLE + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''Hello''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - quoted_literal: '''World''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: column2 +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: MACRO + - function_name: + - function_name_identifier: dynamic_table + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: col1_value + - comma: ',' + - data_type: + - data_type_identifier: col2_value + - end_bracket: ) + - keyword: AS + - keyword: TABLE + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1_value + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2_value + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: column2 +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: TEMP + - keyword: MACRO + - function_name: + - function_name_identifier: dynamic_table + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: col1_value + - comma: ',' + - data_type: + - data_type_identifier: col2_value + - end_bracket: ) + - keyword: AS + - keyword: TABLE + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1_value + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2_value + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: column2 + - set_operator: + - keyword: UNION + - keyword: ALL + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''Hello''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: col1_value + - comma: ',' + - select_clause_element: + - numeric_literal: '456' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: col2_value +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: MACRO + - function_name: + - function_name_identifier: get_users + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: i + - end_bracket: ) + - keyword: AS + - keyword: TABLE + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: users + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: uid + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: unnest + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: i + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: MACRO + - function_name: + - function_name_identifier: list_builder + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: col1 + - comma: ',' + - data_type: + - data_type_identifier: col2 + - end_bracket: ) + - keyword: AS + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: col1 + - binary_operator: AND + - column_reference: + - naked_identifier: col2 + - keyword: THEN + - expression: + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''x''' + - comma: ',' + - quoted_literal: '''y''' + - end_square_bracket: ']' + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: col1 + - keyword: THEN + - expression: + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''x''' + - end_square_bracket: ']' + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: col2 + - keyword: THEN + - expression: + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''y''' + - end_square_bracket: ']' + - else_clause: + - keyword: ELSE + - expression: + - array_literal: + - start_square_bracket: '[' + - end_square_bracket: ']' + - keyword: END +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_table.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_table.sql new file mode 100644 index 000000000..d6a9da03c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_table.sql @@ -0,0 +1,104 @@ +/* Examples from https://duckdb.org/docs/sql/statements/create_table */ + +-- create a table with two integer columns (i and j) +CREATE TABLE t1 (i INTEGER, j INTEGER); + +-- create a table with a primary key +CREATE TABLE t1 (id INTEGER PRIMARY KEY, j VARCHAR); + +-- create a table with a composite primary key +CREATE TABLE t1 (id INTEGER, j VARCHAR, PRIMARY KEY (id, j)); + +-- create a table with various different types and constraints +CREATE TABLE t1 ( + i INTEGER NOT NULL, + decimalnr DOUBLE CHECK (decimalnr < 10), + date DATE UNIQUE, + time TIMESTAMP +); + +-- create a table from the result of a query +CREATE TABLE t1 AS SELECT + 42 AS i, + 84 AS j; + +-- create a table from a CSV file using AUTO-DETECT (i.e., automatically detecting column names and types) +CREATE TABLE t1 AS SELECT * FROM read_csv_auto('path/file.csv'); + +-- we can use the FROM-first syntax to omit 'SELECT *' +CREATE TABLE t1 AS FROM read_csv_auto('path/file.csv'); + +-- create a temporary table from a CSV file (automatically detecting column names and types) +CREATE TEMP TABLE t1 AS SELECT * FROM read_csv('path/file.csv'); + +-- create a table with two integer columns (i and j) even if t1 already exists +CREATE OR REPLACE TABLE t1 (i INTEGER, j INTEGER); + +-- create a table with two integer columns (i and j) only if t1 does not exist yet. +CREATE TABLE IF NOT EXISTS t1 (i INTEGER, j INTEGER); + +CREATE TABLE t1 ( + id INTEGER PRIMARY KEY, + percentage INTEGER CHECK (0 <= percentage AND percentage <= 100) +); + +CREATE TABLE t2 (id INTEGER PRIMARY KEY, x INTEGER, y INTEGER CHECK (x < y)); + +CREATE TABLE t3 ( + id INTEGER PRIMARY KEY, + x INTEGER, + y INTEGER, + CONSTRAINT x_smaller_than_y CHECK (x < y) +); + +CREATE TABLE t1 (id INTEGER PRIMARY KEY, j VARCHAR); +CREATE TABLE t2 ( + id INTEGER PRIMARY KEY, + t1_id INTEGER, + FOREIGN KEY (t1_id) REFERENCES t1 (id) +); + +CREATE TABLE t3 (id INTEGER, j VARCHAR, PRIMARY KEY (id, j)); +CREATE TABLE t4 ( + id INTEGER PRIMARY KEY, t3_id INTEGER, t3_j VARCHAR, + FOREIGN KEY (t3_id, t3_j) REFERENCES t3 (id, j) +); + +CREATE TABLE t5 (id INTEGER UNIQUE, j VARCHAR); +CREATE TABLE t6 ( + id INTEGER PRIMARY KEY, + t5_id INTEGER, + FOREIGN KEY (t5_id) REFERENCES t5 (id) +); + +-- The simplest syntax for a generated column. +-- The type is derived from the expression, and the variant defaults to VIRTUAL +CREATE TABLE t1 (x FLOAT, two_x AS (2 * x)); + +-- Fully specifying the same generated column for completeness +CREATE TABLE t1 (x FLOAT, two_x FLOAT GENERATED ALWAYS AS (2 * x) VIRTUAL); + + +CREATE TABLE t_values AS VALUES (1); + +CREATE TABLE t_dflt_int (id INTEGER DEFAULT 0); + +CREATE OR REPLACE TABLE t_dflt_dt (dt DATE DEFAULT CURRENT_DATE); + +CREATE TABLE t ( + s STRUCT( + val STRING + ) +); + +CREATE TABLE t ( + s STRUCT( + val STRING, + s1 STRUCT( + ival INT, + jval INT + ) + ) +); + +CREATE TABLE map (tags MAP(VARCHAR, VARCHAR)); diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_table.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_table.yml new file mode 100644 index 000000000..222087d2f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_table.yml @@ -0,0 +1,788 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: i + - data_type: + - keyword: INTEGER + - comma: ',' + - column_reference: + - naked_identifier: j + - data_type: + - keyword: INTEGER + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_reference: + - naked_identifier: j + - data_type: + - keyword: VARCHAR + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - data_type: + - keyword: INTEGER + - comma: ',' + - column_reference: + - naked_identifier: j + - data_type: + - keyword: VARCHAR + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - comma: ',' + - column_reference: + - naked_identifier: j + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: i + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_reference: + - naked_identifier: decimalnr + - data_type: + - data_type_identifier: DOUBLE + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: decimalnr + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '10' + - end_bracket: ) + - comma: ',' + - column_reference: + - naked_identifier: date + - data_type: + - datetime_type_identifier: + - keyword: DATE + - column_constraint_segment: + - keyword: UNIQUE + - comma: ',' + - column_reference: + - naked_identifier: time + - data_type: + - datetime_type_identifier: + - keyword: TIMESTAMP + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '42' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: i + - comma: ',' + - select_clause_element: + - numeric_literal: '84' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: j +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: read_csv_auto + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''path/file.csv''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: AS + - select_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: read_csv_auto + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''path/file.csv''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TEMP + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: read_csv + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''path/file.csv''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: i + - data_type: + - keyword: INTEGER + - comma: ',' + - column_reference: + - naked_identifier: j + - data_type: + - keyword: INTEGER + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: i + - data_type: + - keyword: INTEGER + - comma: ',' + - column_reference: + - naked_identifier: j + - data_type: + - keyword: INTEGER + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_reference: + - naked_identifier: percentage + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0' + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - column_reference: + - naked_identifier: percentage + - binary_operator: AND + - column_reference: + - naked_identifier: percentage + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - numeric_literal: '100' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_reference: + - naked_identifier: x + - data_type: + - keyword: INTEGER + - comma: ',' + - column_reference: + - naked_identifier: y + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: < + - column_reference: + - naked_identifier: y + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t3 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_reference: + - naked_identifier: x + - data_type: + - keyword: INTEGER + - comma: ',' + - column_reference: + - naked_identifier: y + - data_type: + - keyword: INTEGER + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: x_smaller_than_y + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: < + - column_reference: + - naked_identifier: y + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_reference: + - naked_identifier: j + - data_type: + - keyword: VARCHAR + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_reference: + - naked_identifier: t1_id + - data_type: + - keyword: INTEGER + - comma: ',' + - table_constraint: + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: t1_id + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t3 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - data_type: + - keyword: INTEGER + - comma: ',' + - column_reference: + - naked_identifier: j + - data_type: + - keyword: VARCHAR + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - comma: ',' + - column_reference: + - naked_identifier: j + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t4 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_reference: + - naked_identifier: t3_id + - data_type: + - keyword: INTEGER + - comma: ',' + - column_reference: + - naked_identifier: t3_j + - data_type: + - keyword: VARCHAR + - comma: ',' + - table_constraint: + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: t3_id + - comma: ',' + - column_reference: + - naked_identifier: t3_j + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: t3 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - comma: ',' + - column_reference: + - naked_identifier: j + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t5 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: UNIQUE + - comma: ',' + - column_reference: + - naked_identifier: j + - data_type: + - keyword: VARCHAR + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t6 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_reference: + - naked_identifier: t5_id + - data_type: + - keyword: INTEGER + - comma: ',' + - table_constraint: + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: t5_id + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: t5 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: x + - data_type: + - keyword: FLOAT + - comma: ',' + - column_reference: + - naked_identifier: two_x + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - binary_operator: '*' + - column_reference: + - naked_identifier: x + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: x + - data_type: + - keyword: FLOAT + - comma: ',' + - column_reference: + - naked_identifier: two_x + - data_type: + - keyword: FLOAT + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - binary_operator: '*' + - column_reference: + - naked_identifier: x + - end_bracket: ) + - keyword: VIRTUAL + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t_values + - keyword: AS + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t_dflt_int + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: DEFAULT + - numeric_literal: '0' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: TABLE + - table_reference: + - naked_identifier: t_dflt_dt + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: dt + - data_type: + - datetime_type_identifier: + - keyword: DATE + - column_constraint_segment: + - keyword: DEFAULT + - expression: + - bare_function: CURRENT_DATE + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: s + - data_type: + - struct_type: + - keyword: STRUCT + - struct_type_schema: + - bracketed: + - start_bracket: ( + - parameter: val + - data_type: + - data_type_identifier: STRING + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: s + - data_type: + - struct_type: + - keyword: STRUCT + - struct_type_schema: + - bracketed: + - start_bracket: ( + - parameter: val + - data_type: + - data_type_identifier: STRING + - comma: ',' + - parameter: s1 + - data_type: + - struct_type: + - keyword: STRUCT + - struct_type_schema: + - bracketed: + - start_bracket: ( + - parameter: ival + - data_type: + - keyword: INT + - comma: ',' + - parameter: jval + - data_type: + - keyword: INT + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: map + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: tags + - data_type: + - map_type: + - keyword: MAP + - map_type_schema: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: VARCHAR + - comma: ',' + - data_type: + - keyword: VARCHAR + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_type.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_type.sql new file mode 100644 index 000000000..d041f23a1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_type.sql @@ -0,0 +1,7 @@ +CREATE TYPE mood AS ENUM ('happy', 'sad', 'curious'); +CREATE TYPE many_things AS STRUCT(k integer, l varchar); +CREATE TYPE one_thing AS UNION (number integer, string varchar); +CREATE TYPE x_index AS integer; +CREATE TYPE myschema.mytype AS int; +CREATE TYPE "myschema".mytype2 AS int; +CREATE TYPE myschema.mytype3 AS myschema.mytype2; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_type.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_type.yml new file mode 100644 index 000000000..ee9282b65 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_type.yml @@ -0,0 +1,108 @@ +file: +- statement: + - create_type_statement: + - keyword: CREATE + - keyword: TYPE + - data_type: + - data_type_identifier: mood + - keyword: AS + - keyword: ENUM + - bracketed: + - start_bracket: ( + - quoted_literal: '''happy''' + - comma: ',' + - quoted_literal: '''sad''' + - comma: ',' + - quoted_literal: '''curious''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_type_statement: + - keyword: CREATE + - keyword: TYPE + - data_type: + - data_type_identifier: many_things + - keyword: AS + - data_type: + - struct_type: + - keyword: STRUCT + - struct_type_schema: + - bracketed: + - start_bracket: ( + - parameter: k + - data_type: + - keyword: integer + - comma: ',' + - parameter: l + - data_type: + - keyword: varchar + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_type_statement: + - keyword: CREATE + - keyword: TYPE + - data_type: + - data_type_identifier: one_thing + - keyword: AS + - keyword: UNION + - struct_type_schema: + - bracketed: + - start_bracket: ( + - parameter: number + - data_type: + - keyword: integer + - comma: ',' + - parameter: string + - data_type: + - keyword: varchar + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_type_statement: + - keyword: CREATE + - keyword: TYPE + - data_type: + - data_type_identifier: x_index + - keyword: AS + - data_type: + - keyword: integer +- statement_terminator: ; +- statement: + - create_type_statement: + - keyword: CREATE + - keyword: TYPE + - data_type: + - naked_identifier: myschema + - dot: . + - data_type_identifier: mytype + - keyword: AS + - data_type: + - keyword: int +- statement_terminator: ; +- statement: + - create_type_statement: + - keyword: CREATE + - keyword: TYPE + - data_type: + - quoted_identifier: '"myschema"' + - dot: . + - data_type_identifier: mytype2 + - keyword: AS + - data_type: + - keyword: int +- statement_terminator: ; +- statement: + - create_type_statement: + - keyword: CREATE + - keyword: TYPE + - data_type: + - naked_identifier: myschema + - dot: . + - data_type_identifier: mytype3 + - keyword: AS + - data_type: + - naked_identifier: myschema + - dot: . + - data_type_identifier: mytype2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_view.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_view.sql new file mode 100644 index 000000000..ec5f48dc8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_view.sql @@ -0,0 +1,4 @@ +CREATE VIEW v1 AS SELECT * FROM tbl; +CREATE OR REPLACE VIEW v1 AS SELECT 42; +CREATE VIEW v1(a) AS SELECT 42; +create view if not exists v as select 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_view.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_view.yml new file mode 100644 index 000000000..cc62920d5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/create_view.yml @@ -0,0 +1,72 @@ +file: +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '42' +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '42' +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: create + - keyword: view + - keyword: if + - keyword: not + - keyword: exists + - table_reference: + - naked_identifier: v + - keyword: as + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/describe.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/describe.sql deleted file mode 100644 index 6d7d4f71d..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/describe.sql +++ /dev/null @@ -1,3 +0,0 @@ -DESCRIBE tbl; - -DESCRIBE SELECT * FROM tbl; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/double_equal.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/double_equal.sql new file mode 100644 index 000000000..427afdd15 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/double_equal.sql @@ -0,0 +1,7 @@ +SELECT + COALESCE( + MAX(CASE WHEN col1 == 'A' THEN cola END), + MAX(CASE WHEN col1 == 'B' THEN colb END), + MAX(CASE WHEN col1 = 'C' THEN colb END) + ) AS result +FROM my_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/double_equal.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/double_equal.yml new file mode 100644 index 000000000..6231b2d06 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/double_equal.yml @@ -0,0 +1,97 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: COALESCE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: MAX + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: col1 + - comparison_operator: == + - quoted_literal: '''A''' + - keyword: THEN + - expression: + - column_reference: + - naked_identifier: cola + - keyword: END + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: MAX + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: col1 + - comparison_operator: == + - quoted_literal: '''B''' + - keyword: THEN + - expression: + - column_reference: + - naked_identifier: colb + - keyword: END + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: MAX + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''C''' + - keyword: THEN + - expression: + - column_reference: + - naked_identifier: colb + - keyword: END + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: result + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/drop_macro.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/drop_macro.sql new file mode 100644 index 000000000..4a8aab818 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/drop_macro.sql @@ -0,0 +1,9 @@ +DROP MACRO mcr; +DROP MACRO TABLE mt; +DROP FUNCTION mcr; +DROP FUNCTION TABLE mt; +DROP MACRO IF EXISTS mymacro; +DROP MACRO myschema.mymacro; +DROP MACRO "myschema".mymacro; +DROP MACRO mcr RESTRICT; +DROP MACRO mcr CASCADE; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/drop_macro.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/drop_macro.yml new file mode 100644 index 000000000..9d8ce2be4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/drop_macro.yml @@ -0,0 +1,74 @@ +file: +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: MACRO + - function_name: + - function_name_identifier: mcr +- statement_terminator: ; +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: MACRO + - keyword: TABLE + - function_name: + - function_name_identifier: mt +- statement_terminator: ; +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: FUNCTION + - function_name: + - function_name_identifier: mcr +- statement_terminator: ; +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: FUNCTION + - keyword: TABLE + - function_name: + - function_name_identifier: mt +- statement_terminator: ; +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: MACRO + - keyword: IF + - keyword: EXISTS + - function_name: + - function_name_identifier: mymacro +- statement_terminator: ; +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: MACRO + - function_name: + - naked_identifier: myschema + - dot: . + - function_name_identifier: mymacro +- statement_terminator: ; +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: MACRO + - function_name: + - quoted_identifier: '"myschema"' + - dot: . + - function_name_identifier: mymacro +- statement_terminator: ; +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: MACRO + - function_name: + - function_name_identifier: mcr + - keyword: RESTRICT +- statement_terminator: ; +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: MACRO + - function_name: + - function_name_identifier: mcr + - keyword: CASCADE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/extract_temporal.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/extract_temporal.sql new file mode 100644 index 000000000..fb96f68e2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/extract_temporal.sql @@ -0,0 +1,13 @@ +/* Checks for functions that use `FROM` */ + +SELECT extract('year' FROM DATE '1992-09-20'); + +SELECT extract('year' FROM '1992-09-20'::DATE); + +VALUES (extract('year' FROM DATE '1992-09-20')); + +SELECT extract('hour' FROM TIMESTAMP '1992-09-20 20:38:48'); + +SELECT extract('hour' FROM TIMESTAMPTZ '1992-09-20 20:38:48'); + +SELECT extract('hour' FROM TIME '14:21:13'); diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/extract_temporal.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/extract_temporal.yml new file mode 100644 index 000000000..b02408a5e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/extract_temporal.yml @@ -0,0 +1,131 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: extract + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''year''' + - keyword: FROM + - expression: + - datetime_literal: + - datetime_type_identifier: + - keyword: DATE + - quoted_literal: '''1992-09-20''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: extract + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''year''' + - keyword: FROM + - expression: + - cast_expression: + - quoted_literal: '''1992-09-20''' + - casting_operator: '::' + - data_type: + - datetime_type_identifier: + - keyword: DATE + - end_bracket: ) +- statement_terminator: ; +- statement: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: extract + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''year''' + - keyword: FROM + - expression: + - datetime_literal: + - datetime_type_identifier: + - keyword: DATE + - quoted_literal: '''1992-09-20''' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: extract + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''hour''' + - keyword: FROM + - expression: + - datetime_literal: + - datetime_type_identifier: + - keyword: TIMESTAMP + - quoted_literal: '''1992-09-20 20:38:48''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: extract + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''hour''' + - keyword: FROM + - expression: + - datetime_literal: + - datetime_type_identifier: + - keyword: TIMESTAMPTZ + - quoted_literal: '''1992-09-20 20:38:48''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: extract + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''hour''' + - keyword: FROM + - expression: + - datetime_literal: + - datetime_type_identifier: + - keyword: TIME + - quoted_literal: '''14:21:13''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/filter.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/filter.sql new file mode 100644 index 000000000..364ab67ac --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/filter.sql @@ -0,0 +1,12 @@ +-- Standard SQL form +SELECT SUM(x) FILTER (WHERE y > 0); + +-- DuckDB (WHERE optional) +SELECT SUM(x) FILTER (y > 0); + +-- Example on documentation page +SELECT + sum(i) FILTER (i <= 5) AS lte_five_sum, + median(i) FILTER (i % 2 = 1) AS odds_median, + median(i) FILTER (i % 2 = 1 AND i <= 5) AS odds_lte_five_median +FROM generate_series(1, 10) tbl(i); diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/filter.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/filter.yml new file mode 100644 index 000000000..a1f8fb3ef --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/filter.yml @@ -0,0 +1,172 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - end_bracket: ) + - keyword: FILTER + - bracketed: + - start_bracket: ( + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: y + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - end_bracket: ) + - keyword: FILTER + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: y + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: i + - end_bracket: ) + - keyword: FILTER + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: i + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - numeric_literal: '5' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: lte_five_sum + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: median + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: i + - end_bracket: ) + - keyword: FILTER + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: i + - binary_operator: '%' + - numeric_literal: '2' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: odds_median + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: median + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: i + - end_bracket: ) + - keyword: FILTER + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: i + - binary_operator: '%' + - numeric_literal: '2' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - binary_operator: AND + - column_reference: + - naked_identifier: i + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - numeric_literal: '5' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: odds_lte_five_median + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: generate_series + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - numeric_literal: '10' + - end_bracket: ) + - alias_expression: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: i + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/from_first.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/from_first.sql new file mode 100644 index 000000000..98721ef90 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/from_first.sql @@ -0,0 +1,8 @@ +/* Examples from https://duckdb.org/docs/sql/query_syntax/from */ + +-- select all columns from the table called "table_name" using the FROM-first syntax +FROM table_name SELECT *; +-- select all columns using the FROM-first syntax and omitting the SELECT clause +FROM table_name; +-- use the FROM-first syntax with WHERE clause and aggregation +FROM range(100) AS t (i) SELECT sum(t.i) WHERE t.i % 2 = 0; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/from_first.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/from_first.yml new file mode 100644 index 000000000..3fc41ef75 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/from_first.yml @@ -0,0 +1,80 @@ +file: +- statement: + - select_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table_name + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' +- statement_terminator: ; +- statement: + - select_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - select_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: range + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '100' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: i + - end_bracket: ) + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: i + - end_bracket: ) + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: i + - binary_operator: '%' + - numeric_literal: '2' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/group_order_by_all.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/group_order_by_all.yml index e16c51090..ebe3b1fed 100644 --- a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/group_order_by_all.yml +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/group_order_by_all.yml @@ -34,7 +34,8 @@ file: - naked_identifier: villainy - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: total_scum_and_villainy - from_clause: - keyword: FROM @@ -56,21 +57,22 @@ file: - wildcard_expression: - wildcard_identifier: - star: '*' - - keyword: EXCLUDE - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: cantinas - - comma: ',' - - column_reference: - - naked_identifier: booths - - comma: ',' - - column_reference: - - naked_identifier: scum - - comma: ',' - - column_reference: - - naked_identifier: villainy - - end_bracket: ) + - wildcard_exclude: + - keyword: EXCLUDE + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: cantinas + - comma: ',' + - column_reference: + - naked_identifier: booths + - comma: ',' + - column_reference: + - naked_identifier: scum + - comma: ',' + - column_reference: + - naked_identifier: villainy + - end_bracket: ) - comma: ',' - select_clause_element: - function: @@ -87,7 +89,8 @@ file: - naked_identifier: villainy - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: total_scum_and_villainy - from_clause: - keyword: FROM @@ -121,7 +124,8 @@ file: - naked_identifier: civility - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: total_civility - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/in_operator.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/in_operator.sql new file mode 100644 index 000000000..6477caf4f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/in_operator.sql @@ -0,0 +1,12 @@ +-- https://duckdb.org/docs/stable/sql/expressions/in +SELECT 'Math' IN ('CS', 'Math'); +SELECT 'Math' IN ('CS', 'Math',); +SELECT 42 IN (SELECT unnest([32, 42, 52]) AS x); +SELECT 'Hello' IN 'Hello World'; +SELECT 1 IN [1,2,3]; +SELECT 17 in [x, y, z,] from t; +SELECT x NOT IN y; +select 17 in (x,y,z,) from t; +-- This test case doesn't work yet, MAP literals are not parsed. +-- https://duckdb.org/docs/stable/sql/data_types/map +-- SELECT 'key1' IN MAP {'key1': 50, 'key2': 75}; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/in_operator.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/in_operator.yml new file mode 100644 index 000000000..22fce1b0a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/in_operator.yml @@ -0,0 +1,164 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''Math''' + - keyword: IN + - bracketed: + - start_bracket: ( + - quoted_literal: '''CS''' + - comma: ',' + - quoted_literal: '''Math''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''Math''' + - keyword: IN + - bracketed: + - start_bracket: ( + - quoted_literal: '''CS''' + - comma: ',' + - quoted_literal: '''Math''' + - comma: ',' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '42' + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: unnest + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '32' + - comma: ',' + - numeric_literal: '42' + - comma: ',' + - numeric_literal: '52' + - end_square_bracket: ']' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: x + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''Hello''' + - keyword: IN + - quoted_literal: '''Hello World''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - keyword: IN + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_square_bracket: ']' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '17' + - keyword: in + - array_literal: + - start_square_bracket: '[' + - column_reference: + - naked_identifier: x + - comma: ',' + - column_reference: + - naked_identifier: y + - comma: ',' + - column_reference: + - naked_identifier: z + - comma: ',' + - end_square_bracket: ']' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: x + - keyword: NOT + - keyword: IN + - column_reference: + - naked_identifier: y +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - expression: + - numeric_literal: '17' + - keyword: in + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: x + - comma: ',' + - column_reference: + - naked_identifier: y + - comma: ',' + - column_reference: + - naked_identifier: z + - comma: ',' + - end_bracket: ) + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/insert.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/insert.sql new file mode 100644 index 000000000..99f282005 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/insert.sql @@ -0,0 +1,50 @@ +INSERT INTO tbl + VALUES (1), (2), (3); + +INSERT INTO tbl + SELECT + col1, + col2, + col3 + FROM other_tbl; + +INSERT OR REPLACE INTO tbl (i) + VALUES (1); + +INSERT OR IGNORE INTO tbl (i) + VALUES (1); + +INSERT INTO tbl +BY POSITION + VALUES (5, 42); + +INSERT INTO tbl BY NAME (SELECT 22 AS b); + +INSERT INTO tbl + VALUES (1, 84) + ON CONFLICT DO NOTHING; + +INSERT INTO tbl VALUES (1, 52), (1, 62) ON CONFLICT DO UPDATE SET j = EXCLUDED.j; + +INSERT INTO tbl +BY NAME ( + SELECT + 1 AS i, + 336 AS j +) +ON CONFLICT DO UPDATE SET j = EXCLUDED.j; + +INSERT INTO t1 + VALUES (1), (2), (3) + RETURNING *; + +CREATE TABLE t1 (i INTEGER); +INSERT INTO t1 + VALUES (1), (2), (3); + +CREATE TABLE t2 (i INTEGER); +INSERT INTO t2 + SELECT i FROM t1 + WHERE i IN (1, 3) + ON CONFLICT DO UPDATE SET j = EXCLUDED.j + RETURNING *; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/insert.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/insert.yml new file mode 100644 index 000000000..65ebee9b1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/insert.yml @@ -0,0 +1,374 @@ +file: +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: tbl + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: tbl + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col3 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: other_tbl +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: OR + - keyword: REPLACE + - keyword: INTO + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: i + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: OR + - keyword: IGNORE + - keyword: INTO + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: i + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: tbl + - keyword: BY + - keyword: POSITION + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '5' + - comma: ',' + - expression: + - numeric_literal: '42' + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: tbl + - keyword: BY + - keyword: NAME + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '22' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: b + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: tbl + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - numeric_literal: '84' + - end_bracket: ) + - keyword: ON + - keyword: CONFLICT + - conflict_action: + - keyword: DO + - keyword: NOTHING +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: tbl + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - numeric_literal: '52' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - numeric_literal: '62' + - end_bracket: ) + - keyword: ON + - keyword: CONFLICT + - conflict_action: + - keyword: DO + - keyword: UPDATE + - keyword: SET + - column_reference: + - naked_identifier: j + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: EXCLUDED + - dot: . + - naked_identifier: j +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: tbl + - keyword: BY + - keyword: NAME + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: i + - comma: ',' + - select_clause_element: + - numeric_literal: '336' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: j + - end_bracket: ) + - keyword: ON + - keyword: CONFLICT + - conflict_action: + - keyword: DO + - keyword: UPDATE + - keyword: SET + - column_reference: + - naked_identifier: j + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: EXCLUDED + - dot: . + - naked_identifier: j +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - end_bracket: ) + - keyword: RETURNING + - star: '*' +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: i + - data_type: + - keyword: INTEGER + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: i + - data_type: + - keyword: INTEGER + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t2 + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: i + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: i + - keyword: IN + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '3' + - end_bracket: ) + - keyword: ON + - keyword: CONFLICT + - conflict_action: + - keyword: DO + - keyword: UPDATE + - keyword: SET + - column_reference: + - naked_identifier: j + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: EXCLUDED + - dot: . + - naked_identifier: j + - keyword: RETURNING + - star: '*' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/json_operators.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/json_operators.sql new file mode 100644 index 000000000..59f03fe3c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/json_operators.sql @@ -0,0 +1,10 @@ +-- https://duckdb.org/docs/extensions/json#json-extraction-functions + +-- Get JSON array element (indexed from zero, negative integers count from the end) +SELECT '[{"a":"foo"},{"b":"bar"},{"c":"baz"}]'::json->2; +-- Get JSON object field by key +SELECT '{"a": {"b":"foo"}}'::json->'a'; +-- Get JSON array element as text +SELECT '[1,2,3]'::json->>2; +-- Get JSON object field as text +SELECT '{"a":1,"b":2}'::json->>'b'; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/json_operators.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/json_operators.yml new file mode 100644 index 000000000..bbd5af125 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/json_operators.yml @@ -0,0 +1,57 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''[{"a":"foo"},{"b":"bar"},{"c":"baz"}]''' + - casting_operator: '::' + - data_type: + - keyword: json + - binary_operator: -> + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''{"a": {"b":"foo"}}''' + - casting_operator: '::' + - data_type: + - keyword: json + - binary_operator: -> + - quoted_literal: '''a''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''[1,2,3]''' + - casting_operator: '::' + - data_type: + - keyword: json + - binary_operator: ->> + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''{"a":1,"b":2}''' + - casting_operator: '::' + - data_type: + - keyword: json + - binary_operator: ->> + - quoted_literal: '''b''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_comprehension.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_comprehension.sql new file mode 100644 index 000000000..b02971e4f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_comprehension.sql @@ -0,0 +1,5 @@ +SELECT [lower(x) FOR x IN strings] +FROM (VALUES (['Hello', '', 'World'])) t(strings); + +SELECT [upper(x) FOR x IN strings IF len(x) > 0] +FROM (VALUES (['Hello', '', 'World'])) t(strings); diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_comprehension.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_comprehension.yml new file mode 100644 index 000000000..caaa6cc68 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_comprehension.yml @@ -0,0 +1,128 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - list_comprehension: + - start_square_bracket: '[' + - expression: + - function: + - function_name: + - function_name_identifier: lower + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - end_bracket: ) + - keyword: FOR + - parameter: x + - keyword: IN + - expression: + - column_reference: + - naked_identifier: strings + - end_square_bracket: ']' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''Hello''' + - comma: ',' + - quoted_literal: '''''' + - comma: ',' + - quoted_literal: '''World''' + - end_square_bracket: ']' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - naked_identifier: t + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: strings + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - list_comprehension: + - start_square_bracket: '[' + - expression: + - function: + - function_name: + - function_name_identifier: upper + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - end_bracket: ) + - keyword: FOR + - parameter: x + - keyword: IN + - expression: + - column_reference: + - naked_identifier: strings + - keyword: IF + - expression: + - function: + - function_name: + - function_name_identifier: len + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' + - end_square_bracket: ']' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''Hello''' + - comma: ',' + - quoted_literal: '''''' + - comma: ',' + - quoted_literal: '''World''' + - end_square_bracket: ']' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - naked_identifier: t + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: strings + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_struct.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_struct.sql index c06246965..4337d75b4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_struct.sql +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_struct.sql @@ -14,4 +14,3 @@ SELECT planet."Amount of sand" FROM (SELECT {name: 'Tatooine', 'Amount of sand': 'High'} as planet) ; - diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_struct.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_struct.yml index 991b4160e..964d8d1d0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_struct.yml +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/list_struct.yml @@ -15,7 +15,8 @@ file: - quoted_literal: '''Y-Wing''' - end_square_bracket: ']' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: starfighter_list - comma: ',' - select_clause_element: @@ -32,7 +33,8 @@ file: - quoted_literal: '''Can''''t in fact destroy a star''' - end_curly_bracket: '}' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: star_destroyer_facts - statement_terminator: ; - statement: @@ -50,7 +52,8 @@ file: - numeric_literal: '2' - end_square_bracket: ']' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: dont_forget_the_b_wing - from_clause: - keyword: FROM @@ -74,7 +77,8 @@ file: - quoted_literal: '''Y-Wing''' - end_square_bracket: ']' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: starfighter_list - end_bracket: ) - statement_terminator: ; @@ -93,7 +97,8 @@ file: - numeric_literal: '3' - end_square_bracket: ']' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: nearly_soloed - statement_terminator: ; - statement: @@ -135,7 +140,8 @@ file: - quoted_literal: '''High''' - end_curly_bracket: '}' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: planet - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/load_statement.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/load_statement.sql deleted file mode 100644 index 3e666b894..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/load_statement.sql +++ /dev/null @@ -1 +0,0 @@ -LOAD spatial; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/load_statement.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/load_statement.yml deleted file mode 100644 index 19e9b0a46..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/load_statement.yml +++ /dev/null @@ -1,5 +0,0 @@ -file: -- statement: - - keyword: LOAD - - naked_identifier: spatial -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/macro.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/macro.sql deleted file mode 100644 index 1959160f1..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/macro.sql +++ /dev/null @@ -1,48 +0,0 @@ -CREATE MACRO one() AS (SELECT 1); - -CREATE MACRO add(a, b) AS a + b; - -CREATE FUNCTION add(a, b) AS a + b; - -CREATE MACRO ifelse(a, b, c) AS CASE WHEN a THEN b ELSE c END; - -CREATE MACRO plus_one(a) AS (WITH cte AS (SELECT 1 AS a) SELECT cte.a + a FROM cte); - -CREATE MACRO arr_append(l, e) AS list_concat(l, list_value(e)); - -CREATE TEMP MACRO add(a, b) AS a + b; - -CREATE TEMPORARY MACRO add(a, b) AS a + b; - --- CREATE OR REPLACE MACRO add(a, b) AS a + b; --- CREATE MACRO add_default(a, b := 5) AS a + b; --- --- CREATE MACRO static_table() AS TABLE --- SELECT 'Hello' AS column1, 'World' AS column2; --- --- CREATE MACRO dynamic_table(col1_value, col2_value) AS TABLE --- SELECT col1_value AS column1, col2_value AS column2; --- --- CREATE OR REPLACE TEMP MACRO dynamic_table(col1_value, col2_value) AS TABLE --- SELECT col1_value AS column1, col2_value AS column2 --- UNION ALL --- SELECT 'Hello' AS col1_value, 456 AS col2_value; --- --- CREATE MACRO get_users(i) AS TABLE --- SELECT * FROM users WHERE uid IN (SELECT unnest(i)); --- --- CREATE TABLE users AS --- SELECT * --- FROM (VALUES (1, 'Ada'), (2, 'Bob'), (3, 'Carl'), (4, 'Dan'), (5, 'Eve')) t(uid, name); --- SELECT * FROM get_users([1, 5]); --- --- CREATE MACRO checksum(table_name) AS TABLE --- SELECT bit_xor(md5_number(COLUMNS(*)::VARCHAR)) --- FROM query_table(table_name); --- --- CREATE TABLE tbl AS SELECT unnest([42, 43]) AS x, 100 AS y; --- SELECT * FROM checksum('tbl'); --- --- CREATE MACRO add_x --- (a, b) AS a + b, --- (a, b, c) AS a + b + c; \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/macro.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/macro.yml deleted file mode 100644 index e7cb72d78..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/macro.yml +++ /dev/null @@ -1,223 +0,0 @@ -file: -- statement: - - keyword: CREATE - - keyword: MACRO - - naked_identifier: one - - bracketed: - - start_bracket: ( - - end_bracket: ) - - keyword: AS - - expression: - - bracketed: - - start_bracket: ( - - expression: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '1' - - end_bracket: ) -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: MACRO - - naked_identifier: add - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: a - - comma: ',' - - column_reference: - - naked_identifier: b - - end_bracket: ) - - keyword: AS - - expression: - - column_reference: - - naked_identifier: a - - binary_operator: + - - column_reference: - - naked_identifier: b -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: FUNCTION - - naked_identifier: add - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: a - - comma: ',' - - column_reference: - - naked_identifier: b - - end_bracket: ) - - keyword: AS - - expression: - - column_reference: - - naked_identifier: a - - binary_operator: + - - column_reference: - - naked_identifier: b -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: MACRO - - naked_identifier: ifelse - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: a - - comma: ',' - - column_reference: - - naked_identifier: b - - comma: ',' - - column_reference: - - naked_identifier: c - - end_bracket: ) - - keyword: AS - - expression: - - case_expression: - - keyword: CASE - - when_clause: - - keyword: WHEN - - expression: - - column_reference: - - naked_identifier: a - - keyword: THEN - - expression: - - column_reference: - - naked_identifier: b - - else_clause: - - keyword: ELSE - - expression: - - column_reference: - - naked_identifier: c - - keyword: END -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: MACRO - - naked_identifier: plus_one - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: a - - end_bracket: ) - - keyword: AS - - expression: - - bracketed: - - start_bracket: ( - - with_compound_statement: - - keyword: WITH - - common_table_expression: - - naked_identifier: cte - - keyword: AS - - bracketed: - - start_bracket: ( - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '1' - - alias_expression: - - keyword: AS - - naked_identifier: a - - end_bracket: ) - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - expression: - - column_reference: - - naked_identifier: cte - - dot: . - - naked_identifier: a - - binary_operator: + - - column_reference: - - naked_identifier: a - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: cte - - end_bracket: ) -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: MACRO - - naked_identifier: arr_append - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: l - - comma: ',' - - column_reference: - - naked_identifier: e - - end_bracket: ) - - keyword: AS - - function: - - function_name: - - function_name_identifier: list_concat - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: l - - comma: ',' - - expression: - - function: - - function_name: - - function_name_identifier: list_value - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: e - - end_bracket: ) - - end_bracket: ) -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: TEMP - - keyword: MACRO - - naked_identifier: add - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: a - - comma: ',' - - column_reference: - - naked_identifier: b - - end_bracket: ) - - keyword: AS - - expression: - - column_reference: - - naked_identifier: a - - binary_operator: + - - column_reference: - - naked_identifier: b -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: TEMPORARY - - keyword: MACRO - - naked_identifier: add - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: a - - comma: ',' - - column_reference: - - naked_identifier: b - - end_bracket: ) - - keyword: AS - - expression: - - column_reference: - - naked_identifier: a - - binary_operator: + - - column_reference: - - naked_identifier: b -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/pivot.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/pivot.sql new file mode 100644 index 000000000..91243a7de --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/pivot.sql @@ -0,0 +1,70 @@ +-- Simplified PIVOT +-- Examples from https://duckdb.org/docs/sql/statements/pivot +PIVOT Cities ON Year USING sum(Population); + +PIVOT Cities ON Year USING first(Population); + +PIVOT Cities ON Year USING sum(Population) GROUP BY Country; + +PIVOT Cities ON Year IN (2000, 2010) USING sum(Population) GROUP BY Country; + +PIVOT Cities ON Country, Name USING sum(Population); + +PIVOT Cities ON Country || '_' || Name USING sum(Population); + +PIVOT Cities ON Year USING sum(Population) AS total, max(Population) AS max GROUP BY Country; + +PIVOT Cities ON Year USING sum(Population) GROUP BY Country, Name; + +PIVOT Cities ON Year USING sum(Population) GROUP BY Country, Name ORDER BY Name; + +PIVOT Cities ON Year USING sum(Population) GROUP BY Country, Name LIMIT 1; + +PIVOT Cities ON Year USING sum(Population) GROUP BY Country, Name ORDER BY Name LIMIT 1; + +-- Without ON +PIVOT Cities USING sum(Population) GROUP BY Country, Name; + +-- Only ON +PIVOT Cities ON Year; + +-- Only USING +PIVOT Cities USING sum(Population); + +-- Only GROUP BY +PIVOT Cities GROUP BY Country, Name; + +-- In a CTE +WITH pivot_alias AS ( + PIVOT Cities ON Year USING sum(Population) GROUP BY Country +) +SELECT * FROM pivot_alias; + +-- In a subquery +SELECT * +FROM ( + PIVOT Cities ON Year USING sum(Population) GROUP BY Country +) pivot_alias; + +-- Multiple pivots with a join +FROM (PIVOT Cities ON Year USING sum(Population) GROUP BY Country) year_pivot +JOIN (PIVOT Cities ON Name USING sum(Population) GROUP BY Country) name_pivot +USING (Country); + +-- Standard PIVOT +FROM Cities +PIVOT ( + sum(Population) + FOR + Year IN (2000, 2010, 2020) + GROUP BY Country +); + +FROM Cities +PIVOT ( + sum(Population) AS total, + count(Population) AS count + FOR + Year IN (2000, 2010) + Country in ('NL', 'US') +); diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/pivot.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/pivot.yml new file mode 100644 index 000000000..ad28f4fbe --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/pivot.yml @@ -0,0 +1,672 @@ +file: +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - column_reference: + - naked_identifier: Year + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) +- statement_terminator: ; +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - column_reference: + - naked_identifier: Year + - keyword: USING + - function: + - function_name: + - function_name_identifier: first + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) +- statement_terminator: ; +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - column_reference: + - naked_identifier: Year + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: Country +- statement_terminator: ; +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - expression: + - column_reference: + - naked_identifier: Year + - keyword: IN + - bracketed: + - start_bracket: ( + - numeric_literal: '2000' + - comma: ',' + - numeric_literal: '2010' + - end_bracket: ) + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: Country +- statement_terminator: ; +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - column_reference: + - naked_identifier: Country + - comma: ',' + - column_reference: + - naked_identifier: Name + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) +- statement_terminator: ; +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - expression: + - column_reference: + - naked_identifier: Country + - binary_operator: + - pipe: '|' + - pipe: '|' + - quoted_literal: '''_''' + - binary_operator: + - pipe: '|' + - pipe: '|' + - column_reference: + - naked_identifier: Name + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) +- statement_terminator: ; +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - column_reference: + - naked_identifier: Year + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: total + - comma: ',' + - function: + - function_name: + - function_name_identifier: max + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: max + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: Country +- statement_terminator: ; +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - column_reference: + - naked_identifier: Year + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: Country + - comma: ',' + - column_reference: + - naked_identifier: Name +- statement_terminator: ; +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - column_reference: + - naked_identifier: Year + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: Country + - comma: ',' + - column_reference: + - naked_identifier: Name + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: Name +- statement_terminator: ; +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - column_reference: + - naked_identifier: Year + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: Country + - comma: ',' + - column_reference: + - naked_identifier: Name + - limit_clause: + - keyword: LIMIT + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - column_reference: + - naked_identifier: Year + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: Country + - comma: ',' + - column_reference: + - naked_identifier: Name + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: Name + - limit_clause: + - keyword: LIMIT + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: Country + - comma: ',' + - column_reference: + - naked_identifier: Name +- statement_terminator: ; +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - column_reference: + - naked_identifier: Year +- statement_terminator: ; +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) +- statement_terminator: ; +- statement: + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: Country + - comma: ',' + - column_reference: + - naked_identifier: Name +- statement_terminator: ; +- statement: + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: pivot_alias + - keyword: AS + - bracketed: + - start_bracket: ( + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - column_reference: + - naked_identifier: Year + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: Country + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: pivot_alias +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - column_reference: + - naked_identifier: Year + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: Country + - end_bracket: ) + - alias_expression: + - naked_identifier: pivot_alias +- statement_terminator: ; +- statement: + - select_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - column_reference: + - naked_identifier: Year + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: Country + - end_bracket: ) + - alias_expression: + - naked_identifier: year_pivot + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - simplified_pivot: + - keyword: PIVOT + - table_expression: + - table_reference: + - naked_identifier: Cities + - keyword: ON + - column_reference: + - naked_identifier: Name + - keyword: USING + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: Country + - end_bracket: ) + - alias_expression: + - naked_identifier: name_pivot + - keyword: USING + - bracketed: + - start_bracket: ( + - naked_identifier: Country + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Cities + - from_pivot_expression: + - keyword: PIVOT + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - keyword: FOR + - naked_identifier: Year + - keyword: IN + - bracketed: + - start_bracket: ( + - numeric_literal: '2000' + - comma: ',' + - numeric_literal: '2010' + - comma: ',' + - numeric_literal: '2020' + - end_bracket: ) + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: Country + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Cities + - from_pivot_expression: + - keyword: PIVOT + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: total + - comma: ',' + - function: + - function_name: + - function_name_identifier: count + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Population + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: count + - keyword: FOR + - naked_identifier: Year + - keyword: IN + - bracketed: + - start_bracket: ( + - numeric_literal: '2000' + - comma: ',' + - numeric_literal: '2010' + - end_bracket: ) + - naked_identifier: Country + - keyword: in + - bracketed: + - start_bracket: ( + - quoted_literal: '''NL''' + - comma: ',' + - quoted_literal: '''US''' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/positional_join.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/positional_join.sql new file mode 100644 index 000000000..4279a0452 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/positional_join.sql @@ -0,0 +1,5 @@ +-- treat two data frames as a single table +SELECT + df1.*, + df2.* +FROM df1 POSITIONAL JOIN df2; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/positional_join.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/positional_join.yml new file mode 100644 index 000000000..3ec60b4ef --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/positional_join.yml @@ -0,0 +1,33 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - naked_identifier: df1 + - dot: . + - star: '*' + - comma: ',' + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - naked_identifier: df2 + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: df1 + - join_clause: + - keyword: POSITIONAL + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: df2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/qualify.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/qualify.sql new file mode 100644 index 000000000..2107cce69 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/qualify.sql @@ -0,0 +1,47 @@ +/* Examples from https://duckdb.org/docs/sql/query_syntax/qualify */ + +-- Filter based on a WINDOW function defined in the QUALIFY clause +SELECT + schema_name, + function_name, + -- In this example the function_rank column in the select clause is for reference + row_number() + OVER (PARTITION BY schema_name ORDER BY function_name) + AS function_rank +FROM duckdb_functions +QUALIFY + row_number() OVER (PARTITION BY schema_name ORDER BY function_name) < 3; + +-- Filter based on a WINDOW function defined in the SELECT clause +SELECT + schema_name, + function_name, + row_number() + OVER (PARTITION BY schema_name ORDER BY function_name) + AS function_rank +FROM duckdb_functions() +QUALIFY + function_rank < 3; + +-- Filter based on a WINDOW function defined in the QUALIFY clause, but using the WINDOW clause +SELECT + schema_name, + function_name, + -- In this example the function_rank column in the select clause is for reference + row_number() OVER my_window AS function_rank +FROM duckdb_functions() +WINDOW + my_window AS (PARTITION BY schema_name ORDER BY function_name) +QUALIFY + row_number() OVER my_window < 3; + +-- Filter based on a WINDOW function defined in the SELECT clause, but using the WINDOW clause +SELECT + schema_name, + function_name, + row_number() OVER my_window AS function_rank +FROM duckdb_functions() +WINDOW + my_window AS (PARTITION BY schema_name ORDER BY function_name) +QUALIFY + function_rank < 3; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/qualify.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/qualify.yml new file mode 100644 index 000000000..a3948ebaa --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/qualify.yml @@ -0,0 +1,286 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: schema_name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: function_name + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: row_number + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - expression: + - column_reference: + - naked_identifier: schema_name + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: function_name + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: function_rank + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: duckdb_functions + - qualify_clause: + - keyword: QUALIFY + - expression: + - function: + - function_name: + - function_name_identifier: row_number + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - expression: + - column_reference: + - naked_identifier: schema_name + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: function_name + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '3' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: schema_name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: function_name + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: row_number + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - expression: + - column_reference: + - naked_identifier: schema_name + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: function_name + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: function_rank + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: duckdb_functions + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - qualify_clause: + - keyword: QUALIFY + - expression: + - column_reference: + - naked_identifier: function_rank + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '3' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: schema_name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: function_name + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: row_number + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: my_window + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: function_rank + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: duckdb_functions + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - named_window: + - keyword: WINDOW + - named_window_expression: + - naked_identifier: my_window + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - expression: + - column_reference: + - naked_identifier: schema_name + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: function_name + - end_bracket: ) + - qualify_clause: + - keyword: QUALIFY + - expression: + - function: + - function_name: + - function_name_identifier: row_number + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: my_window + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '3' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: schema_name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: function_name + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: row_number + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: my_window + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: function_rank + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: duckdb_functions + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - named_window: + - keyword: WINDOW + - named_window_expression: + - naked_identifier: my_window + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - expression: + - column_reference: + - naked_identifier: schema_name + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: function_name + - end_bracket: ) + - qualify_clause: + - keyword: QUALIFY + - expression: + - column_reference: + - naked_identifier: function_rank + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '3' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_columns.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_columns.sql new file mode 100644 index 000000000..fbe277fff --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_columns.sql @@ -0,0 +1,16 @@ +-- columns expression with lambda +SELECT COLUMNS(c -> c LIKE '%num%') FROM addresses; + +-- columns expression with regular expression +SELECT COLUMNS('number\d+') FROM addresses; + +-- function call on columns expression +SELECT min(COLUMNS(*)) FROM addresses; + +SELECT min(COLUMNS(*)), count(COLUMNS(*)) FROM numbers; + +-- columns with wildcard replace and exclude +SELECT min(COLUMNS(* REPLACE (number + id AS number))), count(COLUMNS(* EXCLUDE (number))) FROM numbers; + +-- columns expression with an expression +SELECT COLUMNS(*) + COLUMNS(*) FROM numbers; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_columns.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_columns.yml new file mode 100644 index 000000000..32e5a2015 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_columns.yml @@ -0,0 +1,240 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: COLUMNS + - function_contents: + - bracketed: + - start_bracket: ( + - lambda_function: + - parameter: c + - lambda_arrow: -> + - expression: + - column_reference: + - naked_identifier: c + - keyword: LIKE + - quoted_literal: '''%num%''' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: addresses +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: COLUMNS + - function_contents: + - bracketed: + - start_bracket: ( + - quoted_literal: '''number\d+''' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: addresses +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: min + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - keyword: COLUMNS + - function_contents: + - bracketed: + - start_bracket: ( + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - end_bracket: ) + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: addresses +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: min + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - keyword: COLUMNS + - function_contents: + - bracketed: + - start_bracket: ( + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: count + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - keyword: COLUMNS + - function_contents: + - bracketed: + - start_bracket: ( + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - end_bracket: ) + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: numbers +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: min + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - keyword: COLUMNS + - function_contents: + - bracketed: + - start_bracket: ( + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_replace: + - keyword: REPLACE + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: number + - binary_operator: + + - column_reference: + - naked_identifier: id + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: number + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: count + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - keyword: COLUMNS + - function_contents: + - bracketed: + - start_bracket: ( + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_exclude: + - keyword: EXCLUDE + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: number + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: numbers +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - function: + - function_name: + - keyword: COLUMNS + - function_contents: + - bracketed: + - start_bracket: ( + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - end_bracket: ) + - binary_operator: + + - function: + - function_name: + - keyword: COLUMNS + - function_contents: + - bracketed: + - start_bracket: ( + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: numbers +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_exclude.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_exclude.yml index d6c3af739..c8c8f7baa 100644 --- a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_exclude.yml +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_exclude.yml @@ -7,15 +7,16 @@ file: - wildcard_expression: - wildcard_identifier: - star: '*' - - keyword: EXCLUDE - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: jar_jar_binks - - comma: ',' - - column_reference: - - naked_identifier: midichlorians - - end_bracket: ) + - wildcard_exclude: + - keyword: EXCLUDE + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: jar_jar_binks + - comma: ',' + - column_reference: + - naked_identifier: midichlorians + - end_bracket: ) - from_clause: - keyword: FROM - from_expression: @@ -34,15 +35,16 @@ file: - naked_identifier: sw - dot: . - star: '*' - - keyword: EXCLUDE - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: jar_jar_binks - - comma: ',' - - column_reference: - - naked_identifier: midichlorians - - end_bracket: ) + - wildcard_exclude: + - keyword: EXCLUDE + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: jar_jar_binks + - comma: ',' + - column_reference: + - naked_identifier: midichlorians + - end_bracket: ) - comma: ',' - select_clause_element: - wildcard_expression: @@ -50,9 +52,10 @@ file: - naked_identifier: ff - dot: . - star: '*' - - keyword: EXCLUDE - - column_reference: - - naked_identifier: cancellation + - wildcard_exclude: + - keyword: EXCLUDE + - column_reference: + - naked_identifier: cancellation - from_clause: - keyword: FROM - from_expression: diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_exclude_replace.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_exclude_replace.sql new file mode 100644 index 000000000..bf74dbcd9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_exclude_replace.sql @@ -0,0 +1,6 @@ +SELECT * EXCLUDE y REPLACE (3 AS x) +FROM tabx; + +-- The x column is replaced, but z is not +SELECT * EXCLUDE y REPLACE 3 AS x, 6 as z +FROM tabx; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_exclude_replace.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_exclude_replace.yml new file mode 100644 index 000000000..ffb662fca --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_exclude_replace.yml @@ -0,0 +1,65 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_exclude: + - keyword: EXCLUDE + - column_reference: + - naked_identifier: y + - wildcard_replace: + - keyword: REPLACE + - bracketed: + - start_bracket: ( + - numeric_literal: '3' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: x + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tabx +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_exclude: + - keyword: EXCLUDE + - column_reference: + - naked_identifier: y + - wildcard_replace: + - keyword: REPLACE + - numeric_literal: '3' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: x + - comma: ',' + - select_clause_element: + - numeric_literal: '6' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: z + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tabx +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_lambda.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_lambda.sql new file mode 100644 index 000000000..1a3ae2327 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_lambda.sql @@ -0,0 +1,16 @@ +-- lambda functions +SELECT list_transform([4, 5, 6], x -> x + 1); + +SELECT list_filter([4, 5, 6], x -> x > 4); + +-- nested lambda functions +SELECT list_transform( + list_filter([0, 1, 2, 3, 4, 5], x -> x % 2 = 0), + y -> y * y +); + +-- lambda with index +SELECT list_filter([1, 3, 1, 5], (x, i) -> x > i); + +-- new lambda syntax, introduced in v1.3 +SELECT list_transform([4, 5, 6], lambda x: x + 1); diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_lambda.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_lambda.yml new file mode 100644 index 000000000..239e95bd5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_lambda.yml @@ -0,0 +1,194 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: list_transform + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '6' + - end_square_bracket: ']' + - comma: ',' + - lambda_function: + - parameter: x + - lambda_arrow: -> + - expression: + - column_reference: + - naked_identifier: x + - binary_operator: + + - numeric_literal: '1' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: list_filter + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '6' + - end_square_bracket: ']' + - comma: ',' + - lambda_function: + - parameter: x + - lambda_arrow: -> + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '4' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: list_transform + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: list_filter + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - comma: ',' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '5' + - end_square_bracket: ']' + - comma: ',' + - lambda_function: + - parameter: x + - lambda_arrow: -> + - expression: + - column_reference: + - naked_identifier: x + - binary_operator: '%' + - numeric_literal: '2' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - lambda_function: + - parameter: y + - lambda_arrow: -> + - expression: + - column_reference: + - naked_identifier: y + - binary_operator: '*' + - column_reference: + - naked_identifier: y + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: list_filter + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '3' + - comma: ',' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '5' + - end_square_bracket: ']' + - comma: ',' + - lambda_function: + - bracketed: + - start_bracket: ( + - parameter: x + - comma: ',' + - parameter: i + - end_bracket: ) + - lambda_arrow: -> + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: '>' + - column_reference: + - naked_identifier: i + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: list_transform + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '6' + - end_square_bracket: ']' + - comma: ',' + - lambda_function: + - keyword: lambda + - parameter: x + - colon: ':' + - expression: + - column_reference: + - naked_identifier: x + - binary_operator: + + - numeric_literal: '1' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_replace.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_replace.yml index 6beb8ac33..d9e28498c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_replace.yml +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/select_replace.yml @@ -7,27 +7,30 @@ file: - wildcard_expression: - wildcard_identifier: - star: '*' - - keyword: REPLACE - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: movie_count - - binary_operator: + - - numeric_literal: '3' - - alias_expression: - - keyword: as - - naked_identifier: movie_count - - comma: ',' - - expression: - - column_reference: - - naked_identifier: show_count - - binary_operator: '*' - - numeric_literal: '1000' - - alias_expression: - - keyword: as - - naked_identifier: show_count - - end_bracket: ) + - wildcard_replace: + - keyword: REPLACE + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: movie_count + - binary_operator: + + - numeric_literal: '3' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: movie_count + - comma: ',' + - expression: + - column_reference: + - naked_identifier: show_count + - binary_operator: '*' + - numeric_literal: '1000' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: show_count + - end_bracket: ) - from_clause: - keyword: FROM - from_expression: diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/star_expression.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/star_expression.sql new file mode 100644 index 000000000..05c2ebb00 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/star_expression.sql @@ -0,0 +1,42 @@ +-- * RENAME +SELECT * RENAME (a AS b) +FROM tbl; + +-- Pattern Matching +SELECT * LIKE 'col%' +FROM tbl; + +SELECT * ILIKE 'col%' +FROM tbl; + +SELECT * NOT LIKE 'col%' +FROM tbl; + +SELECT * GLOB 'col*' +FROM tbl; + +SELECT * SIMILAR TO 'col.' +FROM tbl; + +-- Pattern Matching with symbols +SELECT * ~~ 'col%' +FROM tbl; + +SELECT * ~~* 'col%' +FROM tbl; + +SELECT * !~~ 'col%' +FROM tbl; + +SELECT * ~~~ 'col*' +FROM tbl; + +SELECT COLUMNS(['id', 'num']) FROM numbers; + +SELECT COALESCE(*COLUMNS([upper(x) for x in ['a', 'b', 'c']])) AS result +FROM (SELECT NULL AS a, 42 AS b, true AS c); + +-- test trailing commas +SELECT * EXCLUDE (a, b, c,) FROM tbl; +SELECT * REPLACE (a + 1 as a, b || 'c' as b,) FROM TBL; +SELECT * RENAME (a as apple, b as berry,) FROM TBL; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/star_expression.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/star_expression.yml new file mode 100644 index 000000000..c19b1fef3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/star_expression.yml @@ -0,0 +1,419 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_rename: + - keyword: RENAME + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: b + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_pattern_matching: + - keyword: LIKE + - quoted_literal: '''col%''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_pattern_matching: + - keyword: ILIKE + - quoted_literal: '''col%''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_pattern_matching: + - keyword: NOT + - keyword: LIKE + - quoted_literal: '''col%''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_pattern_matching: + - keyword: GLOB + - quoted_literal: '''col*''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_pattern_matching: + - keyword: SIMILAR + - keyword: TO + - quoted_literal: '''col.''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_pattern_matching: + - like_operator: ~~ + - quoted_literal: '''col%''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_pattern_matching: + - like_operator: ~~* + - quoted_literal: '''col%''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_pattern_matching: + - like_operator: '!~~' + - quoted_literal: '''col%''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_pattern_matching: + - glob_operator: ~~~ + - quoted_literal: '''col*''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: COLUMNS + - function_contents: + - bracketed: + - start_bracket: ( + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''id''' + - comma: ',' + - quoted_literal: '''num''' + - end_square_bracket: ']' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: numbers +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: COALESCE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - symbol: '*' + - keyword: COLUMNS + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - list_comprehension: + - start_square_bracket: '[' + - expression: + - function: + - function_name: + - function_name_identifier: upper + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - end_bracket: ) + - keyword: for + - parameter: x + - keyword: in + - expression: + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''a''' + - comma: ',' + - quoted_literal: '''b''' + - comma: ',' + - quoted_literal: '''c''' + - end_square_bracket: ']' + - end_square_bracket: ']' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: result + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - null_literal: 'NULL' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - comma: ',' + - select_clause_element: + - numeric_literal: '42' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: b + - comma: ',' + - select_clause_element: + - boolean_literal: 'true' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: c + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_exclude: + - keyword: EXCLUDE + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - comma: ',' + - column_reference: + - naked_identifier: c + - comma: ',' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_replace: + - keyword: REPLACE + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: a + - binary_operator: + + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: a + - comma: ',' + - expression: + - column_reference: + - naked_identifier: b + - binary_operator: + - pipe: '|' + - pipe: '|' + - quoted_literal: '''c''' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: b + - comma: ',' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: TBL +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_rename: + - keyword: RENAME + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: apple + - comma: ',' + - column_reference: + - naked_identifier: b + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: berry + - comma: ',' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: TBL +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/structs.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/structs.sql new file mode 100644 index 000000000..90db9f88a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/structs.sql @@ -0,0 +1,3 @@ +SELECT a::STRUCT(y INTEGER) AS b +FROM + (SELECT {'x': 42} AS a); diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/structs.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/structs.yml new file mode 100644 index 000000000..d3b5964a0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/structs.yml @@ -0,0 +1,49 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - column_reference: + - naked_identifier: a + - casting_operator: '::' + - data_type: + - struct_type: + - keyword: STRUCT + - struct_type_schema: + - bracketed: + - start_bracket: ( + - parameter: y + - data_type: + - keyword: INTEGER + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - object_literal: + - start_curly_bracket: '{' + - object_literal_element: + - quoted_literal: '''x''' + - colon: ':' + - numeric_literal: '42' + - end_curly_bracket: '}' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/summarize.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/summarize.sql deleted file mode 100644 index e18c8e243..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/summarize.sql +++ /dev/null @@ -1,3 +0,0 @@ -SUMMARIZE tbl; - -SUMMARIZE SELECT * FROM tbl; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/unpivot.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/unpivot.sql new file mode 100644 index 000000000..91ff44c6e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/unpivot.sql @@ -0,0 +1,48 @@ +-- Simplified UNPIVOT +UNPIVOT monthly_sales +ON jan, feb, mar, apr, may, jun +INTO +NAME month +VALUE sales; + +UNPIVOT monthly_sales +ON COLUMNS (* EXCLUDE (empid, dept)) +INTO +NAME month +VALUE sales; + +UNPIVOT monthly_sales +ON (jan, feb, mar) AS q1, (apr, may, jun) AS q2 +INTO +NAME quarter +VALUE month_1_sales, month_2_sales, month_3_sales; + +WITH unpivot_alias AS ( + UNPIVOT monthly_sales + ON COLUMNS (* EXCLUDE (empid, dept)) + INTO + NAME month + VALUE sales +) + +SELECT * FROM unpivot_alias; + +-- Standard UNPIVOT +FROM monthly_sales UNPIVOT ( + sales + FOR month IN (jan, feb, mar, apr, may, jun) +); + +FROM monthly_sales UNPIVOT ( + sales + FOR month IN (COLUMNS (* EXCLUDE (empid, dept))) +); + +FROM monthly_sales +UNPIVOT ( + (month_1_sales, month_2_sales, month_3_sales) + FOR quarter IN ( + (jan, feb, mar) AS q1, + (apr, may, jun) AS q2 + ) +); diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/unpivot.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/unpivot.yml new file mode 100644 index 000000000..cc12e7e5c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/unpivot.yml @@ -0,0 +1,293 @@ +file: +- statement: + - simplified_unpivot: + - keyword: UNPIVOT + - table_expression: + - table_reference: + - naked_identifier: monthly_sales + - keyword: ON + - column_reference: + - naked_identifier: jan + - comma: ',' + - column_reference: + - naked_identifier: feb + - comma: ',' + - column_reference: + - naked_identifier: mar + - comma: ',' + - column_reference: + - naked_identifier: apr + - comma: ',' + - column_reference: + - naked_identifier: may + - comma: ',' + - column_reference: + - naked_identifier: jun + - keyword: INTO + - keyword: NAME + - naked_identifier: month + - keyword: VALUE + - naked_identifier: sales +- statement_terminator: ; +- statement: + - simplified_unpivot: + - keyword: UNPIVOT + - table_expression: + - table_reference: + - naked_identifier: monthly_sales + - keyword: ON + - function_name: + - keyword: COLUMNS + - function_contents: + - bracketed: + - start_bracket: ( + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_exclude: + - keyword: EXCLUDE + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: empid + - comma: ',' + - column_reference: + - naked_identifier: dept + - end_bracket: ) + - end_bracket: ) + - keyword: INTO + - keyword: NAME + - naked_identifier: month + - keyword: VALUE + - naked_identifier: sales +- statement_terminator: ; +- statement: + - simplified_unpivot: + - keyword: UNPIVOT + - table_expression: + - table_reference: + - naked_identifier: monthly_sales + - keyword: ON + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: jan + - comma: ',' + - column_reference: + - naked_identifier: feb + - comma: ',' + - column_reference: + - naked_identifier: mar + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: q1 + - comma: ',' + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: apr + - comma: ',' + - column_reference: + - naked_identifier: may + - comma: ',' + - column_reference: + - naked_identifier: jun + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: q2 + - keyword: INTO + - keyword: NAME + - naked_identifier: quarter + - keyword: VALUE + - naked_identifier: month_1_sales + - comma: ',' + - naked_identifier: month_2_sales + - comma: ',' + - naked_identifier: month_3_sales +- statement_terminator: ; +- statement: + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: unpivot_alias + - keyword: AS + - bracketed: + - start_bracket: ( + - simplified_unpivot: + - keyword: UNPIVOT + - table_expression: + - table_reference: + - naked_identifier: monthly_sales + - keyword: ON + - function_name: + - keyword: COLUMNS + - function_contents: + - bracketed: + - start_bracket: ( + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_exclude: + - keyword: EXCLUDE + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: empid + - comma: ',' + - column_reference: + - naked_identifier: dept + - end_bracket: ) + - end_bracket: ) + - keyword: INTO + - keyword: NAME + - naked_identifier: month + - keyword: VALUE + - naked_identifier: sales + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: unpivot_alias +- statement_terminator: ; +- statement: + - select_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: monthly_sales + - from_unpivot_expression: + - keyword: UNPIVOT + - bracketed: + - start_bracket: ( + - naked_identifier: sales + - keyword: FOR + - naked_identifier: month + - keyword: IN + - bracketed: + - start_bracket: ( + - naked_identifier: jan + - comma: ',' + - naked_identifier: feb + - comma: ',' + - naked_identifier: mar + - comma: ',' + - naked_identifier: apr + - comma: ',' + - naked_identifier: may + - comma: ',' + - naked_identifier: jun + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: monthly_sales + - from_unpivot_expression: + - keyword: UNPIVOT + - bracketed: + - start_bracket: ( + - naked_identifier: sales + - keyword: FOR + - naked_identifier: month + - keyword: IN + - bracketed: + - start_bracket: ( + - function_name: + - keyword: COLUMNS + - function_contents: + - bracketed: + - start_bracket: ( + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - wildcard_exclude: + - keyword: EXCLUDE + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: empid + - comma: ',' + - column_reference: + - naked_identifier: dept + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: monthly_sales + - from_unpivot_expression: + - keyword: UNPIVOT + - bracketed: + - start_bracket: ( + - bracketed: + - start_bracket: ( + - naked_identifier: month_1_sales + - comma: ',' + - naked_identifier: month_2_sales + - comma: ',' + - naked_identifier: month_3_sales + - end_bracket: ) + - keyword: FOR + - naked_identifier: quarter + - keyword: IN + - bracketed: + - start_bracket: ( + - bracketed: + - start_bracket: ( + - naked_identifier: jan + - comma: ',' + - naked_identifier: feb + - comma: ',' + - naked_identifier: mar + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: q1 + - comma: ',' + - bracketed: + - start_bracket: ( + - naked_identifier: apr + - comma: ',' + - naked_identifier: may + - comma: ',' + - naked_identifier: jun + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: q2 + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/walrus_operator_function.sql b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/walrus_operator_function.sql new file mode 100644 index 000000000..022e62906 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/walrus_operator_function.sql @@ -0,0 +1,11 @@ +create view v as +select + t.id, + struct_pack( + val := t.val + ) as s +from + t; + + +select struct_insert({ 'a': 1 }, b := 2); diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/walrus_operator_function.yml b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/walrus_operator_function.yml new file mode 100644 index 000000000..cc7447a32 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/walrus_operator_function.yml @@ -0,0 +1,72 @@ +file: +- statement: + - create_view_statement: + - keyword: create + - keyword: view + - table_reference: + - naked_identifier: v + - keyword: as + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: struct_pack + - function_contents: + - bracketed: + - start_bracket: ( + - named_argument: + - naked_identifier: val + - assignment_operator: := + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: val + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: s + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - function_name_identifier: struct_insert + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - object_literal: + - start_curly_bracket: '{' + - object_literal_element: + - quoted_literal: '''a''' + - colon: ':' + - numeric_literal: '1' + - end_curly_bracket: '}' + - comma: ',' + - named_argument: + - naked_identifier: b + - assignment_operator: := + - expression: + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/.sqlfluff b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/.sqlfluff new file mode 100644 index 000000000..b71883509 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/.sqlfluff @@ -0,0 +1,2 @@ +[sqlfluff] +dialect = hive diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_database.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_database.sql new file mode 100644 index 000000000..a674205a9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_database.sql @@ -0,0 +1,5 @@ +ALTER DATABASE foo SET DBPROPERTIES ("prop1"="val1", "prop2"="val2"); + +ALTER DATABASE bar SET LOCATION "hdfs://alternate_path"; + +ALTER DATABASE foo2 SET OWNER USER "user"; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_database.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_database.yml new file mode 100644 index 000000000..67fd53f0a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_database.yml @@ -0,0 +1,43 @@ +file: +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: foo + - keyword: SET + - keyword: DBPROPERTIES + - bracketed: + - start_bracket: ( + - quoted_literal: '"prop1"' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"val1"' + - comma: ',' + - quoted_literal: '"prop2"' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"val2"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: bar + - keyword: SET + - keyword: LOCATION + - quoted_literal: '"hdfs://alternate_path"' +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: foo2 + - keyword: SET + - keyword: OWNER + - keyword: USER + - quoted_literal: '"user"' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_schema.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_schema.sql new file mode 100644 index 000000000..35acc6485 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_schema.sql @@ -0,0 +1,3 @@ +ALTER DATABASE foo SET OWNER ROLE "role"; + +ALTER DATABASE bar SET MANAGEDLOCATION "hdfs://alternate_path"; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_schema.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_schema.yml new file mode 100644 index 000000000..0c7636c92 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_schema.yml @@ -0,0 +1,22 @@ +file: +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: foo + - keyword: SET + - keyword: OWNER + - keyword: ROLE + - quoted_literal: '"role"' +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: bar + - keyword: SET + - keyword: MANAGEDLOCATION + - quoted_literal: '"hdfs://alternate_path"' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_table.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_table.sql new file mode 100644 index 000000000..f6ac72686 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_table.sql @@ -0,0 +1,5 @@ +ALTER TABLE schema.table1 rename TO schema.table2; + +ALTER TABLE schema.table1 rename TO schema.table2; + +ALTER TABLE table2 EXCHANGE PARTITION (ds='1') WITH TABLE table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_table.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_table.yml new file mode 100644 index 000000000..3e32035d2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_table.yml @@ -0,0 +1,52 @@ +file: +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: schema + - dot: . + - naked_identifier: table1 + - keyword: rename + - keyword: TO + - table_reference: + - naked_identifier: schema + - dot: . + - naked_identifier: table2 +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: schema + - dot: . + - naked_identifier: table1 + - keyword: rename + - keyword: TO + - table_reference: + - naked_identifier: schema + - dot: . + - naked_identifier: table2 +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table2 + - keyword: EXCHANGE + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: ds + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''1''' + - end_bracket: ) + - keyword: WITH + - keyword: TABLE + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_view.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_view.sql new file mode 100644 index 000000000..d2ecf4b94 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_view.sql @@ -0,0 +1,3 @@ +ALTER VIEW db.foo AS SELECT col1 FROM db.bar; + +ALTER VIEW foo SET TBLPROPERTIES ('bar' = '1', 'baz' = '2'); diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_view.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_view.yml new file mode 100644 index 000000000..942c68ee9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/alter_view.yml @@ -0,0 +1,47 @@ +file: +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: foo + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: bar +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: foo + - keyword: SET + - keyword: TBLPROPERTIES + - bracketed: + - start_bracket: ( + - quoted_literal: '''bar''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''1''' + - comma: ',' + - quoted_literal: '''baz''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/array_types.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/array_types.sql new file mode 100644 index 000000000..269f23e0f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/array_types.sql @@ -0,0 +1,26 @@ +-- simple +select array[a, b, c] as arr +from sch.tbl; + +-- bit harder +select t.a +from unnest(array[1, 3, 6, 12]) as t(f); + +-- complex +select map_from_entries(array[ + row('pending.freebet', pending_fb), + row('bonus.balance', bonus) +]) +from sch.tbl; + +-- string consts +select array['a', 'b', 'c'] as arr +from sch.tbl; + +-- null +select array['a', null] as arr +from sch.tbl; + +-- empty array +select array[] as arr +from sch.tbl; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/array_types.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/array_types.yml new file mode 100644 index 000000000..32e04a92c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/array_types.yml @@ -0,0 +1,218 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - typed_array_literal: + - array_type: + - keyword: array + - array_literal: + - start_square_bracket: '[' + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - comma: ',' + - column_reference: + - naked_identifier: c + - end_square_bracket: ']' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: arr + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sch + - dot: . + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: a + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: unnest + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - typed_array_literal: + - array_type: + - keyword: array + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '3' + - comma: ',' + - numeric_literal: '6' + - comma: ',' + - numeric_literal: '12' + - end_square_bracket: ']' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: t + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: f + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - function_name_identifier: map_from_entries + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - typed_array_literal: + - array_type: + - keyword: array + - array_literal: + - start_square_bracket: '[' + - function: + - function_name: + - function_name_identifier: row + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''pending.freebet''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: pending_fb + - end_bracket: ) + - comma: ',' + - function: + - function_name: + - function_name_identifier: row + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''bonus.balance''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: bonus + - end_bracket: ) + - end_square_bracket: ']' + - end_bracket: ) + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sch + - dot: . + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - typed_array_literal: + - array_type: + - keyword: array + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''a''' + - comma: ',' + - quoted_literal: '''b''' + - comma: ',' + - quoted_literal: '''c''' + - end_square_bracket: ']' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: arr + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sch + - dot: . + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - typed_array_literal: + - array_type: + - keyword: array + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''a''' + - comma: ',' + - null_literal: 'null' + - end_square_bracket: ']' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: arr + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sch + - dot: . + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - typed_array_literal: + - array_type: + - keyword: array + - array_literal: + - start_square_bracket: '[' + - end_square_bracket: ']' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: arr + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sch + - dot: . + - naked_identifier: tbl +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_database.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_database.sql new file mode 100644 index 000000000..c757803a9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_database.sql @@ -0,0 +1 @@ +CREATE DATABASE foo LOCATION 'hdfs://path' WITH DBPROPERTIES ("a"="1", "b"="2"); diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_database.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_database.yml new file mode 100644 index 000000000..6d517b16d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_database.yml @@ -0,0 +1,24 @@ +file: +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: foo + - keyword: LOCATION + - quoted_literal: '''hdfs://path''' + - keyword: WITH + - keyword: DBPROPERTIES + - bracketed: + - start_bracket: ( + - quoted_literal: '"a"' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"1"' + - comma: ',' + - quoted_literal: '"b"' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"2"' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_schema.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_schema.sql new file mode 100644 index 000000000..2160808b7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_schema.sql @@ -0,0 +1 @@ +CREATE SCHEMA IF NOT EXISTS foo COMMENT 'test schema' MANAGEDLOCATION 'hdfs://path'; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_schema.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_schema.yml new file mode 100644 index 000000000..9e9f12514 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_schema.yml @@ -0,0 +1,15 @@ +file: +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: SCHEMA + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - database_reference: + - naked_identifier: foo + - keyword: COMMENT + - quoted_literal: '''test schema''' + - keyword: MANAGEDLOCATION + - quoted_literal: '''hdfs://path''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_as_select.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_as_select.sql new file mode 100644 index 000000000..52cb5edb4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_as_select.sql @@ -0,0 +1,6 @@ +CREATE TABLE new_foo + ROW FORMAT SERDE "org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe" + STORED AS RCFile + AS +SELECT (col1 % 1024) col, concat(col1, col2) col12 +FROM foo; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_as_select.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_as_select.yml new file mode 100644 index 000000000..9223eeb0e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_as_select.yml @@ -0,0 +1,57 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: new_foo + - row_format_clause: + - keyword: ROW + - keyword: FORMAT + - keyword: SERDE + - quoted_literal: '"org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe"' + - keyword: STORED + - keyword: AS + - file_format: RCFile + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col1 + - binary_operator: '%' + - numeric_literal: '1024' + - end_bracket: ) + - alias_expression: + - naked_identifier: col + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: concat + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - expression: + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - alias_expression: + - naked_identifier: col12 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_clustered_by.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_clustered_by.sql new file mode 100644 index 000000000..33b278d05 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_clustered_by.sql @@ -0,0 +1,5 @@ +CREATE TABLE IF NOT EXISTS foo ( + col1 string, + col2 float +) +CLUSTERED BY (col2) SORTED BY (col1 DESC) INTO 5 BUCKETS; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_clustered_by.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_clustered_by.yml new file mode 100644 index 000000000..0d2b329fa --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_clustered_by.yml @@ -0,0 +1,43 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: foo + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: string + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - primitive_type: + - keyword: float + - end_bracket: ) + - keyword: CLUSTERED + - keyword: BY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: SORTED + - keyword: BY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - keyword: DESC + - end_bracket: ) + - keyword: INTO + - numeric_literal: '5' + - keyword: BUCKETS +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_constraints.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_constraints.sql new file mode 100644 index 000000000..5a257022f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_constraints.sql @@ -0,0 +1,37 @@ +CREATE TABLE foo( + col1 INT PRIMARY KEY, + col2 INTEGER NOT NULL, + col3 BIGINT NOT NULL, + col4 STRING, + col5 STRING COMMENT 'Column 5' +) +COMMENT 'This is a test table' +STORED AS ORC; + +CREATE TABLE product + ( + product_id INTEGER, + product_vendor_id INTEGER, + PRIMARY KEY (product_id) DISABLE NOVALIDATE, + CONSTRAINT product_fk_1 FOREIGN KEY (product_vendor_id) REFERENCES vendor(vendor_id) DISABLE NOVALIDATE + ); + +CREATE TABLE vendor + ( + vendor_id INTEGER, + PRIMARY KEY (vendor_id) DISABLE NOVALIDATE RELY + ); + +CREATE TABLE product + ( + product_id INTEGER, + product_vendor_id INTEGER, + PRIMARY KEY (product_id) DISABLE NOVALIDATE, + CONSTRAINT product_fk_1 FOREIGN KEY (product_vendor_id) REFERENCES vendor(vendor_id) DISABLE NOVALIDATE + ); + +CREATE TABLE vendor + ( + vendor_id INTEGER, + PRIMARY KEY (vendor_id) DISABLE NOVALIDATE NORELY + ); diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_constraints.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_constraints.yml new file mode 100644 index 000000000..7559b7687 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_constraints.yml @@ -0,0 +1,220 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: INT + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - primitive_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: col3 + - data_type: + - primitive_type: + - keyword: BIGINT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: col4 + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - column_definition: + - naked_identifier: col5 + - data_type: + - primitive_type: + - keyword: STRING + - column_constraint_segment: + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''Column 5''' + - end_bracket: ) + - keyword: COMMENT + - quoted_literal: '''This is a test table''' + - keyword: STORED + - keyword: AS + - keyword: ORC +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: product + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: product_id + - data_type: + - primitive_type: + - keyword: INTEGER + - comma: ',' + - column_definition: + - naked_identifier: product_vendor_id + - data_type: + - primitive_type: + - keyword: INTEGER + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: product_id + - end_bracket: ) + - keyword: DISABLE + - keyword: NOVALIDATE + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: product_fk_1 + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: product_vendor_id + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: vendor + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: vendor_id + - end_bracket: ) + - keyword: DISABLE + - keyword: NOVALIDATE + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: vendor + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: vendor_id + - data_type: + - primitive_type: + - keyword: INTEGER + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: vendor_id + - end_bracket: ) + - keyword: DISABLE + - keyword: NOVALIDATE + - keyword: RELY + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: product + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: product_id + - data_type: + - primitive_type: + - keyword: INTEGER + - comma: ',' + - column_definition: + - naked_identifier: product_vendor_id + - data_type: + - primitive_type: + - keyword: INTEGER + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: product_id + - end_bracket: ) + - keyword: DISABLE + - keyword: NOVALIDATE + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: product_fk_1 + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: product_vendor_id + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: vendor + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: vendor_id + - end_bracket: ) + - keyword: DISABLE + - keyword: NOVALIDATE + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: vendor + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: vendor_id + - data_type: + - primitive_type: + - keyword: INTEGER + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: vendor_id + - end_bracket: ) + - keyword: DISABLE + - keyword: NOVALIDATE + - keyword: NORELY + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_datatypes.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_datatypes.sql new file mode 100644 index 000000000..3255a756c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_datatypes.sql @@ -0,0 +1,10 @@ +CREATE TABLE db.foo ( + col1 string, + col2 int, + col3 decimal, + col4 decimal(10, 2), + col5 ARRAY, + col6 MAP, + col7 STRUCT< field1: boolean, field2: ARRAY, field3: UNIONTYPE>, + col8 UNIONTYPE> +); diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_datatypes.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_datatypes.yml new file mode 100644 index 000000000..a557c1582 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_datatypes.yml @@ -0,0 +1,133 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: foo + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: string + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - primitive_type: + - keyword: int + - comma: ',' + - column_definition: + - naked_identifier: col3 + - data_type: + - primitive_type: + - keyword: decimal + - comma: ',' + - column_definition: + - naked_identifier: col4 + - data_type: + - primitive_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '10' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col5 + - data_type: + - array_type: + - keyword: ARRAY + - start_angle_bracket: < + - data_type: + - primitive_type: + - keyword: double + - end_angle_bracket: '>' + - comma: ',' + - column_definition: + - naked_identifier: col6 + - data_type: + - keyword: MAP + - start_angle_bracket: < + - primitive_type: + - keyword: varchar + - comma: ',' + - data_type: + - primitive_type: + - keyword: date + - end_angle_bracket: '>' + - comma: ',' + - column_definition: + - naked_identifier: col7 + - data_type: + - struct_type: + - keyword: STRUCT + - struct_type_schema: + - start_angle_bracket: < + - naked_identifier: field1 + - colon: ':' + - data_type: + - primitive_type: + - keyword: boolean + - comma: ',' + - naked_identifier: field2 + - colon: ':' + - data_type: + - array_type: + - keyword: ARRAY + - start_angle_bracket: < + - data_type: + - primitive_type: + - keyword: double + - keyword: precision + - end_angle_bracket: '>' + - comma: ',' + - naked_identifier: field3 + - colon: ':' + - data_type: + - keyword: UNIONTYPE + - start_angle_bracket: < + - data_type: + - primitive_type: + - keyword: string + - comma: ',' + - data_type: + - primitive_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '10' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - end_angle_bracket: '>' + - end_angle_bracket: '>' + - comma: ',' + - column_definition: + - naked_identifier: col8 + - data_type: + - keyword: UNIONTYPE + - start_angle_bracket: < + - data_type: + - primitive_type: + - keyword: string + - comma: ',' + - data_type: + - array_type: + - keyword: ARRAY + - start_angle_bracket: < + - data_type: + - primitive_type: + - keyword: char + - end_angle_bracket: '>' + - end_angle_bracket: '>' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_external_partitioned.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_external_partitioned.sql new file mode 100644 index 000000000..4b0d46e78 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_external_partitioned.sql @@ -0,0 +1,6 @@ +CREATE EXTERNAL TABLE IF NOT EXISTS foo ( + col1 int, + col2 string +) +PARTITIONED BY (col3 string, col4 date) +LOCATION 'hdfs://path'; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_external_partitioned.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_external_partitioned.yml new file mode 100644 index 000000000..51fdd2a25 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_external_partitioned.yml @@ -0,0 +1,44 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: foo + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: int + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - primitive_type: + - keyword: string + - end_bracket: ) + - keyword: PARTITIONED + - keyword: BY + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col3 + - data_type: + - primitive_type: + - keyword: string + - comma: ',' + - column_definition: + - naked_identifier: col4 + - data_type: + - primitive_type: + - keyword: date + - end_bracket: ) + - keyword: LOCATION + - quoted_literal: '''hdfs://path''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_like.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_like.sql new file mode 100644 index 000000000..a975f9602 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_like.sql @@ -0,0 +1,3 @@ +CREATE TABLE db.new_foo +LIKE foo +TBLPROPERTIES ("property_name"="property_value"); diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_like.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_like.yml new file mode 100644 index 000000000..efd64bd2a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_like.yml @@ -0,0 +1,21 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: db + - dot: . + - naked_identifier: new_foo + - keyword: LIKE + - table_reference: + - naked_identifier: foo + - keyword: TBLPROPERTIES + - bracketed: + - start_bracket: ( + - quoted_literal: '"property_name"' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"property_value"' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_delimited.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_delimited.sql new file mode 100644 index 000000000..48d9f9797 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_delimited.sql @@ -0,0 +1,14 @@ + +CREATE TABLE foo( + col1 INT PRIMARY KEY, + col2 BIGINT NOT NULL, + col3 STRING, + col4 STRING COMMENT 'Column 4') + COMMENT 'This is a test table' + ROW FORMAT DELIMITED + FIELDS TERMINATED BY '\001' + COLLECTION ITEMS TERMINATED BY '\002' + MAP KEYS TERMINATED BY '\003' + LINES TERMINATED BY '\004' + NULL DEFINED AS '\005' +STORED AS SEQUENCEFILE; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_delimited.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_delimited.yml new file mode 100644 index 000000000..15701f0a8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_delimited.yml @@ -0,0 +1,75 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: INT + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - primitive_type: + - keyword: BIGINT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: col3 + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - column_definition: + - naked_identifier: col4 + - data_type: + - primitive_type: + - keyword: STRING + - column_constraint_segment: + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''Column 4''' + - end_bracket: ) + - keyword: COMMENT + - quoted_literal: '''This is a test table''' + - row_format_clause: + - keyword: ROW + - keyword: FORMAT + - keyword: DELIMITED + - keyword: FIELDS + - keyword: TERMINATED + - keyword: BY + - quoted_literal: '''\001''' + - keyword: COLLECTION + - keyword: ITEMS + - keyword: TERMINATED + - keyword: BY + - quoted_literal: '''\002''' + - keyword: MAP + - keyword: KEYS + - keyword: TERMINATED + - keyword: BY + - quoted_literal: '''\003''' + - keyword: LINES + - keyword: TERMINATED + - keyword: BY + - quoted_literal: '''\004''' + - keyword: 'NULL' + - keyword: DEFINED + - keyword: AS + - quoted_literal: '''\005''' + - keyword: STORED + - keyword: AS + - file_format: SEQUENCEFILE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_serde.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_serde.sql new file mode 100644 index 000000000..062414c9f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_serde.sql @@ -0,0 +1,11 @@ +CREATE TABLE foo ( + col1 int, + col2 string +) +PARTITIONED BY (col3 string, col4 date) +ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe' +WITH SERDEPROPERTIES ( + "input.regex" = "([^]*) ([^]*) ([^]*) (-|\\[^\\]*\\]) ([^ \"]*|\"[^\"]*\") (-|[0-9]*) (-|[0-9]*)(?: ([^ \"]*|\".*\") ([^ \"]*|\".*\"))?" +) +STORED AS TEXTFILE +LOCATION 'hdfs://path'; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_serde.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_serde.yml new file mode 100644 index 000000000..ce1e0fdf0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_row_format_serde.yml @@ -0,0 +1,57 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: int + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - primitive_type: + - keyword: string + - end_bracket: ) + - keyword: PARTITIONED + - keyword: BY + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col3 + - data_type: + - primitive_type: + - keyword: string + - comma: ',' + - column_definition: + - naked_identifier: col4 + - data_type: + - primitive_type: + - keyword: date + - end_bracket: ) + - row_format_clause: + - keyword: ROW + - keyword: FORMAT + - keyword: SERDE + - quoted_literal: '''org.apache.hadoop.hive.serde2.RegexSerDe''' + - keyword: WITH + - keyword: SERDEPROPERTIES + - bracketed: + - start_bracket: ( + - quoted_literal: '"input.regex"' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"([^]*) ([^]*) ([^]*) (-|\\[^\\]*\\]) ([^ \"]*|\"[^\"]*\") (-|[0-9]*) (-|[0-9]*)(?: ([^ \"]*|\".*\") ([^ \"]*|\".*\"))?"' + - end_bracket: ) + - keyword: STORED + - keyword: AS + - file_format: TEXTFILE + - keyword: LOCATION + - quoted_literal: '''hdfs://path''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_skewed_by.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_skewed_by.sql new file mode 100644 index 000000000..5326d65d6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_skewed_by.sql @@ -0,0 +1,2 @@ +CREATE TABLE foo (col1 STRING, col2 int, col3 STRING) + SKEWED BY (col1, col2) ON (('s1',1), ('s3',3), ('s13',13), ('s78',78)) STORED AS DIRECTORIES; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_skewed_by.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_skewed_by.yml new file mode 100644 index 000000000..b040a946f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_skewed_by.yml @@ -0,0 +1,73 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - primitive_type: + - keyword: int + - comma: ',' + - column_definition: + - naked_identifier: col3 + - data_type: + - primitive_type: + - keyword: STRING + - end_bracket: ) + - skewed_by_clause: + - keyword: SKEWED + - keyword: BY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: ON + - bracketed: + - start_bracket: ( + - bracketed: + - start_bracket: ( + - quoted_literal: '''s1''' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - quoted_literal: '''s3''' + - comma: ',' + - numeric_literal: '3' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - quoted_literal: '''s13''' + - comma: ',' + - numeric_literal: '13' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - quoted_literal: '''s78''' + - comma: ',' + - numeric_literal: '78' + - end_bracket: ) + - end_bracket: ) + - keyword: STORED + - keyword: AS + - keyword: DIRECTORIES +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_external.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_external.sql new file mode 100644 index 000000000..6cc7fd91e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_external.sql @@ -0,0 +1,6 @@ +CREATE TEMPORARY EXTERNAL TABLE IF NOT EXISTS foo ( + col1 int, + col2 string +) +PARTITIONED BY (col3 string, col4 date) +LOCATION 'hdfs://path'; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_external.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_external.yml new file mode 100644 index 000000000..f6ad5ce95 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_external.yml @@ -0,0 +1,45 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TEMPORARY + - keyword: EXTERNAL + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: foo + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: int + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - primitive_type: + - keyword: string + - end_bracket: ) + - keyword: PARTITIONED + - keyword: BY + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col3 + - data_type: + - primitive_type: + - keyword: string + - comma: ',' + - column_definition: + - naked_identifier: col4 + - data_type: + - primitive_type: + - keyword: date + - end_bracket: ) + - keyword: LOCATION + - quoted_literal: '''hdfs://path''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_properties.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_properties.sql new file mode 100644 index 000000000..a1fe5977d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_properties.sql @@ -0,0 +1,5 @@ +CREATE TEMPORARY TABLE foo ( + col1 string, + col2 float +) +TBLPROPERTIES ("property1"="value1", "property2"="value2"); diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_properties.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_properties.yml new file mode 100644 index 000000000..e0546fe8f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_temporary_properties.yml @@ -0,0 +1,36 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TEMPORARY + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: string + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - primitive_type: + - keyword: float + - end_bracket: ) + - keyword: TBLPROPERTIES + - bracketed: + - start_bracket: ( + - quoted_literal: '"property1"' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"value1"' + - comma: ',' + - quoted_literal: '"property2"' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"value2"' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_with.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_with.sql new file mode 100644 index 000000000..3d5728d0a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_with.sql @@ -0,0 +1,10 @@ +CREATE TABLE masonboro_sandbox.test +AS +WITH us_sales +AS ( + SELECT rev + FROM masonboro_sales.us_2021 +) + +SELECT rev +FROM us_sales; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_with.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_with.yml new file mode 100644 index 000000000..e2ddf60b9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/create_table_with.yml @@ -0,0 +1,47 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: masonboro_sandbox + - dot: . + - naked_identifier: test + - keyword: AS + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: us_sales + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: rev + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: masonboro_sales + - dot: . + - naked_identifier: us_2021 + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: rev + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: us_sales +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/double_equals.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/double_equals.sql new file mode 100644 index 000000000..2c6b4360a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/double_equals.sql @@ -0,0 +1,6 @@ +SELECT + a +FROM + t +WHERE + t.a == t.b diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/double_equals.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/double_equals.yml new file mode 100644 index 000000000..0cf07f0ba --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/double_equals.yml @@ -0,0 +1,29 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: b diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_database.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_database.sql new file mode 100644 index 000000000..58dc13177 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_database.sql @@ -0,0 +1,3 @@ +DROP DATABASE foo; + +DROP DATABASE bar RESTRICT; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_database.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_database.yml new file mode 100644 index 000000000..520d82ef2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_database.yml @@ -0,0 +1,16 @@ +file: +- statement: + - drop_database_statement: + - keyword: DROP + - keyword: DATABASE + - database_reference: + - naked_identifier: foo +- statement_terminator: ; +- statement: + - drop_database_statement: + - keyword: DROP + - keyword: DATABASE + - database_reference: + - naked_identifier: bar + - keyword: RESTRICT +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_schema.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_schema.sql new file mode 100644 index 000000000..1c81df799 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_schema.sql @@ -0,0 +1 @@ +DROP SCHEMA IF EXISTS foo CASCADE; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_schema.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_schema.yml new file mode 100644 index 000000000..af799091c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_schema.yml @@ -0,0 +1,11 @@ +file: +- statement: + - drop_schema_statement: + - keyword: DROP + - keyword: SCHEMA + - keyword: IF + - keyword: EXISTS + - schema_reference: + - naked_identifier: foo + - keyword: CASCADE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_table.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_table.sql new file mode 100644 index 000000000..39264e4af --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_table.sql @@ -0,0 +1,3 @@ +DROP TABLE foo; + +DROP TABLE IF exists bar PURGE; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_table.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_table.yml new file mode 100644 index 000000000..d0dd53375 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/drop_table.yml @@ -0,0 +1,18 @@ +file: +- statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - naked_identifier: foo +- statement_terminator: ; +- statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - keyword: IF + - keyword: exists + - table_reference: + - naked_identifier: bar + - keyword: PURGE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table.sql new file mode 100644 index 000000000..9370f178a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table.sql @@ -0,0 +1,5 @@ +INSERT INTO TABLE foo +SELECT a, b FROM bar; + +INSERT INTO foo +SELECT a, b FROM bar; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table.yml new file mode 100644 index 000000000..919a3fb25 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table.yml @@ -0,0 +1,50 @@ +file: +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: foo + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_partition.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_partition.sql new file mode 100644 index 000000000..1f90d2ba7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_partition.sql @@ -0,0 +1,3 @@ +INSERT INTO TABLE foo +PARTITION (a='test_foo', b='test_bar') +SELECT a, b, c, d FROM bar; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_partition.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_partition.yml new file mode 100644 index 000000000..88786f5fd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_partition.yml @@ -0,0 +1,49 @@ +file: +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test_foo''' + - comma: ',' + - column_reference: + - naked_identifier: b + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test_bar''' + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: d + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_values.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_values.sql new file mode 100644 index 000000000..0c00752ef --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_values.sql @@ -0,0 +1,2 @@ +INSERT INTO TABLE foo +VALUES ('foo', 'bar'), ('rab', 'oof'); diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_values.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_values.yml new file mode 100644 index 000000000..7335684fb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_into_table_values.yml @@ -0,0 +1,24 @@ +file: +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - quoted_literal: '''foo''' + - comma: ',' + - quoted_literal: '''bar''' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - quoted_literal: '''rab''' + - comma: ',' + - quoted_literal: '''oof''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_directory.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_directory.sql new file mode 100644 index 000000000..5110df972 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_directory.sql @@ -0,0 +1,2 @@ +INSERT OVERWRITE LOCAL DIRECTORY '/path' +SELECT a, b FROM foo; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_directory.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_directory.yml new file mode 100644 index 000000000..ab0ddcfe1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_directory.yml @@ -0,0 +1,26 @@ +file: +- statement: + - insert_statement: + - keyword: INSERT + - keyword: OVERWRITE + - keyword: LOCAL + - keyword: DIRECTORY + - quoted_literal: '''/path''' + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table.sql new file mode 100644 index 000000000..94898999a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table.sql @@ -0,0 +1,2 @@ +INSERT OVERWRITE TABLE foo +SELECT a, b FROM bar; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table.yml new file mode 100644 index 000000000..5c93cd8c2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table.yml @@ -0,0 +1,26 @@ +file: +- statement: + - insert_statement: + - keyword: INSERT + - keyword: OVERWRITE + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_dynamic_partition.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_dynamic_partition.sql new file mode 100644 index 000000000..2bd4c35b5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_dynamic_partition.sql @@ -0,0 +1,7 @@ +INSERT OVERWRITE TABLE foo +PARTITION (a = 'test_foo', b) IF NOT EXISTS +SELECT a, 'test_bar' AS b FROM bar; + +INSERT OVERWRITE TABLE foo +PARTITION (a, b) IF NOT EXISTS +SELECT 'test_foo' AS a, 'test_bar' AS b FROM bar; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_dynamic_partition.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_dynamic_partition.yml new file mode 100644 index 000000000..abbc96da9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_dynamic_partition.yml @@ -0,0 +1,87 @@ +file: +- statement: + - insert_statement: + - keyword: INSERT + - keyword: OVERWRITE + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test_foo''' + - comma: ',' + - column_reference: + - naked_identifier: b + - end_bracket: ) + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - quoted_literal: '''test_bar''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: OVERWRITE + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - end_bracket: ) + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''test_foo''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - comma: ',' + - select_clause_element: + - quoted_literal: '''test_bar''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_partition.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_partition.sql new file mode 100644 index 000000000..472e33d22 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_partition.sql @@ -0,0 +1,3 @@ +INSERT OVERWRITE TABLE foo +PARTITION (a='test_foo', b='test_bar') IF NOT EXISTS +SELECT a, b, c, d FROM bar; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_partition.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_partition.yml new file mode 100644 index 000000000..010a2e7b9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/insert_overwrite_table_partition.yml @@ -0,0 +1,52 @@ +file: +- statement: + - insert_statement: + - keyword: INSERT + - keyword: OVERWRITE + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test_foo''' + - comma: ',' + - column_reference: + - naked_identifier: b + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test_bar''' + - end_bracket: ) + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: d + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_repair_table.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_repair_table.sql new file mode 100644 index 000000000..91d0b550e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_repair_table.sql @@ -0,0 +1,12 @@ +-- REPAIR TABLE with all optional syntax +MSCK REPAIR TABLE table_identifier ADD PARTITIONS; +MSCK REPAIR TABLE table_identifier DROP PARTITIONS; +MSCK REPAIR TABLE table_identifier SYNC PARTITIONS; + +-- REPAIR TABLE with no optional syntax +MSCK REPAIR TABLE table_identifier; + +-- run MSCK REPAIR TABLE to recovers all the partitions +MSCK REPAIR TABLE t1; + +MSCK REPAIR TABLE emp_part DROP PARTITIONS; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_repair_table.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_repair_table.yml new file mode 100644 index 000000000..fe53bf3d5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_repair_table.yml @@ -0,0 +1,57 @@ +file: +- statement: + - msck_repair_table_statement: + - keyword: MSCK + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: table_identifier + - keyword: ADD + - keyword: PARTITIONS +- statement_terminator: ; +- statement: + - msck_repair_table_statement: + - keyword: MSCK + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: table_identifier + - keyword: DROP + - keyword: PARTITIONS +- statement_terminator: ; +- statement: + - msck_repair_table_statement: + - keyword: MSCK + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: table_identifier + - keyword: SYNC + - keyword: PARTITIONS +- statement_terminator: ; +- statement: + - msck_repair_table_statement: + - keyword: MSCK + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: table_identifier +- statement_terminator: ; +- statement: + - msck_repair_table_statement: + - keyword: MSCK + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - msck_repair_table_statement: + - keyword: MSCK + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: emp_part + - keyword: DROP + - keyword: PARTITIONS +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_table.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_table.sql new file mode 100644 index 000000000..08e229ce0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_table.sql @@ -0,0 +1,12 @@ +-- REPAIR TABLE with all optional syntax +MSCK TABLE table_identifier ADD PARTITIONS; +MSCK TABLE table_identifier DROP PARTITIONS; +MSCK TABLE table_identifier SYNC PARTITIONS; + +-- REPAIR TABLE with no optional syntax +MSCK TABLE table_identifier; + +-- run MSCK REPAIR TABLE to recovers all the partitions +MSCK TABLE t1; + +MSCK TABLE emp_part DROP PARTITIONS; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_table.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_table.yml new file mode 100644 index 000000000..250b12571 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/msck_table.yml @@ -0,0 +1,51 @@ +file: +- statement: + - msck_table_statement: + - keyword: MSCK + - keyword: TABLE + - table_reference: + - naked_identifier: table_identifier + - keyword: ADD + - keyword: PARTITIONS +- statement_terminator: ; +- statement: + - msck_table_statement: + - keyword: MSCK + - keyword: TABLE + - table_reference: + - naked_identifier: table_identifier + - keyword: DROP + - keyword: PARTITIONS +- statement_terminator: ; +- statement: + - msck_table_statement: + - keyword: MSCK + - keyword: TABLE + - table_reference: + - naked_identifier: table_identifier + - keyword: SYNC + - keyword: PARTITIONS +- statement_terminator: ; +- statement: + - msck_table_statement: + - keyword: MSCK + - keyword: TABLE + - table_reference: + - naked_identifier: table_identifier +- statement_terminator: ; +- statement: + - msck_table_statement: + - keyword: MSCK + - keyword: TABLE + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - msck_table_statement: + - keyword: MSCK + - keyword: TABLE + - table_reference: + - naked_identifier: emp_part + - keyword: DROP + - keyword: PARTITIONS +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/quoted_literal.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/quoted_literal.sql new file mode 100644 index 000000000..43297d92b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/quoted_literal.sql @@ -0,0 +1,5 @@ +SELECT result, `timestamp` as `timestamp` +FROM student +WHERE + name = "John Smith" + OR name = 'Jane Doe'; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/quoted_literal.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/quoted_literal.yml new file mode 100644 index 000000000..a45f31ba8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/quoted_literal.yml @@ -0,0 +1,37 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: result + - comma: ',' + - select_clause_element: + - quoted_literal: '`timestamp`' + - alias_expression: + - alias_operator: + - keyword: as + - quoted_identifier: '`timestamp`' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: student + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"John Smith"' + - binary_operator: OR + - column_reference: + - naked_identifier: name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Jane Doe''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cast.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cast.sql new file mode 100644 index 000000000..1a20fa98e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cast.sql @@ -0,0 +1,6 @@ +select + cast(row(col1, col2) as row(a bigint, b decimal(23, 2))) +from sch.tbl; + +select cast(a as json) +from sch.tbl; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cast.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cast.yml new file mode 100644 index 000000000..251859559 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cast.yml @@ -0,0 +1,85 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - function_name_identifier: cast + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: row + - function_contents: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: as + - keyword: row + - bracketed: + - start_bracket: ( + - naked_identifier: a + - data_type: + - primitive_type: + - keyword: bigint + - comma: ',' + - naked_identifier: b + - data_type: + - primitive_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '23' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sch + - dot: . + - naked_identifier: tbl +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - function_name_identifier: cast + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: a + - keyword: as + - data_type: + - primitive_type: + - keyword: json + - end_bracket: ) + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sch + - dot: . + - naked_identifier: tbl +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cluster_distribute_sort_by.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cluster_distribute_sort_by.sql new file mode 100644 index 000000000..22ee316d8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cluster_distribute_sort_by.sql @@ -0,0 +1,13 @@ +SELECT col1, col2 FROM t1 ORDER BY col1; + +SELECT col1, col2 FROM t1 CLUSTER BY col1; + +SELECT col1, col2 FROM t1 ORDER BY col1 CLUSTER BY col1; + +SELECT key, value FROM src SORT BY key ASC, value DESC; + +SELECT col1, col2 FROM t1 DISTRIBUTE BY col1; + +SELECT col1, col2 FROM t1 DISTRIBUTE BY col1 SORT BY col1 ASC, col2 DESC; + +SELECT col1, col2 FROM t1 ORDER BY col1 DISTRIBUTE BY col1 SORT BY col1 ASC, col2 DESC; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cluster_distribute_sort_by.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cluster_distribute_sort_by.yml new file mode 100644 index 000000000..73a80a9d1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_cluster_distribute_sort_by.yml @@ -0,0 +1,204 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: col1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - clusterby_clause: + - keyword: CLUSTER + - keyword: BY + - column_reference: + - naked_identifier: col1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: col1 + - clusterby_clause: + - keyword: CLUSTER + - keyword: BY + - column_reference: + - naked_identifier: col1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: key + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: value + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: src + - sortby_clause: + - keyword: SORT + - keyword: BY + - column_reference: + - naked_identifier: key + - keyword: ASC + - comma: ',' + - column_reference: + - naked_identifier: value + - keyword: DESC +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - distributeby_clause: + - keyword: DISTRIBUTE + - keyword: BY + - column_reference: + - naked_identifier: col1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - distributeby_clause: + - keyword: DISTRIBUTE + - keyword: BY + - column_reference: + - naked_identifier: col1 + - sortby_clause: + - keyword: SORT + - keyword: BY + - column_reference: + - naked_identifier: col1 + - keyword: ASC + - comma: ',' + - column_reference: + - naked_identifier: col2 + - keyword: DESC +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: col1 + - distributeby_clause: + - keyword: DISTRIBUTE + - keyword: BY + - column_reference: + - naked_identifier: col1 + - sortby_clause: + - keyword: SORT + - keyword: BY + - column_reference: + - naked_identifier: col1 + - keyword: ASC + - comma: ',' + - column_reference: + - naked_identifier: col2 + - keyword: DESC +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_interval.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_interval.sql new file mode 100644 index 000000000..4962b6931 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_interval.sql @@ -0,0 +1,37 @@ +SELECT current_date + INTERVAL '2' DAY; + +SELECT current_date - INTERVAL '1' DAY AS yesterday; + +SELECT current_date + INTERVAL '12' HOUR; + +-- These examples are from: +-- https://cwiki.apache.org/confluence/display/hive/languagemanual+types#LanguageManualTypes-Intervals +SELECT INTERVAL '1' DAY; + +SELECT INTERVAL '1-2' YEAR TO MONTH; + +SELECT INTERVAL '1' YEAR + INTERVAL '2' MONTH; + +SELECT INTERVAL '1 2:3:4.000005' DAY; + +SELECT INTERVAL '1' DAY+ + INTERVAL '2' HOUR + + INTERVAL '3' MINUTE + + INTERVAL '4' SECOND + + INTERVAL '5' NANO; + +SELECT INTERVAL 1 DAY; + +SELECT INTERVAL (1+dt) DAY; + +SELECT 1 DAY; + +SELECT INTERVAL 1 DAY; + +SELECT '1-2' YEAR TO MONTH; + +SELECT INTERVAL '1-2' YEARS TO MONTH; + +SELECT 2 SECONDS; + +SELECT 2 SECOND; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_interval.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_interval.yml new file mode 100644 index 000000000..93b9c570a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_interval.yml @@ -0,0 +1,210 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bare_function: current_date + - binary_operator: + + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''2''' + - date_part: DAY +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bare_function: current_date + - binary_operator: '-' + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''1''' + - date_part: DAY + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: yesterday +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bare_function: current_date + - binary_operator: + + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''12''' + - date_part: HOUR +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''1''' + - date_part: DAY +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''1-2''' + - date_part: YEAR + - keyword: TO + - date_part: MONTH +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''1''' + - date_part: YEAR + - binary_operator: + + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''2''' + - date_part: MONTH +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''1 2:3:4.000005''' + - date_part: DAY +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''1''' + - date_part: DAY + - binary_operator: + + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''2''' + - date_part: HOUR + - binary_operator: + + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''3''' + - date_part: MINUTE + - binary_operator: + + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''4''' + - date_part: SECOND + - binary_operator: + + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''5''' + - date_part: NANO +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - interval_expression: + - keyword: INTERVAL + - numeric_literal: '1' + - date_part: DAY +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - interval_expression: + - keyword: INTERVAL + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - binary_operator: + + - column_reference: + - naked_identifier: dt + - end_bracket: ) + - date_part: DAY +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - interval_expression: + - numeric_literal: '1' + - date_part: DAY +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - interval_expression: + - keyword: INTERVAL + - numeric_literal: '1' + - date_part: DAY +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - interval_expression: + - quoted_literal: '''1-2''' + - date_part: YEAR + - keyword: TO + - date_part: MONTH +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''1-2''' + - date_part: YEARS + - keyword: TO + - date_part: MONTH +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - interval_expression: + - numeric_literal: '2' + - date_part: SECONDS +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - interval_expression: + - numeric_literal: '2' + - date_part: SECOND +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_lateral_view.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_lateral_view.sql new file mode 100644 index 000000000..1789796f5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_lateral_view.sql @@ -0,0 +1,28 @@ +SELECT pageid, adid +FROM pageAds +LATERAL VIEW explode(adid_list) adTable AS adid; + +SELECT adid, count(1) +FROM pageAds LATERAL VIEW explode(adid_list) adTable AS adid +GROUP BY adid; + +SELECT * FROM exampleTable +LATERAL VIEW explode(col1) myTable1 AS myCol1 +LATERAL VIEW explode(myCol1) myTable2 AS myCol2; + +SELECT myCol1, myCol2 FROM baseTable +LATERAL VIEW explode(col1) myTable1 AS myCol1 +LATERAL VIEW explode(col2) myTable2 AS myCol2; + +SELECT * FROM src LATERAL VIEW explode(array()) C AS a limit 10; + +SELECT * FROM src LATERAL VIEW OUTER explode(array()) C AS a limit 10; + +-- besides as a part of LATERAL VIEW, UDTF can also be used in the SELECT expression +SELECT explode(map('A', 10, 'B', 20, 'C', 30)) AS (key,value); + +SELECT posexplode(array('A', 'B', 'C')) AS (pos,val); + +SELECT inline(array(struct('A', 10, DATE '2015-01-01'), struct('B', 20, DATE '2016-02-02'))) AS (col1,col2,col3); + +SELECT stack(2, 'A', 10, DATE '2015-01-01', 'B', 20, DATE '2016-01-01') AS (col0,col1,col2); diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_lateral_view.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_lateral_view.yml new file mode 100644 index 000000000..216929d6f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_lateral_view.yml @@ -0,0 +1,465 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: pageid + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: adid + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: pageAds + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: explode + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: adid_list + - end_bracket: ) + - naked_identifier: adTable + - keyword: AS + - naked_identifier: adid +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: adid + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: count + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: pageAds + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: explode + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: adid_list + - end_bracket: ) + - naked_identifier: adTable + - keyword: AS + - naked_identifier: adid + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: adid +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: exampleTable + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: explode + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - naked_identifier: myTable1 + - keyword: AS + - naked_identifier: myCol1 + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: explode + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: myCol1 + - end_bracket: ) + - naked_identifier: myTable2 + - keyword: AS + - naked_identifier: myCol2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: myCol1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: myCol2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: baseTable + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: explode + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - naked_identifier: myTable1 + - keyword: AS + - naked_identifier: myCol1 + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: explode + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - naked_identifier: myTable2 + - keyword: AS + - naked_identifier: myCol2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: src + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: explode + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: array + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - naked_identifier: C + - keyword: AS + - naked_identifier: a + - limit_clause: + - keyword: limit + - numeric_literal: '10' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: src + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - keyword: OUTER + - function: + - function_name: + - function_name_identifier: explode + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: array + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - naked_identifier: C + - keyword: AS + - naked_identifier: a + - limit_clause: + - keyword: limit + - numeric_literal: '10' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: explode + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: map + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''A''' + - comma: ',' + - expression: + - numeric_literal: '10' + - comma: ',' + - expression: + - quoted_literal: '''B''' + - comma: ',' + - expression: + - numeric_literal: '20' + - comma: ',' + - expression: + - quoted_literal: '''C''' + - comma: ',' + - expression: + - numeric_literal: '30' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: key + - comma: ',' + - naked_identifier: value + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: posexplode + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: array + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''A''' + - comma: ',' + - expression: + - quoted_literal: '''B''' + - comma: ',' + - expression: + - quoted_literal: '''C''' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: pos + - comma: ',' + - naked_identifier: val + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: inline + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: array + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: struct + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''A''' + - comma: ',' + - expression: + - numeric_literal: '10' + - comma: ',' + - expression: + - keyword: DATE + - date_constructor_literal: '''2015-01-01''' + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: struct + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''B''' + - comma: ',' + - expression: + - numeric_literal: '20' + - comma: ',' + - expression: + - keyword: DATE + - date_constructor_literal: '''2016-02-02''' + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: col1 + - comma: ',' + - naked_identifier: col2 + - comma: ',' + - naked_identifier: col3 + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: stack + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - quoted_literal: '''A''' + - comma: ',' + - expression: + - numeric_literal: '10' + - comma: ',' + - expression: + - keyword: DATE + - date_constructor_literal: '''2015-01-01''' + - comma: ',' + - expression: + - quoted_literal: '''B''' + - comma: ',' + - expression: + - numeric_literal: '20' + - comma: ',' + - expression: + - keyword: DATE + - date_constructor_literal: '''2016-01-01''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: col0 + - comma: ',' + - naked_identifier: col1 + - comma: ',' + - naked_identifier: col2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_left_semi_join.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_left_semi_join.sql new file mode 100644 index 000000000..df52340b2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_left_semi_join.sql @@ -0,0 +1,2 @@ +SELECT a.key, a.val +FROM a LEFT SEMI JOIN b ON (a.key = b.key) diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_left_semi_join.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_left_semi_join.yml new file mode 100644 index 000000000..bd1149f7a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_left_semi_join.yml @@ -0,0 +1,47 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: key + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: val + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: a + - join_clause: + - keyword: LEFT + - keyword: SEMI + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: b + - join_on_condition: + - keyword: ON + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: key + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: key + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_regexp.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_regexp.sql new file mode 100644 index 000000000..d57b7dbd0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_regexp.sql @@ -0,0 +1,26 @@ +SELECT * + FROM example + WHERE url REGEXP '(/click)'; + +SELECT + *, + url REGEXP '(/click)' + FROM example; + +SELECT * + FROM example + WHERE url IREGEXP '(/click)'; + +SELECT + *, + url IREGEXP '(/click)' + FROM example; + +SELECT * + FROM example + WHERE url RLIKE '(/click)'; + +SELECT + *, + url RLIKE '(/click)' + FROM example; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables_comprehensive.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_regexp.yml similarity index 52% rename from crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables_comprehensive.yml rename to crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_regexp.yml index 28fb2e922..c484ce2d6 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables_comprehensive.yml +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_regexp.yml @@ -4,35 +4,46 @@ file: - select_clause: - keyword: SELECT - select_clause_element: - - column_reference: - - quoted_identifier: '[value]' + - wildcard_expression: + - wildcard_identifier: + - star: '*' - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - table_reference: - - tsql_variable: '@DepartmentCodes' + - naked_identifier: example + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: url + - keyword: REGEXP + - quoted_literal: '''(/click)''' - statement_terminator: ; - statement: - select_statement: - select_clause: - keyword: SELECT - select_clause_element: - - column_reference: - - naked_identifier: ids - - dot: . - - quoted_identifier: '[value]' + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: url + - keyword: REGEXP + - quoted_literal: '''(/click)''' - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - table_reference: - - tsql_variable: '@DepartmentCodes' - - alias_expression: - - keyword: AS - - naked_identifier: ids + - naked_identifier: example - statement_terminator: ; - statement: - select_statement: @@ -48,15 +59,14 @@ file: - from_expression_element: - table_expression: - table_reference: - - tsql_variable: '@TableVariable' + - naked_identifier: example - where_clause: - keyword: WHERE - expression: - column_reference: - - quoted_identifier: '[value]' - - comparison_operator: - - raw_comparison_operator: '>' - - numeric_literal: '0' + - naked_identifier: url + - keyword: IREGEXP + - quoted_literal: '''(/click)''' - statement_terminator: ; - statement: - select_statement: @@ -66,18 +76,20 @@ file: - wildcard_expression: - wildcard_identifier: - star: '*' + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: url + - keyword: IREGEXP + - quoted_literal: '''(/click)''' - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - table_reference: - - tsql_variable: '@TableVariable' - - keyword: WITH - - bracketed: - - start_bracket: ( - - keyword: NOLOCK - - end_bracket: ) + - naked_identifier: example - statement_terminator: ; - statement: - select_statement: @@ -93,28 +105,35 @@ file: - from_expression_element: - table_expression: - table_reference: - - object_reference: - - naked_identifier: table1 + - naked_identifier: example - where_clause: - keyword: WHERE - expression: - column_reference: - - naked_identifier: id - - keyword: IN - - bracketed: - - start_bracket: ( - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - quoted_identifier: '[value]' - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - tsql_variable: '@DepartmentCodes' - - end_bracket: ) + - naked_identifier: url + - keyword: RLIKE + - quoted_literal: '''(/click)''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: url + - keyword: RLIKE + - quoted_literal: '''(/click)''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: example - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_sampling_table.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_sampling_table.sql new file mode 100644 index 000000000..7192a1772 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_sampling_table.sql @@ -0,0 +1,13 @@ +SELECT * +FROM source TABLESAMPLE(BUCKET 3 OUT OF 32 ON id) s; + +SELECT * +FROM source TABLESAMPLE(BUCKET 3 OUT OF 32 ON rand()) s; + +SELECT * +FROM source TABLESAMPLE(0.1 PERCENT) AS s; + +SELECT * +FROM source TABLESAMPLE(100M) s; + +SELECT * FROM source TABLESAMPLE(10 ROWS); diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_sampling_table.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_sampling_table.yml new file mode 100644 index 000000000..e59a42c72 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/select_sampling_table.yml @@ -0,0 +1,141 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: source + - sample_expression: + - keyword: TABLESAMPLE + - bracketed: + - start_bracket: ( + - keyword: BUCKET + - numeric_literal: '3' + - keyword: OUT + - keyword: OF + - numeric_literal: '32' + - keyword: ON + - naked_identifier: id + - end_bracket: ) + - alias_expression: + - naked_identifier: s +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: source + - sample_expression: + - keyword: TABLESAMPLE + - bracketed: + - start_bracket: ( + - keyword: BUCKET + - numeric_literal: '3' + - keyword: OUT + - keyword: OF + - numeric_literal: '32' + - keyword: ON + - function: + - function_name: + - function_name_identifier: rand + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - naked_identifier: s +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: source + - sample_expression: + - keyword: TABLESAMPLE + - bracketed: + - start_bracket: ( + - numeric_literal: '0.1' + - keyword: PERCENT + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: s +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: source + - sample_expression: + - keyword: TABLESAMPLE + - bracketed: + - start_bracket: ( + - byte_length_literal: 100M + - end_bracket: ) + - alias_expression: + - naked_identifier: s +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: source + - sample_expression: + - keyword: TABLESAMPLE + - bracketed: + - start_bracket: ( + - numeric_literal: '10' + - keyword: ROWS + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/set.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/set.sql new file mode 100644 index 000000000..89fba2eb3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/set.sql @@ -0,0 +1,6 @@ +set; +set -v; +set foo = 2; +set foo = 'bar'; +set hivevar:cat="Chloe"; +set mapreduce.reduce.memory.mb=12000; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/set.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/set.yml new file mode 100644 index 000000000..f36693929 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/set.yml @@ -0,0 +1,47 @@ +file: +- statement: + - set_statement: + - keyword: set +- statement_terminator: ; +- statement: + - set_statement: + - keyword: set + - option_indicator: '-' + - option: v +- statement_terminator: ; +- statement: + - set_statement: + - keyword: set + - parameter: foo + - raw_comparison_operator: = + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: set + - parameter: foo + - raw_comparison_operator: = + - quoted_literal: '''bar''' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: set + - parameter: hivevar + - colon_delimiter: ':' + - parameter: cat + - raw_comparison_operator: = + - quoted_literal: '"Chloe"' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: set + - parameter: mapreduce + - dot: . + - parameter: reduce + - dot: . + - parameter: memory + - dot: . + - parameter: mb + - raw_comparison_operator: = + - numeric_literal: '12000' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/truncate_table.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/truncate_table.sql new file mode 100644 index 000000000..cdc46b88a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/truncate_table.sql @@ -0,0 +1,3 @@ +TRUNCATE TABLE foo; + +TRUNCATE bar PARTITION (col='val'); diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/truncate_table.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/truncate_table.yml new file mode 100644 index 000000000..292cba0fe --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/truncate_table.yml @@ -0,0 +1,23 @@ +file: +- statement: + - truncate_statement: + - keyword: TRUNCATE + - keyword: TABLE + - table_reference: + - naked_identifier: foo +- statement_terminator: ; +- statement: + - truncate_statement: + - keyword: TRUNCATE + - table_reference: + - naked_identifier: bar + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''val''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/use.sql b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/use.sql new file mode 100644 index 000000000..610507790 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/use.sql @@ -0,0 +1 @@ +USE db; diff --git a/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/use.yml b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/use.yml new file mode 100644 index 000000000..530b518e1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/hive/sqlfluff/use.yml @@ -0,0 +1,7 @@ +file: +- statement: + - use_statement: + - keyword: USE + - database_reference: + - naked_identifier: db +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_database.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_database.sql new file mode 100644 index 000000000..e8e3a90c5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_database.sql @@ -0,0 +1,26 @@ +ALTER DATABASE my_database +DEFAULT CHARACTER SET utf8mb4 +COLLATE utf8mb4_0900_ai_ci +DEFAULT ENCRYPTION 'N'; + +ALTER DATABASE my_database +DEFAULT CHARACTER SET = utf8mb4 +COLLATE = utf8mb4_0900_ai_ci +DEFAULT ENCRYPTION = 'N'; + +ALTER SCHEMA my_database +DEFAULT CHARACTER SET utf8mb4 +COLLATE utf8mb4_0900_ai_ci +DEFAULT ENCRYPTION 'N'; + +ALTER DATABASE my_database +READ ONLY DEFAULT; + +ALTER DATABASE my_database +READ ONLY 0; + +ALTER DATABASE my_database +READ ONLY 1; + +ALTER DATABASE +READ ONLY DEFAULT; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_database.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_database.yml new file mode 100644 index 000000000..bd2c7e617 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_database.yml @@ -0,0 +1,109 @@ +file: +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database + - alter_option_segment: + - keyword: DEFAULT + - keyword: CHARACTER + - keyword: SET + - naked_identifier: utf8mb4 + - alter_option_segment: + - keyword: COLLATE + - collation_reference: + - naked_identifier: utf8mb4_0900_ai_ci + - alter_option_segment: + - keyword: DEFAULT + - keyword: ENCRYPTION + - quoted_literal: '''N''' +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database + - alter_option_segment: + - keyword: DEFAULT + - keyword: CHARACTER + - keyword: SET + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: utf8mb4 + - alter_option_segment: + - keyword: COLLATE + - comparison_operator: + - raw_comparison_operator: = + - collation_reference: + - naked_identifier: utf8mb4_0900_ai_ci + - alter_option_segment: + - keyword: DEFAULT + - keyword: ENCRYPTION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''N''' +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: SCHEMA + - database_reference: + - naked_identifier: my_database + - alter_option_segment: + - keyword: DEFAULT + - keyword: CHARACTER + - keyword: SET + - naked_identifier: utf8mb4 + - alter_option_segment: + - keyword: COLLATE + - collation_reference: + - naked_identifier: utf8mb4_0900_ai_ci + - alter_option_segment: + - keyword: DEFAULT + - keyword: ENCRYPTION + - quoted_literal: '''N''' +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database + - alter_option_segment: + - keyword: READ + - keyword: ONLY + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database + - alter_option_segment: + - keyword: READ + - keyword: ONLY + - numeric_literal: '0' +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database + - alter_option_segment: + - keyword: READ + - keyword: ONLY + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - alter_option_segment: + - keyword: READ + - keyword: ONLY + - keyword: DEFAULT +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_event.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_event.sql new file mode 100644 index 000000000..b554494a4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_event.sql @@ -0,0 +1,23 @@ +ALTER EVENT no_such_event + ON SCHEDULE + EVERY '2:3' DAY_HOUR; + +ALTER EVENT myevent + ON SCHEDULE + EVERY 12 HOUR + STARTS CURRENT_TIMESTAMP + INTERVAL 4 HOUR; + +ALTER EVENT myevent + ON SCHEDULE + AT CURRENT_TIMESTAMP + INTERVAL 1 DAY + DO + TRUNCATE TABLE myschema.mytable; + +ALTER EVENT myevent + DISABLE; + +ALTER EVENT myevent + RENAME TO yourevent; + +ALTER EVENT olddb.myevent + RENAME TO newdb.myevent; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_event.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_event.yml new file mode 100644 index 000000000..c8c207333 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_event.yml @@ -0,0 +1,97 @@ +file: +- statement: + - alter_event_statement: + - keyword: ALTER + - keyword: EVENT + - object_reference: + - naked_identifier: no_such_event + - keyword: ON + - keyword: SCHEDULE + - keyword: EVERY + - expression: + - quoted_literal: '''2:3''' + - date_part: DAY_HOUR +- statement_terminator: ; +- statement: + - alter_event_statement: + - keyword: ALTER + - keyword: EVENT + - object_reference: + - naked_identifier: myevent + - keyword: ON + - keyword: SCHEDULE + - keyword: EVERY + - expression: + - numeric_literal: '12' + - date_part: HOUR + - keyword: STARTS + - expression: + - bare_function: CURRENT_TIMESTAMP + - binary_operator: + + - interval_expression: + - keyword: INTERVAL + - expression: + - numeric_literal: '4' + - date_part: HOUR +- statement_terminator: ; +- statement: + - alter_event_statement: + - keyword: ALTER + - keyword: EVENT + - object_reference: + - naked_identifier: myevent + - keyword: ON + - keyword: SCHEDULE + - keyword: AT + - expression: + - bare_function: CURRENT_TIMESTAMP + - binary_operator: + + - interval_expression: + - keyword: INTERVAL + - expression: + - numeric_literal: '1' + - date_part: DAY + - keyword: DO + - statement: + - truncate_statement: + - keyword: TRUNCATE + - keyword: TABLE + - table_reference: + - naked_identifier: myschema + - dot: . + - naked_identifier: mytable +- statement_terminator: ; +- statement: + - alter_event_statement: + - keyword: ALTER + - keyword: EVENT + - object_reference: + - naked_identifier: myevent + - keyword: DISABLE +- statement_terminator: ; +- statement: + - alter_event_statement: + - keyword: ALTER + - keyword: EVENT + - object_reference: + - naked_identifier: myevent + - keyword: RENAME + - keyword: TO + - object_reference: + - naked_identifier: yourevent +- statement_terminator: ; +- statement: + - alter_event_statement: + - keyword: ALTER + - keyword: EVENT + - object_reference: + - naked_identifier: olddb + - dot: . + - naked_identifier: myevent + - keyword: RENAME + - keyword: TO + - object_reference: + - naked_identifier: newdb + - dot: . + - naked_identifier: myevent +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_table.sql new file mode 100644 index 000000000..6f751beaf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_table.sql @@ -0,0 +1,109 @@ +ALTER TABLE `users` + MODIFY COLUMN + `name` varchar(255) NOT NULL, + COMMENT "name of user"; + +ALTER TABLE `users` MODIFY `name` varchar(255) NOT NULL FIRST; + +ALTER TABLE `users` RENAME TO `user`; + +ALTER TABLE `user` RENAME AS `users`; + +ALTER TABLE `users` RENAME `user`; + +ALTER TABLE `users` RENAME COLUMN `col_1` TO `del_col_1`; + +ALTER TABLE `users` +CHANGE COLUMN `birthday` `date_of_birth` INT(11) NULL DEFAULT NULL; + +ALTER TABLE `users` +CHANGE COLUMN `birthday` `date_of_birth` INT(11) NOT NULL; + +ALTER TABLE `users` +CHANGE COLUMN `birthday` `date_of_birth` INT(11) FIRST; + +ALTER TABLE `users` +CHANGE COLUMN `birthday` `date_of_birth` INT(11) AFTER `name`; + +ALTER TABLE `users` +DROP COLUMN `age`; + +ALTER TABLE `foo`.`bar` +ADD CONSTRAINT `index_name` UNIQUE(`col_1`, `col_2`, `col_3`); + +ALTER TABLE `foo`.`bar` ADD UNIQUE `index_name`(`col_1`, `col_2`, `col_3`); + +ALTER TABLE `foo`.`bar` +ADD CONSTRAINT `index_name` UNIQUE INDEX (`col_1`, `col_2`, `col_3`); + +ALTER TABLE `foo`.`bar` +ADD UNIQUE INDEX `index_name`(`col_1`, `col_2`, `col_3`); + +ALTER TABLE `foo`.`bar` ADD INDEX `index_name`(`col_1`, `col_2`, `col_3`); + +ALTER TABLE `foo`.`bar` ADD INDEX `index_name`(`col_1`, `col_2`, `col_3`) +KEY_BLOCK_SIZE = 8; + +ALTER TABLE `foo`.`bar` ADD INDEX `index_name`(`col_1`, `col_2`, `col_3`) +KEY_BLOCK_SIZE 8; + +ALTER TABLE `foo`.`bar` ADD INDEX `index_name`(`col_1`, `col_2`, `col_3`) +KEY_BLOCK_SIZE 8 COMMENT 'index for col_1, col_2, col_3'; + +ALTER TABLE `foo`.`bar` DROP INDEX `index_name`; + +ALTER TABLE `foo`.`bar` RENAME INDEX `index_name` to `new_index_name`; + +ALTER TABLE `foo`.`bar` RENAME KEY `key_name` to `new_key_name`; + +ALTER TABLE `x` ADD CONSTRAINT FOREIGN KEY(`xk`) REFERENCES `y`(`yk`); + +ALTER TABLE `users` + ADD COLUMN `active` tinyint(1) DEFAULT '0'; + +ALTER TABLE `users` + ADD COLUMN IF NOT EXISTS `active` tinyint(1) DEFAULT '0'; + +ALTER TABLE `foo` ADD `bar` INT FIRST; + +ALTER TABLE `foo` ADD COLUMN d INT GENERATED ALWAYS AS (a*abs(b)) VIRTUAL; + +ALTER TABLE `foo` ADD COLUMN e TEXT GENERATED ALWAYS AS (substr(c,b,b+1)) STORED; + +ALTER TABLE `foo` ADD COLUMN d INT AS (a*abs(b)); + +ALTER TABLE `foo` ADD COLUMN e TEXT AS (substr(c,b,b+1)) STORED; + +ALTER TABLE `foo` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +ALTER TABLE `foo` CONVERT TO CHARACTER SET `utf8mb4` COLLATE `utf8mb4_unicode_ci`; + +ALTER TABLE `foo` CONVERT TO CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci'; + +ALTER TABLE `foo` CONVERT TO CHARACTER SET "utf8mb4" COLLATE "utf8mb4_unicode_ci"; + +ALTER TABLE CUST TRUNCATE PARTITION data_dt; + +ALTER TABLE `foo` ADD COLUMN geo GEOMETRY NOT NULL SRID 4326; + +ALTER TABLE my_table MODIFY num INT SIGNED NOT NULL; + +ALTER TABLE my_table MODIFY num INT UNSIGNED NOT NULL; + +ALTER TABLE my_table MODIFY num INT ZEROFILL NOT NULL; + +ALTER TABLE my_table MODIFY num INT UNSIGNED ZEROFILL NOT NULL; + +ALTER TABLE my_table MODIFY num INT ZEROFILL UNSIGNED NOT NULL; + +ALTER TABLE T ALTER C DROP DEFAULT; + +ALTER TABLE T ALTER C SET DEFAULT 'some default'; + +ALTER TABLE T ALTER C SET DEFAULT CURRENT_TIMESTAMP; + +ALTER TABLE T ALTER C SET INVISIBLE; + +ALTER TABLE T ALTER C SET VISIBLE; + +ALTER TABLE T ALTER C SET VISIBLE DROP DEFAULT; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_table.yml new file mode 100644 index 000000000..be1c6b599 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_table.yml @@ -0,0 +1,940 @@ +file: +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`users`' + - keyword: MODIFY + - keyword: COLUMN + - column_definition: + - quoted_identifier: '`name`' + - data_type: + - data_type_identifier: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - parameter: COMMENT + - quoted_literal: '"name of user"' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`users`' + - keyword: MODIFY + - column_definition: + - quoted_identifier: '`name`' + - data_type: + - data_type_identifier: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - keyword: FIRST +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`users`' + - keyword: RENAME + - keyword: TO + - table_reference: + - quoted_identifier: '`user`' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`user`' + - keyword: RENAME + - keyword: AS + - table_reference: + - quoted_identifier: '`users`' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`users`' + - keyword: RENAME + - table_reference: + - quoted_identifier: '`user`' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`users`' + - keyword: RENAME + - keyword: COLUMN + - column_reference: + - quoted_identifier: '`col_1`' + - keyword: TO + - column_reference: + - quoted_identifier: '`del_col_1`' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`users`' + - keyword: CHANGE + - keyword: COLUMN + - column_reference: + - quoted_identifier: '`birthday`' + - column_definition: + - quoted_identifier: '`date_of_birth`' + - data_type: + - data_type_identifier: INT + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - null_literal: 'NULL' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`users`' + - keyword: CHANGE + - keyword: COLUMN + - column_reference: + - quoted_identifier: '`birthday`' + - column_definition: + - quoted_identifier: '`date_of_birth`' + - data_type: + - data_type_identifier: INT + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`users`' + - keyword: CHANGE + - keyword: COLUMN + - column_reference: + - quoted_identifier: '`birthday`' + - column_definition: + - quoted_identifier: '`date_of_birth`' + - data_type: + - data_type_identifier: INT + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - end_bracket: ) + - keyword: FIRST +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`users`' + - keyword: CHANGE + - keyword: COLUMN + - column_reference: + - quoted_identifier: '`birthday`' + - column_definition: + - quoted_identifier: '`date_of_birth`' + - data_type: + - data_type_identifier: INT + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - end_bracket: ) + - keyword: AFTER + - column_reference: + - quoted_identifier: '`name`' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`users`' + - keyword: DROP + - keyword: COLUMN + - column_reference: + - quoted_identifier: '`age`' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - dot: . + - quoted_identifier: '`bar`' + - keyword: ADD + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - quoted_identifier: '`index_name`' + - keyword: UNIQUE + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '`col_1`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_2`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_3`' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - dot: . + - quoted_identifier: '`bar`' + - keyword: ADD + - table_constraint: + - keyword: UNIQUE + - index_reference: + - quoted_identifier: '`index_name`' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '`col_1`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_2`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_3`' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - dot: . + - quoted_identifier: '`bar`' + - keyword: ADD + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - quoted_identifier: '`index_name`' + - keyword: UNIQUE + - keyword: INDEX + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '`col_1`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_2`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_3`' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - dot: . + - quoted_identifier: '`bar`' + - keyword: ADD + - table_constraint: + - keyword: UNIQUE + - keyword: INDEX + - index_reference: + - quoted_identifier: '`index_name`' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '`col_1`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_2`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_3`' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - dot: . + - quoted_identifier: '`bar`' + - keyword: ADD + - table_constraint: + - keyword: INDEX + - index_reference: + - quoted_identifier: '`index_name`' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '`col_1`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_2`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_3`' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - dot: . + - quoted_identifier: '`bar`' + - keyword: ADD + - table_constraint: + - keyword: INDEX + - index_reference: + - quoted_identifier: '`index_name`' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '`col_1`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_2`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_3`' + - end_bracket: ) + - index_option: + - keyword: KEY_BLOCK_SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '8' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - dot: . + - quoted_identifier: '`bar`' + - keyword: ADD + - table_constraint: + - keyword: INDEX + - index_reference: + - quoted_identifier: '`index_name`' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '`col_1`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_2`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_3`' + - end_bracket: ) + - index_option: + - keyword: KEY_BLOCK_SIZE + - numeric_literal: '8' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - dot: . + - quoted_identifier: '`bar`' + - keyword: ADD + - table_constraint: + - keyword: INDEX + - index_reference: + - quoted_identifier: '`index_name`' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '`col_1`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_2`' + - comma: ',' + - column_reference: + - quoted_identifier: '`col_3`' + - end_bracket: ) + - index_option: + - keyword: KEY_BLOCK_SIZE + - numeric_literal: '8' + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''index for col_1, col_2, col_3''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - dot: . + - quoted_identifier: '`bar`' + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`index_name`' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - dot: . + - quoted_identifier: '`bar`' + - keyword: RENAME + - keyword: INDEX + - index_reference: + - quoted_identifier: '`index_name`' + - keyword: to + - index_reference: + - quoted_identifier: '`new_index_name`' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - dot: . + - quoted_identifier: '`bar`' + - keyword: RENAME + - keyword: KEY + - index_reference: + - quoted_identifier: '`key_name`' + - keyword: to + - index_reference: + - quoted_identifier: '`new_key_name`' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`x`' + - keyword: ADD + - table_constraint: + - keyword: CONSTRAINT + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '`xk`' + - end_bracket: ) + - keyword: REFERENCES + - column_reference: + - quoted_identifier: '`y`' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '`yk`' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`users`' + - keyword: ADD + - keyword: COLUMN + - column_definition: + - quoted_identifier: '`active`' + - data_type: + - data_type_identifier: tinyint + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - end_bracket: ) + - column_constraint_segment: + - keyword: DEFAULT + - quoted_literal: '''0''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`users`' + - keyword: ADD + - keyword: COLUMN + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - column_definition: + - quoted_identifier: '`active`' + - data_type: + - data_type_identifier: tinyint + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - end_bracket: ) + - column_constraint_segment: + - keyword: DEFAULT + - quoted_literal: '''0''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - keyword: ADD + - column_definition: + - quoted_identifier: '`bar`' + - data_type: + - data_type_identifier: INT + - keyword: FIRST +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: d + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: a + - binary_operator: '*' + - function: + - function_name: + - function_name_identifier: abs + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - end_bracket: ) + - end_bracket: ) + - keyword: VIRTUAL +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: e + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: substr + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c + - comma: ',' + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - column_reference: + - naked_identifier: b + - binary_operator: + + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - keyword: STORED +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: d + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: a + - binary_operator: '*' + - function: + - function_name: + - function_name_identifier: abs + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: e + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: substr + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c + - comma: ',' + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - column_reference: + - naked_identifier: b + - binary_operator: + + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - keyword: STORED +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - keyword: CONVERT + - keyword: TO + - alter_option_segment: + - keyword: CHARACTER + - keyword: SET + - naked_identifier: utf8mb4 + - alter_option_segment: + - keyword: COLLATE + - collation_reference: + - naked_identifier: utf8mb4_unicode_ci +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - keyword: CONVERT + - keyword: TO + - alter_option_segment: + - keyword: CHARACTER + - keyword: SET + - quoted_identifier: '`utf8mb4`' + - alter_option_segment: + - keyword: COLLATE + - collation_reference: + - quoted_identifier: '`utf8mb4_unicode_ci`' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - keyword: CONVERT + - keyword: TO + - alter_option_segment: + - keyword: CHARACTER + - keyword: SET + - quoted_identifier: '''utf8mb4''' + - alter_option_segment: + - keyword: COLLATE + - collation_reference: + - quoted_literal: '''utf8mb4_unicode_ci''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - keyword: CONVERT + - keyword: TO + - alter_option_segment: + - keyword: CHARACTER + - keyword: SET + - quoted_identifier: '"utf8mb4"' + - alter_option_segment: + - keyword: COLLATE + - collation_reference: + - quoted_literal: '"utf8mb4_unicode_ci"' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: CUST + - keyword: TRUNCATE + - keyword: PARTITION + - naked_identifier: data_dt +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: geo + - data_type: + - data_type_identifier: GEOMETRY + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: SRID + - numeric_literal: '4326' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: MODIFY + - column_definition: + - naked_identifier: num + - data_type: + - data_type_identifier: INT + - keyword: SIGNED + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: MODIFY + - column_definition: + - naked_identifier: num + - data_type: + - data_type_identifier: INT + - keyword: UNSIGNED + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: MODIFY + - column_definition: + - naked_identifier: num + - data_type: + - data_type_identifier: INT + - keyword: ZEROFILL + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: MODIFY + - column_definition: + - naked_identifier: num + - data_type: + - data_type_identifier: INT + - keyword: UNSIGNED + - keyword: ZEROFILL + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: MODIFY + - column_definition: + - naked_identifier: num + - data_type: + - data_type_identifier: INT + - keyword: ZEROFILL + - keyword: UNSIGNED + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: T + - keyword: ALTER + - naked_identifier: C + - keyword: DROP + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: T + - keyword: ALTER + - naked_identifier: C + - keyword: SET + - keyword: DEFAULT + - quoted_literal: '''some default''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: T + - keyword: ALTER + - naked_identifier: C + - keyword: SET + - keyword: DEFAULT + - expression: + - bare_function: CURRENT_TIMESTAMP +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: T + - keyword: ALTER + - naked_identifier: C + - keyword: SET + - keyword: INVISIBLE +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: T + - keyword: ALTER + - naked_identifier: C + - keyword: SET + - keyword: VISIBLE +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: T + - keyword: ALTER + - naked_identifier: C + - keyword: SET + - keyword: VISIBLE + - keyword: DROP + - keyword: DEFAULT +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_view.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_view.sql new file mode 100644 index 000000000..8f8e674e7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_view.sql @@ -0,0 +1,15 @@ +ALTER VIEW v2 AS +SELECT c, d FROM v1; + +ALTER VIEW v2 AS +(SELECT c, d FROM v1); + +ALTER VIEW v1 (c,d) AS +SELECT a,max(b) FROM t1 GROUP BY a; + +ALTER VIEW v2 AS +SELECT * FROM t2 WHERE s1 IN (SELECT s1 FROM t1) +WITH CHECK OPTION; + +ALTER VIEW v2 AS +SELECT 1 UNION SELECT 2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_view.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_view.yml new file mode 100644 index 000000000..4c57d3480 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/alter_view.yml @@ -0,0 +1,169 @@ +file: +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v2 + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: d + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: v1 +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v2 + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: d + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: v1 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c + - comma: ',' + - column_reference: + - naked_identifier: d + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: max + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: a +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v2 + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: s1 + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: s1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - end_bracket: ) + - with_check_options: + - keyword: WITH + - keyword: CHECK + - keyword: OPTION +- statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: v2 + - keyword: AS + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - set_operator: + - keyword: UNION + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/analyze_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/analyze_table.sql new file mode 100644 index 000000000..cd38b8296 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/analyze_table.sql @@ -0,0 +1,39 @@ +ANALYZE TABLE some_table; + +ANALYZE TABLE some_table1, some_table2; + +ANALYZE NO_WRITE_TO_BINLOG TABLE some_table; + +ANALYZE NO_WRITE_TO_BINLOG TABLE some_table1, some_table2; + +ANALYZE LOCAL TABLE some_table; + +ANALYZE LOCAL TABLE some_table1, some_table2; + +ANALYZE TABLE some_table UPDATE HISTOGRAM ON some_col; + +ANALYZE TABLE some_table UPDATE HISTOGRAM ON some_col1, some_col2; + +ANALYZE NO_WRITE_TO_BINLOG TABLE some_table UPDATE HISTOGRAM ON some_col; + +ANALYZE NO_WRITE_TO_BINLOG TABLE some_table UPDATE HISTOGRAM ON some_col1, some_col2; + +ANALYZE LOCAL TABLE some_table UPDATE HISTOGRAM ON some_col; + +ANALYZE LOCAL TABLE some_table UPDATE HISTOGRAM ON some_col1, some_col2; + +ANALYZE TABLE some_table UPDATE HISTOGRAM ON some_col WITH 10 BUCKETS; + +ANALYZE TABLE some_table UPDATE HISTOGRAM ON some_col1, some_col2 WITH 10 BUCKETS; + +ANALYZE TABLE some_table DROP HISTOGRAM ON some_col; + +ANALYZE TABLE some_table DROP HISTOGRAM ON some_col1, some_col2; + +ANALYZE NO_WRITE_TO_BINLOG TABLE some_table DROP HISTOGRAM ON some_col; + +ANALYZE NO_WRITE_TO_BINLOG TABLE some_table DROP HISTOGRAM ON some_col1, some_col2; + +ANALYZE LOCAL TABLE some_table DROP HISTOGRAM ON some_col; + +ANALYZE LOCAL TABLE some_table DROP HISTOGRAM ON some_col1, some_col2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/analyze_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/analyze_table.yml new file mode 100644 index 000000000..43ee0221f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/analyze_table.yml @@ -0,0 +1,259 @@ +file: +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col1 + - comma: ',' + - column_reference: + - naked_identifier: some_col2 +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col1 + - comma: ',' + - column_reference: + - naked_identifier: some_col2 +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col1 + - comma: ',' + - column_reference: + - naked_identifier: some_col2 +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col + - keyword: WITH + - numeric_literal: '10' + - keyword: BUCKETS +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: UPDATE + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col1 + - comma: ',' + - column_reference: + - naked_identifier: some_col2 + - keyword: WITH + - numeric_literal: '10' + - keyword: BUCKETS +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: DROP + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: DROP + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col1 + - comma: ',' + - column_reference: + - naked_identifier: some_col2 +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: DROP + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: DROP + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col1 + - comma: ',' + - column_reference: + - naked_identifier: some_col2 +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: DROP + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col +- statement_terminator: ; +- statement: + - analyze_table_statement: + - keyword: ANALYZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: DROP + - keyword: HISTOGRAM + - keyword: ON + - column_reference: + - naked_identifier: some_col1 + - comma: ',' + - column_reference: + - naked_identifier: some_col2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/begin.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/begin.sql new file mode 100644 index 000000000..221c86213 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/begin.sql @@ -0,0 +1,3 @@ +blocks:BEGIN +select 1; +END blocks~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/begin.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/begin.yml new file mode 100644 index 000000000..d7a4394df --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/begin.yml @@ -0,0 +1,18 @@ +file: +- statement: + - transaction_statement: + - naked_identifier: blocks + - colon: ':' + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END + - naked_identifier: blocks +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/bit_value_literal.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/bit_value_literal.sql new file mode 100644 index 000000000..1e94007fd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/bit_value_literal.sql @@ -0,0 +1,3 @@ +SELECT b'01'; +SELECT B'01'; +SELECT 0b01; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/bit_value_literal.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/bit_value_literal.yml new file mode 100644 index 000000000..90f3f3c3d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/bit_value_literal.yml @@ -0,0 +1,22 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: b'01' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: B'01' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '0b01' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/call_statement.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/call_statement.sql new file mode 100644 index 000000000..cc85e93c7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/call_statement.sql @@ -0,0 +1,6 @@ +CALL somefunction('a'); +CALL somefunction(test('something')); +CALL somefunction('test', @test1, test2, test3('test'), "test4"); +CALL somefunction(); +CALL `somefunction`('a'); +CALL testdb.testfunc(123); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/call_statement.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/call_statement.yml new file mode 100644 index 000000000..6436cfb83 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/call_statement.yml @@ -0,0 +1,108 @@ +file: +- statement: + - call_statement: + - keyword: CALL + - function: + - function_name: + - function_name_identifier: somefunction + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''a''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - call_statement: + - keyword: CALL + - function: + - function_name: + - function_name_identifier: somefunction + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: test + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''something''' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - call_statement: + - keyword: CALL + - function: + - function_name: + - function_name_identifier: somefunction + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''test''' + - comma: ',' + - expression: + - variable: '@test1' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: test2 + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: test3 + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''test''' + - end_bracket: ) + - comma: ',' + - expression: + - quoted_literal: '"test4"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - call_statement: + - keyword: CALL + - function: + - function_name: + - function_name_identifier: somefunction + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) +- statement_terminator: ; +- statement: + - call_statement: + - keyword: CALL + - function: + - function_name: + - quoted_identifier: '`somefunction`' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''a''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - call_statement: + - keyword: CALL + - function: + - function_name: + - naked_identifier: testdb + - dot: . + - function_name_identifier: testfunc + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '123' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_constraint.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_constraint.sql new file mode 100644 index 000000000..ba42f8ed8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_constraint.sql @@ -0,0 +1,15 @@ +CREATE TABLE t1 +( + CHECK (c1 <> c2), + c1 INT CHECK (c1 > 10), + c2 INT CONSTRAINT c2_positive CHECK (c2 > 0), + c3 INT CHECK (c3 < 100), + CONSTRAINT c1_nonzero CHECK (c1 <> 0), + CHECK (c1 > c3) +); + +ALTER TABLE t1 +ALTER CHECK c2_positive NOT ENFORCED; + +ALTER TABLE t1 +DROP CONSTRAINT c1_nonzero; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_constraint.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_constraint.yml new file mode 100644 index 000000000..3ac46b8da --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_constraint.yml @@ -0,0 +1,128 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - table_constraint: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c1 + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: '>' + - column_reference: + - naked_identifier: c2 + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: c1 + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c1 + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '10' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: c2 + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: c2_positive + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c2 + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: c3 + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c3 + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: c1_nonzero + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c1 + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: '>' + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c1 + - comparison_operator: + - raw_comparison_operator: '>' + - column_reference: + - naked_identifier: c3 + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: ALTER + - keyword: CHECK + - object_reference: + - naked_identifier: c2_positive + - keyword: NOT + - keyword: ENFORCED +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: DROP + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: c1_nonzero +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_table.sql new file mode 100644 index 000000000..1d02e57ad --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_table.sql @@ -0,0 +1,25 @@ +CHECK TABLE some_table FOR UPGRADE; + +CHECK TABLE some_table1, some_table2 FOR UPGRADE; + +CHECK TABLE some_table QUICK; + +CHECK TABLE some_table1, some_table2 QUICK; + +CHECK TABLE some_table FAST; + +CHECK TABLE some_table1, some_table2 FAST; + +CHECK TABLE some_table MEDIUM; + +CHECK TABLE some_table1, some_table2 MEDIUM; + +CHECK TABLE some_table EXTENDED; + +CHECK TABLE some_table1, some_table2 EXTENDED; + +CHECK TABLE some_table CHANGED; + +CHECK TABLE some_table1, some_table2 CHANGED; + +CHECK TABLE some_table FAST QUICK; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_table.yml new file mode 100644 index 000000000..89f062033 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/check_table.yml @@ -0,0 +1,126 @@ +file: +- statement: + - check_table_statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: FOR + - keyword: UPGRADE +- statement_terminator: ; +- statement: + - check_table_statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: FOR + - keyword: UPGRADE +- statement_terminator: ; +- statement: + - check_table_statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: QUICK +- statement_terminator: ; +- statement: + - check_table_statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: QUICK +- statement_terminator: ; +- statement: + - check_table_statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: FAST +- statement_terminator: ; +- statement: + - check_table_statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: FAST +- statement_terminator: ; +- statement: + - check_table_statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: MEDIUM +- statement_terminator: ; +- statement: + - check_table_statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: MEDIUM +- statement_terminator: ; +- statement: + - check_table_statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: EXTENDED +- statement_terminator: ; +- statement: + - check_table_statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: EXTENDED +- statement_terminator: ; +- statement: + - check_table_statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: CHANGED +- statement_terminator: ; +- statement: + - check_table_statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: CHANGED +- statement_terminator: ; +- statement: + - check_table_statement: + - keyword: CHECK + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: FAST + - keyword: QUICK +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/checksum_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/checksum_table.sql new file mode 100644 index 000000000..d0bd37b50 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/checksum_table.sql @@ -0,0 +1,7 @@ +CHECKSUM TABLE some_table QUICK; + +CHECKSUM TABLE some_table1, some_table2 QUICK; + +CHECKSUM TABLE some_table EXTENDED; + +CHECKSUM TABLE some_table1, some_table2 EXTENDED; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/checksum_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/checksum_table.yml new file mode 100644 index 000000000..0664595c5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/checksum_table.yml @@ -0,0 +1,39 @@ +file: +- statement: + - checksum_table_statement: + - keyword: CHECKSUM + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: QUICK +- statement_terminator: ; +- statement: + - checksum_table_statement: + - keyword: CHECKSUM + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: QUICK +- statement_terminator: ; +- statement: + - checksum_table_statement: + - keyword: CHECKSUM + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: EXTENDED +- statement_terminator: ; +- statement: + - checksum_table_statement: + - keyword: CHECKSUM + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 + - keyword: EXTENDED +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close.sql new file mode 100644 index 000000000..3f1510e77 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close.sql @@ -0,0 +1 @@ +CLOSE curcursor; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close.yml new file mode 100644 index 000000000..ca60364d3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close.yml @@ -0,0 +1,6 @@ +file: +- statement: + - cursor_open_close_segment: + - keyword: CLOSE + - naked_identifier: curcursor +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close_qualified.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close_qualified.sql new file mode 100644 index 000000000..281dac8fe --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close_qualified.sql @@ -0,0 +1 @@ +CLOSE `curcursor`; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close_qualified.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close_qualified.yml new file mode 100644 index 000000000..540b07bbb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/close_qualified.yml @@ -0,0 +1,6 @@ +file: +- statement: + - cursor_open_close_segment: + - keyword: CLOSE + - quoted_identifier: '`curcursor`' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/collate.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/collate.sql new file mode 100644 index 000000000..5c12a0284 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/collate.sql @@ -0,0 +1 @@ +SELECT "a string" COLLATE "utf8mb4_general_ci"; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/collate.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/collate.yml new file mode 100644 index 000000000..cb3893812 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/collate.yml @@ -0,0 +1,12 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '"a string"' + - keyword: COLLATE + - collation_reference: + - quoted_literal: '"utf8mb4_general_ci"' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/column_alias.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/column_alias.sql new file mode 100644 index 000000000..55d384371 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/column_alias.sql @@ -0,0 +1,4 @@ +SELECT 1 AS `one`; +SELECT 2 AS 'two'; +SELECT 3 AS "three"; +SELECT 4 AS "four""_with_escaped_double_quotes"; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/column_alias.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/column_alias.yml new file mode 100644 index 000000000..233826906 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/column_alias.yml @@ -0,0 +1,45 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`one`' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '''two''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '3' + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '"three"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '4' + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '"four""_with_escaped_double_quotes"' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_database.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_database.sql new file mode 100644 index 000000000..5831b2456 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_database.sql @@ -0,0 +1,20 @@ +CREATE DATABASE my_database; + +CREATE DATABASE IF NOT EXISTS my_database; + +CREATE DATABASE my_database +DEFAULT CHARACTER SET utf8mb4 +COLLATE utf8mb4_0900_ai_ci +DEFAULT ENCRYPTION 'N'; + +CREATE DATABASE my_database +DEFAULT CHARACTER SET = utf8mb4 +COLLATE = utf8mb4_0900_ai_ci +DEFAULT ENCRYPTION = 'N'; + +CREATE SCHEMA my_database +DEFAULT CHARACTER SET utf8mb4 +COLLATE utf8mb4_0900_ai_ci +DEFAULT ENCRYPTION 'N'; + +CREATE DATABASE IF NOT EXISTS xxx CHARACTER SET "utf8mb4" COLLATE "utf8mb4_bin"; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_database.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_database.yml new file mode 100644 index 000000000..c0c8a4f3a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_database.yml @@ -0,0 +1,102 @@ +file: +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - database_reference: + - naked_identifier: my_database +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database + - create_option_segment: + - keyword: DEFAULT + - keyword: CHARACTER + - keyword: SET + - naked_identifier: utf8mb4 + - create_option_segment: + - keyword: COLLATE + - collation_reference: + - naked_identifier: utf8mb4_0900_ai_ci + - create_option_segment: + - keyword: DEFAULT + - keyword: ENCRYPTION + - quoted_literal: '''N''' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: my_database + - create_option_segment: + - keyword: DEFAULT + - keyword: CHARACTER + - keyword: SET + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: utf8mb4 + - create_option_segment: + - keyword: COLLATE + - comparison_operator: + - raw_comparison_operator: = + - collation_reference: + - naked_identifier: utf8mb4_0900_ai_ci + - create_option_segment: + - keyword: DEFAULT + - keyword: ENCRYPTION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''N''' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: SCHEMA + - database_reference: + - naked_identifier: my_database + - create_option_segment: + - keyword: DEFAULT + - keyword: CHARACTER + - keyword: SET + - naked_identifier: utf8mb4 + - create_option_segment: + - keyword: COLLATE + - collation_reference: + - naked_identifier: utf8mb4_0900_ai_ci + - create_option_segment: + - keyword: DEFAULT + - keyword: ENCRYPTION + - quoted_literal: '''N''' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - database_reference: + - naked_identifier: xxx + - create_option_segment: + - keyword: CHARACTER + - keyword: SET + - quoted_literal: '"utf8mb4"' + - create_option_segment: + - keyword: COLLATE + - collation_reference: + - quoted_literal: '"utf8mb4_bin"' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_event.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_event.sql new file mode 100644 index 000000000..e630bd02c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_event.sql @@ -0,0 +1,40 @@ +CREATE EVENT myevent + ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR + DO + UPDATE myschema.mytable SET mycol = mycol + 1; + +CREATE EVENT e_totals + ON SCHEDULE AT '2006-02-10 23:59:00' + DO INSERT INTO test.totals VALUES (NOW()); + +CREATE EVENT e_hourly + ON SCHEDULE + EVERY 1 HOUR + COMMENT 'Clears out sessions table each hour.' + DO + DELETE FROM site_activity.sessions; + +CREATE EVENT e_daily + ON SCHEDULE + EVERY 1 DAY + COMMENT 'Saves total number of sessions then clears the table each day' + DO + BEGIN + INSERT INTO site_activity.totals (time, total) + SELECT CURRENT_TIMESTAMP, COUNT(*) + FROM site_activity.sessions; + DELETE FROM site_activity.sessions; + END; + +CREATE EVENT e_call_myproc + ON SCHEDULE + AT CURRENT_TIMESTAMP + INTERVAL 1 DAY + DO CALL myproc(5, 27); + +CREATE EVENT e + ON SCHEDULE EVERY interval SECOND + STARTS CURRENT_TIMESTAMP + INTERVAL 10 SECOND + ENDS CURRENT_TIMESTAMP + INTERVAL 2 MINUTE + ON COMPLETION PRESERVE + DO + INSERT INTO d.t1 VALUES ROW(NULL, NOW(), FLOOR(RAND()*100)); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_event.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_event.yml new file mode 100644 index 000000000..dff1ab2e8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_event.yml @@ -0,0 +1,292 @@ +file: +- statement: + - create_event_statement: + - keyword: CREATE + - keyword: EVENT + - object_reference: + - naked_identifier: myevent + - keyword: ON + - keyword: SCHEDULE + - keyword: AT + - expression: + - bare_function: CURRENT_TIMESTAMP + - binary_operator: + + - interval_expression: + - keyword: INTERVAL + - expression: + - numeric_literal: '1' + - date_part: HOUR + - keyword: DO + - statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: myschema + - dot: . + - naked_identifier: mytable + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: mycol + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: mycol + - binary_operator: + + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - create_event_statement: + - keyword: CREATE + - keyword: EVENT + - object_reference: + - naked_identifier: e_totals + - keyword: ON + - keyword: SCHEDULE + - keyword: AT + - expression: + - quoted_literal: '''2006-02-10 23:59:00''' + - keyword: DO + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: test + - dot: . + - naked_identifier: totals + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: NOW + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_event_statement: + - keyword: CREATE + - keyword: EVENT + - object_reference: + - naked_identifier: e_hourly + - keyword: ON + - keyword: SCHEDULE + - keyword: EVERY + - expression: + - numeric_literal: '1' + - date_part: HOUR + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''Clears out sessions table each hour.''' + - keyword: DO + - statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: site_activity + - dot: . + - naked_identifier: sessions +- statement_terminator: ; +- statement: + - create_event_statement: + - keyword: CREATE + - keyword: EVENT + - object_reference: + - naked_identifier: e_daily + - keyword: ON + - keyword: SCHEDULE + - keyword: EVERY + - expression: + - numeric_literal: '1' + - date_part: DAY + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''Saves total number of sessions then clears the table each day''' + - keyword: DO + - statement: + - transaction_statement: + - keyword: BEGIN + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: site_activity + - dot: . + - naked_identifier: totals + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: time + - comma: ',' + - column_reference: + - naked_identifier: total + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - bare_function: CURRENT_TIMESTAMP + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: COUNT + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: site_activity + - dot: . + - naked_identifier: sessions +- statement_terminator: ; +- statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: site_activity + - dot: . + - naked_identifier: sessions +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END +- statement_terminator: ; +- statement: + - create_event_statement: + - keyword: CREATE + - keyword: EVENT + - object_reference: + - naked_identifier: e_call_myproc + - keyword: ON + - keyword: SCHEDULE + - keyword: AT + - expression: + - bare_function: CURRENT_TIMESTAMP + - binary_operator: + + - interval_expression: + - keyword: INTERVAL + - expression: + - numeric_literal: '1' + - date_part: DAY + - keyword: DO + - statement: + - call_statement: + - keyword: CALL + - function: + - function_name: + - function_name_identifier: myproc + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '5' + - comma: ',' + - expression: + - numeric_literal: '27' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_event_statement: + - keyword: CREATE + - keyword: EVENT + - object_reference: + - naked_identifier: e + - keyword: ON + - keyword: SCHEDULE + - keyword: EVERY + - expression: + - interval_expression: + - keyword: interval + - date_part: SECOND + - keyword: STARTS + - expression: + - bare_function: CURRENT_TIMESTAMP + - binary_operator: + + - interval_expression: + - keyword: INTERVAL + - expression: + - numeric_literal: '10' + - date_part: SECOND + - keyword: ENDS + - expression: + - bare_function: CURRENT_TIMESTAMP + - binary_operator: + + - interval_expression: + - keyword: INTERVAL + - expression: + - numeric_literal: '2' + - date_part: MINUTE + - keyword: ON + - keyword: COMPLETION + - keyword: PRESERVE + - keyword: DO + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: d + - dot: . + - naked_identifier: t1 + - values_clause: + - keyword: VALUES + - keyword: ROW + - bracketed: + - start_bracket: ( + - null_literal: 'NULL' + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: NOW + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: FLOOR + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: RAND + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - binary_operator: '*' + - numeric_literal: '100' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_index.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_index.sql new file mode 100644 index 000000000..ecfe09891 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_index.sql @@ -0,0 +1,14 @@ +CREATE INDEX idx ON tbl (col); +CREATE UNIQUE INDEX idx ON tbl (col); +CREATE FULLTEXT INDEX idx ON tbl (col); +CREATE SPATIAL INDEX idx ON tbl (col); +CREATE INDEX idx USING BTREE ON tbl (col); +CREATE INDEX idx USING HASH ON tbl (col); +CREATE INDEX idx ON tbl (col ASC); +CREATE INDEX idx ON tbl (col DESC); +CREATE INDEX part_of_name ON customer (name(10)); +CREATE INDEX idx ON tbl (col) ALGORITHM DEFAULT; +CREATE INDEX idx ON tbl (col) ALGORITHM NOCOPY; +CREATE INDEX idx ON tbl (col) ALGORITHM INSTANT; +CREATE INDEX idx ON tbl (col) LOCK DEFAULT; +CREATE INDEX idx ON tbl ((col1 + col2), (col1 - col2), col1); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_index.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_index.yml new file mode 100644 index 000000000..0220bcf87 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_index.yml @@ -0,0 +1,254 @@ +file: +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: INDEX + - index_reference: + - naked_identifier: idx + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: UNIQUE + - keyword: INDEX + - index_reference: + - naked_identifier: idx + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - index_reference: + - naked_identifier: idx + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: SPATIAL + - keyword: INDEX + - index_reference: + - naked_identifier: idx + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: INDEX + - index_reference: + - naked_identifier: idx + - index_type: + - keyword: USING + - keyword: BTREE + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: INDEX + - index_reference: + - naked_identifier: idx + - index_type: + - keyword: USING + - keyword: HASH + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: INDEX + - index_reference: + - naked_identifier: idx + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - keyword: ASC + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: INDEX + - index_reference: + - naked_identifier: idx + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - keyword: DESC + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: INDEX + - index_reference: + - naked_identifier: part_of_name + - keyword: ON + - table_reference: + - naked_identifier: customer + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: name + - bracketed: + - start_bracket: ( + - numeric_literal: '10' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: INDEX + - index_reference: + - naked_identifier: idx + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - end_bracket: ) + - keyword: ALGORITHM + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: INDEX + - index_reference: + - naked_identifier: idx + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - end_bracket: ) + - keyword: ALGORITHM + - keyword: NOCOPY +- statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: INDEX + - index_reference: + - naked_identifier: idx + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - end_bracket: ) + - keyword: ALGORITHM + - keyword: INSTANT +- statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: INDEX + - index_reference: + - naked_identifier: idx + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - end_bracket: ) + - keyword: LOCK + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: INDEX + - index_reference: + - naked_identifier: idx + - keyword: ON + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col1 + - binary_operator: + + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col1 + - binary_operator: '-' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - comma: ',' + - column_reference: + - naked_identifier: col1 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_procedure.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_procedure.sql new file mode 100644 index 000000000..1e058965a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_procedure.sql @@ -0,0 +1,4 @@ +CREATE PROCEDURE IF NOT EXISTS create_if_not_exists() +BEGIN + SELECT 1; +END; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_procedure.yml new file mode 100644 index 000000000..4c6490a42 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_procedure.yml @@ -0,0 +1,28 @@ +file: +- statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - function_name: + - function_name_identifier: create_if_not_exists + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_role.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_role.sql new file mode 100644 index 000000000..e00c1ec17 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_role.sql @@ -0,0 +1 @@ +CREATE ROLE IF NOT EXISTS 'example-role'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_role.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_role.yml new file mode 100644 index 000000000..838baf913 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_role.yml @@ -0,0 +1,11 @@ +file: +- statement: + - create_role_statement: + - keyword: CREATE + - keyword: ROLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - role_reference: + - quoted_identifier: '''example-role''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table.sql new file mode 100644 index 000000000..b9a002721 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table.sql @@ -0,0 +1,73 @@ +CREATE TABLE `foo` ( + b VARCHAR(255) BINARY, + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +CREATE TABLE `foo` ( + b VARCHAR(255) BINARY, + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=`utf8mb4` COLLATE=`utf8mb4_unicode_ci`; + +CREATE TABLE `foo` ( + b VARCHAR(255) BINARY, + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET='utf8mb4' COLLATE='utf8mb4_unicode_ci'; + +CREATE TABLE `foo` ( + b VARCHAR(255) BINARY, + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET="utf8mb4" COLLATE="utf8mb4_unicode_ci"; + +create table `tickets` ( + `id` serial primary key, + `material_number` varchar(255) default null, + `material_name` varchar(255) default null, + `date_created` date not null default (current_date), + `date_closed` date default null +); + +create table _ (a int); + +CREATE TABLE foo SELECT * FROM bar; + +CREATE TEMPORARY TABLE tbl_name ( + id INT PRIMARY KEY AUTO_INCREMENT, + col VARCHAR(255) DEFAULT '' NOT NULL, + INDEX(col) +) AS SELECT id, col FROM table_name; + +CREATE TEMPORARY TABLE tbl_name ( + id INT PRIMARY KEY AUTO_INCREMENT, + col VARCHAR(255) DEFAULT '' NOT NULL, + INDEX(col) +) SELECT id, col FROM table_name; + +CREATE TEMPORARY TABLE tbl_name (INDEX(col)) AS + SELECT id, col FROM table_name; + +CREATE TEMPORARY TABLE tbl_name (INDEX(col)) + SELECT id, col FROM table_name; + +CREATE TABLE geom ( + p POINT SRID 0, + g GEOMETRY NOT NULL SRID 4326 +); + +CREATE TABLE my_table (num INT(5) SIGNED); + +CREATE TABLE my_table (num INT(5) UNSIGNED); + +CREATE TABLE my_table (num INT(5) ZEROFILL); + +CREATE TABLE my_table (num INT(5) UNSIGNED ZEROFILL); + +CREATE TABLE my_table (num INT(5) ZEROFILL UNSIGNED); + +CREATE TABLE t1 ( + i INT VISIBLE, + j DATE INVISIBLE +) ENGINE = InnoDB; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table.yml new file mode 100644 index 000000000..cd9a2c03e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table.yml @@ -0,0 +1,684 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: b + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - keyword: BINARY + - comma: ',' + - column_definition: + - quoted_identifier: '`id`' + - data_type: + - data_type_identifier: int + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - end_bracket: ) + - keyword: unsigned + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: AUTO_INCREMENT + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '`id`' + - end_bracket: ) + - end_bracket: ) + - parameter: ENGINE + - comparison_operator: + - raw_comparison_operator: = + - parameter: InnoDB + - keyword: DEFAULT + - parameter: CHARSET + - comparison_operator: + - raw_comparison_operator: = + - parameter: utf8mb4 + - parameter: COLLATE + - comparison_operator: + - raw_comparison_operator: = + - parameter: utf8mb4_unicode_ci +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: b + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - keyword: BINARY + - comma: ',' + - column_definition: + - quoted_identifier: '`id`' + - data_type: + - data_type_identifier: int + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - end_bracket: ) + - keyword: unsigned + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: AUTO_INCREMENT + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '`id`' + - end_bracket: ) + - end_bracket: ) + - parameter: ENGINE + - comparison_operator: + - raw_comparison_operator: = + - parameter: InnoDB + - keyword: DEFAULT + - parameter: CHARSET + - comparison_operator: + - raw_comparison_operator: = + - parameter: '`utf8mb4`' + - parameter: COLLATE + - comparison_operator: + - raw_comparison_operator: = + - parameter: '`utf8mb4_unicode_ci`' +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: b + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - keyword: BINARY + - comma: ',' + - column_definition: + - quoted_identifier: '`id`' + - data_type: + - data_type_identifier: int + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - end_bracket: ) + - keyword: unsigned + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: AUTO_INCREMENT + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '`id`' + - end_bracket: ) + - end_bracket: ) + - parameter: ENGINE + - comparison_operator: + - raw_comparison_operator: = + - parameter: InnoDB + - keyword: DEFAULT + - parameter: CHARSET + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''utf8mb4''' + - parameter: COLLATE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''utf8mb4_unicode_ci''' +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: b + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - keyword: BINARY + - comma: ',' + - column_definition: + - quoted_identifier: '`id`' + - data_type: + - data_type_identifier: int + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - end_bracket: ) + - keyword: unsigned + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: AUTO_INCREMENT + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '`id`' + - end_bracket: ) + - end_bracket: ) + - parameter: ENGINE + - comparison_operator: + - raw_comparison_operator: = + - parameter: InnoDB + - keyword: DEFAULT + - parameter: CHARSET + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"utf8mb4"' + - parameter: COLLATE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"utf8mb4_unicode_ci"' +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: create + - keyword: table + - table_reference: + - quoted_identifier: '`tickets`' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '`id`' + - data_type: + - data_type_identifier: serial + - column_constraint_segment: + - keyword: primary + - keyword: key + - comma: ',' + - column_definition: + - quoted_identifier: '`material_number`' + - data_type: + - data_type_identifier: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - column_constraint_segment: + - keyword: default + - null_literal: 'null' + - comma: ',' + - column_definition: + - quoted_identifier: '`material_name`' + - data_type: + - data_type_identifier: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - column_constraint_segment: + - keyword: default + - null_literal: 'null' + - comma: ',' + - column_definition: + - quoted_identifier: '`date_created`' + - data_type: + - data_type_identifier: date + - column_constraint_segment: + - keyword: not + - keyword: 'null' + - column_constraint_segment: + - keyword: default + - bracketed: + - start_bracket: ( + - bare_function: current_date + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '`date_closed`' + - data_type: + - data_type_identifier: date + - column_constraint_segment: + - keyword: default + - null_literal: 'null' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: create + - keyword: table + - table_reference: + - naked_identifier: _ + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: a + - data_type: + - data_type_identifier: int + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TEMPORARY + - keyword: TABLE + - table_reference: + - naked_identifier: tbl_name + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - column_constraint_segment: + - keyword: AUTO_INCREMENT + - comma: ',' + - column_definition: + - naked_identifier: col + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - column_constraint_segment: + - keyword: DEFAULT + - quoted_literal: '''''' + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - table_constraint: + - keyword: INDEX + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TEMPORARY + - keyword: TABLE + - table_reference: + - naked_identifier: tbl_name + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - column_constraint_segment: + - keyword: AUTO_INCREMENT + - comma: ',' + - column_definition: + - naked_identifier: col + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '255' + - end_bracket: ) + - column_constraint_segment: + - keyword: DEFAULT + - quoted_literal: '''''' + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - table_constraint: + - keyword: INDEX + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - end_bracket: ) + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TEMPORARY + - keyword: TABLE + - table_reference: + - naked_identifier: tbl_name + - bracketed: + - start_bracket: ( + - table_constraint: + - keyword: INDEX + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TEMPORARY + - keyword: TABLE + - table_reference: + - naked_identifier: tbl_name + - bracketed: + - start_bracket: ( + - table_constraint: + - keyword: INDEX + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col + - end_bracket: ) + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: geom + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: p + - data_type: + - data_type_identifier: POINT + - column_constraint_segment: + - keyword: SRID + - numeric_literal: '0' + - comma: ',' + - column_definition: + - naked_identifier: g + - data_type: + - data_type_identifier: GEOMETRY + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: SRID + - numeric_literal: '4326' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: num + - data_type: + - data_type_identifier: INT + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - keyword: SIGNED + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: num + - data_type: + - data_type_identifier: INT + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - keyword: UNSIGNED + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: num + - data_type: + - data_type_identifier: INT + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - keyword: ZEROFILL + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: num + - data_type: + - data_type_identifier: INT + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - keyword: UNSIGNED + - keyword: ZEROFILL + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: num + - data_type: + - data_type_identifier: INT + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - keyword: ZEROFILL + - keyword: UNSIGNED + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: i + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: VISIBLE + - comma: ',' + - column_definition: + - naked_identifier: j + - data_type: + - data_type_identifier: DATE + - column_constraint_segment: + - keyword: INVISIBLE + - end_bracket: ) + - parameter: ENGINE + - comparison_operator: + - raw_comparison_operator: = + - parameter: InnoDB +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_column_charset.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_column_charset.sql new file mode 100644 index 000000000..fdf024c84 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_column_charset.sql @@ -0,0 +1,27 @@ +CREATE TABLE t1 +( + col1 VARCHAR(5) + CHARACTER SET latin1 + COLLATE latin1_german1_ci +); + +CREATE TABLE t1 +( + col1 VARCHAR(5) + CHARACTER SET `latin1` + COLLATE `latin1_german1_ci` +); + +CREATE TABLE t1 +( + col1 VARCHAR(5) + CHARACTER SET 'latin1' + COLLATE 'latin1_german1_ci' +); + +CREATE TABLE t1 +( + col1 VARCHAR(5) + CHARACTER SET "latin1" + COLLATE "latin1_german1_ci" +); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_column_charset.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_column_charset.yml new file mode 100644 index 000000000..a8b68b22f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_column_charset.yml @@ -0,0 +1,109 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - column_constraint_segment: + - keyword: CHARACTER + - keyword: SET + - naked_identifier: latin1 + - column_constraint_segment: + - keyword: COLLATE + - collation_reference: + - naked_identifier: latin1_german1_ci + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - column_constraint_segment: + - keyword: CHARACTER + - keyword: SET + - quoted_identifier: '`latin1`' + - column_constraint_segment: + - keyword: COLLATE + - collation_reference: + - quoted_identifier: '`latin1_german1_ci`' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - column_constraint_segment: + - keyword: CHARACTER + - keyword: SET + - quoted_identifier: '''latin1''' + - column_constraint_segment: + - keyword: COLLATE + - collation_reference: + - quoted_literal: '''latin1_german1_ci''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - column_constraint_segment: + - keyword: CHARACTER + - keyword: SET + - quoted_identifier: '"latin1"' + - column_constraint_segment: + - keyword: COLLATE + - collation_reference: + - quoted_literal: '"latin1_german1_ci"' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_constraint_unique.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_constraint_unique.sql new file mode 100644 index 000000000..357b893c9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_constraint_unique.sql @@ -0,0 +1,9 @@ +CREATE TABLE a( + a INT NOT NULL, + UNIQUE (a), + UNIQUE idx_c(a), + UNIQUE KEY (a), + UNIQUE KEY idx_a(a), + UNIQUE INDEX (a), + UNIQUE INDEX idx_b(a) +) diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_constraint_unique.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_constraint_unique.yml new file mode 100644 index 000000000..97056b29c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_constraint_unique.yml @@ -0,0 +1,75 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: a + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: a + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - table_constraint: + - keyword: UNIQUE + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: UNIQUE + - index_reference: + - naked_identifier: idx_c + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: UNIQUE + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: UNIQUE + - keyword: KEY + - index_reference: + - naked_identifier: idx_a + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: UNIQUE + - keyword: INDEX + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: UNIQUE + - keyword: INDEX + - index_reference: + - naked_identifier: idx_b + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - end_bracket: ) + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_datetime.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_datetime.sql new file mode 100644 index 000000000..ee5ed35b0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_datetime.sql @@ -0,0 +1,25 @@ +CREATE TABLE `foo` ( + created_date DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, + ts1 TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + dt1 DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + ts2 TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + dt2 DATETIME DEFAULT CURRENT_TIMESTAMP, + ts3 TIMESTAMP DEFAULT 0, + dt3 DATETIME DEFAULT 0, + ts4 TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP, + dt4 DATETIME DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP, + ts5 TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- default 0 + ts6 TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP, -- default NULL + dt5 DATETIME ON UPDATE CURRENT_TIMESTAMP, -- default NULL + dt6 DATETIME NOT NULL ON UPDATE CURRENT_TIMESTAMP, -- default 0 + ts7 TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + ts8 TIMESTAMP NULL DEFAULT NULL, + ts9 TIMESTAMP NULL DEFAULT 0, + ts10 TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + ts11 TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP(), + ts12 TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00', + ts13 TIMESTAMP NULL DEFAULT NOW ON UPDATE NOW, + ts14 TIMESTAMP NULL DEFAULT NOW() ON UPDATE NOW(), + ts15 TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + ts16 TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP +) diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_datetime.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_datetime.yml new file mode 100644 index 000000000..f2549cb2a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_datetime.yml @@ -0,0 +1,215 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '`foo`' + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: created_date + - keyword: DATETIME + - keyword: DEFAULT + - keyword: CURRENT_TIMESTAMP + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: ts1 + - keyword: TIMESTAMP + - keyword: DEFAULT + - keyword: CURRENT_TIMESTAMP + - keyword: ON + - keyword: UPDATE + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: dt1 + - keyword: DATETIME + - keyword: DEFAULT + - keyword: CURRENT_TIMESTAMP + - keyword: ON + - keyword: UPDATE + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: ts2 + - keyword: TIMESTAMP + - keyword: DEFAULT + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: dt2 + - keyword: DATETIME + - keyword: DEFAULT + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: ts3 + - keyword: TIMESTAMP + - keyword: DEFAULT + - numeric_literal: '0' + - comma: ',' + - column_definition: + - naked_identifier: dt3 + - keyword: DATETIME + - keyword: DEFAULT + - numeric_literal: '0' + - comma: ',' + - column_definition: + - naked_identifier: ts4 + - keyword: TIMESTAMP + - keyword: DEFAULT + - numeric_literal: '0' + - keyword: ON + - keyword: UPDATE + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: dt4 + - keyword: DATETIME + - keyword: DEFAULT + - numeric_literal: '0' + - keyword: ON + - keyword: UPDATE + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: ts5 + - keyword: TIMESTAMP + - keyword: ON + - keyword: UPDATE + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: ts6 + - keyword: TIMESTAMP + - keyword: 'NULL' + - keyword: ON + - keyword: UPDATE + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: dt5 + - keyword: DATETIME + - keyword: ON + - keyword: UPDATE + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: dt6 + - keyword: DATETIME + - keyword: NOT + - keyword: 'NULL' + - keyword: ON + - keyword: UPDATE + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: ts7 + - keyword: TIMESTAMP + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '6' + - end_bracket: ) + - keyword: DEFAULT + - keyword: CURRENT_TIMESTAMP + - bracketed: + - start_bracket: ( + - numeric_literal: '6' + - end_bracket: ) + - keyword: ON + - keyword: UPDATE + - keyword: CURRENT_TIMESTAMP + - bracketed: + - start_bracket: ( + - numeric_literal: '6' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: ts8 + - keyword: TIMESTAMP + - keyword: 'NULL' + - keyword: DEFAULT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: ts9 + - keyword: TIMESTAMP + - keyword: 'NULL' + - keyword: DEFAULT + - numeric_literal: '0' + - comma: ',' + - column_definition: + - naked_identifier: ts10 + - keyword: TIMESTAMP + - keyword: 'NULL' + - keyword: DEFAULT + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: ts11 + - keyword: TIMESTAMP + - keyword: 'NULL' + - keyword: DEFAULT + - keyword: CURRENT_TIMESTAMP + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: ts12 + - keyword: TIMESTAMP + - keyword: 'NULL' + - keyword: DEFAULT + - quoted_literal: '''0000-00-00 00:00:00''' + - comma: ',' + - column_definition: + - naked_identifier: ts13 + - keyword: TIMESTAMP + - keyword: 'NULL' + - keyword: DEFAULT + - keyword: NOW + - keyword: ON + - keyword: UPDATE + - keyword: NOW + - comma: ',' + - column_definition: + - naked_identifier: ts14 + - keyword: TIMESTAMP + - keyword: 'NULL' + - keyword: DEFAULT + - keyword: NOW + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: ON + - keyword: UPDATE + - keyword: NOW + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: ts15 + - keyword: TIMESTAMP + - keyword: NOT + - keyword: 'NULL' + - keyword: DEFAULT + - keyword: CURRENT_TIMESTAMP + - keyword: ON + - keyword: UPDATE + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: ts16 + - keyword: TIMESTAMP + - keyword: 'NULL' + - keyword: DEFAULT + - keyword: 'NULL' + - keyword: ON + - keyword: UPDATE + - keyword: CURRENT_TIMESTAMP + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_equals_optional.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_equals_optional.sql new file mode 100644 index 000000000..d863f0146 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_equals_optional.sql @@ -0,0 +1,3 @@ +CREATE TABLE a ( + id INT +) COLLATE utf8_general_ci; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_equals_optional.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_equals_optional.yml new file mode 100644 index 000000000..f71ced310 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_equals_optional.yml @@ -0,0 +1,17 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: a + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: INT + - end_bracket: ) + - parameter: COLLATE + - parameter: utf8_general_ci +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_generated_column.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_generated_column.sql new file mode 100644 index 000000000..d06506ab7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_generated_column.sql @@ -0,0 +1,17 @@ +CREATE TABLE t1 ( + a INT, + b INT, + c TEXT, + d INT GENERATED ALWAYS AS (a*abs(b)) VIRTUAL, + e TEXT GENERATED ALWAYS AS (substr(c,b,b+1)) STORED, + PRIMARY KEY (a) +); + +CREATE TABLE t1 ( + a INT, + b INT, + c TEXT, + d INT AS (a*abs(b)), + e TEXT AS (substr(c,b,b+1)) STORED COMMENT 'foo', + PRIMARY KEY (a) +); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_generated_column.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_generated_column.yml new file mode 100644 index 000000000..2697f52ab --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_generated_column.yml @@ -0,0 +1,188 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: a + - data_type: + - data_type_identifier: INT + - comma: ',' + - column_definition: + - naked_identifier: b + - data_type: + - data_type_identifier: INT + - comma: ',' + - column_definition: + - naked_identifier: c + - data_type: + - data_type_identifier: TEXT + - comma: ',' + - column_definition: + - naked_identifier: d + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: a + - binary_operator: '*' + - function: + - function_name: + - function_name_identifier: abs + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - end_bracket: ) + - end_bracket: ) + - keyword: VIRTUAL + - comma: ',' + - column_definition: + - naked_identifier: e + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: substr + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c + - comma: ',' + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - column_reference: + - naked_identifier: b + - binary_operator: + + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - keyword: STORED + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: a + - data_type: + - data_type_identifier: INT + - comma: ',' + - column_definition: + - naked_identifier: b + - data_type: + - data_type_identifier: INT + - comma: ',' + - column_definition: + - naked_identifier: c + - data_type: + - data_type_identifier: TEXT + - comma: ',' + - column_definition: + - naked_identifier: d + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: a + - binary_operator: '*' + - function: + - function_name: + - function_name_identifier: abs + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: e + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: substr + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c + - comma: ',' + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - column_reference: + - naked_identifier: b + - binary_operator: + + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - keyword: STORED + - column_constraint_segment: + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''foo''' + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_index.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_index.sql new file mode 100644 index 000000000..d26bd1e7f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_index.sql @@ -0,0 +1,12 @@ +CREATE TABLE foo ( + id INT UNSIGNED AUTO_INCREMENT NOT NULL, + a TEXT(500), + b INT, + c INT, + PRIMARY KEY (id) COMMENT 'primary key (id)', + FULLTEXT `idx_a` (a) COMMENT 'index (a)', + INDEX `idx_prefix_a` (a(20)), + INDEX `idx_b` (b) COMMENT 'index (b)', + INDEX `idx_desc_b` (b DESC), + INDEX `idx_asc_c` (c ASC) +) ENGINE=InnoDB; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_index.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_index.yml new file mode 100644 index 000000000..48ad623e9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_index.yml @@ -0,0 +1,122 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: INT + - keyword: UNSIGNED + - column_constraint_segment: + - keyword: AUTO_INCREMENT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: a + - data_type: + - data_type_identifier: TEXT + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '500' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: b + - data_type: + - data_type_identifier: INT + - comma: ',' + - column_definition: + - naked_identifier: c + - data_type: + - data_type_identifier: INT + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - end_bracket: ) + - index_option: + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''primary key (id)''' + - comma: ',' + - table_constraint: + - keyword: FULLTEXT + - index_reference: + - quoted_identifier: '`idx_a`' + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - end_bracket: ) + - index_option: + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''index (a)''' + - comma: ',' + - table_constraint: + - keyword: INDEX + - index_reference: + - quoted_identifier: '`idx_prefix_a`' + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - bracketed: + - start_bracket: ( + - numeric_literal: '20' + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: INDEX + - index_reference: + - quoted_identifier: '`idx_b`' + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: b + - end_bracket: ) + - index_option: + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''index (b)''' + - comma: ',' + - table_constraint: + - keyword: INDEX + - index_reference: + - quoted_identifier: '`idx_desc_b`' + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: b + - keyword: DESC + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: INDEX + - index_reference: + - quoted_identifier: '`idx_asc_c`' + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c + - keyword: ASC + - end_bracket: ) + - end_bracket: ) + - parameter: ENGINE + - comparison_operator: + - raw_comparison_operator: = + - parameter: InnoDB +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_null_position.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_null_position.sql new file mode 100644 index 000000000..6dc26b41e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_null_position.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS db_name.table_name +( + updated_at1 timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP, + updated_at2 timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, + updated_at3 timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP not null, + updated_at4 timestamp +); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_null_position.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_null_position.yml new file mode 100644 index 000000000..4025392c8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_null_position.yml @@ -0,0 +1,52 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: db_name + - dot: . + - naked_identifier: table_name + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: updated_at1 + - keyword: timestamp + - keyword: default + - keyword: CURRENT_TIMESTAMP + - keyword: not + - keyword: 'null' + - keyword: on + - keyword: update + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: updated_at2 + - keyword: timestamp + - keyword: not + - keyword: 'null' + - keyword: default + - keyword: CURRENT_TIMESTAMP + - keyword: on + - keyword: update + - keyword: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: updated_at3 + - keyword: timestamp + - keyword: default + - keyword: CURRENT_TIMESTAMP + - keyword: on + - keyword: update + - keyword: CURRENT_TIMESTAMP + - keyword: not + - keyword: 'null' + - comma: ',' + - column_definition: + - naked_identifier: updated_at4 + - keyword: timestamp + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_primary_foreign_keys.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_primary_foreign_keys.sql new file mode 100644 index 000000000..42eef540a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_primary_foreign_keys.sql @@ -0,0 +1,49 @@ +CREATE TABLE parent ( + id INT NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE child ( + id INT, + parent_id INT, + INDEX par_ind (parent_id), + FOREIGN KEY (parent_id) + REFERENCES parent(id) + ON DELETE CASCADE +); + +CREATE TABLE product ( + category INT NOT NULL, id INT NOT NULL, + price DECIMAL, + PRIMARY KEY(category, id) +); + +CREATE TABLE customer ( + id INT NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE product_order ( + product_category INT NOT NULL, + product_id INT NOT NULL, + customer_id INT NOT NULL, + + PRIMARY KEY(no), + -- INDEX (product_category, product_id), + -- INDEX (customer_id), + + FOREIGN KEY (product_category, product_id) + REFERENCES product(category, id) + ON UPDATE CASCADE ON DELETE RESTRICT, + + FOREIGN KEY (customer_id) + REFERENCES customer(id) +); + +CREATE TABLE source_tag_assoc ( + source_id INT UNSIGNED NOT NULL, + tag_id INT UNSIGNED NOT NULL, + PRIMARY KEY (source_id, tag_id), + FOREIGN KEY (source_id) REFERENCES source (id) ON DELETE CASCADE, + FOREIGN KEY (tag_id) REFERENCES source_tag (id) ON DELETE CASCADE +); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_primary_foreign_keys.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_primary_foreign_keys.yml new file mode 100644 index 000000000..db89dd329 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_primary_foreign_keys.yml @@ -0,0 +1,311 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: parent + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: child + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: INT + - comma: ',' + - column_definition: + - naked_identifier: parent_id + - data_type: + - data_type_identifier: INT + - comma: ',' + - table_constraint: + - keyword: INDEX + - index_reference: + - naked_identifier: par_ind + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: parent_id + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: parent_id + - end_bracket: ) + - keyword: REFERENCES + - column_reference: + - naked_identifier: parent + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - end_bracket: ) + - keyword: ON + - keyword: DELETE + - keyword: CASCADE + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: product + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: category + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: price + - data_type: + - data_type_identifier: DECIMAL + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: category + - comma: ',' + - column_reference: + - naked_identifier: id + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: customer + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: product_order + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: product_category + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: product_id + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: customer_id + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: no + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: product_category + - comma: ',' + - column_reference: + - naked_identifier: product_id + - end_bracket: ) + - keyword: REFERENCES + - column_reference: + - naked_identifier: product + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: category + - comma: ',' + - column_reference: + - naked_identifier: id + - end_bracket: ) + - keyword: ON + - keyword: UPDATE + - keyword: CASCADE + - keyword: ON + - keyword: DELETE + - keyword: RESTRICT + - comma: ',' + - table_constraint: + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: customer_id + - end_bracket: ) + - keyword: REFERENCES + - column_reference: + - naked_identifier: customer + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: source_tag_assoc + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: source_id + - data_type: + - data_type_identifier: INT + - keyword: UNSIGNED + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: tag_id + - data_type: + - data_type_identifier: INT + - keyword: UNSIGNED + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: source_id + - comma: ',' + - column_reference: + - naked_identifier: tag_id + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: source_id + - end_bracket: ) + - keyword: REFERENCES + - column_reference: + - naked_identifier: source + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - end_bracket: ) + - keyword: ON + - keyword: DELETE + - keyword: CASCADE + - comma: ',' + - table_constraint: + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: tag_id + - end_bracket: ) + - keyword: REFERENCES + - column_reference: + - naked_identifier: source_tag + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - end_bracket: ) + - keyword: ON + - keyword: DELETE + - keyword: CASCADE + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_unique_key.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_unique_key.sql new file mode 100644 index 000000000..0ca8244df --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_unique_key.sql @@ -0,0 +1,3 @@ +create table a( + b int unique key +); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_unique_key.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_unique_key.yml new file mode 100644 index 000000000..4552df994 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_table_unique_key.yml @@ -0,0 +1,18 @@ +file: +- statement: + - create_table_statement: + - keyword: create + - keyword: table + - table_reference: + - naked_identifier: a + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: b + - data_type: + - data_type_identifier: int + - column_constraint_segment: + - keyword: unique + - keyword: key + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_trigger.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_trigger.sql new file mode 100644 index 000000000..0263a0ed2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_trigger.sql @@ -0,0 +1,52 @@ +CREATE TRIGGER delete_members_after_transactions AFTER DELETE ON transactions +FOR EACH ROW DELETE FROM members WHERE username NOT IN +(SELECT UNIQUE(username) FROM transactions); + + + +CREATE TRIGGER some_trigger AFTER DELETE ON some_table +FOR EACH ROW +BEGIN + DELETE FROM some_table; + INSERT INTO some_table; +END; + + +CREATE TRIGGER ins_sum BEFORE INSERT ON account +FOR EACH ROW SET @sum = @sum + NEW.amount; + + +CREATE TRIGGER some_trigger AFTER DELETE ON some_table FOR EACH ROW DELETE FROM other_table; +CREATE TRIGGER some_trigger BEFORE DELETE ON some_table FOR EACH ROW DELETE FROM other_table; +CREATE TRIGGER some_trigger AFTER UPDATE ON some_table FOR EACH ROW DELETE FROM other_table; +CREATE TRIGGER some_trigger BEFORE UPDATE ON some_table FOR EACH ROW DELETE FROM other_table; +CREATE TRIGGER some_trigger AFTER INSERT ON some_table FOR EACH ROW DELETE FROM other_table; +CREATE TRIGGER some_trigger BEFORE INSERT ON some_table FOR EACH ROW DELETE FROM other_table; + +CREATE TRIGGER IF NOT EXISTS some_trigger AFTER DELETE ON some_table +FOR EACH ROW DELETE FROM other_table; + +CREATE TRIGGER some_trigger AFTER DELETE ON some_table FOR EACH ROW +FOLLOWS some_other_trigger +DELETE FROM other_table; +CREATE TRIGGER some_trigger AFTER DELETE ON some_table FOR EACH ROW +PRECEDES some_other_trigger +DELETE FROM other_table; + + +CREATE +DEFINER=`root`@`127.0.0.1` +TRIGGER ins_sum BEFORE INSERT ON account +FOR EACH ROW SET @sum = @sum + NEW.amount; +CREATE +DEFINER=CURRENT_USER +TRIGGER ins_sum BEFORE INSERT ON account +FOR EACH ROW SET @sum = @sum + NEW.amount; + +CREATE TRIGGER tr_downloads_i_copy_new_fields BEFORE INSERT +ON downloads +FOR EACH ROW BEGIN + +SET NEW.createdate = UNIX_TIMESTAMP(NEW.createdate_m); + +END; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_trigger.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_trigger.yml new file mode 100644 index 000000000..916696f3e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_trigger.yml @@ -0,0 +1,468 @@ +file: +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: delete_members_after_transactions + - keyword: AFTER + - keyword: DELETE + - keyword: ON + - table_reference: + - naked_identifier: transactions + - keyword: FOR + - keyword: EACH + - keyword: ROW + - statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: members + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: username + - keyword: NOT + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: UNIQUE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: username + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: transactions + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: some_trigger + - keyword: AFTER + - keyword: DELETE + - keyword: ON + - table_reference: + - naked_identifier: some_table + - keyword: FOR + - keyword: EACH + - keyword: ROW + - statement: + - transaction_statement: + - keyword: BEGIN + - statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: ins_sum + - keyword: BEFORE + - keyword: INSERT + - keyword: ON + - table_reference: + - naked_identifier: account + - keyword: FOR + - keyword: EACH + - keyword: ROW + - statement: + - set_statement: + - keyword: SET + - variable: '@sum' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - variable: '@sum' + - binary_operator: + + - column_reference: + - naked_identifier: NEW + - dot: . + - naked_identifier: amount +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: some_trigger + - keyword: AFTER + - keyword: DELETE + - keyword: ON + - table_reference: + - naked_identifier: some_table + - keyword: FOR + - keyword: EACH + - keyword: ROW + - statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: other_table +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: some_trigger + - keyword: BEFORE + - keyword: DELETE + - keyword: ON + - table_reference: + - naked_identifier: some_table + - keyword: FOR + - keyword: EACH + - keyword: ROW + - statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: other_table +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: some_trigger + - keyword: AFTER + - keyword: UPDATE + - keyword: ON + - table_reference: + - naked_identifier: some_table + - keyword: FOR + - keyword: EACH + - keyword: ROW + - statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: other_table +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: some_trigger + - keyword: BEFORE + - keyword: UPDATE + - keyword: ON + - table_reference: + - naked_identifier: some_table + - keyword: FOR + - keyword: EACH + - keyword: ROW + - statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: other_table +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: some_trigger + - keyword: AFTER + - keyword: INSERT + - keyword: ON + - table_reference: + - naked_identifier: some_table + - keyword: FOR + - keyword: EACH + - keyword: ROW + - statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: other_table +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: some_trigger + - keyword: BEFORE + - keyword: INSERT + - keyword: ON + - table_reference: + - naked_identifier: some_table + - keyword: FOR + - keyword: EACH + - keyword: ROW + - statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: other_table +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - trigger_reference: + - naked_identifier: some_trigger + - keyword: AFTER + - keyword: DELETE + - keyword: ON + - table_reference: + - naked_identifier: some_table + - keyword: FOR + - keyword: EACH + - keyword: ROW + - statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: other_table +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: some_trigger + - keyword: AFTER + - keyword: DELETE + - keyword: ON + - table_reference: + - naked_identifier: some_table + - keyword: FOR + - keyword: EACH + - keyword: ROW + - keyword: FOLLOWS + - naked_identifier: some_other_trigger + - statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: other_table +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: some_trigger + - keyword: AFTER + - keyword: DELETE + - keyword: ON + - table_reference: + - naked_identifier: some_table + - keyword: FOR + - keyword: EACH + - keyword: ROW + - keyword: PRECEDES + - naked_identifier: some_other_trigger + - statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: other_table +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - definer_segment: + - keyword: DEFINER + - comparison_operator: + - raw_comparison_operator: = + - role_reference: + - quoted_identifier: '`root`' + - at_sign_literal: '@' + - quoted_identifier: '`127.0.0.1`' + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: ins_sum + - keyword: BEFORE + - keyword: INSERT + - keyword: ON + - table_reference: + - naked_identifier: account + - keyword: FOR + - keyword: EACH + - keyword: ROW + - statement: + - set_statement: + - keyword: SET + - variable: '@sum' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - variable: '@sum' + - binary_operator: + + - column_reference: + - naked_identifier: NEW + - dot: . + - naked_identifier: amount +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - definer_segment: + - keyword: DEFINER + - comparison_operator: + - raw_comparison_operator: = + - role_reference: + - keyword: CURRENT_USER + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: ins_sum + - keyword: BEFORE + - keyword: INSERT + - keyword: ON + - table_reference: + - naked_identifier: account + - keyword: FOR + - keyword: EACH + - keyword: ROW + - statement: + - set_statement: + - keyword: SET + - variable: '@sum' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - variable: '@sum' + - binary_operator: + + - column_reference: + - naked_identifier: NEW + - dot: . + - naked_identifier: amount +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: tr_downloads_i_copy_new_fields + - keyword: BEFORE + - keyword: INSERT + - keyword: ON + - table_reference: + - naked_identifier: downloads + - keyword: FOR + - keyword: EACH + - keyword: ROW + - statement: + - transaction_statement: + - keyword: BEGIN + - statement: + - set_statement: + - keyword: SET + - keyword: NEW + - dot: . + - variable: createdate + - comparison_operator: + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: UNIX_TIMESTAMP + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: NEW + - dot: . + - naked_identifier: createdate_m + - end_bracket: ) +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_user.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_user.sql new file mode 100644 index 000000000..134eed9e3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_user.sql @@ -0,0 +1,74 @@ +CREATE USER jeffrey; +CREATE USER IF NOT EXISTS jeffrey; +CREATE USER 'prj_svc' IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS'; +CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'password'; +CREATE USER "jeffrey"@"localhost" IDENTIFIED BY "password"; +CREATE USER `jeffrey`@`localhost` IDENTIFIED BY "password"; +CREATE USER 'jeffrey'@'localhost' + IDENTIFIED BY 'new_password' PASSWORD EXPIRE; +CREATE USER 'jeffrey'@'localhost' + IDENTIFIED WITH caching_sha2_password BY 'new_password' + PASSWORD EXPIRE INTERVAL 180 DAY + FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 2; +CREATE USER + 'jeffrey'@'localhost' IDENTIFIED WITH mysql_native_password + BY 'new_password1', + 'jeanne'@'localhost' IDENTIFIED WITH caching_sha2_password + BY 'new_password2' + REQUIRE X509 WITH MAX_QUERIES_PER_HOUR 60 + PASSWORD HISTORY 5 + ACCOUNT LOCK; +CREATE USER 'jeffrey'@'localhost' + IDENTIFIED WITH mysql_native_password BY 'password'; +CREATE USER 'u1'@'localhost' + IDENTIFIED WITH caching_sha2_password + BY 'sha2_password' + AND IDENTIFIED WITH authentication_ldap_sasl + AS 'uid=u1_ldap,ou=People,dc=example,dc=com'; +CREATE USER 'u1'@'localhost' + IDENTIFIED WITH caching_sha2_password + BY 'sha2_password' + AND IDENTIFIED WITH authentication_ldap_sasl + AS 'uid=u1_ldap,ou=People,dc=example,dc=com' + AND IDENTIFIED WITH authentication_fido; +CREATE USER user + IDENTIFIED WITH authentication_fido + INITIAL AUTHENTICATION IDENTIFIED BY RANDOM PASSWORD; +CREATE USER 'joe'@'10.0.0.1' DEFAULT ROLE administrator, developer; +CREATE USER 'jeffrey'@'localhost' REQUIRE NONE; +CREATE USER 'jeffrey'@'localhost' REQUIRE SSL; +CREATE USER 'jeffrey'@'localhost' REQUIRE X509; +CREATE USER 'jeffrey'@'localhost' + REQUIRE ISSUER '/C=SE/ST=Stockholm/L=Stockholm/ + O=MySQL/CN=CA/emailAddress=ca@example.com'; +CREATE USER 'jeffrey'@'localhost' + REQUIRE SUBJECT '/C=SE/ST=Stockholm/L=Stockholm/ + O=MySQL demo client certificate/ + CN=client/emailAddress=client@example.com'; +CREATE USER 'jeffrey'@'localhost' + REQUIRE CIPHER 'EDH-RSA-DES-CBC3-SHA'; +CREATE USER 'jeffrey'@'localhost' + REQUIRE SUBJECT '/C=SE/ST=Stockholm/L=Stockholm/ + O=MySQL demo client certificate/ + CN=client/emailAddress=client@example.com' + AND ISSUER '/C=SE/ST=Stockholm/L=Stockholm/ + O=MySQL/CN=CA/emailAddress=ca@example.com' + AND CIPHER 'EDH-RSA-DES-CBC3-SHA'; +CREATE USER 'jeffrey'@'localhost' + WITH MAX_QUERIES_PER_HOUR 500 MAX_UPDATES_PER_HOUR 100; +CREATE USER 'jeffrey'@'localhost' PASSWORD EXPIRE; +CREATE USER 'jeffrey'@'localhost' PASSWORD EXPIRE DEFAULT; +CREATE USER 'jeffrey'@'localhost' PASSWORD EXPIRE NEVER; +CREATE USER 'jeffrey'@'localhost' PASSWORD EXPIRE INTERVAL 180 DAY; +CREATE USER 'jeffrey'@'localhost' PASSWORD HISTORY DEFAULT; +CREATE USER 'jeffrey'@'localhost' PASSWORD HISTORY 6; +CREATE USER 'jeffrey'@'localhost' PASSWORD REUSE INTERVAL DEFAULT; +CREATE USER 'jeffrey'@'localhost' PASSWORD REUSE INTERVAL 360 DAY; +CREATE USER 'jeffrey'@'localhost' PASSWORD REQUIRE CURRENT; +CREATE USER 'jeffrey'@'localhost' PASSWORD REQUIRE CURRENT OPTIONAL; +CREATE USER 'jeffrey'@'localhost' PASSWORD REQUIRE CURRENT DEFAULT; +CREATE USER 'jeffrey'@'localhost' + FAILED_LOGIN_ATTEMPTS 4 PASSWORD_LOCK_TIME 2; +CREATE USER 'jon'@'localhost' COMMENT 'Some information about Jon'; +CREATE USER 'jim'@'localhost' + ATTRIBUTE '{"fname": "James", "lname": "Scott", "phone": "123-456-7890"}'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_user.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_user.yml new file mode 100644 index 000000000..2cea7f0e5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_user.yml @@ -0,0 +1,522 @@ +file: +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - naked_identifier: jeffrey +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - role_reference: + - naked_identifier: jeffrey +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''prj_svc''' + - keyword: IDENTIFIED + - keyword: WITH + - object_reference: + - naked_identifier: AWSAuthenticationPlugin + - keyword: AS + - quoted_literal: '''RDS''' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: IDENTIFIED + - keyword: BY + - quoted_literal: '''password''' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_literal: '"jeffrey"' + - at_sign_literal: '@' + - quoted_literal: '"localhost"' + - keyword: IDENTIFIED + - keyword: BY + - quoted_literal: '"password"' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '`jeffrey`' + - at_sign_literal: '@' + - quoted_identifier: '`localhost`' + - keyword: IDENTIFIED + - keyword: BY + - quoted_literal: '"password"' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: IDENTIFIED + - keyword: BY + - quoted_literal: '''new_password''' + - keyword: PASSWORD + - keyword: EXPIRE +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: IDENTIFIED + - keyword: WITH + - object_reference: + - naked_identifier: caching_sha2_password + - keyword: BY + - quoted_literal: '''new_password''' + - keyword: PASSWORD + - keyword: EXPIRE + - keyword: INTERVAL + - numeric_literal: '180' + - keyword: DAY + - keyword: FAILED_LOGIN_ATTEMPTS + - numeric_literal: '3' + - keyword: PASSWORD_LOCK_TIME + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: IDENTIFIED + - keyword: WITH + - object_reference: + - naked_identifier: mysql_native_password + - keyword: BY + - quoted_literal: '''new_password1''' + - comma: ',' + - role_reference: + - quoted_identifier: '''jeanne''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: IDENTIFIED + - keyword: WITH + - object_reference: + - naked_identifier: caching_sha2_password + - keyword: BY + - quoted_literal: '''new_password2''' + - keyword: REQUIRE + - keyword: X509 + - keyword: WITH + - keyword: MAX_QUERIES_PER_HOUR + - numeric_literal: '60' + - keyword: PASSWORD + - keyword: HISTORY + - numeric_literal: '5' + - keyword: ACCOUNT + - keyword: LOCK +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: IDENTIFIED + - keyword: WITH + - object_reference: + - naked_identifier: mysql_native_password + - keyword: BY + - quoted_literal: '''password''' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''u1''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: IDENTIFIED + - keyword: WITH + - object_reference: + - naked_identifier: caching_sha2_password + - keyword: BY + - quoted_literal: '''sha2_password''' + - keyword: AND + - keyword: IDENTIFIED + - keyword: WITH + - object_reference: + - naked_identifier: authentication_ldap_sasl + - keyword: AS + - quoted_literal: '''uid=u1_ldap,ou=People,dc=example,dc=com''' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''u1''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: IDENTIFIED + - keyword: WITH + - object_reference: + - naked_identifier: caching_sha2_password + - keyword: BY + - quoted_literal: '''sha2_password''' + - keyword: AND + - keyword: IDENTIFIED + - keyword: WITH + - object_reference: + - naked_identifier: authentication_ldap_sasl + - keyword: AS + - quoted_literal: '''uid=u1_ldap,ou=People,dc=example,dc=com''' + - keyword: AND + - keyword: IDENTIFIED + - keyword: WITH + - object_reference: + - naked_identifier: authentication_fido +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - naked_identifier: user + - keyword: IDENTIFIED + - keyword: WITH + - object_reference: + - naked_identifier: authentication_fido + - keyword: INITIAL + - keyword: AUTHENTICATION + - keyword: IDENTIFIED + - keyword: BY + - keyword: RANDOM + - keyword: PASSWORD +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''joe''' + - at_sign_literal: '@' + - quoted_identifier: '''10.0.0.1''' + - keyword: DEFAULT + - keyword: ROLE + - role_reference: + - naked_identifier: administrator + - comma: ',' + - role_reference: + - naked_identifier: developer +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: REQUIRE + - keyword: NONE +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: REQUIRE + - keyword: SSL +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: REQUIRE + - keyword: X509 +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: REQUIRE + - keyword: ISSUER + - quoted_literal: |- + '/C=SE/ST=Stockholm/L=Stockholm/ + O=MySQL/CN=CA/emailAddress=ca@example.com' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: REQUIRE + - keyword: SUBJECT + - quoted_literal: |- + '/C=SE/ST=Stockholm/L=Stockholm/ + O=MySQL demo client certificate/ + CN=client/emailAddress=client@example.com' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: REQUIRE + - keyword: CIPHER + - quoted_literal: '''EDH-RSA-DES-CBC3-SHA''' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: REQUIRE + - keyword: SUBJECT + - quoted_literal: |- + '/C=SE/ST=Stockholm/L=Stockholm/ + O=MySQL demo client certificate/ + CN=client/emailAddress=client@example.com' + - keyword: AND + - keyword: ISSUER + - quoted_literal: |- + '/C=SE/ST=Stockholm/L=Stockholm/ + O=MySQL/CN=CA/emailAddress=ca@example.com' + - keyword: AND + - keyword: CIPHER + - quoted_literal: '''EDH-RSA-DES-CBC3-SHA''' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: WITH + - keyword: MAX_QUERIES_PER_HOUR + - numeric_literal: '500' + - keyword: MAX_UPDATES_PER_HOUR + - numeric_literal: '100' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: PASSWORD + - keyword: EXPIRE +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: PASSWORD + - keyword: EXPIRE + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: PASSWORD + - keyword: EXPIRE + - keyword: NEVER +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: PASSWORD + - keyword: EXPIRE + - keyword: INTERVAL + - numeric_literal: '180' + - keyword: DAY +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: PASSWORD + - keyword: HISTORY + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: PASSWORD + - keyword: HISTORY + - numeric_literal: '6' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: PASSWORD + - keyword: REUSE + - keyword: INTERVAL + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: PASSWORD + - keyword: REUSE + - keyword: INTERVAL + - numeric_literal: '360' + - keyword: DAY +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: PASSWORD + - keyword: REQUIRE + - keyword: CURRENT +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: PASSWORD + - keyword: REQUIRE + - keyword: CURRENT + - keyword: OPTIONAL +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: PASSWORD + - keyword: REQUIRE + - keyword: CURRENT + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jeffrey''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: FAILED_LOGIN_ATTEMPTS + - numeric_literal: '4' + - keyword: PASSWORD_LOCK_TIME + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jon''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: COMMENT + - quoted_literal: '''Some information about Jon''' +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '''jim''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' + - keyword: ATTRIBUTE + - quoted_literal: '''{"fname": "James", "lname": "Scott", "phone": "123-456-7890"}''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_view.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_view.sql new file mode 100644 index 000000000..c82144e77 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_view.sql @@ -0,0 +1,24 @@ +CREATE VIEW v1 (c,d) AS + SELECT a,b FROM t1; + +CREATE OR REPLACE VIEW v1 (c,d,e,f) AS + SELECT a,b, a IN (SELECT a+2 FROM t1), a = all (SELECT a FROM t1) FROM t1; + +CREATE VIEW v2 AS SELECT a FROM t1 WITH CASCADED CHECK OPTION; + +CREATE VIEW v2 AS (SELECT a FROM t1) WITH CASCADED CHECK OPTION; + +CREATE VIEW v2 AS + SELECT 1 UNION SELECT 2; + + + +CREATE VIEW vw_test AS + WITH testing_cte as ( + SELECT + a + , b + FROM t1 + ) + SELECT a, b from testing_cte +; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_view.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_view.yml new file mode 100644 index 000000000..7f0e29a1d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/create_view.yml @@ -0,0 +1,254 @@ +file: +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c + - comma: ',' + - column_reference: + - naked_identifier: d + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: VIEW + - table_reference: + - naked_identifier: v1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c + - comma: ',' + - column_reference: + - naked_identifier: d + - comma: ',' + - column_reference: + - naked_identifier: e + - comma: ',' + - column_reference: + - naked_identifier: f + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: a + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: a + - binary_operator: + + - numeric_literal: '2' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - end_bracket: ) + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: all + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - table_reference: + - naked_identifier: v2 + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - with_check_options: + - keyword: WITH + - keyword: CASCADED + - keyword: CHECK + - keyword: OPTION +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - table_reference: + - naked_identifier: v2 + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - end_bracket: ) + - with_check_options: + - keyword: WITH + - keyword: CASCADED + - keyword: CHECK + - keyword: OPTION +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - table_reference: + - naked_identifier: v2 + - keyword: AS + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - set_operator: + - keyword: UNION + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - table_reference: + - naked_identifier: vw_test + - keyword: AS + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: testing_cte + - keyword: as + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: testing_cte +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/deallocate_prepare.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/deallocate_prepare.sql new file mode 100644 index 000000000..993de88a2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/deallocate_prepare.sql @@ -0,0 +1 @@ +DEALLOCATE PREPARE dynam; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/deallocate_prepare.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/deallocate_prepare.yml new file mode 100644 index 000000000..a5f54f5ef --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/deallocate_prepare.yml @@ -0,0 +1,7 @@ +file: +- statement: + - deallocate_segment: + - keyword: DEALLOCATE + - keyword: PREPARE + - naked_identifier: dynam +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_condition.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_condition.sql new file mode 100644 index 000000000..8a77f2096 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_condition.sql @@ -0,0 +1 @@ +DECLARE random_condition_name CONDITION FOR 1051; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_condition.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_condition.yml new file mode 100644 index 000000000..d9b09c2ac --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_condition.yml @@ -0,0 +1,9 @@ +file: +- statement: + - declare_statement: + - keyword: DECLARE + - naked_identifier: random_condition_name + - keyword: CONDITION + - keyword: FOR + - numeric_literal: '1051' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_continue_handler_sqlexception.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_continue_handler_sqlexception.sql new file mode 100644 index 000000000..435b03cf6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_continue_handler_sqlexception.sql @@ -0,0 +1,4 @@ +DECLARE continue handler for sqlexception +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_continue_handler_sqlexception.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_continue_handler_sqlexception.yml new file mode 100644 index 000000000..632fc0d9d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_continue_handler_sqlexception.yml @@ -0,0 +1,22 @@ +file: +- statement: + - declare_statement: + - keyword: DECLARE + - keyword: continue + - keyword: handler + - keyword: for + - keyword: sqlexception + - statement: + - transaction_statement: + - keyword: begin + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: end +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_cursor.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_cursor.sql new file mode 100644 index 000000000..579e37803 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_cursor.sql @@ -0,0 +1 @@ +DECLARE test CURSOR FOR SELECT 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_cursor.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_cursor.yml new file mode 100644 index 000000000..8d59c744d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_cursor.yml @@ -0,0 +1,14 @@ +file: +- statement: + - declare_statement: + - keyword: DECLARE + - naked_identifier: test + - keyword: CURSOR + - keyword: FOR + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_numeric.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_numeric.sql new file mode 100644 index 000000000..6a57eee3d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_numeric.sql @@ -0,0 +1 @@ +DECLARE abc int default 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_numeric.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_numeric.yml new file mode 100644 index 000000000..7304873ae --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_numeric.yml @@ -0,0 +1,10 @@ +file: +- statement: + - declare_statement: + - keyword: DECLARE + - variable: abc + - data_type: + - data_type_identifier: int + - keyword: default + - numeric_literal: '1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_quotedliteral.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_quotedliteral.sql new file mode 100644 index 000000000..13cb3cb80 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_quotedliteral.sql @@ -0,0 +1 @@ +DECLARE abc longtext default 'test'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_quotedliteral.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_quotedliteral.yml new file mode 100644 index 000000000..5861eed5b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_default_quotedliteral.yml @@ -0,0 +1,10 @@ +file: +- statement: + - declare_statement: + - keyword: DECLARE + - variable: abc + - data_type: + - data_type_identifier: longtext + - keyword: default + - quoted_literal: '''test''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_exit_handler_sqlexception.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_exit_handler_sqlexception.sql new file mode 100644 index 000000000..fa6f22dae --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_exit_handler_sqlexception.sql @@ -0,0 +1,4 @@ +DECLARE exit handler for sqlexception +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_exit_handler_sqlexception.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_exit_handler_sqlexception.yml new file mode 100644 index 000000000..8b5d74db0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_exit_handler_sqlexception.yml @@ -0,0 +1,22 @@ +file: +- statement: + - declare_statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - keyword: sqlexception + - statement: + - transaction_statement: + - keyword: begin + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: end +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_local_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_local_variable.sql new file mode 100644 index 000000000..e0fd0b204 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_local_variable.sql @@ -0,0 +1 @@ +DECLARE abc int; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_local_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_local_variable.yml new file mode 100644 index 000000000..e7c9edc79 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_local_variable.yml @@ -0,0 +1,8 @@ +file: +- statement: + - declare_statement: + - keyword: DECLARE + - variable: abc + - data_type: + - data_type_identifier: int +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_undo_handler_sqlexception.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_undo_handler_sqlexception.sql new file mode 100644 index 000000000..fcfdec27f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_undo_handler_sqlexception.sql @@ -0,0 +1,4 @@ +DECLARE undo handler for sqlexception +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_undo_handler_sqlexception.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_undo_handler_sqlexception.yml new file mode 100644 index 000000000..b5bfce752 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/declare_undo_handler_sqlexception.yml @@ -0,0 +1,22 @@ +file: +- statement: + - declare_statement: + - keyword: DECLARE + - keyword: undo + - keyword: handler + - keyword: for + - keyword: sqlexception + - statement: + - transaction_statement: + - keyword: begin + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: end +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delete_multitable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delete_multitable.sql new file mode 100644 index 000000000..e95fe9f10 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delete_multitable.sql @@ -0,0 +1,32 @@ +DELETE a FROM a JOIN b USING (id) WHERE b.name = 'example'; + +DELETE FROM somelog WHERE user = 'jcole' +ORDER BY timestamp_column LIMIT 1; + +DELETE LOW_PRIORITY QUICK IGNORE a FROM a JOIN b USING (id) WHERE b.name = 'example'; + +DELETE FROM a PARTITION (p) WHERE b.name = 'example'; + +-- Multiple-Table Syntax 1 +DELETE t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3 +WHERE t1.id=t2.id AND t2.id=t3.id; + +DELETE LOW_PRIORITY QUICK IGNORE t1, t2 FROM t1 INNER JOIN t2 INNER JOIN t3 +WHERE t1.id=t2.id AND t2.id=t3.id; + +-- Multiple-Table Syntax 2 +DELETE FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3 +WHERE t1.id=t2.id AND t2.id=t3.id; + +DELETE LOW_PRIORITY QUICK IGNORE FROM t1, t2 USING t1 INNER JOIN t2 INNER JOIN t3 +WHERE t1.id=t2.id AND t2.id=t3.id; + +DELETE a1, a2 FROM t1 AS a1 INNER JOIN t2 AS a2 +WHERE a1.id=a2.id; + +-- .* after table name +DELETE t1.*, t2.* FROM t1 INNER JOIN t2 INNER JOIN t3 +WHERE t1.id=t2.id AND t2.id=t3.id; + +DELETE FROM t1.*, t2.* USING t1 INNER JOIN t2 INNER JOIN t3 +WHERE t1.id=t2.id AND t2.id=t3.id; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delete_multitable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delete_multitable.yml new file mode 100644 index 000000000..1eb610a28 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delete_multitable.yml @@ -0,0 +1,528 @@ +file: +- statement: + - delete_statement: + - keyword: DELETE + - delete_target_table: + - table_reference: + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: a + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: b + - keyword: USING + - bracketed: + - start_bracket: ( + - naked_identifier: id + - end_bracket: ) + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''example''' +- statement_terminator: ; +- statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: somelog + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: user + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''jcole''' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: timestamp_column + - limit_clause: + - keyword: LIMIT + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - delete_statement: + - keyword: DELETE + - keyword: LOW_PRIORITY + - keyword: QUICK + - keyword: IGNORE + - delete_target_table: + - table_reference: + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: a + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: b + - keyword: USING + - bracketed: + - start_bracket: ( + - naked_identifier: id + - end_bracket: ) + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''example''' +- statement_terminator: ; +- statement: + - delete_statement: + - keyword: DELETE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: a + - partition_clause: + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: p + - end_bracket: ) + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''example''' +- statement_terminator: ; +- statement: + - delete_statement: + - keyword: DELETE + - delete_target_table: + - table_reference: + - naked_identifier: t1 + - comma: ',' + - delete_target_table: + - table_reference: + - naked_identifier: t2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t3 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: id + - binary_operator: AND + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t3 + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - delete_statement: + - keyword: DELETE + - keyword: LOW_PRIORITY + - keyword: QUICK + - keyword: IGNORE + - delete_target_table: + - table_reference: + - naked_identifier: t1 + - comma: ',' + - delete_target_table: + - table_reference: + - naked_identifier: t2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t3 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: id + - binary_operator: AND + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t3 + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - delete_target_table: + - table_reference: + - naked_identifier: t1 + - comma: ',' + - delete_target_table: + - table_reference: + - naked_identifier: t2 + - using_clause: + - keyword: USING + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t3 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: id + - binary_operator: AND + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t3 + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - delete_statement: + - keyword: DELETE + - keyword: LOW_PRIORITY + - keyword: QUICK + - keyword: IGNORE + - keyword: FROM + - delete_target_table: + - table_reference: + - naked_identifier: t1 + - comma: ',' + - delete_target_table: + - table_reference: + - naked_identifier: t2 + - using_clause: + - keyword: USING + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t3 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: id + - binary_operator: AND + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t3 + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - delete_statement: + - keyword: DELETE + - delete_target_table: + - table_reference: + - naked_identifier: a1 + - comma: ',' + - delete_target_table: + - table_reference: + - naked_identifier: a2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a1 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a2 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: a1 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: a2 + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - delete_statement: + - keyword: DELETE + - delete_target_table: + - table_reference: + - naked_identifier: t1 + - dot: . + - star: '*' + - comma: ',' + - delete_target_table: + - table_reference: + - naked_identifier: t2 + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t3 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: id + - binary_operator: AND + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t3 + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - delete_target_table: + - table_reference: + - naked_identifier: t1 + - dot: . + - star: '*' + - comma: ',' + - delete_target_table: + - table_reference: + - naked_identifier: t2 + - dot: . + - star: '*' + - using_clause: + - keyword: USING + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t3 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: id + - binary_operator: AND + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t3 + - dot: . + - naked_identifier: id +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_function.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_function.sql new file mode 100644 index 000000000..e175ab683 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_function.sql @@ -0,0 +1,11 @@ +DELIMITER ~ +CREATE FUNCTION `add`(test int) +RETURNS longtext +DETERMINISTIC +LANGUAGE SQL +CONTAINS SQL +SQL SECURITY DEFINER +BEGIN +SELECT 1 + 2; +END~ +DELIMITER ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_function.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_function.yml new file mode 100644 index 000000000..54d4f1782 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_function.yml @@ -0,0 +1,51 @@ +file: +- statement: + - delimiter_statement: + - keyword: DELIMITER +- statement_terminator: '~' +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - quoted_identifier: '`add`' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: test + - data_type: + - data_type_identifier: int + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: longtext + - characteristic_statement: + - keyword: DETERMINISTIC + - keyword: LANGUAGE + - keyword: SQL + - keyword: CONTAINS + - keyword: SQL + - keyword: SQL + - keyword: SECURITY + - keyword: DEFINER + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: + + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' +- statement: + - delimiter_statement: + - keyword: DELIMITER +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_procedure.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_procedure.sql new file mode 100644 index 000000000..1600b553d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_procedure.sql @@ -0,0 +1,10 @@ +DELIMITER ~ +CREATE PROCEDURE `testprocedure`(test int) +DETERMINISTIC +LANGUAGE SQL +CONTAINS SQL +SQL SECURITY DEFINER +BEGIN +SELECT 1 + 2; +END~ +DELIMITER ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_procedure.yml new file mode 100644 index 000000000..195835bc0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_procedure.yml @@ -0,0 +1,48 @@ +file: +- statement: + - delimiter_statement: + - keyword: DELIMITER +- statement_terminator: '~' +- statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - function_name: + - quoted_identifier: '`testprocedure`' + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: test + - data_type: + - data_type_identifier: int + - end_bracket: ) + - characteristic_statement: + - keyword: DETERMINISTIC + - keyword: LANGUAGE + - keyword: SQL + - keyword: CONTAINS + - keyword: SQL + - keyword: SQL + - keyword: SECURITY + - keyword: DEFINER + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: + + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' +- statement: + - delimiter_statement: + - keyword: DELIMITER +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_select.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_select.sql new file mode 100644 index 000000000..065b19883 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_select.sql @@ -0,0 +1,3 @@ +DELIMITER ~ +SELECT 1~ +DELIMITER ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_select.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_select.yml new file mode 100644 index 000000000..4a9ad98fb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/delimiter_select.yml @@ -0,0 +1,16 @@ +file: +- statement: + - delimiter_statement: + - keyword: DELIMITER +- statement_terminator: '~' +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: '~' +- statement: + - delimiter_statement: + - keyword: DELIMITER +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/derived_tables.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/derived_tables.sql new file mode 100644 index 000000000..78eed8d26 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/derived_tables.sql @@ -0,0 +1,4 @@ +SELECT * FROM (SELECT 1, 2, 3, 4) AS dt; +SELECT * FROM (SELECT 1, 2, 3, 4) AS `dt`; +SELECT * FROM (SELECT 1, 2, 3, 4) AS dt (a, b, c, d); +SELECT * FROM (SELECT 1, 2, 3, 4) AS `dt` (a, b, c, d); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/derived_tables.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/derived_tables.yml new file mode 100644 index 000000000..a929afb06 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/derived_tables.yml @@ -0,0 +1,163 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - comma: ',' + - select_clause_element: + - numeric_literal: '3' + - comma: ',' + - select_clause_element: + - numeric_literal: '4' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: dt +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - comma: ',' + - select_clause_element: + - numeric_literal: '3' + - comma: ',' + - select_clause_element: + - numeric_literal: '4' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`dt`' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - comma: ',' + - select_clause_element: + - numeric_literal: '3' + - comma: ',' + - select_clause_element: + - numeric_literal: '4' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: dt + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: a + - comma: ',' + - naked_identifier: b + - comma: ',' + - naked_identifier: c + - comma: ',' + - naked_identifier: d + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - comma: ',' + - select_clause_element: + - numeric_literal: '3' + - comma: ',' + - select_clause_element: + - numeric_literal: '4' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`dt`' + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: a + - comma: ',' + - naked_identifier: b + - comma: ',' + - naked_identifier: c + - comma: ',' + - naked_identifier: d + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_event.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_event.sql new file mode 100644 index 000000000..4d6951905 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_event.sql @@ -0,0 +1,3 @@ +DROP EVENT test; + +DROP EVENT IF EXISTS test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_event.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_event.yml new file mode 100644 index 000000000..55f507b2f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_event.yml @@ -0,0 +1,17 @@ +file: +- statement: + - drop_event_statement: + - keyword: DROP + - keyword: EVENT + - object_reference: + - naked_identifier: test +- statement_terminator: ; +- statement: + - drop_event_statement: + - keyword: DROP + - keyword: EVENT + - keyword: IF + - keyword: EXISTS + - object_reference: + - naked_identifier: test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_function.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_function.sql new file mode 100644 index 000000000..2cce85c56 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_function.sql @@ -0,0 +1 @@ +DROP FUNCTION IF EXISTS `testfunction`; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_function.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_function.yml new file mode 100644 index 000000000..85b49ef8b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_function.yml @@ -0,0 +1,10 @@ +file: +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: FUNCTION + - keyword: IF + - keyword: EXISTS + - function_name: + - quoted_identifier: '`testfunction`' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index.sql new file mode 100644 index 000000000..4fbd32c00 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index.sql @@ -0,0 +1 @@ +DROP INDEX `test` ON `table1`.`foo`; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index.yml new file mode 100644 index 000000000..9af5dbc8d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index.yml @@ -0,0 +1,13 @@ +file: +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - dot: . + - quoted_identifier: '`foo`' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_algorithm.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_algorithm.sql new file mode 100644 index 000000000..d904c3776 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_algorithm.sql @@ -0,0 +1,6 @@ +DROP INDEX `test` ON `table1`.`foo` ALGORITHM = DEFAULT; +DROP INDEX `test` ON `table1`.`foo` ALGORITHM = INPLACE; +DROP INDEX `test` ON `table1`.`foo` ALGORITHM = COPY; +DROP INDEX `test` ON `table1`.`foo` ALGORITHM DEFAULT; +DROP INDEX `test` ON `table1`.`foo` ALGORITHM INPLACE; +DROP INDEX `test` ON `table1`.`foo` ALGORITHM COPY; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_algorithm.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_algorithm.yml new file mode 100644 index 000000000..8c75425ef --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_algorithm.yml @@ -0,0 +1,91 @@ +file: +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - dot: . + - quoted_identifier: '`foo`' + - keyword: ALGORITHM + - comparison_operator: + - raw_comparison_operator: = + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - dot: . + - quoted_identifier: '`foo`' + - keyword: ALGORITHM + - comparison_operator: + - raw_comparison_operator: = + - keyword: INPLACE +- statement_terminator: ; +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - dot: . + - quoted_identifier: '`foo`' + - keyword: ALGORITHM + - comparison_operator: + - raw_comparison_operator: = + - keyword: COPY +- statement_terminator: ; +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - dot: . + - quoted_identifier: '`foo`' + - keyword: ALGORITHM + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - dot: . + - quoted_identifier: '`foo`' + - keyword: ALGORITHM + - keyword: INPLACE +- statement_terminator: ; +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - dot: . + - quoted_identifier: '`foo`' + - keyword: ALGORITHM + - keyword: COPY +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_lock.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_lock.sql new file mode 100644 index 000000000..90560f63a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_lock.sql @@ -0,0 +1,8 @@ +DROP INDEX `test` ON `table1` LOCK = DEFAULT; +DROP INDEX `test` ON `table1` LOCK = NONE; +DROP INDEX `test` ON `table1` LOCK = SHARED; +DROP INDEX `test` ON `table1` LOCK = EXCLUSIVE; +DROP INDEX `test` ON `table1` LOCK DEFAULT; +DROP INDEX `test` ON `table1` LOCK NONE; +DROP INDEX `test` ON `table1` LOCK SHARED; +DROP INDEX `test` ON `table1` LOCK EXCLUSIVE; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_lock.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_lock.yml new file mode 100644 index 000000000..1126184d8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_index_with_lock.yml @@ -0,0 +1,105 @@ +file: +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - keyword: LOCK + - comparison_operator: + - raw_comparison_operator: = + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - keyword: LOCK + - comparison_operator: + - raw_comparison_operator: = + - keyword: NONE +- statement_terminator: ; +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - keyword: LOCK + - comparison_operator: + - raw_comparison_operator: = + - keyword: SHARED +- statement_terminator: ; +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - keyword: LOCK + - comparison_operator: + - raw_comparison_operator: = + - keyword: EXCLUSIVE +- statement_terminator: ; +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - keyword: LOCK + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - keyword: LOCK + - keyword: NONE +- statement_terminator: ; +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - keyword: LOCK + - keyword: SHARED +- statement_terminator: ; +- statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - quoted_identifier: '`test`' + - keyword: ON + - table_reference: + - quoted_identifier: '`table1`' + - keyword: LOCK + - keyword: EXCLUSIVE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_prepare.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_prepare.sql new file mode 100644 index 000000000..7d8efd833 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_prepare.sql @@ -0,0 +1 @@ +DROP PREPARE dynam; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_prepare.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_prepare.yml new file mode 100644 index 000000000..356401cd8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_prepare.yml @@ -0,0 +1,7 @@ +file: +- statement: + - deallocate_segment: + - keyword: DROP + - keyword: PREPARE + - naked_identifier: dynam +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_procedure.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_procedure.sql new file mode 100644 index 000000000..306457c77 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_procedure.sql @@ -0,0 +1 @@ +DROP PROCEDURE IF EXISTS `testprocedure`; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_procedure.yml new file mode 100644 index 000000000..dd581d211 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_procedure.yml @@ -0,0 +1,10 @@ +file: +- statement: + - drop_procedure_statement: + - keyword: DROP + - keyword: PROCEDURE + - keyword: IF + - keyword: EXISTS + - object_reference: + - quoted_identifier: '`testprocedure`' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_table.sql new file mode 100644 index 000000000..dfc89d132 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_table.sql @@ -0,0 +1,7 @@ +DROP TEMPORARY TABLE IF EXISTS t; + +DROP TEMPORARY TABLE IF EXISTS t, t2; + +DROP TABLE IF EXISTS t RESTRICT; + +DROP TABLE IF EXISTS t CASCADE; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_table.yml new file mode 100644 index 000000000..8fe3550a2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_table.yml @@ -0,0 +1,44 @@ +file: +- statement: + - drop_table_statement: + - keyword: DROP + - keyword: TEMPORARY + - keyword: TABLE + - keyword: IF + - keyword: EXISTS + - table_reference: + - naked_identifier: t +- statement_terminator: ; +- statement: + - drop_table_statement: + - keyword: DROP + - keyword: TEMPORARY + - keyword: TABLE + - keyword: IF + - keyword: EXISTS + - table_reference: + - naked_identifier: t + - comma: ',' + - table_reference: + - naked_identifier: t2 +- statement_terminator: ; +- statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - keyword: IF + - keyword: EXISTS + - table_reference: + - naked_identifier: t + - keyword: RESTRICT +- statement_terminator: ; +- statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - keyword: IF + - keyword: EXISTS + - table_reference: + - naked_identifier: t + - keyword: CASCADE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_trigger.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_trigger.sql new file mode 100644 index 000000000..6eedbd550 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_trigger.sql @@ -0,0 +1,5 @@ +DROP TRIGGER trigger_name; + +DROP TRIGGER schema_name.trigger_name; + +DROP TRIGGER IF EXISTS trigger_name; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_trigger.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_trigger.yml new file mode 100644 index 000000000..af23a8147 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/drop_trigger.yml @@ -0,0 +1,26 @@ +file: +- statement: + - drop_trigger_statement: + - keyword: DROP + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: trigger_name +- statement_terminator: ; +- statement: + - drop_trigger_statement: + - keyword: DROP + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: schema_name + - dot: . + - naked_identifier: trigger_name +- statement_terminator: ; +- statement: + - drop_trigger_statement: + - keyword: DROP + - keyword: TRIGGER + - keyword: IF + - keyword: EXISTS + - trigger_reference: + - naked_identifier: trigger_name +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt.sql new file mode 100644 index 000000000..99f480d99 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt.sql @@ -0,0 +1 @@ +execute test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt.yml new file mode 100644 index 000000000..1247a205d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt.yml @@ -0,0 +1,6 @@ +file: +- statement: + - execute_segment: + - keyword: execute + - naked_identifier: test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using.sql new file mode 100644 index 000000000..26256840c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using.sql @@ -0,0 +1 @@ +execute test using @test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using.yml new file mode 100644 index 000000000..b7bb5b19d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using.yml @@ -0,0 +1,8 @@ +file: +- statement: + - execute_segment: + - keyword: execute + - naked_identifier: test + - keyword: using + - variable: '@test' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using_multiple_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using_multiple_variable.sql new file mode 100644 index 000000000..b2cd9fb27 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using_multiple_variable.sql @@ -0,0 +1 @@ +execute test using @test, @test1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using_multiple_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using_multiple_variable.yml new file mode 100644 index 000000000..20cc737e3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/execute_prepared_stmt_using_multiple_variable.yml @@ -0,0 +1,10 @@ +file: +- statement: + - execute_segment: + - keyword: execute + - naked_identifier: test + - keyword: using + - variable: '@test' + - comma: ',' + - variable: '@test1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/explain.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/explain.sql new file mode 100644 index 000000000..95b72eba3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/explain.sql @@ -0,0 +1,7 @@ +explain select 1; + +explain update tbl set foo = 1 where bar = 2; + +explain delete from tbl where foo = 1; + +explain insert into tbl (col1) values (123); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/explain.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/explain.yml new file mode 100644 index 000000000..c827edec0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/explain.yml @@ -0,0 +1,75 @@ +file: +- statement: + - explain_statement: + - keyword: explain + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - explain_statement: + - keyword: explain + - update_statement: + - keyword: update + - table_reference: + - naked_identifier: tbl + - set_clause_list: + - keyword: set + - set_clause: + - column_reference: + - naked_identifier: foo + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - where_clause: + - keyword: where + - expression: + - column_reference: + - naked_identifier: bar + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - explain_statement: + - keyword: explain + - delete_statement: + - keyword: delete + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl + - where_clause: + - keyword: where + - expression: + - column_reference: + - naked_identifier: foo + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - explain_statement: + - keyword: explain + - insert_statement: + - keyword: insert + - keyword: into + - table_reference: + - naked_identifier: tbl + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - values_clause: + - keyword: values + - bracketed: + - start_bracket: ( + - numeric_literal: '123' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch.sql new file mode 100644 index 000000000..fb51c83ed --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch.sql @@ -0,0 +1 @@ +fetch curcursor into test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch.yml new file mode 100644 index 000000000..17c8fdab3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch.yml @@ -0,0 +1,8 @@ +file: +- statement: + - cursor_fetch_segment: + - keyword: fetch + - naked_identifier: curcursor + - keyword: into + - variable: test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_from.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_from.sql new file mode 100644 index 000000000..25a2e382e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_from.sql @@ -0,0 +1 @@ +fetch from curcursor into test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_from.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_from.yml new file mode 100644 index 000000000..ac9921ebc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_from.yml @@ -0,0 +1,9 @@ +file: +- statement: + - cursor_fetch_segment: + - keyword: fetch + - keyword: from + - naked_identifier: curcursor + - keyword: into + - variable: test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_multiple.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_multiple.sql new file mode 100644 index 000000000..66dc7b9f4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_multiple.sql @@ -0,0 +1 @@ +fetch curcursor into test, test2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_multiple.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_multiple.yml new file mode 100644 index 000000000..294922de1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_multiple.yml @@ -0,0 +1,10 @@ +file: +- statement: + - cursor_fetch_segment: + - keyword: fetch + - naked_identifier: curcursor + - keyword: into + - variable: test + - comma: ',' + - variable: test2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_next_from.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_next_from.sql new file mode 100644 index 000000000..0a0c5b8a3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_next_from.sql @@ -0,0 +1 @@ +fetch next from curcursor into test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_next_from.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_next_from.yml new file mode 100644 index 000000000..c0aa8620e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_next_from.yml @@ -0,0 +1,10 @@ +file: +- statement: + - cursor_fetch_segment: + - keyword: fetch + - keyword: next + - keyword: from + - naked_identifier: curcursor + - keyword: into + - variable: test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session.sql new file mode 100644 index 000000000..588a4e4f9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session.sql @@ -0,0 +1 @@ +fetch curcursor into @test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session.yml new file mode 100644 index 000000000..d7bd37cc1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session.yml @@ -0,0 +1,8 @@ +file: +- statement: + - cursor_fetch_segment: + - keyword: fetch + - naked_identifier: curcursor + - keyword: into + - variable: '@test' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session_multiple.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session_multiple.sql new file mode 100644 index 000000000..88507d69f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session_multiple.sql @@ -0,0 +1 @@ +fetch curcursor into @test, @test2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session_multiple.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session_multiple.yml new file mode 100644 index 000000000..d6a00f0eb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/fetch_session_multiple.yml @@ -0,0 +1,10 @@ +file: +- statement: + - cursor_fetch_segment: + - keyword: fetch + - naked_identifier: curcursor + - keyword: into + - variable: '@test' + - comma: ',' + - variable: '@test2' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/flush.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/flush.sql new file mode 100644 index 000000000..8d0c1c383 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/flush.sql @@ -0,0 +1,10 @@ +FLUSH LOGS; +FLUSH NO_WRITE_TO_BINLOG BINARY LOGS, ENGINE LOGS, ERROR LOGS, GENERAL LOGS, HOSTS; +FLUSH LOCAL PRIVILEGES, OPTIMIZER_COSTS, RELAY LOGS, SLOW LOGS, STATUS, USER_RESOURCES; +FLUSH RELAY LOGS FOR CHANNEL my_channel; +FLUSH TABLES; +FLUSH TABLES WITH READ LOCK; +FLUSH TABLES table1; +FLUSH TABLES table1, `foo`.`bar`; +FLUSH TABLES table1, `foo`.`bar` WITH READ LOCK; +FLUSH TABLES table1, `foo`.`bar` FOR EXPORT; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/flush.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/flush.yml new file mode 100644 index 000000000..e84eca360 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/flush.yml @@ -0,0 +1,113 @@ +file: +- statement: + - flush_statement: + - keyword: FLUSH + - keyword: LOGS +- statement_terminator: ; +- statement: + - flush_statement: + - keyword: FLUSH + - keyword: NO_WRITE_TO_BINLOG + - keyword: BINARY + - keyword: LOGS + - comma: ',' + - keyword: ENGINE + - keyword: LOGS + - comma: ',' + - keyword: ERROR + - keyword: LOGS + - comma: ',' + - keyword: GENERAL + - keyword: LOGS + - comma: ',' + - keyword: HOSTS +- statement_terminator: ; +- statement: + - flush_statement: + - keyword: FLUSH + - keyword: LOCAL + - keyword: PRIVILEGES + - comma: ',' + - keyword: OPTIMIZER_COSTS + - comma: ',' + - keyword: RELAY + - keyword: LOGS + - comma: ',' + - keyword: SLOW + - keyword: LOGS + - comma: ',' + - keyword: STATUS + - comma: ',' + - keyword: USER_RESOURCES +- statement_terminator: ; +- statement: + - flush_statement: + - keyword: FLUSH + - keyword: RELAY + - keyword: LOGS + - keyword: FOR + - keyword: CHANNEL + - object_reference: + - naked_identifier: my_channel +- statement_terminator: ; +- statement: + - flush_statement: + - keyword: FLUSH + - keyword: TABLES +- statement_terminator: ; +- statement: + - flush_statement: + - keyword: FLUSH + - keyword: TABLES + - keyword: WITH + - keyword: READ + - keyword: LOCK +- statement_terminator: ; +- statement: + - flush_statement: + - keyword: FLUSH + - keyword: TABLES + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - flush_statement: + - keyword: FLUSH + - keyword: TABLES + - table_reference: + - naked_identifier: table1 + - comma: ',' + - table_reference: + - quoted_identifier: '`foo`' + - dot: . + - quoted_identifier: '`bar`' +- statement_terminator: ; +- statement: + - flush_statement: + - keyword: FLUSH + - keyword: TABLES + - table_reference: + - naked_identifier: table1 + - comma: ',' + - table_reference: + - quoted_identifier: '`foo`' + - dot: . + - quoted_identifier: '`bar`' + - keyword: WITH + - keyword: READ + - keyword: LOCK +- statement_terminator: ; +- statement: + - flush_statement: + - keyword: FLUSH + - keyword: TABLES + - table_reference: + - naked_identifier: table1 + - comma: ',' + - table_reference: + - quoted_identifier: '`foo`' + - dot: . + - quoted_identifier: '`bar`' + - keyword: FOR + - keyword: EXPORT +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index.sql new file mode 100644 index 000000000..281700d33 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index.sql @@ -0,0 +1 @@ +SELECT * FROM onetable FORCE INDEX (idx_index); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/implicit_alias_test.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index.yml similarity index 53% rename from crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/implicit_alias_test.yml rename to crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index.yml index c70331164..565c1cc08 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/implicit_alias_test.yml +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index.yml @@ -4,23 +4,22 @@ file: - select_clause: - keyword: SELECT - select_clause_element: - - function: - - function_name: - - function_name_identifier: SUM - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: col1 - - end_bracket: ) - - alias_expression: - - naked_identifier: implicit_alias + - wildcard_expression: + - wildcard_identifier: + - star: '*' - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - table_reference: + - naked_identifier: onetable + - index_hint_clause: + - keyword: FORCE + - keyword: INDEX + - bracketed: + - start_bracket: ( - object_reference: - - naked_identifier: table1 + - naked_identifier: idx_index + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_group_by.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_group_by.sql new file mode 100644 index 000000000..229812045 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_group_by.sql @@ -0,0 +1 @@ +SELECT * FROM onetable FORCE INDEX FOR GROUP BY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_group_by.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_group_by.yml new file mode 100644 index 000000000..5c86445e9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_group_by.yml @@ -0,0 +1,28 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - index_hint_clause: + - keyword: FORCE + - keyword: INDEX + - keyword: FOR + - keyword: GROUP + - keyword: BY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_join.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_join.sql new file mode 100644 index 000000000..7628932ea --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_join.sql @@ -0,0 +1 @@ +SELECT * FROM onetable FORCE INDEX FOR JOIN (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alias_equals_syntax.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_join.yml similarity index 53% rename from crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alias_equals_syntax.yml rename to crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_join.yml index 34a912568..34b83095a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alias_equals_syntax.yml +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_join.yml @@ -4,23 +4,24 @@ file: - select_clause: - keyword: SELECT - select_clause_element: - - naked_identifier: TsqlAlias - - raw_comparison_operator: = - - function: - - function_name: - - function_name_identifier: SUM - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: quantity - - end_bracket: ) + - wildcard_expression: + - wildcard_identifier: + - star: '*' - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - table_reference: + - naked_identifier: onetable + - index_hint_clause: + - keyword: FORCE + - keyword: INDEX + - keyword: FOR + - keyword: JOIN + - bracketed: + - start_bracket: ( - object_reference: - - naked_identifier: table1 + - naked_identifier: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_order_by.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_order_by.sql new file mode 100644 index 000000000..3e8797866 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_order_by.sql @@ -0,0 +1 @@ +SELECT * FROM onetable FORCE INDEX FOR ORDER BY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_order_by.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_order_by.yml new file mode 100644 index 000000000..3f3a01958 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_for_order_by.yml @@ -0,0 +1,28 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - index_hint_clause: + - keyword: FORCE + - keyword: INDEX + - keyword: FOR + - keyword: ORDER + - keyword: BY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_inner_join.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_inner_join.sql new file mode 100644 index 000000000..18a4652e5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_inner_join.sql @@ -0,0 +1 @@ +SELECT onetable.f1, twotable.f1 FROM onetable FORCE INDEX (idx_index) inner join twotable on onetable.f1 = twotable.f1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_inner_join.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_inner_join.yml new file mode 100644 index 000000000..0fe36df77 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_inner_join.yml @@ -0,0 +1,52 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: onetable + - dot: . + - naked_identifier: f1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: twotable + - dot: . + - naked_identifier: f1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - index_hint_clause: + - keyword: FORCE + - keyword: INDEX + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: idx_index + - end_bracket: ) + - join_clause: + - keyword: inner + - keyword: join + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: twotable + - join_on_condition: + - keyword: on + - expression: + - column_reference: + - naked_identifier: onetable + - dot: . + - naked_identifier: f1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: twotable + - dot: . + - naked_identifier: f1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_left_join.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_left_join.sql new file mode 100644 index 000000000..8e0b62fd6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_left_join.sql @@ -0,0 +1 @@ +SELECT onetable.f1, twotable.f1 FROM onetable left join twotable FORCE INDEX (idx_index) on onetable.f1 = twotable.f1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_left_join.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_left_join.yml new file mode 100644 index 000000000..a4c260db0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_index_left_join.yml @@ -0,0 +1,52 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: onetable + - dot: . + - naked_identifier: f1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: twotable + - dot: . + - naked_identifier: f1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - join_clause: + - keyword: left + - keyword: join + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: twotable + - index_hint_clause: + - keyword: FORCE + - keyword: INDEX + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: idx_index + - end_bracket: ) + - join_on_condition: + - keyword: on + - expression: + - column_reference: + - naked_identifier: onetable + - dot: . + - naked_identifier: f1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: twotable + - dot: . + - naked_identifier: f1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_key.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_key.sql new file mode 100644 index 000000000..a351aff99 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_key.sql @@ -0,0 +1 @@ +SELECT * FROM onetable FORCE KEY (idx_index); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_key.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_key.yml new file mode 100644 index 000000000..223c3597b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/force_key.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - index_hint_clause: + - keyword: FORCE + - keyword: KEY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: idx_index + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_comment.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_comment.sql new file mode 100644 index 000000000..038a72db8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_comment.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION `testfunction`(var1 int) +RETURNS longtext +COMMENT 'this is a comment' +DETERMINISTIC +BEGIN +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_comment.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_comment.yml new file mode 100644 index 000000000..e3cf8a31d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_comment.yml @@ -0,0 +1,29 @@ +file: +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - quoted_identifier: '`testfunction`' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: var1 + - data_type: + - data_type_identifier: int + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: longtext + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''this is a comment''' + - characteristic_statement: + - keyword: DETERMINISTIC + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_definer.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_definer.sql new file mode 100644 index 000000000..9ca72c26d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_definer.sql @@ -0,0 +1,6 @@ +CREATE DEFINER=`test`@`%` FUNCTION `testfunction`() +RETURNS longtext +DETERMINISTIC +BEGIN +SELECT 1; +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_definer.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_definer.yml new file mode 100644 index 000000000..61f6d99d2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_definer.yml @@ -0,0 +1,38 @@ +file: +- statement: + - create_function_statement: + - keyword: CREATE + - definer_segment: + - keyword: DEFINER + - comparison_operator: + - raw_comparison_operator: = + - role_reference: + - quoted_identifier: '`test`' + - at_sign_literal: '@' + - quoted_identifier: '`%`' + - keyword: FUNCTION + - function_name: + - quoted_identifier: '`testfunction`' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: longtext + - characteristic_statement: + - keyword: DETERMINISTIC + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_modifies_sql.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_modifies_sql.sql new file mode 100644 index 000000000..38784526d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_modifies_sql.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION `add`(test int) +RETURNS longtext +DETERMINISTIC +MODIFIES SQL DATA +BEGIN +SELECT 1 + 2; +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_modifies_sql.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_modifies_sql.yml new file mode 100644 index 000000000..bb1b27492 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_modifies_sql.yml @@ -0,0 +1,39 @@ +file: +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - quoted_identifier: '`add`' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: test + - data_type: + - data_type_identifier: int + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: longtext + - characteristic_statement: + - keyword: DETERMINISTIC + - keyword: MODIFIES + - keyword: SQL + - keyword: DATA + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: + + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_no_sql.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_no_sql.sql new file mode 100644 index 000000000..d4826b788 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_no_sql.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION `add`(test int) +RETURNS longtext +DETERMINISTIC +NO SQL +BEGIN +SELECT 1 + 2; +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_no_sql.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_no_sql.yml new file mode 100644 index 000000000..3f531b421 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_no_sql.yml @@ -0,0 +1,38 @@ +file: +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - quoted_identifier: '`add`' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: test + - data_type: + - data_type_identifier: int + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: longtext + - characteristic_statement: + - keyword: DETERMINISTIC + - keyword: NO + - keyword: SQL + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: + + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_notdeterministic.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_notdeterministic.sql new file mode 100644 index 000000000..611a0570c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_notdeterministic.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION `add`(test int) +RETURNS longtext +NOT DETERMINISTIC +BEGIN +SELECT 1 + 2; +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_notdeterministic.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_notdeterministic.yml new file mode 100644 index 000000000..e276e2050 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_notdeterministic.yml @@ -0,0 +1,37 @@ +file: +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - quoted_identifier: '`add`' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: test + - data_type: + - data_type_identifier: int + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: longtext + - characteristic_statement: + - keyword: NOT + - keyword: DETERMINISTIC + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: + + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_reads_sql.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_reads_sql.sql new file mode 100644 index 000000000..d5c36ff63 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_reads_sql.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION `add`(test int) +RETURNS longtext +DETERMINISTIC +READS SQL DATA +BEGIN +SELECT 1 + 2; +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_reads_sql.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_reads_sql.yml new file mode 100644 index 000000000..da6513cf4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_reads_sql.yml @@ -0,0 +1,39 @@ +file: +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - quoted_identifier: '`add`' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: test + - data_type: + - data_type_identifier: int + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: longtext + - characteristic_statement: + - keyword: DETERMINISTIC + - keyword: READS + - keyword: SQL + - keyword: DATA + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: + + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_return.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_return.sql new file mode 100644 index 000000000..d0cb6926c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_return.sql @@ -0,0 +1,6 @@ +CREATE FUNCTION `testfunction`(var1 int) +RETURNS int +DETERMINISTIC +BEGIN +RETURN (var1 + 1); +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_return.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_return.yml new file mode 100644 index 000000000..616cabaad --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_return.yml @@ -0,0 +1,39 @@ +file: +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - quoted_identifier: '`testfunction`' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: var1 + - data_type: + - data_type_identifier: int + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: int + - characteristic_statement: + - keyword: DETERMINISTIC + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - return_statement: + - keyword: RETURN + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: var1 + - binary_operator: + + - numeric_literal: '1' + - end_bracket: ) +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_definer.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_definer.sql new file mode 100644 index 000000000..c171bbbdc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_definer.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION `add`(test int) +RETURNS longtext +DETERMINISTIC +SQL SECURITY DEFINER +BEGIN +SELECT 1 + 2; +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_definer.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_definer.yml new file mode 100644 index 000000000..bf152737e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_definer.yml @@ -0,0 +1,39 @@ +file: +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - quoted_identifier: '`add`' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: test + - data_type: + - data_type_identifier: int + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: longtext + - characteristic_statement: + - keyword: DETERMINISTIC + - keyword: SQL + - keyword: SECURITY + - keyword: DEFINER + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: + + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_invoker.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_invoker.sql new file mode 100644 index 000000000..cecfe46fe --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_invoker.sql @@ -0,0 +1,7 @@ +CREATE FUNCTION `add`(test int) +RETURNS longtext +DETERMINISTIC +SQL SECURITY INVOKER +BEGIN +SELECT 1 + 2; +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_invoker.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_invoker.yml new file mode 100644 index 000000000..d42ac58cc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/function_sql_security_invoker.yml @@ -0,0 +1,39 @@ +file: +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - quoted_identifier: '`add`' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: test + - data_type: + - data_type_identifier: int + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: longtext + - characteristic_statement: + - keyword: DETERMINISTIC + - keyword: SQL + - keyword: SECURITY + - keyword: INVOKER + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: + + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_local_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_local_variable.sql new file mode 100644 index 000000000..fd5e392fd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_local_variable.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS CONDITION 1 _test = CLASS_ORIGIN; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_local_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_local_variable.yml new file mode 100644 index 000000000..606970a95 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_local_variable.yml @@ -0,0 +1,12 @@ +file: +- statement: + - get_diagnostics_segment: + - keyword: GET + - keyword: DIAGNOSTICS + - keyword: CONDITION + - variable: '1' + - variable: _test + - comparison_operator: + - raw_comparison_operator: = + - keyword: CLASS_ORIGIN +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_multiple_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_multiple_variable.sql new file mode 100644 index 000000000..718ce4ff0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_multiple_variable.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS CONDITION 1 _test = CLASS_ORIGIN, @test = TABLE_NAME; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_multiple_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_multiple_variable.yml new file mode 100644 index 000000000..aaaf96d80 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_multiple_variable.yml @@ -0,0 +1,17 @@ +file: +- statement: + - get_diagnostics_segment: + - keyword: GET + - keyword: DIAGNOSTICS + - keyword: CONDITION + - variable: '1' + - variable: _test + - comparison_operator: + - raw_comparison_operator: = + - keyword: CLASS_ORIGIN + - comma: ',' + - variable: '@test' + - comparison_operator: + - raw_comparison_operator: = + - keyword: TABLE_NAME +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_session_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_session_variable.sql new file mode 100644 index 000000000..104af70b2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_session_variable.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS CONDITION 1 @test = CLASS_ORIGIN; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_session_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_session_variable.yml new file mode 100644 index 000000000..9e01347ea --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_info_session_variable.yml @@ -0,0 +1,12 @@ +file: +- statement: + - get_diagnostics_segment: + - keyword: GET + - keyword: DIAGNOSTICS + - keyword: CONDITION + - variable: '1' + - variable: '@test' + - comparison_operator: + - raw_comparison_operator: = + - keyword: CLASS_ORIGIN +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_local_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_local_variable.sql new file mode 100644 index 000000000..2ca80746f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_local_variable.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS CONDITION _test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_local_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_local_variable.yml new file mode 100644 index 000000000..d0bf3a28a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_local_variable.yml @@ -0,0 +1,8 @@ +file: +- statement: + - get_diagnostics_segment: + - keyword: GET + - keyword: DIAGNOSTICS + - keyword: CONDITION + - variable: _test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_numeric.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_numeric.sql new file mode 100644 index 000000000..5e7371e1b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_numeric.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS CONDITION 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_numeric.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_numeric.yml new file mode 100644 index 000000000..71e9184b5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_numeric.yml @@ -0,0 +1,8 @@ +file: +- statement: + - get_diagnostics_segment: + - keyword: GET + - keyword: DIAGNOSTICS + - keyword: CONDITION + - variable: '1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_session_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_session_variable.sql new file mode 100644 index 000000000..73f242742 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_session_variable.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS CONDITION @test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_session_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_session_variable.yml new file mode 100644 index 000000000..015029418 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_condition_session_variable.yml @@ -0,0 +1,8 @@ +file: +- statement: + - get_diagnostics_segment: + - keyword: GET + - keyword: DIAGNOSTICS + - keyword: CONDITION + - variable: '@test' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_number.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_number.sql new file mode 100644 index 000000000..445b122fd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_number.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS @a = NUMBER CONDITION 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_number.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_number.yml new file mode 100644 index 000000000..e4370a172 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_number.yml @@ -0,0 +1,12 @@ +file: +- statement: + - get_diagnostics_segment: + - keyword: GET + - keyword: DIAGNOSTICS + - variable: '@a' + - comparison_operator: + - raw_comparison_operator: = + - keyword: NUMBER + - keyword: CONDITION + - variable: '1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_row_count.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_row_count.sql new file mode 100644 index 000000000..cfd9cc622 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_row_count.sql @@ -0,0 +1 @@ +GET DIAGNOSTICS @a = ROW_COUNT CONDITION 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_row_count.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_row_count.yml new file mode 100644 index 000000000..8c0c48d48 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/get_diagnostics_row_count.yml @@ -0,0 +1,12 @@ +file: +- statement: + - get_diagnostics_segment: + - keyword: GET + - keyword: DIAGNOSTICS + - variable: '@a' + - comparison_operator: + - raw_comparison_operator: = + - keyword: ROW_COUNT + - keyword: CONDITION + - variable: '1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/grant.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/grant.sql new file mode 100644 index 000000000..0d0486140 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/grant.sql @@ -0,0 +1,11 @@ +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO prj_svc; +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO 'prj_svc'; +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO "prj_svc"; +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO `prj_svc`; +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO 'prj_svc'@'%'; +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO "prj_svc"@"%"; +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO `prj_svc`@`%`; +GRANT INSERT, UPDATE, DELETE, SELECT, REFERENCES ON prj_table TO `prj_svc` @`%`; +GRANT ALL ON db1.* TO 'prj_svc'@'%'; +GRANT ALL PRIVILEGES ON db1.* TO 'prj_svc'@'localhost'; +GRANT ALL PRIVILEGES ON *.* TO 'prj_svc'@'%'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/grant.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/grant.yml new file mode 100644 index 000000000..f9c9daa14 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/grant.yml @@ -0,0 +1,208 @@ +file: +- statement: + - access_statement: + - keyword: GRANT + - keyword: INSERT + - comma: ',' + - keyword: UPDATE + - comma: ',' + - keyword: DELETE + - comma: ',' + - keyword: SELECT + - comma: ',' + - keyword: REFERENCES + - keyword: ON + - object_reference: + - naked_identifier: prj_table + - keyword: TO + - role_reference: + - naked_identifier: prj_svc +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: INSERT + - comma: ',' + - keyword: UPDATE + - comma: ',' + - keyword: DELETE + - comma: ',' + - keyword: SELECT + - comma: ',' + - keyword: REFERENCES + - keyword: ON + - object_reference: + - naked_identifier: prj_table + - keyword: TO + - role_reference: + - quoted_identifier: '''prj_svc''' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: INSERT + - comma: ',' + - keyword: UPDATE + - comma: ',' + - keyword: DELETE + - comma: ',' + - keyword: SELECT + - comma: ',' + - keyword: REFERENCES + - keyword: ON + - object_reference: + - naked_identifier: prj_table + - keyword: TO + - role_reference: + - quoted_literal: '"prj_svc"' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: INSERT + - comma: ',' + - keyword: UPDATE + - comma: ',' + - keyword: DELETE + - comma: ',' + - keyword: SELECT + - comma: ',' + - keyword: REFERENCES + - keyword: ON + - object_reference: + - naked_identifier: prj_table + - keyword: TO + - role_reference: + - quoted_identifier: '`prj_svc`' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: INSERT + - comma: ',' + - keyword: UPDATE + - comma: ',' + - keyword: DELETE + - comma: ',' + - keyword: SELECT + - comma: ',' + - keyword: REFERENCES + - keyword: ON + - object_reference: + - naked_identifier: prj_table + - keyword: TO + - role_reference: + - quoted_identifier: '''prj_svc''' + - at_sign_literal: '@' + - quoted_identifier: '''%''' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: INSERT + - comma: ',' + - keyword: UPDATE + - comma: ',' + - keyword: DELETE + - comma: ',' + - keyword: SELECT + - comma: ',' + - keyword: REFERENCES + - keyword: ON + - object_reference: + - naked_identifier: prj_table + - keyword: TO + - role_reference: + - quoted_literal: '"prj_svc"' + - at_sign_literal: '@' + - quoted_literal: '"%"' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: INSERT + - comma: ',' + - keyword: UPDATE + - comma: ',' + - keyword: DELETE + - comma: ',' + - keyword: SELECT + - comma: ',' + - keyword: REFERENCES + - keyword: ON + - object_reference: + - naked_identifier: prj_table + - keyword: TO + - role_reference: + - quoted_identifier: '`prj_svc`' + - at_sign_literal: '@' + - quoted_identifier: '`%`' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: INSERT + - comma: ',' + - keyword: UPDATE + - comma: ',' + - keyword: DELETE + - comma: ',' + - keyword: SELECT + - comma: ',' + - keyword: REFERENCES + - keyword: ON + - object_reference: + - naked_identifier: prj_table + - keyword: TO + - role_reference: + - quoted_identifier: '`prj_svc`' + - at_sign_literal: '@' + - quoted_identifier: '`%`' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: ALL + - keyword: ON + - wildcard_identifier: + - naked_identifier: db1 + - dot: . + - star: '*' + - keyword: TO + - role_reference: + - quoted_identifier: '''prj_svc''' + - at_sign_literal: '@' + - quoted_identifier: '''%''' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: ALL + - keyword: PRIVILEGES + - keyword: ON + - wildcard_identifier: + - naked_identifier: db1 + - dot: . + - star: '*' + - keyword: TO + - role_reference: + - quoted_identifier: '''prj_svc''' + - at_sign_literal: '@' + - quoted_identifier: '''localhost''' +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: ALL + - keyword: PRIVILEGES + - keyword: ON + - wildcard_identifier: + - star: '*' + - dot: . + - star: '*' + - keyword: TO + - role_reference: + - quoted_identifier: '''prj_svc''' + - at_sign_literal: '@' + - quoted_identifier: '''%''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_condition_name.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_condition_name.sql new file mode 100644 index 000000000..e747b33d4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_condition_name.sql @@ -0,0 +1,4 @@ +DECLARE exit handler for conditionName +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_condition_name.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_condition_name.yml new file mode 100644 index 000000000..00dc4a224 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_condition_name.yml @@ -0,0 +1,22 @@ +file: +- statement: + - declare_statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - naked_identifier: conditionName + - statement: + - transaction_statement: + - keyword: begin + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: end +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_continue_sqlexception.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_continue_sqlexception.yml new file mode 100644 index 000000000..5a68bbbb2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_continue_sqlexception.yml @@ -0,0 +1,22 @@ +file: +- statement: + declare_statement: + - keyword: DECLARE + - keyword: continue + - keyword: handler + - keyword: for + - keyword: sqlexception + - statement: + transaction_statement: + keyword: begin + statement: + select_statement: + select_clause: + keyword: select + select_clause_element: + literal: '1' +- statement_terminator: ; +- statement: + transaction_statement: + keyword: end +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_error_code.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_error_code.sql new file mode 100644 index 000000000..93d0003d3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_error_code.sql @@ -0,0 +1,4 @@ +DECLARE exit handler for 1051 +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_error_code.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_error_code.yml new file mode 100644 index 000000000..0848f65a2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_error_code.yml @@ -0,0 +1,22 @@ +file: +- statement: + - declare_statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - numeric_literal: '1051' + - statement: + - transaction_statement: + - keyword: begin + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: end +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_exit_sqlexception.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_exit_sqlexception.yml new file mode 100644 index 000000000..37b371f19 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_exit_sqlexception.yml @@ -0,0 +1,22 @@ +file: +- statement: + declare_statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - keyword: sqlexception + - statement: + transaction_statement: + keyword: begin + statement: + select_statement: + select_clause: + keyword: select + select_clause_element: + literal: '1' +- statement_terminator: ; +- statement: + transaction_statement: + keyword: end +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_not_found.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_not_found.sql new file mode 100644 index 000000000..1c6f21e20 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_not_found.sql @@ -0,0 +1,4 @@ +DECLARE exit handler for not found +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_not_found.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_not_found.yml new file mode 100644 index 000000000..12f6b87c9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_not_found.yml @@ -0,0 +1,23 @@ +file: +- statement: + - declare_statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - keyword: not + - keyword: found + - statement: + - transaction_statement: + - keyword: begin + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: end +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate.sql new file mode 100644 index 000000000..39de5a8c9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate.sql @@ -0,0 +1,4 @@ +DECLARE exit handler for SQLSTATE '1' +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate.yml new file mode 100644 index 000000000..6868e7450 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate.yml @@ -0,0 +1,23 @@ +file: +- statement: + - declare_statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - keyword: SQLSTATE + - quoted_literal: '''1''' + - statement: + - transaction_statement: + - keyword: begin + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: end +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate_value.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate_value.sql new file mode 100644 index 000000000..461c3e12f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate_value.sql @@ -0,0 +1,4 @@ +DECLARE exit handler for SQLSTATE VALUE '1' +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate_value.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate_value.yml new file mode 100644 index 000000000..913136c89 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlstate_value.yml @@ -0,0 +1,24 @@ +file: +- statement: + - declare_statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - keyword: SQLSTATE + - keyword: VALUE + - quoted_literal: '''1''' + - statement: + - transaction_statement: + - keyword: begin + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: end +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlwarning.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlwarning.sql new file mode 100644 index 000000000..8e2bc3df1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlwarning.sql @@ -0,0 +1,4 @@ +DECLARE exit handler for sqlwarning +begin +select 1; +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlwarning.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlwarning.yml new file mode 100644 index 000000000..67d29a5d3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_sqlwarning.yml @@ -0,0 +1,22 @@ +file: +- statement: + - declare_statement: + - keyword: DECLARE + - keyword: exit + - keyword: handler + - keyword: for + - keyword: sqlwarning + - statement: + - transaction_statement: + - keyword: begin + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: end +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_undo_sqlexception.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_undo_sqlexception.yml new file mode 100644 index 000000000..05879b995 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/handler_undo_sqlexception.yml @@ -0,0 +1,22 @@ +file: +- statement: + declare_statement: + - keyword: DECLARE + - keyword: undo + - keyword: handler + - keyword: for + - keyword: sqlexception + - statement: + transaction_statement: + keyword: begin + statement: + select_statement: + select_clause: + keyword: select + select_clause_element: + literal: '1' +- statement_terminator: ; +- statement: + transaction_statement: + keyword: end +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/help_statement.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/help_statement.sql new file mode 100644 index 000000000..0857cd415 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/help_statement.sql @@ -0,0 +1,6 @@ +HELP 'contents'; +HELP 'data types'; +HELP 'ascii'; +HELP 'create table'; +HELP 'status'; +HELP 'functions'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/help_statement.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/help_statement.yml new file mode 100644 index 000000000..2b7fb1d80 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/help_statement.yml @@ -0,0 +1,31 @@ +file: +- statement: + - help_statement: + - keyword: HELP + - quoted_literal: '''contents''' +- statement_terminator: ; +- statement: + - help_statement: + - keyword: HELP + - quoted_literal: '''data types''' +- statement_terminator: ; +- statement: + - help_statement: + - keyword: HELP + - quoted_literal: '''ascii''' +- statement_terminator: ; +- statement: + - help_statement: + - keyword: HELP + - quoted_literal: '''create table''' +- statement_terminator: ; +- statement: + - help_statement: + - keyword: HELP + - quoted_literal: '''status''' +- statement_terminator: ; +- statement: + - help_statement: + - keyword: HELP + - quoted_literal: '''functions''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/hexadecimal_literal.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/hexadecimal_literal.sql new file mode 100644 index 000000000..d029ee2b8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/hexadecimal_literal.sql @@ -0,0 +1,6 @@ +SELECT X'01AF'; +SELECT X'01af'; +SELECT x'01AF'; +SELECT x'01af'; +SELECT 0x01AF; +SELECT 0x01af; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/hexadecimal_literal.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/hexadecimal_literal.yml new file mode 100644 index 000000000..807a3367f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/hexadecimal_literal.yml @@ -0,0 +1,43 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: X'01AF' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: X'01af' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: x'01AF' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: x'01af' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '0x01AF' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '0x01af' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if.sql new file mode 100644 index 000000000..51a10d001 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if.sql @@ -0,0 +1,4 @@ +if (x = 0) then +set @errmsg = ''; +select 1; +end if; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if.yml new file mode 100644 index 000000000..237f98841 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if.yml @@ -0,0 +1,35 @@ +file: +- statement: + - if_then_statement: + - keyword: if + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - end_bracket: ) + - keyword: then + - statement: + - set_statement: + - keyword: set + - variable: '@errmsg' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - if_then_statement: + - keyword: end + - keyword: if +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_else.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_else.sql new file mode 100644 index 000000000..ade8a36c1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_else.sql @@ -0,0 +1,5 @@ +if (x = 0) then +set @errmsg = ''; +select 1; +else +end if; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_else.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_else.yml new file mode 100644 index 000000000..11642af6f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_else.yml @@ -0,0 +1,38 @@ +file: +- statement: + - if_then_statement: + - keyword: if + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - end_bracket: ) + - keyword: then + - statement: + - set_statement: + - keyword: set + - variable: '@errmsg' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - if_then_statement: + - keyword: else + - statement: + - if_then_statement: + - keyword: end + - keyword: if +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_elseif.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_elseif.sql new file mode 100644 index 000000000..3350218ee --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_elseif.sql @@ -0,0 +1,8 @@ +if (x = 0) then +set @errmsg = ''; +select 1; +elseif (x = 1) then +set _test = 1; +else +select 2; +end if; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_elseif.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_elseif.yml new file mode 100644 index 000000000..a171dbc97 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_elseif.yml @@ -0,0 +1,67 @@ +file: +- statement: + - if_then_statement: + - keyword: if + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - end_bracket: ) + - keyword: then + - statement: + - set_statement: + - keyword: set + - variable: '@errmsg' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - if_then_statement: + - keyword: elseif + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - end_bracket: ) + - keyword: then + - statement: + - set_statement: + - keyword: set + - variable: _test + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - if_then_statement: + - keyword: else + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - if_then_statement: + - keyword: end + - keyword: if +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_multiple_expression.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_multiple_expression.sql new file mode 100644 index 000000000..42682cdad --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_multiple_expression.sql @@ -0,0 +1,4 @@ +if ((select count(*) from table1) = 0 and x = 1) then +set @errmsg = ''; +select 1; +end if; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_multiple_expression.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_multiple_expression.yml new file mode 100644 index 000000000..0e0845432 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_multiple_expression.yml @@ -0,0 +1,62 @@ +file: +- statement: + - if_then_statement: + - keyword: if + - expression: + - bracketed: + - start_bracket: ( + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - function_name_identifier: count + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - binary_operator: and + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - end_bracket: ) + - keyword: then + - statement: + - set_statement: + - keyword: set + - variable: '@errmsg' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - if_then_statement: + - keyword: end + - keyword: if +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_nested.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_nested.sql new file mode 100644 index 000000000..59a50cc93 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_nested.sql @@ -0,0 +1,7 @@ +if (x = 0) then +select 0; +if (y = 1) then +set @errmsg = ''; +select 1; +end if; +end if; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_nested.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_nested.yml new file mode 100644 index 000000000..68ff4da71 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_nested.yml @@ -0,0 +1,61 @@ +file: +- statement: + - if_then_statement: + - keyword: if + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - end_bracket: ) + - keyword: then + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '0' +- statement_terminator: ; +- statement: + - if_then_statement: + - keyword: if + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: y + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - end_bracket: ) + - keyword: then + - statement: + - set_statement: + - keyword: set + - variable: '@errmsg' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - if_then_statement: + - keyword: end + - keyword: if +- statement_terminator: ; +- statement: + - if_then_statement: + - keyword: end + - keyword: if +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_session_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_session_variable.sql new file mode 100644 index 000000000..df7afe915 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_session_variable.sql @@ -0,0 +1 @@ +if (@x = 0) then set @b = ''; select 1; end if; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_session_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_session_variable.yml new file mode 100644 index 000000000..1fa1da5c4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_session_variable.yml @@ -0,0 +1,34 @@ +file: +- statement: + - if_then_statement: + - keyword: if + - expression: + - bracketed: + - start_bracket: ( + - expression: + - variable: '@x' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - end_bracket: ) + - keyword: then + - statement: + - set_statement: + - keyword: set + - variable: '@b' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - if_then_statement: + - keyword: end + - keyword: if +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_subquery_expression.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_subquery_expression.sql new file mode 100644 index 000000000..61fd6fee1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_subquery_expression.sql @@ -0,0 +1,4 @@ +if ((select count(*) from table1) = 0) then +set @errmsg = ''; +select 1; +end if; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_subquery_expression.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_subquery_expression.yml new file mode 100644 index 000000000..3de305f45 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/if_subquery_expression.yml @@ -0,0 +1,56 @@ +file: +- statement: + - if_then_statement: + - keyword: if + - expression: + - bracketed: + - start_bracket: ( + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - function_name_identifier: count + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - end_bracket: ) + - keyword: then + - statement: + - set_statement: + - keyword: set + - variable: '@errmsg' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - if_then_statement: + - keyword: end + - keyword: if +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index.sql new file mode 100644 index 000000000..8fc5c7e81 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index.sql @@ -0,0 +1 @@ +SELECT * FROM onetable IGNORE INDEX (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index.yml new file mode 100644 index 000000000..b0dba86ed --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - index_hint_clause: + - keyword: IGNORE + - keyword: INDEX + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_group_by.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_group_by.sql new file mode 100644 index 000000000..49fb323cf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_group_by.sql @@ -0,0 +1 @@ +SELECT * FROM onetable IGNORE INDEX FOR GROUP BY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_group_by.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_group_by.yml new file mode 100644 index 000000000..aa54c1ef6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_group_by.yml @@ -0,0 +1,28 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - index_hint_clause: + - keyword: IGNORE + - keyword: INDEX + - keyword: FOR + - keyword: GROUP + - keyword: BY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_join.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_join.sql new file mode 100644 index 000000000..6484ba5a9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_join.sql @@ -0,0 +1 @@ +SELECT * FROM onetable IGNORE INDEX FOR JOIN (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_join.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_join.yml new file mode 100644 index 000000000..a2ea9df74 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_join.yml @@ -0,0 +1,27 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - index_hint_clause: + - keyword: IGNORE + - keyword: INDEX + - keyword: FOR + - keyword: JOIN + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_order_by.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_order_by.sql new file mode 100644 index 000000000..1120499ed --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_order_by.sql @@ -0,0 +1 @@ +SELECT * FROM onetable IGNORE INDEX FOR ORDER BY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_order_by.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_order_by.yml new file mode 100644 index 000000000..5ed0ac5b1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_index_for_order_by.yml @@ -0,0 +1,28 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - index_hint_clause: + - keyword: IGNORE + - keyword: INDEX + - keyword: FOR + - keyword: ORDER + - keyword: BY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_key.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_key.sql new file mode 100644 index 000000000..a0e51785d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_key.sql @@ -0,0 +1 @@ +SELECT * FROM onetable IGNORE KEY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_key.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_key.yml new file mode 100644 index 000000000..fc86b1212 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/ignore_key.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable + - index_hint_clause: + - keyword: IGNORE + - keyword: KEY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/insert.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/insert.sql new file mode 100644 index 000000000..e476d6bb2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/insert.sql @@ -0,0 +1,31 @@ +INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6); + +INSERT INTO t1 +SELECT * FROM (SELECT c, c+d AS e FROM t2) AS dt; + +INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6) AS t2 +ON DUPLICATE KEY UPDATE c = t2.a+t2.b; + +INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6) AS t2 +ON DUPLICATE KEY UPDATE a = VALUES(a), b = VALUES(b); + +INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6) AS t2(m,n,p) +ON DUPLICATE KEY UPDATE c = m+n; + +INSERT INTO t1 +SELECT * FROM (SELECT c, c+d AS e FROM t2) AS dt +ON DUPLICATE KEY UPDATE b = e; + +INSERT INTO t1 +SELECT * FROM (SELECT c, c+d AS e FROM t2) +ON DUPLICATE KEY UPDATE b = e; + +INSERT INTO t1 (a,b,c) +TABLE t2 as t3(m,n,p) +ON DUPLICATE KEY UPDATE b = n+p; + +INSERT INTO t1 SET a=1,b=2,c=3 AS t2 +ON DUPLICATE KEY UPDATE c = t2.a+t2.b; + +INSERT INTO t1 SET a=1,b=2,c=3 AS t2(m,n,p) +ON DUPLICATE KEY UPDATE c = m+n, b = n+p; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/insert.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/insert.yml new file mode 100644 index 000000000..6195607b1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/insert.yml @@ -0,0 +1,578 @@ +file: +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - comma: ',' + - column_reference: + - naked_identifier: c + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '6' + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: c + - binary_operator: + + - column_reference: + - naked_identifier: d + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: e + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: dt +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - comma: ',' + - column_reference: + - naked_identifier: c + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '6' + - end_bracket: ) + - insert_row_alias: + - keyword: AS + - naked_identifier: t2 + - upsert_clause_list: + - keyword: ON + - keyword: DUPLICATE + - keyword: KEY + - keyword: UPDATE + - set_clause: + - column_reference: + - naked_identifier: c + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: a + - binary_operator: + + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: b +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - comma: ',' + - column_reference: + - naked_identifier: c + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '6' + - end_bracket: ) + - insert_row_alias: + - keyword: AS + - naked_identifier: t2 + - upsert_clause_list: + - keyword: ON + - keyword: DUPLICATE + - keyword: KEY + - keyword: UPDATE + - set_clause: + - column_reference: + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: a + - end_bracket: ) + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: b + - comparison_operator: + - raw_comparison_operator: = + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - comma: ',' + - column_reference: + - naked_identifier: c + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '6' + - end_bracket: ) + - insert_row_alias: + - keyword: AS + - naked_identifier: t2 + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: m + - comma: ',' + - naked_identifier: n + - comma: ',' + - naked_identifier: p + - end_bracket: ) + - upsert_clause_list: + - keyword: ON + - keyword: DUPLICATE + - keyword: KEY + - keyword: UPDATE + - set_clause: + - column_reference: + - naked_identifier: c + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: m + - binary_operator: + + - column_reference: + - naked_identifier: n +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: c + - binary_operator: + + - column_reference: + - naked_identifier: d + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: e + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: dt + - upsert_clause_list: + - keyword: ON + - keyword: DUPLICATE + - keyword: KEY + - keyword: UPDATE + - set_clause: + - column_reference: + - naked_identifier: b + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: e +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: c + - binary_operator: + + - column_reference: + - naked_identifier: d + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: e + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - end_bracket: ) + - upsert_clause_list: + - keyword: ON + - keyword: DUPLICATE + - keyword: KEY + - keyword: UPDATE + - set_clause: + - column_reference: + - naked_identifier: b + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: e +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - comma: ',' + - column_reference: + - naked_identifier: c + - end_bracket: ) + - keyword: TABLE + - table_reference: + - naked_identifier: t2 + - insert_row_alias: + - keyword: as + - naked_identifier: t3 + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: m + - comma: ',' + - naked_identifier: n + - comma: ',' + - naked_identifier: p + - end_bracket: ) + - upsert_clause_list: + - keyword: ON + - keyword: DUPLICATE + - keyword: KEY + - keyword: UPDATE + - set_clause: + - column_reference: + - naked_identifier: b + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: n + - binary_operator: + + - column_reference: + - naked_identifier: p +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: b + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: c + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '3' + - insert_row_alias: + - keyword: AS + - naked_identifier: t2 + - upsert_clause_list: + - keyword: ON + - keyword: DUPLICATE + - keyword: KEY + - keyword: UPDATE + - set_clause: + - column_reference: + - naked_identifier: c + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: a + - binary_operator: + + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: b +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: b + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: c + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '3' + - insert_row_alias: + - keyword: AS + - naked_identifier: t2 + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: m + - comma: ',' + - naked_identifier: n + - comma: ',' + - naked_identifier: p + - end_bracket: ) + - upsert_clause_list: + - keyword: ON + - keyword: DUPLICATE + - keyword: KEY + - keyword: UPDATE + - set_clause: + - column_reference: + - naked_identifier: c + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: m + - binary_operator: + + - column_reference: + - naked_identifier: n + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: b + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: n + - binary_operator: + + - column_reference: + - naked_identifier: p +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/interval.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/interval.sql new file mode 100644 index 000000000..0ca2c7e95 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/interval.sql @@ -0,0 +1,23 @@ +SELECT DATE_ADD(CURDATE(), INTERVAL -30 DAY); + +SELECT SUBDATE('2008-01-02', INTERVAL 31 DAY); + +SELECT ADDDATE(CURDATE(), INTERVAL -30 DAY); + +SELECT DATE_SUB('1992-12-31 23:59:59.000002', INTERVAL '1.999999' SECOND_MICROSECOND); + +SELECT DATE_ADD('2100-12-31 23:59:59', INTERVAL '1:1' MINUTE_SECOND); + +SELECT DATE_ADD(CURDATE(), INTERVAL 7 * 4 DAY); + +SELECT + ADDDATE(CURDATE(), INTERVAL col1 DAY) +FROM + tbl1 +; + +SELECT + SUBDATE(CURDATE(), INTERVAL col1 + col2 DAY) +FROM + tbl1 +; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/interval.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/interval.yml new file mode 100644 index 000000000..f12ab3987 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/interval.yml @@ -0,0 +1,232 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATE_ADD + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: CURDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - expression: + - interval_expression: + - keyword: INTERVAL + - expression: + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '30' + - date_part: DAY + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUBDATE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2008-01-02''' + - comma: ',' + - expression: + - interval_expression: + - keyword: INTERVAL + - expression: + - numeric_literal: '31' + - date_part: DAY + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: ADDDATE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: CURDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - expression: + - interval_expression: + - keyword: INTERVAL + - expression: + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '30' + - date_part: DAY + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATE_SUB + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''1992-12-31 23:59:59.000002''' + - comma: ',' + - expression: + - interval_expression: + - keyword: INTERVAL + - expression: + - quoted_literal: '''1.999999''' + - date_part: SECOND_MICROSECOND + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATE_ADD + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2100-12-31 23:59:59''' + - comma: ',' + - expression: + - interval_expression: + - keyword: INTERVAL + - expression: + - quoted_literal: '''1:1''' + - date_part: MINUTE_SECOND + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATE_ADD + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: CURDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - expression: + - interval_expression: + - keyword: INTERVAL + - expression: + - numeric_literal: '7' + - binary_operator: '*' + - numeric_literal: '4' + - date_part: DAY + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: ADDDATE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: CURDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - expression: + - interval_expression: + - keyword: INTERVAL + - expression: + - column_reference: + - naked_identifier: col1 + - date_part: DAY + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUBDATE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: CURDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - expression: + - interval_expression: + - keyword: INTERVAL + - expression: + - column_reference: + - naked_identifier: col1 + - binary_operator: + + - column_reference: + - naked_identifier: col2 + - date_part: DAY + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/json.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/json.sql new file mode 100644 index 000000000..b9236365a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/json.sql @@ -0,0 +1,16 @@ +CREATE TABLE facts (sentence JSON); + +INSERT INTO facts VALUES +(JSON_OBJECT("mascot", "Our mascot is a dolphin named \"Sakila\".")); + +SELECT sentence->"$.mascot" FROM facts; + +SELECT sentence->'$.mascot' FROM facts; + +SELECT sentence->>"$.mascot" FROM facts; + +SELECT sentence->>'$.mascot' FROM facts; + +SELECT sentence FROM facts WHERE JSON_TYPE(sentence->"$.mascot") = "NULL"; + +SELECT sentence FROM facts WHERE sentence->"$.mascot" IS NULL; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/json.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/json.yml new file mode 100644 index 000000000..29aeb0e82 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/json.yml @@ -0,0 +1,169 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: facts + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: sentence + - data_type: + - data_type_identifier: JSON + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: facts + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: JSON_OBJECT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '"mascot"' + - comma: ',' + - expression: + - quoted_literal: '"Our mascot is a dolphin named \"Sakila\"."' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: sentence + - column_path_operator: -> + - quoted_literal: '"$.mascot"' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: facts +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: sentence + - column_path_operator: -> + - quoted_literal: '''$.mascot''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: facts +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: sentence + - column_path_operator: ->> + - quoted_literal: '"$.mascot"' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: facts +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: sentence + - column_path_operator: ->> + - quoted_literal: '''$.mascot''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: facts +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: sentence + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: facts + - where_clause: + - keyword: WHERE + - expression: + - function: + - function_name: + - function_name_identifier: JSON_TYPE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: sentence + - column_path_operator: -> + - quoted_literal: '"$.mascot"' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"NULL"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: sentence + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: facts + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: sentence + - column_path_operator: -> + - quoted_literal: '"$.mascot"' + - keyword: IS + - null_literal: 'NULL' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/load_data.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/load_data.sql new file mode 100644 index 000000000..c55350c66 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/load_data.sql @@ -0,0 +1,31 @@ +LOAD DATA INFILE '/var/lib/mysql-files/libaccess.csv' INTO TABLE libaccess FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '"' IGNORE 1 LINES; +LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table; +LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table PARTITION (partition_name); +LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test + FIELDS TERMINATED BY ',' LINES STARTING BY 'xxx'; +LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test IGNORE 1 LINES; +LOAD DATA INFILE 'data.txt' INTO TABLE table2 + FIELDS TERMINATED BY ','; +LOAD DATA INFILE 'data.txt' INTO TABLE table2 + FIELDS TERMINATED BY '\t'; +LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name + FIELDS TERMINATED BY ',' ENCLOSED BY '"' + LINES TERMINATED BY '\r\n' + IGNORE 1 LINES; +LOAD DATA INFILE '/tmp/jokes.txt' INTO TABLE jokes + FIELDS TERMINATED BY '' + LINES TERMINATED BY '\n%%\n' (joke); +LOAD DATA INFILE 'persondata.txt' INTO TABLE persondata; +LOAD DATA INFILE 'file.txt' + INTO TABLE t1 + (column1, @var1) + SET column2 = @var1/100; +LOAD DATA INFILE 'file.txt' + INTO TABLE t1 + (column1, column2) + SET column3 = CURRENT_TIMESTAMP; +LOAD DATA INFILE 'file.txt' + INTO TABLE t1 + (column1, @dummy, column2, @dummy, column3); +LOAD DATA INFILE '/local/access_log' INTO TABLE tbl_name + FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/load_data.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/load_data.yml new file mode 100644 index 000000000..6c9e08b20 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/load_data.yml @@ -0,0 +1,280 @@ +file: +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INFILE + - quoted_literal: '''/var/lib/mysql-files/libaccess.csv''' + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: libaccess + - keyword: FIELDS + - keyword: TERMINATED + - keyword: BY + - quoted_literal: '''\t''' + - keyword: OPTIONALLY + - keyword: ENCLOSED + - keyword: BY + - quoted_literal: '''"''' + - keyword: IGNORE + - numeric_literal: '1' + - keyword: LINES +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INFILE + - quoted_literal: '''data.txt''' + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: db2 + - dot: . + - naked_identifier: my_table +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INFILE + - quoted_literal: '''data.txt''' + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: db2 + - dot: . + - naked_identifier: my_table + - partition_clause: + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: partition_name + - end_bracket: ) +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INFILE + - quoted_literal: '''/tmp/test.txt''' + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: test + - keyword: FIELDS + - keyword: TERMINATED + - keyword: BY + - quoted_literal: ''',''' + - keyword: LINES + - keyword: STARTING + - keyword: BY + - quoted_literal: '''xxx''' +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INFILE + - quoted_literal: '''/tmp/test.txt''' + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: test + - keyword: IGNORE + - numeric_literal: '1' + - keyword: LINES +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INFILE + - quoted_literal: '''data.txt''' + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: table2 + - keyword: FIELDS + - keyword: TERMINATED + - keyword: BY + - quoted_literal: ''',''' +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INFILE + - quoted_literal: '''data.txt''' + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: table2 + - keyword: FIELDS + - keyword: TERMINATED + - keyword: BY + - quoted_literal: '''\t''' +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INFILE + - quoted_literal: '''data.txt''' + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: tbl_name + - keyword: FIELDS + - keyword: TERMINATED + - keyword: BY + - quoted_literal: ''',''' + - keyword: ENCLOSED + - keyword: BY + - quoted_literal: '''"''' + - keyword: LINES + - keyword: TERMINATED + - keyword: BY + - quoted_literal: '''\r\n''' + - keyword: IGNORE + - numeric_literal: '1' + - keyword: LINES +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INFILE + - quoted_literal: '''/tmp/jokes.txt''' + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: jokes + - keyword: FIELDS + - keyword: TERMINATED + - keyword: BY + - quoted_literal: '''''' + - keyword: LINES + - keyword: TERMINATED + - keyword: BY + - quoted_literal: '''\n%%\n''' + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: joke + - end_bracket: ) +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INFILE + - quoted_literal: '''persondata.txt''' + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: persondata +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INFILE + - quoted_literal: '''file.txt''' + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: column1 + - comma: ',' + - column_reference: + - variable: '@var1' + - end_bracket: ) + - keyword: SET + - column_reference: + - naked_identifier: column2 + - comparison_operator: + - raw_comparison_operator: = + - variable: '@var1' + - binary_operator: / + - numeric_literal: '100' +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INFILE + - quoted_literal: '''file.txt''' + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: column1 + - comma: ',' + - column_reference: + - naked_identifier: column2 + - end_bracket: ) + - keyword: SET + - column_reference: + - naked_identifier: column3 + - comparison_operator: + - raw_comparison_operator: = + - bare_function: CURRENT_TIMESTAMP +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INFILE + - quoted_literal: '''file.txt''' + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: column1 + - comma: ',' + - column_reference: + - variable: '@dummy' + - comma: ',' + - column_reference: + - naked_identifier: column2 + - comma: ',' + - column_reference: + - variable: '@dummy' + - comma: ',' + - column_reference: + - naked_identifier: column3 + - end_bracket: ) +- statement_terminator: ; +- statement: + - load_data_statement: + - keyword: LOAD + - keyword: DATA + - keyword: INFILE + - quoted_literal: '''/local/access_log''' + - keyword: INTO + - keyword: TABLE + - table_reference: + - naked_identifier: tbl_name + - keyword: FIELDS + - keyword: TERMINATED + - keyword: BY + - quoted_literal: ''',''' + - keyword: OPTIONALLY + - keyword: ENCLOSED + - keyword: BY + - quoted_literal: '''"''' + - keyword: ESCAPED + - keyword: BY + - quoted_literal: '''\\''' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_label.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_label.sql new file mode 100644 index 000000000..8d109e400 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_label.sql @@ -0,0 +1 @@ +iteration:loop select 1; iterate iteration; leave iteration; end loop iteration; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_label.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_label.yml new file mode 100644 index 000000000..5c12c153d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_label.yml @@ -0,0 +1,29 @@ +file: +- statement: + - loop_statement: + - naked_identifier: iteration + - colon: ':' + - keyword: loop + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - iterate_statement: + - keyword: iterate + - naked_identifier: iteration +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: leave + - naked_identifier: iteration +- statement_terminator: ; +- statement: + - loop_statement: + - keyword: end + - keyword: loop + - naked_identifier: iteration +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_multiple_statements.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_multiple_statements.sql new file mode 100644 index 000000000..263ee2e17 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_multiple_statements.sql @@ -0,0 +1 @@ +loop select 1; select * from onetable; end loop; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_multiple_statements.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_multiple_statements.yml new file mode 100644 index 000000000..9b4c3e90f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_multiple_statements.yml @@ -0,0 +1,32 @@ +file: +- statement: + - loop_statement: + - keyword: loop + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: onetable +- statement_terminator: ; +- statement: + - loop_statement: + - keyword: end + - keyword: loop +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_no_label.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_no_label.sql new file mode 100644 index 000000000..557ebe302 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_no_label.sql @@ -0,0 +1 @@ +loop select 1; end loop; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_no_label.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_no_label.yml new file mode 100644 index 000000000..26b1a8740 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/loop_no_label.yml @@ -0,0 +1,16 @@ +file: +- statement: + - loop_statement: + - keyword: loop + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - loop_statement: + - keyword: end + - keyword: loop +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/nested_begin.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/nested_begin.sql new file mode 100644 index 000000000..037fa004a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/nested_begin.sql @@ -0,0 +1,5 @@ +blocks:BEGIN +nest:begin +set @abc = 1; +end nest; +END blocks~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/nested_begin.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/nested_begin.yml new file mode 100644 index 000000000..82615e59c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/nested_begin.yml @@ -0,0 +1,29 @@ +file: +- statement: + - transaction_statement: + - naked_identifier: blocks + - colon: ':' + - keyword: BEGIN + - statement: + - transaction_statement: + - naked_identifier: nest + - colon: ':' + - keyword: begin + - statement: + - set_statement: + - keyword: set + - variable: '@abc' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: end + - naked_identifier: nest +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: END + - naked_identifier: blocks +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/null_safe_equal.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/null_safe_equal.sql new file mode 100644 index 000000000..b195e320e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/null_safe_equal.sql @@ -0,0 +1,3 @@ +SELECT 1 <=> 1, NULL <=> NULL, 1 <=> NULL; + +SELECT 1 WHERE NULL <=> 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/null_safe_equal.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/null_safe_equal.yml new file mode 100644 index 000000000..2a110be74 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/null_safe_equal.yml @@ -0,0 +1,48 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - raw_comparison_operator: '>' + - numeric_literal: '1' + - comma: ',' + - select_clause_element: + - expression: + - null_literal: 'NULL' + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - raw_comparison_operator: '>' + - null_literal: 'NULL' + - comma: ',' + - select_clause_element: + - expression: + - numeric_literal: '1' + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - raw_comparison_operator: '>' + - null_literal: 'NULL' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - where_clause: + - keyword: WHERE + - expression: + - null_literal: 'NULL' + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - raw_comparison_operator: '>' + - numeric_literal: '1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open.sql new file mode 100644 index 000000000..b8c64db7a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open.sql @@ -0,0 +1 @@ +open curcursor; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open.yml new file mode 100644 index 000000000..9c309db1e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open.yml @@ -0,0 +1,6 @@ +file: +- statement: + - cursor_open_close_segment: + - keyword: open + - naked_identifier: curcursor +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open_qualified.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open_qualified.sql new file mode 100644 index 000000000..9247612d2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open_qualified.sql @@ -0,0 +1 @@ +open `curcursor`; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open_qualified.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open_qualified.yml new file mode 100644 index 000000000..5a9651d16 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/open_qualified.yml @@ -0,0 +1,6 @@ +file: +- statement: + - cursor_open_close_segment: + - keyword: open + - quoted_identifier: '`curcursor`' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/optimize_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/optimize_table.sql new file mode 100644 index 000000000..e7bda7ad2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/optimize_table.sql @@ -0,0 +1,11 @@ +OPTIMIZE TABLE some_table; + +OPTIMIZE TABLE some_table1, some_table2; + +OPTIMIZE NO_WRITE_TO_BINLOG TABLE some_table; + +OPTIMIZE NO_WRITE_TO_BINLOG TABLE some_table1, some_table2; + +OPTIMIZE LOCAL TABLE some_table; + +OPTIMIZE LOCAL TABLE some_table1, some_table2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/optimize_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/optimize_table.yml new file mode 100644 index 000000000..27397961e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/optimize_table.yml @@ -0,0 +1,56 @@ +file: +- statement: + - optimize_table_statement: + - keyword: OPTIMIZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - optimize_table_statement: + - keyword: OPTIMIZE + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - optimize_table_statement: + - keyword: OPTIMIZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - optimize_table_statement: + - keyword: OPTIMIZE + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - optimize_table_statement: + - keyword: OPTIMIZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - optimize_table_statement: + - keyword: OPTIMIZE + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_local_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_local_variable.sql new file mode 100644 index 000000000..06820e2e9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_local_variable.sql @@ -0,0 +1 @@ +PREPARE test FROM _test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_local_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_local_variable.yml new file mode 100644 index 000000000..11a262e90 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_local_variable.yml @@ -0,0 +1,8 @@ +file: +- statement: + - prepare_segment: + - keyword: PREPARE + - naked_identifier: test + - keyword: FROM + - variable: _test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_session_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_session_variable.sql new file mode 100644 index 000000000..aa1b0aab6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_session_variable.sql @@ -0,0 +1 @@ +PREPARE test FROM @test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_session_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_session_variable.yml new file mode 100644 index 000000000..93ec3bd86 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_session_variable.yml @@ -0,0 +1,8 @@ +file: +- statement: + - prepare_segment: + - keyword: PREPARE + - naked_identifier: test + - keyword: FROM + - variable: '@test' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_statement.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_statement.sql new file mode 100644 index 000000000..a5ea424c7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_statement.sql @@ -0,0 +1 @@ +PREPARE test FROM 'select 1;'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_statement.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_statement.yml new file mode 100644 index 000000000..3ab58d0ae --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/prepare_statement.yml @@ -0,0 +1,8 @@ +file: +- statement: + - prepare_segment: + - keyword: PREPARE + - naked_identifier: test + - keyword: FROM + - quoted_literal: '''select 1;''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_definer.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_definer.sql new file mode 100644 index 000000000..62834e30c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_definer.sql @@ -0,0 +1,3 @@ +CREATE DEFINER=`test`@`%` PROCEDURE `testprocedure`() +BEGIN +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_definer.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_definer.yml new file mode 100644 index 000000000..80086d146 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_definer.yml @@ -0,0 +1,26 @@ +file: +- statement: + - create_procedure_statement: + - keyword: CREATE + - definer_segment: + - keyword: DEFINER + - comparison_operator: + - raw_comparison_operator: = + - role_reference: + - quoted_identifier: '`test`' + - at_sign_literal: '@' + - quoted_identifier: '`%`' + - keyword: PROCEDURE + - function_name: + - quoted_identifier: '`testprocedure`' + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_in_param.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_in_param.sql new file mode 100644 index 000000000..c5b8deb44 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_in_param.sql @@ -0,0 +1,3 @@ +CREATE PROCEDURE `testprocedure`(in test int) +BEGIN +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_in_param.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_in_param.yml new file mode 100644 index 000000000..d364de1e4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_in_param.yml @@ -0,0 +1,22 @@ +file: +- statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - function_name: + - quoted_identifier: '`testprocedure`' + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter_direction: in + - parameter: test + - data_type: + - data_type_identifier: int + - end_bracket: ) + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_inout_param.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_inout_param.sql new file mode 100644 index 000000000..f705521fc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_inout_param.sql @@ -0,0 +1,3 @@ +CREATE PROCEDURE `testprocedure`(inout test int) +BEGIN +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_inout_param.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_inout_param.yml new file mode 100644 index 000000000..56d237c4e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_inout_param.yml @@ -0,0 +1,22 @@ +file: +- statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - function_name: + - quoted_identifier: '`testprocedure`' + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter_direction: inout + - parameter: test + - data_type: + - data_type_identifier: int + - end_bracket: ) + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_out_param.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_out_param.sql new file mode 100644 index 000000000..4585500b9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_out_param.sql @@ -0,0 +1,3 @@ +CREATE PROCEDURE `testprocedure`(out test int) +BEGIN +END~ diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_out_param.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_out_param.yml new file mode 100644 index 000000000..0ef7147b0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/procedure_out_param.yml @@ -0,0 +1,22 @@ +file: +- statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - function_name: + - quoted_identifier: '`testprocedure`' + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter_direction: out + - parameter: test + - data_type: + - data_type_identifier: int + - end_bracket: ) + - function_definition: + - transaction_statement: + - keyword: BEGIN + - statement: + - transaction_statement: + - keyword: END +- statement_terminator: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/purge_binary_logs.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/purge_binary_logs.sql new file mode 100644 index 000000000..d1f5c13ac --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/purge_binary_logs.sql @@ -0,0 +1,7 @@ +PURGE BINARY LOGS TO 'mysql-bin.010'; + +PURGE BINARY LOGS BEFORE '2019-04-02 22:46:26'; +PURGE BINARY LOGS BEFORE TIMESTAMP '2019-04-02 22:46:26'; + +PURGE BINARY LOGS BEFORE 19830905132800; +PURGE BINARY LOGS BEFORE TIMESTAMP 19830905132800; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/purge_binary_logs.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/purge_binary_logs.yml new file mode 100644 index 000000000..c52310bdf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/purge_binary_logs.yml @@ -0,0 +1,47 @@ +file: +- statement: + - purge_binary_logs_statement: + - keyword: PURGE + - keyword: BINARY + - keyword: LOGS + - keyword: TO + - quoted_literal: '''mysql-bin.010''' +- statement_terminator: ; +- statement: + - purge_binary_logs_statement: + - keyword: PURGE + - keyword: BINARY + - keyword: LOGS + - keyword: BEFORE + - expression: + - quoted_literal: '''2019-04-02 22:46:26''' +- statement_terminator: ; +- statement: + - purge_binary_logs_statement: + - keyword: PURGE + - keyword: BINARY + - keyword: LOGS + - keyword: BEFORE + - expression: + - keyword: TIMESTAMP + - date_constructor_literal: '''2019-04-02 22:46:26''' +- statement_terminator: ; +- statement: + - purge_binary_logs_statement: + - keyword: PURGE + - keyword: BINARY + - keyword: LOGS + - keyword: BEFORE + - expression: + - numeric_literal: '19830905132800' +- statement_terminator: ; +- statement: + - purge_binary_logs_statement: + - keyword: PURGE + - keyword: BINARY + - keyword: LOGS + - keyword: BEFORE + - expression: + - keyword: TIMESTAMP + - numeric_literal: '19830905132800' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/quoted_literal.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/quoted_literal.sql new file mode 100644 index 000000000..a2ee306f0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/quoted_literal.sql @@ -0,0 +1,75 @@ +SELECT ''; + +SELECT ""; + +SELECT ''''; + +SELECT """"; + +SELECT ' + +'; + +SELECT " + +"; + +SELECT '''aaa'''; + +SELECT """aaa"""; + +SELECT ' +'' +'; + +SELECT " +"" +"; + +SELECT 'foo' +'bar'; + +SELECT "foo" +"bar"; + +SELECT 'foo' 'bar'; + +SELECT "foo" "bar"; + +SELECT 'foo' "bar"; + +SELECT 'foo' + + +'bar'; + +SELECT "foo" + + +"bar"; + +SELECT 'foo' -- some comment +'bar'; + +SELECT "foo" -- some comment +"bar"; + +SELECT 'foo' /* some comment */ 'bar'; + +SELECT "foo" /* some comment */ "bar"; + +UPDATE table1 SET column1 = 'baz\'s'; + +UPDATE table1 SET column1 = "baz\"s"; + +SELECT 'terminating MySQL-y escaped single-quote bazs\''; + +SELECT "terminating MySQL-y escaped double-quote bazs\""; + +SELECT 'terminating ANSI-ish escaped single-quote '''; + +SELECT "terminating ANSI-ish escaped double-quote """; + +SELECT '\\'; + +SELECT "\\"; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/quoted_literal.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/quoted_literal.yml new file mode 100644 index 000000000..1c40e3ddb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/quoted_literal.yml @@ -0,0 +1,241 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '""' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''''''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '""""' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: |- + ' + + ' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: |- + " + + " +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''''''aaa''''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '"""aaa"""' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: |- + ' + '' + ' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: |- + " + "" + " +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''foo''' + - quoted_literal: '''bar''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '"foo"' + - quoted_literal: '"bar"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''foo''' + - quoted_literal: '''bar''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '"foo"' + - quoted_literal: '"bar"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''foo''' + - quoted_literal: '"bar"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''foo''' + - quoted_literal: '''bar''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '"foo"' + - quoted_literal: '"bar"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''foo''' + - quoted_literal: '''bar''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '"foo"' + - quoted_literal: '"bar"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''foo''' + - quoted_literal: '''bar''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '"foo"' + - quoted_literal: '"bar"' +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: table1 + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: column1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''baz\''s''' +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: table1 + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: column1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"baz\"s"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''terminating MySQL-y escaped single-quote bazs\''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '"terminating MySQL-y escaped double-quote bazs\""' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''terminating ANSI-ish escaped single-quote ''''''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '"terminating ANSI-ish escaped double-quote """' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''\\''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '"\\"' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/rename_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/rename_table.sql new file mode 100644 index 000000000..3871afeff --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/rename_table.sql @@ -0,0 +1,2 @@ +RENAME TABLE old_table TO new_table; +RENAME TABLE old_table1 TO new_table1, old_table2 TO new_table2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/rename_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/rename_table.yml new file mode 100644 index 000000000..a7da9856a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/rename_table.yml @@ -0,0 +1,27 @@ +file: +- statement: + - rename_table_statement: + - keyword: RENAME + - keyword: TABLE + - table_reference: + - naked_identifier: old_table + - keyword: TO + - table_reference: + - naked_identifier: new_table +- statement_terminator: ; +- statement: + - rename_table_statement: + - keyword: RENAME + - keyword: TABLE + - table_reference: + - naked_identifier: old_table1 + - keyword: TO + - table_reference: + - naked_identifier: new_table1 + - comma: ',' + - table_reference: + - naked_identifier: old_table2 + - keyword: TO + - table_reference: + - naked_identifier: new_table2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repair_table.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repair_table.sql new file mode 100644 index 000000000..2ab1bd49a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repair_table.sql @@ -0,0 +1,19 @@ +REPAIR TABLE some_table; + +REPAIR TABLE some_table1, some_table2; + +REPAIR NO_WRITE_TO_BINLOG TABLE some_table; + +REPAIR NO_WRITE_TO_BINLOG TABLE some_table1, some_table2; + +REPAIR LOCAL TABLE some_table; + +REPAIR LOCAL TABLE some_table1, some_table2; + +REPAIR TABLE some_table QUICK; + +REPAIR TABLE some_table EXTENDED; + +REPAIR TABLE some_table USE_FRM; + +REPAIR TABLE some_table QUICK EXTENDED USE_FRM; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repair_table.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repair_table.yml new file mode 100644 index 000000000..61c28c0dc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repair_table.yml @@ -0,0 +1,90 @@ +file: +- statement: + - repair_table_statement: + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - repair_table_statement: + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - repair_table_statement: + - keyword: REPAIR + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - repair_table_statement: + - keyword: REPAIR + - keyword: NO_WRITE_TO_BINLOG + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - repair_table_statement: + - keyword: REPAIR + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table +- statement_terminator: ; +- statement: + - repair_table_statement: + - keyword: REPAIR + - keyword: LOCAL + - keyword: TABLE + - table_reference: + - naked_identifier: some_table1 + - comma: ',' + - table_reference: + - naked_identifier: some_table2 +- statement_terminator: ; +- statement: + - repair_table_statement: + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: QUICK +- statement_terminator: ; +- statement: + - repair_table_statement: + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: EXTENDED +- statement_terminator: ; +- statement: + - repair_table_statement: + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: USE_FRM +- statement_terminator: ; +- statement: + - repair_table_statement: + - keyword: REPAIR + - keyword: TABLE + - table_reference: + - naked_identifier: some_table + - keyword: QUICK + - keyword: EXTENDED + - keyword: USE_FRM +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_label.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_label.sql new file mode 100644 index 000000000..b39b29ee9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_label.sql @@ -0,0 +1 @@ +iteration:repeat set @a = @a + 1; until @a > 5 end repeat iteration; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_label.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_label.yml new file mode 100644 index 000000000..8c64061e2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_label.yml @@ -0,0 +1,29 @@ +file: +- statement: + - repeat_statement: + - naked_identifier: iteration + - colon: ':' + - keyword: repeat + - statement: + - set_statement: + - keyword: set + - variable: '@a' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - variable: '@a' + - binary_operator: + + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - repeat_statement: + - keyword: until + - expression: + - variable: '@a' + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '5' + - keyword: end + - keyword: repeat + - naked_identifier: iteration +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_multiple_statements.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_multiple_statements.sql new file mode 100644 index 000000000..9cabce05b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_multiple_statements.sql @@ -0,0 +1 @@ +repeat set @a = @a + 1; select 1; until @a > 5 and x = 1 end repeat; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_multiple_statements.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_multiple_statements.yml new file mode 100644 index 000000000..cffe08a0f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_multiple_statements.yml @@ -0,0 +1,39 @@ +file: +- statement: + - repeat_statement: + - keyword: repeat + - statement: + - set_statement: + - keyword: set + - variable: '@a' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - variable: '@a' + - binary_operator: + + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - repeat_statement: + - keyword: until + - expression: + - variable: '@a' + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '5' + - binary_operator: and + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - keyword: end + - keyword: repeat +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_no_label.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_no_label.sql new file mode 100644 index 000000000..59a34c8fe --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_no_label.sql @@ -0,0 +1 @@ +repeat set @a = @a + 1; until @a > 5 end repeat; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_no_label.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_no_label.yml new file mode 100644 index 000000000..add273326 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/repeat_no_label.yml @@ -0,0 +1,26 @@ +file: +- statement: + - repeat_statement: + - keyword: repeat + - statement: + - set_statement: + - keyword: set + - variable: '@a' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - variable: '@a' + - binary_operator: + + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - repeat_statement: + - keyword: until + - expression: + - variable: '@a' + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '5' + - keyword: end + - keyword: repeat +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/replace.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/replace.sql new file mode 100644 index 000000000..b5d84110f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/replace.sql @@ -0,0 +1,43 @@ +REPLACE tbl_name VALUES (1, 2); + +REPLACE tbl_name VALUES (DEFAULT, DEFAULT); + +REPLACE tbl_name VALUES (1, 2), (11, 22); + +REPLACE tbl_name VALUE (1, 2), (11, 22); + +REPLACE tbl_name (col1, col2) VALUES (1, 2); + +REPLACE tbl_name (col1, col2) VALUES ROW(1, 2), ROW(11, 22); + +REPLACE LOW_PRIORITY tbl_name VALUES (1, 2); + +REPLACE DELAYED tbl_name VALUES (1, 2); + +REPLACE LOW_PRIORITY INTO tbl_name VALUES (1, 2); + +REPLACE tbl_name PARTITION (partition_name) VALUES (1, 2); + +REPLACE tbl_name SET col1 = 1, col2 = 2; + +REPLACE LOW_PRIORITY tbl_name SET col1 = 1, col2 = 2; + +REPLACE DELAYED tbl_name SET col1 = 1, col2 = 2; + +REPLACE LOW_PRIORITY INTO tbl_name SET col1 = 1, col2 = 2; + +REPLACE tbl_name PARTITION (partition_name) SET col1 = 1, col2 = 2; + +REPLACE tbl_name SELECT * FROM table_name; + +REPLACE tbl_name TABLE table_name; + +REPLACE LOW_PRIORITY tbl_name TABLE table_name; + +REPLACE DELAYED tbl_name TABLE table_name; + +REPLACE LOW_PRIORITY INTO tbl_name TABLE table_name; + +REPLACE tbl_name (col1, col2) TABLE table_name; + +REPLACE tbl_name PARTITION (partition_name) TABLE table_name; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/replace.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/replace.yml new file mode 100644 index 000000000..fcadbb20f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/replace.yml @@ -0,0 +1,400 @@ +file: +- statement: + - replace_statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - keyword: DEFAULT + - comma: ',' + - keyword: DEFAULT + - end_bracket: ) +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - comma: ',' + - numeric_literal: '22' + - end_bracket: ) +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - values_clause: + - keyword: VALUE + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - comma: ',' + - numeric_literal: '22' + - end_bracket: ) +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - values_clause: + - keyword: VALUES + - keyword: ROW + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - comma: ',' + - keyword: ROW + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - comma: ',' + - numeric_literal: '22' + - end_bracket: ) +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - keyword: LOW_PRIORITY + - table_reference: + - naked_identifier: tbl_name + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - keyword: DELAYED + - table_reference: + - naked_identifier: tbl_name + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - keyword: LOW_PRIORITY + - keyword: INTO + - table_reference: + - naked_identifier: tbl_name + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - partition_clause: + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: partition_name + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - keyword: LOW_PRIORITY + - table_reference: + - naked_identifier: tbl_name + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - keyword: DELAYED + - table_reference: + - naked_identifier: tbl_name + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - keyword: LOW_PRIORITY + - keyword: INTO + - table_reference: + - naked_identifier: tbl_name + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - partition_clause: + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: partition_name + - end_bracket: ) + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - keyword: TABLE + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - keyword: LOW_PRIORITY + - table_reference: + - naked_identifier: tbl_name + - keyword: TABLE + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - keyword: DELAYED + - table_reference: + - naked_identifier: tbl_name + - keyword: TABLE + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - keyword: LOW_PRIORITY + - keyword: INTO + - table_reference: + - naked_identifier: tbl_name + - keyword: TABLE + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: TABLE + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; +- statement: + - replace_statement: + - keyword: REPLACE + - table_reference: + - naked_identifier: tbl_name + - partition_clause: + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: partition_name + - end_bracket: ) + - keyword: TABLE + - table_reference: + - naked_identifier: table_name +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/reset_master.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/reset_master.sql new file mode 100644 index 000000000..90358cd74 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/reset_master.sql @@ -0,0 +1,2 @@ +RESET MASTER; +RESET MASTER TO 1234; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/reset_master.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/reset_master.yml new file mode 100644 index 000000000..37640ea61 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/reset_master.yml @@ -0,0 +1,13 @@ +file: +- statement: + - reset_master_statement: + - keyword: RESET + - keyword: MASTER +- statement_terminator: ; +- statement: + - reset_master_statement: + - keyword: RESET + - keyword: MASTER + - keyword: TO + - numeric_literal: '1234' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal.sql new file mode 100644 index 000000000..c838afd76 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal.sql @@ -0,0 +1 @@ +resignal; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal.yml new file mode 100644 index 000000000..3cb42a4e8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal.yml @@ -0,0 +1,5 @@ +file: +- statement: + - resignal_segment: + - keyword: resignal +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_name.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_name.sql new file mode 100644 index 000000000..008d08510 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_name.sql @@ -0,0 +1 @@ +resignal testcondition; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_name.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_name.yml new file mode 100644 index 000000000..733677f14 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_name.yml @@ -0,0 +1,6 @@ +file: +- statement: + - resignal_segment: + - keyword: resignal + - naked_identifier: testcondition +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate.sql new file mode 100644 index 000000000..b4372c824 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate.sql @@ -0,0 +1 @@ +resignal sqlstate '42S02'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate.yml new file mode 100644 index 000000000..f23a23ee8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate.yml @@ -0,0 +1,7 @@ +file: +- statement: + - resignal_segment: + - keyword: resignal + - keyword: sqlstate + - quoted_literal: '''42S02''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate_value.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate_value.sql new file mode 100644 index 000000000..0d12b18c9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate_value.sql @@ -0,0 +1 @@ +resignal sqlstate value '42S02'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate_value.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate_value.yml new file mode 100644 index 000000000..a89de0c1e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_condition_sqlstate_value.yml @@ -0,0 +1,8 @@ +file: +- statement: + - resignal_segment: + - keyword: resignal + - keyword: sqlstate + - keyword: value + - quoted_literal: '''42S02''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info.sql new file mode 100644 index 000000000..05c921a9e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info.sql @@ -0,0 +1 @@ +resignal set message_text = 'test message'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info.yml new file mode 100644 index 000000000..b396d7a07 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info.yml @@ -0,0 +1,10 @@ +file: +- statement: + - resignal_segment: + - keyword: resignal + - keyword: set + - keyword: message_text + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test message''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info_multiple.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info_multiple.sql new file mode 100644 index 000000000..e5d4856d1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info_multiple.sql @@ -0,0 +1 @@ +resignal set message_text = 'test message', mysql_errno = '42S500'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info_multiple.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info_multiple.yml new file mode 100644 index 000000000..f800178dc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/resignal_set_signal_info_multiple.yml @@ -0,0 +1,15 @@ +file: +- statement: + - resignal_segment: + - keyword: resignal + - keyword: set + - keyword: message_text + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test message''' + - comma: ',' + - keyword: mysql_errno + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''42S500''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_distinctrow.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_distinctrow.sql new file mode 100644 index 000000000..db2026f18 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_distinctrow.sql @@ -0,0 +1 @@ +select distinctrow * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/databricks_keywords.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_distinctrow.yml similarity index 72% rename from crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/databricks_keywords.yml rename to crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_distinctrow.yml index beea87a39..b55d3e205 100644 --- a/crates/lib-dialects/test/fixtures/dialects/databricks/sqlfluff/databricks_keywords.yml +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_distinctrow.yml @@ -3,6 +3,8 @@ file: - select_statement: - select_clause: - keyword: select + - select_clause_modifier: + - keyword: distinctrow - select_clause_element: - wildcard_expression: - wildcard_identifier: @@ -12,8 +14,6 @@ file: - from_expression: - from_expression_element: - table_expression: - - object_reference: - - naked_identifier: shopify_cz - - dot: . - - naked_identifier: order + - table_reference: + - naked_identifier: table1 - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_share.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_share.sql new file mode 100644 index 000000000..7c51735c7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_share.sql @@ -0,0 +1 @@ +SELECT 1 FROM table1 FOR SHARE; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variable_simple.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_share.yml similarity index 69% rename from crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variable_simple.yml rename to crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_share.yml index fceab6c7e..145a45964 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variable_simple.yml +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_share.yml @@ -4,13 +4,15 @@ file: - select_clause: - keyword: SELECT - select_clause_element: - - column_reference: - - quoted_identifier: '[value]' + - numeric_literal: '1' - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - table_reference: - - tsql_variable: '@DepartmentCodes' + - naked_identifier: table1 + - for_clause: + - keyword: FOR + - keyword: SHARE - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update.sql new file mode 100644 index 000000000..c2d4baa1b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update.sql @@ -0,0 +1 @@ +SELECT 1 FROM table1 FOR UPDATE; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/inline_comments.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update.yml similarity index 68% rename from crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/inline_comments.yml rename to crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update.yml index c52fe0baf..f6bd3d6ed 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/inline_comments.yml +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update.yml @@ -4,14 +4,15 @@ file: - select_clause: - keyword: SELECT - select_clause_element: - - column_reference: - - naked_identifier: column# + - numeric_literal: '1' - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - table_reference: - - object_reference: - - naked_identifier: table# + - naked_identifier: table1 + - for_clause: + - keyword: FOR + - keyword: UPDATE - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_lock_in_share_mode.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_lock_in_share_mode.sql new file mode 100644 index 000000000..146c81e51 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_lock_in_share_mode.sql @@ -0,0 +1 @@ +SELECT 1 FROM table1 LOCK IN SHARE MODE; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_simple.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_lock_in_share_mode.yml similarity index 58% rename from crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_simple.yml rename to crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_lock_in_share_mode.yml index 11b8ebd5e..7864089fe 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_simple.yml +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_lock_in_share_mode.yml @@ -4,16 +4,17 @@ file: - select_clause: - keyword: SELECT - select_clause_element: - - naked_identifier: TsqlAlias - - raw_comparison_operator: = - - column_reference: - - naked_identifier: value + - numeric_literal: '1' - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - table_reference: - - object_reference: - - naked_identifier: table1 + - naked_identifier: table1 + - for_clause: + - keyword: LOCK + - keyword: IN + - keyword: SHARE + - keyword: MODE - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_nowait.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_nowait.sql new file mode 100644 index 000000000..e33fb9a0e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_nowait.sql @@ -0,0 +1 @@ +SELECT 1 FROM table1 FOR UPDATE NOWAIT; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_nowait.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_nowait.yml new file mode 100644 index 000000000..7a023b173 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_nowait.yml @@ -0,0 +1,19 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - for_clause: + - keyword: FOR + - keyword: UPDATE + - keyword: NOWAIT +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of.sql new file mode 100644 index 000000000..25cf21ed4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of.sql @@ -0,0 +1 @@ +SELECT 1 FROM table1 FOR UPDATE OF test; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of.yml new file mode 100644 index 000000000..ad61ecb18 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of.yml @@ -0,0 +1,20 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - for_clause: + - keyword: FOR + - keyword: UPDATE + - keyword: OF + - naked_identifier: test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of_multiple.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of_multiple.sql new file mode 100644 index 000000000..3af55ca2a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of_multiple.sql @@ -0,0 +1 @@ +SELECT 1 FROM table1 FOR UPDATE OF test1, test2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of_multiple.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of_multiple.yml new file mode 100644 index 000000000..8fcf195a5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_of_multiple.yml @@ -0,0 +1,22 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - for_clause: + - keyword: FOR + - keyword: UPDATE + - keyword: OF + - naked_identifier: test1 + - comma: ',' + - naked_identifier: test2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_skip_locked.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_skip_locked.sql new file mode 100644 index 000000000..e01f3b0e4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_skip_locked.sql @@ -0,0 +1 @@ +SELECT 1 FROM table1 FOR UPDATE SKIP LOCKED; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_skip_locked.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_skip_locked.yml new file mode 100644 index 000000000..27bfe6b62 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_for_update_skip_locked.yml @@ -0,0 +1,20 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - for_clause: + - keyword: FOR + - keyword: UPDATE + - keyword: SKIP + - keyword: LOCKED +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_high_priority.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_high_priority.sql new file mode 100644 index 000000000..89acded8c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_high_priority.sql @@ -0,0 +1 @@ +select HIGH_PRIORITY * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/describe.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_high_priority.yml similarity index 64% rename from crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/describe.yml rename to crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_high_priority.yml index acab0f58d..d5a2aa566 100644 --- a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/describe.yml +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_high_priority.yml @@ -1,22 +1,19 @@ file: - statement: - - keyword: DESCRIBE - - naked_identifier: tbl -- statement_terminator: ; -- statement: - - keyword: DESCRIBE - select_statement: - select_clause: - - keyword: SELECT + - keyword: select + - select_clause_modifier: + - keyword: HIGH_PRIORITY - select_clause_element: - wildcard_expression: - wildcard_identifier: - star: '*' - from_clause: - - keyword: FROM + - keyword: from - from_expression: - from_expression_element: - table_expression: - table_reference: - - naked_identifier: tbl + - naked_identifier: table1 - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_dumpfile.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_dumpfile.sql new file mode 100644 index 000000000..73e0e573a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_dumpfile.sql @@ -0,0 +1 @@ +select * into dumpfile '' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/summarize.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_dumpfile.yml similarity index 64% rename from crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/summarize.yml rename to crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_dumpfile.yml index c4f893488..6c7330ee0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/duckdb/sqlfluff/summarize.yml +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_dumpfile.yml @@ -1,22 +1,21 @@ file: - statement: - - keyword: SUMMARIZE - - naked_identifier: tbl -- statement_terminator: ; -- statement: - - keyword: SUMMARIZE - select_statement: - select_clause: - - keyword: SELECT + - keyword: select - select_clause_element: - wildcard_expression: - wildcard_identifier: - star: '*' + - into_clause: + - keyword: into + - keyword: dumpfile + - quoted_literal: '''''' - from_clause: - - keyword: FROM + - keyword: from - from_expression: - from_expression_element: - table_expression: - table_reference: - - naked_identifier: tbl + - naked_identifier: table1 - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_multiple_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_multiple_variable.sql new file mode 100644 index 000000000..170faa1ab --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_multiple_variable.sql @@ -0,0 +1 @@ +select 1, @test2, _test3, 'test4', func(test5) into @test1, @test2, _test3, @test4, @test5 from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_multiple_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_multiple_variable.yml new file mode 100644 index 000000000..6b9d4645a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_multiple_variable.yml @@ -0,0 +1,49 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' + - comma: ',' + - select_clause_element: + - column_reference: + - variable: '@test2' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: _test3 + - comma: ',' + - select_clause_element: + - quoted_literal: '''test4''' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: func + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test5 + - end_bracket: ) + - into_clause: + - keyword: into + - variable: '@test1' + - comma: ',' + - variable: '@test2' + - comma: ',' + - variable: _test3 + - comma: ',' + - variable: '@test4' + - comma: ',' + - variable: '@test5' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile.sql new file mode 100644 index 000000000..eaff0b2bb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile.sql @@ -0,0 +1 @@ +select * into outfile 'a' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile.yml new file mode 100644 index 000000000..1bacb62a5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile.yml @@ -0,0 +1,21 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - into_clause: + - keyword: into + - keyword: outfile + - quoted_literal: '''a''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_enclosed.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_enclosed.sql new file mode 100644 index 000000000..70b22b0f3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_enclosed.sql @@ -0,0 +1 @@ +select * into outfile 'a' fields enclosed by '"' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_enclosed.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_enclosed.yml new file mode 100644 index 000000000..f2d9c4cf3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_enclosed.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - into_clause: + - keyword: into + - keyword: outfile + - quoted_literal: '''a''' + - keyword: fields + - keyword: enclosed + - keyword: by + - quoted_literal: '''"''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_escaped.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_escaped.sql new file mode 100644 index 000000000..3736331c1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_escaped.sql @@ -0,0 +1 @@ +select * into outfile 'a' fields escaped by '-' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_escaped.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_escaped.yml new file mode 100644 index 000000000..44d7420b8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_escaped.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - into_clause: + - keyword: into + - keyword: outfile + - quoted_literal: '''a''' + - keyword: fields + - keyword: escaped + - keyword: by + - quoted_literal: '''-''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_optionally_enclosed.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_optionally_enclosed.sql new file mode 100644 index 000000000..966087e4d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_optionally_enclosed.sql @@ -0,0 +1 @@ +select * into outfile 'a' fields optionally enclosed by '"' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_optionally_enclosed.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_optionally_enclosed.yml new file mode 100644 index 000000000..f5505ac2c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_optionally_enclosed.yml @@ -0,0 +1,26 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - into_clause: + - keyword: into + - keyword: outfile + - quoted_literal: '''a''' + - keyword: fields + - keyword: optionally + - keyword: enclosed + - keyword: by + - quoted_literal: '''"''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_terminated.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_terminated.sql new file mode 100644 index 000000000..5011ef419 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_terminated.sql @@ -0,0 +1 @@ +select * into outfile 'a' fields terminated by '"' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_terminated.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_terminated.yml new file mode 100644 index 000000000..f55c7a85c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_fields_terminated.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - into_clause: + - keyword: into + - keyword: outfile + - quoted_literal: '''a''' + - keyword: fields + - keyword: terminated + - keyword: by + - quoted_literal: '''"''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_starting.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_starting.sql new file mode 100644 index 000000000..85425ce94 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_starting.sql @@ -0,0 +1 @@ +select * into outfile 'a' lines starting by '\n' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_starting.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_starting.yml new file mode 100644 index 000000000..fc750860d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_starting.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - into_clause: + - keyword: into + - keyword: outfile + - quoted_literal: '''a''' + - keyword: lines + - keyword: starting + - keyword: by + - quoted_literal: '''\n''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_terminated.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_terminated.sql new file mode 100644 index 000000000..27d3a1a2b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_terminated.sql @@ -0,0 +1 @@ +select * into outfile 'a' lines terminated by '\n' from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_terminated.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_terminated.yml new file mode 100644 index 000000000..e157a39a1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_outfile_lines_terminated.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - into_clause: + - keyword: into + - keyword: outfile + - quoted_literal: '''a''' + - keyword: lines + - keyword: terminated + - keyword: by + - quoted_literal: '''\n''' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_session_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_session_variable.sql new file mode 100644 index 000000000..5e898e760 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_session_variable.sql @@ -0,0 +1,11 @@ +select 1 into @dumpfile from table1; + +SELECT name +INTO @name +FROM t +WHERE id = 1; + +SELECT name +FROM t +WHERE id = 1 +INTO @name; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_session_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_session_variable.yml new file mode 100644 index 000000000..de3cfb421 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_into_session_variable.yml @@ -0,0 +1,70 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' + - into_clause: + - keyword: into + - variable: '@dumpfile' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: name + - into_clause: + - keyword: INTO + - variable: '@name' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: name + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - into_clause: + - keyword: INTO + - variable: '@name' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_local_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_local_variable.sql new file mode 100644 index 000000000..62687e034 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_local_variable.sql @@ -0,0 +1 @@ +select test2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_local_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_local_variable.yml new file mode 100644 index 000000000..4c270691c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_local_variable.yml @@ -0,0 +1,9 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: test2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_lock_in_share_mode.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_lock_in_share_mode.sql new file mode 100644 index 000000000..bbe8996ff --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_lock_in_share_mode.sql @@ -0,0 +1 @@ +select 1 from table1 lock in share mode; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_lock_in_share_mode.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_lock_in_share_mode.yml new file mode 100644 index 000000000..5a7db96f3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_lock_in_share_mode.yml @@ -0,0 +1,20 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - for_clause: + - keyword: lock + - keyword: in + - keyword: share + - keyword: mode +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_multiple_partition.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_multiple_partition.sql new file mode 100644 index 000000000..bb08982bb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_multiple_partition.sql @@ -0,0 +1 @@ +select * from table1 PARTITION(part1, part2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_multiple_partition.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_multiple_partition.yml new file mode 100644 index 000000000..96c2e8951 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_multiple_partition.yml @@ -0,0 +1,27 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - partition_clause: + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: part1 + - comma: ',' + - object_reference: + - naked_identifier: part2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_operators.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_operators.sql index 08a783996..b68e189e3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_operators.sql +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_operators.sql @@ -1 +1,9 @@ +SELECT !1; +SELECT 1 && 1; +SELECT 1 && 0; +SELECT 1 XOR 1; +SELECT 1 || 1; +SELECT col_1 && 1; +SELECT (col_1 = col_2) || col_3; SELECT 5 DIV 2; +SELECT 5 MOD 2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_operators.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_operators.yml index 6a8b81748..4daa2df2e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_operators.yml +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_operators.yml @@ -1,4 +1,94 @@ file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - not_operator: '!' + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: '&&' + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: '&&' + - numeric_literal: '0' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: XOR + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '1' + - binary_operator: '||' + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: col_1 + - binary_operator: '&&' + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col_1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: col_2 + - end_bracket: ) + - binary_operator: '||' + - column_reference: + - naked_identifier: col_3 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - numeric_literal: '5' + - binary_operator: DIV + - numeric_literal: '2' +- statement_terminator: ; - statement: - select_statement: - select_clause: @@ -6,7 +96,6 @@ file: - select_clause_element: - expression: - numeric_literal: '5' - - binary_operator: - - keyword: DIV + - binary_operator: MOD - numeric_literal: '2' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition.sql new file mode 100644 index 000000000..88f312fcf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition.sql @@ -0,0 +1 @@ +select * from table1 PARTITION(part1); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition.yml new file mode 100644 index 000000000..b1b495a89 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition.yml @@ -0,0 +1,24 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - partition_clause: + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: part1 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition_left_join.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition_left_join.sql new file mode 100644 index 000000000..681c02555 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition_left_join.sql @@ -0,0 +1 @@ +select * from table1 PARTITION(part1) left join table2 PARTITION(part2) on table1.id = table2.id; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition_left_join.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition_left_join.yml new file mode 100644 index 000000000..8287f942a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_partition_left_join.yml @@ -0,0 +1,51 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - partition_clause: + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: part1 + - end_bracket: ) + - join_clause: + - keyword: left + - keyword: join + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 + - partition_clause: + - keyword: PARTITION + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: part2 + - end_bracket: ) + - join_on_condition: + - keyword: on + - expression: + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: table2 + - dot: . + - naked_identifier: id +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_session_variable.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_session_variable.sql new file mode 100644 index 000000000..b3eb25596 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_session_variable.sql @@ -0,0 +1 @@ +select @test2; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_session_variable.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_session_variable.yml new file mode 100644 index 000000000..0eaad40c6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_session_variable.yml @@ -0,0 +1,9 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - variable: '@test2' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_big_result.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_big_result.sql new file mode 100644 index 000000000..5f5b37ccf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_big_result.sql @@ -0,0 +1 @@ +select SQL_BIG_RESULT * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_top_percent.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_big_result.yml similarity index 62% rename from crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_top_percent.yml rename to crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_big_result.yml index ba24797c3..57c5d7d8b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_top_percent.yml +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_big_result.yml @@ -2,22 +2,18 @@ file: - statement: - select_statement: - select_clause: - - keyword: SELECT + - keyword: select - select_clause_modifier: - - keyword: TOP - - expression: - - numeric_literal: '50' - - keyword: PERCENT + - keyword: SQL_BIG_RESULT - select_clause_element: - wildcard_expression: - wildcard_identifier: - star: '*' - from_clause: - - keyword: FROM + - keyword: from - from_expression: - from_expression_element: - table_expression: - table_reference: - - object_reference: - - naked_identifier: sales + - naked_identifier: table1 - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_buffer_result.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_buffer_result.sql new file mode 100644 index 000000000..e2506a9ae --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_buffer_result.sql @@ -0,0 +1 @@ +select SQL_BUFFER_RESULT * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_buffer_result.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_buffer_result.yml new file mode 100644 index 000000000..ebc737462 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_buffer_result.yml @@ -0,0 +1,19 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_modifier: + - keyword: SQL_BUFFER_RESULT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_cache.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_cache.sql new file mode 100644 index 000000000..7e9e3aa7d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_cache.sql @@ -0,0 +1 @@ +select SQL_CACHE * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_cache.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_cache.yml new file mode 100644 index 000000000..d6ac50319 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_cache.yml @@ -0,0 +1,19 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_modifier: + - keyword: SQL_CACHE + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_calc_found_rows.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_calc_found_rows.sql new file mode 100644 index 000000000..8ad75e08f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_calc_found_rows.sql @@ -0,0 +1 @@ +select SQL_CALC_FOUND_ROWS * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_calc_found_rows.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_calc_found_rows.yml new file mode 100644 index 000000000..e7b2701bf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_calc_found_rows.yml @@ -0,0 +1,19 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_modifier: + - keyword: SQL_CALC_FOUND_ROWS + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_no_cache.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_no_cache.sql new file mode 100644 index 000000000..4640f417d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_no_cache.sql @@ -0,0 +1 @@ +select SQL_NO_CACHE * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_no_cache.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_no_cache.yml new file mode 100644 index 000000000..ce25a27ba --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_no_cache.yml @@ -0,0 +1,19 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_modifier: + - keyword: SQL_NO_CACHE + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_small_result.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_small_result.sql new file mode 100644 index 000000000..dece227f3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_small_result.sql @@ -0,0 +1 @@ +select SQL_SMALL_RESULT * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_small_result.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_small_result.yml new file mode 100644 index 000000000..0c2d40223 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_sql_small_result.yml @@ -0,0 +1,19 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_modifier: + - keyword: SQL_SMALL_RESULT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_straight_join.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_straight_join.sql new file mode 100644 index 000000000..fa5a25ccd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_straight_join.sql @@ -0,0 +1 @@ +select STRAIGHT_JOIN * from table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_straight_join.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_straight_join.yml new file mode 100644 index 000000000..f226027f5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_straight_join.yml @@ -0,0 +1,19 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_modifier: + - keyword: STRAIGHT_JOIN + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_date_part_function.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_date_part_function.sql new file mode 100644 index 000000000..c8f39ff08 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_date_part_function.sql @@ -0,0 +1,7 @@ +SELECT EXTRACT(YEAR FROM '2019-07-02'); +SELECT TIMESTAMPADD(MINUTE, 1, '2003-01-02'); +SELECT TIMESTAMPDIFF(MONTH, '2003-02-01', '2003-05-01'); +SELECT TIMESTAMPDIFF(HOUR, x.time_created, x.time_updated) +FROM example_table AS x; +SELECT TIMESTAMPADD(SECOND, 1, x.some_timestamp_field) +FROM example_table AS x; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_date_part_function.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_date_part_function.yml new file mode 100644 index 000000000..3596cde5c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_date_part_function.yml @@ -0,0 +1,129 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: EXTRACT + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: YEAR + - keyword: FROM + - expression: + - quoted_literal: '''2019-07-02''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: TIMESTAMPADD + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: MINUTE + - comma: ',' + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - quoted_literal: '''2003-01-02''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: TIMESTAMPDIFF + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: MONTH + - comma: ',' + - expression: + - quoted_literal: '''2003-02-01''' + - comma: ',' + - expression: + - quoted_literal: '''2003-05-01''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: TIMESTAMPDIFF + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: HOUR + - comma: ',' + - expression: + - column_reference: + - naked_identifier: x + - dot: . + - naked_identifier: time_created + - comma: ',' + - expression: + - column_reference: + - naked_identifier: x + - dot: . + - naked_identifier: time_updated + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: example_table + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: x +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: TIMESTAMPADD + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: SECOND + - comma: ',' + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: x + - dot: . + - naked_identifier: some_timestamp_field + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: example_table + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: x +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_regexp.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_regexp.sql new file mode 100644 index 000000000..e00130dd7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_regexp.sql @@ -0,0 +1,3 @@ +SELECT * +FROM `db`.tbl +WHERE col REGEXP '^[0-9]*$' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_regexp.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_regexp.yml new file mode 100644 index 000000000..73a993855 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/select_with_regexp.yml @@ -0,0 +1,25 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '`db`' + - dot: . + - naked_identifier: tbl + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col + - keyword: REGEXP + - quoted_literal: '''^[0-9]*$''' diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set.sql new file mode 100644 index 000000000..f1150e876 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set.sql @@ -0,0 +1,40 @@ +SET @name = 43; +SET @total_tax = (SELECT SUM(tax) FROM taxable_transactions); +SET counter = counter + increment; +SET GLOBAL max_connections = 1000; +SET @@GLOBAL.max_connections = 1000; +SET SESSION sql_mode = 'TRADITIONAL'; +SET LOCAL sql_mode = 'TRADITIONAL'; +SET @@SESSION.sql_mode = 'TRADITIONAL'; +SET @@LOCAL.sql_mode = 'TRADITIONAL'; +SET @@sql_mode = 'TRADITIONAL'; +SET sql_mode = 'TRADITIONAL'; +SET PERSIST max_connections = 1000; +SET @@PERSIST.max_connections = 1000; +SET PERSIST_ONLY back_log = 100; +SET @@PERSIST_ONLY.back_log = 100; +SET @@SESSION.max_join_size = DEFAULT; +SET @@SESSION.max_join_size = @@GLOBAL.max_join_size; +SET @x = 1, SESSION sql_mode = ''; +SET GLOBAL sort_buffer_size = 1000000, SESSION sort_buffer_size = 1000000; +SET @@GLOBAL.sort_buffer_size = 1000000, @@LOCAL.sort_buffer_size = 1000000; +SET GLOBAL max_connections = 1000, sort_buffer_size = 1000000; +SET @@GLOBAL.sort_buffer_size = 50000, sort_buffer_size = 1000000; +SET @abc = 1 + 2; +SET @abc = (SELECT 1); +SET @id = (SELECT id FROM table1 WHERE field = TRUE LIMIT 1); +SET @abc = 1; +SET @my_var = 1; +SET @my$currency = 1; +SET @sha256enabled = 1; +SET some_bool_param = ON; +SET some_bool_param = OFF; +SET some_bool_param = TRUE; +SET some_bool_param = FALSE; +SET some_bool_param = 0; +SET some_bool_param = 1; +SET sql_log_bin = ON; +SET sql_log_bin = OFF; +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; +SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; +SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set.yml new file mode 100644 index 000000000..87bd7f901 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set.yml @@ -0,0 +1,440 @@ +file: +- statement: + - set_statement: + - keyword: SET + - variable: '@name' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '43' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: '@total_tax' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: tax + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: taxable_transactions + - end_bracket: ) +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: counter + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: counter + - binary_operator: + + - column_reference: + - naked_identifier: increment +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - keyword: GLOBAL + - variable: max_connections + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1000' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - system_variable: '@@GLOBAL.max_connections' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1000' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - keyword: SESSION + - variable: sql_mode + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''TRADITIONAL''' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - keyword: LOCAL + - variable: sql_mode + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''TRADITIONAL''' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - system_variable: '@@SESSION.sql_mode' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''TRADITIONAL''' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - system_variable: '@@LOCAL.sql_mode' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''TRADITIONAL''' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - system_variable: '@@sql_mode' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''TRADITIONAL''' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: sql_mode + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''TRADITIONAL''' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - keyword: PERSIST + - variable: max_connections + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1000' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - system_variable: '@@PERSIST.max_connections' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1000' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - keyword: PERSIST_ONLY + - variable: back_log + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '100' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - system_variable: '@@PERSIST_ONLY.back_log' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '100' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - system_variable: '@@SESSION.max_join_size' + - comparison_operator: + - raw_comparison_operator: = + - variable: DEFAULT +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - system_variable: '@@SESSION.max_join_size' + - comparison_operator: + - raw_comparison_operator: = + - system_variable: '@@GLOBAL.max_join_size' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: '@x' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - keyword: SESSION + - variable: sql_mode + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - keyword: GLOBAL + - variable: sort_buffer_size + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1000000' + - comma: ',' + - keyword: SESSION + - variable: sort_buffer_size + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1000000' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - system_variable: '@@GLOBAL.sort_buffer_size' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1000000' + - comma: ',' + - system_variable: '@@LOCAL.sort_buffer_size' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1000000' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - keyword: GLOBAL + - variable: max_connections + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1000' + - comma: ',' + - variable: sort_buffer_size + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1000000' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - system_variable: '@@GLOBAL.sort_buffer_size' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '50000' + - comma: ',' + - variable: sort_buffer_size + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1000000' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: '@abc' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - numeric_literal: '1' + - binary_operator: + + - numeric_literal: '2' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: '@abc' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - end_bracket: ) +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: '@id' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: field + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - limit_clause: + - keyword: LIMIT + - numeric_literal: '1' + - end_bracket: ) +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: '@abc' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: '@my_var' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: '@my$currency' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: '@sha256enabled' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: some_bool_param + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: some_bool_param + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: some_bool_param + - comparison_operator: + - raw_comparison_operator: = + - keyword: 'TRUE' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: some_bool_param + - comparison_operator: + - raw_comparison_operator: = + - keyword: 'FALSE' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: some_bool_param + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: some_bool_param + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: sql_log_bin + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: sql_log_bin + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: '@OLD_UNIQUE_CHECKS' + - comparison_operator: + - raw_comparison_operator: = + - system_variable: '@@UNIQUE_CHECKS' + - comma: ',' + - variable: UNIQUE_CHECKS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: '@OLD_FOREIGN_KEY_CHECKS' + - comparison_operator: + - raw_comparison_operator: = + - system_variable: '@@FOREIGN_KEY_CHECKS' + - comma: ',' + - variable: FOREIGN_KEY_CHECKS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: '@OLD_SQL_MODE' + - comparison_operator: + - raw_comparison_operator: = + - system_variable: '@@SQL_MODE' + - comma: ',' + - variable: SQL_MODE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_names.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_names.sql new file mode 100644 index 000000000..e06172661 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_names.sql @@ -0,0 +1,11 @@ +SET NAMES utf8mb4; + +SET NAMES 'utf8'; + +SET NAMES DEFAULT; + +SET NAMES ascii COLLATE ascii_bin; + +SET NAMES 'ascii' COLLATE 'ascii_bin'; + +SET NAMES ascii COLLATE 'ascii_bin'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_names.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_names.yml new file mode 100644 index 000000000..54f7b0fea --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_names.yml @@ -0,0 +1,46 @@ +file: +- statement: + - set_names_statement: + - keyword: SET + - keyword: NAMES + - naked_identifier: utf8mb4 +- statement_terminator: ; +- statement: + - set_names_statement: + - keyword: SET + - keyword: NAMES + - quoted_literal: '''utf8''' +- statement_terminator: ; +- statement: + - set_names_statement: + - keyword: SET + - keyword: NAMES + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - set_names_statement: + - keyword: SET + - keyword: NAMES + - naked_identifier: ascii + - keyword: COLLATE + - collation_reference: + - naked_identifier: ascii_bin +- statement_terminator: ; +- statement: + - set_names_statement: + - keyword: SET + - keyword: NAMES + - quoted_literal: '''ascii''' + - keyword: COLLATE + - collation_reference: + - quoted_literal: '''ascii_bin''' +- statement_terminator: ; +- statement: + - set_names_statement: + - keyword: SET + - keyword: NAMES + - naked_identifier: ascii + - keyword: COLLATE + - collation_reference: + - quoted_literal: '''ascii_bin''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_transaction.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_transaction.sql new file mode 100644 index 000000000..32056fa5a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_transaction.sql @@ -0,0 +1,12 @@ +SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; +SET TRANSACTION ISOLATION LEVEL READ COMMITTED; +SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; +SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; +SET GLOBAL TRANSACTION ISOLATION LEVEL REPEATABLE READ; +SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; +SET TRANSACTION READ WRITE; +SET GLOBAL TRANSACTION READ ONLY; +SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ ONLY; +SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ WRITE; +SET SESSION TRANSACTION READ WRITE, ISOLATION LEVEL READ UNCOMMITTED; +SET TRANSACTION READ ONLY, ISOLATION LEVEL SERIALIZABLE; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_transaction.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_transaction.yml new file mode 100644 index 000000000..f3e579ac8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/set_transaction.yml @@ -0,0 +1,120 @@ +file: +- statement: + - set_transaction_statement: + - keyword: SET + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: REPEATABLE + - keyword: READ +- statement_terminator: ; +- statement: + - set_transaction_statement: + - keyword: SET + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: READ + - keyword: COMMITTED +- statement_terminator: ; +- statement: + - set_transaction_statement: + - keyword: SET + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: READ + - keyword: UNCOMMITTED +- statement_terminator: ; +- statement: + - set_transaction_statement: + - keyword: SET + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: SERIALIZABLE +- statement_terminator: ; +- statement: + - set_transaction_statement: + - keyword: SET + - keyword: GLOBAL + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: REPEATABLE + - keyword: READ +- statement_terminator: ; +- statement: + - set_transaction_statement: + - keyword: SET + - keyword: SESSION + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: READ + - keyword: COMMITTED +- statement_terminator: ; +- statement: + - set_transaction_statement: + - keyword: SET + - keyword: TRANSACTION + - keyword: READ + - keyword: WRITE +- statement_terminator: ; +- statement: + - set_transaction_statement: + - keyword: SET + - keyword: GLOBAL + - keyword: TRANSACTION + - keyword: READ + - keyword: ONLY +- statement_terminator: ; +- statement: + - set_transaction_statement: + - keyword: SET + - keyword: SESSION + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: REPEATABLE + - keyword: READ + - comma: ',' + - keyword: READ + - keyword: ONLY +- statement_terminator: ; +- statement: + - set_transaction_statement: + - keyword: SET + - keyword: GLOBAL + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: SERIALIZABLE + - comma: ',' + - keyword: READ + - keyword: WRITE +- statement_terminator: ; +- statement: + - set_transaction_statement: + - keyword: SET + - keyword: SESSION + - keyword: TRANSACTION + - keyword: READ + - keyword: WRITE + - comma: ',' + - keyword: ISOLATION + - keyword: LEVEL + - keyword: READ + - keyword: UNCOMMITTED +- statement_terminator: ; +- statement: + - set_transaction_statement: + - keyword: SET + - keyword: TRANSACTION + - keyword: READ + - keyword: ONLY + - comma: ',' + - keyword: ISOLATION + - keyword: LEVEL + - keyword: SERIALIZABLE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal.sql new file mode 100644 index 000000000..c838afd76 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal.sql @@ -0,0 +1 @@ +resignal; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal.yml new file mode 100644 index 000000000..3cb42a4e8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal.yml @@ -0,0 +1,5 @@ +file: +- statement: + - resignal_segment: + - keyword: resignal +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_name.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_name.sql new file mode 100644 index 000000000..008d08510 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_name.sql @@ -0,0 +1 @@ +resignal testcondition; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_name.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_name.yml new file mode 100644 index 000000000..733677f14 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_name.yml @@ -0,0 +1,6 @@ +file: +- statement: + - resignal_segment: + - keyword: resignal + - naked_identifier: testcondition +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate.sql new file mode 100644 index 000000000..b4372c824 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate.sql @@ -0,0 +1 @@ +resignal sqlstate '42S02'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate.yml new file mode 100644 index 000000000..f23a23ee8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate.yml @@ -0,0 +1,7 @@ +file: +- statement: + - resignal_segment: + - keyword: resignal + - keyword: sqlstate + - quoted_literal: '''42S02''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate_value.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate_value.sql new file mode 100644 index 000000000..0d12b18c9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate_value.sql @@ -0,0 +1 @@ +resignal sqlstate value '42S02'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate_value.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate_value.yml new file mode 100644 index 000000000..a89de0c1e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_condition_sqlstate_value.yml @@ -0,0 +1,8 @@ +file: +- statement: + - resignal_segment: + - keyword: resignal + - keyword: sqlstate + - keyword: value + - quoted_literal: '''42S02''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info.sql new file mode 100644 index 000000000..05c921a9e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info.sql @@ -0,0 +1 @@ +resignal set message_text = 'test message'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info.yml new file mode 100644 index 000000000..b396d7a07 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info.yml @@ -0,0 +1,10 @@ +file: +- statement: + - resignal_segment: + - keyword: resignal + - keyword: set + - keyword: message_text + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test message''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info_multiple.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info_multiple.sql new file mode 100644 index 000000000..e5d4856d1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info_multiple.sql @@ -0,0 +1 @@ +resignal set message_text = 'test message', mysql_errno = '42S500'; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info_multiple.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info_multiple.yml new file mode 100644 index 000000000..f800178dc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/signal_set_signal_info_multiple.yml @@ -0,0 +1,15 @@ +file: +- statement: + - resignal_segment: + - keyword: resignal + - keyword: set + - keyword: message_text + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test message''' + - comma: ',' + - keyword: mysql_errno + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''42S500''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/system_variables.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/system_variables.sql new file mode 100644 index 000000000..ff86cb2ff --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/system_variables.sql @@ -0,0 +1,5 @@ +SELECT @@global.time_zone; +SELECT @@session.time_zone; +SELECT @@global.version; +SELECT @@session.rand_seed1; +SELECT CONVERT_TZ(NOW(), @@global.time_zone, '+00:00') diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/system_variables.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/system_variables.yml new file mode 100644 index 000000000..38a7fb8d7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/system_variables.yml @@ -0,0 +1,55 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - system_variable: '@@global.time_zone' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - system_variable: '@@session.time_zone' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - system_variable: '@@global.version' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - system_variable: '@@session.rand_seed1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CONVERT_TZ + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: NOW + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - expression: + - system_variable: '@@global.time_zone' + - comma: ',' + - expression: + - quoted_literal: '''+00:00''' + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/update.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/update.sql new file mode 100644 index 000000000..92e540781 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/update.sql @@ -0,0 +1,39 @@ +UPDATE t1 SET col1 = col1 + 1; + +UPDATE t1 SET col1 = col1 + 1, col2 = col1; + +UPDATE items,month SET items.price=month.price +WHERE items.id=month.id; + +UPDATE t SET id = id + 1 ORDER BY id DESC; + +UPDATE items +SET retail = retail * 0.9 +WHERE id IN +(SELECT id FROM items +WHERE retail / wholesale >= 1.3 AND quantity > 100); + +UPDATE items, + (SELECT id FROM items + WHERE id IN + (SELECT id FROM items + WHERE retail / wholesale >= 1.3 AND quantity < 100)) + AS discounted +SET items.retail = items.retail * 0.9 +WHERE items.id = discounted.id; + +UPDATE items, + (SELECT id, retail / wholesale AS markup, quantity FROM items) + AS discounted + SET items.retail = items.retail * 0.9 + WHERE discounted.markup >= 1.3 + AND discounted.quantity < 100 + AND items.id = discounted.id; + +UPDATE LOW_PRIORITY foo +SET bar = 7 +LIMIT 4; + +UPDATE a, b SET a.name = b.name WHERE a.id = b.id; + +UPDATE a join b on a.id = b.id set a.type = b.type where a.type is null; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/update.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/update.yml new file mode 100644 index 000000000..608094904 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/update.yml @@ -0,0 +1,456 @@ +file: +- statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: t1 + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: col1 + - binary_operator: + + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: t1 + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: col1 + - binary_operator: + + - numeric_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: col1 +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: items + - comma: ',' + - table_reference: + - naked_identifier: month + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: price + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: month + - dot: . + - naked_identifier: price + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: month + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: t + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: id + - binary_operator: + + - numeric_literal: '1' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: id + - keyword: DESC +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: items + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: retail + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: retail + - binary_operator: '*' + - numeric_literal: '0.9' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: id + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: items + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: retail + - binary_operator: / + - column_reference: + - naked_identifier: wholesale + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - numeric_literal: '1.3' + - binary_operator: AND + - column_reference: + - naked_identifier: quantity + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '100' + - end_bracket: ) +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: items + - comma: ',' + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: items + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: id + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: items + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: retail + - binary_operator: / + - column_reference: + - naked_identifier: wholesale + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - numeric_literal: '1.3' + - binary_operator: AND + - column_reference: + - naked_identifier: quantity + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '100' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: discounted + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: retail + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: retail + - binary_operator: '*' + - numeric_literal: '0.9' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: discounted + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: items + - comma: ',' + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: retail + - binary_operator: / + - column_reference: + - naked_identifier: wholesale + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: markup + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: quantity + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: items + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: discounted + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: retail + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: retail + - binary_operator: '*' + - numeric_literal: '0.9' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: discounted + - dot: . + - naked_identifier: markup + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - numeric_literal: '1.3' + - binary_operator: AND + - column_reference: + - naked_identifier: discounted + - dot: . + - naked_identifier: quantity + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '100' + - binary_operator: AND + - column_reference: + - naked_identifier: items + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: discounted + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - keyword: LOW_PRIORITY + - table_reference: + - naked_identifier: foo + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: bar + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '7' + - limit_clause: + - keyword: LIMIT + - numeric_literal: '4' +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: a + - comma: ',' + - table_reference: + - naked_identifier: b + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: name + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: name + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: id +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: a + - join_clause: + - keyword: join + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: b + - join_on_condition: + - keyword: on + - expression: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: id + - set_clause_list: + - keyword: set + - set_clause: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: type + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: type + - where_clause: + - keyword: where + - expression: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: type + - keyword: is + - null_literal: 'null' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_database.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_database.sql new file mode 100644 index 000000000..256e8e47e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_database.sql @@ -0,0 +1 @@ +use my_db; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_database.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_database.yml new file mode 100644 index 000000000..a6db23ca2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_database.yml @@ -0,0 +1,7 @@ +file: +- statement: + - use_statement: + - keyword: use + - database_reference: + - naked_identifier: my_db +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index.sql new file mode 100644 index 000000000..282152b59 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index.sql @@ -0,0 +1 @@ +SELECT * FROM t1 test USE INDEX (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index.yml new file mode 100644 index 000000000..54c1f6ac5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index.yml @@ -0,0 +1,27 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - alias_expression: + - naked_identifier: test + - index_hint_clause: + - keyword: USE + - keyword: INDEX + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_group_by.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_group_by.sql new file mode 100644 index 000000000..0df246fee --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_group_by.sql @@ -0,0 +1 @@ +SELECT * FROM t1 test USE INDEX FOR GROUP BY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_group_by.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_group_by.yml new file mode 100644 index 000000000..ee515418a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_group_by.yml @@ -0,0 +1,30 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - alias_expression: + - naked_identifier: test + - index_hint_clause: + - keyword: USE + - keyword: INDEX + - keyword: FOR + - keyword: GROUP + - keyword: BY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_join.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_join.sql new file mode 100644 index 000000000..923048b53 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_join.sql @@ -0,0 +1 @@ +SELECT * FROM t1 test USE INDEX FOR JOIN (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_join.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_join.yml new file mode 100644 index 000000000..cad79f27e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_join.yml @@ -0,0 +1,29 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - alias_expression: + - naked_identifier: test + - index_hint_clause: + - keyword: USE + - keyword: INDEX + - keyword: FOR + - keyword: JOIN + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_order_by.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_order_by.sql new file mode 100644 index 000000000..33b7ae47f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_order_by.sql @@ -0,0 +1 @@ +SELECT * FROM t1 test USE INDEX FOR ORDER BY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_order_by.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_order_by.yml new file mode 100644 index 000000000..15014b5f7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_index_for_order_by.yml @@ -0,0 +1,30 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - alias_expression: + - naked_identifier: test + - index_hint_clause: + - keyword: USE + - keyword: INDEX + - keyword: FOR + - keyword: ORDER + - keyword: BY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_key.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_key.sql new file mode 100644 index 000000000..d034b5a7c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_key.sql @@ -0,0 +1 @@ +SELECT * FROM t1 test USE KEY (i2); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_key.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_key.yml new file mode 100644 index 000000000..dfb6f8e3d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_key.yml @@ -0,0 +1,27 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - alias_expression: + - naked_identifier: test + - index_hint_clause: + - keyword: USE + - keyword: KEY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: i2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_statement.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_statement.sql new file mode 100644 index 000000000..610507790 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_statement.sql @@ -0,0 +1 @@ +USE db; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_statement.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_statement.yml new file mode 100644 index 000000000..530b518e1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/use_statement.yml @@ -0,0 +1,7 @@ +file: +- statement: + - use_statement: + - keyword: USE + - database_reference: + - naked_identifier: db +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/values_statement.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/values_statement.sql new file mode 100644 index 000000000..b3e547f46 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/values_statement.sql @@ -0,0 +1,5 @@ +VALUES ROW ('a', 1), ROW ('b', 2); + +VALUES ROW ('a', 1), ROW (upper('b'), 2+1); + +VALUES ROW (CURRENT_DATE, '2020-06-04' + interval -5 day); diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/values_statement.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/values_statement.yml new file mode 100644 index 000000000..3a23d562a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/values_statement.yml @@ -0,0 +1,72 @@ +file: +- statement: + - values_clause: + - keyword: VALUES + - keyword: ROW + - bracketed: + - start_bracket: ( + - quoted_literal: '''a''' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - keyword: ROW + - bracketed: + - start_bracket: ( + - quoted_literal: '''b''' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - values_clause: + - keyword: VALUES + - keyword: ROW + - bracketed: + - start_bracket: ( + - quoted_literal: '''a''' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - keyword: ROW + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: upper + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''b''' + - end_bracket: ) + - comma: ',' + - expression: + - numeric_literal: '2' + - binary_operator: + + - numeric_literal: '1' + - end_bracket: ) +- statement_terminator: ; +- statement: + - values_clause: + - keyword: VALUES + - keyword: ROW + - bracketed: + - start_bracket: ( + - expression: + - bare_function: CURRENT_DATE + - comma: ',' + - expression: + - quoted_literal: '''2020-06-04''' + - binary_operator: + + - interval_expression: + - keyword: interval + - expression: + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '5' + - date_part: day + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/variable_assignment.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/variable_assignment.sql new file mode 100644 index 000000000..99636770a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/variable_assignment.sql @@ -0,0 +1,7 @@ +SELECT @var1:=COUNT(*) FROM t1; + +SET @var1:=0; + +SET @var1:=@var2:=0; + +UPDATE t1 SET c1 = 2 WHERE c1 = @var1:= 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/variable_assignment.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/variable_assignment.yml new file mode 100644 index 000000000..e0775d2ad --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/variable_assignment.yml @@ -0,0 +1,66 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - variable: '@var1' + - assignment_operator: := + - function: + - function_name: + - function_name_identifier: COUNT + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: '@var1' + - assignment_operator: := + - numeric_literal: '0' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: '@var1' + - assignment_operator: := + - expression: + - variable: '@var2' + - assignment_operator: := + - numeric_literal: '0' +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: t1 + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: c1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: c1 + - comparison_operator: + - raw_comparison_operator: = + - variable: '@var1' + - assignment_operator: := + - numeric_literal: '1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_label.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_label.sql new file mode 100644 index 000000000..2fc801127 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_label.sql @@ -0,0 +1 @@ +iteration:while _cnt <= _max_cnt do set _cnt = _cnt + 1; end while iteration; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_label.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_label.yml new file mode 100644 index 000000000..9d7e35a53 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_label.yml @@ -0,0 +1,33 @@ +file: +- statement: + - while_statement: + - naked_identifier: iteration + - colon: ':' + - keyword: while + - expression: + - column_reference: + - naked_identifier: _cnt + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - column_reference: + - naked_identifier: _max_cnt + - keyword: do + - statement: + - set_statement: + - keyword: set + - variable: _cnt + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: _cnt + - binary_operator: + + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - while_statement: + - keyword: end + - keyword: while + - naked_identifier: iteration +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_no_label.sql b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_no_label.sql new file mode 100644 index 000000000..a59989683 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_no_label.sql @@ -0,0 +1 @@ +while _cnt <= _max_cnt do set _cnt = _cnt + 1; end while; diff --git a/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_no_label.yml b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_no_label.yml new file mode 100644 index 000000000..32822e53f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/mysql/sqlfluff/while_no_label.yml @@ -0,0 +1,30 @@ +file: +- statement: + - while_statement: + - keyword: while + - expression: + - column_reference: + - naked_identifier: _cnt + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - column_reference: + - naked_identifier: _max_cnt + - keyword: do + - statement: + - set_statement: + - keyword: set + - variable: _cnt + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: _cnt + - binary_operator: + + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - while_statement: + - keyword: end + - keyword: while +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_aggregate.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_aggregate.yml index 81c9309ca..62993106b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_aggregate.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_aggregate.yml @@ -1,101 +1,107 @@ file: - statement: - - keyword: ALTER - - keyword: AGGREGATE - - object_reference: - - naked_identifier: range_agg_preserve_gaps - - bracketed: - - start_bracket: ( - - word: TSTZRANGE - - end_bracket: ) - - keyword: RENAME - - keyword: TO - - function_name: - - function_name_identifier: my_agg + - alter_aggregate_statement: + - keyword: ALTER + - keyword: AGGREGATE + - object_reference: + - naked_identifier: range_agg_preserve_gaps + - bracketed: + - start_bracket: ( + - word: TSTZRANGE + - end_bracket: ) + - keyword: RENAME + - keyword: TO + - function_name: + - function_name_identifier: my_agg - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: AGGREGATE - - object_reference: - - naked_identifier: my_agg - - bracketed: - - start_bracket: ( - - word: TSTZRANGE - - end_bracket: ) - - keyword: OWNER - - keyword: TO - - role_reference: - - naked_identifier: me + - alter_aggregate_statement: + - keyword: ALTER + - keyword: AGGREGATE + - object_reference: + - naked_identifier: my_agg + - bracketed: + - start_bracket: ( + - word: TSTZRANGE + - end_bracket: ) + - keyword: OWNER + - keyword: TO + - role_reference: + - naked_identifier: me - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: AGGREGATE - - object_reference: - - naked_identifier: my_agg - - bracketed: - - start_bracket: ( - - word: TSTZRANGE - - end_bracket: ) - - keyword: OWNER - - keyword: TO - - keyword: CURRENT_ROLE + - alter_aggregate_statement: + - keyword: ALTER + - keyword: AGGREGATE + - object_reference: + - naked_identifier: my_agg + - bracketed: + - start_bracket: ( + - word: TSTZRANGE + - end_bracket: ) + - keyword: OWNER + - keyword: TO + - keyword: CURRENT_ROLE - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: AGGREGATE - - object_reference: - - naked_identifier: my_agg - - bracketed: - - start_bracket: ( - - word: TSTZRANGE - - end_bracket: ) - - keyword: OWNER - - keyword: TO - - keyword: CURRENT_USER + - alter_aggregate_statement: + - keyword: ALTER + - keyword: AGGREGATE + - object_reference: + - naked_identifier: my_agg + - bracketed: + - start_bracket: ( + - word: TSTZRANGE + - end_bracket: ) + - keyword: OWNER + - keyword: TO + - keyword: CURRENT_USER - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: AGGREGATE - - object_reference: - - naked_identifier: my_agg - - bracketed: - - start_bracket: ( - - word: TSTZRANGE - - end_bracket: ) - - keyword: OWNER - - keyword: TO - - keyword: SESSION_USER + - alter_aggregate_statement: + - keyword: ALTER + - keyword: AGGREGATE + - object_reference: + - naked_identifier: my_agg + - bracketed: + - start_bracket: ( + - word: TSTZRANGE + - end_bracket: ) + - keyword: OWNER + - keyword: TO + - keyword: SESSION_USER - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: AGGREGATE - - object_reference: - - naked_identifier: my_agg - - bracketed: - - start_bracket: ( - - star: '*' - - end_bracket: ) - - keyword: SET - - keyword: SCHEMA - - table_reference: + - alter_aggregate_statement: + - keyword: ALTER + - keyword: AGGREGATE - object_reference: + - naked_identifier: my_agg + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - keyword: SET + - keyword: SCHEMA + - schema_reference: - naked_identifier: api - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: AGGREGATE - - object_reference: - - naked_identifier: complex_agg_function - - bracketed: - - start_bracket: ( - - word: integer - - comma: ',' - - word: text - - comma: ',' - - word: numeric - - end_bracket: ) - - keyword: RENAME - - keyword: TO - - function_name: - - function_name_identifier: renamed_agg_function + - alter_aggregate_statement: + - keyword: ALTER + - keyword: AGGREGATE + - object_reference: + - naked_identifier: complex_agg_function + - bracketed: + - start_bracket: ( + - word: integer + - comma: ',' + - word: text + - comma: ',' + - word: numeric + - end_bracket: ) + - keyword: RENAME + - keyword: TO + - function_name: + - function_name_identifier: renamed_agg_function - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_database.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_database.sql index 250217865..0648c8aa4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_database.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_database.sql @@ -26,6 +26,8 @@ ALTER DATABASE db SET parameter1 = 1; ALTER DATABASE db SET parameter1 = 'some_value'; ALTER DATABASE db SET parameter1 = DEFAULT; ALTER DATABASE db SET parameter1 FROM CURRENT; +ALTER DATABASE db SET search_path TO my_schema; +ALTER DATABASE db SET search_path TO "my_schema"; ALTER USER some_user SET default_transaction_read_only = ON; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_database.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_database.yml index 8459ee47b..52a5afdea 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_database.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_database.yml @@ -272,6 +272,28 @@ file: - keyword: FROM - keyword: CURRENT - statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: db + - keyword: SET + - parameter: search_path + - keyword: TO + - naked_identifier: my_schema +- statement_terminator: ; +- statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: db + - keyword: SET + - parameter: search_path + - keyword: TO + - quoted_identifier: '"my_schema"' +- statement_terminator: ; - statement: - alter_role_statement: - keyword: ALTER diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_default_privileges.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_default_privileges.yml index d68473b3a..9837972ae 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_default_privileges.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_default_privileges.yml @@ -31,9 +31,8 @@ file: - naked_identifier: my_user - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - alter_default_privileges_grant: - keyword: GRANT - alter_default_privileges_object_privilege: @@ -78,13 +77,11 @@ file: - naked_identifier: my_user - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - comma: ',' - - table_reference: - - object_reference: - - naked_identifier: your_schema + - schema_reference: + - naked_identifier: your_schema - alter_default_privileges_grant: - keyword: GRANT - alter_default_privileges_object_privilege: @@ -221,13 +218,11 @@ file: - keyword: PRIVILEGES - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - comma: ',' - - table_reference: - - object_reference: - - naked_identifier: your_schema + - schema_reference: + - naked_identifier: your_schema - alter_default_privileges_grant: - keyword: GRANT - alter_default_privileges_object_privilege: @@ -301,13 +296,11 @@ file: - naked_identifier: your_user - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - comma: ',' - - table_reference: - - object_reference: - - naked_identifier: your_schema + - schema_reference: + - naked_identifier: your_schema - alter_default_privileges_grant: - keyword: GRANT - alter_default_privileges_object_privilege: @@ -372,9 +365,8 @@ file: - naked_identifier: my_user - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - alter_default_privileges_revoke: - keyword: REVOKE - alter_default_privileges_object_privilege: @@ -399,13 +391,11 @@ file: - naked_identifier: my_user - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - comma: ',' - - table_reference: - - object_reference: - - naked_identifier: your_schema + - schema_reference: + - naked_identifier: your_schema - alter_default_privileges_revoke: - keyword: REVOKE - alter_default_privileges_object_privilege: @@ -430,9 +420,8 @@ file: - naked_identifier: my_user - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - alter_default_privileges_revoke: - keyword: REVOKE - alter_default_privileges_object_privilege: @@ -524,13 +513,11 @@ file: - keyword: PRIVILEGES - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - comma: ',' - - table_reference: - - object_reference: - - naked_identifier: your_schema + - schema_reference: + - naked_identifier: your_schema - alter_default_privileges_revoke: - keyword: REVOKE - alter_default_privileges_object_privilege: @@ -585,13 +572,11 @@ file: - naked_identifier: your_user - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - comma: ',' - - table_reference: - - object_reference: - - naked_identifier: your_schema + - schema_reference: + - naked_identifier: your_schema - alter_default_privileges_revoke: - keyword: REVOKE - alter_default_privileges_object_privilege: diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_extension.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_extension.sql new file mode 100644 index 000000000..ad0ec1211 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_extension.sql @@ -0,0 +1,5 @@ +ALTER EXTENSION hstore SET SCHEMA utils; +ALTER EXTENSION hstore ADD FUNCTION populate_record(anyelement, hstore); +ALTER EXTENSION "hstore" DROP TABLE public.ref_table; +ALTER EXTENSION hstore UPDATE TO '2.0'; +ALTER EXTENSION repmgr UPDATE; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_extension.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_extension.yml new file mode 100644 index 000000000..916eef6b4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_extension.yml @@ -0,0 +1,63 @@ +file: +- statement: + - alter_extension_statement: + - keyword: ALTER + - keyword: EXTENSION + - extension_reference: + - naked_identifier: hstore + - keyword: SET + - keyword: SCHEMA + - schema_reference: + - naked_identifier: utils +- statement_terminator: ; +- statement: + - alter_extension_statement: + - keyword: ALTER + - keyword: EXTENSION + - extension_reference: + - naked_identifier: hstore + - keyword: ADD + - keyword: FUNCTION + - function_name: + - function_name_identifier: populate_record + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: anyelement + - comma: ',' + - data_type: + - data_type_identifier: hstore + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_extension_statement: + - keyword: ALTER + - keyword: EXTENSION + - extension_reference: + - quoted_identifier: '"hstore"' + - keyword: DROP + - keyword: TABLE + - table_reference: + - naked_identifier: public + - dot: . + - naked_identifier: ref_table +- statement_terminator: ; +- statement: + - alter_extension_statement: + - keyword: ALTER + - keyword: EXTENSION + - extension_reference: + - naked_identifier: hstore + - keyword: UPDATE + - keyword: TO + - quoted_literal: '''2.0''' +- statement_terminator: ; +- statement: + - alter_extension_statement: + - keyword: ALTER + - keyword: EXTENSION + - extension_reference: + - naked_identifier: repmgr + - keyword: UPDATE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_foreign_table.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_foreign_table.sql new file mode 100644 index 000000000..3111c4784 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_foreign_table.sql @@ -0,0 +1,13 @@ +ALTER FOREIGN TABLE distributors ALTER COLUMN street SET NOT NULL; + +ALTER FOREIGN TABLE t_user ADD COLUMN my_column text; + +ALTER TABLE bar_fdw.foo ADD test varchar NULL; + +ALTER FOREIGN TABLE myschema.distributors OPTIONS (ADD opt1 'value', SET opt2 'value2', DROP opt3); + +ALTER FOREIGN TABLE test OPTIONS (SET table $$(select my_column from my_table)$$); + +ALTER FOREIGN TABLE test ADD COLUMN new_column int8, OPTIONS (SET table $$(select my_column from my_table)$$); + +ALTER FOREIGN TABLE test RENAME TO test_renamed; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_foreign_table.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_foreign_table.yml new file mode 100644 index 000000000..59274de5f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_foreign_table.yml @@ -0,0 +1,126 @@ +file: +- statement: + - alter_foreign_table_statement: + - keyword: ALTER + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: distributors + - alter_foreign_table_action_segment: + - keyword: ALTER + - keyword: COLUMN + - column_reference: + - naked_identifier: street + - keyword: SET + - keyword: NOT + - keyword: 'NULL' +- statement_terminator: ; +- statement: + - alter_foreign_table_statement: + - keyword: ALTER + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: t_user + - alter_foreign_table_action_segment: + - keyword: ADD + - keyword: COLUMN + - column_reference: + - naked_identifier: my_column + - data_type: + - keyword: text +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: bar_fdw + - dot: . + - naked_identifier: foo + - alter_table_action_segment: + - keyword: ADD + - column_reference: + - naked_identifier: test + - data_type: + - keyword: varchar + - column_constraint_segment: + - keyword: 'NULL' +- statement_terminator: ; +- statement: + - alter_foreign_table_statement: + - keyword: ALTER + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: myschema + - dot: . + - naked_identifier: distributors + - alter_foreign_table_action_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - keyword: ADD + - naked_identifier: opt1 + - quoted_literal: '''value''' + - comma: ',' + - keyword: SET + - naked_identifier: opt2 + - quoted_literal: '''value2''' + - comma: ',' + - keyword: DROP + - naked_identifier: opt3 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_foreign_table_statement: + - keyword: ALTER + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: test + - alter_foreign_table_action_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - keyword: SET + - naked_identifier: table + - quoted_literal: $$(select my_column from my_table)$$ + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_foreign_table_statement: + - keyword: ALTER + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: test + - alter_foreign_table_action_segment: + - keyword: ADD + - keyword: COLUMN + - column_reference: + - naked_identifier: new_column + - data_type: + - keyword: int8 + - comma: ',' + - alter_foreign_table_action_segment: + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - keyword: SET + - naked_identifier: table + - quoted_literal: $$(select my_column from my_table)$$ + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_foreign_table_statement: + - keyword: ALTER + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: test + - keyword: RENAME + - keyword: TO + - table_reference: + - naked_identifier: test_renamed +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_index.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_index.yml index 1449983aa..ef8df5c76 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_index.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_index.yml @@ -3,18 +3,18 @@ file: - alter_index_statement: - keyword: ALTER - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: distributors - keyword: RENAME - keyword: TO - - database_reference: + - index_reference: - naked_identifier: suppliers - statement_terminator: ; - statement: - alter_index_statement: - keyword: ALTER - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: distributors - keyword: SET - keyword: TABLESPACE @@ -25,7 +25,7 @@ file: - alter_index_statement: - keyword: ALTER - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: distributors - keyword: SET - bracketed: @@ -40,7 +40,7 @@ file: - alter_index_statement: - keyword: ALTER - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: coord_idx - keyword: ALTER - keyword: COLUMN @@ -55,18 +55,18 @@ file: - keyword: INDEX - keyword: IF - keyword: EXISTS - - database_reference: + - index_reference: - naked_identifier: foo - keyword: ATTACH - keyword: PARTITION - - database_reference: + - index_reference: - naked_identifier: bar - statement_terminator: ; - statement: - alter_index_statement: - keyword: ALTER - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: foo - keyword: NO - keyword: DEPENDS @@ -79,7 +79,7 @@ file: - alter_index_statement: - keyword: ALTER - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: foo - keyword: RESET - bracketed: @@ -93,7 +93,7 @@ file: - alter_index_statement: - keyword: ALTER - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: foo - keyword: ALTER - numeric_literal: '4' diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_materialized_view.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_materialized_view.yml index 073c9c2aa..01fa0b9fc 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_materialized_view.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_materialized_view.yml @@ -403,9 +403,8 @@ file: - naked_identifier: bar - keyword: SET - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: new_schema + - schema_reference: + - naked_identifier: new_schema - statement_terminator: ; - statement: - alter_materialized_view_statement: @@ -418,9 +417,8 @@ file: - naked_identifier: bar - keyword: SET - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: new_schema + - schema_reference: + - naked_identifier: new_schema - statement_terminator: ; - statement: - alter_materialized_view_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_policy.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_policy.sql index 051293718..abb2d81ba 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_policy.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_policy.sql @@ -24,3 +24,8 @@ ALTER POLICY sales_rep_is_self ON invoices WITH CHECK (sales_rep = CURRENT_USER AND CURRENT_USER IN ( SELECT user_id FROM allowed_users )); + +ALTER POLICY test_policy ON test_table + TO public, session_user + USING (username = current_user) + WITH CHECK (col > 10); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_policy.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_policy.yml index 70a402b0c..5f7f31656 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_policy.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_policy.yml @@ -106,8 +106,7 @@ file: - naked_identifier: username - comparison_operator: - raw_comparison_operator: = - - column_reference: - - naked_identifier: current_user + - bare_function: current_user - end_bracket: ) - statement_terminator: ; - statement: @@ -128,11 +127,9 @@ file: - naked_identifier: sales_rep - comparison_operator: - raw_comparison_operator: = - - column_reference: - - naked_identifier: CURRENT_USER + - bare_function: CURRENT_USER - binary_operator: AND - - column_reference: - - naked_identifier: CURRENT_USER + - bare_function: CURRENT_USER - keyword: IN - bracketed: - start_bracket: ( @@ -152,3 +149,39 @@ file: - end_bracket: ) - end_bracket: ) - statement_terminator: ; +- statement: + - alter_policy_statement: + - keyword: ALTER + - keyword: POLICY + - object_reference: + - naked_identifier: test_policy + - keyword: ON + - table_reference: + - naked_identifier: test_table + - keyword: TO + - role_reference: + - naked_identifier: public + - comma: ',' + - keyword: session_user + - keyword: USING + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: username + - comparison_operator: + - raw_comparison_operator: = + - bare_function: current_user + - end_bracket: ) + - keyword: WITH + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '10' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_procedure.yml index b4a2bc03e..1431d433f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_procedure.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_procedure.yml @@ -74,9 +74,8 @@ file: - end_bracket: ) - keyword: SET - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: accounting + - schema_reference: + - naked_identifier: accounting - statement_terminator: ; - statement: - alter_procedure_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_publication.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_publication.yml index e50f47dab..aa2395ef9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_publication.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_publication.yml @@ -83,13 +83,11 @@ file: - keyword: TABLES - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: y + - schema_reference: + - naked_identifier: y - comma: ',' - - table_reference: - - object_reference: - - naked_identifier: z + - schema_reference: + - naked_identifier: z - comma: ',' - keyword: CURRENT_SCHEMA - statement_terminator: ; @@ -251,13 +249,11 @@ file: - keyword: TABLES - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: marketing + - schema_reference: + - naked_identifier: marketing - comma: ',' - - table_reference: - - object_reference: - - naked_identifier: sales + - schema_reference: + - naked_identifier: sales - statement_terminator: ; - statement: - alter_publication_statement: @@ -280,7 +276,6 @@ file: - keyword: TABLES - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: production + - schema_reference: + - naked_identifier: production - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_schema.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_schema.yml index a501e8558..cf8a29af7 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_schema.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_schema.yml @@ -3,22 +3,19 @@ file: - alter_schema_statement: - keyword: ALTER - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: RENAME - keyword: TO - - table_reference: - - object_reference: - - naked_identifier: schema2 + - schema_reference: + - naked_identifier: schema2 - statement_terminator: ; - statement: - alter_schema_statement: - keyword: ALTER - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: OWNER - keyword: TO - role_reference: diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_sequence.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_sequence.sql index eec0d17e2..e972440d5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_sequence.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_sequence.sql @@ -21,3 +21,5 @@ ALTER SEQUENCE foo OWNER TO SESSION_USER; ALTER SEQUENCE foo RENAME TO foo2; ALTER SEQUENCE foo SET SCHEMA my_schema; + +ALTER SEQUENCE foo INCREMENT BY -4 MINVALUE -100 MAXVALUE +2; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_sequence.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_sequence.yml index 0b32c0307..a4b811fb3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_sequence.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_sequence.yml @@ -5,7 +5,7 @@ file: - keyword: SEQUENCE - keyword: IF - keyword: EXISTS - - column_reference: + - sequence_reference: - naked_identifier: foo - alter_sequence_options_segment: - keyword: AS @@ -16,7 +16,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - alter_sequence_options_segment: - keyword: INCREMENT @@ -33,7 +33,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - alter_sequence_options_segment: - keyword: INCREMENT @@ -49,7 +49,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - alter_sequence_options_segment: - keyword: START @@ -62,7 +62,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - alter_sequence_options_segment: - keyword: RESTART @@ -76,7 +76,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - alter_sequence_options_segment: - keyword: OWNED @@ -90,7 +90,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - alter_sequence_options_segment: - keyword: OWNED @@ -103,7 +103,7 @@ file: - keyword: SEQUENCE - keyword: IF - keyword: EXISTS - - column_reference: + - sequence_reference: - naked_identifier: foo - keyword: OWNER - keyword: TO @@ -113,7 +113,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - keyword: OWNER - keyword: TO @@ -123,7 +123,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - keyword: OWNER - keyword: TO @@ -133,22 +133,41 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - keyword: RENAME - keyword: TO - - column_reference: + - sequence_reference: - naked_identifier: foo2 - statement_terminator: ; - statement: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - keyword: SET - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema +- statement_terminator: ; +- statement: + - alter_sequence_statement: + - keyword: ALTER + - keyword: SEQUENCE + - sequence_reference: + - naked_identifier: foo + - alter_sequence_options_segment: + - keyword: INCREMENT + - keyword: BY + - sign_indicator: '-' + - numeric_literal: '4' + - alter_sequence_options_segment: + - keyword: MINVALUE + - sign_indicator: '-' + - numeric_literal: '100' + - alter_sequence_options_segment: + - keyword: MAXVALUE + - sign_indicator: + + - numeric_literal: '2' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_statistics.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_statistics.yml index ff6471c5f..b8b5c9f18 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_statistics.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_statistics.yml @@ -1,40 +1,43 @@ file: - statement: - - keyword: ALTER - - keyword: STATISTICS - - object_reference: - - naked_identifier: foo - - keyword: OWNER - - keyword: TO - - parameter: CURRENT_USER + - alter_statistics_statement: + - keyword: ALTER + - keyword: STATISTICS + - statistics_reference: + - naked_identifier: foo + - keyword: OWNER + - keyword: TO + - parameter: CURRENT_USER - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: STATISTICS - - object_reference: - - naked_identifier: foo - - keyword: RENAME - - keyword: TO - - object_reference: - - naked_identifier: bar + - alter_statistics_statement: + - keyword: ALTER + - keyword: STATISTICS + - statistics_reference: + - naked_identifier: foo + - keyword: RENAME + - keyword: TO + - statistics_reference: + - naked_identifier: bar - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: STATISTICS - - object_reference: - - naked_identifier: foo - - keyword: SET - - keyword: SCHEMA - - table_reference: - - object_reference: + - alter_statistics_statement: + - keyword: ALTER + - keyword: STATISTICS + - statistics_reference: + - naked_identifier: foo + - keyword: SET + - keyword: SCHEMA + - schema_reference: - naked_identifier: my_schema - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: STATISTICS - - object_reference: - - naked_identifier: foo - - keyword: SET - - keyword: STATISTICS - - numeric_literal: '4' + - alter_statistics_statement: + - keyword: ALTER + - keyword: STATISTICS + - statistics_reference: + - naked_identifier: foo + - keyword: SET + - keyword: STATISTICS + - numeric_literal: '4' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_subscription.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_subscription.sql new file mode 100644 index 000000000..b9a923e9e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_subscription.sql @@ -0,0 +1,3 @@ +ALTER SUBSCRIPTION my_subscription DISABLE; + +ALTER SUBSCRIPTION mysub SET PUBLICATION insert_only; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_subscription.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_subscription.yml new file mode 100644 index 000000000..3002613db --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_subscription.yml @@ -0,0 +1,20 @@ +file: +- statement: + - alter_subscription: + - keyword: ALTER + - keyword: SUBSCRIPTION + - subscription_reference: + - naked_identifier: my_subscription + - keyword: DISABLE +- statement_terminator: ; +- statement: + - alter_subscription: + - keyword: ALTER + - keyword: SUBSCRIPTION + - subscription_reference: + - naked_identifier: mysub + - keyword: SET + - keyword: PUBLICATION + - publication_reference: + - naked_identifier: insert_only +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_table.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_table.yml index 890c49557..68f972385 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_table.yml @@ -1042,9 +1042,8 @@ file: - naked_identifier: distributors - keyword: SET - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: yourschema + - schema_reference: + - naked_identifier: yourschema - statement_terminator: ; - statement: - alter_table_statement: @@ -1067,7 +1066,7 @@ file: - keyword: KEY - keyword: USING - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: dist_id_temp_idx - statement_terminator: ; - statement: @@ -1374,7 +1373,7 @@ file: - alter_sequence_options_segment: - keyword: SEQUENCE - keyword: NAME - - column_reference: + - sequence_reference: - naked_identifier: public - dot: . - naked_identifier: history_id_seq diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_text_search_configuration.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_text_search_configuration.sql new file mode 100644 index 000000000..2a9c8df21 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_text_search_configuration.sql @@ -0,0 +1,8 @@ +ALTER TEXT SEARCH CONFIGURATION my_config ADD MAPPING FOR asciiword WITH english_stem; +ALTER TEXT SEARCH CONFIGURATION my_config ALTER MAPPING FOR word WITH french_stem; +ALTER TEXT SEARCH CONFIGURATION my_config ALTER MAPPING REPLACE english WITH french; +ALTER TEXT SEARCH CONFIGURATION my_config ALTER MAPPING FOR asciiword REPLACE english_stem WITH french_stem; +ALTER TEXT SEARCH CONFIGURATION my_config DROP MAPPING IF EXISTS FOR email; +ALTER TEXT SEARCH CONFIGURATION my_config RENAME TO new_config; +ALTER TEXT SEARCH CONFIGURATION my_config OWNER TO new_owner; +ALTER TEXT SEARCH CONFIGURATION my_config SET SCHEMA new_schema; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_text_search_configuration.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_text_search_configuration.yml new file mode 100644 index 000000000..f0bec55dc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_text_search_configuration.yml @@ -0,0 +1,127 @@ +file: +- statement: + - alter_text_search_configuration_statement: + - keyword: ALTER + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - object_reference: + - naked_identifier: my_config + - keyword: ADD + - keyword: MAPPING + - keyword: FOR + - object_reference: + - naked_identifier: asciiword + - keyword: WITH + - object_reference: + - naked_identifier: english_stem +- statement_terminator: ; +- statement: + - alter_text_search_configuration_statement: + - keyword: ALTER + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - object_reference: + - naked_identifier: my_config + - keyword: ALTER + - keyword: MAPPING + - keyword: FOR + - object_reference: + - naked_identifier: word + - keyword: WITH + - object_reference: + - naked_identifier: french_stem +- statement_terminator: ; +- statement: + - alter_text_search_configuration_statement: + - keyword: ALTER + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - object_reference: + - naked_identifier: my_config + - keyword: ALTER + - keyword: MAPPING + - keyword: REPLACE + - object_reference: + - naked_identifier: english + - keyword: WITH + - object_reference: + - naked_identifier: french +- statement_terminator: ; +- statement: + - alter_text_search_configuration_statement: + - keyword: ALTER + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - object_reference: + - naked_identifier: my_config + - keyword: ALTER + - keyword: MAPPING + - keyword: FOR + - object_reference: + - naked_identifier: asciiword + - keyword: REPLACE + - object_reference: + - naked_identifier: english_stem + - keyword: WITH + - object_reference: + - naked_identifier: french_stem +- statement_terminator: ; +- statement: + - alter_text_search_configuration_statement: + - keyword: ALTER + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - object_reference: + - naked_identifier: my_config + - keyword: DROP + - keyword: MAPPING + - keyword: IF + - keyword: EXISTS + - keyword: FOR + - object_reference: + - naked_identifier: email +- statement_terminator: ; +- statement: + - alter_text_search_configuration_statement: + - keyword: ALTER + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - object_reference: + - naked_identifier: my_config + - keyword: RENAME + - keyword: TO + - object_reference: + - naked_identifier: new_config +- statement_terminator: ; +- statement: + - alter_text_search_configuration_statement: + - keyword: ALTER + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - object_reference: + - naked_identifier: my_config + - keyword: OWNER + - keyword: TO + - object_reference: + - naked_identifier: new_owner +- statement_terminator: ; +- statement: + - alter_text_search_configuration_statement: + - keyword: ALTER + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - object_reference: + - naked_identifier: my_config + - keyword: SET + - keyword: SCHEMA + - object_reference: + - naked_identifier: new_schema +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_type.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_type.yml index fa029b6a7..022d4bc4c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_type.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_type.yml @@ -3,8 +3,8 @@ file: - alter_type_statement: - keyword: ALTER - keyword: TYPE - - object_reference: - - naked_identifier: foo + - data_type: + - data_type_identifier: foo - keyword: RENAME - keyword: TO - object_reference: @@ -14,8 +14,8 @@ file: - alter_type_statement: - keyword: ALTER - keyword: TYPE - - object_reference: - - naked_identifier: foo + - data_type: + - data_type_identifier: foo - keyword: OWNER - keyword: TO - keyword: CURRENT_USER @@ -24,8 +24,8 @@ file: - alter_type_statement: - keyword: ALTER - keyword: TYPE - - object_reference: - - naked_identifier: foo + - data_type: + - data_type_identifier: foo - keyword: OWNER - keyword: TO - object_reference: @@ -35,20 +35,19 @@ file: - alter_type_statement: - keyword: ALTER - keyword: TYPE - - object_reference: - - naked_identifier: foo + - data_type: + - data_type_identifier: foo - keyword: SET - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: new_schema + - schema_reference: + - naked_identifier: new_schema - statement_terminator: ; - statement: - alter_type_statement: - keyword: ALTER - keyword: TYPE - - object_reference: - - naked_identifier: compfoo + - data_type: + - data_type_identifier: compfoo - keyword: ADD - keyword: ATTRIBUTE - column_reference: @@ -75,8 +74,8 @@ file: - alter_type_statement: - keyword: ALTER - keyword: TYPE - - object_reference: - - naked_identifier: compfoo + - data_type: + - data_type_identifier: compfoo - keyword: RENAME - keyword: ATTRIBUTE - column_reference: @@ -89,8 +88,8 @@ file: - alter_type_statement: - keyword: ALTER - keyword: TYPE - - object_reference: - - naked_identifier: colors + - data_type: + - data_type_identifier: colors - keyword: ADD - keyword: VALUE - quoted_literal: '''orange''' @@ -101,8 +100,8 @@ file: - alter_type_statement: - keyword: ALTER - keyword: TYPE - - object_reference: - - naked_identifier: foo + - data_type: + - data_type_identifier: foo - keyword: ADD - keyword: VALUE - quoted_literal: '''baz''' @@ -111,8 +110,8 @@ file: - alter_type_statement: - keyword: ALTER - keyword: TYPE - - object_reference: - - naked_identifier: foo + - data_type: + - data_type_identifier: foo - keyword: ADD - keyword: VALUE - quoted_literal: '''qux''' @@ -123,8 +122,8 @@ file: - alter_type_statement: - keyword: ALTER - keyword: TYPE - - object_reference: - - naked_identifier: foo + - data_type: + - data_type_identifier: foo - keyword: ADD - keyword: VALUE - quoted_literal: '''quux''' @@ -135,10 +134,10 @@ file: - alter_type_statement: - keyword: ALTER - keyword: TYPE - - object_reference: + - data_type: - naked_identifier: financial - dot: . - - naked_identifier: reporting_statuses + - data_type_identifier: reporting_statuses - keyword: RENAME - keyword: VALUE - quoted_literal: '''partially''' diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_view.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_view.yml index f25578b69..a30283bad 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_view.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/alter_view.yml @@ -505,9 +505,8 @@ file: - naked_identifier: myview - keyword: SET - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: new_schema + - schema_reference: + - naked_identifier: new_schema - statement_terminator: ; - statement: - alter_view_statement: @@ -519,9 +518,8 @@ file: - naked_identifier: myview - keyword: SET - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: new_schema + - schema_reference: + - naked_identifier: new_schema - statement_terminator: ; - statement: - alter_view_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/array.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/array.yml index fcb6472e0..a40470dc9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/array.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/array.yml @@ -60,26 +60,26 @@ file: - naked_identifier: sal_emp - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: name - - data_type: - - keyword: text + - data_type: + - keyword: text - comma: ',' - - column_reference: + - column_definition: - naked_identifier: pay_by_quarter - - data_type: - - keyword: integer - - start_square_bracket: '[' - - end_square_bracket: ']' + - data_type: + - keyword: integer + - start_square_bracket: '[' + - end_square_bracket: ']' - comma: ',' - - column_reference: + - column_definition: - naked_identifier: schedule - - data_type: - - keyword: text - - start_square_bracket: '[' - - end_square_bracket: ']' - - start_square_bracket: '[' - - end_square_bracket: ']' + - data_type: + - keyword: text + - start_square_bracket: '[' + - end_square_bracket: ']' + - start_square_bracket: '[' + - end_square_bracket: ']' - end_bracket: ) - statement_terminator: ; - statement: @@ -90,18 +90,18 @@ file: - naked_identifier: tictactoe - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: squares - - data_type: - - keyword: integer - - start_square_bracket: '[' - - expression: - - numeric_literal: '3' - - end_square_bracket: ']' - - start_square_bracket: '[' - - expression: - - numeric_literal: '3' - - end_square_bracket: ']' + - data_type: + - keyword: integer + - start_square_bracket: '[' + - expression: + - numeric_literal: '3' + - end_square_bracket: ']' + - start_square_bracket: '[' + - expression: + - numeric_literal: '3' + - end_square_bracket: ']' - end_bracket: ) - statement_terminator: ; - statement: @@ -546,7 +546,8 @@ file: - numeric_literal: '3' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: e1 - comma: ',' - select_clause_element: @@ -568,7 +569,8 @@ file: - numeric_literal: '5' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: e2 - from_clause: - keyword: FROM @@ -590,11 +592,13 @@ file: - start_square_bracket: '[' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: f1 - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: ss - statement_terminator: ; - statement: @@ -609,7 +613,8 @@ file: - data_type: - data_type_identifier: _text - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: text_array - statement_terminator: ; - statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/bare_functions.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/bare_functions.sql index b984ff536..a5645acf5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/bare_functions.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/bare_functions.sql @@ -3,5 +3,11 @@ SELECT current_timestamp AS col2, current_time as col3, localtime as col4, - localtimestamp as col5 + localtimestamp as col5, + current_role as col6, + current_schema as col7, + current_user as col8, + session_user as col9, + system_user as col10, + user as col11 ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/bare_functions.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/bare_functions.yml index b329217f7..b275f8721 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/bare_functions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/bare_functions.yml @@ -6,30 +6,77 @@ file: - select_clause_element: - bare_function: current_date - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col1 - comma: ',' - select_clause_element: - bare_function: current_timestamp - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col2 - comma: ',' - select_clause_element: - bare_function: current_time - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: col3 - comma: ',' - select_clause_element: - bare_function: localtime - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: col4 - comma: ',' - select_clause_element: - bare_function: localtimestamp - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: col5 + - comma: ',' + - select_clause_element: + - bare_function: current_role + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: col6 + - comma: ',' + - select_clause_element: + - bare_function: current_schema + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: col7 + - comma: ',' + - select_clause_element: + - bare_function: current_user + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: col8 + - comma: ',' + - select_clause_element: + - bare_function: session_user + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: col9 + - comma: ',' + - select_clause_element: + - bare_function: system_user + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: col10 + - comma: ',' + - select_clause_element: + - bare_function: user + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: col11 - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/cluster.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/cluster.yml index 941179772..26a56c236 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/cluster.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/cluster.yml @@ -5,7 +5,7 @@ file: - table_reference: - naked_identifier: employees - keyword: USING - - database_reference: + - index_reference: - naked_identifier: employees_ind - statement_terminator: ; - statement: @@ -15,7 +15,7 @@ file: - table_reference: - naked_identifier: employees - keyword: USING - - database_reference: + - index_reference: - naked_identifier: employees_ind - statement_terminator: ; - statement: @@ -36,7 +36,7 @@ file: - statement: - cluster_statement: - keyword: CLUSTER - - database_reference: + - index_reference: - naked_identifier: index_name - keyword: ON - table_reference: @@ -50,6 +50,6 @@ file: - dot: . - naked_identifier: temp_table - keyword: USING - - database_reference: + - index_reference: - naked_identifier: idx_temp_table_ra - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/comment_on.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/comment_on.yml index 43ff7d2bd..c231c8d06 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/comment_on.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/comment_on.yml @@ -230,7 +230,7 @@ file: - keyword: COMMENT - keyword: ON - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: my_index - keyword: IS - quoted_literal: '''Enforces uniqueness on employee ID''' @@ -362,9 +362,8 @@ file: - keyword: COMMENT - keyword: ON - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - keyword: IS - quoted_literal: '''Departmental data''' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/composite_types.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/composite_types.yml index 7626c2fde..462577152 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/composite_types.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/composite_types.yml @@ -3,25 +3,19 @@ file: - create_type_statement: - keyword: CREATE - keyword: TYPE - - object_reference: - - naked_identifier: my_type + - data_type: + - data_type_identifier: my_type - keyword: AS - bracketed: - start_bracket: ( - - column_reference: - - naked_identifier: int_ - - data_type: - - keyword: INT4 + - word: int_ + - word: INT4 - comma: ',' - - column_reference: - - naked_identifier: bool_ - - data_type: - - keyword: BOOLEAN + - word: bool_ + - word: BOOLEAN - comma: ',' - - column_reference: - - naked_identifier: comment_ - - data_type: - - keyword: TEXT + - word: comment_ + - word: TEXT - end_bracket: ) - statement_terminator: ; - statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/composite_value_expansion.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/composite_value_expansion.sql new file mode 100644 index 000000000..47f793ea4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/composite_value_expansion.sql @@ -0,0 +1,12 @@ +SELECT (JSONB_EACH_TEXT(data)).* FROM table1; +SELECT (JSONB_EACH_TEXT(w.inventory_events)).* FROM public.widget AS w; +SELECT (JSON_EACH(config)).* FROM settings; +SELECT (JSONB_EACH(items)).* FROM inventory; +SELECT + id, + (JSONB_EACH_TEXT(data)).*, + (JSON_EACH(metadata)).* +FROM table1; +SELECT (JSONB_EACH_TEXT(COALESCE(data, '{}'::jsonb))).* FROM table1; +SELECT (composite_column).* FROM my_table; +SELECT (myfunc(x)).* FROM my_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/composite_value_expansion.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/composite_value_expansion.yml new file mode 100644 index 000000000..b98d1d4e0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/composite_value_expansion.yml @@ -0,0 +1,279 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - composite_value_expansion: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: JSONB_EACH_TEXT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: data + - end_bracket: ) + - end_bracket: ) + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - composite_value_expansion: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: JSONB_EACH_TEXT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: w + - dot: . + - naked_identifier: inventory_events + - end_bracket: ) + - end_bracket: ) + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: public + - dot: . + - naked_identifier: widget + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: w +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - composite_value_expansion: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: JSON_EACH + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: config + - end_bracket: ) + - end_bracket: ) + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: settings +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - composite_value_expansion: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: JSONB_EACH + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: items + - end_bracket: ) + - end_bracket: ) + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: inventory +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - composite_value_expansion: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: JSONB_EACH_TEXT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: data + - end_bracket: ) + - end_bracket: ) + - dot: . + - star: '*' + - comma: ',' + - select_clause_element: + - composite_value_expansion: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: JSON_EACH + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: metadata + - end_bracket: ) + - end_bracket: ) + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - composite_value_expansion: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: JSONB_EACH_TEXT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: COALESCE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: data + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''{}''' + - casting_operator: '::' + - data_type: + - keyword: jsonb + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - composite_value_expansion: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: composite_column + - end_bracket: ) + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - composite_value_expansion: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: myfunc + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - end_bracket: ) + - end_bracket: ) + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/copy.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/copy.sql index 840f881ab..24ba61a02 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/copy.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/copy.sql @@ -8,6 +8,7 @@ COPY (Select * From my_table) TO '/tmp/dump.csv' WITH (FORMAT csv, ESCAPE '\', F COPY (Select * From my_table) TO '/tmp/dump.csv' WITH (FORMAT csv, ESCAPE '\', FORCE_NULL (col1, col2), FREEZE false); COPY (Select * From my_table) TO STDOUT WITH (FORMAT csv, ESCAPE '\', FORCE_NULL (col1, col2), FREEZE true); COPY (Select * From my_table) TO PROGRAM '/path/to/script' WITH (FORMAT csv, ESCAPE '\', FORCE_NULL (col1, col2), FREEZE false); +COPY (WITH c AS (SELECT 1::int AS id) SELECT id FROM c) TO STDOUT WITH (FORMAT csv, HEADER); COPY my_table(col) TO '/tmp/dump.csv'; COPY my_table TO '/tmp/dump.csv' WITH (FORMAT csv, HEADER true, FREEZE true, FORCE_NULL (col1, col2)); COPY my_table(col1, col2) TO '/tmp/dump.csv' WITH (FORMAT csv, HEADER true); @@ -29,3 +30,48 @@ COPY my_table FROM STDIN WITH (FORMAT csv, HEADER, DELIMITER '#', ENCODING 'UTF8 COPY my_table FROM STDIN WITH (FORMAT csv, ESCAPE '\', FORCE_NULL (col1, col2), FREEZE true); COPY my_table FROM STDIN WITH (FORMAT csv, HEADER, DELIMITER '#', NULL 'null', QUOTE '"', FORCE_QUOTE *); COPY my_table FROM STDIN WITH (FORMAT csv, HEADER, DELIMITER '#', NULL 'null', QUOTE '"', FORCE_QUOTE *) WHERE col1 = 'some_value'; + +COPY copy_statement_bug FROM stdin WITH csv header; +COPY my_table FROM STDIN WITH; +COPY my_table FROM STDIN WITH BINARY; +COPY my_table FROM STDIN WITH DELIMITER '#'; +COPY my_table FROM STDIN WITH DELIMITER AS '#'; +COPY my_table FROM STDIN WITH NULL 'null'; +COPY my_table FROM STDIN WITH NULL AS 'null'; +COPY my_table FROM STDIN WITH CSV; +COPY my_table FROM STDIN WITH CSV QUOTE '"'; +COPY my_table FROM STDIN WITH CSV QUOTE AS '"'; +COPY my_table FROM STDIN WITH CSV ESCAPE '\'; +COPY my_table FROM STDIN WITH CSV ESCAPE AS '\'; +COPY my_table FROM STDIN WITH CSV FORCE NOT NULL col1; +COPY my_table FROM STDIN WITH CSV FORCE NOT NULL col1, col2; + +COPY my_table FROM '/tmp/dump.csv' WITH BINARY; +COPY my_table FROM '/tmp/dump.csv' WITH DELIMITER '#'; +COPY my_table FROM '/tmp/dump.csv' WITH DELIMITER AS '#'; +COPY my_table FROM '/tmp/dump.csv' WITH NULL 'null'; +COPY my_table FROM '/tmp/dump.csv' WITH NULL AS 'null'; +COPY my_table FROM '/tmp/dump.csv' WITH CSV; +COPY my_table FROM '/tmp/dump.csv' WITH CSV QUOTE '"'; +COPY my_table FROM '/tmp/dump.csv' WITH CSV QUOTE AS '"'; +COPY my_table FROM '/tmp/dump.csv' WITH CSV ESCAPE '\'; +COPY my_table FROM '/tmp/dump.csv' WITH CSV ESCAPE AS '\'; + +COPY (SELECT * FROM country WHERE country_name LIKE 'A%') TO '/usr1/proj/bray/sql/a_list_countries.copy'; +COPY my_table(col1, col2) TO STDOUT; +COPY my_table(col2) TO STDOUT; +COPY my_table(col1, col2) TO STDOUT WITH; +COPY my_table(col1, col2) TO STDOUT WITH BINARY; +COPY my_table(col1, col2) TO STDOUT WITH DELIMITER '#'; +COPY my_table(col1, col2) TO STDOUT WITH DELIMITER AS '#'; +COPY my_table TO STDOUT WITH NULL 'null'; +COPY my_table TO STDOUT WITH NULL AS 'null'; + +COPY my_table(col1) TO STDOUT WITH CSV; +COPY my_table TO STDOUT WITH CSV HEADER; +COPY my_table TO STDOUT WITH CSV QUOTE '"'; +COPY my_table TO STDOUT WITH CSV QUOTE AS '"'; +COPY my_table TO STDOUT WITH CSV ESCAPE '\'; +COPY my_table(col1, col2) TO STDOUT WITH CSV ESCAPE AS '\'; +COPY my_table(col1, col2) TO STDOUT WITH CSV FORCE QUOTE *; +COPY my_table(col1, col2) TO STDOUT WITH CSV FORCE QUOTE (col1, col2); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/copy.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/copy.yml index 1994970b0..5c9d4c3a2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/copy.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/copy.yml @@ -365,6 +365,58 @@ file: - boolean_literal: 'false' - end_bracket: ) - statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: c + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - numeric_literal: '1' + - casting_operator: '::' + - data_type: + - keyword: int + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: id + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: c + - end_bracket: ) + - keyword: TO + - keyword: STDOUT + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FORMAT + - naked_identifier: csv + - comma: ',' + - keyword: HEADER + - end_bracket: ) +- statement_terminator: ; - statement: - copy_statement: - keyword: COPY @@ -809,3 +861,577 @@ file: - raw_comparison_operator: = - quoted_literal: '''some_value''' - statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: copy_statement_bug + - keyword: FROM + - keyword: stdin + - keyword: WITH + - keyword: csv + - keyword: header +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - keyword: STDIN + - keyword: WITH +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - keyword: STDIN + - keyword: WITH + - keyword: BINARY +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - keyword: STDIN + - keyword: WITH + - keyword: DELIMITER + - quoted_literal: '''#''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - keyword: STDIN + - keyword: WITH + - keyword: DELIMITER + - keyword: AS + - quoted_literal: '''#''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - keyword: STDIN + - keyword: WITH + - keyword: 'NULL' + - quoted_literal: '''null''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - keyword: STDIN + - keyword: WITH + - keyword: 'NULL' + - keyword: AS + - quoted_literal: '''null''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - keyword: STDIN + - keyword: WITH + - keyword: CSV +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - keyword: STDIN + - keyword: WITH + - keyword: CSV + - keyword: QUOTE + - quoted_literal: '''"''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - keyword: STDIN + - keyword: WITH + - keyword: CSV + - keyword: QUOTE + - keyword: AS + - quoted_literal: '''"''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - keyword: STDIN + - keyword: WITH + - keyword: CSV + - keyword: ESCAPE + - quoted_literal: '''\''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - keyword: STDIN + - keyword: WITH + - keyword: CSV + - keyword: ESCAPE + - keyword: AS + - quoted_literal: '''\''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - keyword: STDIN + - keyword: WITH + - keyword: CSV + - keyword: FORCE + - keyword: NOT + - keyword: 'NULL' + - column_reference: + - naked_identifier: col1 +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - keyword: STDIN + - keyword: WITH + - keyword: CSV + - keyword: FORCE + - keyword: NOT + - keyword: 'NULL' + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - quoted_literal: '''/tmp/dump.csv''' + - keyword: WITH + - keyword: BINARY +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - quoted_literal: '''/tmp/dump.csv''' + - keyword: WITH + - keyword: DELIMITER + - quoted_literal: '''#''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - quoted_literal: '''/tmp/dump.csv''' + - keyword: WITH + - keyword: DELIMITER + - keyword: AS + - quoted_literal: '''#''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - quoted_literal: '''/tmp/dump.csv''' + - keyword: WITH + - keyword: 'NULL' + - quoted_literal: '''null''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - quoted_literal: '''/tmp/dump.csv''' + - keyword: WITH + - keyword: 'NULL' + - keyword: AS + - quoted_literal: '''null''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - quoted_literal: '''/tmp/dump.csv''' + - keyword: WITH + - keyword: CSV +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - quoted_literal: '''/tmp/dump.csv''' + - keyword: WITH + - keyword: CSV + - keyword: QUOTE + - quoted_literal: '''"''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - quoted_literal: '''/tmp/dump.csv''' + - keyword: WITH + - keyword: CSV + - keyword: QUOTE + - keyword: AS + - quoted_literal: '''"''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - quoted_literal: '''/tmp/dump.csv''' + - keyword: WITH + - keyword: CSV + - keyword: ESCAPE + - quoted_literal: '''\''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: FROM + - quoted_literal: '''/tmp/dump.csv''' + - keyword: WITH + - keyword: CSV + - keyword: ESCAPE + - keyword: AS + - quoted_literal: '''\''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: country + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: country_name + - keyword: LIKE + - quoted_literal: '''A%''' + - end_bracket: ) + - keyword: TO + - quoted_literal: '''/usr1/proj/bray/sql/a_list_countries.copy''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: TO + - keyword: STDOUT +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: TO + - keyword: STDOUT +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: TO + - keyword: STDOUT + - keyword: WITH +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: TO + - keyword: STDOUT + - keyword: WITH + - keyword: BINARY +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: TO + - keyword: STDOUT + - keyword: WITH + - keyword: DELIMITER + - quoted_literal: '''#''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: TO + - keyword: STDOUT + - keyword: WITH + - keyword: DELIMITER + - keyword: AS + - quoted_literal: '''#''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: TO + - keyword: STDOUT + - keyword: WITH + - keyword: 'NULL' + - quoted_literal: '''null''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: TO + - keyword: STDOUT + - keyword: WITH + - keyword: 'NULL' + - keyword: AS + - quoted_literal: '''null''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: TO + - keyword: STDOUT + - keyword: WITH + - keyword: CSV +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: TO + - keyword: STDOUT + - keyword: WITH + - keyword: CSV + - keyword: HEADER +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: TO + - keyword: STDOUT + - keyword: WITH + - keyword: CSV + - keyword: QUOTE + - quoted_literal: '''"''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: TO + - keyword: STDOUT + - keyword: WITH + - keyword: CSV + - keyword: QUOTE + - keyword: AS + - quoted_literal: '''"''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - keyword: TO + - keyword: STDOUT + - keyword: WITH + - keyword: CSV + - keyword: ESCAPE + - quoted_literal: '''\''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: TO + - keyword: STDOUT + - keyword: WITH + - keyword: CSV + - keyword: ESCAPE + - keyword: AS + - quoted_literal: '''\''' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: TO + - keyword: STDOUT + - keyword: WITH + - keyword: CSV + - keyword: FORCE + - keyword: QUOTE + - star: '*' +- statement_terminator: ; +- statement: + - copy_statement: + - keyword: COPY + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: TO + - keyword: STDOUT + - keyword: WITH + - keyword: CSV + - keyword: FORCE + - keyword: QUOTE + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_aggregate.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_aggregate.sql new file mode 100644 index 000000000..731a66d98 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_aggregate.sql @@ -0,0 +1,6 @@ +CREATE AGGREGATE agg_twocols(numeric, numeric) ( + SFUNC = mysfunc_accum, + STYPE = numeric, + COMBINEFUNC = mycombine_accum, + INITCOND = 0 +); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_aggregate.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_aggregate.yml new file mode 100644 index 000000000..9d4532756 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_aggregate.yml @@ -0,0 +1,48 @@ +file: +- statement: + - create_aggregate_statement: + - keyword: CREATE + - keyword: AGGREGATE + - object_reference: + - naked_identifier: agg_twocols + - bracketed: + - start_bracket: ( + - word: numeric + - comma: ',' + - word: numeric + - end_bracket: ) + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: SFUNC + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: mysfunc_accum + - comma: ',' + - data_type: + - data_type_identifier: STYPE + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: numeric + - comma: ',' + - data_type: + - data_type_identifier: COMBINEFUNC + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: mycombine_accum + - comma: ',' + - data_type: + - data_type_identifier: INITCOND + - comparison_operator: + - raw_comparison_operator: = + - expression: + - numeric_literal: '0' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_domain.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_domain.yml index f6b85ae53..8df81dc90 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_domain.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_domain.yml @@ -15,12 +15,12 @@ file: - expression: - column_reference: - naked_identifier: VALUE - - comparison_operator: '~' + - like_operator: '~' - quoted_literal: '''^\d{5}$''' - binary_operator: OR - column_reference: - naked_identifier: VALUE - - comparison_operator: '~' + - like_operator: '~' - quoted_literal: '''^\d{5}-\d{4}$''' - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_extension.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_extension.sql index aa911b382..eefcbe619 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_extension.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_extension.sql @@ -13,6 +13,8 @@ CREATE EXTENSION amazing_extension VERSION version_named FROM from_named; +CREATE EXTENSION IF NOT EXISTS aws_lambda CASCADE; + DROP EXTENSION amazing_extension; DROP EXTENSION IF EXISTS amazing_extension; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_extension.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_extension.yml index 25a8a4c85..fda9fb77f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_extension.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_extension.yml @@ -7,9 +7,8 @@ file: - naked_identifier: amazing_extension - keyword: with - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: VERSION - version_identifier: - quoted_literal: '''2.0.1.2''' @@ -28,9 +27,8 @@ file: - naked_identifier: amazing_extension - keyword: with - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: VERSION - version_identifier: - quoted_literal: '''1.2.3a4''' @@ -46,9 +44,8 @@ file: - naked_identifier: amazing_extension - keyword: with - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: VERSION - version_identifier: - naked_identifier: version_named @@ -56,6 +53,17 @@ file: - version_identifier: - naked_identifier: from_named - statement_terminator: ; +- statement: + - create_extension_statement: + - keyword: CREATE + - keyword: EXTENSION + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - extension_reference: + - naked_identifier: aws_lambda + - keyword: CASCADE +- statement_terminator: ; - statement: - drop_extension_statement: - keyword: DROP diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_table.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_table.sql new file mode 100644 index 000000000..f13330680 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_table.sql @@ -0,0 +1,135 @@ +CREATE FOREIGN TABLE foreign_table ( + simple_column integer, + column_with_options char(5) OPTIONS (a 'foo', b 'bar'), + column_with_collate text COLLATE "de_DE", + column_with_not_null_constraint date NOT NULL, + column_with_null_constraint varchar(50) NULL, + column_with_check_constraint float CHECK (column_with_check_constraint > 0.0), + column_with_default_constraint timestamp DEFAULT CURRENT_TIMESTAMP, + column_with_generated_constraint bigint GENERATED ALWAYS AS (simple_column * 2) STORED, + column_with_more_than_one_constraint int NOT NULL CHECK (column_with_more_than_one_constraint > 0), + column_with_options_and_collate char(5) OPTIONS (a 'foo', b 'bar') COLLATE "es_ES", + column_with_options_and_constraint char(5) OPTIONS (a 'foo', b 'bar') NOT NULL, + column_with_collate_and_constraint char(5) COLLATE "de_DE" NOT NULL, + column_with_options_collate_and_constraint char(5) OPTIONS (a 'foo', b 'bar') COLLATE "de_DE" NOT NULL, + CHECK (simple_column > 0), + CHECK (simple_column < 10) NO INHERIT, + CONSTRAINT named_table_constraint CHECK (column_with_options <> ''), + CONSTRAINT named_table_constraint_no_inherit CHECK (column_with_collate <> '') NO INHERIT +) +SERVER a_server; + +CREATE FOREIGN TABLE IF NOT EXISTS foreign_table_that_might_already_exist ( + simple_column integer +) +SERVER a_server; + +CREATE FOREIGN TABLE foreign_table_that_inherits ( + simple_column integer +) +INHERITS ( another_table ) +SERVER a_server; + +CREATE FOREIGN TABLE IF NOT EXISTS foreign_table_that_inherits_that_might_already_exist ( + simple_column integer +) +INHERITS ( another_table ) +SERVER a_server; + +CREATE FOREIGN TABLE foreign_table_with_options ( + simple_column integer +) +SERVER a_server +OPTIONS (c 'baz'); + +CREATE FOREIGN TABLE IF NOT EXISTS foreign_table_with_options_that_might_already_exist ( + simple_column integer +) +SERVER a_server +OPTIONS (c 'baz'); + +CREATE FOREIGN TABLE foreign_table_that_inherits_and_has_options ( + simple_column integer +) +INHERITS ( another_table ) +SERVER a_server +OPTIONS (c 'baz'); + +CREATE FOREIGN TABLE IF NOT EXISTS foreign_table_that_inherits_and_has_options_that_might_already_exist ( + simple_column integer +) +INHERITS ( another_table ) +SERVER a_server +OPTIONS (c 'baz'); + +CREATE FOREIGN TABLE foreign_table_partition_in + PARTITION OF another_table FOR VALUES IN ('2016-07-01', '2016-08-01') + SERVER a_server; + +CREATE FOREIGN TABLE foreign_table_partition_from_min_to_max + PARTITION OF another_table FOR VALUES FROM ('2016-07-01') TO ('2016-08-01') + SERVER a_server; + +CREATE FOREIGN TABLE foreign_table_partition_with + PARTITION OF another_table FOR VALUES WITH ( MODULUS 2, REMAINDER 0) + SERVER a_server; + +CREATE FOREIGN TABLE IF NOT EXISTS foreign_table_partition_in_that_might_already_exist + PARTITION OF another_table FOR VALUES IN ('2016-07-01', '2016-08-01') + SERVER a_server; + +CREATE FOREIGN TABLE IF NOT EXISTS foreign_table_partition_from_min_to_max_that_might_already_exist + PARTITION OF another_table FOR VALUES FROM ('2016-07-01') TO ('2016-08-01') + SERVER a_server; + +CREATE FOREIGN TABLE IF NOT EXISTS foreign_table_partition_with_that_might_already_exist + PARTITION OF another_table FOR VALUES WITH ( MODULUS 2, REMAINDER 0) + SERVER a_server; + +CREATE FOREIGN TABLE foreign_table_partition_in_with_options + PARTITION OF another_table FOR VALUES IN ('2016-07-01', '2016-08-01') + SERVER a_server + OPTIONS (foo 'bar'); + +CREATE FOREIGN TABLE foreign_table_partition_from_min_to_max_with_options + PARTITION OF another_table FOR VALUES FROM ('2016-07-01') TO ('2016-08-01') + SERVER a_server + OPTIONS (foo 'bar'); + +CREATE FOREIGN TABLE foreign_table_partition_with_with_options + PARTITION OF another_table FOR VALUES WITH ( MODULUS 2, REMAINDER 0) + SERVER a_server + OPTIONS (foo 'bar'); + +CREATE FOREIGN TABLE foreign_table_partition_in_with_columns + PARTITION OF another_table ( + simple_column, + column_with_options WITH OPTIONS, + column_with_not_null_constraint NOT NULL, + column_with_null_constraint NULL, + column_with_check_constraint CHECK (column_with_check_constraint > 0.0), + column_with_default_constraint DEFAULT CURRENT_TIMESTAMP, + column_with_generated_constraint GENERATED ALWAYS AS (simple_column * 2) STORED, + column_with_more_than_one_constraint NOT NULL CHECK (column_with_more_than_one_constraint > 0), + column_with_options_and_not_null_constraint WITH OPTIONS NOT NULL, + CHECK (simple_column > 0), + CHECK (simple_column < 10) NO INHERIT, + CONSTRAINT named_table_constraint CHECK (column_with_options <> ''), + CONSTRAINT named_table_constraint_no_inherit CHECK (column_with_options_and_not_null_constraint <> '') NO INHERIT + ) + FOR VALUES IN ('2016-07-01', '2016-08-01') + SERVER a_server; + +CREATE FOREIGN TABLE foreign_table_partition_with_from_min_to_max_with_columns + PARTITION OF another_table ( + simple_column + ) + FOR VALUES FROM ('2016-07-01') TO ('2016-08-01') + SERVER a_server; + +CREATE FOREIGN TABLE foreign_table_partition_with_with_columns + PARTITION OF another_table ( + simple_column + ) + FOR VALUES WITH ( MODULUS 2, REMAINDER 0) + SERVER a_server; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_table.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_table.yml new file mode 100644 index 000000000..438dff1ee --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_table.yml @@ -0,0 +1,977 @@ +file: +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: foreign_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: simple_column + - data_type: + - keyword: integer + - comma: ',' + - column_reference: + - naked_identifier: column_with_options + - data_type: + - keyword: char + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - naked_identifier_all: a + - quoted_literal: '''foo''' + - comma: ',' + - naked_identifier_all: b + - quoted_literal: '''bar''' + - end_bracket: ) + - comma: ',' + - column_reference: + - naked_identifier: column_with_collate + - data_type: + - keyword: text + - keyword: COLLATE + - collation_reference: + - quoted_identifier: '"de_DE"' + - comma: ',' + - column_reference: + - naked_identifier: column_with_not_null_constraint + - data_type: + - datetime_type_identifier: + - keyword: date + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_reference: + - naked_identifier: column_with_null_constraint + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '50' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_reference: + - naked_identifier: column_with_check_constraint + - data_type: + - keyword: float + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: column_with_check_constraint + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0.0' + - end_bracket: ) + - comma: ',' + - column_reference: + - naked_identifier: column_with_default_constraint + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - column_constraint_segment: + - keyword: DEFAULT + - bare_function: CURRENT_TIMESTAMP + - comma: ',' + - column_reference: + - naked_identifier: column_with_generated_constraint + - data_type: + - keyword: bigint + - column_constraint_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: simple_column + - binary_operator: '*' + - numeric_literal: '2' + - end_bracket: ) + - keyword: STORED + - comma: ',' + - column_reference: + - naked_identifier: column_with_more_than_one_constraint + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: column_with_more_than_one_constraint + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - column_reference: + - naked_identifier: column_with_options_and_collate + - data_type: + - keyword: char + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - naked_identifier_all: a + - quoted_literal: '''foo''' + - comma: ',' + - naked_identifier_all: b + - quoted_literal: '''bar''' + - end_bracket: ) + - keyword: COLLATE + - collation_reference: + - quoted_identifier: '"es_ES"' + - comma: ',' + - column_reference: + - naked_identifier: column_with_options_and_constraint + - data_type: + - keyword: char + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - naked_identifier_all: a + - quoted_literal: '''foo''' + - comma: ',' + - naked_identifier_all: b + - quoted_literal: '''bar''' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_reference: + - naked_identifier: column_with_collate_and_constraint + - data_type: + - keyword: char + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - keyword: COLLATE + - collation_reference: + - quoted_identifier: '"de_DE"' + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_reference: + - naked_identifier: column_with_options_collate_and_constraint + - data_type: + - keyword: char + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - naked_identifier_all: a + - quoted_literal: '''foo''' + - comma: ',' + - naked_identifier_all: b + - quoted_literal: '''bar''' + - end_bracket: ) + - keyword: COLLATE + - collation_reference: + - quoted_identifier: '"de_DE"' + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - table_constraint: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: simple_column + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: simple_column + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '10' + - end_bracket: ) + - keyword: NO + - keyword: INHERIT + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: named_table_constraint + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: column_with_options + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: '>' + - quoted_literal: '''''' + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: named_table_constraint_no_inherit + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: column_with_collate + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: '>' + - quoted_literal: '''''' + - end_bracket: ) + - keyword: NO + - keyword: INHERIT + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: foreign_table_that_might_already_exist + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: simple_column + - data_type: + - keyword: integer + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: foreign_table_that_inherits + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: simple_column + - data_type: + - keyword: integer + - end_bracket: ) + - keyword: INHERITS + - bracketed: + - start_bracket: ( + - table_reference: + - naked_identifier: another_table + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: foreign_table_that_inherits_that_might_already_exist + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: simple_column + - data_type: + - keyword: integer + - end_bracket: ) + - keyword: INHERITS + - bracketed: + - start_bracket: ( + - table_reference: + - naked_identifier: another_table + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: foreign_table_with_options + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: simple_column + - data_type: + - keyword: integer + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - naked_identifier_all: c + - quoted_literal: '''baz''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: foreign_table_with_options_that_might_already_exist + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: simple_column + - data_type: + - keyword: integer + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - naked_identifier_all: c + - quoted_literal: '''baz''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: foreign_table_that_inherits_and_has_options + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: simple_column + - data_type: + - keyword: integer + - end_bracket: ) + - keyword: INHERITS + - bracketed: + - start_bracket: ( + - table_reference: + - naked_identifier: another_table + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - naked_identifier_all: c + - quoted_literal: '''baz''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: foreign_table_that_inherits_and_has_options_that_might_already_exist + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: simple_column + - data_type: + - keyword: integer + - end_bracket: ) + - keyword: INHERITS + - bracketed: + - start_bracket: ( + - table_reference: + - naked_identifier: another_table + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - naked_identifier_all: c + - quoted_literal: '''baz''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: foreign_table_partition_in + - keyword: PARTITION + - keyword: OF + - table_reference: + - naked_identifier: another_table + - keyword: FOR + - keyword: VALUES + - partition_bound_spec: + - keyword: IN + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2016-07-01''' + - comma: ',' + - expression: + - quoted_literal: '''2016-08-01''' + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: foreign_table_partition_from_min_to_max + - keyword: PARTITION + - keyword: OF + - table_reference: + - naked_identifier: another_table + - keyword: FOR + - keyword: VALUES + - partition_bound_spec: + - keyword: FROM + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2016-07-01''' + - end_bracket: ) + - keyword: TO + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2016-08-01''' + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: foreign_table_partition_with + - keyword: PARTITION + - keyword: OF + - table_reference: + - naked_identifier: another_table + - keyword: FOR + - keyword: VALUES + - partition_bound_spec: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: MODULUS + - numeric_literal: '2' + - comma: ',' + - keyword: REMAINDER + - numeric_literal: '0' + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: foreign_table_partition_in_that_might_already_exist + - keyword: PARTITION + - keyword: OF + - table_reference: + - naked_identifier: another_table + - keyword: FOR + - keyword: VALUES + - partition_bound_spec: + - keyword: IN + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2016-07-01''' + - comma: ',' + - expression: + - quoted_literal: '''2016-08-01''' + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: foreign_table_partition_from_min_to_max_that_might_already_exist + - keyword: PARTITION + - keyword: OF + - table_reference: + - naked_identifier: another_table + - keyword: FOR + - keyword: VALUES + - partition_bound_spec: + - keyword: FROM + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2016-07-01''' + - end_bracket: ) + - keyword: TO + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2016-08-01''' + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: foreign_table_partition_with_that_might_already_exist + - keyword: PARTITION + - keyword: OF + - table_reference: + - naked_identifier: another_table + - keyword: FOR + - keyword: VALUES + - partition_bound_spec: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: MODULUS + - numeric_literal: '2' + - comma: ',' + - keyword: REMAINDER + - numeric_literal: '0' + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: foreign_table_partition_in_with_options + - keyword: PARTITION + - keyword: OF + - table_reference: + - naked_identifier: another_table + - keyword: FOR + - keyword: VALUES + - partition_bound_spec: + - keyword: IN + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2016-07-01''' + - comma: ',' + - expression: + - quoted_literal: '''2016-08-01''' + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - naked_identifier_all: foo + - quoted_literal: '''bar''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: foreign_table_partition_from_min_to_max_with_options + - keyword: PARTITION + - keyword: OF + - table_reference: + - naked_identifier: another_table + - keyword: FOR + - keyword: VALUES + - partition_bound_spec: + - keyword: FROM + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2016-07-01''' + - end_bracket: ) + - keyword: TO + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2016-08-01''' + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - naked_identifier_all: foo + - quoted_literal: '''bar''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: foreign_table_partition_with_with_options + - keyword: PARTITION + - keyword: OF + - table_reference: + - naked_identifier: another_table + - keyword: FOR + - keyword: VALUES + - partition_bound_spec: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: MODULUS + - numeric_literal: '2' + - comma: ',' + - keyword: REMAINDER + - numeric_literal: '0' + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server + - keyword: OPTIONS + - bracketed: + - start_bracket: ( + - naked_identifier_all: foo + - quoted_literal: '''bar''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: foreign_table_partition_in_with_columns + - keyword: PARTITION + - keyword: OF + - table_reference: + - naked_identifier: another_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: simple_column + - comma: ',' + - column_reference: + - naked_identifier: column_with_options + - keyword: WITH + - keyword: OPTIONS + - comma: ',' + - column_reference: + - naked_identifier: column_with_not_null_constraint + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_reference: + - naked_identifier: column_with_null_constraint + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_reference: + - naked_identifier: column_with_check_constraint + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: column_with_check_constraint + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0.0' + - end_bracket: ) + - comma: ',' + - column_reference: + - naked_identifier: column_with_default_constraint + - column_constraint_segment: + - keyword: DEFAULT + - bare_function: CURRENT_TIMESTAMP + - comma: ',' + - column_reference: + - naked_identifier: column_with_generated_constraint + - column_constraint_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: simple_column + - binary_operator: '*' + - numeric_literal: '2' + - end_bracket: ) + - keyword: STORED + - comma: ',' + - column_reference: + - naked_identifier: column_with_more_than_one_constraint + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: column_with_more_than_one_constraint + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - column_reference: + - naked_identifier: column_with_options_and_not_null_constraint + - keyword: WITH + - keyword: OPTIONS + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - table_constraint: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: simple_column + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: simple_column + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '10' + - end_bracket: ) + - keyword: NO + - keyword: INHERIT + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: named_table_constraint + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: column_with_options + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: '>' + - quoted_literal: '''''' + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: named_table_constraint_no_inherit + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: column_with_options_and_not_null_constraint + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: '>' + - quoted_literal: '''''' + - end_bracket: ) + - keyword: NO + - keyword: INHERIT + - end_bracket: ) + - keyword: FOR + - keyword: VALUES + - partition_bound_spec: + - keyword: IN + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2016-07-01''' + - comma: ',' + - expression: + - quoted_literal: '''2016-08-01''' + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: foreign_table_partition_with_from_min_to_max_with_columns + - keyword: PARTITION + - keyword: OF + - table_reference: + - naked_identifier: another_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: simple_column + - end_bracket: ) + - keyword: FOR + - keyword: VALUES + - partition_bound_spec: + - keyword: FROM + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2016-07-01''' + - end_bracket: ) + - keyword: TO + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2016-08-01''' + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server +- statement_terminator: ; +- statement: + - create_foreign_table_statement: + - keyword: CREATE + - keyword: FOREIGN + - keyword: TABLE + - table_reference: + - naked_identifier: foreign_table_partition_with_with_columns + - keyword: PARTITION + - keyword: OF + - table_reference: + - naked_identifier: another_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: simple_column + - end_bracket: ) + - keyword: FOR + - keyword: VALUES + - partition_bound_spec: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: MODULUS + - numeric_literal: '2' + - comma: ',' + - keyword: REMAINDER + - numeric_literal: '0' + - end_bracket: ) + - keyword: SERVER + - server_reference: + - naked_identifier: a_server +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_wrapper.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_wrapper.sql new file mode 100644 index 000000000..2a64f042f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_wrapper.sql @@ -0,0 +1,3 @@ +create foreign data wrapper stripe_wrapper + handler stripe_fdw_handler + validator stripe_fdw_validator; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_wrapper.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_wrapper.yml new file mode 100644 index 000000000..0b3ae5aa0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_foreign_wrapper.yml @@ -0,0 +1,13 @@ +file: +- statement: + - create_foreign_data_wrapper: + - keyword: create + - keyword: foreign + - keyword: data + - keyword: wrapper + - naked_identifier: stripe_wrapper + - keyword: handler + - naked_identifier: stripe_fdw_handler + - keyword: validator + - naked_identifier: stripe_fdw_validator +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_function.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_function.sql index 6341dcc29..e50ac055d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_function.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_function.sql @@ -145,3 +145,79 @@ as $$ return x; end; $$; + +CREATE OR REPLACE FUNCTION data_wrapper() +RETURNS SETOF data +STABLE PARALLEL SAFE LEAKPROOF +BEGIN ATOMIC + SELECT * + FROM data; +END; + +create or replace function tz_date(timestamp with time zone, text) returns date + language sql + immutable strict + return ($1 at time zone $2)::date; + +CREATE FUNCTION storage.insert_dimension +(in_ordinality int, in_fieldname varchar, in_default_val varchar, + in_valid_from timestamp, in_valid_until timestamp) +returns storage.dimensions language sql +BEGIN ATOMIC + UPDATE storage.dimensions + SET ordinality = ordinality + 1 + WHERE ordinality >= in_ordinality; + + INSERT INTO storage.dimensions + (ordinality, fieldname, default_val, valid_from, valid_until) + VALUES (in_ordinality, in_fieldname, + coalesce(in_default_val, 'notexist'), + coalesce(in_valid_from, '-infinity'), + coalesce(in_valid_until, 'infinity')) + RETURNING *; +END; + +CREATE OR REPLACE FUNCTION time_bucket( + _time timestamp without time zone, + _from timestamp without time zone, + _to timestamp without time zone, + _buckets integer DEFAULT 200, + _offset integer DEFAULT 0 +) +RETURNS timestamp without time zone +IMMUTABLE PARALLEL SAFE +BEGIN ATOMIC +SELECT date_bin(((_to - _from) / greatest((_buckets - 1), 1)), _time, _from) + ((_to - _from) / greatest((_buckets - 1), 1)) * (_offset + 1); +END; + +CREATE OR REPLACE FUNCTION time_bucket_limited(_time timestamp, _from timestamp, _to timestamp, _buckets int = 200) + RETURNS timestamp + IMMUTABLE PARALLEL SAFE +BEGIN ATOMIC + RETURN CASE WHEN _time <= _from THEN _from + WHEN _time >= _to THEN _to + ELSE DATE_BIN((_to - _from) / GREATEST(_buckets - 1, 1), _time, _from) + ((_to - _from) / GREATEST(_buckets - 1, 1)) + end; +END; + +CREATE OR REPLACE FUNCTION time_series( + _from timestamp without time zone, + _to timestamp without time zone, + _buckets integer DEFAULT 200 +) +RETURNS TABLE ("time" timestamp without time zone) +IMMUTABLE PARALLEL SAFE +BEGIN ATOMIC +-- ATTENTION: use integer to generate series, since with timestamps there are rounding issues +SELECT time_bucket(_from, _from, _to, _buckets, g.ofs - 1) +FROM generate_series(0, greatest((_buckets - 1), 1)) AS g (ofs); +END; + +create or replace function test ( + _pt geography(point) +) +returns numeric +language sql +begin atomic + select st_x(_pt::geometry); +end; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_function.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_function.yml index e0ca45e1f..ab99feae6 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_function.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_function.yml @@ -334,20 +334,16 @@ file: - create_type_statement: - keyword: CREATE - keyword: TYPE - - object_reference: - - naked_identifier: dup_result + - data_type: + - data_type_identifier: dup_result - keyword: AS - bracketed: - start_bracket: ( - - column_reference: - - naked_identifier: f1 - - data_type: - - keyword: int + - word: f1 + - word: int - comma: ',' - - column_reference: - - naked_identifier: f2 - - data_type: - - keyword: text + - word: f2 + - word: text - end_bracket: ) - statement_terminator: ; - statement: @@ -801,3 +797,752 @@ file: end; $$ - statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: FUNCTION + - function_name: + - function_name_identifier: data_wrapper + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - keyword: SETOF + - data_type: + - data_type_identifier: data + - function_definition: + - keyword: STABLE + - keyword: PARALLEL + - keyword: SAFE + - keyword: LEAKPROOF + - keyword: BEGIN + - keyword: ATOMIC + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: data + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: create + - keyword: or + - keyword: replace + - keyword: function + - function_name: + - function_name_identifier: tz_date + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - keyword: with + - keyword: time + - keyword: zone + - comma: ',' + - data_type: + - keyword: text + - end_bracket: ) + - keyword: returns + - data_type: + - datetime_type_identifier: + - keyword: date + - function_definition: + - language_clause: + - keyword: language + - naked_identifier: sql + - keyword: immutable + - keyword: strict + - keyword: return + - expression: + - cast_expression: + - bracketed: + - start_bracket: ( + - expression: + - dollar_numeric_literal: $1 + - time_zone_grammar: + - keyword: at + - keyword: time + - keyword: zone + - expression: + - dollar_numeric_literal: $2 + - end_bracket: ) + - casting_operator: '::' + - data_type: + - datetime_type_identifier: + - keyword: date +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - naked_identifier: storage + - dot: . + - function_name_identifier: insert_dimension + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: in_ordinality + - data_type: + - keyword: int + - comma: ',' + - parameter: in_fieldname + - data_type: + - keyword: varchar + - comma: ',' + - parameter: in_default_val + - data_type: + - keyword: varchar + - comma: ',' + - parameter: in_valid_from + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - comma: ',' + - parameter: in_valid_until + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - end_bracket: ) + - keyword: returns + - data_type: + - naked_identifier: storage + - dot: . + - data_type_identifier: dimensions + - function_definition: + - language_clause: + - keyword: language + - naked_identifier: sql + - keyword: BEGIN + - keyword: ATOMIC + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: storage + - dot: . + - naked_identifier: dimensions + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: ordinality + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: ordinality + - binary_operator: + + - numeric_literal: '1' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ordinality + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - column_reference: + - naked_identifier: in_ordinality + - statement_terminator: ; + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: storage + - dot: . + - naked_identifier: dimensions + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: ordinality + - comma: ',' + - column_reference: + - naked_identifier: fieldname + - comma: ',' + - column_reference: + - naked_identifier: default_val + - comma: ',' + - column_reference: + - naked_identifier: valid_from + - comma: ',' + - column_reference: + - naked_identifier: valid_until + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: in_ordinality + - comma: ',' + - expression: + - column_reference: + - naked_identifier: in_fieldname + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: coalesce + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: in_default_val + - comma: ',' + - expression: + - quoted_literal: '''notexist''' + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: coalesce + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: in_valid_from + - comma: ',' + - expression: + - quoted_literal: '''-infinity''' + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: coalesce + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: in_valid_until + - comma: ',' + - expression: + - quoted_literal: '''infinity''' + - end_bracket: ) + - end_bracket: ) + - keyword: RETURNING + - star: '*' + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: FUNCTION + - function_name: + - function_name_identifier: time_bucket + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: _time + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - keyword: without + - keyword: time + - keyword: zone + - comma: ',' + - parameter: _from + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - keyword: without + - keyword: time + - keyword: zone + - comma: ',' + - parameter: _to + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - keyword: without + - keyword: time + - keyword: zone + - comma: ',' + - parameter: _buckets + - data_type: + - keyword: integer + - keyword: DEFAULT + - expression: + - numeric_literal: '200' + - comma: ',' + - parameter: _offset + - data_type: + - keyword: integer + - keyword: DEFAULT + - expression: + - numeric_literal: '0' + - end_bracket: ) + - keyword: RETURNS + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - keyword: without + - keyword: time + - keyword: zone + - function_definition: + - keyword: IMMUTABLE + - keyword: PARALLEL + - keyword: SAFE + - keyword: BEGIN + - keyword: ATOMIC + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - function: + - function_name: + - function_name_identifier: date_bin + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - bracketed: + - start_bracket: ( + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: _to + - binary_operator: '-' + - column_reference: + - naked_identifier: _from + - end_bracket: ) + - binary_operator: / + - function: + - function_name: + - function_name_identifier: greatest + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: _buckets + - binary_operator: '-' + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - expression: + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - expression: + - column_reference: + - naked_identifier: _time + - comma: ',' + - expression: + - column_reference: + - naked_identifier: _from + - end_bracket: ) + - binary_operator: + + - bracketed: + - start_bracket: ( + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: _to + - binary_operator: '-' + - column_reference: + - naked_identifier: _from + - end_bracket: ) + - binary_operator: / + - function: + - function_name: + - function_name_identifier: greatest + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: _buckets + - binary_operator: '-' + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - expression: + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - binary_operator: '*' + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: _offset + - binary_operator: + + - numeric_literal: '1' + - end_bracket: ) + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: FUNCTION + - function_name: + - function_name_identifier: time_bucket_limited + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: _time + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - comma: ',' + - parameter: _from + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - comma: ',' + - parameter: _to + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - comma: ',' + - parameter: _buckets + - data_type: + - keyword: int + - comparison_operator: + - raw_comparison_operator: = + - expression: + - numeric_literal: '200' + - end_bracket: ) + - keyword: RETURNS + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - function_definition: + - keyword: IMMUTABLE + - keyword: PARALLEL + - keyword: SAFE + - keyword: BEGIN + - keyword: ATOMIC + - keyword: RETURN + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: _time + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - column_reference: + - naked_identifier: _from + - keyword: THEN + - expression: + - column_reference: + - naked_identifier: _from + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: _time + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - column_reference: + - naked_identifier: _to + - keyword: THEN + - expression: + - column_reference: + - naked_identifier: _to + - else_clause: + - keyword: ELSE + - expression: + - function: + - function_name: + - function_name_identifier: DATE_BIN + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: _to + - binary_operator: '-' + - column_reference: + - naked_identifier: _from + - end_bracket: ) + - binary_operator: / + - function: + - function_name: + - function_name_identifier: GREATEST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: _buckets + - binary_operator: '-' + - numeric_literal: '1' + - comma: ',' + - expression: + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - expression: + - column_reference: + - naked_identifier: _time + - comma: ',' + - expression: + - column_reference: + - naked_identifier: _from + - end_bracket: ) + - binary_operator: + + - bracketed: + - start_bracket: ( + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: _to + - binary_operator: '-' + - column_reference: + - naked_identifier: _from + - end_bracket: ) + - binary_operator: / + - function: + - function_name: + - function_name_identifier: GREATEST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: _buckets + - binary_operator: '-' + - numeric_literal: '1' + - comma: ',' + - expression: + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - keyword: end + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: FUNCTION + - function_name: + - function_name_identifier: time_series + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: _from + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - keyword: without + - keyword: time + - keyword: zone + - comma: ',' + - parameter: _to + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - keyword: without + - keyword: time + - keyword: zone + - comma: ',' + - parameter: _buckets + - data_type: + - keyword: integer + - keyword: DEFAULT + - expression: + - numeric_literal: '200' + - end_bracket: ) + - keyword: RETURNS + - keyword: TABLE + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '"time"' + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - keyword: without + - keyword: time + - keyword: zone + - end_bracket: ) + - function_definition: + - keyword: IMMUTABLE + - keyword: PARALLEL + - keyword: SAFE + - keyword: BEGIN + - keyword: ATOMIC + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: time_bucket + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: _from + - comma: ',' + - expression: + - column_reference: + - naked_identifier: _from + - comma: ',' + - expression: + - column_reference: + - naked_identifier: _to + - comma: ',' + - expression: + - column_reference: + - naked_identifier: _buckets + - comma: ',' + - expression: + - column_reference: + - naked_identifier: g + - dot: . + - naked_identifier: ofs + - binary_operator: '-' + - numeric_literal: '1' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: generate_series + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0' + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: greatest + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: _buckets + - binary_operator: '-' + - numeric_literal: '1' + - end_bracket: ) + - comma: ',' + - expression: + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: g + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: ofs + - end_bracket: ) + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: create + - keyword: or + - keyword: replace + - keyword: function + - function_name: + - function_name_identifier: test + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: _pt + - data_type: + - wkt_geometry_type: + - keyword: geography + - bracketed: + - start_bracket: ( + - keyword: point + - end_bracket: ) + - end_bracket: ) + - keyword: returns + - data_type: + - keyword: numeric + - function_definition: + - language_clause: + - keyword: language + - naked_identifier: sql + - keyword: begin + - keyword: atomic + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - function_name_identifier: st_x + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - cast_expression: + - column_reference: + - naked_identifier: _pt + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - statement_terminator: ; + - keyword: end +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_index.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_index.sql index a7272a12e..f086216b1 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_index.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_index.sql @@ -39,3 +39,5 @@ CREATE INDEX nulls_not_distinct_index ON documents_table USING GIN (locations) NULLS NOT DISTINCT WITH (fastupdate = 'off'); CREATE INDEX code_idx ON films (code) TABLESPACE indexspace; + +CREATE INDEX CONCURRENTLY IF NOT EXISTS user_my_column_idx ON my_schema.user (my_column); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_index.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_index.yml index 5facd4b74..8bdc08f1e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_index.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_index.yml @@ -4,7 +4,7 @@ file: - keyword: CREATE - keyword: UNIQUE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: title_idx - keyword: ON - table_reference: @@ -21,7 +21,7 @@ file: - keyword: CREATE - keyword: UNIQUE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: title_idx - keyword: ON - table_reference: @@ -48,7 +48,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: title_idx - keyword: ON - table_reference: @@ -100,7 +100,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: title_idx_german - keyword: ON - table_reference: @@ -120,7 +120,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: title_idx_nulls_low - keyword: ON - table_reference: @@ -139,7 +139,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: title_idx_nulls_high - keyword: ON - table_reference: @@ -159,7 +159,7 @@ file: - keyword: CREATE - keyword: UNIQUE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: title_idx - keyword: ON - table_reference: @@ -185,7 +185,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: gin_idx - keyword: ON - table_reference: @@ -214,7 +214,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: code_idx - keyword: ON - table_reference: @@ -233,7 +233,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: pointloc - keyword: ON - table_reference: @@ -265,7 +265,7 @@ file: - keyword: CREATE - keyword: INDEX - keyword: CONCURRENTLY - - database_reference: + - index_reference: - naked_identifier: sales_quantity_index - keyword: ON - table_reference: @@ -281,7 +281,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: super_idx - keyword: ON - table_reference: @@ -302,7 +302,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: opclass_index - keyword: ON - table_reference: @@ -323,7 +323,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: opclass_index_with_parameters - keyword: ON - table_reference: @@ -360,7 +360,7 @@ file: - keyword: CREATE - keyword: UNIQUE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: tests_success_constraint - keyword: ON - table_reference: @@ -384,7 +384,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: nulls_distinct_index - keyword: ON - table_reference: @@ -415,7 +415,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: nulls_not_distinct_index - keyword: ON - table_reference: @@ -447,7 +447,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: code_idx - keyword: ON - table_reference: @@ -462,3 +462,25 @@ file: - tablespace_reference: - naked_identifier: indexspace - statement_terminator: ; +- statement: + - create_index_statement: + - keyword: CREATE + - keyword: INDEX + - keyword: CONCURRENTLY + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - index_reference: + - naked_identifier: user_my_column_idx + - keyword: ON + - table_reference: + - naked_identifier: my_schema + - dot: . + - naked_identifier: user + - bracketed: + - start_bracket: ( + - index_element: + - column_reference: + - naked_identifier: my_column + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_materialized_view.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_materialized_view.yml index 31c232212..d4607a866 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_materialized_view.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_materialized_view.yml @@ -473,7 +473,8 @@ file: - naked_identifier: b - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: my_avg - comma: ',' - select_clause_element: @@ -486,7 +487,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: my_count - from_clause: - keyword: FROM @@ -575,7 +577,8 @@ file: - naked_identifier: b - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: my_avg - comma: ',' - select_clause_element: @@ -588,7 +591,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: my_count - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_operator.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_operator.sql new file mode 100644 index 000000000..d1f08f424 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_operator.sql @@ -0,0 +1,17 @@ +CREATE OPERATOR >=( + LEFTARG = semantic_version, + RIGHTARG = semantic_version, + PROCEDURE = semantic_version_ge, + COMMUTATOR = <= +); + +CREATE OPERATOR === ( + LEFTARG = box, + RIGHTARG = box, + FUNCTION = area_equal_function, + COMMUTATOR = ===, + NEGATOR = !==, + RESTRICT = area_restriction_function, + JOIN = area_join_function, + HASHES, MERGES +); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_operator.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_operator.yml new file mode 100644 index 000000000..9f28517c1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_operator.yml @@ -0,0 +1,92 @@ +file: +- statement: + - create_operator_statement: + - keyword: CREATE + - keyword: OPERATOR + - symbol: '>' + - symbol: = + - bracketed: + - start_bracket: ( + - keyword: LEFTARG + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: semantic_version + - comma: ',' + - keyword: RIGHTARG + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: semantic_version + - comma: ',' + - keyword: PROCEDURE + - comparison_operator: + - raw_comparison_operator: = + - function_name: + - function_name_identifier: semantic_version_ge + - comma: ',' + - keyword: COMMUTATOR + - comparison_operator: + - raw_comparison_operator: = + - symbol: < + - symbol: = + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_operator_statement: + - keyword: CREATE + - keyword: OPERATOR + - symbol: = + - symbol: = + - symbol: = + - bracketed: + - start_bracket: ( + - keyword: LEFTARG + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: box + - comma: ',' + - keyword: RIGHTARG + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: box + - comma: ',' + - keyword: FUNCTION + - comparison_operator: + - raw_comparison_operator: = + - function_name: + - function_name_identifier: area_equal_function + - comma: ',' + - keyword: COMMUTATOR + - comparison_operator: + - raw_comparison_operator: = + - symbol: = + - symbol: = + - symbol: = + - comma: ',' + - keyword: NEGATOR + - comparison_operator: + - raw_comparison_operator: = + - symbol: '!' + - symbol: = + - symbol: = + - comma: ',' + - keyword: RESTRICT + - comparison_operator: + - raw_comparison_operator: = + - function_name: + - function_name_identifier: area_restriction_function + - comma: ',' + - keyword: JOIN + - comparison_operator: + - raw_comparison_operator: = + - function_name: + - function_name_identifier: area_join_function + - comma: ',' + - keyword: HASHES + - comma: ',' + - keyword: MERGES + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_policy.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_policy.yml index 55af1d69b..b925006a1 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_policy.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_policy.yml @@ -144,7 +144,6 @@ file: - naked_identifier: username - comparison_operator: - raw_comparison_operator: = - - column_reference: - - naked_identifier: current_user + - bare_function: current_user - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_procedure.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_procedure.sql index d20432518..b21257a5b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_procedure.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_procedure.sql @@ -15,3 +15,16 @@ AS $$ INSERT INTO tbl VALUES (a); INSERT INTO tbl VALUES (b); $$; + +CREATE PROCEDURE abc.cdf() +LANGUAGE sql +BEGIN ATOMIC +WITH tbl2 AS ( +SELECT a.apple +FROM tbl1 a +) + +SELECT t.apple +FROM tbl2 t +; +END; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_procedure.yml index a809380b2..1ce13164b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_procedure.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_procedure.yml @@ -54,3 +54,66 @@ file: INSERT INTO tbl VALUES (b); $$ - statement_terminator: ; +- statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - function_name: + - naked_identifier: abc + - dot: . + - function_name_identifier: cdf + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - function_definition: + - language_clause: + - keyword: LANGUAGE + - naked_identifier: sql + - keyword: BEGIN + - keyword: ATOMIC + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: tbl2 + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: apple + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 + - alias_expression: + - naked_identifier: a + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: apple + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl2 + - alias_expression: + - naked_identifier: t + - statement_terminator: ; + - keyword: END +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_publication.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_publication.yml index 05dc38b96..184077120 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_publication.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_publication.yml @@ -232,17 +232,15 @@ file: - keyword: TABLES - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: j + - schema_reference: + - naked_identifier: j - comma: ',' - publication_objects: - keyword: TABLES - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: k + - schema_reference: + - naked_identifier: k - comma: ',' - publication_objects: - keyword: TABLES @@ -250,29 +248,24 @@ file: - keyword: SCHEMA - keyword: CURRENT_SCHEMA - comma: ',' - - table_reference: - - object_reference: - - naked_identifier: l + - schema_reference: + - naked_identifier: l - comma: ',' - - table_reference: - - object_reference: - - naked_identifier: m + - schema_reference: + - naked_identifier: m - comma: ',' - publication_objects: - keyword: TABLES - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: n + - schema_reference: + - naked_identifier: n - comma: ',' - - table_reference: - - object_reference: - - naked_identifier: o + - schema_reference: + - naked_identifier: o - comma: ',' - - table_reference: - - object_reference: - - naked_identifier: p + - schema_reference: + - naked_identifier: p - statement_terminator: ; - statement: - create_publication_statement: @@ -471,9 +464,8 @@ file: - keyword: TABLES - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: production + - schema_reference: + - naked_identifier: production - statement_terminator: ; - statement: - create_publication_statement: @@ -486,13 +478,11 @@ file: - keyword: TABLES - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: marketing + - schema_reference: + - naked_identifier: marketing - comma: ',' - - table_reference: - - object_reference: - - naked_identifier: sales + - schema_reference: + - naked_identifier: sales - statement_terminator: ; - statement: - create_publication_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_role.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_role.sql index fff723fd8..b5fbaef47 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_role.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_role.sql @@ -6,6 +6,7 @@ CREATE USER frank WITH SUPERUSER CREATEDB CREATEROLE; CREATE USER frank WITH INHERIT LOGIN REPLICATION BYPASSRLS; CREATE USER davide WITH PASSWORD 'jw8s0F4'; CREATE USER miriam WITH LOGIN PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01'; +CREATE USER test WITH ENCRYPTED PASSWORD 'test'; CREATE ROLE foo_role WITH SUPERUSER NOLOGIN REPLICATION IN GROUP foo_group; CREATE ROLE foo_role; CREATE ROLE frank WITH CONNECTION LIMIT 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_role.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_role.yml index bae30db69..370d878d0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_role.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_role.yml @@ -91,6 +91,17 @@ file: - keyword: UNTIL - quoted_literal: '''2005-01-01''' - statement_terminator: ; +- statement: + - create_role_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - naked_identifier: test + - keyword: WITH + - keyword: ENCRYPTED + - keyword: PASSWORD + - quoted_literal: '''test''' +- statement_terminator: ; - statement: - create_role_statement: - keyword: CREATE diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_schema.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_schema.yml index 31047ca7c..ea95653cf 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_schema.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_schema.yml @@ -3,9 +3,8 @@ file: - create_schema_statement: - keyword: CREATE - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: asdf + - schema_reference: + - naked_identifier: asdf - statement_terminator: ; - statement: - create_schema_statement: @@ -14,17 +13,15 @@ file: - keyword: IF - keyword: NOT - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: asdf + - schema_reference: + - naked_identifier: asdf - statement_terminator: ; - statement: - create_schema_statement: - keyword: CREATE - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: asdf + - schema_reference: + - naked_identifier: asdf - keyword: AUTHORIZATION - role_reference: - naked_identifier: bob @@ -44,9 +41,8 @@ file: - keyword: IF - keyword: NOT - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: asdf + - schema_reference: + - naked_identifier: asdf - keyword: AUTHORIZATION - role_reference: - naked_identifier: bob diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_sequence.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_sequence.sql index ebb488f0e..c92177c23 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_sequence.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_sequence.sql @@ -19,3 +19,5 @@ CREATE SEQUENCE foo OWNED BY my_table.my_column; CREATE TEMP SEQUENCE IF NOT EXISTS foo; CREATE TEMPORARY SEQUENCE foo; + +CREATE SEQUENCE derp INCREMENT BY -5 MINVALUE +50 MAXVALUE -5;; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_sequence.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_sequence.yml index b9d929a44..8c6c2d764 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_sequence.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_sequence.yml @@ -3,14 +3,14 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - statement_terminator: ; - statement: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: AS @@ -21,7 +21,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: INCREMENT @@ -32,7 +32,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: MINVALUE @@ -45,7 +45,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: NO @@ -58,7 +58,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: INCREMENT @@ -75,7 +75,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: NO @@ -85,7 +85,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: OWNED @@ -96,7 +96,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - create_sequence_options_segment: - keyword: OWNED @@ -114,7 +114,7 @@ file: - keyword: IF - keyword: NOT - keyword: EXISTS - - column_reference: + - sequence_reference: - naked_identifier: foo - statement_terminator: ; - statement: @@ -122,6 +122,27 @@ file: - keyword: CREATE - keyword: TEMPORARY - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - statement_terminator: ; +- statement: + - create_sequence_statement: + - keyword: CREATE + - keyword: SEQUENCE + - sequence_reference: + - naked_identifier: derp + - create_sequence_options_segment: + - keyword: INCREMENT + - keyword: BY + - sign_indicator: '-' + - numeric_literal: '5' + - create_sequence_options_segment: + - keyword: MINVALUE + - sign_indicator: + + - numeric_literal: '50' + - create_sequence_options_segment: + - keyword: MAXVALUE + - sign_indicator: '-' + - numeric_literal: '5' +- statement_terminator: ; +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_server.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_server.yml index 6a53140fa..71d4f9c44 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_server.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_server.yml @@ -57,13 +57,13 @@ file: - keyword: OPTIONS - bracketed: - start_bracket: ( - - naked_identifier: host + - naked_identifier_all: host - quoted_literal: '''foo''' - comma: ',' - - naked_identifier: dbname + - naked_identifier_all: dbname - quoted_literal: '''foodb''' - comma: ',' - - naked_identifier: port + - naked_identifier_all: port - quoted_literal: '''5432''' - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_statistics.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_statistics.yml index 400bc1123..105c7e7f8 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_statistics.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_statistics.yml @@ -1,113 +1,116 @@ file: - statement: - - keyword: CREATE - - keyword: STATISTICS - - object_reference: - - naked_identifier: s3 - - bracketed: - - start_bracket: ( - - keyword: ndistinct - - end_bracket: ) - - keyword: ON - - expression: - - function: - - function_name: - - function_name_identifier: date_trunc - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''month''' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: a - - end_bracket: ) - - comma: ',' - - expression: - - function: - - function_name: - - function_name_identifier: date_trunc - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''day''' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: a - - end_bracket: ) - - keyword: FROM - - table_reference: - - naked_identifier: t3 + - create_statistics_statement: + - keyword: CREATE + - keyword: STATISTICS + - statistics_reference: + - naked_identifier: s3 + - bracketed: + - start_bracket: ( + - keyword: ndistinct + - end_bracket: ) + - keyword: ON + - expression: + - function: + - function_name: + - function_name_identifier: date_trunc + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''month''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: a + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: date_trunc + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''day''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: a + - end_bracket: ) + - keyword: FROM + - table_reference: + - naked_identifier: t3 - statement_terminator: ; - statement: - - keyword: CREATE - - keyword: STATISTICS - - object_reference: - - naked_identifier: my_statistic - - bracketed: - - start_bracket: ( - - keyword: dependencies - - end_bracket: ) - - keyword: ON - - column_reference: - - naked_identifier: foo - - comma: ',' - - column_reference: - - naked_identifier: bar - - keyword: FROM - - table_reference: - - naked_identifier: baz + - create_statistics_statement: + - keyword: CREATE + - keyword: STATISTICS + - statistics_reference: + - naked_identifier: my_statistic + - bracketed: + - start_bracket: ( + - keyword: dependencies + - end_bracket: ) + - keyword: ON + - column_reference: + - naked_identifier: foo + - comma: ',' + - column_reference: + - naked_identifier: bar + - keyword: FROM + - table_reference: + - naked_identifier: baz - statement_terminator: ; - statement: - - keyword: CREATE - - keyword: STATISTICS - - keyword: IF - - keyword: NOT - - keyword: EXISTS - - object_reference: - - naked_identifier: s3 - - bracketed: - - start_bracket: ( - - keyword: ndistinct - - comma: ',' - - keyword: mcv + - create_statistics_statement: + - keyword: CREATE + - keyword: STATISTICS + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - statistics_reference: + - naked_identifier: s3 + - bracketed: + - start_bracket: ( + - keyword: ndistinct + - comma: ',' + - keyword: mcv + - comma: ',' + - keyword: dependencies + - end_bracket: ) + - keyword: ON + - expression: + - function: + - function_name: + - function_name_identifier: date_trunc + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''month''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: a + - end_bracket: ) - comma: ',' - - keyword: dependencies - - end_bracket: ) - - keyword: ON - - expression: - - function: - - function_name: - - function_name_identifier: date_trunc - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''month''' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: a - - end_bracket: ) - - comma: ',' - - expression: - - function: - - function_name: - - function_name_identifier: date_trunc - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''day''' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: a - - end_bracket: ) - - keyword: FROM - - table_reference: - - naked_identifier: t3 + - expression: + - function: + - function_name: + - function_name_identifier: date_trunc + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''day''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: a + - end_bracket: ) + - keyword: FROM + - table_reference: + - naked_identifier: t3 - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_subscription.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_subscription.sql new file mode 100644 index 000000000..719917be7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_subscription.sql @@ -0,0 +1,21 @@ +CREATE SUBSCRIPTION my_subscription +CONNECTION 'publishers_uri' +PUBLICATION my_publication +WITH ( + binary = true, + copy_data = true, + create_slot = true, + run_as_owner = false, + slot_name = 'my_slot_name', + streaming = 'parallel' +); + +CREATE SUBSCRIPTION mysub +CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb' +PUBLICATION mypublication, insert_only; + + +CREATE SUBSCRIPTION mysub +CONNECTION 'host=192.168.1.50 port=5432 user=foo dbname=foodb' +PUBLICATION insert_only +WITH (enabled = false); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_subscription.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_subscription.yml new file mode 100644 index 000000000..954d8e437 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_subscription.yml @@ -0,0 +1,90 @@ +file: +- statement: + - create_subscription: + - keyword: CREATE + - keyword: SUBSCRIPTION + - subscription_reference: + - naked_identifier: my_subscription + - keyword: CONNECTION + - quoted_literal: '''publishers_uri''' + - keyword: PUBLICATION + - publication_reference: + - naked_identifier: my_publication + - keyword: WITH + - definition_parameters: + - bracketed: + - start_bracket: ( + - definition_parameter: + - properties_naked_identifier: binary + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'true' + - comma: ',' + - definition_parameter: + - properties_naked_identifier: copy_data + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'true' + - comma: ',' + - definition_parameter: + - properties_naked_identifier: create_slot + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'true' + - comma: ',' + - definition_parameter: + - properties_naked_identifier: run_as_owner + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'false' + - comma: ',' + - definition_parameter: + - properties_naked_identifier: slot_name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my_slot_name''' + - comma: ',' + - definition_parameter: + - properties_naked_identifier: streaming + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''parallel''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_subscription: + - keyword: CREATE + - keyword: SUBSCRIPTION + - subscription_reference: + - naked_identifier: mysub + - keyword: CONNECTION + - quoted_literal: '''host=192.168.1.50 port=5432 user=foo dbname=foodb''' + - keyword: PUBLICATION + - publication_reference: + - naked_identifier: mypublication + - comma: ',' + - publication_reference: + - naked_identifier: insert_only +- statement_terminator: ; +- statement: + - create_subscription: + - keyword: CREATE + - keyword: SUBSCRIPTION + - subscription_reference: + - naked_identifier: mysub + - keyword: CONNECTION + - quoted_literal: '''host=192.168.1.50 port=5432 user=foo dbname=foodb''' + - keyword: PUBLICATION + - publication_reference: + - naked_identifier: insert_only + - keyword: WITH + - definition_parameters: + - bracketed: + - start_bracket: ( + - definition_parameter: + - properties_naked_identifier: enabled + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'false' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_table.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_table.sql index bf7be8091..12741a004 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_table.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_table.sql @@ -341,3 +341,32 @@ CREATE TABLE many_options ( ); CREATE TABLE example_table () INHERITS (parent_table); + +CREATE TABLE IF NOT EXISTS table2( + col1 int, + col2 int NOT NULL, + col3 int, + + FOREIGN KEY (col1, col2) + REFERENCES table1 (col1, col2) + ON DELETE SET NULL (col1) +); + +CREATE TABLE IF NOT EXISTS table2( + col1 int, + col2 int NOT NULL, + col3 int, + + FOREIGN KEY (col1, col2) + REFERENCES table1 (col1, col2) + ON DELETE SET DEFAULT (col1) +); + +CREATE TABLE myschema.user ( + user_id bigint PRIMARY KEY, + name varchar(40) +); + +CREATE TABLE my_table ( + interval bigint +); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_table.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_table.yml index 299e72817..853b24288 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_table.yml @@ -7,12 +7,12 @@ file: - naked_identifier: counters - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: my_type - - data_type: - - naked_identifier: public - - dot: . - - data_type_identifier: MY_TYPE + - data_type: + - naked_identifier: public + - dot: . + - data_type_identifier: MY_TYPE - end_bracket: ) - statement_terminator: ; - statement: @@ -23,44 +23,44 @@ file: - naked_identifier: distributors - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: did - - data_type: - - keyword: integer - - column_constraint_segment: - - keyword: PRIMARY - - keyword: KEY - - column_constraint_segment: - - keyword: GENERATED - - keyword: BY - - keyword: DEFAULT - - keyword: AS - - keyword: IDENTITY - - comma: ',' - - column_reference: + - data_type: + - keyword: integer + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - column_constraint_segment: + - keyword: GENERATED + - keyword: BY + - keyword: DEFAULT + - keyword: AS + - keyword: IDENTITY + - comma: ',' + - column_definition: - naked_identifier: name - - data_type: - - keyword: varchar - - bracketed_arguments: + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '40' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: CHECK - bracketed: - start_bracket: ( - - numeric_literal: '40' + - expression: + - column_reference: + - naked_identifier: name + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: '>' + - quoted_literal: '''''' - end_bracket: ) - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' - - column_constraint_segment: - - keyword: CHECK - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: name - - comparison_operator: - - raw_comparison_operator: < - - raw_comparison_operator: '>' - - quoted_literal: '''''' - - end_bracket: ) - end_bracket: ) - statement_terminator: ; - statement: @@ -71,14 +71,14 @@ file: - naked_identifier: array_int - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: vector - - data_type: - - keyword: int - - start_square_bracket: '[' - - end_square_bracket: ']' - - start_square_bracket: '[' - - end_square_bracket: ']' + - data_type: + - keyword: int + - start_square_bracket: '[' + - end_square_bracket: ']' + - start_square_bracket: '[' + - end_square_bracket: ']' - end_bracket: ) - statement_terminator: ; - statement: @@ -89,42 +89,42 @@ file: - naked_identifier: distributors - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: did - - data_type: - - keyword: integer - - column_constraint_segment: - - keyword: CHECK - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: did - - comparison_operator: - - raw_comparison_operator: '>' - - numeric_literal: '100' - - end_bracket: ) - - comma: ',' - - column_reference: - - naked_identifier: name - - data_type: - - keyword: varchar - - bracketed_arguments: + - data_type: + - keyword: integer + - column_constraint_segment: + - keyword: CHECK - bracketed: - start_bracket: ( - - numeric_literal: '40' + - expression: + - column_reference: + - naked_identifier: did + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '100' - end_bracket: ) - comma: ',' - - column_reference: + - column_definition: + - naked_identifier: name + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '40' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: long_varying - - data_type: - - keyword: char - - keyword: varying - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '100' - - end_bracket: ) + - data_type: + - keyword: char + - keyword: varying + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) - end_bracket: ) - statement_terminator: ; - statement: @@ -135,20 +135,20 @@ file: - naked_identifier: distributors - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: did - - data_type: - - keyword: integer + - data_type: + - keyword: integer - comma: ',' - - column_reference: + - column_definition: - naked_identifier: name - - data_type: - - keyword: varchar - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '40' - - end_bracket: ) + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '40' + - end_bracket: ) - comma: ',' - table_constraint: - keyword: CONSTRAINT @@ -181,20 +181,20 @@ file: - naked_identifier: distributors - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: did - - data_type: - - keyword: integer + - data_type: + - keyword: integer - comma: ',' - - column_reference: + - column_definition: - naked_identifier: name - - data_type: - - keyword: varchar - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '40' - - end_bracket: ) + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '40' + - end_bracket: ) - comma: ',' - table_constraint: - keyword: PRIMARY @@ -214,23 +214,23 @@ file: - naked_identifier: distributors - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: did - - data_type: - - keyword: integer - - column_constraint_segment: - - keyword: PRIMARY - - keyword: KEY + - data_type: + - keyword: integer + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY - comma: ',' - - column_reference: + - column_definition: - naked_identifier: name - - data_type: - - keyword: varchar - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '40' - - end_bracket: ) + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '40' + - end_bracket: ) - end_bracket: ) - statement_terminator: ; - statement: @@ -241,43 +241,43 @@ file: - naked_identifier: distributors - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: name - - data_type: - - keyword: varchar - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '40' - - end_bracket: ) - - column_constraint_segment: - - keyword: DEFAULT - - quoted_literal: '''Luso Films''' - - comma: ',' - - column_reference: - - naked_identifier: did - - data_type: - - keyword: integer - - column_constraint_segment: - - keyword: DEFAULT - - function: - - function_name: - - function_name_identifier: nextval - - function_contents: + - data_type: + - keyword: varchar + - bracketed_arguments: - bracketed: - start_bracket: ( - - expression: - - quoted_literal: '''distributors_serial''' + - numeric_literal: '40' - end_bracket: ) + - column_constraint_segment: + - keyword: DEFAULT + - quoted_literal: '''Luso Films''' - comma: ',' - - column_reference: + - column_definition: + - naked_identifier: did + - data_type: + - keyword: integer + - column_constraint_segment: + - keyword: DEFAULT + - function: + - function_name: + - function_name_identifier: nextval + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''distributors_serial''' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: modtime - - data_type: - - datetime_type_identifier: - - keyword: timestamp - - column_constraint_segment: - - keyword: DEFAULT - - bare_function: current_timestamp + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - column_constraint_segment: + - keyword: DEFAULT + - bare_function: current_timestamp - end_bracket: ) - statement_terminator: ; - statement: @@ -288,29 +288,29 @@ file: - naked_identifier: distributors - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: did - - data_type: - - keyword: integer - - column_constraint_segment: - - keyword: CONSTRAINT - - object_reference: - - naked_identifier: no_null - - keyword: NOT - - keyword: 'NULL' - - comma: ',' - - column_reference: + - data_type: + - keyword: integer + - column_constraint_segment: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: no_null + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: - naked_identifier: name - - data_type: - - keyword: varchar - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '40' - - end_bracket: ) - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '40' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' - end_bracket: ) - statement_terminator: ; - statement: @@ -321,22 +321,22 @@ file: - naked_identifier: distributors - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: did - - data_type: - - keyword: integer + - data_type: + - keyword: integer - comma: ',' - - column_reference: + - column_definition: - naked_identifier: name - - data_type: - - keyword: varchar - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '40' - - end_bracket: ) - - column_constraint_segment: - - keyword: UNIQUE + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '40' + - end_bracket: ) + - column_constraint_segment: + - keyword: UNIQUE - end_bracket: ) - statement_terminator: ; - statement: @@ -347,20 +347,20 @@ file: - naked_identifier: distributors - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: did - - data_type: - - keyword: integer + - data_type: + - keyword: integer - comma: ',' - - column_reference: + - column_definition: - naked_identifier: name - - data_type: - - keyword: varchar - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '40' - - end_bracket: ) + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '40' + - end_bracket: ) - comma: ',' - table_constraint: - keyword: UNIQUE @@ -379,20 +379,20 @@ file: - naked_identifier: distributors - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: did - - data_type: - - keyword: integer + - data_type: + - keyword: integer - comma: ',' - - column_reference: + - column_definition: - naked_identifier: name - - data_type: - - keyword: varchar - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '40' - - end_bracket: ) + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '40' + - end_bracket: ) - comma: ',' - table_constraint: - keyword: UNIQUE @@ -432,20 +432,20 @@ file: - naked_identifier: cinemas - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: id - - data_type: - - keyword: serial + - data_type: + - keyword: serial - comma: ',' - - column_reference: + - column_definition: - naked_identifier: name - - data_type: - - keyword: text + - data_type: + - keyword: text - comma: ',' - - column_reference: + - column_definition: - naked_identifier: location - - data_type: - - keyword: text + - data_type: + - keyword: text - end_bracket: ) - keyword: TABLESPACE - tablespace_reference: @@ -455,20 +455,16 @@ file: - create_type_statement: - keyword: CREATE - keyword: TYPE - - object_reference: - - naked_identifier: employee_type + - data_type: + - data_type_identifier: employee_type - keyword: AS - bracketed: - start_bracket: ( - - column_reference: - - naked_identifier: name - - data_type: - - keyword: text + - word: name + - word: text - comma: ',' - - column_reference: - - naked_identifier: salary - - data_type: - - keyword: numeric + - word: salary + - word: numeric - end_bracket: ) - statement_terminator: ; - statement: @@ -507,24 +503,24 @@ file: - naked_identifier: measurement - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: logdate - - data_type: - - datetime_type_identifier: - - keyword: date - - column_constraint_segment: - - keyword: not - - keyword: 'null' - - comma: ',' - - column_reference: + - data_type: + - datetime_type_identifier: + - keyword: date + - column_constraint_segment: + - keyword: not + - keyword: 'null' + - comma: ',' + - column_definition: - naked_identifier: peaktemp - - data_type: - - keyword: int + - data_type: + - keyword: int - comma: ',' - - column_reference: + - column_definition: - naked_identifier: unitsales - - data_type: - - keyword: int + - data_type: + - keyword: int - end_bracket: ) - keyword: PARTITION - keyword: BY @@ -543,24 +539,24 @@ file: - naked_identifier: measurement_year_month - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: logdate - - data_type: - - datetime_type_identifier: - - keyword: date - - column_constraint_segment: - - keyword: not - - keyword: 'null' - - comma: ',' - - column_reference: + - data_type: + - datetime_type_identifier: + - keyword: date + - column_constraint_segment: + - keyword: not + - keyword: 'null' + - comma: ',' + - column_definition: - naked_identifier: peaktemp - - data_type: - - keyword: int + - data_type: + - keyword: int - comma: ',' - - column_reference: + - column_definition: - naked_identifier: unitsales - - data_type: - - keyword: int + - data_type: + - keyword: int - end_bracket: ) - keyword: PARTITION - keyword: BY @@ -602,26 +598,26 @@ file: - naked_identifier: cities - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: city_id - - data_type: - - keyword: bigserial - - column_constraint_segment: - - keyword: not - - keyword: 'null' + - data_type: + - keyword: bigserial + - column_constraint_segment: + - keyword: not + - keyword: 'null' - comma: ',' - - column_reference: + - column_definition: - naked_identifier: name - - data_type: - - keyword: text - - column_constraint_segment: - - keyword: not - - keyword: 'null' + - data_type: + - keyword: text + - column_constraint_segment: + - keyword: not + - keyword: 'null' - comma: ',' - - column_reference: + - column_definition: - naked_identifier: population - - data_type: - - keyword: bigint + - data_type: + - keyword: bigint - end_bracket: ) - keyword: PARTITION - keyword: BY @@ -659,26 +655,26 @@ file: - naked_identifier: orders - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: order_id - - data_type: - - keyword: bigint - - column_constraint_segment: - - keyword: not - - keyword: 'null' + - data_type: + - keyword: bigint + - column_constraint_segment: + - keyword: not + - keyword: 'null' - comma: ',' - - column_reference: + - column_definition: - naked_identifier: cust_id - - data_type: - - keyword: bigint - - column_constraint_segment: - - keyword: not - - keyword: 'null' + - data_type: + - keyword: bigint + - column_constraint_segment: + - keyword: not + - keyword: 'null' - comma: ',' - - column_reference: + - column_definition: - naked_identifier: status - - data_type: - - keyword: text + - data_type: + - keyword: text - end_bracket: ) - keyword: PARTITION - keyword: BY @@ -1082,32 +1078,32 @@ file: - naked_identifier: staging - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: event_type - - data_type: - - keyword: INTEGER + - data_type: + - keyword: INTEGER - comma: ',' - - column_reference: + - column_definition: - naked_identifier: event_time - - data_type: - - datetime_type_identifier: - - keyword: TIMESTAMP + - data_type: + - datetime_type_identifier: + - keyword: TIMESTAMP - comma: ',' - - column_reference: + - column_definition: - naked_identifier: user_email - - data_type: - - keyword: VARCHAR + - data_type: + - keyword: VARCHAR - comma: ',' - - column_reference: + - column_definition: - naked_identifier: phone_number - - data_type: - - keyword: VARCHAR + - data_type: + - keyword: VARCHAR - comma: ',' - - column_reference: + - column_definition: - naked_identifier: processing_date - - data_type: - - datetime_type_identifier: - - keyword: DATE + - data_type: + - datetime_type_identifier: + - keyword: DATE - comma: ',' - table_constraint: - keyword: PRIMARY @@ -1139,32 +1135,32 @@ file: - naked_identifier: measurement - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: city_id - - data_type: - - keyword: int - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' - comma: ',' - - column_reference: + - column_definition: - naked_identifier: logdate - - data_type: - - datetime_type_identifier: - - keyword: date - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' - - comma: ',' - - column_reference: + - data_type: + - datetime_type_identifier: + - keyword: date + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: - naked_identifier: peaktemp - - data_type: - - keyword: int + - data_type: + - keyword: int - comma: ',' - - column_reference: + - column_definition: - naked_identifier: unitsales - - data_type: - - keyword: int + - data_type: + - keyword: int - end_bracket: ) - keyword: PARTITION - keyword: BY @@ -1185,74 +1181,74 @@ file: - naked_identifier: public - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: id - - data_type: - - keyword: serial - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' + - data_type: + - keyword: serial + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' - comma: ',' - - column_reference: + - column_definition: - naked_identifier: name - - data_type: - - keyword: text - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' + - data_type: + - keyword: text + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' - comma: ',' - - column_reference: + - column_definition: - naked_identifier: group_name - - data_type: - - keyword: text - - column_constraint_segment: - - keyword: 'NULL' + - data_type: + - keyword: text + - column_constraint_segment: + - keyword: 'NULL' - comma: ',' - - column_reference: + - column_definition: - naked_identifier: cluster_id - - data_type: - - keyword: int8 - - column_constraint_segment: - - keyword: 'NULL' + - data_type: + - keyword: int8 + - column_constraint_segment: + - keyword: 'NULL' - comma: ',' - - column_reference: + - column_definition: - naked_identifier: date_created - - data_type: - - datetime_type_identifier: - - keyword: timestamp - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' - - column_constraint_segment: - - keyword: DEFAULT - - bare_function: CURRENT_TIMESTAMP - - comma: ',' - - column_reference: + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - bare_function: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: - naked_identifier: date_updated - - data_type: - - datetime_type_identifier: - - keyword: timestamp - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' - - column_constraint_segment: - - keyword: DEFAULT - - bare_function: CURRENT_TIMESTAMP - - comma: ',' - - column_reference: + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - bare_function: CURRENT_TIMESTAMP + - comma: ',' + - column_definition: - naked_identifier: operation_id - - data_type: - - keyword: int4 - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' - - column_constraint_segment: - - keyword: DEFAULT - - cast_expression: - - quoted_literal: '''-1''' - - casting_operator: '::' - - data_type: - - keyword: integer + - data_type: + - keyword: int4 + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - cast_expression: + - quoted_literal: '''-1''' + - casting_operator: '::' + - data_type: + - keyword: integer - end_bracket: ) - statement_terminator: ; - statement: @@ -1265,25 +1261,25 @@ file: - naked_identifier: test_table - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - quoted_identifier: '"col1"' - - data_type: - - keyword: character - - keyword: varying - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '40' - - end_bracket: ) - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' + - data_type: + - keyword: character + - keyword: varying + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '40' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' - comma: ',' - - column_reference: + - column_definition: - quoted_identifier: '"col2"' - - data_type: - - keyword: double - - keyword: precision + - data_type: + - keyword: double + - keyword: precision - end_bracket: ) - statement_terminator: ; - statement: @@ -1294,19 +1290,19 @@ file: - naked_identifier: groups - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: group_id - - data_type: - - keyword: INTEGER - - column_constraint_segment: - - keyword: PRIMARY - - keyword: KEY - - column_constraint_segment: - - keyword: generated - - keyword: BY - - keyword: DEFAULT - - keyword: AS - - keyword: IDENTITY + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - column_constraint_segment: + - keyword: generated + - keyword: BY + - keyword: DEFAULT + - keyword: AS + - keyword: IDENTITY - end_bracket: ) - statement_terminator: ; - statement: @@ -1317,69 +1313,69 @@ file: - naked_identifier: users - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: user_id - - data_type: - - keyword: INTEGER - - column_constraint_segment: - - keyword: PRIMARY - - keyword: KEY - - column_constraint_segment: - - keyword: generated - - keyword: BY - - keyword: DEFAULT - - keyword: AS - - keyword: IDENTITY - - comma: ',' - - column_reference: + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - column_constraint_segment: + - keyword: generated + - keyword: BY + - keyword: DEFAULT + - keyword: AS + - keyword: IDENTITY + - comma: ',' + - column_definition: - naked_identifier: group_id - - data_type: - - keyword: INTEGER - - column_constraint_segment: - - keyword: REFERENCES - - table_reference: - - naked_identifier: groups - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: group_id - - end_bracket: ) - - keyword: ON - - keyword: DELETE - - keyword: CASCADE + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: REFERENCES + - table_reference: + - naked_identifier: groups + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: group_id + - end_bracket: ) + - keyword: ON + - keyword: DELETE + - keyword: CASCADE - comma: ',' - - column_reference: + - column_definition: - naked_identifier: domain_id - - data_type: - - keyword: INTEGER - - column_constraint_segment: - - keyword: REFERENCES - - table_reference: - - naked_identifier: groups - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: group_id - - end_bracket: ) - - keyword: ON - - keyword: UPDATE - - keyword: RESTRICT + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: REFERENCES + - table_reference: + - naked_identifier: groups + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: group_id + - end_bracket: ) + - keyword: ON + - keyword: UPDATE + - keyword: RESTRICT - comma: ',' - - column_reference: + - column_definition: - naked_identifier: other_id - - data_type: - - keyword: INTEGER - - column_constraint_segment: - - keyword: REFERENCES - - table_reference: - - naked_identifier: groups - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: group_id - - end_bracket: ) - - keyword: MATCH - - keyword: SIMPLE + - data_type: + - keyword: INTEGER + - column_constraint_segment: + - keyword: REFERENCES + - table_reference: + - naked_identifier: groups + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: group_id + - end_bracket: ) + - keyword: MATCH + - keyword: SIMPLE - end_bracket: ) - statement_terminator: ; - statement: @@ -1390,122 +1386,122 @@ file: - naked_identifier: orders - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: id - - data_type: - - keyword: bigint - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' - - column_constraint_segment: - - keyword: DEFAULT - - function: - - function_name: - - function_name_identifier: NEXTVAL - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - cast_expression: - - quoted_literal: '''orders_id_seq''' - - casting_operator: '::' - - data_type: - - data_type_identifier: regclass - - end_bracket: ) + - data_type: + - keyword: bigint + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - function: + - function_name: + - function_name_identifier: NEXTVAL + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - cast_expression: + - quoted_literal: '''orders_id_seq''' + - casting_operator: '::' + - data_type: + - data_type_identifier: regclass + - end_bracket: ) - comma: ',' - - column_reference: + - column_definition: - naked_identifier: constraint_collate_constraints - - data_type: - - keyword: text - - column_constraint_segment: - - keyword: UNIQUE - - keyword: COLLATE - - collation_reference: - - naked_identifier: numeric - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' - - column_constraint_segment: - - keyword: PRIMARY - - keyword: KEY - - comma: ',' - - column_reference: + - data_type: + - keyword: text + - column_constraint_segment: + - keyword: UNIQUE + - keyword: COLLATE + - collation_reference: + - naked_identifier: numeric + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_definition: - naked_identifier: constraints_collate - - data_type: - - keyword: text - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' - - column_constraint_segment: - - keyword: UNIQUE - - keyword: COLLATE - - collation_reference: - - naked_identifier: numeric - - comma: ',' - - column_reference: + - data_type: + - keyword: text + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: UNIQUE + - keyword: COLLATE + - collation_reference: + - naked_identifier: numeric + - comma: ',' + - column_definition: - naked_identifier: collate_constraints - - data_type: - - keyword: text - - keyword: COLLATE - - collation_reference: - - naked_identifier: numeric - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' - - column_constraint_segment: - - keyword: UNIQUE - - comma: ',' - - column_reference: + - data_type: + - keyword: text + - keyword: COLLATE + - collation_reference: + - naked_identifier: numeric + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: UNIQUE + - comma: ',' + - column_definition: - naked_identifier: nulls_distinct - - data_type: - - keyword: text - - column_constraint_segment: - - keyword: UNIQUE - - keyword: NULLS - - keyword: DISTINCT - - comma: ',' - - column_reference: + - data_type: + - keyword: text + - column_constraint_segment: + - keyword: UNIQUE + - keyword: NULLS + - keyword: DISTINCT + - comma: ',' + - column_definition: - naked_identifier: nulls_not_distinct - - data_type: - - keyword: text - - column_constraint_segment: - - keyword: UNIQUE - - keyword: NULLS - - keyword: NOT - - keyword: DISTINCT - - comma: ',' - - column_reference: + - data_type: + - keyword: text + - column_constraint_segment: + - keyword: UNIQUE + - keyword: NULLS + - keyword: NOT + - keyword: DISTINCT + - comma: ',' + - column_definition: - naked_identifier: everything - - data_type: - - keyword: text - - column_constraint_segment: - - keyword: UNIQUE - - keyword: NULLS - - keyword: DISTINCT - - keyword: WITH - - definition_parameters: - - bracketed: - - start_bracket: ( - - definition_parameter: - - properties_naked_identifier: arg1 - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '3' - - comma: ',' - - definition_parameter: - - properties_naked_identifier: arg5 - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''str''' - - end_bracket: ) - - keyword: USING - - keyword: INDEX - - keyword: TABLESPACE - - tablespace_reference: - - naked_identifier: tblspace - - keyword: COLLATE - - collation_reference: - - naked_identifier: numeric + - data_type: + - keyword: text + - column_constraint_segment: + - keyword: UNIQUE + - keyword: NULLS + - keyword: DISTINCT + - keyword: WITH + - definition_parameters: + - bracketed: + - start_bracket: ( + - definition_parameter: + - properties_naked_identifier: arg1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '3' + - comma: ',' + - definition_parameter: + - properties_naked_identifier: arg5 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''str''' + - end_bracket: ) + - keyword: USING + - keyword: INDEX + - keyword: TABLESPACE + - tablespace_reference: + - naked_identifier: tblspace + - keyword: COLLATE + - collation_reference: + - naked_identifier: numeric - end_bracket: ) - statement_terminator: ; - statement: @@ -1516,37 +1512,37 @@ file: - naked_identifier: primary_key_options - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: everything - - data_type: - - keyword: int - - column_constraint_segment: - - keyword: PRIMARY - - keyword: KEY - - keyword: WITH - - definition_parameters: - - bracketed: - - start_bracket: ( - - definition_parameter: - - properties_naked_identifier: arg1 - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '3' - - comma: ',' - - definition_parameter: - - properties_naked_identifier: arg5 - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''str''' - - end_bracket: ) - - keyword: USING - - keyword: INDEX - - keyword: TABLESPACE - - tablespace_reference: - - naked_identifier: tblspace - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - keyword: WITH + - definition_parameters: + - bracketed: + - start_bracket: ( + - definition_parameter: + - properties_naked_identifier: arg1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '3' + - comma: ',' + - definition_parameter: + - properties_naked_identifier: arg5 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''str''' + - end_bracket: ) + - keyword: USING + - keyword: INDEX + - keyword: TABLESPACE + - tablespace_reference: + - naked_identifier: tblspace + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' - end_bracket: ) - statement_terminator: ; - statement: @@ -1562,10 +1558,10 @@ file: - naked_identifier: usage - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: foo - - data_type: - - keyword: int + - data_type: + - keyword: int - end_bracket: ) - statement_terminator: ; - statement: @@ -1581,10 +1577,10 @@ file: - naked_identifier: my_table - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: usage - - data_type: - - keyword: int + - data_type: + - keyword: int - end_bracket: ) - statement_terminator: ; - statement: @@ -1595,16 +1591,16 @@ file: - naked_identifier: with_constraints1 - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: col_1 - - data_type: - - keyword: boolean - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' - - column_constraint_segment: - - keyword: DEFAULT - - boolean_literal: 'false' + - data_type: + - keyword: boolean + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - boolean_literal: 'false' - end_bracket: ) - statement_terminator: ; - statement: @@ -1615,16 +1611,16 @@ file: - naked_identifier: with_constraints2 - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: col_1 - - data_type: - - keyword: boolean - - column_constraint_segment: - - keyword: DEFAULT - - boolean_literal: 'false' - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' + - data_type: + - keyword: boolean + - column_constraint_segment: + - keyword: DEFAULT + - boolean_literal: 'false' + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' - end_bracket: ) - statement_terminator: ; - statement: @@ -1635,31 +1631,31 @@ file: - naked_identifier: with_constraints3 - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: col_1 - - data_type: - - keyword: int - - column_constraint_segment: - - keyword: DEFAULT - - expression: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '1' - - binary_operator: + - - numeric_literal: '2' - - end_bracket: ) - - binary_operator: '*' - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '3' - - binary_operator: + - - numeric_literal: '4' - - end_bracket: ) - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: DEFAULT + - expression: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - binary_operator: + + - numeric_literal: '2' + - end_bracket: ) + - binary_operator: '*' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - binary_operator: + + - numeric_literal: '4' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' - end_bracket: ) - statement_terminator: ; - statement: @@ -1670,23 +1666,23 @@ file: - naked_identifier: with_constraints33 - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: col_1 - - data_type: - - keyword: int - - column_constraint_segment: - - keyword: DEFAULT - - expression: - - numeric_literal: '1' - - binary_operator: + - - numeric_literal: '2' - - binary_operator: '*' - - numeric_literal: '3' - - binary_operator: + - - numeric_literal: '4' - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: DEFAULT + - expression: + - numeric_literal: '1' + - binary_operator: + + - numeric_literal: '2' + - binary_operator: '*' + - numeric_literal: '3' + - binary_operator: + + - numeric_literal: '4' + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' - end_bracket: ) - statement_terminator: ; - statement: @@ -1697,27 +1693,27 @@ file: - naked_identifier: with_constraints4 - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: col_1 - - data_type: - - keyword: int - - column_constraint_segment: - - keyword: DEFAULT - - expression: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '1' - - binary_operator: + - - numeric_literal: '2' - - binary_operator: '*' - - numeric_literal: '3' - - binary_operator: + - - numeric_literal: '4' - - end_bracket: ) - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: DEFAULT + - expression: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - binary_operator: + + - numeric_literal: '2' + - binary_operator: '*' + - numeric_literal: '3' + - binary_operator: + + - numeric_literal: '4' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' - end_bracket: ) - statement_terminator: ; - statement: @@ -1728,29 +1724,29 @@ file: - naked_identifier: with_constraints5 - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: col_1 - - data_type: - - keyword: bool - - column_constraint_segment: - - keyword: DEFAULT - - expression: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '1' - - keyword: NOT - - keyword: IN - - bracketed: - - start_bracket: ( - - numeric_literal: '3' - - comma: ',' - - numeric_literal: '4' - - end_bracket: ) - - end_bracket: ) - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' + - data_type: + - keyword: bool + - column_constraint_segment: + - keyword: DEFAULT + - expression: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - keyword: NOT + - keyword: IN + - bracketed: + - start_bracket: ( + - numeric_literal: '3' + - comma: ',' + - numeric_literal: '4' + - end_bracket: ) + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' - end_bracket: ) - statement_terminator: ; - statement: @@ -1761,29 +1757,29 @@ file: - naked_identifier: with_constraints6 - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: col_1 - - data_type: - - keyword: bool - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' - - column_constraint_segment: - - keyword: DEFAULT - - expression: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '5' - - keyword: NOT - - keyword: IN - - bracketed: - - start_bracket: ( + - data_type: + - keyword: bool + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - expression: + - bracketed: + - start_bracket: ( + - expression: - numeric_literal: '5' - - comma: ',' - - numeric_literal: '6' - - end_bracket: ) - - end_bracket: ) + - keyword: NOT + - keyword: IN + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '6' + - end_bracket: ) + - end_bracket: ) - end_bracket: ) - statement_terminator: ; - statement: @@ -1794,10 +1790,10 @@ file: - naked_identifier: test_with_storage_param - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: col_1 - - data_type: - - keyword: boolean + - data_type: + - keyword: boolean - end_bracket: ) - keyword: WITH - relation_options: @@ -1818,10 +1814,10 @@ file: - naked_identifier: test_with_storage_params - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: col_1 - - data_type: - - keyword: boolean + - data_type: + - keyword: boolean - end_bracket: ) - keyword: WITH - relation_options: @@ -1848,82 +1844,82 @@ file: - naked_identifier: tbl - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: col_char_varying_unlimited - - data_type: - - keyword: character - - keyword: varying + - data_type: + - keyword: character + - keyword: varying - comma: ',' - - column_reference: + - column_definition: - naked_identifier: col_char_varying_limited - - data_type: - - keyword: character - - keyword: varying - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '50' - - end_bracket: ) + - data_type: + - keyword: character + - keyword: varying + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '50' + - end_bracket: ) - comma: ',' - - column_reference: + - column_definition: - naked_identifier: col_varchar_unlimited - - data_type: - - keyword: varchar + - data_type: + - keyword: varchar - comma: ',' - - column_reference: + - column_definition: - naked_identifier: col_varchar_limited - - data_type: - - keyword: varchar - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '50' - - end_bracket: ) + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '50' + - end_bracket: ) - comma: ',' - - column_reference: + - column_definition: - naked_identifier: col_character_default - - data_type: - - keyword: character + - data_type: + - keyword: character - comma: ',' - - column_reference: + - column_definition: - naked_identifier: col_character_specified - - data_type: - - keyword: character - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '50' - - end_bracket: ) + - data_type: + - keyword: character + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '50' + - end_bracket: ) - comma: ',' - - column_reference: + - column_definition: - naked_identifier: col_char_default - - data_type: - - keyword: char + - data_type: + - keyword: char - comma: ',' - - column_reference: + - column_definition: - naked_identifier: col_char_specified - - data_type: - - keyword: character - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '50' - - end_bracket: ) + - data_type: + - keyword: character + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '50' + - end_bracket: ) - comma: ',' - - column_reference: + - column_definition: - naked_identifier: col_text - - data_type: - - keyword: text + - data_type: + - keyword: text - comma: ',' - - column_reference: + - column_definition: - naked_identifier: col_system_char - - data_type: - - quoted_identifier: '"char"' + - data_type: + - quoted_identifier: '"char"' - comma: ',' - - column_reference: + - column_definition: - naked_identifier: col_name - - data_type: - - data_type_identifier: name + - data_type: + - data_type_identifier: name - end_bracket: ) - statement_terminator: ; - statement: @@ -1934,10 +1930,10 @@ file: - naked_identifier: reservation - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: during - - data_type: - - keyword: tsrange + - data_type: + - keyword: tsrange - comma: ',' - table_constraint: - keyword: EXCLUDE @@ -1965,15 +1961,15 @@ file: - naked_identifier: room_reservation - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: room - - data_type: - - keyword: text + - data_type: + - keyword: text - comma: ',' - - column_reference: + - column_definition: - naked_identifier: during - - data_type: - - keyword: tsrange + - data_type: + - keyword: tsrange - comma: ',' - table_constraint: - keyword: EXCLUDE @@ -2009,10 +2005,10 @@ file: - naked_identifier: no_using - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: field - - data_type: - - keyword: text + - data_type: + - keyword: text - comma: ',' - table_constraint: - keyword: EXCLUDE @@ -2042,10 +2038,10 @@ file: - naked_identifier: many_options - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: field - - data_type: - - keyword: text + - data_type: + - keyword: text - comma: ',' - table_constraint: - keyword: EXCLUDE @@ -2308,3 +2304,170 @@ file: - naked_identifier: parent_table - end_bracket: ) - statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: table2 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - keyword: int + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: col3 + - data_type: + - keyword: int + - comma: ',' + - table_constraint: + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: table1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: ON + - keyword: DELETE + - keyword: SET + - keyword: 'NULL' + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: table2 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - keyword: int + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: col3 + - data_type: + - keyword: int + - comma: ',' + - table_constraint: + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: table1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: ON + - keyword: DELETE + - keyword: SET + - keyword: DEFAULT + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: myschema + - dot: . + - naked_identifier: user + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: user_id + - data_type: + - keyword: bigint + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_definition: + - naked_identifier: name + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '40' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: interval + - data_type: + - keyword: bigint + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_text_search_configuration.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_text_search_configuration.sql new file mode 100644 index 000000000..a68c322f1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_text_search_configuration.sql @@ -0,0 +1,9 @@ +CREATE TEXT SEARCH CONFIGURATION my_config ( + PARSER = my_parser +); +CREATE TEXT SEARCH CONFIGURATION public.my_config ( + PARSER = pg_catalog."default" +); +CREATE TEXT SEARCH CONFIGURATION copy_config ( + COPY = pg_catalog.english +); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_text_search_configuration.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_text_search_configuration.yml new file mode 100644 index 000000000..2f04f9c73 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_text_search_configuration.yml @@ -0,0 +1,58 @@ +file: +- statement: + - create_text_search_configuration_statement: + - keyword: CREATE + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - object_reference: + - naked_identifier: my_config + - bracketed: + - start_bracket: ( + - keyword: PARSER + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_parser + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_text_search_configuration_statement: + - keyword: CREATE + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - object_reference: + - naked_identifier: public + - dot: . + - naked_identifier: my_config + - bracketed: + - start_bracket: ( + - keyword: PARSER + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: pg_catalog + - dot: . + - quoted_identifier: '"default"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_text_search_configuration_statement: + - keyword: CREATE + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - object_reference: + - naked_identifier: copy_config + - bracketed: + - start_bracket: ( + - keyword: COPY + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: pg_catalog + - dot: . + - naked_identifier: english + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_type.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_type.sql index f2a16bdf2..b16970184 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_type.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_type.sql @@ -5,8 +5,3 @@ CREATE TYPE bar AS ENUM ('foo', 'bar'); CREATE TYPE foobar AS RANGE (SUBTYPE = FLOAT); CREATE TYPE barbar AS (INPUT = foo, OUTPUT = bar); CREATE TYPE foofoo AS (foo varchar collate utf8); -CREATE TYPE person AS ( - first_name text COLLATE "en_US", - last_name text COLLATE "en_US", - birth_date date -); \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_type.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_type.yml index 3ede1d276..ff37c8c05 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_type.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_type.yml @@ -3,15 +3,15 @@ file: - create_type_statement: - keyword: CREATE - keyword: TYPE - - object_reference: - - naked_identifier: foo + - data_type: + - data_type_identifier: foo - statement_terminator: ; - statement: - create_type_statement: - keyword: CREATE - keyword: TYPE - - object_reference: - - naked_identifier: bar + - data_type: + - data_type_identifier: bar - keyword: AS - keyword: ENUM - bracketed: @@ -22,8 +22,8 @@ file: - create_type_statement: - keyword: CREATE - keyword: TYPE - - object_reference: - - naked_identifier: bar + - data_type: + - data_type_identifier: bar - keyword: AS - keyword: ENUM - bracketed: @@ -37,8 +37,8 @@ file: - create_type_statement: - keyword: CREATE - keyword: TYPE - - object_reference: - - naked_identifier: foobar + - data_type: + - data_type_identifier: foobar - keyword: AS - keyword: RANGE - bracketed: @@ -52,8 +52,8 @@ file: - create_type_statement: - keyword: CREATE - keyword: TYPE - - object_reference: - - naked_identifier: barbar + - data_type: + - data_type_identifier: barbar - keyword: AS - bracketed: - start_bracket: ( @@ -70,49 +70,14 @@ file: - create_type_statement: - keyword: CREATE - keyword: TYPE - - object_reference: - - naked_identifier: foofoo + - data_type: + - data_type_identifier: foofoo - keyword: AS - bracketed: - start_bracket: ( - - column_reference: - - naked_identifier: foo - - data_type: - - keyword: varchar - - keyword: collate - - collation_reference: - - naked_identifier: utf8 - - end_bracket: ) -- statement_terminator: ; -- statement: - - create_type_statement: - - keyword: CREATE - - keyword: TYPE - - object_reference: - - naked_identifier: person - - keyword: AS - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: first_name - - data_type: - - keyword: text - - keyword: COLLATE - - collation_reference: - - quoted_identifier: '"en_US"' - - comma: ',' - - column_reference: - - naked_identifier: last_name - - data_type: - - keyword: text - - keyword: COLLATE - - collation_reference: - - quoted_identifier: '"en_US"' - - comma: ',' - - column_reference: - - naked_identifier: birth_date - - data_type: - - datetime_type_identifier: - - keyword: date + - word: foo + - word: varchar + - word: collate + - word: utf8 - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_user_mapping.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_user_mapping.yml index 762aea157..cf1091e65 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_user_mapping.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_user_mapping.yml @@ -12,10 +12,10 @@ file: - keyword: OPTIONS - bracketed: - start_bracket: ( - - naked_identifier: user + - naked_identifier_all: user - quoted_literal: '''bob''' - comma: ',' - - naked_identifier: password + - naked_identifier_all: password - quoted_literal: '''secret''' - end_bracket: ) - statement_terminator: ; @@ -28,7 +28,7 @@ file: - keyword: NOT - keyword: EXISTS - keyword: FOR - - naked_identifier: PUBLIC + - keyword: PUBLIC - keyword: SERVER - server_reference: - naked_identifier: foo @@ -49,13 +49,13 @@ file: - keyword: OPTIONS - bracketed: - start_bracket: ( - - naked_identifier: user + - naked_identifier_all: user - quoted_literal: '''bob''' - comma: ',' - - naked_identifier: password + - naked_identifier_all: password - quoted_literal: '''secret''' - comma: ',' - - naked_identifier: option + - naked_identifier_all: option - quoted_literal: '''value''' - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_view.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_view.yml index 2d58a8a54..2b231fe95 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_view.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/create_view.yml @@ -43,7 +43,8 @@ file: - keyword: text - quoted_literal: '''Hello World''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: hello - statement_terminator: ; - statement: @@ -63,7 +64,8 @@ file: - keyword: text - quoted_literal: '''Hello World''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: hello - statement_terminator: ; - statement: @@ -83,7 +85,8 @@ file: - keyword: text - quoted_literal: '''Hello World''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: hello - statement_terminator: ; - statement: @@ -490,7 +493,8 @@ file: - column_reference: - quoted_identifier: '"group_id"' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_identifier: '"node_id"' - comma: ',' - select_clause_element: @@ -508,7 +512,8 @@ file: - start_square_bracket: '[' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_identifier: '"ancestors"' - comma: ',' - select_clause_element: @@ -532,7 +537,8 @@ file: - start_square_bracket: '[' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_identifier: '"path"' - comma: ',' - select_clause_element: @@ -552,7 +558,8 @@ file: - start_square_bracket: '[' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_identifier: '"path_nodes"' - from_clause: - keyword: FROM @@ -654,7 +661,8 @@ file: - column_reference: - naked_identifier: col1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: collation - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/cte_in_materialized_view.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/cte_in_materialized_view.yml index 9470e410b..65591a130 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/cte_in_materialized_view.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/cte_in_materialized_view.yml @@ -38,7 +38,8 @@ file: - naked_identifier: amount - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: total_sales - from_clause: - keyword: FROM @@ -131,7 +132,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: product_units - comma: ',' - select_clause_element: @@ -146,7 +148,8 @@ file: - naked_identifier: amount - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: product_sales - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/datatypes.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/datatypes.yml index 283af6bc4..d409ee1f4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/datatypes.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/datatypes.yml @@ -7,81 +7,81 @@ file: - naked_identifier: a - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: smallint + - data_type: + - keyword: smallint - comma: ',' - - column_reference: + - column_definition: - naked_identifier: b - - data_type: - - keyword: integer + - data_type: + - keyword: integer - comma: ',' - - column_reference: + - column_definition: - naked_identifier: ba - - data_type: - - keyword: int2 + - data_type: + - keyword: int2 - comma: ',' - - column_reference: + - column_definition: - naked_identifier: bb - - data_type: - - keyword: int4 + - data_type: + - keyword: int4 - comma: ',' - - column_reference: + - column_definition: - naked_identifier: bc - - data_type: - - keyword: int8 + - data_type: + - keyword: int8 - comma: ',' - - column_reference: + - column_definition: - naked_identifier: bd - - data_type: - - keyword: int + - data_type: + - keyword: int - comma: ',' - - column_reference: + - column_definition: - naked_identifier: c - - data_type: - - keyword: bigint + - data_type: + - keyword: bigint - comma: ',' - - column_reference: + - column_definition: - naked_identifier: d - - data_type: - - keyword: real + - data_type: + - keyword: real - comma: ',' - - column_reference: + - column_definition: - naked_identifier: e - - data_type: - - keyword: double - - keyword: precision + - data_type: + - keyword: double + - keyword: precision - comma: ',' - - column_reference: + - column_definition: - naked_identifier: f - - data_type: - - keyword: smallserial + - data_type: + - keyword: smallserial - comma: ',' - - column_reference: + - column_definition: - naked_identifier: g - - data_type: - - keyword: serial + - data_type: + - keyword: serial - comma: ',' - - column_reference: + - column_definition: - naked_identifier: ga - - data_type: - - keyword: serial2 + - data_type: + - keyword: serial2 - comma: ',' - - column_reference: + - column_definition: - naked_identifier: gb - - data_type: - - keyword: serial4 + - data_type: + - keyword: serial4 - comma: ',' - - column_reference: + - column_definition: - naked_identifier: gc - - data_type: - - keyword: serial8 + - data_type: + - keyword: serial8 - comma: ',' - - column_reference: + - column_definition: - naked_identifier: h - - data_type: - - keyword: bigserial + - data_type: + - keyword: bigserial - end_bracket: ) - statement_terminator: ; - statement: @@ -92,30 +92,30 @@ file: - naked_identifier: b - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: float + - data_type: + - keyword: float - comma: ',' - - column_reference: + - column_definition: - naked_identifier: b - - data_type: - - keyword: float - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '24' - - end_bracket: ) - - comma: ',' - - column_reference: + - data_type: + - keyword: float + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '24' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: c - - data_type: - - keyword: float4 + - data_type: + - keyword: float4 - comma: ',' - - column_reference: + - column_definition: - naked_identifier: e - - data_type: - - keyword: float8 + - data_type: + - keyword: float8 - end_bracket: ) - statement_terminator: ; - statement: @@ -126,59 +126,59 @@ file: - naked_identifier: c - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: numeric + - data_type: + - keyword: numeric - comma: ',' - - column_reference: + - column_definition: - naked_identifier: aa - - data_type: - - keyword: decimal + - data_type: + - keyword: decimal - comma: ',' - - column_reference: + - column_definition: - naked_identifier: b - - data_type: - - keyword: numeric - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '7' - - end_bracket: ) - - comma: ',' - - column_reference: + - data_type: + - keyword: numeric + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '7' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: ba - - data_type: - - keyword: decimal - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '7' - - end_bracket: ) - - comma: ',' - - column_reference: + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '7' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: c - - data_type: - - keyword: numeric - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '7' - - comma: ',' - - numeric_literal: '2' - - end_bracket: ) - - comma: ',' - - column_reference: + - data_type: + - keyword: numeric + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '7' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: ca - - data_type: - - keyword: decimal - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '7' - - comma: ',' - - numeric_literal: '2' - - end_bracket: ) + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '7' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) - end_bracket: ) - statement_terminator: ; - statement: @@ -189,10 +189,10 @@ file: - naked_identifier: d - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: money + - data_type: + - keyword: money - end_bracket: ) - statement_terminator: ; - statement: @@ -203,72 +203,72 @@ file: - naked_identifier: e - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: char + - data_type: + - keyword: char - comma: ',' - - column_reference: + - column_definition: - naked_identifier: b - - data_type: - - keyword: char - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '7' - - end_bracket: ) - - comma: ',' - - column_reference: + - data_type: + - keyword: char + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '7' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: c - - data_type: - - keyword: character + - data_type: + - keyword: character - comma: ',' - - column_reference: + - column_definition: - naked_identifier: d - - data_type: - - keyword: character - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '5' - - end_bracket: ) - - comma: ',' - - column_reference: + - data_type: + - keyword: character + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: e - - data_type: - - keyword: character - - keyword: varying + - data_type: + - keyword: character + - keyword: varying - comma: ',' - - column_reference: + - column_definition: - naked_identifier: f - - data_type: - - keyword: character - - keyword: varying - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '8' - - end_bracket: ) - - comma: ',' - - column_reference: + - data_type: + - keyword: character + - keyword: varying + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '8' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: g - - data_type: - - keyword: varchar - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '9' - - end_bracket: ) - - comma: ',' - - column_reference: + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '9' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: h - - data_type: - - keyword: varchar + - data_type: + - keyword: varchar - comma: ',' - - column_reference: + - column_definition: - naked_identifier: i - - data_type: - - keyword: text + - data_type: + - keyword: text - end_bracket: ) - statement_terminator: ; - statement: @@ -279,10 +279,10 @@ file: - naked_identifier: f - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: bytea + - data_type: + - keyword: bytea - end_bracket: ) - statement_terminator: ; - statement: @@ -293,125 +293,131 @@ file: - naked_identifier: g - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - datetime_type_identifier: - - keyword: date + - data_type: + - datetime_type_identifier: + - keyword: date - comma: ',' - - column_reference: + - column_definition: - naked_identifier: b - - data_type: - - datetime_type_identifier: - - keyword: interval - - bracketed: - - start_bracket: ( - - numeric_literal: '4' - - end_bracket: ) - - comma: ',' - - column_reference: + - data_type: + - datetime_type_identifier: + - keyword: interval + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: c - - data_type: - - datetime_type_identifier: - - keyword: time - - bracketed: - - start_bracket: ( - - numeric_literal: '4' - - end_bracket: ) - - comma: ',' - - column_reference: + - data_type: + - datetime_type_identifier: + - keyword: time + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: d - - data_type: - - datetime_type_identifier: - - keyword: time - - bracketed: - - start_bracket: ( - - numeric_literal: '4' - - end_bracket: ) - - keyword: with - - keyword: time - - keyword: zone - - comma: ',' - - column_reference: + - data_type: + - datetime_type_identifier: + - keyword: time + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - end_bracket: ) + - keyword: with + - keyword: time + - keyword: zone + - comma: ',' + - column_definition: - naked_identifier: e - - data_type: - - datetime_type_identifier: - - keyword: time - - bracketed: - - start_bracket: ( - - numeric_literal: '4' - - end_bracket: ) - - keyword: without - - keyword: time - - keyword: zone - - comma: ',' - - column_reference: + - data_type: + - datetime_type_identifier: + - keyword: time + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - end_bracket: ) + - keyword: without + - keyword: time + - keyword: zone + - comma: ',' + - column_definition: - naked_identifier: f - - data_type: - - datetime_type_identifier: - - keyword: timestamp - - bracketed: - - start_bracket: ( - - numeric_literal: '4' - - end_bracket: ) - - comma: ',' - - column_reference: + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: g - - data_type: - - datetime_type_identifier: - - keyword: timestamp - - bracketed: - - start_bracket: ( - - numeric_literal: '4' - - end_bracket: ) - - keyword: with - - keyword: time - - keyword: zone - - comma: ',' - - column_reference: + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - end_bracket: ) + - keyword: with + - keyword: time + - keyword: zone + - comma: ',' + - column_definition: - naked_identifier: h - - data_type: - - datetime_type_identifier: - - keyword: timestamp - - bracketed: - - start_bracket: ( - - numeric_literal: '4' - - end_bracket: ) - - keyword: without - - keyword: time - - keyword: zone - - comma: ',' - - column_reference: + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - end_bracket: ) + - keyword: without + - keyword: time + - keyword: zone + - comma: ',' + - column_definition: - naked_identifier: i - - data_type: - - datetime_type_identifier: - - keyword: timetz + - data_type: + - datetime_type_identifier: + - keyword: timetz - comma: ',' - - column_reference: + - column_definition: - naked_identifier: j - - data_type: - - datetime_type_identifier: - - keyword: timetz - - bracketed: - - start_bracket: ( - - numeric_literal: '4' - - end_bracket: ) - - comma: ',' - - column_reference: + - data_type: + - datetime_type_identifier: + - keyword: timetz + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: k - - data_type: - - datetime_type_identifier: - - keyword: timestamptz + - data_type: + - datetime_type_identifier: + - keyword: timestamptz - comma: ',' - - column_reference: + - column_definition: - naked_identifier: l - - data_type: - - datetime_type_identifier: - - keyword: timestamptz - - bracketed: - - start_bracket: ( - - numeric_literal: '4' - - end_bracket: ) + - data_type: + - datetime_type_identifier: + - keyword: timestamptz + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - end_bracket: ) - end_bracket: ) - statement_terminator: ; - statement: @@ -422,15 +428,15 @@ file: - naked_identifier: h - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: boolean + - data_type: + - keyword: boolean - comma: ',' - - column_reference: + - column_definition: - naked_identifier: b - - data_type: - - keyword: bool + - data_type: + - keyword: bool - end_bracket: ) - statement_terminator: ; - statement: @@ -441,40 +447,40 @@ file: - naked_identifier: i - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: point + - data_type: + - keyword: point - comma: ',' - - column_reference: + - column_definition: - naked_identifier: b - - data_type: - - keyword: line + - data_type: + - keyword: line - comma: ',' - - column_reference: + - column_definition: - naked_identifier: c - - data_type: - - keyword: lseg + - data_type: + - keyword: lseg - comma: ',' - - column_reference: + - column_definition: - naked_identifier: d - - data_type: - - keyword: box + - data_type: + - keyword: box - comma: ',' - - column_reference: + - column_definition: - naked_identifier: e - - data_type: - - keyword: path + - data_type: + - keyword: path - comma: ',' - - column_reference: + - column_definition: - naked_identifier: f - - data_type: - - keyword: polygon + - data_type: + - keyword: polygon - comma: ',' - - column_reference: + - column_definition: - naked_identifier: g - - data_type: - - keyword: circle + - data_type: + - keyword: circle - end_bracket: ) - statement_terminator: ; - statement: @@ -485,25 +491,25 @@ file: - naked_identifier: j - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: cidr + - data_type: + - keyword: cidr - comma: ',' - - column_reference: + - column_definition: - naked_identifier: b - - data_type: - - keyword: inet + - data_type: + - keyword: inet - comma: ',' - - column_reference: + - column_definition: - naked_identifier: c - - data_type: - - keyword: macaddr + - data_type: + - keyword: macaddr - comma: ',' - - column_reference: + - column_definition: - naked_identifier: d - - data_type: - - keyword: macaddr8 + - data_type: + - keyword: macaddr8 - end_bracket: ) - statement_terminator: ; - statement: @@ -514,37 +520,37 @@ file: - naked_identifier: k - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: bit + - data_type: + - keyword: bit - comma: ',' - - column_reference: + - column_definition: - naked_identifier: b - - data_type: - - keyword: bit - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '3' - - end_bracket: ) - - comma: ',' - - column_reference: + - data_type: + - keyword: bit + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '3' + - end_bracket: ) + - comma: ',' + - column_definition: - naked_identifier: c - - data_type: - - keyword: bit - - keyword: varying + - data_type: + - keyword: bit + - keyword: varying - comma: ',' - - column_reference: + - column_definition: - naked_identifier: d - - data_type: - - keyword: bit - - keyword: varying - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '5' - - end_bracket: ) + - data_type: + - keyword: bit + - keyword: varying + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) - end_bracket: ) - statement_terminator: ; - statement: @@ -555,10 +561,10 @@ file: - naked_identifier: l - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: pg_lsn + - data_type: + - keyword: pg_lsn - end_bracket: ) - statement_terminator: ; - statement: @@ -569,15 +575,15 @@ file: - naked_identifier: l - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: tsvector + - data_type: + - keyword: tsvector - comma: ',' - - column_reference: + - column_definition: - naked_identifier: b - - data_type: - - keyword: tsquery + - data_type: + - keyword: tsquery - end_bracket: ) - statement_terminator: ; - statement: @@ -588,10 +594,10 @@ file: - naked_identifier: m - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: uuid + - data_type: + - keyword: uuid - end_bracket: ) - statement_terminator: ; - statement: @@ -602,10 +608,10 @@ file: - naked_identifier: n - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: xml + - data_type: + - keyword: xml - end_bracket: ) - statement_terminator: ; - statement: @@ -616,15 +622,15 @@ file: - naked_identifier: o - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: json + - data_type: + - keyword: json - comma: ',' - - column_reference: + - column_definition: - naked_identifier: b - - data_type: - - keyword: jsonb + - data_type: + - keyword: jsonb - end_bracket: ) - statement_terminator: ; - statement: @@ -635,70 +641,70 @@ file: - naked_identifier: p - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - keyword: integer - - start_square_bracket: '[' - - end_square_bracket: ']' + - data_type: + - keyword: integer + - start_square_bracket: '[' + - end_square_bracket: ']' - comma: ',' - - column_reference: + - column_definition: - naked_identifier: b - - data_type: - - keyword: float - - start_square_bracket: '[' - - end_square_bracket: ']' - - start_square_bracket: '[' - - end_square_bracket: ']' - - comma: ',' - - column_reference: + - data_type: + - keyword: float + - start_square_bracket: '[' + - end_square_bracket: ']' + - start_square_bracket: '[' + - end_square_bracket: ']' + - comma: ',' + - column_definition: - naked_identifier: c - - data_type: - - keyword: char - - start_square_bracket: '[' - - expression: - - numeric_literal: '1' - - end_square_bracket: ']' + - data_type: + - keyword: char + - start_square_bracket: '[' + - expression: + - numeric_literal: '1' + - end_square_bracket: ']' - comma: ',' - - column_reference: + - column_definition: - naked_identifier: d - - data_type: - - keyword: jsonb - - start_square_bracket: '[' - - expression: - - numeric_literal: '3' - - end_square_bracket: ']' - - start_square_bracket: '[' - - expression: - - numeric_literal: '5' - - end_square_bracket: ']' + - data_type: + - keyword: jsonb + - start_square_bracket: '[' + - expression: + - numeric_literal: '3' + - end_square_bracket: ']' + - start_square_bracket: '[' + - expression: + - numeric_literal: '5' + - end_square_bracket: ']' - comma: ',' - - column_reference: + - column_definition: - naked_identifier: e - - data_type: - - keyword: money - - array_type: - - keyword: ARRAY - - comma: ',' - - column_reference: - - naked_identifier: f - - data_type: - - keyword: money - - sized_array_type: + - data_type: + - keyword: money - array_type: - keyword: ARRAY - - array_accessor: - - start_square_bracket: '[' - - numeric_literal: '7' - - end_square_bracket: ']' + - comma: ',' + - column_definition: + - naked_identifier: f + - data_type: + - keyword: money + - sized_array_type: + - array_type: + - keyword: ARRAY + - array_accessor: + - start_square_bracket: '[' + - numeric_literal: '7' + - end_square_bracket: ']' - end_bracket: ) - statement_terminator: ; - statement: - create_type_statement: - keyword: CREATE - keyword: TYPE - - object_reference: - - naked_identifier: bar + - data_type: + - data_type_identifier: bar - keyword: AS - keyword: ENUM - bracketed: @@ -716,20 +722,20 @@ file: - naked_identifier: q - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - data_type_identifier: bar + - data_type: + - data_type_identifier: bar - end_bracket: ) - statement_terminator: ; - statement: - create_type_statement: - keyword: create - keyword: type - - object_reference: + - data_type: - naked_identifier: public - dot: . - - naked_identifier: c + - data_type_identifier: c - keyword: AS - keyword: ENUM - bracketed: @@ -747,12 +753,12 @@ file: - naked_identifier: r - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: a - - data_type: - - naked_identifier: public - - dot: . - - data_type_identifier: c + - data_type: + - naked_identifier: public + - dot: . + - data_type_identifier: c - end_bracket: ) - statement_terminator: ; - statement: @@ -763,16 +769,16 @@ file: - naked_identifier: a - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: b - - data_type: - - datetime_type_identifier: - - keyword: DATE + - data_type: + - datetime_type_identifier: + - keyword: DATE - comma: ',' - - column_reference: + - column_definition: - naked_identifier: c - - data_type: - - data_type_identifier: DATETIME + - data_type: + - data_type_identifier: DATETIME - end_bracket: ) - statement_terminator: ; - statement: @@ -828,23 +834,23 @@ file: - naked_identifier: test - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: situation - - data_type: - - keyword: bpchar - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '1' - - end_bracket: ) - - column_constraint_segment: - - keyword: 'null' - - column_constraint_segment: - - keyword: default - - cast_expression: - - quoted_literal: '''A''' - - casting_operator: '::' - - data_type: - - keyword: bpchar + - data_type: + - keyword: bpchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'null' + - column_constraint_segment: + - keyword: default + - cast_expression: + - quoted_literal: '''A''' + - casting_operator: '::' + - data_type: + - keyword: bpchar - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/datetime_units.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/datetime_units.sql index 709984889..b02aa975e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/datetime_units.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/datetime_units.sql @@ -62,3 +62,54 @@ SELECT t1.field, EXTRACT(TIMEZONE_MINUTE FROM t1.sometime) AS a FROM t1; + +SELECT + t1.field, + DATE '2001-09-28' + 7 + t1.data AS a +FROM t1; + +SELECT + t1.field, + NOW() + INTERVAL '1 HOUR' + t1.data AS a +FROM t1; + +SELECT + t1.field, + t1.data + TIME '03:00' AS a +FROM t1; + +SELECT + t1.field, + INTERVAL '1 DAY' + INTERVAL '1 HOUR 2 MINUTES' + t1.data AS a +FROM t1; + +SELECT + t1.field, + TIMESTAMP '2001-09-28 01:00' + INTERVAL '23 HOURS' + t1.data AS a +FROM t1; + +SELECT + t1.field, + TIME '01:00' + INTERVAL '3S' + t1.data AS a +FROM t1; + +SELECT + t1.field, + - INTERVAL '23 HOURS' + t1.data AS a +FROM t1; + +SELECT + t1.field, + INTERVAL '1 HOUR' / 1.5 + t1.data AS a +FROM t1; + +SELECT + t1.field, + INTERVAL '1' HOUR * 3.5 + t1.data AS a +FROM t1; + + +SELECT + t1.field, + TIMESTAMP WITH TIME ZONE '2005-04-02 12:00:00-07' + INTERVAL '24 HOURS' + t1.data AS a +FROM t1; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/datetime_units.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/datetime_units.yml index 9194e1228..359b1394d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/datetime_units.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/datetime_units.yml @@ -25,7 +25,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -61,7 +62,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -97,7 +99,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -133,7 +136,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -169,7 +173,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -205,7 +210,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -241,7 +247,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -277,7 +284,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -313,7 +321,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -349,7 +358,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -385,7 +395,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -421,7 +432,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -457,7 +469,376 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: field + - comma: ',' + - select_clause_element: + - expression: + - datetime_literal: + - datetime_type_identifier: + - keyword: DATE + - quoted_literal: '''2001-09-28''' + - binary_operator: + + - numeric_literal: '7' + - binary_operator: + + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: data + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: field + - comma: ',' + - select_clause_element: + - expression: + - function: + - function_name: + - function_name_identifier: NOW + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - binary_operator: + + - datetime_literal: + - datetime_type_identifier: + - keyword: INTERVAL + - quoted_literal: '''1 HOUR''' + - binary_operator: + + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: data + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: field + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: data + - binary_operator: + + - datetime_literal: + - datetime_type_identifier: + - keyword: TIME + - quoted_literal: '''03:00''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: field + - comma: ',' + - select_clause_element: + - expression: + - datetime_literal: + - datetime_type_identifier: + - keyword: INTERVAL + - quoted_literal: '''1 DAY''' + - binary_operator: + + - datetime_literal: + - datetime_type_identifier: + - keyword: INTERVAL + - quoted_literal: '''1 HOUR 2 MINUTES''' + - binary_operator: + + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: data + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: field + - comma: ',' + - select_clause_element: + - expression: + - datetime_literal: + - datetime_type_identifier: + - keyword: TIMESTAMP + - quoted_literal: '''2001-09-28 01:00''' + - binary_operator: + + - datetime_literal: + - datetime_type_identifier: + - keyword: INTERVAL + - quoted_literal: '''23 HOURS''' + - binary_operator: + + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: data + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: field + - comma: ',' + - select_clause_element: + - expression: + - datetime_literal: + - datetime_type_identifier: + - keyword: TIME + - quoted_literal: '''01:00''' + - binary_operator: + + - datetime_literal: + - datetime_type_identifier: + - keyword: INTERVAL + - quoted_literal: '''3S''' + - binary_operator: + + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: data + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: field + - comma: ',' + - select_clause_element: + - expression: + - sign_indicator: '-' + - datetime_literal: + - datetime_type_identifier: + - keyword: INTERVAL + - quoted_literal: '''23 HOURS''' + - binary_operator: + + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: data + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: field + - comma: ',' + - select_clause_element: + - expression: + - datetime_literal: + - datetime_type_identifier: + - keyword: INTERVAL + - quoted_literal: '''1 HOUR''' + - binary_operator: / + - numeric_literal: '1.5' + - binary_operator: + + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: data + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: field + - comma: ',' + - select_clause_element: + - expression: + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''1''' + - date_part: HOUR + - binary_operator: '*' + - numeric_literal: '3.5' + - binary_operator: + + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: data + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: field + - comma: ',' + - select_clause_element: + - expression: + - datetime_literal: + - datetime_type_identifier: + - keyword: TIMESTAMP + - keyword: WITH + - keyword: TIME + - keyword: ZONE + - quoted_literal: '''2005-04-02 12:00:00-07''' + - binary_operator: + + - datetime_literal: + - datetime_type_identifier: + - keyword: INTERVAL + - quoted_literal: '''24 HOURS''' + - binary_operator: + + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: data + - alias_expression: + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/deallocate.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/deallocate.sql new file mode 100644 index 000000000..318214b7a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/deallocate.sql @@ -0,0 +1,7 @@ +DEALLOCATE statement_name; + +DEALLOCATE PREPARE statement_name; + +DEALLOCATE ALL; + +DEALLOCATE PREPARE ALL; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/deallocate.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/deallocate.yml new file mode 100644 index 000000000..96b04e607 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/deallocate.yml @@ -0,0 +1,25 @@ +file: +- statement: + - deallocate_statement: + - keyword: DEALLOCATE + - object_reference: + - naked_identifier: statement_name +- statement_terminator: ; +- statement: + - deallocate_statement: + - keyword: DEALLOCATE + - keyword: PREPARE + - object_reference: + - naked_identifier: statement_name +- statement_terminator: ; +- statement: + - deallocate_statement: + - keyword: DEALLOCATE + - keyword: ALL +- statement_terminator: ; +- statement: + - deallocate_statement: + - keyword: DEALLOCATE + - keyword: PREPARE + - keyword: ALL +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/delete.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/delete.sql index b60f06e66..868e453e3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/delete.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/delete.sql @@ -52,3 +52,8 @@ WITH RECURSIVE t(n) AS ( SELECT n+1 FROM t WHERE n < 100 ) DELETE FROM films; + +DELETE FROM foo USING baz + LEFT JOIN bar ON baz.bar_id = bar.id + WHERE foo.id = bar.foo_id + AND baz.id = 'c'; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/delete.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/delete.yml index 6092d5d26..0e791895a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/delete.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/delete.yml @@ -29,7 +29,8 @@ file: - table_reference: - naked_identifier: films - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: f - statement_terminator: ; - statement: @@ -78,14 +79,16 @@ file: - table_reference: - naked_identifier: films - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: f - keyword: USING - table_expression: - table_reference: - naked_identifier: producers - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: p - where_clause: - keyword: WHERE @@ -116,21 +119,24 @@ file: - table_reference: - naked_identifier: films - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: f - keyword: USING - table_expression: - table_reference: - naked_identifier: producers - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: p - comma: ',' - table_expression: - table_reference: - naked_identifier: actors - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - where_clause: - keyword: WHERE @@ -353,7 +359,8 @@ file: - column_reference: - naked_identifier: actor_id - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: a_id - statement_terminator: ; - statement: @@ -419,14 +426,16 @@ file: - column_reference: - naked_identifier: actor_id - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: a_id - comma: ',' - expression: - column_reference: - naked_identifier: producer_id - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: p_id - statement_terminator: ; - statement: @@ -541,3 +550,55 @@ file: - table_reference: - naked_identifier: films - statement_terminator: ; +- statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: foo + - keyword: USING + - table_expression: + - table_reference: + - naked_identifier: baz + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: baz + - dot: . + - naked_identifier: bar_id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: bar + - dot: . + - naked_identifier: id + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: foo + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: bar + - dot: . + - naked_identifier: foo_id + - binary_operator: AND + - column_reference: + - naked_identifier: baz + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''c''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_aggregate.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_aggregate.sql new file mode 100644 index 000000000..fd3cd0525 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_aggregate.sql @@ -0,0 +1,5 @@ +DROP AGGREGATE myavg(integer), myavg(bigint); + +DROP AGGREGATE myrank(VARIADIC "any" ORDER BY VARIADIC "any"); + +DROP AGGREGATE myavg(integer); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_aggregate.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_aggregate.yml new file mode 100644 index 000000000..e5b03826f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_aggregate.yml @@ -0,0 +1,52 @@ +file: +- statement: + - drop_aggregate_statement: + - keyword: DROP + - keyword: AGGREGATE + - object_reference: + - naked_identifier: myavg + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: integer + - end_bracket: ) + - comma: ',' + - object_reference: + - naked_identifier: myavg + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: bigint + - end_bracket: ) +- statement_terminator: ; +- statement: + - drop_aggregate_statement: + - keyword: DROP + - keyword: AGGREGATE + - object_reference: + - naked_identifier: myrank + - bracketed: + - start_bracket: ( + - word: VARIADIC + - double_quote: '"any"' + - word: ORDER + - word: BY + - word: VARIADIC + - double_quote: '"any"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - drop_aggregate_statement: + - keyword: DROP + - keyword: AGGREGATE + - object_reference: + - naked_identifier: myavg + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: integer + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_collation.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_collation.sql new file mode 100644 index 000000000..dca5b027e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_collation.sql @@ -0,0 +1,7 @@ +DROP COLLATION case_insensitive; + +DROP COLLATION IF EXISTS german; + +DROP COLLATION german CASCADE; + +DROP COLLATION german RESTRICT; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_collation.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_collation.yml new file mode 100644 index 000000000..25ee2662f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_collation.yml @@ -0,0 +1,33 @@ +file: +- statement: + - drop_collation_statement: + - keyword: DROP + - keyword: COLLATION + - object_reference: + - naked_identifier: case_insensitive +- statement_terminator: ; +- statement: + - drop_collation_statement: + - keyword: DROP + - keyword: COLLATION + - keyword: IF + - keyword: EXISTS + - object_reference: + - naked_identifier: german +- statement_terminator: ; +- statement: + - drop_collation_statement: + - keyword: DROP + - keyword: COLLATION + - object_reference: + - naked_identifier: german + - keyword: CASCADE +- statement_terminator: ; +- statement: + - drop_collation_statement: + - keyword: DROP + - keyword: COLLATION + - object_reference: + - naked_identifier: german + - keyword: RESTRICT +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_foreign_table.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_foreign_table.sql new file mode 100644 index 000000000..a7b4fa4b1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_foreign_table.sql @@ -0,0 +1,9 @@ +drop foreign table test; + +drop foreign table films, distributors; + +drop foreign table if exists test; + +drop foreign table if exists test cascade; + +drop foreign table if exists test restrict; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_foreign_table.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_foreign_table.yml new file mode 100644 index 000000000..d6c331824 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_foreign_table.yml @@ -0,0 +1,52 @@ +file: +- statement: + - drop_foreign_table_statement: + - keyword: drop + - keyword: foreign + - keyword: table + - table_reference: + - naked_identifier: test +- statement_terminator: ; +- statement: + - drop_foreign_table_statement: + - keyword: drop + - keyword: foreign + - keyword: table + - table_reference: + - naked_identifier: films + - comma: ',' + - table_reference: + - naked_identifier: distributors +- statement_terminator: ; +- statement: + - drop_foreign_table_statement: + - keyword: drop + - keyword: foreign + - keyword: table + - keyword: if + - keyword: exists + - table_reference: + - naked_identifier: test +- statement_terminator: ; +- statement: + - drop_foreign_table_statement: + - keyword: drop + - keyword: foreign + - keyword: table + - keyword: if + - keyword: exists + - table_reference: + - naked_identifier: test + - keyword: cascade +- statement_terminator: ; +- statement: + - drop_foreign_table_statement: + - keyword: drop + - keyword: foreign + - keyword: table + - keyword: if + - keyword: exists + - table_reference: + - naked_identifier: test + - keyword: restrict +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_function.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_function.sql index 848776d51..6ae1538e8 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_function.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_function.sql @@ -1,5 +1,6 @@ -DROP FUNCTION sqrt(integer); -DROP FUNCTION sqrt(integer), sqrt(bigint); +DROP FUNCTION sqrt (integer); +DROP FUNCTION sqrt (integer), sqrt (bigint); DROP FUNCTION update_employee_salaries; -DROP FUNCTION update_employee_salaries(); +DROP FUNCTION update_employee_salaries (); DROP FUNCTION IF EXISTS foo (IN my_var integer, VARIADIC my_var_2 text); +DROP FUNCTION IF EXISTS f_name CASCADE; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_function.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_function.yml index 73b5a6864..891e84947 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_function.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_function.yml @@ -3,8 +3,8 @@ file: - drop_function_statement: - keyword: DROP - keyword: FUNCTION - - function_name: - - function_name_identifier: sqrt + - object_reference: + - naked_identifier: sqrt - function_parameter_list: - bracketed: - start_bracket: ( @@ -16,8 +16,8 @@ file: - drop_function_statement: - keyword: DROP - keyword: FUNCTION - - function_name: - - function_name_identifier: sqrt + - object_reference: + - naked_identifier: sqrt - function_parameter_list: - bracketed: - start_bracket: ( @@ -25,8 +25,8 @@ file: - keyword: integer - end_bracket: ) - comma: ',' - - function_name: - - function_name_identifier: sqrt + - object_reference: + - naked_identifier: sqrt - function_parameter_list: - bracketed: - start_bracket: ( @@ -38,15 +38,15 @@ file: - drop_function_statement: - keyword: DROP - keyword: FUNCTION - - function_name: - - function_name_identifier: update_employee_salaries + - object_reference: + - naked_identifier: update_employee_salaries - statement_terminator: ; - statement: - drop_function_statement: - keyword: DROP - keyword: FUNCTION - - function_name: - - function_name_identifier: update_employee_salaries + - object_reference: + - naked_identifier: update_employee_salaries - function_parameter_list: - bracketed: - start_bracket: ( @@ -58,8 +58,8 @@ file: - keyword: FUNCTION - keyword: IF - keyword: EXISTS - - function_name: - - function_name_identifier: foo + - object_reference: + - naked_identifier: foo - function_parameter_list: - bracketed: - start_bracket: ( @@ -74,3 +74,13 @@ file: - keyword: text - end_bracket: ) - statement_terminator: ; +- statement: + - drop_function_statement: + - keyword: DROP + - keyword: FUNCTION + - keyword: IF + - keyword: EXISTS + - object_reference: + - naked_identifier: f_name + - keyword: CASCADE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_index.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_index.yml index 940b1e319..da873c3be 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_index.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_index.yml @@ -3,14 +3,14 @@ file: - drop_index_statement: - keyword: DROP - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: abc - statement_terminator: ; - statement: - drop_index_statement: - keyword: DROP - keyword: INDEX - - database_reference: + - index_reference: - quoted_identifier: '"abc"' - statement_terminator: ; - statement: @@ -19,20 +19,20 @@ file: - keyword: INDEX - keyword: IF - keyword: EXISTS - - database_reference: + - index_reference: - naked_identifier: abc - statement_terminator: ; - statement: - drop_index_statement: - keyword: DROP - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: abc - comma: ',' - - database_reference: + - index_reference: - quoted_identifier: '"def"' - comma: ',' - - database_reference: + - index_reference: - naked_identifier: ghi - statement_terminator: ; - statement: @@ -41,20 +41,20 @@ file: - keyword: INDEX - keyword: IF - keyword: EXISTS - - database_reference: + - index_reference: - naked_identifier: abc - comma: ',' - - database_reference: + - index_reference: - naked_identifier: def - comma: ',' - - database_reference: + - index_reference: - naked_identifier: ghi - statement_terminator: ; - statement: - drop_index_statement: - keyword: DROP - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: abc - keyword: CASCADE - statement_terminator: ; @@ -62,13 +62,13 @@ file: - drop_index_statement: - keyword: DROP - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: abc - comma: ',' - - database_reference: + - index_reference: - naked_identifier: def - comma: ',' - - database_reference: + - index_reference: - naked_identifier: ghi - keyword: CASCADE - statement_terminator: ; @@ -78,13 +78,13 @@ file: - keyword: INDEX - keyword: IF - keyword: EXISTS - - database_reference: + - index_reference: - naked_identifier: abc - comma: ',' - - database_reference: + - index_reference: - naked_identifier: def - comma: ',' - - database_reference: + - index_reference: - naked_identifier: ghi - keyword: CASCADE - statement_terminator: ; @@ -92,7 +92,7 @@ file: - drop_index_statement: - keyword: DROP - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: abc - keyword: RESTRICT - statement_terminator: ; @@ -100,13 +100,13 @@ file: - drop_index_statement: - keyword: DROP - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: abc - comma: ',' - - database_reference: + - index_reference: - naked_identifier: def - comma: ',' - - database_reference: + - index_reference: - naked_identifier: ghi - keyword: RESTRICT - statement_terminator: ; @@ -115,7 +115,7 @@ file: - keyword: DROP - keyword: INDEX - keyword: CONCURRENTLY - - database_reference: + - index_reference: - naked_identifier: abc - statement_terminator: ; - statement: @@ -125,7 +125,7 @@ file: - keyword: CONCURRENTLY - keyword: IF - keyword: EXISTS - - database_reference: + - index_reference: - naked_identifier: abc - statement_terminator: ; - statement: @@ -133,10 +133,10 @@ file: - keyword: DROP - keyword: INDEX - keyword: CONCURRENTLY - - database_reference: + - index_reference: - naked_identifier: abc - comma: ',' - - database_reference: + - index_reference: - naked_identifier: def - statement_terminator: ; - statement: @@ -146,10 +146,10 @@ file: - keyword: CONCURRENTLY - keyword: IF - keyword: EXISTS - - database_reference: + - index_reference: - naked_identifier: abc - comma: ',' - - database_reference: + - index_reference: - naked_identifier: def - statement_terminator: ; - statement: @@ -157,10 +157,10 @@ file: - keyword: DROP - keyword: INDEX - keyword: CONCURRENTLY - - database_reference: + - index_reference: - naked_identifier: abc - comma: ',' - - database_reference: + - index_reference: - naked_identifier: def - keyword: CASCADE - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_sequence.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_sequence.yml index 0bce81577..95933b147 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_sequence.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_sequence.yml @@ -3,14 +3,14 @@ file: - drop_sequence_statement: - keyword: DROP - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - statement_terminator: ; - statement: - drop_sequence_statement: - keyword: DROP - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - dot: . - naked_identifier: foo @@ -21,7 +21,7 @@ file: - keyword: SEQUENCE - keyword: IF - keyword: EXISTS - - column_reference: + - sequence_reference: - naked_identifier: foo - statement_terminator: ; - statement: @@ -30,7 +30,7 @@ file: - keyword: SEQUENCE - keyword: IF - keyword: EXISTS - - column_reference: + - sequence_reference: - naked_identifier: foo - keyword: CASCADE - statement_terminator: ; @@ -38,7 +38,7 @@ file: - drop_sequence_statement: - keyword: DROP - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: foo - keyword: RESTRICT - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_statistics.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_statistics.yml index 444c5e8d8..3081dfce9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_statistics.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_statistics.yml @@ -1,30 +1,33 @@ file: - statement: - - keyword: DROP - - keyword: STATISTICS - - keyword: IF - - keyword: EXISTS - - object_reference: - - naked_identifier: accounting - - dot: . - - naked_identifier: users_uid_creation - - comma: ',' - - object_reference: - - naked_identifier: public - - dot: . - - naked_identifier: grants_user_role + - drop_statistics_statement: + - keyword: DROP + - keyword: STATISTICS + - keyword: IF + - keyword: EXISTS + - statistics_reference: + - naked_identifier: accounting + - dot: . + - naked_identifier: users_uid_creation + - comma: ',' + - statistics_reference: + - naked_identifier: public + - dot: . + - naked_identifier: grants_user_role - statement_terminator: ; - statement: - - keyword: DROP - - keyword: STATISTICS - - object_reference: - - naked_identifier: foo - - keyword: CASCADE + - drop_statistics_statement: + - keyword: DROP + - keyword: STATISTICS + - statistics_reference: + - naked_identifier: foo + - keyword: CASCADE - statement_terminator: ; - statement: - - keyword: DROP - - keyword: STATISTICS - - object_reference: - - naked_identifier: bar - - keyword: RESTRICT + - drop_statistics_statement: + - keyword: DROP + - keyword: STATISTICS + - statistics_reference: + - naked_identifier: bar + - keyword: RESTRICT - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_subscription.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_subscription.sql new file mode 100644 index 000000000..7eb1e87d6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_subscription.sql @@ -0,0 +1,4 @@ +DROP SUBSCRIPTION mysub; +DROP SUBSCRIPTION IF EXISTS mysub; +DROP SUBSCRIPTION mysub CASCADE; +DROP SUBSCRIPTION mysub RESTRICT; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_subscription.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_subscription.yml new file mode 100644 index 000000000..18f161fbb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_subscription.yml @@ -0,0 +1,33 @@ +file: +- statement: + - drop_subscription: + - keyword: DROP + - keyword: SUBSCRIPTION + - subscription_reference: + - naked_identifier: mysub +- statement_terminator: ; +- statement: + - drop_subscription: + - keyword: DROP + - keyword: SUBSCRIPTION + - keyword: IF + - keyword: EXISTS + - subscription_reference: + - naked_identifier: mysub +- statement_terminator: ; +- statement: + - drop_subscription: + - keyword: DROP + - keyword: SUBSCRIPTION + - subscription_reference: + - naked_identifier: mysub + - keyword: CASCADE +- statement_terminator: ; +- statement: + - drop_subscription: + - keyword: DROP + - keyword: SUBSCRIPTION + - subscription_reference: + - naked_identifier: mysub + - keyword: RESTRICT +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_text_search_configuration.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_text_search_configuration.sql new file mode 100644 index 000000000..4efffdcbb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_text_search_configuration.sql @@ -0,0 +1,4 @@ +DROP TEXT SEARCH CONFIGURATION my_config; +DROP TEXT SEARCH CONFIGURATION IF EXISTS my_config; +DROP TEXT SEARCH CONFIGURATION public.my_config CASCADE; +DROP TEXT SEARCH CONFIGURATION my_config RESTRICT; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_text_search_configuration.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_text_search_configuration.yml new file mode 100644 index 000000000..e65d32ddc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/drop_text_search_configuration.yml @@ -0,0 +1,43 @@ +file: +- statement: + - drop_text_search_configuration_statement: + - keyword: DROP + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - object_reference: + - naked_identifier: my_config +- statement_terminator: ; +- statement: + - drop_text_search_configuration_statement: + - keyword: DROP + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - keyword: IF + - keyword: EXISTS + - object_reference: + - naked_identifier: my_config +- statement_terminator: ; +- statement: + - drop_text_search_configuration_statement: + - keyword: DROP + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - object_reference: + - naked_identifier: public + - dot: . + - naked_identifier: my_config + - keyword: CASCADE +- statement_terminator: ; +- statement: + - drop_text_search_configuration_statement: + - keyword: DROP + - keyword: TEXT + - keyword: SEARCH + - keyword: CONFIGURATION + - object_reference: + - naked_identifier: my_config + - keyword: RESTRICT +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/execute.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/execute.sql new file mode 100644 index 000000000..0f5ffc07c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/execute.sql @@ -0,0 +1,5 @@ +EXECUTE statement_name; + +EXECUTE statement_name (1); + +EXECUTE statement_name (1, 'foo'); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/execute.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/execute.yml new file mode 100644 index 000000000..5be0f4b61 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/execute.yml @@ -0,0 +1,32 @@ +file: +- statement: + - execute_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: statement_name +- statement_terminator: ; +- statement: + - execute_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: statement_name + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - end_bracket: ) +- statement_terminator: ; +- statement: + - execute_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: statement_name + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - quoted_literal: '''foo''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/filter.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/filter.yml index 4597aa73a..d9cba78e5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/filter.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/filter.yml @@ -24,7 +24,8 @@ file: - bare_function: CURRENT_TIMESTAMP - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: c_active - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/full_text_search.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/full_text_search.sql new file mode 100644 index 000000000..1ff7f9705 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/full_text_search.sql @@ -0,0 +1,31 @@ +SELECT 'a fat cat sat on a mat and ate a fat rat'::tsvector @@ 'cat & rat'::tsquery; + +SELECT 'fat & cow'::tsquery @@ 'a fat cat sat on a mat and ate a fat rat'::tsvector; + +SELECT to_tsvector('fat cats ate fat rats') @@ to_tsquery('fat & rat'); + +SELECT 'fat cats ate fat rats'::tsvector @@ to_tsquery('fat & rat'); + +SELECT 'fat cats ate fat rats'::tsvector @@ to_tsquery('fat & rat'); + +SELECT to_tsvector('error is not fatal') @@ to_tsquery('fatal <-> error'); + +SELECT phraseto_tsquery('cats ate rats'); + +SELECT phraseto_tsquery('the cats ate the rats'); + +SELECT 'a:1 b:2'::tsvector || 'c:1 d:2 b:3'::tsvector; + +SELECT 'fat | rat'::tsquery && 'cat'::tsquery; + +SELECT 'fat | rat'::tsquery || 'cat'::tsquery; + +SELECT to_tsquery('fat') <-> to_tsquery('rat'); + +SELECT 'cat'::tsquery @> 'cat & rat'::tsquery; + +SELECT 'cat'::tsquery <@ 'cat & rat'::tsquery; + +SELECT 'cat'::tsquery <@ '!cat & rat'::tsquery; + +SELECT !! 'cat'::tsquery; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/full_text_search.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/full_text_search.yml new file mode 100644 index 000000000..8b4b064e1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/full_text_search.yml @@ -0,0 +1,316 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''a fat cat sat on a mat and ate a fat rat''' + - casting_operator: '::' + - data_type: + - keyword: tsvector + - binary_operator: '@@' + - cast_expression: + - quoted_literal: '''cat & rat''' + - casting_operator: '::' + - data_type: + - keyword: tsquery +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''fat & cow''' + - casting_operator: '::' + - data_type: + - keyword: tsquery + - binary_operator: '@@' + - cast_expression: + - quoted_literal: '''a fat cat sat on a mat and ate a fat rat''' + - casting_operator: '::' + - data_type: + - keyword: tsvector +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - function: + - function_name: + - function_name_identifier: to_tsvector + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''fat cats ate fat rats''' + - end_bracket: ) + - binary_operator: '@@' + - function: + - function_name: + - function_name_identifier: to_tsquery + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''fat & rat''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''fat cats ate fat rats''' + - casting_operator: '::' + - data_type: + - keyword: tsvector + - binary_operator: '@@' + - function: + - function_name: + - function_name_identifier: to_tsquery + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''fat & rat''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''fat cats ate fat rats''' + - casting_operator: '::' + - data_type: + - keyword: tsvector + - binary_operator: '@@' + - function: + - function_name: + - function_name_identifier: to_tsquery + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''fat & rat''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - function: + - function_name: + - function_name_identifier: to_tsvector + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''error is not fatal''' + - end_bracket: ) + - binary_operator: '@@' + - function: + - function_name: + - function_name_identifier: to_tsquery + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''fatal <-> error''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: phraseto_tsquery + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''cats ate rats''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: phraseto_tsquery + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''the cats ate the rats''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''a:1 b:2''' + - casting_operator: '::' + - data_type: + - keyword: tsvector + - binary_operator: + - pipe: '|' + - pipe: '|' + - cast_expression: + - quoted_literal: '''c:1 d:2 b:3''' + - casting_operator: '::' + - data_type: + - keyword: tsvector +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''fat | rat''' + - casting_operator: '::' + - data_type: + - keyword: tsquery + - comparison_operator: + - ampersand: '&' + - ampersand: '&' + - cast_expression: + - quoted_literal: '''cat''' + - casting_operator: '::' + - data_type: + - keyword: tsquery +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''fat | rat''' + - casting_operator: '::' + - data_type: + - keyword: tsquery + - binary_operator: + - pipe: '|' + - pipe: '|' + - cast_expression: + - quoted_literal: '''cat''' + - casting_operator: '::' + - data_type: + - keyword: tsquery +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - function: + - function_name: + - function_name_identifier: to_tsquery + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''fat''' + - end_bracket: ) + - binary_operator: <-> + - function: + - function_name: + - function_name_identifier: to_tsquery + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''rat''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''cat''' + - casting_operator: '::' + - data_type: + - keyword: tsquery + - binary_operator: '@>' + - cast_expression: + - quoted_literal: '''cat & rat''' + - casting_operator: '::' + - data_type: + - keyword: tsquery +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''cat''' + - casting_operator: '::' + - data_type: + - keyword: tsquery + - binary_operator: <@ + - cast_expression: + - quoted_literal: '''cat & rat''' + - casting_operator: '::' + - data_type: + - keyword: tsquery +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''cat''' + - casting_operator: '::' + - data_type: + - keyword: tsquery + - binary_operator: <@ + - cast_expression: + - quoted_literal: '''!cat & rat''' + - casting_operator: '::' + - data_type: + - keyword: tsquery +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - full_text_search_operator: '!!' + - cast_expression: + - quoted_literal: '''cat''' + - casting_operator: '::' + - data_type: + - keyword: tsquery +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_privileges.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_privileges.sql index 87949bbb1..9d23b213c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_privileges.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_privileges.sql @@ -22,3 +22,5 @@ GRANT CONNECT, CREATE, TEMP, TEMPORARY ON DATABASE my_db TO xyz; GRANT CONNECT, CREATE, TEMP, TEMPORARY ON DATABASE my_db TO my_user, my_other_user WITH GRANT OPTION; GRANT SELECT ON abc TO xyz, mno; GRANT EXECUTE ON ALL ROUTINES IN SCHEMA my_schema TO my_user, my_other_user; +GRANT EXECUTE ON FUNCTION test(a IN TEXT, b OUT TEXT, INOUT c TEXT, VARIADIC d TEXT) TO my_user; +GRANT EXECUTE ON FUNCTION test(a TEXT, b my_table.my_column%type) TO my_user; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_privileges.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_privileges.yml index 1fd6b094c..c90ad512d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_privileges.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_privileges.yml @@ -340,3 +340,66 @@ file: - role_reference: - naked_identifier: my_other_user - statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: EXECUTE + - keyword: ON + - keyword: FUNCTION + - function_name: + - function_name_identifier: test + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: a + - keyword: IN + - data_type: + - keyword: TEXT + - comma: ',' + - parameter: b + - keyword: OUT + - data_type: + - keyword: TEXT + - comma: ',' + - keyword: INOUT + - parameter: c + - data_type: + - keyword: TEXT + - comma: ',' + - keyword: VARIADIC + - parameter: d + - data_type: + - keyword: TEXT + - end_bracket: ) + - keyword: TO + - role_reference: + - naked_identifier: my_user +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: EXECUTE + - keyword: ON + - keyword: FUNCTION + - function_name: + - function_name_identifier: test + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: a + - data_type: + - keyword: TEXT + - comma: ',' + - parameter: b + - column_type_reference: + - column_reference: + - naked_identifier: my_table + - dot: . + - naked_identifier: my_column + - binary_operator: '%' + - keyword: type + - end_bracket: ) + - keyword: TO + - role_reference: + - naked_identifier: my_user +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_role.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_role.sql deleted file mode 100644 index b235071d5..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_role.sql +++ /dev/null @@ -1,2 +0,0 @@ -grant some_role to a_user with admin true; -grant some_role to a_user with admin false; \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_role.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_role.yml deleted file mode 100644 index 14d8ab53b..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/grant_role.yml +++ /dev/null @@ -1,25 +0,0 @@ -file: -- statement: - - access_statement: - - keyword: grant - - object_reference: - - naked_identifier: some_role - - keyword: to - - role_reference: - - naked_identifier: a_user - - keyword: with - - keyword: admin - - boolean_literal: 'true' -- statement_terminator: ; -- statement: - - access_statement: - - keyword: grant - - object_reference: - - naked_identifier: some_role - - keyword: to - - role_reference: - - naked_identifier: a_user - - keyword: with - - keyword: admin - - boolean_literal: 'false' -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/group_by.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/group_by.yml index 13b7a35ec..a05a3974c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/group_by.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/group_by.yml @@ -27,7 +27,8 @@ file: - naked_identifier: city - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: grp_idx - comma: ',' - select_clause_element: @@ -43,7 +44,8 @@ file: - naked_identifier: id - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: num_total - comma: ',' - select_clause_element: @@ -67,7 +69,8 @@ file: - naked_identifier: is_poi - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: num_poi - comma: ',' - select_clause_element: @@ -91,7 +94,8 @@ file: - naked_identifier: is_gov - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: num_gov - from_clause: - keyword: FROM @@ -169,7 +173,8 @@ file: - naked_identifier: city - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: grp_idx - comma: ',' - select_clause_element: @@ -185,7 +190,8 @@ file: - naked_identifier: id - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: num_total - comma: ',' - select_clause_element: @@ -209,7 +215,8 @@ file: - naked_identifier: is_poi - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: num_poi - comma: ',' - select_clause_element: @@ -233,7 +240,8 @@ file: - naked_identifier: is_gov - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: num_gov - from_clause: - keyword: FROM @@ -296,7 +304,8 @@ file: - naked_identifier: city - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: grp_idx - comma: ',' - select_clause_element: @@ -312,7 +321,8 @@ file: - naked_identifier: id - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: num_total - comma: ',' - select_clause_element: @@ -336,7 +346,8 @@ file: - naked_identifier: is_poi - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: num_poi - comma: ',' - select_clause_element: @@ -360,7 +371,8 @@ file: - naked_identifier: is_gov - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: num_gov - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/import_foreign_schema.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/import_foreign_schema.yml index 80059eb03..30298566e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/import_foreign_schema.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/import_foreign_schema.yml @@ -4,57 +4,51 @@ file: - keyword: IMPORT - keyword: FOREIGN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: foreign_films + - schema_reference: + - naked_identifier: foreign_films - keyword: FROM - keyword: SERVER - server_reference: - naked_identifier: film_server - keyword: INTO - - table_reference: - - object_reference: - - naked_identifier: films + - schema_reference: + - naked_identifier: films - statement_terminator: ; - statement: - import_foreign_schema_statement: - keyword: IMPORT - keyword: FOREIGN - keyword: SCHEMA - - table_reference: - - object_reference: - - quoted_identifier: '"TEST"' + - schema_reference: + - quoted_identifier: '"TEST"' - keyword: FROM - keyword: SERVER - server_reference: - naked_identifier: test_server - keyword: INTO - - table_reference: - - object_reference: - - naked_identifier: test + - schema_reference: + - naked_identifier: test - statement_terminator: ; - statement: - import_foreign_schema_statement: - keyword: IMPORT - keyword: FOREIGN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: foreign_films + - schema_reference: + - naked_identifier: foreign_films - keyword: LIMIT - keyword: TO - bracketed: - start_bracket: ( - - naked_identifier: actors + - naked_identifier_all: actors - comma: ',' - - naked_identifier: directors + - naked_identifier_all: directors - end_bracket: ) - keyword: FROM - keyword: SERVER - server_reference: - naked_identifier: film_server - keyword: INTO - - table_reference: - - object_reference: - - naked_identifier: films + - schema_reference: + - naked_identifier: films - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/insert.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/insert.sql index 476e35e75..b443410e2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/insert.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/insert.sql @@ -64,3 +64,36 @@ INSERT INTO abc (foo, bar) SELECT foo, bar FROM baz RETURNING quux ; + +INSERT INTO tbl_a ( + val1 + , val2 +) +SELECT val1 + , val2 +FROM tbl_2 +ON CONFLICT ( + val1 + , COALESCE(val2, '') +) +DO NOTHING; + +INSERT INTO prompt_variants ( + test, + test2 +) +SELECT + test, + test2 +RETURNING + test, + test2; + +INSERT INTO + baz (state, state_changed_at, instance_id) +SELECT + 1, 2, 3 +ON CONFLICT (instance_id) DO UPDATE +SET + state = foo, + state_changed_at = bar; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/insert.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/insert.yml index 95d54c589..26847128f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/insert.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/insert.yml @@ -113,7 +113,8 @@ file: - table_reference: - naked_identifier: distributors - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: d - bracketed: - start_bracket: ( @@ -300,7 +301,8 @@ file: - column_reference: - naked_identifier: bar - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: some_alias - statement_terminator: ; - statement: @@ -365,14 +367,16 @@ file: - column_reference: - naked_identifier: bar - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: alias1 - comma: ',' - expression: - column_reference: - naked_identifier: baz - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: alias2 - statement_terminator: ; - statement: @@ -464,7 +468,8 @@ file: - table_reference: - naked_identifier: foo - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: f - bracketed: - start_bracket: ( @@ -708,7 +713,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: tmp - bracketed: - start_bracket: ( @@ -733,7 +739,8 @@ file: - table_reference: - naked_identifier: megatable - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: mt - where_clause: - keyword: WHERE @@ -791,3 +798,149 @@ file: - column_reference: - naked_identifier: quux - statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: tbl_a + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: val1 + - comma: ',' + - column_reference: + - naked_identifier: val2 + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: val1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: val2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl_2 + - keyword: ON + - keyword: CONFLICT + - conflict_target: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: val1 + - comma: ',' + - function: + - function_name: + - function_name_identifier: COALESCE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: val2 + - comma: ',' + - expression: + - quoted_literal: '''''' + - end_bracket: ) + - end_bracket: ) + - conflict_action: + - keyword: DO + - keyword: NOTHING +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: prompt_variants + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: test + - comma: ',' + - column_reference: + - naked_identifier: test2 + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: test + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: test2 + - keyword: RETURNING + - expression: + - column_reference: + - naked_identifier: test + - comma: ',' + - expression: + - column_reference: + - naked_identifier: test2 +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: baz + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: state + - comma: ',' + - column_reference: + - naked_identifier: state_changed_at + - comma: ',' + - column_reference: + - naked_identifier: instance_id + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - comma: ',' + - select_clause_element: + - numeric_literal: '3' + - keyword: ON + - keyword: CONFLICT + - conflict_target: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: instance_id + - end_bracket: ) + - conflict_action: + - keyword: DO + - keyword: UPDATE + - keyword: SET + - column_reference: + - naked_identifier: state + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: foo + - comma: ',' + - column_reference: + - naked_identifier: state_changed_at + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: bar +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_json.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_json.sql new file mode 100644 index 000000000..3eeef0e06 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_json.sql @@ -0,0 +1,51 @@ +-- PostgreSQL 16 IS JSON syntax tests +-- Based on: https://www.postgresql.org/docs/16/functions-json.html#FUNCTIONS-SQLJSON-MISC + +-- Basic IS JSON syntax +SELECT '{}' IS JSON; +SELECT '[]' IS JSON; +SELECT '"test"' IS JSON; +SELECT 'invalid' IS JSON; + +-- IS NOT JSON syntax +SELECT 'invalid' IS NOT JSON; +SELECT '{}' IS NOT JSON; + +-- IS JSON with type specification +SELECT '{}' IS JSON OBJECT; +SELECT '[]' IS JSON ARRAY; +SELECT '"test"' IS JSON SCALAR; +SELECT '{"a": 1}' IS JSON VALUE; + +-- IS NOT JSON with type specification +SELECT '"test"' IS NOT JSON OBJECT; +SELECT '{}' IS NOT JSON ARRAY; +SELECT '[]' IS NOT JSON SCALAR; +SELECT 'invalid' IS NOT JSON VALUE; + +-- IS JSON with UNIQUE KEYS +SELECT '{"a": 1, "b": 2}' IS JSON WITH UNIQUE KEYS; +SELECT '{"a": 1, "a": 2}' IS JSON WITH UNIQUE KEYS; +SELECT '{"a": 1, "b": 2}' IS JSON WITHOUT UNIQUE KEYS; + +-- IS JSON with type and unique keys +SELECT '{"a": 1, "b": 2}' IS JSON OBJECT WITH UNIQUE KEYS; +SELECT '{"a": 1, "a": 2}' IS JSON OBJECT WITH UNIQUE KEYS; +SELECT '{"a": 1, "b": 2}' IS JSON OBJECT WITHOUT UNIQUE KEYS; + +-- IS NOT JSON with type and unique keys +SELECT '[]' IS NOT JSON OBJECT WITH UNIQUE KEYS; +SELECT '[1, 2]' IS NOT JSON OBJECT WITHOUT UNIQUE KEYS; + +-- Complex expressions with IS JSON +SELECT col1 IS JSON, col2 IS NOT JSON ARRAY FROM table1; +SELECT CASE WHEN data IS JSON OBJECT THEN 'valid' ELSE 'invalid' END FROM table1; + +-- IS JSON in WHERE clauses +SELECT * FROM table1 WHERE data IS JSON; +SELECT * FROM table1 WHERE config IS NOT JSON OBJECT; +SELECT * FROM table1 WHERE metadata IS JSON WITH UNIQUE KEYS; + +-- IS JSON with column expressions +SELECT (column_name::text) IS JSON FROM table1; +SELECT COALESCE(data, '{}') IS JSON OBJECT FROM table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_json.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_json.yml new file mode 100644 index 000000000..1b823d098 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_json.yml @@ -0,0 +1,455 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{}''' + - keyword: IS + - keyword: JSON +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''[]''' + - keyword: IS + - keyword: JSON +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''"test"''' + - keyword: IS + - keyword: JSON +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''invalid''' + - keyword: IS + - keyword: JSON +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''invalid''' + - keyword: IS + - keyword: NOT + - keyword: JSON +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{}''' + - keyword: IS + - keyword: NOT + - keyword: JSON +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{}''' + - keyword: IS + - keyword: JSON + - keyword: OBJECT +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''[]''' + - keyword: IS + - keyword: JSON + - keyword: ARRAY +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''"test"''' + - keyword: IS + - keyword: JSON + - keyword: SCALAR +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a": 1}''' + - keyword: IS + - keyword: JSON + - keyword: VALUE +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''"test"''' + - keyword: IS + - keyword: NOT + - keyword: JSON + - keyword: OBJECT +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{}''' + - keyword: IS + - keyword: NOT + - keyword: JSON + - keyword: ARRAY +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''[]''' + - keyword: IS + - keyword: NOT + - keyword: JSON + - keyword: SCALAR +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''invalid''' + - keyword: IS + - keyword: NOT + - keyword: JSON + - keyword: VALUE +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a": 1, "b": 2}''' + - keyword: IS + - keyword: JSON + - keyword: WITH + - keyword: UNIQUE + - keyword: KEYS +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a": 1, "a": 2}''' + - keyword: IS + - keyword: JSON + - keyword: WITH + - keyword: UNIQUE + - keyword: KEYS +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a": 1, "b": 2}''' + - keyword: IS + - keyword: JSON + - keyword: WITHOUT + - keyword: UNIQUE + - keyword: KEYS +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a": 1, "b": 2}''' + - keyword: IS + - keyword: JSON + - keyword: OBJECT + - keyword: WITH + - keyword: UNIQUE + - keyword: KEYS +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a": 1, "a": 2}''' + - keyword: IS + - keyword: JSON + - keyword: OBJECT + - keyword: WITH + - keyword: UNIQUE + - keyword: KEYS +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a": 1, "b": 2}''' + - keyword: IS + - keyword: JSON + - keyword: OBJECT + - keyword: WITHOUT + - keyword: UNIQUE + - keyword: KEYS +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''[]''' + - keyword: IS + - keyword: NOT + - keyword: JSON + - keyword: OBJECT + - keyword: WITH + - keyword: UNIQUE + - keyword: KEYS +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''[1, 2]''' + - keyword: IS + - keyword: NOT + - keyword: JSON + - keyword: OBJECT + - keyword: WITHOUT + - keyword: UNIQUE + - keyword: KEYS +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: col1 + - keyword: IS + - keyword: JSON + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: col2 + - keyword: IS + - keyword: NOT + - keyword: JSON + - keyword: ARRAY + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: data + - keyword: IS + - keyword: JSON + - keyword: OBJECT + - keyword: THEN + - expression: + - quoted_literal: '''valid''' + - else_clause: + - keyword: ELSE + - expression: + - quoted_literal: '''invalid''' + - keyword: END + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: data + - keyword: IS + - keyword: JSON +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: config + - keyword: IS + - keyword: NOT + - keyword: JSON + - keyword: OBJECT +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: metadata + - keyword: IS + - keyword: JSON + - keyword: WITH + - keyword: UNIQUE + - keyword: KEYS +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - cast_expression: + - column_reference: + - naked_identifier: column_name + - casting_operator: '::' + - data_type: + - keyword: text + - end_bracket: ) + - keyword: IS + - keyword: JSON + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - function: + - function_name: + - function_name_identifier: COALESCE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: data + - comma: ',' + - expression: + - quoted_literal: '''{}''' + - end_bracket: ) + - keyword: IS + - keyword: JSON + - keyword: OBJECT + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_unknown.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_unknown.sql new file mode 100644 index 000000000..8fe2b6cbe --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_unknown.sql @@ -0,0 +1,3 @@ +SELECT TRUE IS UNKNOWN; + +SELECT TRUE IS NOT UNKNOWN; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_unknown.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_unknown.yml new file mode 100644 index 000000000..a7627ee4e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/is_unknown.yml @@ -0,0 +1,22 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - boolean_literal: 'TRUE' + - keyword: IS + - null_literal: UNKNOWN +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - boolean_literal: 'TRUE' + - keyword: IS + - keyword: NOT + - null_literal: UNKNOWN +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/join_lateral.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/join_lateral.sql index 6d7d6e4e1..3cce469b8 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/join_lateral.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/join_lateral.sql @@ -2,10 +2,23 @@ select tbl1.id from tbl1 join tbl2 on tbl1.id = tbl2.id; -- ... but also with lateral joins -select tbl1.id from tbl1 join lateral tbl2 on tbl1.id = tbl2.id; +select tbl1.id from tbl1 join lateral (SELECT * FROM tbl2) AS foo ON tbl1.id = foo.id; -- ... and mixed ones as well! select tbl1.id from tbl1 -full outer join lateral tbl2 on tbl1.id = tbl2.id -cross join tbl3 on tbl1.id = tbl3.id -left join lateral tbl4 on tbl1.id = tbl4.id; +full outer join lateral (SELECT * FROM tbl2) AS tbl2 on tbl1.id = tbl2.id +cross join tbl3 +left join lateral (SELECT * FROM tbl4) AS tbl4 on tbl1.id = tbl4.id; + +-- lateral with comma cross join syntax +SELECT X.NUM, D.id FROM tbl1 AS D, LATERAL (values (0), (1)) AS X (NUM); + +-- lateral with function +SELECT m.name AS mname, pname +FROM manufacturers m, LATERAL get_product_names(m.id) pname; + +SELECT m.name AS mname, pname +FROM manufacturers m LEFT JOIN LATERAL get_product_names(m.id) pname ON true; + +SELECT X.NUM +FROM LATERAL (values (0), (1)) AS X (NUM); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/join_lateral.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/join_lateral.yml index ba0eaf06f..f9faf8a35 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/join_lateral.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/join_lateral.yml @@ -53,13 +53,32 @@ file: - naked_identifier: tbl1 - join_clause: - keyword: join - - keyword: lateral - from_expression_element: + - keyword: lateral - table_expression: - - table_reference: - - naked_identifier: tbl2 + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl2 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: foo - join_on_condition: - - keyword: on + - keyword: ON - expression: - column_reference: - naked_identifier: tbl1 @@ -68,7 +87,7 @@ file: - comparison_operator: - raw_comparison_operator: = - column_reference: - - naked_identifier: tbl2 + - naked_identifier: foo - dot: . - naked_identifier: id - statement_terminator: ; @@ -92,11 +111,30 @@ file: - keyword: full - keyword: outer - keyword: join - - keyword: lateral - from_expression_element: + - keyword: lateral - table_expression: - - table_reference: - - naked_identifier: tbl2 + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl2 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl2 - join_on_condition: - keyword: on - expression: @@ -117,27 +155,33 @@ file: - table_expression: - table_reference: - naked_identifier: tbl3 - - join_on_condition: - - keyword: on - - expression: - - column_reference: - - naked_identifier: tbl1 - - dot: . - - naked_identifier: id - - comparison_operator: - - raw_comparison_operator: = - - column_reference: - - naked_identifier: tbl3 - - dot: . - - naked_identifier: id - join_clause: - keyword: left - keyword: join - - keyword: lateral - from_expression_element: + - keyword: lateral - table_expression: - - table_reference: - - naked_identifier: tbl4 + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl4 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl4 - join_on_condition: - keyword: on - expression: @@ -152,3 +196,198 @@ file: - dot: . - naked_identifier: id - statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: X + - dot: . + - naked_identifier: NUM + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: D + - dot: . + - naked_identifier: id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: D + - comma: ',' + - from_expression: + - from_expression_element: + - keyword: LATERAL + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: values + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: X + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: NUM + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: m + - dot: . + - naked_identifier: name + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: mname + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: pname + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: manufacturers + - alias_expression: + - naked_identifier: m + - comma: ',' + - from_expression: + - from_expression_element: + - keyword: LATERAL + - table_expression: + - function: + - function_name: + - function_name_identifier: get_product_names + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: m + - dot: . + - naked_identifier: id + - end_bracket: ) + - alias_expression: + - naked_identifier: pname +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: m + - dot: . + - naked_identifier: name + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: mname + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: pname + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: manufacturers + - alias_expression: + - naked_identifier: m + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - keyword: LATERAL + - table_expression: + - function: + - function_name: + - function_name_identifier: get_product_names + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: m + - dot: . + - naked_identifier: id + - end_bracket: ) + - alias_expression: + - naked_identifier: pname + - join_on_condition: + - keyword: ON + - expression: + - boolean_literal: 'true' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: X + - dot: . + - naked_identifier: NUM + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - keyword: LATERAL + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: values + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: X + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: NUM + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_operators.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_operators.sql index 757c6d70f..ef7f13eac 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_operators.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_operators.sql @@ -15,3 +15,24 @@ SELECT '{"a":1,"b":2}'::json->>'b'; SELECT '{"a": {"b":{"c": "foo"}}}'::json#>'{a,b}'; -- Get JSON object at the specified path as text SELECT '{"a":[1,2,3],"b":[4,5,6]}'::json#>>'{a,2}'; + +SELECT + '{"a":1, "b":2}'::jsonb @> '{"b":2}'::jsonb, + '{"b":2}'::jsonb <@ '{"a":1, "b":2}'::jsonb, + '{"a":1, "b":2}'::jsonb ? 'b', + '{"a":1, "b":2, "c":3}'::jsonb ?| array['b', 'd'], + '["a", "b", "c"]'::jsonb ?& array['a', 'b'], + '["a", {"b":1}]'::jsonb #- '{1,b}', + '{"a":[1,2,3,4,5]}'::jsonb @? '$.a[*] ? (@ > 2)', + '{"a":[1,2,3,4,5]}'::jsonb @@ '$.a[*] > 2'; + +SELECT json_object('code' VALUE 'P123', 'title': 'Jaws'); + +SELECT json_object( + 'word': CASE + WHEN str = '1' THEN 'One' + WHEN str = '2' THEN 'Two' + ELSE 'Unknown' + END + ) AS json_column +FROM first_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_operators.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_operators.yml index d7ab69711..1c9a0b154 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_operators.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_operators.yml @@ -20,7 +20,8 @@ file: - quoted_literal: '''''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: field - from_clause: - keyword: FROM @@ -124,3 +125,192 @@ file: - binary_operator: '#>>' - quoted_literal: '''{a,2}''' - statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''{"a":1, "b":2}''' + - casting_operator: '::' + - data_type: + - keyword: jsonb + - binary_operator: '@>' + - cast_expression: + - quoted_literal: '''{"b":2}''' + - casting_operator: '::' + - data_type: + - keyword: jsonb + - comma: ',' + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''{"b":2}''' + - casting_operator: '::' + - data_type: + - keyword: jsonb + - binary_operator: <@ + - cast_expression: + - quoted_literal: '''{"a":1, "b":2}''' + - casting_operator: '::' + - data_type: + - keyword: jsonb + - comma: ',' + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''{"a":1, "b":2}''' + - casting_operator: '::' + - data_type: + - keyword: jsonb + - binary_operator: '?' + - quoted_literal: '''b''' + - comma: ',' + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''{"a":1, "b":2, "c":3}''' + - casting_operator: '::' + - data_type: + - keyword: jsonb + - binary_operator: ?| + - typed_array_literal: + - array_type: + - keyword: array + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''b''' + - comma: ',' + - quoted_literal: '''d''' + - end_square_bracket: ']' + - comma: ',' + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''["a", "b", "c"]''' + - casting_operator: '::' + - data_type: + - keyword: jsonb + - binary_operator: ?& + - typed_array_literal: + - array_type: + - keyword: array + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''a''' + - comma: ',' + - quoted_literal: '''b''' + - end_square_bracket: ']' + - comma: ',' + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''["a", {"b":1}]''' + - casting_operator: '::' + - data_type: + - keyword: jsonb + - binary_operator: '#-' + - quoted_literal: '''{1,b}''' + - comma: ',' + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''{"a":[1,2,3,4,5]}''' + - casting_operator: '::' + - data_type: + - keyword: jsonb + - binary_operator: '@?' + - quoted_literal: '''$.a[*] ? (@ > 2)''' + - comma: ',' + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''{"a":[1,2,3,4,5]}''' + - casting_operator: '::' + - data_type: + - keyword: jsonb + - binary_operator: '@@' + - quoted_literal: '''$.a[*] > 2''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_object + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''code''' + - keyword: VALUE + - expression: + - quoted_literal: '''P123''' + - comma: ',' + - expression: + - quoted_literal: '''title''' + - colon: ':' + - expression: + - quoted_literal: '''Jaws''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_object + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''word''' + - colon: ':' + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: str + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''1''' + - keyword: THEN + - expression: + - quoted_literal: '''One''' + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: str + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2''' + - keyword: THEN + - expression: + - quoted_literal: '''Two''' + - else_clause: + - keyword: ELSE + - expression: + - quoted_literal: '''Unknown''' + - keyword: END + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: json_column + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: first_table +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_serialize.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_serialize.sql new file mode 100644 index 000000000..85ffb7816 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_serialize.sql @@ -0,0 +1,6 @@ +SELECT json_serialize('"test"'::json RETURNING bytea); +SELECT json_serialize('"test"'::json RETURNING text); +SELECT json_serialize('"test"'::json); +SELECT json_serialize('{"key": "value"}'::json RETURNING bytea); +SELECT json_serialize('{"key": "value"}'::json RETURNING text); +SELECT json_serialize('{"key": "value"}'::json); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_serialize.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_serialize.yml new file mode 100644 index 000000000..54f46214c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_serialize.yml @@ -0,0 +1,127 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_serialize + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - cast_expression: + - quoted_literal: '''"test"''' + - casting_operator: '::' + - data_type: + - keyword: json + - keyword: RETURNING + - data_type: + - keyword: bytea + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_serialize + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - cast_expression: + - quoted_literal: '''"test"''' + - casting_operator: '::' + - data_type: + - keyword: json + - keyword: RETURNING + - data_type: + - keyword: text + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_serialize + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - cast_expression: + - quoted_literal: '''"test"''' + - casting_operator: '::' + - data_type: + - keyword: json + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_serialize + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - cast_expression: + - quoted_literal: '''{"key": "value"}''' + - casting_operator: '::' + - data_type: + - keyword: json + - keyword: RETURNING + - data_type: + - keyword: bytea + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_serialize + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - cast_expression: + - quoted_literal: '''{"key": "value"}''' + - casting_operator: '::' + - data_type: + - keyword: json + - keyword: RETURNING + - data_type: + - keyword: text + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_serialize + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - cast_expression: + - quoted_literal: '''{"key": "value"}''' + - casting_operator: '::' + - data_type: + - keyword: json + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_value.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_value.sql new file mode 100644 index 000000000..f5b9fa9eb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_value.sql @@ -0,0 +1,11 @@ +SELECT json_value(raw_data, '$."action_type"' RETURNING smallint); +SELECT json_value(raw_data, '$."name"' RETURNING text); +SELECT json_value(raw_data, '$."price"' RETURNING numeric); +SELECT json_value(raw_data, '$."active"' RETURNING boolean); +SELECT json_value(raw_data, '$."timestamp"' RETURNING timestamp); +SELECT json_value(raw_data, '$."id"'); +CREATE TABLE audit_log_entries ( + id bigint NOT NULL, + action_type smallint GENERATED ALWAYS AS (json_value(raw_data, '$."action_type"' RETURNING smallint)) STORED NOT NULL, + target_id bigint GENERATED ALWAYS AS (json_value(raw_data, '$."target_id"' RETURNING bigint)) STORED +); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_value.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_value.yml new file mode 100644 index 000000000..208339e78 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/json_value.yml @@ -0,0 +1,213 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_value + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: raw_data + - comma: ',' + - expression: + - quoted_literal: '''$."action_type"''' + - keyword: RETURNING + - data_type: + - keyword: smallint + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_value + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: raw_data + - comma: ',' + - expression: + - quoted_literal: '''$."name"''' + - keyword: RETURNING + - data_type: + - keyword: text + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_value + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: raw_data + - comma: ',' + - expression: + - quoted_literal: '''$."price"''' + - keyword: RETURNING + - data_type: + - keyword: numeric + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_value + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: raw_data + - comma: ',' + - expression: + - quoted_literal: '''$."active"''' + - keyword: RETURNING + - data_type: + - keyword: boolean + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_value + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: raw_data + - comma: ',' + - expression: + - quoted_literal: '''$."timestamp"''' + - keyword: RETURNING + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_value + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: raw_data + - comma: ',' + - expression: + - quoted_literal: '''$."id"''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: audit_log_entries + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - keyword: bigint + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: action_type + - data_type: + - keyword: smallint + - column_constraint_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - expression: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: json_value + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: raw_data + - comma: ',' + - expression: + - quoted_literal: '''$."action_type"''' + - keyword: RETURNING + - data_type: + - keyword: smallint + - end_bracket: ) + - end_bracket: ) + - keyword: STORED + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: target_id + - data_type: + - keyword: bigint + - column_constraint_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - expression: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: json_value + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: raw_data + - comma: ',' + - expression: + - quoted_literal: '''$."target_id"''' + - keyword: RETURNING + - data_type: + - keyword: bigint + - end_bracket: ) + - end_bracket: ) + - keyword: STORED + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/meta_commands_query_buffer.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/meta_commands_query_buffer.sql new file mode 100644 index 000000000..555263462 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/meta_commands_query_buffer.sql @@ -0,0 +1,23 @@ +SELECT format('create index on my_table(%I)', attname) +FROM pg_attribute +WHERE attrelid = 'my_table'::regclass AND attnum > 0 +ORDER BY attnum +\gexec + +SELECT 'hello' AS var1, 10 AS var2 +\gset + +SELECT 'hello' AS var1, 10 AS var2 +\gset result_ + +SELECT + EXISTS(SELECT 1 FROM customer WHERE customer_id = 123) as is_customer, + EXISTS(SELECT 1 FROM employee WHERE employee_id = 456) as is_employee +\gset + +SELECT 'hello' AS my_psql_var \gset +SELECT :'my_psql_var'; + +SELECT relname, relkind FROM pg_class LIMIT 1 \gset + +SELECT i FROM generate_series(1,2) i \gset prefix diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/meta_commands_query_buffer.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/meta_commands_query_buffer.yml new file mode 100644 index 000000000..75c56df0b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/meta_commands_query_buffer.yml @@ -0,0 +1,223 @@ +file: +- statement: + - meta_command_statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: format + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''create index on my_table(%I)''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: attname + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: pg_attribute + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: attrelid + - comparison_operator: + - raw_comparison_operator: = + - cast_expression: + - quoted_literal: '''my_table''' + - casting_operator: '::' + - data_type: + - data_type_identifier: regclass + - binary_operator: AND + - column_reference: + - naked_identifier: attnum + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: attnum + - meta_command: \gexec + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''hello''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: var1 + - comma: ',' + - select_clause_element: + - numeric_literal: '10' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: var2 + - meta_command: \gset + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''hello''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: var1 + - comma: ',' + - select_clause_element: + - numeric_literal: '10' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: var2 + - meta_command: \gset result_ + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: EXISTS + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: customer + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: customer_id + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '123' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: is_customer + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: EXISTS + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: employee + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: employee_id + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '456' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: is_employee + - meta_command: \gset + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''hello''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: my_psql_var + - meta_command: \gset + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - psql_variable: + - colon: ':' + - quoted_literal: '''my_psql_var''' +- statement_terminator: ; +- statement: + - meta_command_statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: relname + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: relkind + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: pg_class + - limit_clause: + - keyword: LIMIT + - numeric_literal: '1' + - meta_command: \gset + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: i + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: generate_series + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - numeric_literal: '2' + - end_bracket: ) + - alias_expression: + - naked_identifier: i + - meta_command: \gset prefix diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/null_filters.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/null_filters.yml index b7c5db26a..fc5791c40 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/null_filters.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/null_filters.yml @@ -10,7 +10,8 @@ file: - keyword: IS - null_literal: 'NULL' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: standard_is_null - comma: ',' - select_clause_element: @@ -19,7 +20,8 @@ file: - naked_identifier: nullable_field - keyword: ISNULL - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: non_standard_is_null - comma: ',' - select_clause_element: @@ -30,7 +32,8 @@ file: - keyword: NOT - null_literal: 'NULL' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: standard_not_null - comma: ',' - select_clause_element: @@ -39,7 +42,8 @@ file: - naked_identifier: nullable_field - keyword: NOTNULL - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: non_standard_not_null - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/operator_qualified.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/operator_qualified.sql new file mode 100644 index 000000000..a127eff07 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/operator_qualified.sql @@ -0,0 +1,69 @@ +-- Test OPERATOR() syntax for qualified operator references +-- https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-OPERATORS + +-- Basic comparison operators with schema qualification +SELECT * +FROM table1 +WHERE col1 OPERATOR (public.=) 'value1'; + +SELECT * +FROM table1 +WHERE col2 OPERATOR (pg_catalog.<>) 'value2'; + +SELECT * +FROM table1 +WHERE col3 OPERATOR (myschema.>) 100; + +SELECT * +FROM table1 +WHERE col4 OPERATOR (myschema.<) 100; + +SELECT * +FROM table1 +WHERE col5 OPERATOR (public.>=) 50; + +SELECT * +FROM table1 +WHERE col6 OPERATOR (public.<=) 50; + +-- Arithmetic operators +SELECT col1 OPERATOR (public.+) col2 AS sum_result +FROM table1; + +SELECT col1 OPERATOR (public.-) col2 AS diff_result +FROM table1; + +SELECT col1 OPERATOR (public.*) col2 AS mult_result +FROM table1; + +SELECT col1 OPERATOR (public./) col2 AS div_result +FROM table1; + +-- String operators +SELECT str1 OPERATOR (public.||) str2 AS concatenated +FROM table1; + +-- OPERATOR in HAVING clause +SELECT category, COUNT(*) +FROM products +GROUP BY category +HAVING COUNT(*) OPERATOR (public.>) 5; + +-- OPERATOR in JOIN condition +SELECT t1.id, t2.name +FROM table1 AS t1 +INNER JOIN table2 AS t2 ON t1.id OPERATOR (public.=) t2.table1_id; + +-- OPERATOR in CASE expression +SELECT + CASE + WHEN value OPERATOR (public.>) 100 THEN 'high' + WHEN value OPERATOR (public.<=) 100 THEN 'low' + END AS category +FROM measurements; + +-- Multiple schema names +SELECT * +FROM table1 +WHERE col1 OPERATOR (schema1.=) val1 + AND col2 OPERATOR (schema2.<>) val2; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/operator_qualified.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/operator_qualified.yml new file mode 100644 index 000000000..98e1e3863 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/operator_qualified.yml @@ -0,0 +1,543 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col1 + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: public + - dot: . + - operator: = + - end_bracket: ) + - quoted_literal: '''value1''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col2 + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: pg_catalog + - dot: . + - operator: < + - operator: '>' + - end_bracket: ) + - quoted_literal: '''value2''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col3 + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: myschema + - dot: . + - operator: '>' + - end_bracket: ) + - numeric_literal: '100' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col4 + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: myschema + - dot: . + - operator: < + - end_bracket: ) + - numeric_literal: '100' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col5 + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: public + - dot: . + - operator: '>' + - operator: = + - end_bracket: ) + - numeric_literal: '50' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col6 + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: public + - dot: . + - operator: < + - operator: = + - end_bracket: ) + - numeric_literal: '50' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: col1 + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: public + - dot: . + - operator: + + - end_bracket: ) + - column_reference: + - naked_identifier: col2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sum_result + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: col1 + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: public + - dot: . + - operator: '-' + - end_bracket: ) + - column_reference: + - naked_identifier: col2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: diff_result + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: col1 + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: public + - dot: . + - operator: '*' + - end_bracket: ) + - column_reference: + - naked_identifier: col2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: mult_result + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: col1 + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: public + - dot: . + - operator: / + - end_bracket: ) + - column_reference: + - naked_identifier: col2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: div_result + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: str1 + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: public + - dot: . + - operator: '|' + - operator: '|' + - end_bracket: ) + - column_reference: + - naked_identifier: str2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: concatenated + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: category + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: COUNT + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: products + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: category + - having_clause: + - keyword: HAVING + - expression: + - function: + - function_name: + - function_name_identifier: COUNT + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: public + - dot: . + - operator: '>' + - end_bracket: ) + - numeric_literal: '5' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: name + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t1 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t2 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: id + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: public + - dot: . + - operator: = + - end_bracket: ) + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: table1_id +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: value + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: public + - dot: . + - operator: '>' + - end_bracket: ) + - numeric_literal: '100' + - keyword: THEN + - expression: + - quoted_literal: '''high''' + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: value + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: public + - dot: . + - operator: < + - operator: = + - end_bracket: ) + - numeric_literal: '100' + - keyword: THEN + - expression: + - quoted_literal: '''low''' + - keyword: END + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: category + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: measurements +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col1 + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: schema1 + - dot: . + - operator: = + - end_bracket: ) + - column_reference: + - naked_identifier: val1 + - binary_operator: AND + - column_reference: + - naked_identifier: col2 + - qualified_operator: + - keyword: OPERATOR + - bracketed: + - start_bracket: ( + - naked_identifier: schema2 + - dot: . + - operator: < + - operator: '>' + - end_bracket: ) + - column_reference: + - naked_identifier: val2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/overlaps.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/overlaps.sql index 6a3971169..fb897b26f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/overlaps.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/overlaps.sql @@ -10,3 +10,41 @@ select end_date from test_overlaps where (start_date, end_date) overlaps ('2023-02-15', '2023-03-15'); + +SELECT + t1.start_date, + t1.end_date +FROM test_overlaps1 AS t1 +LEFT JOIN test_overlaps2 AS t2 +WHERE (t1.start_date, t1.end_date) OVERLAPS (t2.start_date, t2.end_date); + +SELECT + start_date, + end_date +FROM test_overlaps +WHERE (start_date, end_date) OVERLAPS ('2023-12-30T00:00:00'::TIMESTAMP, '2024-01-14T13:01:39.884877'::TIMESTAMP); + +SELECT + start_date, + end_date +FROM test_overlaps +WHERE ('2023-12-30T00:00:00'::TIMESTAMP, '2024-01-14T13:01:39.884877'::TIMESTAMP) OVERLAPS (start_date, end_date); + +SELECT + start_date, + end_date +FROM test_overlaps +WHERE (start_date, end_date) OVERLAPS (DATE '2023-12-30', INTERVAL '2 HOURS'); + +SELECT + start_date, + end_date +FROM test_overlaps +WHERE (DATE '2023-12-30', DATE '2024-01-14') OVERLAPS (start_date, end_date); + +SELECT + start_date_1, + start_date_2, + end_date +FROM test_overlaps +WHERE (DATE '2023-12-30', DATE '2024-01-14') OVERLAPS (GREATEST(start_date_1, start_date_2), end_date); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/overlaps.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/overlaps.yml index a9515010c..c1956e672 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/overlaps.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/overlaps.yml @@ -20,28 +20,28 @@ file: - where_clause: - keyword: where - expression: - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: start_date - - comma: ',' - - column_reference: - - naked_identifier: end_date - - end_bracket: ) - - overlaps_clause: - - keyword: overlaps - - bracketed: - - start_bracket: ( - - datetime_literal: - - datetime_type_identifier: - - keyword: DATE - - quoted_literal: '''2023-02-15''' - - comma: ',' - - datetime_literal: - - datetime_type_identifier: - - keyword: DATE - - quoted_literal: '''2023-03-15''' - - end_bracket: ) + - overlaps_clause: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: start_date + - comma: ',' + - column_reference: + - naked_identifier: end_date + - end_bracket: ) + - keyword: overlaps + - bracketed: + - start_bracket: ( + - datetime_literal: + - datetime_type_identifier: + - keyword: DATE + - quoted_literal: '''2023-02-15''' + - comma: ',' + - datetime_literal: + - datetime_type_identifier: + - keyword: DATE + - quoted_literal: '''2023-03-15''' + - end_bracket: ) - statement_terminator: ; - statement: - select_statement: @@ -64,22 +64,334 @@ file: - where_clause: - keyword: where - expression: - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: start_date - - comma: ',' - - column_reference: - - naked_identifier: end_date - - end_bracket: ) - - overlaps_clause: - - keyword: overlaps - - bracketed: - - start_bracket: ( - - datetime_literal: - - quoted_literal: '''2023-02-15''' - - comma: ',' - - datetime_literal: - - quoted_literal: '''2023-03-15''' - - end_bracket: ) + - overlaps_clause: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: start_date + - comma: ',' + - column_reference: + - naked_identifier: end_date + - end_bracket: ) + - keyword: overlaps + - bracketed: + - start_bracket: ( + - datetime_literal: + - quoted_literal: '''2023-02-15''' + - comma: ',' + - datetime_literal: + - quoted_literal: '''2023-03-15''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: start_date + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: end_date + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_overlaps1 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t1 + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_overlaps2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t2 + - where_clause: + - keyword: WHERE + - expression: + - overlaps_clause: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: start_date + - comma: ',' + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: end_date + - end_bracket: ) + - keyword: OVERLAPS + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: start_date + - comma: ',' + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: end_date + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: start_date + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: end_date + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_overlaps + - where_clause: + - keyword: WHERE + - expression: + - overlaps_clause: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: start_date + - comma: ',' + - column_reference: + - naked_identifier: end_date + - end_bracket: ) + - keyword: OVERLAPS + - bracketed: + - start_bracket: ( + - cast_expression: + - quoted_literal: '''2023-12-30T00:00:00''' + - casting_operator: '::' + - data_type: + - datetime_type_identifier: + - keyword: TIMESTAMP + - comma: ',' + - cast_expression: + - quoted_literal: '''2024-01-14T13:01:39.884877''' + - casting_operator: '::' + - data_type: + - datetime_type_identifier: + - keyword: TIMESTAMP + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: start_date + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: end_date + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_overlaps + - where_clause: + - keyword: WHERE + - expression: + - overlaps_clause: + - bracketed: + - start_bracket: ( + - cast_expression: + - quoted_literal: '''2023-12-30T00:00:00''' + - casting_operator: '::' + - data_type: + - datetime_type_identifier: + - keyword: TIMESTAMP + - comma: ',' + - cast_expression: + - quoted_literal: '''2024-01-14T13:01:39.884877''' + - casting_operator: '::' + - data_type: + - datetime_type_identifier: + - keyword: TIMESTAMP + - end_bracket: ) + - keyword: OVERLAPS + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: start_date + - comma: ',' + - column_reference: + - naked_identifier: end_date + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: start_date + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: end_date + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_overlaps + - where_clause: + - keyword: WHERE + - expression: + - overlaps_clause: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: start_date + - comma: ',' + - column_reference: + - naked_identifier: end_date + - end_bracket: ) + - keyword: OVERLAPS + - bracketed: + - start_bracket: ( + - datetime_literal: + - datetime_type_identifier: + - keyword: DATE + - quoted_literal: '''2023-12-30''' + - comma: ',' + - datetime_literal: + - datetime_type_identifier: + - keyword: INTERVAL + - quoted_literal: '''2 HOURS''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: start_date + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: end_date + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_overlaps + - where_clause: + - keyword: WHERE + - expression: + - overlaps_clause: + - bracketed: + - start_bracket: ( + - datetime_literal: + - datetime_type_identifier: + - keyword: DATE + - quoted_literal: '''2023-12-30''' + - comma: ',' + - datetime_literal: + - datetime_type_identifier: + - keyword: DATE + - quoted_literal: '''2024-01-14''' + - end_bracket: ) + - keyword: OVERLAPS + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: start_date + - comma: ',' + - column_reference: + - naked_identifier: end_date + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: start_date_1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: start_date_2 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: end_date + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_overlaps + - where_clause: + - keyword: WHERE + - expression: + - overlaps_clause: + - bracketed: + - start_bracket: ( + - datetime_literal: + - datetime_type_identifier: + - keyword: DATE + - quoted_literal: '''2023-12-30''' + - comma: ',' + - datetime_literal: + - datetime_type_identifier: + - keyword: DATE + - quoted_literal: '''2024-01-14''' + - end_bracket: ) + - keyword: OVERLAPS + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: GREATEST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: start_date_1 + - comma: ',' + - expression: + - column_reference: + - naked_identifier: start_date_2 + - end_bracket: ) + - comma: ',' + - column_reference: + - naked_identifier: end_date + - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pattern_match_expressions.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pattern_match_expressions.yml index 881c513f4..8e26aa750 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pattern_match_expressions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pattern_match_expressions.yml @@ -167,7 +167,8 @@ file: - boolean_literal: 'FALSE' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: is_bear - from_clause: - keyword: FROM @@ -352,7 +353,8 @@ file: - boolean_literal: 'FALSE' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: is_bear - from_clause: - keyword: FROM @@ -409,7 +411,8 @@ file: - quoted_literal: '''24601''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: honey_numerical_code - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pg_trgm.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pg_trgm.sql new file mode 100644 index 000000000..d2a2e2806 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pg_trgm.sql @@ -0,0 +1,32 @@ +-- PostgreSQL pg_trgm similarity operators +-- https://www.postgresql.org/docs/current/pgtrgm.html + +-- text % text → boolean (similarity) +SELECT 'abc' % 'abd'; + +-- text <% text → boolean (word_similarity) +SELECT 'word' <% 'some word here'; + +-- text %> text → boolean (word_similarity reverse) +SELECT 'some word here' %> 'word'; + +-- text <<% text → boolean (strict_word_similarity) +SELECT 'text' <<% 'some text example'; + +-- text %>> text → boolean (strict_word_similarity reverse) +SELECT 'some text example' %>> 'text'; + +-- text <-> text → real (similarity distance) +SELECT 'str1' <-> 'str2'; + +-- text <<-> text → real (word_similarity distance) +SELECT 'item' <<-> 'some item value'; + +-- text <->> text → real (word_similarity distance reverse) +SELECT 'some item value' <->> 'item'; + +-- text <<<-> text → real (strict_word_similarity distance) +SELECT 'name' <<<-> 'some name field'; + +-- text <->>> text → real (strict_word_similarity distance reverse) +SELECT 'some name field' <->>> 'name'; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pg_trgm.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pg_trgm.yml new file mode 100644 index 000000000..95072b365 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pg_trgm.yml @@ -0,0 +1,101 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''abc''' + - binary_operator: '%' + - quoted_literal: '''abd''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''word''' + - binary_operator: <% + - quoted_literal: '''some word here''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''some word here''' + - binary_operator: '%>' + - quoted_literal: '''word''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''text''' + - binary_operator: <<% + - quoted_literal: '''some text example''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''some text example''' + - binary_operator: '%>>' + - quoted_literal: '''text''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''str1''' + - binary_operator: <-> + - quoted_literal: '''str2''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''item''' + - binary_operator: <<-> + - quoted_literal: '''some item value''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''some item value''' + - binary_operator: <->> + - quoted_literal: '''item''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''name''' + - binary_operator: <<<-> + - quoted_literal: '''some name field''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''some name field''' + - binary_operator: <->>> + - quoted_literal: '''name''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pgvector.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pgvector.sql new file mode 100644 index 000000000..7e818eaff --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pgvector.sql @@ -0,0 +1,3 @@ +CREATE TABLE search ( + embedding VECTOR(1536) +); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pgvector.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pgvector.yml new file mode 100644 index 000000000..ad8367942 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/pgvector.yml @@ -0,0 +1,20 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: search + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: embedding + - data_type: + - keyword: VECTOR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '1536' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/position.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/position.sql index c4e0b154b..329989b1a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/position.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/position.sql @@ -4,4 +4,7 @@ select p.product_id from user_tb as u inner join product_tb as p on u.user_id = p.user_id - and position('@domain' in u.user_email) = 0 + and position('@domain' in u.user_email) = 0; + + +SELECT position('#' IN tbl.col_a -> 'b') AS hash_pos FROM tbl; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/position.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/position.yml index a3c3cd2b0..f7ed08db8 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/position.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/position.yml @@ -28,7 +28,8 @@ file: - table_reference: - naked_identifier: user_tb - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: u - join_clause: - keyword: inner @@ -38,7 +39,8 @@ file: - table_reference: - naked_identifier: product_tb - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: p - join_on_condition: - keyword: on @@ -70,3 +72,37 @@ file: - comparison_operator: - raw_comparison_operator: = - numeric_literal: '0' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: position + - function_contents: + - bracketed: + - start_bracket: ( + - quoted_literal: '''#''' + - keyword: IN + - expression: + - column_reference: + - naked_identifier: tbl + - dot: . + - naked_identifier: col_a + - binary_operator: -> + - quoted_literal: '''b''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: hash_pos + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgis.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgis.yml index bf31ecf59..ca392bedb 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgis.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgis.yml @@ -9,657 +9,657 @@ file: - naked_identifier: foo - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: quadkey - - data_type: - - keyword: TEXT + - data_type: + - keyword: TEXT - comma: ',' - - column_reference: + - column_definition: - naked_identifier: my_geometry_column - - data_type: - - wkt_geometry_type: - - keyword: GEOMETRY - - bracketed: - - start_bracket: ( + - data_type: + - wkt_geometry_type: - keyword: GEOMETRY - - comma: ',' - - numeric_literal: '4326' - - end_bracket: ) + - bracketed: + - start_bracket: ( + - keyword: GEOMETRY + - comma: ',' + - numeric_literal: '4326' + - end_bracket: ) - comma: ',' - - column_reference: + - column_definition: - naked_identifier: my_point - - data_type: - - wkt_geometry_type: - - keyword: POINT - - bracketed: - - start_bracket: ( - - numeric_literal: '0' - - numeric_literal: '0' - - end_bracket: ) - - comma: ',' - - column_reference: - - naked_identifier: my_linestring - - data_type: - - wkt_geometry_type: - - keyword: LINESTRING - - bracketed: - - start_bracket: ( - - numeric_literal: '0' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '2' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '2' - - numeric_literal: '2' - - end_bracket: ) - - comma: ',' - - column_reference: - - naked_identifier: my_simple_polygon - - data_type: - - wkt_geometry_type: - - keyword: POLYGON - - bracketed: - - start_bracket: ( + - data_type: + - wkt_geometry_type: + - keyword: POINT - bracketed: - start_bracket: ( - numeric_literal: '0' - numeric_literal: '0' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '0' - end_bracket: ) - - end_bracket: ) - comma: ',' - - column_reference: - - naked_identifier: my_complex_polygon - - data_type: - - wkt_geometry_type: - - keyword: POLYGON - - bracketed: - - start_bracket: ( + - column_definition: + - naked_identifier: my_linestring + - data_type: + - wkt_geometry_type: + - keyword: LINESTRING - bracketed: - start_bracket: ( - numeric_literal: '0' - numeric_literal: '0' - comma: ',' - - numeric_literal: '10' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '10' - - numeric_literal: '10' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '10' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '0' - - end_bracket: ) - - comma: ',' - - bracketed: - - start_bracket: ( - numeric_literal: '1' - numeric_literal: '1' - comma: ',' - - numeric_literal: '1' - numeric_literal: '2' + - numeric_literal: '1' - comma: ',' - numeric_literal: '2' - numeric_literal: '2' - - comma: ',' - - numeric_literal: '2' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '1' - - end_bracket: ) - - end_bracket: ) - - comma: ',' - - column_reference: - - naked_identifier: my_geometry_collection - - data_type: - - wkt_geometry_type: - - keyword: GEOMETRYCOLLECTION - - bracketed: - - start_bracket: ( - - wkt_geometry_type: - - keyword: POINT - - bracketed: - - start_bracket: ( - - numeric_literal: '2' - - numeric_literal: '0' - - end_bracket: ) - - comma: ',' - - wkt_geometry_type: - - keyword: POLYGON - - bracketed: - - start_bracket: ( - - bracketed: - - start_bracket: ( - - numeric_literal: '0' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '0' - - end_bracket: ) - - end_bracket: ) - - end_bracket: ) - - comma: ',' - - column_reference: - - naked_identifier: my_3d_linestring - - data_type: - - wkt_geometry_type: - - keyword: LINESTRINGZ - - bracketed: - - start_bracket: ( - - numeric_literal: '0' - - numeric_literal: '0' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '0' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '1' - - numeric_literal: '2' - - end_bracket: ) - - comma: ',' - - column_reference: - - naked_identifier: my_geography_column - - data_type: - - wkt_geometry_type: - - keyword: GEOGRAPHY - - bracketed: - - start_bracket: ( - - keyword: GEOGRAPHY - - comma: ',' - - numeric_literal: '6679' - - end_bracket: ) - - comma: ',' - - column_reference: - - naked_identifier: my_4d_point - - data_type: - - wkt_geometry_type: - - keyword: POINTZM - - bracketed: - - start_bracket: ( - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '1' - - end_bracket: ) - - comma: ',' - - column_reference: - - naked_identifier: my_multicurve - - data_type: - - wkt_geometry_type: - - keyword: MULTICURVE - - bracketed: - - start_bracket: ( - - bracketed: - - start_bracket: ( - - numeric_literal: '0' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '5' - - numeric_literal: '5' - end_bracket: ) - - comma: ',' - - wkt_geometry_type: - - keyword: CIRCULARSTRING - - bracketed: - - start_bracket: ( - - numeric_literal: '4' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '4' - - numeric_literal: '4' - - comma: ',' - - numeric_literal: '8' - - numeric_literal: '4' - - end_bracket: ) - - end_bracket: ) - comma: ',' - - column_reference: - - naked_identifier: my_tin - - data_type: - - wkt_geometry_type: - - keyword: TIN - - bracketed: - - start_bracket: ( + - column_definition: + - naked_identifier: my_simple_polygon + - data_type: + - wkt_geometry_type: + - keyword: POLYGON - bracketed: - start_bracket: ( - bracketed: - start_bracket: ( - numeric_literal: '0' - numeric_literal: '0' - - numeric_literal: '0' - comma: ',' + - numeric_literal: '1' - numeric_literal: '0' - - numeric_literal: '0' + - comma: ',' + - numeric_literal: '1' - numeric_literal: '1' - comma: ',' - numeric_literal: '0' - numeric_literal: '1' - - numeric_literal: '0' - comma: ',' - numeric_literal: '0' - numeric_literal: '0' - - numeric_literal: '0' - end_bracket: ) - end_bracket: ) - - comma: ',' + - comma: ',' + - column_definition: + - naked_identifier: my_complex_polygon + - data_type: + - wkt_geometry_type: + - keyword: POLYGON - bracketed: - start_bracket: ( - bracketed: - start_bracket: ( - numeric_literal: '0' - numeric_literal: '0' + - comma: ',' + - numeric_literal: '10' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '10' + - numeric_literal: '10' + - comma: ',' - numeric_literal: '0' + - numeric_literal: '10' - comma: ',' - numeric_literal: '0' - - numeric_literal: '1' - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - numeric_literal: '1' - comma: ',' - numeric_literal: '1' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '2' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '2' - numeric_literal: '1' - - numeric_literal: '0' - comma: ',' - - numeric_literal: '0' - - numeric_literal: '0' - - numeric_literal: '0' + - numeric_literal: '1' + - numeric_literal: '1' - end_bracket: ) - end_bracket: ) - - end_bracket: ) - comma: ',' - - column_reference: - - naked_identifier: my_triangle - - data_type: - - wkt_geometry_type: - - keyword: TRIANGLE - - bracketed: - - start_bracket: ( + - column_definition: + - naked_identifier: my_geometry_collection + - data_type: + - wkt_geometry_type: + - keyword: GEOMETRYCOLLECTION - bracketed: - start_bracket: ( - - numeric_literal: '0' - - numeric_literal: '0' + - wkt_geometry_type: + - keyword: POINT + - bracketed: + - start_bracket: ( + - numeric_literal: '2' + - numeric_literal: '0' + - end_bracket: ) - comma: ',' + - wkt_geometry_type: + - keyword: POLYGON + - bracketed: + - start_bracket: ( + - bracketed: + - start_bracket: ( + - numeric_literal: '0' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '1' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '1' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '0' + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: my_3d_linestring + - data_type: + - wkt_geometry_type: + - keyword: LINESTRINGZ + - bracketed: + - start_bracket: ( + - numeric_literal: '0' - numeric_literal: '0' - - numeric_literal: '9' - - comma: ',' - - numeric_literal: '9' - numeric_literal: '0' - comma: ',' + - numeric_literal: '1' - numeric_literal: '0' - numeric_literal: '0' + - comma: ',' + - numeric_literal: '1' + - numeric_literal: '1' + - numeric_literal: '2' - end_bracket: ) - - end_bracket: ) - comma: ',' - - column_reference: - - naked_identifier: my_polyhedral_surface - - data_type: - - wkt_geometry_type: - - keyword: POLYHEDRALSURFACE - - bracketed: - - start_bracket: ( + - column_definition: + - naked_identifier: my_geography_column + - data_type: + - wkt_geometry_type: + - keyword: GEOGRAPHY - bracketed: - start_bracket: ( - - bracketed: - - start_bracket: ( - - numeric_literal: '0' - - numeric_literal: '0' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '0' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '1' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '1' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '0' - - numeric_literal: '0' - - end_bracket: ) + - keyword: GEOGRAPHY + - comma: ',' + - numeric_literal: '6679' - end_bracket: ) - - comma: ',' + - comma: ',' + - column_definition: + - naked_identifier: my_4d_point + - data_type: + - wkt_geometry_type: + - keyword: POINTZM - bracketed: - start_bracket: ( - - bracketed: - - start_bracket: ( - - numeric_literal: '0' - - numeric_literal: '0' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '1' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '1' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '0' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '0' - - numeric_literal: '0' - - end_bracket: ) + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '1' - end_bracket: ) - - comma: ',' + - comma: ',' + - column_definition: + - naked_identifier: my_multicurve + - data_type: + - wkt_geometry_type: + - keyword: MULTICURVE - bracketed: - start_bracket: ( - bracketed: - start_bracket: ( - numeric_literal: '0' - numeric_literal: '0' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '0' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '0' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '0' - - numeric_literal: '1' - comma: ',' - - numeric_literal: '0' - - numeric_literal: '0' - - numeric_literal: '0' + - numeric_literal: '5' + - numeric_literal: '5' - end_bracket: ) + - comma: ',' + - wkt_geometry_type: + - keyword: CIRCULARSTRING + - bracketed: + - start_bracket: ( + - numeric_literal: '4' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '4' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '8' + - numeric_literal: '4' + - end_bracket: ) - end_bracket: ) - - comma: ',' + - comma: ',' + - column_definition: + - naked_identifier: my_tin + - data_type: + - wkt_geometry_type: + - keyword: TIN - bracketed: - start_bracket: ( - bracketed: - start_bracket: ( - - numeric_literal: '1' - - numeric_literal: '1' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '1' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '0' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '0' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '1' - - numeric_literal: '0' + - bracketed: + - start_bracket: ( + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '1' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '0' + - end_bracket: ) - end_bracket: ) - - end_bracket: ) - - comma: ',' - - bracketed: - - start_bracket: ( + - comma: ',' - bracketed: - start_bracket: ( - - numeric_literal: '0' - - numeric_literal: '1' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '1' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '1' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '1' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '1' - - numeric_literal: '0' + - bracketed: + - start_bracket: ( + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '1' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '1' + - numeric_literal: '1' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '0' + - end_bracket: ) - end_bracket: ) - end_bracket: ) - - comma: ',' + - comma: ',' + - column_definition: + - naked_identifier: my_triangle + - data_type: + - wkt_geometry_type: + - keyword: TRIANGLE - bracketed: - start_bracket: ( - bracketed: - start_bracket: ( - numeric_literal: '0' - numeric_literal: '0' - - numeric_literal: '1' - comma: ',' - - numeric_literal: '1' - numeric_literal: '0' - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '1' - - numeric_literal: '1' - - numeric_literal: '1' + - numeric_literal: '9' - comma: ',' + - numeric_literal: '9' - numeric_literal: '0' - - numeric_literal: '1' - - numeric_literal: '1' - comma: ',' - numeric_literal: '0' - numeric_literal: '0' - - numeric_literal: '1' - end_bracket: ) - end_bracket: ) - - end_bracket: ) - comma: ',' - - column_reference: - - naked_identifier: my_3d_geometry_collection - - data_type: - - wkt_geometry_type: - - keyword: GEOMETRYCOLLECTIONM - - bracketed: - - start_bracket: ( - - wkt_geometry_type: - - keyword: POINTM + - column_definition: + - naked_identifier: my_polyhedral_surface + - data_type: + - wkt_geometry_type: + - keyword: POLYHEDRALSURFACE + - bracketed: + - start_bracket: ( - bracketed: - start_bracket: ( - - numeric_literal: '2' - - numeric_literal: '3' - - numeric_literal: '9' + - bracketed: + - start_bracket: ( + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '1' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '1' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '0' + - end_bracket: ) - end_bracket: ) - - comma: ',' - - wkt_geometry_type: - - keyword: LINESTRINGM + - comma: ',' - bracketed: - start_bracket: ( - - numeric_literal: '2' - - numeric_literal: '3' - - numeric_literal: '4' - - comma: ',' - - numeric_literal: '3' - - numeric_literal: '4' - - numeric_literal: '5' + - bracketed: + - start_bracket: ( + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '1' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '1' + - numeric_literal: '1' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '1' + - numeric_literal: '0' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '0' + - end_bracket: ) - end_bracket: ) - - end_bracket: ) - - comma: ',' - - column_reference: - - naked_identifier: my_curve_polygon - - data_type: - - wkt_geometry_type: - - keyword: CURVEPOLYGON - - bracketed: - - start_bracket: ( - - wkt_geometry_type: - - keyword: CIRCULARSTRING + - comma: ',' - bracketed: - start_bracket: ( - - numeric_literal: '0' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '4' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '4' - - numeric_literal: '4' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '4' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '0' + - bracketed: + - start_bracket: ( + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '1' + - numeric_literal: '0' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '1' + - numeric_literal: '0' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '0' + - end_bracket: ) - end_bracket: ) - - comma: ',' - - bracketed: - - start_bracket: ( - - numeric_literal: '1' - - numeric_literal: '1' - comma: ',' - - numeric_literal: '3' - - numeric_literal: '3' - - comma: ',' - - numeric_literal: '3' - - numeric_literal: '1' + - bracketed: + - start_bracket: ( + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - numeric_literal: '1' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '1' + - numeric_literal: '1' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '1' + - numeric_literal: '0' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '1' + - numeric_literal: '0' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '1' + - numeric_literal: '1' + - numeric_literal: '0' + - end_bracket: ) + - end_bracket: ) - comma: ',' - - numeric_literal: '1' - - numeric_literal: '1' - - end_bracket: ) - - end_bracket: ) - - comma: ',' - - column_reference: - - naked_identifier: my_multisurface - - data_type: - - wkt_geometry_type: - - keyword: MULTISURFACE - - bracketed: - - start_bracket: ( - - wkt_geometry_type: - - keyword: CURVEPOLYGON - bracketed: - start_bracket: ( - - wkt_geometry_type: - - keyword: CIRCULARSTRING - - bracketed: - - start_bracket: ( - - numeric_literal: '0' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '4' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '4' - - numeric_literal: '4' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '4' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '0' - - end_bracket: ) - - comma: ',' - bracketed: - start_bracket: ( + - numeric_literal: '0' + - numeric_literal: '1' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '0' - numeric_literal: '1' - numeric_literal: '1' - comma: ',' - - numeric_literal: '3' - - numeric_literal: '3' + - numeric_literal: '1' + - numeric_literal: '1' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '1' + - numeric_literal: '1' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '1' + - numeric_literal: '0' + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - bracketed: + - start_bracket: ( + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '1' - comma: ',' - - numeric_literal: '3' + - numeric_literal: '1' + - numeric_literal: '0' - numeric_literal: '1' - comma: ',' - numeric_literal: '1' - numeric_literal: '1' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '1' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '0' + - numeric_literal: '1' - end_bracket: ) - end_bracket: ) - - comma: ',' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: my_3d_geometry_collection + - data_type: + - wkt_geometry_type: + - keyword: GEOMETRYCOLLECTIONM + - bracketed: + - start_bracket: ( + - wkt_geometry_type: + - keyword: POINTM + - bracketed: + - start_bracket: ( + - numeric_literal: '2' + - numeric_literal: '3' + - numeric_literal: '9' + - end_bracket: ) + - comma: ',' + - wkt_geometry_type: + - keyword: LINESTRINGM + - bracketed: + - start_bracket: ( + - numeric_literal: '2' + - numeric_literal: '3' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '3' + - numeric_literal: '4' + - numeric_literal: '5' + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: my_curve_polygon + - data_type: + - wkt_geometry_type: + - keyword: CURVEPOLYGON - bracketed: - start_bracket: ( + - wkt_geometry_type: + - keyword: CIRCULARSTRING + - bracketed: + - start_bracket: ( + - numeric_literal: '0' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '4' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '4' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' - bracketed: - start_bracket: ( - - numeric_literal: '10' - - numeric_literal: '10' + - numeric_literal: '1' + - numeric_literal: '1' - comma: ',' - - numeric_literal: '14' - - numeric_literal: '12' + - numeric_literal: '3' + - numeric_literal: '3' - comma: ',' - - numeric_literal: '11' - - numeric_literal: '10' + - numeric_literal: '3' + - numeric_literal: '1' - comma: ',' - - numeric_literal: '10' - - numeric_literal: '10' + - numeric_literal: '1' + - numeric_literal: '1' - end_bracket: ) + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: my_multisurface + - data_type: + - wkt_geometry_type: + - keyword: MULTISURFACE + - bracketed: + - start_bracket: ( + - wkt_geometry_type: + - keyword: CURVEPOLYGON + - bracketed: + - start_bracket: ( + - wkt_geometry_type: + - keyword: CIRCULARSTRING + - bracketed: + - start_bracket: ( + - numeric_literal: '0' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '4' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '4' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '3' + - numeric_literal: '3' + - comma: ',' + - numeric_literal: '3' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '1' + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) - comma: ',' - bracketed: - start_bracket: ( - - numeric_literal: '11' - - numeric_literal: '11' - - comma: ',' - - numeric_literal: '11.5' - - numeric_literal: '11' - - comma: ',' - - numeric_literal: '11' - - numeric_literal: '11.5' + - bracketed: + - start_bracket: ( + - numeric_literal: '10' + - numeric_literal: '10' + - comma: ',' + - numeric_literal: '14' + - numeric_literal: '12' + - comma: ',' + - numeric_literal: '11' + - numeric_literal: '10' + - comma: ',' + - numeric_literal: '10' + - numeric_literal: '10' + - end_bracket: ) - comma: ',' - - numeric_literal: '11' - - numeric_literal: '11' + - bracketed: + - start_bracket: ( + - numeric_literal: '11' + - numeric_literal: '11' + - comma: ',' + - numeric_literal: '11.5' + - numeric_literal: '11' + - comma: ',' + - numeric_literal: '11' + - numeric_literal: '11.5' + - comma: ',' + - numeric_literal: '11' + - numeric_literal: '11' + - end_bracket: ) - end_bracket: ) - end_bracket: ) - - end_bracket: ) - comma: ',' - - column_reference: + - column_definition: - naked_identifier: my_circularstring - - data_type: - - wkt_geometry_type: - - keyword: CIRCULARSTRING - - bracketed: - - start_bracket: ( - - numeric_literal: '0' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '4' - - numeric_literal: '0' - - comma: ',' - - numeric_literal: '4' - - numeric_literal: '4' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '4' - - comma: ',' - - numeric_literal: '0' - - numeric_literal: '0' - - end_bracket: ) + - data_type: + - wkt_geometry_type: + - keyword: CIRCULARSTRING + - bracketed: + - start_bracket: ( + - numeric_literal: '0' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '4' + - numeric_literal: '0' + - comma: ',' + - numeric_literal: '4' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '0' + - numeric_literal: '0' + - end_bracket: ) - comma: ',' - table_constraint: - keyword: PRIMARY diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_pgvector_operators.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_pgvector_operators.sql new file mode 100644 index 000000000..58b5caaa7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_pgvector_operators.sql @@ -0,0 +1,7 @@ +SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5; + +SELECT * FROM items ORDER BY embedding <=> '[3,1,2]' LIMIT 5; + +SELECT * FROM items ORDER BY embedding <+> '[3,1,2]' LIMIT 5; + +SELECT * FROM items ORDER BY embedding <#> '[3,1,2]' LIMIT 5; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_pgvector_operators.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_pgvector_operators.yml new file mode 100644 index 000000000..eed7b84c5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_pgvector_operators.yml @@ -0,0 +1,109 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: items + - orderby_clause: + - keyword: ORDER + - keyword: BY + - expression: + - column_reference: + - naked_identifier: embedding + - binary_operator: <-> + - quoted_literal: '''[3,1,2]''' + - limit_clause: + - keyword: LIMIT + - numeric_literal: '5' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: items + - orderby_clause: + - keyword: ORDER + - keyword: BY + - expression: + - column_reference: + - naked_identifier: embedding + - binary_operator: <=> + - quoted_literal: '''[3,1,2]''' + - limit_clause: + - keyword: LIMIT + - numeric_literal: '5' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: items + - orderby_clause: + - keyword: ORDER + - keyword: BY + - expression: + - column_reference: + - naked_identifier: embedding + - binary_operator: <+> + - quoted_literal: '''[3,1,2]''' + - limit_clause: + - keyword: LIMIT + - numeric_literal: '5' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: items + - orderby_clause: + - keyword: ORDER + - keyword: BY + - expression: + - column_reference: + - naked_identifier: embedding + - binary_operator: <#> + - quoted_literal: '''[3,1,2]''' + - limit_clause: + - keyword: LIMIT + - numeric_literal: '5' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_postgis_operators.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_postgis_operators.sql new file mode 100644 index 000000000..6e3f7d4c4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_postgis_operators.sql @@ -0,0 +1,149 @@ +SELECT tbl1.column1, tbl2.column1, tbl1.column2 && tbl2.column2 AS overlap +FROM ( VALUES + (1, 'LINESTRING(0 0, 3 3)'::geometry), + (2, 'LINESTRING(0 1, 0 5)'::geometry)) AS tbl1, +( VALUES + (3, 'LINESTRING(1 2, 4 6)'::geometry)) AS tbl2; + +SELECT tbl1.column1, tbl2.column1, tbl1.column2 &&& tbl2.column2 AS overlaps_3d, + tbl1.column2 && tbl2.column2 AS overlaps_2d +FROM ( VALUES + (1, 'LINESTRING Z(0 0 1, 3 3 2)'::geometry), + (2, 'LINESTRING Z(1 2 0, 0 5 -1)'::geometry)) AS tbl1, +( VALUES + (3, 'LINESTRING Z(1 2 1, 4 6 1)'::geometry)) AS tbl2; + +SELECT tbl1.column1, tbl2.column1, tbl1.column2 &< tbl2.column2 AS overleft +FROM + ( VALUES + (1, 'LINESTRING(1 2, 4 6)'::geometry)) AS tbl1, + ( VALUES + (2, 'LINESTRING(0 0, 3 3)'::geometry), + (3, 'LINESTRING(0 1, 0 5)'::geometry), + (4, 'LINESTRING(6 0, 6 1)'::geometry)) AS tbl2; + +SELECT tbl1.column1, tbl2.column1, tbl1.column2 &<| tbl2.column2 AS overbelow +FROM + ( VALUES + (1, 'LINESTRING(6 0, 6 4)'::geometry)) AS tbl1, + ( VALUES + (2, 'LINESTRING(0 0, 3 3)'::geometry), + (3, 'LINESTRING(0 1, 0 5)'::geometry), + (4, 'LINESTRING(1 2, 4 6)'::geometry)) AS tbl2; + +SELECT tbl1.column1, tbl2.column1, tbl1.column2 &> tbl2.column2 AS overright +FROM + ( VALUES + (1, 'LINESTRING(1 2, 4 6)'::geometry)) AS tbl1, + ( VALUES + (2, 'LINESTRING(0 0, 3 3)'::geometry), + (3, 'LINESTRING(0 1, 0 5)'::geometry), + (4, 'LINESTRING(6 0, 6 1)'::geometry)) AS tbl2; + +SELECT tbl1.column1, tbl2.column1, tbl1.column2 << tbl2.column2 AS strict_left +FROM + ( VALUES + (1, 'LINESTRING (1 2, 1 5)'::geometry)) AS tbl1, + ( VALUES + (2, 'LINESTRING (0 0, 4 3)'::geometry), + (3, 'LINESTRING (6 0, 6 5)'::geometry), + (4, 'LINESTRING (2 2, 5 6)'::geometry)) AS tbl2; + +SELECT tbl1.column1, tbl2.column1, tbl1.column2 <<| tbl2.column2 AS below +FROM + ( VALUES + (1, 'LINESTRING (0 0, 4 3)'::geometry)) AS tbl1, + ( VALUES + (2, 'LINESTRING (1 4, 1 7)'::geometry), + (3, 'LINESTRING (6 1, 6 5)'::geometry), + (4, 'LINESTRING (2 3, 5 6)'::geometry)) AS tbl2; + +SELECT 'LINESTRING(0 0, 0 1, 1 0)'::geometry = 'LINESTRING(1 1, 0 0)'::geometry; + +SELECT tbl1.column1, tbl2.column1, tbl1.column2 >> tbl2.column2 AS strict_right +FROM + ( VALUES + (1, 'LINESTRING (2 3, 5 6)'::geometry)) AS tbl1, + ( VALUES + (2, 'LINESTRING (1 4, 1 7)'::geometry), + (3, 'LINESTRING (6 1, 6 5)'::geometry), + (4, 'LINESTRING (0 0, 4 3)'::geometry)) AS tbl2; + +SELECT tbl1.column1, tbl2.column1, tbl1.column2 @ tbl2.column2 AS contained +FROM + ( VALUES + (1, 'LINESTRING (1 1, 3 3)'::geometry)) AS tbl1, + ( VALUES + (2, 'LINESTRING (0 0, 4 4)'::geometry), + (3, 'LINESTRING (2 2, 4 4)'::geometry), + (4, 'LINESTRING (1 1, 3 3)'::geometry)) AS tbl2; + +SELECT tbl1.column1, tbl2.column1, tbl1.column2 |&> tbl2.column2 AS overabove +FROM + ( VALUES + (1, 'LINESTRING(6 0, 6 4)'::geometry)) AS tbl1, + ( VALUES + (2, 'LINESTRING(0 0, 3 3)'::geometry), + (3, 'LINESTRING(0 1, 0 5)'::geometry), + (4, 'LINESTRING(1 2, 4 6)'::geometry)) AS tbl2; + +SELECT tbl1.column1, tbl2.column1, tbl1.column2 |>> tbl2.column2 AS above +FROM + ( VALUES + (1, 'LINESTRING (1 4, 1 7)'::geometry)) AS tbl1, + ( VALUES + (2, 'LINESTRING (0 0, 4 2)'::geometry), + (3, 'LINESTRING (6 1, 6 5)'::geometry), + (4, 'LINESTRING (2 3, 5 6)'::geometry)) AS tbl2; + +SELECT tbl1.column1, tbl2.column1, tbl1.column2 ~ tbl2.column2 AS contains +FROM + ( VALUES + (1, 'LINESTRING (0 0, 3 3)'::geometry)) AS tbl1, + ( VALUES + (2, 'LINESTRING (0 0, 4 4)'::geometry), + (3, 'LINESTRING (1 1, 2 2)'::geometry), + (4, 'LINESTRING (0 0, 3 3)'::geometry)) AS tbl2; + +select 'LINESTRING(0 0, 1 1)'::geometry ~= 'LINESTRING(0 1, 1 0)'::geometry as equality; + +SELECT st_distance(geom, 'SRID=3005;POINT(1011102 450541)'::geometry) as d,edabbr, vaabbr +FROM va2005 +ORDER BY geom <-> 'SRID=3005;POINT(1011102 450541)'::geometry limit 10; + +SELECT track_id, dist FROM ( + SELECT track_id, ST_DistanceCPA(tr,:qt) dist + FROM trajectories + ORDER BY tr |=| :qt + LIMIT 5 +) foo; + +SELECT * +FROM ( +SELECT b.tlid, b.mtfcc, + b.geom <#> ST_GeomFromText('LINESTRING(746149 2948672,745954 2948576, + 745787 2948499,745740 2948468,745712 2948438, + 745690 2948384,745677 2948319)',2249) As b_dist, + ST_Distance(b.geom, ST_GeomFromText('LINESTRING(746149 2948672,745954 2948576, + 745787 2948499,745740 2948468,745712 2948438, + 745690 2948384,745677 2948319)',2249)) As act_dist + FROM bos_roads As b + ORDER BY b_dist, b.tlid + LIMIT 100) As foo + ORDER BY act_dist, tlid LIMIT 10; + +WITH index_query AS ( + SELECT ST_Distance(geom, 'SRID=3005;POINT(1011102 450541)'::geometry) as d,edabbr, vaabbr + FROM va2005 + ORDER BY geom <<->> 'SRID=3005;POINT(1011102 450541)'::geometry LIMIT 100) + SELECT * + FROM index_query + ORDER BY d limit 10; + +WITH index_query AS ( + SELECT ST_Distance(geom, 'SRID=3005;POINT(1011102 450541)'::geometry) as d,edabbr, vaabbr + FROM va2005 + ORDER BY geom <<#>> 'SRID=3005;POINT(1011102 450541)'::geometry LIMIT 100) + SELECT * + FROM index_query + ORDER BY d limit 10; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_postgis_operators.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_postgis_operators.yml new file mode 100644 index 000000000..bada91d15 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/postgres_postgis_operators.yml @@ -0,0 +1,1776 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column2 + - comparison_operator: + - ampersand: '&' + - ampersand: '&' + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: overlap + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(0 0, 3 3)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(0 1, 0 5)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl1 + - comma: ',' + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(1 2, 4 6)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column2 + - binary_operator: '&&&' + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: overlaps_3d + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column2 + - comparison_operator: + - ampersand: '&' + - ampersand: '&' + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: overlaps_2d + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING Z(0 0 1, 3 3 2)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING Z(1 2 0, 0 5 -1)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl1 + - comma: ',' + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING Z(1 2 1, 4 6 1)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column2 + - comparison_operator: + - ampersand: '&' + - raw_comparison_operator: < + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: overleft + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(1 2, 4 6)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl1 + - comma: ',' + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(0 0, 3 3)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(0 1, 0 5)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '4' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(6 0, 6 1)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column2 + - binary_operator: '&<|' + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: overbelow + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(6 0, 6 4)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl1 + - comma: ',' + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(0 0, 3 3)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(0 1, 0 5)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '4' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(1 2, 4 6)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column2 + - comparison_operator: + - ampersand: '&' + - raw_comparison_operator: '>' + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: overright + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(1 2, 4 6)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl1 + - comma: ',' + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(0 0, 3 3)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(0 1, 0 5)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '4' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(6 0, 6 1)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column2 + - binary_operator: + - raw_comparison_operator: < + - raw_comparison_operator: < + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: strict_left + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (1 2, 1 5)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl1 + - comma: ',' + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (0 0, 4 3)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (6 0, 6 5)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '4' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (2 2, 5 6)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column2 + - binary_operator: <<| + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: below + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (0 0, 4 3)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl1 + - comma: ',' + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (1 4, 1 7)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (6 1, 6 5)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '4' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (2 3, 5 6)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(0 0, 0 1, 1 0)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - comparison_operator: + - raw_comparison_operator: = + - cast_expression: + - quoted_literal: '''LINESTRING(1 1, 0 0)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column2 + - binary_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: '>' + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: strict_right + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (2 3, 5 6)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl1 + - comma: ',' + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (1 4, 1 7)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (6 1, 6 5)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '4' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (0 0, 4 3)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column2 + - binary_operator: '@' + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: contained + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (1 1, 3 3)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl1 + - comma: ',' + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (0 0, 4 4)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (2 2, 4 4)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '4' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (1 1, 3 3)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column2 + - binary_operator: '|&>' + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: overabove + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(6 0, 6 4)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl1 + - comma: ',' + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(0 0, 3 3)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(0 1, 0 5)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '4' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(1 2, 4 6)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column2 + - binary_operator: '|>>' + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: above + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (1 4, 1 7)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl1 + - comma: ',' + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (0 0, 4 2)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (6 1, 6 5)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '4' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (2 3, 5 6)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: tbl1 + - dot: . + - naked_identifier: column2 + - like_operator: '~' + - column_reference: + - naked_identifier: tbl2 + - dot: . + - naked_identifier: column2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: contains + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (0 0, 3 3)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl1 + - comma: ',' + - from_expression: + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (0 0, 4 4)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (1 1, 2 2)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '4' + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING (0 0, 3 3)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tbl2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - expression: + - cast_expression: + - quoted_literal: '''LINESTRING(0 0, 1 1)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - binary_operator: ~= + - cast_expression: + - quoted_literal: '''LINESTRING(0 1, 1 0)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: equality +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: st_distance + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: geom + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''SRID=3005;POINT(1011102 450541)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: d + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: edabbr + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: vaabbr + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: va2005 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - expression: + - column_reference: + - naked_identifier: geom + - binary_operator: <-> + - cast_expression: + - quoted_literal: '''SRID=3005;POINT(1011102 450541)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - limit_clause: + - keyword: limit + - numeric_literal: '10' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: track_id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: dist + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: track_id + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: ST_DistanceCPA + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: tr + - comma: ',' + - expression: + - psql_variable: + - colon: ':' + - parameter: qt + - end_bracket: ) + - alias_expression: + - naked_identifier: dist + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: trajectories + - orderby_clause: + - keyword: ORDER + - keyword: BY + - expression: + - column_reference: + - naked_identifier: tr + - binary_operator: '|=|' + - psql_variable: + - colon: ':' + - parameter: qt + - limit_clause: + - keyword: LIMIT + - numeric_literal: '5' + - end_bracket: ) + - alias_expression: + - naked_identifier: foo +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: tlid + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: mtfcc + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: geom + - binary_operator: <#> + - function: + - function_name: + - function_name_identifier: ST_GeomFromText + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: "'LINESTRING(746149 2948672,745954 2948576,\n\t\t745787 2948499,745740 2948468,745712 2948438,\n\t\t745690 2948384,745677 2948319)'" + - comma: ',' + - expression: + - numeric_literal: '2249' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: As + - naked_identifier: b_dist + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: ST_Distance + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: geom + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: ST_GeomFromText + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: "'LINESTRING(746149 2948672,745954 2948576,\n\t\t745787 2948499,745740 2948468,745712 2948438,\n\t\t745690 2948384,745677 2948319)'" + - comma: ',' + - expression: + - numeric_literal: '2249' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: As + - naked_identifier: act_dist + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bos_roads + - alias_expression: + - alias_operator: + - keyword: As + - naked_identifier: b + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: b_dist + - comma: ',' + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: tlid + - limit_clause: + - keyword: LIMIT + - numeric_literal: '100' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: As + - naked_identifier: foo + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: act_dist + - comma: ',' + - column_reference: + - naked_identifier: tlid + - limit_clause: + - keyword: LIMIT + - numeric_literal: '10' +- statement_terminator: ; +- statement: + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: index_query + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: ST_Distance + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: geom + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''SRID=3005;POINT(1011102 450541)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: d + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: edabbr + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: vaabbr + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: va2005 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - expression: + - column_reference: + - naked_identifier: geom + - binary_operator: <<->> + - cast_expression: + - quoted_literal: '''SRID=3005;POINT(1011102 450541)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - limit_clause: + - keyword: LIMIT + - numeric_literal: '100' + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: index_query + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: d + - limit_clause: + - keyword: limit + - numeric_literal: '10' +- statement_terminator: ; +- statement: + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: index_query + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: ST_Distance + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: geom + - comma: ',' + - expression: + - cast_expression: + - quoted_literal: '''SRID=3005;POINT(1011102 450541)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: d + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: edabbr + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: vaabbr + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: va2005 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - expression: + - column_reference: + - naked_identifier: geom + - binary_operator: <<#>> + - cast_expression: + - quoted_literal: '''SRID=3005;POINT(1011102 450541)''' + - casting_operator: '::' + - data_type: + - data_type_identifier: geometry + - limit_clause: + - keyword: LIMIT + - numeric_literal: '100' + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: index_query + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: d + - limit_clause: + - keyword: limit + - numeric_literal: '10' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/prepare.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/prepare.sql new file mode 100644 index 000000000..b9e0ba3e2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/prepare.sql @@ -0,0 +1,27 @@ +PREPARE select_statement AS +SELECT * FROM table1; + +PREPARE insert_statement AS +INSERT INTO table1 (col1, col2) VALUES (1, 'foo'); + +PREPARE update_statement AS +UPDATE table1 SET col2 = 'bar' WHERE col1 = 1; + +PREPARE delete_statement AS +DELETE FROM table1 WHERE col1 = 1; + +PREPARE values_statement AS +VALUES (1, 'foo'); + +PREPARE merge_statement AS +MERGE INTO table1 USING table2 ON (table1.col1 = table2.col1) +WHEN MATCHED THEN +UPDATE SET col1 = table2.col1, col2 = table2.col2 +WHEN NOT MATCHED THEN +INSERT (col1, col2) VALUES (table2.col1, table2.col2); + +PREPARE parametrized_statement_1 (int) AS +VALUES ($1); + +PREPARE parametrized_statement_2 (int, character(3)) AS +VALUES ($1, $2); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/prepare.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/prepare.yml new file mode 100644 index 000000000..24ea322d7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/prepare.yml @@ -0,0 +1,255 @@ +file: +- statement: + - prepare_statement: + - keyword: PREPARE + - object_reference: + - naked_identifier: select_statement + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - prepare_statement: + - keyword: PREPARE + - object_reference: + - naked_identifier: insert_statement + - keyword: AS + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: table1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - quoted_literal: '''foo''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - prepare_statement: + - keyword: PREPARE + - object_reference: + - naked_identifier: update_statement + - keyword: AS + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: table1 + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''bar''' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - prepare_statement: + - keyword: PREPARE + - object_reference: + - naked_identifier: delete_statement + - keyword: AS + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - prepare_statement: + - keyword: PREPARE + - object_reference: + - naked_identifier: values_statement + - keyword: AS + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - quoted_literal: '''foo''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - prepare_statement: + - keyword: PREPARE + - object_reference: + - naked_identifier: merge_statement + - keyword: AS + - merge_statement: + - keyword: MERGE + - keyword: INTO + - table_reference: + - naked_identifier: table1 + - keyword: USING + - table_reference: + - naked_identifier: table2 + - join_on_condition: + - keyword: ON + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: table2 + - dot: . + - naked_identifier: col1 + - end_bracket: ) + - merge_match: + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: THEN + - merge_update_clause: + - keyword: UPDATE + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: table2 + - dot: . + - naked_identifier: col1 + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: table2 + - dot: . + - naked_identifier: col2 + - merge_when_not_matched_clause: + - keyword: WHEN + - keyword: NOT + - keyword: MATCHED + - keyword: THEN + - merge_insert_clause: + - keyword: INSERT + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: table2 + - dot: . + - naked_identifier: col1 + - comma: ',' + - expression: + - column_reference: + - naked_identifier: table2 + - dot: . + - naked_identifier: col2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - prepare_statement: + - keyword: PREPARE + - object_reference: + - naked_identifier: parametrized_statement_1 + - bracketed: + - start_bracket: ( + - data_type: + - keyword: int + - end_bracket: ) + - keyword: AS + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - dollar_numeric_literal: $1 + - end_bracket: ) +- statement_terminator: ; +- statement: + - prepare_statement: + - keyword: PREPARE + - object_reference: + - naked_identifier: parametrized_statement_2 + - bracketed: + - start_bracket: ( + - data_type: + - keyword: int + - comma: ',' + - data_type: + - keyword: character + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '3' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - dollar_numeric_literal: $1 + - comma: ',' + - expression: + - dollar_numeric_literal: $2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/psql_variable.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/psql_variable.yml index bff2c4ce8..9f9542cee 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/psql_variable.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/psql_variable.yml @@ -6,7 +6,8 @@ file: - select_clause_element: - quoted_literal: '''from''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: direction - comma: ',' - select_clause_element: @@ -127,7 +128,8 @@ file: - select_clause_element: - quoted_literal: '''from''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: direction - comma: ',' - select_clause_element: diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/range_operators.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/range_operators.yml index 1ad21a7e8..f2bc58cac 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/range_operators.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/range_operators.yml @@ -16,7 +16,8 @@ file: - dot: . - naked_identifier: id - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: paragraph_id - from_clause: - keyword: FROM @@ -84,7 +85,7 @@ file: - naked_identifier: word - dot: . - naked_identifier: character_range - - comparison_operator: + - binary_operator: - raw_comparison_operator: < - raw_comparison_operator: < - column_reference: @@ -96,7 +97,7 @@ file: - naked_identifier: word - dot: . - naked_identifier: character_range - - comparison_operator: + - binary_operator: - raw_comparison_operator: '>' - raw_comparison_operator: '>' - column_reference: diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/reindex.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/reindex.yml index 0ec3c1dcf..8bfaf9711 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/reindex.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/reindex.yml @@ -3,7 +3,7 @@ file: - reindex_statement_segment: - keyword: REINDEX - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: my_index - statement_terminator: ; - statement: @@ -53,7 +53,6 @@ file: - boolean_literal: 'TRUE' - end_bracket: ) - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/reset_session_authorization.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/reset_session_authorization.sql new file mode 100644 index 000000000..c8bfebe9c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/reset_session_authorization.sql @@ -0,0 +1 @@ +RESET SESSION AUTHORIZATION; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/reset_session_authorization.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/reset_session_authorization.yml new file mode 100644 index 000000000..7161df1e7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/reset_session_authorization.yml @@ -0,0 +1,7 @@ +file: +- statement: + - reset_session_authorization_statement: + - keyword: RESET + - keyword: SESSION + - keyword: AUTHORIZATION +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/security_label.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/security_label.sql new file mode 100644 index 000000000..de19fca7f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/security_label.sql @@ -0,0 +1,6 @@ +SECURITY LABEL FOR selinux ON TABLE mytable IS 'system_u:object_r:sepgsql_table_t:s0'; +SECURITY LABEL FOR selinux ON TABLE mytable IS NULL; +SECURITY LABEL ON FUNCTION show_credit(int) IS 'system_u:object_r:sepgsql_trusted_proc_exec_t:s0'; +SECURITY LABEL ON COLUMN customer.credit IS 'system_u:object_r:sepgsql_secret_table_t:s0'; +SECURITY LABEL FOR anon ON ROLE skynet IS 'MASKED'; +SECURITY LABEL FOR anon ON COLUMN customer.first_name IS 'MASKED WITH FUNCTION anon.dummy_first_name()'; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/security_label.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/security_label.yml new file mode 100644 index 000000000..eb1ca30ed --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/security_label.yml @@ -0,0 +1,88 @@ +file: +- statement: + - security_label_statement: + - keyword: SECURITY + - keyword: LABEL + - keyword: FOR + - object_reference: + - naked_identifier: selinux + - keyword: ON + - keyword: TABLE + - table_reference: + - naked_identifier: mytable + - keyword: IS + - quoted_literal: '''system_u:object_r:sepgsql_table_t:s0''' +- statement_terminator: ; +- statement: + - security_label_statement: + - keyword: SECURITY + - keyword: LABEL + - keyword: FOR + - object_reference: + - naked_identifier: selinux + - keyword: ON + - keyword: TABLE + - table_reference: + - naked_identifier: mytable + - keyword: IS + - keyword: 'NULL' +- statement_terminator: ; +- statement: + - security_label_statement: + - keyword: SECURITY + - keyword: LABEL + - keyword: ON + - keyword: FUNCTION + - function_name: + - function_name_identifier: show_credit + - bracketed: + - start_bracket: ( + - data_type: + - keyword: int + - end_bracket: ) + - keyword: IS + - quoted_literal: '''system_u:object_r:sepgsql_trusted_proc_exec_t:s0''' +- statement_terminator: ; +- statement: + - security_label_statement: + - keyword: SECURITY + - keyword: LABEL + - keyword: ON + - keyword: COLUMN + - column_reference: + - naked_identifier: customer + - dot: . + - naked_identifier: credit + - keyword: IS + - quoted_literal: '''system_u:object_r:sepgsql_secret_table_t:s0''' +- statement_terminator: ; +- statement: + - security_label_statement: + - keyword: SECURITY + - keyword: LABEL + - keyword: FOR + - object_reference: + - naked_identifier: anon + - keyword: ON + - keyword: ROLE + - role_reference: + - naked_identifier: skynet + - keyword: IS + - quoted_literal: '''MASKED''' +- statement_terminator: ; +- statement: + - security_label_statement: + - keyword: SECURITY + - keyword: LABEL + - keyword: FOR + - object_reference: + - naked_identifier: anon + - keyword: ON + - keyword: COLUMN + - column_reference: + - naked_identifier: customer + - dot: . + - naked_identifier: first_name + - keyword: IS + - quoted_literal: '''MASKED WITH FUNCTION anon.dummy_first_name()''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select.sql index eadbef4cf..392d157b4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select.sql @@ -78,8 +78,9 @@ SELECT col1, col2 FROM mytable1 JOIN mytable2 ON col1 = col2 ORDER BY sync_time ASC +LIMIT 1 FOR SHARE OF mytable1, mytable2 SKIP LOCKED -LIMIT 1; +; Select * from foo TABLESAMPLE SYSTEM (10); @@ -89,3 +90,19 @@ Select * from foo TABLESAMPLE BERNOULLI (10); SELECT * FROM (SELECT * FROM mytable FOR UPDATE) ss WHERE col1 = $1; SELECT i + $1 INTO j from foo; + +SELECT 1 /* hi hi /* foo */ ho ho */ AS bar; + +-- escape double quotes +SELECT """t".col1 FROM tbl1 AS """t"; + +SELECT + film_id, + title +FROM + film +ORDER BY + title +FETCH FIRST 10 ROW ONLY; + +SELECT foo FROM bar LIMIT 1 FOR UPDATE; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select.yml index 07a531a47..38f2c4e8a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select.yml @@ -417,8 +417,8 @@ file: - join_clause: - keyword: CROSS - keyword: JOIN - - keyword: LATERAL - from_expression_element: + - keyword: LATERAL - table_expression: - function: - function_name: @@ -433,7 +433,8 @@ file: - naked_identifier: columnb - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - bracketed: - start_bracket: ( @@ -599,7 +600,7 @@ file: - column_reference: - naked_identifier: periods - dot: . - - naked_identifier: end + - naked_identifier_all: end - from_clause: - keyword: from - from_expression: @@ -779,6 +780,9 @@ file: - column_reference: - naked_identifier: sync_time - keyword: ASC + - limit_clause: + - keyword: LIMIT + - numeric_literal: '1' - for_clause: - keyword: FOR - keyword: SHARE @@ -790,9 +794,6 @@ file: - naked_identifier: mytable2 - keyword: SKIP - keyword: LOCKED - - limit_clause: - - keyword: LIMIT - - numeric_literal: '1' - statement_terminator: ; - statement: - select_statement: @@ -906,3 +907,86 @@ file: - table_reference: - naked_identifier: foo - statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: bar +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '"""t"' + - dot: . + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '"""t"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: film_id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: title + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: film + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: title + - fetch_clause: + - keyword: FETCH + - keyword: FIRST + - numeric_literal: '10' + - keyword: ROW + - keyword: ONLY +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: foo + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar + - limit_clause: + - keyword: LIMIT + - numeric_literal: '1' + - for_clause: + - keyword: FOR + - keyword: UPDATE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_case_cast.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_case_cast.yml index ff4893a7f..917cbaec6 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_case_cast.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_case_cast.yml @@ -31,7 +31,8 @@ file: - data_type: - keyword: text - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: mycol - from_clause: - keyword: from @@ -76,7 +77,8 @@ file: - data_type: - keyword: float - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: mycol - from_clause: - keyword: from @@ -124,7 +126,8 @@ file: - keyword: text - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: mycol - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_frame_clause.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_frame_clause.yml index 5cf9c7dfd..6ed2e34e4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_frame_clause.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_frame_clause.yml @@ -55,7 +55,8 @@ file: - keyword: following - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: col_name - from_clause: - keyword: from @@ -155,12 +156,14 @@ file: - frame_clause: - keyword: RANGE - keyword: BETWEEN - - keyword: INTERVAL - - quoted_literal: '''1 YEAR - 1 DAYS''' + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''1 YEAR - 1 DAYS''' - keyword: PRECEDING - keyword: AND - - keyword: INTERVAL - - quoted_literal: '''15 DAYS''' + - interval_expression: + - keyword: INTERVAL + - quoted_literal: '''15 DAYS''' - keyword: PRECEDING - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_natural_join.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_natural_join.sql new file mode 100644 index 000000000..eece92c56 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_natural_join.sql @@ -0,0 +1,31 @@ +SELECT * +FROM table1 +NATURAL JOIN table2; + +SELECT * +FROM table1 +NATURAL INNER JOIN table2; + +SELECT * +FROM table1 +NATURAL LEFT JOIN table2; + +SELECT * +FROM table1 +NATURAL LEFT OUTER JOIN table2; + +SELECT * +FROM table1 +NATURAL RIGHT JOIN table2; + +SELECT * +FROM table1 +NATURAL RIGHT OUTER JOIN table2; + +SELECT * +FROM table1 +NATURAL FULL JOIN table2; + +SELECT * +FROM table1 +NATURAL FULL OUTER JOIN table2; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_natural_join.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_natural_join.yml new file mode 100644 index 000000000..e95b1d113 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_natural_join.yml @@ -0,0 +1,195 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - join_clause: + - keyword: NATURAL + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - join_clause: + - keyword: NATURAL + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - join_clause: + - keyword: NATURAL + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - join_clause: + - keyword: NATURAL + - keyword: LEFT + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - join_clause: + - keyword: NATURAL + - keyword: RIGHT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - join_clause: + - keyword: NATURAL + - keyword: RIGHT + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - join_clause: + - keyword: NATURAL + - keyword: FULL + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - join_clause: + - keyword: NATURAL + - keyword: FULL + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_offset.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_offset.sql new file mode 100644 index 000000000..7440541d6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_offset.sql @@ -0,0 +1,5 @@ +SELECT * FROM test OFFSET 10; + +SELECT * FROM test LIMIT 20 OFFSET 10; + +SELECT 1 FROM course_permissions AS cp WHERE cp.course_id = 4 OFFSET 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_offset.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_offset.yml new file mode 100644 index 000000000..097105d6f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_offset.yml @@ -0,0 +1,72 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test + - offset_clause: + - keyword: OFFSET + - numeric_literal: '10' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test + - limit_clause: + - keyword: LIMIT + - numeric_literal: '20' + - keyword: OFFSET + - numeric_literal: '10' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: course_permissions + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: cp + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: cp + - dot: . + - naked_identifier: course_id + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '4' + - offset_clause: + - keyword: OFFSET + - numeric_literal: '1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_ordered_nested_sets.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_ordered_nested_sets.sql new file mode 100644 index 000000000..98cb5b6fc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_ordered_nested_sets.sql @@ -0,0 +1,13 @@ +( + SELECT * FROM tbl1 + EXCEPT + SELECT * FROM tbl2 +) +UNION ALL +( + SELECT * FROM tbl2 + EXCEPT + SELECT * FROM tbl1 + ORDER BY column_1 +) +ORDER BY column_2; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_ordered_nested_sets.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_ordered_nested_sets.yml new file mode 100644 index 000000000..577e54d5f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_ordered_nested_sets.yml @@ -0,0 +1,85 @@ +file: +- statement: + - set_expression: + - bracketed: + - start_bracket: ( + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 + - set_operator: + - keyword: EXCEPT + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl2 + - end_bracket: ) + - set_operator: + - keyword: UNION + - keyword: ALL + - bracketed: + - start_bracket: ( + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl2 + - set_operator: + - keyword: EXCEPT + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: column_1 + - end_bracket: ) + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: column_2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_utf8.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_utf8.sql new file mode 100644 index 000000000..1394c435e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_utf8.sql @@ -0,0 +1,32 @@ +-- Postgres should work with Unicode identifiers in various places + +SELECT größe, länge FROM measurements; + +SELECT + width AS größe, + height AS höhe +FROM dimensions; + +SELECT 'Não' reativação FROM table1; + +SELECT αλφα, βητα, γαμμα FROM greek_letters; + +SELECT москва, санкт_петербург FROM cities; + +SELECT field1 AS 名前 FROM users; + +SELECT + id, + größe, + description +FROM products; + +WITH größen AS ( + SELECT * FROM base_table +) +SELECT * FROM größen; + +CREATE TABLE größen ( + länge INTEGER, + breite INTEGER +); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_utf8.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_utf8.yml new file mode 100644 index 000000000..e8f8bc7f8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/select_utf8.yml @@ -0,0 +1,204 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: größe + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: länge + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: measurements +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: width + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: größe + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: height + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: höhe + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dimensions +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''Não''' + - alias_expression: + - naked_identifier: reativação + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: αλφα + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: βητα + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: γαμμα + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: greek_letters +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: москва + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: санкт_петербург + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: cities +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: field1 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: 名前 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: users +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: größe + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: description + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: products +- statement_terminator: ; +- statement: + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: größen + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: base_table + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: größen +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: größen + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: länge + - data_type: + - keyword: INTEGER + - comma: ',' + - column_definition: + - naked_identifier: breite + - data_type: + - keyword: INTEGER + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_constraints.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_constraints.sql new file mode 100644 index 000000000..11aa9406f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_constraints.sql @@ -0,0 +1,3 @@ +SET CONSTRAINTS ALL DEFERRED; +SET CONSTRAINTS ALL IMMEDIATE; +SET CONSTRAINTS pk1, uk1 DEFERRED; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_constraints.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_constraints.yml new file mode 100644 index 000000000..ce22e5e6d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_constraints.yml @@ -0,0 +1,26 @@ +file: +- statement: + - set_constraint_statement: + - keyword: SET + - keyword: CONSTRAINTS + - keyword: ALL + - keyword: DEFERRED +- statement_terminator: ; +- statement: + - set_constraint_statement: + - keyword: SET + - keyword: CONSTRAINTS + - keyword: ALL + - keyword: IMMEDIATE +- statement_terminator: ; +- statement: + - set_constraint_statement: + - keyword: SET + - keyword: CONSTRAINTS + - object_reference: + - naked_identifier: pk1 + - comma: ',' + - object_reference: + - naked_identifier: uk1 + - keyword: DEFERRED +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_session_authorization.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_session_authorization.sql new file mode 100644 index 000000000..ab3d1a61a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_session_authorization.sql @@ -0,0 +1,5 @@ +SET SESSION AUTHORIZATION DEFAULT; +SET SESSION AUTHORIZATION my_user; +SET SESSION AUTHORIZATION "my_user"; +SET SESSION SESSION AUTHORIZATION my_user; +SET LOCAL SESSION AUTHORIZATION my_user; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_session_authorization.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_session_authorization.yml new file mode 100644 index 000000000..fcf7bad00 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/set_session_authorization.yml @@ -0,0 +1,42 @@ +file: +- statement: + - set_session_authorization_statement: + - keyword: SET + - keyword: SESSION + - keyword: AUTHORIZATION + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - set_session_authorization_statement: + - keyword: SET + - keyword: SESSION + - keyword: AUTHORIZATION + - role_reference: + - naked_identifier: my_user +- statement_terminator: ; +- statement: + - set_session_authorization_statement: + - keyword: SET + - keyword: SESSION + - keyword: AUTHORIZATION + - role_reference: + - quoted_identifier: '"my_user"' +- statement_terminator: ; +- statement: + - set_session_authorization_statement: + - keyword: SET + - keyword: SESSION + - keyword: SESSION + - keyword: AUTHORIZATION + - role_reference: + - naked_identifier: my_user +- statement_terminator: ; +- statement: + - set_session_authorization_statement: + - keyword: SET + - keyword: LOCAL + - keyword: SESSION + - keyword: AUTHORIZATION + - role_reference: + - naked_identifier: my_user +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/show.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/show.sql new file mode 100644 index 000000000..8ac59fa81 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/show.sql @@ -0,0 +1,8 @@ +SHOW ALL; +SHOW IS_SUPERUSER; +SHOW LC_COLLATE; +SHOW LC_CTYPE; +SHOW SERVER_ENCODING; +SHOW SERVER_VERSION; +SHOW DateStyle; +SHOW geqo; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/show.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/show.yml new file mode 100644 index 000000000..755142f99 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/show.yml @@ -0,0 +1,41 @@ +file: +- statement: + - show_statement: + - keyword: SHOW + - keyword: ALL +- statement_terminator: ; +- statement: + - show_statement: + - keyword: SHOW + - keyword: IS_SUPERUSER +- statement_terminator: ; +- statement: + - show_statement: + - keyword: SHOW + - keyword: LC_COLLATE +- statement_terminator: ; +- statement: + - show_statement: + - keyword: SHOW + - keyword: LC_CTYPE +- statement_terminator: ; +- statement: + - show_statement: + - keyword: SHOW + - keyword: SERVER_ENCODING +- statement_terminator: ; +- statement: + - show_statement: + - keyword: SHOW + - keyword: SERVER_VERSION +- statement_terminator: ; +- statement: + - show_statement: + - keyword: SHOW + - parameter: DateStyle +- statement_terminator: ; +- statement: + - show_statement: + - keyword: SHOW + - parameter: geqo +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/single_quote.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/single_quote.sql index ec4079647..0e7478064 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/single_quote.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/single_quote.sql @@ -29,3 +29,42 @@ SELECT 'foo' SELECT 'foo' -- some comment 'bar'; + +COMMENT ON TABLE "some_table" IS E'' +'This is a valid comment style' +'\n\n' +'which is escaped'; + +SELECT +e'da' --this is a comment +'ta'; + +SELECT +e'value of newline here: +' + 'space ' +'no' +'space'; + +SELECT U&'' +'d\0061t\+000061' +' which has unicode', +U&'d!0061t!+000061' +' which has unicode' UESCAPE '!', +u&'d!0061t!+000061 which has unicode' uescape '!'; + +SELECT b'' +'000' +'010' +'101'; + +SELECT x'1234' +'abcd' +'dead' +'beEF'; + +SELECT e'two ' +'line', +E'can have single quotes escaped this way: \' ', +e'but the second line' +'requires it like this '' \n\n'; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/single_quote.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/single_quote.yml index 88c1f43d6..292d59e1d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/single_quote.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/single_quote.yml @@ -79,3 +79,89 @@ file: - quoted_literal: '''foo''' - quoted_literal: '''bar''' - statement_terminator: ; +- statement: + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: TABLE + - table_reference: + - quoted_identifier: '"some_table"' + - keyword: IS + - quoted_literal: E'' + - quoted_literal: '''This is a valid comment style''' + - quoted_literal: '''\n\n''' + - quoted_literal: '''which is escaped''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: e'da' + - quoted_literal: '''ta''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: |- + e'value of newline here: + ' + - quoted_literal: '''space ''' + - quoted_literal: '''no''' + - quoted_literal: '''space''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: U&'' + - quoted_literal: '''d\0061t\+000061''' + - quoted_literal: ''' which has unicode''' + - comma: ',' + - select_clause_element: + - quoted_literal: U&'d!0061t!+000061' + - quoted_literal: ''' which has unicode''' + - keyword: UESCAPE + - code: '''!''' + - comma: ',' + - select_clause_element: + - quoted_literal: u&'d!0061t!+000061 which has unicode' uescape '!' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: b'' + - quoted_literal: '''000''' + - quoted_literal: '''010''' + - quoted_literal: '''101''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: x'1234' + - quoted_literal: '''abcd''' + - quoted_literal: '''dead''' + - quoted_literal: '''beEF''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: e'two ' + - quoted_literal: '''line''' + - comma: ',' + - select_clause_element: + - quoted_literal: 'E''can have single quotes escaped this way: \'' ''' + - comma: ',' + - select_clause_element: + - quoted_literal: e'but the second line' + - quoted_literal: '''requires it like this '''' \n\n''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/string_normalization.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/string_normalization.sql new file mode 100644 index 000000000..8c376c4ef --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/string_normalization.sql @@ -0,0 +1,36 @@ +SELECT (test_column IS NORMALIZED) AS is_normalized FROM test_table; +SELECT (test_column IS NFC NORMALIZED) AS is_normalized FROM test_table; +SELECT (test_column IS NFD NORMALIZED) AS is_normalized FROM test_table; +SELECT (test_column IS NFKC NORMALIZED) AS is_normalized FROM test_table; +SELECT (test_column IS NFKD NORMALIZED) AS is_normalized FROM test_table; +SELECT (test_column IS NOT NORMALIZED) AS is_normalized FROM test_table; +SELECT (test_column IS NOT NFC NORMALIZED) AS is_normalized FROM test_table; +SELECT (test_column IS NOT NFD NORMALIZED) AS is_normalized FROM test_table; +SELECT (test_column IS NOT NFKC NORMALIZED) AS is_normalized FROM test_table; +SELECT (test_column IS NOT NFKD NORMALIZED) AS is_normalized FROM test_table; + +CREATE DOMAIN text_default AS TEXT CHECK (VALUE IS NORMALIZED); +CREATE DOMAIN text_nfc AS TEXT CHECK (VALUE IS NFC NORMALIZED); +CREATE DOMAIN text_nfd AS TEXT CHECK (VALUE IS NFD NORMALIZED); +CREATE DOMAIN text_nfkc AS TEXT CHECK (VALUE IS NFKC NORMALIZED); +CREATE DOMAIN text_nfkd AS TEXT CHECK (VALUE IS NFKD NORMALIZED); +CREATE DOMAIN text_default AS TEXT CHECK (VALUE IS NOT normalized); +CREATE DOMAIN text_nfc AS TEXT CHECK (VALUE IS NOT NFC NORMALIZED); +CREATE DOMAIN text_nfd AS TEXT CHECK (VALUE IS NOT NFD NORMALIZED); +CREATE DOMAIN text_nfkc AS TEXT CHECK (VALUE IS NOT NFKC NORMALIZED); +CREATE DOMAIN text_nfkd AS TEXT CHECK (VALUE IS NOT NFKD NORMALIZED); + + +create table test_table ( + test_column text primary key, + CONSTRAINT default_constraint CHECK (test_column IS NORMALIZED), + CONSTRAINT nfc_constraint CHECK (test_column IS NFC NORMALIZED), + CONSTRAINT nfd_constraint CHECK (test_column IS NFD NORMALIZED), + CONSTRAINT nfkc_constraint CHECK (test_column IS NFKC NORMALIZED), + CONSTRAINT nfkd_constraint CHECK (test_column IS NFKD NORMALIZED), + CONSTRAINT not_default_constraint CHECK (test_column IS NOT NORMALIZED), + CONSTRAINT not_nfc_constraint CHECK (test_column IS NOT NFC NORMALIZED), + CONSTRAINT not_nfd_constraint CHECK (test_column IS NOT NFD NORMALIZED), + CONSTRAINT not_nfkc_constraint CHECK (test_column IS NOT NFKC NORMALIZED), + CONSTRAINT not_nfkd_constraint CHECK (test_column IS NOT NFKD NORMALIZED) +); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/string_normalization.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/string_normalization.yml new file mode 100644 index 000000000..c5258778c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/string_normalization.yml @@ -0,0 +1,657 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NORMALIZED + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: is_normalized + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NFC + - keyword: NORMALIZED + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: is_normalized + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NFD + - keyword: NORMALIZED + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: is_normalized + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NFKC + - keyword: NORMALIZED + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: is_normalized + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NFKD + - keyword: NORMALIZED + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: is_normalized + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NOT + - keyword: NORMALIZED + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: is_normalized + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NOT + - keyword: NFC + - keyword: NORMALIZED + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: is_normalized + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NOT + - keyword: NFD + - keyword: NORMALIZED + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: is_normalized + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NOT + - keyword: NFKC + - keyword: NORMALIZED + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: is_normalized + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NOT + - keyword: NFKD + - keyword: NORMALIZED + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: is_normalized + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test_table +- statement_terminator: ; +- statement: + - create_domain_statement: + - keyword: CREATE + - keyword: DOMAIN + - object_reference: + - naked_identifier: text_default + - keyword: AS + - data_type: + - keyword: TEXT + - keyword: CHECK + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: VALUE + - keyword: IS + - keyword: NORMALIZED + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_domain_statement: + - keyword: CREATE + - keyword: DOMAIN + - object_reference: + - naked_identifier: text_nfc + - keyword: AS + - data_type: + - keyword: TEXT + - keyword: CHECK + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: VALUE + - keyword: IS + - keyword: NFC + - keyword: NORMALIZED + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_domain_statement: + - keyword: CREATE + - keyword: DOMAIN + - object_reference: + - naked_identifier: text_nfd + - keyword: AS + - data_type: + - keyword: TEXT + - keyword: CHECK + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: VALUE + - keyword: IS + - keyword: NFD + - keyword: NORMALIZED + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_domain_statement: + - keyword: CREATE + - keyword: DOMAIN + - object_reference: + - naked_identifier: text_nfkc + - keyword: AS + - data_type: + - keyword: TEXT + - keyword: CHECK + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: VALUE + - keyword: IS + - keyword: NFKC + - keyword: NORMALIZED + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_domain_statement: + - keyword: CREATE + - keyword: DOMAIN + - object_reference: + - naked_identifier: text_nfkd + - keyword: AS + - data_type: + - keyword: TEXT + - keyword: CHECK + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: VALUE + - keyword: IS + - keyword: NFKD + - keyword: NORMALIZED + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_domain_statement: + - keyword: CREATE + - keyword: DOMAIN + - object_reference: + - naked_identifier: text_default + - keyword: AS + - data_type: + - keyword: TEXT + - keyword: CHECK + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: VALUE + - keyword: IS + - keyword: NOT + - keyword: normalized + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_domain_statement: + - keyword: CREATE + - keyword: DOMAIN + - object_reference: + - naked_identifier: text_nfc + - keyword: AS + - data_type: + - keyword: TEXT + - keyword: CHECK + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: VALUE + - keyword: IS + - keyword: NOT + - keyword: NFC + - keyword: NORMALIZED + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_domain_statement: + - keyword: CREATE + - keyword: DOMAIN + - object_reference: + - naked_identifier: text_nfd + - keyword: AS + - data_type: + - keyword: TEXT + - keyword: CHECK + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: VALUE + - keyword: IS + - keyword: NOT + - keyword: NFD + - keyword: NORMALIZED + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_domain_statement: + - keyword: CREATE + - keyword: DOMAIN + - object_reference: + - naked_identifier: text_nfkc + - keyword: AS + - data_type: + - keyword: TEXT + - keyword: CHECK + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: VALUE + - keyword: IS + - keyword: NOT + - keyword: NFKC + - keyword: NORMALIZED + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_domain_statement: + - keyword: CREATE + - keyword: DOMAIN + - object_reference: + - naked_identifier: text_nfkd + - keyword: AS + - data_type: + - keyword: TEXT + - keyword: CHECK + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: VALUE + - keyword: IS + - keyword: NOT + - keyword: NFKD + - keyword: NORMALIZED + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: create + - keyword: table + - table_reference: + - naked_identifier: test_table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: test_column + - data_type: + - keyword: text + - column_constraint_segment: + - keyword: primary + - keyword: key + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: default_constraint + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NORMALIZED + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: nfc_constraint + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NFC + - keyword: NORMALIZED + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: nfd_constraint + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NFD + - keyword: NORMALIZED + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: nfkc_constraint + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NFKC + - keyword: NORMALIZED + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: nfkd_constraint + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NFKD + - keyword: NORMALIZED + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: not_default_constraint + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NOT + - keyword: NORMALIZED + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: not_nfc_constraint + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NOT + - keyword: NFC + - keyword: NORMALIZED + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: not_nfd_constraint + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NOT + - keyword: NFD + - keyword: NORMALIZED + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: not_nfkc_constraint + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NOT + - keyword: NFKC + - keyword: NORMALIZED + - end_bracket: ) + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: not_nfkd_constraint + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: test_column + - keyword: IS + - keyword: NOT + - keyword: NFKD + - keyword: NORMALIZED + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/subquery.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/subquery.yml index 2cf260838..7e9c27787 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/subquery.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/subquery.yml @@ -49,7 +49,8 @@ file: - naked_identifier: table2 - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: temp3 - join_on_condition: - keyword: ON diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/substring.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/substring.sql new file mode 100644 index 000000000..756ab3950 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/substring.sql @@ -0,0 +1,5 @@ +select * FROM substring('Thomas' from 2 for 3); +select * FROM substring('Thomas' from 3); +select * FROM substring('Thomas' for 2); +select * FROM substring('Thomas' similar '%#"o_a#"_' escape '#'); +select * FROM substring('Thomas' from '...$'); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/substring.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/substring.yml new file mode 100644 index 000000000..7a918b5ef --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/substring.yml @@ -0,0 +1,139 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: substring + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''Thomas''' + - keyword: from + - expression: + - numeric_literal: '2' + - keyword: for + - expression: + - numeric_literal: '3' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: substring + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''Thomas''' + - keyword: from + - expression: + - numeric_literal: '3' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: substring + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''Thomas''' + - keyword: for + - expression: + - numeric_literal: '2' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: substring + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''Thomas''' + - expression: + - data_type: + - data_type_identifier: similar + - quoted_literal: '''%#"o_a#"_''' + - expression: + - data_type: + - data_type_identifier: escape + - quoted_literal: '''#''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: substring + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''Thomas''' + - keyword: from + - expression: + - quoted_literal: '''...$''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/table_functions.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/table_functions.sql index 9743f85f3..1eb8c74ef 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/table_functions.sql +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/table_functions.sql @@ -5,3 +5,9 @@ select * from unnest(array['123', '456']) as a(val, row_num); select * from unnest(array['123', '456']) with ordinality; select * from unnest(array['123', '456']) with ordinality as a(val, row_num); + +SELECT * FROM table_1 +WHERE utc_activity_start_dttm + make_interval(mins := activity_dur_mnt) + BETWEEN '2024-01-07T00:00:00'::timestamp AND '2024-01-14T23:59:59.999999'::timestamp; + +SELECT ARRAY(SELECT UNNEST(list_field_1) INTERSECT SELECT UNNEST(list_field_2)) FROM table_1; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/table_functions.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/table_functions.yml index c9d89fd62..41d01820c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/table_functions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/table_functions.yml @@ -61,7 +61,8 @@ file: - end_square_bracket: ']' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: a - bracketed: - start_bracket: ( @@ -137,7 +138,8 @@ file: - keyword: with - keyword: ordinality - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: a - bracketed: - start_bracket: ( @@ -147,3 +149,103 @@ file: - naked_identifier: row_num - end_bracket: ) - statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table_1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: utc_activity_start_dttm + - binary_operator: + + - function: + - function_name: + - function_name_identifier: make_interval + - function_contents: + - bracketed: + - start_bracket: ( + - named_argument: + - naked_identifier: mins + - assignment_operator: := + - expression: + - column_reference: + - naked_identifier: activity_dur_mnt + - end_bracket: ) + - keyword: BETWEEN + - cast_expression: + - quoted_literal: '''2024-01-07T00:00:00''' + - casting_operator: '::' + - data_type: + - datetime_type_identifier: + - keyword: timestamp + - keyword: AND + - cast_expression: + - quoted_literal: '''2024-01-14T23:59:59.999999''' + - casting_operator: '::' + - data_type: + - datetime_type_identifier: + - keyword: timestamp +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: UNNEST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: list_field_1 + - end_bracket: ) + - set_operator: + - keyword: INTERSECT + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: UNNEST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: list_field_2 + - end_bracket: ) + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table_1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/unicode_double_quote.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/unicode_double_quote.yml index 184b056e0..dd171a648 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/unicode_double_quote.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/unicode_double_quote.yml @@ -5,7 +5,7 @@ file: - keyword: SELECT - select_clause_element: - column_reference: - - quoted_literal: U&"a" + - quoted_identifier: U&"a" - statement_terminator: ; - statement: - select_statement: @@ -13,7 +13,7 @@ file: - keyword: SELECT - select_clause_element: - column_reference: - - quoted_literal: U&"aaaa" UESCAPE '!' + - quoted_identifier: U&"aaaa" UESCAPE '!' - statement_terminator: ; - statement: - select_statement: @@ -21,7 +21,7 @@ file: - keyword: SELECT - select_clause_element: - column_reference: - - quoted_literal: |- + - quoted_identifier: |- U&"aaaa" UESCAPE diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/update_table.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/update_table.yml index 6208dde75..8ec16e5a3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/update_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/update_table.yml @@ -548,6 +548,7 @@ file: - column_reference: - naked_identifier: short_name - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: employee_name - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/values_alias.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/values_alias.yml index 6d17dc87e..5921a521d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/values_alias.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/values_alias.yml @@ -35,7 +35,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - bracketed: - start_bracket: ( diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/values_in_subquery.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/values_in_subquery.yml index c73d7ff0f..7c552d717 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/values_in_subquery.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/values_in_subquery.yml @@ -76,7 +76,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t - bracketed: - start_bracket: ( @@ -120,7 +121,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t - bracketed: - start_bracket: ( diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/variadic.sql b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/variadic.sql new file mode 100644 index 000000000..4a092eb62 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/variadic.sql @@ -0,0 +1,53 @@ +CREATE FUNCTION mleast(VARIADIC arr numeric[]) RETURNS numeric AS $$ + SELECT min($1[i]) FROM generate_subscripts($1, 1) g(i); +$$ LANGUAGE SQL; + +SELECT mleast(VARIADIC ARRAY[10, -1, 5, 4.4]); + +SELECT mleast(VARIADIC ARRAY[]::numeric[]); + +SELECT mleast(VARIADIC arr := ARRAY[10, -1, 5, 4.4]); + +CREATE FUNCTION anyleast (VARIADIC anyarray) RETURNS anyelement AS $$ + SELECT min($1[i]) FROM generate_subscripts($1, 1) g(i); +$$ LANGUAGE SQL; + +CREATE FUNCTION concat_values(text, VARIADIC anyarray) RETURNS text AS $$ + SELECT array_to_string($2, $1); +$$ LANGUAGE SQL; + +SELECT my_function(other_function( + VARIADIC ARRAY_REMOVE(ARRAY[ + a.value1, + b.value2, + c.value3 + ], NULL) +)) +FROM a +FULL OUTER JOIN b USING (id) +FULL OUTER JOIN c USING (id); + +SELECT json_extract_path_text(t.col::json, VARIADIC ARRAY['foo'::text]) +FROM t; + +SELECT my_function(VARIADIC ARRAY[ + CASE WHEN x > 0 THEN x ELSE 0 END, + y + z, + 'literal' +]); + +SELECT my_function(VARIADIC ARRAY(SELECT value FROM table1)); + +SELECT my_function(VARIADIC param_name = ARRAY[1, 2, 3]); + +SELECT my_function( + regular_param = 'value', + VARIADIC variadic_param = ARRAY[1, 2, 3] +); + +SELECT my_function(VARIADIC param_name => ARRAY[1, 2, 3]); + +SELECT my_function( + regular_param => 'value', + VARIADIC variadic_param => ARRAY[1, 2, 3] +); diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/variadic.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/variadic.yml new file mode 100644 index 000000000..3fb6b0095 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/variadic.yml @@ -0,0 +1,522 @@ +file: +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - function_name_identifier: mleast + - function_parameter_list: + - bracketed: + - start_bracket: ( + - keyword: VARIADIC + - parameter: arr + - data_type: + - keyword: numeric + - start_square_bracket: '[' + - end_square_bracket: ']' + - end_bracket: ) + - keyword: RETURNS + - data_type: + - keyword: numeric + - function_definition: + - keyword: AS + - quoted_literal: |- + $$ + SELECT min($1[i]) FROM generate_subscripts($1, 1) g(i); + $$ + - language_clause: + - keyword: LANGUAGE + - naked_identifier: SQL +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: mleast + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - typed_array_literal: + - keyword: VARIADIC + - array_type: + - keyword: ARRAY + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '10' + - comma: ',' + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '4.4' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: mleast + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - cast_expression: + - typed_array_literal: + - keyword: VARIADIC + - array_type: + - keyword: ARRAY + - array_literal: + - start_square_bracket: '[' + - end_square_bracket: ']' + - casting_operator: '::' + - data_type: + - keyword: numeric + - start_square_bracket: '[' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: mleast + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - typed_array_literal: + - keyword: VARIADIC + - naked_identifier: arr + - assignment_operator: := + - array_type: + - keyword: ARRAY + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '10' + - comma: ',' + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '4.4' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - function_name_identifier: anyleast + - function_parameter_list: + - bracketed: + - start_bracket: ( + - keyword: VARIADIC + - data_type: + - data_type_identifier: anyarray + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: anyelement + - function_definition: + - keyword: AS + - quoted_literal: |- + $$ + SELECT min($1[i]) FROM generate_subscripts($1, 1) g(i); + $$ + - language_clause: + - keyword: LANGUAGE + - naked_identifier: SQL +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - function_name: + - function_name_identifier: concat_values + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: text + - comma: ',' + - keyword: VARIADIC + - data_type: + - data_type_identifier: anyarray + - end_bracket: ) + - keyword: RETURNS + - data_type: + - keyword: text + - function_definition: + - keyword: AS + - quoted_literal: |- + $$ + SELECT array_to_string($2, $1); + $$ + - language_clause: + - keyword: LANGUAGE + - naked_identifier: SQL +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: my_function + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: other_function + - function_contents: + - bracketed: + - start_bracket: ( + - keyword: VARIADIC + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY_REMOVE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - typed_array_literal: + - array_type: + - keyword: ARRAY + - array_literal: + - start_square_bracket: '[' + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: value1 + - comma: ',' + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: value2 + - comma: ',' + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: value3 + - end_square_bracket: ']' + - comma: ',' + - expression: + - null_literal: 'NULL' + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: a + - join_clause: + - keyword: FULL + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: b + - keyword: USING + - bracketed: + - start_bracket: ( + - naked_identifier: id + - end_bracket: ) + - join_clause: + - keyword: FULL + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: c + - keyword: USING + - bracketed: + - start_bracket: ( + - naked_identifier: id + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: json_extract_path_text + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - cast_expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col + - casting_operator: '::' + - data_type: + - keyword: json + - comma: ',' + - expression: + - typed_array_literal: + - keyword: VARIADIC + - array_type: + - keyword: ARRAY + - array_literal: + - start_square_bracket: '[' + - expression: + - cast_expression: + - quoted_literal: '''foo''' + - casting_operator: '::' + - data_type: + - keyword: text + - end_square_bracket: ']' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: my_function + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - typed_array_literal: + - keyword: VARIADIC + - array_type: + - keyword: ARRAY + - array_literal: + - start_square_bracket: '[' + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' + - keyword: THEN + - expression: + - column_reference: + - naked_identifier: x + - else_clause: + - keyword: ELSE + - expression: + - numeric_literal: '0' + - keyword: END + - comma: ',' + - expression: + - column_reference: + - naked_identifier: y + - binary_operator: + + - column_reference: + - naked_identifier: z + - comma: ',' + - quoted_literal: '''literal''' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: my_function + - function_contents: + - bracketed: + - start_bracket: ( + - keyword: VARIADIC + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: value + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: my_function + - function_contents: + - bracketed: + - start_bracket: ( + - keyword: VARIADIC + - expression: + - column_reference: + - naked_identifier: param_name + - comparison_operator: + - raw_comparison_operator: = + - typed_array_literal: + - array_type: + - keyword: ARRAY + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: my_function + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: regular_param + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value''' + - comma: ',' + - keyword: VARIADIC + - expression: + - column_reference: + - naked_identifier: variadic_param + - comparison_operator: + - raw_comparison_operator: = + - typed_array_literal: + - array_type: + - keyword: ARRAY + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: my_function + - function_contents: + - bracketed: + - start_bracket: ( + - keyword: VARIADIC + - named_argument: + - naked_identifier: param_name + - right_arrow: => + - expression: + - typed_array_literal: + - array_type: + - keyword: ARRAY + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: my_function + - function_contents: + - bracketed: + - start_bracket: ( + - named_argument: + - naked_identifier: regular_param + - right_arrow: => + - expression: + - quoted_literal: '''value''' + - comma: ',' + - keyword: VARIADIC + - named_argument: + - naked_identifier: variadic_param + - right_arrow: => + - expression: + - typed_array_literal: + - array_type: + - keyword: ARRAY + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/with.yml b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/with.yml index 74671a5ea..c118cf0f1 100644 --- a/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/with.yml +++ b/crates/lib-dialects/test/fixtures/dialects/postgres/sqlfluff/with.yml @@ -38,7 +38,8 @@ file: - table_reference: - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: w1 - join_clause: - keyword: JOIN @@ -47,7 +48,8 @@ file: - table_reference: - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: w2 - join_on_condition: - keyword: ON @@ -113,7 +115,8 @@ file: - table_reference: - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: w1 - join_clause: - keyword: JOIN @@ -122,7 +125,8 @@ file: - table_reference: - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: w2 - join_on_condition: - keyword: ON diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_datashare.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_datashare.yml index 61e4632f1..eb43020b4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_datashare.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_datashare.yml @@ -22,9 +22,8 @@ file: - boolean_literal: 'TRUE' - keyword: FOR - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: public + - schema_reference: + - naked_identifier: public - statement_terminator: ; - statement: - create_datashare_statement: @@ -65,9 +64,8 @@ file: - naked_identifier: salesshare - keyword: ADD - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: public + - schema_reference: + - naked_identifier: public - statement_terminator: ; - statement: - create_datashare_statement: @@ -98,9 +96,8 @@ file: - keyword: TABLES - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: public + - schema_reference: + - naked_identifier: public - statement_terminator: ; - statement: - create_datashare_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_default_privileges.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_default_privileges.yml index d180faf3b..5fcbd06e9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_default_privileges.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_default_privileges.yml @@ -10,9 +10,8 @@ file: - naked_identifier: the_user - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: the_schema + - schema_reference: + - naked_identifier: the_schema - alter_default_privileges_grant: - keyword: GRANT - alter_default_privileges_object_privilege: @@ -36,9 +35,8 @@ file: - naked_identifier: the_user - keyword: IN - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: the_schema + - schema_reference: + - naked_identifier: the_schema - alter_default_privileges_grant: - keyword: GRANT - alter_default_privileges_object_privilege: diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_schema.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_schema.yml index 3ac5e1c11..334b8a0d0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_schema.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_schema.yml @@ -3,22 +3,19 @@ file: - alter_schema_statement: - keyword: ALTER - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: RENAME - keyword: TO - - table_reference: - - object_reference: - - naked_identifier: schema2 + - schema_reference: + - naked_identifier: schema2 - statement_terminator: ; - statement: - alter_schema_statement: - keyword: ALTER - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: OWNER - keyword: TO - role_reference: @@ -28,9 +25,8 @@ file: - alter_schema_statement: - keyword: ALTER - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: QUOTA - numeric_literal: '50' - keyword: GB @@ -39,9 +35,8 @@ file: - alter_schema_statement: - keyword: ALTER - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: QUOTA - keyword: UNLIMITED - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_table.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_table.sql index 5525ebdb1..1fdc1f6ab 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_table.sql +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_table.sql @@ -55,3 +55,11 @@ alter table users drop column feedback_score; alter table users drop column feedback_score cascade; + +ALTER TABLE the_schema.the_table APPEND FROM the_schema.the_temp_table IGNOREEXTRA FILLTARGET; + +ALTER TABLE the_schema.the_table APPEND FROM the_schema.the_temp_table; + +ALTER TABLE the_schema.the_table SET LOCATION 's3://bucket/folder/'; + +ALTER TABLE my_schema.my_table ADD COLUMN my_column BIGINT ENCODE ZSTD; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_table.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_table.yml index 74469eae5..a3cc82c01 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_table.yml @@ -391,3 +391,68 @@ file: - naked_identifier: feedback_score - keyword: cascade - statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: the_schema + - dot: . + - naked_identifier: the_table + - alter_table_action_segment: + - keyword: APPEND + - keyword: FROM + - table_reference: + - naked_identifier: the_schema + - dot: . + - naked_identifier: the_temp_table + - keyword: IGNOREEXTRA + - keyword: FILLTARGET +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: the_schema + - dot: . + - naked_identifier: the_table + - alter_table_action_segment: + - keyword: APPEND + - keyword: FROM + - table_reference: + - naked_identifier: the_schema + - dot: . + - naked_identifier: the_temp_table +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: the_schema + - dot: . + - naked_identifier: the_table + - alter_table_action_segment: + - keyword: SET + - keyword: LOCATION + - quoted_literal: '''s3://bucket/folder/''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_schema + - dot: . + - naked_identifier: my_table + - alter_table_action_segment: + - keyword: ADD + - keyword: COLUMN + - column_reference: + - naked_identifier: my_column + - data_type: + - keyword: BIGINT + - keyword: ENCODE + - keyword: ZSTD +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_user.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_user.yml index 9d9fd0b27..2319e6703 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_user.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/alter_user.yml @@ -242,9 +242,10 @@ file: - keyword: user - role_reference: - naked_identifier: admin - - keyword: connection - - keyword: limit - - keyword: unlimited + - connection_limit_segment: + - keyword: connection + - keyword: limit + - keyword: unlimited - statement_terminator: ; - statement: - alter_user_statement: @@ -253,9 +254,10 @@ file: - role_reference: - naked_identifier: admin - keyword: with - - keyword: connection - - keyword: limit - - keyword: unlimited + - connection_limit_segment: + - keyword: connection + - keyword: limit + - keyword: unlimited - statement_terminator: ; - statement: - alter_user_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/approximate_functions.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/approximate_functions.yml index 2c076eb7c..64c7ab59e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/approximate_functions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/approximate_functions.yml @@ -16,34 +16,37 @@ file: - function: - function_name: - function_name_identifier: count - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: totalprice - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: totalprice + - end_bracket: ) - comma: ',' - select_clause_element: - function: - function_name: - function_name_identifier: sum - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: totalprice - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: totalprice + - end_bracket: ) - comma: ',' - select_clause_element: - function: - keyword: approximate - function_name: - function_name_identifier: percentile_disc - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '0.5' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.5' + - end_bracket: ) - withingroup_clause: - keyword: within - keyword: group @@ -98,13 +101,14 @@ file: - keyword: approximate - function_name: - function_name_identifier: count - - bracketed: - - start_bracket: ( - - keyword: distinct - - expression: - - column_reference: - - naked_identifier: pricepaid - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - keyword: distinct + - expression: + - column_reference: + - naked_identifier: pricepaid + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -121,13 +125,14 @@ file: - function: - function_name: - function_name_identifier: count - - bracketed: - - start_bracket: ( - - keyword: distinct - - expression: - - column_reference: - - naked_identifier: pricepaid - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - keyword: distinct + - expression: + - column_reference: + - naked_identifier: pricepaid + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -144,12 +149,13 @@ file: - function: - function_name: - function_name_identifier: approximate - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/array_unnest.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/array_unnest.yml index 1085bb8cc..0954c2570 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/array_unnest.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/array_unnest.yml @@ -14,20 +14,23 @@ file: - select_clause_element: - numeric_literal: '10' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: shop_id - comma: ',' - select_clause_element: - function: - function_name: - function_name_identifier: json_parse - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''[1, 2]''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''[1, 2]''' + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: inventory - set_operator: - keyword: UNION @@ -38,20 +41,23 @@ file: - select_clause_element: - numeric_literal: '20' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: shop_id - comma: ',' - select_clause_element: - function: - function_name: - function_name_identifier: json_parse - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''[3, 4, 5]''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''[3, 4, 5]''' + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: inventory - set_operator: - keyword: UNION @@ -62,20 +68,23 @@ file: - select_clause_element: - numeric_literal: '30' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: shop_id - comma: ',' - select_clause_element: - function: - function_name: - function_name_identifier: json_parse - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''[6, 7, 8, 9]''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''[6, 7, 8, 9]''' + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: inventory - end_bracket: ) - select_statement: @@ -129,14 +138,16 @@ file: - dot: . - naked_identifier: o_orderkey - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: orderkey - comma: ',' - select_clause_element: - column_reference: - naked_identifier: index - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: orderkey_index - from_clause: - keyword: FROM @@ -194,7 +205,8 @@ file: - data_type: - keyword: VARCHAR - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: value_b - comma: ',' - select_clause_element: @@ -208,15 +220,16 @@ file: - function: - function_name: - function_name_identifier: MOD - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: idx - - comma: ',' - - expression: - - numeric_literal: '3' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: idx + - comma: ',' + - expression: + - numeric_literal: '3' + - end_bracket: ) - binary_operator: + - numeric_literal: '1' - end_square_bracket: ']' @@ -224,7 +237,8 @@ file: - data_type: - keyword: FLOAT8 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: value_c - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/call.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/call.yml index c63981707..cefe1d457 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/call.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/call.yml @@ -5,9 +5,10 @@ file: - function: - function_name: - function_name_identifier: test_proc - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - statement_terminator: ; - statement: - call_statement: @@ -15,16 +16,18 @@ file: - function: - function_name: - function_name_identifier: test_proc - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: pg_last_query_id - - bracketed: - - start_bracket: ( - - end_bracket: ) - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: pg_last_query_id + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) - statement_terminator: ; - statement: - call_statement: @@ -32,11 +35,12 @@ file: - function: - function_name: - function_name_identifier: outer_proc - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '5' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '5' + - end_bracket: ) - statement_terminator: ; - statement: - call_statement: @@ -44,14 +48,15 @@ file: - function: - function_name: - function_name_identifier: test_sp1 - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '3' - - comma: ',' - - expression: - - quoted_literal: '''book''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - quoted_literal: '''book''' + - end_bracket: ) - statement_terminator: ; - statement: - call_statement: @@ -59,12 +64,13 @@ file: - function: - function_name: - function_name_identifier: test_sp2 - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '2' - - comma: ',' - - expression: - - quoted_literal: '''2019''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - quoted_literal: '''2019''' + - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/cast_conversion.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/cast_conversion.sql index 83e0be744..367b14c96 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/cast_conversion.sql +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/cast_conversion.sql @@ -33,3 +33,6 @@ from tbl1; select col1::interval from tbl1; + +select cast(pg_namespace.nspname as information_schema.sql_identifier) +from pg_namespace; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/cast_conversion.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/cast_conversion.yml index 1ea16446a..692667064 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/cast_conversion.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/cast_conversion.yml @@ -7,15 +7,16 @@ file: - function: - function_name: - function_name_identifier: cast - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: col1 - - keyword: as - - data_type: - - keyword: integer - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col1 + - keyword: as + - data_type: + - keyword: integer + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -32,15 +33,16 @@ file: - function: - function_name: - keyword: convert - - bracketed: - - start_bracket: ( - - data_type: - - keyword: integer - - comma: ',' - - expression: - - column_reference: - - naked_identifier: col1 - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: integer + - comma: ',' + - expression: + - column_reference: + - naked_identifier: col1 + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -77,16 +79,17 @@ file: - function: - function_name: - function_name_identifier: cast - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: col1 - - keyword: as - - data_type: - - datetime_type_identifier: - - keyword: timestamptz - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col1 + - keyword: as + - data_type: + - datetime_type_identifier: + - keyword: timestamptz + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -103,16 +106,17 @@ file: - function: - function_name: - keyword: convert - - bracketed: - - start_bracket: ( - - data_type: - - datetime_type_identifier: - - keyword: timestamptz - - comma: ',' - - expression: - - column_reference: - - naked_identifier: col1 - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - data_type: + - datetime_type_identifier: + - keyword: timestamptz + - comma: ',' + - expression: + - column_reference: + - naked_identifier: col1 + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -150,22 +154,23 @@ file: - function: - function_name: - function_name_identifier: cast - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: col1 - - keyword: as - - data_type: - - keyword: decimal - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '38' - - comma: ',' - - numeric_literal: '2' - - end_bracket: ) - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col1 + - keyword: as + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '38' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -182,22 +187,23 @@ file: - function: - function_name: - keyword: convert - - bracketed: - - start_bracket: ( - - data_type: - - keyword: decimal - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '38' - - comma: ',' - - numeric_literal: '2' - - end_bracket: ) - - comma: ',' - - expression: - - column_reference: - - naked_identifier: col1 - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '38' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - comma: ',' + - expression: + - column_reference: + - naked_identifier: col1 + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -241,15 +247,16 @@ file: - function: - function_name: - function_name_identifier: cast - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: col1 - - keyword: as - - data_type: - - keyword: interval - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col1 + - keyword: as + - data_type: + - keyword: interval + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -266,15 +273,16 @@ file: - function: - function_name: - keyword: convert - - bracketed: - - start_bracket: ( - - data_type: - - keyword: interval - - comma: ',' - - expression: - - column_reference: - - naked_identifier: col1 - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: interval + - comma: ',' + - expression: + - column_reference: + - naked_identifier: col1 + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -303,3 +311,33 @@ file: - table_reference: - naked_identifier: tbl1 - statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - function_name_identifier: cast + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: pg_namespace + - dot: . + - naked_identifier: nspname + - keyword: as + - data_type: + - naked_identifier: information_schema + - dot: . + - data_type_identifier: sql_identifier + - end_bracket: ) + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: pg_namespace +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_database.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_database.sql new file mode 100644 index 000000000..64a4af70f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_database.sql @@ -0,0 +1,77 @@ +-- Basic +CREATE DATABASE db1; + +-- WITH options +CREATE DATABASE db2 WITH OWNER = my_owner CONNECTION LIMIT 10 COLLATE CASE_SENSITIVE ISOLATION LEVEL SERIALIZABLE; + +-- FROM INTEGRATION with DATABASE +CREATE DATABASE db3 FROM INTEGRATION 'integration_id' DATABASE 'source_db'; + +-- FROM INTEGRATION with SET and options +CREATE DATABASE db4 FROM INTEGRATION 'integration_id' SET ACCEPTINVCHARS = TRUE QUERY_ALL_STATES = FALSE REFRESH_INTERVAL 60 TRUNCATECOLUMNS = TRUE HISTORY_MODE = FALSE; + +-- FROM ARN with DATA CATALOG SCHEMA +CREATE DATABASE db5 FROM ARN 'arn:aws:redshift:us-east-1:123456789012:datashare:mydatashare' WITH DATA CATALOG SCHEMA 'my_schema'; + +-- FROM ARN with NO DATA CATALOG SCHEMA +CREATE DATABASE db6 FROM ARN 'arn:aws:redshift:us-east-1:123456789012:datashare:mydatashare' WITH NO DATA CATALOG SCHEMA; + +-- IAM_ROLE default +CREATE DATABASE db7 IAM_ROLE default; + +-- IAM_ROLE SESSION +CREATE DATABASE db8 IAM_ROLE 'SESSION'; + +-- IAM_ROLE with ARN +CREATE DATABASE db9 IAM_ROLE 'arn:aws:iam::123456789012:role/MyRedshiftRole'; + +-- FROM DATASHARE minimal +CREATE DATABASE db10 FROM DATASHARE my_datashare OF NAMESPACE 'my_namespace_guid'; + +-- FROM DATASHARE with ACCOUNT and NAMESPACE +CREATE DATABASE db11 FROM DATASHARE my_datashare OF ACCOUNT '123456789012' NAMESPACE 'my_namespace_guid'; + +-- WITH PERMISSIONS FROM DATASHARE +CREATE DATABASE db12 WITH PERMISSIONS FROM DATASHARE my_datashare OF ACCOUNT 123456789012 NAMESPACE my_namespace_guid; + +-- Combination: WITH and FROM DATASHARE +CREATE DATABASE db13 WITH OWNER = my_owner CONNECTION LIMIT 5 FROM DATASHARE my_datashare OF NAMESPACE 'my_namespace_guid'; + +-- Combination: FROM INTEGRATION and WITH +CREATE DATABASE db14 FROM INTEGRATION 'integration_id' WITH OWNER = my_owner COLLATE CASE_INSENSITIVE; + +-- WITH options: COLLATE short forms and CONNECTION LIMIT UNLIMITED +CREATE DATABASE db15 WITH OWNER = my_owner CONNECTION LIMIT UNLIMITED COLLATE CS ISOLATION LEVEL SNAPSHOT; + +-- WITH options: OWNER without equals +CREATE DATABASE db16 WITH OWNER my_owner CONNECTION LIMIT 20 COLLATE CI; + +-- FROM INTEGRATION with only SET and one option +CREATE DATABASE db17 FROM INTEGRATION 'integration_id' SET ACCEPTINVCHARS = FALSE; + +-- FROM INTEGRATION with SET and options in different order +CREATE DATABASE db18 FROM INTEGRATION 'integration_id' SET HISTORY_MODE = TRUE TRUNCATECOLUMNS = FALSE; + +-- FROM ARN with DATA CATALOG SCHEMA, schema name +CREATE DATABASE db19 FROM ARN 'arn:aws:redshift:us-east-1:123456789012:datashare:mydatashare' WITH DATA CATALOG SCHEMA 'my_schema'; + +-- FROM ARN with NO DATA CATALOG SCHEMA (no quotes) +CREATE DATABASE db20 FROM ARN 'arn:aws:redshift:us-east-1:123456789012:datashare:mydatashare' WITH NO DATA CATALOG SCHEMA; + +-- FROM DATASHARE with ACCOUNT as unquoted number, NAMESPACE as unquoted identifier +CREATE DATABASE db22 FROM DATASHARE my_datashare OF ACCOUNT 123456789012 NAMESPACE my_namespace_guid; + +-- WITH and FROM INTEGRATION and IAM_ROLE +CREATE DATABASE db26 FROM INTEGRATION 'integration_id' WITH OWNER = my_owner IAM_ROLE 'arn:aws:iam::123456789012:role/MyRedshiftRole'; + +-- WITH and FROM ARN and IAM_ROLE +CREATE DATABASE db27 FROM ARN 'arn:aws:redshift:us-east-1:123456789012:datashare:mydatashare' WITH DATA CATALOG SCHEMA 'my_schema' IAM_ROLE default; + +-- WITH and FROM DATASHARE and IAM_ROLE +CREATE DATABASE db28 WITH OWNER = my_owner FROM DATASHARE my_datashare OF NAMESPACE 'hello' IAM_ROLE 'SESSION'; + +-- WITH only COLLATE +CREATE DATABASE db29 WITH COLLATE CS; + +-- WITH only ISOLATION LEVEL +CREATE DATABASE db30 WITH ISOLATION LEVEL SNAPSHOT; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_database.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_database.yml new file mode 100644 index 000000000..553913874 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_database.yml @@ -0,0 +1,457 @@ +file: +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db1 +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db2 + - keyword: WITH + - create_database_with_options: + - keyword: OWNER + - comparison_operator: + - raw_comparison_operator: = + - role_reference: + - naked_identifier: my_owner + - connection_limit_segment: + - keyword: CONNECTION + - keyword: LIMIT + - numeric_literal: '10' + - collation_clause: + - keyword: COLLATE + - keyword: CASE_SENSITIVE + - isolation_level_clause: + - keyword: ISOLATION + - keyword: LEVEL + - keyword: SERIALIZABLE +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db3 + - from_integration_clause: + - keyword: FROM + - keyword: INTEGRATION + - quoted_literal: '''integration_id''' + - keyword: DATABASE + - quoted_literal: '''source_db''' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db4 + - from_integration_clause: + - keyword: FROM + - keyword: INTEGRATION + - quoted_literal: '''integration_id''' + - keyword: SET + - keyword: ACCEPTINVCHARS + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - keyword: QUERY_ALL_STATES + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' + - keyword: REFRESH_INTERVAL + - numeric_literal: '60' + - keyword: TRUNCATECOLUMNS + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - keyword: HISTORY_MODE + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db5 + - arn_catalog_schema_segment: + - keyword: FROM + - keyword: ARN + - quoted_literal: '''arn:aws:redshift:us-east-1:123456789012:datashare:mydatashare''' + - keyword: WITH + - keyword: DATA + - keyword: CATALOG + - keyword: SCHEMA + - quoted_literal: '''my_schema''' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db6 + - arn_catalog_schema_segment: + - keyword: FROM + - keyword: ARN + - quoted_literal: '''arn:aws:redshift:us-east-1:123456789012:datashare:mydatashare''' + - keyword: WITH + - keyword: NO + - keyword: DATA + - keyword: CATALOG + - keyword: SCHEMA +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db7 + - iam_role_clause: + - keyword: IAM_ROLE + - keyword: default +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db8 + - iam_role_clause: + - keyword: IAM_ROLE + - quoted_literal: '''SESSION''' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db9 + - iam_role_clause: + - keyword: IAM_ROLE + - quoted_literal: '''arn:aws:iam::123456789012:role/MyRedshiftRole''' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db10 + - from_datashare_clause: + - keyword: FROM + - keyword: DATASHARE + - object_reference: + - naked_identifier: my_datashare + - keyword: OF + - keyword: NAMESPACE + - quoted_literal: '''my_namespace_guid''' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db11 + - from_datashare_clause: + - keyword: FROM + - keyword: DATASHARE + - object_reference: + - naked_identifier: my_datashare + - keyword: OF + - keyword: ACCOUNT + - quoted_literal: '''123456789012''' + - keyword: NAMESPACE + - quoted_literal: '''my_namespace_guid''' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db12 + - from_datashare_clause: + - keyword: WITH + - keyword: PERMISSIONS + - keyword: FROM + - keyword: DATASHARE + - object_reference: + - naked_identifier: my_datashare + - keyword: OF + - keyword: ACCOUNT + - numeric_literal: '123456789012' + - keyword: NAMESPACE + - object_reference: + - naked_identifier: my_namespace_guid +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db13 + - keyword: WITH + - create_database_with_options: + - keyword: OWNER + - comparison_operator: + - raw_comparison_operator: = + - role_reference: + - naked_identifier: my_owner + - connection_limit_segment: + - keyword: CONNECTION + - keyword: LIMIT + - numeric_literal: '5' + - from_datashare_clause: + - keyword: FROM + - keyword: DATASHARE + - object_reference: + - naked_identifier: my_datashare + - keyword: OF + - keyword: NAMESPACE + - quoted_literal: '''my_namespace_guid''' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db14 + - from_integration_clause: + - keyword: FROM + - keyword: INTEGRATION + - quoted_literal: '''integration_id''' + - keyword: WITH + - create_database_with_options: + - keyword: OWNER + - comparison_operator: + - raw_comparison_operator: = + - role_reference: + - naked_identifier: my_owner + - collation_clause: + - keyword: COLLATE + - keyword: CASE_INSENSITIVE +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db15 + - keyword: WITH + - create_database_with_options: + - keyword: OWNER + - comparison_operator: + - raw_comparison_operator: = + - role_reference: + - naked_identifier: my_owner + - connection_limit_segment: + - keyword: CONNECTION + - keyword: LIMIT + - keyword: UNLIMITED + - collation_clause: + - keyword: COLLATE + - keyword: CS + - isolation_level_clause: + - keyword: ISOLATION + - keyword: LEVEL + - keyword: SNAPSHOT +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db16 + - keyword: WITH + - create_database_with_options: + - keyword: OWNER + - role_reference: + - naked_identifier: my_owner + - connection_limit_segment: + - keyword: CONNECTION + - keyword: LIMIT + - numeric_literal: '20' + - collation_clause: + - keyword: COLLATE + - keyword: CI +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db17 + - from_integration_clause: + - keyword: FROM + - keyword: INTEGRATION + - quoted_literal: '''integration_id''' + - keyword: SET + - keyword: ACCEPTINVCHARS + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db18 + - from_integration_clause: + - keyword: FROM + - keyword: INTEGRATION + - quoted_literal: '''integration_id''' + - keyword: SET + - keyword: HISTORY_MODE + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - keyword: TRUNCATECOLUMNS + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db19 + - arn_catalog_schema_segment: + - keyword: FROM + - keyword: ARN + - quoted_literal: '''arn:aws:redshift:us-east-1:123456789012:datashare:mydatashare''' + - keyword: WITH + - keyword: DATA + - keyword: CATALOG + - keyword: SCHEMA + - quoted_literal: '''my_schema''' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db20 + - arn_catalog_schema_segment: + - keyword: FROM + - keyword: ARN + - quoted_literal: '''arn:aws:redshift:us-east-1:123456789012:datashare:mydatashare''' + - keyword: WITH + - keyword: NO + - keyword: DATA + - keyword: CATALOG + - keyword: SCHEMA +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db22 + - from_datashare_clause: + - keyword: FROM + - keyword: DATASHARE + - object_reference: + - naked_identifier: my_datashare + - keyword: OF + - keyword: ACCOUNT + - numeric_literal: '123456789012' + - keyword: NAMESPACE + - object_reference: + - naked_identifier: my_namespace_guid +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db26 + - from_integration_clause: + - keyword: FROM + - keyword: INTEGRATION + - quoted_literal: '''integration_id''' + - keyword: WITH + - create_database_with_options: + - keyword: OWNER + - comparison_operator: + - raw_comparison_operator: = + - role_reference: + - naked_identifier: my_owner + - iam_role_clause: + - keyword: IAM_ROLE + - quoted_literal: '''arn:aws:iam::123456789012:role/MyRedshiftRole''' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db27 + - arn_catalog_schema_segment: + - keyword: FROM + - keyword: ARN + - quoted_literal: '''arn:aws:redshift:us-east-1:123456789012:datashare:mydatashare''' + - keyword: WITH + - keyword: DATA + - keyword: CATALOG + - keyword: SCHEMA + - quoted_literal: '''my_schema''' + - iam_role_clause: + - keyword: IAM_ROLE + - keyword: default +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db28 + - keyword: WITH + - create_database_with_options: + - keyword: OWNER + - comparison_operator: + - raw_comparison_operator: = + - role_reference: + - naked_identifier: my_owner + - from_datashare_clause: + - keyword: FROM + - keyword: DATASHARE + - object_reference: + - naked_identifier: my_datashare + - keyword: OF + - keyword: NAMESPACE + - quoted_literal: '''hello''' + - iam_role_clause: + - keyword: IAM_ROLE + - quoted_literal: '''SESSION''' +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db29 + - keyword: WITH + - create_database_with_options: + - collation_clause: + - keyword: COLLATE + - keyword: CS +- statement_terminator: ; +- statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: db30 + - keyword: WITH + - create_database_with_options: + - isolation_level_clause: + - keyword: ISOLATION + - keyword: LEVEL + - keyword: SNAPSHOT +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_external_schema.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_external_schema.sql index afe890a79..a2de966e0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_external_schema.sql +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_external_schema.sql @@ -44,3 +44,28 @@ from data catalog database 'sampledb' region 'us-west-2' iam_role 'arn:aws:iam::123456789012:role/MySpectrumRole'; + +create external schema my_schema +from kafka +iam_role 'arn:aws:iam::012345678901:role/my_role' +authentication iam +uri 'b-1.myTestCluster.123z8u.c2.kafka.us-west-1.amazonaws.com:9098,b-2.myTestCluster.123z8u.c2.kafka.us-west-1.amazonaws.com:9098'; + +create external schema my_schema +from kafka +authentication none +uri 'b-1.myTestCluster.123z8u.c2.kafka.us-west-1.amazonaws.com:9092,b-2.myTestCluster.123z8u.c2.kafka.us-west-1.amazonaws.com:9092'; + +create external schema my_schema +from kafka +iam_role 'arn:aws:iam::012345678901:role/my_role' +authentication mtls +uri 'lkc-2v531.domz6wj0p.us-west-1.aws.confluent.cloud:9092' +authentication_arn 'arn:aws:acm:region:444455556666:certificate/certificate_ID'; + +create external schema my_schema +from kafka +iam_role 'arn:aws:iam::012345678901:role/my_role' +authentication mtls +uri 'b-1.myTestCluster.123z8u.c2.kafka.us-west-1.amazonaws.com:9094,b-2.myTestCluster.123z8u.c2.kafka.us-west-1.amazonaws.com:9094' +secret_arn 'arn:aws:secretsmanager:us-east-1:012345678910:secret:myMTLSSecret'; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_external_schema.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_external_schema.yml index 739ac5dd4..549cdf12c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_external_schema.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_external_schema.yml @@ -4,9 +4,8 @@ file: - keyword: create - keyword: external - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: spectrum_schema + - schema_reference: + - naked_identifier: spectrum_schema - keyword: from - keyword: data - keyword: catalog @@ -22,9 +21,8 @@ file: - keyword: create - keyword: external - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: spectrum_schema + - schema_reference: + - naked_identifier: spectrum_schema - keyword: from - keyword: data - keyword: catalog @@ -44,9 +42,8 @@ file: - keyword: create - keyword: external - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: hive_schema + - schema_reference: + - naked_identifier: hive_schema - keyword: from - keyword: hive - keyword: metastore @@ -64,9 +61,8 @@ file: - keyword: create - keyword: external - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: spectrum_schema + - schema_reference: + - naked_identifier: spectrum_schema - keyword: from - keyword: data - keyword: catalog @@ -91,9 +87,8 @@ file: - keyword: IF - keyword: NOT - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: myRedshiftSchema + - schema_reference: + - naked_identifier: myRedshiftSchema - keyword: FROM - keyword: POSTGRES - keyword: DATABASE @@ -114,9 +109,8 @@ file: - keyword: CREATE - keyword: EXTERNAL - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: sales_schema + - schema_reference: + - naked_identifier: sales_schema - keyword: FROM - keyword: REDSHIFT - keyword: DATABASE @@ -132,9 +126,8 @@ file: - keyword: IF - keyword: NOT - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: myRedshiftSchema + - schema_reference: + - naked_identifier: myRedshiftSchema - keyword: FROM - keyword: MYSQL - keyword: DATABASE @@ -151,9 +144,8 @@ file: - keyword: create - keyword: external - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: spectrum_schema + - schema_reference: + - naked_identifier: spectrum_schema - keyword: from - keyword: data - keyword: catalog @@ -164,3 +156,69 @@ file: - keyword: iam_role - quoted_literal: '''arn:aws:iam::123456789012:role/MySpectrumRole''' - statement_terminator: ; +- statement: + - create_external_schema_statement: + - keyword: create + - keyword: external + - keyword: schema + - schema_reference: + - naked_identifier: my_schema + - keyword: from + - keyword: kafka + - keyword: iam_role + - quoted_literal: '''arn:aws:iam::012345678901:role/my_role''' + - keyword: authentication + - keyword: iam + - keyword: uri + - quoted_literal: '''b-1.myTestCluster.123z8u.c2.kafka.us-west-1.amazonaws.com:9098,b-2.myTestCluster.123z8u.c2.kafka.us-west-1.amazonaws.com:9098''' +- statement_terminator: ; +- statement: + - create_external_schema_statement: + - keyword: create + - keyword: external + - keyword: schema + - schema_reference: + - naked_identifier: my_schema + - keyword: from + - keyword: kafka + - keyword: authentication + - keyword: none + - keyword: uri + - quoted_literal: '''b-1.myTestCluster.123z8u.c2.kafka.us-west-1.amazonaws.com:9092,b-2.myTestCluster.123z8u.c2.kafka.us-west-1.amazonaws.com:9092''' +- statement_terminator: ; +- statement: + - create_external_schema_statement: + - keyword: create + - keyword: external + - keyword: schema + - schema_reference: + - naked_identifier: my_schema + - keyword: from + - keyword: kafka + - keyword: iam_role + - quoted_literal: '''arn:aws:iam::012345678901:role/my_role''' + - keyword: authentication + - keyword: mtls + - keyword: uri + - quoted_literal: '''lkc-2v531.domz6wj0p.us-west-1.aws.confluent.cloud:9092''' + - keyword: authentication_arn + - quoted_literal: '''arn:aws:acm:region:444455556666:certificate/certificate_ID''' +- statement_terminator: ; +- statement: + - create_external_schema_statement: + - keyword: create + - keyword: external + - keyword: schema + - schema_reference: + - naked_identifier: my_schema + - keyword: from + - keyword: kafka + - keyword: iam_role + - quoted_literal: '''arn:aws:iam::012345678901:role/my_role''' + - keyword: authentication + - keyword: mtls + - keyword: uri + - quoted_literal: '''b-1.myTestCluster.123z8u.c2.kafka.us-west-1.amazonaws.com:9094,b-2.myTestCluster.123z8u.c2.kafka.us-west-1.amazonaws.com:9094''' + - keyword: secret_arn + - quoted_literal: '''arn:aws:secretsmanager:us-east-1:012345678910:secret:myMTLSSecret''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_materialized_view.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_materialized_view.sql index 4ab9102f4..f95ed18ad 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_materialized_view.sql +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_materialized_view.sql @@ -22,9 +22,9 @@ select salesid, qtysold, pricepaid, commission, saletime from spectrum.sales ; -CREATE MATERIALIZED VIEW mv_baseball -DISTSTYLE ALL -AUTO REFRESH YES -AS -SELECT ball AS baseball +CREATE MATERIALIZED VIEW mv_baseball +DISTSTYLE ALL +AUTO REFRESH YES +AS +SELECT ball AS baseball FROM baseball_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_materialized_view.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_materialized_view.yml index 71a2ce19b..f5d74b810 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_materialized_view.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_materialized_view.yml @@ -45,14 +45,16 @@ file: - function: - function_name: - function_name_identifier: sum - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: qtysold - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: qtysold + - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: sold - from_clause: - keyword: from @@ -205,7 +207,8 @@ file: - column_reference: - naked_identifier: ball - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: baseball - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_procedure.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_procedure.sql index a23b1c899..b427b7f40 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_procedure.sql +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_procedure.sql @@ -29,3 +29,30 @@ BEGIN SELECT INTO out_var count(*) from my_etl; END; $$ LANGUAGE plpgsql; + +CREATE OR REPLACE PROCEDURE test_sp_nonatomic () +NONATOMIC +AS $$ +BEGIN + SELECT 1; +END; +$$ LANGUAGE plpgsql +SECURITY INVOKER; + +CREATE PROCEDURE etl.test_sp_na (param1 int) +NONATOMIC +AS $$ +BEGIN + INSERT INTO test_table VALUES (param1); + COMMIT; + SELECT param1; +END; +$$ LANGUAGE plpgsql; + +CREATE PROCEDURE test_set_config() +AS $$ +BEGIN + SELECT 1; +END; +$$ LANGUAGE plpgsql +SET work_mem = '256MB'; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_procedure.yml index db8931c9b..9cfd6230a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_procedure.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_procedure.yml @@ -102,3 +102,87 @@ file: - keyword: LANGUAGE - naked_identifier: plpgsql - statement_terminator: ; +- statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: PROCEDURE + - function_name: + - function_name_identifier: test_sp_nonatomic + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: NONATOMIC + - function_definition: + - keyword: AS + - quoted_literal: |- + $$ + BEGIN + SELECT 1; + END; + $$ + - language_clause: + - keyword: LANGUAGE + - naked_identifier: plpgsql + - keyword: SECURITY + - keyword: INVOKER +- statement_terminator: ; +- statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - function_name: + - naked_identifier: etl + - dot: . + - function_name_identifier: test_sp_na + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: param1 + - data_type: + - keyword: int + - end_bracket: ) + - keyword: NONATOMIC + - function_definition: + - keyword: AS + - quoted_literal: |- + $$ + BEGIN + INSERT INTO test_table VALUES (param1); + COMMIT; + SELECT param1; + END; + $$ + - language_clause: + - keyword: LANGUAGE + - naked_identifier: plpgsql +- statement_terminator: ; +- statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - function_name: + - function_name_identifier: test_set_config + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - function_definition: + - keyword: AS + - quoted_literal: |- + $$ + BEGIN + SELECT 1; + END; + $$ + - language_clause: + - keyword: LANGUAGE + - naked_identifier: plpgsql + - keyword: SET + - parameter: work_mem + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''256MB''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_schema.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_schema.yml index cf0486c34..3f8d24cc3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_schema.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_schema.yml @@ -3,9 +3,8 @@ file: - create_schema_statement: - keyword: CREATE - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: s1 + - schema_reference: + - naked_identifier: s1 - statement_terminator: ; - statement: - create_schema_statement: @@ -14,17 +13,15 @@ file: - keyword: IF - keyword: NOT - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: s1 + - schema_reference: + - naked_identifier: s1 - statement_terminator: ; - statement: - create_schema_statement: - keyword: CREATE - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: s1 + - schema_reference: + - naked_identifier: s1 - keyword: AUTHORIZATION - role_reference: - naked_identifier: dwuser @@ -36,9 +33,8 @@ file: - keyword: IF - keyword: NOT - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: s1 + - schema_reference: + - naked_identifier: s1 - keyword: AUTHORIZATION - role_reference: - naked_identifier: dwuser @@ -47,9 +43,8 @@ file: - create_schema_statement: - keyword: CREATE - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: s1 + - schema_reference: + - naked_identifier: s1 - keyword: AUTHORIZATION - role_reference: - naked_identifier: dwuser @@ -64,9 +59,8 @@ file: - keyword: IF - keyword: NOT - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: s1 + - schema_reference: + - naked_identifier: s1 - keyword: AUTHORIZATION - role_reference: - naked_identifier: dwuser @@ -78,9 +72,8 @@ file: - create_schema_statement: - keyword: CREATE - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: s1 + - schema_reference: + - naked_identifier: s1 - keyword: AUTHORIZATION - role_reference: - naked_identifier: dwuser @@ -95,9 +88,8 @@ file: - keyword: IF - keyword: NOT - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: s1 + - schema_reference: + - naked_identifier: s1 - keyword: AUTHORIZATION - role_reference: - naked_identifier: dwuser @@ -109,9 +101,8 @@ file: - create_schema_statement: - keyword: CREATE - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: s1 + - schema_reference: + - naked_identifier: s1 - keyword: AUTHORIZATION - role_reference: - naked_identifier: dwuser @@ -126,9 +117,8 @@ file: - keyword: IF - keyword: NOT - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: s1 + - schema_reference: + - naked_identifier: s1 - keyword: AUTHORIZATION - role_reference: - naked_identifier: dwuser @@ -140,9 +130,8 @@ file: - create_schema_statement: - keyword: CREATE - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: s1 + - schema_reference: + - naked_identifier: s1 - keyword: AUTHORIZATION - role_reference: - naked_identifier: dwuser @@ -156,9 +145,8 @@ file: - keyword: IF - keyword: NOT - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: s1 + - schema_reference: + - naked_identifier: s1 - keyword: AUTHORIZATION - role_reference: - naked_identifier: dwuser diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_table.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_table.sql index 68ca43abc..af9f8f71d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_table.sql +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_table.sql @@ -150,3 +150,15 @@ CREATE TABLE IdentityColumnNotNull_demo ( CREATE TABLE IdentityColumnGeneratedByDefaultNotNull_demo ( col1 BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL ); + +create table public.t1 ( c1 int, c2 int, c3 int, unique (c1, c2) ); + +create table public.t2 +( + c1 int, + c2 int, + c3 int, + foreign key (c1, c2) references public.t1 (c1, c2) +); + +create table test(col1 varchar(max)); diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_table.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_table.yml index 5393d49a4..5c0e55456 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_table.yml @@ -921,3 +921,110 @@ file: - keyword: 'NULL' - end_bracket: ) - statement_terminator: ; +- statement: + - create_table_statement: + - keyword: create + - keyword: table + - table_reference: + - naked_identifier: public + - dot: . + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c1 + - data_type: + - keyword: int + - comma: ',' + - column_reference: + - naked_identifier: c2 + - data_type: + - keyword: int + - comma: ',' + - column_reference: + - naked_identifier: c3 + - data_type: + - keyword: int + - comma: ',' + - table_constraint: + - keyword: unique + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c1 + - comma: ',' + - column_reference: + - naked_identifier: c2 + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: create + - keyword: table + - table_reference: + - naked_identifier: public + - dot: . + - naked_identifier: t2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c1 + - data_type: + - keyword: int + - comma: ',' + - column_reference: + - naked_identifier: c2 + - data_type: + - keyword: int + - comma: ',' + - column_reference: + - naked_identifier: c3 + - data_type: + - keyword: int + - comma: ',' + - table_constraint: + - keyword: foreign + - keyword: key + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c1 + - comma: ',' + - column_reference: + - naked_identifier: c2 + - end_bracket: ) + - keyword: references + - table_reference: + - naked_identifier: public + - dot: . + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c1 + - comma: ',' + - column_reference: + - naked_identifier: c2 + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: create + - keyword: table + - table_reference: + - naked_identifier: test + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - max_literal: max + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_user.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_user.yml index 61d18d027..55fd207d0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_user.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/create_user.yml @@ -160,9 +160,10 @@ file: - naked_identifier: user1 - keyword: PASSWORD - quoted_literal: '''md5153c434b4b77c89e6b94f12c5393af5b''' - - keyword: CONNECTION - - keyword: LIMIT - - numeric_literal: '30' + - connection_limit_segment: + - keyword: CONNECTION + - keyword: LIMIT + - numeric_literal: '30' - statement_terminator: ; - statement: - create_user_statement: @@ -172,9 +173,10 @@ file: - naked_identifier: user1 - keyword: PASSWORD - quoted_literal: '''md5153c434b4b77c89e6b94f12c5393af5b''' - - keyword: CONNECTION - - keyword: LIMIT - - keyword: UNLIMITED + - connection_limit_segment: + - keyword: CONNECTION + - keyword: LIMIT + - keyword: UNLIMITED - statement_terminator: ; - statement: - create_user_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/dateparts.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/dateparts.yml index 3624cac7b..725df6e82 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/dateparts.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/dateparts.yml @@ -7,14 +7,15 @@ file: - function: - function_name: - function_name_identifier: date_part - - bracketed: - - start_bracket: ( - - date_part: millennium - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: millennium + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -31,14 +32,15 @@ file: - function: - function_name: - function_name_identifier: date_part - - bracketed: - - start_bracket: ( - - date_part: millennia - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: millennia + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -55,14 +57,15 @@ file: - function: - function_name: - function_name_identifier: date_part - - bracketed: - - start_bracket: ( - - date_part: mil - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: mil + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -79,14 +82,15 @@ file: - function: - function_name: - function_name_identifier: date_part - - bracketed: - - start_bracket: ( - - date_part: mils - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: mils + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -103,14 +107,15 @@ file: - function: - function_name: - function_name_identifier: date_part - - bracketed: - - start_bracket: ( - - date_part: century - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: century + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -127,14 +132,15 @@ file: - function: - function_name: - function_name_identifier: date_part - - bracketed: - - start_bracket: ( - - date_part: centuries - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: centuries + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -151,14 +157,15 @@ file: - function: - function_name: - function_name_identifier: date_part - - bracketed: - - start_bracket: ( - - date_part: c - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: c + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -175,14 +182,15 @@ file: - function: - function_name: - function_name_identifier: date_part - - bracketed: - - start_bracket: ( - - date_part: cent - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: cent + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -199,14 +207,15 @@ file: - function: - function_name: - function_name_identifier: date_part - - bracketed: - - start_bracket: ( - - date_part: cents - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: cents + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -223,14 +232,15 @@ file: - function: - function_name: - function_name_identifier: date_part - - bracketed: - - start_bracket: ( - - date_part: decade - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: decade + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -247,14 +257,15 @@ file: - function: - function_name: - function_name_identifier: date_part - - bracketed: - - start_bracket: ( - - date_part: decades - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: decades + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -271,14 +282,15 @@ file: - function: - function_name: - function_name_identifier: date_part - - bracketed: - - start_bracket: ( - - date_part: dec - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: dec + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -295,14 +307,15 @@ file: - function: - function_name: - function_name_identifier: date_part - - bracketed: - - start_bracket: ( - - date_part: decs - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: decs + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -319,14 +332,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: epoch - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: epoch + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -343,14 +357,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: year - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: year + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -367,14 +382,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: years - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: years + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -391,14 +407,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: y - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: y + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -415,14 +432,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: yr - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: yr + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -439,14 +457,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: yrs - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: yrs + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -463,14 +482,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: quarter - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: quarter + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -487,14 +507,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: quarters - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: quarters + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -511,14 +532,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: qtr - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: qtr + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -535,14 +557,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: qtrs - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: qtrs + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -559,14 +582,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: month - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: month + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -583,14 +607,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: months - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: months + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -607,14 +632,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: mon - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: mon + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -631,14 +657,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: mons - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: mons + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -655,14 +682,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: week - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: week + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -679,14 +707,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: weeks - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: weeks + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -703,14 +732,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: w - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: w + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -727,14 +757,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: dayofweek - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: dayofweek + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -751,14 +782,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: dow - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: dow + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -775,14 +807,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: dw - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: dw + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -799,14 +832,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: weekday - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: weekday + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -823,14 +857,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: dayofyear - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: dayofyear + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -847,14 +882,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: doy - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: doy + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -871,14 +907,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: dy - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: dy + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -895,14 +932,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: yearday - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: yearday + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -919,14 +957,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: day - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: day + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -943,14 +982,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: days - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: days + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -967,14 +1007,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: d - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: d + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -991,14 +1032,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: hour - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: hour + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1015,14 +1057,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: hours - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: hours + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1039,14 +1082,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: h - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: h + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1063,14 +1107,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: hr - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: hr + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1087,14 +1132,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: hrs - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: hrs + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1111,14 +1157,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: minute - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: minute + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1135,14 +1182,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: minutes - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: minutes + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1159,14 +1207,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: m - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: m + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1183,14 +1232,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: min - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: min + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1207,14 +1257,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: mins - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: mins + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1231,14 +1282,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: second - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: second + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1255,14 +1307,15 @@ file: - function: - function_name: - function_name_identifier: extract - - bracketed: - - start_bracket: ( - - date_part: seconds - - keyword: from - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: seconds + - keyword: from + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1279,17 +1332,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: s - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: s + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1306,17 +1360,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: sec - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: sec + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1333,17 +1388,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: secs - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: secs + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1360,17 +1416,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: millisecond - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: millisecond + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1387,17 +1444,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: milliseconds - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: milliseconds + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1414,17 +1472,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: ms - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: ms + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1441,17 +1500,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: msec - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: msec + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1468,17 +1528,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: msecs - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: msecs + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1495,17 +1556,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: msecond - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: msecond + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1522,17 +1584,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: mseconds - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: mseconds + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1549,17 +1612,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: millisec - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: millisec + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1576,17 +1640,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: millisecs - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: millisecs + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1603,17 +1668,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: millisecon - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: millisecon + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1630,17 +1696,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: microsecond - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: microsecond + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1657,17 +1724,18 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: microseconds - - comma: ',' - - expression: - - numeric_literal: '123' - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: microseconds + - comma: ',' + - expression: + - numeric_literal: '123' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1684,18 +1752,19 @@ file: - function: - function_name: - function_name_identifier: datediff - - bracketed: - - start_bracket: ( - - date_part: microsec - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - comma: ',' - - expression: - - column_reference: - - naked_identifier: bar - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: microsec + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - comma: ',' + - expression: + - column_reference: + - naked_identifier: bar + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1712,18 +1781,19 @@ file: - function: - function_name: - function_name_identifier: datediff - - bracketed: - - start_bracket: ( - - date_part: microsecs - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - comma: ',' - - expression: - - column_reference: - - naked_identifier: bar - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: microsecs + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - comma: ',' + - expression: + - column_reference: + - naked_identifier: bar + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1740,18 +1810,19 @@ file: - function: - function_name: - function_name_identifier: datediff - - bracketed: - - start_bracket: ( - - date_part: microsecond - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - comma: ',' - - expression: - - column_reference: - - naked_identifier: bar - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: microsecond + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - comma: ',' + - expression: + - column_reference: + - naked_identifier: bar + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1768,18 +1839,19 @@ file: - function: - function_name: - function_name_identifier: datediff - - bracketed: - - start_bracket: ( - - date_part: usecond - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - comma: ',' - - expression: - - column_reference: - - naked_identifier: bar - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: usecond + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - comma: ',' + - expression: + - column_reference: + - naked_identifier: bar + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1796,18 +1868,19 @@ file: - function: - function_name: - function_name_identifier: datediff - - bracketed: - - start_bracket: ( - - date_part: useconds - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - comma: ',' - - expression: - - column_reference: - - naked_identifier: bar - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: useconds + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - comma: ',' + - expression: + - column_reference: + - naked_identifier: bar + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1824,18 +1897,19 @@ file: - function: - function_name: - function_name_identifier: datediff - - bracketed: - - start_bracket: ( - - date_part: us - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - comma: ',' - - expression: - - column_reference: - - naked_identifier: bar - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: us + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - comma: ',' + - expression: + - column_reference: + - naked_identifier: bar + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1852,18 +1926,19 @@ file: - function: - function_name: - function_name_identifier: datediff - - bracketed: - - start_bracket: ( - - date_part: usec - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - comma: ',' - - expression: - - column_reference: - - naked_identifier: bar - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: usec + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - comma: ',' + - expression: + - column_reference: + - naked_identifier: bar + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1880,18 +1955,19 @@ file: - function: - function_name: - function_name_identifier: datediff - - bracketed: - - start_bracket: ( - - date_part: usecs - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - comma: ',' - - expression: - - column_reference: - - naked_identifier: bar - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: usecs + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - comma: ',' + - expression: + - column_reference: + - naked_identifier: bar + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1908,18 +1984,19 @@ file: - function: - function_name: - function_name_identifier: datediff - - bracketed: - - start_bracket: ( - - date_part: timezone - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - comma: ',' - - expression: - - column_reference: - - naked_identifier: bar - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: timezone + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - comma: ',' + - expression: + - column_reference: + - naked_identifier: bar + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1936,18 +2013,19 @@ file: - function: - function_name: - function_name_identifier: datediff - - bracketed: - - start_bracket: ( - - date_part: timezone_hour - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - comma: ',' - - expression: - - column_reference: - - naked_identifier: bar - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: timezone_hour + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - comma: ',' + - expression: + - column_reference: + - naked_identifier: bar + - end_bracket: ) - from_clause: - keyword: from - from_expression: @@ -1964,18 +2042,19 @@ file: - function: - function_name: - function_name_identifier: datediff - - bracketed: - - start_bracket: ( - - date_part: timezone_minute - - comma: ',' - - expression: - - column_reference: - - naked_identifier: foo - - comma: ',' - - expression: - - column_reference: - - naked_identifier: bar - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: timezone_minute + - comma: ',' + - expression: + - column_reference: + - naked_identifier: foo + - comma: ',' + - expression: + - column_reference: + - naked_identifier: bar + - end_bracket: ) - from_clause: - keyword: from - from_expression: diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/datetime_cast.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/datetime_cast.yml index b9a9a8274..8dd93bd6c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/datetime_cast.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/datetime_cast.yml @@ -192,7 +192,8 @@ file: - data_type: - keyword: VARCHAR - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: status - comma: ',' - select_clause_element: @@ -213,7 +214,8 @@ file: - expression: - quoted_literal: '''UTC''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: started_at - comma: ',' - select_clause_element: @@ -234,7 +236,8 @@ file: - expression: - quoted_literal: '''UTC''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: ended_at - comma: ',' - select_clause_element: @@ -255,7 +258,8 @@ file: - expression: - quoted_literal: '''UTC''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: created_at - comma: ',' - select_clause_element: @@ -276,7 +280,8 @@ file: - data_type: - keyword: VARCHAR - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: communication_request_fhir_reference_origin - comma: ',' - select_clause_element: @@ -290,9 +295,10 @@ file: - function: - function_name: - function_name_identifier: GETDATE - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - time_zone_grammar: - keyword: AT - keyword: TIME @@ -308,9 +314,10 @@ file: - function: - function_name: - function_name_identifier: GETDATE - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - time_zone_grammar: - keyword: AT - keyword: TIME @@ -336,9 +343,10 @@ file: - function: - function_name: - function_name_identifier: GETDATE - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - time_zone_grammar: - keyword: AT - keyword: TIME diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/deallocate.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/deallocate.sql new file mode 100644 index 000000000..dc7a1076f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/deallocate.sql @@ -0,0 +1,3 @@ +DEALLOCATE statement_name; + +DEALLOCATE PREPARE statement_name; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/deallocate.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/deallocate.yml new file mode 100644 index 000000000..d44f68d9b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/deallocate.yml @@ -0,0 +1,14 @@ +file: +- statement: + - deallocate_statement: + - keyword: DEALLOCATE + - object_reference: + - naked_identifier: statement_name +- statement_terminator: ; +- statement: + - deallocate_statement: + - keyword: DEALLOCATE + - keyword: PREPARE + - object_reference: + - naked_identifier: statement_name +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/declare.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/declare.yml index efaf9ab0e..07b17945d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/declare.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/declare.yml @@ -50,7 +50,8 @@ file: - column_reference: - naked_identifier: qtysold - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: costperticket - comma: ',' - select_clause_element: diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/execute.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/execute.sql new file mode 100644 index 000000000..0f5ffc07c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/execute.sql @@ -0,0 +1,5 @@ +EXECUTE statement_name; + +EXECUTE statement_name (1); + +EXECUTE statement_name (1, 'foo'); diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/execute.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/execute.yml new file mode 100644 index 000000000..5be0f4b61 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/execute.yml @@ -0,0 +1,32 @@ +file: +- statement: + - execute_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: statement_name +- statement_terminator: ; +- statement: + - execute_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: statement_name + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - end_bracket: ) +- statement_terminator: ; +- statement: + - execute_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: statement_name + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - quoted_literal: '''foo''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/merge.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/merge.sql new file mode 100644 index 000000000..c8e3b9d4a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/merge.sql @@ -0,0 +1,9 @@ +MERGE INTO target USING source ON target.id = source.id +WHEN MATCHED THEN UPDATE SET id = source.id, name = source.name +WHEN NOT MATCHED THEN INSERT VALUES (source.id, source.name); + +MERGE INTO target USING source ON target.id = source.id +WHEN MATCHED THEN DELETE +WHEN NOT MATCHED THEN INSERT VALUES (source.id, source.name); + +MERGE INTO target USING source ON target.id = source.id REMOVE DUPLICATES; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/merge.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/merge.yml new file mode 100644 index 000000000..919988764 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/merge.yml @@ -0,0 +1,153 @@ +file: +- statement: + - merge_statement: + - keyword: MERGE + - keyword: INTO + - table_reference: + - naked_identifier: target + - keyword: USING + - table_reference: + - naked_identifier: source + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: target + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: id + - merge_match: + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: THEN + - merge_update_clause: + - keyword: UPDATE + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: id + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: name + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: name + - merge_when_not_matched_clause: + - keyword: WHEN + - keyword: NOT + - keyword: MATCHED + - keyword: THEN + - merge_insert_clause: + - keyword: INSERT + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: id + - comma: ',' + - expression: + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: name + - end_bracket: ) +- statement_terminator: ; +- statement: + - merge_statement: + - keyword: MERGE + - keyword: INTO + - table_reference: + - naked_identifier: target + - keyword: USING + - table_reference: + - naked_identifier: source + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: target + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: id + - merge_match: + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: THEN + - merge_delete_clause: + - keyword: DELETE + - merge_when_not_matched_clause: + - keyword: WHEN + - keyword: NOT + - keyword: MATCHED + - keyword: THEN + - merge_insert_clause: + - keyword: INSERT + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: id + - comma: ',' + - expression: + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: name + - end_bracket: ) +- statement_terminator: ; +- statement: + - merge_statement: + - keyword: MERGE + - keyword: INTO + - table_reference: + - naked_identifier: target + - keyword: USING + - table_reference: + - naked_identifier: source + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: target + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: id + - keyword: REMOVE + - keyword: DUPLICATES +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/object_unpivot.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/object_unpivot.yml index 9102cd85b..778f8b8db 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/object_unpivot.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/object_unpivot.yml @@ -14,20 +14,23 @@ file: - select_clause_element: - numeric_literal: '10' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: shop_id - comma: ',' - select_clause_element: - function: - function_name: - function_name_identifier: json_parse - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''{"apple_count": 2, "orange_count": 6}''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''{"apple_count": 2, "orange_count": 6}''' + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: inventory - set_operator: - keyword: UNION @@ -38,20 +41,23 @@ file: - select_clause_element: - numeric_literal: '20' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: shop_id - comma: ',' - select_clause_element: - function: - function_name: - function_name_identifier: json_parse - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''{"pear_count": 10, "other_data": 42}''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''{"pear_count": 10, "other_data": 42}''' + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: inventory - set_operator: - keyword: UNION @@ -62,20 +68,23 @@ file: - select_clause_element: - numeric_literal: '30' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: shop_id - comma: ',' - select_clause_element: - function: - function_name: - function_name_identifier: json_parse - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''{"apple_count": 3, "lemon_count": 5}''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''{"apple_count": 3, "lemon_count": 5}''' + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: inventory - end_bracket: ) - select_statement: @@ -124,14 +133,16 @@ file: - column_reference: - naked_identifier: attr - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: attribute_name - comma: ',' - select_clause_element: - column_reference: - naked_identifier: val - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: object_value - from_clause: - keyword: FROM @@ -151,7 +162,8 @@ file: - dot: . - naked_identifier: c_orders - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: o - comma: ',' - from_expression: diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/pattern_match_expressions.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/pattern_match_expressions.yml index 42f2e92f3..8e26aa750 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/pattern_match_expressions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/pattern_match_expressions.yml @@ -152,21 +152,23 @@ file: - function: - function_name: - function_name_identifier: COALESCE - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: family - - keyword: LIKE - - quoted_literal: '''%ursidae%''' - - keyword: ESCAPE - - quoted_literal: '''\\''' - - comma: ',' - - expression: - - boolean_literal: 'FALSE' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: family + - keyword: LIKE + - quoted_literal: '''%ursidae%''' + - keyword: ESCAPE + - quoted_literal: '''\\''' + - comma: ',' + - expression: + - boolean_literal: 'FALSE' + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: is_bear - from_clause: - keyword: FROM @@ -335,22 +337,24 @@ file: - function: - function_name: - function_name_identifier: COALESCE - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: family - - keyword: SIMILAR - - keyword: TO - - quoted_literal: '''%ursidae%''' - - keyword: ESCAPE - - quoted_literal: '''\\''' - - comma: ',' - - expression: - - boolean_literal: 'FALSE' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: family + - keyword: SIMILAR + - keyword: TO + - quoted_literal: '''%ursidae%''' + - keyword: ESCAPE + - quoted_literal: '''\\''' + - comma: ',' + - expression: + - boolean_literal: 'FALSE' + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: is_bear - from_clause: - keyword: FROM @@ -379,34 +383,36 @@ file: - function: - function_name: - function_name_identifier: TO_NUMBER - - bracketed: - - start_bracket: ( - - expression: - - case_expression: - - keyword: CASE - - when_clause: - - keyword: WHEN - - expression: - - column_reference: - - naked_identifier: honey_numerical_code - - keyword: SIMILAR - - keyword: TO - - quoted_literal: '''[0-9]{0,7}.?[0-9]{0,2}''' - - keyword: THEN - - expression: - - column_reference: - - naked_identifier: honey_numerical_code - - else_clause: - - keyword: ELSE - - expression: - - null_literal: 'NULL' - - keyword: END - - comma: ',' - - expression: - - quoted_literal: '''24601''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: honey_numerical_code + - keyword: SIMILAR + - keyword: TO + - quoted_literal: '''[0-9]{0,7}.?[0-9]{0,2}''' + - keyword: THEN + - expression: + - column_reference: + - naked_identifier: honey_numerical_code + - else_clause: + - keyword: ELSE + - expression: + - null_literal: 'NULL' + - keyword: END + - comma: ',' + - expression: + - quoted_literal: '''24601''' + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: honey_numerical_code - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/percentile_cont.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/percentile_cont.yml index 80be1b062..962f026b1 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/percentile_cont.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/percentile_cont.yml @@ -15,11 +15,12 @@ file: - function: - function_name: - function_name_identifier: percentile_cont - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '0.20' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.20' + - end_bracket: ) - withingroup_clause: - keyword: within - keyword: group @@ -46,18 +47,20 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: percentile_20 - comma: ',' - select_clause_element: - function: - function_name: - function_name_identifier: percentile_cont - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '0.40' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.40' + - end_bracket: ) - withingroup_clause: - keyword: within - keyword: group @@ -83,7 +86,8 @@ file: - naked_identifier: dataset_id - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: percentile_40 - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/pivot.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/pivot.yml index 3d5cfa4fd..b47b95630 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/pivot.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/pivot.yml @@ -39,12 +39,13 @@ file: - function: - function_name: - function_name_identifier: AVG - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: price - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: price + - end_bracket: ) - keyword: FOR - column_reference: - naked_identifier: partname @@ -102,10 +103,11 @@ file: - function: - function_name: - function_name_identifier: COUNT - - bracketed: - - start_bracket: ( - - star: '*' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) - keyword: FOR - column_reference: - naked_identifier: quality @@ -163,12 +165,14 @@ file: - function: - function_name: - function_name_identifier: COUNT - - bracketed: - - start_bracket: ( - - star: '*' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: count - keyword: FOR - column_reference: @@ -179,19 +183,22 @@ file: - expression: - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: high - comma: ',' - expression: - numeric_literal: '2' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: low - comma: ',' - expression: - null_literal: 'NULL' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: na - end_bracket: ) - end_bracket: ) @@ -247,12 +254,14 @@ file: - function: - function_name: - function_name_identifier: COUNT - - bracketed: - - start_bracket: ( - - star: '*' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: num_ate_food - keyword: FOR - column_reference: @@ -308,10 +317,11 @@ file: - function: - function_name: - function_name_identifier: COUNT - - bracketed: - - start_bracket: ( - - star: '*' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) - keyword: FOR - column_reference: - naked_identifier: color @@ -366,10 +376,11 @@ file: - function: - function_name: - function_name_identifier: COUNT - - bracketed: - - start_bracket: ( - - star: '*' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) - keyword: FOR - column_reference: - naked_identifier: quality @@ -387,6 +398,7 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: quality_matrix - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/prepare.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/prepare.sql new file mode 100644 index 000000000..f32efa4e8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/prepare.sql @@ -0,0 +1,17 @@ +PREPARE select_statement AS +SELECT * FROM table1; + +PREPARE insert_statement AS +INSERT INTO table1 (col1, col2) VALUES (1, 'foo'); + +PREPARE update_statement AS +UPDATE table1 SET col2 = 'bar' WHERE col1 = 1; + +PREPARE delete_statement AS +DELETE FROM table1 WHERE col1 = 1; + +PREPARE parametrized_statement_1 (int) AS +SELECT ($1); + +PREPARE parametrized_statement_2 (int, character(3)) AS +SELECT $1, $2; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/prepare.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/prepare.yml new file mode 100644 index 000000000..c3920af2f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/prepare.yml @@ -0,0 +1,149 @@ +file: +- statement: + - prepare_statement: + - keyword: PREPARE + - object_reference: + - naked_identifier: select_statement + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - prepare_statement: + - keyword: PREPARE + - object_reference: + - naked_identifier: insert_statement + - keyword: AS + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: table1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - quoted_literal: '''foo''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - prepare_statement: + - keyword: PREPARE + - object_reference: + - naked_identifier: update_statement + - keyword: AS + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: table1 + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col2 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''bar''' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - prepare_statement: + - keyword: PREPARE + - object_reference: + - naked_identifier: delete_statement + - keyword: AS + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - prepare_statement: + - keyword: PREPARE + - object_reference: + - naked_identifier: parametrized_statement_1 + - bracketed: + - start_bracket: ( + - data_type: + - keyword: int + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - bracketed: + - start_bracket: ( + - expression: + - dollar_numeric_literal: $1 + - end_bracket: ) +- statement_terminator: ; +- statement: + - prepare_statement: + - keyword: PREPARE + - object_reference: + - naked_identifier: parametrized_statement_2 + - bracketed: + - start_bracket: ( + - data_type: + - keyword: int + - comma: ',' + - data_type: + - keyword: character + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '3' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - dollar_numeric_literal: $1 + - comma: ',' + - select_clause_element: + - dollar_numeric_literal: $2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/qualify.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/qualify.yml index bcddea0c6..3da36029d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/qualify.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/qualify.yml @@ -33,9 +33,10 @@ file: - function: - function_name: - function_name_identifier: row_number - - bracketed: - - start_bracket: ( - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) - over_clause: - keyword: OVER - bracketed: @@ -82,12 +83,13 @@ file: - function: - function_name: - function_name_identifier: last_value - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: ss_item - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: ss_item + - end_bracket: ) - over_clause: - keyword: OVER - bracketed: @@ -146,12 +148,13 @@ file: - function: - function_name: - function_name_identifier: last_value - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: ss_item - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: ss_item + - end_bracket: ) - over_clause: - keyword: OVER - bracketed: diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select.sql new file mode 100644 index 000000000..8d1be3fef --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select.sql @@ -0,0 +1,4 @@ +SELECT foo, baz, SUM(*) +FROM bar +GROUP BY ALL +; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alias_standard_as.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select.yml similarity index 55% rename from crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alias_standard_as.yml rename to crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select.yml index b1665b52a..a0b128a5c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alias_standard_as.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select.yml @@ -3,6 +3,14 @@ file: - select_statement: - select_clause: - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: foo + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: baz + - comma: ',' - select_clause_element: - function: - function_name: @@ -10,18 +18,17 @@ file: - function_contents: - bracketed: - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: quantity + - star: '*' - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: StandardAlias - from_clause: - keyword: FROM - from_expression: - from_expression_element: - table_expression: - table_reference: - - object_reference: - - naked_identifier: table1 + - naked_identifier: bar + - groupby_clause: + - keyword: GROUP + - keyword: BY + - keyword: ALL +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_dateadd.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_dateadd.yml index dd26a22b1..9483141b9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_dateadd.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_dateadd.yml @@ -7,14 +7,15 @@ file: - function: - function_name: - function_name_identifier: dateadd - - bracketed: - - start_bracket: ( - - date_part: month - - comma: ',' - - expression: - - numeric_literal: '18' - - comma: ',' - - expression: - - quoted_literal: '''2008-02-28''' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: month + - comma: ',' + - expression: + - numeric_literal: '18' + - comma: ',' + - expression: + - quoted_literal: '''2008-02-28''' + - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_datetime_functions.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_datetime_functions.yml index 5977a3e78..662bed687 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_datetime_functions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_datetime_functions.yml @@ -28,11 +28,12 @@ file: - function: - function_name: - function_name_identifier: TRUNC - - bracketed: - - start_bracket: ( - - expression: - - bare_function: sysdate - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - bare_function: sysdate + - end_bracket: ) - statement_terminator: ; - statement: - select_statement: @@ -50,27 +51,31 @@ file: - function: - function_name: - function_name_identifier: TRUNC - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: saletime - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: saletime + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: saletime - comma: ',' - select_clause_element: - function: - function_name: - function_name_identifier: TRUNC - - bracketed: - - start_bracket: ( - - expression: - - bare_function: sysdate - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - bare_function: sysdate + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: now - from_clause: - keyword: FROM @@ -88,22 +93,24 @@ file: - function: - function_name: - function_name_identifier: TRUNC - - bracketed: - - start_bracket: ( - - expression: - - bare_function: sysdate - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - bare_function: sysdate + - end_bracket: ) - binary_operator: '-' - numeric_literal: '120' - keyword: AND - function: - function_name: - function_name_identifier: TRUNC - - bracketed: - - start_bracket: ( - - expression: - - bare_function: sysdate - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - bare_function: sysdate + - end_bracket: ) - orderby_clause: - keyword: ORDER - keyword: BY diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_exclude.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_exclude.sql new file mode 100644 index 000000000..f4f7ea9ad --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_exclude.sql @@ -0,0 +1,7 @@ +SELECT * EXCLUDE col1 FROM table1; + +SELECT * EXCLUDE col1, col2 FROM table1; + +SELECT * EXCLUDE (col1) FROM table1; + +SELECT * EXCLUDE (col1, col2) FROM table1; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_exclude.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_exclude.yml new file mode 100644 index 000000000..af9a74ef2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_exclude.yml @@ -0,0 +1,89 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - select_exclude_clause: + - keyword: EXCLUDE + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - select_exclude_clause: + - keyword: EXCLUDE + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - select_exclude_clause: + - keyword: EXCLUDE + - bracketed: + - start_bracket: ( + - naked_identifier: col1 + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - select_exclude_clause: + - keyword: EXCLUDE + - bracketed: + - start_bracket: ( + - naked_identifier: col1 + - comma: ',' + - naked_identifier: col2 + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_first_value.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_first_value.yml index d64e06ff9..28f8fbce4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_first_value.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_first_value.yml @@ -7,21 +7,23 @@ file: - function: - function_name: - function_name_identifier: first_value - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: finalsaleprice - - keyword: ignore - - keyword: nulls - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: finalsaleprice + - keyword: ignore + - keyword: nulls + - end_bracket: ) - over_clause: - keyword: over - bracketed: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: c1 - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_into.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_into.yml index ae4d736e5..c1f001a3c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_into.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_into.yml @@ -35,17 +35,19 @@ file: - function: - function_name: - function_name_identifier: sum - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: pricepaid - - binary_operator: '-' - - column_reference: - - naked_identifier: commission - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: pricepaid + - binary_operator: '-' + - column_reference: + - naked_identifier: commission + - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: profit - into_clause: - keyword: into diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_keywords.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_keywords.yml index 7a74f830d..dae757396 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_keywords.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/select_keywords.yml @@ -9,7 +9,8 @@ file: - dot: . - naked_identifier: nspname - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: constraint_schema - comma: ',' - select_clause_element: @@ -18,7 +19,8 @@ file: - dot: . - naked_identifier: conname - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: constraint_name - from_clause: - keyword: FROM @@ -39,7 +41,7 @@ file: - column_reference: - naked_identifier: pg_namespace - dot: . - - naked_identifier: oid + - naked_identifier_all: oid - comparison_operator: - raw_comparison_operator: = - column_reference: @@ -57,10 +59,10 @@ file: - select_statement: - select_clause: - keyword: select + - select_clause_modifier: + - keyword: distinct - select_clause_element: - - function: - - function_name: - - function_name_identifier: distinct + - expression: - bracketed: - start_bracket: ( - expression: @@ -74,12 +76,13 @@ file: - function: - function_name: - function_name_identifier: trim - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: datname - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: datname + - end_bracket: ) - alias_expression: - naked_identifier: db_name - comma: ',' @@ -87,12 +90,13 @@ file: - function: - function_name: - function_name_identifier: trim - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: nspname - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: nspname + - end_bracket: ) - alias_expression: - naked_identifier: schema_name - comma: ',' @@ -100,12 +104,13 @@ file: - function: - function_name: - function_name_identifier: trim - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: relname - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: relname + - end_bracket: ) - alias_expression: - naked_identifier: table_name - from_clause: @@ -127,7 +132,7 @@ file: - column_reference: - naked_identifier: pg_class - dot: . - - naked_identifier: oid + - naked_identifier_all: oid - comparison_operator: - raw_comparison_operator: = - column_reference: @@ -146,7 +151,7 @@ file: - column_reference: - naked_identifier: pg_namespace - dot: . - - naked_identifier: oid + - naked_identifier_all: oid - comparison_operator: - raw_comparison_operator: = - column_reference: @@ -163,7 +168,7 @@ file: - column_reference: - naked_identifier: pg_database - dot: . - - naked_identifier: oid + - naked_identifier_all: oid - comparison_operator: - raw_comparison_operator: = - column_reference: diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/set_operators.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/set_operators.sql new file mode 100644 index 000000000..e11b13c0a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/set_operators.sql @@ -0,0 +1,19 @@ +SELECT col FROM tab1 +MINUS +(SELECT col FROM tab2); + +SELECT col FROM tab1 +EXCEPT +(SELECT col FROM tab2); + +SELECT col FROM tab1 +UNION +(SELECT col FROM tab2); + +SELECT col FROM tab1 +INTERSECT +(SELECT col FROM tab2); + +SELECT col FROM tab1 +UNION ALL +(SELECT col FROM tab2); diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/set_operators.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/set_operators.yml new file mode 100644 index 000000000..ba20abb86 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/set_operators.yml @@ -0,0 +1,172 @@ +file: +- statement: + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab1 + - set_operator: + - keyword: MINUS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab1 + - set_operator: + - keyword: EXCEPT + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab1 + - set_operator: + - keyword: UNION + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab1 + - set_operator: + - keyword: INTERSECT + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab1 + - set_operator: + - keyword: UNION + - keyword: ALL + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab2 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/super_data_type.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/super_data_type.yml index f32b4b46a..fd5f3a421 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/super_data_type.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/super_data_type.yml @@ -46,10 +46,11 @@ file: - function: - function_name: - function_name_identifier: COUNT - - bracketed: - - start_bracket: ( - - star: '*' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) - from_clause: - keyword: FROM - from_expression: @@ -98,19 +99,20 @@ file: - function: - function_name: - function_name_identifier: JSON_TYPEOF - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: c_orders - - array_accessor: - - start_square_bracket: '[' - - numeric_literal: '0' - - end_square_bracket: ']' - - semi_structured_expression: - - dot: . - - naked_identifier: o_orderstatus - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c_orders + - array_accessor: + - start_square_bracket: '[' + - numeric_literal: '0' + - end_square_bracket: ']' + - semi_structured_expression: + - dot: . + - naked_identifier: o_orderstatus + - end_bracket: ) - comparison_operator: - raw_comparison_operator: = - quoted_literal: '''string''' @@ -298,19 +300,20 @@ file: - function: - function_name: - function_name_identifier: COUNT - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: messages - - array_accessor: - - start_square_bracket: '[' - - numeric_literal: '0' - - end_square_bracket: ']' - - semi_structured_expression: - - dot: . - - naked_identifier: topic - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: messages + - array_accessor: + - start_square_bracket: '[' + - numeric_literal: '0' + - end_square_bracket: ']' + - semi_structured_expression: + - dot: . + - naked_identifier: topic + - end_bracket: ) - from_clause: - keyword: FROM - from_expression: diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/unload.sql b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/unload.sql index 5a00954fe..a0378336c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/unload.sql +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/unload.sql @@ -86,3 +86,8 @@ unload ('select * from venue') to 's3://mybucket/nulls/' iam_role 'arn:aws:iam::0123456789012:role/MyRedshiftRole' null as 'fred'; + +unload ('select * from tbl') +to 's3://mybucket/unload/' +csv header credentials 'aws_access_key_id=abc;aws_secret_access_key=def' +extension 'csv' parallel false; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/unload.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/unload.yml index 203b8a8c1..0135aca97 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/unload.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/unload.yml @@ -257,3 +257,22 @@ file: - keyword: as - quoted_literal: '''fred''' - statement_terminator: ; +- statement: + - unload_statement: + - keyword: unload + - bracketed: + - start_bracket: ( + - quoted_literal: '''select * from tbl''' + - end_bracket: ) + - keyword: to + - quoted_literal: '''s3://mybucket/unload/''' + - keyword: csv + - keyword: header + - authorization_segment: + - keyword: credentials + - quoted_literal: '''aws_access_key_id=abc;aws_secret_access_key=def''' + - keyword: extension + - quoted_literal: '''csv''' + - keyword: parallel + - keyword: 'false' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/unpivot.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/unpivot.yml index c5d7c6d10..d767a924e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/unpivot.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/unpivot.yml @@ -189,19 +189,22 @@ file: - column_reference: - naked_identifier: red - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: r - comma: ',' - column_reference: - naked_identifier: green - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: g - comma: ',' - column_reference: - naked_identifier: blue - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: b - end_bracket: ) - end_bracket: ) @@ -408,6 +411,7 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: floofy_bears - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/update.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/update.yml index f10e846a4..bdc78cfe7 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/update.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/update.yml @@ -20,7 +20,8 @@ file: - table_reference: - naked_identifier: tbl1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: set - set_clause_list: - keyword: set diff --git a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/window_functions.yml b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/window_functions.yml index c49f7af2d..e7e573f75 100644 --- a/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/window_functions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/redshift/sqlfluff/window_functions.yml @@ -7,15 +7,16 @@ file: - function: - function_name: - function_name_identifier: lead - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: col1 - - comma: ',' - - expression: - - numeric_literal: '1' - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - expression: + - numeric_literal: '1' + - end_bracket: ) - over_clause: - keyword: respect - keyword: nulls diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_account.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_account.sql index 207bb14a8..0e10e47db 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_account.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_account.sql @@ -24,3 +24,5 @@ ALTER ACCOUNT SET TAG ; ALTER ACCOUNT UNSET TAG env, domain; + +ALTER ACCOUNT SET EVENT_TABLE = LOG_TRACE_DB.PUBLIC.EVENT_TABLE; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_account.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_account.yml index d42834bc0..93200041b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_account.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_account.yml @@ -1,126 +1,152 @@ file: - statement: - - keyword: ALTER - - keyword: ACCOUNT - - keyword: SET - - parameter: TIMEZONE - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''UTC''' + - alter_account_statement: + - keyword: ALTER + - keyword: ACCOUNT + - keyword: SET + - parameter: TIMEZONE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''UTC''' +- statement_terminator: ; +- statement: + - alter_account_statement: + - keyword: ALTER + - keyword: ACCOUNT + - keyword: SET + - parameter: ALLOW_ID_TOKEN + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - comma: ',' + - parameter: DEFAULT_DDL_COLLATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''en-ci''' + - comma: ',' + - parameter: CLIENT_ENCRYPTION_KEY_SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '128' + - comma: ',' + - parameter: NETWORK_POLICY + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: mypolicy - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: ACCOUNT - - keyword: SET - - parameter: ALLOW_ID_TOKEN - - comparison_operator: - - raw_comparison_operator: = - - boolean_literal: 'TRUE' - - comma: ',' - - parameter: DEFAULT_DDL_COLLATION - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''en-ci''' - - comma: ',' - - parameter: CLIENT_ENCRYPTION_KEY_SIZE - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '128' - - comma: ',' - - parameter: NETWORK_POLICY - - comparison_operator: - - raw_comparison_operator: = - - naked_identifier: mypolicy + - alter_account_statement: + - keyword: ALTER + - keyword: ACCOUNT + - keyword: UNSET + - naked_identifier: TIMEZONE - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: ACCOUNT - - keyword: UNSET - - naked_identifier: TIMEZONE + - alter_account_statement: + - keyword: ALTER + - keyword: ACCOUNT + - keyword: UNSET + - naked_identifier: DATA_RETENTION_TIME_IN_DAYS + - comma: ',' + - naked_identifier: JSON_INDENT - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: ACCOUNT - - keyword: UNSET - - naked_identifier: DATA_RETENTION_TIME_IN_DAYS - - comma: ',' - - naked_identifier: JSON_INDENT + - alter_account_statement: + - keyword: ALTER + - keyword: ACCOUNT + - keyword: SET + - keyword: RESOURCE_MONITOR + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: VERY_RESTRICTIVE_MONITOR - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: ACCOUNT - - keyword: SET - - keyword: RESOURCE_MONITOR - - comparison_operator: - - raw_comparison_operator: = - - naked_identifier: VERY_RESTRICTIVE_MONITOR + - alter_account_statement: + - keyword: ALTER + - keyword: ACCOUNT + - keyword: SET + - keyword: PASSWORD + - keyword: POLICY + - table_reference: + - naked_identifier: mydb + - dot: . + - naked_identifier: security + - dot: . + - naked_identifier: at_least_twelve_characters - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: ACCOUNT - - keyword: SET - - keyword: PASSWORD - - keyword: POLICY - - table_reference: - - naked_identifier: mydb - - dot: . - - naked_identifier: security - - dot: . - - naked_identifier: at_least_twelve_characters + - alter_account_statement: + - keyword: ALTER + - keyword: ACCOUNT + - keyword: SET + - keyword: SESSION + - keyword: POLICY + - table_reference: + - naked_identifier: mydb + - dot: . + - naked_identifier: policies + - dot: . + - naked_identifier: only_one_hour - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: ACCOUNT - - keyword: SET - - keyword: SESSION - - keyword: POLICY - - table_reference: - - naked_identifier: mydb - - dot: . - - naked_identifier: policies - - dot: . - - naked_identifier: only_one_hour + - alter_account_statement: + - keyword: ALTER + - keyword: ACCOUNT + - keyword: UNSET + - keyword: PASSWORD + - keyword: POLICY - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: ACCOUNT - - keyword: UNSET - - keyword: PASSWORD - - keyword: POLICY + - alter_account_statement: + - keyword: ALTER + - keyword: ACCOUNT + - keyword: UNSET + - keyword: SESSION + - keyword: POLICY - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: ACCOUNT - - keyword: UNSET - - keyword: SESSION - - keyword: POLICY + - alter_account_statement: + - keyword: ALTER + - keyword: ACCOUNT + - keyword: SET + - tag_equals: + - keyword: TAG + - tag_reference: + - naked_identifier: env + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''prod''' + - comma: ',' + - tag_reference: + - naked_identifier: domain + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''sales''' - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: ACCOUNT - - keyword: SET - - tag_equals: + - alter_account_statement: + - keyword: ALTER + - keyword: ACCOUNT + - keyword: UNSET - keyword: TAG - tag_reference: - naked_identifier: env - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''prod''' - comma: ',' - tag_reference: - naked_identifier: domain - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''sales''' - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: ACCOUNT - - keyword: UNSET - - keyword: TAG - - tag_reference: - - naked_identifier: env - - comma: ',' - - tag_reference: - - naked_identifier: domain + - alter_account_statement: + - keyword: ALTER + - keyword: ACCOUNT + - keyword: SET + - parameter: EVENT_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - naked_identifier: LOG_TRACE_DB + - dot: . + - naked_identifier: PUBLIC + - dot: . + - naked_identifier: EVENT_TABLE - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_cortex_search_service.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_cortex_search_service.sql new file mode 100644 index 000000000..8ce96b8a1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_cortex_search_service.sql @@ -0,0 +1,8 @@ +ALTER CORTEX SEARCH SERVICE mysvc SET WAREHOUSE = my_new_wh; +ALTER CORTEX SEARCH SERVICE mysvc SET COMMENT = 'new_comment'; +ALTER CORTEX SEARCH SERVICE mysvc set target_lag = '1 hour'; +ALTER CORTEX SEARCH SERVICE mysvc SUSPEND SERVING; +alter cortex search service mysvc resume indexing; +alter cortex search service if exists mysvc suspend indexing; +ALTER CORTEX SEARCH SERVICE mysvc SET WAREHOUSE = my_new_wh; +ALTER CORTEX SEARCH SERVICE mysvc SET COMMENT = 'new_comment' target_lag = '1 hour'; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_cortex_search_service.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_cortex_search_service.yml new file mode 100644 index 000000000..89d2f7b04 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_cortex_search_service.yml @@ -0,0 +1,114 @@ +file: +- statement: + - alter_streamlit_statement: + - keyword: ALTER + - keyword: CORTEX + - keyword: SEARCH + - keyword: SERVICE + - object_reference: + - naked_identifier: mysvc + - keyword: SET + - keyword: WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_new_wh +- statement_terminator: ; +- statement: + - alter_streamlit_statement: + - keyword: ALTER + - keyword: CORTEX + - keyword: SEARCH + - keyword: SERVICE + - object_reference: + - naked_identifier: mysvc + - keyword: SET + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''new_comment''' +- statement_terminator: ; +- statement: + - alter_streamlit_statement: + - keyword: ALTER + - keyword: CORTEX + - keyword: SEARCH + - keyword: SERVICE + - object_reference: + - naked_identifier: mysvc + - keyword: set + - keyword: target_lag + - comparison_operator: + - raw_comparison_operator: = + - dynamic_table_lag_interval_segment: '''1 hour''' +- statement_terminator: ; +- statement: + - alter_streamlit_statement: + - keyword: ALTER + - keyword: CORTEX + - keyword: SEARCH + - keyword: SERVICE + - object_reference: + - naked_identifier: mysvc + - keyword: SUSPEND + - keyword: SERVING +- statement_terminator: ; +- statement: + - alter_streamlit_statement: + - keyword: alter + - keyword: cortex + - keyword: search + - keyword: service + - object_reference: + - naked_identifier: mysvc + - keyword: resume + - keyword: indexing +- statement_terminator: ; +- statement: + - alter_streamlit_statement: + - keyword: alter + - keyword: cortex + - keyword: search + - keyword: service + - keyword: if + - keyword: exists + - object_reference: + - naked_identifier: mysvc + - keyword: suspend + - keyword: indexing +- statement_terminator: ; +- statement: + - alter_streamlit_statement: + - keyword: ALTER + - keyword: CORTEX + - keyword: SEARCH + - keyword: SERVICE + - object_reference: + - naked_identifier: mysvc + - keyword: SET + - keyword: WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_new_wh +- statement_terminator: ; +- statement: + - alter_streamlit_statement: + - keyword: ALTER + - keyword: CORTEX + - keyword: SEARCH + - keyword: SERVICE + - object_reference: + - naked_identifier: mysvc + - keyword: SET + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''new_comment''' + - keyword: target_lag + - comparison_operator: + - raw_comparison_operator: = + - dynamic_table_lag_interval_segment: '''1 hour''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_dynamic_table.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_dynamic_table.sql new file mode 100644 index 000000000..808f99c16 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_dynamic_table.sql @@ -0,0 +1,135 @@ +ALTER DYNAMIC TABLE foo REFRESH; + +ALTER DYNAMIC TABLE my_dynamic_table SUSPEND; + +ALTER DYNAMIC TABLE IF EXISTS my_dynamic_table SUSPEND; + +ALTER DYNAMIC TABLE my_dynamic_table RESUME; + +ALTER DYNAMIC TABLE my_dynamic_table RENAME TO my_updated_dynamic_table; + +ALTER DYNAMIC TABLE my_dynamic_table SWAP WITH my_new_dynamic_table; + +ALTER DYNAMIC TABLE my_dynamic_table REFRESH; + +ALTER DYNAMIC TABLE my_dynamic_table REFRESH COPY SESSION; + +ALTER DYNAMIC TABLE my_dynamic_table CLUSTER BY (date); + +ALTER DYNAMIC TABLE my_dynamic_table CLUSTER BY (c1, c2); + +ALTER DYNAMIC TABLE my_dynamic_table DROP CLUSTERING KEY; + +ALTER DYNAMIC TABLE my_dynamic_table RESUME RECLUSTER; + +ALTER DYNAMIC TABLE my_dynamic_table SUSPEND RECLUSTER; + +ALTER DYNAMIC TABLE my_dynamic_table SET COMMENT = 'a dynamic table comment'; + +ALTER DYNAMIC TABLE my_dynamic_table UNSET COMMENT; + +ALTER DYNAMIC TABLE my_dynamic_table SET TAG my_tag = 'tag_value'; + +ALTER DYNAMIC TABLE my_dynamic_table SET TAG my_tag = 'tag_value', +my_other_tag = 'other_value'; + +ALTER DYNAMIC TABLE my_dynamic_table UNSET TAG my_tag; + +ALTER DYNAMIC TABLE my_dynamic_table ADD ROW ACCESS POLICY rap ON (pii1); + +ALTER DYNAMIC TABLE my_dynamic_table ADD ROW ACCESS POLICY rap ON (pii1, pii2); + +ALTER DYNAMIC TABLE my_dynamic_table DROP ROW ACCESS POLICY rap; + +ALTER DYNAMIC TABLE my_dynamic_table DROP ROW ACCESS POLICY rap, +ADD ROW ACCESS POLICY rap ON (pii1, pii2); + +ALTER DYNAMIC TABLE my_dynamic_table DROP ALL ROW ACCESS POLICIES; + +ALTER DYNAMIC TABLE my_dynamic_table SET AGGREGATION POLICY my_policy; + +ALTER DYNAMIC TABLE my_dynamic_table +SET AGGREGATION POLICY my_policy ENTITY KEY (col1); + +ALTER DYNAMIC TABLE my_dynamic_table +SET AGGREGATION POLICY my_policy ENTITY KEY (col1, col2, col3); + +ALTER DYNAMIC TABLE my_dynamic_table SET AGGREGATION POLICY my_policy FORCE; + +ALTER DYNAMIC TABLE my_dynamic_table +SET AGGREGATION POLICY my_policy ENTITY KEY (col1) FORCE; + +ALTER DYNAMIC TABLE my_table UNSET AGGREGATION POLICY; + +ALTER DYNAMIC TABLE my_dynamic_table ADD SEARCH OPTIMIZATION; + +ALTER DYNAMIC TABLE my_dynamic_table ADD SEARCH OPTIMIZATION +ON EQUALITY (c1), EQUALITY (c2, c3); + +ALTER DYNAMIC TABLE my_dynamic_table ADD SEARCH OPTIMIZATION +ON EQUALITY (*); + +ALTER DYNAMIC TABLE my_dynamic_table ADD SEARCH OPTIMIZATION +ON EQUALITY (*), SUBSTRING (*), GEO (*); + +ALTER DYNAMIC TABLE my_dynamic_table ADD SEARCH OPTIMIZATION +ON EQUALITY (c1, c2); + +ALTER DYNAMIC TABLE my_dynamic_table DROP SEARCH OPTIMIZATION +ON EQUALITY (c1), EQUALITY (c2, c3); + +ALTER DYNAMIC TABLE my_dynamic_table DROP SEARCH OPTIMIZATION +ON EQUALITY (c1, c2), 5, c3; + +ALTER DYNAMIC TABLE my_dynamic_table SUSPEND SEARCH OPTIMIZATION +ON EQUALITY (c1), EQUALITY (c2, c3); + +ALTER DYNAMIC TABLE my_dynamic_table SUSPEND SEARCH OPTIMIZATION +ON EQUALITY (c1, c2), 5, c3; + +ALTER DYNAMIC TABLE my_dynamic_table RESUME SEARCH OPTIMIZATION +ON EQUALITY (c1), EQUALITY (c2, c3); + +ALTER DYNAMIC TABLE my_dynamic_table RESUME SEARCH OPTIMIZATION +ON EQUALITY (c1, c2), 5, c3; + +ALTER DYNAMIC TABLE my_dynamic_table SET TARGET_LAG = '1 hour'; + +ALTER DYNAMIC TABLE my_dynamic_table SET TARGET_LAG = DOWNSTREAM; + +ALTER DYNAMIC TABLE my_dynamic_table SET WAREHOUSE = my_warehouse; + +ALTER DYNAMIC TABLE my_dynamic_table SET DATA_RETENTION_TIME_IN_DAYS = 7; + +ALTER DYNAMIC TABLE my_dynamic_table SET MAX_DATA_EXTENSION_TIME_IN_DAYS = 7; + +ALTER DYNAMIC TABLE my_dynamic_table SET DEFAULT_DDL_COLLATION = 'en_US-trim'; + +-- TODO: Validate if DEBUG might be quoted or must be quoted +ALTER DYNAMIC TABLE my_dynamic_table SET LOG_LEVEL = DEBUG; + +ALTER DYNAMIC TABLE my_dynamic_table SET CONTACT (STEWARD = steward_group); + +ALTER DYNAMIC TABLE my_dynamic_table SET CONTACT +( + STEWARD = steward_group, + SUPPORT = support_group, + ACCESS_APPROVAL = access_group +); + +ALTER DYNAMIC TABLE my_dynamic_table SET WAREHOUSE = my_warehouse, +TARGET_LAG = '1 hour'; + +ALTER DYNAMIC TABLE my_dynamic_table +SET IMMUTABLE WHERE (ts < current_timestamp() - INTERVAL '1 day'); + + +ALTER DYNAMIC TABLE my_dynamic_table UNSET DATA_RETENTION_TIME_IN_DAYS; +ALTER DYNAMIC TABLE my_dynamic_table UNSET MAX_DATA_EXTENSION_TIME_IN_DAYS; +ALTER DYNAMIC TABLE my_dynamic_table UNSET DEFAULT_DDL_COLLATION; +ALTER DYNAMIC TABLE my_dynamic_table UNSET LOG_LEVEL; +ALTER DYNAMIC TABLE my_dynamic_table UNSET CONTACT STEWARD; +ALTER DYNAMIC TABLE my_dynamic_table UNSET CONTACT SUPPORT; +ALTER DYNAMIC TABLE my_dynamic_table UNSET CONTACT ACCESS_APPROVAL; +ALTER DYNAMIC TABLE my_dynamic_table UNSET IMMUTABLE; +ALTER DYNAMIC TABLE my_dynamic_table UNSET IMMUTABLE, LOG_LEVEL; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_dynamic_table.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_dynamic_table.yml new file mode 100644 index 000000000..693a28c22 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_dynamic_table.yml @@ -0,0 +1,1011 @@ +file: +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - keyword: REFRESH +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SUSPEND +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - keyword: IF + - keyword: EXISTS + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SUSPEND +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: RESUME +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: RENAME + - keyword: TO + - table_reference: + - naked_identifier: my_updated_dynamic_table +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SWAP + - keyword: WITH + - table_reference: + - naked_identifier: my_new_dynamic_table +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: REFRESH +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: REFRESH + - keyword: COPY + - keyword: SESSION +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - alter_table_clustering_action: + - keyword: CLUSTER + - keyword: BY + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: date + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - alter_table_clustering_action: + - keyword: CLUSTER + - keyword: BY + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c1 + - comma: ',' + - expression: + - column_reference: + - naked_identifier: c2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - alter_table_clustering_action: + - keyword: DROP + - keyword: CLUSTERING + - keyword: KEY +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - alter_table_clustering_action: + - keyword: RESUME + - keyword: RECLUSTER +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - alter_table_clustering_action: + - keyword: SUSPEND + - keyword: RECLUSTER +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SET + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''a dynamic table comment''' +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: UNSET + - keyword: COMMENT +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - tag_equals: + - keyword: TAG + - tag_reference: + - naked_identifier: my_tag + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''tag_value''' +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - tag_equals: + - keyword: TAG + - tag_reference: + - naked_identifier: my_tag + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''tag_value''' + - comma: ',' + - tag_reference: + - naked_identifier: my_other_tag + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''other_value''' +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - data_governance_policy_tag_action_segment: + - keyword: UNSET + - keyword: TAG + - tag_reference: + - naked_identifier: my_tag +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - data_governance_policy_tag_action_segment: + - keyword: ADD + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: rap + - keyword: ON + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: pii1 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - data_governance_policy_tag_action_segment: + - keyword: ADD + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: rap + - keyword: ON + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: pii1 + - comma: ',' + - object_reference: + - naked_identifier: pii2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - data_governance_policy_tag_action_segment: + - keyword: DROP + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: rap +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - data_governance_policy_tag_action_segment: + - keyword: DROP + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: rap + - comma: ',' + - keyword: ADD + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: rap + - keyword: ON + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: pii1 + - comma: ',' + - object_reference: + - naked_identifier: pii2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - data_governance_policy_tag_action_segment: + - keyword: DROP + - keyword: ALL + - keyword: ROW + - keyword: ACCESS + - keyword: POLICIES +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - keyword: AGGREGATION + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - keyword: AGGREGATION + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - keyword: ENTITY + - keyword: KEY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: col1 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - keyword: AGGREGATION + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - keyword: ENTITY + - keyword: KEY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: col1 + - comma: ',' + - object_reference: + - naked_identifier: col2 + - comma: ',' + - object_reference: + - naked_identifier: col3 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - keyword: AGGREGATION + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - keyword: FORCE +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - keyword: AGGREGATION + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - keyword: ENTITY + - keyword: KEY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: FORCE +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: UNSET + - keyword: AGGREGATION + - keyword: POLICY +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - search_optimization_action: + - keyword: ADD + - keyword: SEARCH + - keyword: OPTIMIZATION +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - search_optimization_action: + - keyword: ADD + - keyword: SEARCH + - keyword: OPTIMIZATION + - keyword: ON + - keyword: EQUALITY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c1 + - end_bracket: ) + - comma: ',' + - keyword: EQUALITY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c2 + - comma: ',' + - column_reference: + - naked_identifier: c3 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - search_optimization_action: + - keyword: ADD + - keyword: SEARCH + - keyword: OPTIMIZATION + - keyword: ON + - keyword: EQUALITY + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - search_optimization_action: + - keyword: ADD + - keyword: SEARCH + - keyword: OPTIMIZATION + - keyword: ON + - keyword: EQUALITY + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - comma: ',' + - keyword: SUBSTRING + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - comma: ',' + - keyword: GEO + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - search_optimization_action: + - keyword: ADD + - keyword: SEARCH + - keyword: OPTIMIZATION + - keyword: ON + - keyword: EQUALITY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c1 + - comma: ',' + - column_reference: + - naked_identifier: c2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - search_optimization_action: + - keyword: DROP + - keyword: SEARCH + - keyword: OPTIMIZATION + - keyword: ON + - keyword: EQUALITY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c1 + - end_bracket: ) + - comma: ',' + - keyword: EQUALITY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c2 + - comma: ',' + - column_reference: + - naked_identifier: c3 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - search_optimization_action: + - keyword: DROP + - keyword: SEARCH + - keyword: OPTIMIZATION + - keyword: ON + - keyword: EQUALITY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c1 + - comma: ',' + - column_reference: + - naked_identifier: c2 + - end_bracket: ) + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - column_reference: + - naked_identifier: c3 +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - search_optimization_action: + - keyword: SUSPEND + - keyword: SEARCH + - keyword: OPTIMIZATION + - keyword: ON + - keyword: EQUALITY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c1 + - end_bracket: ) + - comma: ',' + - keyword: EQUALITY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c2 + - comma: ',' + - column_reference: + - naked_identifier: c3 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - search_optimization_action: + - keyword: SUSPEND + - keyword: SEARCH + - keyword: OPTIMIZATION + - keyword: ON + - keyword: EQUALITY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c1 + - comma: ',' + - column_reference: + - naked_identifier: c2 + - end_bracket: ) + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - column_reference: + - naked_identifier: c3 +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - search_optimization_action: + - keyword: RESUME + - keyword: SEARCH + - keyword: OPTIMIZATION + - keyword: ON + - keyword: EQUALITY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c1 + - end_bracket: ) + - comma: ',' + - keyword: EQUALITY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c2 + - comma: ',' + - column_reference: + - naked_identifier: c3 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - search_optimization_action: + - keyword: RESUME + - keyword: SEARCH + - keyword: OPTIMIZATION + - keyword: ON + - keyword: EQUALITY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: c1 + - comma: ',' + - column_reference: + - naked_identifier: c2 + - end_bracket: ) + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - column_reference: + - naked_identifier: c3 +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SET + - keyword: TARGET_LAG + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''1 hour''' +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SET + - keyword: TARGET_LAG + - comparison_operator: + - raw_comparison_operator: = + - keyword: DOWNSTREAM +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SET + - keyword: WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_warehouse +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SET + - keyword: DATA_RETENTION_TIME_IN_DAYS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '7' +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SET + - keyword: MAX_DATA_EXTENSION_TIME_IN_DAYS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '7' +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SET + - keyword: DEFAULT_DDL_COLLATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''en_US-trim''' +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SET + - log_level_equals: + - keyword: LOG_LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: DEBUG +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SET + - keyword: CONTACT + - bracketed: + - start_bracket: ( + - keyword: STEWARD + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: steward_group + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SET + - keyword: CONTACT + - bracketed: + - start_bracket: ( + - keyword: STEWARD + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: steward_group + - comma: ',' + - keyword: SUPPORT + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: support_group + - comma: ',' + - keyword: ACCESS_APPROVAL + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: access_group + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SET + - keyword: WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_warehouse + - comma: ',' + - keyword: TARGET_LAG + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''1 hour''' +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: SET + - keyword: IMMUTABLE + - keyword: WHERE + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: ts + - comparison_operator: + - raw_comparison_operator: < + - function: + - function_name: + - function_name_identifier: current_timestamp + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - binary_operator: '-' + - keyword: INTERVAL + - date_constructor_literal: '''1 day''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: UNSET + - keyword: DATA_RETENTION_TIME_IN_DAYS +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: UNSET + - keyword: MAX_DATA_EXTENSION_TIME_IN_DAYS +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: UNSET + - keyword: DEFAULT_DDL_COLLATION +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: UNSET + - keyword: LOG_LEVEL +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: UNSET + - keyword: CONTACT + - keyword: STEWARD +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: UNSET + - keyword: CONTACT + - keyword: SUPPORT +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: UNSET + - keyword: CONTACT + - keyword: ACCESS_APPROVAL +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: UNSET + - keyword: IMMUTABLE +- statement_terminator: ; +- statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_dynamic_table + - keyword: UNSET + - keyword: IMMUTABLE + - comma: ',' + - keyword: LOG_LEVEL +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_external_volume.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_external_volume.sql new file mode 100644 index 000000000..55bdeaaa3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_external_volume.sql @@ -0,0 +1,31 @@ +ALTER EXTERNAL VOLUME exvol1 + ADD STORAGE_LOCATION = + ( + NAME = 'my-s3-us-central-2' + STORAGE_PROVIDER = 'S3' + STORAGE_BASE_URL = 's3://my_bucket_us_central-1/' + STORAGE_AWS_ROLE_ARN = 'arn:aws:iam::123456789012:role/myrole' + ); + +ALTER EXTERNAL VOLUME exvol2 + ADD STORAGE_LOCATION = + ( + NAME = 'my-gcs-europe-west4' + STORAGE_PROVIDER = 'GCS' + STORAGE_BASE_URL = 'gcs://my_bucket_europe-west4/' + ); + +ALTER EXTERNAL VOLUME exvol3 + ADD STORAGE_LOCATION = + ( + NAME = 'my-azure-japaneast' + STORAGE_PROVIDER = 'AZURE' + STORAGE_BASE_URL = 'azure://sfcdev1.blob.core.windows.net/my_container_japaneast/' + AZURE_TENANT_ID = 'a9876545-4321-987b-b23c-2kz436789d0' + ); + +ALTER EXTERNAL VOLUME exvol4 REMOVE STORAGE_LOCATION 'foo'; + +ALTER EXTERNAL VOLUME exvol5 SET ALLOW_WRITES = TRUE; + +ALTER EXTERNAL VOLUME IF EXISTS exvol6 SET COMMENT = 'bar'; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_external_volume.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_external_volume.yml new file mode 100644 index 000000000..8be122c03 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_external_volume.yml @@ -0,0 +1,130 @@ +file: +- statement: + - alter_external_volume_statement: + - keyword: ALTER + - keyword: EXTERNAL + - keyword: VOLUME + - external_volume_reference: + - naked_identifier: exvol1 + - keyword: ADD + - keyword: STORAGE_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my-s3-us-central-2''' + - keyword: STORAGE_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''S3''' + - keyword: STORAGE_BASE_URL + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''s3://my_bucket_us_central-1/''' + - keyword: STORAGE_AWS_ROLE_ARN + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''arn:aws:iam::123456789012:role/myrole''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_external_volume_statement: + - keyword: ALTER + - keyword: EXTERNAL + - keyword: VOLUME + - external_volume_reference: + - naked_identifier: exvol2 + - keyword: ADD + - keyword: STORAGE_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my-gcs-europe-west4''' + - keyword: STORAGE_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''GCS''' + - keyword: STORAGE_BASE_URL + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''gcs://my_bucket_europe-west4/''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_external_volume_statement: + - keyword: ALTER + - keyword: EXTERNAL + - keyword: VOLUME + - external_volume_reference: + - naked_identifier: exvol3 + - keyword: ADD + - keyword: STORAGE_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my-azure-japaneast''' + - keyword: STORAGE_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''AZURE''' + - keyword: STORAGE_BASE_URL + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''azure://sfcdev1.blob.core.windows.net/my_container_japaneast/''' + - keyword: AZURE_TENANT_ID + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''a9876545-4321-987b-b23c-2kz436789d0''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_external_volume_statement: + - keyword: ALTER + - keyword: EXTERNAL + - keyword: VOLUME + - external_volume_reference: + - naked_identifier: exvol4 + - keyword: REMOVE + - keyword: STORAGE_LOCATION + - quoted_literal: '''foo''' +- statement_terminator: ; +- statement: + - alter_external_volume_statement: + - keyword: ALTER + - keyword: EXTERNAL + - keyword: VOLUME + - external_volume_reference: + - naked_identifier: exvol5 + - keyword: SET + - keyword: ALLOW_WRITES + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - alter_external_volume_statement: + - keyword: ALTER + - keyword: EXTERNAL + - keyword: VOLUME + - keyword: IF + - keyword: EXISTS + - external_volume_reference: + - naked_identifier: exvol6 + - keyword: SET + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''bar''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_file_format.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_file_format.sql index 03727ac17..63fd6d737 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_file_format.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_file_format.sql @@ -65,6 +65,9 @@ ALTER FILE FORMAT IF EXISTS my_parquet_format SET SNAPPY_COMPRESSION = FALSE TRIM_SPACE = FALSE BINARY_AS_TEXT = TRUE + USE_LOGICAL_TYPE = FALSE + USE_VECTORIZED_SCANNER = FALSE + REPLACE_INVALID_CHARACTERS = FALSE NULL_IF = ('foo', 'bar') COMMENT = 'FOOBAR' ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_file_format.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_file_format.yml index f52f0c759..b082ef475 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_file_format.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_file_format.yml @@ -328,6 +328,18 @@ file: - comparison_operator: - raw_comparison_operator: = - boolean_literal: 'TRUE' + - keyword: USE_LOGICAL_TYPE + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' + - keyword: USE_VECTORIZED_SCANNER + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' + - keyword: REPLACE_INVALID_CHARACTERS + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' - keyword: NULL_IF - comparison_operator: - raw_comparison_operator: = diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_function.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_function.sql index 1e53abc67..147875d0c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_function.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_function.sql @@ -1,3 +1,33 @@ ALTER FUNCTION IF EXISTS function1(number) RENAME TO function2; ALTER FUNCTION IF EXISTS function2(number) SET SECURE; ALTER FUNCTION function3() UNSET COMMENT; + +ALTER function function1(FLOAT_PARAM1 FLOAT) +SET TAG TAG1 = 'value1', TAG2 = 'value2', TAG3 = 'value3'; + +ALTER function function1() +UNSET TAG TAG1, TAG2, TAG3; + +ALTER function function1() +SET COMMENT = 'just a comment'; + +ALTER function function1() +UNSET COMMENT; + +ALTER FUNCTION example_function() +SET + EXTERNAL_ACCESS_INTEGRATIONS = (my_external_access_integration), + LOG_LEVEL = DEBUG, + TRACE_LEVEL = ON_EVENT, + SECRETS = ('cred' = oauth_token), + COMMENT = 'just a comment' +; + +ALTER FUNCTION example_function() +SET TAG TAG1 = 'value1', TAG2 = 'value2', TAG3 = 'value3', + EXTERNAL_ACCESS_INTEGRATIONS = (my_external_access_integration), + LOG_LEVEL = DEBUG, + TRACE_LEVEL = ON_EVENT, + SECRETS = ('cred' = oauth_token), + COMMENT = 'just a comment' +; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_function.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_function.yml index b02798b10..1b7dea1e2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_function.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_function.yml @@ -48,3 +48,208 @@ file: - keyword: UNSET - keyword: COMMENT - statement_terminator: ; +- statement: + - alter_function_statement: + - keyword: ALTER + - keyword: function + - function_name: + - function_name_identifier: function1 + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: FLOAT_PARAM1 + - data_type: + - data_type_identifier: FLOAT + - end_bracket: ) + - keyword: SET + - tag_equals: + - keyword: TAG + - tag_reference: + - naked_identifier: TAG1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value1''' + - comma: ',' + - tag_reference: + - naked_identifier: TAG2 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value2''' + - comma: ',' + - tag_reference: + - naked_identifier: TAG3 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value3''' +- statement_terminator: ; +- statement: + - alter_function_statement: + - keyword: ALTER + - keyword: function + - function_name: + - function_name_identifier: function1 + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: UNSET + - keyword: TAG + - tag_reference: + - naked_identifier: TAG1 + - comma: ',' + - tag_reference: + - naked_identifier: TAG2 + - comma: ',' + - tag_reference: + - naked_identifier: TAG3 +- statement_terminator: ; +- statement: + - alter_function_statement: + - keyword: ALTER + - keyword: function + - function_name: + - function_name_identifier: function1 + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: SET + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''just a comment''' +- statement_terminator: ; +- statement: + - alter_function_statement: + - keyword: ALTER + - keyword: function + - function_name: + - function_name_identifier: function1 + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: UNSET + - keyword: COMMENT +- statement_terminator: ; +- statement: + - alter_function_statement: + - keyword: ALTER + - keyword: FUNCTION + - function_name: + - function_name_identifier: example_function + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: SET + - external_access_integration_equals: + - keyword: EXTERNAL_ACCESS_INTEGRATIONS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - naked_identifier: my_external_access_integration + - end_bracket: ) + - comma: ',' + - log_level_equals: + - keyword: LOG_LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: DEBUG + - comma: ',' + - trace_level_equals: + - keyword: TRACE_LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON_EVENT + - comma: ',' + - external_access_integration_equals: + - keyword: SECRETS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''cred''' + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: oauth_token + - end_bracket: ) + - comma: ',' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''just a comment''' +- statement_terminator: ; +- statement: + - alter_function_statement: + - keyword: ALTER + - keyword: FUNCTION + - function_name: + - function_name_identifier: example_function + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: SET + - tag_equals: + - keyword: TAG + - tag_reference: + - naked_identifier: TAG1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value1''' + - comma: ',' + - tag_reference: + - naked_identifier: TAG2 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value2''' + - comma: ',' + - tag_reference: + - naked_identifier: TAG3 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value3''' + - comma: ',' + - external_access_integration_equals: + - keyword: EXTERNAL_ACCESS_INTEGRATIONS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - naked_identifier: my_external_access_integration + - end_bracket: ) + - comma: ',' + - log_level_equals: + - keyword: LOG_LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: DEBUG + - comma: ',' + - trace_level_equals: + - keyword: TRACE_LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON_EVENT + - comma: ',' + - external_access_integration_equals: + - keyword: SECRETS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''cred''' + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: oauth_token + - end_bracket: ) + - comma: ',' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''just a comment''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_masking_policy.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_masking_policy.yml index 646affb8a..57a520bac 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_masking_policy.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_masking_policy.yml @@ -1,127 +1,133 @@ file: - statement: - - keyword: ALTER - - keyword: MASKING - - keyword: POLICY - - keyword: IF - - keyword: EXISTS - - object_reference: - - quoted_identifier: '"a quoted policy name"' - - keyword: RENAME - - keyword: TO - - object_reference: - - naked_identifier: a_sane_name + - alter_masking_policy: + - keyword: ALTER + - keyword: MASKING + - keyword: POLICY + - keyword: IF + - keyword: EXISTS + - object_reference: + - quoted_identifier: '"a quoted policy name"' + - keyword: RENAME + - keyword: TO + - object_reference: + - naked_identifier: a_sane_name - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: MASKING - - keyword: POLICY - - object_reference: - - naked_identifier: email_mask - - keyword: SET - - keyword: BODY - - function_assigner: -> - - expression: - - case_expression: - - keyword: CASE - - when_clause: - - keyword: WHEN - - expression: - - function: - - function_name: - - function_name_identifier: current_role - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) - - keyword: IN - - bracketed: - - start_bracket: ( - - quoted_literal: '''ANALYST''' - - end_bracket: ) - - keyword: THEN - - expression: - - column_reference: - - naked_identifier: VAL - - else_clause: - - keyword: ELSE - - expression: - - function: - - function_name: - - function_name_identifier: sha2 - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: VAL - - comma: ',' - - expression: - - numeric_literal: '512' - - end_bracket: ) - - keyword: END + - alter_masking_policy: + - keyword: ALTER + - keyword: MASKING + - keyword: POLICY + - object_reference: + - naked_identifier: email_mask + - keyword: SET + - keyword: BODY + - function_assigner: -> + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - function: + - function_name: + - function_name_identifier: current_role + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: IN + - bracketed: + - start_bracket: ( + - quoted_literal: '''ANALYST''' + - end_bracket: ) + - keyword: THEN + - expression: + - column_reference: + - naked_identifier: VAL + - else_clause: + - keyword: ELSE + - expression: + - function: + - function_name: + - function_name_identifier: sha2 + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: VAL + - comma: ',' + - expression: + - numeric_literal: '512' + - end_bracket: ) + - keyword: END - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: MASKING - - keyword: POLICY - - object_reference: - - naked_identifier: aggressively_mask_pii - - keyword: SET - - tag_equals: + - alter_masking_policy: + - keyword: ALTER + - keyword: MASKING + - keyword: POLICY + - object_reference: + - naked_identifier: aggressively_mask_pii + - keyword: SET + - tag_equals: + - keyword: TAG + - tag_reference: + - naked_identifier: environment + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''silver''' + - comma: ',' + - tag_reference: + - naked_identifier: silo + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''sales''' +- statement_terminator: ; +- statement: + - alter_masking_policy: + - keyword: ALTER + - keyword: MASKING + - keyword: POLICY + - keyword: IF + - keyword: EXISTS + - object_reference: + - naked_identifier: mask_pii_policy + - keyword: UNSET - keyword: TAG - tag_reference: - naked_identifier: environment - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''silver''' - comma: ',' - tag_reference: - - naked_identifier: silo - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''sales''' -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: MASKING - - keyword: POLICY - - keyword: IF - - keyword: EXISTS - - object_reference: - - naked_identifier: mask_pii_policy - - keyword: UNSET - - keyword: TAG - - tag_reference: - - naked_identifier: environment - - comma: ',' - - tag_reference: - - naked_identifier: billing + - naked_identifier: billing - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: MASKING - - keyword: POLICY - - object_reference: - - naked_identifier: db - - dot: . - - naked_identifier: sch - - dot: . - - naked_identifier: fully_redacted_policy - - keyword: SET - - keyword: COMMENT - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''A super strict policy''' + - alter_masking_policy: + - keyword: ALTER + - keyword: MASKING + - keyword: POLICY + - object_reference: + - naked_identifier: db + - dot: . + - naked_identifier: sch + - dot: . + - naked_identifier: fully_redacted_policy + - keyword: SET + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''A super strict policy''' - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: MASKING - - keyword: POLICY - - keyword: IF - - keyword: EXISTS - - object_reference: - - naked_identifier: mask_pii_policy - - keyword: UNSET - - keyword: COMMENT + - alter_masking_policy: + - keyword: ALTER + - keyword: MASKING + - keyword: POLICY + - keyword: IF + - keyword: EXISTS + - object_reference: + - naked_identifier: mask_pii_policy + - keyword: UNSET + - keyword: COMMENT - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_network_policy.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_network_policy.yml index c861f37b8..3fc2c905b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_network_policy.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_network_policy.yml @@ -1,93 +1,100 @@ file: - statement: - - keyword: ALTER - - keyword: NETWORK - - keyword: POLICY - - naked_identifier: mypolicy1 - - keyword: SET - - keyword: ALLOWED_IP_LIST - - comparison_operator: - - raw_comparison_operator: = - - bracketed: - - start_bracket: ( - - quoted_literal: '''192.168.1.0/24''' - - comma: ',' - - quoted_literal: '''192.168.255.100''' - - end_bracket: ) - - keyword: BLOCKED_IP_LIST - - comparison_operator: - - raw_comparison_operator: = - - bracketed: - - start_bracket: ( - - quoted_literal: '''192.168.1.99''' - - end_bracket: ) + - alter_network_policy_statement: + - keyword: ALTER + - keyword: NETWORK + - keyword: POLICY + - naked_identifier: mypolicy1 + - keyword: SET + - keyword: ALLOWED_IP_LIST + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''192.168.1.0/24''' + - comma: ',' + - quoted_literal: '''192.168.255.100''' + - end_bracket: ) + - keyword: BLOCKED_IP_LIST + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''192.168.1.99''' + - end_bracket: ) - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: NETWORK - - keyword: POLICY - - naked_identifier: foo - - keyword: RENAME - - keyword: TO - - naked_identifier: bar + - alter_network_policy_statement: + - keyword: ALTER + - keyword: NETWORK + - keyword: POLICY + - naked_identifier: foo + - keyword: RENAME + - keyword: TO + - naked_identifier: bar - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: NETWORK - - keyword: POLICY - - naked_identifier: foo - - keyword: SET - - tag_equals: + - alter_network_policy_statement: + - keyword: ALTER + - keyword: NETWORK + - keyword: POLICY + - naked_identifier: foo + - keyword: SET + - tag_equals: + - keyword: TAG + - tag_reference: + - naked_identifier: admin + - dot: . + - naked_identifier: my_tag + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''foo''' +- statement_terminator: ; +- statement: + - alter_network_policy_statement: + - keyword: ALTER + - keyword: NETWORK + - keyword: POLICY + - naked_identifier: foo + - keyword: UNSET - keyword: TAG - tag_reference: - naked_identifier: admin - dot: . - naked_identifier: my_tag - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''foo''' -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: NETWORK - - keyword: POLICY - - naked_identifier: foo - - keyword: UNSET - - keyword: TAG - - tag_reference: - - naked_identifier: admin - - dot: . - - naked_identifier: my_tag - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: NETWORK - - keyword: POLICY - - keyword: IF - - keyword: EXISTS - - naked_identifier: foo - - keyword: UNSET - - keyword: COMMENT + - alter_network_policy_statement: + - keyword: ALTER + - keyword: NETWORK + - keyword: POLICY + - keyword: IF + - keyword: EXISTS + - naked_identifier: foo + - keyword: UNSET + - keyword: COMMENT - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: NETWORK - - keyword: POLICY - - naked_identifier: foo - - keyword: REMOVE - - keyword: ALLOWED_NETWORK_RULE_LIST - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''foo''' + - alter_network_policy_statement: + - keyword: ALTER + - keyword: NETWORK + - keyword: POLICY + - naked_identifier: foo + - keyword: REMOVE + - keyword: ALLOWED_NETWORK_RULE_LIST + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''foo''' - statement_terminator: ; - statement: - - keyword: ALTER - - keyword: NETWORK - - keyword: POLICY - - naked_identifier: foo - - keyword: ADD - - keyword: BLOCKED_NETWORK_RULE_LIST - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''bar''' + - alter_network_policy_statement: + - keyword: ALTER + - keyword: NETWORK + - keyword: POLICY + - naked_identifier: foo + - keyword: ADD + - keyword: BLOCKED_NETWORK_RULE_LIST + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''bar''' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_password_policy.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_password_policy.sql new file mode 100644 index 000000000..10e286266 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_password_policy.sql @@ -0,0 +1,9 @@ +ALTER PASSWORD POLICY password_policy_prod_1 SET PASSWORD_MAX_RETRIES = 3; + +ALTER PASSWORD POLICY IF EXISTS password_policy_prod_1 RENAME TO password_policy_prod_2; + +ALTER PASSWORD POLICY IF EXISTS password_policy_prod_1 UNSET TAG foo; + +ALTER PASSWORD POLICY IF EXISTS password_policy_prod_1 UNSET PASSWORD_MIN_UPPER_CASE_CHARS PASSWORD_MAX_AGE_DAYS; + +ALTER PASSWORD POLICY IF EXISTS password_policy_prod_1 SET TAG foo = 'bar'; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_password_policy.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_password_policy.yml new file mode 100644 index 000000000..c4a12f645 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_password_policy.yml @@ -0,0 +1,74 @@ +file: +- statement: + - alter_password_policy_statement: + - keyword: ALTER + - keyword: PASSWORD + - keyword: POLICY + - password_policy_reference: + - naked_identifier: password_policy_prod_1 + - keyword: SET + - password_policy_options: + - keyword: PASSWORD_MAX_RETRIES + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '3' +- statement_terminator: ; +- statement: + - alter_password_policy_statement: + - keyword: ALTER + - keyword: PASSWORD + - keyword: POLICY + - keyword: IF + - keyword: EXISTS + - password_policy_reference: + - naked_identifier: password_policy_prod_1 + - keyword: RENAME + - keyword: TO + - password_policy_reference: + - naked_identifier: password_policy_prod_2 +- statement_terminator: ; +- statement: + - alter_password_policy_statement: + - keyword: ALTER + - keyword: PASSWORD + - keyword: POLICY + - keyword: IF + - keyword: EXISTS + - password_policy_reference: + - naked_identifier: password_policy_prod_1 + - keyword: UNSET + - keyword: TAG + - tag_reference: + - naked_identifier: foo +- statement_terminator: ; +- statement: + - alter_password_policy_statement: + - keyword: ALTER + - keyword: PASSWORD + - keyword: POLICY + - keyword: IF + - keyword: EXISTS + - password_policy_reference: + - naked_identifier: password_policy_prod_1 + - keyword: UNSET + - keyword: PASSWORD_MIN_UPPER_CASE_CHARS + - keyword: PASSWORD_MAX_AGE_DAYS +- statement_terminator: ; +- statement: + - alter_password_policy_statement: + - keyword: ALTER + - keyword: PASSWORD + - keyword: POLICY + - keyword: IF + - keyword: EXISTS + - password_policy_reference: + - naked_identifier: password_policy_prod_1 + - keyword: SET + - tag_equals: + - keyword: TAG + - tag_reference: + - naked_identifier: foo + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''bar''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_pipe.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_pipe.sql index 8d4e9524c..6ec7ae156 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_pipe.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_pipe.sql @@ -7,3 +7,4 @@ alter pipe mypipe set tag tag1 = 'value1', tag2 = 'value2'; alter pipe mypipe unset pipe_execution_paused; alter pipe mypipe unset comment; alter pipe mypipe unset tag foo, bar; +ALTER PIPE mypipe SET ERROR_INTEGRATION = my_notification_int; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_pipe.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_pipe.yml index 3d58c72be..8299426a0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_pipe.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_pipe.yml @@ -120,3 +120,16 @@ file: - tag_reference: - naked_identifier: bar - statement_terminator: ; +- statement: + - alter_pipe_segment: + - keyword: ALTER + - keyword: PIPE + - object_reference: + - naked_identifier: mypipe + - keyword: SET + - keyword: ERROR_INTEGRATION + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_notification_int +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_procedure.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_procedure.sql index 4f1860668..7f0f7a0d1 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_procedure.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_procedure.sql @@ -15,3 +15,28 @@ UNSET COMMENT; ALTER PROCEDURE procedure1() UNSET TAG TAG1, TAG2, TAG3; + +ALTER PROCEDURE procedure1(varchar) +SET LOG_LEVEL = WARN +; + +ALTER PROCEDURE procedure1(varchar) +SET TRACE_LEVEL = ALWAYS +; + +ALTER PROCEDURE mirror.procedure1(varchar) +SET LOG_LEVEL = WARN, TRACE_LEVEL = ON_EVENT +; + +ALTER PROCEDURE example_procedure() +SET + EXTERNAL_ACCESS_INTEGRATIONS = (my_external_access_integration), + LOG_LEVEL = DEBUG, + TRACE_LEVEL = ON_EVENT, + SECRETS = ('cred' = oauth_token) + +; + +ALTER PROCEDURE example_procedure() +SET EXTERNAL_ACCESS_INTEGRATIONS = (my_external_access_integration) +; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_procedure.yml index 61d854e00..74ee5076a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_procedure.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_procedure.yml @@ -142,3 +142,132 @@ file: - tag_reference: - naked_identifier: TAG3 - statement_terminator: ; +- statement: + - alter_procedure_statement: + - keyword: ALTER + - keyword: PROCEDURE + - function_name: + - function_name_identifier: procedure1 + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: varchar + - end_bracket: ) + - keyword: SET + - log_level_equals: + - keyword: LOG_LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: WARN +- statement_terminator: ; +- statement: + - alter_procedure_statement: + - keyword: ALTER + - keyword: PROCEDURE + - function_name: + - function_name_identifier: procedure1 + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: varchar + - end_bracket: ) + - keyword: SET + - trace_level_equals: + - keyword: TRACE_LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: ALWAYS +- statement_terminator: ; +- statement: + - alter_procedure_statement: + - keyword: ALTER + - keyword: PROCEDURE + - function_name: + - naked_identifier: mirror + - dot: . + - function_name_identifier: procedure1 + - function_parameter_list: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: varchar + - end_bracket: ) + - keyword: SET + - log_level_equals: + - keyword: LOG_LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: WARN + - comma: ',' + - trace_level_equals: + - keyword: TRACE_LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON_EVENT +- statement_terminator: ; +- statement: + - alter_procedure_statement: + - keyword: ALTER + - keyword: PROCEDURE + - function_name: + - function_name_identifier: example_procedure + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: SET + - external_access_integration_equals: + - keyword: EXTERNAL_ACCESS_INTEGRATIONS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - naked_identifier: my_external_access_integration + - end_bracket: ) + - comma: ',' + - log_level_equals: + - keyword: LOG_LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: DEBUG + - comma: ',' + - trace_level_equals: + - keyword: TRACE_LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON_EVENT + - comma: ',' + - external_access_integration_equals: + - keyword: SECRETS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''cred''' + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: oauth_token + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_procedure_statement: + - keyword: ALTER + - keyword: PROCEDURE + - function_name: + - function_name_identifier: example_procedure + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: SET + - external_access_integration_equals: + - keyword: EXTERNAL_ACCESS_INTEGRATIONS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - naked_identifier: my_external_access_integration + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_resource_monitor.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_resource_monitor.sql index 7d6470da6..d3c4af19a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_resource_monitor.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_resource_monitor.sql @@ -1,55 +1,18 @@ --- Test cases for ALTER RESOURCE MONITOR statement --- From SQLFluff PR #5272 - --- Simple alter with credit quota -ALTER RESOURCE MONITOR my_monitor SET CREDIT_QUOTA=200; - --- Alter with frequency -ALTER RESOURCE MONITOR budget_monitor SET FREQUENCY=WEEKLY; - --- Alter with multiple options -ALTER RESOURCE MONITOR my_monitor SET - CREDIT_QUOTA=300 - FREQUENCY=MONTHLY; - --- Alter with start timestamp -ALTER RESOURCE MONITOR timed_monitor SET START_TIMESTAMP='2024-06-01 00:00:00'; -ALTER RESOURCE MONITOR immediate_monitor SET START_TIMESTAMP=IMMEDIATELY; - --- Alter with end timestamp -ALTER RESOURCE MONITOR limited_monitor SET END_TIMESTAMP='2025-12-31 23:59:59'; - --- Alter with notify users -ALTER RESOURCE MONITOR notify_monitor SET NOTIFY_USERS=(user1, user2, admin); - --- Alter with triggers -ALTER RESOURCE MONITOR trigger_monitor SET - TRIGGERS ON 85 PERCENT DO NOTIFY - ON 95 PERCENT DO SUSPEND; - --- Alter with all options -ALTER RESOURCE MONITOR full_monitor SET - CREDIT_QUOTA=3000 - FREQUENCY=YEARLY - START_TIMESTAMP='2024-02-01 00:00:00' - END_TIMESTAMP='2025-01-31 23:59:59' - NOTIFY_USERS=(superadmin, billing_team) - TRIGGERS ON 70 PERCENT DO NOTIFY - ON 85 PERCENT DO SUSPEND - ON 98 PERCENT DO SUSPEND_IMMEDIATE; - --- Alter with IF EXISTS -ALTER RESOURCE MONITOR IF EXISTS my_monitor SET CREDIT_QUOTA=150; - --- Alter with schema qualified name -ALTER RESOURCE MONITOR my_schema.my_monitor SET CREDIT_QUOTA=250; - --- Alter with database and schema qualified name -ALTER RESOURCE MONITOR my_db.my_schema.my_monitor SET CREDIT_QUOTA=350; - --- Alter with different frequency options -ALTER RESOURCE MONITOR monitor1 SET FREQUENCY=DAILY; -ALTER RESOURCE MONITOR monitor2 SET FREQUENCY=WEEKLY; -ALTER RESOURCE MONITOR monitor3 SET FREQUENCY=MONTHLY; -ALTER RESOURCE MONITOR monitor4 SET FREQUENCY=YEARLY; -ALTER RESOURCE MONITOR monitor5 SET FREQUENCY=NEVER; \ No newline at end of file +alter resource monitor limiter +set + credit_quota=2000 + notify_users = (jdoe, "jane smith", "john doe") + FREQUENCY=DAILY + start_timestamp = immediately + end_timestamp = '2038-01-19 03:14:07' + triggers + on 80 percent do notify + on 100 percent do suspend_immediate +; + + +ALTER RESOURCE MONITOR limiter + SET CREDIT_QUOTA=2000 + TRIGGERS ON 80 PERCENT DO NOTIFY + ON 100 PERCENT DO SUSPEND_IMMEDIATE +; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_resource_monitor.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_resource_monitor.yml index cc1781fae..91910c4f7 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_resource_monitor.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_resource_monitor.yml @@ -1,268 +1,77 @@ file: - statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: my_monitor - - keyword: SET - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '200' -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: budget_monitor - - keyword: SET - - keyword: FREQUENCY - - comparison_operator: - - raw_comparison_operator: = - - keyword: WEEKLY -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: my_monitor - - keyword: SET - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '300' - - keyword: FREQUENCY - - comparison_operator: - - raw_comparison_operator: = - - keyword: MONTHLY -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: timed_monitor - - keyword: SET - - keyword: START_TIMESTAMP - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''2024-06-01 00:00:00''' -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: immediate_monitor - - keyword: SET - - keyword: START_TIMESTAMP - - comparison_operator: - - raw_comparison_operator: = - - keyword: IMMEDIATELY -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: limited_monitor - - keyword: SET - - keyword: END_TIMESTAMP - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''2025-12-31 23:59:59''' -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: notify_monitor - - keyword: SET - - keyword: NOTIFY_USERS - - comparison_operator: - - raw_comparison_operator: = - - bracketed: - - start_bracket: ( - - naked_identifier: user1 - - comma: ',' - - naked_identifier: user2 - - comma: ',' - - naked_identifier: admin - - end_bracket: ) -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: trigger_monitor - - keyword: SET - - keyword: TRIGGERS - - keyword: ON - - numeric_literal: '85' - - keyword: PERCENT - - keyword: DO - - keyword: NOTIFY - - keyword: ON - - numeric_literal: '95' - - keyword: PERCENT - - keyword: DO - - keyword: SUSPEND -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: full_monitor - - keyword: SET - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '3000' - - keyword: FREQUENCY - - comparison_operator: - - raw_comparison_operator: = - - keyword: YEARLY - - keyword: START_TIMESTAMP - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''2024-02-01 00:00:00''' - - keyword: END_TIMESTAMP - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''2025-01-31 23:59:59''' - - keyword: NOTIFY_USERS - - comparison_operator: - - raw_comparison_operator: = - - bracketed: - - start_bracket: ( - - naked_identifier: superadmin - - comma: ',' - - naked_identifier: billing_team - - end_bracket: ) - - keyword: TRIGGERS - - keyword: ON - - numeric_literal: '70' - - keyword: PERCENT - - keyword: DO - - keyword: NOTIFY - - keyword: ON - - numeric_literal: '85' - - keyword: PERCENT - - keyword: DO - - keyword: SUSPEND - - keyword: ON - - numeric_literal: '98' - - keyword: PERCENT - - keyword: DO - - keyword: SUSPEND_IMMEDIATE -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - keyword: IF - - keyword: EXISTS - - object_reference: - - naked_identifier: my_monitor - - keyword: SET - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '150' -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: my_schema - - dot: . - - naked_identifier: my_monitor - - keyword: SET - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '250' -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: my_db - - dot: . - - naked_identifier: my_schema - - dot: . - - naked_identifier: my_monitor - - keyword: SET - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '350' -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: monitor1 - - keyword: SET - - keyword: FREQUENCY - - comparison_operator: - - raw_comparison_operator: = - - keyword: DAILY -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: monitor2 - - keyword: SET - - keyword: FREQUENCY - - comparison_operator: - - raw_comparison_operator: = - - keyword: WEEKLY -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: monitor3 - - keyword: SET - - keyword: FREQUENCY - - comparison_operator: - - raw_comparison_operator: = - - keyword: MONTHLY -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: monitor4 - - keyword: SET - - keyword: FREQUENCY - - comparison_operator: - - raw_comparison_operator: = - - keyword: YEARLY -- statement_terminator: ; -- statement: - - keyword: ALTER - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: monitor5 - - keyword: SET - - keyword: FREQUENCY - - comparison_operator: - - raw_comparison_operator: = - - keyword: NEVER + - alter_resource_monitor_statement: + - keyword: alter + - keyword: resource + - keyword: monitor + - object_reference: + - naked_identifier: limiter + - keyword: set + - resource_monitor_options: + - keyword: credit_quota + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '2000' + - keyword: notify_users + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: jdoe + - comma: ',' + - object_reference: + - quoted_identifier: '"jane smith"' + - comma: ',' + - object_reference: + - quoted_identifier: '"john doe"' + - end_bracket: ) + - keyword: FREQUENCY + - comparison_operator: + - raw_comparison_operator: = + - keyword: DAILY + - keyword: start_timestamp + - comparison_operator: + - raw_comparison_operator: = + - keyword: immediately + - keyword: end_timestamp + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2038-01-19 03:14:07''' + - keyword: triggers + - keyword: on + - integer_literal: '80' + - keyword: percent + - keyword: do + - keyword: notify + - keyword: on + - integer_literal: '100' + - keyword: percent + - keyword: do + - keyword: suspend_immediate +- statement_terminator: ; +- statement: + - alter_resource_monitor_statement: + - keyword: ALTER + - keyword: RESOURCE + - keyword: MONITOR + - object_reference: + - naked_identifier: limiter + - keyword: SET + - resource_monitor_options: + - keyword: CREDIT_QUOTA + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '2000' + - keyword: TRIGGERS + - keyword: ON + - integer_literal: '80' + - keyword: PERCENT + - keyword: DO + - keyword: NOTIFY + - keyword: ON + - integer_literal: '100' + - keyword: PERCENT + - keyword: DO + - keyword: SUSPEND_IMMEDIATE - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_role.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_role.yml index c10e5064f..947463cf2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_role.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_role.yml @@ -32,10 +32,11 @@ file: - role_reference: - quoted_identifier: '"test_role"' - keyword: SET - - keyword: COMMENT - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''test_comment''' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test_comment''' - statement_terminator: ; - statement: - alter_role_statement: @@ -56,10 +57,11 @@ file: - role_reference: - quoted_identifier: '"test_role"' - keyword: SET - - keyword: COMMENT - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''test_comment''' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test_comment''' - statement_terminator: ; - statement: - alter_role_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_row_access_policy.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_row_access_policy.sql new file mode 100644 index 000000000..e5352e600 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_row_access_policy.sql @@ -0,0 +1,15 @@ +ALTER ROW ACCESS POLICY my_access_policy RENAME TO other_access_policy; + +ALTER ROW ACCESS POLICY IF EXISTS my_access_policy RENAME TO other_access_policy; + +ALTER ROW ACCESS POLICY my_access_policy SET BODY -> EXISTS(some_val); + +ALTER ROW ACCESS POLICY my_access_policy SET TAG tag_name = 'tag_value'; + +ALTER ROW ACCESS POLICY my_access_policy SET TAG tag_name = 'tag_value', tag_name = 'tag_value'; + +ALTER ROW ACCESS POLICY my_access_policy UNSET TAG tag_name, tag_name; + +ALTER ROW ACCESS POLICY my_access_policy SET COMMENT = 'comment'; + +ALTER ROW ACCESS POLICY my_access_policy UNSET COMMENT; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_row_access_policy.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_row_access_policy.yml new file mode 100644 index 000000000..6dc8472c0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_row_access_policy.yml @@ -0,0 +1,133 @@ +file: +- statement: + - alter_row_access_policy_statement: + - keyword: ALTER + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_access_policy + - keyword: RENAME + - keyword: TO + - object_reference: + - naked_identifier: other_access_policy +- statement_terminator: ; +- statement: + - alter_row_access_policy_statement: + - keyword: ALTER + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - keyword: IF + - keyword: EXISTS + - object_reference: + - naked_identifier: my_access_policy + - keyword: RENAME + - keyword: TO + - object_reference: + - naked_identifier: other_access_policy +- statement_terminator: ; +- statement: + - alter_row_access_policy_statement: + - keyword: ALTER + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_access_policy + - keyword: SET + - keyword: BODY + - function_assigner: -> + - expression: + - function: + - function_name: + - function_name_identifier: EXISTS + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: some_val + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_row_access_policy_statement: + - keyword: ALTER + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_access_policy + - keyword: SET + - tag_equals: + - keyword: TAG + - tag_reference: + - naked_identifier: tag_name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''tag_value''' +- statement_terminator: ; +- statement: + - alter_row_access_policy_statement: + - keyword: ALTER + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_access_policy + - keyword: SET + - tag_equals: + - keyword: TAG + - tag_reference: + - naked_identifier: tag_name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''tag_value''' + - comma: ',' + - tag_reference: + - naked_identifier: tag_name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''tag_value''' +- statement_terminator: ; +- statement: + - alter_row_access_policy_statement: + - keyword: ALTER + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_access_policy + - keyword: UNSET + - keyword: TAG + - tag_reference: + - naked_identifier: tag_name + - comma: ',' + - tag_reference: + - naked_identifier: tag_name +- statement_terminator: ; +- statement: + - alter_row_access_policy_statement: + - keyword: ALTER + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_access_policy + - keyword: SET + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''comment''' +- statement_terminator: ; +- statement: + - alter_row_access_policy_statement: + - keyword: ALTER + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_access_policy + - keyword: UNSET + - keyword: COMMENT +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_schema.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_schema.yml index 9866b0700..156ebeb32 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_schema.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_schema.yml @@ -5,35 +5,30 @@ file: - keyword: schema - keyword: if - keyword: exists - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: rename - keyword: to - - table_reference: - - object_reference: - - naked_identifier: schema2 + - schema_reference: + - naked_identifier: schema2 - statement_terminator: ; - statement: - alter_schema_statement: - keyword: alter - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: swap - keyword: with - - table_reference: - - object_reference: - - naked_identifier: schema2 + - schema_reference: + - naked_identifier: schema2 - statement_terminator: ; - statement: - alter_schema_statement: - keyword: alter - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: schema2 + - schema_reference: + - naked_identifier: schema2 - keyword: enable - keyword: managed - keyword: access @@ -42,9 +37,8 @@ file: - alter_schema_statement: - keyword: alter - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: set - schema_object_properties: - keyword: data_retention_time_in_days @@ -56,9 +50,8 @@ file: - alter_schema_statement: - keyword: alter - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: set - tag_equals: - keyword: tag @@ -78,9 +71,8 @@ file: - alter_schema_statement: - keyword: alter - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: unset - keyword: data_retention_time_in_days - statement_terminator: ; @@ -88,9 +80,8 @@ file: - alter_schema_statement: - keyword: alter - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: unset - keyword: data_retention_time_in_days - comma: ',' @@ -100,9 +91,8 @@ file: - alter_schema_statement: - keyword: alter - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: schema1 + - schema_reference: + - naked_identifier: schema1 - keyword: unset - keyword: tag - tag_reference: diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_sequence.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_sequence.yml index 353a638fa..20df89ca3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_sequence.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_sequence.yml @@ -3,18 +3,18 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: seq - keyword: RENAME - keyword: TO - - column_reference: + - sequence_reference: - naked_identifier: seq2 - statement_terminator: ; - statement: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: seq - keyword: SET - keyword: INCREMENT @@ -27,7 +27,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: seq - keyword: INCREMENT - keyword: BY @@ -39,7 +39,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: seq - keyword: INCREMENT - comparison_operator: @@ -50,7 +50,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: seq - keyword: INCREMENT - integer_literal: '2' @@ -59,7 +59,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: seq - keyword: SET - keyword: ORDER @@ -73,7 +73,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: seq - keyword: SET - keyword: NOORDER @@ -87,7 +87,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: seq - keyword: UNSET - keyword: COMMENT @@ -96,7 +96,7 @@ file: - alter_sequence_statement: - keyword: ALTER - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: seq - keyword: SET - keyword: INCREMENT diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_share.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_share.sql index 42e34c530..40935187e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_share.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_share.sql @@ -12,3 +12,4 @@ ALTER SHARE MY_SHARE ADD ACCOUNTS = my_account_1 SHARE_RESTRICTIONS = TRUE; ALTER SHARE MY_SHARE ADD ACCOUNTS = my_account_1, my_account_2 SHARE_RESTRICTIONS = FALSE; ALTER SHARE MY_SHARE SET ACCOUNTS = my_account_1 COMMENT = 'my_comment'; ALTER SHARE IF EXISTS MY_SHARE SET ACCOUNTS = my_account_1, my_account_2 COMMENT = 'my_comment'; +ALTER SHARE my_share ADD ACCOUNTS = org.account; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_share.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_share.yml index 3794a94fc..f2c8c306d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_share.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_share.yml @@ -8,7 +8,8 @@ file: - keyword: ACCOUNTS - comparison_operator: - raw_comparison_operator: = - - naked_identifier: my_account_1 + - object_reference: + - naked_identifier: my_account_1 - statement_terminator: ; - statement: - alter_share_statement: @@ -21,7 +22,8 @@ file: - keyword: ACCOUNTS - comparison_operator: - raw_comparison_operator: = - - naked_identifier: my_account_1 + - object_reference: + - naked_identifier: my_account_1 - statement_terminator: ; - statement: - alter_share_statement: @@ -32,7 +34,8 @@ file: - keyword: ACCOUNTS - comparison_operator: - raw_comparison_operator: = - - naked_identifier: my_account_1 + - object_reference: + - naked_identifier: my_account_1 - statement_terminator: ; - statement: - alter_share_statement: @@ -43,9 +46,11 @@ file: - keyword: ACCOUNTS - comparison_operator: - raw_comparison_operator: = - - naked_identifier: my_account_1 + - object_reference: + - naked_identifier: my_account_1 - comma: ',' - - naked_identifier: my_account_2 + - object_reference: + - naked_identifier: my_account_2 - statement_terminator: ; - statement: - alter_share_statement: @@ -56,11 +61,14 @@ file: - keyword: ACCOUNTS - comparison_operator: - raw_comparison_operator: = - - naked_identifier: my_account_1 + - object_reference: + - naked_identifier: my_account_1 - comma: ',' - - naked_identifier: my_account_2 + - object_reference: + - naked_identifier: my_account_2 - comma: ',' - - naked_identifier: my_account_3 + - object_reference: + - naked_identifier: my_account_3 - statement_terminator: ; - statement: - alter_share_statement: @@ -138,7 +146,8 @@ file: - keyword: ACCOUNTS - comparison_operator: - raw_comparison_operator: = - - naked_identifier: my_account_1 + - object_reference: + - naked_identifier: my_account_1 - keyword: SHARE_RESTRICTIONS - comparison_operator: - raw_comparison_operator: = @@ -153,9 +162,11 @@ file: - keyword: ACCOUNTS - comparison_operator: - raw_comparison_operator: = - - naked_identifier: my_account_1 + - object_reference: + - naked_identifier: my_account_1 - comma: ',' - - naked_identifier: my_account_2 + - object_reference: + - naked_identifier: my_account_2 - keyword: SHARE_RESTRICTIONS - comparison_operator: - raw_comparison_operator: = @@ -170,7 +181,8 @@ file: - keyword: ACCOUNTS - comparison_operator: - raw_comparison_operator: = - - naked_identifier: my_account_1 + - object_reference: + - naked_identifier: my_account_1 - comment_equals_clause: - keyword: COMMENT - comparison_operator: @@ -188,12 +200,28 @@ file: - keyword: ACCOUNTS - comparison_operator: - raw_comparison_operator: = - - naked_identifier: my_account_1 + - object_reference: + - naked_identifier: my_account_1 - comma: ',' - - naked_identifier: my_account_2 + - object_reference: + - naked_identifier: my_account_2 - comment_equals_clause: - keyword: COMMENT - comparison_operator: - raw_comparison_operator: = - quoted_literal: '''my_comment''' - statement_terminator: ; +- statement: + - alter_share_statement: + - keyword: ALTER + - keyword: SHARE + - naked_identifier: my_share + - keyword: ADD + - keyword: ACCOUNTS + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: org + - dot: . + - naked_identifier: account +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_stage.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_stage.yml index 4d3defc73..0b78c68d1 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_stage.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_stage.yml @@ -40,7 +40,7 @@ file: - object_reference: - naked_identifier: my_ext_stage - keyword: SET - - s3_external_stage_parameters: + - stage_parameters: - keyword: STORAGE_INTEGRATION - comparison_operator: - raw_comparison_operator: = @@ -54,7 +54,7 @@ file: - object_reference: - naked_identifier: my_ext_stage - keyword: SET - - s3_external_stage_parameters: + - stage_parameters: - keyword: CREDENTIALS - comparison_operator: - raw_comparison_operator: = @@ -77,7 +77,7 @@ file: - object_reference: - naked_identifier: my_ext_stage3 - keyword: SET - - s3_external_stage_parameters: + - stage_parameters: - keyword: ENCRYPTION - comparison_operator: - raw_comparison_operator: = diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_storage_integration.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_storage_integration.sql index 18606f369..7a5334584 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_storage_integration.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_storage_integration.sql @@ -111,4 +111,5 @@ alter storage integration if exists azure_int set storage_blocked_locations = ( 'azure://myaccount.blob.core.windows.net/mycontainer/path3/', 'azure://myaccount.blob.core.windows.net/mycontainer/path4/' - ); + ) + use_privatelink_endpoint = true; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_storage_integration.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_storage_integration.yml index 0ce621d24..f00a12834 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_storage_integration.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_storage_integration.yml @@ -45,10 +45,11 @@ file: - object_reference: - naked_identifier: test_integration - keyword: set - - keyword: comment - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''test comment''' + - comment_equals_clause: + - keyword: comment + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test comment''' - statement_terminator: ; - statement: - alter_storage_integration_statement: @@ -147,10 +148,11 @@ file: - comparison_operator: - raw_comparison_operator: = - boolean_literal: 'false' - - keyword: comment - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''test comment''' + - comment_equals_clause: + - keyword: comment + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test comment''' - statement_terminator: ; - statement: - alter_storage_integration_statement: @@ -160,10 +162,11 @@ file: - object_reference: - naked_identifier: test_integration - keyword: set - - keyword: comment - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''test comment''' + - comment_equals_clause: + - keyword: comment + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test comment''' - keyword: enabled - comparison_operator: - raw_comparison_operator: = @@ -389,10 +392,11 @@ file: - comparison_operator: - raw_comparison_operator: = - boolean_literal: 'true' - - keyword: comment - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''test_comment''' + - comment_equals_clause: + - keyword: comment + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test_comment''' - keyword: azure_tenant_id - comparison_operator: - raw_comparison_operator: = @@ -428,10 +432,11 @@ file: - comparison_operator: - raw_comparison_operator: = - boolean_literal: 'true' - - keyword: comment - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''test_comment''' + - comment_equals_clause: + - keyword: comment + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test_comment''' - keyword: azure_tenant_id - comparison_operator: - raw_comparison_operator: = @@ -452,4 +457,8 @@ file: - comma: ',' - bucket_path: '''azure://myaccount.blob.core.windows.net/mycontainer/path4/''' - end_bracket: ) + - keyword: use_privatelink_endpoint + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'true' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_streamlit.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_streamlit.sql new file mode 100644 index 000000000..2c08ff362 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_streamlit.sql @@ -0,0 +1,16 @@ +ALTER STREAMLIT my_streamlit SET +ROOT_LOCATION = '@stage_name/folder' +MAIN_FILE = 'main.py'; + +ALTER STREAMLIT my_streamlit SET +ROOT_LOCATION = '@stage_name/folder' +MAIN_FILE = 'main.py' +QUERY_WAREHOUSE = my_wh; + +ALTER STREAMLIT my_streamlit SET +ROOT_LOCATION = '@stage_name/folder' +MAIN_FILE = 'main.py' +QUERY_WAREHOUSE = my_wh +comment = 'New comment for stream'; + +ALTER STREAMLIT my_streamlit RENAME TO new_my_streamlit; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_streamlit.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_streamlit.yml new file mode 100644 index 000000000..fdf9e3d67 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_streamlit.yml @@ -0,0 +1,75 @@ +file: +- statement: + - alter_streamlit_statement: + - keyword: ALTER + - keyword: STREAMLIT + - object_reference: + - naked_identifier: my_streamlit + - keyword: SET + - keyword: ROOT_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - stage_path: '''@stage_name/folder''' + - keyword: MAIN_FILE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''main.py''' +- statement_terminator: ; +- statement: + - alter_streamlit_statement: + - keyword: ALTER + - keyword: STREAMLIT + - object_reference: + - naked_identifier: my_streamlit + - keyword: SET + - keyword: ROOT_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - stage_path: '''@stage_name/folder''' + - keyword: MAIN_FILE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''main.py''' + - keyword: QUERY_WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_wh +- statement_terminator: ; +- statement: + - alter_streamlit_statement: + - keyword: ALTER + - keyword: STREAMLIT + - object_reference: + - naked_identifier: my_streamlit + - keyword: SET + - keyword: ROOT_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - stage_path: '''@stage_name/folder''' + - keyword: MAIN_FILE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''main.py''' + - keyword: QUERY_WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_wh + - comment_equals_clause: + - keyword: comment + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''New comment for stream''' +- statement_terminator: ; +- statement: + - alter_streamlit_statement: + - keyword: ALTER + - keyword: STREAMLIT + - object_reference: + - naked_identifier: my_streamlit + - keyword: RENAME + - keyword: TO + - object_reference: + - naked_identifier: new_my_streamlit +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table.sql index 6dc4bd3fd..1cf983fd6 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table.sql @@ -14,12 +14,26 @@ ALTER TABLE my_table SET COMMENT = 'my table comment'; ALTER TABLE table1 ADD CONSTRAINT constraint1 PRIMARY KEY ( col1 ); +ALTER TABLE table1 ADD CONSTRAINT constraint1 PRIMARY KEY ( col1 ) ENFORCED VALIDATE RELY; + +ALTER TABLE table1 ADD CONSTRAINT constraint1 PRIMARY KEY ( col1 ) NOT ENFORCED NOVALIDATE NORELY; + +ALTER TABLE table1 ADD CONSTRAINT constraint1 UNIQUE ( col1 ); + +ALTER TABLE table1 ADD CONSTRAINT constraint1 UNIQUE ( col1 ) ENFORCED VALIDATE RELY; + +ALTER TABLE table1 ADD CONSTRAINT constraint1 UNIQUE ( col1 ) NOT ENFORCED NOVALIDATE NORELY; + ALTER TABLE table1 ADD CONSTRAINT "constraint1" PRIMARY KEY ( col1 ); ALTER TABLE table1 ADD CONSTRAINT "constraint1" PRIMARY KEY ( col1, col2 ); ALTER TABLE table1 ADD CONSTRAINT constraint1 FOREIGN KEY ( col1 ) REFERENCES table2 ( col2 ); +ALTER TABLE table1 ADD CONSTRAINT constraint1 FOREIGN KEY ( col1 ) REFERENCES table2 ( col2 ) ENFORCED VALIDATE RELY; + +ALTER TABLE table1 ADD CONSTRAINT constraint1 FOREIGN KEY ( col1 ) REFERENCES table2 ( col2 ) NOT ENFORCED NOVALIDATE NORELY; + ALTER TABLE table1 ADD CONSTRAINT "constraint1" FOREIGN KEY ( col1 ) REFERENCES table2 ( col2 ); ALTER TABLE table1 ADD CONSTRAINT "constraint1" FOREIGN KEY ( col1 ) REFERENCES "schema1"."table1" ("col2"); @@ -31,3 +45,61 @@ ALTER TABLE table1 DROP CONSTRAINT constraint1 UNIQUE pk_col, pk_col2; ALTER TABLE table1 RENAME CONSTRAINT constraint1 TO constraint2; ALTER TABLE "ADW_TEMP"."FRUIT_PRICE_SAT" ADD CONSTRAINT "FK_2" FOREIGN KEY ("SPECIAL_OFFER_ID") REFERENCES "ADW_TEMP"."OFFER_SAT" ("SPECIAL_OFFER_ID"); + +ALTER TABLE "my_table" ALTER COLUMN "my_column" SET MASKING POLICY my_masking_policy FORCE; + +ALTER TABLE SAMPLE_DB.SAMPLE_SCHEMA.TBL UNSET COMMENT; + +ALTER TABLE table1 UNSET COMMENT, DATA_RETENTION_TIME_IN_DAYS; + +ALTER TABLE table1 ADD CONSTRAINT constraint1 FOREIGN KEY (address) REFERENCES addresses (address) ON DELETE RESTRICT ON UPDATE CASCADE; + +ALTER TABLE table2 ADD CONSTRAINT constraint2 FOREIGN KEY (address) REFERENCES addresses (address) ON DELETE NO ACTION ON UPDATE SET NULL; + +ALTER TABLE table3 ADD CONSTRAINT constraint3 FOREIGN KEY (address) REFERENCES addresses (address) ON DELETE SET DEFAULT; + +ALTER TABLE table1 ADD CONSTRAINT constraint1 FOREIGN KEY (address) REFERENCES addresses (address) MATCH FULL; + +ALTER TABLE table1 ADD CONSTRAINT constraint1 FOREIGN KEY (address) REFERENCES addresses (address) MATCH SIMPLE; + +ALTER TABLE table1 ADD CONSTRAINT constraint1 FOREIGN KEY (address) REFERENCES addresses (address) MATCH PARTIAL; + +ALTER TABLE table1 DROP CONSTRAINT my_constraint; + +ALTER TABLE my_table SET TAG tag1 = "some_value"; + +ALTER TABLE my_table SET TAG tag1 = "some_value", tag2 = "some_value", tag3 = "some_value", tag4 = "some_value"; + +ALTER TABLE my_table UNSET TAG tag1; + +ALTER TABLE my_table UNSET TAG tag1, tag2, tag3, tag4; + +ALTER TABLE my_table ADD ROW ACCESS POLICY my_policy ON (col1); + +ALTER TABLE my_table ADD ROW ACCESS POLICY my_policy ON (col1, col2, col3); + +ALTER TABLE my_table DROP ROW ACCESS POLICY my_policy; + +ALTER TABLE my_table DROP ROW ACCESS POLICY my_policy, ADD ROW ACCESS POLICY my_policy ON (col1); + +ALTER TABLE my_table DROP ROW ACCESS POLICY my_policy, ADD ROW ACCESS POLICY my_policy ON (col1, col2, col3); + +ALTER TABLE my_table DROP ALL ROW ACCESS POLICIES; + +ALTER TABLE my_table SET AGGREGATION POLICY my_policy; + +ALTER TABLE my_table SET AGGREGATION POLICY my_policy ENTITY KEY (col1); + +ALTER TABLE my_table SET AGGREGATION POLICY my_policy ENTITY KEY (col1, col2, col3); + +ALTER TABLE my_table SET AGGREGATION POLICY my_policy FORCE; + +ALTER TABLE my_table SET AGGREGATION POLICY my_policy ENTITY KEY (col1) FORCE; + +ALTER TABLE my_table UNSET AGGREGATION POLICY; + +ALTER TABLE my_table SET JOIN POLICY my_policy; + +ALTER TABLE my_table SET JOIN POLICY my_policy FORCE; + +ALTER TABLE my_table UNSET JOIN POLICY; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table.yml index 1071ee920..b9fe00833 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table.yml @@ -85,15 +85,16 @@ file: - naked_identifier: table1 - alter_table_constraint_action: - keyword: ADD - - keyword: CONSTRAINT - - naked_identifier: constraint1 - - keyword: PRIMARY - - keyword: KEY - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: col1 - - end_bracket: ) + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint1 + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) - statement_terminator: ; - statement: - alter_table_statement: @@ -103,15 +104,19 @@ file: - naked_identifier: table1 - alter_table_constraint_action: - keyword: ADD - - keyword: CONSTRAINT - - quoted_identifier: '"constraint1"' - - keyword: PRIMARY - - keyword: KEY - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: col1 - - end_bracket: ) + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint1 + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: ENFORCED + - keyword: VALIDATE + - keyword: RELY - statement_terminator: ; - statement: - alter_table_statement: @@ -121,18 +126,20 @@ file: - naked_identifier: table1 - alter_table_constraint_action: - keyword: ADD - - keyword: CONSTRAINT - - quoted_identifier: '"constraint1"' - - keyword: PRIMARY - - keyword: KEY - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: col1 - - comma: ',' - - column_reference: - - naked_identifier: col2 - - end_bracket: ) + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint1 + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: NOT + - keyword: ENFORCED + - keyword: NOVALIDATE + - keyword: NORELY - statement_terminator: ; - statement: - alter_table_statement: @@ -142,23 +149,15 @@ file: - naked_identifier: table1 - alter_table_constraint_action: - keyword: ADD - - keyword: CONSTRAINT - - naked_identifier: constraint1 - - keyword: FOREIGN - - keyword: KEY - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: col1 - - end_bracket: ) - - keyword: REFERENCES - - table_reference: - - naked_identifier: table2 - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: col2 - - end_bracket: ) + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint1 + - keyword: UNIQUE + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) - statement_terminator: ; - statement: - alter_table_statement: @@ -168,23 +167,18 @@ file: - naked_identifier: table1 - alter_table_constraint_action: - keyword: ADD - - keyword: CONSTRAINT - - quoted_identifier: '"constraint1"' - - keyword: FOREIGN - - keyword: KEY - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: col1 - - end_bracket: ) - - keyword: REFERENCES - - table_reference: - - naked_identifier: table2 - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: col2 - - end_bracket: ) + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint1 + - keyword: UNIQUE + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: ENFORCED + - keyword: VALIDATE + - keyword: RELY - statement_terminator: ; - statement: - alter_table_statement: @@ -194,25 +188,19 @@ file: - naked_identifier: table1 - alter_table_constraint_action: - keyword: ADD - - keyword: CONSTRAINT - - quoted_identifier: '"constraint1"' - - keyword: FOREIGN - - keyword: KEY - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: col1 - - end_bracket: ) - - keyword: REFERENCES - - table_reference: - - quoted_identifier: '"schema1"' - - dot: . - - quoted_identifier: '"table1"' - - bracketed: - - start_bracket: ( - - column_reference: - - quoted_identifier: '"col2"' - - end_bracket: ) + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint1 + - keyword: UNIQUE + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: NOT + - keyword: ENFORCED + - keyword: NOVALIDATE + - keyword: NORELY - statement_terminator: ; - statement: - alter_table_statement: @@ -222,28 +210,214 @@ file: - naked_identifier: table1 - alter_table_constraint_action: - keyword: ADD - - keyword: CONSTRAINT - - quoted_identifier: '"constraint1"' - - keyword: FOREIGN - - keyword: KEY - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: col1 - - end_bracket: ) - - keyword: REFERENCES - - table_reference: - - quoted_identifier: '"schema1"' - - dot: . - - quoted_identifier: '"table1"' - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: col1 - - comma: ',' - - column_reference: - - naked_identifier: col2 - - end_bracket: ) + - constraint_properties_segment: + - keyword: CONSTRAINT + - quoted_identifier: '"constraint1"' + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - alter_table_constraint_action: + - keyword: ADD + - constraint_properties_segment: + - keyword: CONSTRAINT + - quoted_identifier: '"constraint1"' + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - alter_table_constraint_action: + - keyword: ADD + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint1 + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: table2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - alter_table_constraint_action: + - keyword: ADD + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint1 + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: table2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: ENFORCED + - keyword: VALIDATE + - keyword: RELY +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - alter_table_constraint_action: + - keyword: ADD + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint1 + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: table2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: NOT + - keyword: ENFORCED + - keyword: NOVALIDATE + - keyword: NORELY +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - alter_table_constraint_action: + - keyword: ADD + - constraint_properties_segment: + - keyword: CONSTRAINT + - quoted_identifier: '"constraint1"' + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: table2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - alter_table_constraint_action: + - keyword: ADD + - constraint_properties_segment: + - keyword: CONSTRAINT + - quoted_identifier: '"constraint1"' + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - quoted_identifier: '"schema1"' + - dot: . + - quoted_identifier: '"table1"' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '"col2"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - alter_table_constraint_action: + - keyword: ADD + - constraint_properties_segment: + - keyword: CONSTRAINT + - quoted_identifier: '"constraint1"' + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - quoted_identifier: '"schema1"' + - dot: . + - quoted_identifier: '"table1"' + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) - statement_terminator: ; - statement: - alter_table_statement: @@ -285,23 +459,623 @@ file: - quoted_identifier: '"FRUIT_PRICE_SAT"' - alter_table_constraint_action: - keyword: ADD + - constraint_properties_segment: + - keyword: CONSTRAINT + - quoted_identifier: '"FK_2"' + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '"SPECIAL_OFFER_ID"' + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - quoted_identifier: '"ADW_TEMP"' + - dot: . + - quoted_identifier: '"OFFER_SAT"' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '"SPECIAL_OFFER_ID"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '"my_table"' + - alter_table_table_column_action: + - keyword: ALTER + - keyword: COLUMN + - column_reference: + - quoted_identifier: '"my_column"' + - keyword: SET + - keyword: MASKING + - keyword: POLICY + - function_name: + - function_name_identifier: my_masking_policy + - keyword: FORCE +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: SAMPLE_DB + - dot: . + - naked_identifier: SAMPLE_SCHEMA + - dot: . + - naked_identifier: TBL + - keyword: UNSET + - parameter: COMMENT +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - keyword: UNSET + - parameter: COMMENT + - comma: ',' + - parameter: DATA_RETENTION_TIME_IN_DAYS +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - alter_table_constraint_action: + - keyword: ADD + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint1 + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: address + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: addresses + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: address + - end_bracket: ) + - keyword: ON + - keyword: DELETE + - keyword: RESTRICT + - keyword: ON + - keyword: UPDATE + - keyword: CASCADE +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table2 + - alter_table_constraint_action: + - keyword: ADD + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint2 + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: address + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: addresses + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: address + - end_bracket: ) + - keyword: ON + - keyword: DELETE + - keyword: NO + - keyword: ACTION + - keyword: ON + - keyword: UPDATE + - keyword: SET + - keyword: 'NULL' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table3 + - alter_table_constraint_action: + - keyword: ADD + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint3 + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: address + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: addresses + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: address + - end_bracket: ) + - keyword: ON + - keyword: DELETE + - keyword: SET + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - alter_table_constraint_action: + - keyword: ADD + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint1 + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: address + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: addresses + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: address + - end_bracket: ) + - keyword: MATCH + - keyword: FULL +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - alter_table_constraint_action: + - keyword: ADD + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint1 + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: address + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: addresses + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: address + - end_bracket: ) + - keyword: MATCH + - keyword: SIMPLE +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - alter_table_constraint_action: + - keyword: ADD + - constraint_properties_segment: + - keyword: CONSTRAINT + - naked_identifier: constraint1 + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: address + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: addresses + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: address + - end_bracket: ) + - keyword: MATCH + - keyword: PARTIAL +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table1 + - alter_table_table_column_action: + - keyword: DROP - keyword: CONSTRAINT - - quoted_identifier: '"FK_2"' - - keyword: FOREIGN + - object_reference: + - naked_identifier: my_constraint +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - tag_equals: + - keyword: TAG + - tag_reference: + - naked_identifier: tag1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"some_value"' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - tag_equals: + - keyword: TAG + - tag_reference: + - naked_identifier: tag1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"some_value"' + - comma: ',' + - tag_reference: + - naked_identifier: tag2 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"some_value"' + - comma: ',' + - tag_reference: + - naked_identifier: tag3 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"some_value"' + - comma: ',' + - tag_reference: + - naked_identifier: tag4 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"some_value"' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: UNSET + - keyword: TAG + - tag_reference: + - naked_identifier: tag1 +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: UNSET + - keyword: TAG + - tag_reference: + - naked_identifier: tag1 + - comma: ',' + - tag_reference: + - naked_identifier: tag2 + - comma: ',' + - tag_reference: + - naked_identifier: tag3 + - comma: ',' + - tag_reference: + - naked_identifier: tag4 +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: ADD + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - keyword: ON + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: col1 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: ADD + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - keyword: ON + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: col1 + - comma: ',' + - object_reference: + - naked_identifier: col2 + - comma: ',' + - object_reference: + - naked_identifier: col3 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: DROP + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: DROP + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - comma: ',' + - keyword: ADD + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - keyword: ON + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: col1 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: DROP + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - comma: ',' + - keyword: ADD + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - keyword: ON + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: col1 + - comma: ',' + - object_reference: + - naked_identifier: col2 + - comma: ',' + - object_reference: + - naked_identifier: col3 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: DROP + - keyword: ALL + - keyword: ROW + - keyword: ACCESS + - keyword: POLICIES +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - keyword: AGGREGATION + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - keyword: AGGREGATION + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - keyword: ENTITY + - keyword: KEY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: col1 + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - keyword: AGGREGATION + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - keyword: ENTITY - keyword: KEY - bracketed: - start_bracket: ( - - column_reference: - - quoted_identifier: '"SPECIAL_OFFER_ID"' + - object_reference: + - naked_identifier: col1 + - comma: ',' + - object_reference: + - naked_identifier: col2 + - comma: ',' + - object_reference: + - naked_identifier: col3 - end_bracket: ) - - keyword: REFERENCES - - table_reference: - - quoted_identifier: '"ADW_TEMP"' - - dot: . - - quoted_identifier: '"OFFER_SAT"' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - keyword: AGGREGATION + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - keyword: FORCE +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - keyword: AGGREGATION + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - keyword: ENTITY + - keyword: KEY - bracketed: - start_bracket: ( - - column_reference: - - quoted_identifier: '"SPECIAL_OFFER_ID"' + - object_reference: + - naked_identifier: col1 - end_bracket: ) + - keyword: FORCE +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: UNSET + - keyword: AGGREGATION + - keyword: POLICY +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - keyword: JOIN + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: SET + - keyword: JOIN + - keyword: POLICY + - object_reference: + - naked_identifier: my_policy + - keyword: FORCE +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - data_governance_policy_tag_action_segment: + - keyword: UNSET + - keyword: JOIN + - keyword: POLICY - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table_column.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table_column.sql index 72379ad04..e447a8d30 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table_column.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table_column.sql @@ -1,10 +1,13 @@ --- Add column +-- ADD column ---- Base cases ALTER TABLE my_table ADD COLUMN my_column INTEGER; ALTER TABLE my_table ADD COLUMN my_column VARCHAR(5000) NOT NULL; +ALTER TABLE my_table ADD COLUMN IF NOT EXISTS my_column INTEGER; ------ Multiple columns ALTER TABLE my_table ADD COLUMN column_1 varchar, column_2 integer; +ALTER TABLE my_table ADD COLUMN IF NOT EXISTS column_1 varchar, IF NOT EXISTS column_2 integer; +ALTER TABLE my_table ADD COLUMN IF NOT EXISTS column_1 varchar, column_2 integer; ---- Default, auto-increment & identity ALTER TABLE my_table ADD COLUMN my_column INTEGER DEFAULT 1; @@ -33,32 +36,32 @@ ALTER TABLE empl_info RENAME COLUMN old_col_name TO new_col_name; -- Alter-modify column(s) ---- Base cases ------ Single column -alter table t1 alter column c1 drop not null; -alter table t1 alter c5 comment '50 character column'; +ALTER TABLE t1 alter column c1 drop not null; +ALTER TABLE t1 alter c5 comment '50 character column'; ------ Multiple columns/properties -alter table t1 modify c2 drop default, c3 set default seq5.nextval ; -alter table t1 alter c4 set data type varchar(50), column c4 drop default; +ALTER TABLE t1 modify c2 drop default, c3 set default seq5.nextval ; +ALTER TABLE t1 alter c4 set data type varchar(50), column c4 drop default; ---- Set Masking Policy ------ Single column ALTER TABLE xxxx.example_table MODIFY COLUMN employeeCode SET MASKING POLICY example_MASKING_POLICY; ALTER TABLE aschema.atable MODIFY COLUMN acolumn SET MASKING POLICY adatabase.aschema.apolicy; -alter table empl_info modify column empl_id set masking policy mask_empl_id; -alter table empl_info modify column empl_id set masking policy mask_empl_id using(empl_id, empl_id > 10); +ALTER TABLE empl_info modify column empl_id set masking policy mask_empl_id; +ALTER TABLE empl_info modify column empl_id set masking policy mask_empl_id using(empl_id, empl_id > 10); ------ Multiple columns -alter table empl_info modify +ALTER TABLE empl_info modify column empl_id set masking policy mask_empl_id , column empl_dob set masking policy mask_empl_dob ; ---- Unset masking policy ------ Single column -alter table empl_info modify column empl_id unset masking policy; +ALTER TABLE empl_info modify column empl_id unset masking policy; ------ Multiple columns -alter table empl_info modify +ALTER TABLE empl_info modify column empl_id unset masking policy , column empl_dob unset masking policy ; @@ -74,6 +77,12 @@ ALTER TABLE empl_info DROP COLUMN my_column; ALTER TABLE some_schema.empl_info DROP COLUMN my_column; ALTER TABLE my_table DROP COLUMN column_1, column_2, column_3; +-- Drop column if exists +ALTER TABLE demo_db.public DROP column IF EXISTS public_name, IF EXISTS description_text, IF EXISTS type_alias; +ALTER TABLE demo_db.public DROP column public_name, description_text, type_alias; +ALTER TABLE demo_db.public DROP public_name, description_text, type_alias; +ALTER TABLE demo_db.public DROP IF EXISTS public_name, IF EXISTS description_text, IF EXISTS type_alias; + -- IF EXISTS ALTER TABLE IF EXISTS my_table ADD COLUMN my_column INTEGER; ALTER TABLE IF EXISTS empl_info DROP COLUMN my_column; @@ -84,4 +93,12 @@ ALTER TABLE IF EXISTS empl_info RENAME COLUMN old_col_name TO new_col_name; ALTER TABLE my_schema.my_table drop PRIMARY KEY; -- ADD PRIMARY KEY -ALTER TABLE my_schema.my_table add PRIMARY KEY(TABLE_ID); +ALTER TABLE my_schema.my_table ADD PRIMARY KEY(TABLE_ID); + +-- ADD Virtual/Calculated columns +ALTER TABLE some_schema.some_table ADD some_column_upr VARCHAR AS UPPER(some_column) COMMENT 'This is a virtual column'; +ALTER TABLE some_schema.some_table ADD column IF NOT EXISTS some_other_column_upr VARCHAR AS UPPER(some_column) || 'some characters' || LOWER(some_column); +ALTER TABLE some_schema.some_table ADD column IF NOT EXISTS some_column_upr VARCHAR AS (UPPER(some_column)); +ALTER TABLE some_schema.some_table ADD column IF NOT EXISTS some_event_date_time_utc TIMESTAMP AS (IFF(is_condition_true AND TRY_TO_NUMBER(some_text_value) IS NOT NULL, TO_TIMESTAMP(SUBSTR(some_text_value, 5, 13)), '1900-01-01')); + +ALTER TABLE IF EXISTS table1 ADD COLUMN IF NOT EXISTS some_column INTEGER NOT NULL; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table_column.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table_column.yml index 0e70f00dc..f9928f787 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table_column.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_table_column.yml @@ -22,18 +22,78 @@ file: - alter_table_table_column_action: - keyword: ADD - keyword: COLUMN - - column_definition: + - column_reference: - naked_identifier: my_column - - data_type: - - data_type_identifier: VARCHAR - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '5000' - - end_bracket: ) - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '5000' + - end_bracket: ) + - keyword: NOT + - keyword: 'NULL' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - alter_table_table_column_action: + - keyword: ADD + - keyword: COLUMN + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - column_reference: + - naked_identifier: my_column + - data_type: + - data_type_identifier: INTEGER +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - alter_table_table_column_action: + - keyword: ADD + - keyword: COLUMN + - column_reference: + - naked_identifier: column_1 + - data_type: + - data_type_identifier: varchar + - comma: ',' + - column_reference: + - naked_identifier: column_2 + - data_type: + - data_type_identifier: integer +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - alter_table_table_column_action: + - keyword: ADD + - keyword: COLUMN + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - column_reference: + - naked_identifier: column_1 + - data_type: + - data_type_identifier: varchar + - comma: ',' + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - column_reference: + - naked_identifier: column_2 + - data_type: + - data_type_identifier: integer - statement_terminator: ; - statement: - alter_table_statement: @@ -44,6 +104,9 @@ file: - alter_table_table_column_action: - keyword: ADD - keyword: COLUMN + - keyword: IF + - keyword: NOT + - keyword: EXISTS - column_reference: - naked_identifier: column_1 - data_type: @@ -283,8 +346,8 @@ file: - statement_terminator: ; - statement: - alter_table_statement: - - keyword: alter - - keyword: table + - keyword: ALTER + - keyword: TABLE - table_reference: - naked_identifier: t1 - alter_table_table_column_action: @@ -298,8 +361,8 @@ file: - statement_terminator: ; - statement: - alter_table_statement: - - keyword: alter - - keyword: table + - keyword: ALTER + - keyword: TABLE - table_reference: - naked_identifier: t1 - alter_table_table_column_action: @@ -312,8 +375,8 @@ file: - statement_terminator: ; - statement: - alter_table_statement: - - keyword: alter - - keyword: table + - keyword: ALTER + - keyword: TABLE - table_reference: - naked_identifier: t1 - alter_table_table_column_action: @@ -333,8 +396,8 @@ file: - statement_terminator: ; - statement: - alter_table_statement: - - keyword: alter - - keyword: table + - keyword: ALTER + - keyword: TABLE - table_reference: - naked_identifier: t1 - alter_table_table_column_action: @@ -402,8 +465,8 @@ file: - statement_terminator: ; - statement: - alter_table_statement: - - keyword: alter - - keyword: table + - keyword: ALTER + - keyword: TABLE - table_reference: - naked_identifier: empl_info - alter_table_table_column_action: @@ -419,8 +482,8 @@ file: - statement_terminator: ; - statement: - alter_table_statement: - - keyword: alter - - keyword: table + - keyword: ALTER + - keyword: TABLE - table_reference: - naked_identifier: empl_info - alter_table_table_column_action: @@ -449,8 +512,8 @@ file: - statement_terminator: ; - statement: - alter_table_statement: - - keyword: alter - - keyword: table + - keyword: ALTER + - keyword: TABLE - table_reference: - naked_identifier: empl_info - alter_table_table_column_action: @@ -475,8 +538,8 @@ file: - statement_terminator: ; - statement: - alter_table_statement: - - keyword: alter - - keyword: table + - keyword: ALTER + - keyword: TABLE - table_reference: - naked_identifier: empl_info - alter_table_table_column_action: @@ -490,8 +553,8 @@ file: - statement_terminator: ; - statement: - alter_table_statement: - - keyword: alter - - keyword: table + - keyword: ALTER + - keyword: TABLE - table_reference: - naked_identifier: empl_info - alter_table_table_column_action: @@ -589,6 +652,96 @@ file: - column_reference: - naked_identifier: column_3 - statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: demo_db + - dot: . + - naked_identifier: public + - alter_table_table_column_action: + - keyword: DROP + - keyword: column + - keyword: IF + - keyword: EXISTS + - column_reference: + - naked_identifier: public_name + - comma: ',' + - keyword: IF + - keyword: EXISTS + - column_reference: + - naked_identifier: description_text + - comma: ',' + - keyword: IF + - keyword: EXISTS + - column_reference: + - naked_identifier: type_alias +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: demo_db + - dot: . + - naked_identifier: public + - alter_table_table_column_action: + - keyword: DROP + - keyword: column + - column_reference: + - naked_identifier: public_name + - comma: ',' + - column_reference: + - naked_identifier: description_text + - comma: ',' + - column_reference: + - naked_identifier: type_alias +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: demo_db + - dot: . + - naked_identifier: public + - alter_table_table_column_action: + - keyword: DROP + - column_reference: + - naked_identifier: public_name + - comma: ',' + - column_reference: + - naked_identifier: description_text + - comma: ',' + - column_reference: + - naked_identifier: type_alias +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: demo_db + - dot: . + - naked_identifier: public + - alter_table_table_column_action: + - keyword: DROP + - keyword: IF + - keyword: EXISTS + - column_reference: + - naked_identifier: public_name + - comma: ',' + - keyword: IF + - keyword: EXISTS + - column_reference: + - naked_identifier: description_text + - comma: ',' + - keyword: IF + - keyword: EXISTS + - column_reference: + - naked_identifier: type_alias +- statement_terminator: ; - statement: - alter_table_statement: - keyword: ALTER @@ -669,12 +822,226 @@ file: - naked_identifier: my_schema - dot: . - naked_identifier: my_table - - keyword: add - - keyword: PRIMARY - - keyword: KEY - - bracketed: - - start_bracket: ( + - alter_table_constraint_action: + - keyword: ADD + - constraint_properties_segment: + - keyword: PRIMARY + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: TABLE_ID + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: some_schema + - dot: . + - naked_identifier: some_table + - alter_table_table_column_action: + - keyword: ADD + - column_reference: + - naked_identifier: some_column_upr + - data_type: + - data_type_identifier: VARCHAR + - keyword: AS + - expression: + - function: + - function_name: + - function_name_identifier: UPPER + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: some_column + - end_bracket: ) + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''This is a virtual column''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: some_schema + - dot: . + - naked_identifier: some_table + - alter_table_table_column_action: + - keyword: ADD + - keyword: column + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - column_reference: + - naked_identifier: some_other_column_upr + - data_type: + - data_type_identifier: VARCHAR + - keyword: AS + - expression: + - function: + - function_name: + - function_name_identifier: UPPER + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: some_column + - end_bracket: ) + - binary_operator: + - pipe: '|' + - pipe: '|' + - quoted_literal: '''some characters''' + - binary_operator: + - pipe: '|' + - pipe: '|' + - function: + - function_name: + - function_name_identifier: LOWER + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: some_column + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: some_schema + - dot: . + - naked_identifier: some_table + - alter_table_table_column_action: + - keyword: ADD + - keyword: column + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - column_reference: + - naked_identifier: some_column_upr + - data_type: + - data_type_identifier: VARCHAR + - keyword: AS + - expression: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: UPPER + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: some_column + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: some_schema + - dot: . + - naked_identifier: some_table + - alter_table_table_column_action: + - keyword: ADD + - keyword: column + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - column_reference: + - naked_identifier: some_event_date_time_utc + - data_type: + - keyword: TIMESTAMP + - keyword: AS + - expression: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: IFF + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: is_condition_true + - binary_operator: AND + - function: + - function_name: + - function_name_identifier: TRY_TO_NUMBER + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: some_text_value + - end_bracket: ) + - keyword: IS + - keyword: NOT + - null_literal: 'NULL' + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: TO_TIMESTAMP + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: SUBSTR + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: some_text_value + - comma: ',' + - expression: + - numeric_literal: '5' + - comma: ',' + - expression: + - numeric_literal: '13' + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - expression: + - quoted_literal: '''1900-01-01''' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - keyword: IF + - keyword: EXISTS + - table_reference: + - naked_identifier: table1 + - alter_table_table_column_action: + - keyword: ADD + - keyword: COLUMN + - keyword: IF + - keyword: NOT + - keyword: EXISTS - column_reference: - - naked_identifier: TABLE_ID - - end_bracket: ) + - naked_identifier: some_column + - data_type: + - data_type_identifier: INTEGER + - keyword: NOT + - keyword: 'NULL' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_tag.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_tag.sql new file mode 100644 index 000000000..a5f0ce5a1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_tag.sql @@ -0,0 +1,21 @@ +ALTER TAG my_tag RENAME TO your_tag; + +ALTER TAG IF EXISTS my_tag RENAME TO your_tag; + +ALTER TAG my_tag SET MASKING POLICY policy_name; + +ALTER TAG my_tag SET MASKING POLICY policy_name, MASKING POLICY policy_name_2, MASKING POLICY policy_name_3; + +ALTER TAG my_tag SET COMMENT = 'this is a comment'; + +ALTER TAG my_tag UNSET COMMENT; + +ALTER TAG my_tag ADD ALLOWED_VALUES 'my_value'; + +ALTER TAG my_tag ADD ALLOWED_VALUES 'my_value', 'my_value_2'; + +ALTER TAG my_tag DROP ALLOWED_VALUES 'my_value'; + +ALTER TAG my_tag DROP ALLOWED_VALUES 'my_value', 'my_value_2'; + +ALTER TAG my_tag UNSET ALLOWED_VALUES; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_tag.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_tag.yml new file mode 100644 index 000000000..f32b8c148 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_tag.yml @@ -0,0 +1,130 @@ +file: +- statement: + - alter_tag_statement: + - keyword: ALTER + - keyword: TAG + - object_reference: + - naked_identifier: my_tag + - keyword: RENAME + - keyword: TO + - object_reference: + - naked_identifier: your_tag +- statement_terminator: ; +- statement: + - alter_tag_statement: + - keyword: ALTER + - keyword: TAG + - keyword: IF + - keyword: EXISTS + - object_reference: + - naked_identifier: my_tag + - keyword: RENAME + - keyword: TO + - object_reference: + - naked_identifier: your_tag +- statement_terminator: ; +- statement: + - alter_tag_statement: + - keyword: ALTER + - keyword: TAG + - object_reference: + - naked_identifier: my_tag + - keyword: SET + - keyword: MASKING + - keyword: POLICY + - parameter: policy_name +- statement_terminator: ; +- statement: + - alter_tag_statement: + - keyword: ALTER + - keyword: TAG + - object_reference: + - naked_identifier: my_tag + - keyword: SET + - keyword: MASKING + - keyword: POLICY + - parameter: policy_name + - comma: ',' + - keyword: MASKING + - keyword: POLICY + - parameter: policy_name_2 + - comma: ',' + - keyword: MASKING + - keyword: POLICY + - parameter: policy_name_3 +- statement_terminator: ; +- statement: + - alter_tag_statement: + - keyword: ALTER + - keyword: TAG + - object_reference: + - naked_identifier: my_tag + - keyword: SET + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''this is a comment''' +- statement_terminator: ; +- statement: + - alter_tag_statement: + - keyword: ALTER + - keyword: TAG + - object_reference: + - naked_identifier: my_tag + - keyword: UNSET + - keyword: COMMENT +- statement_terminator: ; +- statement: + - alter_tag_statement: + - keyword: ALTER + - keyword: TAG + - object_reference: + - naked_identifier: my_tag + - keyword: ADD + - keyword: ALLOWED_VALUES + - quoted_literal: '''my_value''' +- statement_terminator: ; +- statement: + - alter_tag_statement: + - keyword: ALTER + - keyword: TAG + - object_reference: + - naked_identifier: my_tag + - keyword: ADD + - keyword: ALLOWED_VALUES + - quoted_literal: '''my_value''' + - comma: ',' + - quoted_literal: '''my_value_2''' +- statement_terminator: ; +- statement: + - alter_tag_statement: + - keyword: ALTER + - keyword: TAG + - object_reference: + - naked_identifier: my_tag + - keyword: DROP + - keyword: ALLOWED_VALUES + - quoted_literal: '''my_value''' +- statement_terminator: ; +- statement: + - alter_tag_statement: + - keyword: ALTER + - keyword: TAG + - object_reference: + - naked_identifier: my_tag + - keyword: DROP + - keyword: ALLOWED_VALUES + - quoted_literal: '''my_value''' + - comma: ',' + - quoted_literal: '''my_value_2''' +- statement_terminator: ; +- statement: + - alter_tag_statement: + - keyword: ALTER + - keyword: TAG + - object_reference: + - naked_identifier: my_tag + - keyword: UNSET + - keyword: ALLOWED_VALUES +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_add_after.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_add_after.sql index 7bcdf67bb..e1f39c8ad 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_add_after.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_add_after.sql @@ -1 +1,3 @@ ALTER TASK my_task ADD AFTER another_task; + +ALTER TASK my_task ADD AFTER another_task, yet_another_task; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_add_after.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_add_after.yml index 103ee3154..4d9e1fd6e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_add_after.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_add_after.yml @@ -10,3 +10,17 @@ file: - object_reference: - naked_identifier: another_task - statement_terminator: ; +- statement: + - alter_task_statement: + - keyword: ALTER + - keyword: TASK + - object_reference: + - naked_identifier: my_task + - keyword: ADD + - keyword: AFTER + - object_reference: + - naked_identifier: another_task + - comma: ',' + - object_reference: + - naked_identifier: yet_another_task +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_remove_after.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_remove_after.sql index 6821fe092..1a6d40646 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_remove_after.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_remove_after.sql @@ -1 +1,3 @@ ALTER TASK my_task REMOVE AFTER another_task; + +ALTER TASK my_task REMOVE AFTER another_task, yet_another_task; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_remove_after.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_remove_after.yml index d6a57a8e0..c2958d101 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_remove_after.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_task_remove_after.yml @@ -10,3 +10,17 @@ file: - object_reference: - naked_identifier: another_task - statement_terminator: ; +- statement: + - alter_task_statement: + - keyword: ALTER + - keyword: TASK + - object_reference: + - naked_identifier: my_task + - keyword: REMOVE + - keyword: AFTER + - object_reference: + - naked_identifier: another_task + - comma: ',' + - object_reference: + - naked_identifier: yet_another_task +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_set_values.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_set_values.sql index a0eb65fb9..b40e3c53e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_set_values.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_set_values.sql @@ -1 +1,3 @@ -ALTER USER my_user SET password = 'abc123', DEFAULT_ROLE = user_role; +ALTER USER my_user SET password = 'abc123', DEFAULT_ROLE = user_role, type = person; +ALTER USER "John" SET DEFAULT_ROLE = JOHNNY DEFAULT_WAREHOUSE = FEU; +ALTER USER "John" SET DEFAULT_ROLE = JOHNNY DEFAULT_WAREHOUSE = FEU, COMMENT = "Foo"; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_set_values.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_set_values.yml index 297d44e35..0e7eb6da3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_set_values.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_set_values.yml @@ -16,4 +16,52 @@ file: - raw_comparison_operator: = - object_reference: - naked_identifier: user_role + - comma: ',' + - parameter: type + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: person +- statement_terminator: ; +- statement: + - alter_user_statement: + - keyword: ALTER + - keyword: USER + - role_reference: + - quoted_identifier: '"John"' + - keyword: SET + - parameter: DEFAULT_ROLE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: JOHNNY + - parameter: DEFAULT_WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: FEU +- statement_terminator: ; +- statement: + - alter_user_statement: + - keyword: ALTER + - keyword: USER + - role_reference: + - quoted_identifier: '"John"' + - keyword: SET + - parameter: DEFAULT_ROLE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: JOHNNY + - parameter: DEFAULT_WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: FEU + - comma: ',' + - parameter: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - quoted_identifier: '"Foo"' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_unset_values.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_unset_values.sql index d035471c4..185168cc0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_unset_values.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_unset_values.sql @@ -1 +1 @@ -ALTER USER my_user unset USE_CACHED_RESULT, must_change_password; +ALTER USER my_user unset USE_CACHED_RESULT, must_change_password, type; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_unset_values.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_unset_values.yml index ad8b90445..10ba3274c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_unset_values.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_user_unset_values.yml @@ -9,4 +9,6 @@ file: - parameter: USE_CACHED_RESULT - comma: ',' - parameter: must_change_password + - comma: ',' + - parameter: type - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_view.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_view.sql index 81fbb8dab..856e33c7c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_view.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_view.sql @@ -34,7 +34,10 @@ alter view v1 alter view v1 drop row access policy rap_v1_version_1, - add row access policy rap_v1_version_2 on (empl_id); + add row access policy rap_v1_version_2 on (empl_id), + add row access policy rap_v1_version_3 on ("empl_id"); alter view v1 modify column foo set masking policy my.scoped.policy; + +ALTER VIEW "my_table" ALTER COLUMN "my_column" SET MASKING POLICY my_masking_policy FORCE; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_view.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_view.yml index 2a0a8afa6..5b136eb53 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_view.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_view.yml @@ -161,6 +161,19 @@ file: - column_reference: - naked_identifier: empl_id - end_bracket: ) + - comma: ',' + - keyword: add + - keyword: row + - keyword: access + - keyword: policy + - function_name: + - function_name_identifier: rap_v1_version_3 + - keyword: on + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '"empl_id"' + - end_bracket: ) - statement_terminator: ; - statement: - alter_view_statement: @@ -182,3 +195,20 @@ file: - dot: . - function_name_identifier: policy - statement_terminator: ; +- statement: + - alter_view_statement: + - keyword: ALTER + - keyword: VIEW + - table_reference: + - quoted_identifier: '"my_table"' + - keyword: ALTER + - keyword: COLUMN + - column_reference: + - quoted_identifier: '"my_column"' + - keyword: SET + - keyword: MASKING + - keyword: POLICY + - function_name: + - function_name_identifier: my_masking_policy + - keyword: FORCE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_warehouse.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_warehouse.sql index 6b5590da2..08a1a9bd3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_warehouse.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_warehouse.sql @@ -34,9 +34,16 @@ alter warehouse set warehouse_size=medium; alter warehouse LOAD_WH set WAREHOUSE_TYPE = STANDARD; alter warehouse LOAD_WH set WAREHOUSE_TYPE = 'SNOWPARK-OPTIMIZED'; +alter warehouse LOAD_WH set RESOURCE_CONSTRAINT = 'MEMORY_64X'; +alter warehouse LOAD_WH set RESOURCE_CONSTRAINT = MEMORY_1X; + ALTER WAREHOUSE IDENTIFIER($var_wh) SET WAREHOUSE_TYPE = STANDARD; ALTER WAREHOUSE CI_TRANSFORMING SET COMMENT = 'Warehouse for dbt development transformations in CI' , AUTO_RESUME = TRUE , AUTO_SUSPEND=30; + +ALTER WAREHOUSE LOAD_WH SET +ENABLE_QUERY_ACCELERATION = true +QUERY_ACCELERATION_MAX_SCALE_FACTOR = 4; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_warehouse.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_warehouse.yml index 90fab12be..36db17c4f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_warehouse.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/alter_warehouse.yml @@ -377,6 +377,32 @@ file: - raw_comparison_operator: = - warehouse_size: '''SNOWPARK-OPTIMIZED''' - statement_terminator: ; +- statement: + - alter_warehouse_statement: + - keyword: alter + - keyword: warehouse + - object_reference: + - naked_identifier: LOAD_WH + - keyword: set + - warehouse_object_properties: + - keyword: RESOURCE_CONSTRAINT + - comparison_operator: + - raw_comparison_operator: = + - resource_constraint: '''MEMORY_64X''' +- statement_terminator: ; +- statement: + - alter_warehouse_statement: + - keyword: alter + - keyword: warehouse + - object_reference: + - naked_identifier: LOAD_WH + - keyword: set + - warehouse_object_properties: + - keyword: RESOURCE_CONSTRAINT + - comparison_operator: + - raw_comparison_operator: = + - resource_constraint: MEMORY_1X +- statement_terminator: ; - statement: - alter_warehouse_statement: - keyword: ALTER @@ -419,3 +445,20 @@ file: - raw_comparison_operator: = - numeric_literal: '30' - statement_terminator: ; +- statement: + - alter_warehouse_statement: + - keyword: ALTER + - keyword: WAREHOUSE + - object_reference: + - naked_identifier: LOAD_WH + - keyword: SET + - warehouse_object_properties: + - keyword: ENABLE_QUERY_ACCELERATION + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'true' + - keyword: QUERY_ACCELERATION_MAX_SCALE_FACTOR + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '4' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/at_before_time_travel.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/at_before_time_travel.sql new file mode 100644 index 000000000..d47932d6c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/at_before_time_travel.sql @@ -0,0 +1,29 @@ +SELECT * FROM my_table AT ( TIMESTAMP => '2024-06-05 12:30:00'::TIMESTAMP_LTZ ); + +SELECT * FROM my_table AT ( TIMESTAMP => '2024-06-05 12:30:00'::TIMESTAMP ); + +SELECT * FROM my_table AT ( TIMESTAMP => '2024-06-05 12:30:00' ); + +SELECT * FROM my_table AT ( TIMESTAMP => '2024-06-05 12:30:00' ) AS T; + +SELECT * FROM my_table BEFORE(STATEMENT => '8e5d0ca9-005e-44e6-b858-a8f5b37c5726'); + +SELECT oldt.* ,newt.* + FROM my_table BEFORE(STATEMENT => '8e5d0ca9-005e-44e6-b858-a8f5b37c5726') AS oldt + FULL OUTER JOIN my_table AT(STATEMENT => '8e5d0ca9-005e-44e6-b858-a8f5b37c5726') AS newt + ON oldt.id = newt.id + WHERE oldt.id IS NULL OR newt.id IS NULL; + + SELECT * + FROM db1.public.htt1 + AT(TIMESTAMP => '2024-06-05 17:50:00'::TIMESTAMP_LTZ) h + JOIN db1.public.tt1 + AT(TIMESTAMP => '2024-06-05 17:50:00'::TIMESTAMP_LTZ) t + ON h.c1=t.c1; + + +-- https://github.com/sqlfluff/sqlfluff/issues/6070 +SELECT * FROM my_table AT (TIMESTAMP => TO_TIMESTAMP(DATEADD('DAY', -1, DATEADD('MONTH', -1, DATEADD('DAY', -1, CURRENT_DATE))))); + +-- https://github.com/sqlfluff/sqlfluff/issues/5570 +SELECT * FROM my_table AT(TIMESTAMP => 'Fri, 01 May 2015 16:20:00 -0700'::timestamp_tz); diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/at_before_time_travel.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/at_before_time_travel.yml new file mode 100644 index 000000000..bbccf2991 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/at_before_time_travel.yml @@ -0,0 +1,409 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - from_at_expression: + - keyword: AT + - bracketed: + - start_bracket: ( + - keyword: TIMESTAMP + - parameter_assigner: => + - expression: + - cast_expression: + - quoted_literal: '''2024-06-05 12:30:00''' + - casting_operator: '::' + - data_type: + - data_type_identifier: TIMESTAMP_LTZ + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - from_at_expression: + - keyword: AT + - bracketed: + - start_bracket: ( + - keyword: TIMESTAMP + - parameter_assigner: => + - expression: + - cast_expression: + - quoted_literal: '''2024-06-05 12:30:00''' + - casting_operator: '::' + - data_type: + - keyword: TIMESTAMP + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - from_at_expression: + - keyword: AT + - bracketed: + - start_bracket: ( + - keyword: TIMESTAMP + - parameter_assigner: => + - expression: + - quoted_literal: '''2024-06-05 12:30:00''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - from_at_expression: + - keyword: AT + - bracketed: + - start_bracket: ( + - keyword: TIMESTAMP + - parameter_assigner: => + - expression: + - quoted_literal: '''2024-06-05 12:30:00''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: T +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - from_before_expression: + - keyword: BEFORE + - bracketed: + - start_bracket: ( + - keyword: STATEMENT + - parameter_assigner: => + - expression: + - quoted_literal: '''8e5d0ca9-005e-44e6-b858-a8f5b37c5726''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - naked_identifier: oldt + - dot: . + - star: '*' + - comma: ',' + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - naked_identifier: newt + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - from_before_expression: + - keyword: BEFORE + - bracketed: + - start_bracket: ( + - keyword: STATEMENT + - parameter_assigner: => + - expression: + - quoted_literal: '''8e5d0ca9-005e-44e6-b858-a8f5b37c5726''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: oldt + - join_clause: + - keyword: FULL + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - from_at_expression: + - keyword: AT + - bracketed: + - start_bracket: ( + - keyword: STATEMENT + - parameter_assigner: => + - expression: + - quoted_literal: '''8e5d0ca9-005e-44e6-b858-a8f5b37c5726''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: newt + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: oldt + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: newt + - dot: . + - naked_identifier: id + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: oldt + - dot: . + - naked_identifier: id + - keyword: IS + - null_literal: 'NULL' + - binary_operator: OR + - column_reference: + - naked_identifier: newt + - dot: . + - naked_identifier: id + - keyword: IS + - null_literal: 'NULL' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: db1 + - dot: . + - naked_identifier: public + - dot: . + - naked_identifier: htt1 + - from_at_expression: + - keyword: AT + - bracketed: + - start_bracket: ( + - keyword: TIMESTAMP + - parameter_assigner: => + - expression: + - cast_expression: + - quoted_literal: '''2024-06-05 17:50:00''' + - casting_operator: '::' + - data_type: + - data_type_identifier: TIMESTAMP_LTZ + - end_bracket: ) + - alias_expression: + - naked_identifier: h + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: db1 + - dot: . + - naked_identifier: public + - dot: . + - naked_identifier: tt1 + - from_at_expression: + - keyword: AT + - bracketed: + - start_bracket: ( + - keyword: TIMESTAMP + - parameter_assigner: => + - expression: + - cast_expression: + - quoted_literal: '''2024-06-05 17:50:00''' + - casting_operator: '::' + - data_type: + - data_type_identifier: TIMESTAMP_LTZ + - end_bracket: ) + - alias_expression: + - naked_identifier: t + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: h + - dot: . + - naked_identifier: c1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: c1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - from_at_expression: + - keyword: AT + - bracketed: + - start_bracket: ( + - keyword: TIMESTAMP + - parameter_assigner: => + - expression: + - function: + - function_name: + - function_name_identifier: TO_TIMESTAMP + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: DATEADD + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''DAY''' + - comma: ',' + - expression: + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '1' + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: DATEADD + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''MONTH''' + - comma: ',' + - expression: + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '1' + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: DATEADD + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''DAY''' + - comma: ',' + - expression: + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '1' + - comma: ',' + - expression: + - bare_function: CURRENT_DATE + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - from_at_expression: + - keyword: AT + - bracketed: + - start_bracket: ( + - keyword: TIMESTAMP + - parameter_assigner: => + - expression: + - cast_expression: + - quoted_literal: '''Fri, 01 May 2015 16:20:00 -0700''' + - casting_operator: '::' + - data_type: + - data_type_identifier: timestamp_tz + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/begin_end.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/begin_end.sql index 0c6c65292..eb9ab761f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/begin_end.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/begin_end.sql @@ -1,7 +1,11 @@ -begin; +-- NOTE: This is a loop BEGIN, and not a transaction BEGIN, +-- because BEGIN is NOT followed immediately by a ";" +-- See: https://docs.snowflake.com/en/sql-reference/sql/begin +-- See: https://docs.snowflake.com/en/sql-reference/snowflake-scripting/begin +begin select 1; select 2; -begin; +begin select 3; select 4; end; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/begin_end.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/begin_end.yml index 8cae5e3ea..9d37019e1 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/begin_end.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/begin_end.yml @@ -1,45 +1,39 @@ file: -- statement: - - transaction_statement: - - keyword: begin -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: select - - select_clause_element: - - numeric_literal: '1' -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: select - - select_clause_element: - - numeric_literal: '2' -- statement_terminator: ; -- statement: - - transaction_statement: - - keyword: begin -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: select - - select_clause_element: - - numeric_literal: '3' -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: select - - select_clause_element: - - numeric_literal: '4' -- statement_terminator: ; -- statement: - - scripting_block_statement: - - keyword: end -- statement_terminator: ; - statement: - scripting_block_statement: + - keyword: begin + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '2' + - statement_terminator: ; + - statement: + - scripting_block_statement: + - keyword: begin + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '3' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '4' + - statement_terminator: ; + - keyword: end + - statement_terminator: ; - keyword: end - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/cast_datatype_accessor.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/cast_datatype_accessor.sql index 2e6cfecc3..d44ccb932 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/cast_datatype_accessor.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/cast_datatype_accessor.sql @@ -3,3 +3,15 @@ SELECT bar::array[0] AS channel , bar::array[0][1] AS channel3 , raw:foo::array[0]::string AS channel4 FROM my_table; + +SELECT + foo::variant:field::array[0]::string AS name +FROM my_table; + +SELECT DISTINCT + payload::variant::object:name::text AS name, + payload::variant::object AS details, + payload::variant::object:createdAt::timestamp_ntz AS created, + payload::variant::object:updatedAt::timestamp_ntz AS updated, + payload::variant::object:id::number AS id +FROM raw_source_table diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/cast_datatype_accessor.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/cast_datatype_accessor.yml index 1fe5a9992..b17a5689b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/cast_datatype_accessor.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/cast_datatype_accessor.yml @@ -16,7 +16,8 @@ file: - numeric_literal: '0' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: channel - comma: ',' - select_clause_element: @@ -35,7 +36,8 @@ file: - numeric_literal: '2' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: channel2 - comma: ',' - select_clause_element: @@ -55,7 +57,8 @@ file: - numeric_literal: '1' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: channel3 - comma: ',' - select_clause_element: @@ -77,7 +80,8 @@ file: - data_type: - data_type_identifier: string - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: channel4 - from_clause: - keyword: FROM @@ -87,3 +91,156 @@ file: - table_reference: - naked_identifier: my_table - statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - column_reference: + - naked_identifier: foo + - casting_operator: '::' + - data_type: + - data_type_identifier: variant + - semi_structured_expression: + - colon: ':' + - semi_structured_element: field + - casting_operator: '::' + - data_type: + - data_type_identifier: array + - array_accessor: + - start_square_bracket: '[' + - numeric_literal: '0' + - end_square_bracket: ']' + - casting_operator: '::' + - data_type: + - data_type_identifier: string + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: name + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: DISTINCT + - select_clause_element: + - expression: + - cast_expression: + - column_reference: + - naked_identifier: payload + - casting_operator: '::' + - data_type: + - data_type_identifier: variant + - casting_operator: '::' + - data_type: + - data_type_identifier: object + - semi_structured_expression: + - colon: ':' + - semi_structured_element: name + - casting_operator: '::' + - data_type: + - data_type_identifier: text + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: name + - comma: ',' + - select_clause_element: + - expression: + - cast_expression: + - column_reference: + - naked_identifier: payload + - casting_operator: '::' + - data_type: + - data_type_identifier: variant + - casting_operator: '::' + - data_type: + - data_type_identifier: object + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: details + - comma: ',' + - select_clause_element: + - expression: + - cast_expression: + - column_reference: + - naked_identifier: payload + - casting_operator: '::' + - data_type: + - data_type_identifier: variant + - casting_operator: '::' + - data_type: + - data_type_identifier: object + - semi_structured_expression: + - colon: ':' + - semi_structured_element: createdAt + - casting_operator: '::' + - data_type: + - data_type_identifier: timestamp_ntz + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: created + - comma: ',' + - select_clause_element: + - expression: + - cast_expression: + - column_reference: + - naked_identifier: payload + - casting_operator: '::' + - data_type: + - data_type_identifier: variant + - casting_operator: '::' + - data_type: + - data_type_identifier: object + - semi_structured_expression: + - colon: ':' + - semi_structured_element: updatedAt + - casting_operator: '::' + - data_type: + - data_type_identifier: timestamp_ntz + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: updated + - comma: ',' + - select_clause_element: + - expression: + - cast_expression: + - column_reference: + - naked_identifier: payload + - casting_operator: '::' + - data_type: + - data_type_identifier: variant + - casting_operator: '::' + - data_type: + - data_type_identifier: object + - semi_structured_expression: + - colon: ':' + - semi_structured_element: id + - casting_operator: '::' + - data_type: + - data_type_identifier: number + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: raw_source_table diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/changes_clause.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/changes_clause.sql index bc60842e1..5739c3bd3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/changes_clause.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/changes_clause.sql @@ -18,3 +18,8 @@ select * from t1 changes(information => default) before(statement => '8e5d0ca9-005e-44e6-b858-a8f5b37c5726'); + +select * +from st.test + changes (information => append_only) + at (stream => 'ppr.str_test'); diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/changes_clause.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/changes_clause.yml index 6cc377026..c35d6ef4b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/changes_clause.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/changes_clause.yml @@ -150,3 +150,37 @@ file: - quoted_literal: '''8e5d0ca9-005e-44e6-b858-a8f5b37c5726''' - end_bracket: ) - statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: st + - dot: . + - naked_identifier: test + - changes_clause: + - keyword: changes + - bracketed: + - start_bracket: ( + - keyword: information + - parameter_assigner: => + - keyword: append_only + - end_bracket: ) + - keyword: at + - bracketed: + - start_bracket: ( + - keyword: stream + - parameter_assigner: => + - expression: + - quoted_literal: '''ppr.str_test''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/col_position.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/col_position.yml index 113e4d1f4..95ae78ee1 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/col_position.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/col_position.yml @@ -7,14 +7,16 @@ file: - column_reference: - column_index_identifier_segment: $1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: type - comma: ',' - select_clause_element: - column_reference: - column_index_identifier_segment: $2 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: price - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/connect_by.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/connect_by.sql index c4bdff960..8833a06df 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/connect_by.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/connect_by.sql @@ -32,3 +32,26 @@ start with title = 'President' connect by manager_id = prior employee_id order by employee_id; + +select + description, + quantity, + component_id, + parent_component_id, + component_type +from components c +connect by prior c.parent_component_id = c.component_id AND PRIOR c.component_type = c.component_type +order by quantity; + +with tbl as ( + select 'A' as foo, 'B' as bar + union all + select 'B' as foo, 'C' as bar +) + +select + *, + connect_by_root bar as connect_by_root, + sys_connect_by_path(bar, '') as path +from tbl +connect by prior foo = bar and not contains(prior path, bar); diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/connect_by.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/connect_by.yml index 29e4fa097..422c0c846 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/connect_by.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/connect_by.yml @@ -32,13 +32,14 @@ file: - quoted_literal: '''President''' - keyword: connect - keyword: by - - column_reference: - - naked_identifier: manager_id - - comparison_operator: - - raw_comparison_operator: = - - keyword: prior - - column_reference: - - naked_identifier: employee_id + - expression: + - column_reference: + - naked_identifier: manager_id + - comparison_operator: + - raw_comparison_operator: = + - keyword: prior + - column_reference: + - naked_identifier: employee_id - orderby_clause: - keyword: order - keyword: by @@ -93,13 +94,14 @@ file: - quoted_literal: '''President''' - keyword: connect - keyword: by - - column_reference: - - naked_identifier: manager_id - - comparison_operator: - - raw_comparison_operator: = - - keyword: prior - - column_reference: - - naked_identifier: employee_id + - expression: + - column_reference: + - naked_identifier: manager_id + - comparison_operator: + - raw_comparison_operator: = + - keyword: prior + - column_reference: + - naked_identifier: employee_id - orderby_clause: - keyword: order - keyword: by @@ -141,7 +143,8 @@ file: - quoted_literal: ''' -> ''' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: path - from_clause: - keyword: from @@ -161,13 +164,14 @@ file: - numeric_literal: '1' - keyword: connect - keyword: by - - column_reference: - - naked_identifier: parent_component_id - - comparison_operator: - - raw_comparison_operator: = - - keyword: prior - - column_reference: - - naked_identifier: component_id + - expression: + - column_reference: + - naked_identifier: parent_component_id + - comparison_operator: + - raw_comparison_operator: = + - keyword: prior + - column_reference: + - naked_identifier: component_id - orderby_clause: - keyword: order - keyword: by @@ -195,7 +199,8 @@ file: - column_reference: - naked_identifier: title - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: root_title - from_clause: - keyword: from @@ -215,16 +220,198 @@ file: - quoted_literal: '''President''' - keyword: connect - keyword: by - - column_reference: - - naked_identifier: manager_id - - comparison_operator: - - raw_comparison_operator: = - - keyword: prior - - column_reference: - - naked_identifier: employee_id + - expression: + - column_reference: + - naked_identifier: manager_id + - comparison_operator: + - raw_comparison_operator: = + - keyword: prior + - column_reference: + - naked_identifier: employee_id - orderby_clause: - keyword: order - keyword: by - column_reference: - naked_identifier: employee_id - statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: description + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: quantity + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: component_id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: parent_component_id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: component_type + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: components + - alias_expression: + - naked_identifier: c + - connectby_clause: + - keyword: connect + - keyword: by + - expression: + - keyword: prior + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: parent_component_id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: component_id + - binary_operator: AND + - keyword: PRIOR + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: component_type + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: component_type + - orderby_clause: + - keyword: order + - keyword: by + - column_reference: + - naked_identifier: quantity +- statement_terminator: ; +- statement: + - with_compound_statement: + - keyword: with + - common_table_expression: + - naked_identifier: tbl + - keyword: as + - bracketed: + - start_bracket: ( + - set_expression: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - quoted_literal: '''A''' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: foo + - comma: ',' + - select_clause_element: + - quoted_literal: '''B''' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: bar + - set_operator: + - keyword: union + - keyword: all + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - quoted_literal: '''B''' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: foo + - comma: ',' + - select_clause_element: + - quoted_literal: '''C''' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: bar + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - comma: ',' + - select_clause_element: + - keyword: connect_by_root + - column_reference: + - naked_identifier: bar + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: connect_by_root + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sys_connect_by_path + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: bar + - comma: ',' + - expression: + - quoted_literal: '''''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: path + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl + - connectby_clause: + - keyword: connect + - keyword: by + - expression: + - keyword: prior + - column_reference: + - naked_identifier: foo + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: bar + - binary_operator: and + - keyword: not + - function: + - function_name: + - function_name_identifier: contains + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - keyword: prior + - column_reference: + - naked_identifier: path + - comma: ',' + - expression: + - column_reference: + - naked_identifier: bar + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_files_into_location_statement.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_files_into_location_statement.sql new file mode 100644 index 000000000..28579fe96 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_files_into_location_statement.sql @@ -0,0 +1,20 @@ +COPY FILES INTO '@stage/folder' + FROM '@other_stage/folder'; + +COPY FILES INTO '@stage/folder' + FROM '@other_stage/folder' + FILES = ('data.csv', 'data2.csv'); + +COPY FILES INTO '@stage/folder' + FROM '@other_stage/folder' + PATTERN = '.*[.]parquet.*'; + +COPY FILES INTO '@stage/folder' + FROM '@other_stage/folder' + DETAILED_OUTPUT = TRUE; + +COPY FILES INTO '@stage/folder' + FROM '@other_stage/folder' + FILES = ('data.csv', 'data2.csv') + PATTERN = '.*[.]parquet.*' + DETAILED_OUTPUT = TRUE; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_files_into_location_statement.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_files_into_location_statement.yml new file mode 100644 index 000000000..3c029e35d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_files_into_location_statement.yml @@ -0,0 +1,90 @@ +file: +- statement: + - copy_files_into_location_statement: + - keyword: COPY + - keyword: FILES + - keyword: INTO + - storage_location: + - stage_path: '''@stage/folder''' + - keyword: FROM + - storage_location: + - stage_path: '''@other_stage/folder''' +- statement_terminator: ; +- statement: + - copy_files_into_location_statement: + - keyword: COPY + - keyword: FILES + - keyword: INTO + - storage_location: + - stage_path: '''@stage/folder''' + - keyword: FROM + - storage_location: + - stage_path: '''@other_stage/folder''' + - keyword: FILES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''data.csv''' + - comma: ',' + - quoted_literal: '''data2.csv''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_files_into_location_statement: + - keyword: COPY + - keyword: FILES + - keyword: INTO + - storage_location: + - stage_path: '''@stage/folder''' + - keyword: FROM + - storage_location: + - stage_path: '''@other_stage/folder''' + - keyword: PATTERN + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''.*[.]parquet.*''' +- statement_terminator: ; +- statement: + - copy_files_into_location_statement: + - keyword: COPY + - keyword: FILES + - keyword: INTO + - storage_location: + - stage_path: '''@stage/folder''' + - keyword: FROM + - storage_location: + - stage_path: '''@other_stage/folder''' + - keyword: DETAILED_OUTPUT + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - copy_files_into_location_statement: + - keyword: COPY + - keyword: FILES + - keyword: INTO + - storage_location: + - stage_path: '''@stage/folder''' + - keyword: FROM + - storage_location: + - stage_path: '''@other_stage/folder''' + - keyword: FILES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''data.csv''' + - comma: ',' + - quoted_literal: '''data2.csv''' + - end_bracket: ) + - keyword: PATTERN + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''.*[.]parquet.*''' + - keyword: DETAILED_OUTPUT + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location.sql index 97e1bf8a7..30ec7f189 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location.sql @@ -4,4 +4,32 @@ COPY INTO '@public.dir/airflow-pipelines/' SINGLE = FALSE MAX_FILE_SIZE = 1000000000 INCLUDE_QUERY_ID = TRUE - HEADER = TRUE + HEADER = TRUE; + +-- mixed order between `copyOptions` and other copy configurations +COPY INTO 's3://geotags.csv.gz' +FROM +( + SELECT DISTINCT + ID, + CAST(Z.VALUE AS INTEGER) AS LISTING_ADDRESS_POSTALCODE + FROM + ANALYTICS_PROD.SERVICE.GEO_DATA_LAYER_FLATTEN, + LATERAL FLATTEN(ZIPS) AS Z + WHERE + TYPE IN ('canton', 'region', 'zip') + AND PARENTPATHS LIKE '%geo-country-switzerland%' +) STORAGE_INTEGRATION = SI_S3_DS_ASSETS FILE_FORMAT = ( + TYPE = CSV NULL_IF = () EMPTY_FIELD_AS_NULL = FALSE COMPRESSION = GZIP +) SINGLE = TRUE OVERWRITE = TRUE HEADER = TRUE MAX_FILE_SIZE = 5368709120; + +-- with a CTE in the query segment +COPY INTO @my_stage/path/to/file.json.gz +FROM +( + WITH my_cte AS ( + SELECT 1 + ) + SELECT * + FROM my_cte +); diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location.yml index ab64913c1..042b9ab16 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location.yml @@ -22,20 +22,195 @@ file: - raw_comparison_operator: = - file_type: PARQUET - end_bracket: ) - - copy_options: - - keyword: SINGLE - - comparison_operator: - - raw_comparison_operator: = - - boolean_literal: 'FALSE' - - keyword: MAX_FILE_SIZE - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1000000000' - - keyword: INCLUDE_QUERY_ID + - keyword: SINGLE + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' + - keyword: MAX_FILE_SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1000000000' + - keyword: INCLUDE_QUERY_ID + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - keyword: HEADER + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - copy_into_location_statement: + - keyword: COPY + - keyword: INTO + - storage_location: + - bucket_path: '''s3://geotags.csv.gz''' + - keyword: FROM + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: DISTINCT + - select_clause_element: + - column_reference: + - naked_identifier: ID + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: Z + - dot: . + - naked_identifier: VALUE + - keyword: AS + - data_type: + - data_type_identifier: INTEGER + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: LISTING_ADDRESS_POSTALCODE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: ANALYTICS_PROD + - dot: . + - naked_identifier: SERVICE + - dot: . + - naked_identifier: GEO_DATA_LAYER_FLATTEN + - comma: ',' + - from_expression: + - from_expression_element: + - keyword: LATERAL + - table_expression: + - function: + - function_name: + - function_name_identifier: FLATTEN + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: ZIPS + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Z + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: TYPE + - keyword: IN + - bracketed: + - start_bracket: ( + - quoted_literal: '''canton''' + - comma: ',' + - quoted_literal: '''region''' + - comma: ',' + - quoted_literal: '''zip''' + - end_bracket: ) + - binary_operator: AND + - column_reference: + - naked_identifier: PARENTPATHS + - keyword: LIKE + - quoted_literal: '''%geo-country-switzerland%''' + - end_bracket: ) + - stage_parameters: + - keyword: STORAGE_INTEGRATION - comparison_operator: - raw_comparison_operator: = - - boolean_literal: 'TRUE' + - object_reference: + - naked_identifier: SI_S3_DS_ASSETS + - keyword: FILE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - file_format_segment: + - bracketed: + - start_bracket: ( + - csv_file_format_type_parameters: + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - file_type: CSV + - keyword: NULL_IF + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: EMPTY_FIELD_AS_NULL + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' + - keyword: COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - compression_type: GZIP + - end_bracket: ) + - keyword: SINGLE + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - keyword: OVERWRITE + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' - keyword: HEADER - comparison_operator: - raw_comparison_operator: = - boolean_literal: 'TRUE' + - keyword: MAX_FILE_SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '5368709120' +- statement_terminator: ; +- statement: + - copy_into_location_statement: + - keyword: COPY + - keyword: INTO + - storage_location: + - stage_path: '@my_stage/path/to/file.json.gz' + - keyword: FROM + - bracketed: + - start_bracket: ( + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: my_cte + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_cte + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_Amazon_SC3.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_Amazon_SC3.yml index 76c2cfee9..22f8cbec3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_Amazon_SC3.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_Amazon_SC3.yml @@ -8,7 +8,7 @@ file: - keyword: from - table_reference: - naked_identifier: mytable - - s3_external_stage_parameters: + - stage_parameters: - keyword: credentials - comparison_operator: - raw_comparison_operator: = diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_Azure.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_Azure.yml index a390a7908..2702f683c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_Azure.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_Azure.yml @@ -8,7 +8,7 @@ file: - keyword: from - table_reference: - naked_identifier: mytable - - azure_blob_storage_external_stage_parameters: + - stage_parameters: - keyword: credentials - comparison_operator: - raw_comparison_operator: = diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_GoogleCloud.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_GoogleCloud.yml index a390a7908..2702f683c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_GoogleCloud.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_GoogleCloud.yml @@ -8,7 +8,7 @@ file: - keyword: from - table_reference: - naked_identifier: mytable - - azure_blob_storage_external_stage_parameters: + - stage_parameters: - keyword: credentials - comparison_operator: - raw_comparison_operator: = diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_partitionby.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_partitionby.yml index 7b834d069..1a3c1a78c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_partitionby.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_location_partitionby.yml @@ -71,11 +71,10 @@ file: - raw_comparison_operator: = - file_type: parquet - end_bracket: ) - - copy_options: - - keyword: max_file_size - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '32000000' + - keyword: max_file_size + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '32000000' - keyword: header - comparison_operator: - raw_comparison_operator: = diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_table.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_table.sql index e3b82737e..77671b0ab 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_table.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_table.sql @@ -70,3 +70,24 @@ copy into mytable1 (column1) copy into mytable1 (column1) from @public.stage/subfolder/ file_format = (TYPE = JSON); + +COPY INTO table1 FROM @stage1 +MATCH_BY_COLUMN_NAME = CASE_INSENSITIVE +INCLUDE_METADATA = ( + ingestdate = METADATA$START_SCAN_TIME, filename = METADATA$FILENAME); + +COPY INTO table1 FROM @stage1 +MATCH_BY_COLUMN_NAME = CASE_INSENSITIVE +FILE_FORMAT = (TYPE = JSON) +LOAD_UNCERTAIN_FILES = TRUE +INCLUDE_METADATA = ( + ingestdate = METADATA$START_SCAN_TIME, filename = METADATA$FILENAME); + +COPY INTO test.transactions_all +FROM @rawdata.STITCH_STAGE_NETSUITE/transactions/ +FILE_FORMAT = rawdata.json_format +MATCH_BY_COLUMN_NAME = 'case_insensitive'; + +copy into mytable1 + from 's3://bucket/source' + file_format = (type=csv MULTI_LINE=FALSE); diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_table.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_table.yml index 4a48e7e87..ddafab014 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/copy_into_table.yml @@ -183,11 +183,10 @@ file: - keyword: into - table_reference: - naked_identifier: mytable - - copy_options: - - keyword: purge - - comparison_operator: - - raw_comparison_operator: = - - boolean_literal: 'true' + - keyword: purge + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'true' - statement_terminator: ; - statement: - copy_into_table_statement: @@ -389,3 +388,127 @@ file: - file_type: JSON - end_bracket: ) - statement_terminator: ; +- statement: + - copy_into_table_statement: + - keyword: COPY + - keyword: INTO + - table_reference: + - naked_identifier: table1 + - keyword: FROM + - storage_location: + - stage_path: '@stage1' + - keyword: MATCH_BY_COLUMN_NAME + - comparison_operator: + - raw_comparison_operator: = + - keyword: CASE_INSENSITIVE + - keyword: INCLUDE_METADATA + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - naked_identifier: ingestdate + - comparison_operator: + - raw_comparison_operator: = + - keyword: METADATA$START_SCAN_TIME + - comma: ',' + - naked_identifier: filename + - comparison_operator: + - raw_comparison_operator: = + - keyword: METADATA$FILENAME + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_into_table_statement: + - keyword: COPY + - keyword: INTO + - table_reference: + - naked_identifier: table1 + - keyword: FROM + - storage_location: + - stage_path: '@stage1' + - keyword: MATCH_BY_COLUMN_NAME + - comparison_operator: + - raw_comparison_operator: = + - keyword: CASE_INSENSITIVE + - keyword: FILE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - file_format_segment: + - bracketed: + - start_bracket: ( + - json_file_format_type_parameters: + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - file_type: JSON + - end_bracket: ) + - keyword: LOAD_UNCERTAIN_FILES + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - keyword: INCLUDE_METADATA + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - naked_identifier: ingestdate + - comparison_operator: + - raw_comparison_operator: = + - keyword: METADATA$START_SCAN_TIME + - comma: ',' + - naked_identifier: filename + - comparison_operator: + - raw_comparison_operator: = + - keyword: METADATA$FILENAME + - end_bracket: ) +- statement_terminator: ; +- statement: + - copy_into_table_statement: + - keyword: COPY + - keyword: INTO + - table_reference: + - naked_identifier: test + - dot: . + - naked_identifier: transactions_all + - keyword: FROM + - storage_location: + - stage_path: '@rawdata.STITCH_STAGE_NETSUITE/transactions/' + - keyword: FILE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - file_format_segment: + - object_reference: + - naked_identifier: rawdata + - dot: . + - naked_identifier: json_format + - keyword: MATCH_BY_COLUMN_NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''case_insensitive''' +- statement_terminator: ; +- statement: + - copy_into_table_statement: + - keyword: copy + - keyword: into + - table_reference: + - naked_identifier: mytable1 + - keyword: from + - storage_location: + - bucket_path: '''s3://bucket/source''' + - keyword: file_format + - comparison_operator: + - raw_comparison_operator: = + - file_format_segment: + - bracketed: + - start_bracket: ( + - csv_file_format_type_parameters: + - keyword: type + - comparison_operator: + - raw_comparison_operator: = + - file_type: csv + - keyword: MULTI_LINE + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_api_integration.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_api_integration.sql new file mode 100644 index 000000000..8cb6b100b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_api_integration.sql @@ -0,0 +1,67 @@ +CREATE OR REPLACE API INTEGRATION aws + API_PROVIDER = aws_api_gateway + API_AWS_ROLE_ARN = 'arn:aws:iam::123456789012:role/my_cloud_account_role' + API_ALLOWED_PREFIXES = ('https://xyz.execute-api.us-west-2.amazonaws.com/production') + ENABLED = TRUE; + +CREATE OR REPLACE API INTEGRATION aws2 + API_PROVIDER = aws_private_api_gateway + API_AWS_ROLE_ARN = 'arn:aws:iam::123456789012:role/my_cloud_account_role' + API_ALLOWED_PREFIXES = ('https://xyz.execute-api.us-west-2.amazonaws.com/production') + API_KEY='123' + ENABLED = FALSE + COMMENT='blabla'; + +CREATE OR REPLACE API INTEGRATION aws3 + API_PROVIDER = aws_gov_api_gateway + API_AWS_ROLE_ARN = 'arn:aws:iam::123456789012:role/my_cloud_account_role' + API_ALLOWED_PREFIXES = ('https://xyz.execute-api.us-west-2.amazonaws.com/production') + ENABLED = TRUE; + +CREATE OR REPLACE API INTEGRATION aws4 +API_PROVIDER = aws_gov_private_api_gateway +API_AWS_ROLE_ARN = 'arn:aws:iam::123456789012:role/my_cloud_account_role' +API_ALLOWED_PREFIXES = ('https://xyz.execute-api.us-west-2.amazonaws.com/production') +ENABLED = TRUE; + +CREATE OR REPLACE API INTEGRATION azure +API_PROVIDER = azure_api_management +AZURE_TENANT_ID = '' +AZURE_AD_APPLICATION_ID = '' +API_KEY = '' +API_ALLOWED_PREFIXES = ( 'go' ) +API_BLOCKED_PREFIXES = ( 'do_not_go' ) +ENABLED = TRUE; + +CREATE OR REPLACE API INTEGRATION google +API_PROVIDER = google_api_gateway +GOOGLE_AUDIENCE = '' +API_ALLOWED_PREFIXES = ( 'go' ) +ENABLED = TRUE; + +CREATE OR REPLACE API INTEGRATION git +API_PROVIDER = git_https_api +GOOGLE_AUDIENCE = '' +API_ALLOWED_PREFIXES = ( 'go' ) +ALLOWED_AUTHENTICATION_SECRETS = ( 'pedo mellon a minno' ) +; + +CREATE OR REPLACE API INTEGRATION git2 +API_PROVIDER = git_https_api +GOOGLE_AUDIENCE = '' +ALLOWED_AUTHENTICATION_SECRETS = ( all ) +; + + +CREATE OR REPLACE API INTEGRATION git3 +API_PROVIDER = git_https_api +GOOGLE_AUDIENCE = '' +API_ALLOWED_PREFIXES = ( 'go' ) +ALLOWED_AUTHENTICATION_SECRETS = ( none ) +; + +CREATE OR REPLACE API INTEGRATION git2 +API_PROVIDER = git_https_api +GOOGLE_AUDIENCE = '' +ALLOWED_AUTHENTICATION_SECRETS = ('pedo','mellon a','minno') +; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_api_integration.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_api_integration.yml new file mode 100644 index 000000000..bf9666d43 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_api_integration.yml @@ -0,0 +1,317 @@ +file: +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: API + - keyword: INTEGRATION + - object_reference: + - naked_identifier: aws + - keyword: API_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - keyword: aws_api_gateway + - keyword: API_AWS_ROLE_ARN + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''arn:aws:iam::123456789012:role/my_cloud_account_role''' + - keyword: API_ALLOWED_PREFIXES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''https://xyz.execute-api.us-west-2.amazonaws.com/production''' + - end_bracket: ) + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: API + - keyword: INTEGRATION + - object_reference: + - naked_identifier: aws2 + - keyword: API_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - keyword: aws_private_api_gateway + - keyword: API_AWS_ROLE_ARN + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''arn:aws:iam::123456789012:role/my_cloud_account_role''' + - keyword: API_ALLOWED_PREFIXES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''https://xyz.execute-api.us-west-2.amazonaws.com/production''' + - end_bracket: ) + - keyword: API_KEY + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''123''' + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''blabla''' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: API + - keyword: INTEGRATION + - object_reference: + - naked_identifier: aws3 + - keyword: API_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - keyword: aws_gov_api_gateway + - keyword: API_AWS_ROLE_ARN + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''arn:aws:iam::123456789012:role/my_cloud_account_role''' + - keyword: API_ALLOWED_PREFIXES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''https://xyz.execute-api.us-west-2.amazonaws.com/production''' + - end_bracket: ) + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: API + - keyword: INTEGRATION + - object_reference: + - naked_identifier: aws4 + - keyword: API_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - keyword: aws_gov_private_api_gateway + - keyword: API_AWS_ROLE_ARN + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''arn:aws:iam::123456789012:role/my_cloud_account_role''' + - keyword: API_ALLOWED_PREFIXES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''https://xyz.execute-api.us-west-2.amazonaws.com/production''' + - end_bracket: ) + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: API + - keyword: INTEGRATION + - object_reference: + - naked_identifier: azure + - keyword: API_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - keyword: azure_api_management + - keyword: AZURE_TENANT_ID + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: AZURE_AD_APPLICATION_ID + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: API_KEY + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: API_ALLOWED_PREFIXES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''go''' + - end_bracket: ) + - keyword: API_BLOCKED_PREFIXES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''do_not_go''' + - end_bracket: ) + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: API + - keyword: INTEGRATION + - object_reference: + - naked_identifier: google + - keyword: API_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - keyword: google_api_gateway + - keyword: GOOGLE_AUDIENCE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: API_ALLOWED_PREFIXES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''go''' + - end_bracket: ) + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: API + - keyword: INTEGRATION + - object_reference: + - naked_identifier: git + - keyword: API_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - keyword: git_https_api + - keyword: GOOGLE_AUDIENCE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: API_ALLOWED_PREFIXES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''go''' + - end_bracket: ) + - keyword: ALLOWED_AUTHENTICATION_SECRETS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''pedo mellon a minno''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: API + - keyword: INTEGRATION + - object_reference: + - naked_identifier: git2 + - keyword: API_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - keyword: git_https_api + - keyword: GOOGLE_AUDIENCE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: ALLOWED_AUTHENTICATION_SECRETS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: all + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: API + - keyword: INTEGRATION + - object_reference: + - naked_identifier: git3 + - keyword: API_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - keyword: git_https_api + - keyword: GOOGLE_AUDIENCE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: API_ALLOWED_PREFIXES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''go''' + - end_bracket: ) + - keyword: ALLOWED_AUTHENTICATION_SECRETS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: none + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: API + - keyword: INTEGRATION + - object_reference: + - naked_identifier: git2 + - keyword: API_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - keyword: git_https_api + - keyword: GOOGLE_AUDIENCE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: ALLOWED_AUTHENTICATION_SECRETS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''pedo''' + - comma: ',' + - quoted_literal: '''mellon a''' + - comma: ',' + - quoted_literal: '''minno''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_authentication_policy.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_authentication_policy.sql new file mode 100644 index 000000000..e05cda7a6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_authentication_policy.sql @@ -0,0 +1,21 @@ +CREATE AUTHENTICATION POLICY my_policy; + +CREATE AUTHENTICATION POLICY IF NOT EXISTS my_authentication_policy + AUTHENTICATION_METHODS = ( 'MY METHOD' ) + CLIENT_TYPES = ( 'MY CLIENT' ) + COMMENT = 'My Comment' ; + +CREATE AUTHENTICATION POLICY IF NOT EXISTS my_authentication_policy + AUTHENTICATION_METHODS = ( 'METHOD1', 'METHOD2', 'METHOD3' ) + CLIENT_TYPES = ( 'CLIENT1', 'CLIENT2', 'CLIENT3' ) + COMMENT = 'My Comment' ; + +CREATE AUTHENTICATION POLICY my_policy + MFA_AUTHENTICATION_METHODS = ('METHOD1') + MFA_ENROLLMENT = REQUIRED + SECURITY_INTEGRATIONS = ('INTEGRATION1'); + +CREATE OR REPLACE AUTHENTICATION POLICY my_policy + MFA_AUTHENTICATION_METHODS = ( 'METHOD1', 'METHOD2', 'METHOD3' ) + MFA_ENROLLMENT = REQUIRED + SECURITY_INTEGRATIONS = ('INTEGRATION1', 'INTEGRATION2', 'INTEGRATION3'); diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_authentication_policy.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_authentication_policy.yml new file mode 100644 index 000000000..a6f54febd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_authentication_policy.yml @@ -0,0 +1,139 @@ +file: +- statement: + - create_authentication_policy_segment: + - keyword: CREATE + - keyword: AUTHENTICATION + - keyword: POLICY + - table_reference: + - naked_identifier: my_policy +- statement_terminator: ; +- statement: + - create_authentication_policy_segment: + - keyword: CREATE + - keyword: AUTHENTICATION + - keyword: POLICY + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: my_authentication_policy + - keyword: AUTHENTICATION_METHODS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''MY METHOD''' + - end_bracket: ) + - keyword: CLIENT_TYPES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''MY CLIENT''' + - end_bracket: ) + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''My Comment''' +- statement_terminator: ; +- statement: + - create_authentication_policy_segment: + - keyword: CREATE + - keyword: AUTHENTICATION + - keyword: POLICY + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: my_authentication_policy + - keyword: AUTHENTICATION_METHODS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''METHOD1''' + - comma: ',' + - quoted_literal: '''METHOD2''' + - comma: ',' + - quoted_literal: '''METHOD3''' + - end_bracket: ) + - keyword: CLIENT_TYPES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''CLIENT1''' + - comma: ',' + - quoted_literal: '''CLIENT2''' + - comma: ',' + - quoted_literal: '''CLIENT3''' + - end_bracket: ) + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''My Comment''' +- statement_terminator: ; +- statement: + - create_authentication_policy_segment: + - keyword: CREATE + - keyword: AUTHENTICATION + - keyword: POLICY + - table_reference: + - naked_identifier: my_policy + - keyword: MFA_AUTHENTICATION_METHODS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''METHOD1''' + - end_bracket: ) + - keyword: MFA_ENROLLMENT + - comparison_operator: + - raw_comparison_operator: = + - keyword: REQUIRED + - keyword: SECURITY_INTEGRATIONS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''INTEGRATION1''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_authentication_policy_segment: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: AUTHENTICATION + - keyword: POLICY + - table_reference: + - naked_identifier: my_policy + - keyword: MFA_AUTHENTICATION_METHODS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''METHOD1''' + - comma: ',' + - quoted_literal: '''METHOD2''' + - comma: ',' + - quoted_literal: '''METHOD3''' + - end_bracket: ) + - keyword: MFA_ENROLLMENT + - comparison_operator: + - raw_comparison_operator: = + - keyword: REQUIRED + - keyword: SECURITY_INTEGRATIONS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''INTEGRATION1''' + - comma: ',' + - quoted_literal: '''INTEGRATION2''' + - comma: ',' + - quoted_literal: '''INTEGRATION3''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_catalog_integration.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_catalog_integration.sql new file mode 100644 index 000000000..981e865f5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_catalog_integration.sql @@ -0,0 +1,123 @@ +CREATE CATALOG INTEGRATION glue_int + CATALOG_SOURCE = GLUE + TABLE_FORMAT = ICEBERG + GLUE_AWS_ROLE_ARN = 'arn' + GLUE_CATALOG_ID = 'catalog_id' + GLUE_REGION = 'region.us.east' + CATALOG_NAMESPACE = 'namespace' + ENABLED = true + REFRESH_INTERVAL_SECONDS = 10 + COMMENT = 'comment'; + + +CREATE OR REPLACE CATALOG INTEGRATION IF NOT EXISTS glue_int_2 + CATALOG_SOURCE = GLUE + TABLE_FORMAT = ICEBERG + GLUE_AWS_ROLE_ARN = 'arn' + GLUE_CATALOG_ID = 'catalog_id' + ENABLED = false; + + + +CREATE CATALOG INTEGRATION object_storage_int_iceberg + CATALOG_SOURCE = OBJECT_STORE + TABLE_FORMAT = ICEBERG + ENABLED = TRUE + REFRESH_INTERVAL_SECONDS = 10 + COMMENT = ''; + +CREATE CATALOG INTEGRATION object_storage_int_iceberg + CATALOG_SOURCE = OBJECT_STORE + TABLE_FORMAT = DELTA + ENABLED = FALSE; + + + +CREATE OR REPLACE CATALOG INTEGRATION snow_open_catalog_int + CATALOG_SOURCE = POLARIS + TABLE_FORMAT = ICEBERG + CATALOG_NAMESPACE = 'my_catalog_namespace' + REST_CONFIG = ( + CATALOG_URI = 'https://my_org_name-my_snowflake_open_catalog_account_name.snowflakecomputing.com/polaris/api/catalog' + CATALOG_NAME = 'my_catalog_name' + ) + REST_AUTHENTICATION = ( + TYPE = OAUTH + OAUTH_CLIENT_ID = 'my_client_id' + OAUTH_CLIENT_SECRET = 'my_client_secret' + OAUTH_ALLOWED_SCOPES = ('PRINCIPAL_ROLE:ALL') + ) + ENABLED = TRUE; + + +CREATE OR REPLACE CATALOG INTEGRATION snow_open_catalog_2_int + CATALOG_SOURCE = POLARIS + TABLE_FORMAT = ICEBERG + CATALOG_NAMESPACE = 'my_catalog_namespace' + REST_CONFIG = ( + CATALOG_URI = 'https://my_org_name-my_snowflake_open_catalog_account_name.snowflakecomputing.com/polaris/api/catalog' + CATALOG_NAME = 'my_catalog_name' + ) + REST_AUTHENTICATION = ( + TYPE = OAUTH + OAUTH_CLIENT_ID = 'my_client_id' + OAUTH_CLIENT_SECRET = 'my_client_secret' + OAUTH_ALLOWED_SCOPES = ('PRINCIPAL_ROLE:ALL', 'OTHER_ROLE:ALL') + ) + ENABLED = TRUE; + + + +CREATE CATALOG INTEGRATION apache_iceberg_rest_tabular_int + CATALOG_SOURCE = ICEBERG_REST + TABLE_FORMAT = ICEBERG + CATALOG_NAMESPACE = '' + REST_CONFIG = ( + CATALOG_URI = 'https://api.tabular.io/ws' + CATALOG_NAME = '' + ) + REST_AUTHENTICATION = ( + TYPE = OAUTH + OAUTH_TOKEN_URI = 'https://api.tabular.io/ws/v1/oauth/tokens' + OAUTH_CLIENT_ID = '' + OAUTH_CLIENT_SECRET = '' + OAUTH_ALLOWED_SCOPES = ('catalog') + ) + ENABLED = TRUE + REFRESH_INTERVAL_SECONDS = 10 + COMMENT = ''; + +CREATE CATALOG INTEGRATION apache_iceberg_rest_sigv4_int + CATALOG_SOURCE = ICEBERG_REST + TABLE_FORMAT = ICEBERG + CATALOG_NAMESPACE = '' + REST_CONFIG = ( + CATALOG_URI = 'https://glue.us-west-2.amazonaws.com/iceberg' + CATALOG_API_TYPE = AWS_GLUE + CATALOG_NAME = '123456789012' + ) + REST_AUTHENTICATION = ( + TYPE = SIGV4 + SIGV4_IAM_ROLE = 'arn:aws:iam::123456789012:role/my-role' + SIGV4_SIGNING_REGION = 'us-west-2' + ) + ENABLED = TRUE + REFRESH_INTERVAL_SECONDS = 10 + COMMENT = ''; + +CREATE CATALOG INTEGRATION apache_iceberg_rest_bearer_int + CATALOG_SOURCE = ICEBERG_REST + TABLE_FORMAT = ICEBERG + CATALOG_NAMESPACE = '' + REST_CONFIG = ( + CATALOG_URI = 'https://glue.us-west-2.amazonaws.com/iceberg' + CATALOG_API_TYPE = AWS_GLUE + CATALOG_NAME = '123456789012' + ) + REST_AUTHENTICATION = ( + TYPE = BEARER + BEARER_TOKEN = 'bearer-token' + ) + ENABLED = TRUE + REFRESH_INTERVAL_SECONDS = 10 + COMMENT = ''; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_catalog_integration.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_catalog_integration.yml new file mode 100644 index 000000000..7effc377f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_catalog_integration.yml @@ -0,0 +1,470 @@ +file: +- statement: + - create_statement: + - keyword: CREATE + - keyword: CATALOG + - keyword: INTEGRATION + - object_reference: + - naked_identifier: glue_int + - keyword: CATALOG_SOURCE + - comparison_operator: + - raw_comparison_operator: = + - keyword: GLUE + - keyword: TABLE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - keyword: ICEBERG + - keyword: GLUE_AWS_ROLE_ARN + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''arn''' + - keyword: GLUE_CATALOG_ID + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''catalog_id''' + - keyword: GLUE_REGION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''region.us.east''' + - keyword: CATALOG_NAMESPACE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''namespace''' + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'true' + - keyword: REFRESH_INTERVAL_SECONDS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''comment''' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: CATALOG + - keyword: INTEGRATION + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - object_reference: + - naked_identifier: glue_int_2 + - keyword: CATALOG_SOURCE + - comparison_operator: + - raw_comparison_operator: = + - keyword: GLUE + - keyword: TABLE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - keyword: ICEBERG + - keyword: GLUE_AWS_ROLE_ARN + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''arn''' + - keyword: GLUE_CATALOG_ID + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''catalog_id''' + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'false' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: CATALOG + - keyword: INTEGRATION + - object_reference: + - naked_identifier: object_storage_int_iceberg + - keyword: CATALOG_SOURCE + - comparison_operator: + - raw_comparison_operator: = + - keyword: OBJECT_STORE + - keyword: TABLE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - keyword: ICEBERG + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - keyword: REFRESH_INTERVAL_SECONDS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: CATALOG + - keyword: INTEGRATION + - object_reference: + - naked_identifier: object_storage_int_iceberg + - keyword: CATALOG_SOURCE + - comparison_operator: + - raw_comparison_operator: = + - keyword: OBJECT_STORE + - keyword: TABLE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - keyword: DELTA + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: CATALOG + - keyword: INTEGRATION + - object_reference: + - naked_identifier: snow_open_catalog_int + - keyword: CATALOG_SOURCE + - comparison_operator: + - raw_comparison_operator: = + - keyword: POLARIS + - keyword: TABLE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - keyword: ICEBERG + - keyword: CATALOG_NAMESPACE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my_catalog_namespace''' + - keyword: REST_CONFIG + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: CATALOG_URI + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''https://my_org_name-my_snowflake_open_catalog_account_name.snowflakecomputing.com/polaris/api/catalog''' + - keyword: CATALOG_NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my_catalog_name''' + - end_bracket: ) + - keyword: REST_AUTHENTICATION + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: OAUTH + - keyword: OAUTH_CLIENT_ID + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my_client_id''' + - keyword: OAUTH_CLIENT_SECRET + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my_client_secret''' + - keyword: OAUTH_ALLOWED_SCOPES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''PRINCIPAL_ROLE:ALL''' + - end_bracket: ) + - end_bracket: ) + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: CATALOG + - keyword: INTEGRATION + - object_reference: + - naked_identifier: snow_open_catalog_2_int + - keyword: CATALOG_SOURCE + - comparison_operator: + - raw_comparison_operator: = + - keyword: POLARIS + - keyword: TABLE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - keyword: ICEBERG + - keyword: CATALOG_NAMESPACE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my_catalog_namespace''' + - keyword: REST_CONFIG + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: CATALOG_URI + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''https://my_org_name-my_snowflake_open_catalog_account_name.snowflakecomputing.com/polaris/api/catalog''' + - keyword: CATALOG_NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my_catalog_name''' + - end_bracket: ) + - keyword: REST_AUTHENTICATION + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: OAUTH + - keyword: OAUTH_CLIENT_ID + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my_client_id''' + - keyword: OAUTH_CLIENT_SECRET + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my_client_secret''' + - keyword: OAUTH_ALLOWED_SCOPES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''PRINCIPAL_ROLE:ALL''' + - comma: ',' + - quoted_literal: '''OTHER_ROLE:ALL''' + - end_bracket: ) + - end_bracket: ) + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: CATALOG + - keyword: INTEGRATION + - object_reference: + - naked_identifier: apache_iceberg_rest_tabular_int + - keyword: CATALOG_SOURCE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ICEBERG_REST + - keyword: TABLE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - keyword: ICEBERG + - keyword: CATALOG_NAMESPACE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: REST_CONFIG + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: CATALOG_URI + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''https://api.tabular.io/ws''' + - keyword: CATALOG_NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - end_bracket: ) + - keyword: REST_AUTHENTICATION + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: OAUTH + - keyword: OAUTH_TOKEN_URI + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''https://api.tabular.io/ws/v1/oauth/tokens''' + - keyword: OAUTH_CLIENT_ID + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: OAUTH_CLIENT_SECRET + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: OAUTH_ALLOWED_SCOPES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''catalog''' + - end_bracket: ) + - end_bracket: ) + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - keyword: REFRESH_INTERVAL_SECONDS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: CATALOG + - keyword: INTEGRATION + - object_reference: + - naked_identifier: apache_iceberg_rest_sigv4_int + - keyword: CATALOG_SOURCE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ICEBERG_REST + - keyword: TABLE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - keyword: ICEBERG + - keyword: CATALOG_NAMESPACE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: REST_CONFIG + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: CATALOG_URI + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''https://glue.us-west-2.amazonaws.com/iceberg''' + - keyword: CATALOG_API_TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: AWS_GLUE + - keyword: CATALOG_NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''123456789012''' + - end_bracket: ) + - keyword: REST_AUTHENTICATION + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: SIGV4 + - keyword: SIGV4_IAM_ROLE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''arn:aws:iam::123456789012:role/my-role''' + - keyword: SIGV4_SIGNING_REGION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''us-west-2''' + - end_bracket: ) + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - keyword: REFRESH_INTERVAL_SECONDS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: CATALOG + - keyword: INTEGRATION + - object_reference: + - naked_identifier: apache_iceberg_rest_bearer_int + - keyword: CATALOG_SOURCE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ICEBERG_REST + - keyword: TABLE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - keyword: ICEBERG + - keyword: CATALOG_NAMESPACE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: REST_CONFIG + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: CATALOG_URI + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''https://glue.us-west-2.amazonaws.com/iceberg''' + - keyword: CATALOG_API_TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: AWS_GLUE + - keyword: CATALOG_NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''123456789012''' + - end_bracket: ) + - keyword: REST_AUTHENTICATION + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: BEARER + - keyword: BEARER_TOKEN + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''bearer-token''' + - end_bracket: ) + - keyword: ENABLED + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - keyword: REFRESH_INTERVAL_SECONDS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_cortex_search_service.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_cortex_search_service.sql new file mode 100644 index 000000000..bfaa47ce2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_cortex_search_service.sql @@ -0,0 +1,35 @@ +-- create cortex search service my_service; + +CREATE OR REPLACE CORTEX SEARCH SERVICE mysvc + ON transcript_text + ATTRIBUTES region,agent_id + WAREHOUSE = mywh + TARGET_LAG = '1 hour' + EMBEDDING_MODEL = 'snowflake-arctic-embed-l-v2.0' +AS ( + SELECT + transcript_text, + date, + region, + agent_id + FROM support_db.public.transcripts_etl +); + +create cortex search service my_service +on text +attributes id, type, title +warehouse = my_warehouse +target_lag = '1 days' +as +select text, id, type, title, +from my_db.my_schema.my_table +; + +create or replace cortex search service my_service +on text +warehouse = my_warehouse +target_lag = '1 days' +as +select text, id, type, title, +from my_db.my_schema.my_table +; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_cortex_search_service.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_cortex_search_service.yml new file mode 100644 index 000000000..0ac1b74c3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_cortex_search_service.yml @@ -0,0 +1,182 @@ +file: +- statement: + - create_cortex_search_service_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: CORTEX + - keyword: SEARCH + - keyword: SERVICE + - object_reference: + - naked_identifier: mysvc + - keyword: ON + - column_reference: + - naked_identifier: transcript_text + - keyword: ATTRIBUTES + - column_reference: + - naked_identifier: region + - comma: ',' + - column_reference: + - naked_identifier: agent_id + - keyword: WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: mywh + - keyword: TARGET_LAG + - comparison_operator: + - raw_comparison_operator: = + - dynamic_table_lag_interval_segment: '''1 hour''' + - keyword: EMBEDDING_MODEL + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''snowflake-arctic-embed-l-v2.0''' + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: transcript_text + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: date + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: region + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: agent_id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: support_db + - dot: . + - naked_identifier: public + - dot: . + - naked_identifier: transcripts_etl + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_cortex_search_service_statement: + - keyword: create + - keyword: cortex + - keyword: search + - keyword: service + - object_reference: + - naked_identifier: my_service + - keyword: on + - column_reference: + - naked_identifier: text + - keyword: attributes + - column_reference: + - naked_identifier: id + - comma: ',' + - column_reference: + - naked_identifier: type + - comma: ',' + - column_reference: + - naked_identifier: title + - keyword: warehouse + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_warehouse + - keyword: target_lag + - comparison_operator: + - raw_comparison_operator: = + - dynamic_table_lag_interval_segment: '''1 days''' + - keyword: as + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: text + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: type + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: title + - comma: ',' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_db + - dot: . + - naked_identifier: my_schema + - dot: . + - naked_identifier: my_table +- statement_terminator: ; +- statement: + - create_cortex_search_service_statement: + - keyword: create + - keyword: or + - keyword: replace + - keyword: cortex + - keyword: search + - keyword: service + - object_reference: + - naked_identifier: my_service + - keyword: on + - column_reference: + - naked_identifier: text + - keyword: warehouse + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_warehouse + - keyword: target_lag + - comparison_operator: + - raw_comparison_operator: = + - dynamic_table_lag_interval_segment: '''1 days''' + - keyword: as + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: text + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: type + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: title + - comma: ',' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_db + - dot: . + - naked_identifier: my_schema + - dot: . + - naked_identifier: my_table +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database.sql index 58e1dc2ff..8f14d1e4c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database.sql @@ -1,3 +1,4 @@ CREATE DATABASE MY_DATABASE; CREATE DATABASE IF NOT EXISTS MY_DATABASE; CREATE DATABASE MY_DATABASE FROM SHARE MY_ACCOUNT.MY_SHARE; +CREATE OR ALTER DATABASE MY_DATABASE; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database.yml index 887ea4d0c..4ea220f41 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database.yml @@ -29,3 +29,12 @@ file: - dot: . - naked_identifier: MY_SHARE - statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: DATABASE + - object_reference: + - naked_identifier: MY_DATABASE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database_role.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database_role.sql new file mode 100644 index 000000000..e2136ee98 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database_role.sql @@ -0,0 +1,2 @@ +create database role dbname.rolename + comment = 'TEST'; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database_role.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database_role.yml new file mode 100644 index 000000000..64d459ab9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_database_role.yml @@ -0,0 +1,16 @@ +file: +- statement: + - create_database_role_statement: + - keyword: create + - keyword: database + - keyword: role + - database_role_reference: + - naked_identifier: dbname + - dot: . + - naked_identifier: rolename + - comment_equals_clause: + - keyword: comment + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''TEST''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_dynamic_table.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_dynamic_table.sql new file mode 100644 index 000000000..4a4b1eb68 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_dynamic_table.sql @@ -0,0 +1,46 @@ +CREATE OR REPLACE DYNAMIC TABLE names( + id, + first_name, + last_name +) +REFRESH_MODE = AUTO +TARGET_LAG = '1 minute' +INITIALIZE = ON_CREATE +WAREHOUSE = 'mywh' +AS +SELECT var:id::int id, var:fname::string first_name, +var:lname::string last_name FROM raw; + + +CREATE OR REPLACE DYNAMIC TABLE product + TARGET_LAG = '20 minutes' + WAREHOUSE = mywh + AS + SELECT product_id, product_name FROM staging_table; + + +CREATE DYNAMIC ICEBERG TABLE product (date TIMESTAMP_NTZ, id NUMBER, content STRING) + TARGET_LAG = '20 minutes' + WAREHOUSE = mywh + EXTERNAL_VOLUME = 'my_external_volume' + CATALOG = 'SNOWFLAKE' + BASE_LOCATION = 'my_iceberg_table' + AS + SELECT product_id, product_name FROM staging_table; + +CREATE DYNAMIC TABLE product (date TIMESTAMP_NTZ, id NUMBER, content VARIANT) + TARGET_LAG = '20 minutes' + WAREHOUSE = mywh + CLUSTER BY (date, id) + AS + SELECT product_id, product_name FROM staging_table; + +CREATE DYNAMIC TABLE product_clone CLONE product AT (TIMESTAMP => TO_TIMESTAMP_TZ('04/05/2013 01:02:03', 'mm/dd/yyyy hh24:mi:ss')); + +CREATE DYNAMIC TABLE product + TARGET_LAG = 'DOWNSTREAM' + WAREHOUSE = mywh + INITIALIZE = on_schedule + REQUIRE USER + AS + SELECT product_id, product_name FROM staging_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_dynamic_table.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_dynamic_table.yml new file mode 100644 index 000000000..e25d3911e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_dynamic_table.yml @@ -0,0 +1,329 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: names + - bracketed: + - start_bracket: ( + - naked_identifier: id + - comma: ',' + - naked_identifier: first_name + - comma: ',' + - naked_identifier: last_name + - end_bracket: ) + - dynamic_table_options: + - keyword: REFRESH_MODE + - comparison_operator: + - raw_comparison_operator: = + - keyword: AUTO + - keyword: TARGET_LAG + - comparison_operator: + - raw_comparison_operator: = + - dynamic_table_lag_interval_segment: '''1 minute''' + - keyword: INITIALIZE + - comparison_operator: + - raw_comparison_operator: = + - initialize_type: ON_CREATE + - keyword: WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''mywh''' + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - column_reference: + - naked_identifier: var + - semi_structured_expression: + - colon: ':' + - semi_structured_element: id + - casting_operator: '::' + - data_type: + - data_type_identifier: int + - alias_expression: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - expression: + - cast_expression: + - column_reference: + - naked_identifier: var + - semi_structured_expression: + - colon: ':' + - semi_structured_element: fname + - casting_operator: '::' + - data_type: + - data_type_identifier: string + - alias_expression: + - naked_identifier: first_name + - comma: ',' + - select_clause_element: + - expression: + - cast_expression: + - column_reference: + - naked_identifier: var + - semi_structured_expression: + - colon: ':' + - semi_structured_element: lname + - casting_operator: '::' + - data_type: + - data_type_identifier: string + - alias_expression: + - naked_identifier: last_name + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: raw +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: product + - dynamic_table_options: + - keyword: TARGET_LAG + - comparison_operator: + - raw_comparison_operator: = + - dynamic_table_lag_interval_segment: '''20 minutes''' + - keyword: WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: mywh + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: product_id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: product_name + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: staging_table +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: DYNAMIC + - keyword: ICEBERG + - keyword: TABLE + - table_reference: + - naked_identifier: product + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: date + - data_type: + - data_type_identifier: TIMESTAMP_NTZ + - comma: ',' + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: NUMBER + - comma: ',' + - column_definition: + - naked_identifier: content + - data_type: + - data_type_identifier: STRING + - end_bracket: ) + - dynamic_table_options: + - keyword: TARGET_LAG + - comparison_operator: + - raw_comparison_operator: = + - dynamic_table_lag_interval_segment: '''20 minutes''' + - keyword: WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: mywh + - keyword: EXTERNAL_VOLUME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my_external_volume''' + - keyword: CATALOG + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''SNOWFLAKE''' + - keyword: BASE_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my_iceberg_table''' + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: product_id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: product_name + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: staging_table +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: product + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: date + - data_type: + - data_type_identifier: TIMESTAMP_NTZ + - comma: ',' + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: NUMBER + - comma: ',' + - column_definition: + - naked_identifier: content + - data_type: + - data_type_identifier: VARIANT + - end_bracket: ) + - dynamic_table_options: + - keyword: TARGET_LAG + - comparison_operator: + - raw_comparison_operator: = + - dynamic_table_lag_interval_segment: '''20 minutes''' + - keyword: WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: mywh + - keyword: CLUSTER + - keyword: BY + - expression: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: date + - comma: ',' + - column_reference: + - naked_identifier: id + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: product_id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: product_name + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: staging_table +- statement_terminator: ; +- statement: + - create_clone_statement: + - keyword: CREATE + - keyword: DYNAMIC + - keyword: TABLE + - object_reference: + - naked_identifier: product_clone + - keyword: CLONE + - object_reference: + - naked_identifier: product + - from_at_expression: + - keyword: AT + - bracketed: + - start_bracket: ( + - keyword: TIMESTAMP + - parameter_assigner: => + - expression: + - function: + - function_name: + - function_name_identifier: TO_TIMESTAMP_TZ + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''04/05/2013 01:02:03''' + - comma: ',' + - expression: + - quoted_literal: '''mm/dd/yyyy hh24:mi:ss''' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: product + - dynamic_table_options: + - keyword: TARGET_LAG + - comparison_operator: + - raw_comparison_operator: = + - dynamic_table_lag_interval_segment: '''DOWNSTREAM''' + - keyword: WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: mywh + - keyword: INITIALIZE + - comparison_operator: + - raw_comparison_operator: = + - initialize_type: on_schedule + - keyword: REQUIRE + - keyword: USER + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: product_id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: product_name + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: staging_table +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_event_table.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_event_table.sql new file mode 100644 index 000000000..dd3ceae65 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_event_table.sql @@ -0,0 +1,15 @@ +CREATE EVENT TABLE my_events; +CREATE OR REPLACE EVENT TABLE IF NOT EXISTS my_database.my_schema.my_events; +CREATE EVENT TABLE IF NOT EXISTS log_trace_db.public.event_table; + +CREATE OR REPLACE EVENT TABLE IF NOT EXISTS my_events + CLUSTER BY (date, type) + DATA_RETENTION_TIME_IN_DAYS = 5 + MAX_DATA_EXTENSION_TIME_IN_DAYS = 30 + CHANGE_TRACKING = FALSE + DEFAULT_DDL_COLLATION = 'en-ci' + COPY GRANTS + WITH COMMENT = 'My events table' + WITH ROW ACCESS POLICY sales_policy ON (type, region) + WITH TAG (cost_center = 'sales') +; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_event_table.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_event_table.yml new file mode 100644 index 000000000..eba5bce7e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_event_table.yml @@ -0,0 +1,116 @@ +file: +- statement: + - create_event_table_statement: + - keyword: CREATE + - keyword: EVENT + - keyword: TABLE + - table_reference: + - naked_identifier: my_events +- statement_terminator: ; +- statement: + - create_event_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: EVENT + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: my_database + - dot: . + - naked_identifier: my_schema + - dot: . + - naked_identifier: my_events +- statement_terminator: ; +- statement: + - create_event_table_statement: + - keyword: CREATE + - keyword: EVENT + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: log_trace_db + - dot: . + - naked_identifier: public + - dot: . + - naked_identifier: event_table +- statement_terminator: ; +- statement: + - create_event_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: EVENT + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: my_events + - keyword: CLUSTER + - keyword: BY + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: date + - comma: ',' + - expression: + - column_reference: + - naked_identifier: type + - end_bracket: ) + - keyword: DATA_RETENTION_TIME_IN_DAYS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '5' + - keyword: MAX_DATA_EXTENSION_TIME_IN_DAYS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '30' + - keyword: CHANGE_TRACKING + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' + - keyword: DEFAULT_DDL_COLLATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''en-ci''' + - keyword: COPY + - keyword: GRANTS + - keyword: WITH + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''My events table''' + - keyword: WITH + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: sales_policy + - keyword: ON + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: type + - comma: ',' + - column_reference: + - naked_identifier: region + - end_bracket: ) + - tag_bracketed_equals: + - keyword: WITH + - keyword: TAG + - bracketed: + - start_bracket: ( + - tag_reference: + - naked_identifier: cost_center + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''sales''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_table.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_table.sql index c09b28c2c..c0dd939a2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_table.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_table.sql @@ -30,3 +30,14 @@ CREATE EXTERNAL TABLE EXTERNAL_TABLES.TRIPS( PARTITION BY (year) LOCATION = @external_tables.citibike_trips FILE_FORMAT = ( TYPE = 'CSV' FIELD_OPTIONALLY_ENCLOSED_BY = '"' ); + + +CREATE EXTERNAL TABLE IF NOT EXISTS source_test.test ( + yyyymmdd TEXT AS (value:YYYYMMDD::TEXT), + product TEXT AS (value:product::TEXT) +) +PARTITION BY (yyyymmdd) +PARTITION_TYPE = user_specified +LOCATION = @public.test_stage +FILE_FORMAT = public.parquet_format_convert_binary +AUTO_REFRESH = false; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_table.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_table.yml index fff8e4128..12fdfa6e5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_table.yml @@ -519,3 +519,80 @@ file: - quoted_literal: '''"''' - end_bracket: ) - statement_terminator: ; +- statement: + - create_external_table_statement: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: source_test + - dot: . + - naked_identifier: test + - bracketed: + - start_bracket: ( + - naked_identifier: yyyymmdd + - data_type: + - data_type_identifier: TEXT + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - cast_expression: + - column_reference: + - naked_identifier: value + - semi_structured_expression: + - colon: ':' + - semi_structured_element: YYYYMMDD + - casting_operator: '::' + - data_type: + - data_type_identifier: TEXT + - end_bracket: ) + - comma: ',' + - naked_identifier: product + - data_type: + - data_type_identifier: TEXT + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - cast_expression: + - column_reference: + - naked_identifier: value + - semi_structured_expression: + - colon: ':' + - semi_structured_element: product + - casting_operator: '::' + - data_type: + - data_type_identifier: TEXT + - end_bracket: ) + - end_bracket: ) + - keyword: PARTITION + - keyword: BY + - bracketed: + - start_bracket: ( + - naked_identifier: yyyymmdd + - end_bracket: ) + - keyword: PARTITION_TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: user_specified + - keyword: LOCATION + - comparison_operator: + - raw_comparison_operator: = + - stage_path: '@public.test_stage' + - keyword: FILE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - file_format_segment: + - object_reference: + - naked_identifier: public + - dot: . + - naked_identifier: parquet_format_convert_binary + - keyword: AUTO_REFRESH + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'false' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_volume.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_volume.sql new file mode 100644 index 000000000..699df2d5e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_volume.sql @@ -0,0 +1,56 @@ +CREATE OR REPLACE EXTERNAL VOLUME exvol + STORAGE_LOCATIONS = + ( + ( + NAME = 'my-s3-us-west-2' + STORAGE_PROVIDER = 'S3' + STORAGE_BASE_URL = 's3://MY_EXAMPLE_BUCKET/' + STORAGE_AWS_ROLE_ARN = 'arn:aws:iam::123456789012:role/myrole' + ENCRYPTION=(TYPE='AWS_SSE_KMS' KMS_KEY_ID='1234abcd-12ab-34cd-56ef-1234567890ab') + ) + ) +; + +CREATE EXTERNAL VOLUME exvol + STORAGE_LOCATIONS = + ( + ( + NAME = 'my-us-east-1' + STORAGE_PROVIDER = 'GCS' + STORAGE_BASE_URL = 'gcs://mybucket1/path1/' + ENCRYPTION=(TYPE='GCS_SSE_KMS' KMS_KEY_ID = '1234abcd-12ab-34cd-56ef-1234567890ab') + ) + ); + +CREATE EXTERNAL VOLUME exvol + STORAGE_LOCATIONS = + ( + ( + NAME = 'my-azure-northeurope' + STORAGE_PROVIDER = 'AZURE' + STORAGE_BASE_URL = 'azure://exampleacct.blob.core.windows.net/my_container_northeurope/' + AZURE_TENANT_ID = 'a123b4c5-1234-123a-a12b-1a23b45678c9' + ) + ); + +CREATE EXTERNAL VOLUME IF NOT EXISTS exvol + STORAGE_LOCATIONS = + ( + ( + NAME = 'my-s3-us-west-2' + STORAGE_PROVIDER = 'S3' + STORAGE_BASE_URL = 's3://MY_EXAMPLE_BUCKET/' + STORAGE_AWS_ROLE_ARN = 'arn:aws:iam::123456789012:role/myrole' + ENCRYPTION=(TYPE='AWS_SSE_KMS' KMS_KEY_ID='1234abcd-12ab-34cd-56ef-1234567890ab') + ), + ( + NAME = 'my-s3-us-west-3' + STORAGE_PROVIDER = 'S3' + STORAGE_BASE_URL = 's3://MY_EXAMPLE_BUCKET_2/' + STORAGE_AWS_ROLE_ARN = 'arn:aws:iam::123456789012:role/myrole' + ENCRYPTION=(TYPE='AWS_SSE_KMS' KMS_KEY_ID='1234abcd-12ab-34cd-56ef-1234567890ab') + ) + ) + ALLOW_WRITES=FALSE + COMMENT='foo' +; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_volume.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_volume.yml new file mode 100644 index 000000000..019ce498f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_external_volume.yml @@ -0,0 +1,219 @@ +file: +- statement: + - create_external_volume_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: EXTERNAL + - keyword: VOLUME + - external_volume_reference: + - naked_identifier: exvol + - keyword: STORAGE_LOCATIONS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - bracketed: + - start_bracket: ( + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my-s3-us-west-2''' + - keyword: STORAGE_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''S3''' + - keyword: STORAGE_BASE_URL + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''s3://MY_EXAMPLE_BUCKET/''' + - keyword: STORAGE_AWS_ROLE_ARN + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''arn:aws:iam::123456789012:role/myrole''' + - keyword: ENCRYPTION + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - stage_encryption_option: '''AWS_SSE_KMS''' + - keyword: KMS_KEY_ID + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''1234abcd-12ab-34cd-56ef-1234567890ab''' + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_external_volume_statement: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: VOLUME + - external_volume_reference: + - naked_identifier: exvol + - keyword: STORAGE_LOCATIONS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - bracketed: + - start_bracket: ( + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my-us-east-1''' + - keyword: STORAGE_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''GCS''' + - keyword: STORAGE_BASE_URL + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''gcs://mybucket1/path1/''' + - keyword: ENCRYPTION + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - stage_encryption_option: '''GCS_SSE_KMS''' + - keyword: KMS_KEY_ID + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''1234abcd-12ab-34cd-56ef-1234567890ab''' + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_external_volume_statement: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: VOLUME + - external_volume_reference: + - naked_identifier: exvol + - keyword: STORAGE_LOCATIONS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - bracketed: + - start_bracket: ( + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my-azure-northeurope''' + - keyword: STORAGE_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''AZURE''' + - keyword: STORAGE_BASE_URL + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''azure://exampleacct.blob.core.windows.net/my_container_northeurope/''' + - keyword: AZURE_TENANT_ID + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''a123b4c5-1234-123a-a12b-1a23b45678c9''' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_external_volume_statement: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: VOLUME + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - external_volume_reference: + - naked_identifier: exvol + - keyword: STORAGE_LOCATIONS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - bracketed: + - start_bracket: ( + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my-s3-us-west-2''' + - keyword: STORAGE_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''S3''' + - keyword: STORAGE_BASE_URL + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''s3://MY_EXAMPLE_BUCKET/''' + - keyword: STORAGE_AWS_ROLE_ARN + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''arn:aws:iam::123456789012:role/myrole''' + - keyword: ENCRYPTION + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - stage_encryption_option: '''AWS_SSE_KMS''' + - keyword: KMS_KEY_ID + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''1234abcd-12ab-34cd-56ef-1234567890ab''' + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my-s3-us-west-3''' + - keyword: STORAGE_PROVIDER + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''S3''' + - keyword: STORAGE_BASE_URL + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''s3://MY_EXAMPLE_BUCKET_2/''' + - keyword: STORAGE_AWS_ROLE_ARN + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''arn:aws:iam::123456789012:role/myrole''' + - keyword: ENCRYPTION + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - stage_encryption_option: '''AWS_SSE_KMS''' + - keyword: KMS_KEY_ID + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''1234abcd-12ab-34cd-56ef-1234567890ab''' + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - keyword: ALLOW_WRITES + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''foo''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_file_format.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_file_format.sql index abec71bf9..0f146554c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_file_format.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_file_format.sql @@ -58,6 +58,11 @@ CREATE FILE FORMAT IF NOT EXISTS my_csv_format COMMENT = 'FOOBAR' ; +CREATE FILE FORMAT IF NOT EXISTS my_csv_format + TYPE = CSV + PARSE_HEADER = TRUE +; + CREATE OR REPLACE FILE FORMAT my_json_format TYPE = JSON, COMPRESSION = AUTO, @@ -144,6 +149,9 @@ CREATE FILE FORMAT IF NOT EXISTS my_parquet_format SNAPPY_COMPRESSION = FALSE TRIM_SPACE = FALSE BINARY_AS_TEXT = TRUE + USE_LOGICAL_TYPE = FALSE + USE_VECTORIZED_SCANNER = FALSE + REPLACE_INVALID_CHARACTERS = FALSE NULL_IF = ('foo', 'bar') COMMENT = 'FOOBAR' ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_file_format.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_file_format.yml index 3938dc98c..739892f68 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_file_format.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_file_format.yml @@ -267,6 +267,26 @@ file: - raw_comparison_operator: = - quoted_literal: '''FOOBAR''' - statement_terminator: ; +- statement: + - create_file_format_segment: + - keyword: CREATE + - keyword: FILE + - keyword: FORMAT + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - object_reference: + - naked_identifier: my_csv_format + - csv_file_format_type_parameters: + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - file_type: CSV + - keyword: PARSE_HEADER + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' +- statement_terminator: ; - statement: - create_file_format_segment: - keyword: CREATE @@ -678,6 +698,18 @@ file: - comparison_operator: - raw_comparison_operator: = - boolean_literal: 'TRUE' + - keyword: USE_LOGICAL_TYPE + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' + - keyword: USE_VECTORIZED_SCANNER + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' + - keyword: REPLACE_INVALID_CHARACTERS + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' - keyword: NULL_IF - comparison_operator: - raw_comparison_operator: = diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_function.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_function.sql index 35224a4ba..7ec8eb61d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_function.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_function.sql @@ -109,3 +109,63 @@ class Echo { } } $$; + +CREATE OR REPLACE FUNCTION google_translate_python(sentence STRING, language STRING) +RETURNS STRING +LANGUAGE PYTHON +RUNTIME_VERSION = '3.8' +HANDLER = 'get_translation' +EXTERNAL_ACCESS_INTEGRATIONS = (google_apis_access_integration, my_integration ) +PACKAGES = ('snowflake-snowpark-python','requests') +SECRETS = ('cred' = oauth_token, 'cred2' = DATA_STAGE.AWS_SECRET_KEY ) +AS +$$ +import _snowflake +import requests +import json +session = requests.Session() +def get_translation(sentence, language): + token = _snowflake.get_oauth_access_token('cred') + url = "https://translation.googleapis.com/language/translate/v2" + data = {'q': sentence,'target': language} + response = session.post(url, json = data, headers = {"Authorization": "Bearer " + token}) + return response.json()['data']['translations'][0]['translatedText'] +$$; + + +create or replace aggregate function addone(i int) +returns int +language python +runtime_version = '3.8' +handler = 'addone_py' +as +$$ +def addone_py(i): + return i+1 +$$; + + +CREATE OR REPLACE FUNCTION TEST_DB.TEST_SCHEMA.TEST_TABLE( + COL_1 VARCHAR DEFAULT NULL + , COL_2 VARCHAR DEFAULT NULL +) +RETURNS VARCHAR +LANGUAGE SQL +AS +$$ +SELECT + CASE + WHEN (LOWER(COL_1) IS NOT NULL AND + LOWER(COL_2) = 'test_marketing') + THEN 'marketing_channel' + ELSE '(Other)' +END +$$;; + +CREATE TEMPORARY FUNCTION pi_udf() + RETURNS FLOAT + AS '3.141592654::FLOAT'; + +CREATE TEMP FUNCTION pi_udf() + RETURNS FLOAT + AS '3.141592654::FLOAT'; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_function.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_function.yml index 48c2f1361..24ec1b736 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_function.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_function.yml @@ -392,3 +392,202 @@ file: } $$ - statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: FUNCTION + - function_name: + - function_name_identifier: google_translate_python + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: sentence + - data_type: + - data_type_identifier: STRING + - comma: ',' + - parameter: language + - data_type: + - data_type_identifier: STRING + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: STRING + - keyword: LANGUAGE + - keyword: PYTHON + - keyword: RUNTIME_VERSION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''3.8''' + - keyword: HANDLER + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''get_translation''' + - keyword: EXTERNAL_ACCESS_INTEGRATIONS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - naked_identifier: google_apis_access_integration + - comma: ',' + - naked_identifier: my_integration + - end_bracket: ) + - keyword: PACKAGES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''snowflake-snowpark-python''' + - comma: ',' + - quoted_literal: '''requests''' + - end_bracket: ) + - keyword: SECRETS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''cred''' + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: oauth_token + - comma: ',' + - quoted_literal: '''cred2''' + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: DATA_STAGE + - dot: . + - naked_identifier: AWS_SECRET_KEY + - end_bracket: ) + - keyword: AS + - udf_body: |- + $$ + import _snowflake + import requests + import json + session = requests.Session() + def get_translation(sentence, language): + token = _snowflake.get_oauth_access_token('cred') + url = "https://translation.googleapis.com/language/translate/v2" + data = {'q': sentence,'target': language} + response = session.post(url, json = data, headers = {"Authorization": "Bearer " + token}) + return response.json()['data']['translations'][0]['translatedText'] + $$ +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: create + - keyword: or + - keyword: replace + - keyword: aggregate + - keyword: function + - function_name: + - function_name_identifier: addone + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: i + - data_type: + - data_type_identifier: int + - end_bracket: ) + - keyword: returns + - data_type: + - data_type_identifier: int + - keyword: language + - keyword: python + - keyword: runtime_version + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''3.8''' + - keyword: handler + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''addone_py''' + - keyword: as + - udf_body: |- + $$ + def addone_py(i): + return i+1 + $$ +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: FUNCTION + - function_name: + - naked_identifier: TEST_DB + - dot: . + - naked_identifier: TEST_SCHEMA + - dot: . + - function_name_identifier: TEST_TABLE + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: COL_1 + - data_type: + - data_type_identifier: VARCHAR + - keyword: DEFAULT + - expression: + - null_literal: 'NULL' + - comma: ',' + - parameter: COL_2 + - data_type: + - data_type_identifier: VARCHAR + - keyword: DEFAULT + - expression: + - null_literal: 'NULL' + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: VARCHAR + - keyword: LANGUAGE + - keyword: SQL + - keyword: AS + - udf_body: |- + $$ + SELECT + CASE + WHEN (LOWER(COL_1) IS NOT NULL AND + LOWER(COL_2) = 'test_marketing') + THEN 'marketing_channel' + ELSE '(Other)' + END + $$ +- statement_terminator: ; +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: TEMPORARY + - keyword: FUNCTION + - function_name: + - function_name_identifier: pi_udf + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: FLOAT + - keyword: AS + - udf_body: '''3.141592654::FLOAT''' +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: TEMP + - keyword: FUNCTION + - function_name: + - function_name_identifier: pi_udf + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: FLOAT + - keyword: AS + - udf_body: '''3.141592654::FLOAT''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_masking_policy.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_masking_policy.yml index f1885f3b0..47e471b1e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_masking_policy.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_masking_policy.yml @@ -13,15 +13,16 @@ file: - dot: . - naked_identifier: example_MASKING_POLICY - keyword: AS - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: val - - expression: - - column_reference: - - naked_identifier: VARCHAR - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: val + - expression: + - column_reference: + - naked_identifier: VARCHAR + - end_bracket: ) - keyword: RETURNS - data_type: - data_type_identifier: VARCHAR @@ -50,10 +51,11 @@ file: - expression: - quoted_literal: '''*** masked ***''' - keyword: END - - keyword: COMMENT - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''Applied 2021-07-13T03:12:16+0000''' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Applied 2021-07-13T03:12:16+0000''' - statement_terminator: ; - statement: - create_statement: @@ -65,15 +67,16 @@ file: - object_reference: - naked_identifier: email_mask - keyword: as - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: val - - expression: - - column_reference: - - naked_identifier: string - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: val + - expression: + - column_reference: + - naked_identifier: string + - end_bracket: ) - keyword: returns - data_type: - data_type_identifier: string @@ -116,15 +119,16 @@ file: - object_reference: - naked_identifier: email_mask - keyword: as - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: val - - expression: - - column_reference: - - naked_identifier: string - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: val + - expression: + - column_reference: + - naked_identifier: string + - end_bracket: ) - keyword: returns - data_type: - data_type_identifier: string @@ -167,15 +171,16 @@ file: - object_reference: - naked_identifier: email_mask - keyword: as - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: val - - expression: - - column_reference: - - naked_identifier: string - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: val + - expression: + - column_reference: + - naked_identifier: string + - end_bracket: ) - keyword: returns - data_type: - data_type_identifier: string @@ -218,15 +223,16 @@ file: - object_reference: - naked_identifier: email_mask - keyword: as - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: val - - expression: - - column_reference: - - naked_identifier: string - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: val + - expression: + - column_reference: + - naked_identifier: string + - end_bracket: ) - keyword: returns - data_type: - data_type_identifier: string @@ -269,15 +275,16 @@ file: - object_reference: - naked_identifier: email_mask - keyword: as - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: val - - expression: - - column_reference: - - naked_identifier: string - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: val + - expression: + - column_reference: + - naked_identifier: string + - end_bracket: ) - keyword: returns - data_type: - data_type_identifier: string @@ -329,15 +336,16 @@ file: - object_reference: - naked_identifier: email_mask - keyword: as - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: val - - expression: - - column_reference: - - naked_identifier: string - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: val + - expression: + - column_reference: + - naked_identifier: string + - end_bracket: ) - keyword: returns - data_type: - data_type_identifier: string @@ -413,15 +421,16 @@ file: - object_reference: - naked_identifier: email_mask - keyword: as - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: val - - expression: - - column_reference: - - naked_identifier: string - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: val + - expression: + - column_reference: + - naked_identifier: string + - end_bracket: ) - keyword: returns - data_type: - data_type_identifier: string @@ -482,15 +491,16 @@ file: - object_reference: - naked_identifier: email_mask - keyword: as - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: val - - expression: - - column_reference: - - naked_identifier: string - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: val + - expression: + - column_reference: + - naked_identifier: string + - end_bracket: ) - keyword: returns - data_type: - data_type_identifier: string @@ -542,15 +552,16 @@ file: - object_reference: - naked_identifier: email_mask - keyword: as - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: val - - expression: - - column_reference: - - naked_identifier: string - - end_bracket: ) + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: val + - expression: + - column_reference: + - naked_identifier: string + - end_bracket: ) - keyword: returns - data_type: - data_type_identifier: string diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_policy.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_policy.sql index cb2cf2e57..3ad1d49cf 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_policy.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_policy.sql @@ -3,3 +3,13 @@ create network policy mypolicy1 allowed_ip_list=('192.168.1.0/24') CREATE OR REPLACE NETWORK POLICY TEST_NW_POLICY ALLOWED_IP_LIST=('xx.xxx.xxx.xx/xx','xx.xxx.xxx.xx/xx') COMMENT='NW Policy' ; + +CREATE NETWORK POLICY np + ALLOWED_NETWORK_RULE_LIST = ('blabla','blabla2','blabla3') + COMMENT='comment' + ; + +CREATE NETWORK POLICY np + BLOCKED_NETWORK_RULE_LIST = ('blabla','blabla2','blabla3') + COMMENT='comment' + ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_policy.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_policy.yml index dd2df04dd..d8beee361 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_policy.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_policy.yml @@ -39,8 +39,57 @@ file: - comma: ',' - quoted_literal: '''xx.xxx.xxx.xx/xx''' - end_bracket: ) - - keyword: COMMENT + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''NW Policy''' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: NETWORK + - keyword: POLICY + - object_reference: + - naked_identifier: np + - keyword: ALLOWED_NETWORK_RULE_LIST + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''blabla''' + - comma: ',' + - quoted_literal: '''blabla2''' + - comma: ',' + - quoted_literal: '''blabla3''' + - end_bracket: ) + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''comment''' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: NETWORK + - keyword: POLICY + - object_reference: + - naked_identifier: np + - keyword: BLOCKED_NETWORK_RULE_LIST - comparison_operator: - raw_comparison_operator: = - - quoted_literal: '''NW Policy''' + - bracketed: + - start_bracket: ( + - quoted_literal: '''blabla''' + - comma: ',' + - quoted_literal: '''blabla2''' + - comma: ',' + - quoted_literal: '''blabla3''' + - end_bracket: ) + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''comment''' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_rule.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_rule.sql new file mode 100644 index 000000000..24ba441a8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_rule.sql @@ -0,0 +1,20 @@ +CREATE NETWORK RULE corporate_network +TYPE = AWSVPCEID +VALUE_LIST = ('vpce-123abc3420c1931') +MODE = INTERNAL_STAGE +COMMENT = 'corporate privatelink endpoint'; + +CREATE NETWORK RULE cloud_network +TYPE = IPV4 +VALUE_LIST = ('47.88.25.32/27') +COMMENT = 'cloud egress ip range'; + +CREATE NETWORK RULE external_access_rule +TYPE = HOST_PORT +MODE = EGRESS +VALUE_LIST = ('example.com', 'example.com:443'); + +CREATE OR REPLACE NETWORK RULE ext_network_access_db.network_rules.azure_sql_private_rule +MODE = EGRESS +TYPE = PRIVATE_HOST_PORT +VALUE_LIST = ('externalaccessdemo.database.windows.net'); diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_rule.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_rule.yml new file mode 100644 index 000000000..65b1c00a7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_network_rule.yml @@ -0,0 +1,107 @@ +file: +- statement: + - create_statement: + - keyword: CREATE + - keyword: NETWORK + - keyword: RULE + - object_reference: + - naked_identifier: corporate_network + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: AWSVPCEID + - keyword: VALUE_LIST + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''vpce-123abc3420c1931''' + - end_bracket: ) + - keyword: MODE + - comparison_operator: + - raw_comparison_operator: = + - keyword: INTERNAL_STAGE + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''corporate privatelink endpoint''' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: NETWORK + - keyword: RULE + - object_reference: + - naked_identifier: cloud_network + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: IPV4 + - keyword: VALUE_LIST + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''47.88.25.32/27''' + - end_bracket: ) + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''cloud egress ip range''' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: NETWORK + - keyword: RULE + - object_reference: + - naked_identifier: external_access_rule + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: HOST_PORT + - keyword: MODE + - comparison_operator: + - raw_comparison_operator: = + - keyword: EGRESS + - keyword: VALUE_LIST + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''example.com''' + - comma: ',' + - quoted_literal: '''example.com:443''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: NETWORK + - keyword: RULE + - object_reference: + - naked_identifier: ext_network_access_db + - dot: . + - naked_identifier: network_rules + - dot: . + - naked_identifier: azure_sql_private_rule + - keyword: MODE + - comparison_operator: + - raw_comparison_operator: = + - keyword: EGRESS + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: PRIVATE_HOST_PORT + - keyword: VALUE_LIST + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''externalaccessdemo.database.windows.net''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_password_policy.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_password_policy.sql new file mode 100644 index 000000000..0241e3490 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_password_policy.sql @@ -0,0 +1,13 @@ +CREATE PASSWORD POLICY PASSWORD_POLICY_PROD_1 + PASSWORD_MIN_LENGTH = 12 + PASSWORD_MAX_LENGTH = 24 + PASSWORD_MIN_UPPER_CASE_CHARS = 2 + PASSWORD_MIN_LOWER_CASE_CHARS = 2 + PASSWORD_MIN_NUMERIC_CHARS = 2 + PASSWORD_MIN_SPECIAL_CHARS = 2 + PASSWORD_MIN_AGE_DAYS = 1 + PASSWORD_MAX_AGE_DAYS = 30 + PASSWORD_MAX_RETRIES = 3 + PASSWORD_LOCKOUT_TIME_MINS = 30 + PASSWORD_HISTORY = 5 + COMMENT = 'production account password policy'; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_password_policy.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_password_policy.yml new file mode 100644 index 000000000..4461252b0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_password_policy.yml @@ -0,0 +1,59 @@ +file: +- statement: + - create_password_policy_statement: + - keyword: CREATE + - keyword: PASSWORD + - keyword: POLICY + - password_policy_reference: + - naked_identifier: PASSWORD_POLICY_PROD_1 + - password_policy_options: + - keyword: PASSWORD_MIN_LENGTH + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '12' + - keyword: PASSWORD_MAX_LENGTH + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '24' + - keyword: PASSWORD_MIN_UPPER_CASE_CHARS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' + - keyword: PASSWORD_MIN_LOWER_CASE_CHARS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' + - keyword: PASSWORD_MIN_NUMERIC_CHARS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' + - keyword: PASSWORD_MIN_SPECIAL_CHARS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' + - keyword: PASSWORD_MIN_AGE_DAYS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - keyword: PASSWORD_MAX_AGE_DAYS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '30' + - keyword: PASSWORD_MAX_RETRIES + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '3' + - keyword: PASSWORD_LOCKOUT_TIME_MINS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '30' + - keyword: PASSWORD_HISTORY + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '5' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''production account password policy''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_pipe.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_pipe.yml index 421df7dbc..c665c725e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_pipe.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_pipe.yml @@ -96,7 +96,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: column2 - from_clause: - keyword: from @@ -156,7 +157,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: column2 - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_procedure.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_procedure.sql index 0599730f2..03070e4e0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_procedure.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_procedure.sql @@ -44,6 +44,15 @@ catch (err) { $$ ; +CREATE OR REPLACE PROCEDURE IF NOT EXISTS UTIL_DB.PUBLIC.PROCEDURE_IF_NOT_EXISTS() +RETURNS INT +LANGUAGE JAVASCRIPT +AS +$$ + return 1; +$$; + + CREATE OR REPLACE PROCEDURE UTIL_DB.PUBLIC.PROCEDURE_WITHOUT_EXPLICIT_LANGUAGE() RETURNS INT AS @@ -146,3 +155,28 @@ select 3; select 4; return 5; END; + + +CREATE OR REPLACE PROCEDURE MY_PROCEDURE(hello_world VARCHAR(10000)) +COPY GRANTS +RETURNS TABLE () +LANGUAGE PYTHON +RUNTIME_VERSION = '3.11' +PACKAGES = ('snowflake-snowpark-python') +HANDLER = 'my.path.func_formula_parser_test_script_runner_proc' +IMPORTS = ('@MIRROR.PYTHON_SCRIPTS/script.py') +EXECUTE AS OWNER +; + +CREATE OR REPLACE PROCEDURE DATA_STAGE.INGEST_DATA_FROM_GS(P_GOOGLE_SPREADSHEET_ID VARCHAR(16777216), P_SHEET_NAME VARCHAR(16777216), P_STAGING_TABLE VARCHAR(16777216)) +COPY GRANTS +RETURNS VARCHAR(16777216) +LANGUAGE PYTHON +RUNTIME_VERSION = '3.11' +PACKAGES = ('snowflake-snowpark-python','requests') +HANDLER = 'SF_GOOGLE_SHEET_LOADER.ingest_gs_to_staging_table' +IMPORTS = ('@DATA_STAGE.PYTHON_SCRIPTS/SF_GOOGLE_SHEET_LOADER.py') +EXTERNAL_ACCESS_INTEGRATIONS = (GOOGLESHEET_APIS_ACCESS_INTEGRATION) +SECRETS = ('cred' = DATA_STAGE.GS_OAUTH_TOKEN, 'cred2' = my_cred) +EXECUTE AS CALLER +; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_procedure.yml index dcc353d10..e2979292d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_procedure.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_procedure.yml @@ -115,6 +115,36 @@ file: } $$ - statement_terminator: ; +- statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: PROCEDURE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - function_name: + - naked_identifier: UTIL_DB + - dot: . + - naked_identifier: PUBLIC + - dot: . + - function_name_identifier: PROCEDURE_IF_NOT_EXISTS + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: INT + - keyword: LANGUAGE + - keyword: JAVASCRIPT + - keyword: AS + - udf_body: |- + $$ + return 1; + $$ +- statement_terminator: ; - statement: - create_procedure_statement: - keyword: CREATE @@ -401,35 +431,194 @@ file: - keyword: select - select_clause_element: - numeric_literal: '1' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '2' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '3' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '4' + - statement_terminator: ; + - statement: + - return_statement: + - keyword: return + - expression: + - numeric_literal: '5' + - statement_terminator: ; + - keyword: END - statement_terminator: ; - statement: - - select_statement: - - select_clause: - - keyword: select - - select_clause_element: - - numeric_literal: '2' -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: select - - select_clause_element: - - numeric_literal: '3' -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: select - - select_clause_element: - - numeric_literal: '4' -- statement_terminator: ; -- statement: - - return_statement: - - keyword: return - - expression: - - numeric_literal: '5' + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: PROCEDURE + - function_name: + - function_name_identifier: MY_PROCEDURE + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: hello_world + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '10000' + - end_bracket: ) + - end_bracket: ) + - keyword: COPY + - keyword: GRANTS + - keyword: RETURNS + - data_type: + - data_type_identifier: TABLE + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: LANGUAGE + - keyword: PYTHON + - keyword: RUNTIME_VERSION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''3.11''' + - keyword: PACKAGES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''snowflake-snowpark-python''' + - end_bracket: ) + - keyword: HANDLER + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my.path.func_formula_parser_test_script_runner_proc''' + - keyword: IMPORTS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''@MIRROR.PYTHON_SCRIPTS/script.py''' + - end_bracket: ) + - keyword: EXECUTE + - keyword: AS + - keyword: OWNER - statement_terminator: ; - statement: - - scripting_block_statement: - - keyword: END + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: PROCEDURE + - function_name: + - naked_identifier: DATA_STAGE + - dot: . + - function_name_identifier: INGEST_DATA_FROM_GS + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: P_GOOGLE_SPREADSHEET_ID + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '16777216' + - end_bracket: ) + - comma: ',' + - parameter: P_SHEET_NAME + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '16777216' + - end_bracket: ) + - comma: ',' + - parameter: P_STAGING_TABLE + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '16777216' + - end_bracket: ) + - end_bracket: ) + - keyword: COPY + - keyword: GRANTS + - keyword: RETURNS + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '16777216' + - end_bracket: ) + - keyword: LANGUAGE + - keyword: PYTHON + - keyword: RUNTIME_VERSION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''3.11''' + - keyword: PACKAGES + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''snowflake-snowpark-python''' + - comma: ',' + - quoted_literal: '''requests''' + - end_bracket: ) + - keyword: HANDLER + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''SF_GOOGLE_SHEET_LOADER.ingest_gs_to_staging_table''' + - keyword: IMPORTS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''@DATA_STAGE.PYTHON_SCRIPTS/SF_GOOGLE_SHEET_LOADER.py''' + - end_bracket: ) + - keyword: EXTERNAL_ACCESS_INTEGRATIONS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - naked_identifier: GOOGLESHEET_APIS_ACCESS_INTEGRATION + - end_bracket: ) + - keyword: SECRETS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''cred''' + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: DATA_STAGE + - dot: . + - naked_identifier: GS_OAUTH_TOKEN + - comma: ',' + - quoted_literal: '''cred2''' + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: my_cred + - end_bracket: ) + - keyword: EXECUTE + - keyword: AS + - keyword: CALLER - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_resource_monitor.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_resource_monitor.sql index 83bbe428e..34801148d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_resource_monitor.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_resource_monitor.sql @@ -1,55 +1,22 @@ --- Test cases for CREATE RESOURCE MONITOR statement --- From SQLFluff PR #5272 +create resource monitor if not exists test; --- Simple resource monitor with credit quota -CREATE RESOURCE MONITOR my_monitor WITH CREDIT_QUOTA=100; --- Resource monitor with frequency -CREATE RESOURCE MONITOR budget_monitor WITH CREDIT_QUOTA=500 FREQUENCY=MONTHLY; +create or replace resource monitor limiter with credit_quota = 1; +create or replace resource monitor test with frequency = monthly; --- Resource monitor with all frequency options -CREATE RESOURCE MONITOR daily_monitor WITH CREDIT_QUOTA=10 FREQUENCY=DAILY; -CREATE RESOURCE MONITOR weekly_monitor WITH CREDIT_QUOTA=70 FREQUENCY=WEEKLY; -CREATE RESOURCE MONITOR yearly_monitor WITH CREDIT_QUOTA=5000 FREQUENCY=YEARLY; -CREATE RESOURCE MONITOR never_monitor WITH CREDIT_QUOTA=1000 FREQUENCY=NEVER; +create or replace resource monitor limiter with start_timestamp = immediately; +create or replace resource monitor limiter with start_timestamp= '2038-01-19 03:14:07'; --- Resource monitor with start timestamp -CREATE RESOURCE MONITOR timed_monitor WITH CREDIT_QUOTA=100 START_TIMESTAMP='2024-01-01 00:00:00'; -CREATE RESOURCE MONITOR immediate_monitor WITH CREDIT_QUOTA=100 START_TIMESTAMP=IMMEDIATELY; +create or replace resource monitor limiter with +credit_quota = 100 +NOTIFY_USERS = (joe, "sara", "ashlee") +start_timestamp = immediately +end_timestamp = '2038-01-19 03:14:07' +; --- Resource monitor with end timestamp -CREATE RESOURCE MONITOR limited_monitor WITH CREDIT_QUOTA=100 END_TIMESTAMP='2024-12-31 23:59:59'; - --- Resource monitor with notify users -CREATE RESOURCE MONITOR notify_monitor WITH CREDIT_QUOTA=100 NOTIFY_USERS=(user1, user2, user3); - --- Resource monitor with single trigger -CREATE RESOURCE MONITOR trigger_monitor WITH CREDIT_QUOTA=100 - TRIGGERS ON 90 PERCENT DO SUSPEND; - --- Resource monitor with multiple triggers -CREATE RESOURCE MONITOR multi_trigger_monitor WITH CREDIT_QUOTA=1000 - TRIGGERS ON 50 PERCENT DO NOTIFY - ON 75 PERCENT DO NOTIFY - ON 90 PERCENT DO SUSPEND - ON 100 PERCENT DO SUSPEND_IMMEDIATE; - --- Resource monitor with all options -CREATE OR REPLACE RESOURCE MONITOR full_monitor WITH - CREDIT_QUOTA=2000 - FREQUENCY=MONTHLY - START_TIMESTAMP='2024-01-01 00:00:00' - END_TIMESTAMP='2024-12-31 23:59:59' - NOTIFY_USERS=(admin, finance_team) - TRIGGERS ON 60 PERCENT DO NOTIFY - ON 80 PERCENT DO SUSPEND - ON 95 PERCENT DO SUSPEND_IMMEDIATE; - --- Resource monitor with OR REPLACE -CREATE OR REPLACE RESOURCE MONITOR replaced_monitor WITH CREDIT_QUOTA=300; - --- Resource monitor with schema qualified name -CREATE RESOURCE MONITOR my_schema.my_monitor WITH CREDIT_QUOTA=100; - --- Resource monitor with database and schema qualified name -CREATE RESOURCE MONITOR my_db.my_schema.my_monitor WITH CREDIT_QUOTA=100; \ No newline at end of file +create or replace resource monitor limiter with credit_quota=5000 + notify_users = (jdoe, "jane smith", "john doe") + triggers on 75 percent do notify + on 100 percent do suspend + on 110 percent do suspend_immediate +; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_resource_monitor.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_resource_monitor.yml index 30f26b286..378ea65fe 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_resource_monitor.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_resource_monitor.yml @@ -1,310 +1,160 @@ file: - statement: - - keyword: CREATE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: my_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '100' -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: budget_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '500' - - keyword: FREQUENCY - - comparison_operator: - - raw_comparison_operator: = - - keyword: MONTHLY -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: daily_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '10' - - keyword: FREQUENCY - - comparison_operator: - - raw_comparison_operator: = - - keyword: DAILY -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: weekly_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '70' - - keyword: FREQUENCY - - comparison_operator: - - raw_comparison_operator: = - - keyword: WEEKLY -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: yearly_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '5000' - - keyword: FREQUENCY - - comparison_operator: - - raw_comparison_operator: = - - keyword: YEARLY -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: never_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1000' - - keyword: FREQUENCY - - comparison_operator: - - raw_comparison_operator: = - - keyword: NEVER -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: timed_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '100' - - keyword: START_TIMESTAMP - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''2024-01-01 00:00:00''' -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: immediate_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '100' - - keyword: START_TIMESTAMP - - comparison_operator: - - raw_comparison_operator: = - - keyword: IMMEDIATELY -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: limited_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '100' - - keyword: END_TIMESTAMP - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''2024-12-31 23:59:59''' -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: notify_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '100' - - keyword: NOTIFY_USERS - - comparison_operator: - - raw_comparison_operator: = - - bracketed: - - start_bracket: ( - - naked_identifier: user1 - - comma: ',' - - naked_identifier: user2 - - comma: ',' - - naked_identifier: user3 - - end_bracket: ) -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: trigger_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '100' - - keyword: TRIGGERS - - keyword: ON - - numeric_literal: '90' - - keyword: PERCENT - - keyword: DO - - keyword: SUSPEND -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: multi_trigger_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1000' - - keyword: TRIGGERS - - keyword: ON - - numeric_literal: '50' - - keyword: PERCENT - - keyword: DO - - keyword: NOTIFY - - keyword: ON - - numeric_literal: '75' - - keyword: PERCENT - - keyword: DO - - keyword: NOTIFY - - keyword: ON - - numeric_literal: '90' - - keyword: PERCENT - - keyword: DO - - keyword: SUSPEND - - keyword: ON - - numeric_literal: '100' - - keyword: PERCENT - - keyword: DO - - keyword: SUSPEND_IMMEDIATE -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: OR - - keyword: REPLACE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: full_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '2000' - - keyword: FREQUENCY - - comparison_operator: - - raw_comparison_operator: = - - keyword: MONTHLY - - keyword: START_TIMESTAMP - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''2024-01-01 00:00:00''' - - keyword: END_TIMESTAMP - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''2024-12-31 23:59:59''' - - keyword: NOTIFY_USERS - - comparison_operator: - - raw_comparison_operator: = - - bracketed: - - start_bracket: ( - - naked_identifier: admin - - comma: ',' - - naked_identifier: finance_team - - end_bracket: ) - - keyword: TRIGGERS - - keyword: ON - - numeric_literal: '60' - - keyword: PERCENT - - keyword: DO - - keyword: NOTIFY - - keyword: ON - - numeric_literal: '80' - - keyword: PERCENT - - keyword: DO - - keyword: SUSPEND - - keyword: ON - - numeric_literal: '95' - - keyword: PERCENT - - keyword: DO - - keyword: SUSPEND_IMMEDIATE -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: OR - - keyword: REPLACE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: replaced_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '300' -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: my_schema - - dot: . - - naked_identifier: my_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '100' -- statement_terminator: ; -- statement: - - keyword: CREATE - - keyword: RESOURCE - - keyword: MONITOR - - object_reference: - - naked_identifier: my_db - - dot: . - - naked_identifier: my_schema - - dot: . - - naked_identifier: my_monitor - - keyword: WITH - - keyword: CREDIT_QUOTA - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '100' + - create_statement: + - keyword: create + - keyword: resource + - keyword: monitor + - keyword: if + - keyword: not + - keyword: exists + - object_reference: + - naked_identifier: test +- statement_terminator: ; +- statement: + - create_resource_monitor_statement: + - keyword: create + - keyword: or + - keyword: replace + - keyword: resource + - keyword: monitor + - object_reference: + - naked_identifier: limiter + - keyword: with + - resource_monitor_options: + - keyword: credit_quota + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' +- statement_terminator: ; +- statement: + - create_resource_monitor_statement: + - keyword: create + - keyword: or + - keyword: replace + - keyword: resource + - keyword: monitor + - object_reference: + - naked_identifier: test + - keyword: with + - resource_monitor_options: + - keyword: frequency + - comparison_operator: + - raw_comparison_operator: = + - keyword: monthly +- statement_terminator: ; +- statement: + - create_resource_monitor_statement: + - keyword: create + - keyword: or + - keyword: replace + - keyword: resource + - keyword: monitor + - object_reference: + - naked_identifier: limiter + - keyword: with + - resource_monitor_options: + - keyword: start_timestamp + - comparison_operator: + - raw_comparison_operator: = + - keyword: immediately +- statement_terminator: ; +- statement: + - create_resource_monitor_statement: + - keyword: create + - keyword: or + - keyword: replace + - keyword: resource + - keyword: monitor + - object_reference: + - naked_identifier: limiter + - keyword: with + - resource_monitor_options: + - keyword: start_timestamp + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2038-01-19 03:14:07''' +- statement_terminator: ; +- statement: + - create_resource_monitor_statement: + - keyword: create + - keyword: or + - keyword: replace + - keyword: resource + - keyword: monitor + - object_reference: + - naked_identifier: limiter + - keyword: with + - resource_monitor_options: + - keyword: credit_quota + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '100' + - keyword: NOTIFY_USERS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: joe + - comma: ',' + - object_reference: + - quoted_identifier: '"sara"' + - comma: ',' + - object_reference: + - quoted_identifier: '"ashlee"' + - end_bracket: ) + - keyword: start_timestamp + - comparison_operator: + - raw_comparison_operator: = + - keyword: immediately + - keyword: end_timestamp + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''2038-01-19 03:14:07''' +- statement_terminator: ; +- statement: + - create_resource_monitor_statement: + - keyword: create + - keyword: or + - keyword: replace + - keyword: resource + - keyword: monitor + - object_reference: + - naked_identifier: limiter + - keyword: with + - resource_monitor_options: + - keyword: credit_quota + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '5000' + - keyword: notify_users + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: jdoe + - comma: ',' + - object_reference: + - quoted_identifier: '"jane smith"' + - comma: ',' + - object_reference: + - quoted_identifier: '"john doe"' + - end_bracket: ) + - keyword: triggers + - keyword: on + - integer_literal: '75' + - keyword: percent + - keyword: do + - keyword: notify + - keyword: on + - integer_literal: '100' + - keyword: percent + - keyword: do + - keyword: suspend + - keyword: on + - integer_literal: '110' + - keyword: percent + - keyword: do + - keyword: suspend_immediate - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_role.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_role.sql index 5ea8b5b76..3abbed35c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_role.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_role.sql @@ -1,3 +1,4 @@ CREATE ROLE MY_ROLE; CREATE ROLE "my_role"; -CREATE OR REPLACE ROLE IF NOT EXISTS foo_role COMMENT = 'this is a fake role' +CREATE OR REPLACE ROLE IF NOT EXISTS foo_role COMMENT = 'this is a fake role'; +CREATE OR ALTER ROLE MY_ROLE; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_role.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_role.yml index 5d76e279b..0972a75e0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_role.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_role.yml @@ -24,7 +24,18 @@ file: - keyword: EXISTS - role_reference: - naked_identifier: foo_role - - keyword: COMMENT - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''this is a fake role''' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''this is a fake role''' +- statement_terminator: ; +- statement: + - create_role_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: ROLE + - role_reference: + - naked_identifier: MY_ROLE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_row_access_policy.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_row_access_policy.sql new file mode 100644 index 000000000..e1cda0837 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_row_access_policy.sql @@ -0,0 +1,29 @@ +CREATE ROW ACCESS POLICY IF NOT EXISTS my_access_policy AS( + TEXT VARCHAR +) RETURNS BOOLEAN -> FALSE; + +CREATE OR REPLACE ROW ACCESS POLICY my_access_policy AS( + val VARCHAR +) RETURNS BOOLEAN -> TRUE; + +CREATE OR REPLACE ROW ACCESS POLICY IF NOT EXISTS my_access_policy AS( + val VARCHAR +) RETURNS BOOLEAN -> TRUE; + +CREATE OR REPLACE ROW ACCESS POLICY IF NOT EXISTS my_access_policy AS( + val VARCHAR +) RETURNS BOOLEAN -> TRUE COMMENT += 'My Comment'; + +CREATE ROW ACCESS POLICY my_access_policy AS( + val VARCHAR +) RETURNS BOOLEAN -> TRUE; + +CREATE ROW ACCESS POLICY my_access_policy AS( + val VARCHAR +) RETURNS BOOLEAN -> TRUE COMMENT += 'My Comment'; + +CREATE ROW ACCESS POLICY "My-Access-Policy" AS( + val VARCHAR +) RETURNS BOOLEAN -> TRUE; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_row_access_policy.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_row_access_policy.yml new file mode 100644 index 000000000..c6131de97 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_row_access_policy.yml @@ -0,0 +1,173 @@ +file: +- statement: + - create_row_access_policy_statement: + - keyword: CREATE + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - naked_identifier: my_access_policy + - keyword: AS + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: TEXT + - data_type: + - data_type_identifier: VARCHAR + - end_bracket: ) + - keyword: RETURNS + - keyword: BOOLEAN + - function_assigner: -> + - expression: + - boolean_literal: 'FALSE' +- statement_terminator: ; +- statement: + - create_row_access_policy_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - naked_identifier: my_access_policy + - keyword: AS + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: val + - data_type: + - data_type_identifier: VARCHAR + - end_bracket: ) + - keyword: RETURNS + - keyword: BOOLEAN + - function_assigner: -> + - expression: + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - create_row_access_policy_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - naked_identifier: my_access_policy + - keyword: AS + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: val + - data_type: + - data_type_identifier: VARCHAR + - end_bracket: ) + - keyword: RETURNS + - keyword: BOOLEAN + - function_assigner: -> + - expression: + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - create_row_access_policy_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - naked_identifier: my_access_policy + - keyword: AS + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: val + - data_type: + - data_type_identifier: VARCHAR + - end_bracket: ) + - keyword: RETURNS + - keyword: BOOLEAN + - function_assigner: -> + - expression: + - boolean_literal: 'TRUE' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''My Comment''' +- statement_terminator: ; +- statement: + - create_row_access_policy_statement: + - keyword: CREATE + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - naked_identifier: my_access_policy + - keyword: AS + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: val + - data_type: + - data_type_identifier: VARCHAR + - end_bracket: ) + - keyword: RETURNS + - keyword: BOOLEAN + - function_assigner: -> + - expression: + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - create_row_access_policy_statement: + - keyword: CREATE + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - naked_identifier: my_access_policy + - keyword: AS + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: val + - data_type: + - data_type_identifier: VARCHAR + - end_bracket: ) + - keyword: RETURNS + - keyword: BOOLEAN + - function_assigner: -> + - expression: + - boolean_literal: 'TRUE' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''My Comment''' +- statement_terminator: ; +- statement: + - create_row_access_policy_statement: + - keyword: CREATE + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - quoted_identifier: '"My-Access-Policy"' + - keyword: AS + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: val + - data_type: + - data_type_identifier: VARCHAR + - end_bracket: ) + - keyword: RETURNS + - keyword: BOOLEAN + - function_assigner: -> + - expression: + - boolean_literal: 'TRUE' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_schema.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_schema.sql index e61779f93..b16685dcb 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_schema.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_schema.sql @@ -5,3 +5,6 @@ create schema mytestschema comment = 'My test schema.'; create schema mytestschema tag (tag1 = 'foo', tag2 = 'bar'); create schema mytestschema with managed access; create transient schema if not exists mytestschema default_ddl_collation = 'de_DE'; +CREATE SCHEMA MYDB.MYSCHEMA COMMENT = "Space for landing my data"; +CREATE SCHEMA IF NOT EXISTS MYDB.MYSCHEMA COMMENT = "Space for landing my data"; +CREATE OR ALTER SCHEMA MYDB.MYSCHEMA; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_schema.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_schema.yml index 7c0cd453c..79e11d788 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_schema.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_schema.yml @@ -58,9 +58,8 @@ file: - create_schema_statement: - keyword: create - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: mytestschema + - schema_reference: + - naked_identifier: mytestschema - schema_object_properties: - comment_equals_clause: - keyword: comment @@ -72,9 +71,8 @@ file: - create_schema_statement: - keyword: create - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: mytestschema + - schema_reference: + - naked_identifier: mytestschema - tag_bracketed_equals: - keyword: tag - bracketed: @@ -96,9 +94,8 @@ file: - create_schema_statement: - keyword: create - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: mytestschema + - schema_reference: + - naked_identifier: mytestschema - keyword: with - keyword: managed - keyword: access @@ -111,12 +108,55 @@ file: - keyword: if - keyword: not - keyword: exists - - table_reference: - - object_reference: - - naked_identifier: mytestschema + - schema_reference: + - naked_identifier: mytestschema - schema_object_properties: - keyword: default_ddl_collation - comparison_operator: - raw_comparison_operator: = - quoted_literal: '''de_DE''' - statement_terminator: ; +- statement: + - create_schema_statement: + - keyword: CREATE + - keyword: SCHEMA + - schema_reference: + - naked_identifier: MYDB + - dot: . + - naked_identifier: MYSCHEMA + - schema_object_properties: + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"Space for landing my data"' +- statement_terminator: ; +- statement: + - create_schema_statement: + - keyword: CREATE + - keyword: SCHEMA + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - schema_reference: + - naked_identifier: MYDB + - dot: . + - naked_identifier: MYSCHEMA + - schema_object_properties: + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"Space for landing my data"' +- statement_terminator: ; +- statement: + - create_schema_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: SCHEMA + - schema_reference: + - naked_identifier: MYDB + - dot: . + - naked_identifier: MYSCHEMA +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_sequence.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_sequence.yml index 41e4baa32..f544aebf4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_sequence.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_sequence.yml @@ -3,7 +3,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: seq - statement_terminator: ; - statement: @@ -15,7 +15,7 @@ file: - keyword: IF - keyword: NOT - keyword: EXISTS - - column_reference: + - sequence_reference: - naked_identifier: seq - keyword: WITH - keyword: START @@ -44,7 +44,7 @@ file: - keyword: IF - keyword: NOT - keyword: EXISTS - - column_reference: + - sequence_reference: - naked_identifier: seq - keyword: START - comparison_operator: @@ -60,7 +60,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: seq - keyword: START - integer_literal: '2' @@ -69,7 +69,7 @@ file: - create_sequence_statement: - keyword: CREATE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: seq - keyword: INCREMENT - integer_literal: '2' diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_stage.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_stage.sql index 1f4670a32..ffaf58c63 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_stage.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_stage.sql @@ -80,3 +80,59 @@ CREATE OR REPLACE STAGE foo.bar STORAGE_INTEGRATION = foo FILE_FORMAT = (FORMAT_NAME = foo.bar.baz) ; + +CREATE OR REPLACE STAGE your_stage_name + URL = 's3://your_s3_bucket/your_path_in_s3'; + +CREATE OR REPLACE STAGE your_stage_name + URL = 's3://your-s3-bucket/your-path-in-s3'; + +CREATE STAGE mystage + URL=$your_variable + CREDENTIALS=(AZURE_SAS_TOKEN=$your_variable); + +CREATE STAGE mystage + URL=$your_variable + STORAGE_INTEGRATION=$your_variable; + +CREATE OR REPLACE STAGE foo.bar + URL = 's3://foobar' + STORAGE_INTEGRATION = foo + FILE_FORMAT = ( + TYPE = CSV + PARSE_HEADER = TRUE + ); + +CREATE OR ALTER STAGE foo.bar + URL = 's3://foobar'; + +CREATE STAGE foo.bar + STORAGE_INTEGRATION=$your_variable + URL=$your_variable; + +CREATE OR REPLACE STAGE foo.bar + STORAGE_INTEGRATION = foo + URL = 's3://foobar' + FILE_FORMAT = ( + TYPE = CSV + PARSE_HEADER = TRUE + ); + +CREATE STAGE my_ext_stage + STORAGE_INTEGRATION = myint + URL='azure://myaccount.blob.core.windows.net/load/files/'; + +CREATE STAGE mystage + CREDENTIALS=(AZURE_SAS_TOKEN='?sv=2016-05-31&ss=b&srt=sco&sp=rwdl&se=2018-06-27T10:05:50Z&st=2017-06-27T02:05:50Z&spr=https,http&sig=bgqQwoXwxzuD2GJfagRg7VOS8hzNr3QLT7rhS8OFRLQ%3D') + ENCRYPTION=(TYPE='AZURE_CSE' MASTER_KEY = 'kPxX0jzYfIamtnJEUTHwq80Au6NbSgPH5r4BDDwOaO8=') + URL='azure://myaccount.blob.core.windows.net/mycontainer/files/' + FILE_FORMAT = my_csv_format; + +CREATE STAGE mystage + STORAGE_INTEGRATION = my_storage_int + DIRECTORY = ( + ENABLE = true + AUTO_REFRESH = true + NOTIFICATION_INTEGRATION = 'MY_NOTIFICATION_INT' + ) + URL='azure://myaccount.blob.core.windows.net/load/files/'; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_stage.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_stage.yml index ae284ecf1..583776f6f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_stage.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_stage.yml @@ -101,7 +101,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''s3://load/files/''' - - s3_external_stage_parameters: + - stage_parameters: - keyword: STORAGE_INTEGRATION - comparison_operator: - raw_comparison_operator: = @@ -118,7 +118,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''s3://load''' - - s3_external_stage_parameters: + - stage_parameters: - keyword: STORAGE_INTEGRATION - comparison_operator: - raw_comparison_operator: = @@ -135,7 +135,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''s3://load/''' - - s3_external_stage_parameters: + - stage_parameters: - keyword: STORAGE_INTEGRATION - comparison_operator: - raw_comparison_operator: = @@ -152,7 +152,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''s3://load/files''' - - s3_external_stage_parameters: + - stage_parameters: - keyword: STORAGE_INTEGRATION - comparison_operator: - raw_comparison_operator: = @@ -169,7 +169,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''s3://load/files/''' - - s3_external_stage_parameters: + - stage_parameters: - keyword: CREDENTIALS - comparison_operator: - raw_comparison_operator: = @@ -195,7 +195,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''s3://load/encrypted_files/''' - - s3_external_stage_parameters: + - stage_parameters: - keyword: CREDENTIALS - comparison_operator: - raw_comparison_operator: = @@ -231,7 +231,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''s3://load/encrypted_files/''' - - s3_external_stage_parameters: + - stage_parameters: - keyword: CREDENTIALS - comparison_operator: - raw_comparison_operator: = @@ -271,7 +271,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''s3://load/encrypted_files/''' - - s3_external_stage_parameters: + - stage_parameters: - keyword: CREDENTIALS - comparison_operator: - raw_comparison_operator: = @@ -307,7 +307,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''s3://load/files/''' - - s3_external_stage_parameters: + - stage_parameters: - keyword: STORAGE_INTEGRATION - comparison_operator: - raw_comparison_operator: = @@ -338,7 +338,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''gcs://load/files/''' - - gcs_external_stage_parameters: + - stage_parameters: - keyword: STORAGE_INTEGRATION - comparison_operator: - raw_comparison_operator: = @@ -355,7 +355,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''gcs://load/files/''' - - gcs_external_stage_parameters: + - stage_parameters: - keyword: STORAGE_INTEGRATION - comparison_operator: - raw_comparison_operator: = @@ -390,7 +390,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''azure://myaccount.blob.core.windows.net/load/files/''' - - azure_blob_storage_external_stage_parameters: + - stage_parameters: - keyword: STORAGE_INTEGRATION - comparison_operator: - raw_comparison_operator: = @@ -407,7 +407,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''azure://myaccount.blob.core.windows.net/mycontainer/files/''' - - azure_blob_storage_external_stage_parameters: + - stage_parameters: - keyword: CREDENTIALS - comparison_operator: - raw_comparison_operator: = @@ -449,7 +449,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''azure://myaccount.blob.core.windows.net/load/files/''' - - azure_blob_storage_external_stage_parameters: + - stage_parameters: - keyword: STORAGE_INTEGRATION - comparison_operator: - raw_comparison_operator: = @@ -488,7 +488,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''s3://foobar''' - - s3_external_stage_parameters: + - stage_parameters: - keyword: STORAGE_INTEGRATION - comparison_operator: - raw_comparison_operator: = @@ -519,7 +519,7 @@ file: - comparison_operator: - raw_comparison_operator: = - bucket_path: '''s3://foobar''' - - s3_external_stage_parameters: + - stage_parameters: - keyword: STORAGE_INTEGRATION - comparison_operator: - raw_comparison_operator: = @@ -542,3 +542,270 @@ file: - naked_identifier: baz - end_bracket: ) - statement_terminator: ; +- statement: + - create_stage_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: STAGE + - object_reference: + - naked_identifier: your_stage_name + - keyword: URL + - comparison_operator: + - raw_comparison_operator: = + - bucket_path: '''s3://your_s3_bucket/your_path_in_s3''' +- statement_terminator: ; +- statement: + - create_stage_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: STAGE + - object_reference: + - naked_identifier: your_stage_name + - keyword: URL + - comparison_operator: + - raw_comparison_operator: = + - bucket_path: '''s3://your-s3-bucket/your-path-in-s3''' +- statement_terminator: ; +- statement: + - create_stage_statement: + - keyword: CREATE + - keyword: STAGE + - object_reference: + - naked_identifier: mystage + - keyword: URL + - comparison_operator: + - raw_comparison_operator: = + - variable: $your_variable + - stage_parameters: + - keyword: CREDENTIALS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: AZURE_SAS_TOKEN + - comparison_operator: + - raw_comparison_operator: = + - variable: $your_variable + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_stage_statement: + - keyword: CREATE + - keyword: STAGE + - object_reference: + - naked_identifier: mystage + - keyword: URL + - comparison_operator: + - raw_comparison_operator: = + - variable: $your_variable + - stage_parameters: + - keyword: STORAGE_INTEGRATION + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - variable: $your_variable +- statement_terminator: ; +- statement: + - create_stage_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: STAGE + - object_reference: + - naked_identifier: foo + - dot: . + - naked_identifier: bar + - keyword: URL + - comparison_operator: + - raw_comparison_operator: = + - bucket_path: '''s3://foobar''' + - stage_parameters: + - keyword: STORAGE_INTEGRATION + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: foo + - keyword: FILE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - file_format_segment: + - bracketed: + - start_bracket: ( + - csv_file_format_type_parameters: + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - file_type: CSV + - keyword: PARSE_HEADER + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_stage_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: STAGE + - object_reference: + - naked_identifier: foo + - dot: . + - naked_identifier: bar + - keyword: URL + - comparison_operator: + - raw_comparison_operator: = + - bucket_path: '''s3://foobar''' +- statement_terminator: ; +- statement: + - create_stage_statement: + - keyword: CREATE + - keyword: STAGE + - object_reference: + - naked_identifier: foo + - dot: . + - naked_identifier: bar + - stage_parameters: + - keyword: STORAGE_INTEGRATION + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - variable: $your_variable + - keyword: URL + - comparison_operator: + - raw_comparison_operator: = + - variable: $your_variable +- statement_terminator: ; +- statement: + - create_stage_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: STAGE + - object_reference: + - naked_identifier: foo + - dot: . + - naked_identifier: bar + - stage_parameters: + - keyword: STORAGE_INTEGRATION + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: foo + - keyword: URL + - comparison_operator: + - raw_comparison_operator: = + - bucket_path: '''s3://foobar''' + - keyword: FILE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - file_format_segment: + - bracketed: + - start_bracket: ( + - csv_file_format_type_parameters: + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - file_type: CSV + - keyword: PARSE_HEADER + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_stage_statement: + - keyword: CREATE + - keyword: STAGE + - object_reference: + - naked_identifier: my_ext_stage + - stage_parameters: + - keyword: STORAGE_INTEGRATION + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: myint + - keyword: URL + - comparison_operator: + - raw_comparison_operator: = + - bucket_path: '''azure://myaccount.blob.core.windows.net/load/files/''' +- statement_terminator: ; +- statement: + - create_stage_statement: + - keyword: CREATE + - keyword: STAGE + - object_reference: + - naked_identifier: mystage + - stage_parameters: + - keyword: CREDENTIALS + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: AZURE_SAS_TOKEN + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''?sv=2016-05-31&ss=b&srt=sco&sp=rwdl&se=2018-06-27T10:05:50Z&st=2017-06-27T02:05:50Z&spr=https,http&sig=bgqQwoXwxzuD2GJfagRg7VOS8hzNr3QLT7rhS8OFRLQ%3D''' + - end_bracket: ) + - keyword: ENCRYPTION + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: TYPE + - comparison_operator: + - raw_comparison_operator: = + - stage_encryption_option: '''AZURE_CSE''' + - keyword: MASTER_KEY + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''kPxX0jzYfIamtnJEUTHwq80Au6NbSgPH5r4BDDwOaO8=''' + - end_bracket: ) + - keyword: URL + - comparison_operator: + - raw_comparison_operator: = + - bucket_path: '''azure://myaccount.blob.core.windows.net/mycontainer/files/''' + - keyword: FILE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - file_format_segment: + - object_reference: + - naked_identifier: my_csv_format +- statement_terminator: ; +- statement: + - create_stage_statement: + - keyword: CREATE + - keyword: STAGE + - object_reference: + - naked_identifier: mystage + - stage_parameters: + - keyword: STORAGE_INTEGRATION + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_storage_int + - keyword: DIRECTORY + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: ENABLE + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'true' + - keyword: AUTO_REFRESH + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'true' + - keyword: NOTIFICATION_INTEGRATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''MY_NOTIFICATION_INT''' + - end_bracket: ) + - keyword: URL + - comparison_operator: + - raw_comparison_operator: = + - bucket_path: '''azure://myaccount.blob.core.windows.net/load/files/''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_storage_integration.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_storage_integration.sql index b2bf42437..abe5cf2bd 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_storage_integration.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_storage_integration.sql @@ -66,4 +66,6 @@ create storage integration azure_int storage_provider = 'azure' enabled = true azure_tenant_id = '' - storage_allowed_locations = ('azure://myaccount.blob.core.windows.net/mycontainer/path1/', 'azure://myaccount.blob.core.windows.net/mycontainer/path2/'); + storage_allowed_locations = ('azure://myaccount.blob.core.windows.net/mycontainer/path1/', 'azure://myaccount.blob.core.windows.net/mycontainer/path2/') + use_privatelink_endpoint = false; + ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_storage_integration.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_storage_integration.yml index ef5091140..a877f6c47 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_storage_integration.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_storage_integration.yml @@ -343,4 +343,9 @@ file: - comma: ',' - bucket_path: '''azure://myaccount.blob.core.windows.net/mycontainer/path2/''' - end_bracket: ) + - keyword: use_privatelink_endpoint + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'false' +- statement_terminator: ; - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_streamlit.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_streamlit.sql new file mode 100644 index 000000000..b9cb0dcff --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_streamlit.sql @@ -0,0 +1,34 @@ +CREATE STREAMLIT new_streamlit +ROOT_LOCATION = '@stage_name/folder' +MAIN_FILE = 'main.py'; + +CREATE OR REPLACE STREAMLIT new_streamlit +ROOT_LOCATION = '@stage_name/folder' +MAIN_FILE = 'main.py'; + +CREATE STREAMLIT new_streamlit +ROOT_LOCATION = '@stage_name/folder' +MAIN_FILE = 'main.py' +QUERY_WAREHOUSE = my_wh; + +CREATE OR REPLACE STREAMLIT new_streamlit +ROOT_LOCATION = '@stage_name/folder' +MAIN_FILE = 'main.py' +QUERY_WAREHOUSE = my_wh; + +CREATE STREAMLIT new_streamlit +ROOT_LOCATION = '@stage_name/folder' +MAIN_FILE = 'main.py' +QUERY_WAREHOUSE = my_wh +COMMENT = 'amazing comment'; + +CREATE OR REPLACE STREAMLIT new_streamlit +ROOT_LOCATION = '@stage_name/folder' +MAIN_FILE = 'main.py' +QUERY_WAREHOUSE = my_wh +COMMENT = 'amazing comment'; + +CREATE STREAMLIT new_streamlit +ROOT_LOCATION = '@stage_name/folder' +MAIN_FILE = 'main.py' +TITLE = 'amazing title'; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_streamlit.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_streamlit.yml new file mode 100644 index 000000000..005dfbe17 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_streamlit.yml @@ -0,0 +1,146 @@ +file: +- statement: + - create_streamlit_statement: + - keyword: CREATE + - keyword: STREAMLIT + - object_reference: + - naked_identifier: new_streamlit + - keyword: ROOT_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - stage_path: '''@stage_name/folder''' + - keyword: MAIN_FILE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''main.py''' +- statement_terminator: ; +- statement: + - create_streamlit_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: STREAMLIT + - object_reference: + - naked_identifier: new_streamlit + - keyword: ROOT_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - stage_path: '''@stage_name/folder''' + - keyword: MAIN_FILE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''main.py''' +- statement_terminator: ; +- statement: + - create_streamlit_statement: + - keyword: CREATE + - keyword: STREAMLIT + - object_reference: + - naked_identifier: new_streamlit + - keyword: ROOT_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - stage_path: '''@stage_name/folder''' + - keyword: MAIN_FILE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''main.py''' + - keyword: QUERY_WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_wh +- statement_terminator: ; +- statement: + - create_streamlit_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: STREAMLIT + - object_reference: + - naked_identifier: new_streamlit + - keyword: ROOT_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - stage_path: '''@stage_name/folder''' + - keyword: MAIN_FILE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''main.py''' + - keyword: QUERY_WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_wh +- statement_terminator: ; +- statement: + - create_streamlit_statement: + - keyword: CREATE + - keyword: STREAMLIT + - object_reference: + - naked_identifier: new_streamlit + - keyword: ROOT_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - stage_path: '''@stage_name/folder''' + - keyword: MAIN_FILE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''main.py''' + - keyword: QUERY_WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_wh + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''amazing comment''' +- statement_terminator: ; +- statement: + - create_streamlit_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: STREAMLIT + - object_reference: + - naked_identifier: new_streamlit + - keyword: ROOT_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - stage_path: '''@stage_name/folder''' + - keyword: MAIN_FILE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''main.py''' + - keyword: QUERY_WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_wh + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''amazing comment''' +- statement_terminator: ; +- statement: + - create_streamlit_statement: + - keyword: CREATE + - keyword: STREAMLIT + - object_reference: + - naked_identifier: new_streamlit + - keyword: ROOT_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - stage_path: '''@stage_name/folder''' + - keyword: MAIN_FILE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''main.py''' + - keyword: TITLE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''amazing title''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_table.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_table.sql index f3a22262a..96299ad0f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_table.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_table.sql @@ -60,6 +60,7 @@ create table collation_demo ( spanish_phrase varchar collate 'sp' ); +create table t2 as select col1 collate 'fr' as col1 from t1; create table mytable using template ( @@ -99,3 +100,258 @@ CREATE TABLE my_table ( foo TIMESTAMP_NTZ DEFAULT CURRENT_TIMESTAMP::TIMESTAMP_NTZ ) ; + +CREATE TABLE IF NOT EXISTS EXAMPLE_TABLE +( + EXAMPLE VARCHAR AUTOINCREMENT START 1 INCREMENT 1 ORDER +); + +CREATE TABLE IF NOT EXISTS EXAMPLE_TABLE +( + EXAMPLE VARCHAR AUTOINCREMENT START 1 INCREMENT 1 NOORDER +); + +CREATE OR REPLACE DYNAMIC TABLE names +TARGET_LAG = '1 minute' +WAREHOUSE = mywh +AS +SELECT var:id::int id, var:fname::string first_name, +var:lname::string last_name FROM raw; + +CREATE OR REPLACE DYNAMIC TABLE names +TARGET_LAG = '1 minute' +REFRESH_MODE = AUTO +INITIALIZE = ON_CREATE +WAREHOUSE = mywh +AS +SELECT var:id::int id, var:fname::string first_name, +var:lname::string last_name FROM raw; + +CREATE OR REPLACE DYNAMIC TABLE DT_WITH_DOWNSTREAM_LAG +TARGET_LAG = DOWNSTREAM +WAREHOUSE = mywh +AS +SELECT * FROM my_table; + +CREATE OR REPLACE DYNAMIC TABLE DT_WITH_DOWNSTREAM_QUOTED_LITERAL_LAG +TARGET_LAG = 'DOWNSTREAM' +WAREHOUSE = mywh +AS +SELECT * FROM my_table; + +CREATE OR REPLACE DYNAMIC TABLE DT_WITH_SINGLE_SECOND_LAG +TARGET_LAG = '1 second' +WAREHOUSE = mywh +AS +SELECT * FROM my_table; + +CREATE OR REPLACE DYNAMIC TABLE DT_WITH_MULTIPLE_SECONDS_LAG +TARGET_LAG = '5 seconds' +WAREHOUSE = mywh +AS +SELECT * FROM my_table; + +CREATE OR REPLACE DYNAMIC TABLE DT_WITH_SINGLE_MINUTE_LAG +TARGET_LAG = '1 minute' +WAREHOUSE = mywh +AS +SELECT * FROM my_table; + +CREATE OR REPLACE DYNAMIC TABLE DT_WITH_MULTIPLE_MINUTES_LAG +TARGET_LAG = '5 minutes' +WAREHOUSE = mywh +AS +SELECT * FROM my_table; + +CREATE OR REPLACE DYNAMIC TABLE DT_WITH_SINGLE_HOUR_LAG +TARGET_LAG = '1 hour' +WAREHOUSE = mywh +AS +SELECT * FROM my_table; + +CREATE OR REPLACE DYNAMIC TABLE DT_WITH_MULTIPLE_HOURS_LAG +TARGET_LAG = '5 hours' +WAREHOUSE = mywh +AS +SELECT * FROM my_table; + +CREATE OR REPLACE DYNAMIC TABLE DT_WITH_SINGLE_DAY_LAG +TARGET_LAG = '1 day' +WAREHOUSE = mywh +AS +SELECT * FROM my_table; + +CREATE OR REPLACE DYNAMIC TABLE my_table +TARGET_LAG = '5 days' +WAREHOUSE = mywh +AS +SELECT * FROM my_table; + +CREATE OR REPLACE DYNAMIC TABLE my_table +TARGET_LAG = '${my_time_variable}' +WAREHOUSE = mywh +AS +SELECT * FROM my_table; + +CREATE OR REPLACE TABLE IF NOT EXISTS EXAMPLE_TABLE_WITH_RLS ( + EXAMPLE VARCHAR + ) WITH ROW ACCESS POLICY my_db.my_schema.rls_policy ON (EXAMPLE); + +CREATE OR REPLACE TABLE IF NOT EXISTS EXAMPLE_TABLE_WITH_RLS ( + EXAMPLE VARCHAR +) WITH ROW ACCESS POLICY rls_policy ON (EXAMPLE); + +CREATE TABLE IDENTIFIER(:SOME_TABLE) (AMOUNT NUMBER); + +CREATE OR REPLACE TEMP TABLE mytable ( + id INTEGER NOT NULL PRIMARY KEY ENABLE ENFORCED VALIDATE RELY +); + +CREATE OR REPLACE TABLE myschema.mytable ( + id INTEGER NOT NULL + , CONSTRAINT mytable_pk PRIMARY KEY (id) NOT ENFORCED NOVALIDATE NORELY +); + +CREATE TABLE some_schema.some_table +( + is_condition_true BOOLEAN + , some_text_value VARCHAR(100) + , some_event_date_time_utc VARCHAR AS (TO_TIMESTAMP(SUBSTR(some_text_value, 5, 13))) + , some_other_event_date_time_utc TIMESTAMP AS (IFF(is_condition_true AND TRY_TO_NUMBER(some_text_value) IS NOT NULL, TO_TIMESTAMP(SUBSTR(some_text_value, 5, 13)), '1900-01-01')) COMMENT 'The date and time of the other event' +); + + +CREATE OR REPLACE TABLE some_table ( + id INTEGER NOT NULL, + CONSTRAINT MY_FK FOREIGN KEY (id) REFERENCES another_table(id) MATCH SIMPLE ON DELETE RESTRICT +); + +CREATE OR REPLACE TABLE some_table ( + id INTEGER NOT NULL, + CONSTRAINT MY_FK FOREIGN KEY (id) REFERENCES another_table MATCH FULL ON DELETE RESTRICT +); + + +CREATE OR REPLACE TABLE some_table ( + ID INTEGER NOT NULL CONSTRAINT MY_FK + FOREIGN KEY REFERENCES another_table (id) + MATCH PARTIAL + ON DELETE RESTRICT + ON UPDATE SET DEFAULT +); + +CREATE OR REPLACE TABLE some_table ( + ID INTEGER NOT NULL, + CONSTRAINT MY_FK FOREIGN KEY (ID) REFERENCES another_table (id) + MATCH SIMPLE + ON DELETE CASCADE +); + +CREATE OR ALTER TABLE some_table ( + id INTEGER NOT NULL +); + +CREATE OR ALTER TABLE some_table ( + id INTEGER NOT NULL +) +DEFAULT_DDL_COLLATION = 'fr'; + +-- Iceberg tables + +CREATE ICEBERG TABLE db.archival.iceberg_report_invoicesummary + ( + _v string, + partition_date date, + clientid string, + invoiceclientid string + ) + EXTERNAL_VOLUME='iceberg_ext_vol' + CATALOG='SNOWFLAKE' + BASE_LOCATION ='report_invoicesummary'; + +CREATE ICEBERG TABLE iceberg1 + ( + value string, + partition_date date, + clientid string, + amount INTEGER + ) +CLUSTER BY amount +EXTERNAL_VOLUME = '' +CATALOG = 'SNOWFLAKE' +BASE_LOCATION = '' +COPY GRANTS +AS SELECT * from example; + +CREATE ICEBERG TABLE iceberg2 LIKE example +CLUSTER BY (amount) (amount number) +COPY GRANTS; + +CREATE ICEBERG TABLE iceberg_glue +EXTERNAL_VOLUME = '' +CATALOG = '' +CATALOG_TABLE_NAME = '''' + - keyword: CATALOG + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''SNOWFLAKE''' + - keyword: BASE_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: COPY + - keyword: GRANTS + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: example +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: ICEBERG + - keyword: TABLE + - table_reference: + - naked_identifier: iceberg2 + - keyword: LIKE + - table_reference: + - naked_identifier: example + - keyword: CLUSTER + - keyword: BY + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: amount + - end_bracket: ) + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: amount + - data_type: + - data_type_identifier: number + - end_bracket: ) + - keyword: COPY + - keyword: GRANTS +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: ICEBERG + - keyword: TABLE + - table_reference: + - naked_identifier: iceberg_glue + - iceberg_table_options: + - keyword: EXTERNAL_VOLUME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: CATALOG + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: CATALOG_TABLE_NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: REPLACE_INVALID_CHARACTERS + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - keyword: AUTO_REFRESH + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'FALSE' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - dynamic_table_options: + - tag_bracketed_equals: + - keyword: WITH + - keyword: TAG + - bracketed: + - start_bracket: ( + - tag_reference: + - naked_identifier: tag1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''r''' + - comma: ',' + - tag_reference: + - naked_identifier: tag2 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''rr''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: ICEBERG + - keyword: TABLE + - table_reference: + - naked_identifier: iceberg_object_storage + - iceberg_table_options: + - keyword: EXTERNAL_VOLUME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: CATALOG + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: METADATA_FILE_PATH + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: REPLACE_INVALID_CHARACTERS + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'false' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: ICEBERG + - keyword: TABLE + - table_reference: + - naked_identifier: iceberg_object_delta + - iceberg_table_options: + - keyword: BASE_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: ICEBERG + - keyword: TABLE + - table_reference: + - naked_identifier: iceberg_object_snowflake_open_catalog + - iceberg_table_options: + - keyword: CATALOG_TABLE_NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: HYBRID + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: NUMBER + - column_constraint_segment: + - constraint_properties_segment: + - keyword: PRIMARY + - keyword: KEY + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: HYBRID + - keyword: TABLE + - table_reference: + - naked_identifier: ref_hybrid_table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '32' + - end_bracket: ) + - column_constraint_segment: + - constraint_properties_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - data_type_identifier: NUMBER + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '38' + - comma: ',' + - numeric_literal: '0' + - end_bracket: ) + - column_constraint_segment: + - constraint_properties_segment: + - keyword: UNIQUE + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: HYBRID + - keyword: TABLE + - table_reference: + - naked_identifier: fk_hybrid_table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '32' + - end_bracket: ) + - column_constraint_segment: + - constraint_properties_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - data_type_identifier: NUMBER + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '38' + - comma: ',' + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col3 + - data_type: + - data_type_identifier: NUMBER + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '38' + - comma: ',' + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - constraint_properties_segment: + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: REFERENCES + - table_reference: + - naked_identifier: ref_hybrid_table + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: INDEX + - data_type: + - data_type_identifier: index_col3 + - bracketed: + - start_bracket: ( + - word: col3 + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: HYBRID + - keyword: TABLE + - table_reference: + - naked_identifier: target_hybrid_table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '32' + - end_bracket: ) + - column_constraint_segment: + - constraint_properties_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - data_type_identifier: NUMBER + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '38' + - comma: ',' + - numeric_literal: '0' + - end_bracket: ) + - column_constraint_segment: + - constraint_properties_segment: + - keyword: UNIQUE + - comma: ',' + - column_definition: + - naked_identifier: col3 + - data_type: + - data_type_identifier: NUMBER + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '38' + - comma: ',' + - numeric_literal: '0' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: INDEX + - data_type: + - data_type_identifier: index_col3 + - bracketed: + - start_bracket: ( + - word: col3 + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col3 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: source_table +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: HYBRID + - keyword: TABLE + - table_reference: + - naked_identifier: dept_employees + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: employee_id + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - constraint_properties_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_definition: + - naked_identifier: department_id + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '200' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: employee_id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: department_id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: company_employees +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: HYBRID + - keyword: TABLE + - table_reference: + - naked_identifier: application_log + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: NUMBER + - column_constraint_segment: + - constraint_properties_segment: + - keyword: PRIMARY + - keyword: KEY + - keyword: AUTOINCREMENT + - comma: ',' + - column_definition: + - naked_identifier: col1 + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '20' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - data_type_identifier: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '20' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: my_schema + - dot: . + - naked_identifier: my_table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: DELTA + - data_type: + - data_type_identifier: INT + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_tag.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_tag.yml index 57abd1237..eb1a70bd2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_tag.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_tag.yml @@ -17,10 +17,11 @@ file: - keyword: TAG - object_reference: - naked_identifier: cost_center - - keyword: COMMENT - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''cost_center tag''' + - comment_equals_clause: + - keyword: COMMENT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''cost_center tag''' - statement_terminator: ; - statement: - create_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_task.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_task.sql index 035518aa0..2d4e7e813 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_task.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_task.sql @@ -93,3 +93,26 @@ WHEN AND 1=1 AS CALL SCH.MY_SPROC(); + +CREATE OR ALTER TASK mytask + WAREHOUSE = mywh +AS + CALL SCH.MY_SPROC(); + +CREATE TASK task5 + AFTER task2, task3, task4 +AS + INSERT INTO t1(ts) VALUES(CURRENT_TIMESTAMP); + +SET custom_warehouse = 'mywh'; +SET custom_schedule = 'USING CRON 15 7 2 * * UTC'; +CREATE OR ALTER TASK mytask + WAREHOUSE = $custom_warehouse + SCHEDULE = $custom_schedule + LOG_LEVEL = TRACE +AS + CALL SCH.MY_SPROC(); + +CREATE TASK mytask +AS + ALTER DYNAMIC TABLE foo REFRESH; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_task.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_task.yml index 8a5481868..a52931028 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_task.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_task.yml @@ -231,7 +231,8 @@ file: - naked_identifier: datetime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: session_id - from_clause: - keyword: FROM @@ -350,7 +351,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: session_id - from_clause: - keyword: FROM @@ -384,7 +386,8 @@ file: - naked_identifier: datetime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v - where_clause: - keyword: WHERE @@ -515,3 +518,135 @@ file: - start_bracket: ( - end_bracket: ) - statement_terminator: ; +- statement: + - create_task_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: TASK + - object_reference: + - naked_identifier: mytask + - keyword: WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: mywh + - keyword: AS + - statement: + - call_segment: + - keyword: CALL + - function: + - function_name: + - naked_identifier: SCH + - dot: . + - function_name_identifier: MY_SPROC + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_task_statement: + - keyword: CREATE + - keyword: TASK + - object_reference: + - naked_identifier: task5 + - keyword: AFTER + - object_reference: + - naked_identifier: task2 + - comma: ',' + - object_reference: + - naked_identifier: task3 + - comma: ',' + - object_reference: + - naked_identifier: task4 + - keyword: AS + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: ts + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - bare_function: CURRENT_TIMESTAMP + - end_bracket: ) +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: custom_warehouse + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''mywh''' +- statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - variable: custom_schedule + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''USING CRON 15 7 2 * * UTC''' +- statement_terminator: ; +- statement: + - create_task_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: TASK + - object_reference: + - naked_identifier: mytask + - keyword: WAREHOUSE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - variable: $custom_warehouse + - keyword: SCHEDULE + - comparison_operator: + - raw_comparison_operator: = + - variable: $custom_schedule + - log_level_equals: + - keyword: LOG_LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: TRACE + - keyword: AS + - statement: + - call_segment: + - keyword: CALL + - function: + - function_name: + - naked_identifier: SCH + - dot: . + - function_name_identifier: MY_SPROC + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_task_statement: + - keyword: CREATE + - keyword: TASK + - object_reference: + - naked_identifier: mytask + - keyword: AS + - statement: + - alter_dynamic_table_statement: + - keyword: ALTER + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - keyword: REFRESH +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_user.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_user.sql index ae275e3a8..f13efc9d6 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_user.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_user.sql @@ -1,4 +1,5 @@ create user user1 + type = person password='abc123' default_role = myrole display_name = user1 @@ -12,6 +13,7 @@ create user user1 must_change_password = true; create user user2 + type = 'service' password='abc123' default_role = 'myrole' display_name = 'user 2' @@ -22,3 +24,30 @@ create user user2 default_warehouse = 'my_default_warehouse' default_namespace = 'my_default_namespace' must_change_password = false; + +create user user3 + type = person + rsa_public_key = '' + default_role = myrole + display_name = user1 + login_name = my_login_name + first_name = User1 + middle_name = abc + last_name = Test1 + default_warehouse = my_default_warehouse + default_namespace = my_default_namespace + default_secondary_roles = ('ALL'); + +create user user4 + type = person + rsa_public_key = '' + rsa_public_key_2 = '' + default_role = myrole + display_name = user1 + login_name = my_login_name + first_name = User1 + middle_name = abc + last_name = Test1 + default_warehouse = my_default_warehouse + default_namespace = my_default_namespace + default_secondary_roles = ('ALL'); diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_user.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_user.yml index cded340cf..bcb59ebe5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_user.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_user.yml @@ -5,6 +5,11 @@ file: - keyword: user - object_reference: - naked_identifier: user1 + - keyword: type + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: person - keyword: password - comparison_operator: - raw_comparison_operator: = @@ -67,6 +72,10 @@ file: - keyword: user - object_reference: - naked_identifier: user2 + - keyword: type + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''service''' - keyword: password - comparison_operator: - raw_comparison_operator: = @@ -108,3 +117,133 @@ file: - raw_comparison_operator: = - boolean_literal: 'false' - statement_terminator: ; +- statement: + - create_user_statement: + - keyword: create + - keyword: user + - object_reference: + - naked_identifier: user3 + - keyword: type + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: person + - keyword: rsa_public_key + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: default_role + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: myrole + - keyword: display_name + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: user1 + - keyword: login_name + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_login_name + - keyword: first_name + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: User1 + - keyword: middle_name + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: abc + - keyword: last_name + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: Test1 + - keyword: default_warehouse + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_default_warehouse + - keyword: default_namespace + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_default_namespace + - keyword: default_secondary_roles + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''ALL''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_user_statement: + - keyword: create + - keyword: user + - object_reference: + - naked_identifier: user4 + - keyword: type + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: person + - keyword: rsa_public_key + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: rsa_public_key_2 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: default_role + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: myrole + - keyword: display_name + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: user1 + - keyword: login_name + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_login_name + - keyword: first_name + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: User1 + - keyword: middle_name + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: abc + - keyword: last_name + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: Test1 + - keyword: default_warehouse + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_default_warehouse + - keyword: default_namespace + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: my_default_namespace + - keyword: default_secondary_roles + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - quoted_literal: '''ALL''' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_view.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_view.sql index 8b6f31b75..9ee858f1f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_view.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_view.sql @@ -22,6 +22,11 @@ WITH TAG (foo = 'bar', hello = 'world') COPY GRANTS AS SELECT col1, col2 FROM src_table; +CREATE OR REPLACE VIEW view_with_tags_and_copy_grants +WITH TAG (foo = "bar", hello = "world") +COPY GRANTS +AS SELECT col1, col2 FROM src_table; + CREATE OR REPLACE VIEW view_with_column_comment ( col1, @@ -50,3 +55,55 @@ CREATE OR REPLACE VIEW vw_appt_latest AS ( ) SELECT * from most_current ); + +CREATE OR REPLACE VIEW IF NOT EXISTS view_with_rls +( + COL1, + COL2 +) WITH ROW ACCESS POLICY my_db.my_schema.my_policy ON (COL1) AS ( + SELECT + COL1, + COL2 + FROM my_table +); + + +CREATE OR REPLACE VIEW IF NOT EXISTS view_with_rls +( + COL1 WITH MASKING POLICY my_db.my_schema.my_policy, + COL2 +) WITH ROW ACCESS POLICY my_db.my_schema.my_policy ON (COL1) AS ( + SELECT + COL1, + COL2 + FROM my_table +); + +CREATE OR REPLACE MATERIALIZED VIEW IF NOT EXISTS view_with_rls +( + COL1, + COL2 +) WITH ROW ACCESS POLICY my_db.my_schema.my_policy ON (COL1) AS ( + SELECT + COL1, + COL2 + FROM my_table +); + +CREATE OR REPLACE VIEW IF NOT EXISTS view_with_column_tags +( + COL1 WITH TAG (my_db.my_schema.my_policy='MY_TAG'), + COL2 +) AS ( + SELECT + COL1, + COL2 + FROM my_table +); + +CREATE OR ALTER VIEW view_with_column_comment +( + col1 +) +AS SELECT col1 +FROM src_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_view.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_view.yml index d0de2ea95..87cc3563c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_view.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_view.yml @@ -234,6 +234,52 @@ file: - table_reference: - naked_identifier: src_table - statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: VIEW + - table_reference: + - naked_identifier: view_with_tags_and_copy_grants + - tag_bracketed_equals: + - keyword: WITH + - keyword: TAG + - bracketed: + - start_bracket: ( + - tag_reference: + - naked_identifier: foo + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"bar"' + - comma: ',' + - tag_reference: + - naked_identifier: hello + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '"world"' + - end_bracket: ) + - keyword: COPY + - keyword: GRANTS + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: src_table +- statement_terminator: ; - statement: - create_view_statement: - keyword: CREATE @@ -423,3 +469,268 @@ file: - naked_identifier: most_current - end_bracket: ) - statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: VIEW + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: view_with_rls + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: COL1 + - comma: ',' + - column_reference: + - naked_identifier: COL2 + - end_bracket: ) + - keyword: WITH + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_db + - dot: . + - naked_identifier: my_schema + - dot: . + - naked_identifier: my_policy + - keyword: ON + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: COL1 + - end_bracket: ) + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: COL1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: COL2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: VIEW + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: view_with_rls + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: COL1 + - keyword: WITH + - keyword: MASKING + - keyword: POLICY + - function_name: + - naked_identifier: my_db + - dot: . + - naked_identifier: my_schema + - dot: . + - function_name_identifier: my_policy + - comma: ',' + - column_reference: + - naked_identifier: COL2 + - end_bracket: ) + - keyword: WITH + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_db + - dot: . + - naked_identifier: my_schema + - dot: . + - naked_identifier: my_policy + - keyword: ON + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: COL1 + - end_bracket: ) + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: COL1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: COL2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: MATERIALIZED + - keyword: VIEW + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: view_with_rls + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: COL1 + - comma: ',' + - column_reference: + - naked_identifier: COL2 + - end_bracket: ) + - keyword: WITH + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - object_reference: + - naked_identifier: my_db + - dot: . + - naked_identifier: my_schema + - dot: . + - naked_identifier: my_policy + - keyword: ON + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: COL1 + - end_bracket: ) + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: COL1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: COL2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: VIEW + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: view_with_column_tags + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: COL1 + - tag_bracketed_equals: + - keyword: WITH + - keyword: TAG + - bracketed: + - start_bracket: ( + - tag_reference: + - naked_identifier: my_db + - dot: . + - naked_identifier: my_schema + - dot: . + - naked_identifier: my_policy + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''MY_TAG''' + - end_bracket: ) + - comma: ',' + - column_reference: + - naked_identifier: COL2 + - end_bracket: ) + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: COL1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: COL2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: VIEW + - table_reference: + - naked_identifier: view_with_column_comment + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: src_table +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_warehouse.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_warehouse.sql index 6b02dba3f..8076408f8 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_warehouse.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_warehouse.sql @@ -10,3 +10,18 @@ create warehouse my_wh comment = 'comment' auto_suspend = 60 ; + +CREATE OR ALTER WAREHOUSE my_wh; + +create warehouse my_wh + resource_constraint = 'STANDARD_GEN_1' + warehouse_size = 'medium' +; + +create warehouse my_wh + resource_constraint = STANDARD_GEN_2 + warehouse_size = 'medium' + SCALING_POLICY = ECONOMY + comment = 'comment' + auto_suspend = 60 +; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_warehouse.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_warehouse.yml index 8fe60c609..973552f03 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_warehouse.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/create_warehouse.yml @@ -96,3 +96,58 @@ file: - raw_comparison_operator: = - numeric_literal: '60' - statement_terminator: ; +- statement: + - create_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: WAREHOUSE + - object_reference: + - naked_identifier: my_wh +- statement_terminator: ; +- statement: + - create_statement: + - keyword: create + - keyword: warehouse + - object_reference: + - naked_identifier: my_wh + - warehouse_object_properties: + - keyword: resource_constraint + - comparison_operator: + - raw_comparison_operator: = + - resource_constraint: '''STANDARD_GEN_1''' + - keyword: warehouse_size + - comparison_operator: + - raw_comparison_operator: = + - warehouse_size: '''medium''' +- statement_terminator: ; +- statement: + - create_statement: + - keyword: create + - keyword: warehouse + - object_reference: + - naked_identifier: my_wh + - warehouse_object_properties: + - keyword: resource_constraint + - comparison_operator: + - raw_comparison_operator: = + - resource_constraint: STANDARD_GEN_2 + - keyword: warehouse_size + - comparison_operator: + - raw_comparison_operator: = + - warehouse_size: '''medium''' + - keyword: SCALING_POLICY + - comparison_operator: + - raw_comparison_operator: = + - scaling_policy: ECONOMY + - comment_equals_clause: + - keyword: comment + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''comment''' + - warehouse_object_properties: + - keyword: auto_suspend + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '60' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/current_user.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/current_user.sql new file mode 100644 index 000000000..b4c7a3669 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/current_user.sql @@ -0,0 +1,8 @@ +SELECT + CURRENT_ACCOUNT() as CURRENT_ACCOUNT, + CURRENT_ROLE() as CURRENT_ROLE, + CURRENT_REGION() AS CURRENT_REGION, + CURRENT_SESSION() as CURRENT_SESSION, + CURRENT_USER() as CURRENT_USER, + CURRENT_ACCOUNT_NAME() as CURRENT_ACCOUNT_NAME, + CURRENT_ORGANIZATION_NAME() as CURRENT_ORGANIZATION_NAME diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/current_user.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/current_user.yml new file mode 100644 index 000000000..65bbc720d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/current_user.yml @@ -0,0 +1,95 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CURRENT_ACCOUNT + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: CURRENT_ACCOUNT + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CURRENT_ROLE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: CURRENT_ROLE + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CURRENT_REGION + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: CURRENT_REGION + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CURRENT_SESSION + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: CURRENT_SESSION + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CURRENT_USER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: CURRENT_USER + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CURRENT_ACCOUNT_NAME + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: CURRENT_ACCOUNT_NAME + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CURRENT_ORGANIZATION_NAME + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: CURRENT_ORGANIZATION_NAME diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datatypes.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datatypes.sql new file mode 100644 index 000000000..0d5817fa3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datatypes.sql @@ -0,0 +1,25 @@ +select + blob:content::array(integer) as field1, + cast(blob:content as array(integer)) as field2, +from foo +; + +CREATE TABLE IF NOT EXISTS table_name ( + col1 ARRAY(NUMBER), + col2 ARRAY(NUMBER NOT NULL) +); + +CREATE OR REPLACE FUNCTION my_udtf(check BOOLEAN) + RETURNS TABLE(col1 ARRAY(VARCHAR)) + AS + $$ + ... + $$; + +CREATE OR REPLACE PROCEDURE my_procedure(values ARRAY(INTEGER)) + RETURNS ARRAY(INTEGER) + LANGUAGE SQL + AS + $$ + ... + $$; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datatypes.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datatypes.yml new file mode 100644 index 000000000..2803b72aa --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datatypes.yml @@ -0,0 +1,180 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - expression: + - cast_expression: + - column_reference: + - naked_identifier: blob + - semi_structured_expression: + - colon: ':' + - semi_structured_element: content + - casting_operator: '::' + - data_type: + - array_type: + - keyword: array + - array_type_schema: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: integer + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: field1 + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: cast + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: blob + - semi_structured_expression: + - colon: ':' + - semi_structured_element: content + - keyword: as + - data_type: + - array_type: + - keyword: array + - array_type_schema: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: integer + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: field2 + - comma: ',' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: table_name + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - array_type: + - keyword: ARRAY + - array_type_schema: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: NUMBER + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col2 + - data_type: + - array_type: + - keyword: ARRAY + - array_type_schema: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: NUMBER + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: FUNCTION + - function_name: + - function_name_identifier: my_udtf + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: check + - data_type: + - data_type_identifier: BOOLEAN + - end_bracket: ) + - keyword: RETURNS + - keyword: TABLE + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col1 + - data_type: + - array_type: + - keyword: ARRAY + - array_type_schema: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: VARCHAR + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - udf_body: |- + $$ + ... + $$ +- statement_terminator: ; +- statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: PROCEDURE + - function_name: + - function_name_identifier: my_procedure + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: values + - data_type: + - array_type: + - keyword: ARRAY + - array_type_schema: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: INTEGER + - end_bracket: ) + - end_bracket: ) + - keyword: RETURNS + - data_type: + - array_type: + - keyword: ARRAY + - array_type_schema: + - bracketed: + - start_bracket: ( + - data_type: + - data_type_identifier: INTEGER + - end_bracket: ) + - keyword: LANGUAGE + - keyword: SQL + - keyword: AS + - udf_body: |- + $$ + ... + $$ +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datetime_intervals.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datetime_intervals.yml index 3a0cbff49..030482b39 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datetime_intervals.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datetime_intervals.yml @@ -72,7 +72,8 @@ file: '1 year, 3 quarters, 4 months, 5 weeks, 6 days, 7 minutes, 8 seconds, 1000 milliseconds, 4000000 microseconds, 5000000001 nanoseconds' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: complex_interval1 - statement_terminator: ; - statement: @@ -96,7 +97,8 @@ file: '1 y, 3 q, 4 mm, 5 w, 6 d, 7 h, 9 m, 8 s, 1000 ms, 445343232 us, 898498273498 ns' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: complex_interval2 - statement_terminator: ; - statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datetime_units.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datetime_units.yml index 4aed16766..bb11a5a1b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datetime_units.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/datetime_units.yml @@ -25,7 +25,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -61,7 +62,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -97,7 +99,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -133,7 +136,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -169,7 +173,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -205,7 +210,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -241,7 +247,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -277,7 +284,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -313,7 +321,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -349,7 +358,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -385,7 +395,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -421,7 +432,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -457,7 +469,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -493,7 +506,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -529,7 +543,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -565,7 +580,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -601,7 +617,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -637,7 +654,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -673,7 +691,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -709,7 +728,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -745,7 +765,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -781,7 +802,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -817,7 +839,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -853,7 +876,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -889,7 +913,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -925,7 +950,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -961,7 +987,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -997,7 +1024,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1033,7 +1061,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1069,7 +1098,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1105,7 +1135,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1141,7 +1172,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1177,7 +1209,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1213,7 +1246,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1249,7 +1283,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1285,7 +1320,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1321,7 +1357,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1357,7 +1394,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1393,7 +1431,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1429,7 +1468,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1465,7 +1505,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1501,7 +1542,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1537,7 +1579,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1573,7 +1616,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1609,7 +1653,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1645,7 +1690,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1681,7 +1727,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1717,7 +1764,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1753,7 +1801,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1789,7 +1838,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1825,7 +1875,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1861,7 +1912,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1897,7 +1949,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1933,7 +1986,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -1969,7 +2023,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2005,7 +2060,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2041,7 +2097,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2077,7 +2134,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2113,7 +2171,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2149,7 +2208,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2185,7 +2245,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2221,7 +2282,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2257,7 +2319,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2293,7 +2356,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2329,7 +2393,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2365,7 +2430,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2401,7 +2467,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2437,7 +2504,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2473,7 +2541,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2509,7 +2578,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2545,7 +2615,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2581,7 +2652,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2617,7 +2689,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2653,7 +2726,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2689,7 +2763,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2725,7 +2800,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2761,7 +2837,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2797,7 +2874,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2833,7 +2911,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2869,7 +2948,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2905,7 +2985,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2941,7 +3022,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -2977,7 +3059,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -3013,7 +3096,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -3049,7 +3133,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -3085,7 +3170,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -3121,7 +3207,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -3157,7 +3244,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -3193,7 +3281,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -3229,7 +3318,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -3265,7 +3355,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -3301,7 +3392,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM @@ -3337,7 +3429,8 @@ file: - naked_identifier: sometime - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/declare.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/declare.sql new file mode 100644 index 000000000..604796ffb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/declare.sql @@ -0,0 +1,30 @@ +DECLARE + profit number(38, 2) DEFAULT 0.0; + revenue number(38, 2) DEFAULT 110.0; + c1 CURSOR FOR SELECT price FROM invoices; + myexception EXCEPTION (-20000, 'my first exception'); +BEGIN + profit := 1.0; +END; + +DECLARE + res RESULTSET DEFAULT (SELECT price FROM invoices); + c1 CURSOR FOR res; +BEGIN + RETURN c1; +END; + +DECLARE + res RESULTSET; + +DECLARE + res RESULTSET DEFAULT; + +DECLARE + res RESULTSET DEFAULT ASYNC (SELECT a FROM t001 ORDER BY a); + +DECLARE + res RESULTSET := (SELECT a FROM t001 ORDER BY a); + +DECLARE + res RESULTSET := ASYNC (SELECT a FROM t001 ORDER BY a); diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/declare.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/declare.yml new file mode 100644 index 000000000..4a692abf4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/declare.yml @@ -0,0 +1,228 @@ +file: +- statement: + - scripting_declare_statement: + - keyword: DECLARE + - variable: profit + - data_type: + - data_type_identifier: number + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '38' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - keyword: DEFAULT + - expression: + - numeric_literal: '0.0' + - statement_terminator: ; + - variable: revenue + - data_type: + - data_type_identifier: number + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '38' + - comma: ',' + - numeric_literal: '2' + - end_bracket: ) + - keyword: DEFAULT + - expression: + - numeric_literal: '110.0' + - statement_terminator: ; + - variable: c1 + - keyword: CURSOR + - keyword: FOR + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: price + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: invoices + - statement_terminator: ; + - variable: myexception + - keyword: EXCEPTION + - bracketed: + - start_bracket: ( + - sign_indicator: '-' + - exception_code: '20000' + - comma: ',' + - quoted_literal: '''my first exception''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - scripting_block_statement: + - keyword: BEGIN + - statement: + - scripting_let_statement: + - variable: profit + - assignment_operator: := + - expression: + - numeric_literal: '1.0' + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- statement: + - scripting_declare_statement: + - keyword: DECLARE + - variable: res + - data_type: + - data_type_identifier: RESULTSET + - keyword: DEFAULT + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: price + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: invoices + - end_bracket: ) + - statement_terminator: ; + - variable: c1 + - keyword: CURSOR + - keyword: FOR + - variable: res +- statement_terminator: ; +- statement: + - scripting_block_statement: + - keyword: BEGIN + - statement: + - return_statement: + - keyword: RETURN + - expression: + - column_reference: + - naked_identifier: c1 + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- statement: + - scripting_declare_statement: + - keyword: DECLARE + - variable: res + - keyword: RESULTSET +- statement_terminator: ; +- statement: + - scripting_declare_statement: + - keyword: DECLARE + - variable: res + - keyword: RESULTSET + - keyword: DEFAULT +- statement_terminator: ; +- statement: + - scripting_declare_statement: + - keyword: DECLARE + - variable: res + - data_type: + - data_type_identifier: RESULTSET + - keyword: DEFAULT + - expression: + - function: + - function_name: + - function_name_identifier: ASYNC + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t001 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: a + - end_bracket: ) +- statement_terminator: ; +- statement: + - scripting_declare_statement: + - keyword: DECLARE + - variable: res + - data_type: + - data_type_identifier: RESULTSET + - assignment_operator: := + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t001 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: a + - end_bracket: ) +- statement_terminator: ; +- statement: + - scripting_declare_statement: + - keyword: DECLARE + - variable: res + - data_type: + - data_type_identifier: RESULTSET + - assignment_operator: := + - expression: + - function: + - function_name: + - function_name_identifier: ASYNC + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t001 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: a + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/delete.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/delete.yml index 98fcaac69..7c77e6af7 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/delete.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/delete.yml @@ -13,7 +13,8 @@ file: - table_reference: - naked_identifier: leased_bicycles - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: lb - statement_terminator: ; - statement: @@ -76,14 +77,16 @@ file: - table_reference: - naked_identifier: leased_bicycles - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: lb - keyword: using - table_expression: - table_reference: - naked_identifier: returned_bicycles - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: rb - where_clause: - keyword: where @@ -173,21 +176,24 @@ file: - table_reference: - naked_identifier: leased_bicycles - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: lb - keyword: using - table_expression: - table_reference: - naked_identifier: returned_bicycles - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: rb - comma: ',' - table_expression: - table_reference: - naked_identifier: broken_bicycles - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: bb - where_clause: - keyword: where @@ -276,7 +282,8 @@ file: - column_reference: - naked_identifier: bicycle_id - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: bicycle_id - from_clause: - keyword: from @@ -287,7 +294,8 @@ file: - naked_identifier: returned_bicycles - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: returned - where_clause: - keyword: where @@ -320,7 +328,8 @@ file: - column_reference: - naked_identifier: bicycle_id - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: bicycle_id - from_clause: - keyword: from @@ -338,7 +347,8 @@ file: - numeric_literal: '2' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: returned - where_clause: - keyword: where diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/describe_statements.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/describe_statements.sql index a0da4eb28..3a27492b3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/describe_statements.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/describe_statements.sql @@ -114,3 +114,11 @@ DESC PROCEDURE my_pi(); DESCRIBE PROCEDURE area_of_circle(FLOAT); DESC PROCEDURE area_of_circle(FLOAT); + +DESCRIBE EXTERNAL VOLUME my_volume; + +DESC PASSWORD POLICY password_policy_prod_1; + +DESCRIBE CORTEX SEARCH SERVICE mysvc; + +DESC CORTEX SEARCH SERVICE mysvc; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/describe_statements.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/describe_statements.yml index 5f1235abc..273842d03 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/describe_statements.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/describe_statements.yml @@ -231,37 +231,33 @@ file: - describe_statement: - keyword: DESCRIBE - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - statement_terminator: ; - statement: - describe_statement: - keyword: DESC - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - statement_terminator: ; - statement: - describe_statement: - keyword: DESCRIBE - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_database - - dot: . - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_database + - dot: . + - naked_identifier: my_schema - statement_terminator: ; - statement: - describe_statement: - keyword: DESC - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: my_database - - dot: . - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_database + - dot: . + - naked_identifier: my_schema - statement_terminator: ; - statement: - describe_statement: @@ -487,14 +483,14 @@ file: - describe_statement: - keyword: DESCRIBE - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: my_sequence - statement_terminator: ; - statement: - describe_statement: - keyword: DESC - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: my_sequence - statement_terminator: ; - statement: @@ -677,3 +673,37 @@ file: - data_type_identifier: FLOAT - end_bracket: ) - statement_terminator: ; +- statement: + - describe_statement: + - keyword: DESCRIBE + - keyword: EXTERNAL + - keyword: VOLUME + - external_volume_reference: + - naked_identifier: my_volume +- statement_terminator: ; +- statement: + - describe_statement: + - keyword: DESC + - keyword: PASSWORD + - keyword: POLICY + - password_policy_reference: + - naked_identifier: password_policy_prod_1 +- statement_terminator: ; +- statement: + - describe_statement: + - keyword: DESCRIBE + - keyword: CORTEX + - keyword: SEARCH + - keyword: SERVICE + - object_reference: + - naked_identifier: mysvc +- statement_terminator: ; +- statement: + - describe_statement: + - keyword: DESC + - keyword: CORTEX + - keyword: SEARCH + - keyword: SERVICE + - object_reference: + - naked_identifier: mysvc +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/double_quote_escapes.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/double_quote_escapes.sql new file mode 100644 index 000000000..f99b7de61 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/double_quote_escapes.sql @@ -0,0 +1,10 @@ +select + 1 as foo, + 2 as "foo", + 3 as """foo""", + 4 as """""foo""""", + bar, + "bar", + """bar""", + """""bar""""" +from """""a"""""."""""b"""""."""""c""""" diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/double_quote_escapes.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/double_quote_escapes.yml new file mode 100644 index 000000000..ff20e9fd2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/double_quote_escapes.yml @@ -0,0 +1,59 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: foo + - comma: ',' + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: as + - quoted_identifier: '"foo"' + - comma: ',' + - select_clause_element: + - numeric_literal: '3' + - alias_expression: + - alias_operator: + - keyword: as + - quoted_identifier: '"""foo"""' + - comma: ',' + - select_clause_element: + - numeric_literal: '4' + - alias_expression: + - alias_operator: + - keyword: as + - quoted_identifier: '"""""foo"""""' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: bar + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '"bar"' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '"""bar"""' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '"""""bar"""""' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '"""""a"""""' + - dot: . + - quoted_identifier: '"""""b"""""' + - dot: . + - quoted_identifier: '"""""c"""""' diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_dynamic_table.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_dynamic_table.sql new file mode 100644 index 000000000..7ed32a7e0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_dynamic_table.sql @@ -0,0 +1,3 @@ +DROP DYNAMIC TABLE my_table; + +DROP DYNAMIC TABLE IF EXISTS my_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_dynamic_table.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_dynamic_table.yml new file mode 100644 index 000000000..d3f540ce6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_dynamic_table.yml @@ -0,0 +1,19 @@ +file: +- statement: + - drop_dynamic_table_segment: + - keyword: DROP + - keyword: DYNAMIC + - keyword: TABLE + - table_reference: + - naked_identifier: my_table +- statement_terminator: ; +- statement: + - drop_dynamic_table_segment: + - keyword: DROP + - keyword: DYNAMIC + - keyword: TABLE + - keyword: IF + - keyword: EXISTS + - table_reference: + - naked_identifier: my_table +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_iceberg_table.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_iceberg_table.sql new file mode 100644 index 000000000..7df50339f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_iceberg_table.sql @@ -0,0 +1,3 @@ +DROP ICEBERG TABLE my_table; + +DROP ICEBERG TABLE IF EXISTS my_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_iceberg_table.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_iceberg_table.yml new file mode 100644 index 000000000..f947f395e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_iceberg_table.yml @@ -0,0 +1,19 @@ +file: +- statement: + - drop_iceberg_table_statement: + - keyword: DROP + - keyword: ICEBERG + - keyword: TABLE + - table_reference: + - naked_identifier: my_table +- statement_terminator: ; +- statement: + - drop_iceberg_table_statement: + - keyword: DROP + - keyword: ICEBERG + - keyword: TABLE + - keyword: IF + - keyword: EXISTS + - table_reference: + - naked_identifier: my_table +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_password_policy.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_password_policy.sql new file mode 100644 index 000000000..937319e92 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_password_policy.sql @@ -0,0 +1 @@ +DROP PASSWORD POLICY password_policy_production_1; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_password_policy.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_password_policy.yml new file mode 100644 index 000000000..0dd59daff --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_password_policy.yml @@ -0,0 +1,9 @@ +file: +- statement: + - drop_password_policy_statement: + - keyword: DROP + - keyword: PASSWORD + - keyword: POLICY + - password_policy_reference: + - naked_identifier: password_policy_production_1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_resource_monitor.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_resource_monitor.sql new file mode 100644 index 000000000..bc2e0f46b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_resource_monitor.sql @@ -0,0 +1 @@ +DROP RESOURCE MONITOR IF EXISTS my_rm; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_resource_monitor.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_resource_monitor.yml new file mode 100644 index 000000000..8382677af --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_resource_monitor.yml @@ -0,0 +1,11 @@ +file: +- statement: + - drop_resource_monitor_statement: + - keyword: DROP + - keyword: RESOURCE + - keyword: MONITOR + - keyword: IF + - keyword: EXISTS + - object_reference: + - naked_identifier: my_rm +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_statements.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_statements.sql index 9d597f3e8..d6b410ac2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_statements.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_statements.sql @@ -107,3 +107,11 @@ DROP VIEW IF EXISTS MY_SCHEMA.MY_VIEW; DROP WAREHOUSE MY_WAREHOUSE; DROP WAREHOUSE IF EXISTS MY_WAREHOUSE; + +DROP EXTERNAL VOLUME my_volume; + +DROP EXTERNAL VOLUME IF EXISTS foo; + +DROP CORTEX SEARCH SERVICE mysvc; + +DROP CORTEX SEARCH SERVICE IF EXISTS mysvc; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_statements.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_statements.yml index ffe576bc9..b61a3f050 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_statements.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/drop_statements.yml @@ -307,9 +307,8 @@ file: - drop_schema_statement: - keyword: DROP - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: MY_SCHEMA + - schema_reference: + - naked_identifier: MY_SCHEMA - statement_terminator: ; - statement: - drop_schema_statement: @@ -317,9 +316,8 @@ file: - keyword: SCHEMA - keyword: IF - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: MY_SCHEMA + - schema_reference: + - naked_identifier: MY_SCHEMA - statement_terminator: ; - statement: - drop_schema_statement: @@ -327,16 +325,15 @@ file: - keyword: SCHEMA - keyword: IF - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: MY_SCHEMA + - schema_reference: + - naked_identifier: MY_SCHEMA - keyword: CASCADE - statement_terminator: ; - statement: - drop_sequence_statement: - keyword: DROP - keyword: SEQUENCE - - column_reference: + - sequence_reference: - naked_identifier: MY_SCHEMA - dot: . - naked_identifier: INVOICE_SEQUENCE_NUMBER @@ -545,3 +542,41 @@ file: - keyword: EXISTS - naked_identifier: MY_WAREHOUSE - statement_terminator: ; +- statement: + - drop_external_volume_statement: + - keyword: DROP + - keyword: EXTERNAL + - keyword: VOLUME + - external_volume_reference: + - naked_identifier: my_volume +- statement_terminator: ; +- statement: + - drop_external_volume_statement: + - keyword: DROP + - keyword: EXTERNAL + - keyword: VOLUME + - keyword: IF + - keyword: EXISTS + - external_volume_reference: + - naked_identifier: foo +- statement_terminator: ; +- statement: + - drop_object_statement: + - keyword: DROP + - keyword: CORTEX + - keyword: SEARCH + - keyword: SERVICE + - object_reference: + - naked_identifier: mysvc +- statement_terminator: ; +- statement: + - drop_object_statement: + - keyword: DROP + - keyword: CORTEX + - keyword: SEARCH + - keyword: SERVICE + - keyword: IF + - keyword: EXISTS + - object_reference: + - naked_identifier: mysvc +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/escape.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/escape.yml index e0af26858..b170bf561 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/escape.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/escape.yml @@ -6,11 +6,13 @@ file: - select_clause_element: - quoted_literal: '''c\'' ''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: escaped - comma: ',' - select_clause_element: - quoted_literal: '''c\'' '''' ''' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: escaped_double diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/exception.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/exception.sql new file mode 100644 index 000000000..105557ff7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/exception.sql @@ -0,0 +1,47 @@ +EXCEPTION + WHEN EXCEPTION_2 THEN + RETURN SQLERRM; + WHEN EXCEPTION_1 THEN + RETURN SQLERRM; + +EXCEPTION + WHEN MY_FIRST_EXCEPTION OR MY_SECOND_EXCEPTION THEN + RETURN 123; + WHEN MY_FOURTH_EXCEPTION THEN + RETURN 4; + WHEN OTHER THEN + RETURN 99; + +EXCEPTION + WHEN STATEMENT_ERROR THEN + RETURN OBJECT_CONSTRUCT('Error type', 'STATEMENT_ERROR', + 'SQLCODE', SQLCODE, + 'SQLERRM', SQLERRM, + 'SQLSTATE', SQLSTATE); + WHEN EXPRESSION_ERROR THEN + RETURN OBJECT_CONSTRUCT('Error type', 'EXPRESSION_ERROR', + 'SQLCODE', SQLCODE, + 'SQLERRM', SQLERRM, + 'SQLSTATE', SQLSTATE); + WHEN OTHER THEN + RETURN OBJECT_CONSTRUCT('Error type', 'Other error', + 'SQLCODE', SQLCODE, + 'SQLERRM', SQLERRM, + 'SQLSTATE', SQLSTATE); + +EXCEPTION + WHEN STATEMENT_ERROR THEN + RETURN OBJECT_CONSTRUCT('Error type', 'STATEMENT_ERROR', + 'SQLCODE', SQLCODE, + 'SQLERRM', SQLERRM, + 'SQLSTATE', SQLSTATE); + WHEN EXPRESSION_ERROR THEN + RETURN OBJECT_CONSTRUCT('Error type', 'EXPRESSION_ERROR', + 'SQLCODE', SQLCODE, + 'SQLERRM', SQLERRM, + 'SQLSTATE', SQLSTATE); + WHEN OTHER THEN + RETURN OBJECT_CONSTRUCT('Error type', 'Other error', + 'SQLCODE', SQLCODE, + 'SQLERRM', SQLERRM, + 'SQLSTATE', SQLSTATE); diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/exception.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/exception.yml new file mode 100644 index 000000000..bd7ee9f23 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/exception.yml @@ -0,0 +1,320 @@ +file: +- statement: + - exception_block_statement: + - keyword: EXCEPTION + - keyword: WHEN + - object_reference: + - naked_identifier: EXCEPTION_2 + - keyword: THEN + - statement: + - return_statement: + - keyword: RETURN + - expression: + - column_reference: + - naked_identifier: SQLERRM + - statement_terminator: ; + - keyword: WHEN + - object_reference: + - naked_identifier: EXCEPTION_1 + - keyword: THEN + - statement: + - return_statement: + - keyword: RETURN + - expression: + - column_reference: + - naked_identifier: SQLERRM +- statement_terminator: ; +- statement: + - exception_block_statement: + - keyword: EXCEPTION + - keyword: WHEN + - object_reference: + - naked_identifier: MY_FIRST_EXCEPTION + - keyword: OR + - object_reference: + - naked_identifier: MY_SECOND_EXCEPTION + - keyword: THEN + - statement: + - return_statement: + - keyword: RETURN + - expression: + - numeric_literal: '123' + - statement_terminator: ; + - keyword: WHEN + - object_reference: + - naked_identifier: MY_FOURTH_EXCEPTION + - keyword: THEN + - statement: + - return_statement: + - keyword: RETURN + - expression: + - numeric_literal: '4' + - statement_terminator: ; + - keyword: WHEN + - object_reference: + - naked_identifier: OTHER + - keyword: THEN + - statement: + - return_statement: + - keyword: RETURN + - expression: + - numeric_literal: '99' +- statement_terminator: ; +- statement: + - exception_block_statement: + - keyword: EXCEPTION + - keyword: WHEN + - object_reference: + - naked_identifier: STATEMENT_ERROR + - keyword: THEN + - statement: + - return_statement: + - keyword: RETURN + - expression: + - function: + - function_name: + - function_name_identifier: OBJECT_CONSTRUCT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''Error type''' + - comma: ',' + - expression: + - quoted_literal: '''STATEMENT_ERROR''' + - comma: ',' + - expression: + - quoted_literal: '''SQLCODE''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLCODE + - comma: ',' + - expression: + - quoted_literal: '''SQLERRM''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLERRM + - comma: ',' + - expression: + - quoted_literal: '''SQLSTATE''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLSTATE + - end_bracket: ) + - statement_terminator: ; + - keyword: WHEN + - object_reference: + - naked_identifier: EXPRESSION_ERROR + - keyword: THEN + - statement: + - return_statement: + - keyword: RETURN + - expression: + - function: + - function_name: + - function_name_identifier: OBJECT_CONSTRUCT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''Error type''' + - comma: ',' + - expression: + - quoted_literal: '''EXPRESSION_ERROR''' + - comma: ',' + - expression: + - quoted_literal: '''SQLCODE''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLCODE + - comma: ',' + - expression: + - quoted_literal: '''SQLERRM''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLERRM + - comma: ',' + - expression: + - quoted_literal: '''SQLSTATE''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLSTATE + - end_bracket: ) + - statement_terminator: ; + - keyword: WHEN + - object_reference: + - naked_identifier: OTHER + - keyword: THEN + - statement: + - return_statement: + - keyword: RETURN + - expression: + - function: + - function_name: + - function_name_identifier: OBJECT_CONSTRUCT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''Error type''' + - comma: ',' + - expression: + - quoted_literal: '''Other error''' + - comma: ',' + - expression: + - quoted_literal: '''SQLCODE''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLCODE + - comma: ',' + - expression: + - quoted_literal: '''SQLERRM''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLERRM + - comma: ',' + - expression: + - quoted_literal: '''SQLSTATE''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLSTATE + - end_bracket: ) +- statement_terminator: ; +- statement: + - exception_block_statement: + - keyword: EXCEPTION + - keyword: WHEN + - object_reference: + - naked_identifier: STATEMENT_ERROR + - keyword: THEN + - statement: + - return_statement: + - keyword: RETURN + - expression: + - function: + - function_name: + - function_name_identifier: OBJECT_CONSTRUCT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''Error type''' + - comma: ',' + - expression: + - quoted_literal: '''STATEMENT_ERROR''' + - comma: ',' + - expression: + - quoted_literal: '''SQLCODE''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLCODE + - comma: ',' + - expression: + - quoted_literal: '''SQLERRM''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLERRM + - comma: ',' + - expression: + - quoted_literal: '''SQLSTATE''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLSTATE + - end_bracket: ) + - statement_terminator: ; + - keyword: WHEN + - object_reference: + - naked_identifier: EXPRESSION_ERROR + - keyword: THEN + - statement: + - return_statement: + - keyword: RETURN + - expression: + - function: + - function_name: + - function_name_identifier: OBJECT_CONSTRUCT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''Error type''' + - comma: ',' + - expression: + - quoted_literal: '''EXPRESSION_ERROR''' + - comma: ',' + - expression: + - quoted_literal: '''SQLCODE''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLCODE + - comma: ',' + - expression: + - quoted_literal: '''SQLERRM''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLERRM + - comma: ',' + - expression: + - quoted_literal: '''SQLSTATE''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLSTATE + - end_bracket: ) + - statement_terminator: ; + - keyword: WHEN + - object_reference: + - naked_identifier: OTHER + - keyword: THEN + - statement: + - return_statement: + - keyword: RETURN + - expression: + - function: + - function_name: + - function_name_identifier: OBJECT_CONSTRUCT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''Error type''' + - comma: ',' + - expression: + - quoted_literal: '''Other error''' + - comma: ',' + - expression: + - quoted_literal: '''SQLCODE''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLCODE + - comma: ',' + - expression: + - quoted_literal: '''SQLERRM''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLERRM + - comma: ',' + - expression: + - quoted_literal: '''SQLSTATE''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SQLSTATE + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/execute_immediate.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/execute_immediate.sql index 945e6b290..d5815a9fa 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/execute_immediate.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/execute_immediate.sql @@ -19,3 +19,7 @@ EXECUTE IMMEDIATE $pie USING (one, two); SET three = 'select ? + ?'; EXECUTE IMMEDIATE :three; EXECUTE IMMEDIATE :three USING (one, two); + +EXECUTE IMMEDIATE FROM './insert-inventory.sql'; + +EXECUTE IMMEDIATE FROM @my_stage/scripts/create-inventory.sql; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/execute_immediate.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/execute_immediate.yml index c453d47e4..52b39ad17 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/execute_immediate.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/execute_immediate.yml @@ -76,14 +76,14 @@ file: - execute_immediate_clause: - keyword: EXECUTE - keyword: IMMEDIATE - - colon: ':' + - colon_prefix: ':' - variable: three - statement_terminator: ; - statement: - execute_immediate_clause: - keyword: EXECUTE - keyword: IMMEDIATE - - colon: ':' + - colon_prefix: ':' - variable: three - keyword: USING - bracketed: @@ -93,3 +93,18 @@ file: - variable: two - end_bracket: ) - statement_terminator: ; +- statement: + - execute_immediate_clause: + - keyword: EXECUTE + - keyword: IMMEDIATE + - keyword: FROM + - quoted_literal: '''./insert-inventory.sql''' +- statement_terminator: ; +- statement: + - execute_immediate_clause: + - keyword: EXECUTE + - keyword: IMMEDIATE + - keyword: FROM + - storage_location: + - stage_path: '@my_stage/scripts/create-inventory.sql' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/first_value_ignore_nulls.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/first_value_ignore_nulls.yml index c197b1d1d..3ab48e124 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/first_value_ignore_nulls.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/first_value_ignore_nulls.yml @@ -57,7 +57,8 @@ file: - boolean_literal: 'false' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: c - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/for_in_loop.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/for_in_loop.sql new file mode 100644 index 000000000..b8c05828c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/for_in_loop.sql @@ -0,0 +1,18 @@ +-- Simple LET +LET CUR_TABLE CURSOR FOR SELECT * FROM THE_TABLE; +-- Simple LOOP +BEGIN + SELECT 1; + SELECT 2; +END; +-- Simple FOR +FOR THE_ROW IN CUR_TABLE DO + LET NEW_VAR := THE_ROW.COL1 || "_SUFFIX"; +END FOR; +-- FOR and LET in LOOP +BEGIN +LET CUR_TABLE CURSOR FOR SELECT * FROM THE_TABLE; +FOR THE_ROW IN CUR_TABLE DO + LET NEW_VAR := THE_ROW.COL1 || "_SUFFIX"; +END FOR; +END; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/for_in_loop.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/for_in_loop.yml new file mode 100644 index 000000000..aa4db4e0a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/for_in_loop.yml @@ -0,0 +1,119 @@ +file: +- statement: + - scripting_let_statement: + - keyword: LET + - variable: CUR_TABLE + - keyword: CURSOR + - keyword: FOR + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: THE_TABLE +- statement_terminator: ; +- statement: + - scripting_block_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- statement: + - for_in_statement: + - keyword: FOR + - variable: THE_ROW + - keyword: IN + - variable: CUR_TABLE + - keyword: DO + - statement: + - scripting_let_statement: + - keyword: LET + - variable: NEW_VAR + - assignment_operator: := + - expression: + - column_reference: + - naked_identifier: THE_ROW + - dot: . + - naked_identifier: COL1 + - binary_operator: + - pipe: '|' + - pipe: '|' + - column_reference: + - quoted_identifier: '"_SUFFIX"' + - statement_terminator: ; + - keyword: END + - keyword: FOR +- statement_terminator: ; +- statement: + - scripting_block_statement: + - keyword: BEGIN + - statement: + - scripting_let_statement: + - keyword: LET + - variable: CUR_TABLE + - keyword: CURSOR + - keyword: FOR + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: THE_TABLE + - statement_terminator: ; + - statement: + - for_in_statement: + - keyword: FOR + - variable: THE_ROW + - keyword: IN + - variable: CUR_TABLE + - keyword: DO + - statement: + - scripting_let_statement: + - keyword: LET + - variable: NEW_VAR + - assignment_operator: := + - expression: + - column_reference: + - naked_identifier: THE_ROW + - dot: . + - naked_identifier: COL1 + - binary_operator: + - pipe: '|' + - pipe: '|' + - column_reference: + - quoted_identifier: '"_SUFFIX"' + - statement_terminator: ; + - keyword: END + - keyword: FOR + - statement_terminator: ; + - keyword: END +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/frame_clause.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/frame_clause.sql index dc0c65bd5..dca93166d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/frame_clause.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/frame_clause.sql @@ -8,3 +8,11 @@ SELECT ) AS vehicle_type_id_last_value FROM foo ; + +SELECT + account_id + , SUM(amount) + OVER (ORDER BY date_created RANGE BETWEEN INTERVAL '7 DAYS' PRECEDING AND CURRENT ROW) + AS trailing_7d_sum_amount +FROM my_database.my_schema.my_table +; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/frame_clause.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/frame_clause.yml index c9da38c50..7aba67aae 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/frame_clause.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/frame_clause.yml @@ -47,7 +47,8 @@ file: - keyword: ROW - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: vehicle_type_id_last_value - from_clause: - keyword: FROM @@ -57,3 +58,58 @@ file: - table_reference: - naked_identifier: foo - statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: account_id + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: amount + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: date_created + - frame_clause: + - keyword: RANGE + - keyword: BETWEEN + - keyword: INTERVAL + - quoted_literal: '''7 DAYS''' + - keyword: PRECEDING + - keyword: AND + - keyword: CURRENT + - keyword: ROW + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: trailing_7d_sum_amount + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_database + - dot: . + - naked_identifier: my_schema + - dot: . + - naked_identifier: my_table +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/grant_revoke.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/grant_revoke.sql index 1a319ddb9..e8e885d37 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/grant_revoke.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/grant_revoke.sql @@ -2,103 +2,138 @@ GRANT OWNERSHIP ON SCHEMA MY_DATABASE.MY_SCHEMA TO ROLE MY_ROLE; GRANT ROLE MY_ROLE TO ROLE MY_OTHER_ROLE; -grant use_any_role on integration external_oauth_1 to role1; +GRANT USE_ANY_ROLE ON INTEGRATION EXTERNAL_OAUTH_1 TO ROLE1; -grant ownership on table myschema.mytable to role analyst; +GRANT OWNERSHIP ON TABLE MYSCHEMA.MYTABLE TO ROLE ANALYST; -grant ownership on all tables in schema public to role analyst; +GRANT OWNERSHIP ON ALL TABLES IN SCHEMA PUBLIC TO ROLE ANALYST; -grant ownership on all tables in schema mydb.public to role analyst; +GRANT OWNERSHIP ON ALL TABLES IN SCHEMA MYDB.PUBLIC TO ROLE ANALYST; -grant ownership on all tables in schema mydb.public to role analyst copy current grants; +GRANT OWNERSHIP ON ALL TABLES IN SCHEMA MYDB.PUBLIC TO ROLE ANALYST COPY CURRENT GRANTS; GRANT ROLE ROLENAME TO ROLE IDENTIFIER($THIS_ROLE); GRANT OWNERSHIP ON ROLE TEST_ROLE TO ROLE DIFFERENT_ROLE; -grant all on all materialized views in database my_db to role analyst; -grant all on all file formats in database my_db to role analyst; -grant create temporary table on schema my_db.my_schema to role analyst; -grant all on future pipes in database my_db to role analyst; -grant all on future file formats in database my_db to role analyst; -grant all on future materialized views in database my_db to role analyst; -grant all on future pipes in database my_db to role analyst; -grant usage on all sequences in database my_db to role analyst; -grant all on all materialized views in database my_db to role analyst; -grant all on all sequences in database my_db to role analyst; -grant all on all functions in database my_db to role analyst; -grant all on all file formats in database my_db to role analyst; -grant all on all stages in database my_db to role analyst; -grant select on all views in database my_db to role analyst; +GRANT ALL ON ALL MATERIALIZED VIEWS IN DATABASE MY_DB TO ROLE ANALYST; +GRANT ALL ON ALL FILE FORMATS IN DATABASE MY_DB TO ROLE ANALYST; +GRANT CREATE TEMPORARY TABLE ON SCHEMA MY_DB.MY_SCHEMA TO ROLE ANALYST; +GRANT ALL ON FUTURE PIPES IN DATABASE MY_DB TO ROLE ANALYST; +GRANT ALL ON FUTURE FILE FORMATS IN DATABASE MY_DB TO ROLE ANALYST; +GRANT ALL ON FUTURE MATERIALIZED VIEWS IN DATABASE MY_DB TO ROLE ANALYST; +GRANT ALL ON FUTURE PIPES IN DATABASE MY_DB TO ROLE ANALYST; +GRANT USAGE ON ALL SEQUENCES IN DATABASE MY_DB TO ROLE ANALYST; +GRANT ALL ON ALL MATERIALIZED VIEWS IN DATABASE MY_DB TO ROLE ANALYST; +GRANT ALL ON ALL SEQUENCES IN DATABASE MY_DB TO ROLE ANALYST; +GRANT ALL ON ALL FUNCTIONS IN DATABASE MY_DB TO ROLE ANALYST; +GRANT ALL ON ALL FILE FORMATS IN DATABASE MY_DB TO ROLE ANALYST; +GRANT ALL ON ALL STAGES IN DATABASE MY_DB TO ROLE ANALYST; +GRANT SELECT ON ALL VIEWS IN DATABASE MY_DB TO ROLE ANALYST; -revoke role analyst from role sysadmin; +REVOKE ROLE ANALYST FROM ROLE SYSADMIN; -revoke select,insert on future tables in schema mydb.myschema from role role1; +REVOKE SELECT, INSERT ON FUTURE TABLES IN SCHEMA MYDB.MYSCHEMA FROM ROLE ROLE1; -revoke all privileges on function add5(number) from role analyst; +REVOKE ALL PRIVILEGES ON FUNCTION add5(number) FROM ROLE ANALYST; -revoke grant option for operate on warehouse report_wh from role analyst; +REVOKE GRANT OPTION FOR OPERATE ON WAREHOUSE REPORT_WH FROM ROLE ANALYST; -revoke select on all tables in schema mydb.myschema from role analyst; +REVOKE SELECT ON ALL TABLES IN SCHEMA MYDB.MYSCHEMA FROM ROLE ANALYST; -revoke operate on warehouse report_wh from role analyst; +REVOKE OPERATE ON WAREHOUSE REPORT_WH FROM ROLE ANALYST; -revoke reference_usage on database database2 from share share1; +REVOKE REFERENCE_USAGE ON DATABASE DATABASE2 FROM SHARE SHARE1; REVOKE OWNERSHIP ON ROLE TEST_ROLE FROM ROLE DIFFERENT_ROLE; -grant operate on warehouse report_wh to role analyst; -grant operate on warehouse report_wh to role analyst with grant option; -grant select on all tables in schema mydb.myschema to role analyst; -grant all privileges on function mydb.myschema.add5(number) to role analyst; -grant all privileges on function mydb.myschema.add5(string) to role analyst; -grant usage on procedure mydb.myschema.myprocedure(number) to role analyst; -grant create materialized view on schema mydb.myschema to role myrole; -grant select,insert on future tables in schema mydb.myschema to role role1; -grant usage on future schemas in database mydb to role role1; - -grant usage on database database1 to share share1; -grant usage on schema database1.schema1 to share share1; -grant reference_usage on database database2 to share share1; -grant select on view view2 to share share1; -grant usage on database mydb to share share1; -grant usage on schema mydb.public to share share1; -grant usage on function mydb.shared_schema.function1 to share share1; -grant select on all tables in schema mydb.public to share share1; -grant usage on schema mydb.shared_schema to share share1; -grant select on view mydb.shared_schema.view1 to share share1; -grant select on view mydb.shared_schema.view3 to share share1; - -grant role analyst to user user1; - -revoke all privileges on procedure clean_schema(string) from role analyst; -revoke all privileges on function add5(string) from role analyst; - -revoke select on view mydb.shared_schema.view1 from share share1; -revoke usage on schema mydb.shared_schema from share share1; -revoke select on all tables in schema mydb.public from share share1; -revoke usage on schema mydb.public from share share1; -revoke usage on database mydb from share share1; - -grant apply masking policy on account to role my_role; -grant apply row access policy on account to role my_role; -grant apply session policy on account to role my_role; -grant apply tag on account to role my_role; -grant attach policy on account to role my_role; -grant execute task on account to role my_role; -grant import share on account to role my_role; -grant manage grants on account to role my_role; -grant monitor execution on account to role my_role; -grant monitor usage on account to role my_role; -grant override share restrictions on account to role my_role; -grant create account on account to role my_role; -grant create share on account to role my_role; -grant create network policy on account to role my_role; -grant create data exchange listing on account to role my_role; - -GRANT MANAGE ACCOUNT SUPPORT CASES ON ACCOUNT TO ROLE my_role; -GRANT MANAGE ORGANIZATION SUPPORT CASES ON ACCOUNT TO ROLE my_role; -GRANT MANAGE USER SUPPORT CASES ON ACCOUNT TO ROLE my_role; +GRANT IMPORTED PRIVILEGES ON SCHEMA MYDB.MYSCHEMA TO APPLICATION MY_APP; + +GRANT OPERATE ON WAREHOUSE REPORT_WH TO ROLE ANALYST; +GRANT OPERATE ON WAREHOUSE REPORT_WH TO ROLE ANALYST WITH GRANT OPTION; +GRANT OPERATE ON FUTURE DYNAMIC TABLES IN SCHEMA MYDB.MYSCHEMA TO ROLE ANALYST; +GRANT OPERATE ON ALL DYNAMIC TABLES IN SCHEMA MYDB.MYSCHEMA TO ROLE ANALYST; +GRANT SELECT ON ALL TABLES IN SCHEMA MYDB.MYSCHEMA TO ROLE ANALYST; +GRANT ALL PRIVILEGES ON FUNCTION mydb.myschema.add5(number) TO ROLE ANALYST; +GRANT ALL PRIVILEGES ON FUNCTION mydb.myschema.add5(string) TO ROLE ANALYST; +GRANT USAGE ON PROCEDURE mydb.myschema.myprocedure(number) TO ROLE ANALYST; +GRANT CREATE MATERIALIZED VIEW ON SCHEMA MYDB.MYSCHEMA TO ROLE MYROLE; +GRANT SELECT, INSERT ON FUTURE TABLES IN SCHEMA MYDB.MYSCHEMA TO ROLE ROLE1; +GRANT USAGE ON FUTURE SCHEMAS IN DATABASE MYDB TO ROLE ROLE1; + +GRANT USAGE ON DATABASE DATABASE1 TO SHARE SHARE1; +GRANT USAGE ON SCHEMA DATABASE1.SCHEMA1 TO SHARE SHARE1; +GRANT REFERENCE_USAGE ON DATABASE DATABASE2 TO SHARE SHARE1; +GRANT SELECT ON VIEW VIEW2 TO SHARE SHARE1; +GRANT USAGE ON DATABASE MYDB TO SHARE SHARE1; +GRANT USAGE ON SCHEMA MYDB.PUBLIC TO SHARE SHARE1; +GRANT USAGE ON FUNCTION MYDB.SHARED_SCHEMA.FUNCTION1 TO SHARE SHARE1; +GRANT SELECT ON ALL TABLES IN SCHEMA MYDB.PUBLIC TO SHARE SHARE1; +GRANT USAGE ON SCHEMA MYDB.SHARED_SCHEMA TO SHARE SHARE1; +GRANT SELECT ON VIEW MYDB.SHARED_SCHEMA.VIEW1 TO SHARE SHARE1; +GRANT SELECT ON VIEW MYDB.SHARED_SCHEMA.VIEW3 TO SHARE SHARE1; + +GRANT ROLE ANALYST TO USER USER1; + +REVOKE ALL PRIVILEGES ON PROCEDURE clean_schema(string) FROM ROLE ANALYST; +REVOKE ALL PRIVILEGES ON FUNCTION add5(string) FROM ROLE ANALYST; + +REVOKE SELECT ON VIEW MYDB.SHARED_SCHEMA.VIEW1 FROM SHARE SHARE1; +REVOKE USAGE ON SCHEMA MYDB.SHARED_SCHEMA FROM SHARE SHARE1; +REVOKE SELECT ON ALL TABLES IN SCHEMA MYDB.PUBLIC FROM SHARE SHARE1; +REVOKE USAGE ON SCHEMA MYDB.PUBLIC FROM SHARE SHARE1; +REVOKE USAGE ON DATABASE MYDB FROM SHARE SHARE1; + +GRANT APPLY MASKING POLICY ON ACCOUNT TO ROLE MY_ROLE; +GRANT APPLY ROW ACCESS POLICY ON ACCOUNT TO ROLE MY_ROLE; +GRANT APPLY SESSION POLICY ON ACCOUNT TO ROLE MY_ROLE; +GRANT APPLY TAG ON ACCOUNT TO ROLE MY_ROLE; +GRANT ATTACH POLICY ON ACCOUNT TO ROLE MY_ROLE; +GRANT EXECUTE ALERT ON ACCOUNT TO ROLE MY_ROLE; +GRANT EXECUTE TASK ON ACCOUNT TO ROLE MY_ROLE; +GRANT EXECUTE MANAGED TASK ON ACCOUNT TO ROLE MY_ROLE; +GRANT IMPORT SHARE ON ACCOUNT TO ROLE MY_ROLE; +GRANT MANAGE GRANTS ON ACCOUNT TO ROLE MY_ROLE; +GRANT MONITOR EXECUTION ON ACCOUNT TO ROLE MY_ROLE; +GRANT MONITOR USAGE ON ACCOUNT TO ROLE MY_ROLE; +GRANT MONITOR ON USER SOME_USER TO ROLE MY_ROLE; +REVOKE MONITOR ON USER SOME_USER FROM ROLE MY_ROLE; +GRANT OVERRIDE SHARE RESTRICTIONS ON ACCOUNT TO ROLE MY_ROLE; +GRANT CREATE ACCOUNT ON ACCOUNT TO ROLE MY_ROLE; +GRANT CREATE SHARE ON ACCOUNT TO ROLE MY_ROLE; +GRANT CREATE NETWORK POLICY ON ACCOUNT TO ROLE MY_ROLE; +GRANT CREATE TAG ON SCHEMA MY_SCHEMA TO ROLE MY_ROLE; +GRANT CREATE DATA EXCHANGE LISTING ON ACCOUNT TO ROLE MY_ROLE; +GRANT CREATE CORTEX SEARCH SERVICE ON SCHEMA MY_SCHEMA TO ROLE MY_ROLE; +GRANT USAGE ON CORTEX SEARCH SERVICE MY_SERVICE TO ROLE MY_ROLE; +GRANT MANAGE ACCOUNT SUPPORT CASES ON ACCOUNT TO ROLE MY_ROLE; +GRANT MANAGE ORGANIZATION SUPPORT CASES ON ACCOUNT TO ROLE MY_ROLE; +GRANT MANAGE USER SUPPORT CASES ON ACCOUNT TO ROLE MY_ROLE; GRANT ADD SEARCH OPTIMIZATION ON SCHEMA MY_SCHEMA TO ROLE MY_ROLE; -REVOKE ADD SEARCH OPTIMIZATION ON SCHEMA MY_SCHEMA FROM ROLE MY_ROLE; + +GRANT DATABASE ROLE DBNAME.ROLENAME TO ROLE PUBLIC; +GRANT DATABASE ROLE DBROLENAME TO ROLE PUBLIC; +REVOKE DATABASE ROLE DBNAME.ROLENAME FROM ROLE PUBLIC; +REVOKE DATABASE ROLE DBROLENAME FROM ROLE PUBLIC; +GRANT SELECT ON TABLE DBNAME.SCHEMANAME.TABLENAME TO DATABASE ROLE DBNAME.ROLENAME; +GRANT SELECT ON TABLE DBNAME.SCHEMANAME.TABLENAME TO DATABASE ROLE DBROLENAME; +REVOKE SELECT ON TABLE DBNAME.SCHEMANAME.TABLENAME FROM DATABASE ROLE DBNAME.ROLENAME; +REVOKE SELECT ON TABLE DBNAME.SCHEMANAME.TABLENAME FROM DATABASE ROLE DBROLENAME; + +GRANT APPLICATION ROLE DBROLENAME TO ROLE PUBLIC; + +GRANT CREATE NOTEBOOK ON SCHEMA MY_DB.MYSCHEMA TO ROLE MYROLE; +GRANT OWNERSHIP ON NOTEBOOK MY_DB.MYSCHEMA.MYNOTEBOOK TO ROLE MYROLE; +GRANT USAGE ON NOTEBOOK MY_DB.MYSCHEMA.MYNOTEBOOK TO ROLE MYROLE; +REVOKE CREATE NOTEBOOK ON SCHEMA MY_DB.MYSCHEMA FROM ROLE MYROLE; +REVOKE USAGE ON NOTEBOOK MY_DB.MYSCHEMA.MYNOTEBOOK FROM ROLE MYROLE; + +GRANT CREATE MODEL ON SCHEMA MY_DB.MYSCHEMA TO ROLE MYROLE; +GRANT OWNERSHIP ON MODEL MY_DB.MYSCHEMA.MYMODEL TO ROLE MYROLE; +GRANT USAGE ON MODEL MY_DB.MYSCHEMA.MYMODEL TO ROLE MYROLE; +REVOKE CREATE MODEL ON SCHEMA MY_DB.MYSCHEMA FROM ROLE MYROLE; +REVOKE USAGE ON MODEL MY_DB.MYSCHEMA.MYMODEL FROM ROLE MYROLE; + +GRANT USAGE ON EXTERNAL VOLUME ext_vol TO ROLE MY_ROLE; +REVOKE USAGE ON EXTERNAL VOLUME ext_vol FROM ROLE MY_ROLE; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/grant_revoke.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/grant_revoke.yml index 4e9e17566..82b6b99c4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/grant_revoke.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/grant_revoke.yml @@ -27,85 +27,85 @@ file: - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: use_any_role - - keyword: on - - keyword: integration + - keyword: GRANT + - keyword: USE_ANY_ROLE + - keyword: ON + - keyword: INTEGRATION - object_reference: - - naked_identifier: external_oauth_1 - - keyword: to + - naked_identifier: EXTERNAL_OAUTH_1 + - keyword: TO - role_reference: - - naked_identifier: role1 + - naked_identifier: ROLE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: ownership - - keyword: on - - keyword: table + - keyword: GRANT + - keyword: OWNERSHIP + - keyword: ON + - keyword: TABLE - object_reference: - - naked_identifier: myschema + - naked_identifier: MYSCHEMA - dot: . - - naked_identifier: mytable - - keyword: to - - keyword: role + - naked_identifier: MYTABLE + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: ownership - - keyword: on - - keyword: all - - keyword: tables - - keyword: in - - keyword: schema + - keyword: GRANT + - keyword: OWNERSHIP + - keyword: ON + - keyword: ALL + - keyword: TABLES + - keyword: IN + - keyword: SCHEMA - object_reference: - - naked_identifier: public - - keyword: to - - keyword: role + - naked_identifier: PUBLIC + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: ownership - - keyword: on - - keyword: all - - keyword: tables - - keyword: in - - keyword: schema + - keyword: GRANT + - keyword: OWNERSHIP + - keyword: ON + - keyword: ALL + - keyword: TABLES + - keyword: IN + - keyword: SCHEMA - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: public - - keyword: to - - keyword: role + - naked_identifier: PUBLIC + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: ownership - - keyword: on - - keyword: all - - keyword: tables - - keyword: in - - keyword: schema + - keyword: GRANT + - keyword: OWNERSHIP + - keyword: ON + - keyword: ALL + - keyword: TABLES + - keyword: IN + - keyword: SCHEMA - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: public - - keyword: to - - keyword: role + - naked_identifier: PUBLIC + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst - - keyword: copy - - keyword: current - - keyword: grants + - naked_identifier: ANALYST + - keyword: COPY + - keyword: CURRENT + - keyword: GRANTS - statement_terminator: ; - statement: - access_statement: @@ -137,273 +137,273 @@ file: - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: all - - keyword: on - - keyword: all - - keyword: materialized - - keyword: views - - keyword: in - - keyword: database + - keyword: GRANT + - keyword: ALL + - keyword: ON + - keyword: ALL + - keyword: MATERIALIZED + - keyword: VIEWS + - keyword: IN + - keyword: DATABASE - object_reference: - - naked_identifier: my_db - - keyword: to - - keyword: role + - naked_identifier: MY_DB + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: all - - keyword: on - - keyword: all - - keyword: file - - keyword: formats - - keyword: in - - keyword: database + - keyword: GRANT + - keyword: ALL + - keyword: ON + - keyword: ALL + - keyword: FILE + - keyword: FORMATS + - keyword: IN + - keyword: DATABASE - object_reference: - - naked_identifier: my_db - - keyword: to - - keyword: role + - naked_identifier: MY_DB + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: create - - keyword: temporary - - keyword: table - - keyword: on - - keyword: schema + - keyword: GRANT + - keyword: CREATE + - keyword: TEMPORARY + - keyword: TABLE + - keyword: ON + - keyword: SCHEMA - object_reference: - - naked_identifier: my_db + - naked_identifier: MY_DB - dot: . - - naked_identifier: my_schema - - keyword: to - - keyword: role + - naked_identifier: MY_SCHEMA + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: all - - keyword: on - - keyword: future - - keyword: pipes - - keyword: in - - keyword: database + - keyword: GRANT + - keyword: ALL + - keyword: ON + - keyword: FUTURE + - keyword: PIPES + - keyword: IN + - keyword: DATABASE - object_reference: - - naked_identifier: my_db - - keyword: to - - keyword: role + - naked_identifier: MY_DB + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: all - - keyword: on - - keyword: future - - keyword: file - - keyword: formats - - keyword: in - - keyword: database + - keyword: GRANT + - keyword: ALL + - keyword: ON + - keyword: FUTURE + - keyword: FILE + - keyword: FORMATS + - keyword: IN + - keyword: DATABASE - object_reference: - - naked_identifier: my_db - - keyword: to - - keyword: role + - naked_identifier: MY_DB + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: all - - keyword: on - - keyword: future - - keyword: materialized - - keyword: views - - keyword: in - - keyword: database + - keyword: GRANT + - keyword: ALL + - keyword: ON + - keyword: FUTURE + - keyword: MATERIALIZED + - keyword: VIEWS + - keyword: IN + - keyword: DATABASE - object_reference: - - naked_identifier: my_db - - keyword: to - - keyword: role + - naked_identifier: MY_DB + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: all - - keyword: on - - keyword: future - - keyword: pipes - - keyword: in - - keyword: database + - keyword: GRANT + - keyword: ALL + - keyword: ON + - keyword: FUTURE + - keyword: PIPES + - keyword: IN + - keyword: DATABASE - object_reference: - - naked_identifier: my_db - - keyword: to - - keyword: role + - naked_identifier: MY_DB + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: usage - - keyword: on - - keyword: all - - keyword: sequences - - keyword: in - - keyword: database + - keyword: GRANT + - keyword: USAGE + - keyword: ON + - keyword: ALL + - keyword: SEQUENCES + - keyword: IN + - keyword: DATABASE - object_reference: - - naked_identifier: my_db - - keyword: to - - keyword: role + - naked_identifier: MY_DB + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: all - - keyword: on - - keyword: all - - keyword: materialized - - keyword: views - - keyword: in - - keyword: database + - keyword: GRANT + - keyword: ALL + - keyword: ON + - keyword: ALL + - keyword: MATERIALIZED + - keyword: VIEWS + - keyword: IN + - keyword: DATABASE - object_reference: - - naked_identifier: my_db - - keyword: to - - keyword: role + - naked_identifier: MY_DB + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: all - - keyword: on - - keyword: all - - keyword: sequences - - keyword: in - - keyword: database + - keyword: GRANT + - keyword: ALL + - keyword: ON + - keyword: ALL + - keyword: SEQUENCES + - keyword: IN + - keyword: DATABASE - object_reference: - - naked_identifier: my_db - - keyword: to - - keyword: role + - naked_identifier: MY_DB + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: all - - keyword: on - - keyword: all - - keyword: functions - - keyword: in - - keyword: database + - keyword: GRANT + - keyword: ALL + - keyword: ON + - keyword: ALL + - keyword: FUNCTIONS + - keyword: IN + - keyword: DATABASE - object_reference: - - naked_identifier: my_db - - keyword: to - - keyword: role + - naked_identifier: MY_DB + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: all - - keyword: on - - keyword: all - - keyword: file - - keyword: formats - - keyword: in - - keyword: database + - keyword: GRANT + - keyword: ALL + - keyword: ON + - keyword: ALL + - keyword: FILE + - keyword: FORMATS + - keyword: IN + - keyword: DATABASE - object_reference: - - naked_identifier: my_db - - keyword: to - - keyword: role + - naked_identifier: MY_DB + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: all - - keyword: on - - keyword: all - - keyword: stages - - keyword: in - - keyword: database + - keyword: GRANT + - keyword: ALL + - keyword: ON + - keyword: ALL + - keyword: STAGES + - keyword: IN + - keyword: DATABASE - object_reference: - - naked_identifier: my_db - - keyword: to - - keyword: role + - naked_identifier: MY_DB + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: select - - keyword: on - - keyword: all - - keyword: views - - keyword: in - - keyword: database + - keyword: GRANT + - keyword: SELECT + - keyword: ON + - keyword: ALL + - keyword: VIEWS + - keyword: IN + - keyword: DATABASE - object_reference: - - naked_identifier: my_db - - keyword: to - - keyword: role + - naked_identifier: MY_DB + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: revoke - - keyword: role + - keyword: REVOKE + - keyword: ROLE - object_reference: - - naked_identifier: analyst - - keyword: from - - keyword: role + - naked_identifier: ANALYST + - keyword: FROM + - keyword: ROLE - object_reference: - - naked_identifier: sysadmin + - naked_identifier: SYSADMIN - statement_terminator: ; - statement: - access_statement: - - keyword: revoke - - keyword: select + - keyword: REVOKE + - keyword: SELECT - comma: ',' - - keyword: insert - - keyword: on - - keyword: future - - keyword: tables - - keyword: in - - keyword: schema + - keyword: INSERT + - keyword: ON + - keyword: FUTURE + - keyword: TABLES + - keyword: IN + - keyword: SCHEMA - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: myschema - - keyword: from - - keyword: role + - naked_identifier: MYSCHEMA + - keyword: FROM + - keyword: ROLE - object_reference: - - naked_identifier: role1 + - naked_identifier: ROLE1 - statement_terminator: ; - statement: - access_statement: - - keyword: revoke - - keyword: all - - keyword: privileges - - keyword: on - - keyword: function + - keyword: REVOKE + - keyword: ALL + - keyword: PRIVILEGES + - keyword: ON + - keyword: FUNCTION - function_name: - function_name_identifier: add5 - function_parameter_list: @@ -412,70 +412,70 @@ file: - data_type: - data_type_identifier: number - end_bracket: ) - - keyword: from - - keyword: role + - keyword: FROM + - keyword: ROLE - object_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: revoke - - keyword: grant - - keyword: option - - keyword: for - - keyword: operate - - keyword: on - - keyword: warehouse + - keyword: REVOKE + - keyword: GRANT + - keyword: OPTION + - keyword: FOR + - keyword: OPERATE + - keyword: ON + - keyword: WAREHOUSE - object_reference: - - naked_identifier: report_wh - - keyword: from - - keyword: role + - naked_identifier: REPORT_WH + - keyword: FROM + - keyword: ROLE - object_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: revoke - - keyword: select - - keyword: on - - keyword: all - - keyword: tables - - keyword: in - - keyword: schema + - keyword: REVOKE + - keyword: SELECT + - keyword: ON + - keyword: ALL + - keyword: TABLES + - keyword: IN + - keyword: SCHEMA - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: myschema - - keyword: from - - keyword: role + - naked_identifier: MYSCHEMA + - keyword: FROM + - keyword: ROLE - object_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: revoke - - keyword: operate - - keyword: on - - keyword: warehouse + - keyword: REVOKE + - keyword: OPERATE + - keyword: ON + - keyword: WAREHOUSE - object_reference: - - naked_identifier: report_wh - - keyword: from - - keyword: role + - naked_identifier: REPORT_WH + - keyword: FROM + - keyword: ROLE - object_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: revoke - - keyword: reference_usage - - keyword: on - - keyword: database + - keyword: REVOKE + - keyword: REFERENCE_USAGE + - keyword: ON + - keyword: DATABASE - object_reference: - - naked_identifier: database2 - - keyword: from - - keyword: share + - naked_identifier: DATABASE2 + - keyword: FROM + - keyword: SHARE - object_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: @@ -492,58 +492,112 @@ file: - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: operate - - keyword: on - - keyword: warehouse + - keyword: GRANT + - keyword: IMPORTED + - keyword: PRIVILEGES + - keyword: ON + - keyword: SCHEMA + - object_reference: + - naked_identifier: MYDB + - dot: . + - naked_identifier: MYSCHEMA + - keyword: TO + - keyword: APPLICATION + - role_reference: + - naked_identifier: MY_APP +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: OPERATE + - keyword: ON + - keyword: WAREHOUSE - object_reference: - - naked_identifier: report_wh - - keyword: to - - keyword: role + - naked_identifier: REPORT_WH + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: operate - - keyword: on - - keyword: warehouse + - keyword: GRANT + - keyword: OPERATE + - keyword: ON + - keyword: WAREHOUSE - object_reference: - - naked_identifier: report_wh - - keyword: to - - keyword: role + - naked_identifier: REPORT_WH + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst - - keyword: with - - keyword: grant - - keyword: option + - naked_identifier: ANALYST + - keyword: WITH + - keyword: GRANT + - keyword: OPTION - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: select - - keyword: on - - keyword: all - - keyword: tables - - keyword: in - - keyword: schema + - keyword: GRANT + - keyword: OPERATE + - keyword: ON + - keyword: FUTURE + - keyword: DYNAMIC + - keyword: TABLES + - keyword: IN + - keyword: SCHEMA - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: myschema - - keyword: to - - keyword: role + - naked_identifier: MYSCHEMA + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: ANALYST +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: OPERATE + - keyword: ON + - keyword: ALL + - keyword: DYNAMIC + - keyword: TABLES + - keyword: IN + - keyword: SCHEMA + - object_reference: + - naked_identifier: MYDB + - dot: . + - naked_identifier: MYSCHEMA + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: ANALYST +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: SELECT + - keyword: ON + - keyword: ALL + - keyword: TABLES + - keyword: IN + - keyword: SCHEMA + - object_reference: + - naked_identifier: MYDB + - dot: . + - naked_identifier: MYSCHEMA + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: all - - keyword: privileges - - keyword: on - - keyword: function + - keyword: GRANT + - keyword: ALL + - keyword: PRIVILEGES + - keyword: ON + - keyword: FUNCTION - function_name: - naked_identifier: mydb - dot: . @@ -556,18 +610,18 @@ file: - data_type: - data_type_identifier: number - end_bracket: ) - - keyword: to - - keyword: role + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: all - - keyword: privileges - - keyword: on - - keyword: function + - keyword: GRANT + - keyword: ALL + - keyword: PRIVILEGES + - keyword: ON + - keyword: FUNCTION - function_name: - naked_identifier: mydb - dot: . @@ -580,17 +634,17 @@ file: - data_type: - data_type_identifier: string - end_bracket: ) - - keyword: to - - keyword: role + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: usage - - keyword: on - - keyword: procedure + - keyword: GRANT + - keyword: USAGE + - keyword: ON + - keyword: PROCEDURE - function_name: - naked_identifier: mydb - dot: . @@ -603,248 +657,248 @@ file: - data_type: - data_type_identifier: number - end_bracket: ) - - keyword: to - - keyword: role + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: create - - keyword: materialized - - keyword: view - - keyword: on - - keyword: schema + - keyword: GRANT + - keyword: CREATE + - keyword: MATERIALIZED + - keyword: VIEW + - keyword: ON + - keyword: SCHEMA - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: myschema - - keyword: to - - keyword: role + - naked_identifier: MYSCHEMA + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: myrole + - naked_identifier: MYROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: select + - keyword: GRANT + - keyword: SELECT - comma: ',' - - keyword: insert - - keyword: on - - keyword: future - - keyword: tables - - keyword: in - - keyword: schema + - keyword: INSERT + - keyword: ON + - keyword: FUTURE + - keyword: TABLES + - keyword: IN + - keyword: SCHEMA - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: myschema - - keyword: to - - keyword: role + - naked_identifier: MYSCHEMA + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: role1 + - naked_identifier: ROLE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: usage - - keyword: on - - keyword: future - - keyword: schemas - - keyword: in - - keyword: database + - keyword: GRANT + - keyword: USAGE + - keyword: ON + - keyword: FUTURE + - keyword: SCHEMAS + - keyword: IN + - keyword: DATABASE - object_reference: - - naked_identifier: mydb - - keyword: to - - keyword: role + - naked_identifier: MYDB + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: role1 + - naked_identifier: ROLE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: usage - - keyword: on - - keyword: database + - keyword: GRANT + - keyword: USAGE + - keyword: ON + - keyword: DATABASE - object_reference: - - naked_identifier: database1 - - keyword: to - - keyword: share + - naked_identifier: DATABASE1 + - keyword: TO + - keyword: SHARE - role_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: usage - - keyword: on - - keyword: schema + - keyword: GRANT + - keyword: USAGE + - keyword: ON + - keyword: SCHEMA - object_reference: - - naked_identifier: database1 + - naked_identifier: DATABASE1 - dot: . - - naked_identifier: schema1 - - keyword: to - - keyword: share + - naked_identifier: SCHEMA1 + - keyword: TO + - keyword: SHARE - role_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: reference_usage - - keyword: on - - keyword: database + - keyword: GRANT + - keyword: REFERENCE_USAGE + - keyword: ON + - keyword: DATABASE - object_reference: - - naked_identifier: database2 - - keyword: to - - keyword: share + - naked_identifier: DATABASE2 + - keyword: TO + - keyword: SHARE - role_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: select - - keyword: on - - keyword: view + - keyword: GRANT + - keyword: SELECT + - keyword: ON + - keyword: VIEW - object_reference: - - naked_identifier: view2 - - keyword: to - - keyword: share + - naked_identifier: VIEW2 + - keyword: TO + - keyword: SHARE - role_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: usage - - keyword: on - - keyword: database + - keyword: GRANT + - keyword: USAGE + - keyword: ON + - keyword: DATABASE - object_reference: - - naked_identifier: mydb - - keyword: to - - keyword: share + - naked_identifier: MYDB + - keyword: TO + - keyword: SHARE - role_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: usage - - keyword: on - - keyword: schema + - keyword: GRANT + - keyword: USAGE + - keyword: ON + - keyword: SCHEMA - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: public - - keyword: to - - keyword: share + - naked_identifier: PUBLIC + - keyword: TO + - keyword: SHARE - role_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: usage - - keyword: on - - keyword: function + - keyword: GRANT + - keyword: USAGE + - keyword: ON + - keyword: FUNCTION - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: shared_schema + - naked_identifier: SHARED_SCHEMA - dot: . - - naked_identifier: function1 - - keyword: to - - keyword: share + - naked_identifier: FUNCTION1 + - keyword: TO + - keyword: SHARE - role_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: select - - keyword: on - - keyword: all - - keyword: tables - - keyword: in - - keyword: schema + - keyword: GRANT + - keyword: SELECT + - keyword: ON + - keyword: ALL + - keyword: TABLES + - keyword: IN + - keyword: SCHEMA - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: public - - keyword: to - - keyword: share + - naked_identifier: PUBLIC + - keyword: TO + - keyword: SHARE - role_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: usage - - keyword: on - - keyword: schema + - keyword: GRANT + - keyword: USAGE + - keyword: ON + - keyword: SCHEMA - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: shared_schema - - keyword: to - - keyword: share + - naked_identifier: SHARED_SCHEMA + - keyword: TO + - keyword: SHARE - role_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: select - - keyword: on - - keyword: view + - keyword: GRANT + - keyword: SELECT + - keyword: ON + - keyword: VIEW - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: shared_schema + - naked_identifier: SHARED_SCHEMA - dot: . - - naked_identifier: view1 - - keyword: to - - keyword: share + - naked_identifier: VIEW1 + - keyword: TO + - keyword: SHARE - role_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: select - - keyword: on - - keyword: view + - keyword: GRANT + - keyword: SELECT + - keyword: ON + - keyword: VIEW - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: shared_schema + - naked_identifier: SHARED_SCHEMA - dot: . - - naked_identifier: view3 - - keyword: to - - keyword: share + - naked_identifier: VIEW3 + - keyword: TO + - keyword: SHARE - role_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: role + - keyword: GRANT + - keyword: ROLE - object_reference: - - naked_identifier: analyst - - keyword: to - - keyword: user + - naked_identifier: ANALYST + - keyword: TO + - keyword: USER - role_reference: - - naked_identifier: user1 + - naked_identifier: USER1 - statement_terminator: ; - statement: - access_statement: - - keyword: revoke - - keyword: all - - keyword: privileges - - keyword: on - - keyword: procedure + - keyword: REVOKE + - keyword: ALL + - keyword: PRIVILEGES + - keyword: ON + - keyword: PROCEDURE - function_name: - function_name_identifier: clean_schema - function_parameter_list: @@ -853,18 +907,18 @@ file: - data_type: - data_type_identifier: string - end_bracket: ) - - keyword: from - - keyword: role + - keyword: FROM + - keyword: ROLE - object_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: revoke - - keyword: all - - keyword: privileges - - keyword: on - - keyword: function + - keyword: REVOKE + - keyword: ALL + - keyword: PRIVILEGES + - keyword: ON + - keyword: FUNCTION - function_name: - function_name_identifier: add5 - function_parameter_list: @@ -873,276 +927,372 @@ file: - data_type: - data_type_identifier: string - end_bracket: ) - - keyword: from - - keyword: role + - keyword: FROM + - keyword: ROLE - object_reference: - - naked_identifier: analyst + - naked_identifier: ANALYST - statement_terminator: ; - statement: - access_statement: - - keyword: revoke - - keyword: select - - keyword: on - - keyword: view + - keyword: REVOKE + - keyword: SELECT + - keyword: ON + - keyword: VIEW - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: shared_schema + - naked_identifier: SHARED_SCHEMA - dot: . - - naked_identifier: view1 - - keyword: from - - keyword: share + - naked_identifier: VIEW1 + - keyword: FROM + - keyword: SHARE - object_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: revoke - - keyword: usage - - keyword: on - - keyword: schema + - keyword: REVOKE + - keyword: USAGE + - keyword: ON + - keyword: SCHEMA - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: shared_schema - - keyword: from - - keyword: share + - naked_identifier: SHARED_SCHEMA + - keyword: FROM + - keyword: SHARE - object_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: revoke - - keyword: select - - keyword: on - - keyword: all - - keyword: tables - - keyword: in - - keyword: schema + - keyword: REVOKE + - keyword: SELECT + - keyword: ON + - keyword: ALL + - keyword: TABLES + - keyword: IN + - keyword: SCHEMA - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: public - - keyword: from - - keyword: share + - naked_identifier: PUBLIC + - keyword: FROM + - keyword: SHARE - object_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: revoke - - keyword: usage - - keyword: on - - keyword: schema + - keyword: REVOKE + - keyword: USAGE + - keyword: ON + - keyword: SCHEMA - object_reference: - - naked_identifier: mydb + - naked_identifier: MYDB - dot: . - - naked_identifier: public - - keyword: from - - keyword: share + - naked_identifier: PUBLIC + - keyword: FROM + - keyword: SHARE - object_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: revoke - - keyword: usage - - keyword: on - - keyword: database + - keyword: REVOKE + - keyword: USAGE + - keyword: ON + - keyword: DATABASE - object_reference: - - naked_identifier: mydb - - keyword: from - - keyword: share + - naked_identifier: MYDB + - keyword: FROM + - keyword: SHARE - object_reference: - - naked_identifier: share1 + - naked_identifier: SHARE1 - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: apply - - keyword: masking - - keyword: policy - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: GRANT + - keyword: APPLY + - keyword: MASKING + - keyword: POLICY + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: apply - - keyword: row - - keyword: access - - keyword: policy - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: GRANT + - keyword: APPLY + - keyword: ROW + - keyword: ACCESS + - keyword: POLICY + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: apply - - keyword: session - - keyword: policy - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: GRANT + - keyword: APPLY + - keyword: SESSION + - keyword: POLICY + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: apply - - keyword: tag - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: GRANT + - keyword: APPLY + - keyword: TAG + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: attach - - keyword: policy - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: GRANT + - keyword: ATTACH + - keyword: POLICY + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: execute - - keyword: task - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: GRANT + - keyword: EXECUTE + - keyword: ALERT + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: import - - keyword: share - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: GRANT + - keyword: EXECUTE + - keyword: TASK + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: manage - - keyword: grants - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: GRANT + - keyword: EXECUTE + - keyword: MANAGED + - keyword: TASK + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: monitor - - keyword: execution - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: GRANT + - keyword: IMPORT + - keyword: SHARE + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: monitor - - keyword: usage - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: GRANT + - keyword: MANAGE + - keyword: GRANTS + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: override - - keyword: share - - keyword: restrictions - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: GRANT + - keyword: MONITOR + - keyword: EXECUTION + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: create - - keyword: account - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: GRANT + - keyword: MONITOR + - keyword: USAGE + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: create - - keyword: share - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: GRANT + - keyword: MONITOR + - keyword: ON + - keyword: USER + - object_reference: + - naked_identifier: SOME_USER + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: create - - keyword: network - - keyword: policy - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: REVOKE + - keyword: MONITOR + - keyword: ON + - keyword: USER + - object_reference: + - naked_identifier: SOME_USER + - keyword: FROM + - keyword: ROLE + - object_reference: + - naked_identifier: MY_ROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: OVERRIDE + - keyword: SHARE + - keyword: RESTRICTIONS + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: MY_ROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: CREATE + - keyword: ACCOUNT + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: - - keyword: grant - - keyword: create - - keyword: data - - keyword: exchange - - keyword: listing - - keyword: on - - keyword: account - - keyword: to - - keyword: role + - keyword: GRANT + - keyword: CREATE + - keyword: SHARE + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: MY_ROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: CREATE + - keyword: NETWORK + - keyword: POLICY + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: CREATE + - keyword: TAG + - keyword: ON + - keyword: SCHEMA + - object_reference: + - naked_identifier: MY_SCHEMA + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: MY_ROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: CREATE + - keyword: DATA + - keyword: EXCHANGE + - keyword: LISTING + - keyword: ON + - keyword: ACCOUNT + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: MY_ROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: CREATE + - keyword: CORTEX + - keyword: SEARCH + - keyword: SERVICE + - keyword: ON + - keyword: SCHEMA + - object_reference: + - naked_identifier: MY_SCHEMA + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: MY_ROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: USAGE + - keyword: ON + - keyword: CORTEX + - keyword: SEARCH + - keyword: SERVICE + - object_reference: + - naked_identifier: MY_SERVICE + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: @@ -1156,7 +1306,7 @@ file: - keyword: TO - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: @@ -1170,7 +1320,7 @@ file: - keyword: TO - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: @@ -1184,7 +1334,7 @@ file: - keyword: TO - keyword: ROLE - role_reference: - - naked_identifier: my_role + - naked_identifier: MY_ROLE - statement_terminator: ; - statement: - access_statement: @@ -1194,25 +1344,342 @@ file: - keyword: OPTIMIZATION - keyword: ON - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: MY_SCHEMA + - schema_reference: + - naked_identifier: MY_SCHEMA - keyword: TO - keyword: ROLE - role_reference: - naked_identifier: MY_ROLE - statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: DATABASE + - keyword: ROLE + - database_role_reference: + - naked_identifier: DBNAME + - dot: . + - naked_identifier: ROLENAME + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: PUBLIC +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: DATABASE + - keyword: ROLE + - database_role_reference: + - naked_identifier: DBROLENAME + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: PUBLIC +- statement_terminator: ; - statement: - access_statement: - keyword: REVOKE - - keyword: ADD - - keyword: SEARCH - - keyword: OPTIMIZATION + - keyword: DATABASE + - keyword: ROLE + - database_role_reference: + - naked_identifier: DBNAME + - dot: . + - naked_identifier: ROLENAME + - keyword: FROM + - keyword: ROLE + - object_reference: + - naked_identifier: PUBLIC +- statement_terminator: ; +- statement: + - access_statement: + - keyword: REVOKE + - keyword: DATABASE + - keyword: ROLE + - database_role_reference: + - naked_identifier: DBROLENAME + - keyword: FROM + - keyword: ROLE + - object_reference: + - naked_identifier: PUBLIC +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: SELECT + - keyword: ON + - keyword: TABLE + - object_reference: + - naked_identifier: DBNAME + - dot: . + - naked_identifier: SCHEMANAME + - dot: . + - naked_identifier: TABLENAME + - keyword: TO + - keyword: DATABASE + - keyword: ROLE + - database_role_reference: + - naked_identifier: DBNAME + - dot: . + - naked_identifier: ROLENAME +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: SELECT + - keyword: ON + - keyword: TABLE + - object_reference: + - naked_identifier: DBNAME + - dot: . + - naked_identifier: SCHEMANAME + - dot: . + - naked_identifier: TABLENAME + - keyword: TO + - keyword: DATABASE + - keyword: ROLE + - role_reference: + - naked_identifier: DBROLENAME +- statement_terminator: ; +- statement: + - access_statement: + - keyword: REVOKE + - keyword: SELECT + - keyword: ON + - keyword: TABLE + - object_reference: + - naked_identifier: DBNAME + - dot: . + - naked_identifier: SCHEMANAME + - dot: . + - naked_identifier: TABLENAME + - keyword: FROM + - keyword: DATABASE + - keyword: ROLE + - object_reference: + - naked_identifier: DBNAME + - dot: . + - naked_identifier: ROLENAME +- statement_terminator: ; +- statement: + - access_statement: + - keyword: REVOKE + - keyword: SELECT + - keyword: ON + - keyword: TABLE + - object_reference: + - naked_identifier: DBNAME + - dot: . + - naked_identifier: SCHEMANAME + - dot: . + - naked_identifier: TABLENAME + - keyword: FROM + - keyword: DATABASE + - keyword: ROLE + - object_reference: + - naked_identifier: DBROLENAME +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: APPLICATION + - keyword: ROLE + - object_reference: + - naked_identifier: DBROLENAME + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: PUBLIC +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: CREATE + - keyword: NOTEBOOK - keyword: ON - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: MY_SCHEMA + - object_reference: + - naked_identifier: MY_DB + - dot: . + - naked_identifier: MYSCHEMA + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: MYROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: OWNERSHIP + - keyword: ON + - keyword: NOTEBOOK + - object_reference: + - naked_identifier: MY_DB + - dot: . + - naked_identifier: MYSCHEMA + - dot: . + - naked_identifier: MYNOTEBOOK + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: MYROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: USAGE + - keyword: ON + - keyword: NOTEBOOK + - object_reference: + - naked_identifier: MY_DB + - dot: . + - naked_identifier: MYSCHEMA + - dot: . + - naked_identifier: MYNOTEBOOK + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: MYROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: REVOKE + - keyword: CREATE + - keyword: NOTEBOOK + - keyword: ON + - keyword: SCHEMA + - object_reference: + - naked_identifier: MY_DB + - dot: . + - naked_identifier: MYSCHEMA + - keyword: FROM + - keyword: ROLE + - object_reference: + - naked_identifier: MYROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: REVOKE + - keyword: USAGE + - keyword: ON + - keyword: NOTEBOOK + - object_reference: + - naked_identifier: MY_DB + - dot: . + - naked_identifier: MYSCHEMA + - dot: . + - naked_identifier: MYNOTEBOOK + - keyword: FROM + - keyword: ROLE + - object_reference: + - naked_identifier: MYROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: CREATE + - keyword: MODEL + - keyword: ON + - keyword: SCHEMA + - object_reference: + - naked_identifier: MY_DB + - dot: . + - naked_identifier: MYSCHEMA + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: MYROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: OWNERSHIP + - keyword: ON + - keyword: MODEL + - object_reference: + - naked_identifier: MY_DB + - dot: . + - naked_identifier: MYSCHEMA + - dot: . + - naked_identifier: MYMODEL + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: MYROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: USAGE + - keyword: ON + - keyword: MODEL + - object_reference: + - naked_identifier: MY_DB + - dot: . + - naked_identifier: MYSCHEMA + - dot: . + - naked_identifier: MYMODEL + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: MYROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: REVOKE + - keyword: CREATE + - keyword: MODEL + - keyword: ON + - keyword: SCHEMA + - object_reference: + - naked_identifier: MY_DB + - dot: . + - naked_identifier: MYSCHEMA + - keyword: FROM + - keyword: ROLE + - object_reference: + - naked_identifier: MYROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: REVOKE + - keyword: USAGE + - keyword: ON + - keyword: MODEL + - object_reference: + - naked_identifier: MY_DB + - dot: . + - naked_identifier: MYSCHEMA + - dot: . + - naked_identifier: MYMODEL + - keyword: FROM + - keyword: ROLE + - object_reference: + - naked_identifier: MYROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: GRANT + - keyword: USAGE + - keyword: ON + - keyword: EXTERNAL + - keyword: VOLUME + - object_reference: + - naked_identifier: ext_vol + - keyword: TO + - keyword: ROLE + - role_reference: + - naked_identifier: MY_ROLE +- statement_terminator: ; +- statement: + - access_statement: + - keyword: REVOKE + - keyword: USAGE + - keyword: ON + - keyword: EXTERNAL + - keyword: VOLUME + - object_reference: + - naked_identifier: ext_vol - keyword: FROM - keyword: ROLE - object_reference: diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/group_by_all.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/group_by_all.yml index da47d0aad..b57785f11 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/group_by_all.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/group_by_all.yml @@ -26,7 +26,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: gross_revenue - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/identifier_pseudo_function.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/identifier_pseudo_function.yml index 23f7b9b3c..b851ee020 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/identifier_pseudo_function.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/identifier_pseudo_function.yml @@ -3,25 +3,23 @@ file: - use_statement: - keyword: USE - keyword: SCHEMA - - table_reference: - - object_reference: - - keyword: identifier - - bracketed: - - start_bracket: ( - - quoted_identifier: '''my_schema''' - - end_bracket: ) + - schema_reference: + - keyword: identifier + - bracketed: + - start_bracket: ( + - quoted_identifier: '''my_schema''' + - end_bracket: ) - statement_terminator: ; - statement: - use_statement: - keyword: USE - keyword: SCHEMA - - table_reference: - - object_reference: - - keyword: identifier - - bracketed: - - start_bracket: ( - - quoted_identifier: '''{{ params.schema_name }}''' - - end_bracket: ) + - schema_reference: + - keyword: identifier + - bracketed: + - start_bracket: ( + - quoted_identifier: '''{{ params.schema_name }}''' + - end_bracket: ) - statement_terminator: ; - statement: - create_statement: @@ -42,13 +40,12 @@ file: - keyword: or - keyword: replace - keyword: schema - - table_reference: - - object_reference: - - keyword: identifier - - bracketed: - - start_bracket: ( - - quoted_identifier: '''my_schema''' - - end_bracket: ) + - schema_reference: + - keyword: identifier + - bracketed: + - start_bracket: ( + - quoted_identifier: '''my_schema''' + - end_bracket: ) - statement_terminator: ; - statement: - create_table_statement: @@ -107,13 +104,12 @@ file: - use_statement: - keyword: use - keyword: schema - - table_reference: - - object_reference: - - keyword: identifier - - bracketed: - - start_bracket: ( - - variable: $schema_name - - end_bracket: ) + - schema_reference: + - keyword: identifier + - bracketed: + - start_bracket: ( + - variable: $schema_name + - end_bracket: ) - statement_terminator: ; - statement: - insert_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/if_statement.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/if_statement.sql new file mode 100644 index 000000000..7e6aa0443 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/if_statement.sql @@ -0,0 +1,15 @@ +BEGIN + IF (1 + 1 = 2) THEN + SELECT 1; + SELECT 2; + ELSEIF (2 + 2 = 4) THEN + SELECT 3; + SELECT 4; + ELSEIF (3 + 3 = 6) THEN + SELECT 5; + SELECT 6; + ELSE + SELECT 7; + SELECT 8; + END IF; +END; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/if_statement.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/if_statement.yml new file mode 100644 index 000000000..c09b355ff --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/if_statement.yml @@ -0,0 +1,104 @@ +file: +- statement: + - scripting_block_statement: + - keyword: BEGIN + - statement: + - scripting_if_statement: + - keyword: IF + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - binary_operator: + + - numeric_literal: '1' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' + - end_bracket: ) + - keyword: THEN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' + - statement_terminator: ; + - keyword: ELSEIF + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - binary_operator: + + - numeric_literal: '2' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '4' + - end_bracket: ) + - keyword: THEN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '3' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '4' + - statement_terminator: ; + - keyword: ELSEIF + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - binary_operator: + + - numeric_literal: '3' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '6' + - end_bracket: ) + - keyword: THEN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '5' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '6' + - statement_terminator: ; + - keyword: ELSE + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '7' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '8' + - statement_terminator: ; + - keyword: END + - keyword: IF + - statement_terminator: ; + - keyword: END +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/insert.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/insert.yml index 6f68fc022..25ac2b302 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/insert.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/insert.yml @@ -350,7 +350,8 @@ file: - select_clause_element: - numeric_literal: '50' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: an_alias - comma: ',' - select_clause_element: @@ -387,7 +388,8 @@ file: - dot: . - naked_identifier: key - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: key - comma: ',' - select_clause_element: @@ -396,7 +398,8 @@ file: - dot: . - naked_identifier: a - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: a - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/lateral_flatten_after_join.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/lateral_flatten_after_join.yml index a5a04f41a..6d19e85e5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/lateral_flatten_after_join.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/lateral_flatten_after_join.yml @@ -7,7 +7,8 @@ file: - column_reference: - naked_identifier: value - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: p_id - comma: ',' - select_clause_element: @@ -58,7 +59,8 @@ file: - boolean_literal: 'false' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: most_recent - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/let.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/let.sql index 0cff66494..9b496d6db 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/let.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/let.sql @@ -16,3 +16,6 @@ begin -- resultset reassignment someresult := (select SOME_COL from some_database.schema.some_table); end; + +LET VARIABLE := SOME_VALUE; +SELECT :variable FROM my_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/let.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/let.yml index 712080ad7..d39d98f63 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/let.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/let.yml @@ -9,146 +9,169 @@ file: - assignment_operator: := - expression: - numeric_literal: '5' -- statement_terminator: ; -- statement: - - scripting_let_statement: - - keyword: let - - variable: somevariable - - data_type: - - data_type_identifier: number - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '38' - - comma: ',' - - numeric_literal: '0' - - end_bracket: ) - - assignment_operator: := - - expression: - - numeric_literal: '5' -- statement_terminator: ; -- statement: - - scripting_let_statement: - - keyword: let - - variable: somevariable - - data_type: - - data_type_identifier: number - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '38' - - comma: ',' - - numeric_literal: '0' - - end_bracket: ) - - keyword: default - - expression: - - numeric_literal: '5' -- statement_terminator: ; -- statement: - - scripting_let_statement: - - keyword: let - - variable: somevariable - - keyword: default - - expression: - - numeric_literal: '5' -- statement_terminator: ; -- statement: - - scripting_let_statement: - - variable: somevariable - - assignment_operator: := - - expression: - - numeric_literal: '5' -- statement_terminator: ; -- statement: - - scripting_let_statement: - - keyword: let - - variable: somevariable - - keyword: cursor - - keyword: for - - select_statement: - - select_clause: - - keyword: select - - select_clause_element: - - column_reference: - - naked_identifier: some_col - - from_clause: - - keyword: from - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: some_database - - dot: . - - naked_identifier: schema - - dot: . - - naked_identifier: some_table -- statement_terminator: ; -- statement: - - scripting_let_statement: - - keyword: let - - variable: somevariable - - keyword: cursor - - keyword: for - - variable: somevariable -- statement_terminator: ; -- statement: - - scripting_let_statement: - - keyword: let - - variable: someresult - - data_type: - - data_type_identifier: resultset - - assignment_operator: := - - expression: - - bracketed: - - start_bracket: ( + - statement_terminator: ; + - statement: + - scripting_let_statement: + - keyword: let + - variable: somevariable + - data_type: + - data_type_identifier: number + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '38' + - comma: ',' + - numeric_literal: '0' + - end_bracket: ) + - assignment_operator: := - expression: - - select_statement: - - select_clause: - - keyword: select - - select_clause_element: - - column_reference: - - naked_identifier: some_col - - from_clause: - - keyword: from - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: some_database - - dot: . - - naked_identifier: schema - - dot: . - - naked_identifier: some_table - - end_bracket: ) + - numeric_literal: '5' + - statement_terminator: ; + - statement: + - scripting_let_statement: + - keyword: let + - variable: somevariable + - data_type: + - data_type_identifier: number + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '38' + - comma: ',' + - numeric_literal: '0' + - end_bracket: ) + - keyword: default + - expression: + - numeric_literal: '5' + - statement_terminator: ; + - statement: + - scripting_let_statement: + - keyword: let + - variable: somevariable + - keyword: default + - expression: + - numeric_literal: '5' + - statement_terminator: ; + - statement: + - scripting_let_statement: + - variable: somevariable + - assignment_operator: := + - expression: + - numeric_literal: '5' + - statement_terminator: ; + - statement: + - scripting_let_statement: + - keyword: let + - variable: somevariable + - keyword: cursor + - keyword: for + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: some_col + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: some_database + - dot: . + - naked_identifier: schema + - dot: . + - naked_identifier: some_table + - statement_terminator: ; + - statement: + - scripting_let_statement: + - keyword: let + - variable: somevariable + - keyword: cursor + - keyword: for + - variable: somevariable + - statement_terminator: ; + - statement: + - scripting_let_statement: + - keyword: let + - variable: someresult + - data_type: + - data_type_identifier: resultset + - assignment_operator: := + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: some_col + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: some_database + - dot: . + - naked_identifier: schema + - dot: . + - naked_identifier: some_table + - end_bracket: ) + - statement_terminator: ; + - statement: + - scripting_let_statement: + - variable: someresult + - assignment_operator: := + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: SOME_COL + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: some_database + - dot: . + - naked_identifier: schema + - dot: . + - naked_identifier: some_table + - end_bracket: ) + - statement_terminator: ; + - keyword: end - statement_terminator: ; - statement: - scripting_let_statement: - - variable: someresult + - keyword: LET + - variable: VARIABLE - assignment_operator: := - expression: - - bracketed: - - start_bracket: ( - - expression: - - select_statement: - - select_clause: - - keyword: select - - select_clause_element: - - column_reference: - - naked_identifier: SOME_COL - - from_clause: - - keyword: from - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: some_database - - dot: . - - naked_identifier: schema - - dot: . - - naked_identifier: some_table - - end_bracket: ) + - column_reference: + - naked_identifier: SOME_VALUE - statement_terminator: ; - statement: - - scripting_block_statement: - - keyword: end + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - variable: ':' + - alias_expression: + - naked_identifier: variable + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/limit.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/limit.yml index c56d1a91c..28637595d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/limit.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/limit.yml @@ -312,10 +312,11 @@ file: - keyword: by - column_reference: - naked_identifier: c1 - - limit_clause: + - offset_clause: - keyword: offset - numeric_literal: '1' - keyword: row + - limit_clause: - keyword: fetch - numeric_literal: '1' - keyword: row @@ -339,10 +340,11 @@ file: - keyword: by - column_reference: - naked_identifier: c1 - - limit_clause: + - offset_clause: - keyword: offset - numeric_literal: '3' - keyword: rows + - limit_clause: - keyword: fetch - numeric_literal: '3' - keyword: rows diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/match_recognize.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/match_recognize.yml index a38081e6e..83c85f58b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/match_recognize.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/match_recognize.yml @@ -39,7 +39,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: match_number - comma: ',' - expression: @@ -54,7 +55,8 @@ file: - naked_identifier: price_date - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: start_date - comma: ',' - expression: @@ -69,7 +71,8 @@ file: - naked_identifier: price_date - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: end_date - comma: ',' - expression: @@ -82,7 +85,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: rows_in_sequence - comma: ',' - expression: @@ -98,7 +102,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_decreases - comma: ',' - expression: @@ -114,7 +119,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_increases - keyword: one - keyword: row @@ -254,7 +260,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - quoted_identifier: '"MATCH_NUMBER"' - comma: ',' - expression: @@ -266,7 +273,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: msq - comma: ',' - expression: @@ -278,7 +286,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: cl - keyword: all - keyword: rows @@ -365,7 +374,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - quoted_identifier: '"MATCH_NUMBER"' - keyword: all - keyword: rows @@ -463,7 +473,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - quoted_identifier: '"MATCH_NUMBER"' - comma: ',' - expression: @@ -475,7 +486,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: cl - keyword: all - keyword: rows @@ -594,7 +606,8 @@ file: - naked_identifier: price - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - quoted_identifier: '"FINAL FIRST(LT45.price)"' - comma: ',' - keyword: final @@ -612,7 +625,8 @@ file: - naked_identifier: price - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - quoted_identifier: '"FINAL LAST(LT45.price)"' - keyword: all - keyword: rows @@ -695,7 +709,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: match_number - comma: ',' - expression: @@ -710,7 +725,8 @@ file: - naked_identifier: price_date - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: start_date - comma: ',' - expression: @@ -725,7 +741,8 @@ file: - naked_identifier: price_date - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: end_date - comma: ',' - expression: @@ -738,7 +755,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: rows_in_sequence - comma: ',' - expression: @@ -754,7 +772,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_decreases - comma: ',' - expression: @@ -770,7 +789,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_increases - keyword: one - keyword: row @@ -904,7 +924,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: match_number - comma: ',' - expression: @@ -919,7 +940,8 @@ file: - naked_identifier: price_date - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: start_date - comma: ',' - expression: @@ -934,7 +956,8 @@ file: - naked_identifier: price_date - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: end_date - comma: ',' - expression: @@ -947,7 +970,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: rows_in_sequence - comma: ',' - expression: @@ -963,7 +987,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_decreases - comma: ',' - expression: @@ -979,7 +1004,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_increases - keyword: one - keyword: row @@ -999,7 +1025,7 @@ file: - bracketed: - start_bracket: ( - naked_identifier: S1 - - comparison_operator: + - binary_operator: - pipe: '|' - naked_identifier: S2 - star: '*' @@ -1109,7 +1135,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: match_number - comma: ',' - expression: @@ -1124,7 +1151,8 @@ file: - naked_identifier: price_date - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: start_date - comma: ',' - expression: @@ -1139,7 +1167,8 @@ file: - naked_identifier: price_date - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: end_date - comma: ',' - expression: @@ -1152,7 +1181,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: rows_in_sequence - comma: ',' - expression: @@ -1168,7 +1198,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_decreases - comma: ',' - expression: @@ -1184,7 +1215,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_increases - keyword: one - keyword: row @@ -1300,7 +1332,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: match_number - comma: ',' - expression: @@ -1315,7 +1348,8 @@ file: - naked_identifier: price_date - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: start_date - comma: ',' - expression: @@ -1330,7 +1364,8 @@ file: - naked_identifier: price_date - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: end_date - comma: ',' - expression: @@ -1343,7 +1378,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: rows_in_sequence - comma: ',' - expression: @@ -1359,7 +1395,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_decreases - comma: ',' - expression: @@ -1375,7 +1412,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: num_increases - keyword: one - keyword: row @@ -1394,7 +1432,7 @@ file: - bracketed: - start_bracket: ( - naked_identifier: A - - comparison_operator: + - binary_operator: - pipe: '|' - naked_identifier: B - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/multiple_shorthand_casts.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/multiple_shorthand_casts.yml index 0589a4068..e8989a532 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/multiple_shorthand_casts.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/multiple_shorthand_casts.yml @@ -14,7 +14,8 @@ file: - data_type: - data_type_identifier: boolean - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: bool - statement_terminator: ; - statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/pivot.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/pivot.sql index ce86765db..609411e71 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/pivot.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/pivot.sql @@ -5,9 +5,82 @@ PIVOT (min(f_val) FOR f_id IN (1, 2)) AS f (a, b); SELECT * FROM my_tbl UNPIVOT (val FOR col_name IN (a, b)); +SELECT * FROM my_tbl +UNPIVOT INCLUDE NULLS (val FOR col_name IN (a, b)); + +SELECT * FROM my_tbl +UNPIVOT EXCLUDE NULLS (val FOR col_name IN (a, b)); + select * from table_a unpivot (a for b in (col_1, col_2, col_3)) unpivot (c for d in (col_a, col_b, col_c)) ; + +-- from Snowflake's PIVOT docs +SELECT * +FROM quarterly_sales + PIVOT(SUM(amount) FOR quarter IN (ANY ORDER BY quarter)) +ORDER BY empid; + + +-- from Snowflake's PIVOT docs +SELECT * +FROM quarterly_sales + PIVOT(SUM(amount) FOR quarter IN ( + SELECT DISTINCT quarter + FROM ad_campaign_types_by_quarter + WHERE television = TRUE + ORDER BY quarter) + ) +ORDER BY empid; + +-- from Snowflake's PIVOT docs +SELECT * +FROM quarterly_sales + PIVOT(SUM(amount) FOR quarter IN ( + '2023_Q1', + '2023_Q2', + '2023_Q3', + '2023_Q4') + ) AS p (empid_renamed, Q1, Q2, Q3, Q4) +ORDER BY empid_renamed; + +-- from Snowflake's PIVOT docs +SELECT * +FROM quarterly_sales + PIVOT(SUM(amount) + FOR quarter IN ( + '2023_Q1', + '2023_Q2', + '2023_Q3', + '2023_Q4', + '2024_Q1') + DEFAULT ON NULL (0) + ) +ORDER BY empid; + + +-- https://github.com/sqlfluff/sqlfluff/issues/5876 +select * +from to_pivot pivot(sum(val) for col in (any order by col)) +order by id; + +-- https://github.com/sqlfluff/sqlfluff/issues/7244 +SELECT + empid AS employee_id, + q1_2023_sales, + q2_2023_sales, + q3_2023_sales, + q4_2023_sales +FROM quarterly_sales +PIVOT ( + SUM(amount) FOR quarter IN ( + '2023_Q1' AS q1_2023_sales, + '2023_Q2' AS q2_2023_sales, + '2023_Q3' AS q3_2023_sales, + '2023_Q4' AS q4_2023_sales + ) +) +WHERE q1_2023_sales IS NOT NULL; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/pivot.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/pivot.yml index 53d8be980..370806258 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/pivot.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/pivot.yml @@ -39,7 +39,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: f - bracketed: - start_bracket: ( @@ -80,6 +81,72 @@ file: - end_bracket: ) - end_bracket: ) - statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_tbl + - from_unpivot_expression: + - keyword: UNPIVOT + - keyword: INCLUDE + - keyword: NULLS + - bracketed: + - start_bracket: ( + - naked_identifier: val + - keyword: FOR + - naked_identifier: col_name + - keyword: IN + - bracketed: + - start_bracket: ( + - naked_identifier: a + - comma: ',' + - naked_identifier: b + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_tbl + - from_unpivot_expression: + - keyword: UNPIVOT + - keyword: EXCLUDE + - keyword: NULLS + - bracketed: + - start_bracket: ( + - naked_identifier: val + - keyword: FOR + - naked_identifier: col_name + - keyword: IN + - bracketed: + - start_bracket: ( + - naked_identifier: a + - comma: ',' + - naked_identifier: b + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; - statement: - select_statement: - select_clause: @@ -130,3 +197,380 @@ file: - end_bracket: ) - end_bracket: ) - statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: quarterly_sales + - from_pivot_expression: + - keyword: PIVOT + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: amount + - end_bracket: ) + - keyword: FOR + - naked_identifier: quarter + - keyword: IN + - bracketed: + - start_bracket: ( + - keyword: ANY + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: quarter + - end_bracket: ) + - end_bracket: ) + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: empid +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: quarterly_sales + - from_pivot_expression: + - keyword: PIVOT + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: amount + - end_bracket: ) + - keyword: FOR + - naked_identifier: quarter + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: DISTINCT + - select_clause_element: + - column_reference: + - naked_identifier: quarter + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: ad_campaign_types_by_quarter + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: television + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'TRUE' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: quarter + - end_bracket: ) + - end_bracket: ) + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: empid +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: quarterly_sales + - from_pivot_expression: + - keyword: PIVOT + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: amount + - end_bracket: ) + - keyword: FOR + - naked_identifier: quarter + - keyword: IN + - bracketed: + - start_bracket: ( + - quoted_literal: '''2023_Q1''' + - comma: ',' + - quoted_literal: '''2023_Q2''' + - comma: ',' + - quoted_literal: '''2023_Q3''' + - comma: ',' + - quoted_literal: '''2023_Q4''' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: p + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: empid_renamed + - comma: ',' + - naked_identifier: Q1 + - comma: ',' + - naked_identifier: Q2 + - comma: ',' + - naked_identifier: Q3 + - comma: ',' + - naked_identifier: Q4 + - end_bracket: ) + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: empid_renamed +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: quarterly_sales + - from_pivot_expression: + - keyword: PIVOT + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: amount + - end_bracket: ) + - keyword: FOR + - naked_identifier: quarter + - keyword: IN + - bracketed: + - start_bracket: ( + - quoted_literal: '''2023_Q1''' + - comma: ',' + - quoted_literal: '''2023_Q2''' + - comma: ',' + - quoted_literal: '''2023_Q3''' + - comma: ',' + - quoted_literal: '''2023_Q4''' + - comma: ',' + - quoted_literal: '''2024_Q1''' + - end_bracket: ) + - keyword: DEFAULT + - keyword: ON + - keyword: 'NULL' + - bracketed: + - start_bracket: ( + - numeric_literal: '0' + - end_bracket: ) + - end_bracket: ) + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: empid +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: to_pivot + - from_pivot_expression: + - keyword: pivot + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: val + - end_bracket: ) + - keyword: for + - naked_identifier: col + - keyword: in + - bracketed: + - start_bracket: ( + - keyword: any + - orderby_clause: + - keyword: order + - keyword: by + - column_reference: + - naked_identifier: col + - end_bracket: ) + - end_bracket: ) + - orderby_clause: + - keyword: order + - keyword: by + - column_reference: + - naked_identifier: id +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: empid + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: employee_id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: q1_2023_sales + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: q2_2023_sales + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: q3_2023_sales + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: q4_2023_sales + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: quarterly_sales + - from_pivot_expression: + - keyword: PIVOT + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: amount + - end_bracket: ) + - keyword: FOR + - naked_identifier: quarter + - keyword: IN + - bracketed: + - start_bracket: ( + - quoted_literal: '''2023_Q1''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: q1_2023_sales + - comma: ',' + - quoted_literal: '''2023_Q2''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: q2_2023_sales + - comma: ',' + - quoted_literal: '''2023_Q3''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: q3_2023_sales + - comma: ',' + - quoted_literal: '''2023_Q4''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: q4_2023_sales + - end_bracket: ) + - end_bracket: ) + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: q1_2023_sales + - keyword: IS + - keyword: NOT + - null_literal: 'NULL' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/raise_statement.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/raise_statement.sql new file mode 100644 index 000000000..0c872e949 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/raise_statement.sql @@ -0,0 +1,6 @@ +BEGIN + SELECT 1; +EXCEPTION + WHEN OTHER THEN + RAISE; +END; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/raise_statement.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/raise_statement.yml new file mode 100644 index 000000000..e8f4481ad --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/raise_statement.yml @@ -0,0 +1,24 @@ +file: +- statement: + - scripting_block_statement: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - statement_terminator: ; + - statement: + - exception_block_statement: + - keyword: EXCEPTION + - keyword: WHEN + - object_reference: + - naked_identifier: OTHER + - keyword: THEN + - statement: + - scripting_raise_statement: + - keyword: RAISE + - statement_terminator: ; + - keyword: END +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/return.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/return.yml index 89f27eb43..06ed1b031 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/return.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/return.yml @@ -8,21 +8,19 @@ file: - keyword: select - select_clause_element: - numeric_literal: '1' -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: select - - select_clause_element: - - numeric_literal: '2' -- statement_terminator: ; -- statement: - - return_statement: - - keyword: return - - expression: - - numeric_literal: '5' -- statement_terminator: ; -- statement: - - scripting_block_statement: + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: '2' + - statement_terminator: ; + - statement: + - return_statement: + - keyword: return + - expression: + - numeric_literal: '5' + - statement_terminator: ; - keyword: end - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/sample.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/sample.yml index ac15d1f86..a0d141bed 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/sample.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/sample.yml @@ -50,7 +50,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: row_number - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select.sql index 6ca6feebe..7952c5a6b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select.sql @@ -14,3 +14,21 @@ FROM my_table; SELECT customer_id FROM my_table cross join my_table2; + +select notify from foo; + +select + coalesce(do.a, do.b) as value +from delivery_override as do +; + +SELECT + t.id + , TRUE AS test +FROM mytable t +ORDER BY TRUE +; + +select + limit as renamed +from sometable; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select.yml index 7e89ae22d..b8ea68fa3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select.yml @@ -82,7 +82,8 @@ file: - semi_structured_element: cross - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: cross - from_clause: - keyword: FROM @@ -114,3 +115,106 @@ file: - table_reference: - naked_identifier: my_table2 - statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: notify + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: foo +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - function_name_identifier: coalesce + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: do + - dot: . + - naked_identifier: a + - comma: ',' + - expression: + - column_reference: + - naked_identifier: do + - dot: . + - naked_identifier: b + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: value + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: delivery_override + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: do +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - boolean_literal: 'TRUE' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: test + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: mytable + - alias_expression: + - naked_identifier: t + - orderby_clause: + - keyword: ORDER + - keyword: BY + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: limit + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: renamed + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sometable +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_asof_join.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_asof_join.yml index c1f4249c1..770c8e0c3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_asof_join.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_asof_join.yml @@ -50,7 +50,7 @@ file: - naked_identifier: quotes - alias_expression: - naked_identifier: q - - match_condition_clause: + - match_condition: - keyword: MATCH_CONDITION - bracketed: - start_bracket: ( @@ -143,7 +143,7 @@ file: - naked_identifier: quotes - alias_expression: - naked_identifier: q - - match_condition_clause: + - match_condition: - keyword: MATCH_CONDITION - bracketed: - start_bracket: ( @@ -227,7 +227,7 @@ file: - naked_identifier: quotes_unixtime - alias_expression: - naked_identifier: qu - - match_condition_clause: + - match_condition: - keyword: MATCH_CONDITION - bracketed: - start_bracket: ( @@ -271,7 +271,7 @@ file: - naked_identifier: snowtime - alias_expression: - naked_identifier: s - - match_condition_clause: + - match_condition: - keyword: MATCH_CONDITION - bracketed: - start_bracket: ( @@ -315,7 +315,7 @@ file: - naked_identifier: raintime - alias_expression: - naked_identifier: r - - match_condition_clause: + - match_condition: - keyword: MATCH_CONDITION - bracketed: - start_bracket: ( @@ -354,7 +354,7 @@ file: - naked_identifier: preciptime - alias_expression: - naked_identifier: p - - match_condition_clause: + - match_condition: - keyword: MATCH_CONDITION - bracketed: - start_bracket: ( @@ -418,7 +418,7 @@ file: - naked_identifier: raintime - alias_expression: - naked_identifier: r - - match_condition_clause: + - match_condition: - keyword: MATCH_CONDITION - bracketed: - start_bracket: ( @@ -456,7 +456,7 @@ file: - naked_identifier: preciptime - alias_expression: - naked_identifier: p - - match_condition_clause: + - match_condition: - keyword: MATCH_CONDITION - bracketed: - start_bracket: ( diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_except.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_except.sql index 1b6608180..e60834970 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_except.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_except.sql @@ -1,3 +1,3 @@ select * from table1 EXCEPT -(select * from table1) \ No newline at end of file +(select * from table1) diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_group_by_cube_rollup.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_group_by_cube_rollup.yml index 88fb50c41..6a90eda02 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_group_by_cube_rollup.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_group_by_cube_rollup.yml @@ -21,7 +21,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: record_count - from_clause: - keyword: FROM @@ -65,7 +66,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: record_count - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_higher_order_function.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_higher_order_function.sql new file mode 100644 index 000000000..8637a5ef0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_higher_order_function.sql @@ -0,0 +1,13 @@ +SELECT + FILTER(ident, i -> i:value > 0) as sample_filter, + TRANSFORM(ident, j -> j:value) as sample_transform, + TRANSFORM(ident, k variant -> k:val) as sample_transform_with_type +FROM ref; + +SELECT + FILTER("ident", (i INT, j VARIANT) -> (i:value is not null and j:value = 'some_literal')) as sample_filter, + TRANSFORM("ident", j -> j) as sample_transform, + some_other_function('unusual arguments', x -> 'still a lambda expression', true) as sample_other +FROM ref; + +SELECT REDUCE([1,2,3], 0, (acc, val) -> acc + val); diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_higher_order_function.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_higher_order_function.yml new file mode 100644 index 000000000..cc6cc8f25 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_higher_order_function.yml @@ -0,0 +1,244 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: FILTER + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: ident + - comma: ',' + - lambda_function: + - parameter: i + - lambda_arrow: -> + - expression: + - column_reference: + - naked_identifier: i + - semi_structured_expression: + - colon: ':' + - semi_structured_element: value + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: sample_filter + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: TRANSFORM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: ident + - comma: ',' + - lambda_function: + - parameter: j + - lambda_arrow: -> + - expression: + - column_reference: + - naked_identifier: j + - semi_structured_expression: + - colon: ':' + - semi_structured_element: value + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: sample_transform + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: TRANSFORM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: ident + - comma: ',' + - lambda_function: + - parameter: k + - data_type: + - data_type_identifier: variant + - lambda_arrow: -> + - expression: + - column_reference: + - naked_identifier: k + - semi_structured_expression: + - colon: ':' + - semi_structured_element: val + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: sample_transform_with_type + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: ref +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: FILTER + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '"ident"' + - comma: ',' + - lambda_function: + - bracketed: + - start_bracket: ( + - parameter: i + - data_type: + - data_type_identifier: INT + - comma: ',' + - parameter: j + - data_type: + - data_type_identifier: VARIANT + - end_bracket: ) + - lambda_arrow: -> + - expression: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: i + - semi_structured_expression: + - colon: ':' + - semi_structured_element: value + - keyword: is + - keyword: not + - null_literal: 'null' + - binary_operator: and + - column_reference: + - naked_identifier: j + - semi_structured_expression: + - colon: ':' + - semi_structured_element: value + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''some_literal''' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: sample_filter + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: TRANSFORM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '"ident"' + - comma: ',' + - lambda_function: + - parameter: j + - lambda_arrow: -> + - expression: + - column_reference: + - naked_identifier: j + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: sample_transform + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: some_other_function + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''unusual arguments''' + - comma: ',' + - lambda_function: + - parameter: x + - lambda_arrow: -> + - expression: + - quoted_literal: '''still a lambda expression''' + - comma: ',' + - expression: + - boolean_literal: 'true' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: sample_other + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: ref +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: REDUCE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - array_literal: + - start_square_bracket: '[' + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '3' + - end_square_bracket: ']' + - comma: ',' + - expression: + - numeric_literal: '0' + - comma: ',' + - lambda_function: + - bracketed: + - start_bracket: ( + - parameter: acc + - comma: ',' + - parameter: val + - end_bracket: ) + - lambda_arrow: -> + - expression: + - column_reference: + - naked_identifier: acc + - binary_operator: + + - column_reference: + - naked_identifier: val + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_into.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_into.sql new file mode 100644 index 000000000..95235b155 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_into.sql @@ -0,0 +1,3 @@ +LET query_tag STRING := NULL; +SHOW PARAMETERS LIKE 'QUERY_TAG' IN SESSION; +SELECT $2 INTO :query_tag FROM TABLE(RESULT_SCAN(LAST_QUERY_ID())); diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_into.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_into.yml new file mode 100644 index 000000000..162400a09 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_into.yml @@ -0,0 +1,61 @@ +file: +- statement: + - scripting_let_statement: + - keyword: LET + - variable: query_tag + - data_type: + - data_type_identifier: STRING + - assignment_operator: := + - expression: + - null_literal: 'NULL' +- statement_terminator: ; +- statement: + - show_statement: + - keyword: SHOW + - keyword: PARAMETERS + - keyword: LIKE + - quoted_literal: '''QUERY_TAG''' + - keyword: IN + - keyword: SESSION +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - column_index_identifier_segment: $2 + - into_clause: + - keyword: INTO + - bind_variable: + - colon_prefix: ':' + - variable: query_tag + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: TABLE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: RESULT_SCAN + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: LAST_QUERY_ID + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_system_function.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_system_function.sql index 74df4074f..8d7325cc8 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_system_function.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_system_function.sql @@ -1,2 +1,3 @@ SELECT SYSTEM$STREAM_HAS_DATA('SCH.MY_STREAM'); SELECT SYSTEM$USER_TASK_CANCEL_ONGOING_EXECUTIONS('MY_TASK'); +SELECT SYSTEM$SHOW_STREAMLITS_IN_ACCOUNT(true, false); diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_system_function.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_system_function.yml index 7d65c5446..cdf7c3ff6 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_system_function.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_system_function.yml @@ -21,3 +21,16 @@ file: - quoted_literal: '''MY_TASK''' - end_bracket: ) - statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - system_function_name: SYSTEM$SHOW_STREAMLITS_IN_ACCOUNT + - bracketed: + - start_bracket: ( + - boolean_literal: 'true' + - comma: ',' + - boolean_literal: 'false' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_union.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_union.sql index 1c0cc010a..6ed09f90b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_union.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_union.sql @@ -2,3 +2,14 @@ SELECT 1 UNION SELECT 2 ORDER BY 1 +; + +SELECT 1 AS foo +UNION ALL BY NAME +SELECT 2 AS foo +; + +SELECT 1 AS foo +UNION BY NAME +SELECT 2 AS foo +; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_union.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_union.yml index f11b88795..152ecf016 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_union.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/select_union.yml @@ -17,3 +17,55 @@ file: - keyword: ORDER - keyword: BY - numeric_literal: '1' +- statement_terminator: ; +- statement: + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: foo + - set_operator: + - keyword: UNION + - keyword: ALL + - keyword: BY + - keyword: NAME + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: foo +- statement_terminator: ; +- statement: + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: foo + - set_operator: + - keyword: UNION + - keyword: BY + - keyword: NAME + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - numeric_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: foo +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured.yml index 674f2f0c6..1799ce852 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured.yml @@ -15,7 +15,8 @@ file: - colon: ':' - semi_structured_element: value - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: uncasted - comma: ',' - select_clause_element: @@ -30,7 +31,8 @@ file: - data_type: - data_type_identifier: bigint - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: field_id - comma: ',' - select_clause_element: @@ -45,7 +47,8 @@ file: - data_type: - data_type_identifier: STRING - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: field_val - comma: ',' - select_clause_element: @@ -62,7 +65,8 @@ file: - dot: . - semi_structured_element: foo - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: another_val - comma: ',' - select_clause_element: @@ -91,7 +95,8 @@ file: - data_type: - data_type_identifier: bigint - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: another_val - comma: ',' - select_clause_element: @@ -106,7 +111,8 @@ file: - dot: . - semi_structured_element: array_element_property - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: test_array_access - from_clause: - keyword: FROM @@ -160,7 +166,8 @@ file: - numeric_literal: '6' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: lat - comma: ',' - select_clause_element: @@ -186,7 +193,8 @@ file: - numeric_literal: '6' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: lng - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_2.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_2.yml index bdc14c0e3..34fe4f12c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_2.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_2.yml @@ -17,7 +17,8 @@ file: - data_type: - data_type_identifier: string - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: TO_PHONE_NUMBER - comma: ',' - select_clause_element: @@ -34,7 +35,8 @@ file: - data_type: - data_type_identifier: string - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: FROM_PHONE_NUMBER - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_3.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_3.yml index 44b8e8a90..d0eb81d02 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_3.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_3.yml @@ -27,7 +27,8 @@ file: - numeric_literal: '0' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: first_name - comma: ',' - select_clause_element: @@ -48,7 +49,8 @@ file: - colon: ':' - semi_structured_element: customer_id - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: customer_id - from_clause: - keyword: FROM @@ -58,5 +60,6 @@ file: - table_reference: - naked_identifier: tickets - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_4.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_4.sql new file mode 100644 index 000000000..5f2627ed5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_4.sql @@ -0,0 +1,9 @@ +SELECT + SEMI_STRUCTURED_OBJECT:ID_FIELD::VARCHAR AS ID_FIELD, + SEMI_STRUCTURED_OBJECT:METADATA$FILENAME::VARCHAR AS METADATA$FILENAME, + PARSE_JSON($1):FILE_CONTENT_KEY FILE_CONTENT_KEY, + DATEADD(MS, PARSE_JSON($1):EVENT_TIME '1970-01-01') EVENT_TIME, + parse_json($1):METADATA$FILENAME METADATA$FILENAME, + DATEADD(MS, PARSE_JSON($1):METADATA$INSERTION_TIME, '1970-01-01') METADATA$INSERTION_TIME, + DATEADD(MS, PARSE_JSON($1):METADATA$LAST_EVENT_INSERTION_TIME, '1970-01-01') METADATA$LAST_EVENT_INSERTION_TIME +FROM @staging_area_root/ingest/data/file_name.ndjson diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_4.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_4.yml new file mode 100644 index 000000000..8c320f296 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/semi_structured_4.yml @@ -0,0 +1,168 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - cast_expression: + - column_reference: + - naked_identifier: SEMI_STRUCTURED_OBJECT + - semi_structured_expression: + - colon: ':' + - semi_structured_element: ID_FIELD + - casting_operator: '::' + - data_type: + - data_type_identifier: VARCHAR + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: ID_FIELD + - comma: ',' + - select_clause_element: + - expression: + - cast_expression: + - column_reference: + - naked_identifier: SEMI_STRUCTURED_OBJECT + - semi_structured_expression: + - colon: ':' + - semi_structured_element: METADATA$FILENAME + - casting_operator: '::' + - data_type: + - data_type_identifier: VARCHAR + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: METADATA$FILENAME + - comma: ',' + - select_clause_element: + - expression: + - function: + - function_name: + - function_name_identifier: PARSE_JSON + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - column_index_identifier_segment: $1 + - end_bracket: ) + - semi_structured_expression: + - colon: ':' + - semi_structured_element: FILE_CONTENT_KEY + - alias_expression: + - naked_identifier: FILE_CONTENT_KEY + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEADD + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: MS + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: PARSE_JSON + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - column_index_identifier_segment: $1 + - end_bracket: ) + - semi_structured_expression: + - colon: ':' + - semi_structured_element: EVENT_TIME + - expression: + - quoted_literal: '''1970-01-01''' + - end_bracket: ) + - alias_expression: + - naked_identifier: EVENT_TIME + - comma: ',' + - select_clause_element: + - expression: + - function: + - function_name: + - function_name_identifier: parse_json + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - column_index_identifier_segment: $1 + - end_bracket: ) + - semi_structured_expression: + - colon: ':' + - semi_structured_element: METADATA$FILENAME + - alias_expression: + - naked_identifier: METADATA$FILENAME + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEADD + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: MS + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: PARSE_JSON + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - column_index_identifier_segment: $1 + - end_bracket: ) + - semi_structured_expression: + - colon: ':' + - semi_structured_element: METADATA$INSERTION_TIME + - comma: ',' + - expression: + - quoted_literal: '''1970-01-01''' + - end_bracket: ) + - alias_expression: + - naked_identifier: METADATA$INSERTION_TIME + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEADD + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: MS + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: PARSE_JSON + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - column_index_identifier_segment: $1 + - end_bracket: ) + - semi_structured_expression: + - colon: ':' + - semi_structured_element: METADATA$LAST_EVENT_INSERTION_TIME + - comma: ',' + - expression: + - quoted_literal: '''1970-01-01''' + - end_bracket: ) + - alias_expression: + - naked_identifier: METADATA$LAST_EVENT_INSERTION_TIME + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - stage_path: '@staging_area_root/ingest/data/file_name.ndjson' diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/set_command.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/set_command.sql index aa712bed0..cd15aedbc 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/set_command.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/set_command.sql @@ -11,3 +11,10 @@ set (min, max) = (40, 70); set (min, max) = (50, 2 * $min); SET THIS_ROLE=CURRENT_ROLE(); + +SET (rec_updated_cutoff_orders, rec_updated_cutoff_deliverables) = ( + SELECT + COALESCE(MAX(CASE WHEN entity_type = 'x' THEN rec_updated_at::DATE END), '2013-01-01') + , COALESCE(MAX(CASE WHEN entity_type = 'x' THEN rec_updated_at::DATE END), '2025-01-01') + FROM test.x +); diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/set_command.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/set_command.yml index 97d967dab..1baa9a925 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/set_command.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/set_command.yml @@ -127,3 +127,110 @@ file: - start_bracket: ( - end_bracket: ) - statement_terminator: ; +- statement: + - set_statement: + - keyword: SET + - bracketed: + - start_bracket: ( + - variable: rec_updated_cutoff_orders + - comma: ',' + - variable: rec_updated_cutoff_deliverables + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: COALESCE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: MAX + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: entity_type + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''x''' + - keyword: THEN + - expression: + - cast_expression: + - column_reference: + - naked_identifier: rec_updated_at + - casting_operator: '::' + - data_type: + - data_type_identifier: DATE + - keyword: END + - end_bracket: ) + - comma: ',' + - expression: + - quoted_literal: '''2013-01-01''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: COALESCE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: MAX + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: entity_type + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''x''' + - keyword: THEN + - expression: + - cast_expression: + - column_reference: + - naked_identifier: rec_updated_at + - casting_operator: '::' + - data_type: + - data_type_identifier: DATE + - keyword: END + - end_bracket: ) + - comma: ',' + - expression: + - quoted_literal: '''2025-01-01''' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: test + - dot: . + - naked_identifier: x + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/show.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/show.sql new file mode 100644 index 000000000..74d325ed7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/show.sql @@ -0,0 +1,3 @@ +SHOW PASSWORD POLICIES; +SHOW CORTEX SEARCH SERVICES; +SHOW RESOURCE MONITORS; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/show.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/show.yml new file mode 100644 index 000000000..f0098b7e2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/show.yml @@ -0,0 +1,20 @@ +file: +- statement: + - show_statement: + - keyword: SHOW + - keyword: PASSWORD + - keyword: POLICIES +- statement_terminator: ; +- statement: + - show_statement: + - keyword: SHOW + - keyword: CORTEX + - keyword: SEARCH + - keyword: SERVICES +- statement_terminator: ; +- statement: + - show_statement: + - keyword: SHOW + - keyword: RESOURCE + - keyword: MONITORS +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/undrop.sql b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/undrop.sql index 82d1b13e1..52f57d16a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/undrop.sql +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/undrop.sql @@ -1,3 +1,4 @@ UNDROP database mytestdb2; undrop schema myschema; undrop table t2; +UNDROP EXTERNAL VOLUME my_external_volume; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/undrop.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/undrop.yml index 664c4cb22..82f0cabea 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/undrop.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/undrop.yml @@ -10,9 +10,8 @@ file: - undrop_statement: - keyword: undrop - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: myschema + - schema_reference: + - naked_identifier: myschema - statement_terminator: ; - statement: - undrop_statement: @@ -21,3 +20,11 @@ file: - table_reference: - naked_identifier: t2 - statement_terminator: ; +- statement: + - undrop_statement: + - keyword: UNDROP + - keyword: EXTERNAL + - keyword: VOLUME + - external_volume_reference: + - naked_identifier: my_external_volume +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/use.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/use.yml index fdc128e05..03df6da8e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/use.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/use.yml @@ -24,9 +24,8 @@ file: - use_statement: - keyword: use - keyword: schema - - table_reference: - - object_reference: - - naked_identifier: my_schema + - schema_reference: + - naked_identifier: my_schema - statement_terminator: ; - statement: - use_statement: @@ -59,19 +58,17 @@ file: - use_statement: - keyword: USE - keyword: SCHEMA - - table_reference: - - object_reference: - - quoted_identifier: '"MY_DATABASE"' - - dot: . - - quoted_identifier: '"MY_SCHEMA"' + - schema_reference: + - quoted_identifier: '"MY_DATABASE"' + - dot: . + - quoted_identifier: '"MY_SCHEMA"' - statement_terminator: ; - statement: - use_statement: - keyword: USE - keyword: SCHEMA - - table_reference: - - object_reference: - - quoted_identifier: '"MY_SCHEMA"' + - schema_reference: + - quoted_identifier: '"MY_SCHEMA"' - statement_terminator: ; - statement: - use_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/window_function_ignore_nulls.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/window_function_ignore_nulls.yml index fe86428fc..8e2cdec0e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/window_function_ignore_nulls.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/window_function_ignore_nulls.yml @@ -42,7 +42,8 @@ file: - keyword: ROW - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: bat - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/within_group.yml b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/within_group.yml index 3e4dae0c1..918f41ce0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/within_group.yml +++ b/crates/lib-dialects/test/fixtures/dialects/snowflake/sqlfluff/within_group.yml @@ -14,14 +14,16 @@ file: - column_reference: - naked_identifier: column1 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: name - comma: ',' - select_clause_element: - column_reference: - naked_identifier: column2 - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: colour - from_clause: - keyword: from @@ -120,7 +122,8 @@ file: - naked_identifier: name - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: fruits - from_clause: - keyword: from diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/add_file.sql b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/add_file.sql index b3dc9bfc8..9a39dcdf0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/add_file.sql +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/add_file.sql @@ -8,5 +8,4 @@ ADD FILE "/path/to/some/directory"; ADD FILES "/path with space/cde.txt" '/path with space/fgh.txt'; --- NB: Non-quoted paths are not supported in SQLFluff currently ---ADD FILE /tmp/test; +ADD FILE /tmp/test; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/add_file.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/add_file.yml index 97ca98ed8..c71d8700e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/add_file.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/add_file.yml @@ -30,3 +30,13 @@ file: - quoted_literal: '"/path with space/cde.txt"' - quoted_literal: '''/path with space/fgh.txt''' - statement_terminator: ; +- statement: + - add_file_statement: + - keyword: ADD + - file_keyword: FILE + - file_literal: + - slash: / + - path_segment: tmp + - slash: / + - path_segment: test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/add_jar.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/add_jar.yml index c94384b02..7c975aefd 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/add_jar.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/add_jar.yml @@ -58,13 +58,28 @@ file: - add_jar_statement: - keyword: ADD - file_keyword: JAR - - file_literal: /path/to/some.jar + - file_literal: + - slash: / + - path_segment: path + - slash: / + - path_segment: to + - slash: / + - path_segment: some + - dot: . + - path_segment: jar - statement_terminator: ; - statement: - add_jar_statement: - keyword: ADD - file_keyword: JAR - - file_literal: path/to/some.jar + - file_literal: + - path_segment: path + - slash: / + - path_segment: to + - slash: / + - path_segment: some + - dot: . + - path_segment: jar - statement_terminator: ; - statement: - add_jar_statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/bytes_literal.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/bytes_literal.yml index a3bab3586..5b02f7636 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/bytes_literal.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/bytes_literal.yml @@ -6,7 +6,8 @@ file: - select_clause_element: - bytes_quoted_literal: X'123456' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -16,6 +17,7 @@ file: - select_clause_element: - bytes_quoted_literal: X"123456" - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/case_clause.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/case_clause.yml index beb64242f..c8056ae5f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/case_clause.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/case_clause.yml @@ -64,7 +64,8 @@ file: - quoted_literal: '''small''' - keyword: END - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: id_size - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_complex_datatypes.sql b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_complex_datatypes.sql index fc00e29e8..c92c7c093 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_complex_datatypes.sql +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_complex_datatypes.sql @@ -2,6 +2,10 @@ CREATE TABLE table_identifier ( a STRUCT, d MAP, e ARRAY); +--Create Table with complex datatypes without : in struct +CREATE TABLE table_identifier +( a STRUCT, d MAP, e ARRAY); + --Create Table with complex datatypes and comments CREATE TABLE table_identifier ( a STRUCT COMMENT 'col_comment', d MAP COMMENT 'col_comment', e ARRAY COMMENT 'col_comment'); @@ -10,6 +14,11 @@ CREATE TABLE table_identifier CREATE TABLE table_identifier ( a STRUCT>, d MAP>>, g ARRAY>>); +--Create Table with nested complex datatypes without : in struct +CREATE TABLE table_identifier +( a STRUCT>, d MAP>>, g ARRAY>>); + + --Create Table with complex datatypes and quoted identifiers CREATE TABLE table_identifier ( a STRUCT<`b`: STRING, c: BOOLEAN>, `d` MAP, e ARRAY); diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_complex_datatypes.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_complex_datatypes.yml index b6caedd03..c90b6b7ef 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_complex_datatypes.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_complex_datatypes.yml @@ -8,7 +8,8 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: a + - column_reference: + - naked_identifier: a - data_type: - struct_type: - keyword: STRUCT @@ -28,7 +29,8 @@ file: - end_angle_bracket: '>' - comma: ',' - column_definition: - - naked_identifier: d + - column_reference: + - naked_identifier: d - data_type: - keyword: MAP - start_angle_bracket: < @@ -42,7 +44,8 @@ file: - end_angle_bracket: '>' - comma: ',' - column_definition: - - naked_identifier: e + - column_reference: + - naked_identifier: e - data_type: - array_type: - keyword: ARRAY @@ -62,7 +65,63 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: a + - column_reference: + - naked_identifier: a + - data_type: + - struct_type: + - keyword: STRUCT + - struct_type_schema: + - start_angle_bracket: < + - naked_identifier: b + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - naked_identifier: c + - data_type: + - primitive_type: + - keyword: BOOLEAN + - end_angle_bracket: '>' + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: d + - data_type: + - keyword: MAP + - start_angle_bracket: < + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - data_type: + - primitive_type: + - keyword: BOOLEAN + - end_angle_bracket: '>' + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: e + - data_type: + - array_type: + - keyword: ARRAY + - start_angle_bracket: < + - data_type: + - primitive_type: + - keyword: STRING + - end_angle_bracket: '>' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: table_identifier + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: a - data_type: - struct_type: - keyword: STRUCT @@ -88,7 +147,8 @@ file: - quoted_literal: '''col_comment''' - comma: ',' - column_definition: - - naked_identifier: d + - column_reference: + - naked_identifier: d - data_type: - keyword: MAP - start_angle_bracket: < @@ -106,7 +166,8 @@ file: - quoted_literal: '''col_comment''' - comma: ',' - column_definition: - - naked_identifier: e + - column_reference: + - naked_identifier: e - data_type: - array_type: - keyword: ARRAY @@ -130,7 +191,8 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: a + - column_reference: + - naked_identifier: a - data_type: - struct_type: - keyword: STRUCT @@ -158,7 +220,8 @@ file: - end_angle_bracket: '>' - comma: ',' - column_definition: - - naked_identifier: d + - column_reference: + - naked_identifier: d - data_type: - keyword: MAP - start_angle_bracket: < @@ -194,7 +257,8 @@ file: - end_angle_bracket: '>' - comma: ',' - column_definition: - - naked_identifier: g + - column_reference: + - naked_identifier: g - data_type: - array_type: - keyword: ARRAY @@ -236,7 +300,111 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: a + - column_reference: + - naked_identifier: a + - data_type: + - struct_type: + - keyword: STRUCT + - struct_type_schema: + - start_angle_bracket: < + - naked_identifier: b + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - naked_identifier: c + - data_type: + - keyword: MAP + - start_angle_bracket: < + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - data_type: + - primitive_type: + - keyword: BOOLEAN + - end_angle_bracket: '>' + - end_angle_bracket: '>' + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: d + - data_type: + - keyword: MAP + - start_angle_bracket: < + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - data_type: + - struct_type: + - keyword: STRUCT + - struct_type_schema: + - start_angle_bracket: < + - naked_identifier: e + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - naked_identifier: f + - data_type: + - keyword: MAP + - start_angle_bracket: < + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - data_type: + - primitive_type: + - keyword: BOOLEAN + - end_angle_bracket: '>' + - end_angle_bracket: '>' + - end_angle_bracket: '>' + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: g + - data_type: + - array_type: + - keyword: ARRAY + - start_angle_bracket: < + - data_type: + - struct_type: + - keyword: STRUCT + - struct_type_schema: + - start_angle_bracket: < + - naked_identifier: h + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - naked_identifier: i + - data_type: + - keyword: MAP + - start_angle_bracket: < + - data_type: + - primitive_type: + - keyword: STRING + - comma: ',' + - data_type: + - primitive_type: + - keyword: BOOLEAN + - end_angle_bracket: '>' + - end_angle_bracket: '>' + - end_angle_bracket: '>' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: table_identifier + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: a - data_type: - struct_type: - keyword: STRUCT @@ -256,7 +424,8 @@ file: - end_angle_bracket: '>' - comma: ',' - column_definition: - - quoted_identifier: '`d`' + - column_reference: + - quoted_identifier: '`d`' - data_type: - keyword: MAP - start_angle_bracket: < @@ -270,7 +439,8 @@ file: - end_angle_bracket: '>' - comma: ',' - column_definition: - - naked_identifier: e + - column_reference: + - naked_identifier: e - data_type: - array_type: - keyword: ARRAY @@ -290,13 +460,15 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: field_a + - column_reference: + - naked_identifier: field_a - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: field_b + - column_reference: + - naked_identifier: field_b - data_type: - primitive_type: - keyword: VARIANT diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_datasource.sql b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_datasource.sql index 2aab889da..f633f07e9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_datasource.sql +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_datasource.sql @@ -57,3 +57,15 @@ create table if not exists my_table_space.my_test_table ( using DELTA location 's3://some-bucket/test-data/' partitioned by (activity_date_partition); + +CREATE TABLE cluster_by_table_none ( + col1 STRING +) +USING DELTA +CLUSTER BY NONE; + +CREATE TABLE cluster_by_table_cols ( + col1 STRING +) +USING DELTA +CLUSTER BY (col1); diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_datasource.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_datasource.yml index cca970ca5..b5d2f9bd4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_datasource.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_datasource.yml @@ -11,7 +11,8 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: test + - column_reference: + - naked_identifier: test - data_type: - primitive_type: - keyword: STRING @@ -121,19 +122,22 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: age + - column_reference: + - naked_identifier: age - data_type: - primitive_type: - keyword: INT @@ -181,19 +185,22 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: age + - column_reference: + - naked_identifier: age - data_type: - primitive_type: - keyword: INT @@ -208,19 +215,22 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: age + - column_reference: + - naked_identifier: age - data_type: - primitive_type: - keyword: INT @@ -250,19 +260,22 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: age + - column_reference: + - naked_identifier: age - data_type: - primitive_type: - keyword: INT @@ -302,19 +315,22 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: age + - column_reference: + - naked_identifier: age - data_type: - primitive_type: - keyword: INT @@ -340,19 +356,22 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: age + - column_reference: + - naked_identifier: age - data_type: - primitive_type: - keyword: INT @@ -388,13 +407,15 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: test_value + - column_reference: + - naked_identifier: test_value - data_type: - primitive_type: - keyword: string - comma: ',' - column_definition: - - naked_identifier: activity_date_partition + - column_reference: + - naked_identifier: activity_date_partition - data_type: - primitive_type: - keyword: date @@ -413,3 +434,55 @@ file: - naked_identifier: activity_date_partition - end_bracket: ) - statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: cluster_by_table_none + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: STRING + - end_bracket: ) + - using_clause: + - keyword: USING + - data_source_format: + - keyword: DELTA + - table_cluster_by_clause: + - keyword: CLUSTER + - keyword: BY + - keyword: NONE +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: cluster_by_table_cols + - bracketed: + - start_bracket: ( + - column_definition: + - column_reference: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: STRING + - end_bracket: ) + - using_clause: + - keyword: USING + - data_source_format: + - keyword: DELTA + - table_cluster_by_clause: + - keyword: CLUSTER + - keyword: BY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_hiveformat.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_hiveformat.yml index 112efe88c..cba935606 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_hiveformat.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_hiveformat.yml @@ -12,7 +12,8 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: col_name1 + - column_reference: + - naked_identifier: col_name1 - data_type: - primitive_type: - keyword: STRING @@ -118,19 +119,22 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: age + - column_reference: + - naked_identifier: age - data_type: - primitive_type: - keyword: INT @@ -173,19 +177,22 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: age + - column_reference: + - naked_identifier: age - data_type: - primitive_type: - keyword: INT @@ -214,19 +221,22 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: age + - column_reference: + - naked_identifier: age - data_type: - primitive_type: - keyword: INT @@ -255,13 +265,15 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING @@ -289,13 +301,15 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING @@ -323,13 +337,15 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING @@ -356,13 +372,15 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: friends + - column_reference: + - naked_identifier: friends - data_type: - array_type: - keyword: ARRAY @@ -373,7 +391,8 @@ file: - end_angle_bracket: '>' - comma: ',' - column_definition: - - naked_identifier: children + - column_reference: + - naked_identifier: children - data_type: - keyword: MAP - start_angle_bracket: < @@ -387,7 +406,8 @@ file: - end_angle_bracket: '>' - comma: ',' - column_definition: - - naked_identifier: address + - column_reference: + - naked_identifier: address - data_type: - struct_type: - keyword: STRUCT @@ -490,13 +510,15 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: family_name + - column_reference: + - naked_identifier: family_name - data_type: - primitive_type: - keyword: STRING @@ -524,13 +546,15 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: age + - column_reference: + - naked_identifier: age - data_type: - primitive_type: - keyword: STRING @@ -558,13 +582,15 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: test_name + - column_reference: + - naked_identifier: test_name - data_type: - primitive_type: - keyword: STRING diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_primitive_datatypes.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_primitive_datatypes.yml index f12671182..4861995af 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_primitive_datatypes.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_table_primitive_datatypes.yml @@ -8,19 +8,22 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: a + - column_reference: + - naked_identifier: a - data_type: - primitive_type: - keyword: LONG - comma: ',' - column_definition: - - naked_identifier: b + - column_reference: + - naked_identifier: b - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: c + - column_reference: + - naked_identifier: c - data_type: - primitive_type: - keyword: SMALLINT diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_view_schema_evolution.sql b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_view_schema_evolution.sql new file mode 100644 index 000000000..95bde43df --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_view_schema_evolution.sql @@ -0,0 +1,3 @@ +-- Create a view filtering the `orders` table which will adjust to schema changes in `orders`. +CREATE OR REPLACE VIEW open_orders WITH SCHEMA EVOLUTION + AS SELECT * FROM orders WHERE status = 'open'; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_view_schema_evolution.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_view_schema_evolution.yml new file mode 100644 index 000000000..194d37ef3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/create_view_schema_evolution.yml @@ -0,0 +1,36 @@ +file: +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: REPLACE + - keyword: VIEW + - table_reference: + - naked_identifier: open_orders + - keyword: WITH + - keyword: SCHEMA + - keyword: EVOLUTION + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: orders + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: status + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''open''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_dlt_create_table.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_dlt_create_table.yml index eb328dbd3..09ce1090a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_dlt_create_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_dlt_create_table.yml @@ -220,7 +220,8 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: a + - column_reference: + - naked_identifier: a - data_type: - primitive_type: - keyword: STRING @@ -230,7 +231,8 @@ file: - quoted_literal: '''a''' - comma: ',' - column_definition: - - naked_identifier: b + - column_reference: + - naked_identifier: b - data_type: - primitive_type: - keyword: INT diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_dlt_create_view.sql b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_dlt_create_view.sql index b48eecc91..bacb32961 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_dlt_create_view.sql +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_dlt_create_view.sql @@ -26,3 +26,41 @@ FROM live.taxi_raw; CREATE OR REFRESH MATERIALIZED VIEW temp_table AS SELECT 1 AS ID; + +CREATE OR REFRESH MATERIALIZED VIEW dlt_view ( + a STRING COMMENT 'a', + b TIMESTAMP COMMENT 'b' +) +COMMENT 'DLT materialized view' +AS SELECT + a, + b +FROM live.dlt_bronze; + +CREATE OR REFRESH MATERIALIZED VIEW my_dlt_mat_view ( + col1 STRING COMMENT 'Dummy column 1', + col2 BIGINT COMMENT 'Dummy column 2', + col3 BOOLEAN COMMENT 'Dummy column 3' +) +PARTITIONED BY (col1) +COMMENT 'Example simplified materialized view with dummy fields.' +TBLPROPERTIES ('quality' = 'gold') +AS SELECT + col1, + col2, + col3 +FROM my_source_table; + +CREATE OR REFRESH MATERIALIZED VIEW my_dlt_mat_view ( + col1 STRING COMMENT 'Dummy column 1', + col2 BIGINT COMMENT 'Dummy column 2', + col3 BOOLEAN COMMENT 'Dummy column 3' +) +CLUSTER BY (col1) +COMMENT 'Example simplified materialized view with dummy fields.' +TBLPROPERTIES ('quality' = 'gold') +AS SELECT + col1, + col2, + col3 +FROM my_source_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_dlt_create_view.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_dlt_create_view.yml index 3dd61fd68..49185d09c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_dlt_create_view.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_dlt_create_view.yml @@ -153,6 +153,210 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: ID - statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: REFRESH + - keyword: MATERIALIZED + - keyword: VIEW + - table_reference: + - naked_identifier: dlt_view + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - data_type: + - primitive_type: + - keyword: STRING + - keyword: COMMENT + - quoted_literal: '''a''' + - comma: ',' + - column_reference: + - naked_identifier: b + - data_type: + - primitive_type: + - keyword: TIMESTAMP + - keyword: COMMENT + - quoted_literal: '''b''' + - end_bracket: ) + - keyword: COMMENT + - quoted_literal: '''DLT materialized view''' + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: live + - dot: . + - naked_identifier: dlt_bronze +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: REFRESH + - keyword: MATERIALIZED + - keyword: VIEW + - table_reference: + - naked_identifier: my_dlt_mat_view + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: STRING + - keyword: COMMENT + - quoted_literal: '''Dummy column 1''' + - comma: ',' + - column_reference: + - naked_identifier: col2 + - data_type: + - primitive_type: + - keyword: BIGINT + - keyword: COMMENT + - quoted_literal: '''Dummy column 2''' + - comma: ',' + - column_reference: + - naked_identifier: col3 + - data_type: + - primitive_type: + - keyword: BOOLEAN + - keyword: COMMENT + - quoted_literal: '''Dummy column 3''' + - end_bracket: ) + - keyword: PARTITIONED + - keyword: BY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: COMMENT + - quoted_literal: '''Example simplified materialized view with dummy fields.''' + - keyword: TBLPROPERTIES + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''quality''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''gold''' + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col3 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_source_table +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: REFRESH + - keyword: MATERIALIZED + - keyword: VIEW + - table_reference: + - naked_identifier: my_dlt_mat_view + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: STRING + - keyword: COMMENT + - quoted_literal: '''Dummy column 1''' + - comma: ',' + - column_reference: + - naked_identifier: col2 + - data_type: + - primitive_type: + - keyword: BIGINT + - keyword: COMMENT + - quoted_literal: '''Dummy column 2''' + - comma: ',' + - column_reference: + - naked_identifier: col3 + - data_type: + - primitive_type: + - keyword: BOOLEAN + - keyword: COMMENT + - quoted_literal: '''Dummy column 3''' + - end_bracket: ) + - table_cluster_by_clause: + - keyword: CLUSTER + - keyword: BY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - end_bracket: ) + - keyword: COMMENT + - quoted_literal: '''Example simplified materialized view with dummy fields.''' + - keyword: TBLPROPERTIES + - bracketed: + - start_bracket: ( + - property_name_identifier: + - quoted_identifier: '''quality''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''gold''' + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col3 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_source_table +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_operator_colon_sign.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_operator_colon_sign.yml index 2d0b4c4aa..8e52b6e8c 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_operator_colon_sign.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/databricks_operator_colon_sign.yml @@ -23,7 +23,8 @@ file: - quoted_literal: '''{ "price": 5 }''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: T - bracketed: - start_bracket: ( @@ -69,7 +70,8 @@ file: - quoted_literal: '''{ "price": 5 }''' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: T - bracketed: - start_bracket: ( diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/date_functions.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/date_functions.yml index 5a60ee4c4..56105da09 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/date_functions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/date_functions.yml @@ -76,7 +76,8 @@ file: - naked_identifier: start_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: date_add_micro - comma: ',' - select_clause_element: @@ -97,7 +98,8 @@ file: - naked_identifier: end_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: datediff_milli - comma: ',' - select_clause_element: @@ -117,7 +119,8 @@ file: - naked_identifier: start_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: dateadd_min - comma: ',' - select_clause_element: @@ -138,7 +141,8 @@ file: - naked_identifier: end_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: datediff_hr - comma: ',' - select_clause_element: @@ -148,9 +152,7 @@ file: - function_contents: - bracketed: - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: DAYOFYEAR + - date_part: DAYOFYEAR - comma: ',' - expression: - numeric_literal: '5' @@ -160,7 +162,8 @@ file: - naked_identifier: start_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: ts_add_day_of_yr - comma: ',' - select_clause_element: @@ -181,7 +184,8 @@ file: - naked_identifier: end_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: ts_diff_week - comma: ',' - select_clause_element: @@ -201,7 +205,8 @@ file: - naked_identifier: start_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: date_add_month - comma: ',' - select_clause_element: @@ -221,7 +226,8 @@ file: - naked_identifier: start_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: date_add_quarter - comma: ',' - select_clause_element: @@ -241,7 +247,8 @@ file: - naked_identifier: start_dt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: date_add_year - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_change_data_feed.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_change_data_feed.yml index 0a6123b79..a8a0a9f5b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_change_data_feed.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_change_data_feed.yml @@ -8,19 +8,22 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: age + - column_reference: + - naked_identifier: age - data_type: - primitive_type: - keyword: INT diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_create_table.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_create_table.yml index b908b2cef..d25aa9f93 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_create_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_create_table.yml @@ -13,49 +13,57 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: first_name + - column_reference: + - naked_identifier: first_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: middle_name + - column_reference: + - naked_identifier: middle_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: last_name + - column_reference: + - naked_identifier: last_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: gender + - column_reference: + - naked_identifier: gender - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: birth_date + - column_reference: + - naked_identifier: birth_date - data_type: - primitive_type: - keyword: TIMESTAMP - comma: ',' - column_definition: - - naked_identifier: ssn + - column_reference: + - naked_identifier: ssn - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: salary + - column_reference: + - naked_identifier: salary - data_type: - primitive_type: - keyword: INT @@ -78,49 +86,57 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: first_name + - column_reference: + - naked_identifier: first_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: middle_name + - column_reference: + - naked_identifier: middle_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: last_name + - column_reference: + - naked_identifier: last_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: gender + - column_reference: + - naked_identifier: gender - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: birth_date + - column_reference: + - naked_identifier: birth_date - data_type: - primitive_type: - keyword: TIMESTAMP - comma: ',' - column_definition: - - naked_identifier: ssn + - column_reference: + - naked_identifier: ssn - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: salary + - column_reference: + - naked_identifier: salary - data_type: - primitive_type: - keyword: INT @@ -143,49 +159,57 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: first_name + - column_reference: + - naked_identifier: first_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: middle_name + - column_reference: + - naked_identifier: middle_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: last_name + - column_reference: + - naked_identifier: last_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: gender + - column_reference: + - naked_identifier: gender - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: birth_date + - column_reference: + - naked_identifier: birth_date - data_type: - primitive_type: - keyword: TIMESTAMP - comma: ',' - column_definition: - - naked_identifier: ssn + - column_reference: + - naked_identifier: ssn - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: salary + - column_reference: + - naked_identifier: salary - data_type: - primitive_type: - keyword: INT @@ -206,49 +230,57 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: first_name + - column_reference: + - naked_identifier: first_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: middle_name + - column_reference: + - naked_identifier: middle_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: last_name + - column_reference: + - naked_identifier: last_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: gender + - column_reference: + - naked_identifier: gender - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: birth_date + - column_reference: + - naked_identifier: birth_date - data_type: - primitive_type: - keyword: TIMESTAMP - comma: ',' - column_definition: - - naked_identifier: ssn + - column_reference: + - naked_identifier: ssn - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: salary + - column_reference: + - naked_identifier: salary - data_type: - primitive_type: - keyword: INT @@ -291,75 +323,85 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: first_name + - column_reference: + - naked_identifier: first_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: middle_name + - column_reference: + - naked_identifier: middle_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: last_name + - column_reference: + - naked_identifier: last_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: gender + - column_reference: + - naked_identifier: gender - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: birth_date + - column_reference: + - naked_identifier: birth_date - data_type: - primitive_type: - keyword: TIMESTAMP - comma: ',' - - generated_column_definition: - - naked_identifier: date_of_birth + - column_definition: + - column_reference: + - naked_identifier: date_of_birth - data_type: - primitive_type: - keyword: DATE - - keyword: GENERATED - - keyword: ALWAYS - - keyword: AS - - bracketed: - - start_bracket: ( - - function: - - function_name: - - function_name_identifier: CAST - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: birth_date - - keyword: AS - - data_type: - - primitive_type: - - keyword: DATE - - end_bracket: ) - - end_bracket: ) - - comma: ',' - - column_definition: - - naked_identifier: ssn + - column_constraint_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: birth_date + - keyword: AS + - data_type: + - primitive_type: + - keyword: DATE + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - column_definition: + - column_reference: + - naked_identifier: ssn - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: salary + - column_reference: + - naked_identifier: salary - data_type: - primitive_type: - keyword: INT diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_delete_from.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_delete_from.yml index cf94da44a..550eb6ba3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_delete_from.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_delete_from.yml @@ -93,7 +93,8 @@ file: - table_reference: - naked_identifier: orders - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t1 - where_clause: - keyword: WHERE diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_merge.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_merge.yml index 1fe1a589f..e340cc39f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_merge.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_merge.yml @@ -321,7 +321,8 @@ file: - dot: . - naked_identifier: customer_id - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: merge_unique_key - comma: ',' - select_clause_element: @@ -346,7 +347,8 @@ file: - select_clause_element: - null_literal: 'NULL' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: merge_unique_key - comma: ',' - select_clause_element: @@ -544,7 +546,8 @@ file: - dot: . - naked_identifier: new_value - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: new_value - comma: ',' - select_clause_element: @@ -555,7 +558,8 @@ file: - dot: . - naked_identifier: deleted - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: deleted - from_clause: - keyword: FROM @@ -599,7 +603,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: latest - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_update_table.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_update_table.yml index 483d7ce7e..b4d42ff1d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_update_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/delta_update_table.yml @@ -104,7 +104,8 @@ file: - table_reference: - naked_identifier: orders - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t1 - set_clause_list: - keyword: SET diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/describe_query.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/describe_query.yml index 892918aeb..deb1023f9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/describe_query.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/describe_query.yml @@ -23,7 +23,8 @@ file: - naked_identifier: age - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_age - from_clause: - keyword: FROM @@ -97,7 +98,8 @@ file: - numeric_literal: 10000.20D - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: employee - bracketed: - start_bracket: ( diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/division_operator.sql b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/division_operator.sql new file mode 100644 index 000000000..196a2e70b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/division_operator.sql @@ -0,0 +1,2 @@ +select t1.year_earn/t1.avg_cost/t1.rcp_cnt as fourth_cnt from dw.test t1; +select t1.year_earn/t1.avg_cost/t1.jar as fourth_cnt from dw.test t1; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/division_operator.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/division_operator.yml new file mode 100644 index 000000000..1d3ff397f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/division_operator.yml @@ -0,0 +1,73 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: year_earn + - binary_operator: / + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: avg_cost + - binary_operator: / + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: rcp_cnt + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: fourth_cnt + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dw + - dot: . + - naked_identifier: test + - alias_expression: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: year_earn + - binary_operator: / + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: avg_cost + - binary_operator: / + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: jar + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: fourth_cnt + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dw + - dot: . + - naked_identifier: test + - alias_expression: + - naked_identifier: t1 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/drop_schema.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/drop_schema.yml index cbaf8c3d1..01d31cde4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/drop_schema.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/drop_schema.yml @@ -5,9 +5,8 @@ file: - keyword: SCHEMA - keyword: IF - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: dbname + - schema_reference: + - naked_identifier: dbname - keyword: RESTRICT - statement_terminator: ; - statement: @@ -16,18 +15,16 @@ file: - keyword: SCHEMA - keyword: IF - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: dbname + - schema_reference: + - naked_identifier: dbname - keyword: CASCADE - statement_terminator: ; - statement: - drop_schema_statement: - keyword: DROP - keyword: SCHEMA - - table_reference: - - object_reference: - - naked_identifier: inventory_db + - schema_reference: + - naked_identifier: inventory_db - keyword: CASCADE - statement_terminator: ; - statement: @@ -36,8 +33,7 @@ file: - keyword: SCHEMA - keyword: IF - keyword: EXISTS - - table_reference: - - object_reference: - - naked_identifier: inventory_db + - schema_reference: + - naked_identifier: inventory_db - keyword: CASCADE - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/exclamation_mark.sql b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/exclamation_mark.sql new file mode 100644 index 000000000..40c90ba48 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/exclamation_mark.sql @@ -0,0 +1,6 @@ +SELECT ! TRUE; + +SELECT ! NULL; + +SELECT * FROM tab +WHERE ! (col > 0); diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/exclamation_mark.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/exclamation_mark.yml new file mode 100644 index 000000000..98217a718 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/exclamation_mark.yml @@ -0,0 +1,48 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - not_operator: '!' + - boolean_literal: 'TRUE' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - not_operator: '!' + - null_literal: 'NULL' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab + - where_clause: + - keyword: WHERE + - expression: + - not_operator: '!' + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/explain.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/explain.yml index 332397c2c..8c03aa698 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/explain.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/explain.yml @@ -172,19 +172,22 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: age + - column_reference: + - naked_identifier: age - data_type: - primitive_type: - keyword: INT @@ -206,19 +209,22 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: INT - comma: ',' - column_definition: - - naked_identifier: student_name + - column_reference: + - naked_identifier: student_name - data_type: - primitive_type: - keyword: STRING - comma: ',' - column_definition: - - naked_identifier: age + - column_reference: + - naked_identifier: age - data_type: - primitive_type: - keyword: INT diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/from_supported_tvf.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/from_supported_tvf.yml index 4c58704a6..f77c80991 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/from_supported_tvf.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/from_supported_tvf.yml @@ -164,7 +164,8 @@ file: - numeric_literal: '8' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: test - statement_terminator: ; - statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/iceberg_create_table.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/iceberg_create_table.yml index 4e959c416..b56c759c5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/iceberg_create_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/iceberg_create_table.yml @@ -12,7 +12,8 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: bigint @@ -22,7 +23,8 @@ file: - quoted_literal: '''unique id''' - comma: ',' - column_definition: - - naked_identifier: data + - column_reference: + - naked_identifier: data - data_type: - primitive_type: - keyword: string @@ -45,19 +47,22 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: bigint - comma: ',' - column_definition: - - naked_identifier: data + - column_reference: + - naked_identifier: data - data_type: - primitive_type: - keyword: string - comma: ',' - column_definition: - - naked_identifier: category + - column_reference: + - naked_identifier: category - data_type: - primitive_type: - keyword: string @@ -87,25 +92,29 @@ file: - bracketed: - start_bracket: ( - column_definition: - - naked_identifier: id + - column_reference: + - naked_identifier: id - data_type: - primitive_type: - keyword: bigint - comma: ',' - column_definition: - - naked_identifier: data + - column_reference: + - naked_identifier: data - data_type: - primitive_type: - keyword: string - comma: ',' - column_definition: - - naked_identifier: category + - column_reference: + - naked_identifier: category - data_type: - primitive_type: - keyword: string - comma: ',' - column_definition: - - naked_identifier: ts + - column_reference: + - naked_identifier: ts - data_type: - primitive_type: - keyword: timestamp diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/insert_overwrite_directory.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/insert_overwrite_directory.yml index df0ae18dc..7dd19d7b4 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/insert_overwrite_directory.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/insert_overwrite_directory.yml @@ -230,17 +230,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: COALESCE - - bracketed: - - start_bracket: ( - - numeric_literal: '1' - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - wildcard_expression: - wildcard_identifier: diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/insert_table.sql b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/insert_table.sql index 11690860d..b59ce96db 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/insert_table.sql +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/insert_table.sql @@ -62,3 +62,31 @@ INSERT INTO students PARTITION (student_id = 11215017) (address, name) VALUES INSERT OVERWRITE students PARTITION (student_id = 11215017) (address, name) VALUES ('Hangzhou, China', 'Kent Yao Jr.'); + +INSERT INTO students REPLACE USING (country) +SELECT * +FROM new_students; + +INSERT INTO students REPLACE USING (country, city) +SELECT * +FROM new_students; + +INSERT INTO students REPLACE USING (country, city) +VALUES + ('Amy Smith', 1100), + ('Kent Yao', 2200); + +INSERT INTO sales REPLACE +WHERE tx_date BETWEEN '2023-10-01' AND '2023-10-02' +VALUES + ('2023-10-01', 1100), + ('2023-10-02', 2200), + ('2023-10-04', 4000); + +INSERT INTO sales REPLACE +WHERE + tx_date BETWEEN '2023-10-01' AND '2023-10-02' + AND store_nbr = 1 + AND item_nbr = 1 +SELECT * +FROM new_sales; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/insert_table.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/insert_table.yml index fef2fd2e1..47176e437 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/insert_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/insert_table.yml @@ -402,3 +402,186 @@ file: - quoted_literal: '''Kent Yao Jr.''' - end_bracket: ) - statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: students + - keyword: REPLACE + - keyword: USING + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: country + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: new_students +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: students + - keyword: REPLACE + - keyword: USING + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: country + - comma: ',' + - column_reference: + - naked_identifier: city + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: new_students +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: students + - keyword: REPLACE + - keyword: USING + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: country + - comma: ',' + - column_reference: + - naked_identifier: city + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''Amy Smith''' + - comma: ',' + - expression: + - numeric_literal: '1100' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''Kent Yao''' + - comma: ',' + - expression: + - numeric_literal: '2200' + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: sales + - keyword: REPLACE + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: tx_date + - keyword: BETWEEN + - quoted_literal: '''2023-10-01''' + - keyword: AND + - quoted_literal: '''2023-10-02''' + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2023-10-01''' + - comma: ',' + - expression: + - numeric_literal: '1100' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2023-10-02''' + - comma: ',' + - expression: + - numeric_literal: '2200' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2023-10-04''' + - comma: ',' + - expression: + - numeric_literal: '4000' + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: sales + - keyword: REPLACE + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: tx_date + - keyword: BETWEEN + - quoted_literal: '''2023-10-01''' + - keyword: AND + - quoted_literal: '''2023-10-02''' + - binary_operator: AND + - column_reference: + - naked_identifier: store_nbr + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - binary_operator: AND + - column_reference: + - naked_identifier: item_nbr + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: new_sales +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/list_file.sql b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/list_file.sql index f86cbab93..dd6b382c8 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/list_file.sql +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/list_file.sql @@ -8,5 +8,4 @@ LIST FILE "/path/to/some/directory"; LIST FILES "/path with space/cde.txt" '/path with space/fgh.txt'; --- NB: Non-quoted paths are not supported in SQLFluff currently ---LIST FILE /tmp/test; +LIST FILE /tmp/test; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/list_file.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/list_file.yml index 6556e3d39..98db89f6d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/list_file.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/list_file.yml @@ -30,3 +30,13 @@ file: - quoted_literal: '"/path with space/cde.txt"' - quoted_literal: '''/path with space/fgh.txt''' - statement_terminator: ; +- statement: + - list_file_statement: + - keyword: LIST + - file_keyword: FILE + - file_literal: + - slash: / + - path_segment: tmp + - slash: / + - path_segment: test +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/literals.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/literals.yml index 9261fc160..88f366f34 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/literals.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/literals.yml @@ -6,7 +6,8 @@ file: - select_clause_element: - quoted_literal: '''Hello, World!''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -16,7 +17,8 @@ file: - select_clause_element: - quoted_literal: '''SPARK SQL''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -26,7 +28,8 @@ file: - select_clause_element: - quoted_literal: '"it''s $10."' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -36,7 +39,8 @@ file: - select_clause_element: - bytes_quoted_literal: X'123456' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -46,7 +50,8 @@ file: - select_clause_element: - null_literal: 'NULL' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -56,7 +61,8 @@ file: - select_clause_element: - boolean_literal: 'TRUE' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -66,7 +72,8 @@ file: - select_clause_element: - boolean_literal: 'FALSE' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -78,7 +85,8 @@ file: - sign_indicator: '-' - numeric_literal: '2147483648' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -88,7 +96,8 @@ file: - select_clause_element: - numeric_literal: 9223372036854775807l - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -100,7 +109,8 @@ file: - sign_indicator: '-' - numeric_literal: 32Y - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -110,7 +120,8 @@ file: - select_clause_element: - numeric_literal: 482S - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -120,7 +131,8 @@ file: - select_clause_element: - numeric_literal: '12.578' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -132,7 +144,8 @@ file: - sign_indicator: '-' - numeric_literal: '0.1234567' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -144,7 +157,8 @@ file: - sign_indicator: '-' - numeric_literal: '.1234567' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -154,7 +168,8 @@ file: - select_clause_element: - numeric_literal: '123.' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -164,7 +179,8 @@ file: - select_clause_element: - numeric_literal: 123.BD - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -174,7 +190,8 @@ file: - select_clause_element: - numeric_literal: '5E2' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -184,7 +201,8 @@ file: - select_clause_element: - numeric_literal: 5D - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -196,7 +214,8 @@ file: - sign_indicator: '-' - numeric_literal: 5BD - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -206,7 +225,8 @@ file: - select_clause_element: - numeric_literal: 12.578e-2d - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -218,7 +238,8 @@ file: - sign_indicator: '-' - numeric_literal: .1234567E+2BD - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -230,7 +251,8 @@ file: - sign_indicator: + - numeric_literal: '3.e+3' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -242,7 +264,8 @@ file: - sign_indicator: '-' - numeric_literal: 3.E-3D - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -253,7 +276,8 @@ file: - keyword: DATE - date_constructor_literal: '''1997''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -264,7 +288,8 @@ file: - keyword: DATE - date_constructor_literal: '''1997-01''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -275,7 +300,8 @@ file: - keyword: DATE - date_constructor_literal: '''2011-11-11''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -286,7 +312,8 @@ file: - keyword: TIMESTAMP - date_constructor_literal: '''1997-01-31 09:26:56.123''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -297,7 +324,8 @@ file: - keyword: TIMESTAMP - date_constructor_literal: '''1997-01-31 09:26:56.66666666UTC+08:00''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -308,7 +336,8 @@ file: - keyword: TIMESTAMP - date_constructor_literal: '''1997-01''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -324,7 +353,8 @@ file: - keyword: TO - date_part: MONTH - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -341,7 +371,8 @@ file: - keyword: TO - date_part: SECOND - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -355,7 +386,8 @@ file: - numeric_literal: '3' - date_part: YEAR - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -373,7 +405,8 @@ file: - signed_quoted_literal: '''3''' - date_part: MINUTE - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -419,6 +452,7 @@ file: - numeric_literal: '9' - date_part: MICROSECONDS - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/merge_into.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/merge_into.yml index e22abc3fb..9c1f1f457 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/merge_into.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/merge_into.yml @@ -82,7 +82,8 @@ file: - naked_identifier: u - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: u - join_on_condition: - keyword: ON diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/parse_integer_type.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/parse_integer_type.yml index c30851321..6fe2f1f45 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/parse_integer_type.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/parse_integer_type.yml @@ -6,11 +6,13 @@ file: - select_clause_element: - numeric_literal: '123' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: INTEGER - comma: ',' - select_clause_element: - numeric_literal: '123' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: INT diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/parse_timestamp_ltz_ntz_type.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/parse_timestamp_ltz_ntz_type.yml index d9f02cb7f..04217518a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/parse_timestamp_ltz_ntz_type.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/parse_timestamp_ltz_ntz_type.yml @@ -4,18 +4,12 @@ file: - select_clause: - keyword: select - select_clause_element: - - expression: - - data_type: - - primitive_type: - - keyword: timestamp_ntz - - quoted_literal: '''1970-01-01''' + - keyword: timestamp_ntz + - date_constructor_literal: '''1970-01-01''' - comma: ',' - select_clause_element: - - expression: - - data_type: - - primitive_type: - - keyword: TIMESTAMP_LTZ - - quoted_literal: '''1970-01-01''' + - keyword: TIMESTAMP_LTZ + - date_constructor_literal: '''1970-01-01''' - comma: ',' - select_clause_element: - function: diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/pivot_clause.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/pivot_clause.yml index 6282f5e06..a126e958f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/pivot_clause.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/pivot_clause.yml @@ -28,7 +28,8 @@ file: - naked_identifier: age - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - keyword: FOR - naked_identifier: name @@ -38,7 +39,8 @@ file: - expression: - quoted_literal: '''John''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: john - end_bracket: ) - end_bracket: ) @@ -72,7 +74,8 @@ file: - naked_identifier: age - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - keyword: FOR - naked_identifier: name @@ -82,13 +85,15 @@ file: - expression: - quoted_literal: '''John''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: john - comma: ',' - expression: - quoted_literal: '''Mike''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: mike - end_bracket: ) - end_bracket: ) @@ -122,7 +127,8 @@ file: - naked_identifier: age - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - keyword: FOR - bracketed: @@ -135,13 +141,15 @@ file: - expression: - quoted_literal: '''John''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: john - comma: ',' - expression: - quoted_literal: '''Mike''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: mike - end_bracket: ) - end_bracket: ) @@ -175,7 +183,8 @@ file: - naked_identifier: age - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - keyword: FOR - naked_identifier: name @@ -185,13 +194,15 @@ file: - expression: - quoted_literal: '''John''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: john - comma: ',' - expression: - quoted_literal: '''Mike''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: mike - end_bracket: ) - end_bracket: ) @@ -229,7 +240,8 @@ file: - naked_identifier: age - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - comma: ',' - function: @@ -243,7 +255,8 @@ file: - naked_identifier: class - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: c - keyword: FOR - naked_identifier: name @@ -253,13 +266,15 @@ file: - expression: - quoted_literal: '''John''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: john - comma: ',' - expression: - quoted_literal: '''Mike''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: mike - end_bracket: ) - end_bracket: ) @@ -297,7 +312,8 @@ file: - naked_identifier: age - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - comma: ',' - function: @@ -311,7 +327,8 @@ file: - naked_identifier: class - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: c - keyword: FOR - naked_identifier: name @@ -321,13 +338,15 @@ file: - expression: - quoted_literal: '''John''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: john - comma: ',' - expression: - quoted_literal: '''Mike''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: mike - end_bracket: ) - end_bracket: ) @@ -365,7 +384,8 @@ file: - naked_identifier: age - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - comma: ',' - function: @@ -379,7 +399,8 @@ file: - naked_identifier: class - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: c - keyword: FOR - naked_identifier: name @@ -397,7 +418,8 @@ file: - numeric_literal: '30' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: c1 - comma: ',' - bracketed: @@ -409,7 +431,8 @@ file: - numeric_literal: '40' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: c2 - end_bracket: ) - end_bracket: ) @@ -437,7 +460,8 @@ file: - table_reference: - naked_identifier: person - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: p - pivot_clause: - keyword: PIVOT @@ -454,7 +478,8 @@ file: - naked_identifier: age - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - comma: ',' - function: @@ -468,7 +493,8 @@ file: - naked_identifier: class - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: c - keyword: FOR - naked_identifier: name @@ -486,7 +512,8 @@ file: - numeric_literal: '30' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: c1 - comma: ',' - bracketed: @@ -498,7 +525,8 @@ file: - numeric_literal: '40' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: c2 - end_bracket: ) - end_bracket: ) @@ -536,7 +564,8 @@ file: - naked_identifier: age - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: a - comma: ',' - function: @@ -550,7 +579,8 @@ file: - naked_identifier: class - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: c - keyword: FOR - bracketed: @@ -565,7 +595,8 @@ file: - expression: - quoted_literal: '''John''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: c1 - comma: ',' - bracketed: @@ -577,7 +608,8 @@ file: - numeric_literal: '40' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: c2 - end_bracket: ) - end_bracket: ) @@ -618,7 +650,8 @@ file: - binary_operator: / - numeric_literal: '1e9' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: min_timestamp_s - keyword: FOR - naked_identifier: run_id @@ -629,14 +662,16 @@ file: - column_reference: - naked_identifier: test_run_id - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: test - comma: ',' - expression: - column_reference: - naked_identifier: ctrl_run_id - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: ctrl - end_bracket: ) - end_bracket: ) @@ -679,7 +714,8 @@ file: - naked_identifier: sales - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: s - pivot_clause: - keyword: PIVOT @@ -696,7 +732,8 @@ file: - naked_identifier: sales - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: total - comma: ',' - function: @@ -710,7 +747,8 @@ file: - naked_identifier: sales - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: avg - keyword: FOR - naked_identifier: quarter @@ -720,25 +758,29 @@ file: - expression: - numeric_literal: '1' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q1 - comma: ',' - expression: - numeric_literal: '2' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q2 - comma: ',' - expression: - numeric_literal: '3' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q3 - comma: ',' - expression: - numeric_literal: '4' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: q4 - end_bracket: ) - end_bracket: ) @@ -757,7 +799,8 @@ file: - naked_identifier: q1_avg - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: total - keyword: FOR - naked_identifier: year diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/raw_literal.sql b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/raw_literal.sql new file mode 100644 index 000000000..817e73cde --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/raw_literal.sql @@ -0,0 +1,4 @@ +SELECT r'foo\nbar' AS col; +SELECT r"foo\nbar" AS col; +SELECT R'foo\nbar' AS col; +SELECT R"foo\nbar" AS col; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/raw_literal.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/raw_literal.yml new file mode 100644 index 000000000..701c88950 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/raw_literal.yml @@ -0,0 +1,45 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - raw_quoted_literal: r'foo\nbar' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: col +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - raw_quoted_literal: r"foo\nbar" + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: col +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - raw_quoted_literal: R'foo\nbar' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: col +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - raw_quoted_literal: R"foo\nbar" + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: col +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_cluster_by.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_cluster_by.yml index d4ae3363b..eec66b88b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_cluster_by.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_cluster_by.yml @@ -290,7 +290,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: p_data_date - cluster_by_clause: - keyword: CLUSTER diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_delimited_identifier.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_delimited_identifier.yml index 69c1417d7..2d7a2ce4e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_delimited_identifier.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_delimited_identifier.yml @@ -6,7 +6,8 @@ file: - select_clause_element: - numeric_literal: '1' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - quoted_identifier: '`delimited_but_regular_identifer_0`' - statement_terminator: ; - statement: @@ -16,7 +17,8 @@ file: - select_clause_element: - numeric_literal: '2' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - quoted_identifier: '`100% unruly-identifier`' - statement_terminator: ; - statement: diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_delimited_identifier_with_escaped_backticks.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_delimited_identifier_with_escaped_backticks.yml index ddd645bc0..0d0f293de 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_delimited_identifier_with_escaped_backticks.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_delimited_identifier_with_escaped_backticks.yml @@ -31,7 +31,8 @@ file: - table_reference: - quoted_identifier: '`some``table`' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - quoted_identifier: '`some``alias`' - statement_terminator: ; - statement: @@ -99,7 +100,8 @@ file: - column_reference: - quoted_identifier: '`delimited ``identifier`' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_identifier: '`alias`' - from_clause: - keyword: FROM @@ -109,6 +111,7 @@ file: - table_reference: - quoted_identifier: '`some``table`' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_identifier: '`some``alias`' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_distribute_by.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_distribute_by.yml index 813b1bf39..148b4f7cf 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_distribute_by.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_distribute_by.yml @@ -345,7 +345,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: p_data_date - distribute_by_clause: - keyword: DISTRIBUTE diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_from_lateral_view.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_from_lateral_view.yml index 449702d1d..32f9c3a1b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_from_lateral_view.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_from_lateral_view.yml @@ -37,57 +37,57 @@ file: - table_expression: - table_reference: - naked_identifier: person - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: EXPLODE - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: ARRAY - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '30' - - comma: ',' - - expression: - - numeric_literal: '60' - - end_bracket: ) - - end_bracket: ) - - naked_identifier: tbl_name - - keyword: AS - - naked_identifier: c_age - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: EXPLODE - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: ARRAY - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '40' - - comma: ',' - - expression: - - numeric_literal: '80' - - end_bracket: ) - - end_bracket: ) - - keyword: AS - - naked_identifier: d_age + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '30' + - comma: ',' + - expression: + - numeric_literal: '60' + - end_bracket: ) + - end_bracket: ) + - naked_identifier: tbl_name + - keyword: AS + - naked_identifier: c_age + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '40' + - comma: ',' + - expression: + - numeric_literal: '80' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - naked_identifier: d_age - statement_terminator: ; - statement: - select_statement: @@ -107,7 +107,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: record_count - from_clause: - keyword: FROM @@ -116,56 +117,56 @@ file: - table_expression: - table_reference: - naked_identifier: person - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: EXPLODE - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: ARRAY - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '30' - - comma: ',' - - expression: - - numeric_literal: '60' - - end_bracket: ) - - end_bracket: ) - - keyword: AS - - naked_identifier: c_age - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: EXPLODE - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: ARRAY - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '40' - - comma: ',' - - expression: - - numeric_literal: '80' - - end_bracket: ) - - end_bracket: ) - - keyword: AS - - naked_identifier: d_age + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '30' + - comma: ',' + - expression: + - numeric_literal: '60' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - naked_identifier: c_age + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '40' + - comma: ',' + - expression: + - numeric_literal: '80' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - naked_identifier: d_age - groupby_clause: - keyword: GROUP - keyword: BY @@ -210,27 +211,27 @@ file: - table_expression: - table_reference: - naked_identifier: person - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: EXPLODE - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: ARRAY - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) - - end_bracket: ) - - naked_identifier: tbl_name - - keyword: AS - - naked_identifier: c_age + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - naked_identifier: tbl_name + - keyword: AS + - naked_identifier: c_age - statement_terminator: ; - statement: - select_statement: @@ -270,28 +271,28 @@ file: - table_expression: - table_reference: - naked_identifier: person - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - keyword: OUTER - - function: - - function_name: - - function_name_identifier: EXPLODE - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: ARRAY - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) - - end_bracket: ) - - naked_identifier: tbl_name - - keyword: AS - - naked_identifier: c_age + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - keyword: OUTER + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - naked_identifier: tbl_name + - keyword: AS + - naked_identifier: c_age - statement_terminator: ; - statement: - select_statement: @@ -331,27 +332,27 @@ file: - table_expression: - table_reference: - naked_identifier: person - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - keyword: OUTER - - function: - - function_name: - - function_name_identifier: EXPLODE - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: ARRAY - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) - - end_bracket: ) - - naked_identifier: tbl_name - - naked_identifier: c_age + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - keyword: OUTER + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - naked_identifier: tbl_name + - naked_identifier: c_age - statement_terminator: ; - statement: - select_statement: @@ -391,26 +392,26 @@ file: - table_expression: - table_reference: - naked_identifier: person - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - keyword: OUTER - - function: - - function_name: - - function_name_identifier: EXPLODE - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: ARRAY - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) - - end_bracket: ) - - naked_identifier: c_age + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - keyword: OUTER + - function: + - function_name: + - function_name_identifier: EXPLODE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - naked_identifier: c_age - statement_terminator: ; - statement: - select_statement: @@ -446,26 +447,26 @@ file: - table_expression: - table_reference: - naked_identifier: person - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: INLINE - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: array_of_structs - - end_bracket: ) - - naked_identifier: exploded_people - - keyword: AS - - naked_identifier: name - - comma: ',' - - naked_identifier: age - - comma: ',' - - naked_identifier: state + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: INLINE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: array_of_structs + - end_bracket: ) + - naked_identifier: exploded_people + - keyword: AS + - naked_identifier: name + - comma: ',' + - naked_identifier: age + - comma: ',' + - naked_identifier: state - statement_terminator: ; - statement: - select_statement: @@ -502,28 +503,29 @@ file: - table_reference: - naked_identifier: person - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: p - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: INLINE - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: array_of_structs - - end_bracket: ) - - naked_identifier: exploded_people - - keyword: AS - - naked_identifier: name - - comma: ',' - - naked_identifier: age - - comma: ',' - - naked_identifier: state + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: INLINE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: array_of_structs + - end_bracket: ) + - naked_identifier: exploded_people + - keyword: AS + - naked_identifier: name + - comma: ',' + - naked_identifier: age + - comma: ',' + - naked_identifier: state - statement_terminator: ; - statement: - select_statement: @@ -560,22 +562,23 @@ file: - table_reference: - naked_identifier: person - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: p - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: INLINE - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: array_of_structs - - end_bracket: ) - - naked_identifier: exploded_people + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: INLINE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: array_of_structs + - end_bracket: ) + - naked_identifier: exploded_people - statement_terminator: ; - statement: - select_statement: @@ -612,27 +615,28 @@ file: - table_reference: - naked_identifier: person - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: p - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: INLINE - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: array_of_structs - - end_bracket: ) - - naked_identifier: exploded_people - - naked_identifier: name - - comma: ',' - - naked_identifier: age - - comma: ',' - - naked_identifier: state + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: INLINE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: array_of_structs + - end_bracket: ) + - naked_identifier: exploded_people + - naked_identifier: name + - comma: ',' + - naked_identifier: age + - comma: ',' + - naked_identifier: state - statement_terminator: ; - statement: - select_statement: @@ -669,27 +673,28 @@ file: - table_reference: - naked_identifier: person - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: p - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: INLINE - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: array_of_structs - - end_bracket: ) - - keyword: AS - - naked_identifier: name - - comma: ',' - - naked_identifier: age - - comma: ',' - - naked_identifier: state + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: INLINE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: array_of_structs + - end_bracket: ) + - keyword: AS + - naked_identifier: name + - comma: ',' + - naked_identifier: age + - comma: ',' + - naked_identifier: state - statement_terminator: ; - statement: - select_statement: @@ -735,7 +740,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: ptc - from_clause: - keyword: FROM @@ -745,7 +751,8 @@ file: - table_reference: - naked_identifier: table1 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t1 - join_clause: - keyword: LEFT @@ -755,7 +762,8 @@ file: - table_reference: - naked_identifier: table2 - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t2 - join_on_condition: - keyword: ON diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_from_values.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_from_values.yml index 1a4c207fe..a1b5707b1 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_from_values.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_from_values.yml @@ -316,7 +316,8 @@ file: - expression: - numeric_literal: '1' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - statement_terminator: ; - statement: @@ -343,7 +344,8 @@ file: - numeric_literal: '2' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - bracketed: - start_bracket: ( @@ -389,7 +391,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - bracketed: - start_bracket: ( @@ -435,7 +438,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - bracketed: - start_bracket: ( - identifier_list: diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_group_by.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_group_by.yml index da7a9e77c..b32625c6f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_group_by.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_group_by.yml @@ -19,7 +19,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM @@ -59,7 +60,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM @@ -97,7 +99,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - comma: ',' - select_clause_element: @@ -112,7 +115,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: max_quantity - from_clause: - keyword: FROM @@ -153,7 +157,8 @@ file: - naked_identifier: city - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: count_distinct_city - from_clause: - keyword: FROM @@ -203,7 +208,8 @@ file: - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - quoted_identifier: '`sum(quantity)`' - from_clause: - keyword: FROM @@ -247,7 +253,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM @@ -326,7 +333,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM @@ -410,7 +418,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM @@ -495,7 +504,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM @@ -548,7 +558,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM @@ -618,7 +629,8 @@ file: - keyword: NULLS - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: first_age - comma: ',' - select_clause_element: @@ -633,7 +645,8 @@ file: - naked_identifier: id - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: last_id - comma: ',' - select_clause_element: @@ -648,7 +661,8 @@ file: - naked_identifier: id - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_id - from_clause: - keyword: FROM @@ -680,7 +694,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: record_count - from_clause: - keyword: FROM @@ -723,7 +738,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: record_count - from_clause: - keyword: FROM @@ -767,7 +783,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: record_count - from_clause: - keyword: FROM @@ -814,7 +831,8 @@ file: - star: '*' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: record_count - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_having.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_having.yml index 6784f15e2..20867c174 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_having.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_having.yml @@ -19,7 +19,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM @@ -62,7 +63,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM @@ -113,7 +115,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM @@ -156,7 +159,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM @@ -207,7 +211,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM @@ -250,7 +255,8 @@ file: - naked_identifier: quantity - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: sum_quantity - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_hints.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_hints.yml index 74eaf3ebc..a6e5d65c1 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_hints.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_hints.yml @@ -3,17 +3,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: COALESCE - - bracketed: - - start_bracket: ( - - numeric_literal: '3' - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: a @@ -37,17 +26,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: REPARTITION - - bracketed: - - start_bracket: ( - - numeric_literal: '3' - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: a @@ -71,17 +49,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: REPARTITION - - bracketed: - - start_bracket: ( - - naked_identifier: c - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: a @@ -105,19 +72,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: REPARTITION - - bracketed: - - start_bracket: ( - - numeric_literal: '3' - - comma: ',' - - naked_identifier: c - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: a @@ -141,17 +95,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: REPARTITION_BY_RANGE - - bracketed: - - start_bracket: ( - - naked_identifier: c - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: a @@ -175,19 +118,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: REPARTITION_BY_RANGE - - bracketed: - - start_bracket: ( - - numeric_literal: '3' - - comma: ',' - - naked_identifier: c - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: a @@ -211,13 +141,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: REBALANCE - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: a @@ -241,17 +164,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: REBALANCE - - bracketed: - - start_bracket: ( - - naked_identifier: c - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: a @@ -275,35 +187,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: REPARTITION - - bracketed: - - start_bracket: ( - - numeric_literal: '100' - - end_bracket: ) - - comma: ',' - - hint_function: - - function_name: - - function_name_identifier: COALESCE - - bracketed: - - start_bracket: ( - - numeric_literal: '500' - - end_bracket: ) - - comma: ',' - - hint_function: - - function_name: - - function_name_identifier: REPARTITION_BY_RANGE - - bracketed: - - start_bracket: ( - - numeric_literal: '3' - - comma: ',' - - naked_identifier: c - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: a @@ -327,17 +210,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: BROADCAST - - bracketed: - - start_bracket: ( - - naked_identifier: t1 - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: t1 @@ -387,17 +259,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: BROADCASTJOIN - - bracketed: - - start_bracket: ( - - naked_identifier: t1 - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: t1 @@ -447,17 +308,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: MAPJOIN - - bracketed: - - start_bracket: ( - - naked_identifier: t2 - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: t1 @@ -507,17 +357,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: SHUFFLE_MERGE - - bracketed: - - start_bracket: ( - - naked_identifier: t1 - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: t1 @@ -567,17 +406,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: MERGEJOIN - - bracketed: - - start_bracket: ( - - naked_identifier: t2 - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: t1 @@ -627,17 +455,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: MERGE - - bracketed: - - start_bracket: ( - - naked_identifier: t1 - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: t1 @@ -687,17 +504,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: SHUFFLE_HASH - - bracketed: - - start_bracket: ( - - naked_identifier: t1 - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: t1 @@ -747,17 +553,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: SHUFFLE_REPLICATE_NL - - bracketed: - - start_bracket: ( - - naked_identifier: t1 - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: t1 @@ -807,27 +602,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: BROADCAST - - bracketed: - - start_bracket: ( - - naked_identifier: t1 - - end_bracket: ) - - comma: ',' - - hint_function: - - function_name: - - function_name_identifier: MERGE - - bracketed: - - start_bracket: ( - - naked_identifier: t1 - - comma: ',' - - naked_identifier: t2 - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: t1 @@ -877,20 +651,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: BROADCAST - - bracketed: - - start_bracket: ( - - table_reference: - - naked_identifier: db - - dot: . - - naked_identifier: t1 - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: t1 diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_lateral_view_supported_tvf.sql b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_lateral_view_supported_tvf.sql index e9346e4b5..2d112cf61 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_lateral_view_supported_tvf.sql +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_lateral_view_supported_tvf.sql @@ -91,3 +91,10 @@ FROM test LATERAL VIEW parse_url( 'http://spark.apache.org/path?query=1', 'HOST' ) AS c1; + +-- explode in a LATERAL CLAUSE +SELECT + a.id, + b.col +FROM range(10) as test, + LATERAL explode(array('a', 'b', 'c')) as b; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_lateral_view_supported_tvf.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_lateral_view_supported_tvf.yml index f2573fd41..120a30b17 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_lateral_view_supported_tvf.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_lateral_view_supported_tvf.yml @@ -73,31 +73,31 @@ file: - table_expression: - table_reference: - naked_identifier: test - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: explode - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: array - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '3' - - comma: ',' - - expression: - - numeric_literal: '4' - - end_bracket: ) - - end_bracket: ) - - keyword: AS - - naked_identifier: c2 + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: explode + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: array + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - numeric_literal: '4' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - naked_identifier: c2 - statement_terminator: ; - statement: - select_statement: @@ -121,31 +121,31 @@ file: - table_expression: - table_reference: - naked_identifier: test - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: explode_outer - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: array - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '3' - - comma: ',' - - expression: - - numeric_literal: '4' - - end_bracket: ) - - end_bracket: ) - - keyword: AS - - naked_identifier: c2 + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: explode_outer + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: array + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '3' + - comma: ',' + - expression: + - numeric_literal: '4' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - naked_identifier: c2 - statement_terminator: ; - statement: - select_statement: @@ -265,55 +265,55 @@ file: - table_expression: - table_reference: - naked_identifier: test - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: inline - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: array - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: struct - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '1' - - comma: ',' - - expression: - - quoted_literal: '''a''' - - end_bracket: ) - - comma: ',' - - expression: - - function: - - function_name: - - function_name_identifier: struct - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '2' - - comma: ',' - - expression: - - quoted_literal: '''b''' - - end_bracket: ) - - end_bracket: ) - - end_bracket: ) - - keyword: AS - - naked_identifier: c1 - - comma: ',' - - naked_identifier: c2 + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: inline + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: array + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: struct + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - quoted_literal: '''a''' + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: struct + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - quoted_literal: '''b''' + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - naked_identifier: c1 + - comma: ',' + - naked_identifier: c2 - statement_terminator: ; - statement: - select_statement: @@ -337,55 +337,55 @@ file: - table_expression: - table_reference: - naked_identifier: test - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: inline_outer - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: array - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: struct - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '1' - - comma: ',' - - expression: - - quoted_literal: '''a''' - - end_bracket: ) - - comma: ',' - - expression: - - function: - - function_name: - - function_name_identifier: struct - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '2' - - comma: ',' - - expression: - - quoted_literal: '''b''' - - end_bracket: ) - - end_bracket: ) - - end_bracket: ) - - keyword: AS - - naked_identifier: c1 - - comma: ',' - - naked_identifier: c2 + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: inline_outer + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: array + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: struct + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - quoted_literal: '''a''' + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: struct + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - quoted_literal: '''b''' + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - naked_identifier: c1 + - comma: ',' + - naked_identifier: c2 - statement_terminator: ; - statement: - select_statement: @@ -461,31 +461,31 @@ file: - table_expression: - table_reference: - naked_identifier: test - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: posexplode - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: array - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '10' - - comma: ',' - - expression: - - numeric_literal: '20' - - end_bracket: ) - - end_bracket: ) - - keyword: AS - - naked_identifier: c1 + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: posexplode + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: array + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '10' + - comma: ',' + - expression: + - numeric_literal: '20' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - naked_identifier: c1 - statement_terminator: ; - statement: - select_statement: @@ -509,31 +509,31 @@ file: - table_expression: - table_reference: - naked_identifier: test - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: posexplode_outer - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: array - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '10' - - comma: ',' - - expression: - - numeric_literal: '20' - - end_bracket: ) - - end_bracket: ) - - keyword: AS - - naked_identifier: c1 + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: posexplode_outer + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: array + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '10' + - comma: ',' + - expression: + - numeric_literal: '20' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - naked_identifier: c1 - statement_terminator: ; - statement: - select_statement: @@ -581,31 +581,31 @@ file: - table_expression: - table_reference: - naked_identifier: test - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: stack - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '2' - - comma: ',' - - expression: - - numeric_literal: '1' - - comma: ',' - - expression: - - numeric_literal: '2' - - comma: ',' - - expression: - - numeric_literal: '3' - - end_bracket: ) - - keyword: AS - - naked_identifier: c1 - - comma: ',' - - naked_identifier: c2 + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: stack + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - numeric_literal: '3' + - end_bracket: ) + - keyword: AS + - naked_identifier: c1 + - comma: ',' + - naked_identifier: c2 - statement_terminator: ; - statement: - select_statement: @@ -650,28 +650,28 @@ file: - table_expression: - table_reference: - naked_identifier: test - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW - - function: - - function_name: - - function_name_identifier: json_tuple - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - quoted_literal: '''{"a":1, "b":2}''' - - comma: ',' - - expression: - - quoted_literal: '''a''' - - comma: ',' - - expression: - - quoted_literal: '''b''' - - end_bracket: ) - - keyword: AS - - naked_identifier: c1 - - comma: ',' - - naked_identifier: c2 + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: json_tuple + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''{"a":1, "b":2}''' + - comma: ',' + - expression: + - quoted_literal: '''a''' + - comma: ',' + - expression: + - quoted_literal: '''b''' + - end_bracket: ) + - keyword: AS + - naked_identifier: c1 + - comma: ',' + - naked_identifier: c2 - statement_terminator: ; - statement: - select_statement: @@ -713,21 +713,83 @@ file: - table_expression: - table_reference: - naked_identifier: test - - lateral_view_clause: - - keyword: LATERAL - - keyword: VIEW + - lateral_view_clause: + - keyword: LATERAL + - keyword: VIEW + - function: + - function_name: + - function_name_identifier: parse_url + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''http://spark.apache.org/path?query=1''' + - comma: ',' + - expression: + - quoted_literal: '''HOST''' + - end_bracket: ) + - keyword: AS + - naked_identifier: c1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: - function: - function_name: - - function_name_identifier: parse_url + - function_name_identifier: range - function_contents: - bracketed: - start_bracket: ( - expression: - - quoted_literal: '''http://spark.apache.org/path?query=1''' - - comma: ',' - - expression: - - quoted_literal: '''HOST''' + - numeric_literal: '10' - end_bracket: ) - - keyword: AS - - naked_identifier: c1 + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: test + - lateral_view_clause: + - comma: ',' + - keyword: LATERAL + - function: + - function_name: + - function_name_identifier: explode + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: array + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''a''' + - comma: ',' + - expression: + - quoted_literal: '''b''' + - comma: ',' + - expression: + - quoted_literal: '''c''' + - end_bracket: ) + - end_bracket: ) + - keyword: as + - naked_identifier: b - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_like_clause.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_like_clause.yml index a720e84a1..866f842f2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_like_clause.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_like_clause.yml @@ -211,11 +211,9 @@ file: - keyword: ALL - bracketed: - start_bracket: ( - - column_reference: - - quoted_identifier: '''%an%''' + - quoted_literal: '''%an%''' - comma: ',' - - column_reference: - - quoted_identifier: '''%an''' + - quoted_literal: '''%an''' - end_bracket: ) - statement_terminator: ; - statement: @@ -245,11 +243,9 @@ file: - keyword: ANY - bracketed: - start_bracket: ( - - column_reference: - - quoted_identifier: '''%an%''' + - quoted_literal: '''%an%''' - comma: ',' - - column_reference: - - quoted_identifier: '''%an''' + - quoted_literal: '''%an''' - end_bracket: ) - statement_terminator: ; - statement: @@ -279,11 +275,9 @@ file: - keyword: SOME - bracketed: - start_bracket: ( - - column_reference: - - quoted_identifier: '''%an%''' + - quoted_literal: '''%an%''' - comma: ',' - - column_reference: - - quoted_identifier: '''%an''' + - quoted_literal: '''%an''' - end_bracket: ) - statement_terminator: ; - statement: @@ -314,11 +308,9 @@ file: - keyword: ALL - bracketed: - start_bracket: ( - - column_reference: - - quoted_identifier: '''%an%''' + - quoted_literal: '''%an%''' - comma: ',' - - column_reference: - - quoted_identifier: '''%an''' + - quoted_literal: '''%an''' - end_bracket: ) - statement_terminator: ; - statement: @@ -349,11 +341,9 @@ file: - keyword: ANY - bracketed: - start_bracket: ( - - column_reference: - - quoted_identifier: '''%an%''' + - quoted_literal: '''%an%''' - comma: ',' - - column_reference: - - quoted_identifier: '''%an''' + - quoted_literal: '''%an''' - end_bracket: ) - statement_terminator: ; - statement: @@ -384,11 +374,9 @@ file: - keyword: SOME - bracketed: - start_bracket: ( - - column_reference: - - quoted_identifier: '''%an%''' + - quoted_literal: '''%an%''' - comma: ',' - - column_reference: - - quoted_identifier: '''%an''' + - quoted_literal: '''%an''' - end_bracket: ) - statement_terminator: ; - statement: @@ -414,11 +402,9 @@ file: - keyword: ALL - bracketed: - start_bracket: ( - - column_reference: - - quoted_identifier: '''%oO%''' + - quoted_literal: '''%oO%''' - comma: ',' - - column_reference: - - quoted_identifier: '''%Go%''' + - quoted_literal: '''%Go%''' - end_bracket: ) - statement_terminator: ; - statement: @@ -444,13 +430,10 @@ file: - keyword: ANY - bracketed: - start_bracket: ( - - column_reference: - - quoted_identifier: '''%oo%''' + - quoted_literal: '''%oo%''' - comma: ',' - - column_reference: - - quoted_identifier: '''%IN''' + - quoted_literal: '''%IN''' - comma: ',' - - column_reference: - - quoted_identifier: '''fA%''' + - quoted_literal: '''fA%''' - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_qualify.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_qualify.yml index 67ffd4e1d..1601e0b47 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_qualify.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_qualify.yml @@ -34,7 +34,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM @@ -88,7 +89,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM @@ -152,7 +154,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM @@ -221,7 +224,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM @@ -288,7 +292,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM @@ -360,7 +365,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM @@ -427,7 +433,8 @@ file: - keyword: DESC - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: rank - from_clause: - keyword: FROM @@ -502,7 +509,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: p_data_date - qualify_clause: - keyword: QUALIFY diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_reduce.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_reduce.yml index 6e0bd5091..cfd17e511 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_reduce.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_reduce.yml @@ -210,6 +210,7 @@ file: - naked_identifier: cnt - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: avg - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_sort_by.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_sort_by.yml index 8bbf45a3c..29f420e12 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_sort_by.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_sort_by.yml @@ -3,17 +3,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: REPARTITION - - bracketed: - - start_bracket: ( - - naked_identifier: zip_code - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: name @@ -70,17 +59,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: REPARTITION - - bracketed: - - start_bracket: ( - - naked_identifier: zip_code - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: name @@ -135,17 +113,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: REPARTITION - - bracketed: - - start_bracket: ( - - naked_identifier: zip_code - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: age @@ -206,17 +173,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: REPARTITION - - bracketed: - - start_bracket: ( - - naked_identifier: zip_code - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: age @@ -275,17 +231,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: REPARTITION - - bracketed: - - start_bracket: ( - - naked_identifier: zip_code - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: age @@ -348,17 +293,6 @@ file: - select_statement: - select_clause: - keyword: SELECT - - select_clause_modifier: - - select_hint: - - start_hint: /*+ - - hint_function: - - function_name: - - function_name_identifier: REPARTITION - - bracketed: - - start_bracket: ( - - naked_identifier: zip_code - - end_bracket: ) - - end_hint: '*/' - select_clause_element: - column_reference: - naked_identifier: name @@ -593,7 +527,8 @@ file: - start_bracket: ( - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: p_data_date - sort_by_clause: - keyword: SORT diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_tablesample.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_tablesample.yml index e0047742d..f449e9687 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_tablesample.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_tablesample.yml @@ -87,7 +87,8 @@ file: - keyword: PERCENT - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t - statement_terminator: ; - statement: @@ -273,7 +274,8 @@ file: - keyword: ROWS - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t1 - join_clause: - keyword: NATURAL @@ -293,6 +295,7 @@ file: - numeric_literal: '10' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: t2 - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_union.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_union.yml index a1fbd0af5..eb507302a 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_union.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/select_union.yml @@ -7,7 +7,8 @@ file: - select_clause_element: - quoted_literal: '''a''' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - set_operator: - keyword: UNION diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/set_variable.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/set_variable.yml index baf3d5584..ba08f92b3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/set_variable.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/set_variable.yml @@ -1,149 +1,155 @@ file: - statement: - - keyword: SET - - keyword: VAR - - naked_identifier: var1 - - comparison_operator: - - raw_comparison_operator: = - - expression: - - numeric_literal: '5' + - set_variable_statement: + - keyword: SET + - keyword: VAR + - naked_identifier: var1 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - numeric_literal: '5' - statement_terminator: ; - statement: - - keyword: SET - - keyword: VARIABLE - - naked_identifier: var1 - - comparison_operator: - - raw_comparison_operator: = - - expression: - - bracketed: - - start_bracket: ( - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - function: - - function_name: - - function_name_identifier: max - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: c1 - - end_bracket: ) - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - values_clause: - - keyword: VALUES - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '1' - - end_bracket: ) - - comma: ',' + - set_variable_statement: + - keyword: SET + - keyword: VARIABLE + - naked_identifier: var1 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: max + - function_contents: - bracketed: - start_bracket: ( - expression: - - numeric_literal: '2' + - column_reference: + - naked_identifier: c1 - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: t + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - values_clause: + - keyword: VALUES - bracketed: - start_bracket: ( - - identifier_list: - - naked_identifier: c1 + - expression: + - numeric_literal: '1' - end_bracket: ) - - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: c1 + - end_bracket: ) + - end_bracket: ) - statement_terminator: ; - statement: - - keyword: SET - - keyword: VAR - - naked_identifier: var1 - - comparison_operator: - - raw_comparison_operator: = - - keyword: DEFAULT + - set_variable_statement: + - keyword: SET + - keyword: VAR + - naked_identifier: var1 + - comparison_operator: + - raw_comparison_operator: = + - keyword: DEFAULT - statement_terminator: ; - statement: - - keyword: SET - - keyword: VAR - - bracketed: - - start_bracket: ( - - naked_identifier: var1 - - comma: ',' - - naked_identifier: var2 - - end_bracket: ) - - comparison_operator: - - raw_comparison_operator: = - - expression: + - set_variable_statement: + - keyword: SET + - keyword: VAR - bracketed: - start_bracket: ( - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - function: - - function_name: - - function_name_identifier: max - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: c1 - - end_bracket: ) - - comma: ',' - - select_clause_element: - - function: - - function_name: - - function_name_identifier: CAST - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: min - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: c1 - - end_bracket: ) - - keyword: AS - - data_type: - - primitive_type: - - keyword: STRING - - end_bracket: ) - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - values_clause: - - keyword: VALUES + - naked_identifier: var1 + - comma: ',' + - naked_identifier: var2 + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: max + - function_contents: - bracketed: - start_bracket: ( - expression: - - numeric_literal: '1' + - column_reference: + - naked_identifier: c1 - end_bracket: ) - - comma: ',' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CAST + - function_contents: - bracketed: - start_bracket: ( - expression: - - numeric_literal: '2' - - end_bracket: ) - - alias_expression: + - function: + - function_name: + - function_name_identifier: min + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c1 + - end_bracket: ) - keyword: AS - - naked_identifier: t + - data_type: + - primitive_type: + - keyword: STRING + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - values_clause: + - keyword: VALUES - bracketed: - start_bracket: ( - - identifier_list: - - naked_identifier: c1 + - expression: + - numeric_literal: '1' - end_bracket: ) - - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: c1 + - end_bracket: ) + - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/structure_accessor.sql b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/structure_accessor.sql new file mode 100644 index 000000000..e96a59be2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/structure_accessor.sql @@ -0,0 +1,4 @@ +select + struct_column.inner_array[0].foo as inner_array__foo, + try_element_at(struct_column.inner_array, 1).foo as inner_array__foo2 +from src; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/structure_accessor.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/structure_accessor.yml new file mode 100644 index 000000000..3ceaaa986 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/structure_accessor.yml @@ -0,0 +1,55 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: struct_column + - dot: . + - naked_identifier: inner_array + - array_accessor: + - start_square_bracket: '[' + - numeric_literal: '0' + - end_square_bracket: ']' + - semi_structured_expression: + - dot: . + - semi_structured_element: foo + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: inner_array__foo + - comma: ',' + - select_clause_element: + - expression: + - function: + - function_name: + - function_name_identifier: try_element_at + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: struct_column + - dot: . + - naked_identifier: inner_array + - comma: ',' + - expression: + - numeric_literal: '1' + - end_bracket: ) + - semi_structured_expression: + - dot: . + - semi_structured_element: foo + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: inner_array__foo2 + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: src +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/table_alias.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/table_alias.yml index c94ede793..17f1c57eb 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/table_alias.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/table_alias.yml @@ -15,7 +15,8 @@ file: - table_reference: - naked_identifier: u - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - bracketed: - start_bracket: ( @@ -41,7 +42,8 @@ file: - table_reference: - naked_identifier: u - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - bracketed: - start_bracket: ( @@ -67,7 +69,8 @@ file: - table_reference: - naked_identifier: u - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - bracketed: - start_bracket: ( @@ -93,7 +96,8 @@ file: - table_reference: - naked_identifier: u - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - bracketed: - start_bracket: ( - identifier_list: diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/unpivot_clause.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/unpivot_clause.yml index 0df066381..b640df498 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/unpivot_clause.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/unpivot_clause.yml @@ -18,24 +18,25 @@ file: - keyword: UNPIVOT - bracketed: - start_bracket: ( - - naked_identifier: sales - - keyword: FOR - - naked_identifier: quarter - - keyword: IN - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: q1 - - comma: ',' - - column_reference: - - naked_identifier: q2 - - comma: ',' - - column_reference: - - naked_identifier: q3 - - comma: ',' - - column_reference: - - naked_identifier: q4 - - end_bracket: ) + - unpivot_single_column: + - naked_identifier: sales + - keyword: FOR + - naked_identifier: quarter + - keyword: IN + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: q1 + - comma: ',' + - column_reference: + - naked_identifier: q2 + - comma: ',' + - column_reference: + - naked_identifier: q3 + - comma: ',' + - column_reference: + - naked_identifier: q4 + - end_bracket: ) - end_bracket: ) - statement_terminator: ; - statement: @@ -61,39 +62,45 @@ file: - keyword: NULLS - bracketed: - start_bracket: ( - - naked_identifier: sales - - keyword: FOR - - naked_identifier: quarter - - keyword: IN - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: q1 - - alias_expression: - - keyword: AS - - naked_identifier: Q1 - - comma: ',' - - column_reference: - - naked_identifier: q2 - - alias_expression: - - keyword: AS - - naked_identifier: Q2 - - comma: ',' - - column_reference: - - naked_identifier: q3 - - alias_expression: - - keyword: AS - - naked_identifier: Q3 - - comma: ',' - - column_reference: - - naked_identifier: q4 - - alias_expression: - - keyword: AS - - naked_identifier: Q4 - - end_bracket: ) + - unpivot_single_column: + - naked_identifier: sales + - keyword: FOR + - naked_identifier: quarter + - keyword: IN + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: q1 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Q1 + - comma: ',' + - column_reference: + - naked_identifier: q2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Q2 + - comma: ',' + - column_reference: + - naked_identifier: q3 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Q3 + - comma: ',' + - column_reference: + - naked_identifier: q4 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Q4 + - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: up - statement_terminator: ; - statement: @@ -117,41 +124,44 @@ file: - keyword: NULLS - bracketed: - start_bracket: ( - - bracketed: - - start_bracket: ( - - naked_identifier: first_quarter - - comma: ',' - - naked_identifier: second_quarter - - end_bracket: ) - - keyword: FOR - - naked_identifier: half_of_the_year - - keyword: IN - - bracketed: - - start_bracket: ( + - unpivot_multi_column: - bracketed: - start_bracket: ( - - column_reference: - - naked_identifier: q1 + - naked_identifier: first_quarter - comma: ',' - - column_reference: - - naked_identifier: q2 + - naked_identifier: second_quarter - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: H1 - - comma: ',' + - keyword: FOR + - naked_identifier: half_of_the_year + - keyword: IN - bracketed: - start_bracket: ( - - column_reference: - - naked_identifier: q3 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: q1 + - comma: ',' + - column_reference: + - naked_identifier: q2 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: H1 - comma: ',' - - column_reference: - - naked_identifier: q4 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: q3 + - comma: ',' + - column_reference: + - naked_identifier: q4 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: H2 - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: H2 - - end_bracket: ) - end_bracket: ) - statement_terminator: ; - statement: @@ -175,38 +185,43 @@ file: - keyword: NULLS - bracketed: - start_bracket: ( - - naked_identifier: sales - - keyword: FOR - - naked_identifier: quarter - - keyword: IN - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: q1 - - alias_expression: - - keyword: AS - - quoted_identifier: '`Jan-Mar`' - - comma: ',' - - column_reference: - - naked_identifier: q2 - - alias_expression: - - keyword: AS - - quoted_identifier: '`Apr-Jun`' - - comma: ',' - - column_reference: - - naked_identifier: q3 - - alias_expression: - - keyword: AS - - quoted_identifier: '`Jul-Sep`' - - comma: ',' - - column_reference: - - naked_identifier: sales - - dot: . - - naked_identifier: q4 - - alias_expression: - - keyword: AS - - quoted_identifier: '`Oct-Dec`' - - end_bracket: ) + - unpivot_single_column: + - naked_identifier: sales + - keyword: FOR + - naked_identifier: quarter + - keyword: IN + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: q1 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`Jan-Mar`' + - comma: ',' + - column_reference: + - naked_identifier: q2 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`Apr-Jun`' + - comma: ',' + - column_reference: + - naked_identifier: q3 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`Jul-Sep`' + - comma: ',' + - column_reference: + - naked_identifier: sales + - dot: . + - naked_identifier: q4 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`Oct-Dec`' + - end_bracket: ) - end_bracket: ) - comma: ',' - from_expression: @@ -220,37 +235,42 @@ file: - keyword: NULLS - bracketed: - start_bracket: ( - - naked_identifier: sales - - keyword: FOR - - naked_identifier: quarter - - keyword: IN - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: q1 - - alias_expression: - - keyword: AS - - quoted_identifier: '`Jan-Mar`' - - comma: ',' - - column_reference: - - naked_identifier: q2 - - alias_expression: - - keyword: AS - - quoted_identifier: '`Apr-Jun`' - - comma: ',' - - column_reference: - - naked_identifier: q3 - - alias_expression: - - keyword: AS - - quoted_identifier: '`Jul-Sep`' - - comma: ',' - - column_reference: - - naked_identifier: sales - - dot: . - - naked_identifier: q4 - - alias_expression: - - keyword: AS - - quoted_identifier: '`Oct-Dec`' - - end_bracket: ) + - unpivot_single_column: + - naked_identifier: sales + - keyword: FOR + - naked_identifier: quarter + - keyword: IN + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: q1 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`Jan-Mar`' + - comma: ',' + - column_reference: + - naked_identifier: q2 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`Apr-Jun`' + - comma: ',' + - column_reference: + - naked_identifier: q3 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`Jul-Sep`' + - comma: ',' + - column_reference: + - naked_identifier: sales + - dot: . + - naked_identifier: q4 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`Oct-Dec`' + - end_bracket: ) - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/values_with_alias.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/values_with_alias.yml index 657752145..cf9beabbc 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/values_with_alias.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/values_with_alias.yml @@ -11,7 +11,8 @@ file: - numeric_literal: '2' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - statement_terminator: ; - statement: @@ -40,7 +41,8 @@ file: - numeric_literal: '2' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - bracketed: - start_bracket: ( @@ -71,7 +73,8 @@ file: - numeric_literal: '4' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: t - bracketed: - start_bracket: ( @@ -93,7 +96,8 @@ file: - numeric_literal: '2' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - bracketed: - start_bracket: ( - identifier_list: @@ -164,7 +168,8 @@ file: - numeric_literal: '4' - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - bracketed: - start_bracket: ( - identifier_list: diff --git a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/window_functions.yml b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/window_functions.yml index 6c332e412..678b42d2e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/window_functions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sparksql/sqlfluff/window_functions.yml @@ -37,7 +37,8 @@ file: - naked_identifier: salary - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: row_rank - from_clause: - keyword: FROM @@ -93,7 +94,8 @@ file: - keyword: ROW - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: row_dense_rank - from_clause: - keyword: FROM @@ -153,7 +155,8 @@ file: - keyword: ROW - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: data_cume_dist - from_clause: - keyword: FROM @@ -208,7 +211,8 @@ file: - naked_identifier: salary - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: salary_min - from_clause: - keyword: FROM @@ -259,7 +263,8 @@ file: - naked_identifier: salary - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: salary_lag - comma: ',' - select_clause_element: @@ -297,7 +302,8 @@ file: - naked_identifier: salary - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: salary_lead - from_clause: - keyword: FROM @@ -350,7 +356,8 @@ file: - naked_identifier: salary - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: salary_lag - comma: ',' - select_clause_element: @@ -390,7 +397,8 @@ file: - naked_identifier: salary - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: salary_lead - from_clause: - keyword: FROM @@ -443,7 +451,8 @@ file: - naked_identifier: salary - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: salary_lag - comma: ',' - select_clause_element: @@ -483,7 +492,8 @@ file: - naked_identifier: salary - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: salary_lead - from_clause: - keyword: FROM @@ -525,7 +535,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_lead - comma: ',' - select_clause_element: @@ -548,7 +559,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_lag - comma: ',' - select_clause_element: @@ -571,7 +583,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_nth_value - comma: ',' - select_clause_element: @@ -591,7 +604,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_first_value - comma: ',' - select_clause_element: @@ -611,7 +625,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_last_value - from_clause: - keyword: FROM @@ -620,20 +635,20 @@ file: - table_expression: - table_reference: - naked_identifier: test_ignore_null - - named_window: - - keyword: WINDOW - - named_window_expression: - - naked_identifier: w - - keyword: AS - - bracketed: - - start_bracket: ( - - window_specification: - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: id - - end_bracket: ) + - named_window: + - keyword: WINDOW + - named_window_expression: + - naked_identifier: w + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: id + - end_bracket: ) - orderby_clause: - keyword: ORDER - keyword: BY @@ -672,7 +687,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_lead - comma: ',' - select_clause_element: @@ -695,7 +711,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_lag - comma: ',' - select_clause_element: @@ -718,7 +735,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_nth_value - comma: ',' - select_clause_element: @@ -738,7 +756,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_first_value - comma: ',' - select_clause_element: @@ -758,7 +777,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_last_value - from_clause: - keyword: FROM @@ -767,20 +787,20 @@ file: - table_expression: - table_reference: - naked_identifier: test_ignore_null - - named_window: - - keyword: WINDOW - - named_window_expression: - - naked_identifier: w - - keyword: AS - - bracketed: - - start_bracket: ( - - window_specification: - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: id - - end_bracket: ) + - named_window: + - keyword: WINDOW + - named_window_expression: + - naked_identifier: w + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: id + - end_bracket: ) - orderby_clause: - keyword: ORDER - keyword: BY @@ -825,7 +845,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_lead - comma: ',' - select_clause_element: @@ -850,7 +871,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_lag - comma: ',' - select_clause_element: @@ -875,7 +897,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_nth_value - comma: ',' - select_clause_element: @@ -897,7 +920,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_first_value - comma: ',' - select_clause_element: @@ -919,7 +943,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_last_value - from_clause: - keyword: FROM @@ -929,24 +954,25 @@ file: - table_reference: - naked_identifier: test_ignore_null - alias_expression: - - keyword: AS - - naked_identifier: ignore_nulls - - named_window: - - keyword: WINDOW - - named_window_expression: - - naked_identifier: w + - alias_operator: - keyword: AS - - bracketed: - - start_bracket: ( - - window_specification: - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: ignore_nulls - - dot: . - - naked_identifier: id - - end_bracket: ) + - naked_identifier: ignore_nulls + - named_window: + - keyword: WINDOW + - named_window_expression: + - naked_identifier: w + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: ignore_nulls + - dot: . + - naked_identifier: id + - end_bracket: ) - orderby_clause: - keyword: ORDER - keyword: BY @@ -993,7 +1019,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_lead - comma: ',' - select_clause_element: @@ -1018,7 +1045,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_lag - comma: ',' - select_clause_element: @@ -1043,7 +1071,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_nth_value - comma: ',' - select_clause_element: @@ -1065,7 +1094,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_first_value - comma: ',' - select_clause_element: @@ -1087,7 +1117,8 @@ file: - keyword: OVER - naked_identifier: w - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: v_last_value - from_clause: - keyword: FROM @@ -1097,36 +1128,37 @@ file: - table_reference: - naked_identifier: test_ignore_null - alias_expression: - - keyword: AS - - naked_identifier: ignore_nulls - - named_window: - - keyword: WINDOW - - named_window_expression: - - naked_identifier: w + - alias_operator: - keyword: AS - - bracketed: - - start_bracket: ( - - window_specification: - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: ignore_nulls - - dot: . - - naked_identifier: id - - frame_clause: - - keyword: range - - keyword: between - - interval_expression: - - keyword: interval - - interval_literal: - - numeric_literal: '6' - - date_part: days - - keyword: preceding - - keyword: and - - keyword: current - - keyword: row - - end_bracket: ) + - naked_identifier: ignore_nulls + - named_window: + - keyword: WINDOW + - named_window_expression: + - naked_identifier: w + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: ignore_nulls + - dot: . + - naked_identifier: id + - frame_clause: + - keyword: range + - keyword: between + - interval_expression: + - keyword: interval + - interval_literal: + - numeric_literal: '6' + - date_part: days + - keyword: preceding + - keyword: and + - keyword: current + - keyword: row + - end_bracket: ) - orderby_clause: - keyword: ORDER - keyword: BY diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/alter.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/alter.sql deleted file mode 100644 index 31c6a17df..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/alter.sql +++ /dev/null @@ -1,13 +0,0 @@ -ALTER TABLE table1 RENAME TO "table2"; - -ALTER TABLE table1 RENAME COLUMN "a" TO b; - -ALTER TABLE table1 DROP a; - -ALTER TABLE table1 DROP COLUMN "a"; - -ALTER TABLE table1 ADD COLUMN a INTEGER NOT NULL; - -ALTER TABLE table1 ADD COLUMN "a" INTEGER NOT NULL; - -ALTER TABLE "table1" ADD COLUMN a INTEGER NOT NULL; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/alter_table.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/alter_table.sql new file mode 100644 index 000000000..a5d89afe0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/alter_table.sql @@ -0,0 +1,15 @@ +ALTER TABLE users RENAME TO people; + +ALTER TABLE users RENAME COLUMN user_id TO person_id; + +ALTER TABLE users ADD COLUMN name TEXT UNIQUE; + +ALTER TABLE users +ADD COLUMN credentials_last_changed +INTEGER NOT NULL DEFAULT 0; + +ALTER TABLE users +ADD COLUMN credentials_last_changed +TEXT NOT NULL DEFAULT '0001-01-01T00:00:00.000000+00:00'; + +ALTER TABLE users DROP COLUMN age; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/alter.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/alter_table.yml similarity index 64% rename from crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/alter.yml rename to crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/alter_table.yml index 1c7e907fb..69a21da43 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/alter.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/alter_table.yml @@ -4,91 +4,87 @@ file: - keyword: ALTER - keyword: TABLE - table_reference: - - naked_identifier: table1 + - naked_identifier: users - keyword: RENAME - keyword: TO - - parameter: '"table2"' + - naked_identifier: people - statement_terminator: ; - statement: - alter_table_statement: - keyword: ALTER - keyword: TABLE - table_reference: - - naked_identifier: table1 + - naked_identifier: users - keyword: RENAME - keyword: COLUMN - column_reference: - - quoted_identifier: '"a"' + - naked_identifier: user_id - keyword: TO - - column_reference: - - naked_identifier: b -- statement_terminator: ; -- statement: - - alter_table_statement: - - keyword: ALTER - - keyword: TABLE - - table_reference: - - naked_identifier: table1 - - keyword: DROP - - column_reference: - - naked_identifier: a + - naked_identifier: person_id - statement_terminator: ; - statement: - alter_table_statement: - keyword: ALTER - keyword: TABLE - table_reference: - - naked_identifier: table1 - - keyword: DROP + - naked_identifier: users + - keyword: ADD - keyword: COLUMN - - column_reference: - - quoted_identifier: '"a"' + - column_definition: + - naked_identifier: name + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: UNIQUE - statement_terminator: ; - statement: - alter_table_statement: - keyword: ALTER - keyword: TABLE - table_reference: - - naked_identifier: table1 + - naked_identifier: users - keyword: ADD - keyword: COLUMN - column_definition: - - naked_identifier: a + - naked_identifier: credentials_last_changed - data_type: - data_type_identifier: INTEGER - column_constraint_segment: - keyword: NOT - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - expression: + - numeric_literal: '0' - statement_terminator: ; - statement: - alter_table_statement: - keyword: ALTER - keyword: TABLE - table_reference: - - naked_identifier: table1 + - naked_identifier: users - keyword: ADD - keyword: COLUMN - column_definition: - - quoted_identifier: '"a"' + - naked_identifier: credentials_last_changed - data_type: - - data_type_identifier: INTEGER + - data_type_identifier: TEXT - column_constraint_segment: - keyword: NOT - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - expression: + - quoted_literal: '''0001-01-01T00:00:00.000000+00:00''' - statement_terminator: ; - statement: - alter_table_statement: - keyword: ALTER - keyword: TABLE - table_reference: - - quoted_identifier: '"table1"' - - keyword: ADD + - naked_identifier: users + - keyword: DROP - keyword: COLUMN - - column_definition: - - naked_identifier: a - - data_type: - - data_type_identifier: INTEGER - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' + - column_reference: + - naked_identifier: age - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/arithmetric_a.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/arithmetric_a.yml index 6163d1aba..35fcfd264 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/arithmetric_a.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/arithmetric_a.yml @@ -23,7 +23,8 @@ file: - binary_operator: + - numeric_literal: '13' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: val - statement_terminator: ; - statement: @@ -53,7 +54,8 @@ file: - binary_operator: + - numeric_literal: '13' - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: val - statement_terminator: ; - statement: @@ -106,11 +108,11 @@ file: - select_clause_element: - expression: - numeric_literal: '4' - - comparison_operator: + - binary_operator: - ampersand: '&' - tilde: '~' - numeric_literal: '8' - - comparison_operator: + - binary_operator: - pipe: '|' - numeric_literal: '16' - statement_terminator: ; @@ -136,7 +138,7 @@ file: - select_clause_element: - expression: - numeric_literal: '8' - - comparison_operator: + - binary_operator: - pipe: '|' - tilde: '~' - tilde: '~' diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/block_comment_end_of_input.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/block_comment_end_of_input.sql new file mode 100644 index 000000000..604047607 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/block_comment_end_of_input.sql @@ -0,0 +1,4 @@ +/* + According to https://www.sqlite.org/lang_comment.html, it is valid for a C-style comment to end + at the "end-of-input", without being closed explicitly. This document is a valid SQLite file, + but gives a parsing error in SQLFluff. diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/block_comment_end_of_input.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/block_comment_end_of_input.yml new file mode 100644 index 000000000..8be5edd31 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/block_comment_end_of_input.yml @@ -0,0 +1 @@ +file: [] diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/conflict_clause.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/conflict_clause.sql new file mode 100644 index 000000000..c913afa98 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/conflict_clause.sql @@ -0,0 +1,12 @@ +CREATE TABLE users ( + user_id INTEGER PRIMARY KEY ON CONFLICT ROLLBACK, + user_name TEXT NOT NULL ON CONFLICT ABORT +); + +ALTER TABLE users ADD COLUMN name TEXT UNIQUE ON CONFLICT FAIL; + +create table imap_boxes ( + account_id integer not null, + box_name text not null, + unique (account_id, box_name) on conflict replace +); diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/conflict_clause.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/conflict_clause.yml new file mode 100644 index 000000000..e351e0f7e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/conflict_clause.yml @@ -0,0 +1,93 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: users + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: user_id + - data_type: + - data_type_identifier: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - conflict_clause: + - keyword: ON + - keyword: CONFLICT + - keyword: ROLLBACK + - comma: ',' + - column_definition: + - naked_identifier: user_name + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - conflict_clause: + - keyword: ON + - keyword: CONFLICT + - keyword: ABORT + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: users + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: name + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: UNIQUE + - conflict_clause: + - keyword: ON + - keyword: CONFLICT + - keyword: FAIL +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: create + - keyword: table + - table_reference: + - naked_identifier: imap_boxes + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: account_id + - data_type: + - data_type_identifier: integer + - column_constraint_segment: + - keyword: not + - keyword: 'null' + - comma: ',' + - column_definition: + - naked_identifier: box_name + - data_type: + - data_type_identifier: text + - column_constraint_segment: + - keyword: not + - keyword: 'null' + - comma: ',' + - table_constraint: + - keyword: unique + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: account_id + - comma: ',' + - column_reference: + - naked_identifier: box_name + - end_bracket: ) + - conflict_clause: + - keyword: on + - keyword: conflict + - keyword: replace + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_index.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_index.yml index 957b7503c..1c6df083d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_index.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_index.yml @@ -3,7 +3,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: li1 - keyword: ON - table_reference: @@ -31,7 +31,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: acctchng_magnitude - keyword: ON - table_reference: @@ -59,7 +59,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: t2xy - keyword: ON - table_reference: @@ -80,7 +80,7 @@ file: - keyword: CREATE - keyword: UNIQUE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: team_leader - keyword: ON - table_reference: @@ -100,7 +100,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: ex1 - keyword: ON - table_reference: @@ -132,7 +132,7 @@ file: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: po_parent - keyword: ON - table_reference: @@ -149,13 +149,13 @@ file: - naked_identifier: parent_po - keyword: IS - keyword: NOT - - keyword: 'NULL' + - null_literal: 'NULL' - statement_terminator: ; - statement: - create_index_statement: - keyword: CREATE - keyword: INDEX - - database_reference: + - index_reference: - naked_identifier: ex2 - keyword: ON - table_reference: @@ -175,5 +175,5 @@ file: - naked_identifier: c - keyword: IS - keyword: NOT - - keyword: 'NULL' + - null_literal: 'NULL' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table.sql index ad6ff1258..1024ac7b5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table.sql +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table.sql @@ -4,3 +4,16 @@ CREATE TABLE users ( password TEXT NOT NULL COLLATE NOCASE, email TEXT NOT NULL UNIQUE ); + +CREATE TABLE users ( + user_id INTEGER PRIMARY KEY ASC AUTOINCREMENT +); + +CREATE TABLE users ( + user_id INTEGER PRIMARY KEY DESC AUTOINCREMENT +); + +CREATE TABLE example ( + id INTEGER PRIMARY KEY, + description CHARACTER VARYING(32) NOT NULL +); diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table.yml index 58495773f..a43d4e922 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table.yml @@ -49,3 +49,72 @@ file: - keyword: UNIQUE - end_bracket: ) - statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: users + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: user_id + - data_type: + - data_type_identifier: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - keyword: ASC + - keyword: AUTOINCREMENT + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: users + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: user_id + - data_type: + - data_type_identifier: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - keyword: DESC + - keyword: AUTOINCREMENT + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: example + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_definition: + - naked_identifier: description + - data_type: + - keyword: CHARACTER + - keyword: VARYING + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '32' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_constraint_generated.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_constraint_generated.sql new file mode 100644 index 000000000..fceda63b7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_constraint_generated.sql @@ -0,0 +1,15 @@ +CREATE TABLE t1 ( + a INTEGER PRIMARY KEY, + b INT, + c TEXT, + d INT GENERATED ALWAYS AS (a*abs(b)) VIRTUAL, + e TEXT GENERATED ALWAYS AS (substr(c,b,b+1)) STORED +); + +CREATE TABLE t1 ( + a INTEGER PRIMARY KEY, + b INT, + c TEXT, + d INT AS (a*abs(b)), + e TEXT AS (substr(c,b,b+1)) STORED +); diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_constraint_generated.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_constraint_generated.yml new file mode 100644 index 000000000..41a1576bd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_constraint_generated.yml @@ -0,0 +1,172 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: a + - data_type: + - data_type_identifier: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_definition: + - naked_identifier: b + - data_type: + - data_type_identifier: INT + - comma: ',' + - column_definition: + - naked_identifier: c + - data_type: + - data_type_identifier: TEXT + - comma: ',' + - column_definition: + - naked_identifier: d + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: a + - binary_operator: '*' + - function: + - function_name: + - function_name_identifier: abs + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - end_bracket: ) + - end_bracket: ) + - keyword: VIRTUAL + - comma: ',' + - column_definition: + - naked_identifier: e + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: substr + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c + - comma: ',' + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - column_reference: + - naked_identifier: b + - binary_operator: + + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - keyword: STORED + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: a + - data_type: + - data_type_identifier: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_definition: + - naked_identifier: b + - data_type: + - data_type_identifier: INT + - comma: ',' + - column_definition: + - naked_identifier: c + - data_type: + - data_type_identifier: TEXT + - comma: ',' + - column_definition: + - naked_identifier: d + - data_type: + - data_type_identifier: INT + - column_constraint_segment: + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: a + - binary_operator: '*' + - function: + - function_name: + - function_name_identifier: abs + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: e + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: substr + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c + - comma: ',' + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - column_reference: + - naked_identifier: b + - binary_operator: + + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - keyword: STORED + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_deferrable.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_deferrable.sql index cec0533f6..81775fa5d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_deferrable.sql +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_deferrable.sql @@ -38,36 +38,36 @@ CREATE TABLE messages( -- check deferrable in column constrain segment CREATE TABLE track( trackid INTEGER, - trackname TEXT, + trackname TEXT, trackartist INTEGER REFERENCES artist(artistid) DEFERRABLE ); CREATE TABLE track( trackid INTEGER, - trackname TEXT, + trackname TEXT, trackartist INTEGER REFERENCES artist(artistid) DEFERRABLE INITIALLY DEFERRED ); CREATE TABLE track( trackid INTEGER, - trackname TEXT, + trackname TEXT, trackartist INTEGER REFERENCES artist(artistid) DEFERRABLE INITIALLY IMMEDIATE ); CREATE TABLE track( trackid INTEGER, - trackname TEXT, + trackname TEXT, trackartist INTEGER REFERENCES artist(artistid) NOT DEFERRABLE ); CREATE TABLE track( trackid INTEGER, - trackname TEXT, + trackname TEXT, trackartist INTEGER REFERENCES artist(artistid) NOT DEFERRABLE INITIALLY DEFERRED ); CREATE TABLE track( trackid INTEGER, - trackname TEXT, + trackname TEXT, trackartist INTEGER REFERENCES artist(artistid) NOT DEFERRABLE INITIALLY IMMEDIATE ); diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_table_end.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_table_end.sql index 3007eeeee..6988ac17e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_table_end.sql +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_table_end.sql @@ -17,4 +17,3 @@ CREATE TABLE IF NOT EXISTS wordcount( word TEXT PRIMARY KEY, cnt INTEGER ) WITHOUT ROWID, STRICT; - diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_unsigned.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_unsigned.sql new file mode 100644 index 000000000..f0f47d6a8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_unsigned.sql @@ -0,0 +1,5 @@ +CREATE TABLE "wellplated_format" ( + "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, + "bottom_row" varchar(1) NOT NULL, + "right_column" smallint unsigned NOT NULL CHECK ("right_column" >= 0) +); diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_unsigned.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_unsigned.yml new file mode 100644 index 000000000..51163fbcc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_table_unsigned.yml @@ -0,0 +1,56 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '"wellplated_format"' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '"id"' + - data_type: + - data_type_identifier: integer + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - keyword: AUTOINCREMENT + - comma: ',' + - column_definition: + - quoted_identifier: '"bottom_row"' + - data_type: + - data_type_identifier: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - quoted_identifier: '"right_column"' + - data_type: + - data_type_identifier: smallint + - keyword: unsigned + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '"right_column"' + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - numeric_literal: '0' + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_trigger.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_trigger.sql index 90eb0a8c9..7cf45d08e 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_trigger.sql +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_trigger.sql @@ -47,4 +47,15 @@ INSERT INTO emp_log(emp_id,salary,edittime) VALUES(NEW.employee_id,NEW.salary,current_date); END; +CREATE TRIGGER x +AFTER INSERT ON y +WHEN new.z IS NULL -- putting this expression in parens allows parsing +BEGIN +UPDATE y SET z = TRUE WHERE rowid = new.rowid; +END; +CREATE TRIGGER trigger_name +AFTER UPDATE ON table_name +BEGIN + INSERT INTO table_name_history (action) VALUES ('UPDATE'); +END; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_trigger.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_trigger.yml index 76a295e4c..098449d43 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_trigger.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_trigger.yml @@ -20,14 +20,14 @@ file: - set_clause_list: - keyword: SET - set_clause: - - column_reference: - - naked_identifier: address + - naked_identifier: address - comparison_operator: - raw_comparison_operator: = - - column_reference: - - naked_identifier: new - - dot: . - - naked_identifier: address + - expression: + - column_reference: + - naked_identifier: new + - dot: . + - naked_identifier: address - where_clause: - keyword: WHERE - expression: @@ -65,14 +65,14 @@ file: - set_clause_list: - keyword: SET - set_clause: - - column_reference: - - naked_identifier: cust_addr + - naked_identifier: cust_addr - comparison_operator: - raw_comparison_operator: = - - column_reference: - - naked_identifier: NEW - - dot: . - - naked_identifier: cust_addr + - expression: + - column_reference: + - naked_identifier: NEW + - dot: . + - naked_identifier: cust_addr - where_clause: - keyword: WHERE - expression: @@ -246,3 +246,81 @@ file: - statement_terminator: ; - keyword: END - statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: x + - keyword: AFTER + - keyword: INSERT + - keyword: ON + - table_reference: + - naked_identifier: y + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: new + - dot: . + - naked_identifier: z + - keyword: IS + - null_literal: 'NULL' + - keyword: BEGIN + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: y + - set_clause_list: + - keyword: SET + - set_clause: + - naked_identifier: z + - comparison_operator: + - raw_comparison_operator: = + - expression: + - boolean_literal: 'TRUE' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: rowid + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: new + - dot: . + - naked_identifier: rowid + - statement_terminator: ; + - keyword: END +- statement_terminator: ; +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: trigger_name + - keyword: AFTER + - keyword: UPDATE + - keyword: ON + - table_reference: + - naked_identifier: table_name + - keyword: BEGIN + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: table_name_history + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: action + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''UPDATE''' + - end_bracket: ) + - statement_terminator: ; + - keyword: END +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_view.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_view.sql new file mode 100644 index 000000000..0ae642df6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_view.sql @@ -0,0 +1,11 @@ +CREATE TEMPORARY VIEW IF NOT EXISTS temp_table AS +SELECT * FROM tab +WHERE col = 'value'; + + +CREATE VIEW Test.Data (id, name, age) +AS +SELECT id, name, age +FROM temp_table +WHERE age > 18 +AND name = 'John'; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_view.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_view.yml new file mode 100644 index 000000000..9c79727a1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_view.yml @@ -0,0 +1,91 @@ +file: +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: TEMPORARY + - keyword: VIEW + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: temp_table + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value''' +- statement_terminator: ; +- statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - table_reference: + - naked_identifier: Test + - dot: . + - naked_identifier: Data + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - comma: ',' + - column_reference: + - naked_identifier: name + - comma: ',' + - column_reference: + - naked_identifier: age + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: age + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: temp_table + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: age + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '18' + - binary_operator: AND + - column_reference: + - naked_identifier: name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''John''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_virtual_table_check.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_virtual_table_check.sql new file mode 100644 index 000000000..392eb236f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_virtual_table_check.sql @@ -0,0 +1,21 @@ +CREATE VIRTUAL TABLE email USING fts5; + +CREATE VIRTUAL TABLE email USING fts5(sender, title, body); + +CREATE VIRTUAL TABLE IF NOT EXISTS email USING fts5(name, phone, email); + +CREATE VIRTUAL TABLE sample_schema.email USING fts3(content, date); + +CREATE VIRTUAL TABLE email USING fts5( + 'email text', + user_id, + 100, + "complex-field@!#" +); + +CREATE VIRTUAL TABLE IF NOT EXISTS sample_schema.email USING fts5( + 'email text', + user_id, + 0, + "complex-field@!#" +); diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_virtual_table_check.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_virtual_table_check.yml new file mode 100644 index 000000000..ce6ae4c24 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/create_virtual_table_check.yml @@ -0,0 +1,113 @@ +file: +- statement: + - create_virtual_table_statement: + - keyword: CREATE + - keyword: VIRTUAL + - keyword: TABLE + - table_reference: + - naked_identifier: email + - keyword: USING + - naked_identifier: fts5 +- statement_terminator: ; +- statement: + - create_virtual_table_statement: + - keyword: CREATE + - keyword: VIRTUAL + - keyword: TABLE + - table_reference: + - naked_identifier: email + - keyword: USING + - naked_identifier: fts5 + - bracketed: + - start_bracket: ( + - naked_identifier: sender + - comma: ',' + - naked_identifier: title + - comma: ',' + - naked_identifier: body + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_virtual_table_statement: + - keyword: CREATE + - keyword: VIRTUAL + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: email + - keyword: USING + - naked_identifier: fts5 + - bracketed: + - start_bracket: ( + - naked_identifier: name + - comma: ',' + - naked_identifier: phone + - comma: ',' + - naked_identifier: email + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_virtual_table_statement: + - keyword: CREATE + - keyword: VIRTUAL + - keyword: TABLE + - table_reference: + - naked_identifier: sample_schema + - dot: . + - naked_identifier: email + - keyword: USING + - naked_identifier: fts3 + - bracketed: + - start_bracket: ( + - naked_identifier: content + - comma: ',' + - naked_identifier: date + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_virtual_table_statement: + - keyword: CREATE + - keyword: VIRTUAL + - keyword: TABLE + - table_reference: + - naked_identifier: email + - keyword: USING + - naked_identifier: fts5 + - bracketed: + - start_bracket: ( + - quoted_literal: '''email text''' + - comma: ',' + - naked_identifier: user_id + - comma: ',' + - numeric_literal: '100' + - comma: ',' + - quoted_identifier: '"complex-field@!#"' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_virtual_table_statement: + - keyword: CREATE + - keyword: VIRTUAL + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: sample_schema + - dot: . + - naked_identifier: email + - keyword: USING + - naked_identifier: fts5 + - bracketed: + - start_bracket: ( + - quoted_literal: '''email text''' + - comma: ',' + - naked_identifier: user_id + - comma: ',' + - numeric_literal: '0' + - comma: ',' + - quoted_identifier: '"complex-field@!#"' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/delete.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/delete.sql index 072047316..0b278b4e5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/delete.sql +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/delete.sql @@ -3,12 +3,15 @@ WHERE a > 0; DELETE FROM table_name WHERE a > 0 -RETURNING *; +RETURNING * +; DELETE FROM table_name WHERE a > 0 -RETURNING a; +RETURNING *, id +; DELETE FROM table_name WHERE a > 0 -RETURNING a, b AS bee; +RETURNING id foo, id_2 AS bar +; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/delete.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/delete.yml index 2451ade86..a363cdd87 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/delete.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/delete.yml @@ -36,8 +36,11 @@ file: - comparison_operator: - raw_comparison_operator: '>' - numeric_literal: '0' - - keyword: RETURNING - - star: '*' + - returning_clause: + - keyword: RETURNING + - wildcard_expression: + - wildcard_identifier: + - star: '*' - statement_terminator: ; - statement: - delete_statement: @@ -57,10 +60,15 @@ file: - comparison_operator: - raw_comparison_operator: '>' - numeric_literal: '0' - - keyword: RETURNING - - expression: - - column_reference: - - naked_identifier: a + - returning_clause: + - keyword: RETURNING + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: id - statement_terminator: ; - statement: - delete_statement: @@ -80,15 +88,19 @@ file: - comparison_operator: - raw_comparison_operator: '>' - numeric_literal: '0' - - keyword: RETURNING - - expression: - - column_reference: - - naked_identifier: a - - comma: ',' - - expression: - - column_reference: - - naked_identifier: b - - alias_expression: - - keyword: AS - - naked_identifier: bee + - returning_clause: + - keyword: RETURNING + - expression: + - column_reference: + - naked_identifier: id + - alias_expression: + - naked_identifier: foo + - comma: ',' + - expression: + - column_reference: + - naked_identifier: id_2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: bar - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/insert.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/insert.sql index 387297300..621e3c3fe 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/insert.sql +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/insert.sql @@ -24,17 +24,12 @@ INSERT INTO t1 DEFAULT VALUES; INSERT INTO t1 (a, b, c) DEFAULT VALUES; -INSERT INTO t1 (a, b, c) VALUES (1, 2, 3), (4, 5, 6) -RETURNING *; +INSERT INTO t1 (a, b, c) DEFAULT VALUES RETURNING *; -INSERT INTO t1 (a, b, c) VALUES (1, 2, 3), (4, 5, 6) -RETURNING a; +INSERT INTO t1 (a, b, c) DEFAULT VALUES RETURNING a foo; -INSERT INTO t1 (a, b, c) VALUES (1, 2, 3), (4, 5, 6) -RETURNING a AS b; +INSERT INTO t1 (a, b, c) DEFAULT VALUES RETURNING a AS foo, *; -INSERT INTO t1 (a, b, c) VALUES (1, 2, 3), (4, 5, 6) -RETURNING a, b; +INSERT INTO t1 (a, b, c) DEFAULT VALUES RETURNING a AS foo; -INSERT INTO t1 (a, b, c) VALUES (1, 2, 3), (4, 5, 6) -RETURNING a AS aa, b AS bb; +INSERT INTO users (name, email) VALUES (1, 2) RETURNING *; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/insert.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/insert.yml index 71a5547c2..f6cd013c0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/insert.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/insert.yml @@ -377,7 +377,8 @@ file: - column_reference: - naked_identifier: d - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: e - from_clause: - keyword: FROM @@ -388,7 +389,8 @@ file: - naked_identifier: t2 - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: dt - statement_terminator: ; - statement: @@ -437,33 +439,13 @@ file: - column_reference: - naked_identifier: c - end_bracket: ) - - values_clause: - - keyword: VALUES - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '1' - - comma: ',' - - expression: - - numeric_literal: '2' - - comma: ',' - - expression: - - numeric_literal: '3' - - end_bracket: ) - - comma: ',' - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '4' - - comma: ',' - - expression: - - numeric_literal: '5' - - comma: ',' - - expression: - - numeric_literal: '6' - - end_bracket: ) - - keyword: RETURNING - - star: '*' + - keyword: DEFAULT + - keyword: VALUES + - returning_clause: + - keyword: RETURNING + - wildcard_expression: + - wildcard_identifier: + - star: '*' - statement_terminator: ; - statement: - insert_statement: @@ -482,35 +464,15 @@ file: - column_reference: - naked_identifier: c - end_bracket: ) - - values_clause: - - keyword: VALUES - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '1' - - comma: ',' - - expression: - - numeric_literal: '2' - - comma: ',' - - expression: - - numeric_literal: '3' - - end_bracket: ) - - comma: ',' - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '4' - - comma: ',' - - expression: - - numeric_literal: '5' - - comma: ',' - - expression: - - numeric_literal: '6' - - end_bracket: ) - - keyword: RETURNING - - expression: - - column_reference: - - naked_identifier: a + - keyword: DEFAULT + - keyword: VALUES + - returning_clause: + - keyword: RETURNING + - expression: + - column_reference: + - naked_identifier: a + - alias_expression: + - naked_identifier: foo - statement_terminator: ; - statement: - insert_statement: @@ -529,38 +491,21 @@ file: - column_reference: - naked_identifier: c - end_bracket: ) - - values_clause: - - keyword: VALUES - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '1' - - comma: ',' - - expression: - - numeric_literal: '2' - - comma: ',' - - expression: - - numeric_literal: '3' - - end_bracket: ) - - comma: ',' - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '4' - - comma: ',' - - expression: - - numeric_literal: '5' - - comma: ',' - - expression: - - numeric_literal: '6' - - end_bracket: ) - - keyword: RETURNING - - expression: - - column_reference: - - naked_identifier: a - - alias_expression: - - keyword: AS - - naked_identifier: b + - keyword: DEFAULT + - keyword: VALUES + - returning_clause: + - keyword: RETURNING + - expression: + - column_reference: + - naked_identifier: a + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: foo + - comma: ',' + - wildcard_expression: + - wildcard_identifier: + - star: '*' - statement_terminator: ; - statement: - insert_statement: @@ -579,56 +524,31 @@ file: - column_reference: - naked_identifier: c - end_bracket: ) - - values_clause: - - keyword: VALUES - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '1' - - comma: ',' - - expression: - - numeric_literal: '2' - - comma: ',' - - expression: - - numeric_literal: '3' - - end_bracket: ) - - comma: ',' - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '4' - - comma: ',' - - expression: - - numeric_literal: '5' - - comma: ',' - - expression: - - numeric_literal: '6' - - end_bracket: ) - - keyword: RETURNING - - expression: - - column_reference: - - naked_identifier: a - - comma: ',' - - expression: - - column_reference: - - naked_identifier: b + - keyword: DEFAULT + - keyword: VALUES + - returning_clause: + - keyword: RETURNING + - expression: + - column_reference: + - naked_identifier: a + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: foo - statement_terminator: ; - statement: - insert_statement: - keyword: INSERT - keyword: INTO - table_reference: - - naked_identifier: t1 + - naked_identifier: users - bracketed: - start_bracket: ( - column_reference: - - naked_identifier: a + - naked_identifier: name - comma: ',' - column_reference: - - naked_identifier: b - - comma: ',' - - column_reference: - - naked_identifier: c + - naked_identifier: email - end_bracket: ) - values_clause: - keyword: VALUES @@ -639,34 +559,10 @@ file: - comma: ',' - expression: - numeric_literal: '2' - - comma: ',' - - expression: - - numeric_literal: '3' - end_bracket: ) - - comma: ',' - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '4' - - comma: ',' - - expression: - - numeric_literal: '5' - - comma: ',' - - expression: - - numeric_literal: '6' - - end_bracket: ) - - keyword: RETURNING - - expression: - - column_reference: - - naked_identifier: a - - alias_expression: - - keyword: AS - - naked_identifier: aa - - comma: ',' - - expression: - - column_reference: - - naked_identifier: b - - alias_expression: - - keyword: AS - - naked_identifier: bb + - returning_clause: + - keyword: RETURNING + - wildcard_expression: + - wildcard_identifier: + - star: '*' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/is_clause.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/is_clause.sql new file mode 100644 index 000000000..4f58f8392 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/is_clause.sql @@ -0,0 +1,19 @@ +CREATE TABLE Repro ( + col TEXT NOT NULL CHECK (col IS DATE(col)) +); + +CREATE TABLE Repro ( + col TEXT NOT NULL CHECK (col IS NOT DATE(col)) +); + +SELECT * +FROM Tab +WHERE col1 IS NOT DATE(col2); + +SELECT * +FROM Tab +WHERE col1 IS col2; + +SELECT * +FROM Tab +WHERE col1 IS NOT col2; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/is_clause.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/is_clause.yml new file mode 100644 index 000000000..6ed09ae81 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/is_clause.yml @@ -0,0 +1,156 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: Repro + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col + - keyword: IS + - function: + - function_name: + - function_name_identifier: DATE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: Repro + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col + - keyword: IS + - keyword: NOT + - function: + - function_name: + - function_name_identifier: DATE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Tab + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col1 + - keyword: IS + - keyword: NOT + - function: + - function_name: + - function_name_identifier: DATE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: col2 + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Tab + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col1 + - keyword: IS + - column_reference: + - naked_identifier: col2 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Tab + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col1 + - keyword: IS + - keyword: NOT + - column_reference: + - naked_identifier: col2 +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_keys.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_keys.sql new file mode 100644 index 000000000..6b516fa77 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_keys.sql @@ -0,0 +1 @@ +SELECT j.key, j.value, j.type, j.atom, j.id, j.parent, j.fullkey, j.path FROM json_tree('{}') AS j; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_keys.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_keys.yml new file mode 100644 index 000000000..1679fb4c0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_keys.yml @@ -0,0 +1,71 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: j + - dot: . + - naked_identifier: key + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: j + - dot: . + - naked_identifier: value + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: j + - dot: . + - naked_identifier: type + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: j + - dot: . + - naked_identifier: atom + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: j + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: j + - dot: . + - naked_identifier: parent + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: j + - dot: . + - naked_identifier: fullkey + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: j + - dot: . + - naked_identifier: path + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: json_tree + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''{}''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: j +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_operators.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_operators.sql new file mode 100644 index 000000000..335fb5726 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_operators.sql @@ -0,0 +1,20 @@ +SELECT value FROM '[11,22,33,44]' -> 3 WHERE '{"x": "y"}' ->> '$.x' = 'y'; + + +SELECT value FROM '{"a":2,"c":[4,5,{"f":7}]}' -> 'c' WHERE Upper('{"x": "y"}') ->> '$.x' = 'y'; +SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> '$'; +SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> "$"; +SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> '$.c'; +SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> 'c'; +SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> '$.c[2]'; +SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> '$.c[2].f'; +SELECT '{"a":2,"c":[4,5,{"f":7}]}' ->> '$.c[2].f'; +SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> 'c' -> 2 ->> 'f'; +SELECT '{"a":2,"c":[4,5],"f":7}' -> '$.c[#-1]'; +SELECT '{"a":2,"c":[4,5,{"f":7}]}' -> '$.x'; +SELECT '[11,22,33,44]' -> 3; +SELECT '[11,22,33,44]' ->> 3; +SELECT '{"a":"xyz"}' -> '$.a'; +SELECT '{"a":"xyz"}' ->> '$.a'; +SELECT '{"a":null}' -> '$.a'; +SELECT '{"a":null}' ->> '$.a'; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_operators.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_operators.yml new file mode 100644 index 000000000..b5abbf623 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/json_operators.yml @@ -0,0 +1,226 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: value + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '''[11,22,33,44]''' + - column_path_operator: -> + - numeric_literal: '3' + - where_clause: + - keyword: WHERE + - expression: + - quoted_literal: '''{"x": "y"}''' + - column_path_operator: ->> + - quoted_literal: '''$.x''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''y''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: value + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '''{"a":2,"c":[4,5,{"f":7}]}''' + - column_path_operator: -> + - quoted_literal: '''c''' + - where_clause: + - keyword: WHERE + - expression: + - function: + - function_name: + - function_name_identifier: Upper + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''{"x": "y"}''' + - end_bracket: ) + - column_path_operator: ->> + - quoted_literal: '''$.x''' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''y''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a":2,"c":[4,5,{"f":7}]}''' + - column_path_operator: -> + - quoted_literal: '''$''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a":2,"c":[4,5,{"f":7}]}''' + - column_path_operator: -> + - column_reference: + - quoted_identifier: '"$"' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a":2,"c":[4,5,{"f":7}]}''' + - column_path_operator: -> + - quoted_literal: '''$.c''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a":2,"c":[4,5,{"f":7}]}''' + - column_path_operator: -> + - quoted_literal: '''c''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a":2,"c":[4,5,{"f":7}]}''' + - column_path_operator: -> + - quoted_literal: '''$.c[2]''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a":2,"c":[4,5,{"f":7}]}''' + - column_path_operator: -> + - quoted_literal: '''$.c[2].f''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a":2,"c":[4,5,{"f":7}]}''' + - column_path_operator: ->> + - quoted_literal: '''$.c[2].f''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a":2,"c":[4,5,{"f":7}]}''' + - column_path_operator: -> + - quoted_literal: '''c''' + - column_path_operator: -> + - numeric_literal: '2' + - column_path_operator: ->> + - quoted_literal: '''f''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a":2,"c":[4,5],"f":7}''' + - column_path_operator: -> + - quoted_literal: '''$.c[#-1]''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a":2,"c":[4,5,{"f":7}]}''' + - column_path_operator: -> + - quoted_literal: '''$.x''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''[11,22,33,44]''' + - column_path_operator: -> + - numeric_literal: '3' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''[11,22,33,44]''' + - column_path_operator: ->> + - numeric_literal: '3' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a":"xyz"}''' + - column_path_operator: -> + - quoted_literal: '''$.a''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a":"xyz"}''' + - column_path_operator: ->> + - quoted_literal: '''$.a''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a":null}''' + - column_path_operator: -> + - quoted_literal: '''$.a''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - quoted_literal: '''{"a":null}''' + - column_path_operator: ->> + - quoted_literal: '''$.a''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/named_parameters.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/named_parameters.sql new file mode 100644 index 000000000..f2420cda3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/named_parameters.sql @@ -0,0 +1,22 @@ +SELECT @variable +FROM table1 +WHERE @variable = 1; + +SELECT ?2 +FROM table1 +WHERE ?2 = 1; + +SELECT :variable +FROM table1 +WHERE :variable = 1; + +SELECT $variable +FROM table1 +WHERE $variable = 1; + +SELECT @variable +FROM table1 +GROUP BY @variable +HAVING $variable = 1; + +SELECT ? from table1 where ? = 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/named_parameters.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/named_parameters.yml new file mode 100644 index 000000000..2ba31c0cb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/named_parameters.yml @@ -0,0 +1,145 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameterized_expression: + - at_sign_literal: '@variable' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - parameterized_expression: + - at_sign_literal: '@variable' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameterized_expression: + - question_literal: ?2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - parameterized_expression: + - question_literal: ?2 + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameterized_expression: + - colon_literal: :variable + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - parameterized_expression: + - colon_literal: :variable + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameterized_expression: + - dollar_literal: $variable + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: WHERE + - expression: + - parameterized_expression: + - dollar_literal: $variable + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameterized_expression: + - at_sign_literal: '@variable' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - parameterized_expression: + - at_sign_literal: '@variable' + - having_clause: + - keyword: HAVING + - expression: + - parameterized_expression: + - dollar_literal: $variable + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameterized_expression: + - question_mark: '?' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - where_clause: + - keyword: where + - expression: + - parameterized_expression: + - question_mark: '?' + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/over_clause.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/over_clause.sql new file mode 100644 index 000000000..c4e94d593 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/over_clause.sql @@ -0,0 +1,79 @@ +SELECT x, y, row_number() OVER (ORDER BY y) AS row_number FROM t0 ORDER BY x; + +SELECT a, b, group_concat(b, '.') OVER ( + ORDER BY a + ROWS + BETWEEN 1 PRECEDING + AND 1 FOLLOWING +) AS group_concat FROM t1; + +SELECT c, a, b, group_concat(b, '.') OVER ( + PARTITION BY c ORDER BY a RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING +) AS group_concat +FROM t1 ORDER BY c, a; + +SELECT c, a, b, group_concat(b, '.') OVER ( + PARTITION BY c ORDER BY a RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING +) AS group_concat +FROM t1 ORDER BY a; + +SELECT a, b, c, + group_concat(b, '.') OVER (ORDER BY c) AS group_concat +FROM t1 ORDER BY a; + +SELECT c, a, b, group_concat(b, '.') OVER ( + ORDER BY c, a ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING +) AS group_concat +FROM t1 ORDER BY c, a; + +SELECT c, a, b, + group_concat(b, '.') OVER ( + ORDER BY c GROUPS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE NO OTHERS + ) AS no_others, + group_concat(b, '.') OVER ( + ORDER BY c GROUPS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE CURRENT ROW + ) AS current_row, + group_concat(b, '.') OVER ( + ORDER BY c GROUPS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE GROUP + ) AS grp, + group_concat(b, '.') OVER ( + ORDER BY c GROUPS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW EXCLUDE TIES + ) AS ties +FROM t1 ORDER BY c, a; + +SELECT c, a, b, group_concat(b, '.') FILTER (WHERE c != 'two') OVER ( + ORDER BY a +) AS group_concat +FROM t1 ORDER BY a; + +SELECT a AS a, + row_number() OVER win AS row_number, + rank() OVER win AS rank, + dense_rank() OVER win AS dense_rank, + percent_rank() OVER win AS percent_rank, + cume_dist() OVER win AS cume_dist +FROM t2 +WINDOW win AS (ORDER BY a); + +SELECT a AS a, + b AS b, + ntile(2) OVER win AS ntile_2, + ntile(4) OVER win AS ntile_4 +FROM t2 +WINDOW win AS (ORDER BY a); + +SELECT b AS b, + lead(b, 2, 'n/a') OVER win AS lead, + lag(b) OVER win AS lag, + first_value(b) OVER win AS first_value, + last_value(b) OVER win AS last_value, + nth_value(b, 3) OVER win AS nth_value_3 +FROM t1 +WINDOW win AS (ORDER BY b ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW); + + +SELECT group_concat(b, '.') OVER ( + win ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW +) +FROM t1 +WINDOW win AS (PARTITION BY a ORDER BY c); diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/over_clause.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/over_clause.yml new file mode 100644 index 000000000..3d76f817d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/over_clause.yml @@ -0,0 +1,1044 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: x + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: y + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: row_number + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: y + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: row_number + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t0 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: x +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: group_concat + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - quoted_literal: '''.''' + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: a + - frame_clause: + - keyword: ROWS + - keyword: BETWEEN + - expression: + - numeric_literal: '1' + - keyword: PRECEDING + - keyword: AND + - expression: + - numeric_literal: '1' + - keyword: FOLLOWING + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: group_concat + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: group_concat + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - quoted_literal: '''.''' + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - expression: + - column_reference: + - naked_identifier: c + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: a + - frame_clause: + - keyword: RANGE + - keyword: BETWEEN + - keyword: CURRENT + - keyword: ROW + - keyword: AND + - keyword: UNBOUNDED + - keyword: FOLLOWING + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: group_concat + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: c + - comma: ',' + - column_reference: + - naked_identifier: a +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: group_concat + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - quoted_literal: '''.''' + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - expression: + - column_reference: + - naked_identifier: c + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: a + - frame_clause: + - keyword: RANGE + - keyword: BETWEEN + - keyword: CURRENT + - keyword: ROW + - keyword: AND + - keyword: UNBOUNDED + - keyword: FOLLOWING + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: group_concat + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: a +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: group_concat + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - quoted_literal: '''.''' + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: c + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: group_concat + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: a +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: group_concat + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - quoted_literal: '''.''' + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: c + - comma: ',' + - column_reference: + - naked_identifier: a + - frame_clause: + - keyword: ROWS + - keyword: BETWEEN + - keyword: CURRENT + - keyword: ROW + - keyword: AND + - keyword: UNBOUNDED + - keyword: FOLLOWING + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: group_concat + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: c + - comma: ',' + - column_reference: + - naked_identifier: a +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: group_concat + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - quoted_literal: '''.''' + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: c + - frame_clause: + - keyword: GROUPS + - keyword: BETWEEN + - keyword: UNBOUNDED + - keyword: PRECEDING + - keyword: AND + - keyword: CURRENT + - keyword: ROW + - keyword: EXCLUDE + - keyword: NO + - keyword: OTHERS + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: no_others + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: group_concat + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - quoted_literal: '''.''' + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: c + - frame_clause: + - keyword: GROUPS + - keyword: BETWEEN + - keyword: UNBOUNDED + - keyword: PRECEDING + - keyword: AND + - keyword: CURRENT + - keyword: ROW + - keyword: EXCLUDE + - keyword: CURRENT + - keyword: ROW + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: current_row + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: group_concat + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - quoted_literal: '''.''' + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: c + - frame_clause: + - keyword: GROUPS + - keyword: BETWEEN + - keyword: UNBOUNDED + - keyword: PRECEDING + - keyword: AND + - keyword: CURRENT + - keyword: ROW + - keyword: EXCLUDE + - keyword: GROUP + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: grp + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: group_concat + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - quoted_literal: '''.''' + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: c + - frame_clause: + - keyword: GROUPS + - keyword: BETWEEN + - keyword: UNBOUNDED + - keyword: PRECEDING + - keyword: AND + - keyword: CURRENT + - keyword: ROW + - keyword: EXCLUDE + - keyword: TIES + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: ties + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: c + - comma: ',' + - column_reference: + - naked_identifier: a +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: group_concat + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - quoted_literal: '''.''' + - end_bracket: ) + - keyword: FILTER + - bracketed: + - start_bracket: ( + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: c + - comparison_operator: + - raw_comparison_operator: '!' + - raw_comparison_operator: = + - quoted_literal: '''two''' + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: a + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: group_concat + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: a +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: row_number + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: row_number + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: rank + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: rank + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: dense_rank + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: dense_rank + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: percent_rank + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: percent_rank + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: cume_dist + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: cume_dist + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - named_window: + - keyword: WINDOW + - named_window_expression: + - naked_identifier: win + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: a + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: b + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: ntile + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '2' + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: ntile_2 + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: ntile + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '4' + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: ntile_4 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 + - named_window: + - keyword: WINDOW + - named_window_expression: + - naked_identifier: win + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: a + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: b + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: b + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: lead + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - numeric_literal: '2' + - comma: ',' + - expression: + - quoted_literal: '''n/a''' + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: lead + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: lag + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: lag + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: first_value + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: first_value + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: last_value + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: last_value + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: nth_value + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - numeric_literal: '3' + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: nth_value_3 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - named_window: + - keyword: WINDOW + - named_window_expression: + - naked_identifier: win + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: b + - frame_clause: + - keyword: ROWS + - keyword: BETWEEN + - keyword: UNBOUNDED + - keyword: PRECEDING + - keyword: AND + - keyword: CURRENT + - keyword: ROW + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: group_concat + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - quoted_literal: '''.''' + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - naked_identifier: win + - frame_clause: + - keyword: ROWS + - keyword: BETWEEN + - keyword: UNBOUNDED + - keyword: PRECEDING + - keyword: AND + - keyword: CURRENT + - keyword: ROW + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - named_window: + - keyword: WINDOW + - named_window_expression: + - naked_identifier: win + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - expression: + - column_reference: + - naked_identifier: a + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: c + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/pattern_matching.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/pattern_matching.sql new file mode 100644 index 000000000..4bfe4dbfa --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/pattern_matching.sql @@ -0,0 +1,46 @@ +CREATE TABLE IF NOT EXISTS task ( + id TEXT PRIMARY KEY CHECK (length(id) = 15), + priority TEXT CHECK (priority GLOB '[A-Z]'), + regex_col TEXT CHECK (priority REGEXP '[A-Z]'), + match_col TEXT CHECK (priority MATCH 'tacos'), + title TEXT NOT NULL, + note TEXT, + created_at DATETIME NOT NULL DEFAULT current_timestamp, + updated_at DATETIME NOT NULL DEFAULT current_timestamp +); + +SELECT col1 +FROM tab_a +WHERE this_col MATCH 'that'; + +SELECT col1 +FROM tab_a +WHERE this_col REGEXP '(that|other)'; + +SELECT col1 +FROM tab_a +WHERE this_col GLOB 'one*two'; + +SELECT col1 +FROM tab_a +WHERE this_col NOT MATCH 'that'; + +SELECT col1 +FROM tab_a +WHERE this_col NOT REGEXP '(that|other)'; + +SELECT col1 +FROM tab_a +WHERE this_col NOT GLOB 'one*two'; + +SELECT col1 +FROM tab_a +WHERE NOT this_col MATCH 'that'; + +SELECT col1 +FROM tab_a +WHERE NOT this_col REGEXP '(that|other)'; + +SELECT col1 +FROM tab_a +WHERE NOT this_col GLOB 'one*two'; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/pattern_matching.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/pattern_matching.yml new file mode 100644 index 000000000..4ff77a7c9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/pattern_matching.yml @@ -0,0 +1,326 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: task + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: length + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: id + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '15' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: priority + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: priority + - keyword: GLOB + - quoted_literal: '''[A-Z]''' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: regex_col + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: priority + - keyword: REGEXP + - quoted_literal: '''[A-Z]''' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: match_col + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: CHECK + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: priority + - keyword: MATCH + - quoted_literal: '''tacos''' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: title + - data_type: + - data_type_identifier: TEXT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: note + - data_type: + - data_type_identifier: TEXT + - comma: ',' + - column_definition: + - naked_identifier: created_at + - data_type: + - data_type_identifier: DATETIME + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - expression: + - bare_function: current_timestamp + - comma: ',' + - column_definition: + - naked_identifier: updated_at + - data_type: + - data_type_identifier: DATETIME + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - expression: + - bare_function: current_timestamp + - end_bracket: ) +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab_a + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: this_col + - keyword: MATCH + - quoted_literal: '''that''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab_a + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: this_col + - keyword: REGEXP + - quoted_literal: '''(that|other)''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab_a + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: this_col + - keyword: GLOB + - quoted_literal: '''one*two''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab_a + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: this_col + - keyword: NOT + - keyword: MATCH + - quoted_literal: '''that''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab_a + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: this_col + - keyword: NOT + - keyword: REGEXP + - quoted_literal: '''(that|other)''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab_a + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: this_col + - keyword: NOT + - keyword: GLOB + - quoted_literal: '''one*two''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab_a + - where_clause: + - keyword: WHERE + - expression: + - keyword: NOT + - column_reference: + - naked_identifier: this_col + - keyword: MATCH + - quoted_literal: '''that''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab_a + - where_clause: + - keyword: WHERE + - expression: + - keyword: NOT + - column_reference: + - naked_identifier: this_col + - keyword: REGEXP + - quoted_literal: '''(that|other)''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tab_a + - where_clause: + - keyword: WHERE + - expression: + - keyword: NOT + - column_reference: + - naked_identifier: this_col + - keyword: GLOB + - quoted_literal: '''one*two''' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/quoted_identifiers.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/quoted_identifiers.sql new file mode 100644 index 000000000..7bbb1162d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/quoted_identifiers.sql @@ -0,0 +1,9 @@ +SELECT `nih`.`userID` +FROM `flight_notification_item_history` AS `nih`; + +-- NOTE: Normally single quoted items are interpreted as strings rather than objects - but this does still run on SQLite. +SELECT 'nih'.'userID' +FROM 'flight_notification_item_history' AS 'nih'; + +SELECT "nih"."userID" +FROM "flight_notification_item_history" AS "nih"; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/quoted_identifiers.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/quoted_identifiers.yml new file mode 100644 index 000000000..a96aa3c5c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/quoted_identifiers.yml @@ -0,0 +1,64 @@ +file: +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '`nih`' + - dot: . + - quoted_identifier: '`userID`' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '`flight_notification_item_history`' + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '`nih`' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '''nih''' + - dot: . + - quoted_identifier: '''userID''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '''flight_notification_item_history''' + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '''nih''' +- statement_terminator: ; +- statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '"nih"' + - dot: . + - quoted_identifier: '"userID"' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '"flight_notification_item_history"' + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '"nih"' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/raise_function.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/raise_function.sql new file mode 100644 index 000000000..072f4b1d7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/raise_function.sql @@ -0,0 +1,5 @@ +CREATE TRIGGER x +BEFORE UPDATE OF z ON y +BEGIN +SELECT RAISE (ROLLBACK, 'updating z not allowed'); +END; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/raise_function.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/raise_function.yml new file mode 100644 index 000000000..d25f99bb0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/raise_function.yml @@ -0,0 +1,33 @@ +file: +- statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: x + - keyword: BEFORE + - keyword: UPDATE + - keyword: OF + - column_reference: + - naked_identifier: z + - keyword: ON + - table_reference: + - naked_identifier: y + - keyword: BEGIN + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: RAISE + - function_contents: + - bracketed: + - start_bracket: ( + - keyword: ROLLBACK + - comma: ',' + - quoted_literal: '''updating z not allowed''' + - end_bracket: ) + - statement_terminator: ; + - keyword: END +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/select.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/select.yml index e2074b422..c2a1baf42 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/select.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/select.yml @@ -37,7 +37,8 @@ file: - naked_identifier: light - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: trips - from_clause: - keyword: FROM @@ -119,7 +120,8 @@ file: - data_type_identifier: real - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: time_spent - from_clause: - keyword: FROM @@ -174,7 +176,8 @@ file: - column_reference: - naked_identifier: branch - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: name - comma: ',' - select_clause_element: @@ -192,7 +195,8 @@ file: - data_type_identifier: real - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: time_spent - comma: ',' - select_clause_element: @@ -236,7 +240,8 @@ file: - data_type_identifier: real - end_bracket: ) - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: time_percentage - from_clause: - keyword: FROM @@ -275,7 +280,8 @@ file: - data_type_identifier: real - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: time_spent - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/update.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/update.sql index f5f68d499..03e965ec1 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/update.sql +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/update.sql @@ -2,6 +2,16 @@ UPDATE table_name SET column1 = value1, column2 = value2 WHERE a=1; UPDATE table_name SET column1 = value1, column2 = value2 WHERE a=1 RETURNING *; -UPDATE table_name SET column1 = value1, column2 = value2 WHERE a=1 RETURNING column1; +UPDATE table_name SET column1 = value1, column2 = value2 WHERE a=1 RETURNING id foo, id_2 AS bar; -UPDATE table_name SET column1 = value1, column2 = value2 WHERE a=1 RETURNING column1 AS c1, column2; +UPDATE OR IGNORE table_name SET column1 = value1, column2 = value2 WHERE a=1; + +UPDATE OR ABORT table_name SET column1 = value1, column2 = value2 WHERE a=1; + +UPDATE OR FAIL table_name SET column1 = value1, column2 = value2 WHERE a=1; + +UPDATE OR REPLACE table_name SET column1 = value1, column2 = value2 WHERE a=1; + +UPDATE OR ROLLBACK table_name SET column1 = value1, column2 = value2 WHERE a=1; + +UPDATE table_name SET (context, country) = (SELECT context, country FROM Nations); diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/update.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/update.yml index a573b3b7e..fa00fc3be 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/update.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/update.yml @@ -7,20 +7,20 @@ file: - set_clause_list: - keyword: SET - set_clause: - - column_reference: - - naked_identifier: column1 + - naked_identifier: column1 - comparison_operator: - raw_comparison_operator: = - - column_reference: - - naked_identifier: value1 + - expression: + - column_reference: + - naked_identifier: value1 - comma: ',' - set_clause: - - column_reference: - - naked_identifier: column2 + - naked_identifier: column2 - comparison_operator: - raw_comparison_operator: = - - column_reference: - - naked_identifier: value2 + - expression: + - column_reference: + - naked_identifier: value2 - where_clause: - keyword: WHERE - expression: @@ -38,20 +38,20 @@ file: - set_clause_list: - keyword: SET - set_clause: - - column_reference: - - naked_identifier: column1 + - naked_identifier: column1 - comparison_operator: - raw_comparison_operator: = - - column_reference: - - naked_identifier: value1 + - expression: + - column_reference: + - naked_identifier: value1 - comma: ',' - set_clause: - - column_reference: - - naked_identifier: column2 + - naked_identifier: column2 - comparison_operator: - raw_comparison_operator: = - - column_reference: - - naked_identifier: value2 + - expression: + - column_reference: + - naked_identifier: value2 - where_clause: - keyword: WHERE - expression: @@ -60,8 +60,11 @@ file: - comparison_operator: - raw_comparison_operator: = - numeric_literal: '1' - - keyword: RETURNING - - star: '*' + - returning_clause: + - keyword: RETURNING + - wildcard_expression: + - wildcard_identifier: + - star: '*' - statement_terminator: ; - statement: - update_statement: @@ -71,20 +74,68 @@ file: - set_clause_list: - keyword: SET - set_clause: - - column_reference: - - naked_identifier: column1 + - naked_identifier: column1 - comparison_operator: - raw_comparison_operator: = - - column_reference: - - naked_identifier: value1 + - expression: + - column_reference: + - naked_identifier: value1 - comma: ',' - set_clause: + - naked_identifier: column2 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: value2 + - where_clause: + - keyword: WHERE + - expression: - column_reference: - - naked_identifier: column2 + - naked_identifier: a - comparison_operator: - raw_comparison_operator: = + - numeric_literal: '1' + - returning_clause: + - keyword: RETURNING + - expression: + - column_reference: + - naked_identifier: id + - alias_expression: + - naked_identifier: foo + - comma: ',' + - expression: - column_reference: - - naked_identifier: value2 + - naked_identifier: id_2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: bar +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - keyword: OR + - keyword: IGNORE + - table_reference: + - naked_identifier: table_name + - set_clause_list: + - keyword: SET + - set_clause: + - naked_identifier: column1 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: value1 + - comma: ',' + - set_clause: + - naked_identifier: column2 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: value2 - where_clause: - keyword: WHERE - expression: @@ -93,33 +144,97 @@ file: - comparison_operator: - raw_comparison_operator: = - numeric_literal: '1' - - keyword: RETURNING - - expression: - - column_reference: - - naked_identifier: column1 - statement_terminator: ; - statement: - update_statement: - keyword: UPDATE + - keyword: OR + - keyword: ABORT - table_reference: - naked_identifier: table_name - set_clause_list: - keyword: SET - set_clause: - - column_reference: - - naked_identifier: column1 + - naked_identifier: column1 - comparison_operator: - raw_comparison_operator: = - - column_reference: - - naked_identifier: value1 + - expression: + - column_reference: + - naked_identifier: value1 - comma: ',' - set_clause: + - naked_identifier: column2 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: value2 + - where_clause: + - keyword: WHERE + - expression: - column_reference: - - naked_identifier: column2 + - naked_identifier: a - comparison_operator: - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - keyword: OR + - keyword: FAIL + - table_reference: + - naked_identifier: table_name + - set_clause_list: + - keyword: SET + - set_clause: + - naked_identifier: column1 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: value1 + - comma: ',' + - set_clause: + - naked_identifier: column2 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: value2 + - where_clause: + - keyword: WHERE + - expression: - column_reference: - - naked_identifier: value2 + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - keyword: OR + - keyword: REPLACE + - table_reference: + - naked_identifier: table_name + - set_clause_list: + - keyword: SET + - set_clause: + - naked_identifier: column1 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: value1 + - comma: ',' + - set_clause: + - naked_identifier: column2 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: value2 - where_clause: - keyword: WHERE - expression: @@ -128,15 +243,77 @@ file: - comparison_operator: - raw_comparison_operator: = - numeric_literal: '1' - - keyword: RETURNING - - expression: - - column_reference: +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - keyword: OR + - keyword: ROLLBACK + - table_reference: + - naked_identifier: table_name + - set_clause_list: + - keyword: SET + - set_clause: - naked_identifier: column1 - - alias_expression: - - keyword: AS - - naked_identifier: c1 - - comma: ',' - - expression: - - column_reference: + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: value1 + - comma: ',' + - set_clause: - naked_identifier: column2 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: value2 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' +- statement_terminator: ; +- statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: table_name + - set_clause_list: + - keyword: SET + - set_clause: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: context + - comma: ',' + - column_reference: + - naked_identifier: country + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: context + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: country + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Nations + - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/upsert.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/upsert.sql new file mode 100644 index 000000000..825998f97 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/upsert.sql @@ -0,0 +1,19 @@ +INSERT INTO t1 (a, b) VALUES (1, 2) ON CONFLICT DO NOTHING; + +INSERT INTO t1 (a, b) VALUES (1, 2) ON CONFLICT (a, b) DO NOTHING; + +INSERT INTO t1 (a, b) +VALUES (1, 2) +ON CONFLICT (a, b) DO UPDATE SET +a = excluded.a; + +INSERT INTO t1 (a, b) +VALUES (1, 2) +ON CONFLICT (a, b) DO UPDATE SET +a = excluded.a WHERE a < 10; + +INSERT INTO t1 (a, b) +VALUES (1, 2) +ON CONFLICT (a, b) DO UPDATE SET +a = excluded.a WHERE a < 10 +RETURNING *; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/upsert.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/upsert.yml new file mode 100644 index 000000000..1e6e73185 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/upsert.yml @@ -0,0 +1,241 @@ +file: +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - numeric_literal: '2' + - end_bracket: ) + - upsert_clause: + - keyword: ON + - keyword: CONFLICT + - keyword: DO + - keyword: NOTHING +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - numeric_literal: '2' + - end_bracket: ) + - upsert_clause: + - keyword: ON + - keyword: CONFLICT + - conflict_target: + - index_column_definition: + - expression: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - end_bracket: ) + - keyword: DO + - keyword: NOTHING +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - numeric_literal: '2' + - end_bracket: ) + - upsert_clause: + - keyword: ON + - keyword: CONFLICT + - conflict_target: + - index_column_definition: + - expression: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - end_bracket: ) + - keyword: DO + - keyword: UPDATE + - keyword: SET + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: excluded + - dot: . + - naked_identifier: a +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - numeric_literal: '2' + - end_bracket: ) + - upsert_clause: + - keyword: ON + - keyword: CONFLICT + - conflict_target: + - index_column_definition: + - expression: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - end_bracket: ) + - keyword: DO + - keyword: UPDATE + - keyword: SET + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: excluded + - dot: . + - naked_identifier: a + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '10' +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '1' + - comma: ',' + - expression: + - numeric_literal: '2' + - end_bracket: ) + - upsert_clause: + - keyword: ON + - keyword: CONFLICT + - conflict_target: + - index_column_definition: + - expression: + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - end_bracket: ) + - keyword: DO + - keyword: UPDATE + - keyword: SET + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: excluded + - dot: . + - naked_identifier: a + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: a + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '10' + - returning_clause: + - keyword: RETURNING + - wildcard_expression: + - wildcard_identifier: + - star: '*' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/window.sql b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/window.sql deleted file mode 100644 index 5b5c13257..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/window.sql +++ /dev/null @@ -1,10 +0,0 @@ -SELECT - name, - ROW_NUMBER() OVER(PARTITION BY dept), - salary as sal -FROM employees; - -SELECT c, a, b, group_concat(b, '.') FILTER (WHERE c!='two') OVER ( - ORDER BY a -) AS group_concat -FROM t1 ORDER BY a; diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/window.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/window.yml deleted file mode 100644 index c09eaf21b..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqlfluff/window.yml +++ /dev/null @@ -1,113 +0,0 @@ -file: -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: name - - comma: ',' - - select_clause_element: - - function: - - function_name: - - function_name_identifier: ROW_NUMBER - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) - - over_clause: - - keyword: OVER - - bracketed: - - start_bracket: ( - - window_specification: - - partitionby_clause: - - keyword: PARTITION - - keyword: BY - - expression: - - column_reference: - - naked_identifier: dept - - end_bracket: ) - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: salary - - alias_expression: - - keyword: as - - naked_identifier: sal - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: employees -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: c - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: a - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: b - - comma: ',' - - select_clause_element: - - function: - - function_name: - - function_name_identifier: group_concat - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: b - - comma: ',' - - expression: - - quoted_literal: '''.''' - - end_bracket: ) - - keyword: FILTER - - bracketed: - - start_bracket: ( - - keyword: WHERE - - expression: - - column_reference: - - naked_identifier: c - - comparison_operator: - - raw_comparison_operator: '!' - - raw_comparison_operator: = - - quoted_literal: '''two''' - - end_bracket: ) - - over_clause: - - keyword: OVER - - bracketed: - - start_bracket: ( - - window_specification: - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: a - - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: group_concat - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - naked_identifier: t1 - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: a -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/alter_table.sql b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/alter_table.sql new file mode 100644 index 000000000..18ab7d186 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/alter_table.sql @@ -0,0 +1,35 @@ +ALTER TABLE t1 RENAME TO t2; +ALTER TABLE IF EXISTS t1 RENAME TO t2; + +ALTER TABLE t1 ADD COLUMN col1 VARCHAR; +ALTER TABLE t1 ADD COLUMN IF NOT EXISTS col1 VARCHAR; +ALTER TABLE t1 ADD COLUMN col1 VARCHAR NOT NULL; +ALTER TABLE t1 ADD COLUMN col1 VARCHAR COMMENT 'comment'; +ALTER TABLE t1 ADD COLUMN col1 VARCHAR WITH (x = 'y'); +ALTER TABLE t1 ADD COLUMN col1 VARCHAR FIRST; +ALTER TABLE t1 ADD COLUMN col1 VARCHAR LAST; +ALTER TABLE t1 ADD COLUMN col1 VARCHAR AFTER col2; + +ALTER TABLE t1 DROP COLUMN col1; +ALTER TABLE t1 DROP COLUMN IF EXISTS col1; + +ALTER TABLE t1 RENAME COLUMN col1 TO col2; +ALTER TABLE t1 RENAME COLUMN IF EXISTS col1 TO col2; + +ALTER TABLE t1 ALTER COLUMN col1 SET DATA TYPE INTEGER; +ALTER TABLE t1 ALTER COLUMN col1 SET DATA TYPE VARCHAR(100); + +ALTER TABLE t1 ALTER COLUMN col1 DROP NOT NULL; + +ALTER TABLE t1 SET AUTHORIZATION u1; +ALTER TABLE t1 SET AUTHORIZATION USER u1; +ALTER TABLE t1 SET AUTHORIZATION ROLE r1; + +ALTER TABLE t1 SET PROPERTIES x = 'y'; +ALTER TABLE t1 SET PROPERTIES x = DEFAULT; +ALTER TABLE t1 SET PROPERTIES foo = 123, bar = 456; + +ALTER TABLE t1 EXECUTE func; +ALTER TABLE t1 EXECUTE func(x => 'y'); +ALTER TABLE t1 EXECUTE func(foo => 123, bar => 456); +ALTER TABLE t1 EXECUTE func(x => 'y') WHERE col1 > 0; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/alter_table.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/alter_table.yml new file mode 100644 index 000000000..27cc235e6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/alter_table.yml @@ -0,0 +1,424 @@ +file: +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: RENAME + - keyword: TO + - table_reference: + - naked_identifier: t2 +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - keyword: IF + - keyword: EXISTS + - table_reference: + - naked_identifier: t1 + - keyword: RENAME + - keyword: TO + - table_reference: + - naked_identifier: t2 +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: VARCHAR +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: ADD + - keyword: COLUMN + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: VARCHAR +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: VARCHAR + - keyword: NOT + - keyword: 'NULL' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: VARCHAR + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''comment''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: VARCHAR + - keyword: WITH + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''y''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: VARCHAR + - keyword: FIRST +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: VARCHAR + - keyword: LAST +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: ADD + - keyword: COLUMN + - column_definition: + - naked_identifier: col1 + - data_type: + - primitive_type: + - keyword: VARCHAR + - keyword: AFTER + - column_reference: + - naked_identifier: col2 +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: DROP + - keyword: COLUMN + - column_reference: + - naked_identifier: col1 +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: DROP + - keyword: COLUMN + - keyword: IF + - keyword: EXISTS + - column_reference: + - naked_identifier: col1 +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: RENAME + - keyword: COLUMN + - column_reference: + - naked_identifier: col1 + - keyword: TO + - column_reference: + - naked_identifier: col2 +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: RENAME + - keyword: COLUMN + - keyword: IF + - keyword: EXISTS + - column_reference: + - naked_identifier: col1 + - keyword: TO + - column_reference: + - naked_identifier: col2 +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: ALTER + - keyword: COLUMN + - column_reference: + - naked_identifier: col1 + - keyword: SET + - keyword: DATA + - keyword: TYPE + - data_type: + - primitive_type: + - keyword: INTEGER +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: ALTER + - keyword: COLUMN + - column_reference: + - naked_identifier: col1 + - keyword: SET + - keyword: DATA + - keyword: TYPE + - data_type: + - primitive_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: ALTER + - keyword: COLUMN + - column_reference: + - naked_identifier: col1 + - keyword: DROP + - keyword: NOT + - keyword: 'NULL' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: SET + - keyword: AUTHORIZATION + - role_reference: + - naked_identifier: u1 +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: SET + - keyword: AUTHORIZATION + - keyword: USER + - role_reference: + - naked_identifier: u1 +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: SET + - keyword: AUTHORIZATION + - keyword: ROLE + - role_reference: + - naked_identifier: r1 +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: SET + - keyword: PROPERTIES + - parameter: x + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''y''' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: SET + - keyword: PROPERTIES + - parameter: x + - comparison_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: DEFAULT +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: SET + - keyword: PROPERTIES + - parameter: foo + - comparison_operator: + - raw_comparison_operator: = + - expression: + - numeric_literal: '123' + - comma: ',' + - parameter: bar + - comparison_operator: + - raw_comparison_operator: = + - expression: + - numeric_literal: '456' +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: EXECUTE + - function_name: + - function_name_identifier: func +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: EXECUTE + - function_name: + - function_name_identifier: func + - bracketed: + - start_bracket: ( + - parameter: x + - execute_arrow: => + - expression: + - quoted_literal: '''y''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: EXECUTE + - function_name: + - function_name_identifier: func + - bracketed: + - start_bracket: ( + - parameter: foo + - execute_arrow: => + - expression: + - numeric_literal: '123' + - comma: ',' + - parameter: bar + - execute_arrow: => + - expression: + - numeric_literal: '456' + - end_bracket: ) +- statement_terminator: ; +- statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: t1 + - keyword: EXECUTE + - function_name: + - function_name_identifier: func + - bracketed: + - start_bracket: ( + - parameter: x + - execute_arrow: => + - expression: + - quoted_literal: '''y''' + - end_bracket: ) + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/analyze.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/analyze.yml index f7f5c7d69..ec3a84904 100644 --- a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/analyze.yml +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/analyze.yml @@ -1,34 +1,36 @@ file: - statement: - - keyword: ANALYZE - - table_reference: - - naked_identifier: web + - analyze_statement: + - keyword: ANALYZE + - table_reference: + - naked_identifier: web - statement_terminator: ; - statement: - - keyword: ANALYZE - - table_reference: - - naked_identifier: hive - - dot: . - - naked_identifier: default - - dot: . - - naked_identifier: stores + - analyze_statement: + - keyword: ANALYZE + - table_reference: + - naked_identifier: hive + - dot: . + - naked_identifier: default + - dot: . + - naked_identifier: stores - statement_terminator: ; - statement: - - keyword: ANALYZE - - table_reference: - - naked_identifier: hive - - dot: . - - naked_identifier: default - - dot: . - - naked_identifier: sales - - keyword: WITH - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: partitions + - analyze_statement: + - keyword: ANALYZE + - table_reference: + - naked_identifier: hive + - dot: . + - naked_identifier: default + - dot: . + - naked_identifier: sales + - keyword: WITH + - bracketed: + - start_bracket: ( + - parameter: partitions - comparison_operator: - raw_comparison_operator: = - - numeric_literal: '1' - - end_bracket: ) + - expression: + - numeric_literal: '1' + - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/array.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/array.yml index db4c430b1..09a0b56ac 100644 --- a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/array.yml +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/array.yml @@ -116,14 +116,15 @@ file: - numeric_literal: '7' - end_square_bracket: ']' - comma: ',' - - parameter: x - - symbol: -> - - expression: - - column_reference: - - naked_identifier: x - - comparison_operator: - - raw_comparison_operator: '>' - - numeric_literal: '0' + - lambda_function: + - parameter: x + - lambda_arrow: -> + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' - end_bracket: ) - statement_terminator: ; - statement: @@ -154,14 +155,15 @@ file: - numeric_literal: '7' - end_square_bracket: ']' - comma: ',' - - parameter: x - - symbol: -> - - expression: - - column_reference: - - naked_identifier: x - - comparison_operator: - - raw_comparison_operator: '>' - - numeric_literal: '0' + - lambda_function: + - parameter: x + - lambda_arrow: -> + - expression: + - column_reference: + - naked_identifier: x + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '0' - end_bracket: ) - statement_terminator: ; - statement: @@ -217,10 +219,12 @@ file: - data_type: - array_type: - keyword: ARRAY - - start_angle_bracket: < - - data_type: - - keyword: DOUBLE - - end_angle_bracket: '>' + - array_type_schema: + - start_angle_bracket: < + - data_type: + - primitive_type: + - keyword: DOUBLE + - end_angle_bracket: '>' - end_bracket: ) - statement_terminator: ; - statement: @@ -248,11 +252,13 @@ file: - data_type: - array_type: - keyword: ARRAY - - bracketed: - - start_bracket: ( - - data_type: - - keyword: DOUBLE - - end_bracket: ) + - array_type_schema: + - bracketed: + - start_bracket: ( + - data_type: + - primitive_type: + - keyword: DOUBLE + - end_bracket: ) - end_bracket: ) - statement_terminator: ; - statement: @@ -280,9 +286,11 @@ file: - data_type: - array_type: - keyword: ARRAY - - start_angle_bracket: < - - data_type: - - keyword: DOUBLE - - end_angle_bracket: '>' + - array_type_schema: + - start_angle_bracket: < + - data_type: + - primitive_type: + - keyword: DOUBLE + - end_angle_bracket: '>' - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/bare_functions.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/bare_functions.yml index b329217f7..2abde17b3 100644 --- a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/bare_functions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/bare_functions.yml @@ -6,30 +6,35 @@ file: - select_clause_element: - bare_function: current_date - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col1 - comma: ',' - select_clause_element: - bare_function: current_timestamp - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col2 - comma: ',' - select_clause_element: - bare_function: current_time - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: col3 - comma: ',' - select_clause_element: - bare_function: localtime - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: col4 - comma: ',' - select_clause_element: - bare_function: localtimestamp - alias_expression: - - keyword: as + - alias_operator: + - keyword: as - naked_identifier: col5 - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/comment_on.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/comment_on.yml index 5ab5be3e1..6f0e302b2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/comment_on.yml +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/comment_on.yml @@ -1,52 +1,57 @@ file: - statement: - - keyword: COMMENT - - keyword: ON - - keyword: TABLE - - table_reference: - - naked_identifier: abc - - keyword: IS - - quoted_literal: '''xyz''' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: TABLE + - table_reference: + - naked_identifier: abc + - keyword: IS + - quoted_literal: '''xyz''' - statement_terminator: ; - statement: - - keyword: COMMENT - - keyword: ON - - keyword: VIEW - - table_reference: - - naked_identifier: abc - - keyword: IS - - quoted_literal: '''xyz''' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: VIEW + - table_reference: + - naked_identifier: abc + - keyword: IS + - quoted_literal: '''xyz''' - statement_terminator: ; - statement: - - keyword: COMMENT - - keyword: ON - - keyword: COLUMN - - column_reference: - - naked_identifier: table1 - - dot: . - - naked_identifier: column1 - - keyword: IS - - quoted_literal: '''abc''' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: COLUMN + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: column1 + - keyword: IS + - quoted_literal: '''abc''' - statement_terminator: ; - statement: - - keyword: COMMENT - - keyword: ON - - keyword: COLUMN - - column_reference: - - naked_identifier: table1 - - dot: . - - naked_identifier: column2 - - keyword: IS - - quoted_literal: '''abc''' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: COLUMN + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: column2 + - keyword: IS + - quoted_literal: '''abc''' - statement_terminator: ; - statement: - - keyword: COMMENT - - keyword: ON - - keyword: COLUMN - - column_reference: - - naked_identifier: table1 - - dot: . - - naked_identifier: column3 - - keyword: IS - - quoted_literal: '''abc.''' + - comment_clause: + - keyword: COMMENT + - keyword: ON + - keyword: COLUMN + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: column3 + - keyword: IS + - quoted_literal: '''abc.''' - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/commit.sql b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/commit.sql new file mode 100644 index 000000000..a3f09c359 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/commit.sql @@ -0,0 +1,3 @@ +COMMIT; + +COMMIT WORK; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/commit.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/commit.yml new file mode 100644 index 000000000..2221ee95b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/commit.yml @@ -0,0 +1,10 @@ +file: +- statement: + - transaction_statement: + - keyword: COMMIT +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: COMMIT + - keyword: WORK +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/create_table.sql b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/create_table.sql new file mode 100644 index 000000000..dc00d3954 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/create_table.sql @@ -0,0 +1,76 @@ +CREATE TABLE a ( + str varchar +); + +create table if not exists foo.bar.baz +( +date_nk date, +date_ts timestamp, +site varchar(30), +partition_date date +) +with ( +format = 'parquet', +partitioned_by = array ['partition_date'] +); + +CREATE TABLE orders ( + orderkey bigint, + orderstatus varchar, + totalprice double, + orderdate date +) +WITH (format = 'ORC') +; + +CREATE TABLE IF NOT EXISTS orders ( + orderkey bigint, + orderstatus varchar, + totalprice double COMMENT 'Price in cents.', + shipmentstatus varchar not null, + orderdate date +) +COMMENT 'A table to keep track of orders.' +; + +CREATE TABLE bigger_orders ( + another_orderkey bigint, + LIKE orders, + another_orderdate date +) +; + +CREATE TABLE orders_column_aliased (order_date, total_price) +AS +SELECT orderdate, totalprice +FROM orders +; + +CREATE TABLE orders_by_date +COMMENT 'Summary of orders by date' +WITH (format = 'ORC') +AS +SELECT orderdate, sum(totalprice) AS price +FROM orders +GROUP BY orderdate +; + +CREATE TABLE IF NOT EXISTS orders_by_date AS +SELECT orderdate, sum(totalprice) AS price +FROM orders +GROUP BY orderdate +; + +CREATE TABLE empty_nation AS +SELECT * +FROM nation +WITH NO DATA +; + +CREATE TABLE structural_types ( + array_type_1 array(integer), + array_type_2 array, + map_type_1 map(varchar(20), integer), + map_type_2 map, + row_type row(a integer, b varchar(20), c array(real)) +); diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/create_table.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/create_table.yml new file mode 100644 index 000000000..4cff964a5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/create_table.yml @@ -0,0 +1,471 @@ +file: +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: a + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: str + - data_type: + - primitive_type: + - keyword: varchar + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: create + - keyword: table + - keyword: if + - keyword: not + - keyword: exists + - table_reference: + - naked_identifier: foo + - dot: . + - naked_identifier: bar + - dot: . + - naked_identifier: baz + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: date_nk + - data_type: + - primitive_type: + - keyword: date + - comma: ',' + - column_definition: + - naked_identifier: date_ts + - data_type: + - primitive_type: + - keyword: timestamp + - comma: ',' + - column_definition: + - naked_identifier: site + - data_type: + - primitive_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '30' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: partition_date + - data_type: + - primitive_type: + - keyword: date + - end_bracket: ) + - keyword: with + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''parquet''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: partitioned_by + - comparison_operator: + - raw_comparison_operator: = + - typed_array_literal: + - array_type: + - keyword: array + - array_literal: + - start_square_bracket: '[' + - quoted_literal: '''partition_date''' + - end_square_bracket: ']' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: orders + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: orderkey + - data_type: + - primitive_type: + - keyword: bigint + - comma: ',' + - column_definition: + - naked_identifier: orderstatus + - data_type: + - primitive_type: + - keyword: varchar + - comma: ',' + - column_definition: + - naked_identifier: totalprice + - data_type: + - primitive_type: + - keyword: double + - comma: ',' + - column_definition: + - naked_identifier: orderdate + - data_type: + - primitive_type: + - keyword: date + - end_bracket: ) + - keyword: WITH + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''ORC''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: orders + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: orderkey + - data_type: + - primitive_type: + - keyword: bigint + - comma: ',' + - column_definition: + - naked_identifier: orderstatus + - data_type: + - primitive_type: + - keyword: varchar + - comma: ',' + - column_definition: + - naked_identifier: totalprice + - data_type: + - primitive_type: + - keyword: double + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''Price in cents.''' + - comma: ',' + - column_definition: + - naked_identifier: shipmentstatus + - data_type: + - primitive_type: + - keyword: varchar + - keyword: not + - keyword: 'null' + - comma: ',' + - column_definition: + - naked_identifier: orderdate + - data_type: + - primitive_type: + - keyword: date + - end_bracket: ) + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''A table to keep track of orders.''' +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: bigger_orders + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: another_orderkey + - data_type: + - primitive_type: + - keyword: bigint + - comma: ',' + - keyword: LIKE + - table_reference: + - naked_identifier: orders + - comma: ',' + - column_definition: + - naked_identifier: another_orderdate + - data_type: + - primitive_type: + - keyword: date + - end_bracket: ) +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: orders_column_aliased + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: order_date + - comma: ',' + - column_reference: + - naked_identifier: total_price + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: orderdate + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: totalprice + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: orders +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: orders_by_date + - comment_clause: + - keyword: COMMENT + - quoted_literal: '''Summary of orders by date''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''ORC''' + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: orderdate + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: totalprice + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: price + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: orders + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: orderdate +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - keyword: IF + - keyword: NOT + - keyword: EXISTS + - table_reference: + - naked_identifier: orders_by_date + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: orderdate + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: totalprice + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: price + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: orders + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: orderdate +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: empty_nation + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: nation + - keyword: WITH + - keyword: NO + - keyword: DATA +- statement_terminator: ; +- statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: structural_types + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: array_type_1 + - data_type: + - array_type: + - keyword: array + - array_type_schema: + - bracketed: + - start_bracket: ( + - data_type: + - primitive_type: + - keyword: integer + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: array_type_2 + - data_type: + - array_type: + - keyword: array + - array_type_schema: + - start_angle_bracket: < + - data_type: + - primitive_type: + - keyword: integer + - end_angle_bracket: '>' + - comma: ',' + - column_definition: + - naked_identifier: map_type_1 + - data_type: + - map_type: + - keyword: map + - map_type_schema: + - bracketed: + - start_bracket: ( + - primitive_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '20' + - end_bracket: ) + - comma: ',' + - data_type: + - primitive_type: + - keyword: integer + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: map_type_2 + - data_type: + - map_type: + - keyword: map + - map_type_schema: + - start_angle_bracket: < + - primitive_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '20' + - end_bracket: ) + - comma: ',' + - data_type: + - primitive_type: + - keyword: integer + - end_angle_bracket: '>' + - comma: ',' + - column_definition: + - naked_identifier: row_type + - data_type: + - struct_type: + - keyword: row + - struct_type_schema: + - bracketed: + - start_bracket: ( + - parameter: a + - data_type: + - primitive_type: + - keyword: integer + - comma: ',' + - parameter: b + - data_type: + - primitive_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '20' + - end_bracket: ) + - comma: ',' + - parameter: c + - data_type: + - array_type: + - keyword: array + - array_type_schema: + - bracketed: + - start_bracket: ( + - data_type: + - primitive_type: + - keyword: real + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/filter_aggregate.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/filter_aggregate.yml index 67575c987..ef11ab85f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/filter_aggregate.yml +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/filter_aggregate.yml @@ -28,7 +28,8 @@ file: - null_literal: 'NULL' - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: count - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/grouping_sets.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/grouping_sets.yml index c2c7c5ab2..34270c331 100644 --- a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/grouping_sets.yml +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/grouping_sets.yml @@ -63,7 +63,8 @@ file: - naked_identifier: price - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: volume - comma: ',' - select_clause_element: diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/insert.sql b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/insert.sql new file mode 100644 index 000000000..4920fbdc6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/insert.sql @@ -0,0 +1,7 @@ +INSERT INTO t1 SELECT * FROM t2; + +INSERT INTO t1 VALUES (1, 'San Francisco'); + +INSERT INTO t1 (a,b,c) SELECT * FROM t2; + +INSERT INTO t1 (a,b,c) VALUES (26, 'POLAND', 3); diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/insert.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/insert.yml new file mode 100644 index 000000000..2d4c99d9f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/insert.yml @@ -0,0 +1,99 @@ +file: +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - values_clause: + - keyword: VALUES + - expression: + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - quoted_literal: '''San Francisco''' + - end_bracket: ) +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - comma: ',' + - column_reference: + - naked_identifier: c + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t2 +- statement_terminator: ; +- statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: a + - comma: ',' + - column_reference: + - naked_identifier: b + - comma: ',' + - column_reference: + - naked_identifier: c + - end_bracket: ) + - values_clause: + - keyword: VALUES + - expression: + - bracketed: + - start_bracket: ( + - numeric_literal: '26' + - comma: ',' + - quoted_literal: '''POLAND''' + - comma: ',' + - numeric_literal: '3' + - end_bracket: ) +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/integer_types.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/integer_types.yml index 42234052f..a5791b499 100644 --- a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/integer_types.yml +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/integer_types.yml @@ -14,7 +14,8 @@ file: - numeric_literal: '1' - keyword: AS - data_type: - - keyword: TINYINT + - primitive_type: + - keyword: TINYINT - end_bracket: ) - statement_terminator: ; - statement: @@ -32,7 +33,8 @@ file: - numeric_literal: '2' - keyword: AS - data_type: - - keyword: SMALLINT + - primitive_type: + - keyword: SMALLINT - end_bracket: ) - statement_terminator: ; - statement: @@ -50,7 +52,8 @@ file: - numeric_literal: '3' - keyword: AS - data_type: - - keyword: INTEGER + - primitive_type: + - keyword: INTEGER - end_bracket: ) - statement_terminator: ; - statement: @@ -68,7 +71,8 @@ file: - numeric_literal: '4' - keyword: AS - data_type: - - keyword: INT + - primitive_type: + - keyword: INT - end_bracket: ) - statement_terminator: ; - statement: @@ -86,6 +90,7 @@ file: - numeric_literal: '5' - keyword: AS - data_type: - - keyword: BIGINT + - primitive_type: + - keyword: BIGINT - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/json_functions.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/json_functions.yml index 1149066fc..43680460d 100644 --- a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/json_functions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/json_functions.yml @@ -13,12 +13,8 @@ file: - expression: - column_reference: - naked_identifier: payload - - expression: - - column_reference: - - naked_identifier: format - - expression: - - column_reference: - - naked_identifier: json + - keyword: format + - keyword: json - comma: ',' - expression: - quoted_literal: '''lax $.unstructured.abcd[*].field?(@ > 0.5)''' @@ -104,12 +100,8 @@ file: - expression: - column_reference: - naked_identifier: payload - - expression: - - column_reference: - - naked_identifier: format - - expression: - - column_reference: - - naked_identifier: json + - keyword: format + - keyword: json - comma: ',' - expression: - quoted_literal: '''lax $.unstructured.abcd[*].field?(@ > 0.5)''' diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/range_offset.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/range_offset.yml index c20dbb626..26e382535 100644 --- a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/range_offset.yml +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/range_offset.yml @@ -40,7 +40,8 @@ file: - keyword: FOLLOWING - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: close_better_scores_count - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/regexp_replace_with_lambda.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/regexp_replace_with_lambda.yml index 4bdad7afc..e0831eedf 100644 --- a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/regexp_replace_with_lambda.yml +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/regexp_replace_with_lambda.yml @@ -16,39 +16,40 @@ file: - expression: - quoted_literal: '''(\w)(\w*)''' - comma: ',' - - parameter: x - - symbol: -> - - expression: - - function: - - function_name: - - function_name_identifier: UPPER - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: x - - array_accessor: - - start_square_bracket: '[' - - numeric_literal: '1' - - end_square_bracket: ']' - - end_bracket: ) - - binary_operator: - - pipe: '|' - - pipe: '|' - - function: - - function_name: - - function_name_identifier: LOWER - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: x - - array_accessor: - - start_square_bracket: '[' - - numeric_literal: '2' - - end_square_bracket: ']' - - end_bracket: ) + - lambda_function: + - parameter: x + - lambda_arrow: -> + - expression: + - function: + - function_name: + - function_name_identifier: UPPER + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - array_accessor: + - start_square_bracket: '[' + - numeric_literal: '1' + - end_square_bracket: ']' + - end_bracket: ) + - binary_operator: + - pipe: '|' + - pipe: '|' + - function: + - function_name: + - function_name_identifier: LOWER + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: x + - array_accessor: + - start_square_bracket: '[' + - numeric_literal: '2' + - end_square_bracket: ']' + - end_bracket: ) - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/rollback.sql b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/rollback.sql new file mode 100644 index 000000000..77013a810 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/rollback.sql @@ -0,0 +1,3 @@ +ROLLBACK; + +ROLLBACK WORK; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/rollback.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/rollback.yml new file mode 100644 index 000000000..3eb95ee93 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/rollback.yml @@ -0,0 +1,10 @@ +file: +- statement: + - transaction_statement: + - keyword: ROLLBACK +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: ROLLBACK + - keyword: WORK +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/row_datatype.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/row_datatype.yml index 6b28deb31..212c778e1 100644 --- a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/row_datatype.yml +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/row_datatype.yml @@ -31,20 +31,25 @@ file: - end_bracket: ) - keyword: AS - data_type: - - keyword: ROW - - bracketed: - - start_bracket: ( - - parameter: price - - data_type: - - keyword: REAL - - comma: ',' - - parameter: store - - data_type: - - keyword: VARCHAR - - end_bracket: ) + - struct_type: + - keyword: ROW + - struct_type_schema: + - bracketed: + - start_bracket: ( + - parameter: price + - data_type: + - primitive_type: + - keyword: REAL + - comma: ',' + - parameter: store + - data_type: + - primitive_type: + - keyword: VARCHAR + - end_bracket: ) - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: data_row - from_clause: - keyword: FROM @@ -81,18 +86,23 @@ file: - end_bracket: ) - keyword: AS - data_type: - - keyword: ROW - - bracketed: - - start_bracket: ( - - parameter: x - - data_type: - - keyword: BIGINT - - comma: ',' - - parameter: y - - data_type: - - keyword: DOUBLE - - end_bracket: ) + - struct_type: + - keyword: ROW + - struct_type_schema: + - bracketed: + - start_bracket: ( + - parameter: x + - data_type: + - primitive_type: + - keyword: BIGINT + - comma: ',' + - parameter: y + - data_type: + - primitive_type: + - keyword: DOUBLE + - end_bracket: ) - end_bracket: ) - - dot: . - - naked_identifier: x + - semi_structured_expression: + - dot: . + - naked_identifier: x - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/set_session.sql b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/set_session.sql new file mode 100644 index 000000000..379bc0ef0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/set_session.sql @@ -0,0 +1,3 @@ +SET SESSION name = 'expression'; + +SET SESSION catalog.value = 100; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/set_session.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/set_session.yml new file mode 100644 index 000000000..e80f091e9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/set_session.yml @@ -0,0 +1,23 @@ +file: +- statement: + - set_session_statement: + - keyword: SET + - keyword: SESSION + - parameter: name + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''expression''' +- statement_terminator: ; +- statement: + - set_session_statement: + - keyword: SET + - keyword: SESSION + - parameter: catalog + - dot: . + - parameter: value + - comparison_operator: + - raw_comparison_operator: = + - expression: + - numeric_literal: '100' +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/start_transaction.sql b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/start_transaction.sql new file mode 100644 index 000000000..a3d42ead8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/start_transaction.sql @@ -0,0 +1,5 @@ +START TRANSACTION; +START TRANSACTION ISOLATION LEVEL REPEATABLE READ; +START TRANSACTION READ WRITE; +START TRANSACTION ISOLATION LEVEL READ COMMITTED, READ ONLY; +START TRANSACTION READ WRITE, ISOLATION LEVEL SERIALIZABLE; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/start_transaction.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/start_transaction.yml new file mode 100644 index 000000000..6ddb5134e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/start_transaction.yml @@ -0,0 +1,45 @@ +file: +- statement: + - transaction_statement: + - keyword: START + - keyword: TRANSACTION +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: START + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: REPEATABLE + - keyword: READ +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: START + - keyword: TRANSACTION + - keyword: READ + - keyword: WRITE +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: START + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: READ + - keyword: COMMITTED + - comma: ',' + - keyword: READ + - keyword: ONLY +- statement_terminator: ; +- statement: + - transaction_statement: + - keyword: START + - keyword: TRANSACTION + - keyword: READ + - keyword: WRITE + - comma: ',' + - keyword: ISOLATION + - keyword: LEVEL + - keyword: SERIALIZABLE +- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/timestamp_resolutions.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/timestamp_resolutions.yml index 8d2c57e0d..fb1e7b8f8 100644 --- a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/timestamp_resolutions.yml +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/timestamp_resolutions.yml @@ -19,7 +19,8 @@ file: - end_bracket: ) - keyword: AS - data_type: - - keyword: TIMESTAMP + - primitive_type: + - keyword: TIMESTAMP - end_bracket: ) - statement_terminator: ; - statement: @@ -42,11 +43,13 @@ file: - end_bracket: ) - keyword: AS - data_type: - - keyword: TIMESTAMP - - bracketed: - - start_bracket: ( - - numeric_literal: '0' - - end_bracket: ) + - primitive_type: + - keyword: TIMESTAMP + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '0' + - end_bracket: ) - end_bracket: ) - statement_terminator: ; - statement: @@ -69,11 +72,13 @@ file: - end_bracket: ) - keyword: AS - data_type: - - keyword: TIMESTAMP - - bracketed: - - start_bracket: ( - - numeric_literal: '12' - - end_bracket: ) + - primitive_type: + - keyword: TIMESTAMP + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '12' + - end_bracket: ) - end_bracket: ) - statement_terminator: ; - statement: @@ -96,10 +101,11 @@ file: - end_bracket: ) - keyword: AS - data_type: - - keyword: TIMESTAMP - - keyword: WITH - - keyword: TIME - - keyword: ZONE + - primitive_type: + - keyword: TIMESTAMP + - keyword: WITH + - keyword: TIME + - keyword: ZONE - end_bracket: ) - statement_terminator: ; - statement: @@ -122,10 +128,11 @@ file: - end_bracket: ) - keyword: AS - data_type: - - keyword: TIMESTAMP - - keyword: WITHOUT - - keyword: TIME - - keyword: ZONE + - primitive_type: + - keyword: TIMESTAMP + - keyword: WITHOUT + - keyword: TIME + - keyword: ZONE - end_bracket: ) - statement_terminator: ; - statement: @@ -148,14 +155,16 @@ file: - end_bracket: ) - keyword: AS - data_type: - - keyword: TIMESTAMP - - bracketed: - - start_bracket: ( - - numeric_literal: '6' - - end_bracket: ) - - keyword: WITH - - keyword: TIME - - keyword: ZONE + - primitive_type: + - keyword: TIMESTAMP + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '6' + - end_bracket: ) + - keyword: WITH + - keyword: TIME + - keyword: ZONE - end_bracket: ) - statement_terminator: ; - statement: @@ -178,13 +187,15 @@ file: - end_bracket: ) - keyword: AS - data_type: - - keyword: TIMESTAMP - - bracketed: - - start_bracket: ( - - numeric_literal: '6' - - end_bracket: ) - - keyword: WITHOUT - - keyword: TIME - - keyword: ZONE + - primitive_type: + - keyword: TIMESTAMP + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - numeric_literal: '6' + - end_bracket: ) + - keyword: WITHOUT + - keyword: TIME + - keyword: ZONE - end_bracket: ) - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/unnest_with_ordinality.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/unnest_with_ordinality.yml index bf0eeb45d..bff17beb5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/unnest_with_ordinality.yml +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/unnest_with_ordinality.yml @@ -23,7 +23,8 @@ file: - quoted_literal: '''c''' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: array_column - end_bracket: ) - select_statement: @@ -64,10 +65,12 @@ file: - dot: . - naked_identifier: array_column - end_bracket: ) - - keyword: WITH - - keyword: ORDINALITY + - withordinality_clause: + - keyword: WITH + - keyword: ORDINALITY - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: u - bracketed: - start_bracket: ( @@ -101,7 +104,8 @@ file: - quoted_literal: '''c''' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: array_column - end_bracket: ) - select_statement: @@ -142,8 +146,9 @@ file: - dot: . - naked_identifier: array_column - end_bracket: ) - - keyword: WITH - - keyword: ORDINALITY + - withordinality_clause: + - keyword: WITH + - keyword: ORDINALITY - alias_expression: - naked_identifier: u - bracketed: @@ -178,7 +183,8 @@ file: - quoted_literal: '''c''' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: array_column - end_bracket: ) - select_statement: @@ -219,8 +225,9 @@ file: - dot: . - naked_identifier: array_column - end_bracket: ) - - keyword: WITH - - keyword: ORDINALITY + - withordinality_clause: + - keyword: WITH + - keyword: ORDINALITY - alias_expression: - naked_identifier: u - bracketed: @@ -255,7 +262,8 @@ file: - quoted_literal: '''c''' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: array_column1 - comma: ',' - select_clause_element: @@ -269,7 +277,8 @@ file: - numeric_literal: '2' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: array_column2 - end_bracket: ) - select_statement: @@ -322,10 +331,12 @@ file: - dot: . - naked_identifier: array_column2 - end_bracket: ) - - keyword: WITH - - keyword: ORDINALITY + - withordinality_clause: + - keyword: WITH + - keyword: ORDINALITY - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: u - bracketed: - start_bracket: ( @@ -359,7 +370,8 @@ file: - numeric_literal: '2' - end_square_bracket: ']' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: array_column - end_bracket: ) - select_statement: @@ -395,7 +407,8 @@ file: - naked_identifier: array_column - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: u - bracketed: - start_bracket: ( diff --git a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/within_group.yml b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/within_group.yml index 79e2e0a0d..b67ddc680 100644 --- a/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/within_group.yml +++ b/crates/lib-dialects/test/fixtures/dialects/trino/sqlfluff/within_group.yml @@ -17,16 +17,17 @@ file: - expression: - quoted_literal: ''',''' - end_bracket: ) - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: value - - end_bracket: ) + - withingroup_clause: + - keyword: WITHIN + - keyword: GROUP + - bracketed: + - start_bracket: ( + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: value + - end_bracket: ) - alias_expression: - naked_identifier: csv_value - from_clause: @@ -72,20 +73,22 @@ file: - comma: ',' - expression: - quoted_literal: ''',''' - - keyword: ON - - keyword: OVERFLOW - - keyword: ERROR + - listagg_overflow_clause: + - keyword: ON + - keyword: OVERFLOW + - keyword: ERROR + - end_bracket: ) + - withingroup_clause: + - keyword: WITHIN + - keyword: GROUP + - bracketed: + - start_bracket: ( + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: value - end_bracket: ) - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: value - - end_bracket: ) - alias_expression: - naked_identifier: csv_value - from_clause: @@ -131,23 +134,25 @@ file: - comma: ',' - expression: - quoted_literal: ''',''' - - keyword: ON - - keyword: OVERFLOW - - keyword: TRUNCATE - - quoted_identifier: '''.....''' - - keyword: WITH - - keyword: COUNT + - listagg_overflow_clause: + - keyword: ON + - keyword: OVERFLOW + - keyword: TRUNCATE + - quoted_literal: '''.....''' + - keyword: WITH + - keyword: COUNT + - end_bracket: ) + - withingroup_clause: + - keyword: WITHIN + - keyword: GROUP + - bracketed: + - start_bracket: ( + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: value - end_bracket: ) - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: value - - end_bracket: ) - from_clause: - keyword: FROM - from_expression: @@ -196,16 +201,17 @@ file: - expression: - quoted_literal: ''',''' - end_bracket: ) - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: o - - end_bracket: ) + - withingroup_clause: + - keyword: WITHIN + - keyword: GROUP + - bracketed: + - start_bracket: ( + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: o + - end_bracket: ) - alias_expression: - naked_identifier: csv_value - from_clause: @@ -291,29 +297,31 @@ file: - expression: - quoted_literal: ''',''' - end_bracket: ) - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: o - - end_bracket: ) - - keyword: FILTER - - bracketed: - - start_bracket: ( - - keyword: WHERE - - expression: - - column_reference: - - naked_identifier: o - - keyword: IS - - keyword: NOT - - null_literal: 'NULL' - - end_bracket: ) + - withingroup_clause: + - keyword: WITHIN + - keyword: GROUP + - bracketed: + - start_bracket: ( + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: o + - end_bracket: ) + - keyword: FILTER + - bracketed: + - start_bracket: ( + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: o + - keyword: IS + - keyword: NOT + - null_literal: 'NULL' + - end_bracket: ) - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: csv_value - from_clause: - keyword: FROM diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/.sqlfluff b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/.sqlfluff new file mode 100644 index 000000000..be4c41cc0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/.sqlfluff @@ -0,0 +1,2 @@ +[sqlfluff] +dialect = tsql diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/add_index.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/add_index.sql new file mode 100644 index 000000000..5e40a243d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/add_index.sql @@ -0,0 +1,80 @@ +IF NOT EXISTS(SELECT * FROM sys.indexes WHERE NAME='IX_INTER_VIMR_INFECTIOUS_PEOPLE') + CREATE NONCLUSTERED INDEX IX_INTER_VIMR_INFECTIOUS_PEOPLE + ON dbo.VIMR_INFECTIOUS_PEOPLE(DATE_LAST_INSERTED); +GO + +IF NOT EXISTS(SELECT * FROM sys.indexes WHERE NAME='IX_INTER_FOUNDATION_NICE_IC_INTAKE_COUNT') + CREATE NONCLUSTERED INDEX IX_INTER_FOUNDATION_NICE_IC_INTAKE_COUNT + ON dbo.FOUNDATION_NICE_IC_INTAKE_COUNT(DATE_LAST_INSERTED); +GO + +IF EXISTS(SELECT * FROM sys.indexes WHERE NAME='IX_INTER_VIMR_REPRODUCTION_NUMBER') + CREATE CLUSTERED INDEX IX_INTER_VIMR_REPRODUCTION_NUMBER + ON dbo.VIMR_INFECTIOUS_PEOPLE(DATE_LAST_INSERTED); +GO + +CREATE NONCLUSTERED INDEX [ind_1] + ON [schema1].[table1]([column1] ASC) + INCLUDE([column2]) WHERE ([column3] IS NULL); +GO + +CREATE NONCLUSTERED INDEX [NI_name] + ON [schema1].[table1]([column1] DESC) + ON [PRIMARY]; +GO + +CREATE UNIQUE INDEX [ix_name] + ON [schema1].[table1]([column1], [column2]) + WITH FILLFACTOR = 80; +GO + +CREATE UNIQUE INDEX [ix_name] + ON [schema1].[table1]([column1]) + WITH (PAD_INDEX = OFF, SORT_IN_TEMPDB = ON); + +CREATE UNIQUE INDEX [ix_name] + ON [schema1].[table1]([column1]) + WITH (ONLINE = ON); +GO + +CREATE UNIQUE INDEX [ix_name] + ON [schema1].[table1]([column1]) + WITH (ONLINE = ON (WAIT_AT_LOW_PRIORITY ( MAX_DURATION = 5 MINUTES, + ABORT_AFTER_WAIT = NONE ) ) ); + +GO +CREATE UNIQUE INDEX [ix_name] + ON [schema1].[table1]([column1]) + WITH DATA_COMPRESSION = ROW ON PARTITIONS (2, 4, 6 TO 8) +GO + + +CREATE STATISTICS Stats_Population ON [Reporting].[Population] +([ID],[Facility],[Population]) + +GO + +UPDATE STATISTICS Reporting.Population Stats_Population; + +GO + +UPDATE STATISTICS Reporting.Population (Stats_Facility, Stats_Population); + +GO + +UPDATE STATISTICS Reporting.Population (Stats_Facility, Stats_Population) WITH FULLSCAN; + +GO + +UPDATE STATISTICS Reporting.Population (Stats_Facility, Stats_Population) WITH RESAMPLE; + +GO + +DROP STATISTICS Reporting.Population.Stats_Population + +GO + +DROP INDEX IX_INTER_VIMR_REPRODUCTION_NUMBER + ON dbo.VIMR_INFECTIOUS_PEOPLE; + +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/add_index.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/add_index.yml new file mode 100644 index 000000000..ddcd3e7c4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/add_index.yml @@ -0,0 +1,544 @@ +file: +- batch: + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - keyword: NOT + - keyword: EXISTS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sys + - dot: . + - naked_identifier: indexes + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''IX_INTER_VIMR_INFECTIOUS_PEOPLE''' + - end_bracket: ) + - statement: + - create_index_statement: + - keyword: CREATE + - keyword: NONCLUSTERED + - keyword: INDEX + - index_reference: + - naked_identifier: IX_INTER_VIMR_INFECTIOUS_PEOPLE + - keyword: ON + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: VIMR_INFECTIOUS_PEOPLE + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: DATE_LAST_INSERTED + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - keyword: NOT + - keyword: EXISTS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sys + - dot: . + - naked_identifier: indexes + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''IX_INTER_FOUNDATION_NICE_IC_INTAKE_COUNT''' + - end_bracket: ) + - statement: + - create_index_statement: + - keyword: CREATE + - keyword: NONCLUSTERED + - keyword: INDEX + - index_reference: + - naked_identifier: IX_INTER_FOUNDATION_NICE_IC_INTAKE_COUNT + - keyword: ON + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: FOUNDATION_NICE_IC_INTAKE_COUNT + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: DATE_LAST_INSERTED + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - keyword: EXISTS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sys + - dot: . + - naked_identifier: indexes + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''IX_INTER_VIMR_REPRODUCTION_NUMBER''' + - end_bracket: ) + - statement: + - create_index_statement: + - keyword: CREATE + - keyword: CLUSTERED + - keyword: INDEX + - index_reference: + - naked_identifier: IX_INTER_VIMR_REPRODUCTION_NUMBER + - keyword: ON + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: VIMR_INFECTIOUS_PEOPLE + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: DATE_LAST_INSERTED + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_index_statement: + - keyword: CREATE + - keyword: NONCLUSTERED + - keyword: INDEX + - index_reference: + - quoted_identifier: '[ind_1]' + - keyword: ON + - table_reference: + - quoted_identifier: '[schema1]' + - dot: . + - quoted_identifier: '[table1]' + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - quoted_identifier: '[column1]' + - keyword: ASC + - end_bracket: ) + - keyword: INCLUDE + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[column2]' + - end_bracket: ) + - where_clause: + - keyword: WHERE + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '[column3]' + - keyword: IS + - null_literal: 'NULL' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_index_statement: + - keyword: CREATE + - keyword: NONCLUSTERED + - keyword: INDEX + - index_reference: + - quoted_identifier: '[NI_name]' + - keyword: ON + - table_reference: + - quoted_identifier: '[schema1]' + - dot: . + - quoted_identifier: '[table1]' + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - quoted_identifier: '[column1]' + - keyword: DESC + - end_bracket: ) + - on_partition_or_filegroup_statement: + - filegroup_clause: + - keyword: ON + - filegroup_name: + - quoted_identifier: '[PRIMARY]' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_index_statement: + - keyword: CREATE + - keyword: UNIQUE + - keyword: INDEX + - index_reference: + - quoted_identifier: '[ix_name]' + - keyword: ON + - table_reference: + - quoted_identifier: '[schema1]' + - dot: . + - quoted_identifier: '[table1]' + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - quoted_identifier: '[column1]' + - comma: ',' + - index_column_definition: + - quoted_identifier: '[column2]' + - end_bracket: ) + - relational_index_options: + - keyword: WITH + - keyword: FILLFACTOR + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '80' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_index_statement: + - keyword: CREATE + - keyword: UNIQUE + - keyword: INDEX + - index_reference: + - quoted_identifier: '[ix_name]' + - keyword: ON + - table_reference: + - quoted_identifier: '[schema1]' + - dot: . + - quoted_identifier: '[table1]' + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - quoted_identifier: '[column1]' + - end_bracket: ) + - relational_index_options: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: PAD_INDEX + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - comma: ',' + - keyword: SORT_IN_TEMPDB + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_index_statement: + - keyword: CREATE + - keyword: UNIQUE + - keyword: INDEX + - index_reference: + - quoted_identifier: '[ix_name]' + - keyword: ON + - table_reference: + - quoted_identifier: '[schema1]' + - dot: . + - quoted_identifier: '[table1]' + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - quoted_identifier: '[column1]' + - end_bracket: ) + - relational_index_options: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: ONLINE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_index_statement: + - keyword: CREATE + - keyword: UNIQUE + - keyword: INDEX + - index_reference: + - quoted_identifier: '[ix_name]' + - keyword: ON + - table_reference: + - quoted_identifier: '[schema1]' + - dot: . + - quoted_identifier: '[table1]' + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - quoted_identifier: '[column1]' + - end_bracket: ) + - relational_index_options: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: ONLINE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: WAIT_AT_LOW_PRIORITY + - bracketed: + - start_bracket: ( + - max_duration: + - keyword: MAX_DURATION + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '5' + - keyword: MINUTES + - comma: ',' + - keyword: ABORT_AFTER_WAIT + - comparison_operator: + - raw_comparison_operator: = + - keyword: NONE + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_index_statement: + - keyword: CREATE + - keyword: UNIQUE + - keyword: INDEX + - index_reference: + - quoted_identifier: '[ix_name]' + - keyword: ON + - table_reference: + - quoted_identifier: '[schema1]' + - dot: . + - quoted_identifier: '[table1]' + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - quoted_identifier: '[column1]' + - end_bracket: ) + - relational_index_options: + - keyword: WITH + - keyword: DATA_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ROW + - on_partitions_clause: + - keyword: ON + - keyword: PARTITIONS + - bracketed: + - start_bracket: ( + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '6' + - keyword: TO + - numeric_literal: '8' + - end_bracket: ) + - go_statement: + - keyword: GO +- batch: + - statement: + - create_index_statement: + - keyword: CREATE + - keyword: STATISTICS + - index_reference: + - naked_identifier: Stats_Population + - keyword: ON + - table_reference: + - quoted_identifier: '[Reporting]' + - dot: . + - quoted_identifier: '[Population]' + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - quoted_identifier: '[ID]' + - comma: ',' + - index_column_definition: + - quoted_identifier: '[Facility]' + - comma: ',' + - index_column_definition: + - quoted_identifier: '[Population]' + - end_bracket: ) + - go_statement: + - keyword: GO +- batch: + - statement: + - update_statistics_statement: + - keyword: UPDATE + - keyword: STATISTICS + - object_reference: + - naked_identifier: Reporting + - dot: . + - naked_identifier: Population + - naked_identifier: Stats_Population + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - update_statistics_statement: + - keyword: UPDATE + - keyword: STATISTICS + - object_reference: + - naked_identifier: Reporting + - dot: . + - naked_identifier: Population + - bracketed: + - start_bracket: ( + - naked_identifier: Stats_Facility + - comma: ',' + - naked_identifier: Stats_Population + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - update_statistics_statement: + - keyword: UPDATE + - keyword: STATISTICS + - object_reference: + - naked_identifier: Reporting + - dot: . + - naked_identifier: Population + - bracketed: + - start_bracket: ( + - naked_identifier: Stats_Facility + - comma: ',' + - naked_identifier: Stats_Population + - end_bracket: ) + - keyword: WITH + - keyword: FULLSCAN + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - update_statistics_statement: + - keyword: UPDATE + - keyword: STATISTICS + - object_reference: + - naked_identifier: Reporting + - dot: . + - naked_identifier: Population + - bracketed: + - start_bracket: ( + - naked_identifier: Stats_Facility + - comma: ',' + - naked_identifier: Stats_Population + - end_bracket: ) + - keyword: WITH + - keyword: RESAMPLE + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - drop_statement: + - keyword: DROP + - keyword: STATISTICS + - index_reference: + - naked_identifier: Reporting + - dot: . + - naked_identifier: Population + - dot: . + - naked_identifier: Stats_Population + - go_statement: + - keyword: GO +- batch: + - statement: + - drop_index_statement: + - keyword: DROP + - keyword: INDEX + - index_reference: + - naked_identifier: IX_INTER_VIMR_REPRODUCTION_NUMBER + - keyword: ON + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: VIMR_INFECTIOUS_PEOPLE + - statement_terminator: ; + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_alias_in_where_clause.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_alias_in_where_clause.sql deleted file mode 100644 index ab409d619..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_alias_in_where_clause.sql +++ /dev/null @@ -1,15 +0,0 @@ --- Test case for AL05: Alias used in WHERE clause with IN statement --- This tests that aliases used in complex WHERE conditions are properly detected -SELECT - COUNT(*) -FROM - schema1.Table_Sales_Position_Reference AS op2ref WITH(NOLOCK) - INNER JOIN schema1.TBL_POS_DATA AS Position WITH(NOLOCK) ON Position.I_POS_ID = op2ref.i_position_id - INNER JOIN schema1.TBL_POS_DATA AS PositionRef WITH(NOLOCK) ON PositionRef.I_POS_ID = op2ref.i_positionref_id -WHERE - -- Alias used in IN clause - OrderPositions.I_POS_ID IN (op2ref.i_position_id, op2ref.i_positionref_id) - -- Alias used in equality check - AND op2ref.i_referencetype_id = 1 - -- Alias used in IS NULL check - AND op2ref.dt_deleted IS NULL; \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_alias_in_where_clause.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_alias_in_where_clause.yml deleted file mode 100644 index 78b910581..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_alias_in_where_clause.yml +++ /dev/null @@ -1,130 +0,0 @@ -file: -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - function: - - function_name: - - function_name_identifier: COUNT - - function_contents: - - bracketed: - - start_bracket: ( - - star: '*' - - end_bracket: ) - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: schema1 - - dot: . - - naked_identifier: Table_Sales_Position_Reference - - alias_expression: - - keyword: AS - - naked_identifier: op2ref - - keyword: WITH - - bracketed: - - start_bracket: ( - - keyword: NOLOCK - - end_bracket: ) - - join_clause: - - keyword: INNER - - keyword: JOIN - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: schema1 - - dot: . - - naked_identifier: TBL_POS_DATA - - alias_expression: - - keyword: AS - - naked_identifier: Position - - keyword: WITH - - bracketed: - - start_bracket: ( - - keyword: NOLOCK - - end_bracket: ) - - join_on_condition: - - keyword: ON - - expression: - - column_reference: - - naked_identifier: Position - - dot: . - - naked_identifier: I_POS_ID - - comparison_operator: - - raw_comparison_operator: = - - column_reference: - - naked_identifier: op2ref - - dot: . - - naked_identifier: i_position_id - - join_clause: - - keyword: INNER - - keyword: JOIN - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: schema1 - - dot: . - - naked_identifier: TBL_POS_DATA - - alias_expression: - - keyword: AS - - naked_identifier: PositionRef - - keyword: WITH - - bracketed: - - start_bracket: ( - - keyword: NOLOCK - - end_bracket: ) - - join_on_condition: - - keyword: ON - - expression: - - column_reference: - - naked_identifier: PositionRef - - dot: . - - naked_identifier: I_POS_ID - - comparison_operator: - - raw_comparison_operator: = - - column_reference: - - naked_identifier: op2ref - - dot: . - - naked_identifier: i_positionref_id - - where_clause: - - keyword: WHERE - - expression: - - column_reference: - - naked_identifier: OrderPositions - - dot: . - - naked_identifier: I_POS_ID - - keyword: IN - - bracketed: - - start_bracket: ( - - column_reference: - - naked_identifier: op2ref - - dot: . - - naked_identifier: i_position_id - - comma: ',' - - column_reference: - - naked_identifier: op2ref - - dot: . - - naked_identifier: i_positionref_id - - end_bracket: ) - - binary_operator: AND - - column_reference: - - naked_identifier: op2ref - - dot: . - - naked_identifier: i_referencetype_id - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1' - - binary_operator: AND - - column_reference: - - naked_identifier: op2ref - - dot: . - - naked_identifier: dt_deleted - - keyword: IS - - null_literal: 'NULL' -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_exact_issue.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_exact_issue.sql deleted file mode 100644 index 5baade282..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_exact_issue.sql +++ /dev/null @@ -1,5 +0,0 @@ --- Exact reproduction of the AL05 issue -SELECT COUNT(*) -FROM schema1.Table_Sales_Position_Reference AS op2ref WITH(NOLOCK) -INNER JOIN schema1.TBL_POS_DATA AS Position WITH(NOLOCK) ON Position.I_POS_ID = op2ref.i_position_id -WHERE op2ref.i_referencetype_id = 1; \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_exact_issue.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_exact_issue.yml deleted file mode 100644 index 3652b3a14..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/al05_exact_issue.yml +++ /dev/null @@ -1,74 +0,0 @@ -file: -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - function: - - function_name: - - function_name_identifier: COUNT - - function_contents: - - bracketed: - - start_bracket: ( - - star: '*' - - end_bracket: ) - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: schema1 - - dot: . - - naked_identifier: Table_Sales_Position_Reference - - alias_expression: - - keyword: AS - - naked_identifier: op2ref - - keyword: WITH - - bracketed: - - start_bracket: ( - - keyword: NOLOCK - - end_bracket: ) - - join_clause: - - keyword: INNER - - keyword: JOIN - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: schema1 - - dot: . - - naked_identifier: TBL_POS_DATA - - alias_expression: - - keyword: AS - - naked_identifier: Position - - keyword: WITH - - bracketed: - - start_bracket: ( - - keyword: NOLOCK - - end_bracket: ) - - join_on_condition: - - keyword: ON - - expression: - - column_reference: - - naked_identifier: Position - - dot: . - - naked_identifier: I_POS_ID - - comparison_operator: - - raw_comparison_operator: = - - column_reference: - - naked_identifier: op2ref - - dot: . - - naked_identifier: i_position_id - - where_clause: - - keyword: WHERE - - expression: - - column_reference: - - naked_identifier: op2ref - - dot: . - - naked_identifier: i_referencetype_id - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1' -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alias_equals_syntax.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alias_equals_syntax.sql deleted file mode 100644 index 3c357c6d3..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alias_equals_syntax.sql +++ /dev/null @@ -1,3 +0,0 @@ -SELECT - TsqlAlias = SUM(quantity) -FROM table1 \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alias_standard_as.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alias_standard_as.sql deleted file mode 100644 index 5b9d7d201..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alias_standard_as.sql +++ /dev/null @@ -1,3 +0,0 @@ -SELECT - SUM(quantity) AS StandardAlias -FROM table1 \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_and_drop.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_and_drop.sql new file mode 100644 index 000000000..a3db32391 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_and_drop.sql @@ -0,0 +1,5 @@ +ALTER TABLE [REPORTING].[UN_NEW] SWITCH to [REPORTING].[UN_BASE] WITH (TRUNCATE_TARGET = ON); +DROP TABLE [REPORTING].[UN_NEW]; + +ALTER TABLE table_name +DROP COLUMN column1, column2; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_and_drop.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_and_drop.yml new file mode 100644 index 000000000..63ef4feac --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_and_drop.yml @@ -0,0 +1,48 @@ +file: +- batch: + - statement: + - alter_table_switch_statement: + - keyword: ALTER + - keyword: TABLE + - object_reference: + - quoted_identifier: '[REPORTING]' + - dot: . + - quoted_identifier: '[UN_NEW]' + - keyword: SWITCH + - keyword: to + - object_reference: + - quoted_identifier: '[REPORTING]' + - dot: . + - quoted_identifier: '[UN_BASE]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: TRUNCATE_TARGET + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - quoted_identifier: '[REPORTING]' + - dot: . + - quoted_identifier: '[UN_NEW]' + - statement_terminator: ; + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: table_name + - keyword: DROP + - keyword: COLUMN + - column_reference: + - naked_identifier: column1 + - comma: ',' + - column_reference: + - naked_identifier: column2 + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_database.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_database.sql new file mode 100644 index 000000000..9f329065a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_database.sql @@ -0,0 +1,110 @@ +-- Rename database +ALTER DATABASE AdventureWorks2022 +Modify Name = Northwind ; +GO + +ALTER DATABASE db1 + MODIFY Name = db2 ; + +ALTER DATABASE CURRENT + MODIFY Name = db2 ; + +-- Change collation +ALTER DATABASE testDB +COLLATE French_CI_AI ; +GO + +--Change Recovery Model +ALTER DATABASE testDB +SET RECOVERY FULL ; +GO + +ALTER DATABASE testDB + SET RECOVERY SIMPLE ; +GO + +ALTER DATABASE [testDB] +SET RECOVERY BULK_LOGGED ; +GO + +-- Add file +ALTER DATABASE WideWorldImporters + ADD FILE (NAME = 'data_17'); + +-- change database options using SET +ALTER DATABASE CustomerSales + SET AUTO_CREATE_STATISTICS ON; + +ALTER DATABASE CustomerSales + SET AUTO_UPDATE_STATISTICS ON; + +ALTER DATABASE CURRENT + SET AUTO_UPDATE_STATISTICS_ASYNC ON; + +-- Add / remove secondary database +ALTER DATABASE db1 +ADD SECONDARY ON SERVER secondaryserver; + +ALTER DATABASE db1 +ADD SECONDARY ON SERVER secondaryserver +WITH ( ALLOW_CONNECTIONS = ALL ); + +ALTER DATABASE db1 +REMOVE SECONDARY ON SERVER testsecondaryserver; + +-- Initiate failover +ALTER DATABASE db1 FAILOVER; + +ALTER DATABASE db1 FORCE_FAILOVER_ALLOW_DATA_LOSS; + +ALTER DATABASE [mySampleDatabase] PERFORM_CUTOVER; + +-- Modify database options using MODIFY +ALTER DATABASE current + MODIFY (EDITION = 'Premium'); + +ALTER DATABASE db1 + MODIFY (SERVICE_OBJECTIVE = 'P6'); + +ALTER DATABASE dw1 MODIFY ( MAXSIZE=10240 GB ); + +ALTER DATABASE [db1] + MODIFY (EDITION = 'Standard', MAXSIZE = 250 GB, SERVICE_OBJECTIVE = 'S0'); + +ALTER DATABASE db1 + MODIFY ( SERVICE_OBJECTIVE = ELASTIC_POOL ( name = pool1 ) ) ; + +ALTER DATABASE [mySampleDatabase] + MODIFY (EDITION = 'Hyperscale', SERVICE_OBJECTIVE = 'HS_Gen5_2') + WITH MANUAL_CUTOVER; + +ALTER DATABASE db1 + MODIFY BACKUP_STORAGE_REDUNDANCY = 'ZONE'; + +ALTER DATABASE CustomerSales + SET ( AUTOGROW = ON ); + +ALTER DATABASE CustomerSales + SET ( REPLICATED_SIZE = 1 GB ); + +ALTER DATABASE CustomerSales + SET ( DISTRIBUTED_SIZE = 1000 GB ); + +ALTER DATABASE CustomerSales + SET ( LOG_SIZE = 10 GB ); + +ALTER DATABASE CustomerSales + SET ( AUTOGROW = ON, LOG_SIZE = 10 GB ); + +ALTER DATABASE [DatabaseName] SET MULTI_USER; +ALTER DATABASE [DatabaseName] SET QUOTED_IDENTIFIER ON; +ALTER DATABASE [DatabaseName] SET RECURSIVE_TRIGGERS OFF; +ALTER DATABASE [DatabaseName] SET DISABLE_BROKER; +ALTER DATABASE [DatabaseName] SET PAGE_VERIFY NONE; +ALTER DATABASE [DatabaseName] SET DELAYED_DURABILITY = DISABLED; +ALTER DATABASE [DatabaseName] SET QUERY_STORE = OFF; +ALTER DATABASE [DatabaseName] SET READ_WRITE; +ALTER DATABASE [DatabaseName] SET FILESTREAM +( + NON_TRANSACTED_ACCESS = OFF +); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_database.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_database.yml new file mode 100644 index 000000000..26323d6b7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_database.yml @@ -0,0 +1,532 @@ +file: +- batch: + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: AdventureWorks2022 + - keyword: Modify + - keyword: Name + - comparison_operator: + - raw_comparison_operator: = + - database_reference: + - naked_identifier: Northwind + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: db1 + - keyword: MODIFY + - keyword: Name + - comparison_operator: + - raw_comparison_operator: = + - database_reference: + - naked_identifier: db2 + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - keyword: CURRENT + - keyword: MODIFY + - keyword: Name + - comparison_operator: + - raw_comparison_operator: = + - database_reference: + - naked_identifier: db2 + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: testDB + - keyword: COLLATE + - collation_reference: + - naked_identifier: French_CI_AI + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: testDB + - keyword: SET + - keyword: RECOVERY + - keyword: FULL + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: testDB + - keyword: SET + - keyword: RECOVERY + - keyword: SIMPLE + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[testDB]' + - keyword: SET + - keyword: RECOVERY + - keyword: BULK_LOGGED + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: WideWorldImporters + - keyword: ADD + - keyword: FILE + - file_spec: + - bracketed: + - start_bracket: ( + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''data_17''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: CustomerSales + - keyword: SET + - auto_option: + - keyword: AUTO_CREATE_STATISTICS + - keyword: ON + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: CustomerSales + - keyword: SET + - auto_option: + - keyword: AUTO_UPDATE_STATISTICS + - keyword: ON + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - keyword: CURRENT + - keyword: SET + - auto_option: + - keyword: AUTO_UPDATE_STATISTICS_ASYNC + - keyword: ON + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: db1 + - keyword: ADD + - keyword: SECONDARY + - keyword: ON + - keyword: SERVER + - naked_identifier: secondaryserver + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: db1 + - keyword: ADD + - keyword: SECONDARY + - keyword: ON + - keyword: SERVER + - naked_identifier: secondaryserver + - keyword: WITH + - bracketed: + - start_bracket: ( + - allow_connections: + - keyword: ALLOW_CONNECTIONS + - comparison_operator: + - raw_comparison_operator: = + - keyword: ALL + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: db1 + - keyword: REMOVE + - keyword: SECONDARY + - keyword: ON + - keyword: SERVER + - naked_identifier: testsecondaryserver + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: db1 + - keyword: FAILOVER + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: db1 + - keyword: FORCE_FAILOVER_ALLOW_DATA_LOSS + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[mySampleDatabase]' + - keyword: PERFORM_CUTOVER + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - keyword: current + - keyword: MODIFY + - bracketed: + - start_bracket: ( + - edition: + - keyword: EDITION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Premium''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: db1 + - keyword: MODIFY + - bracketed: + - start_bracket: ( + - service_objective: + - keyword: SERVICE_OBJECTIVE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''P6''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: dw1 + - keyword: MODIFY + - bracketed: + - start_bracket: ( + - file_spec_max_size: + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10240' + - keyword: GB + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[db1]' + - keyword: MODIFY + - bracketed: + - start_bracket: ( + - edition: + - keyword: EDITION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Standard''' + - comma: ',' + - file_spec_max_size: + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '250' + - keyword: GB + - comma: ',' + - service_objective: + - keyword: SERVICE_OBJECTIVE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''S0''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: db1 + - keyword: MODIFY + - bracketed: + - start_bracket: ( + - service_objective: + - keyword: SERVICE_OBJECTIVE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ELASTIC_POOL + - bracketed: + - start_bracket: ( + - keyword: name + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: pool1 + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[mySampleDatabase]' + - keyword: MODIFY + - bracketed: + - start_bracket: ( + - edition: + - keyword: EDITION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Hyperscale''' + - comma: ',' + - service_objective: + - keyword: SERVICE_OBJECTIVE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''HS_Gen5_2''' + - end_bracket: ) + - keyword: WITH + - keyword: MANUAL_CUTOVER + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: db1 + - keyword: MODIFY + - backup_storage_redundancy: + - keyword: BACKUP_STORAGE_REDUNDANCY + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''ZONE''' + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: CustomerSales + - keyword: SET + - bracketed: + - start_bracket: ( + - naked_identifier: AUTOGROW + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: CustomerSales + - keyword: SET + - bracketed: + - start_bracket: ( + - naked_identifier: REPLICATED_SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - keyword: GB + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: CustomerSales + - keyword: SET + - bracketed: + - start_bracket: ( + - naked_identifier: DISTRIBUTED_SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1000' + - keyword: GB + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: CustomerSales + - keyword: SET + - bracketed: + - start_bracket: ( + - naked_identifier: LOG_SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - keyword: GB + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - naked_identifier: CustomerSales + - keyword: SET + - bracketed: + - start_bracket: ( + - naked_identifier: AUTOGROW + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - comma: ',' + - naked_identifier: LOG_SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - keyword: GB + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[DatabaseName]' + - keyword: SET + - naked_identifier: MULTI_USER + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[DatabaseName]' + - keyword: SET + - naked_identifier: QUOTED_IDENTIFIER + - keyword: ON + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[DatabaseName]' + - keyword: SET + - naked_identifier: RECURSIVE_TRIGGERS + - keyword: OFF + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[DatabaseName]' + - keyword: SET + - naked_identifier: DISABLE_BROKER + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[DatabaseName]' + - keyword: SET + - naked_identifier: PAGE_VERIFY + - keyword: NONE + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[DatabaseName]' + - keyword: SET + - naked_identifier: DELAYED_DURABILITY + - comparison_operator: + - raw_comparison_operator: = + - keyword: DISABLED + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[DatabaseName]' + - keyword: SET + - naked_identifier: QUERY_STORE + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[DatabaseName]' + - keyword: SET + - naked_identifier: READ_WRITE + - statement_terminator: ; + - statement: + - alter_database_statement: + - keyword: ALTER + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[DatabaseName]' + - keyword: SET + - keyword: FILESTREAM + - bracketed: + - start_bracket: ( + - keyword: NON_TRANSACTED_ACCESS + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_index.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_index.sql new file mode 100644 index 000000000..37ab3c78a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_index.sql @@ -0,0 +1,75 @@ +ALTER INDEX index1 ON table1 REBUILD; + +ALTER INDEX ALL ON table1 REBUILD; + +ALTER INDEX idxcci_cci_target ON cci_target REORGANIZE WITH (COMPRESS_ALL_ROW_GROUPS = ON); + +ALTER INDEX cci_FactInternetSales2 ON FactInternetSales2 REORGANIZE; + +ALTER INDEX cci_FactInternetSales2 ON FactInternetSales2 REORGANIZE PARTITION = 0; + +ALTER INDEX cci_FactInternetSales2 ON FactInternetSales2 REORGANIZE WITH (COMPRESS_ALL_ROW_GROUPS = ON); + +ALTER INDEX cci_FactInternetSales2 ON FactInternetSales2 REORGANIZE PARTITION = 0 WITH (COMPRESS_ALL_ROW_GROUPS = ON); + +ALTER INDEX cci_FactInternetSales2 ON FactInternetSales2 REORGANIZE; + +ALTER INDEX cci_fact3ON ON fact3 REBUILD PARTITION = 12; + +ALTER INDEX cci_SimpleTable ON SimpleTable +REBUILD +WITH (DATA_COMPRESSION = COLUMNSTORE_ARCHIVE); + +ALTER INDEX cci_SimpleTable ON SimpleTable +REBUILD +WITH (DATA_COMPRESSION = COLUMNSTORE); + +ALTER INDEX PK_ProductPhoto_ProductPhotoID ON Production.ProductPhoto REORGANIZE WITH (LOB_COMPACTION = ON); + +ALTER INDEX IX_Employee_ManagerID ON HumanResources.Employee DISABLE; + +ALTER INDEX IX_INDEX1 +ON T1 +REBUILD +WITH (XML_COMPRESSION = ON); + +ALTER INDEX ALL ON Production.Product +REBUILD WITH (FILLFACTOR = 80, SORT_IN_TEMPDB = ON, STATISTICS_NORECOMPUTE = ON); + +ALTER INDEX test_idx on test_table REBUILD WITH (ONLINE = ON, MAXDOP = 1, RESUMABLE = ON); + +ALTER INDEX test_idx on test_table PAUSE; + +ALTER INDEX test_idx on test_table ABORT; + +ALTER INDEX test_idx on test_table +REBUILD WITH (XML_COMPRESSION = ON ON PARTITIONS (2, 4, 6 TO 8)); + +ALTER INDEX test_idx on test_table +REBUILD WITH (DATA_COMPRESSION = PAGE ON PARTITIONS (3, 5)); + +ALTER INDEX test_idx on test_table +REBUILD WITH (DATA_COMPRESSION = NONE ON PARTITIONS (1)); + +ALTER INDEX IX_TransactionHistory_TransactionDate ON Production.TransactionHistory +REBUILD Partition = 5 + WITH (ONLINE = ON (WAIT_AT_LOW_PRIORITY (MAX_DURATION = 10, ABORT_AFTER_WAIT = SELF))); + + +ALTER INDEX cci_FactInternetSales2 ON FactInternetSales2 SET (ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = OFF); + +ALTER INDEX cci_FactInternetSales2 ON FactInternetSales2 SET (OPTIMIZE_FOR_SEQUENTIAL_KEY = ON, +IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = ON); + +ALTER INDEX cci_FactInternetSales2 ON FactInternetSales2 SET (COMPRESSION_DELAY = 0); + +ALTER INDEX cci_FactInternetSales2 ON FactInternetSales2 SET (COMPRESSION_DELAY = 100 minutes); + +ALTER INDEX cci_FactInternetSales2 ON FactInternetSales2 RESUME; + +ALTER INDEX cci_FactInternetSales2 ON FactInternetSales2 RESUME WITH (MAXDOP = 100, MAX_DURATION = 500 minutes, +WAIT_AT_LOW_PRIORITY (MAX_DURATION = 10, ABORT_AFTER_WAIT = SELF)); + +ALTER INDEX cci_FactInternetSales2 ON FactInternetSales2 RESUME WITH (MAX_DURATION = 500); + +ALTER INDEX cci_FactInternetSales2 ON FactInternetSales2 RESUME WITH (WAIT_AT_LOW_PRIORITY (MAX_DURATION = 10, ABORT_AFTER_WAIT = SELF)); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_index.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_index.yml new file mode 100644 index 000000000..9fd566398 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_index.yml @@ -0,0 +1,617 @@ +file: +- batch: + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: index1 + - keyword: ON + - table_reference: + - naked_identifier: table1 + - keyword: REBUILD + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - keyword: ALL + - keyword: ON + - table_reference: + - naked_identifier: table1 + - keyword: REBUILD + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: idxcci_cci_target + - keyword: ON + - table_reference: + - naked_identifier: cci_target + - keyword: REORGANIZE + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: COMPRESS_ALL_ROW_GROUPS + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_FactInternetSales2 + - keyword: ON + - table_reference: + - naked_identifier: FactInternetSales2 + - keyword: REORGANIZE + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_FactInternetSales2 + - keyword: ON + - table_reference: + - naked_identifier: FactInternetSales2 + - keyword: REORGANIZE + - keyword: PARTITION + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_FactInternetSales2 + - keyword: ON + - table_reference: + - naked_identifier: FactInternetSales2 + - keyword: REORGANIZE + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: COMPRESS_ALL_ROW_GROUPS + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_FactInternetSales2 + - keyword: ON + - table_reference: + - naked_identifier: FactInternetSales2 + - keyword: REORGANIZE + - keyword: PARTITION + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: COMPRESS_ALL_ROW_GROUPS + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_FactInternetSales2 + - keyword: ON + - table_reference: + - naked_identifier: FactInternetSales2 + - keyword: REORGANIZE + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_fact3ON + - keyword: ON + - table_reference: + - naked_identifier: fact3 + - keyword: REBUILD + - keyword: PARTITION + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '12' + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_SimpleTable + - keyword: ON + - table_reference: + - naked_identifier: SimpleTable + - keyword: REBUILD + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: DATA_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - keyword: COLUMNSTORE_ARCHIVE + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_SimpleTable + - keyword: ON + - table_reference: + - naked_identifier: SimpleTable + - keyword: REBUILD + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: DATA_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - keyword: COLUMNSTORE + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: PK_ProductPhoto_ProductPhotoID + - keyword: ON + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ProductPhoto + - keyword: REORGANIZE + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: LOB_COMPACTION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: IX_Employee_ManagerID + - keyword: ON + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: Employee + - keyword: DISABLE + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: IX_INDEX1 + - keyword: ON + - table_reference: + - naked_identifier: T1 + - keyword: REBUILD + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: XML_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - keyword: ALL + - keyword: ON + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: Product + - keyword: REBUILD + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FILLFACTOR + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '80' + - comma: ',' + - keyword: SORT_IN_TEMPDB + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - comma: ',' + - keyword: STATISTICS_NORECOMPUTE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: test_idx + - keyword: on + - table_reference: + - naked_identifier: test_table + - keyword: REBUILD + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: ONLINE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - comma: ',' + - keyword: MAXDOP + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - comma: ',' + - keyword: RESUMABLE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: test_idx + - keyword: on + - table_reference: + - naked_identifier: test_table + - keyword: PAUSE + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: test_idx + - keyword: on + - table_reference: + - naked_identifier: test_table + - keyword: ABORT + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: test_idx + - keyword: on + - table_reference: + - naked_identifier: test_table + - keyword: REBUILD + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: XML_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - keyword: ON + - keyword: PARTITIONS + - bracketed: + - start_bracket: ( + - numeric_literal: '2' + - comma: ',' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '6' + - keyword: TO + - numeric_literal: '8' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: test_idx + - keyword: on + - table_reference: + - naked_identifier: test_table + - keyword: REBUILD + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: DATA_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - keyword: PAGE + - keyword: ON + - keyword: PARTITIONS + - bracketed: + - start_bracket: ( + - numeric_literal: '3' + - comma: ',' + - numeric_literal: '5' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: test_idx + - keyword: on + - table_reference: + - naked_identifier: test_table + - keyword: REBUILD + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: DATA_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - keyword: NONE + - keyword: ON + - keyword: PARTITIONS + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: IX_TransactionHistory_TransactionDate + - keyword: ON + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: TransactionHistory + - keyword: REBUILD + - keyword: Partition + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '5' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: ONLINE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: WAIT_AT_LOW_PRIORITY + - bracketed: + - start_bracket: ( + - keyword: MAX_DURATION + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - comma: ',' + - keyword: ABORT_AFTER_WAIT + - comparison_operator: + - raw_comparison_operator: = + - keyword: SELF + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_FactInternetSales2 + - keyword: ON + - table_reference: + - naked_identifier: FactInternetSales2 + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: ALLOW_ROW_LOCKS + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - comma: ',' + - keyword: ALLOW_PAGE_LOCKS + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_FactInternetSales2 + - keyword: ON + - table_reference: + - naked_identifier: FactInternetSales2 + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: OPTIMIZE_FOR_SEQUENTIAL_KEY + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - comma: ',' + - keyword: IGNORE_DUP_KEY + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - comma: ',' + - keyword: STATISTICS_NORECOMPUTE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_FactInternetSales2 + - keyword: ON + - table_reference: + - naked_identifier: FactInternetSales2 + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: COMPRESSION_DELAY + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_FactInternetSales2 + - keyword: ON + - table_reference: + - naked_identifier: FactInternetSales2 + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: COMPRESSION_DELAY + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '100' + - keyword: minutes + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_FactInternetSales2 + - keyword: ON + - table_reference: + - naked_identifier: FactInternetSales2 + - keyword: RESUME + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_FactInternetSales2 + - keyword: ON + - table_reference: + - naked_identifier: FactInternetSales2 + - keyword: RESUME + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: MAXDOP + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '100' + - comma: ',' + - keyword: MAX_DURATION + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '500' + - keyword: minutes + - comma: ',' + - keyword: WAIT_AT_LOW_PRIORITY + - bracketed: + - start_bracket: ( + - keyword: MAX_DURATION + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - comma: ',' + - keyword: ABORT_AFTER_WAIT + - comparison_operator: + - raw_comparison_operator: = + - keyword: SELF + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_FactInternetSales2 + - keyword: ON + - table_reference: + - naked_identifier: FactInternetSales2 + - keyword: RESUME + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: MAX_DURATION + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '500' + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_index_statement: + - keyword: ALTER + - keyword: INDEX + - object_reference: + - naked_identifier: cci_FactInternetSales2 + - keyword: ON + - table_reference: + - naked_identifier: FactInternetSales2 + - keyword: RESUME + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: WAIT_AT_LOW_PRIORITY + - bracketed: + - start_bracket: ( + - keyword: MAX_DURATION + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - comma: ',' + - keyword: ABORT_AFTER_WAIT + - comparison_operator: + - raw_comparison_operator: = + - keyword: SELF + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table.sql new file mode 100644 index 000000000..5008210a9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table.sql @@ -0,0 +1,163 @@ +CREATE TABLE dbo.doc_exa (column_a INT) ; +GO +ALTER TABLE dbo.doc_exa ADD column_b VARCHAR(20) NULL ; +GO + +CREATE TABLE dbo.doc_exc (column_a INT) ; +GO +ALTER TABLE dbo.doc_exc ADD column_b VARCHAR(20) NULL + CONSTRAINT exb_unique UNIQUE, DROP COLUMN column_a, DROP COLUMN IF EXISTS column_c ; +GO +EXEC sp_help doc_exc ; +GO +DROP TABLE dbo.doc_exc ; +GO + + +CREATE TABLE dbo.doc_exz (column_a INT, column_b INT) ; +GO +INSERT INTO dbo.doc_exz (column_a) VALUES (7) ; +GO +ALTER TABLE dbo.doc_exz + ADD CONSTRAINT col_b_def + DEFAULT 50 FOR column_b ; +GO +INSERT INTO dbo.doc_exz (column_a) VALUES (10) ; +GO +SELECT * FROM dbo.doc_exz ; +GO +DROP TABLE dbo.doc_exz ; +GO + + +ALTER TABLE Production.TransactionHistoryArchive +ADD CONSTRAINT PK_TransactionHistoryArchive_TransactionID PRIMARY KEY CLUSTERED (TransactionID) +GO + +ALTER TABLE Production.TransactionHistoryArchive +ALTER COLUMN rec_number VARCHAR(36) +GO + +ALTER TABLE Production.TransactionHistoryArchive +DROP CONSTRAINT PK_TransactionHistoryArchive_TransactionID + +ALTER TABLE Production.TransactionHistoryArchive +DROP CONSTRAINT IF EXISTS PK_TransactionHistoryArchive_TransactionID + +ALTER TABLE [Production].[ProductCostHistory] +WITH CHECK ADD CONSTRAINT [FK_ProductCostHistory_Product_ProductID] FOREIGN KEY([ProductID]) +REFERENCES [Production].[Product] ([ProductID]) +GO + +ALTER TABLE [Production].[ProductCostHistory] +CHECK CONSTRAINT [FK_ProductCostHistory_Product_ProductID] +GO + +ALTER TABLE [Production].[ProductCostHistory] +CHECK CONSTRAINT [FK_ProductCostHistory_Product_ProductID] + +ALTER TABLE Purchasing.PurchaseOrderHeader +NOCHECK CONSTRAINT FK_PurchaseOrderHeader_Employee_EmployeeID; + +ALTER TABLE [dbo].[Attachment] +WITH CHECK +CHECK CONSTRAINT [FK_Attachment_EmailMessage]; + +ALTER TABLE [dbo].[Attachment] +WITH CHECK +NOCHECK CONSTRAINT [FK_Attachment_EmailMessage]; + +ALTER TABLE [dbo].[Attachment] +WITH NOCHECK +NOCHECK CONSTRAINT [FK_Attachment_EmailMessage]; + +ALTER TABLE [dbo].[Attachment] +WITH NOCHECK +CHECK CONSTRAINT [FK_Attachment_EmailMessage]; + +ALTER TABLE my_table +ADD my_col_1 INT + , my_col_2 INT +GO + +ALTER TABLE TestTable SET (SYSTEM_VERSIONING = ON); GO +ALTER TABLE TestTable SET (SYSTEM_VERSIONING = OFF); GO + +ALTER TABLE TestTable SET + (SYSTEM_VERSIONING = OFF ( + HISTORY_TABLE = TestTableHistory + )); +GO + +ALTER TABLE TestTable SET + (SYSTEM_VERSIONING = OFF ( + HISTORY_TABLE = TestTableHistory, + DATA_CONSISTENCY_CHECK = ON + )); +GO + +ALTER TABLE TestTable SET + (SYSTEM_VERSIONING = OFF ( + HISTORY_TABLE = TestTableHistory, + DATA_CONSISTENCY_CHECK = ON, + HISTORY_RETENTION_PERIOD = INFINITE + )); +GO + +ALTER TABLE TestTable SET + (SYSTEM_VERSIONING = OFF ( + HISTORY_TABLE = TestTableHistory, + DATA_CONSISTENCY_CHECK = ON, + HISTORY_RETENTION_PERIOD = 1 YEAR + )); +GO + +ALTER TABLE TestTable SET + (SYSTEM_VERSIONING = OFF ( + HISTORY_TABLE = TestTableHistory, + DATA_CONSISTENCY_CHECK = ON, + HISTORY_RETENTION_PERIOD = 7 MONTHS + )); +GO + +ALTER TABLE TestTable SET (FILESTREAM_ON = "NULL"); GO +ALTER TABLE TestTable SET (FILESTREAM_ON = "default"); GO +ALTER TABLE TestTable SET (FILESTREAM_ON = PartitionSchemeName); GO +ALTER TABLE TestTable SET (DATA_DELETION = ON); GO +ALTER TABLE TestTable SET (DATA_DELETION = OFF(FILTER_COLUMN = ColumnName)); GO +ALTER TABLE TestTable SET (DATA_DELETION = OFF(FILTER_COLUMN = ColumnName, RETENTION_PERIOD = 1 YEAR)); GO +ALTER TABLE TestTable SET (DATA_DELETION = OFF(FILTER_COLUMN = ColumnName, RETENTION_PERIOD = INFINITE)); GO +ALTER TABLE TestTable SET (DATA_DELETION = OFF(FILTER_COLUMN = ColumnName, RETENTION_PERIOD = 7 YEARS)); GO +ALTER TABLE TestTable SET (DATA_DELETION = OFF(FILTER_COLUMN = ColumnName, RETENTION_PERIOD = 7 DAYS)); GO + +-- computed columm +-- https://learn.microsoft.com/en-us/sql/relational-databases/tables/specify-computed-columns-in-a-table?view=sql-server-ver16 +ALTER TABLE dbo.Products ADD RetailValue AS [QtyAvailable] * UnitPrice * 1.5 PERSISTED; GO +ALTER TABLE dbo.Products ADD RetailValue AS (QtyAvailable * [UnitPrice] * 1.5) PERSISTED NOT NULL; GO +ALTER TABLE dbo.Products ADD InventoyDate AS CAST([InventoryTs] AS date); GO + +ALTER TABLE [HangFire].[JobParameter] +ADD CONSTRAINT [FK_HangFire_JobParameter_Job] +FOREIGN KEY ([JobId]) +REFERENCES [HangFire].[Job] ([Id]) +ON UPDATE CASCADE +ON DELETE CASCADE; GO + +-- Drop multiple columns in one statement +ALTER TABLE UserData DROP COLUMN [StrSkill], [StrItem], [StrSerial]; +ALTER TABLE UserData DROP COLUMN IF EXISTS StrSkill, StrItem, StrSerial; + +-- Check hexadecimal defaults in constraints +CREATE TABLE [dbo].[UserData] ( + [strUserId] [char](21) NOT NULL, + [strItem] [binary](400) NULL, + [strSkill] [binary](400) NULL, + CONSTRAINT PK_UserData PRIMARY KEY CLUSTERED ([strUserId] ASC) +); + +ALTER TABLE [dbo].[UserData] +ADD CONSTRAINT [DF_UserData_strSkill] DEFAULT (0x00) FOR [strSkill]; +GO + +ALTER TABLE [TestTable] DROP PERIOD FOR SYSTEM_TIME; +ALTER TABLE [TestTable] ADD PERIOD FOR SYSTEM_TIME (StartDate, EndDate); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table.yml new file mode 100644 index 000000000..e876dc21b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table.yml @@ -0,0 +1,1194 @@ +file: +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: doc_exa + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: column_a + - data_type: + - keyword: INT + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: doc_exa + - keyword: ADD + - column_definition: + - naked_identifier: column_b + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '20' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: doc_exc + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: column_a + - data_type: + - keyword: INT + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: doc_exc + - keyword: ADD + - column_definition: + - naked_identifier: column_b + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '20' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - column_constraint_segment: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: exb_unique + - keyword: UNIQUE + - comma: ',' + - keyword: DROP + - keyword: COLUMN + - column_reference: + - naked_identifier: column_a + - comma: ',' + - keyword: DROP + - keyword: COLUMN + - keyword: IF + - keyword: EXISTS + - column_reference: + - naked_identifier: column_c + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - execute_script_statement: + - keyword: EXEC + - object_reference: + - naked_identifier: sp_help + - expression: + - column_reference: + - naked_identifier: doc_exc + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: doc_exc + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: doc_exz + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: column_a + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: column_b + - data_type: + - keyword: INT + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: doc_exz + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: column_a + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - integer_literal: '7' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: doc_exz + - keyword: ADD + - column_constraint_segment: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: col_b_def + - keyword: DEFAULT + - integer_literal: '50' + - keyword: FOR + - column_reference: + - naked_identifier: column_b + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: doc_exz + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: column_a + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - integer_literal: '10' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: doc_exz + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: doc_exz + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: TransactionHistoryArchive + - keyword: ADD + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: PK_TransactionHistoryArchive_TransactionID + - keyword: PRIMARY + - keyword: KEY + - keyword: CLUSTERED + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: TransactionID + - end_bracket: ) + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: TransactionHistoryArchive + - keyword: ALTER + - keyword: COLUMN + - column_definition: + - naked_identifier: rec_number + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '36' + - end_bracket: ) + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: TransactionHistoryArchive + - keyword: DROP + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: PK_TransactionHistoryArchive_TransactionID + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: TransactionHistoryArchive + - keyword: DROP + - keyword: CONSTRAINT + - keyword: IF + - keyword: EXISTS + - object_reference: + - naked_identifier: PK_TransactionHistoryArchive_TransactionID + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '[Production]' + - dot: . + - quoted_identifier: '[ProductCostHistory]' + - keyword: WITH + - keyword: CHECK + - keyword: ADD + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - quoted_identifier: '[FK_ProductCostHistory_Product_ProductID]' + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[ProductID]' + - end_bracket: ) + - references_constraint_grammar: + - keyword: REFERENCES + - table_reference: + - quoted_identifier: '[Production]' + - dot: . + - quoted_identifier: '[Product]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[ProductID]' + - end_bracket: ) + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '[Production]' + - dot: . + - quoted_identifier: '[ProductCostHistory]' + - keyword: CHECK + - keyword: CONSTRAINT + - object_reference: + - quoted_identifier: '[FK_ProductCostHistory_Product_ProductID]' + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '[Production]' + - dot: . + - quoted_identifier: '[ProductCostHistory]' + - keyword: CHECK + - keyword: CONSTRAINT + - object_reference: + - quoted_identifier: '[FK_ProductCostHistory_Product_ProductID]' + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: Purchasing + - dot: . + - naked_identifier: PurchaseOrderHeader + - keyword: NOCHECK + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: FK_PurchaseOrderHeader_Employee_EmployeeID + - statement_terminator: ; + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[Attachment]' + - keyword: WITH + - keyword: CHECK + - keyword: CHECK + - keyword: CONSTRAINT + - object_reference: + - quoted_identifier: '[FK_Attachment_EmailMessage]' + - statement_terminator: ; + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[Attachment]' + - keyword: WITH + - keyword: CHECK + - keyword: NOCHECK + - keyword: CONSTRAINT + - object_reference: + - quoted_identifier: '[FK_Attachment_EmailMessage]' + - statement_terminator: ; + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[Attachment]' + - keyword: WITH + - keyword: NOCHECK + - keyword: NOCHECK + - keyword: CONSTRAINT + - object_reference: + - quoted_identifier: '[FK_Attachment_EmailMessage]' + - statement_terminator: ; + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[Attachment]' + - keyword: WITH + - keyword: NOCHECK + - keyword: CHECK + - keyword: CONSTRAINT + - object_reference: + - quoted_identifier: '[FK_Attachment_EmailMessage]' + - statement_terminator: ; + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: my_table + - keyword: ADD + - column_definition: + - naked_identifier: my_col_1 + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: my_col_2 + - data_type: + - keyword: INT + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - bracketed: + - start_bracket: ( + - keyword: HISTORY_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - naked_identifier: TestTableHistory + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - bracketed: + - start_bracket: ( + - keyword: HISTORY_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - naked_identifier: TestTableHistory + - comma: ',' + - keyword: DATA_CONSISTENCY_CHECK + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - bracketed: + - start_bracket: ( + - keyword: HISTORY_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - naked_identifier: TestTableHistory + - comma: ',' + - keyword: DATA_CONSISTENCY_CHECK + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - comma: ',' + - keyword: HISTORY_RETENTION_PERIOD + - comparison_operator: + - raw_comparison_operator: = + - date_part: INFINITE + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - bracketed: + - start_bracket: ( + - keyword: HISTORY_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - naked_identifier: TestTableHistory + - comma: ',' + - keyword: DATA_CONSISTENCY_CHECK + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - comma: ',' + - keyword: HISTORY_RETENTION_PERIOD + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - date_part: YEAR + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - bracketed: + - start_bracket: ( + - keyword: HISTORY_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - naked_identifier: TestTableHistory + - comma: ',' + - keyword: DATA_CONSISTENCY_CHECK + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - comma: ',' + - keyword: HISTORY_RETENTION_PERIOD + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '7' + - date_part: MONTHS + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: FILESTREAM_ON + - comparison_operator: + - raw_comparison_operator: = + - filegroup_name: + - quoted_identifier: '"NULL"' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: FILESTREAM_ON + - comparison_operator: + - raw_comparison_operator: = + - filegroup_name: + - quoted_identifier: '"default"' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: FILESTREAM_ON + - comparison_operator: + - raw_comparison_operator: = + - filegroup_name: + - naked_identifier: PartitionSchemeName + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: DATA_DELETION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: DATA_DELETION + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - bracketed: + - start_bracket: ( + - keyword: FILTER_COLUMN + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: ColumnName + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: DATA_DELETION + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - bracketed: + - start_bracket: ( + - keyword: FILTER_COLUMN + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: ColumnName + - comma: ',' + - keyword: RETENTION_PERIOD + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - date_part: YEAR + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: DATA_DELETION + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - bracketed: + - start_bracket: ( + - keyword: FILTER_COLUMN + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: ColumnName + - comma: ',' + - keyword: RETENTION_PERIOD + - comparison_operator: + - raw_comparison_operator: = + - date_part: INFINITE + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: DATA_DELETION + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - bracketed: + - start_bracket: ( + - keyword: FILTER_COLUMN + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: ColumnName + - comma: ',' + - keyword: RETENTION_PERIOD + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '7' + - date_part: YEARS + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: TestTable + - keyword: SET + - bracketed: + - start_bracket: ( + - keyword: DATA_DELETION + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - bracketed: + - start_bracket: ( + - keyword: FILTER_COLUMN + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: ColumnName + - comma: ',' + - keyword: RETENTION_PERIOD + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '7' + - date_part: DAYS + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Products + - keyword: ADD + - computed_column_definition: + - naked_identifier: RetailValue + - keyword: AS + - expression: + - column_reference: + - quoted_identifier: '[QtyAvailable]' + - binary_operator: '*' + - column_reference: + - naked_identifier: UnitPrice + - binary_operator: '*' + - numeric_literal: '1.5' + - keyword: PERSISTED + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Products + - keyword: ADD + - computed_column_definition: + - naked_identifier: RetailValue + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: QtyAvailable + - binary_operator: '*' + - column_reference: + - quoted_identifier: '[UnitPrice]' + - binary_operator: '*' + - numeric_literal: '1.5' + - end_bracket: ) + - keyword: PERSISTED + - keyword: NOT + - keyword: 'NULL' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Products + - keyword: ADD + - computed_column_definition: + - naked_identifier: InventoyDate + - keyword: AS + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '[InventoryTs]' + - keyword: AS + - data_type: + - keyword: date + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '[HangFire]' + - dot: . + - quoted_identifier: '[JobParameter]' + - keyword: ADD + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - quoted_identifier: '[FK_HangFire_JobParameter_Job]' + - keyword: FOREIGN + - keyword: KEY + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[JobId]' + - end_bracket: ) + - references_constraint_grammar: + - keyword: REFERENCES + - table_reference: + - quoted_identifier: '[HangFire]' + - dot: . + - quoted_identifier: '[Job]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[Id]' + - end_bracket: ) + - keyword: ON + - keyword: UPDATE + - keyword: CASCADE + - keyword: ON + - keyword: DELETE + - keyword: CASCADE + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: UserData + - keyword: DROP + - keyword: COLUMN + - column_reference: + - quoted_identifier: '[StrSkill]' + - comma: ',' + - column_reference: + - quoted_identifier: '[StrItem]' + - comma: ',' + - column_reference: + - quoted_identifier: '[StrSerial]' + - statement_terminator: ; + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - naked_identifier: UserData + - keyword: DROP + - keyword: COLUMN + - keyword: IF + - keyword: EXISTS + - column_reference: + - naked_identifier: StrSkill + - comma: ',' + - column_reference: + - naked_identifier: StrItem + - comma: ',' + - column_reference: + - naked_identifier: StrSerial + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[UserData]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[strUserId]' + - data_type: + - data_type_identifier: '[char]' + - bracketed: + - start_bracket: ( + - numeric_literal: '21' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - quoted_identifier: '[strItem]' + - data_type: + - data_type_identifier: '[binary]' + - bracketed: + - start_bracket: ( + - numeric_literal: '400' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - quoted_identifier: '[strSkill]' + - data_type: + - data_type_identifier: '[binary]' + - bracketed: + - start_bracket: ( + - numeric_literal: '400' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: PK_UserData + - keyword: PRIMARY + - keyword: KEY + - keyword: CLUSTERED + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - quoted_identifier: '[strUserId]' + - keyword: ASC + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[UserData]' + - keyword: ADD + - column_constraint_segment: + - keyword: CONSTRAINT + - object_reference: + - quoted_identifier: '[DF_UserData_strSkill]' + - keyword: DEFAULT + - bracketed: + - start_bracket: ( + - binary_literal: '0x00' + - end_bracket: ) + - keyword: FOR + - column_reference: + - quoted_identifier: '[strSkill]' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '[TestTable]' + - keyword: DROP + - period_segment: + - keyword: PERIOD + - keyword: FOR + - keyword: SYSTEM_TIME + - statement_terminator: ; + - statement: + - alter_table_statement: + - keyword: ALTER + - keyword: TABLE + - table_reference: + - quoted_identifier: '[TestTable]' + - keyword: ADD + - period_segment: + - keyword: PERIOD + - keyword: FOR + - keyword: SYSTEM_TIME + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: StartDate + - comma: ',' + - column_reference: + - naked_identifier: EndDate + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table_switch.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table_switch.sql new file mode 100644 index 000000000..be1f143b2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table_switch.sql @@ -0,0 +1,17 @@ +--TRUNCATE_TARGET is Azure Synapse Analytics specific +ALTER TABLE [Facility].[PL_stage] SWITCH TO [Facility].[PL_BASE] WITH (TRUNCATE_TARGET = ON); + +-- https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-table-transact-sql +ALTER TABLE [PartitionTable] SWITCH PARTITION 1 TO NonPartitionTable; + +ALTER TABLE Orders SWITCH PARTITION 2 TO [OrdersHistory] PARTITION 2; + +ALTER TABLE Orders SWITCH PARTITION 3 TO [OrdersHistory] PARTITION 3; + +ALTER TABLE Orders SWITCH PARTITION 4 TO [OrdersHistory] PARTITION 4 WITH ( + WAIT_AT_LOW_PRIORITY ( MAX_DURATION = 15 MINUTES, ABORT_AFTER_WAIT = NONE ) +); + +ALTER TABLE Orders SWITCH PARTITION 5 TO [OrdersHistory] PARTITION 5 WITH ( + WAIT_AT_LOW_PRIORITY ( MAX_DURATION = 25, ABORT_AFTER_WAIT = SELF ) +); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table_switch.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table_switch.yml new file mode 100644 index 000000000..6e85500d8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/alter_table_switch.yml @@ -0,0 +1,133 @@ +file: +- batch: + - statement: + - alter_table_switch_statement: + - keyword: ALTER + - keyword: TABLE + - object_reference: + - quoted_identifier: '[Facility]' + - dot: . + - quoted_identifier: '[PL_stage]' + - keyword: SWITCH + - keyword: TO + - object_reference: + - quoted_identifier: '[Facility]' + - dot: . + - quoted_identifier: '[PL_BASE]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: TRUNCATE_TARGET + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_table_switch_statement: + - keyword: ALTER + - keyword: TABLE + - object_reference: + - quoted_identifier: '[PartitionTable]' + - keyword: SWITCH + - keyword: PARTITION + - numeric_literal: '1' + - keyword: TO + - object_reference: + - naked_identifier: NonPartitionTable + - statement_terminator: ; + - statement: + - alter_table_switch_statement: + - keyword: ALTER + - keyword: TABLE + - object_reference: + - naked_identifier: Orders + - keyword: SWITCH + - keyword: PARTITION + - numeric_literal: '2' + - keyword: TO + - object_reference: + - quoted_identifier: '[OrdersHistory]' + - keyword: PARTITION + - numeric_literal: '2' + - statement_terminator: ; + - statement: + - alter_table_switch_statement: + - keyword: ALTER + - keyword: TABLE + - object_reference: + - naked_identifier: Orders + - keyword: SWITCH + - keyword: PARTITION + - numeric_literal: '3' + - keyword: TO + - object_reference: + - quoted_identifier: '[OrdersHistory]' + - keyword: PARTITION + - numeric_literal: '3' + - statement_terminator: ; + - statement: + - alter_table_switch_statement: + - keyword: ALTER + - keyword: TABLE + - object_reference: + - naked_identifier: Orders + - keyword: SWITCH + - keyword: PARTITION + - numeric_literal: '4' + - keyword: TO + - object_reference: + - quoted_identifier: '[OrdersHistory]' + - keyword: PARTITION + - numeric_literal: '4' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: WAIT_AT_LOW_PRIORITY + - bracketed: + - start_bracket: ( + - keyword: MAX_DURATION + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '15' + - keyword: MINUTES + - comma: ',' + - keyword: ABORT_AFTER_WAIT + - comparison_operator: + - raw_comparison_operator: = + - keyword: NONE + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_table_switch_statement: + - keyword: ALTER + - keyword: TABLE + - object_reference: + - naked_identifier: Orders + - keyword: SWITCH + - keyword: PARTITION + - numeric_literal: '5' + - keyword: TO + - object_reference: + - quoted_identifier: '[OrdersHistory]' + - keyword: PARTITION + - numeric_literal: '5' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: WAIT_AT_LOW_PRIORITY + - bracketed: + - start_bracket: ( + - keyword: MAX_DURATION + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '25' + - comma: ',' + - keyword: ABORT_AFTER_WAIT + - comparison_operator: + - raw_comparison_operator: = + - keyword: SELF + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_simple.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_simple.sql deleted file mode 100644 index 07fddff91..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_simple.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT a FROM t1 CROSS APPLY t2 \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_simple.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_simple.yml deleted file mode 100644 index fd41c2f53..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_simple.yml +++ /dev/null @@ -1,24 +0,0 @@ -file: -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: a - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: t1 - - join_clause: - - keyword: CROSS - - keyword: APPLY - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: t2 diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_with_alias.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_with_alias.sql deleted file mode 100644 index c085bb57a..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_with_alias.sql +++ /dev/null @@ -1,14 +0,0 @@ --- Test case for APPLY clause with table alias -SELECT - c.CustomerID, - c.CustomerName, - Orders.TotalAmount -FROM - Customers AS c - OUTER APPLY ( - SELECT TotalAmount = SUM(o.Amount) - FROM Orders AS o - WHERE o.CustomerID = c.CustomerID - ) AS Orders -WHERE - c.Active = 1 \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_with_alias.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_with_alias.yml deleted file mode 100644 index 6ae5a9706..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/apply_with_alias.yml +++ /dev/null @@ -1,96 +0,0 @@ -file: -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: c - - dot: . - - naked_identifier: CustomerID - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: c - - dot: . - - naked_identifier: CustomerName - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: Orders - - dot: . - - naked_identifier: TotalAmount - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: Customers - - alias_expression: - - keyword: AS - - naked_identifier: c - - join_clause: - - keyword: OUTER - - keyword: APPLY - - from_expression_element: - - table_expression: - - bracketed: - - start_bracket: ( - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - naked_identifier: TotalAmount - - raw_comparison_operator: = - - function: - - function_name: - - function_name_identifier: SUM - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: o - - dot: . - - naked_identifier: Amount - - end_bracket: ) - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: Orders - - alias_expression: - - keyword: AS - - naked_identifier: o - - where_clause: - - keyword: WHERE - - expression: - - column_reference: - - naked_identifier: o - - dot: . - - naked_identifier: CustomerID - - comparison_operator: - - raw_comparison_operator: = - - column_reference: - - naked_identifier: c - - dot: . - - naked_identifier: CustomerID - - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: Orders - - where_clause: - - keyword: WHERE - - expression: - - column_reference: - - naked_identifier: c - - dot: . - - naked_identifier: Active - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1' diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/arithmetic_operations.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/arithmetic_operations.sql new file mode 100644 index 000000000..be05b2747 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/arithmetic_operations.sql @@ -0,0 +1,11 @@ +DECLARE @I INT = 0; +SELECT @I + 1; +SELECT @I += 2; +SELECT @I - 3; +SELECT @I -= 4; +SELECT @I * 5; +SELECT @I *= 6; +SELECT @I / 7; +SELECT @I /= 8; +SELECT @I % 9; +SELECT @I %= 10; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/arithmetic_operations.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/arithmetic_operations.yml new file mode 100644 index 000000000..f15893b1a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/arithmetic_operations.yml @@ -0,0 +1,128 @@ +file: +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@I' + - data_type: + - keyword: INT + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '0' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - parameter: '@I' + - binary_operator: + + - integer_literal: '1' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - select_variable_assignment: + - parameter: '@I' + - assignment_operator: + - binary_operator: + + - raw_comparison_operator: = + - expression: + - integer_literal: '2' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - parameter: '@I' + - binary_operator: '-' + - integer_literal: '3' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - select_variable_assignment: + - parameter: '@I' + - assignment_operator: + - binary_operator: '-' + - raw_comparison_operator: = + - expression: + - integer_literal: '4' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - parameter: '@I' + - binary_operator: '*' + - integer_literal: '5' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - select_variable_assignment: + - parameter: '@I' + - assignment_operator: + - binary_operator: '*' + - raw_comparison_operator: = + - expression: + - integer_literal: '6' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - parameter: '@I' + - binary_operator: / + - integer_literal: '7' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - select_variable_assignment: + - parameter: '@I' + - assignment_operator: + - binary_operator: / + - raw_comparison_operator: = + - expression: + - integer_literal: '8' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - parameter: '@I' + - binary_operator: '%' + - integer_literal: '9' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - select_variable_assignment: + - parameter: '@I' + - assignment_operator: + - binary_operator: '%' + - raw_comparison_operator: = + - expression: + - integer_literal: '10' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end.sql new file mode 100644 index 000000000..9a9b8d6ba --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end.sql @@ -0,0 +1,15 @@ +BEGIN + SELECT 'Weekend'; +END + +BEGIN; + SELECT 'Weekend'; +END; + +BEGIN; + SELECT 'Weekend'; +END + +BEGIN + SELECT 'Weekend'; +END; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end.yml new file mode 100644 index 000000000..3d1d0d9f3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end.yml @@ -0,0 +1,50 @@ +file: +- batch: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''Weekend''' + - statement_terminator: ; + - keyword: END + - statement: + - begin_end_block: + - keyword: BEGIN + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''Weekend''' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - statement: + - begin_end_block: + - keyword: BEGIN + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''Weekend''' + - statement_terminator: ; + - keyword: END + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''Weekend''' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_block.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_block.sql deleted file mode 100644 index d8f979d72..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_block.sql +++ /dev/null @@ -1,4 +0,0 @@ -BEGIN - SELECT * FROM customers; - UPDATE customers SET status = 'Active'; -END \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_block.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_block.yml deleted file mode 100644 index f357a207f..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_block.yml +++ /dev/null @@ -1,34 +0,0 @@ -file: -- statement: - - keyword: BEGIN - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - wildcard_expression: - - wildcard_identifier: - - star: '*' - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: customers - - statement_terminator: ; - - update_statement: - - keyword: UPDATE - - table_reference: - - object_reference: - - naked_identifier: customers - - set_clause_list: - - keyword: SET - - set_clause: - - column_reference: - - naked_identifier: status - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''Active''' - - statement_terminator: ; - - keyword: END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_nested.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_nested.sql new file mode 100644 index 000000000..9bddb74d1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_nested.sql @@ -0,0 +1,5 @@ +BEGIN + BEGIN + SELECT 'Weekend'; + END +END; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_nested.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_nested.yml new file mode 100644 index 000000000..c42e428fb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_nested.yml @@ -0,0 +1,18 @@ +file: +- batch: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''Weekend''' + - statement_terminator: ; + - keyword: END + - keyword: END + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_no_semicolon.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_no_semicolon.sql new file mode 100644 index 000000000..b05520546 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_no_semicolon.sql @@ -0,0 +1,3 @@ +BEGIN + SELECT 1 +END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_no_semicolon.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_no_semicolon.yml new file mode 100644 index 000000000..2cb988909 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/begin_end_no_semicolon.yml @@ -0,0 +1,12 @@ +file: +- batch: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - keyword: END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants.sql new file mode 100644 index 000000000..d33bba2f5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants.sql @@ -0,0 +1,17 @@ +-- T-SQL binary constants test cases +-- Test basic binary constants parsing +select 0x0; +select 0xAE; +select 0x12Ef; +select 0x69048AEFDD010E; +select 0x; + +-- Test mixed case +select 0X0; +select 0XAE; + +-- Test multiple constants in one query +select 0x0, 0xAE, 0x12Ef; + +-- Test with old-style x'...' format +select x'FF', X'DEAD'; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants.yml new file mode 100644 index 000000000..bbc314a65 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants.yml @@ -0,0 +1,74 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - binary_literal: '0x0' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - binary_literal: '0xAE' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - binary_literal: '0x12Ef' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - binary_literal: '0x69048AEFDD010E' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - binary_literal: 0x + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - binary_literal: 0X0 + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - binary_literal: 0XAE + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - binary_literal: '0x0' + - comma: ',' + - select_clause_element: + - binary_literal: '0xAE' + - comma: ',' + - select_clause_element: + - binary_literal: '0x12Ef' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - numeric_literal: x'FF' + - comma: ',' + - select_clause_element: + - numeric_literal: X'DEAD' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_functions.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_functions.sql new file mode 100644 index 000000000..f854a8f37 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_functions.sql @@ -0,0 +1,12 @@ +-- T-SQL binary constants function calls test cases +-- Function calls with binary constants +select CAST(0x0 as uniqueidentifier); +select CAST(0xAE as binary(2)); +select CAST(0x12Ef as varbinary(16)); + +-- Mixed cases with functions +select CAST(0X0 as uniqueidentifier); +select CONVERT(binary(4), 0x69048AEF); + +-- Empty binary constant in function +select CAST(0x as binary(1)); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_functions.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_functions.yml new file mode 100644 index 000000000..be9d6c41d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_functions.yml @@ -0,0 +1,134 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - binary_literal: '0x0' + - keyword: as + - data_type: + - keyword: uniqueidentifier + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - binary_literal: '0xAE' + - keyword: as + - data_type: + - keyword: binary + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '2' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - binary_literal: '0x12Ef' + - keyword: as + - data_type: + - keyword: varbinary + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '16' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - binary_literal: 0X0 + - keyword: as + - data_type: + - keyword: uniqueidentifier + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - keyword: CONVERT + - function_contents: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: binary + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '4' + - end_bracket: ) + - comma: ',' + - expression: + - binary_literal: '0x69048AEF' + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - binary_literal: 0x + - keyword: as + - data_type: + - keyword: binary + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '1' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_variables.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_variables.sql new file mode 100644 index 000000000..1958fe305 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_variables.sql @@ -0,0 +1,14 @@ +-- T-SQL binary constants variable assignment test cases +-- Variable assignment with binary constants +declare @var1 binary(1); +set @var1 = 0x0; + +declare @var2 binary(2); +set @var2 = 0xAE; + +declare @var3 binary(8); +set @var3 = 0x69048AEFDD010E; + +-- Empty binary constant +declare @var4 binary(16); +set @var4 = 0x; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_variables.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_variables.yml new file mode 100644 index 000000000..1b8d6dd7d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/binary_constants_variables.yml @@ -0,0 +1,90 @@ +file: +- batch: + - statement: + - declare_segment: + - keyword: declare + - parameter: '@var1' + - data_type: + - keyword: binary + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '1' + - end_bracket: ) + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: set + - parameter: '@var1' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - binary_literal: '0x0' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: declare + - parameter: '@var2' + - data_type: + - keyword: binary + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '2' + - end_bracket: ) + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: set + - parameter: '@var2' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - binary_literal: '0xAE' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: declare + - parameter: '@var3' + - data_type: + - keyword: binary + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '8' + - end_bracket: ) + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: set + - parameter: '@var3' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - binary_literal: '0x69048AEFDD010E' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: declare + - parameter: '@var4' + - data_type: + - keyword: binary + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '16' + - end_bracket: ) + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: set + - parameter: '@var4' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - binary_literal: 0x + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/bulk_insert.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/bulk_insert.sql new file mode 100644 index 000000000..4c9466e2a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/bulk_insert.sql @@ -0,0 +1,13 @@ +-- Plain BULK insert +BULK INSERT my_schema.my_table +FROM 'data.csv'; + +-- BULK insert with options +BULK INSERT my_schema.my_table +FROM 'data.csv' +WITH ( + BATCHSIZE = 1024, + CHECK_CONSTRAINTS, + ORDER (col1 ASC, col2 DESC), + FORMAT = 'CSV' +); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/bulk_insert.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/bulk_insert.yml new file mode 100644 index 000000000..d0319d9ea --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/bulk_insert.yml @@ -0,0 +1,52 @@ +file: +- batch: + - statement: + - bulk_insert_statement: + - keyword: BULK + - keyword: INSERT + - table_reference: + - naked_identifier: my_schema + - dot: . + - naked_identifier: my_table + - keyword: FROM + - quoted_literal: '''data.csv''' + - statement_terminator: ; + - statement: + - bulk_insert_statement: + - keyword: BULK + - keyword: INSERT + - table_reference: + - naked_identifier: my_schema + - dot: . + - naked_identifier: my_table + - keyword: FROM + - quoted_literal: '''data.csv''' + - bulk_insert_with_segment: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: BATCHSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1024' + - comma: ',' + - keyword: CHECK_CONSTRAINTS + - comma: ',' + - keyword: ORDER + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: col1 + - keyword: ASC + - comma: ',' + - column_reference: + - naked_identifier: col2 + - keyword: DESC + - end_bracket: ) + - comma: ',' + - keyword: FORMAT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''CSV''' + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cast_variable.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cast_variable.sql new file mode 100644 index 000000000..1c594b16c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cast_variable.sql @@ -0,0 +1,7 @@ +DECLARE @DateNow date = ISNULL(Shared.GetESTDateTime(GETDATE()), GETDATE()) + +select enc.personid as personid, + cast('1900-01-01' as datetime2(7)) as DataRefreshDate +from encounter enc; + + declare @sample nvarchar(max) = cast(100 as nvarchar(max)) diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cast_variable.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cast_variable.yml new file mode 100644 index 000000000..55e693a2e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cast_variable.yml @@ -0,0 +1,123 @@ +file: +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@DateNow' + - data_type: + - keyword: date + - comparison_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: ISNULL + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - naked_identifier: Shared + - dot: . + - function_name_identifier: GetESTDateTime + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: enc + - dot: . + - naked_identifier: personid + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: personid + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: cast + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''1900-01-01''' + - keyword: as + - data_type: + - keyword: datetime2 + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '7' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: DataRefreshDate + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: encounter + - alias_expression: + - naked_identifier: enc + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: declare + - parameter: '@sample' + - data_type: + - keyword: nvarchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: max + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - keyword: cast + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - keyword: as + - data_type: + - keyword: nvarchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: max + - end_bracket: ) + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/collate.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/collate.sql new file mode 100644 index 000000000..c0af73229 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/collate.sql @@ -0,0 +1,22 @@ +-- `COLLATE` in JOIN condition +SELECT table1.col +FROM table1 +INNER JOIN table2 + ON table1.col = table2.col COLLATE Latin1_GENERAL_CS_AS; + +SELECT table1.col +FROM table1 +INNER JOIN table2 + ON table1.col COLLATE Latin1_GENERAL_CS_AS = table2.col; + +-- `COLLATE` in ORDER BY clause +SELECT col +FROM my_table +ORDER BY col COLLATE Latin1_General_CS_AS_KS_WS DESC; + +-- `COLLATE` in SELECT +SELECT col COLLATE Latin1_General_CS_AS_KS_WS +FROM my_table; + +SELECT col COLLATE database_default +FROM my_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/collate.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/collate.yml new file mode 100644 index 000000000..8fcbcd994 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/collate.yml @@ -0,0 +1,145 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: col + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: table2 + - dot: . + - naked_identifier: col + - keyword: COLLATE + - collation_reference: + - naked_identifier: Latin1_GENERAL_CS_AS + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: col + - keyword: COLLATE + - collation_reference: + - naked_identifier: Latin1_GENERAL_CS_AS + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: table2 + - dot: . + - naked_identifier: col + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - orderby_clause: + - keyword: ORDER + - keyword: BY + - expression: + - column_reference: + - naked_identifier: col + - keyword: COLLATE + - collation_reference: + - naked_identifier: Latin1_General_CS_AS_KS_WS + - keyword: DESC + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: col + - keyword: COLLATE + - collation_reference: + - naked_identifier: Latin1_General_CS_AS_KS_WS + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: col + - keyword: COLLATE + - collation_reference: + - naked_identifier: database_default + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comment_blocks.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comment_blocks.sql index 9cbce247c..6865c37f6 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comment_blocks.sql +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comment_blocks.sql @@ -1,6 +1,3 @@ --- Test cases from sqlfluff for block comments --- These ensure we handle nested comments correctly - /* birds /* live /* in /* nests */ */ */fdsfdlsjf */ /* although @@ -26,4 +23,4 @@ nest nest /* */*/*/*/nest*/*/*/ FROM bar /** ' -**/ \ No newline at end of file +**/ diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comment_blocks.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comment_blocks.yml index 4fbc491ed..9be7f93fe 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comment_blocks.yml +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comment_blocks.yml @@ -1,16 +1,16 @@ file: -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: foo - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: foo + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: - naked_identifier: bar diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comprehensive_hash_identifiers.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comprehensive_hash_identifiers.sql deleted file mode 100644 index caf195fee..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comprehensive_hash_identifiers.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Comprehensive test for SQL Server 2017+ # suffix syntax - --- Simple SELECT with # identifiers -SELECT o#.id# FROM orders# o#; - --- Column alias with # -SELECT total AS amount# FROM orders#; \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comprehensive_hash_identifiers.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comprehensive_hash_identifiers.yml deleted file mode 100644 index 1ff8a0da4..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/comprehensive_hash_identifiers.yml +++ /dev/null @@ -1,40 +0,0 @@ -file: -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: o# - - dot: . - - naked_identifier: id# - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: orders# - - alias_expression: - - naked_identifier: o# -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: total - - alias_expression: - - keyword: AS - - naked_identifier: amount# - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: orders# -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/convert.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/convert.sql new file mode 100644 index 000000000..eaad22dbd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/convert.sql @@ -0,0 +1,4 @@ +SELECT + CONVERT(nvarchar(100), first_column) as first, + TRY_CONVERT(float, second_column) as second +FROM some_table diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/convert.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/convert.yml new file mode 100644 index 000000000..34a70eed0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/convert.yml @@ -0,0 +1,56 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: CONVERT + - function_contents: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: nvarchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - expression: + - column_reference: + - naked_identifier: first_column + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: first + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: TRY_CONVERT + - function_contents: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: float + - comma: ',' + - expression: + - column_reference: + - naked_identifier: second_column + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: second + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: some_table diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/copy.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/copy.sql new file mode 100644 index 000000000..65214bf64 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/copy.sql @@ -0,0 +1,53 @@ +COPY INTO dbo.[lineitem] +FROM 'https://unsecureaccount.blob.core.windows.net/customerdatasets/folder1/lineitem.csv'; + +COPY INTO test_1 +FROM 'https://myaccount.blob.core.windows.net/myblobcontainer/folder1/' +WITH ( + FILE_TYPE = 'CSV', + CREDENTIAL=(IDENTITY= 'Shared Access Signature', SECRET=''), + --CREDENTIAL should look something like this: + --CREDENTIAL=(IDENTITY= 'Shared Access Signature', SECRET='?sv=2018-03-28&ss=bfqt&srt=sco&sp=rl&st=2016-10-17T20%3A14%3A55Z&se=2021-10-18T20%3A19%3A00Z&sig=IEoOdmeYnE9%2FKiJDSHFSYsz4AkNa%2F%2BTx61FuQ%2FfKHefqoBE%3D'), + FIELDQUOTE = '"', + FIELDTERMINATOR=';', + ROWTERMINATOR='0X0A', + ENCODING = 'UTF8', + DATEFORMAT = 'ymd', + MAXERRORS = 10, + ERRORFILE = '/errorsfolder',--path starting from the storage container + IDENTITY_INSERT = 'ON' +); + +COPY INTO test_parquet +FROM 'https://myaccount.blob.core.windows.net/myblobcontainer/folder1/*.parquet' +WITH ( + FILE_FORMAT = myFileFormat, + CREDENTIAL=(IDENTITY= 'Shared Access Signature', SECRET='') +); + +COPY INTO t1 +FROM +'https://myaccount.blob.core.windows.net/myblobcontainer/folder0/*.txt', + 'https://myaccount.blob.core.windows.net/myblobcontainer/folder1' +WITH ( + FILE_TYPE = 'CSV', + CREDENTIAL=(IDENTITY= '@',SECRET=''), + FIELDTERMINATOR = '|' +); + +COPY INTO dbo.myCOPYDemoTable +FROM 'https://myaccount.blob.core.windows.net/myblobcontainer/folder0/*.txt' +WITH ( + FILE_TYPE = 'CSV', + CREDENTIAL = (IDENTITY = 'Managed Identity'), + FIELDQUOTE = '"', + FIELDTERMINATOR=',' +); + +COPY INTO [myCOPYDemoTable] +FROM 'https://myaccount.blob.core.windows.net/customerdatasets/folder1/lineitem.parquet' +WITH ( + FILE_TYPE = 'Parquet', + CREDENTIAL = ( IDENTITY = 'Shared Access Signature', SECRET=''), + AUTO_CREATE_TABLE = 'ON' +); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/copy.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/copy.yml new file mode 100644 index 000000000..7309959ec --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/copy.yml @@ -0,0 +1,272 @@ +file: +- batch: + - statement: + - copy_into_table_statement: + - keyword: COPY + - keyword: INTO + - table_reference: + - naked_identifier: dbo + - dot: . + - quoted_identifier: '[lineitem]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - storage_location: + - external_location: '''https://unsecureaccount.blob.core.windows.net/customerdatasets/folder1/lineitem.csv''' + - statement_terminator: ; + - statement: + - copy_into_table_statement: + - keyword: COPY + - keyword: INTO + - table_reference: + - naked_identifier: test_1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - storage_location: + - external_location: '''https://myaccount.blob.core.windows.net/myblobcontainer/folder1/''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FILE_TYPE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''CSV''' + - comma: ',' + - keyword: CREDENTIAL + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: IDENTITY + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Shared Access Signature''' + - comma: ',' + - keyword: SECRET + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - end_bracket: ) + - comma: ',' + - keyword: FIELDQUOTE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''"''' + - comma: ',' + - keyword: FIELDTERMINATOR + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: ''';''' + - comma: ',' + - keyword: ROWTERMINATOR + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''0X0A''' + - comma: ',' + - keyword: ENCODING + - comparison_operator: + - raw_comparison_operator: = + - file_encoding: '''UTF8''' + - comma: ',' + - keyword: DATEFORMAT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''ymd''' + - comma: ',' + - keyword: MAXERRORS + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - comma: ',' + - keyword: ERRORFILE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''/errorsfolder''' + - comma: ',' + - keyword: IDENTITY_INSERT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''ON''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - copy_into_table_statement: + - keyword: COPY + - keyword: INTO + - table_reference: + - naked_identifier: test_parquet + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - storage_location: + - external_location: '''https://myaccount.blob.core.windows.net/myblobcontainer/folder1/*.parquet''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FILE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: myFileFormat + - comma: ',' + - keyword: CREDENTIAL + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: IDENTITY + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Shared Access Signature''' + - comma: ',' + - keyword: SECRET + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - copy_into_table_statement: + - keyword: COPY + - keyword: INTO + - table_reference: + - naked_identifier: t1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - storage_location: + - external_location: '''https://myaccount.blob.core.windows.net/myblobcontainer/folder0/*.txt''' + - comma: ',' + - from_expression: + - from_expression_element: + - table_expression: + - storage_location: + - external_location: '''https://myaccount.blob.core.windows.net/myblobcontainer/folder1''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FILE_TYPE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''CSV''' + - comma: ',' + - keyword: CREDENTIAL + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: IDENTITY + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''@''' + - comma: ',' + - keyword: SECRET + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - end_bracket: ) + - comma: ',' + - keyword: FIELDTERMINATOR + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''|''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - copy_into_table_statement: + - keyword: COPY + - keyword: INTO + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: myCOPYDemoTable + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - storage_location: + - external_location: '''https://myaccount.blob.core.windows.net/myblobcontainer/folder0/*.txt''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FILE_TYPE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''CSV''' + - comma: ',' + - keyword: CREDENTIAL + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: IDENTITY + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Managed Identity''' + - end_bracket: ) + - comma: ',' + - keyword: FIELDQUOTE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''"''' + - comma: ',' + - keyword: FIELDTERMINATOR + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: ''',''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - copy_into_table_statement: + - keyword: COPY + - keyword: INTO + - table_reference: + - quoted_identifier: '[myCOPYDemoTable]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - storage_location: + - external_location: '''https://myaccount.blob.core.windows.net/customerdatasets/folder1/lineitem.parquet''' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FILE_TYPE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Parquet''' + - comma: ',' + - keyword: CREDENTIAL + - comparison_operator: + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - keyword: IDENTITY + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Shared Access Signature''' + - comma: ',' + - keyword: SECRET + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - end_bracket: ) + - comma: ',' + - keyword: AUTO_CREATE_TABLE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''ON''' + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_columnstore_index.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_columnstore_index.sql new file mode 100644 index 000000000..43e32f67d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_columnstore_index.sql @@ -0,0 +1,23 @@ +CREATE CLUSTERED COLUMNSTORE INDEX cci ON dbo.Orders +WITH (MAXDOP = 2); + +CREATE CLUSTERED COLUMNSTORE INDEX cci_comp ON dbo.Compression +WITH ( COMPRESSION_DELAY = 10 MINUTES ); + +CREATE CLUSTERED COLUMNSTORE INDEX cci_data ON dbo.DataColumns +WITH ( DATA_COMPRESSION = COLUMNSTORE_ARCHIVE ); + +CREATE CLUSTERED COLUMNSTORE INDEX cci_online ON dbo.OnlineTable +WITH ( ONLINE = ON ); + + +CREATE NONCLUSTERED COLUMNSTORE INDEX ncci ON dbo.Orders (StockItemID, Quantity, UnitPrice, TaxRate) +WITH ( ONLINE = ON ); + + +CREATE COLUMNSTORE INDEX ncci2 ON dbo.Orders2 (StockItemID, Quantity, UnitPrice, TaxRate) +WITH ( ONLINE = ON ); + +CREATE NONCLUSTERED COLUMNSTORE INDEX FIBillOfMaterialsWithEndDate + ON dbo.Materials (ComponentID, StartDate) + WHERE EndDate IS NOT NULL; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_columnstore_index.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_columnstore_index.yml new file mode 100644 index 000000000..29e84fdee --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_columnstore_index.yml @@ -0,0 +1,195 @@ +file: +- batch: + - statement: + - create_columnstore_index_statement: + - keyword: CREATE + - keyword: CLUSTERED + - keyword: COLUMNSTORE + - keyword: INDEX + - index_reference: + - naked_identifier: cci + - keyword: ON + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Orders + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: MAXDOP + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_columnstore_index_statement: + - keyword: CREATE + - keyword: CLUSTERED + - keyword: COLUMNSTORE + - keyword: INDEX + - index_reference: + - naked_identifier: cci_comp + - keyword: ON + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Compression + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: COMPRESSION_DELAY + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - keyword: MINUTES + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_columnstore_index_statement: + - keyword: CREATE + - keyword: CLUSTERED + - keyword: COLUMNSTORE + - keyword: INDEX + - index_reference: + - naked_identifier: cci_data + - keyword: ON + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: DataColumns + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: DATA_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - keyword: COLUMNSTORE_ARCHIVE + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_columnstore_index_statement: + - keyword: CREATE + - keyword: CLUSTERED + - keyword: COLUMNSTORE + - keyword: INDEX + - index_reference: + - naked_identifier: cci_online + - keyword: ON + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: OnlineTable + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: ONLINE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_columnstore_index_statement: + - keyword: CREATE + - keyword: NONCLUSTERED + - keyword: COLUMNSTORE + - keyword: INDEX + - index_reference: + - naked_identifier: ncci + - keyword: ON + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Orders + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: StockItemID + - comma: ',' + - index_column_definition: + - naked_identifier: Quantity + - comma: ',' + - index_column_definition: + - naked_identifier: UnitPrice + - comma: ',' + - index_column_definition: + - naked_identifier: TaxRate + - end_bracket: ) + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: ONLINE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_columnstore_index_statement: + - keyword: CREATE + - keyword: COLUMNSTORE + - keyword: INDEX + - index_reference: + - naked_identifier: ncci2 + - keyword: ON + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Orders2 + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: StockItemID + - comma: ',' + - index_column_definition: + - naked_identifier: Quantity + - comma: ',' + - index_column_definition: + - naked_identifier: UnitPrice + - comma: ',' + - index_column_definition: + - naked_identifier: TaxRate + - end_bracket: ) + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: ONLINE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_columnstore_index_statement: + - keyword: CREATE + - keyword: NONCLUSTERED + - keyword: COLUMNSTORE + - keyword: INDEX + - index_reference: + - naked_identifier: FIBillOfMaterialsWithEndDate + - keyword: ON + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Materials + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: ComponentID + - comma: ',' + - index_column_definition: + - naked_identifier: StartDate + - end_bracket: ) + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: EndDate + - keyword: IS + - keyword: NOT + - null_literal: 'NULL' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database.sql new file mode 100644 index 000000000..8b47b6efd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database.sql @@ -0,0 +1,154 @@ +CREATE DATABASE mytest; + +CREATE DATABASE Sales +ON +( NAME = Sales_dat, + FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\saledat.mdf', + SIZE = 10, + MAXSIZE = 50, + FILEGROWTH = 5 ) +LOG ON +( NAME = Sales_log, + FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\salelog.ldf', + SIZE = 5MB, + MAXSIZE = 25MB, + FILEGROWTH = 5MB + ) ; +GO + +CREATE DATABASE Archive +ON +PRIMARY + (NAME = Arch1, + FILENAME = 'D:\SalesData\archdat1.mdf', + SIZE = 100MB, + MAXSIZE = 200, + FILEGROWTH = 20), + ( NAME = Arch2, + FILENAME = 'D:\SalesData\archdat2.ndf', + SIZE = 100MB, + MAXSIZE = 200, + FILEGROWTH = 20), + ( NAME = Arch3, + FILENAME = 'D:\SalesData\archdat3.ndf', + SIZE = 100MB, + MAXSIZE = 200, + FILEGROWTH = 20) +LOG ON + (NAME = Archlog1, + FILENAME = 'D:\SalesData\archlog1.ldf', + SIZE = 100MB, + MAXSIZE = 200, + FILEGROWTH = 20), + (NAME = Archlog2, + FILENAME = 'D:\SalesData\archlog2.ldf', + SIZE = 100MB, + MAXSIZE = 200, + FILEGROWTH = 20) ; +GO + +CREATE DATABASE Sales +ON PRIMARY +( NAME = SPri1_dat, + FILENAME = 'D:\SalesData\SPri1dat.mdf', + SIZE = 10, + MAXSIZE = 50, + FILEGROWTH = 15% ), +( NAME = SPri2_dat, + FILENAME = 'D:\SalesData\SPri2dt.ndf', + SIZE = 10, + MAXSIZE = 50, + FILEGROWTH = 15% ), +FILEGROUP SalesGroup1 +( NAME = SGrp1Fi1_dat, + FILENAME = 'D:\SalesData\SG1Fi1dt.ndf', + SIZE = 10, + MAXSIZE = 50, + FILEGROWTH = 5 ), +( NAME = SGrp1Fi2_dat, + FILENAME = 'D:\SalesData\SG1Fi2dt.ndf', + SIZE = 10, + MAXSIZE = 50, + FILEGROWTH = 5 ), +FILEGROUP SalesGroup2 +( NAME = SGrp2Fi1_dat, + FILENAME = 'D:\SalesData\SG2Fi1dt.ndf', + SIZE = 10, + MAXSIZE = 50, + FILEGROWTH = 5 ), +( NAME = SGrp2Fi2_dat, + FILENAME = 'D:\SalesData\SG2Fi2dt.ndf', + SIZE = 10, + MAXSIZE = 50, + FILEGROWTH = 5 ) +LOG ON +( NAME = Sales_log, + FILENAME = 'E:\SalesLog\salelog.ldf', + SIZE = 5MB, + MAXSIZE = 25MB, + FILEGROWTH = 5MB ) ; +GO + + +CREATE DATABASE sales_snapshot0600 ON + ( NAME = SPri1_dat, FILENAME = 'D:\SalesData\SPri1dat_0600.ss'), + ( NAME = SPri2_dat, FILENAME = 'D:\SalesData\SPri2dt_0600.ss'), + ( NAME = SGrp1Fi1_dat, FILENAME = 'D:\SalesData\SG1Fi1dt_0600.ss'), + ( NAME = SGrp1Fi2_dat, FILENAME = 'D:\SalesData\SG1Fi2dt_0600.ss'), + ( NAME = SGrp2Fi1_dat, FILENAME = 'D:\SalesData\SG2Fi1dt_0600.ss'), + ( NAME = SGrp2Fi2_dat, FILENAME = 'D:\SalesData\SG2Fi2dt_0600.ss') +AS SNAPSHOT OF Sales ; +GO + +CREATE DATABASE MyOptionsTest +COLLATE French_CI_AI +WITH TRUSTWORTHY ON, DB_CHAINING ON; + +CREATE DATABASE AdventureWorks2022 ON + (FILENAME = 'c:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Data\AdventureWorks2022_data.mdf'), + (FILENAME = 'c:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Data\AdventureWorks2022_log.ldf'), + (FILENAME = 'c:\myFTCatalogs\AdvWksFtCat') +FOR ATTACH; +GO + +CREATE DATABASE [BlobStore1] +CONTAINMENT = NONE +ON PRIMARY +( + NAME = N'BlobStore1', + FILENAME = N'C:\BlobStore\BlobStore1.mdf', + SIZE = 100MB, + MAXSIZE = UNLIMITED, + FILEGROWTH = 1MB +), +FILEGROUP [FS] CONTAINS FILESTREAM DEFAULT +( + NAME = N'FS1', + FILENAME = N'C:\BlobStore\FS1', + MAXSIZE = UNLIMITED +), +( + NAME = N'FS2', + FILENAME = N'C:\BlobStore\FS2', + MAXSIZE = 100MB +) +LOG ON +( + NAME = N'BlobStore1_log', + FILENAME = N'C:\BlobStore\BlobStore1_log.ldf', + SIZE = 100MB, + MAXSIZE = 1GB, + FILEGROWTH = 1MB +); +GO + +CREATE DATABASE [different-collations] COLLATE SQL_Latin1_General_CP1_CS_AS + +CREATE DATABASE [same-collations] COLLATE SQL_Latin1_General_CP1_CS_AS +WITH CATALOG_COLLATION = DATABASE_DEFAULT; + +CREATE DATABASE Archive + ON + (FILENAME = 'D:\SalesData\archdat1.mdf') + FOR ATTACH ; +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database.yml new file mode 100644 index 000000000..20eab712a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database.yml @@ -0,0 +1,889 @@ +file: +- batch: + - statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: mytest + - statement_terminator: ; + - statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: Sales + - keyword: ON + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: Sales_dat + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\saledat.mdf''' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '50' + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '5' + - end_bracket: ) + - keyword: LOG + - keyword: ON + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: Sales_log + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\salelog.ldf''' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 5MB + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 25MB + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 5MB + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: Archive + - keyword: ON + - keyword: PRIMARY + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: Arch1 + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\archdat1.mdf''' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 100MB + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '200' + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '20' + - end_bracket: ) + - comma: ',' + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: Arch2 + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\archdat2.ndf''' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 100MB + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '200' + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '20' + - end_bracket: ) + - comma: ',' + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: Arch3 + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\archdat3.ndf''' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 100MB + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '200' + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '20' + - end_bracket: ) + - keyword: LOG + - keyword: ON + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: Archlog1 + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\archlog1.ldf''' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 100MB + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '200' + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '20' + - end_bracket: ) + - comma: ',' + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: Archlog2 + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\archlog2.ldf''' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 100MB + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '200' + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '20' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: Sales + - keyword: ON + - keyword: PRIMARY + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: SPri1_dat + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\SPri1dat.mdf''' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '50' + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '15' + - percent: '%' + - end_bracket: ) + - comma: ',' + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: SPri2_dat + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\SPri2dt.ndf''' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '50' + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '15' + - percent: '%' + - end_bracket: ) + - comma: ',' + - keyword: FILEGROUP + - naked_identifier: SalesGroup1 + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: SGrp1Fi1_dat + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\SG1Fi1dt.ndf''' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '50' + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '5' + - end_bracket: ) + - comma: ',' + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: SGrp1Fi2_dat + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\SG1Fi2dt.ndf''' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '50' + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '5' + - end_bracket: ) + - comma: ',' + - keyword: FILEGROUP + - naked_identifier: SalesGroup2 + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: SGrp2Fi1_dat + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\SG2Fi1dt.ndf''' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '50' + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '5' + - end_bracket: ) + - comma: ',' + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: SGrp2Fi2_dat + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\SG2Fi2dt.ndf''' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '50' + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '5' + - end_bracket: ) + - keyword: LOG + - keyword: ON + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: Sales_log + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''E:\SalesLog\salelog.ldf''' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 5MB + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 25MB + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 5MB + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: sales_snapshot0600 + - keyword: ON + - bracketed: + - start_bracket: ( + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: SPri1_dat + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\SPri1dat_0600.ss''' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: SPri2_dat + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\SPri2dt_0600.ss''' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: SGrp1Fi1_dat + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\SG1Fi1dt_0600.ss''' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: SGrp1Fi2_dat + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\SG1Fi2dt_0600.ss''' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: SGrp2Fi1_dat + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\SG2Fi1dt_0600.ss''' + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: SGrp2Fi2_dat + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\SG2Fi2dt_0600.ss''' + - end_bracket: ) + - keyword: AS + - keyword: SNAPSHOT + - keyword: OF + - naked_identifier: Sales + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: MyOptionsTest + - keyword: COLLATE + - collation_reference: + - naked_identifier: French_CI_AI + - keyword: WITH + - keyword: TRUSTWORTHY + - keyword: ON + - comma: ',' + - keyword: DB_CHAINING + - keyword: ON + - statement_terminator: ; + - statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: AdventureWorks2022 + - keyword: ON + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - file_spec_file_name: + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''c:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Data\AdventureWorks2022_data.mdf''' + - end_bracket: ) + - comma: ',' + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - file_spec_file_name: + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''c:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Data\AdventureWorks2022_log.ldf''' + - end_bracket: ) + - comma: ',' + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - file_spec_file_name: + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''c:\myFTCatalogs\AdvWksFtCat''' + - end_bracket: ) + - keyword: FOR + - keyword: ATTACH + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[BlobStore1]' + - keyword: CONTAINMENT + - comparison_operator: + - raw_comparison_operator: = + - keyword: NONE + - keyword: ON + - keyword: PRIMARY + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'BlobStore1' + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'C:\BlobStore\BlobStore1.mdf' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 100MB + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - keyword: UNLIMITED + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 1MB + - end_bracket: ) + - comma: ',' + - keyword: FILEGROUP + - quoted_identifier: '[FS]' + - keyword: CONTAINS + - keyword: FILESTREAM + - keyword: DEFAULT + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'FS1' + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'C:\BlobStore\FS1' + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - keyword: UNLIMITED + - end_bracket: ) + - comma: ',' + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'FS2' + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'C:\BlobStore\FS2' + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 100MB + - end_bracket: ) + - keyword: LOG + - keyword: ON + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - logical_file_name: + - keyword: NAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'BlobStore1_log' + - file_spec_file_name: + - comma: ',' + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'C:\BlobStore\BlobStore1_log.ldf' + - file_spec_size: + - comma: ',' + - keyword: SIZE + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 100MB + - file_spec_max_size: + - comma: ',' + - keyword: MAXSIZE + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 1GB + - file_spec_file_growth: + - comma: ',' + - keyword: FILEGROWTH + - comparison_operator: + - raw_comparison_operator: = + - size_literal: 1MB + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[different-collations]' + - keyword: COLLATE + - collation_reference: + - naked_identifier: SQL_Latin1_General_CP1_CS_AS + - statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - quoted_identifier: '[same-collations]' + - keyword: COLLATE + - collation_reference: + - naked_identifier: SQL_Latin1_General_CP1_CS_AS + - keyword: WITH + - keyword: CATALOG_COLLATION + - comparison_operator: + - raw_comparison_operator: = + - collation_reference: + - naked_identifier: DATABASE_DEFAULT + - statement_terminator: ; + - statement: + - create_database_statement: + - keyword: CREATE + - keyword: DATABASE + - database_reference: + - naked_identifier: Archive + - keyword: ON + - file_spec: + - bracketed: + - start_bracket: ( + - file_spec_without_bracket: + - file_spec_file_name: + - keyword: FILENAME + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''D:\SalesData\archdat1.mdf''' + - end_bracket: ) + - keyword: FOR + - keyword: ATTACH + - statement_terminator: ; + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database_scoped_credential.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database_scoped_credential.sql new file mode 100644 index 000000000..2106d2e38 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database_scoped_credential.sql @@ -0,0 +1,4 @@ +CREATE DATABASE SCOPED CREDENTIAL AppCred WITH IDENTITY = 'Mary5'; + +CREATE DATABASE SCOPED CREDENTIAL AppCred WITH IDENTITY = 'Mary5', + SECRET = ''; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database_scoped_credential.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database_scoped_credential.yml new file mode 100644 index 000000000..0d2e6ace7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_database_scoped_credential.yml @@ -0,0 +1,35 @@ +file: +- batch: + - statement: + - create_database_scoped_credential_statement: + - keyword: CREATE + - keyword: DATABASE + - keyword: SCOPED + - keyword: CREDENTIAL + - object_reference: + - naked_identifier: AppCred + - keyword: WITH + - keyword: IDENTITY + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Mary5''' + - statement_terminator: ; + - statement: + - create_database_scoped_credential_statement: + - keyword: CREATE + - keyword: DATABASE + - keyword: SCOPED + - keyword: CREDENTIAL + - object_reference: + - naked_identifier: AppCred + - keyword: WITH + - keyword: IDENTITY + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Mary5''' + - comma: ',' + - keyword: SECRET + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_data_source.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_data_source.sql new file mode 100644 index 000000000..7625bd02f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_data_source.sql @@ -0,0 +1,20 @@ +CREATE EXTERNAL DATA SOURCE MyOracleServer +WITH ( + LOCATION = 'oracle://145.145.145.145:1521', + CREDENTIAL = OracleProxyAccount, + PUSHDOWN = ON +); + +CREATE EXTERNAL DATA SOURCE [OracleSalesSrvr] +WITH ( + LOCATION = 'oracle://145.145.145.145:1521', + CONNECTION_OPTIONS = 'ImpersonateUser=%CURRENT_USER', + CREDENTIAL = [OracleProxyCredential] +); + +CREATE EXTERNAL DATA SOURCE [external_data_source_name] +WITH ( + LOCATION = N'oracle://XE', + CREDENTIAL = [OracleCredentialTest], + CONNECTION_OPTIONS = N'TNSNamesFile=C:\Temp\tnsnames.ora;ServerName=XE' +); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_data_source.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_data_source.yml new file mode 100644 index 000000000..20152b6aa --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_data_source.yml @@ -0,0 +1,89 @@ +file: +- batch: + - statement: + - create_external_data_source_statement: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: DATA + - keyword: SOURCE + - object_reference: + - naked_identifier: MyOracleServer + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_location_clause: + - keyword: LOCATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''oracle://145.145.145.145:1521''' + - comma: ',' + - keyword: CREDENTIAL + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: OracleProxyAccount + - comma: ',' + - keyword: PUSHDOWN + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_external_data_source_statement: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: DATA + - keyword: SOURCE + - object_reference: + - quoted_identifier: '[OracleSalesSrvr]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_location_clause: + - keyword: LOCATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''oracle://145.145.145.145:1521''' + - comma: ',' + - keyword: CONNECTION_OPTIONS + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''ImpersonateUser=%CURRENT_USER''' + - comma: ',' + - keyword: CREDENTIAL + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - quoted_identifier: '[OracleProxyCredential]' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_external_data_source_statement: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: DATA + - keyword: SOURCE + - object_reference: + - quoted_identifier: '[external_data_source_name]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_location_clause: + - keyword: LOCATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'oracle://XE' + - comma: ',' + - keyword: CREDENTIAL + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - quoted_identifier: '[OracleCredentialTest]' + - comma: ',' + - keyword: CONNECTION_OPTIONS + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'TNSNamesFile=C:\Temp\tnsnames.ora;ServerName=XE' + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_file_format.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_file_format.sql new file mode 100644 index 000000000..5de8ebbff --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_file_format.sql @@ -0,0 +1,54 @@ +/* +https://learn.microsoft.com/en-us/sql/t-sql/statements/create-external-file-format-transact-sql?view=sql-server-ver16&tabs=delimited#examples +*/ + +CREATE EXTERNAL FILE FORMAT textdelimited1 +WITH ( + FORMAT_TYPE = DELIMITEDTEXT, + FORMAT_OPTIONS ( + FIELD_TERMINATOR = '|', + DATE_FORMAT = 'MM/dd/yyyy' + ), + DATA_COMPRESSION = 'org.apache.hadoop.io.compress.GzipCodec' +); + +CREATE EXTERNAL FILE FORMAT skipHeader_CSV +WITH ( + FORMAT_TYPE = DELIMITEDTEXT, + FORMAT_OPTIONS ( + FIELD_TERMINATOR = ',', + STRING_DELIMITER = '"', + FIRST_ROW = 2, + USE_TYPE_DEFAULT = True + ) +); + +CREATE EXTERNAL FILE FORMAT [rcfile1] +WITH ( + FORMAT_TYPE = RCFILE, + SERDE_METHOD = 'org.apache.hadoop.hive.serde2.columnar.LazyBinaryColumnarSerDe', + DATA_COMPRESSION = 'org.apache.hadoop.io.compress.DefaultCodec' +); + +CREATE EXTERNAL FILE FORMAT orcfile1 +WITH ( + FORMAT_TYPE = ORC, + DATA_COMPRESSION = 'org.apache.hadoop.io.compress.SnappyCodec' +); + +CREATE EXTERNAL FILE FORMAT parquetfile1 +WITH ( + FORMAT_TYPE = PARQUET, + DATA_COMPRESSION = 'org.apache.hadoop.io.compress.SnappyCodec' +); + +CREATE EXTERNAL FILE FORMAT jsonFileFormat +WITH ( + FORMAT_TYPE = JSON, + DATA_COMPRESSION = 'org.apache.hadoop.io.compress.SnappyCodec' +); + +CREATE EXTERNAL FILE FORMAT DeltaFileFormat +WITH ( + FORMAT_TYPE = DELTA +); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_file_format.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_file_format.yml new file mode 100644 index 000000000..ad5257d78 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_file_format.yml @@ -0,0 +1,202 @@ +file: +- batch: + - statement: + - create_external_file_format: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: FILE + - keyword: FORMAT + - object_reference: + - naked_identifier: textdelimited1 + - keyword: WITH + - bracketed: + - start_bracket: ( + - external_file_delimited_text_clause: + - keyword: FORMAT_TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: DELIMITEDTEXT + - comma: ',' + - keyword: FORMAT_OPTIONS + - bracketed: + - start_bracket: ( + - external_file_delimited_text_format_options_clause: + - keyword: FIELD_TERMINATOR + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''|''' + - comma: ',' + - external_file_delimited_text_format_options_clause: + - keyword: DATE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''MM/dd/yyyy''' + - end_bracket: ) + - comma: ',' + - keyword: DATA_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - file_compression: '''org.apache.hadoop.io.compress.GzipCodec''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_external_file_format: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: FILE + - keyword: FORMAT + - object_reference: + - naked_identifier: skipHeader_CSV + - keyword: WITH + - bracketed: + - start_bracket: ( + - external_file_delimited_text_clause: + - keyword: FORMAT_TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: DELIMITEDTEXT + - comma: ',' + - keyword: FORMAT_OPTIONS + - bracketed: + - start_bracket: ( + - external_file_delimited_text_format_options_clause: + - keyword: FIELD_TERMINATOR + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: ''',''' + - comma: ',' + - external_file_delimited_text_format_options_clause: + - keyword: STRING_DELIMITER + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''"''' + - comma: ',' + - external_file_delimited_text_format_options_clause: + - keyword: FIRST_ROW + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' + - comma: ',' + - external_file_delimited_text_format_options_clause: + - keyword: USE_TYPE_DEFAULT + - comparison_operator: + - raw_comparison_operator: = + - boolean_literal: 'True' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_external_file_format: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: FILE + - keyword: FORMAT + - object_reference: + - quoted_identifier: '[rcfile1]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - external_file_rc_clause: + - keyword: FORMAT_TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: RCFILE + - comma: ',' + - keyword: SERDE_METHOD + - comparison_operator: + - raw_comparison_operator: = + - serde_method: '''org.apache.hadoop.hive.serde2.columnar.LazyBinaryColumnarSerDe''' + - comma: ',' + - keyword: DATA_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - file_compression: '''org.apache.hadoop.io.compress.DefaultCodec''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_external_file_format: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: FILE + - keyword: FORMAT + - object_reference: + - naked_identifier: orcfile1 + - keyword: WITH + - bracketed: + - start_bracket: ( + - external_file_orc_clause: + - keyword: FORMAT_TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ORC + - comma: ',' + - keyword: DATA_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - file_compression: '''org.apache.hadoop.io.compress.SnappyCodec''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_external_file_format: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: FILE + - keyword: FORMAT + - object_reference: + - naked_identifier: parquetfile1 + - keyword: WITH + - bracketed: + - start_bracket: ( + - external_file_parquet_clause: + - keyword: FORMAT_TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: PARQUET + - comma: ',' + - keyword: DATA_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - file_compression: '''org.apache.hadoop.io.compress.SnappyCodec''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_external_file_format: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: FILE + - keyword: FORMAT + - object_reference: + - naked_identifier: jsonFileFormat + - keyword: WITH + - bracketed: + - start_bracket: ( + - external_file_json_clause: + - keyword: FORMAT_TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: JSON + - comma: ',' + - keyword: DATA_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - file_compression: '''org.apache.hadoop.io.compress.SnappyCodec''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_external_file_format: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: FILE + - keyword: FORMAT + - object_reference: + - naked_identifier: DeltaFileFormat + - keyword: WITH + - bracketed: + - start_bracket: ( + - external_file_delta_clause: + - keyword: FORMAT_TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: DELTA + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_table.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_table.sql new file mode 100644 index 000000000..a7616afc1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_table.sql @@ -0,0 +1,46 @@ +CREATE EXTERNAL TABLE schema_name.table_name +( + column_name_1 VARCHAR(50), + column_name_2 VARCHAR(50) NULL, + column_name_3 VARCHAR(50) NOT NULL +) +WITH ( + LOCATION = N'/path/to/folder/', + DATA_SOURCE = external_data_source, + FILE_FORMAT = parquetfileformat, + REJECT_TYPE = VALUE, + REJECT_VALUE = 0, + REJECTED_ROW_LOCATION = '/REJECT_Directory' +) + +CREATE EXTERNAL TABLE schema_name.table_name +( + column_name_1 VARCHAR(50), + column_name_2 VARCHAR(50) NULL, + column_name_3 VARCHAR(50) NOT NULL +) +WITH ( + LOCATION = N'/path/to/folder/', + DATA_SOURCE = external_data_source, + FILE_FORMAT = parquetfileformat, + REJECT_TYPE = PERCENTAGE, + REJECT_VALUE = 0, + REJECT_SAMPLE_VALUE = 0, + REJECTED_ROW_LOCATION = '/REJECT_DIRECTORY' +) + +CREATE EXTERNAL TABLE customers ( + o_orderkey DECIMAL(38) NOT NULL, + o_custkey DECIMAL(38) NOT NULL, + o_orderstatus CHAR COLLATE latin1_general_bin NOT NULL, + o_totalprice DECIMAL(15, 2) NOT NULL, + o_orderdate DATETIME2(0) NOT NULL, + o_orderpriority CHAR(15) COLLATE latin1_general_bin NOT NULL, + o_clerk CHAR(15) COLLATE latin1_general_bin NOT NULL, + o_shippriority DECIMAL(38) NOT NULL, + o_comment VARCHAR(79) COLLATE latin1_general_bin NOT NULL +) +WITH ( + LOCATION = 'DB1.mySchema.customer', + DATA_SOURCE = external_data_source_name +); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_table.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_table.yml new file mode 100644 index 000000000..4cc06eca3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_external_table.yml @@ -0,0 +1,341 @@ +file: +- batch: + - statement: + - create_external_table_statement: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: TABLE + - object_reference: + - naked_identifier: schema_name + - dot: . + - naked_identifier: table_name + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: column_name_1 + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: column_name_2 + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: column_name_3 + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_location_clause: + - keyword: LOCATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'/path/to/folder/' + - comma: ',' + - keyword: DATA_SOURCE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: external_data_source + - comma: ',' + - keyword: FILE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: parquetfileformat + - comma: ',' + - keyword: REJECT_TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: VALUE + - comma: ',' + - keyword: REJECT_VALUE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - comma: ',' + - keyword: REJECTED_ROW_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''/REJECT_Directory''' + - end_bracket: ) + - statement: + - create_external_table_statement: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: TABLE + - object_reference: + - naked_identifier: schema_name + - dot: . + - naked_identifier: table_name + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: column_name_1 + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: column_name_2 + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: column_name_3 + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_location_clause: + - keyword: LOCATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'/path/to/folder/' + - comma: ',' + - keyword: DATA_SOURCE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: external_data_source + - comma: ',' + - keyword: FILE_FORMAT + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: parquetfileformat + - comma: ',' + - keyword: REJECT_TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: PERCENTAGE + - comma: ',' + - keyword: REJECT_VALUE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - comma: ',' + - keyword: REJECT_SAMPLE_VALUE + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0' + - comma: ',' + - keyword: REJECTED_ROW_LOCATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''/REJECT_DIRECTORY''' + - end_bracket: ) + - statement: + - create_external_table_statement: + - keyword: CREATE + - keyword: EXTERNAL + - keyword: TABLE + - object_reference: + - naked_identifier: customers + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: o_orderkey + - data_type: + - keyword: DECIMAL + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '38' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: o_custkey + - data_type: + - keyword: DECIMAL + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '38' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: o_orderstatus + - data_type: + - keyword: CHAR + - column_constraint_segment: + - keyword: COLLATE + - collation_reference: + - naked_identifier: latin1_general_bin + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: o_totalprice + - data_type: + - keyword: DECIMAL + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '15' + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: o_orderdate + - data_type: + - keyword: DATETIME2 + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '0' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: o_orderpriority + - data_type: + - keyword: CHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '15' + - end_bracket: ) + - column_constraint_segment: + - keyword: COLLATE + - collation_reference: + - naked_identifier: latin1_general_bin + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: o_clerk + - data_type: + - keyword: CHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '15' + - end_bracket: ) + - column_constraint_segment: + - keyword: COLLATE + - collation_reference: + - naked_identifier: latin1_general_bin + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: o_shippriority + - data_type: + - keyword: DECIMAL + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '38' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: o_comment + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '79' + - end_bracket: ) + - column_constraint_segment: + - keyword: COLLATE + - collation_reference: + - naked_identifier: latin1_general_bin + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_location_clause: + - keyword: LOCATION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''DB1.mySchema.customer''' + - comma: ',' + - keyword: DATA_SOURCE + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: external_data_source_name + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_catalog.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_catalog.sql new file mode 100644 index 000000000..d798c029f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_catalog.sql @@ -0,0 +1,22 @@ +CREATE FULLTEXT CATALOG [ftCatalog] WITH ACCENT_SENSITIVITY = OFF + AS DEFAULT; + +CREATE FULLTEXT CATALOG ftCatalog AS DEFAULT; +GO +CREATE FULLTEXT INDEX ON HumanResources.JobCandidate (Resume) +KEY INDEX PK_JobCandidate_JobCandidateID; +GO + +CREATE FULLTEXT CATALOG ftCatalog AUTHORIZATION [dbo]; + +CREATE FULLTEXT CATALOG ftCatalog +ON FILEGROUP [filegroup] +IN PATH 'rootpath'; + +CREATE FULLTEXT CATALOG ftCatalog +AS DEFAULT +AUTHORIZATION [dbo]; + +CREATE FULLTEXT CATALOG ftCatalog +ON FILEGROUP [filegroup] +AUTHORIZATION [dbo]; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_catalog.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_catalog.yml new file mode 100644 index 000000000..10110a7fa --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_catalog.yml @@ -0,0 +1,107 @@ +file: +- batch: + - statement: + - create_fulltext_catalog_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: CATALOG + - object_reference: + - quoted_identifier: '[ftCatalog]' + - keyword: WITH + - keyword: ACCENT_SENSITIVITY + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - keyword: AS + - keyword: DEFAULT + - statement_terminator: ; + - statement: + - create_fulltext_catalog_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: CATALOG + - object_reference: + - naked_identifier: ftCatalog + - keyword: AS + - keyword: DEFAULT + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: JobCandidate + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: Resume + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - naked_identifier: PK_JobCandidate_JobCandidateID + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_fulltext_catalog_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: CATALOG + - object_reference: + - naked_identifier: ftCatalog + - keyword: AUTHORIZATION + - role_reference: + - quoted_identifier: '[dbo]' + - statement_terminator: ; + - statement: + - create_fulltext_catalog_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: CATALOG + - object_reference: + - naked_identifier: ftCatalog + - keyword: ON + - keyword: FILEGROUP + - filegroup_name: + - quoted_identifier: '[filegroup]' + - keyword: IN + - keyword: PATH + - quoted_literal: '''rootpath''' + - statement_terminator: ; + - statement: + - create_fulltext_catalog_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: CATALOG + - object_reference: + - naked_identifier: ftCatalog + - keyword: AS + - keyword: DEFAULT + - keyword: AUTHORIZATION + - role_reference: + - quoted_identifier: '[dbo]' + - statement_terminator: ; + - statement: + - create_fulltext_catalog_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: CATALOG + - object_reference: + - naked_identifier: ftCatalog + - keyword: ON + - keyword: FILEGROUP + - filegroup_name: + - quoted_identifier: '[filegroup]' + - keyword: AUTHORIZATION + - role_reference: + - quoted_identifier: '[dbo]' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_index.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_index.sql new file mode 100644 index 000000000..ee71b4dca --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_index.sql @@ -0,0 +1,132 @@ +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062, + [test] STATISTICAL_SEMANTICS +) KEY INDEX [KEY_INDEX]; + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 'french' +) KEY INDEX [KEY_INDEX]; + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] STATISTICAL_SEMANTICS +) KEY INDEX [KEY_INDEX]; + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE +) KEY INDEX [KEY_INDEX]; + +-- catalog_filegroup_options +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] ON [ft_catalog_name]; + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] ON [ft_catalog_name], FILEGROUP [filegroup_name]; + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] ON FILEGROUP [filegroup_name], [ft_catalog_name],; + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] ON FILEGROUP [filegroup_name]; + +-- change_tracking (MANUAL | AUTO | OFF | OFF, NO POPULATION) +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] ON [ft_catalog_name] WITH ( + CHANGE_TRACKING MANUAL +); + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] ON [ft_catalog_name] WITH ( + CHANGE_TRACKING = MANUAL +); + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] ON [ft_catalog_name] WITH ( + CHANGE_TRACKING AUTO +); + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] ON [ft_catalog_name] WITH ( + CHANGE_TRACKING = AUTO +); + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] WITH ( + CHANGE_TRACKING OFF +); + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] WITH ( + CHANGE_TRACKING = OFF +); + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] WITH ( + CHANGE_TRACKING OFF, NO POPULATION +); + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] WITH ( + CHANGE_TRACKING = OFF, NO POPULATION +); + +-- stoplist (OFF | SYSTEM | stoplist_name) +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] WITH ( + STOPLIST OFF +); + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] WITH ( + STOPLIST = OFF +); + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] WITH ( + STOPLIST SYSTEM +); + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] WITH ( + STOPLIST = SYSTEM +); + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] WITH ( + STOPLIST [custom_stoplist_name] +); + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] WITH ( + STOPLIST = [custom_stoplist_name] +); + +-- search property list +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] WITH ( + SEARCH PROPERTY LIST [property_list_name] +); + +CREATE FULLTEXT INDEX ON [dbo].[TEST_FULLTEXT_INDEX] ( + [id] LANGUAGE 1062 +) KEY INDEX [PK_IDENTIFIER] WITH ( + SEARCH PROPERTY LIST = [property_list_name] +); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_index.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_index.yml new file mode 100644 index 000000000..673766f83 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_fulltext_index.yml @@ -0,0 +1,692 @@ +file: +- batch: + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - comma: ',' + - column_reference: + - quoted_identifier: '[test]' + - keyword: STATISTICAL_SEMANTICS + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[KEY_INDEX]' + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - quoted_literal: '''french''' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[KEY_INDEX]' + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: STATISTICAL_SEMANTICS + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[KEY_INDEX]' + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[KEY_INDEX]' + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: ON + - object_reference: + - quoted_identifier: '[ft_catalog_name]' + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: ON + - object_reference: + - quoted_identifier: '[ft_catalog_name]' + - comma: ',' + - keyword: FILEGROUP + - object_reference: + - quoted_identifier: '[filegroup_name]' + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: ON + - keyword: FILEGROUP + - object_reference: + - quoted_identifier: '[filegroup_name]' + - comma: ',' + - object_reference: + - quoted_identifier: '[ft_catalog_name]' + - comma: ',' + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: ON + - keyword: FILEGROUP + - object_reference: + - quoted_identifier: '[filegroup_name]' + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: ON + - object_reference: + - quoted_identifier: '[ft_catalog_name]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: CHANGE_TRACKING + - keyword: MANUAL + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: ON + - object_reference: + - quoted_identifier: '[ft_catalog_name]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: CHANGE_TRACKING + - comparison_operator: + - raw_comparison_operator: = + - keyword: MANUAL + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: ON + - object_reference: + - quoted_identifier: '[ft_catalog_name]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: CHANGE_TRACKING + - keyword: AUTO + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: ON + - object_reference: + - quoted_identifier: '[ft_catalog_name]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: CHANGE_TRACKING + - comparison_operator: + - raw_comparison_operator: = + - keyword: AUTO + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: CHANGE_TRACKING + - keyword: OFF + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: CHANGE_TRACKING + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: CHANGE_TRACKING + - keyword: OFF + - comma: ',' + - keyword: NO + - keyword: POPULATION + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: CHANGE_TRACKING + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - comma: ',' + - keyword: NO + - keyword: POPULATION + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: STOPLIST + - keyword: OFF + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: STOPLIST + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: STOPLIST + - keyword: SYSTEM + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: STOPLIST + - comparison_operator: + - raw_comparison_operator: = + - keyword: SYSTEM + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: STOPLIST + - object_reference: + - quoted_identifier: '[custom_stoplist_name]' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: STOPLIST + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - quoted_identifier: '[custom_stoplist_name]' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: SEARCH + - keyword: PROPERTY + - keyword: LIST + - object_reference: + - quoted_identifier: '[property_list_name]' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_fulltext_index_statement: + - keyword: CREATE + - keyword: FULLTEXT + - keyword: INDEX + - keyword: ON + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_FULLTEXT_INDEX]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[id]' + - keyword: LANGUAGE + - numeric_literal: '1062' + - end_bracket: ) + - keyword: KEY + - keyword: INDEX + - object_reference: + - quoted_identifier: '[PK_IDENTIFIER]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: SEARCH + - keyword: PROPERTY + - keyword: LIST + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - quoted_identifier: '[property_list_name]' + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_function.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_function.sql new file mode 100644 index 000000000..8978ccbb7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_function.sql @@ -0,0 +1,62 @@ +CREATE FUNCTION dbo.ISOweek (@DATE datetime) +RETURNS int +WITH EXECUTE AS CALLER +AS +BEGIN + DECLARE @ISOweek int; + SET @ISOweek= DATEPART(wk,@DATE)+1 + -DATEPART(wk,CAST(DATEPART(yy,@DATE) as CHAR(4))+'0104'); +--Special cases: Jan 1-3 may belong to the previous year + IF (@ISOweek=0) + SET @ISOweek=dbo.ISOweek(CAST(DATEPART(yy,@DATE)-1 + AS CHAR(4))+'12'+ CAST(24+DATEPART(DAY,@DATE) AS CHAR(2)))+1; +--Special case: Dec 29-31 may belong to the next year + IF ((DATEPART(mm,@DATE)=12) AND + ((DATEPART(dd,@DATE)-DATEPART(dw,@DATE))>= 28)) + SET @ISOweek=1; + RETURN(@ISOweek); +END; +GO + +CREATE FUNCTION f () +RETURNS @t TABLE (i int) +AS +BEGIN + INSERT INTO @t SELECT 1; + RETURN; +END; +GO + +CREATE OR ALTER FUNCTION F (@DATE as datetime) RETURNS INT AS BEGIN RETURN 1 END; +GO + +ALTER FUNCTION F (@DATE as datetime) RETURNS INT AS BEGIN RETURN 0 END; +GO + +CREATE FUNCTION [UTIL].[getItemList] ( + @list ItemList READONLY +) +RETURNS nvarchar(max) +AS + +BEGIN + DECLARE @str nvarchar(max) = '' + + SELECT @str = @str + [item] FROM ( + SELECT TOP (9999) [item] + FROM @list + ORDER BY [order] + ) i + + RETURN @str +END; +GO + + +create function my_function(@my_parameter int) +returns int +with schemabinding, returns null on null input +begin + return @my_parameter +end +go diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_function.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_function.yml new file mode 100644 index 000000000..79d26f1f0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_function.yml @@ -0,0 +1,535 @@ +file: +- batch: + - statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ISOweek + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@DATE' + - data_type: + - keyword: datetime + - end_bracket: ) + - keyword: RETURNS + - data_type: + - keyword: int + - function_option_segment: + - keyword: WITH + - execute_as_clause: + - keyword: EXECUTE + - keyword: AS + - keyword: CALLER + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@ISOweek' + - data_type: + - keyword: int + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@ISOweek' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: DATEPART + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: wk + - comma: ',' + - expression: + - parameter: '@DATE' + - end_bracket: ) + - binary_operator: + + - integer_literal: '1' + - binary_operator: '-' + - function: + - function_name: + - function_name_identifier: DATEPART + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: wk + - comma: ',' + - expression: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: DATEPART + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: yy + - comma: ',' + - expression: + - parameter: '@DATE' + - end_bracket: ) + - keyword: as + - data_type: + - keyword: CHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '4' + - end_bracket: ) + - end_bracket: ) + - binary_operator: + + - quoted_literal: '''0104''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - bracketed: + - start_bracket: ( + - expression: + - parameter: '@ISOweek' + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '0' + - end_bracket: ) + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@ISOweek' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - naked_identifier: dbo + - dot: . + - function_name_identifier: ISOweek + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: DATEPART + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: yy + - comma: ',' + - expression: + - parameter: '@DATE' + - end_bracket: ) + - binary_operator: '-' + - integer_literal: '1' + - keyword: AS + - data_type: + - keyword: CHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '4' + - end_bracket: ) + - end_bracket: ) + - binary_operator: + + - quoted_literal: '''12''' + - binary_operator: + + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '24' + - binary_operator: + + - function: + - function_name: + - function_name_identifier: DATEPART + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: DAY + - comma: ',' + - expression: + - parameter: '@DATE' + - end_bracket: ) + - keyword: AS + - data_type: + - keyword: CHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '2' + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - binary_operator: + + - integer_literal: '1' + - statement_terminator: ; + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - bracketed: + - start_bracket: ( + - expression: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: DATEPART + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: mm + - comma: ',' + - expression: + - parameter: '@DATE' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '12' + - end_bracket: ) + - binary_operator: AND + - bracketed: + - start_bracket: ( + - expression: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: DATEPART + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: dd + - comma: ',' + - expression: + - parameter: '@DATE' + - end_bracket: ) + - binary_operator: '-' + - function: + - function_name: + - function_name_identifier: DATEPART + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: dw + - comma: ',' + - expression: + - parameter: '@DATE' + - end_bracket: ) + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - integer_literal: '28' + - end_bracket: ) + - end_bracket: ) + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@ISOweek' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '1' + - statement_terminator: ; + - statement: + - return_segment: + - keyword: RETURN + - expression: + - bracketed: + - start_bracket: ( + - expression: + - parameter: '@ISOweek' + - end_bracket: ) + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - object_reference: + - naked_identifier: f + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - parameter: '@t' + - keyword: TABLE + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: i + - data_type: + - keyword: int + - end_bracket: ) + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - parameter: '@t' + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - statement_terminator: ; + - statement: + - return_segment: + - keyword: RETURN + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: FUNCTION + - object_reference: + - naked_identifier: F + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@DATE' + - keyword: as + - data_type: + - keyword: datetime + - end_bracket: ) + - keyword: RETURNS + - data_type: + - keyword: INT + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - return_segment: + - keyword: RETURN + - expression: + - integer_literal: '1' + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_function_statement: + - keyword: ALTER + - keyword: FUNCTION + - object_reference: + - naked_identifier: F + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@DATE' + - keyword: as + - data_type: + - keyword: datetime + - end_bracket: ) + - keyword: RETURNS + - data_type: + - keyword: INT + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - return_segment: + - keyword: RETURN + - expression: + - integer_literal: '0' + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - object_reference: + - quoted_identifier: '[UTIL]' + - dot: . + - quoted_identifier: '[getItemList]' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@list' + - data_type: + - data_type_identifier: ItemList + - keyword: READONLY + - end_bracket: ) + - keyword: RETURNS + - data_type: + - keyword: nvarchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: max + - end_bracket: ) + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@str' + - data_type: + - keyword: nvarchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: max + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''''' + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - select_variable_assignment: + - parameter: '@str' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - parameter: '@str' + - binary_operator: + + - column_reference: + - quoted_identifier: '[item]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '9999' + - end_bracket: ) + - select_clause_element: + - column_reference: + - quoted_identifier: '[item]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - parameter: '@list' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - quoted_identifier: '[order]' + - end_bracket: ) + - alias_expression: + - naked_identifier: i + - statement: + - return_segment: + - keyword: RETURN + - expression: + - parameter: '@str' + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_function_statement: + - keyword: create + - keyword: function + - object_reference: + - naked_identifier: my_function + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@my_parameter' + - data_type: + - keyword: int + - end_bracket: ) + - keyword: returns + - data_type: + - keyword: int + - function_option_segment: + - keyword: with + - keyword: schemabinding + - comma: ',' + - keyword: returns + - keyword: 'null' + - keyword: on + - keyword: 'null' + - keyword: input + - procedure_statement: + - statement: + - begin_end_block: + - keyword: begin + - statement: + - return_segment: + - keyword: return + - expression: + - parameter: '@my_parameter' + - keyword: end + - go_statement: + - keyword: go diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_login.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_login.sql new file mode 100644 index 000000000..df843b6ab --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_login.sql @@ -0,0 +1,35 @@ +CREATE LOGIN [MyUserName] +WITH PASSWORD = ''; + +CREATE LOGIN [MyUserName] +WITH PASSWORD = '' MUST_CHANGE; + +CREATE LOGIN [MyUserName] +WITH PASSWORD = '', CHECK_EXPIRATION = ON; + +CREATE LOGIN [MyUserName] WITH PASSWORD = '' +MUST_CHANGE, CHECK_EXPIRATION = ON; + +CREATE LOGIN [MyUserName] +WITH PASSWORD = '', +DEFAULT_DATABASE = 'TestDb'; + +CREATE LOGIN [MyUserName] +WITH PASSWORD = '', +SID = 0x241C11948AEEB749B0D22646DB1A19F2; + +CREATE LOGIN [MyUserName] +WITH PASSWORD = '' +FROM WINDOWS; + +CREATE LOGIN [MyUserName] +WITH PASSWORD = '', +CHECK_EXPIRATION = ON, +CHECK_POLICY = ON, +CREDENTIAL = [MyCredential]; + +CREATE LOGIN [myapp] FROM EXTERNAL PROVIDER; + +CREATE LOGIN [myapp] FROM CERTIFICATE [MyCert]; + +CREATE LOGIN [myapp] FROM ASYMMETRIC KEY [MyAsymKey]; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_login.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_login.yml new file mode 100644 index 000000000..dfdab46ee --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_login.yml @@ -0,0 +1,171 @@ +file: +- batch: + - statement: + - create_login_statement: + - keyword: CREATE + - keyword: LOGIN + - object_reference: + - quoted_identifier: '[MyUserName]' + - keyword: WITH + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - statement_terminator: ; + - statement: + - create_login_statement: + - keyword: CREATE + - keyword: LOGIN + - object_reference: + - quoted_identifier: '[MyUserName]' + - keyword: WITH + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: MUST_CHANGE + - statement_terminator: ; + - statement: + - create_login_statement: + - keyword: CREATE + - keyword: LOGIN + - object_reference: + - quoted_identifier: '[MyUserName]' + - keyword: WITH + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - comma: ',' + - keyword: CHECK_EXPIRATION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - statement_terminator: ; + - statement: + - create_login_statement: + - keyword: CREATE + - keyword: LOGIN + - object_reference: + - quoted_identifier: '[MyUserName]' + - keyword: WITH + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: MUST_CHANGE + - comma: ',' + - keyword: CHECK_EXPIRATION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - statement_terminator: ; + - statement: + - create_login_statement: + - keyword: CREATE + - keyword: LOGIN + - object_reference: + - quoted_identifier: '[MyUserName]' + - keyword: WITH + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - comma: ',' + - keyword: DEFAULT_DATABASE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''TestDb''' + - statement_terminator: ; + - statement: + - create_login_statement: + - keyword: CREATE + - keyword: LOGIN + - object_reference: + - quoted_identifier: '[MyUserName]' + - keyword: WITH + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - comma: ',' + - keyword: SID + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0x241C11948AEEB749B0D22646DB1A19F2' + - statement_terminator: ; + - statement: + - create_login_statement: + - keyword: CREATE + - keyword: LOGIN + - object_reference: + - quoted_identifier: '[MyUserName]' + - keyword: WITH + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - keyword: FROM + - keyword: WINDOWS + - statement_terminator: ; + - statement: + - create_login_statement: + - keyword: CREATE + - keyword: LOGIN + - object_reference: + - quoted_identifier: '[MyUserName]' + - keyword: WITH + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - comma: ',' + - keyword: CHECK_EXPIRATION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - comma: ',' + - keyword: CHECK_POLICY + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - comma: ',' + - keyword: CREDENTIAL + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - quoted_identifier: '[MyCredential]' + - statement_terminator: ; + - statement: + - create_login_statement: + - keyword: CREATE + - keyword: LOGIN + - object_reference: + - quoted_identifier: '[myapp]' + - keyword: FROM + - keyword: EXTERNAL + - keyword: PROVIDER + - statement_terminator: ; + - statement: + - create_login_statement: + - keyword: CREATE + - keyword: LOGIN + - object_reference: + - quoted_identifier: '[myapp]' + - keyword: FROM + - keyword: CERTIFICATE + - object_reference: + - quoted_identifier: '[MyCert]' + - statement_terminator: ; + - statement: + - create_login_statement: + - keyword: CREATE + - keyword: LOGIN + - object_reference: + - quoted_identifier: '[myapp]' + - keyword: FROM + - keyword: ASYMMETRIC + - keyword: KEY + - object_reference: + - quoted_identifier: '[MyAsymKey]' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_master_key.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_master_key.sql new file mode 100644 index 000000000..114d4f321 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_master_key.sql @@ -0,0 +1,19 @@ +-- https://learn.microsoft.com/en-us/sql/t-sql/statements/create-master-key-transact-sql +-- https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-master-key-transact-sql +-- https://learn.microsoft.com/en-us/sql/t-sql/statements/drop-master-key-transact-sql + +CREATE MASTER KEY ENCRYPTION BY PASSWORD = ''; + +CREATE MASTER KEY; + +ALTER MASTER KEY REGENERATE WITH ENCRYPTION BY PASSWORD = ''; + +ALTER MASTER KEY FORCE REGENERATE WITH ENCRYPTION BY PASSWORD = ''; + +ALTER MASTER KEY ADD ENCRYPTION BY PASSWORD = ''; + +ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY; + +ALTER MASTER KEY DROP ENCRYPTION BY PASSWORD = ''; + +DROP MASTER KEY; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_master_key.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_master_key.yml new file mode 100644 index 000000000..4ed712a16 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_master_key.yml @@ -0,0 +1,98 @@ +file: +- batch: + - statement: + - create_master_key_statement: + - keyword: CREATE + - keyword: MASTER + - keyword: KEY + - keyword: ENCRYPTION + - keyword: BY + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - statement_terminator: ; + - statement: + - create_master_key_statement: + - keyword: CREATE + - keyword: MASTER + - keyword: KEY + - statement_terminator: ; + - statement: + - alter_master_key_statement: + - keyword: ALTER + - keyword: MASTER + - keyword: KEY + - keyword: REGENERATE + - keyword: WITH + - keyword: ENCRYPTION + - keyword: BY + - master_key_encryption_option: + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - statement_terminator: ; + - statement: + - alter_master_key_statement: + - keyword: ALTER + - keyword: MASTER + - keyword: KEY + - keyword: FORCE + - keyword: REGENERATE + - keyword: WITH + - keyword: ENCRYPTION + - keyword: BY + - master_key_encryption_option: + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - statement_terminator: ; + - statement: + - alter_master_key_statement: + - keyword: ALTER + - keyword: MASTER + - keyword: KEY + - keyword: ADD + - keyword: ENCRYPTION + - keyword: BY + - master_key_encryption_option: + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - statement_terminator: ; + - statement: + - alter_master_key_statement: + - keyword: ALTER + - keyword: MASTER + - keyword: KEY + - keyword: ADD + - keyword: ENCRYPTION + - keyword: BY + - master_key_encryption_option: + - keyword: SERVICE + - keyword: MASTER + - keyword: KEY + - statement_terminator: ; + - statement: + - alter_master_key_statement: + - keyword: ALTER + - keyword: MASTER + - keyword: KEY + - keyword: DROP + - keyword: ENCRYPTION + - keyword: BY + - master_key_encryption_option: + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''''' + - statement_terminator: ; + - statement: + - drop_master_key_statement: + - keyword: DROP + - keyword: MASTER + - keyword: KEY + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_function.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_function.sql new file mode 100644 index 000000000..08b4ea21c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_function.sql @@ -0,0 +1,23 @@ +-- https://learn.microsoft.com/en-us/sql/t-sql/statements/create-partition-scheme-transact-sql#examples + +CREATE PARTITION FUNCTION myIntRangePF1 (INT) +AS RANGE LEFT FOR VALUES (1, 100, 1000); + +CREATE PARTITION FUNCTION myCharRangePF2 (CHAR(1)) +AS RANGE RIGHT FOR VALUES ('A', 'B', 'C'); + +CREATE PARTITION FUNCTION [myDateRangePF1] (date) +AS RANGE RIGHT FOR VALUES ( + '20030201', '20030301', '20030401', + '20030501', '20030601', '20030701', '20030801', + '20030901', '20031001', '20031101', '20031201' +); + +ALTER PARTITION FUNCTION myIntRangePF1() +SPLIT RANGE (500); + +ALTER PARTITION FUNCTION myCharRangePF2() +MERGE RANGE ('D'); + +CREATE PARTITION FUNCTION [partition_function_3] (varbinary(128)) AS RANGE LEFT +FOR VALUES (0x0039003900390039002D00310039003700320032003300350032, 0x006A0070003800370039003000390034); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_function.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_function.yml new file mode 100644 index 000000000..ed3da0e09 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_function.yml @@ -0,0 +1,166 @@ +file: +- batch: + - statement: + - create_partition_function_statement: + - keyword: CREATE + - keyword: PARTITION + - keyword: FUNCTION + - object_reference: + - naked_identifier: myIntRangePF1 + - bracketed: + - start_bracket: ( + - data_type: + - keyword: INT + - end_bracket: ) + - keyword: AS + - keyword: RANGE + - keyword: LEFT + - keyword: FOR + - keyword: VALUES + - bracketed: + - start_bracket: ( + - integer_literal: '1' + - comma: ',' + - integer_literal: '100' + - comma: ',' + - integer_literal: '1000' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_partition_function_statement: + - keyword: CREATE + - keyword: PARTITION + - keyword: FUNCTION + - object_reference: + - naked_identifier: myCharRangePF2 + - bracketed: + - start_bracket: ( + - data_type: + - keyword: CHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '1' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - keyword: RANGE + - keyword: RIGHT + - keyword: FOR + - keyword: VALUES + - bracketed: + - start_bracket: ( + - quoted_literal: '''A''' + - comma: ',' + - quoted_literal: '''B''' + - comma: ',' + - quoted_literal: '''C''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_partition_function_statement: + - keyword: CREATE + - keyword: PARTITION + - keyword: FUNCTION + - object_reference: + - quoted_identifier: '[myDateRangePF1]' + - bracketed: + - start_bracket: ( + - data_type: + - keyword: date + - end_bracket: ) + - keyword: AS + - keyword: RANGE + - keyword: RIGHT + - keyword: FOR + - keyword: VALUES + - bracketed: + - start_bracket: ( + - quoted_literal: '''20030201''' + - comma: ',' + - quoted_literal: '''20030301''' + - comma: ',' + - quoted_literal: '''20030401''' + - comma: ',' + - quoted_literal: '''20030501''' + - comma: ',' + - quoted_literal: '''20030601''' + - comma: ',' + - quoted_literal: '''20030701''' + - comma: ',' + - quoted_literal: '''20030801''' + - comma: ',' + - quoted_literal: '''20030901''' + - comma: ',' + - quoted_literal: '''20031001''' + - comma: ',' + - quoted_literal: '''20031101''' + - comma: ',' + - quoted_literal: '''20031201''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_partition_function_statement: + - keyword: ALTER + - keyword: PARTITION + - keyword: FUNCTION + - object_reference: + - naked_identifier: myIntRangePF1 + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: SPLIT + - keyword: RANGE + - bracketed: + - start_bracket: ( + - integer_literal: '500' + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_partition_function_statement: + - keyword: ALTER + - keyword: PARTITION + - keyword: FUNCTION + - object_reference: + - naked_identifier: myCharRangePF2 + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: MERGE + - keyword: RANGE + - bracketed: + - start_bracket: ( + - quoted_literal: '''D''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_partition_function_statement: + - keyword: CREATE + - keyword: PARTITION + - keyword: FUNCTION + - object_reference: + - quoted_identifier: '[partition_function_3]' + - bracketed: + - start_bracket: ( + - data_type: + - keyword: varbinary + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '128' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - keyword: RANGE + - keyword: LEFT + - keyword: FOR + - keyword: VALUES + - bracketed: + - start_bracket: ( + - binary_literal: 0x0039003900390039002D00310039003700320032003300350032 + - comma: ',' + - binary_literal: '0x006A0070003800370039003000390034' + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_scheme.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_scheme.sql new file mode 100644 index 000000000..65fa1ef18 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_scheme.sql @@ -0,0 +1,17 @@ +-- https://learn.microsoft.com/en-us/sql/t-sql/statements/create-partition-function-transact-sql#BKMK_examples + +CREATE PARTITION SCHEME myRangePS1 +AS PARTITION myRangePF1 +TO (test1fg, [test2fg], test3fg, test4fg); + + +CREATE PARTITION SCHEME myRangePS3 +AS PARTITION myRangePF3 +ALL TO ( test1fg ); + +CREATE PARTITION SCHEME [myRangePS1] +AS PARTITION myRangePF1 +ALL TO ( [PRIMARY] ); + +ALTER PARTITION SCHEME MyRangePS1 +NEXT USED test5fg; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_scheme.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_scheme.yml new file mode 100644 index 000000000..ecb7d9ea6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_partition_scheme.yml @@ -0,0 +1,79 @@ +file: +- batch: + - statement: + - create_partition_scheme_statement: + - keyword: CREATE + - keyword: PARTITION + - keyword: SCHEME + - object_reference: + - naked_identifier: myRangePS1 + - keyword: AS + - keyword: PARTITION + - object_reference: + - naked_identifier: myRangePF1 + - keyword: TO + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: test1fg + - comma: ',' + - object_reference: + - quoted_identifier: '[test2fg]' + - comma: ',' + - object_reference: + - naked_identifier: test3fg + - comma: ',' + - object_reference: + - naked_identifier: test4fg + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_partition_scheme_statement: + - keyword: CREATE + - keyword: PARTITION + - keyword: SCHEME + - object_reference: + - naked_identifier: myRangePS3 + - keyword: AS + - keyword: PARTITION + - object_reference: + - naked_identifier: myRangePF3 + - keyword: ALL + - keyword: TO + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: test1fg + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_partition_scheme_statement: + - keyword: CREATE + - keyword: PARTITION + - keyword: SCHEME + - object_reference: + - quoted_identifier: '[myRangePS1]' + - keyword: AS + - keyword: PARTITION + - object_reference: + - naked_identifier: myRangePF1 + - keyword: ALL + - keyword: TO + - bracketed: + - start_bracket: ( + - object_reference: + - quoted_identifier: '[PRIMARY]' + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_partition_scheme_statement: + - keyword: ALTER + - keyword: PARTITION + - keyword: SCHEME + - object_reference: + - naked_identifier: MyRangePS1 + - keyword: NEXT + - keyword: USED + - object_reference: + - naked_identifier: test5fg + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_procedure.yml index ea0926b47..c87b327fa 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_procedure.yml +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_procedure.yml @@ -1,710 +1,786 @@ file: -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: PROC - - object_reference: - - quoted_identifier: '[PROCEDURE_NAME]' - - keyword: AS - - statement: - - keyword: BEGIN - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '1' - - statement_terminator: ; - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[TEST]' - - keyword: AS - - statement: - - keyword: BEGIN - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '1' - - statement_terminator: ; - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: ALTER - - keyword: PROC - - object_reference: - - quoted_identifier: '[PROCEDURE_NAME]' - - keyword: AS - - statement: - - keyword: BEGIN - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '1' - - statement_terminator: ; - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: ALTER - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[PROCEDURE_NAME]' - - keyword: AS - - statement: - - keyword: BEGIN - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '1' - - statement_terminator: ; - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: OR - - keyword: ALTER - - keyword: PROC - - object_reference: - - quoted_identifier: '[PROCEDURE_NAME]' - - keyword: AS - - statement: - - keyword: BEGIN - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '1' - - statement_terminator: ; - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: OR - - keyword: ALTER - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[PROCEDURE_NAME]' - - keyword: AS - - statement: - - keyword: BEGIN - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '1' - - statement_terminator: ; - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[TEST]' - - bracketed: - - start_bracket: ( - - tsql_variable: '@id' - - data_type: - - data_type: - - data_type_identifier: UNIQUEIDENTIFIER - - end_bracket: ) - - keyword: AS - - statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '1' -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[TEST]' - - bracketed: - - start_bracket: ( - - tsql_variable: '@id' - - data_type: - - data_type: - - data_type_identifier: UNIQUEIDENTIFIER - - keyword: 'NULL' - - comparison_operator: - - raw_comparison_operator: = - - null_literal: 'NULL' - - comma: ',' - - tsql_variable: '@fooReadonly' - - data_type: - - data_type: - - data_type_identifier: NVARCHAR - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '42' - - end_bracket: ) - - comparison_operator: - - raw_comparison_operator: = - - naked_identifier: N - - quoted_literal: '''foo''' - - keyword: READONLY +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROC + - object_reference: + - quoted_identifier: '[PROCEDURE_NAME]' + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: ALTER + - keyword: PROC + - object_reference: + - quoted_identifier: '[PROCEDURE_NAME]' + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: ALTER + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[PROCEDURE_NAME]' + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: PROC + - object_reference: + - quoted_identifier: '[PROCEDURE_NAME]' + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[PROCEDURE_NAME]' + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@id' + - data_type: + - keyword: UNIQUEIDENTIFIER + - end_bracket: ) + - keyword: AS + - procedure_statement: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@id' + - data_type: + - keyword: UNIQUEIDENTIFIER + - keyword: 'NULL' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - null_literal: 'NULL' + - comma: ',' + - parameter: '@fooReadonly' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '42' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: N'foo' + - keyword: READONLY + - comma: ',' + - parameter: '@bar' + - data_type: + - keyword: BIT + - keyword: VARYING + - keyword: 'NULL' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - null_literal: 'NULL' + - keyword: OUTPUT + - comma: ',' + - parameter: '@output' + - data_type: + - keyword: TINYINT + - keyword: OUT + - end_bracket: ) + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@output' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: tinyint_value + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: TEST + - end_bracket: ) + - statement_terminator: ; + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - parameter: '@id' + - keyword: IS + - null_literal: 'NULL' + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameter: '@bar' + - comma: ',' + - select_clause_element: + - parameter: '@fooReadonly' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@id' + - data_type: + - keyword: UNIQUEIDENTIFIER + - keyword: 'NULL' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - null_literal: 'NULL' + - comma: ',' + - parameter: '@bar' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '32' + - end_bracket: ) + - keyword: 'NULL' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - null_literal: 'NULL' + - end_bracket: ) + - keyword: WITH + - keyword: ENCRYPTION - comma: ',' - - tsql_variable: '@bar' - - data_type: - - data_type: - - data_type_identifier: BIT - - keyword: VARYING - - keyword: 'NULL' - - comparison_operator: - - raw_comparison_operator: = - - null_literal: 'NULL' - - keyword: OUTPUT + - keyword: RECOMPILE - comma: ',' - - tsql_variable: '@output' - - data_type: - - data_type: - - data_type_identifier: TINYINT - - keyword: OUT - - end_bracket: ) - - keyword: AS - - statement: - - keyword: BEGIN - - keyword: SET - - tsql_variable: '@output' - - assignment_operator: - - raw_comparison_operator: = - - expression: + - execute_as_clause: + - keyword: EXECUTE + - keyword: AS + - quoted_literal: '''sa''' + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - procedure_parameter_list: - bracketed: - start_bracket: ( + - parameter: '@id' + - data_type: + - keyword: UNIQUEIDENTIFIER + - keyword: 'NULL' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - null_literal: 'NULL' + - comma: ',' + - parameter: '@bar' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '32' + - end_bracket: ) + - keyword: 'NULL' + - comparison_operator: + - raw_comparison_operator: = - expression: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: tinyint_value - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: dbo - - dot: . - - naked_identifier: TEST + - null_literal: 'NULL' - end_bracket: ) - - statement_terminator: ; - - keyword: IF - - expression: - - parameterized_expression: - - tsql_variable: '@id' - - keyword: IS - - null_literal: 'NULL' - - statement: - - keyword: BEGIN - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - parameterized_expression: - - tsql_variable: '@bar' - - comma: ',' - - select_clause_element: - - parameterized_expression: - - tsql_variable: '@fooReadonly' + - keyword: WITH + - keyword: ENCRYPTION + - comma: ',' + - keyword: RECOMPILE + - comma: ',' + - execute_as_clause: + - keyword: EXECUTE + - keyword: AS + - quoted_literal: '''sa''' + - keyword: FOR + - keyword: REPLICATION + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameter: '@id' + - comma: ',' + - select_clause_element: + - parameter: '@bar' + - statement_terminator: ; + - keyword: END - statement_terminator: ; - - keyword: END - - statement_terminator: ; - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[TEST]' - - bracketed: - - start_bracket: ( - - tsql_variable: '@id' - - data_type: - - data_type: - - data_type_identifier: UNIQUEIDENTIFIER - - keyword: 'NULL' - - comparison_operator: - - raw_comparison_operator: = - - null_literal: 'NULL' + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@id' + - data_type: + - keyword: INT + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - keyword: WITH + - keyword: NATIVE_COMPILATION + - comma: ',' + - keyword: SCHEMABINDING - comma: ',' - - tsql_variable: '@bar' - - data_type: - - data_type: - - data_type_identifier: NVARCHAR - - bracketed_arguments: + - execute_as_clause: + - keyword: EXECUTE + - keyword: AS + - keyword: OWNER + - keyword: AS + - procedure_statement: + - statement: + - atomic_begin_end_block: + - keyword: BEGIN + - keyword: ATOMIC + - keyword: WITH - bracketed: - start_bracket: ( - - numeric_literal: '32' + - keyword: LANGUAGE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'us_english' + - comma: ',' + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: SERIALIZABLE + - comma: ',' + - keyword: DATEFIRST + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - comma: ',' + - keyword: DATEFORMAT + - comparison_operator: + - raw_comparison_operator: = + - date_format: dym + - comma: ',' + - keyword: DELAYED_DURABILITY + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON - end_bracket: ) - - keyword: 'NULL' - - comparison_operator: - - raw_comparison_operator: = - - null_literal: 'NULL' - - end_bracket: ) - - keyword: WITH - - keyword: ENCRYPTION - - comma: ',' - - keyword: RECOMPILE - - comma: ',' - - keyword: EXECUTE - - keyword: AS - - quoted_literal: '''sa''' - - keyword: AS - - statement: - - keyword: BEGIN - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '1' - - statement_terminator: ; - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[TEST]' - - bracketed: - - start_bracket: ( - - tsql_variable: '@id' - - data_type: - - data_type: - - data_type_identifier: UNIQUEIDENTIFIER - - keyword: 'NULL' - - comparison_operator: - - raw_comparison_operator: = - - null_literal: 'NULL' + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@id' + - data_type: + - keyword: INT + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - keyword: WITH + - keyword: NATIVE_COMPILATION - comma: ',' - - tsql_variable: '@bar' - - data_type: - - data_type: - - data_type_identifier: NVARCHAR - - bracketed_arguments: + - keyword: SCHEMABINDING + - comma: ',' + - execute_as_clause: + - keyword: EXECUTE + - keyword: AS + - keyword: OWNER + - keyword: AS + - procedure_statement: + - statement: + - atomic_begin_end_block: + - keyword: BEGIN + - keyword: ATOMIC + - keyword: WITH - bracketed: - start_bracket: ( - - numeric_literal: '32' + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: SNAPSHOT + - comma: ',' + - keyword: LANGUAGE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''us_english''' - end_bracket: ) - - keyword: 'NULL' - - comparison_operator: - - raw_comparison_operator: = - - null_literal: 'NULL' - - end_bracket: ) - - keyword: WITH - - keyword: ENCRYPTION - - comma: ',' - - keyword: RECOMPILE - - comma: ',' - - keyword: EXECUTE - - keyword: AS - - quoted_literal: '''sa''' - - keyword: FOR - - keyword: REPLICATION - - keyword: AS - - statement: - - keyword: BEGIN - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - parameterized_expression: - - tsql_variable: '@id' - - comma: ',' - - select_clause_element: - - parameterized_expression: - - tsql_variable: '@bar' - - statement_terminator: ; - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: OR - - keyword: ALTER - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[TEST]' - - bracketed: - - start_bracket: ( - - tsql_variable: '@id' - - data_type: - - data_type: - - data_type_identifier: INT - - keyword: NOT - - keyword: 'NULL' - - end_bracket: ) - - keyword: WITH - - keyword: NATIVE_COMPILATION - - comma: ',' - - keyword: SCHEMABINDING - - comma: ',' - - keyword: EXECUTE - - keyword: AS - - keyword: OWNER - - keyword: AS - - keyword: BEGIN - - keyword: ATOMIC - - keyword: WITH - - bracketed: - - start_bracket: ( - - keyword: LANGUAGE - - comparison_operator: - - raw_comparison_operator: = - - naked_identifier: N - - quoted_literal: '''us_english''' - - comma: ',' - - keyword: TRANSACTION - - keyword: ISOLATION - - keyword: LEVEL - - comparison_operator: - - raw_comparison_operator: = - - naked_identifier: SERIALIZABLE - - comma: ',' - - keyword: DATEFIRST - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '10' - - comma: ',' - - keyword: DATEFORMAT - - comparison_operator: - - raw_comparison_operator: = - - naked_identifier: dym - - comma: ',' - - keyword: DELAYED_DURABILITY - - comparison_operator: - - raw_comparison_operator: = - - keyword: ON - - end_bracket: ) - - statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '1' - - statement_terminator: ; - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: OR - - keyword: ALTER - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[TEST]' - - bracketed: - - start_bracket: ( - - tsql_variable: '@id' - - data_type: - - data_type: - - data_type_identifier: INT - - keyword: NOT - - keyword: 'NULL' - - end_bracket: ) - - keyword: WITH - - keyword: NATIVE_COMPILATION - - comma: ',' - - keyword: SCHEMABINDING - - comma: ',' - - keyword: EXECUTE - - keyword: AS - - keyword: OWNER - - keyword: AS - - keyword: BEGIN - - keyword: ATOMIC - - keyword: WITH - - bracketed: - - start_bracket: ( - - keyword: TRANSACTION - - keyword: ISOLATION - - keyword: LEVEL - - comparison_operator: - - raw_comparison_operator: = - - naked_identifier: SNAPSHOT - - comma: ',' - - keyword: LANGUAGE - - comparison_operator: - - raw_comparison_operator: = - - quoted_literal: '''us_english''' - - end_bracket: ) - - statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '1' - - statement_terminator: ; - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: OR - - keyword: ALTER - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[TEST]' - - bracketed: - - start_bracket: ( - - tsql_variable: '@id' - - data_type: - - data_type: - - data_type_identifier: INT - - keyword: NOT - - keyword: 'NULL' - - end_bracket: ) - - keyword: WITH - - keyword: NATIVE_COMPILATION - - comma: ',' - - keyword: SCHEMABINDING - - comma: ',' - - keyword: EXECUTE - - keyword: AS - - keyword: OWNER - - keyword: AS - - keyword: BEGIN - - keyword: ATOMIC - - keyword: WITH - - bracketed: - - start_bracket: ( - - keyword: TRANSACTION - - keyword: ISOLATION - - keyword: LEVEL - - comparison_operator: - - raw_comparison_operator: = - - keyword: REPEATABLE - - keyword: READ - - comma: ',' - - keyword: LANGUAGE - - comparison_operator: - - raw_comparison_operator: = - - naked_identifier: N - - quoted_literal: '''us_english''' - - comma: ',' - - keyword: DELAYED_DURABILITY - - comparison_operator: - - raw_comparison_operator: = - - keyword: OFF + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@id' + - data_type: + - keyword: INT + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - keyword: WITH + - keyword: NATIVE_COMPILATION - comma: ',' - - keyword: DATEFORMAT - - comparison_operator: - - raw_comparison_operator: = - - naked_identifier: myd - - end_bracket: ) - - statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '1' - - statement_terminator: ; - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[TEST]' - - keyword: AS - - keyword: EXTERNAL - - keyword: NAME - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[class_name]' - - dot: . - - quoted_identifier: '[static_method]' -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[TEST]' - - statement_terminator: ; - - numeric_literal: '1064' - - keyword: AS - - keyword: EXTERNAL - - keyword: NAME - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[class_name]' - - dot: . - - quoted_identifier: '[static_method]' -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: OR - - keyword: ALTER - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[TEST]' - - bracketed: - - start_bracket: ( - - tsql_variable: '@id' - - data_type: - - data_type: - - data_type_identifier: UNIQUEIDENTIFIER - - comparison_operator: - - raw_comparison_operator: = - - function: - - function_name: - - function_name_identifier: NEWID - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) + - keyword: SCHEMABINDING - comma: ',' - - tsql_variable: '@output' - - data_type: - - data_type: - - data_type_identifier: NVARCHAR - - bracketed_arguments: + - execute_as_clause: + - keyword: EXECUTE + - keyword: AS + - keyword: OWNER + - keyword: AS + - procedure_statement: + - statement: + - atomic_begin_end_block: + - keyword: BEGIN + - keyword: ATOMIC + - keyword: WITH - bracketed: - start_bracket: ( - - numeric_literal: '32' + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - comparison_operator: + - raw_comparison_operator: = + - keyword: REPEATABLE + - keyword: READ + - comma: ',' + - keyword: LANGUAGE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'us_english' + - comma: ',' + - keyword: DELAYED_DURABILITY + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - comma: ',' + - keyword: DATEFORMAT + - comparison_operator: + - raw_comparison_operator: = + - date_format: myd - end_bracket: ) - - keyword: OUTPUT - - comma: ',' - - tsql_variable: '@activated' - - data_type: - - data_type: - - data_type_identifier: BIT - - keyword: OUT - - keyword: READONLY - - end_bracket: ) - - keyword: WITH - - keyword: EXECUTE - - keyword: AS - - quoted_literal: '''sa''' - - keyword: AS - - keyword: EXTERNAL - - keyword: NAME - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[class_name]' - - dot: . - - quoted_identifier: '[static_method]' -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: OR - - keyword: ALTER - - keyword: PROCEDURE - - object_reference: - - naked_identifier: dbo - - dot: . - - naked_identifier: DoSomething - - keyword: AS - - statement: - - keyword: BEGIN - - keyword: SET - - keyword: NOCOUNT - - keyword: ON - - statement_terminator: ; - - keyword: SET - - keyword: XACT_ABORT - - keyword: ON - - statement_terminator: ; - - keyword: END -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: OR - - keyword: ALTER - - keyword: PROCEDURE - - object_reference: - - naked_identifier: dbo - - dot: . - - naked_identifier: DoSomething - - keyword: AS - - statement: - - keyword: BEGIN - - keyword: SET - - keyword: NOCOUNT - - comma: ',' - - keyword: XACT_ABORT - - keyword: ON + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - keyword: AS + - procedure_statement: + - keyword: EXTERNAL + - keyword: NAME + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[class_name]' + - dot: . + - quoted_identifier: '[static_method]' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' - statement_terminator: ; - - keyword: END -- statement: - - keyword: GO + - numeric_literal: '1064' + - keyword: AS + - procedure_statement: + - keyword: EXTERNAL + - keyword: NAME + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[class_name]' + - dot: . + - quoted_identifier: '[static_method]' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - procedure_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@id' + - data_type: + - keyword: UNIQUEIDENTIFIER + - comparison_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: NEWID + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - parameter: '@output' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '32' + - end_bracket: ) + - keyword: OUTPUT + - comma: ',' + - parameter: '@activated' + - data_type: + - keyword: BIT + - keyword: OUT + - keyword: READONLY + - end_bracket: ) + - keyword: WITH + - execute_as_clause: + - keyword: EXECUTE + - keyword: AS + - quoted_literal: '''sa''' + - keyword: AS + - procedure_statement: + - keyword: EXTERNAL + - keyword: NAME + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[class_name]' + - dot: . + - quoted_identifier: '[static_method]' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: PROCEDURE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: DoSomething + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - set_segment: + - keyword: SET + - keyword: NOCOUNT + - keyword: ON + - statement_terminator: ; + - statement: + - set_segment: + - keyword: SET + - keyword: XACT_ABORT + - keyword: ON + - statement_terminator: ; + - keyword: END + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: PROCEDURE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: DoSomething + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - set_segment: + - keyword: SET + - keyword: NOCOUNT + - comma: ',' + - keyword: XACT_ABORT + - keyword: ON + - statement_terminator: ; + - keyword: END + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_role.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_role.sql new file mode 100644 index 000000000..c9c64e20f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_role.sql @@ -0,0 +1,2 @@ +CREATE ROLE testuser; +CREATE ROLE testuser AUTHORIZATION dbo; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_role.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_role.yml new file mode 100644 index 000000000..468ad9468 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_role.yml @@ -0,0 +1,19 @@ +file: +- batch: + - statement: + - create_role_statement: + - keyword: CREATE + - keyword: ROLE + - role_reference: + - naked_identifier: testuser + - statement_terminator: ; + - statement: + - create_role_statement: + - keyword: CREATE + - keyword: ROLE + - role_reference: + - naked_identifier: testuser + - keyword: AUTHORIZATION + - role_reference: + - naked_identifier: dbo + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_schema.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_schema.sql new file mode 100644 index 000000000..6e5292bbb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_schema.sql @@ -0,0 +1,6 @@ +CREATE SCHEMA [Reporting] +GO + +CREATE SCHEMA [Extracts] + AUTHORIZATION [dbo]; +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_schema.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_schema.yml new file mode 100644 index 000000000..0297d405b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_schema.yml @@ -0,0 +1,23 @@ +file: +- batch: + - statement: + - create_schema_statement: + - keyword: CREATE + - keyword: SCHEMA + - schema_reference: + - quoted_identifier: '[Reporting]' + - go_statement: + - keyword: GO +- batch: + - statement: + - create_schema_statement: + - keyword: CREATE + - keyword: SCHEMA + - schema_reference: + - quoted_identifier: '[Extracts]' + - keyword: AUTHORIZATION + - role_reference: + - quoted_identifier: '[dbo]' + - statement_terminator: ; + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_security_policy.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_security_policy.sql new file mode 100644 index 000000000..7ce11ca3b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_security_policy.sql @@ -0,0 +1,53 @@ +-- https://learn.microsoft.com/en-us/sql/t-sql/statements/create-security-policy-transact-sql + +CREATE SECURITY POLICY [FederatedSecurityPolicy] +ADD FILTER PREDICATE [rls].[fn_securitypredicate]([CustomerId]) +ON [dbo].[Customer]; + + +CREATE SECURITY POLICY [FederatedSecurityPolicy] +ADD FILTER PREDICATE [rls].[fn_securitypredicate1]([CustomerId]) + ON [dbo].[Customer], +ADD FILTER PREDICATE [rls].[fn_securitypredicate1]([VendorId]) + ON [dbo].[Vendor], +ADD FILTER PREDICATE [rls].[fn_securitypredicate2]([WingId]) + ON [dbo].[Patient] +WITH (STATE = ON); + + +CREATE SECURITY POLICY rls.SecPol + ADD FILTER PREDICATE rls.tenantAccessPredicate(TenantId) ON dbo.Sales, + ADD BLOCK PREDICATE rls.tenantAccessPredicate(TenantId) ON dbo.Sales AFTER INSERT +; + + + +-- https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-security-policy-transact-sql + +ALTER SECURITY POLICY pol1 + ADD FILTER PREDICATE schema_preds.SecPredicate(column1) + ON myschema.mytable; + +ALTER SECURITY POLICY pol1 WITH ( STATE = ON ); + +ALTER SECURITY POLICY pol1 +ADD FILTER PREDICATE schema_preds.SecPredicate1(column1) + ON myschema.mytable1, +DROP FILTER PREDICATE + ON myschema.mytable2, +ADD FILTER PREDICATE schema_preds.SecPredicate2(column2, 1) + ON myschema.mytable3; + +ALTER SECURITY POLICY pol1 + ALTER FILTER PREDICATE schema_preds.SecPredicate2(column1) + ON myschema.mytable; + +ALTER SECURITY POLICY rls.SecPol + ALTER BLOCK PREDICATE rls.tenantAccessPredicate_v2(TenantId) + ON dbo.Sales AFTER INSERT; + + + +-- https://learn.microsoft.com/en-us/sql/t-sql/statements/drop-security-policy-transact-sql + +DROP SECURITY POLICY secPolicy; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_security_policy.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_security_policy.yml new file mode 100644 index 000000000..2023af6ed --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_security_policy.yml @@ -0,0 +1,301 @@ +file: +- batch: + - statement: + - create_security_policy_statement: + - keyword: CREATE + - keyword: SECURITY + - keyword: POLICY + - object_reference: + - quoted_identifier: '[FederatedSecurityPolicy]' + - keyword: ADD + - keyword: FILTER + - keyword: PREDICATE + - object_reference: + - quoted_identifier: '[rls]' + - dot: . + - quoted_identifier: '[fn_securitypredicate]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[CustomerId]' + - end_bracket: ) + - keyword: ON + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[Customer]' + - statement_terminator: ; + - statement: + - create_security_policy_statement: + - keyword: CREATE + - keyword: SECURITY + - keyword: POLICY + - object_reference: + - quoted_identifier: '[FederatedSecurityPolicy]' + - keyword: ADD + - keyword: FILTER + - keyword: PREDICATE + - object_reference: + - quoted_identifier: '[rls]' + - dot: . + - quoted_identifier: '[fn_securitypredicate1]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[CustomerId]' + - end_bracket: ) + - keyword: ON + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[Customer]' + - comma: ',' + - keyword: ADD + - keyword: FILTER + - keyword: PREDICATE + - object_reference: + - quoted_identifier: '[rls]' + - dot: . + - quoted_identifier: '[fn_securitypredicate1]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[VendorId]' + - end_bracket: ) + - keyword: ON + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[Vendor]' + - comma: ',' + - keyword: ADD + - keyword: FILTER + - keyword: PREDICATE + - object_reference: + - quoted_identifier: '[rls]' + - dot: . + - quoted_identifier: '[fn_securitypredicate2]' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[WingId]' + - end_bracket: ) + - keyword: ON + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[Patient]' + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: STATE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_security_policy_statement: + - keyword: CREATE + - keyword: SECURITY + - keyword: POLICY + - object_reference: + - naked_identifier: rls + - dot: . + - naked_identifier: SecPol + - keyword: ADD + - keyword: FILTER + - keyword: PREDICATE + - object_reference: + - naked_identifier: rls + - dot: . + - naked_identifier: tenantAccessPredicate + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: TenantId + - end_bracket: ) + - keyword: ON + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Sales + - comma: ',' + - keyword: ADD + - keyword: BLOCK + - keyword: PREDICATE + - object_reference: + - naked_identifier: rls + - dot: . + - naked_identifier: tenantAccessPredicate + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: TenantId + - end_bracket: ) + - keyword: ON + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Sales + - keyword: AFTER + - keyword: INSERT + - statement_terminator: ; + - statement: + - alter_security_policy_statement: + - keyword: ALTER + - keyword: SECURITY + - keyword: POLICY + - object_reference: + - naked_identifier: pol1 + - keyword: ADD + - keyword: FILTER + - keyword: PREDICATE + - object_reference: + - naked_identifier: schema_preds + - dot: . + - naked_identifier: SecPredicate + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: column1 + - end_bracket: ) + - keyword: ON + - object_reference: + - naked_identifier: myschema + - dot: . + - naked_identifier: mytable + - statement_terminator: ; + - statement: + - alter_security_policy_statement: + - keyword: ALTER + - keyword: SECURITY + - keyword: POLICY + - object_reference: + - naked_identifier: pol1 + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: STATE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - statement_terminator: ; + - statement: + - alter_security_policy_statement: + - keyword: ALTER + - keyword: SECURITY + - keyword: POLICY + - object_reference: + - naked_identifier: pol1 + - keyword: ADD + - keyword: FILTER + - keyword: PREDICATE + - object_reference: + - naked_identifier: schema_preds + - dot: . + - naked_identifier: SecPredicate1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: column1 + - end_bracket: ) + - keyword: ON + - object_reference: + - naked_identifier: myschema + - dot: . + - naked_identifier: mytable1 + - comma: ',' + - keyword: DROP + - keyword: FILTER + - keyword: PREDICATE + - keyword: ON + - object_reference: + - naked_identifier: myschema + - dot: . + - naked_identifier: mytable2 + - comma: ',' + - keyword: ADD + - keyword: FILTER + - keyword: PREDICATE + - object_reference: + - naked_identifier: schema_preds + - dot: . + - naked_identifier: SecPredicate2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: column2 + - comma: ',' + - expression: + - integer_literal: '1' + - end_bracket: ) + - keyword: ON + - object_reference: + - naked_identifier: myschema + - dot: . + - naked_identifier: mytable3 + - statement_terminator: ; + - statement: + - alter_security_policy_statement: + - keyword: ALTER + - keyword: SECURITY + - keyword: POLICY + - object_reference: + - naked_identifier: pol1 + - keyword: ALTER + - keyword: FILTER + - keyword: PREDICATE + - object_reference: + - naked_identifier: schema_preds + - dot: . + - naked_identifier: SecPredicate2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: column1 + - end_bracket: ) + - keyword: ON + - object_reference: + - naked_identifier: myschema + - dot: . + - naked_identifier: mytable + - statement_terminator: ; + - statement: + - alter_security_policy_statement: + - keyword: ALTER + - keyword: SECURITY + - keyword: POLICY + - object_reference: + - naked_identifier: rls + - dot: . + - naked_identifier: SecPol + - keyword: ALTER + - keyword: BLOCK + - keyword: PREDICATE + - object_reference: + - naked_identifier: rls + - dot: . + - naked_identifier: tenantAccessPredicate_v2 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: TenantId + - end_bracket: ) + - keyword: ON + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Sales + - keyword: AFTER + - keyword: INSERT + - statement_terminator: ; + - statement: + - drop_security_policy: + - keyword: DROP + - keyword: SECURITY + - keyword: POLICY + - object_reference: + - naked_identifier: secPolicy + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_server_role.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_server_role.sql new file mode 100644 index 000000000..24131d836 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_server_role.sql @@ -0,0 +1,3 @@ +CREATE SERVER ROLE server_role AUTHORIZATION sa; + +CREATE SERVER ROLE server_role2; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_server_role.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_server_role.yml new file mode 100644 index 000000000..a8eb093b6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_server_role.yml @@ -0,0 +1,21 @@ +file: +- batch: + - statement: + - create_server_role_statement: + - keyword: CREATE + - keyword: SERVER + - keyword: ROLE + - role_reference: + - naked_identifier: server_role + - keyword: AUTHORIZATION + - role_reference: + - naked_identifier: sa + - statement_terminator: ; + - statement: + - create_server_role_statement: + - keyword: CREATE + - keyword: SERVER + - keyword: ROLE + - role_reference: + - naked_identifier: server_role2 + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table.sql new file mode 100644 index 000000000..f93577057 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table.sql @@ -0,0 +1,39 @@ +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) + +-- Test various forms of quoted data types +CREATE TABLE foo ( + pk int PRIMARY KEY, + quoted_name [custom udt], + qualified_name sch.qualified, + quoted_qualified "my schema".qualified, + more_quoted "my schema"."custom udt", + quoted_udt sch.[custom udt] +); + +-- computed column +-- https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql?view=sql-server-ver16#column_name-as-computed_column_expression +-- https://learn.microsoft.com/en-us/sql/relational-databases/tables/specify-computed-columns-in-a-table?view=sql-server-ver16 +CREATE TABLE dbo.Products ( + ProductID int IDENTITY (1,1) NOT NULL + , InventoryTs datetime2(0) + , QtyAvailable smallint + , QtySold smallint + , UnitPrice money + , InventoryValue1 AS QtyAvailable * UnitPrice PERSISTED + , InventoryValue2 AS QtyAvailable * UnitPrice PERSISTED NOT NULL + , InventoryValue3 AS QtyAvailable * UnitPrice + , InventoryValue4 AS QtyAvailable * UnitPrice PRIMARY KEY + , [SoldValue] AS (QtySold * UnitPrice) + , InventoyDate AS CAST(InventoryTs AS date) +); + +-- issue #6340 +CREATE TABLE [dbo].[Foo]( + [ID] [int] IDENTITY(1,1) NOT NULL + CONSTRAINT [PK_Foo_ID] PRIMARY KEY CLUSTERED ([ID] ASC), + [other_ID] [int] FOREIGN KEY REFERENCES [dbo].[Bar] (id) UNIQUE +); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table.yml new file mode 100644 index 000000000..e8276c0a8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table.yml @@ -0,0 +1,292 @@ +file: +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: foo + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: pk + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_definition: + - naked_identifier: quoted_name + - data_type: + - quoted_identifier: '[custom udt]' + - comma: ',' + - column_definition: + - naked_identifier: qualified_name + - data_type: + - naked_identifier: sch + - dot: . + - data_type_identifier: qualified + - comma: ',' + - column_definition: + - naked_identifier: quoted_qualified + - data_type: + - quoted_identifier: '"my schema"' + - dot: . + - data_type_identifier: qualified + - comma: ',' + - column_definition: + - naked_identifier: more_quoted + - data_type: + - quoted_identifier: '"my schema"' + - dot: . + - quoted_identifier: '"custom udt"' + - comma: ',' + - column_definition: + - naked_identifier: quoted_udt + - data_type: + - naked_identifier: sch + - dot: . + - quoted_identifier: '[custom udt]' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Products + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: ProductID + - data_type: + - keyword: int + - column_constraint_segment: + - identity_grammar: + - keyword: IDENTITY + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: InventoryTs + - data_type: + - keyword: datetime2 + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '0' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: QtyAvailable + - data_type: + - keyword: smallint + - comma: ',' + - column_definition: + - naked_identifier: QtySold + - data_type: + - keyword: smallint + - comma: ',' + - column_definition: + - naked_identifier: UnitPrice + - data_type: + - keyword: money + - comma: ',' + - computed_column_definition: + - naked_identifier: InventoryValue1 + - keyword: AS + - expression: + - column_reference: + - naked_identifier: QtyAvailable + - binary_operator: '*' + - column_reference: + - naked_identifier: UnitPrice + - keyword: PERSISTED + - comma: ',' + - computed_column_definition: + - naked_identifier: InventoryValue2 + - keyword: AS + - expression: + - column_reference: + - naked_identifier: QtyAvailable + - binary_operator: '*' + - column_reference: + - naked_identifier: UnitPrice + - keyword: PERSISTED + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - computed_column_definition: + - naked_identifier: InventoryValue3 + - keyword: AS + - expression: + - column_reference: + - naked_identifier: QtyAvailable + - binary_operator: '*' + - column_reference: + - naked_identifier: UnitPrice + - comma: ',' + - computed_column_definition: + - naked_identifier: InventoryValue4 + - keyword: AS + - expression: + - column_reference: + - naked_identifier: QtyAvailable + - binary_operator: '*' + - column_reference: + - naked_identifier: UnitPrice + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - computed_column_definition: + - quoted_identifier: '[SoldValue]' + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: QtySold + - binary_operator: '*' + - column_reference: + - naked_identifier: UnitPrice + - end_bracket: ) + - comma: ',' + - computed_column_definition: + - naked_identifier: InventoyDate + - keyword: AS + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: InventoryTs + - keyword: AS + - data_type: + - keyword: date + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[Foo]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[ID]' + - data_type: + - data_type_identifier: '[int]' + - column_constraint_segment: + - identity_grammar: + - keyword: IDENTITY + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - quoted_identifier: '[PK_Foo_ID]' + - keyword: PRIMARY + - keyword: KEY + - keyword: CLUSTERED + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - quoted_identifier: '[ID]' + - keyword: ASC + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[other_ID]' + - data_type: + - data_type_identifier: '[int]' + - column_constraint_segment: + - keyword: FOREIGN + - keyword: KEY + - column_constraint_segment: + - references_constraint_grammar: + - keyword: REFERENCES + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[Bar]' + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - end_bracket: ) + - column_constraint_segment: + - keyword: UNIQUE + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_as_select.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_as_select.sql new file mode 100644 index 000000000..df2925810 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_as_select.sql @@ -0,0 +1,55 @@ +--Azure Synapse Analytics specific +CREATE TABLE [dbo].[PL_stage] +WITH (DISTRIBUTION = HASH([ID]), HEAP) +AS +WITH CommentsTracking +AS +( + SELECT + 'Program' AS Program +) +SELECT e.[ID] + ,e.[ArriveDate] + ,e.[Contribution] + ,e.[DischargeDate] + ,e.[Encounter] + ,e.[Facility] + ,e.[Region] + ,e.[LOS] +FROM dbo.Encounter e +JOIN dbo.Finance f ON e.[ID] = f.[ID] + +DROP TABLE [dbo].[PL_stage] + +CREATE TABLE [dbo].[PL_stage] +WITH (DISTRIBUTION = HASH([ID]), HEAP) +AS +SELECT e.[ID] + ,e.[ArriveDate] + ,e.[Contribution] + ,e.[DischargeDate] + ,e.[Encounter] + ,e.[Facility] + ,e.[Region] + ,e.[LOS] +FROM dbo.Encounter e +JOIN dbo.Finance f ON e.[ID] = f.[ID]; + +DROP TABLE [dbo].[PL_stage]; + +CREATE TABLE [dbo].[PL_stage] +WITH (DISTRIBUTION = HASH([ID]), HEAP) +AS +( + SELECT e.[ID] + ,e.[ArriveDate] + ,e.[Contribution] + ,e.[DischargeDate] + ,e.[Encounter] + ,e.[Facility] + ,e.[Region] + ,e.[LOS] + FROM dbo.Encounter e + JOIN dbo.Finance f ON e.[ID] = f.[ID] +) +OPTION (LABEL = 'Test_Label') diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_as_select.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_as_select.yml new file mode 100644 index 000000000..d11b92477 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_as_select.yml @@ -0,0 +1,383 @@ +file: +- batch: + - statement: + - create_table_as_select_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[PL_stage]' + - table_distribution_index_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_distribution_clause: + - keyword: DISTRIBUTION + - comparison_operator: + - raw_comparison_operator: = + - keyword: HASH + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[ID]' + - end_bracket: ) + - comma: ',' + - table_index_clause: + - keyword: HEAP + - end_bracket: ) + - keyword: AS + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: CommentsTracking + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''Program''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Program + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[ID]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[ArriveDate]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[Contribution]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[DischargeDate]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[Encounter]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[Facility]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[Region]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[LOS]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Encounter + - alias_expression: + - naked_identifier: e + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Finance + - alias_expression: + - naked_identifier: f + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[ID]' + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: f + - dot: . + - quoted_identifier: '[ID]' + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[PL_stage]' + - statement: + - create_table_as_select_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[PL_stage]' + - table_distribution_index_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_distribution_clause: + - keyword: DISTRIBUTION + - comparison_operator: + - raw_comparison_operator: = + - keyword: HASH + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[ID]' + - end_bracket: ) + - comma: ',' + - table_index_clause: + - keyword: HEAP + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[ID]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[ArriveDate]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[Contribution]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[DischargeDate]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[Encounter]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[Facility]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[Region]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[LOS]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Encounter + - alias_expression: + - naked_identifier: e + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Finance + - alias_expression: + - naked_identifier: f + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[ID]' + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: f + - dot: . + - quoted_identifier: '[ID]' + - statement_terminator: ; + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[PL_stage]' + - statement_terminator: ; + - statement: + - create_table_as_select_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[PL_stage]' + - table_distribution_index_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_distribution_clause: + - keyword: DISTRIBUTION + - comparison_operator: + - raw_comparison_operator: = + - keyword: HASH + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[ID]' + - end_bracket: ) + - comma: ',' + - table_index_clause: + - keyword: HEAP + - end_bracket: ) + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[ID]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[ArriveDate]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[Contribution]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[DischargeDate]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[Encounter]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[Facility]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[Region]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[LOS]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Encounter + - alias_expression: + - naked_identifier: e + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Finance + - alias_expression: + - naked_identifier: f + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: e + - dot: . + - quoted_identifier: '[ID]' + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: f + - dot: . + - quoted_identifier: '[ID]' + - end_bracket: ) + - option_clause: + - keyword: OPTION + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: LABEL + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Test_Label''' + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_constraints.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_constraints.sql new file mode 100644 index 000000000..0f28684fe --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_constraints.sql @@ -0,0 +1,43 @@ +CREATE TABLE [dbo].[example]( + [Column A] [int] IDENTITY, + [Column B] [int] IDENTITY(1, 1) NOT NULL, + [ColumnC] varchar(100) DEFAULT 'mydefault', + [ColumnDecimal] DATE DEFAULT GETDATE(), + [ColumnUser] char(30) DEFAULT CURRENT_USER, + [col1] int default ((-1)) not null, + [col1] int default (-1) not null, + [col1] int default -1 not null, + [col1] INT DEFAULT (NULL) NULL +) +GO + +create table [schema1].[table1] ( + [col1] INT + , PRIMARY KEY CLUSTERED ([col1] ASC) +) +GO + +create table [schema1].[table1] ( + [col1] INT + , CONSTRAINT [Pk_Id] PRIMARY KEY NONCLUSTERED ([col1] DESC) +) +GO + +CREATE TABLE [dbo].[table1] ( + [ColumnB] [varchar](100) FILESTREAM MASKED WITH (FUNCTION = 'my_func'), + [ColumnC] varchar(100) NULL NOT FOR REPLICATION, + [ColumnDecimal] decimal(10,3) GENERATED ALWAYS AS ROW START HIDDEN, + [columnE] varchar(100) ENCRYPTED WITH (COLUMN_ENCRYPTION_KEY = key_name, + ENCRYPTION_TYPE = RANDOMIZED, + ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256' + ), + [column1] varchar (100) collate Latin1_General_BIN +) +GO + +CREATE TABLE table_name ( + id UNIQUEIDENTIFIER NOT NULL + CONSTRAINT constraint_name + REFERENCES referenced_table_name + ON DELETE NO ACTION +); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_constraints.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_constraints.yml new file mode 100644 index 000000000..8d8a7cba0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_constraints.yml @@ -0,0 +1,354 @@ +file: +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[example]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column A]' + - data_type: + - data_type_identifier: '[int]' + - column_constraint_segment: + - identity_grammar: + - keyword: IDENTITY + - comma: ',' + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[int]' + - column_constraint_segment: + - identity_grammar: + - keyword: IDENTITY + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: DEFAULT + - quoted_literal: '''mydefault''' + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: DATE + - column_constraint_segment: + - keyword: DEFAULT + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnUser]' + - data_type: + - keyword: char + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '30' + - end_bracket: ) + - column_constraint_segment: + - keyword: DEFAULT + - bare_function: CURRENT_USER + - comma: ',' + - column_definition: + - quoted_identifier: '[col1]' + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: default + - bracketed: + - start_bracket: ( + - bracketed: + - start_bracket: ( + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '1' + - end_bracket: ) + - end_bracket: ) + - column_constraint_segment: + - keyword: not + - keyword: 'null' + - comma: ',' + - column_definition: + - quoted_identifier: '[col1]' + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: default + - bracketed: + - start_bracket: ( + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '1' + - end_bracket: ) + - column_constraint_segment: + - keyword: not + - keyword: 'null' + - comma: ',' + - column_definition: + - quoted_identifier: '[col1]' + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: default + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '1' + - column_constraint_segment: + - keyword: not + - keyword: 'null' + - comma: ',' + - column_definition: + - quoted_identifier: '[col1]' + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: DEFAULT + - bracketed: + - start_bracket: ( + - null_literal: 'NULL' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - end_bracket: ) + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: create + - keyword: table + - table_reference: + - quoted_identifier: '[schema1]' + - dot: . + - quoted_identifier: '[table1]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[col1]' + - data_type: + - keyword: INT + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - keyword: CLUSTERED + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - quoted_identifier: '[col1]' + - keyword: ASC + - end_bracket: ) + - end_bracket: ) + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: create + - keyword: table + - table_reference: + - quoted_identifier: '[schema1]' + - dot: . + - quoted_identifier: '[table1]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[col1]' + - data_type: + - keyword: INT + - comma: ',' + - table_constraint: + - keyword: CONSTRAINT + - object_reference: + - quoted_identifier: '[Pk_Id]' + - keyword: PRIMARY + - keyword: KEY + - keyword: NONCLUSTERED + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - quoted_identifier: '[col1]' + - keyword: DESC + - end_bracket: ) + - end_bracket: ) + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[table1]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[ColumnB]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: FILESTREAM + - column_constraint_segment: + - keyword: MASKED + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FUNCTION + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''my_func''' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - column_constraint_segment: + - keyword: NOT + - keyword: FOR + - keyword: REPLICATION + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - column_constraint_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - keyword: ROW + - keyword: START + - keyword: HIDDEN + - comma: ',' + - column_definition: + - quoted_identifier: '[columnE]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - encrypted_with_grammar: + - keyword: ENCRYPTED + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: COLUMN_ENCRYPTION_KEY + - comparison_operator: + - raw_comparison_operator: = + - naked_identifier: key_name + - comma: ',' + - keyword: ENCRYPTION_TYPE + - comparison_operator: + - raw_comparison_operator: = + - keyword: RANDOMIZED + - comma: ',' + - keyword: ALGORITHM + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''AEAD_AES_256_CBC_HMAC_SHA_256''' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[column1]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: collate + - collation_reference: + - naked_identifier: Latin1_General_BIN + - end_bracket: ) + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: table_name + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - keyword: UNIQUEIDENTIFIER + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: constraint_name + - references_constraint_grammar: + - keyword: REFERENCES + - table_reference: + - naked_identifier: referenced_table_name + - keyword: ON + - keyword: DELETE + - keyword: NO + - keyword: ACTION + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_graph.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_graph.sql new file mode 100644 index 000000000..cd1882ea0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_graph.sql @@ -0,0 +1,27 @@ +-- Simple node table with a user defined attributes +CREATE TABLE [dbo].[Person] ( + ID INTEGER PRIMARY KEY, + [name] VARCHAR(100) +) AS NODE; + +-- A simple edge table with a user defined attribute +CREATE TABLE friends ( + id INTEGER PRIMARY KEY, + start_date DATE +) AS EDGE; + +-- Create a likes edge table, this table does not have any user defined attributes +CREATE TABLE likes AS EDGE; + +-- Create friend edge table with CONSTRAINT, restricts for nodes and its direction +CREATE TABLE dbo.FriendOf( + CONSTRAINT cnt_Person_FriendOf_Person + CONNECTION (dbo.Person TO dbo.Person) +) AS EDGE; + +-- Create friend edge table with CONSTRAINT, +-- with ON DELETE CASCADE option +CREATE TABLE dbo.FriendOf( + CONSTRAINT cnt_Person_FriendOf_Person + CONNECTION (dbo.Person TO dbo.Person) ON DELETE CASCADE +) AS EDGE; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_graph.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_graph.yml new file mode 100644 index 000000000..41b67763b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_graph.yml @@ -0,0 +1,134 @@ +file: +- batch: + - statement: + - create_table_graph_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[Person]' + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: ID + - data_type: + - data_type_identifier: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_definition: + - quoted_identifier: '[name]' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - keyword: NODE + - statement_terminator: ; + - statement: + - create_table_graph_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: friends + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - data_type_identifier: INTEGER + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - comma: ',' + - column_definition: + - naked_identifier: start_date + - data_type: + - keyword: DATE + - end_bracket: ) + - keyword: AS + - keyword: EDGE + - statement_terminator: ; + - statement: + - create_table_graph_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: likes + - keyword: AS + - keyword: EDGE + - statement_terminator: ; + - statement: + - create_table_graph_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: FriendOf + - bracketed: + - start_bracket: ( + - graph_table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: cnt_Person_FriendOf_Person + - connection_constraint_grammar: + - keyword: CONNECTION + - bracketed: + - start_bracket: ( + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Person + - keyword: TO + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Person + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - keyword: EDGE + - statement_terminator: ; + - statement: + - create_table_graph_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: FriendOf + - bracketed: + - start_bracket: ( + - graph_table_constraint: + - keyword: CONSTRAINT + - object_reference: + - naked_identifier: cnt_Person_FriendOf_Person + - connection_constraint_grammar: + - keyword: CONNECTION + - bracketed: + - start_bracket: ( + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Person + - keyword: TO + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Person + - end_bracket: ) + - keyword: ON + - keyword: DELETE + - keyword: CASCADE + - end_bracket: ) + - keyword: AS + - keyword: EDGE + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_on_filegroup.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_on_filegroup.sql new file mode 100644 index 000000000..7326e7796 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_on_filegroup.sql @@ -0,0 +1,5 @@ +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) ON MyFileGroup diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_on_filegroup.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_on_filegroup.yml new file mode 100644 index 000000000..6e9fb25b9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_on_filegroup.yml @@ -0,0 +1,51 @@ +file: +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - on_partition_or_filegroup_statement: + - filegroup_clause: + - keyword: ON + - filegroup_name: + - naked_identifier: MyFileGroup diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_distribution.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_distribution.sql new file mode 100644 index 000000000..f6620560c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_distribution.sql @@ -0,0 +1,65 @@ +--Azure Synapse Analytics specific +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH (CLUSTERED COLUMNSTORE INDEX, DISTRIBUTION = ROUND_ROBIN); +GO +DROP TABLE [dbo].[EC DC] +GO + +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH (HEAP, DISTRIBUTION = REPLICATE); +GO +DROP TABLE [dbo].[EC DC] +GO + +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH (LOCATION = USER_DB, DISTRIBUTION = HASH([Column B])); +GO +DROP TABLE [dbo].[EC DC] +GO + +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH (CLUSTERED COLUMNSTORE INDEX, LOCATION = USER_DB, DISTRIBUTION = HASH([Column B])); +GO +DROP TABLE [dbo].[EC DC] +GO + +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH (CLUSTERED INDEX ([Column B]), DISTRIBUTION = HASH([Column B])); +GO +DROP TABLE [dbo].[EC DC]; +GO + + +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH (CLUSTERED COLUMNSTORE INDEX ORDER ([Column B]), DISTRIBUTION = HASH([Column B])); +GO +DROP TABLE [dbo].[EC DC]; +GO + +CREATE TABLE [dbo].[table] ( [name] [varchar](100) NOT NULL, [month_num] [int] NULL ) +WITH ( DISTRIBUTION = REPLICATE, CLUSTERED INDEX ( [name] ASC, [month_num] ASC ) ) +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_distribution.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_distribution.yml new file mode 100644 index 000000000..15a065fe2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_distribution.yml @@ -0,0 +1,538 @@ +file: +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_distribution_index_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_index_clause: + - keyword: CLUSTERED + - keyword: COLUMNSTORE + - keyword: INDEX + - comma: ',' + - table_distribution_clause: + - keyword: DISTRIBUTION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ROUND_ROBIN + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_distribution_index_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_index_clause: + - keyword: HEAP + - comma: ',' + - table_distribution_clause: + - keyword: DISTRIBUTION + - comparison_operator: + - raw_comparison_operator: = + - keyword: REPLICATE + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_distribution_index_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_location_clause: + - keyword: LOCATION + - comparison_operator: + - raw_comparison_operator: = + - keyword: USER_DB + - comma: ',' + - table_distribution_clause: + - keyword: DISTRIBUTION + - comparison_operator: + - raw_comparison_operator: = + - keyword: HASH + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[Column B]' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_distribution_index_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_index_clause: + - keyword: CLUSTERED + - keyword: COLUMNSTORE + - keyword: INDEX + - comma: ',' + - table_location_clause: + - keyword: LOCATION + - comparison_operator: + - raw_comparison_operator: = + - keyword: USER_DB + - comma: ',' + - table_distribution_clause: + - keyword: DISTRIBUTION + - comparison_operator: + - raw_comparison_operator: = + - keyword: HASH + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[Column B]' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_distribution_index_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_index_clause: + - keyword: CLUSTERED + - keyword: INDEX + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[Column B]' + - end_bracket: ) + - comma: ',' + - table_distribution_clause: + - keyword: DISTRIBUTION + - comparison_operator: + - raw_comparison_operator: = + - keyword: HASH + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[Column B]' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_distribution_index_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_index_clause: + - keyword: CLUSTERED + - keyword: COLUMNSTORE + - keyword: INDEX + - keyword: ORDER + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[Column B]' + - end_bracket: ) + - comma: ',' + - table_distribution_clause: + - keyword: DISTRIBUTION + - comparison_operator: + - raw_comparison_operator: = + - keyword: HASH + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[Column B]' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[table]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[name]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - quoted_identifier: '[month_num]' + - data_type: + - data_type_identifier: '[int]' + - column_constraint_segment: + - keyword: 'NULL' + - end_bracket: ) + - table_distribution_index_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_distribution_clause: + - keyword: DISTRIBUTION + - comparison_operator: + - raw_comparison_operator: = + - keyword: REPLICATE + - comma: ',' + - table_index_clause: + - keyword: CLUSTERED + - keyword: INDEX + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[name]' + - keyword: ASC + - comma: ',' + - column_reference: + - quoted_identifier: '[month_num]' + - keyword: ASC + - end_bracket: ) + - end_bracket: ) + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence.sql new file mode 100644 index 000000000..ab03c7174 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence.sql @@ -0,0 +1,7 @@ +CREATE TABLE DEST.MELDER( + [ID] INT PRIMARY KEY NOT NULL DEFAULT NEXT VALUE FOR [dbo].[SEQ_MELDER] + ,[DOWNLOADED_TOTAL] INT NULL + ,[WARNED_DAILY] INT NULL + ,[DATE_OF_REPORT] DATETIME NULL + ,DATE_LAST_INSERTED DATETIME DEFAULT GETDATE() +); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence.yml new file mode 100644 index 000000000..36de45814 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence.yml @@ -0,0 +1,69 @@ +file: +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: DEST + - dot: . + - naked_identifier: MELDER + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[ID]' + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - sequence_next_value: + - keyword: NEXT + - keyword: VALUE + - keyword: FOR + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[SEQ_MELDER]' + - comma: ',' + - column_definition: + - quoted_identifier: '[DOWNLOADED_TOTAL]' + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - quoted_identifier: '[WARNED_DAILY]' + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - quoted_identifier: '[DATE_OF_REPORT]' + - data_type: + - keyword: DATETIME + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: DATE_LAST_INSERTED + - data_type: + - keyword: DATETIME + - column_constraint_segment: + - keyword: DEFAULT + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence_bracketed.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence_bracketed.sql new file mode 100644 index 000000000..eb1d092a9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence_bracketed.sql @@ -0,0 +1,61 @@ +IF NOT EXISTS(SELECT * FROM sys.sequences WHERE object_id = OBJECT_ID(N'[dbo].[SEQ_SCHEMA_NAME_TABLE_NAME]') AND type = 'SO') +CREATE SEQUENCE SEQ_SCHEMA_NAME_TABLE_NAME + START WITH 1 + INCREMENT BY 1; +GO + +CREATE TABLE SCHEMA_NAME.TABLE_NAME( + [ID] INT PRIMARY KEY NOT NULL DEFAULT (NEXT VALUE FOR [dbo].[SEQ_SCHEMA_NAME_TABLE_NAME]), + [WEEK_UNIX] BIGINT, + GMCODE VARCHAR(100), + AVERAGE_RNA_FLOW_PER_100000 DECIMAL(16,2) NULL, + NUMBER_OF_MEASUREMENTS INT NULL, + NUMBER_OF_LOCATIONS INT NULL, + TOTAL_LOCATIONS INT NULL, + DATE_LAST_INSERTED DATETIME DEFAULT GETDATE() +); + +IF NOT EXISTS(SELECT * FROM sys.sequences WHERE object_id = OBJECT_ID(N'[dbo].[SEQ_STAGE_CBS_POPULATION_BASE]') AND type = 'SO') +CREATE SEQUENCE SEQ_STAGE_CBS_POPULATION_BASE + START WITH 1 + INCREMENT BY 1; +GO + +CREATE TABLE STAGE.CBS_POPULATION_BASE( + [ID] INT PRIMARY KEY NONCLUSTERED NOT NULL DEFAULT (NEXT VALUE FOR [dbo].[SEQ_STAGE_CBS_POPULATION_BASE]), + GEMEENTE_CODE VARCHAR(100) NULL, + GEMEENTE VARCHAR(100) NULL, + LEEFTIJD VARCHAR(100) NULL, + GESLACHT VARCHAR(100) NULL, + DATUM_PEILING VARCHAR(100) NULL, + POPULATIE VARCHAR(100) NULL, + VEILIGHEIDSREGIO_CODE VARCHAR(100) NULL, + VEILIGHEIDSREGIO_NAAM VARCHAR(100) NULL, + PROVINCIE_CODE VARCHAR(100) NULL, + PROVINCIE_NAAM VARCHAR(100) NULL, + GGD_CODE VARCHAR(100) NULL, + GGD_NAAM VARCHAR(100) NULL, + DATE_LAST_INSERTED DATETIME DEFAULT GETDATE() +); +GO +CREATE CLUSTERED INDEX CI_DLI_STAGE_CBS_POPULATION_BASE ON STAGE.CBS_POPULATION_BASE (DATE_LAST_INSERTED) +GO +CREATE NONCLUSTERED INDEX NCI_DLI_STAGE_CIMS_VACCINATED_AGE_GROUP +ON STAGE.CBS_POPULATION_BASE (DATE_LAST_INSERTED, GEMEENTE_CODE, GEMEENTE, LEEFTIJD, GESLACHT, DATUM_PEILING, POPULATIE, +VEILIGHEIDSREGIO_CODE, VEILIGHEIDSREGIO_NAAM, PROVINCIE_CODE, PROVINCIE_NAAM, GGD_CODE, GGD_NAAM); + + +CREATE TABLE DEST.POSITIVE_TESTED_PEOPLE( + [ID] INT PRIMARY KEY NOT NULL DEFAULT (NEXT VALUE FOR [dbo].[SEQ_DEST_POSITIVE_TESTED_PEOPLE]), + DATE_OF_REPORT DATETIME NULL, + DATE_OF_REPORT_UNIX BIGINT NULL, + INFECTED_DAILY_INCREASE DECIMAL(16, 1) NULL, + INFECTED_DAILY_TOTAL INT NULL, + DATE_LAST_INSERTED DATETIME DEFAULT GETDATE(), + [DATE_RANGE_START] datetime, + [DATE_OF_REPORTS_LAG] datetime, + [DATE_RANGE_START_LAG] datetime, + [7D_AVERAGE_INFECTED_DAILY_INCREASE_TOTAL] decimal (16,2), + [7D_AVERAGE_INFECTED_DAILY_INCREASE_LAG] decimal (16,2), + [7D_AVERAGE_INFECTED_DAILY_INCREASE_ABSOLUTE] decimal (16,2) + ); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence_bracketed.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence_bracketed.yml new file mode 100644 index 000000000..8944626fd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_sequence_bracketed.yml @@ -0,0 +1,664 @@ +file: +- batch: + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - keyword: NOT + - keyword: EXISTS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sys + - dot: . + - naked_identifier: sequences + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: object_id + - comparison_operator: + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: OBJECT_ID + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: N'[dbo].[SEQ_SCHEMA_NAME_TABLE_NAME]' + - end_bracket: ) + - binary_operator: AND + - column_reference: + - naked_identifier: type + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''SO''' + - end_bracket: ) + - statement: + - create_sequence_statement: + - keyword: CREATE + - keyword: SEQUENCE + - sequence_reference: + - naked_identifier: SEQ_SCHEMA_NAME_TABLE_NAME + - create_sequence_options_segment: + - keyword: START + - keyword: WITH + - numeric_literal: '1' + - create_sequence_options_segment: + - keyword: INCREMENT + - keyword: BY + - numeric_literal: '1' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: SCHEMA_NAME + - dot: . + - naked_identifier: TABLE_NAME + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[ID]' + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - bracketed: + - start_bracket: ( + - sequence_next_value: + - keyword: NEXT + - keyword: VALUE + - keyword: FOR + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[SEQ_SCHEMA_NAME_TABLE_NAME]' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[WEEK_UNIX]' + - data_type: + - keyword: BIGINT + - comma: ',' + - column_definition: + - naked_identifier: GMCODE + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: AVERAGE_RNA_FLOW_PER_100000 + - data_type: + - keyword: DECIMAL + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '16' + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: NUMBER_OF_MEASUREMENTS + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: NUMBER_OF_LOCATIONS + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: TOTAL_LOCATIONS + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: DATE_LAST_INSERTED + - data_type: + - keyword: DATETIME + - column_constraint_segment: + - keyword: DEFAULT + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - keyword: NOT + - keyword: EXISTS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sys + - dot: . + - naked_identifier: sequences + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: object_id + - comparison_operator: + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: OBJECT_ID + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: N'[dbo].[SEQ_STAGE_CBS_POPULATION_BASE]' + - end_bracket: ) + - binary_operator: AND + - column_reference: + - naked_identifier: type + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''SO''' + - end_bracket: ) + - statement: + - create_sequence_statement: + - keyword: CREATE + - keyword: SEQUENCE + - sequence_reference: + - naked_identifier: SEQ_STAGE_CBS_POPULATION_BASE + - create_sequence_options_segment: + - keyword: START + - keyword: WITH + - numeric_literal: '1' + - create_sequence_options_segment: + - keyword: INCREMENT + - keyword: BY + - numeric_literal: '1' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: STAGE + - dot: . + - naked_identifier: CBS_POPULATION_BASE + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[ID]' + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - keyword: NONCLUSTERED + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - bracketed: + - start_bracket: ( + - sequence_next_value: + - keyword: NEXT + - keyword: VALUE + - keyword: FOR + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[SEQ_STAGE_CBS_POPULATION_BASE]' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: GEMEENTE_CODE + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: GEMEENTE + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: LEEFTIJD + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: GESLACHT + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: DATUM_PEILING + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: POPULATIE + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: VEILIGHEIDSREGIO_CODE + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: VEILIGHEIDSREGIO_NAAM + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: PROVINCIE_CODE + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: PROVINCIE_NAAM + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: GGD_CODE + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: GGD_NAAM + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: DATE_LAST_INSERTED + - data_type: + - keyword: DATETIME + - column_constraint_segment: + - keyword: DEFAULT + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_index_statement: + - keyword: CREATE + - keyword: CLUSTERED + - keyword: INDEX + - index_reference: + - naked_identifier: CI_DLI_STAGE_CBS_POPULATION_BASE + - keyword: ON + - table_reference: + - naked_identifier: STAGE + - dot: . + - naked_identifier: CBS_POPULATION_BASE + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: DATE_LAST_INSERTED + - end_bracket: ) + - go_statement: + - keyword: GO +- batch: + - statement: + - create_index_statement: + - keyword: CREATE + - keyword: NONCLUSTERED + - keyword: INDEX + - index_reference: + - naked_identifier: NCI_DLI_STAGE_CIMS_VACCINATED_AGE_GROUP + - keyword: ON + - table_reference: + - naked_identifier: STAGE + - dot: . + - naked_identifier: CBS_POPULATION_BASE + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: DATE_LAST_INSERTED + - comma: ',' + - index_column_definition: + - naked_identifier: GEMEENTE_CODE + - comma: ',' + - index_column_definition: + - naked_identifier: GEMEENTE + - comma: ',' + - index_column_definition: + - naked_identifier: LEEFTIJD + - comma: ',' + - index_column_definition: + - naked_identifier: GESLACHT + - comma: ',' + - index_column_definition: + - naked_identifier: DATUM_PEILING + - comma: ',' + - index_column_definition: + - naked_identifier: POPULATIE + - comma: ',' + - index_column_definition: + - naked_identifier: VEILIGHEIDSREGIO_CODE + - comma: ',' + - index_column_definition: + - naked_identifier: VEILIGHEIDSREGIO_NAAM + - comma: ',' + - index_column_definition: + - naked_identifier: PROVINCIE_CODE + - comma: ',' + - index_column_definition: + - naked_identifier: PROVINCIE_NAAM + - comma: ',' + - index_column_definition: + - naked_identifier: GGD_CODE + - comma: ',' + - index_column_definition: + - naked_identifier: GGD_NAAM + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: DEST + - dot: . + - naked_identifier: POSITIVE_TESTED_PEOPLE + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[ID]' + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: DEFAULT + - bracketed: + - start_bracket: ( + - sequence_next_value: + - keyword: NEXT + - keyword: VALUE + - keyword: FOR + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[SEQ_DEST_POSITIVE_TESTED_PEOPLE]' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: DATE_OF_REPORT + - data_type: + - keyword: DATETIME + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: DATE_OF_REPORT_UNIX + - data_type: + - keyword: BIGINT + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: INFECTED_DAILY_INCREASE + - data_type: + - keyword: DECIMAL + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '16' + - comma: ',' + - expression: + - integer_literal: '1' + - end_bracket: ) + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: INFECTED_DAILY_TOTAL + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: DATE_LAST_INSERTED + - data_type: + - keyword: DATETIME + - column_constraint_segment: + - keyword: DEFAULT + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[DATE_RANGE_START]' + - data_type: + - keyword: datetime + - comma: ',' + - column_definition: + - quoted_identifier: '[DATE_OF_REPORTS_LAG]' + - data_type: + - keyword: datetime + - comma: ',' + - column_definition: + - quoted_identifier: '[DATE_RANGE_START_LAG]' + - data_type: + - keyword: datetime + - comma: ',' + - column_definition: + - quoted_identifier: '[7D_AVERAGE_INFECTED_DAILY_INCREASE_TOTAL]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '16' + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[7D_AVERAGE_INFECTED_DAILY_INCREASE_LAG]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '16' + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[7D_AVERAGE_INFECTED_DAILY_INCREASE_ABSOLUTE]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '16' + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_table_option_segment.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_table_option_segment.sql new file mode 100644 index 000000000..8d53dd41f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_table_option_segment.sql @@ -0,0 +1,53 @@ +CREATE TABLE [dbo].[TEST] ( + [id] INT NOT NULL +) ON [PRIMARY] WITH ( + SYSTEM_VERSIONING = ON ( + HISTORY_TABLE = [dbo].[TEST_HISTORY], + HISTORY_RETENTION_PERIOD = INFINITE + ) +); + +CREATE TABLE [dbo].[TEST] ( + [id] INT NOT NULL +) ON [PRIMARY] WITH ( + SYSTEM_VERSIONING = ON ( + HISTORY_TABLE = [dbo].[TEST_HISTORY], + HISTORY_RETENTION_PERIOD = 1 DAYS, + DATA_CONSISTENCY_CHECK = ON + ) +); + +CREATE TABLE [dbo].[TEST] ( + [id] INT NOT NULL +) ON [PRIMARY] WITH ( + SYSTEM_VERSIONING = ON ( + HISTORY_TABLE = [dbo].[TEST_HISTORY], + HISTORY_RETENTION_PERIOD = 10 WEEKS + ) +); + +CREATE TABLE [dbo].[TEST] ( + [id] INT NOT NULL +) ON [PRIMARY] WITH ( + SYSTEM_VERSIONING = ON ( + HISTORY_TABLE = [dbo].[TEST_HISTORY], + HISTORY_RETENTION_PERIOD = 4 MONTHS + ) +); + +CREATE TABLE [dbo].[TEST] ( + [id] INT NOT NULL +) ON [PRIMARY] WITH ( + SYSTEM_VERSIONING = ON ( + HISTORY_TABLE = [dbo].[TEST_HISTORY], + HISTORY_RETENTION_PERIOD = 1 YEARS + ) +); + +CREATE TABLE [dbo].[TEST] ( + [id] INT NOT NULL +) ON [PRIMARY] WITH ( + SYSTEM_VERSIONING = ON ( + HISTORY_TABLE = [dbo].[TEST_HISTORY] + ) +); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_table_option_segment.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_table_option_segment.yml new file mode 100644 index 000000000..157f89005 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_table_option_segment.yml @@ -0,0 +1,294 @@ +file: +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[id]' + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - on_partition_or_filegroup_statement: + - filegroup_clause: + - keyword: ON + - filegroup_name: + - quoted_identifier: '[PRIMARY]' + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: HISTORY_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_HISTORY]' + - comma: ',' + - keyword: HISTORY_RETENTION_PERIOD + - comparison_operator: + - raw_comparison_operator: = + - keyword: INFINITE + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[id]' + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - on_partition_or_filegroup_statement: + - filegroup_clause: + - keyword: ON + - filegroup_name: + - quoted_identifier: '[PRIMARY]' + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: HISTORY_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_HISTORY]' + - comma: ',' + - keyword: HISTORY_RETENTION_PERIOD + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - keyword: DAYS + - comma: ',' + - keyword: DATA_CONSISTENCY_CHECK + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[id]' + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - on_partition_or_filegroup_statement: + - filegroup_clause: + - keyword: ON + - filegroup_name: + - quoted_identifier: '[PRIMARY]' + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: HISTORY_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_HISTORY]' + - comma: ',' + - keyword: HISTORY_RETENTION_PERIOD + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '10' + - keyword: WEEKS + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[id]' + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - on_partition_or_filegroup_statement: + - filegroup_clause: + - keyword: ON + - filegroup_name: + - quoted_identifier: '[PRIMARY]' + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: HISTORY_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_HISTORY]' + - comma: ',' + - keyword: HISTORY_RETENTION_PERIOD + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '4' + - keyword: MONTHS + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[id]' + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - on_partition_or_filegroup_statement: + - filegroup_clause: + - keyword: ON + - filegroup_name: + - quoted_identifier: '[PRIMARY]' + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: HISTORY_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_HISTORY]' + - comma: ',' + - keyword: HISTORY_RETENTION_PERIOD + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '1' + - keyword: YEARS + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[id]' + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - on_partition_or_filegroup_statement: + - filegroup_clause: + - keyword: ON + - filegroup_name: + - quoted_identifier: '[PRIMARY]' + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: HISTORY_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[TEST_HISTORY]' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_trailing_comma.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_trailing_comma.sql new file mode 100644 index 000000000..d0b904c8e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_trailing_comma.sql @@ -0,0 +1,3 @@ +CREATE TABLE [dbo].[test] ( + [Column B] [varchar](100), +) diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_trailing_comma.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_trailing_comma.yml new file mode 100644 index 000000000..24bc15c2f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_table_with_trailing_comma.yml @@ -0,0 +1,22 @@ +file: +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[test]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_type.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_type.sql new file mode 100644 index 000000000..883308006 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_type.sql @@ -0,0 +1,7 @@ +CREATE TYPE person AS TABLE ( + name nvarchar(10), + height int, + favorite_color int +); + +CREATE TYPE weird_int FROM int; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_type.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_type.yml new file mode 100644 index 000000000..eea2cba63 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_type.yml @@ -0,0 +1,44 @@ +file: +- batch: + - statement: + - create_type_statement: + - keyword: CREATE + - keyword: TYPE + - object_reference: + - naked_identifier: person + - keyword: AS + - keyword: TABLE + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: name + - data_type: + - keyword: nvarchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: height + - data_type: + - keyword: int + - comma: ',' + - column_definition: + - naked_identifier: favorite_color + - data_type: + - keyword: int + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_type_statement: + - keyword: CREATE + - keyword: TYPE + - object_reference: + - naked_identifier: weird_int + - keyword: FROM + - object_reference: + - naked_identifier: int + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_user.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_user.sql new file mode 100644 index 000000000..7296bf66d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_user.sql @@ -0,0 +1,32 @@ +CREATE USER user_name FOR LOGIN login_name; + +CREATE USER user_name FROM LOGIN login_name; + +CREATE USER [TestUser]; + +CREATE USER Barry WITH PASSWORD = 'sdjklalie8rew8337!$d'; + +CREATE USER [TestUser] FROM EXTERNAL PROVIDER; + +CREATE USER RIGHTSHOLDER WITHOUT LOGIN; + +CREATE USER RIGHTSHOLDER WITHOUT LOGIN +WITH DEFAULT_SCHEMA = Other; + +CREATE USER [Barry] +WITH ALLOW_ENCRYPTED_VALUE_MODIFICATIONS = ON; + +CREATE USER Wanida FOR LOGIN WanidaBenshoof +WITH DEFAULT_SCHEMA = Marketing; + +CREATE USER Wanida FOR LOGIN WanidaSmith +WITH DEFAULT_SCHEMA = Tech, +ALLOW_ENCRYPTED_VALUE_MODIFICATIONS = ON; + +CREATE USER JinghaoLiu FOR CERTIFICATE CarnationProduction50; + +CREATE USER JinghaoLiu FOR ASYMMETRIC KEY CarnationProduction; + +CREATE USER Barry +WITH PASSWORD = 'sdjklalie8rew8337!$d', +SID = 0x241C11948AEEB749B0D22646DB1A19F2; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_user.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_user.yml new file mode 100644 index 000000000..1898ed881 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_user.yml @@ -0,0 +1,168 @@ +file: +- batch: + - statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - naked_identifier: user_name + - keyword: FOR + - keyword: LOGIN + - object_reference: + - naked_identifier: login_name + - statement_terminator: ; + - statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - naked_identifier: user_name + - keyword: FROM + - keyword: LOGIN + - object_reference: + - naked_identifier: login_name + - statement_terminator: ; + - statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '[TestUser]' + - statement_terminator: ; + - statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - naked_identifier: Barry + - keyword: WITH + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''sdjklalie8rew8337!$d''' + - statement_terminator: ; + - statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '[TestUser]' + - keyword: FROM + - keyword: EXTERNAL + - keyword: PROVIDER + - statement_terminator: ; + - statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - naked_identifier: RIGHTSHOLDER + - keyword: WITHOUT + - keyword: LOGIN + - statement_terminator: ; + - statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - naked_identifier: RIGHTSHOLDER + - keyword: WITHOUT + - keyword: LOGIN + - keyword: WITH + - keyword: DEFAULT_SCHEMA + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: Other + - statement_terminator: ; + - statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - quoted_identifier: '[Barry]' + - keyword: WITH + - keyword: ALLOW_ENCRYPTED_VALUE_MODIFICATIONS + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - statement_terminator: ; + - statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - naked_identifier: Wanida + - keyword: FOR + - keyword: LOGIN + - object_reference: + - naked_identifier: WanidaBenshoof + - keyword: WITH + - keyword: DEFAULT_SCHEMA + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: Marketing + - statement_terminator: ; + - statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - naked_identifier: Wanida + - keyword: FOR + - keyword: LOGIN + - object_reference: + - naked_identifier: WanidaSmith + - keyword: WITH + - keyword: DEFAULT_SCHEMA + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: Tech + - comma: ',' + - keyword: ALLOW_ENCRYPTED_VALUE_MODIFICATIONS + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - statement_terminator: ; + - statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - naked_identifier: JinghaoLiu + - keyword: FOR + - keyword: CERTIFICATE + - object_reference: + - naked_identifier: CarnationProduction50 + - statement_terminator: ; + - statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - naked_identifier: JinghaoLiu + - keyword: FOR + - keyword: ASYMMETRIC + - keyword: KEY + - object_reference: + - naked_identifier: CarnationProduction + - statement_terminator: ; + - statement: + - create_user_statement: + - keyword: CREATE + - keyword: USER + - role_reference: + - naked_identifier: Barry + - keyword: WITH + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''sdjklalie8rew8337!$d''' + - comma: ',' + - keyword: SID + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '0x241C11948AEEB749B0D22646DB1A19F2' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view.sql new file mode 100644 index 000000000..d49ce17ce --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view.sql @@ -0,0 +1,57 @@ +CREATE OR ALTER VIEW Sales.SalesPersonPerform +AS +SELECT TOP (100) SalesPersonID, SUM(TotalDue) AS TotalSales +FROM Sales.SalesOrderHeader +WHERE OrderDate > CONVERT(DATETIME, '20001231', 101) +GROUP BY SalesPersonID; + +CREATE OR ALTER VIEW Sales.SalesPersonPerform +AS +SELECT TOP (100) SalesPersonID, SUM(TotalDue) AS TotalSales +FROM Sales.SalesOrderHeader +WHERE OrderDate > CONVERT(DATETIME, '20001231', 101) +GROUP BY SalesPersonID; + + +CREATE VIEW Purchasing.PurchaseOrderReject +WITH SCHEMABINDING +AS +SELECT PurchaseOrderID, ReceivedQty, RejectedQty, + RejectedQty / ReceivedQty AS RejectRatio, DueDate +FROM Purchasing.PurchaseOrderDetail +WHERE RejectedQty / ReceivedQty > 0 +AND DueDate > CONVERT(DATETIME,'20010630',101) ; + + +CREATE VIEW dbo.SeattleOnly +AS +SELECT p.LastName, p.FirstName, e.JobTitle, a.City, sp.StateProvinceCode +FROM HumanResources.Employee e +INNER JOIN Person.Person p +ON p.BusinessEntityID = e.BusinessEntityID + INNER JOIN Person.BusinessEntityAddress bea + ON bea.BusinessEntityID = e.BusinessEntityID + INNER JOIN Person.Address a + ON a.AddressID = bea.AddressID + INNER JOIN Person.StateProvince sp + ON sp.StateProvinceID = a.StateProvinceID +WHERE a.City = 'Seattle' +WITH CHECK OPTION ; + + +CREATE VIEW dbo.all_supplier_view +WITH SCHEMABINDING +AS +SELECT supplyID, supplier + FROM dbo.SUPPLY1 +UNION ALL +SELECT supplyID, supplier + FROM dbo.SUPPLY2 +UNION ALL +SELECT supplyID, supplier + FROM dbo.SUPPLY3 +UNION ALL +SELECT supplyID, supplier + FROM dbo.SUPPLY4; + +create view vw_view with schemabinding, view_metadata as select A.ID from A diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view.yml new file mode 100644 index 000000000..ebf121503 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view.yml @@ -0,0 +1,521 @@ +file: +- batch: + - statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: VIEW + - object_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesPersonPerform + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - select_clause_element: + - column_reference: + - naked_identifier: SalesPersonID + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: TotalDue + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: TotalSales + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderHeader + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: OrderDate + - comparison_operator: + - raw_comparison_operator: '>' + - function: + - function_name: + - keyword: CONVERT + - function_contents: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: DATETIME + - comma: ',' + - expression: + - quoted_literal: '''20001231''' + - comma: ',' + - numeric_literal: '101' + - end_bracket: ) + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: SalesPersonID + - statement_terminator: ; + - statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: VIEW + - object_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesPersonPerform + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - select_clause_element: + - column_reference: + - naked_identifier: SalesPersonID + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: TotalDue + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: TotalSales + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderHeader + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: OrderDate + - comparison_operator: + - raw_comparison_operator: '>' + - function: + - function_name: + - keyword: CONVERT + - function_contents: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: DATETIME + - comma: ',' + - expression: + - quoted_literal: '''20001231''' + - comma: ',' + - numeric_literal: '101' + - end_bracket: ) + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: SalesPersonID + - statement_terminator: ; + - statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - object_reference: + - naked_identifier: Purchasing + - dot: . + - naked_identifier: PurchaseOrderReject + - keyword: WITH + - keyword: SCHEMABINDING + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: PurchaseOrderID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ReceivedQty + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: RejectedQty + - comma: ',' + - select_clause_element: + - expression: + - column_reference: + - naked_identifier: RejectedQty + - binary_operator: / + - column_reference: + - naked_identifier: ReceivedQty + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: RejectRatio + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: DueDate + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Purchasing + - dot: . + - naked_identifier: PurchaseOrderDetail + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: RejectedQty + - binary_operator: / + - column_reference: + - naked_identifier: ReceivedQty + - comparison_operator: + - raw_comparison_operator: '>' + - integer_literal: '0' + - binary_operator: AND + - column_reference: + - naked_identifier: DueDate + - comparison_operator: + - raw_comparison_operator: '>' + - function: + - function_name: + - keyword: CONVERT + - function_contents: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: DATETIME + - comma: ',' + - expression: + - quoted_literal: '''20010630''' + - comma: ',' + - numeric_literal: '101' + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: SeattleOnly + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: LastName + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: FirstName + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - naked_identifier: JobTitle + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: City + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: sp + - dot: . + - naked_identifier: StateProvinceCode + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: Employee + - alias_expression: + - naked_identifier: e + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: Person + - alias_expression: + - naked_identifier: p + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: BusinessEntityID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: e + - dot: . + - naked_identifier: BusinessEntityID + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: BusinessEntityAddress + - alias_expression: + - naked_identifier: bea + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: bea + - dot: . + - naked_identifier: BusinessEntityID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: e + - dot: . + - naked_identifier: BusinessEntityID + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: Address + - alias_expression: + - naked_identifier: a + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: AddressID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: bea + - dot: . + - naked_identifier: AddressID + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: StateProvince + - alias_expression: + - naked_identifier: sp + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: sp + - dot: . + - naked_identifier: StateProvinceID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: StateProvinceID + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: City + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Seattle''' + - keyword: WITH + - keyword: CHECK + - keyword: OPTION + - statement_terminator: ; + - statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: all_supplier_view + - keyword: WITH + - keyword: SCHEMABINDING + - keyword: AS + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: supplyID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: supplier + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: SUPPLY1 + - set_operator: + - keyword: UNION + - keyword: ALL + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: supplyID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: supplier + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: SUPPLY2 + - set_operator: + - keyword: UNION + - keyword: ALL + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: supplyID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: supplier + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: SUPPLY3 + - set_operator: + - keyword: UNION + - keyword: ALL + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: supplyID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: supplier + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: SUPPLY4 + - statement_terminator: ; + - statement: + - create_view_statement: + - keyword: create + - keyword: view + - object_reference: + - naked_identifier: vw_view + - keyword: with + - keyword: schemabinding + - comma: ',' + - keyword: view_metadata + - keyword: as + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: A + - dot: . + - naked_identifier: ID + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: A diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_columns.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_columns.sql new file mode 100644 index 000000000..3c7abc7d5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_columns.sql @@ -0,0 +1,9 @@ +CREATE VIEW my_view ( + col1, + col2 +) +AS +SELECT + col1, + col2 +FROM source_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_columns.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_columns.yml new file mode 100644 index 000000000..320264f39 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_columns.yml @@ -0,0 +1,35 @@ +file: +- batch: + - statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - object_reference: + - naked_identifier: my_view + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: col1 + - comma: ',' + - index_column_definition: + - naked_identifier: col2 + - end_bracket: ) + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: source_table + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_cte.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_cte.sql new file mode 100644 index 000000000..c4057438e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_cte.sql @@ -0,0 +1,17 @@ +CREATE VIEW vwCTE AS +--Creates an infinite loop +WITH cte (EmployeeID, ManagerID, Title) AS +( + SELECT EmployeeID, ManagerID, Title + FROM HumanResources.Employee + WHERE ManagerID IS NOT NULL + UNION ALL + SELECT cte.EmployeeID, cte.ManagerID, cte.Title + FROM cte + JOIN HumanResources.Employee AS e + ON cte.ManagerID = e.EmployeeID +) +-- Notice the MAXRECURSION option is removed +SELECT EmployeeID, ManagerID, Title +FROM cte +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_cte.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_cte.yml new file mode 100644 index 000000000..4f958c627 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_cte.yml @@ -0,0 +1,137 @@ +file: +- batch: + - statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - object_reference: + - naked_identifier: vwCTE + - keyword: AS + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: cte + - cte_column_list: + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: EmployeeID + - comma: ',' + - naked_identifier: ManagerID + - comma: ',' + - naked_identifier: Title + - end_bracket: ) + - keyword: AS + - bracketed: + - start_bracket: ( + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: EmployeeID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ManagerID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Title + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: Employee + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ManagerID + - keyword: IS + - keyword: NOT + - null_literal: 'NULL' + - set_operator: + - keyword: UNION + - keyword: ALL + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: cte + - dot: . + - naked_identifier: EmployeeID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: cte + - dot: . + - naked_identifier: ManagerID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: cte + - dot: . + - naked_identifier: Title + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: cte + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: Employee + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: e + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: cte + - dot: . + - naked_identifier: ManagerID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: e + - dot: . + - naked_identifier: EmployeeID + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: EmployeeID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ManagerID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Title + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: cte + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_pivot.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_pivot.sql new file mode 100644 index 000000000..ee40b595c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_pivot.sql @@ -0,0 +1,15 @@ +CREATE OR ALTER VIEW DEST.V_HOSPITAL_ADMISSIONS_OVERTIME_BYAGEGROUP +AS + -- Pivot table with one row and five columns +SELECT 'AverageCost' AS Cost_Sorted_By_Production_Days, + [0], [1], [2], [3], [4] +FROM +( + SELECT DaysToManufacture, StandardCost + FROM Production.Product +) AS SourceTable +PIVOT +( + AVG(StandardCost) + FOR DaysToManufacture IN ([0], [1], [2], [3], [4]) +) AS PivotTable; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_pivot.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_pivot.yml new file mode 100644 index 000000000..dc4f50a97 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_pivot.yml @@ -0,0 +1,113 @@ +file: +- batch: + - statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: VIEW + - object_reference: + - naked_identifier: DEST + - dot: . + - naked_identifier: V_HOSPITAL_ADMISSIONS_OVERTIME_BYAGEGROUP + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''AverageCost''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Cost_Sorted_By_Production_Days + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[0]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[1]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[2]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[3]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[4]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: DaysToManufacture + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: StandardCost + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: Product + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: SourceTable + - from_pivot_expression: + - keyword: PIVOT + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: AVG + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: StandardCost + - end_bracket: ) + - keyword: FOR + - column_reference: + - naked_identifier: DaysToManufacture + - keyword: IN + - bracketed: + - start_bracket: ( + - pivot_column_reference: + - quoted_identifier: '[0]' + - comma: ',' + - pivot_column_reference: + - quoted_identifier: '[1]' + - comma: ',' + - pivot_column_reference: + - quoted_identifier: '[2]' + - comma: ',' + - pivot_column_reference: + - quoted_identifier: '[3]' + - comma: ',' + - pivot_column_reference: + - quoted_identifier: '[4]' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - table_reference: + - naked_identifier: PivotTable + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_set_statements.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_set_statements.sql new file mode 100644 index 000000000..6bb106552 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_set_statements.sql @@ -0,0 +1,36 @@ +SET ANSI_NULLS ON +GO + +SET QUOTED_IDENTIFIER ON +GO + +CREATE VIEW [DEST].[V_DIFFERENCE_NURSING_HOME__INFECTED_LOCATIONS_TOTAL_PER_REGION] AS + +SELECT TOP 1 DATE_OF_REPORT +FROM BASE_CTE; + +GO + +CREATE OR ALTER VIEW [DEST].[V_DIFFERENCE_NURSING_HOME__INFECTED_LOCATIONS_TOTAL_PER_REGION] AS + +SELECT TOP 1 DATE_OF_REPORT +FROM BASE_CTE +ORDER BY DATE_OF_REPORT; + +GO + + +ALTER VIEW [DEST].[V_DIFFERENCE_NURSING_HOME__INFECTED_LOCATIONS_TOTAL_PER_REGION] AS + +SELECT DATE_OF_REPORT + ,NEW_DATE_OF_REPORT_UNIX AS NEW_DATE_UNIX + ,OLD_DATE_OF_REPORT_UNIX AS OLD_DATE_UNIX + ,T1.VRCODE + ,CASE WHEN OLD_VALUE IS NULL THEN 0 ELSE OLD_VALUE END AS OLD_VALUE + ,CASE WHEN [DIFFERENCE] IS NULL THEN 0 ELSE [DIFFERENCE] END AS [DIFFERENCE] +FROM BASE_CTE T1 +LEFT JOIN LAST_DATE_OF_REPORT T2 + ON T1.[VRCODE] = T2.[VRCODE] +WHERE DATE_OF_REPORT = LAST_DATE_OF_REPORT; + +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_set_statements.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_set_statements.yml new file mode 100644 index 000000000..3e9202efb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_set_statements.yml @@ -0,0 +1,215 @@ +file: +- batch: + - statement: + - set_segment: + - keyword: SET + - keyword: ANSI_NULLS + - keyword: ON + - go_statement: + - keyword: GO +- batch: + - statement: + - set_segment: + - keyword: SET + - keyword: QUOTED_IDENTIFIER + - keyword: ON + - go_statement: + - keyword: GO +- batch: + - statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - object_reference: + - quoted_identifier: '[DEST]' + - dot: . + - quoted_identifier: '[V_DIFFERENCE_NURSING_HOME__INFECTED_LOCATIONS_TOTAL_PER_REGION]' + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - expression: + - integer_literal: '1' + - select_clause_element: + - column_reference: + - naked_identifier: DATE_OF_REPORT + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: BASE_CTE + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_view_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: VIEW + - object_reference: + - quoted_identifier: '[DEST]' + - dot: . + - quoted_identifier: '[V_DIFFERENCE_NURSING_HOME__INFECTED_LOCATIONS_TOTAL_PER_REGION]' + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - expression: + - integer_literal: '1' + - select_clause_element: + - column_reference: + - naked_identifier: DATE_OF_REPORT + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: BASE_CTE + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: DATE_OF_REPORT + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_view_statement: + - keyword: ALTER + - keyword: VIEW + - object_reference: + - quoted_identifier: '[DEST]' + - dot: . + - quoted_identifier: '[V_DIFFERENCE_NURSING_HOME__INFECTED_LOCATIONS_TOTAL_PER_REGION]' + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: DATE_OF_REPORT + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: NEW_DATE_OF_REPORT_UNIX + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: NEW_DATE_UNIX + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: OLD_DATE_OF_REPORT_UNIX + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: OLD_DATE_UNIX + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: T1 + - dot: . + - naked_identifier: VRCODE + - comma: ',' + - select_clause_element: + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: OLD_VALUE + - keyword: IS + - null_literal: 'NULL' + - keyword: THEN + - expression: + - integer_literal: '0' + - else_clause: + - keyword: ELSE + - expression: + - column_reference: + - naked_identifier: OLD_VALUE + - keyword: END + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: OLD_VALUE + - comma: ',' + - select_clause_element: + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - quoted_identifier: '[DIFFERENCE]' + - keyword: IS + - null_literal: 'NULL' + - keyword: THEN + - expression: + - integer_literal: '0' + - else_clause: + - keyword: ELSE + - expression: + - column_reference: + - quoted_identifier: '[DIFFERENCE]' + - keyword: END + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[DIFFERENCE]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: BASE_CTE + - alias_expression: + - naked_identifier: T1 + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: LAST_DATE_OF_REPORT + - alias_expression: + - naked_identifier: T2 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: T1 + - dot: . + - quoted_identifier: '[VRCODE]' + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: T2 + - dot: . + - quoted_identifier: '[VRCODE]' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: DATE_OF_REPORT + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: LAST_DATE_OF_REPORT + - statement_terminator: ; + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_unpivot.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_unpivot.sql new file mode 100644 index 000000000..81f7f7559 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_unpivot.sql @@ -0,0 +1,11 @@ +CREATE VIEW UnpivotView +AS + -- Unpivot the table. + SELECT VendorID, Employee, Orders + FROM + (SELECT VendorID, Emp1, Emp2, Emp3, Emp4, Emp5 + FROM pvt) p + UNPIVOT + (Orders FOR Employee IN + (Emp1, Emp2, Emp3, Emp4, Emp5) + ) AS unpvt; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_unpivot.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_unpivot.yml new file mode 100644 index 000000000..955ba9140 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/create_view_with_unpivot.yml @@ -0,0 +1,98 @@ +file: +- batch: + - statement: + - create_view_statement: + - keyword: CREATE + - keyword: VIEW + - object_reference: + - naked_identifier: UnpivotView + - keyword: AS + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: VendorID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Employee + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Orders + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: VendorID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Emp1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Emp2 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Emp3 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Emp4 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Emp5 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: pvt + - end_bracket: ) + - alias_expression: + - naked_identifier: p + - from_pivot_expression: + - keyword: UNPIVOT + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: Orders + - keyword: FOR + - column_reference: + - naked_identifier: Employee + - keyword: IN + - bracketed: + - start_bracket: ( + - pivot_column_reference: + - naked_identifier: Emp1 + - comma: ',' + - pivot_column_reference: + - naked_identifier: Emp2 + - comma: ',' + - pivot_column_reference: + - naked_identifier: Emp3 + - comma: ',' + - pivot_column_reference: + - naked_identifier: Emp4 + - comma: ',' + - pivot_column_reference: + - naked_identifier: Emp5 + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - table_reference: + - naked_identifier: unpvt + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cross_apply_with_function.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cross_apply_with_function.sql deleted file mode 100644 index 01bf9b157..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cross_apply_with_function.sql +++ /dev/null @@ -1,10 +0,0 @@ --- Test case for CROSS APPLY with table-valued function -SELECT - p.ProductID, - p.ProductName, - s.StockLevel -FROM - Products p - CROSS APPLY dbo.GetCurrentStock(p.ProductID) s -WHERE - s.StockLevel < 10 \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cross_apply_with_function.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cross_apply_with_function.yml deleted file mode 100644 index 8c92adf99..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cross_apply_with_function.yml +++ /dev/null @@ -1,63 +0,0 @@ -file: -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: p - - dot: . - - naked_identifier: ProductID - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: p - - dot: . - - naked_identifier: ProductName - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: s - - dot: . - - naked_identifier: StockLevel - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: Products - - alias_expression: - - naked_identifier: p - - join_clause: - - keyword: CROSS - - keyword: APPLY - - from_expression_element: - - table_expression: - - function: - - function_name: - - naked_identifier: dbo - - dot: . - - function_name_identifier: GetCurrentStock - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: p - - dot: . - - naked_identifier: ProductID - - end_bracket: ) - - alias_expression: - - naked_identifier: s - - where_clause: - - keyword: WHERE - - expression: - - column_reference: - - naked_identifier: s - - dot: . - - naked_identifier: StockLevel - - comparison_operator: - - raw_comparison_operator: < - - numeric_literal: '10' diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_s.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_s.sql new file mode 100644 index 000000000..cc999e465 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_s.sql @@ -0,0 +1,10 @@ +WITH Sales_CTE (SalesPersonID, NumberOfOrders) +AS +( + SELECT SalesPersonID, COUNT(*) + FROM Sales.SalesOrderHeader + WHERE SalesPersonID IS NOT NULL + GROUP BY SalesPersonID +) +SELECT AVG(NumberOfOrders) AS "Average Sales Per Person" +FROM Sales_CTE; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_s.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_s.yml new file mode 100644 index 000000000..d7afb2d39 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_s.yml @@ -0,0 +1,83 @@ +file: +- batch: + - statement: + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: Sales_CTE + - cte_column_list: + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: SalesPersonID + - comma: ',' + - naked_identifier: NumberOfOrders + - end_bracket: ) + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: SalesPersonID + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: COUNT + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderHeader + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: SalesPersonID + - keyword: IS + - keyword: NOT + - null_literal: 'NULL' + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: SalesPersonID + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: AVG + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: NumberOfOrders + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '"Average Sales Per Person"' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales_CTE + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_with_join.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_with_join.sql deleted file mode 100644 index 61c60e827..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_with_join.sql +++ /dev/null @@ -1,6 +0,0 @@ -WITH bu2ic AS ( - SELECT ItemCategoryID FROM table1 -) -SELECT * -FROM NxItem -LEFT OUTER JOIN bu2ic AS BU2IC ON BU2IC.ItemCategoryID = NxItem.i_category_id \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_with_join.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_with_join.yml deleted file mode 100644 index 070fff3e9..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cte_with_join.yml +++ /dev/null @@ -1,64 +0,0 @@ -file: -- statement: - - with_compound_statement: - - keyword: WITH - - common_table_expression: - - naked_identifier: bu2ic - - keyword: AS - - bracketed: - - start_bracket: ( - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: ItemCategoryID - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: table1 - - end_bracket: ) - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - wildcard_expression: - - wildcard_identifier: - - star: '*' - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: NxItem - - join_clause: - - keyword: LEFT - - keyword: OUTER - - keyword: JOIN - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: bu2ic - - alias_expression: - - keyword: AS - - naked_identifier: BU2IC - - join_on_condition: - - keyword: ON - - expression: - - column_reference: - - naked_identifier: BU2IC - - dot: . - - naked_identifier: ItemCategoryID - - comparison_operator: - - raw_comparison_operator: = - - column_reference: - - naked_identifier: NxItem - - dot: . - - naked_identifier: i_category_id diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cursor.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cursor.sql new file mode 100644 index 000000000..9ad565722 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cursor.sql @@ -0,0 +1,18 @@ +DECLARE pointy CURSOR LOCAL FORWARD_ONLY READ_ONLY FOR +SELECT + column_a, + column_b +FROM some_table +WHERE column_a IS NOT NULL +ORDER BY column_b + +OPEN pointy; + +FETCH FIRST FROM @pointy INTO @result; +FETCH NEXT FROM GLOBAL pointy; + +CLOSE GLOBAL pointy; + +DEALLOCATE pointy; + +DECLARE @cursorName CURSOR; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cursor.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cursor.yml new file mode 100644 index 000000000..1fd345abc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/cursor.yml @@ -0,0 +1,82 @@ +file: +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - naked_identifier: pointy + - cursor_definition: + - keyword: CURSOR + - keyword: LOCAL + - keyword: FORWARD_ONLY + - keyword: READ_ONLY + - keyword: FOR + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: column_a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: column_b + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: some_table + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: column_a + - keyword: IS + - keyword: NOT + - null_literal: 'NULL' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: column_b + - statement: + - open_cursor_statement: + - keyword: OPEN + - naked_identifier: pointy + - statement_terminator: ; + - statement: + - fetch_cursor_statement: + - keyword: FETCH + - keyword: FIRST + - keyword: FROM + - parameter: '@pointy' + - keyword: INTO + - parameter: '@result' + - statement_terminator: ; + - statement: + - fetch_cursor_statement: + - keyword: FETCH + - keyword: NEXT + - keyword: FROM + - keyword: GLOBAL + - naked_identifier: pointy + - statement_terminator: ; + - statement: + - close_cursor_statement: + - keyword: CLOSE + - keyword: GLOBAL + - naked_identifier: pointy + - statement_terminator: ; + - statement: + - deallocate_cursor_statement: + - keyword: DEALLOCATE + - naked_identifier: pointy + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@cursorName' + - data_type: + - keyword: CURSOR + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types.sql new file mode 100644 index 000000000..b5f780b23 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types.sql @@ -0,0 +1,187 @@ +-- Test file for T-SQL data types +-- https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql + +-- Exact numeric types (no parameters) +DECLARE @tinyint_var TINYINT; +DECLARE @smallint_var SMALLINT; +DECLARE @int_var INT; +DECLARE @bigint_var BIGINT; +DECLARE @bit_var BIT; +DECLARE @money_var MONEY; +DECLARE @smallmoney_var SMALLMONEY; + +-- Exact numeric types (with precision and scale) +DECLARE @decimal_var DECIMAL; +DECLARE @decimal_p_var DECIMAL(10); +DECLARE @decimal_ps_var DECIMAL(10, 2); +DECLARE @numeric_var NUMERIC; +DECLARE @numeric_p_var NUMERIC(18); +DECLARE @numeric_ps_var NUMERIC(18, 4); +DECLARE @dec_var DEC; +DECLARE @dec_p_var DEC(15); +DECLARE @dec_ps_var DEC(15, 3); + +-- Approximate numeric types +DECLARE @float_var FLOAT; +DECLARE @float_p_var FLOAT(24); +DECLARE @real_var REAL; + +-- Date and time types +DECLARE @date_var DATE; +DECLARE @smalldatetime_var SMALLDATETIME; +DECLARE @datetime_var DATETIME; +DECLARE @time_var TIME; +DECLARE @time_p_var TIME(7); +DECLARE @datetime2_var DATETIME2; +DECLARE @datetime2_p_var DATETIME2(7); +DECLARE @datetimeoffset_var DATETIMEOFFSET; +DECLARE @datetimeoffset_p_var DATETIMEOFFSET(7); + +-- Character string types +DECLARE @char_var CHAR; +DECLARE @char_n_var CHAR(10); +DECLARE @character_var CHARACTER; +DECLARE @character_n_var CHARACTER(10); +DECLARE @char_varying_var CHAR VARYING; +DECLARE @char_varying_n_var CHAR VARYING(100); +DECLARE @character_varying_var CHARACTER VARYING; +DECLARE @character_varying_n_var CHARACTER VARYING(100); +DECLARE @varchar_var VARCHAR; +DECLARE @varchar_n_var VARCHAR(50); +DECLARE @varchar_max_var VARCHAR(MAX); +DECLARE @text_var TEXT; + +-- Unicode character string types +DECLARE @nchar_var NCHAR; +DECLARE @nchar_n_var NCHAR(10); +-- DECLARE @national_char_var NATIONAL CHAR; +DECLARE @national_char_n_var NATIONAL CHAR(10); +DECLARE @national_character_var NATIONAL CHARACTER; +DECLARE @national_character_n_var NATIONAL CHARACTER(10); +DECLARE @nchar_varying_var NCHAR VARYING; +DECLARE @nchar_varying_n_var NCHAR VARYING(100); +DECLARE @nvarchar_var NVARCHAR; +DECLARE @nvarchar_n_var NVARCHAR(50); +DECLARE @nvarchar_max_var NVARCHAR(MAX); +DECLARE @national_char_varying_var NATIONAL CHARACTER VARYING; +DECLARE @national_char_varying_n_var NATIONAL CHARACTER VARYING(100); +DECLARE @ntext_var NTEXT; + +-- Binary string types +DECLARE @binary_var BINARY; +DECLARE @binary_n_var BINARY(10); +DECLARE @varbinary_var VARBINARY; +DECLARE @varbinary_n_var VARBINARY(50); +DECLARE @varbinary_max_var VARBINARY(MAX); +DECLARE @image_var IMAGE; + +-- Other data types +DECLARE @cursor_var CURSOR; +DECLARE @sql_variant_var SQL_VARIANT; +DECLARE @timestamp_var TIMESTAMP; +DECLARE @rowversion_var ROWVERSION; +DECLARE @uniqueidentifier_var UNIQUEIDENTIFIER; +DECLARE @xml_var XML; +DECLARE @json_var JSON; + +-- Spatial types +DECLARE @geography_var GEOGRAPHY; +DECLARE @geometry_var GEOMETRY; +DECLARE @hierarchyid_var HIERARCHYID; + +-- Vector type (Azure SQL Database) +DECLARE @vector_var VECTOR; +DECLARE @vector_n_var VECTOR(1536); + +-- User-defined data types +DECLARE @custom_type MyCustomType; + +-- Schema-qualified data types +DECLARE @sys_type sys.sysname; + +-- Bracketed data type identifiers +DECLARE @bracketed_type [sys].[sysname]; +GO + +-- Data types in CREATE TABLE +CREATE TABLE DataTypesTest ( + -- Exact numeric + col_tinyint TINYINT, + col_smallint SMALLINT, + col_int INT, + col_bigint BIGINT, + col_bit BIT, + col_money MONEY, + col_smallmoney SMALLMONEY, + col_decimal DECIMAL(18, 2), + col_numeric NUMERIC(10, 5), + + -- Approximate numeric + col_float FLOAT, + col_real REAL, + + -- Date and time + col_date DATE, + col_time TIME(7), + col_datetime DATETIME, + col_datetime2 DATETIME2(7), + col_datetimeoffset DATETIMEOFFSET(7), + col_smalldatetime SMALLDATETIME, + + -- Character strings + col_char CHAR(10), + col_varchar VARCHAR(50), + col_varchar_max VARCHAR(MAX), + col_text TEXT, + + -- Unicode strings + col_nchar NCHAR(10), + col_nvarchar NVARCHAR(100), + col_nvarchar_max NVARCHAR(MAX), + col_ntext NTEXT, + + -- Binary strings + col_binary BINARY(10), + col_varbinary VARBINARY(100), + col_varbinary_max VARBINARY(MAX), + col_image IMAGE, + + -- Other types + col_uniqueidentifier UNIQUEIDENTIFIER, + col_xml XML, + col_json JSON, + col_geography GEOGRAPHY, + col_geometry GEOMETRY, + col_hierarchyid HIERARCHYID, + col_sql_variant SQL_VARIANT, + col_timestamp TIMESTAMP, + col_rowversion ROWVERSION +); +GO + +-- Function parameters with data types +CREATE FUNCTION TestDataTypes( + @param_int INT, + @param_varchar VARCHAR(100), + @param_decimal DECIMAL(10, 2), + @param_datetime DATETIME2, + @param_nvarchar NVARCHAR(MAX) +) +RETURNS INT +AS +BEGIN + RETURN 1; +END; +GO + +-- Procedure parameters with data types +CREATE PROCEDURE TestDataTypesProc + @param_bigint BIGINT, + @param_nchar NCHAR(50), + @param_varbinary VARBINARY(MAX), + @param_xml XML, + @param_geography GEOGRAPHY +AS +BEGIN + SELECT @param_bigint; +END; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types.yml new file mode 100644 index 000000000..2564f6680 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types.yml @@ -0,0 +1,1116 @@ +file: +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@tinyint_var' + - data_type: + - keyword: TINYINT + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@smallint_var' + - data_type: + - keyword: SMALLINT + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@int_var' + - data_type: + - keyword: INT + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@bigint_var' + - data_type: + - keyword: BIGINT + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@bit_var' + - data_type: + - keyword: BIT + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@money_var' + - data_type: + - keyword: MONEY + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@smallmoney_var' + - data_type: + - keyword: SMALLMONEY + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@decimal_var' + - data_type: + - keyword: DECIMAL + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@decimal_p_var' + - data_type: + - keyword: DECIMAL + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@decimal_ps_var' + - data_type: + - keyword: DECIMAL + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@numeric_var' + - data_type: + - keyword: NUMERIC + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@numeric_p_var' + - data_type: + - keyword: NUMERIC + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '18' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@numeric_ps_var' + - data_type: + - keyword: NUMERIC + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '18' + - comma: ',' + - expression: + - integer_literal: '4' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@dec_var' + - data_type: + - keyword: DEC + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@dec_p_var' + - data_type: + - keyword: DEC + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '15' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@dec_ps_var' + - data_type: + - keyword: DEC + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '15' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@float_var' + - data_type: + - keyword: FLOAT + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@float_p_var' + - data_type: + - keyword: FLOAT + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '24' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@real_var' + - data_type: + - keyword: REAL + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@date_var' + - data_type: + - keyword: DATE + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@smalldatetime_var' + - data_type: + - keyword: SMALLDATETIME + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@datetime_var' + - data_type: + - keyword: DATETIME + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@time_var' + - data_type: + - keyword: TIME + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@time_p_var' + - data_type: + - keyword: TIME + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '7' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@datetime2_var' + - data_type: + - keyword: DATETIME2 + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@datetime2_p_var' + - data_type: + - keyword: DATETIME2 + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '7' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@datetimeoffset_var' + - data_type: + - keyword: DATETIMEOFFSET + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@datetimeoffset_p_var' + - data_type: + - keyword: DATETIMEOFFSET + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '7' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@char_var' + - data_type: + - keyword: CHAR + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@char_n_var' + - data_type: + - keyword: CHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@character_var' + - data_type: + - keyword: CHARACTER + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@character_n_var' + - data_type: + - keyword: CHARACTER + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@char_varying_var' + - data_type: + - keyword: CHAR + - keyword: VARYING + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@char_varying_n_var' + - data_type: + - keyword: CHAR + - keyword: VARYING + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@character_varying_var' + - data_type: + - keyword: CHARACTER + - keyword: VARYING + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@character_varying_n_var' + - data_type: + - keyword: CHARACTER + - keyword: VARYING + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@varchar_var' + - data_type: + - keyword: VARCHAR + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@varchar_n_var' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@varchar_max_var' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: MAX + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@text_var' + - data_type: + - keyword: TEXT + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@nchar_var' + - data_type: + - keyword: NCHAR + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@nchar_n_var' + - data_type: + - keyword: NCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@national_char_n_var' + - data_type: + - keyword: NATIONAL + - keyword: CHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@national_character_var' + - data_type: + - keyword: NATIONAL + - keyword: CHARACTER + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@national_character_n_var' + - data_type: + - keyword: NATIONAL + - keyword: CHARACTER + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@nchar_varying_var' + - data_type: + - keyword: NCHAR + - keyword: VARYING + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@nchar_varying_n_var' + - data_type: + - keyword: NCHAR + - keyword: VARYING + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@nvarchar_var' + - data_type: + - keyword: NVARCHAR + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@nvarchar_n_var' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@nvarchar_max_var' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: MAX + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@national_char_varying_var' + - data_type: + - keyword: NATIONAL + - keyword: CHARACTER + - keyword: VARYING + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@national_char_varying_n_var' + - data_type: + - keyword: NATIONAL + - keyword: CHARACTER + - keyword: VARYING + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@ntext_var' + - data_type: + - keyword: NTEXT + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@binary_var' + - data_type: + - keyword: BINARY + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@binary_n_var' + - data_type: + - keyword: BINARY + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@varbinary_var' + - data_type: + - keyword: VARBINARY + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@varbinary_n_var' + - data_type: + - keyword: VARBINARY + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@varbinary_max_var' + - data_type: + - keyword: VARBINARY + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: MAX + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@image_var' + - data_type: + - keyword: IMAGE + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@cursor_var' + - data_type: + - keyword: CURSOR + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@sql_variant_var' + - data_type: + - keyword: SQL_VARIANT + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@timestamp_var' + - data_type: + - keyword: TIMESTAMP + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@rowversion_var' + - data_type: + - keyword: ROWVERSION + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@uniqueidentifier_var' + - data_type: + - keyword: UNIQUEIDENTIFIER + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@xml_var' + - data_type: + - keyword: XML + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@json_var' + - data_type: + - keyword: JSON + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@geography_var' + - data_type: + - keyword: GEOGRAPHY + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@geometry_var' + - data_type: + - keyword: GEOMETRY + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@hierarchyid_var' + - data_type: + - keyword: HIERARCHYID + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@vector_var' + - data_type: + - keyword: VECTOR + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@vector_n_var' + - data_type: + - keyword: VECTOR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '1536' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@custom_type' + - data_type: + - data_type_identifier: MyCustomType + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@sys_type' + - data_type: + - naked_identifier: sys + - dot: . + - data_type_identifier: sysname + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@bracketed_type' + - data_type: + - quoted_identifier: '[sys]' + - dot: . + - data_type_identifier: '[sysname]' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: DataTypesTest + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: col_tinyint + - data_type: + - keyword: TINYINT + - comma: ',' + - column_definition: + - naked_identifier: col_smallint + - data_type: + - keyword: SMALLINT + - comma: ',' + - column_definition: + - naked_identifier: col_int + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: col_bigint + - data_type: + - keyword: BIGINT + - comma: ',' + - column_definition: + - naked_identifier: col_bit + - data_type: + - keyword: BIT + - comma: ',' + - column_definition: + - naked_identifier: col_money + - data_type: + - keyword: MONEY + - comma: ',' + - column_definition: + - naked_identifier: col_smallmoney + - data_type: + - keyword: SMALLMONEY + - comma: ',' + - column_definition: + - naked_identifier: col_decimal + - data_type: + - keyword: DECIMAL + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '18' + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col_numeric + - data_type: + - keyword: NUMERIC + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '5' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col_float + - data_type: + - keyword: FLOAT + - comma: ',' + - column_definition: + - naked_identifier: col_real + - data_type: + - keyword: REAL + - comma: ',' + - column_definition: + - naked_identifier: col_date + - data_type: + - keyword: DATE + - comma: ',' + - column_definition: + - naked_identifier: col_time + - data_type: + - keyword: TIME + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '7' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col_datetime + - data_type: + - keyword: DATETIME + - comma: ',' + - column_definition: + - naked_identifier: col_datetime2 + - data_type: + - keyword: DATETIME2 + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '7' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col_datetimeoffset + - data_type: + - keyword: DATETIMEOFFSET + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '7' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col_smalldatetime + - data_type: + - keyword: SMALLDATETIME + - comma: ',' + - column_definition: + - naked_identifier: col_char + - data_type: + - keyword: CHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col_varchar + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col_varchar_max + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: MAX + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col_text + - data_type: + - keyword: TEXT + - comma: ',' + - column_definition: + - naked_identifier: col_nchar + - data_type: + - keyword: NCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col_nvarchar + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col_nvarchar_max + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: MAX + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col_ntext + - data_type: + - keyword: NTEXT + - comma: ',' + - column_definition: + - naked_identifier: col_binary + - data_type: + - keyword: BINARY + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col_varbinary + - data_type: + - keyword: VARBINARY + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col_varbinary_max + - data_type: + - keyword: VARBINARY + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: MAX + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: col_image + - data_type: + - keyword: IMAGE + - comma: ',' + - column_definition: + - naked_identifier: col_uniqueidentifier + - data_type: + - keyword: UNIQUEIDENTIFIER + - comma: ',' + - column_definition: + - naked_identifier: col_xml + - data_type: + - keyword: XML + - comma: ',' + - column_definition: + - naked_identifier: col_json + - data_type: + - keyword: JSON + - comma: ',' + - column_definition: + - naked_identifier: col_geography + - data_type: + - keyword: GEOGRAPHY + - comma: ',' + - column_definition: + - naked_identifier: col_geometry + - data_type: + - keyword: GEOMETRY + - comma: ',' + - column_definition: + - naked_identifier: col_hierarchyid + - data_type: + - keyword: HIERARCHYID + - comma: ',' + - column_definition: + - naked_identifier: col_sql_variant + - data_type: + - keyword: SQL_VARIANT + - comma: ',' + - column_definition: + - naked_identifier: col_timestamp + - data_type: + - keyword: TIMESTAMP + - comma: ',' + - column_definition: + - naked_identifier: col_rowversion + - data_type: + - keyword: ROWVERSION + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - object_reference: + - naked_identifier: TestDataTypes + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@param_int' + - data_type: + - keyword: INT + - comma: ',' + - parameter: '@param_varchar' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - parameter: '@param_decimal' + - data_type: + - keyword: DECIMAL + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - comma: ',' + - parameter: '@param_datetime' + - data_type: + - keyword: DATETIME2 + - comma: ',' + - parameter: '@param_nvarchar' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: MAX + - end_bracket: ) + - end_bracket: ) + - keyword: RETURNS + - data_type: + - keyword: INT + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - return_segment: + - keyword: RETURN + - expression: + - integer_literal: '1' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - object_reference: + - naked_identifier: TestDataTypesProc + - procedure_parameter_list: + - parameter: '@param_bigint' + - data_type: + - keyword: BIGINT + - comma: ',' + - parameter: '@param_nchar' + - data_type: + - keyword: NCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - comma: ',' + - parameter: '@param_varbinary' + - data_type: + - keyword: VARBINARY + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: MAX + - end_bracket: ) + - comma: ',' + - parameter: '@param_xml' + - data_type: + - keyword: XML + - comma: ',' + - parameter: '@param_geography' + - data_type: + - keyword: GEOGRAPHY + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameter: '@param_bigint' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types_max.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types_max.sql deleted file mode 100644 index 202178eb4..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types_max.sql +++ /dev/null @@ -1,13 +0,0 @@ --- Test T-SQL data types with MAX and -1 parameters --- MAX is equivalent to the maximum storage size --- -1 is equivalent to MAX for certain data types - --- Variable declarations with MAX -DECLARE @LargeText NVARCHAR(MAX); -DECLARE @BigString VARCHAR(MAX); -DECLARE @BinaryData VARBINARY(MAX); - --- Variable declarations with -1 (equivalent to MAX) -DECLARE @LargeText2 NVARCHAR(-1); -DECLARE @BigString2 VARCHAR(-1); -DECLARE @BinaryData2 VARBINARY(-1); \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types_max.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types_max.yml deleted file mode 100644 index 7365d65c0..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/data_types_max.yml +++ /dev/null @@ -1,73 +0,0 @@ -file: -- statement: - - keyword: DECLARE - - tsql_variable: '@LargeText' - - data_type: - - data_type_identifier: NVARCHAR - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - keyword: MAX - - end_bracket: ) -- statement_terminator: ; -- statement: - - keyword: DECLARE - - tsql_variable: '@BigString' - - data_type: - - data_type_identifier: VARCHAR - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - keyword: MAX - - end_bracket: ) -- statement_terminator: ; -- statement: - - keyword: DECLARE - - tsql_variable: '@BinaryData' - - data_type: - - data_type_identifier: VARBINARY - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - keyword: MAX - - end_bracket: ) -- statement_terminator: ; -- statement: - - keyword: DECLARE - - tsql_variable: '@LargeText2' - - data_type: - - data_type_identifier: NVARCHAR - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: - - sign_indicator: '-' - - numeric_literal: '1' - - end_bracket: ) -- statement_terminator: ; -- statement: - - keyword: DECLARE - - tsql_variable: '@BigString2' - - data_type: - - data_type_identifier: VARCHAR - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: - - sign_indicator: '-' - - numeric_literal: '1' - - end_bracket: ) -- statement_terminator: ; -- statement: - - keyword: DECLARE - - tsql_variable: '@BinaryData2' - - data_type: - - data_type_identifier: VARBINARY - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: - - sign_indicator: '-' - - numeric_literal: '1' - - end_bracket: ) -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/date_functions.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/date_functions.sql new file mode 100644 index 000000000..95750b18d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/date_functions.sql @@ -0,0 +1,21 @@ +select convert( + date, + dateadd( + month, + datediff( + month, + 0, + t.valid_from_date + ), + 0 + ) + ) as valid_from_date +from t as t +where t.activity_month >= + convert( + date, + dateadd( + yy, + datediff(yy, 0, getdate() + ) - 1, 0) + ) diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/date_functions.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/date_functions.yml new file mode 100644 index 000000000..ab2a1e926 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/date_functions.yml @@ -0,0 +1,119 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - keyword: convert + - function_contents: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: date + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: dateadd + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: month + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: datediff + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: month + - comma: ',' + - expression: + - integer_literal: '0' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: valid_from_date + - end_bracket: ) + - comma: ',' + - expression: + - integer_literal: '0' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: valid_from_date + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: t + - where_clause: + - keyword: where + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: activity_month + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - function: + - function_name: + - keyword: convert + - function_contents: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: date + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: dateadd + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: yy + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: datediff + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: yy + - comma: ',' + - expression: + - integer_literal: '0' + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: getdate + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - binary_operator: '-' + - integer_literal: '1' + - comma: ',' + - expression: + - integer_literal: '0' + - end_bracket: ) + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datepart.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datepart.sql new file mode 100644 index 000000000..4b19fa54a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datepart.sql @@ -0,0 +1,2 @@ +SELECT DATEPART(DW, my_table.date) AS dayofweek +FROM my_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datepart.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datepart.yml new file mode 100644 index 000000000..2e21e6e24 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datepart.yml @@ -0,0 +1,33 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEPART + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: DW + - comma: ',' + - expression: + - column_reference: + - naked_identifier: my_table + - dot: . + - naked_identifier: date + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: dayofweek + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datetrunc.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datetrunc.sql new file mode 100644 index 000000000..0423a6b17 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datetrunc.sql @@ -0,0 +1,4 @@ +SELECT DATETRUNC(YEAR, my_table.date) AS [beginningOfYear] +, DATETRUNC(MONTH, my_table.date) AS [FirstOfMonth] +, DATETRUNC(DAY, my_table.date) AS [Today] +FROM my_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datetrunc.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datetrunc.yml new file mode 100644 index 000000000..c5b602217 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/datetrunc.yml @@ -0,0 +1,73 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATETRUNC + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: YEAR + - comma: ',' + - expression: + - column_reference: + - naked_identifier: my_table + - dot: . + - naked_identifier: date + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[beginningOfYear]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATETRUNC + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: MONTH + - comma: ',' + - expression: + - column_reference: + - naked_identifier: my_table + - dot: . + - naked_identifier: date + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[FirstOfMonth]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATETRUNC + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: DAY + - comma: ',' + - expression: + - column_reference: + - naked_identifier: my_table + - dot: . + - naked_identifier: date + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[Today]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_type.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_type.sql index 980101bcc..be7864318 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_type.sql +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_type.sql @@ -4,4 +4,20 @@ DECLARE @MyTableVar TABLE( NewVacationHours INT, ModifiedDate DATETIME, PRIMARY KEY (EmpID) -); \ No newline at end of file +); + +DECLARE + @myTable TABLE + ( + ID INT, + MyCol1 BIT, + MyCol2 BIT, + MyComputedCol AS ( + CASE + WHEN MyCol1 & MyCol2 = 0 + THEN 1 + WHEN MyCol2 = 0 THEN 2 + ELSE 3 + END + ) + ); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_type.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_type.yml index c2dd3f545..76fb9414f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_type.yml +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_type.yml @@ -1,40 +1,107 @@ file: -- statement: - - keyword: DECLARE - - tsql_variable: '@MyTableVar' - - keyword: TABLE - - bracketed: - - start_bracket: ( - - column_definition: - - naked_identifier: EmpID - - data_type: - - data_type_identifier: INT - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' - - comma: ',' - - column_definition: - - naked_identifier: OldVacationHours - - data_type: - - data_type_identifier: INT - - comma: ',' - - column_definition: - - naked_identifier: NewVacationHours - - data_type: - - data_type_identifier: INT - - comma: ',' - - column_definition: - - naked_identifier: ModifiedDate - - data_type: - - data_type_identifier: DATETIME - - comma: ',' - - table_constraint: - - keyword: PRIMARY - - keyword: KEY +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@MyTableVar' + - keyword: TABLE - bracketed: - start_bracket: ( - - column_reference: + - column_definition: - naked_identifier: EmpID + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: OldVacationHours + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: NewVacationHours + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: ModifiedDate + - data_type: + - keyword: DATETIME + - comma: ',' + - table_constraint: + - keyword: PRIMARY + - keyword: KEY + - bracketed_index_column_list_grammar: + - bracketed: + - start_bracket: ( + - index_column_definition: + - naked_identifier: EmpID + - end_bracket: ) - end_bracket: ) - - end_bracket: ) -- statement_terminator: ; + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@myTable' + - keyword: TABLE + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: ID + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: MyCol1 + - data_type: + - keyword: BIT + - comma: ',' + - column_definition: + - naked_identifier: MyCol2 + - data_type: + - keyword: BIT + - comma: ',' + - computed_column_definition: + - naked_identifier: MyComputedCol + - keyword: AS + - bracketed: + - start_bracket: ( + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: MyCol1 + - binary_operator: + - ampersand: '&' + - column_reference: + - naked_identifier: MyCol2 + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '0' + - keyword: THEN + - expression: + - integer_literal: '1' + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: MyCol2 + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '0' + - keyword: THEN + - expression: + - integer_literal: '2' + - else_clause: + - keyword: ELSE + - expression: + - integer_literal: '3' + - keyword: END + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_variable_complex.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_variable_complex.sql deleted file mode 100644 index a0b9d6b34..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_variable_complex.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Table variable with complex constraints (IDENTITY, DEFAULT, CHECK) --- Created for testing T-SQL constraint parsing enhancements -DECLARE @orders TABLE ( - OrderId INT IDENTITY(1,1) PRIMARY KEY, - CustomerId INT NOT NULL, - OrderDate DATETIME DEFAULT GETDATE(), - Amount DECIMAL(10,2) CHECK (Amount > 0) -); \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_variable_complex.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_variable_complex.yml deleted file mode 100644 index 57b679b0a..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_table_variable_complex.yml +++ /dev/null @@ -1,69 +0,0 @@ -file: -- statement: - - keyword: DECLARE - - tsql_variable: '@orders' - - keyword: TABLE - - bracketed: - - start_bracket: ( - - column_definition: - - naked_identifier: OrderId - - data_type: - - data_type_identifier: INT - - column_constraint_segment: - - keyword: IDENTITY - - bracketed: - - start_bracket: ( - - numeric_literal: '1' - - comma: ',' - - numeric_literal: '1' - - end_bracket: ) - - column_constraint_segment: - - keyword: PRIMARY - - keyword: KEY - - comma: ',' - - column_definition: - - naked_identifier: CustomerId - - data_type: - - data_type_identifier: INT - - column_constraint_segment: - - keyword: NOT - - keyword: 'NULL' - - comma: ',' - - column_definition: - - naked_identifier: OrderDate - - data_type: - - data_type_identifier: DATETIME - - column_constraint_segment: - - keyword: DEFAULT - - function: - - function_name: - - function_name_identifier: GETDATE - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) - - comma: ',' - - column_definition: - - naked_identifier: Amount - - data_type: - - data_type_identifier: DECIMAL - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '10' - - comma: ',' - - numeric_literal: '2' - - end_bracket: ) - - column_constraint_segment: - - keyword: CHECK - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: Amount - - comparison_operator: - - raw_comparison_operator: '>' - - numeric_literal: '0' - - end_bracket: ) - - end_bracket: ) -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_variable.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_variable.sql deleted file mode 100644 index 6a3509857..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_variable.sql +++ /dev/null @@ -1 +0,0 @@ -DECLARE @MyVariable INT = 42; \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_variable.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_variable.yml deleted file mode 100644 index 9a80fd976..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_variable.yml +++ /dev/null @@ -1,11 +0,0 @@ -file: -- statement: - - keyword: DECLARE - - tsql_variable: '@MyVariable' - - data_type: - - data_type_identifier: INT - - assignment_operator: - - raw_comparison_operator: = - - expression: - - numeric_literal: '42' -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_with_following_statements.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_with_following_statements.sql new file mode 100644 index 000000000..4905fcd23 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_with_following_statements.sql @@ -0,0 +1,24 @@ +CREATE PROC Reporting.DeclareProblem AS +BEGIN + + DECLARE @startdate AS DATE; + + DECLARE @DateNow DATE = GETDATE(); + + DECLARE @DateStart DATETIME2 = GETDATE() + ,@DateEnd DATETIME2 = GETDATE() + + DECLARE @EOMONTH DATE = ('1900-01-01') + + DECLARE @USER DATE = SYSTEM_USER; + + DECLARE @CURRENTTIME DATE = CURRENT_TIMESTAMP; + + SET @EOMONTH = ('2000-01-01') + + SET @EOMONTH = ('2001-01-01'); + + IF OBJECT_ID('tempdb..#UP') IS NOT NULL DROP TABLE #UP; + + +END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_with_following_statements.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_with_following_statements.yml new file mode 100644 index 000000000..c85784d1f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/declare_with_following_statements.yml @@ -0,0 +1,156 @@ +file: +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROC + - object_reference: + - naked_identifier: Reporting + - dot: . + - naked_identifier: DeclareProblem + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@startdate' + - keyword: AS + - data_type: + - keyword: DATE + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@DateNow' + - data_type: + - keyword: DATE + - comparison_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@DateStart' + - data_type: + - keyword: DATETIME2 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - parameter: '@DateEnd' + - data_type: + - keyword: DATETIME2 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@EOMONTH' + - data_type: + - keyword: DATE + - comparison_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''1900-01-01''' + - end_bracket: ) + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@USER' + - data_type: + - keyword: DATE + - comparison_operator: + - raw_comparison_operator: = + - expression: + - bare_function: SYSTEM_USER + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@CURRENTTIME' + - data_type: + - keyword: DATE + - comparison_operator: + - raw_comparison_operator: = + - expression: + - bare_function: CURRENT_TIMESTAMP + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@EOMONTH' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2000-01-01''' + - end_bracket: ) + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@EOMONTH' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''2001-01-01''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - function: + - function_name: + - function_name_identifier: OBJECT_ID + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''tempdb..#UP''' + - end_bracket: ) + - keyword: IS + - keyword: NOT + - null_literal: 'NULL' + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - hash_identifier: '#UP' + - statement_terminator: ; + - keyword: END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete.sql new file mode 100644 index 000000000..987a25530 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete.sql @@ -0,0 +1,107 @@ +DELETE FROM Sales.SalesPersonQuotaHistory; +GO + +DELETE FROM Production.ProductCostHistory +WHERE StandardCost > 1000.00; +GO + +DELETE Production.ProductCostHistory +WHERE StandardCost BETWEEN 12.00 AND 14.00 + AND EndDate IS NULL; +PRINT 'Number of rows deleted is ' + CAST(@@ROWCOUNT as char(3)); +GO + +DECLARE complex_cursor CURSOR FOR + SELECT a.BusinessEntityID + FROM HumanResources.EmployeePayHistory AS a + WHERE RateChangeDate <> + (SELECT MAX(RateChangeDate) + FROM HumanResources.EmployeePayHistory AS b + WHERE a.BusinessEntityID = b.BusinessEntityID) ; +OPEN complex_cursor; +FETCH FROM complex_cursor; +DELETE FROM HumanResources.EmployeePayHistory +WHERE CURRENT OF complex_cursor; +CLOSE complex_cursor; +DEALLOCATE complex_cursor; +GO + +-- SQL-2003 Standard subquery + +DELETE FROM Sales.SalesPersonQuotaHistory +WHERE BusinessEntityID IN + (SELECT BusinessEntityID + FROM Sales.SalesPerson + WHERE SalesYTD > 2500000.00); +GO + +-- Transact-SQL extension + +DELETE FROM Sales.SalesPersonQuotaHistory +FROM Sales.SalesPersonQuotaHistory AS spqh +INNER JOIN Sales.SalesPerson AS sp +ON spqh.BusinessEntityID = sp.BusinessEntityID +WHERE sp.SalesYTD > 2500000.00; +GO + +-- No need to mention target table more than once. + +DELETE spqh + FROM + Sales.SalesPersonQuotaHistory AS spqh + INNER JOIN Sales.SalesPerson AS sp + ON spqh.BusinessEntityID = sp.BusinessEntityID + WHERE sp.SalesYTD > 2500000.00; + +DELETE TOP (20) +FROM Purchasing.PurchaseOrderDetail +WHERE DueDate < '20020701'; +GO + +DELETE FROM Purchasing.PurchaseOrderDetail +WHERE PurchaseOrderDetailID IN + (SELECT TOP 10 PurchaseOrderDetailID + FROM Purchasing.PurchaseOrderDetail + ORDER BY DueDate ASC); +GO + +-- Specify the remote data source using a four-part name +-- in the form linked_server.catalog.schema.object. + +DELETE MyLinkServer.AdventureWorks2012.HumanResources.Department +WHERE DepartmentID > 16; +GO + +DELETE OPENQUERY (MyLinkServer, 'SELECT Name, GroupName +FROM AdventureWorks2012.HumanResources.Department +WHERE DepartmentID = 18'); +GO + +DELETE OPENROWSET('SQLNCLI', 'Server=Seattle1;Trusted_Connection=yes;', Department) +GO + +DELETE FROM OPENDATASOURCE('SQLNCLI', + 'Data Source= ; Integrated Security=SSPI') + .AdventureWorks2012.HumanResources.Department +WHERE DepartmentID = 17; + +DELETE Sales.ShoppingCartItem +OUTPUT DELETED.* +WHERE ShoppingCartID = 20621; + +DECLARE @MyTableVar table ( + ProductID int NOT NULL, + ProductName nvarchar(50)NOT NULL, + ProductModelID int NOT NULL, + PhotoID int NOT NULL); + +DELETE Production.ProductProductPhoto +OUTPUT DELETED.ProductID, + p.Name, + p.ProductModelID, + DELETED.ProductPhotoID + INTO @MyTableVar +FROM Production.ProductProductPhoto AS ph +JOIN Production.Product as p + ON ph.ProductID = p.ProductID + WHERE p.ProductModelID BETWEEN 120 and 130; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete.yml new file mode 100644 index 000000000..c09e0c401 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete.yml @@ -0,0 +1,662 @@ +file: +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesPersonQuotaHistory + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ProductCostHistory + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: StandardCost + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '1000.00' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ProductCostHistory + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: StandardCost + - keyword: BETWEEN + - numeric_literal: '12.00' + - keyword: AND + - numeric_literal: '14.00' + - binary_operator: AND + - column_reference: + - naked_identifier: EndDate + - keyword: IS + - null_literal: 'NULL' + - statement_terminator: ; + - statement: + - print_statement: + - keyword: PRINT + - expression: + - quoted_literal: '''Number of rows deleted is ''' + - binary_operator: + + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - system_variable: '@@ROWCOUNT' + - keyword: as + - data_type: + - keyword: char + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - naked_identifier: complex_cursor + - cursor_definition: + - keyword: CURSOR + - keyword: FOR + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: BusinessEntityID + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: EmployeePayHistory + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: RateChangeDate + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: '>' + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: MAX + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: RateChangeDate + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: EmployeePayHistory + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: b + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: BusinessEntityID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: BusinessEntityID + - end_bracket: ) + - statement_terminator: ; + - statement: + - open_cursor_statement: + - keyword: OPEN + - naked_identifier: complex_cursor + - statement_terminator: ; + - statement: + - fetch_cursor_statement: + - keyword: FETCH + - keyword: FROM + - naked_identifier: complex_cursor + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: EmployeePayHistory + - keyword: WHERE + - keyword: CURRENT + - keyword: OF + - naked_identifier: complex_cursor + - statement_terminator: ; + - statement: + - close_cursor_statement: + - keyword: CLOSE + - naked_identifier: complex_cursor + - statement_terminator: ; + - statement: + - deallocate_cursor_statement: + - keyword: DEALLOCATE + - naked_identifier: complex_cursor + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesPersonQuotaHistory + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: BusinessEntityID + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: BusinessEntityID + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesPerson + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: SalesYTD + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '2500000.00' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesPersonQuotaHistory + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesPersonQuotaHistory + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: spqh + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesPerson + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sp + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: spqh + - dot: . + - naked_identifier: BusinessEntityID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: sp + - dot: . + - naked_identifier: BusinessEntityID + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: sp + - dot: . + - naked_identifier: SalesYTD + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '2500000.00' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: spqh + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesPersonQuotaHistory + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: spqh + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesPerson + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sp + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: spqh + - dot: . + - naked_identifier: BusinessEntityID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: sp + - dot: . + - naked_identifier: BusinessEntityID + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: sp + - dot: . + - naked_identifier: SalesYTD + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '2500000.00' + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - keyword: TOP + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '20' + - end_bracket: ) + - keyword: FROM + - table_reference: + - naked_identifier: Purchasing + - dot: . + - naked_identifier: PurchaseOrderDetail + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: DueDate + - comparison_operator: + - raw_comparison_operator: < + - quoted_literal: '''20020701''' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: Purchasing + - dot: . + - naked_identifier: PurchaseOrderDetail + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: PurchaseOrderDetailID + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - expression: + - integer_literal: '10' + - select_clause_element: + - column_reference: + - naked_identifier: PurchaseOrderDetailID + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Purchasing + - dot: . + - naked_identifier: PurchaseOrderDetail + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: DueDate + - keyword: ASC + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: MyLinkServer + - dot: . + - naked_identifier: AdventureWorks2012 + - dot: . + - naked_identifier: HumanResources + - dot: . + - naked_identifier: Department + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: DepartmentID + - comparison_operator: + - raw_comparison_operator: '>' + - integer_literal: '16' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - keyword: OPENQUERY + - bracketed: + - start_bracket: ( + - naked_identifier: MyLinkServer + - comma: ',' + - quoted_literal: |- + 'SELECT Name, GroupName + FROM AdventureWorks2012.HumanResources.Department + WHERE DepartmentID = 18' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - openrowset_segment: + - keyword: OPENROWSET + - bracketed: + - start_bracket: ( + - quoted_literal: '''SQLNCLI''' + - comma: ',' + - quoted_literal: '''Server=Seattle1;Trusted_Connection=yes;''' + - comma: ',' + - table_reference: + - naked_identifier: Department + - end_bracket: ) + - go_statement: + - keyword: GO +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - keyword: OPENDATASOURCE + - bracketed: + - start_bracket: ( + - quoted_literal: '''SQLNCLI''' + - comma: ',' + - quoted_literal: '''Data Source= ; Integrated Security=SSPI''' + - end_bracket: ) + - dot: . + - table_reference: + - naked_identifier: AdventureWorks2012 + - dot: . + - naked_identifier: HumanResources + - dot: . + - naked_identifier: Department + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: DepartmentID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '17' + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: ShoppingCartItem + - output_clause: + - keyword: OUTPUT + - keyword: DELETED + - dot: . + - wildcard_identifier: + - star: '*' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ShoppingCartID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '20621' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@MyTableVar' + - keyword: table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: ProductID + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: ProductName + - data_type: + - keyword: nvarchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: ProductModelID + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: PhotoID + - data_type: + - keyword: int + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ProductProductPhoto + - output_clause: + - keyword: OUTPUT + - keyword: DELETED + - dot: . + - naked_identifier: ProductID + - comma: ',' + - naked_identifier: p + - dot: . + - naked_identifier: Name + - comma: ',' + - naked_identifier: p + - dot: . + - naked_identifier: ProductModelID + - comma: ',' + - keyword: DELETED + - dot: . + - naked_identifier: ProductPhotoID + - keyword: INTO + - parameter: '@MyTableVar' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ProductProductPhoto + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: ph + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: Product + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: p + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: ph + - dot: . + - naked_identifier: ProductID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: ProductID + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: ProductModelID + - keyword: BETWEEN + - integer_literal: '120' + - keyword: and + - integer_literal: '130' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete_azure_synapse_analytics.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete_azure_synapse_analytics.sql new file mode 100644 index 000000000..0569b66fb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete_azure_synapse_analytics.sql @@ -0,0 +1,35 @@ +DELETE dbo.Table2 +FROM dbo.Table2 + INNER JOIN dbo.Table1 + ON (dbo.Table2.ColA = dbo.Table1.ColA) + WHERE dboTable2.ColA = 1; + +DELETE +FROM dodos WITH(NOLOCK) +OUTPUT age INTO ages + +DELETE FROM Table1; + +DELETE FROM Table1 +WHERE StandardCost > 1000.00; + +DELETE FROM Table1 +OPTION ( LABEL = N'label1' ); + +DELETE FROM dbo.FactInternetSales +WHERE ProductKey IN ( + SELECT T1.ProductKey FROM dbo.DimProduct T1 + JOIN dbo.DimProductSubcategory T2 + ON T1.ProductSubcategoryKey = T2.ProductSubcategoryKey + WHERE T2.EnglishProductSubcategoryName = 'Road Bikes' ) +OPTION ( LABEL = N'CustomJoin', HASH JOIN ) ; + +DELETE tableA WHERE EXISTS ( +SELECT TOP 1 1 FROM tableB tb WHERE tb.col1 = tableA.col1 +) + +DELETE dbo.Table2 +FROM dbo.Table2 + INNER JOIN dbo.Table1 + ON (dbo.Table2.ColA = dbo.Table1.ColA) + WHERE dboTable2.ColA = 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete_azure_synapse_analytics.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete_azure_synapse_analytics.yml new file mode 100644 index 000000000..c5954c495 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/delete_azure_synapse_analytics.yml @@ -0,0 +1,301 @@ +file: +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Table2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Table2 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Table1 + - join_on_condition: + - keyword: ON + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Table2 + - dot: . + - naked_identifier: ColA + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Table1 + - dot: . + - naked_identifier: ColA + - end_bracket: ) + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: dboTable2 + - dot: . + - naked_identifier: ColA + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: dodos + - post_table_expression: + - keyword: WITH + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: NOLOCK + - end_bracket: ) + - output_clause: + - keyword: OUTPUT + - expression: + - column_reference: + - naked_identifier: age + - keyword: INTO + - table_reference: + - naked_identifier: ages + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: Table1 + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: Table1 + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: StandardCost + - comparison_operator: + - raw_comparison_operator: '>' + - numeric_literal: '1000.00' + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: Table1 + - option_clause: + - keyword: OPTION + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: LABEL + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'label1' + - end_bracket: ) + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: FactInternetSales + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ProductKey + - keyword: IN + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: T1 + - dot: . + - naked_identifier: ProductKey + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: DimProduct + - alias_expression: + - naked_identifier: T1 + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: DimProductSubcategory + - alias_expression: + - naked_identifier: T2 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: T1 + - dot: . + - naked_identifier: ProductSubcategoryKey + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: T2 + - dot: . + - naked_identifier: ProductSubcategoryKey + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: T2 + - dot: . + - naked_identifier: EnglishProductSubcategoryName + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Road Bikes''' + - end_bracket: ) + - option_clause: + - keyword: OPTION + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: LABEL + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'CustomJoin' + - comma: ',' + - query_hint_segment: + - keyword: HASH + - keyword: JOIN + - end_bracket: ) + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: tableA + - where_clause: + - keyword: WHERE + - expression: + - keyword: EXISTS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - expression: + - integer_literal: '1' + - select_clause_element: + - integer_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tableB + - alias_expression: + - naked_identifier: tb + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: tb + - dot: . + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: tableA + - dot: . + - naked_identifier: col1 + - end_bracket: ) + - statement: + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Table2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Table2 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Table1 + - join_on_condition: + - keyword: ON + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Table2 + - dot: . + - naked_identifier: ColA + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Table1 + - dot: . + - naked_identifier: ColA + - end_bracket: ) + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: dboTable2 + - dot: . + - naked_identifier: ColA + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/dml_as_derived_table.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/dml_as_derived_table.sql new file mode 100644 index 000000000..614d208c1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/dml_as_derived_table.sql @@ -0,0 +1,36 @@ +-- DELETE with OUTPUT as derived table +INSERT INTO tbl1 +SELECT id FROM ( + DELETE tbl2 + OUTPUT deleted.id +) AS x; + +-- UPDATE with OUTPUT as derived table +SELECT * FROM ( + UPDATE tbl3 + SET col1 = 'value' + OUTPUT inserted.id, deleted.col1, inserted.col1 +) AS updated_data; + +-- INSERT with OUTPUT as derived table +SELECT new_id FROM ( + INSERT INTO tbl4 (name) + OUTPUT inserted.id AS new_id + VALUES ('test') +) AS ins; + +-- DELETE with OUTPUT and WHERE clause +SELECT deleted_id FROM ( + DELETE FROM tbl5 + OUTPUT deleted.id AS deleted_id + WHERE status = 'inactive' +) AS del_result; + +-- Complex DELETE with OUTPUT and JOIN in outer query +SELECT d.id, t.name +FROM ( + DELETE tbl6 + OUTPUT deleted.id, deleted.category_id + WHERE deleted_date < '2020-01-01' +) AS d +INNER JOIN tbl7 t ON d.category_id = t.id; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/dml_as_derived_table.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/dml_as_derived_table.yml new file mode 100644 index 000000000..c561535bd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/dml_as_derived_table.yml @@ -0,0 +1,241 @@ +file: +- batch: + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: tbl1 + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: tbl2 + - output_clause: + - keyword: OUTPUT + - keyword: deleted + - dot: . + - naked_identifier: id + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: x + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: tbl3 + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: col1 + - assignment_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''value''' + - output_clause: + - keyword: OUTPUT + - keyword: inserted + - dot: . + - naked_identifier: id + - comma: ',' + - keyword: deleted + - dot: . + - naked_identifier: col1 + - comma: ',' + - keyword: inserted + - dot: . + - naked_identifier: col1 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: updated_data + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: new_id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: tbl4 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: name + - end_bracket: ) + - output_clause: + - keyword: OUTPUT + - keyword: inserted + - dot: . + - naked_identifier: id + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: new_id + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - quoted_literal: '''test''' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: ins + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: deleted_id + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: tbl5 + - output_clause: + - keyword: OUTPUT + - keyword: deleted + - dot: . + - naked_identifier: id + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: deleted_id + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: status + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''inactive''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: del_result + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: name + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: tbl6 + - output_clause: + - keyword: OUTPUT + - keyword: deleted + - dot: . + - naked_identifier: id + - comma: ',' + - keyword: deleted + - dot: . + - naked_identifier: category_id + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: deleted_date + - comparison_operator: + - raw_comparison_operator: < + - quoted_literal: '''2020-01-01''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: d + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl7 + - alias_expression: + - naked_identifier: t + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: category_id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: id + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_external_table.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_external_table.sql new file mode 100644 index 000000000..e9aacbee0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_external_table.sql @@ -0,0 +1,7 @@ +/* +https://learn.microsoft.com/en-us/sql/t-sql/statements/drop-external-table-transact-sql?view=sql-server-ver16#examples +*/ + +DROP EXTERNAL TABLE SalesPerson; +DROP EXTERNAL TABLE dbo.SalesPerson; +DROP EXTERNAL TABLE EasternDivision.dbo.SalesPerson; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_external_table.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_external_table.yml new file mode 100644 index 000000000..d68189f7e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_external_table.yml @@ -0,0 +1,32 @@ +file: +- batch: + - statement: + - drop_external_table_statement: + - keyword: DROP + - keyword: EXTERNAL + - keyword: TABLE + - table_reference: + - naked_identifier: SalesPerson + - statement_terminator: ; + - statement: + - drop_external_table_statement: + - keyword: DROP + - keyword: EXTERNAL + - keyword: TABLE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: SalesPerson + - statement_terminator: ; + - statement: + - drop_external_table_statement: + - keyword: DROP + - keyword: EXTERNAL + - keyword: TABLE + - table_reference: + - naked_identifier: EasternDivision + - dot: . + - naked_identifier: dbo + - dot: . + - naked_identifier: SalesPerson + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_function.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_function.sql new file mode 100644 index 000000000..c3db0ba98 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_function.sql @@ -0,0 +1,2 @@ +DROP FUNCTION Sales.fn_SalesByStore; +DROP FUNCTION IF EXISTS sales, sales2; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_function.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_function.yml new file mode 100644 index 000000000..954b2fec7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_function.yml @@ -0,0 +1,23 @@ +file: +- batch: + - statement: + - drop_function_statement: + - keyword: DROP + - keyword: FUNCTION + - function_name: + - naked_identifier: Sales + - dot: . + - function_name_identifier: fn_SalesByStore + - statement_terminator: ; + - statement: + - drop_function_statement: + - keyword: DROP + - keyword: FUNCTION + - keyword: IF + - keyword: EXISTS + - function_name: + - function_name_identifier: sales + - comma: ',' + - function_name: + - function_name_identifier: sales2 + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_procedure.yml index c74d6ee5e..29e416041 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_procedure.yml +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_procedure.yml @@ -1,34 +1,35 @@ file: -- statement: - - drop_procedure_statement: - - keyword: DROP - - keyword: PROCEDURE - - object_reference: - - naked_identifier: procedure_name -- statement_terminator: ; -- statement: - - drop_procedure_statement: - - keyword: DROP - - keyword: PROC - - object_reference: - - naked_identifier: procedure_name -- statement_terminator: ; -- statement: - - drop_procedure_statement: - - keyword: DROP - - keyword: PROCEDURE - - keyword: IF - - keyword: EXISTS - - object_reference: - - naked_identifier: procedure_name -- statement_terminator: ; -- statement: - - drop_procedure_statement: - - keyword: DROP - - keyword: PROCEDURE - - object_reference: - - naked_identifier: procedure_name1 - - comma: ',' - - object_reference: - - naked_identifier: procedure_name2 -- statement_terminator: ; +- batch: + - statement: + - drop_procedure_statement: + - keyword: DROP + - keyword: PROCEDURE + - object_reference: + - naked_identifier: procedure_name + - statement_terminator: ; + - statement: + - drop_procedure_statement: + - keyword: DROP + - keyword: PROC + - object_reference: + - naked_identifier: procedure_name + - statement_terminator: ; + - statement: + - drop_procedure_statement: + - keyword: DROP + - keyword: PROCEDURE + - keyword: IF + - keyword: EXISTS + - object_reference: + - naked_identifier: procedure_name + - statement_terminator: ; + - statement: + - drop_procedure_statement: + - keyword: DROP + - keyword: PROCEDURE + - object_reference: + - naked_identifier: procedure_name1 + - comma: ',' + - object_reference: + - naked_identifier: procedure_name2 + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_table.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_table.sql new file mode 100644 index 000000000..a949f676f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_table.sql @@ -0,0 +1,11 @@ +drop table some_table; + +drop table if exists some_table; + +drop table some_table restrict; + +drop table if exists some_table restrict; + +drop table some_table cascade; + +drop table if exists some_table cascade; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_table.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_table.yml new file mode 100644 index 000000000..fe78e9a97 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_table.yml @@ -0,0 +1,54 @@ +file: +- batch: + - statement: + - drop_table_statement: + - keyword: drop + - keyword: table + - table_reference: + - naked_identifier: some_table + - statement_terminator: ; + - statement: + - drop_table_statement: + - keyword: drop + - keyword: table + - keyword: if + - keyword: exists + - table_reference: + - naked_identifier: some_table + - statement_terminator: ; + - statement: + - drop_table_statement: + - keyword: drop + - keyword: table + - table_reference: + - naked_identifier: some_table + - keyword: restrict + - statement_terminator: ; + - statement: + - drop_table_statement: + - keyword: drop + - keyword: table + - keyword: if + - keyword: exists + - table_reference: + - naked_identifier: some_table + - keyword: restrict + - statement_terminator: ; + - statement: + - drop_table_statement: + - keyword: drop + - keyword: table + - table_reference: + - naked_identifier: some_table + - keyword: cascade + - statement_terminator: ; + - statement: + - drop_table_statement: + - keyword: drop + - keyword: table + - keyword: if + - keyword: exists + - table_reference: + - naked_identifier: some_table + - keyword: cascade + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_user.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_user.sql new file mode 100644 index 000000000..755a656cc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_user.sql @@ -0,0 +1,3 @@ +drop user some_user; + +drop user if exists some_user; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_user.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_user.yml new file mode 100644 index 000000000..0c2a70b1a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_user.yml @@ -0,0 +1,18 @@ +file: +- batch: + - statement: + - drop_user_statement: + - keyword: drop + - keyword: user + - role_reference: + - naked_identifier: some_user + - statement_terminator: ; + - statement: + - drop_user_statement: + - keyword: drop + - keyword: user + - keyword: if + - keyword: exists + - role_reference: + - naked_identifier: some_user + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_view.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_view.sql new file mode 100644 index 000000000..90a07d559 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_view.sql @@ -0,0 +1,11 @@ +drop view some_view; + +drop view if exists some_view; + +drop view some_view restrict; + +drop view if exists some_view restrict; + +drop view some_view cascade; + +drop view if exists some_view cascade; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_view.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_view.yml new file mode 100644 index 000000000..16abbbaaf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/drop_view.yml @@ -0,0 +1,54 @@ +file: +- batch: + - statement: + - drop_view_statement: + - keyword: drop + - keyword: view + - table_reference: + - naked_identifier: some_view + - statement_terminator: ; + - statement: + - drop_view_statement: + - keyword: drop + - keyword: view + - keyword: if + - keyword: exists + - table_reference: + - naked_identifier: some_view + - statement_terminator: ; + - statement: + - drop_view_statement: + - keyword: drop + - keyword: view + - table_reference: + - naked_identifier: some_view + - keyword: restrict + - statement_terminator: ; + - statement: + - drop_view_statement: + - keyword: drop + - keyword: view + - keyword: if + - keyword: exists + - table_reference: + - naked_identifier: some_view + - keyword: restrict + - statement_terminator: ; + - statement: + - drop_view_statement: + - keyword: drop + - keyword: view + - table_reference: + - naked_identifier: some_view + - keyword: cascade + - statement_terminator: ; + - statement: + - drop_view_statement: + - keyword: drop + - keyword: view + - keyword: if + - keyword: exists + - table_reference: + - naked_identifier: some_view + - keyword: cascade + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/execute.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/execute.sql new file mode 100644 index 000000000..ae87f983f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/execute.sql @@ -0,0 +1,139 @@ +EXEC [Reporting].[Load_CLL] + +-- Specifying a value only for one parameter (@p2). +EXECUTE dbo.ProcTestDefaults @p2 = 'A'; +-- Specifying a value for the first two parameters. +EXECUTE dbo.ProcTestDefaults 68, 'B'; +-- Specifying a value for all three parameters. +EXECUTE dbo.ProcTestDefaults 68, 'C', 'House'; +-- Using the DEFAULT keyword for the first parameter. +EXECUTE dbo.ProcTestDefaults @p1 = DEFAULT, @p2 = 'D'; +-- Specifying the parameters in an order different from the order defined in the procedure. +EXECUTE dbo.ProcTestDefaults DEFAULT, @p3 = 'Local', @p2 = 'E'; +-- Using the DEFAULT keyword for the first and third parameters. +EXECUTE dbo.ProcTestDefaults DEFAULT, 'H', DEFAULT; +EXECUTE dbo.ProcTestDefaults DEFAULT, 'I', @p3 = DEFAULT; + + +EXECUTE sp_addextendedproperty +@name = N'MS_Description', +@value = 'my text description', +@level0type = N'SCHEMA', +@level0name = N'my_schema_name', +@level1type = N'my_object_type', +@level1name = N'my_object_name' + + +-- Executing a stored procedure and capturing the RETURN value in a variable +EXEC @pRes = dbo.ProcTestDefaults; +EXEC @pRes = dbo.ProcTestDefaults @p1 = DEFAULT; +EXECUTE @pRes = dbo.ProcTestDefaults; +EXECUTE @pRes = dbo.ProcTestDefaults @p1 = DEFAULT; + +-- Executing statement from a variable +DECLARE @statement nvarchar(max) = 'SELECT 1' +EXEC (@statement); + +EXEC ('DROP TABLE BoardInventory.BoardInventoryFact_Stage;'); + +DECLARE @s1 AS varchar(10) = NULL; +DECLARE @s2 varchar(10) = NULL; +SET @s1 = 'select '; +SET @s2 = '123'; +EXECUTE (@s1 + @s2); + +EXEC ('select ' + '123'); + +-- Use EXECUTE with a character string +EXECUTE ('USE AdventureWorks2022; SELECT BusinessEntityID, JobTitle FROM HumanResources.Employee;'); + +-- Use EXECUTE to pass a single parameter +EXECUTE dbo.uspGetEmployeeManagers 6; + +-- The variable can be explicitly named in the execution: +EXECUTE dbo.uspGetEmployeeManagers @EmployeeID = 6; + +-- Use EXECUTE to pass a parameter and capture the output +EXECUTE dbo.uspGetEmployeeManagers @EmployeeID, @ManagerID OUTPUT; +GO + +-- first statement in a batch or a sqlcmd script, EXECUTE isn't required. +dbo.uspGetEmployeeManagers @EmployeeID = 6; +GO + +-- Use multiple parameters +DECLARE @CheckDate AS DATETIME = GETDATE(); +EXECUTE dbo.uspGetWhereUsedProductID 819, @CheckDate; + +-- Use EXECUTE 'tsql_string' with a variable +DECLARE @schemaname AS sysname; +DECLARE @tablename AS sysname; +EXECUTE ('ALTER INDEX ALL ON ' + + @schemaname + '.' + + @tablename + ' REBUILD;'); + +-- Use EXECUTE with a remote stored procedure +DECLARE @retstat AS INT; +EXECUTE + @retstat = SQLSERVER1.AdventureWorks2022.dbo.uspGetEmployeeManagers + @BusinessEntityID = 6; + +-- Use EXECUTE with a stored procedure variable +DECLARE @proc_name AS VARCHAR (30) = 'sys.sp_who'; +EXECUTE @proc_name; + +-- Using the DEFAULT keyword for the first parameter. +EXECUTE dbo.ProcTestDefaults + @p1 = DEFAULT, + @p2 = 'D'; + +-- Using the DEFAULT keyword for the first and third parameters. +EXECUTE dbo.ProcTestDefaults DEFAULT, 'H', DEFAULT; +EXECUTE dbo.ProcTestDefaults DEFAULT, 'I', @p3 = DEFAULT; + +-- Use EXECUTE with AT linked_server_name +EXECUTE ('CREATE TABLE AdventureWorks2022.dbo.SalesTbl +(SalesID INT, SalesName VARCHAR(10)); ') AT SeattleSales; +EXECUTE ('SELECT * FROM scott.emp WHERE MGR = ?', 7902) AT ORACLE; + +-- Use EXECUTE WITH RECOMPILE +EXECUTE dbo.Proc_Test_Defaults @p2 = 'A' WITH RECOMPILE; + +-- Use EXECUTE with a user-defined function +DECLARE @returnstatus AS NVARCHAR (15); +EXECUTE + @returnstatus = dbo.ufnGetSalesOrderStatusText + @Status = 2; + +-- Use EXECUTE AS USER to switch context to another user +EXECUTE ('CREATE TABLE Sales.SalesTable (SalesID INT, SalesName VARCHAR(10));') +AS USER = 'User1'; + +-- Use EXECUTE to redefine a single result set +EXECUTE uspGetEmployeeManagers 16 WITH RESULT SETS +(( + [Reporting Level] INT NOT NULL, + [ID of Employee] INT NOT NULL, + [Employee First Name] NVARCHAR (50) NOT NULL, + [Employee Last Name] NVARCHAR (50) NOT NULL, + [Employee ID of Manager] NVARCHAR (MAX) NOT NULL, + [Manager First Name] NVARCHAR (50) NOT NULL, + [Manager Last Name] NVARCHAR (50) NOT NULL +)); + +-- Use EXECUTE to redefine a two result sets +EXECUTE Production.ProductList '%tire%' WITH RESULT SETS +( + -- first result set definition starts here + (ProductID INT, + [Name] NAME, + ListPrice MONEY) + -- comma separates result set definitions + , + -- second result set definition starts here + ([Name] NAME, + NumberOfOrders INT) +); + +-- Use EXECUTE with AT DATA_SOURCE data_source_name to query a remote SQL Server +EXECUTE ( 'SELECT @@SERVERNAME' ) AT DATA_SOURCE my_sql_server; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/execute.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/execute.yml new file mode 100644 index 000000000..5c0a3a82a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/execute.yml @@ -0,0 +1,790 @@ +file: +- batch: + - statement: + - execute_script_statement: + - keyword: EXEC + - object_reference: + - quoted_identifier: '[Reporting]' + - dot: . + - quoted_identifier: '[Load_CLL]' + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ProcTestDefaults + - parameter: '@p2' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''A''' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ProcTestDefaults + - expression: + - integer_literal: '68' + - comma: ',' + - expression: + - quoted_literal: '''B''' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ProcTestDefaults + - expression: + - integer_literal: '68' + - comma: ',' + - expression: + - quoted_literal: '''C''' + - comma: ',' + - expression: + - quoted_literal: '''House''' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ProcTestDefaults + - parameter: '@p1' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - keyword: DEFAULT + - comma: ',' + - parameter: '@p2' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''D''' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ProcTestDefaults + - expression: + - keyword: DEFAULT + - comma: ',' + - parameter: '@p3' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''Local''' + - comma: ',' + - parameter: '@p2' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''E''' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ProcTestDefaults + - expression: + - keyword: DEFAULT + - comma: ',' + - expression: + - quoted_literal: '''H''' + - comma: ',' + - expression: + - keyword: DEFAULT + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ProcTestDefaults + - expression: + - keyword: DEFAULT + - comma: ',' + - expression: + - quoted_literal: '''I''' + - comma: ',' + - parameter: '@p3' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - keyword: DEFAULT + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: sp_addextendedproperty + - parameter: '@name' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: N'MS_Description' + - comma: ',' + - parameter: '@value' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''my text description''' + - comma: ',' + - parameter: '@level0type' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: N'SCHEMA' + - comma: ',' + - parameter: '@level0name' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: N'my_schema_name' + - comma: ',' + - parameter: '@level1type' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: N'my_object_type' + - comma: ',' + - parameter: '@level1name' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: N'my_object_name' + - statement: + - execute_script_statement: + - keyword: EXEC + - parameter: '@pRes' + - raw_comparison_operator: = + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ProcTestDefaults + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXEC + - parameter: '@pRes' + - raw_comparison_operator: = + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ProcTestDefaults + - parameter: '@p1' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - keyword: DEFAULT + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - parameter: '@pRes' + - raw_comparison_operator: = + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ProcTestDefaults + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - parameter: '@pRes' + - raw_comparison_operator: = + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ProcTestDefaults + - parameter: '@p1' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - keyword: DEFAULT + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@statement' + - data_type: + - keyword: nvarchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: max + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''SELECT 1''' + - statement: + - execute_script_statement: + - keyword: EXEC + - bracketed: + - start_bracket: ( + - parameter: '@statement' + - end_bracket: ) + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXEC + - bracketed: + - start_bracket: ( + - quoted_literal: '''DROP TABLE BoardInventory.BoardInventoryFact_Stage;''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@s1' + - keyword: AS + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - null_literal: 'NULL' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@s2' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - null_literal: 'NULL' + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@s1' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''select ''' + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@s2' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''123''' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - bracketed: + - start_bracket: ( + - parameter: '@s1' + - binary_operator: + + - parameter: '@s2' + - end_bracket: ) + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXEC + - bracketed: + - start_bracket: ( + - quoted_literal: '''select ''' + - binary_operator: + + - quoted_literal: '''123''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - bracketed: + - start_bracket: ( + - quoted_literal: '''USE AdventureWorks2022; SELECT BusinessEntityID, JobTitle FROM HumanResources.Employee;''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: uspGetEmployeeManagers + - expression: + - integer_literal: '6' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: uspGetEmployeeManagers + - parameter: '@EmployeeID' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '6' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: uspGetEmployeeManagers + - expression: + - parameter: '@EmployeeID' + - comma: ',' + - parameter: '@ManagerID' + - keyword: OUTPUT + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - execute_script_statement: + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: uspGetEmployeeManagers + - parameter: '@EmployeeID' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '6' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@CheckDate' + - keyword: AS + - data_type: + - keyword: DATETIME + - comparison_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: uspGetWhereUsedProductID + - expression: + - integer_literal: '819' + - comma: ',' + - expression: + - parameter: '@CheckDate' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@schemaname' + - keyword: AS + - data_type: + - data_type_identifier: sysname + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@tablename' + - keyword: AS + - data_type: + - data_type_identifier: sysname + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - bracketed: + - start_bracket: ( + - quoted_literal: '''ALTER INDEX ALL ON ''' + - binary_operator: + + - parameter: '@schemaname' + - binary_operator: + + - quoted_literal: '''.''' + - binary_operator: + + - parameter: '@tablename' + - binary_operator: + + - quoted_literal: ''' REBUILD;''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@retstat' + - keyword: AS + - data_type: + - keyword: INT + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - parameter: '@retstat' + - raw_comparison_operator: = + - object_reference: + - naked_identifier: SQLSERVER1 + - dot: . + - naked_identifier: AdventureWorks2022 + - dot: . + - naked_identifier: dbo + - dot: . + - naked_identifier: uspGetEmployeeManagers + - parameter: '@BusinessEntityID' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '6' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@proc_name' + - keyword: AS + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '30' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''sys.sp_who''' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - parameter: '@proc_name' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ProcTestDefaults + - parameter: '@p1' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - keyword: DEFAULT + - comma: ',' + - parameter: '@p2' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''D''' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ProcTestDefaults + - expression: + - keyword: DEFAULT + - comma: ',' + - expression: + - quoted_literal: '''H''' + - comma: ',' + - expression: + - keyword: DEFAULT + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ProcTestDefaults + - expression: + - keyword: DEFAULT + - comma: ',' + - expression: + - quoted_literal: '''I''' + - comma: ',' + - parameter: '@p3' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - keyword: DEFAULT + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - bracketed: + - start_bracket: ( + - quoted_literal: |- + 'CREATE TABLE AdventureWorks2022.dbo.SalesTbl + (SalesID INT, SalesName VARCHAR(10)); ' + - end_bracket: ) + - keyword: AT + - object_reference: + - naked_identifier: SeattleSales + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - bracketed: + - start_bracket: ( + - quoted_literal: '''SELECT * FROM scott.emp WHERE MGR = ?''' + - comma: ',' + - expression: + - integer_literal: '7902' + - end_bracket: ) + - keyword: AT + - object_reference: + - naked_identifier: ORACLE + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Proc_Test_Defaults + - parameter: '@p2' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''A''' + - keyword: WITH + - execute_option: + - keyword: RECOMPILE + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@returnstatus' + - keyword: AS + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '15' + - end_bracket: ) + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - parameter: '@returnstatus' + - raw_comparison_operator: = + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ufnGetSalesOrderStatusText + - parameter: '@Status' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '2' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - bracketed: + - start_bracket: ( + - quoted_literal: '''CREATE TABLE Sales.SalesTable (SalesID INT, SalesName VARCHAR(10));''' + - end_bracket: ) + - login_user_segment: + - keyword: AS + - keyword: USER + - raw_comparison_operator: = + - quoted_literal: '''User1''' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: uspGetEmployeeManagers + - expression: + - integer_literal: '16' + - keyword: WITH + - execute_option: + - keyword: RESULT + - keyword: SETS + - bracketed: + - start_bracket: ( + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[Reporting Level]' + - data_type: + - keyword: INT + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_reference: + - quoted_identifier: '[ID of Employee]' + - data_type: + - keyword: INT + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_reference: + - quoted_identifier: '[Employee First Name]' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_reference: + - quoted_identifier: '[Employee Last Name]' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_reference: + - quoted_identifier: '[Employee ID of Manager]' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: MAX + - end_bracket: ) + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_reference: + - quoted_identifier: '[Manager First Name]' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_reference: + - quoted_identifier: '[Manager Last Name]' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - keyword: NOT + - keyword: 'NULL' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ProductList + - expression: + - quoted_literal: '''%tire%''' + - keyword: WITH + - execute_option: + - keyword: RESULT + - keyword: SETS + - bracketed: + - start_bracket: ( + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: ProductID + - data_type: + - keyword: INT + - comma: ',' + - column_reference: + - quoted_identifier: '[Name]' + - data_type: + - data_type_identifier: NAME + - comma: ',' + - column_reference: + - naked_identifier: ListPrice + - data_type: + - keyword: MONEY + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[Name]' + - data_type: + - data_type_identifier: NAME + - comma: ',' + - column_reference: + - naked_identifier: NumberOfOrders + - data_type: + - keyword: INT + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - bracketed: + - start_bracket: ( + - quoted_literal: '''SELECT @@SERVERNAME''' + - end_bracket: ) + - keyword: AT + - keyword: DATA_SOURCE + - object_reference: + - naked_identifier: my_sql_server + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/fetch_cursor_statement.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/fetch_cursor_statement.sql new file mode 100644 index 000000000..fe9339409 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/fetch_cursor_statement.sql @@ -0,0 +1,98 @@ +-- Using FETCH in a simple cursor +USE ADVENTUREWORKS2022; +GO +DECLARE CONTACT_CURSOR CURSOR FOR +SELECT LASTNAME FROM PERSON.PERSON +WHERE LASTNAME LIKE 'B%' +ORDER BY LASTNAME; + +OPEN CONTACT_CURSOR; + +-- Perform the first fetch. +FETCH NEXT FROM CONTACT_CURSOR; + +-- Check @@FETCH_STATUS to see if there are any more rows to fetch. +WHILE @@FETCH_STATUS = 0 + BEGIN + -- This is executed as long as the previous fetch succeeds. + FETCH NEXT FROM CONTACT_CURSOR; + END + +CLOSE CONTACT_CURSOR; +DEALLOCATE CONTACT_CURSOR; +GO + +-- Using FETCH to store values in variables +USE ADVENTUREWORKS2022; +GO +-- Declare the variables to store the values returned by FETCH. +DECLARE @LastName VARCHAR(50), @FirstName VARCHAR(50); + +DECLARE CONTACT_CURSOR CURSOR FOR +SELECT + LASTNAME, + FIRSTNAME +FROM PERSON.PERSON +WHERE LASTNAME LIKE 'B%' +ORDER BY LASTNAME, FIRSTNAME; + +OPEN CONTACT_CURSOR; + +-- Perform the first fetch and store the values in variables. +-- Note: The variables are in the same order as the columns +-- in the SELECT statement. + +FETCH NEXT FROM CONTACT_CURSOR +INTO @LastName, @FirstName; + +-- Check @@FETCH_STATUS to see if there are any more rows to fetch. +WHILE @@FETCH_STATUS = 0 + BEGIN + + -- Concatenate and display the current values in the variables. + PRINT 'Contact Name: ' + @FirstName + ' ' + @LastName + + -- This is executed as long as the previous fetch succeeds. + FETCH NEXT FROM CONTACT_CURSOR + INTO @LastName, @FirstName; + END + +CLOSE CONTACT_CURSOR; +DEALLOCATE CONTACT_CURSOR; +GO + +-- Declaring a SCROLL cursor and using the other FETCH options +USE ADVENTUREWORKS2022; +GO +-- Execute the SELECT statement alone to show the +-- full result set that is used by the cursor. +SELECT + LASTNAME, + FIRSTNAME +FROM PERSON.PERSON +ORDER BY LASTNAME, FIRSTNAME; + +-- Declare the cursor. +DECLARE @contact_cursor SCROLL CURSOR FOR +SELECT [LastName], [FirstName] FROM [Person].[Person] +ORDER BY [LastName], [FirstName]; + +OPEN contact_cursor; + +-- Fetch the last row in the cursor. +FETCH LAST FROM contact_cursor; + +-- Fetch the row immediately prior to the current row in the cursor. +FETCH PRIOR FROM contact_cursor; + +-- Fetch the second row in the cursor. +FETCH ABSOLUTE 2 FROM contact_cursor; + +-- Fetch the row that is three rows after the current row. +FETCH RELATIVE 3 FROM contact_cursor; + +-- Fetch the row that is two rows prior to the current row. +FETCH RELATIVE -2 FROM contact_cursor; + +CLOSE contact_cursor; +DEALLOCATE contact_cursor; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/fetch_cursor_statement.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/fetch_cursor_statement.yml new file mode 100644 index 000000000..c97d27448 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/fetch_cursor_statement.yml @@ -0,0 +1,354 @@ +file: +- batch: + - statement: + - use_statement: + - keyword: USE + - database_reference: + - naked_identifier: ADVENTUREWORKS2022 + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - naked_identifier: CONTACT_CURSOR + - cursor_definition: + - keyword: CURSOR + - keyword: FOR + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: LASTNAME + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: PERSON + - dot: . + - naked_identifier: PERSON + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: LASTNAME + - keyword: LIKE + - quoted_literal: '''B%''' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: LASTNAME + - statement_terminator: ; + - statement: + - open_cursor_statement: + - keyword: OPEN + - naked_identifier: CONTACT_CURSOR + - statement_terminator: ; + - statement: + - fetch_cursor_statement: + - keyword: FETCH + - keyword: NEXT + - keyword: FROM + - naked_identifier: CONTACT_CURSOR + - statement_terminator: ; + - statement: + - while_statement: + - keyword: WHILE + - expression: + - system_variable: '@@FETCH_STATUS' + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '0' + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - fetch_cursor_statement: + - keyword: FETCH + - keyword: NEXT + - keyword: FROM + - naked_identifier: CONTACT_CURSOR + - statement_terminator: ; + - keyword: END + - statement: + - close_cursor_statement: + - keyword: CLOSE + - naked_identifier: CONTACT_CURSOR + - statement_terminator: ; + - statement: + - deallocate_cursor_statement: + - keyword: DEALLOCATE + - naked_identifier: CONTACT_CURSOR + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - use_statement: + - keyword: USE + - database_reference: + - naked_identifier: ADVENTUREWORKS2022 + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@LastName' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - comma: ',' + - parameter: '@FirstName' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - naked_identifier: CONTACT_CURSOR + - cursor_definition: + - keyword: CURSOR + - keyword: FOR + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: LASTNAME + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: FIRSTNAME + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: PERSON + - dot: . + - naked_identifier: PERSON + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: LASTNAME + - keyword: LIKE + - quoted_literal: '''B%''' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: LASTNAME + - comma: ',' + - column_reference: + - naked_identifier: FIRSTNAME + - statement_terminator: ; + - statement: + - open_cursor_statement: + - keyword: OPEN + - naked_identifier: CONTACT_CURSOR + - statement_terminator: ; + - statement: + - fetch_cursor_statement: + - keyword: FETCH + - keyword: NEXT + - keyword: FROM + - naked_identifier: CONTACT_CURSOR + - keyword: INTO + - parameter: '@LastName' + - comma: ',' + - parameter: '@FirstName' + - statement_terminator: ; + - statement: + - while_statement: + - keyword: WHILE + - expression: + - system_variable: '@@FETCH_STATUS' + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '0' + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - print_statement: + - keyword: PRINT + - expression: + - quoted_literal: '''Contact Name: ''' + - binary_operator: + + - parameter: '@FirstName' + - binary_operator: + + - quoted_literal: ''' ''' + - binary_operator: + + - parameter: '@LastName' + - statement: + - fetch_cursor_statement: + - keyword: FETCH + - keyword: NEXT + - keyword: FROM + - naked_identifier: CONTACT_CURSOR + - keyword: INTO + - parameter: '@LastName' + - comma: ',' + - parameter: '@FirstName' + - statement_terminator: ; + - keyword: END + - statement: + - close_cursor_statement: + - keyword: CLOSE + - naked_identifier: CONTACT_CURSOR + - statement_terminator: ; + - statement: + - deallocate_cursor_statement: + - keyword: DEALLOCATE + - naked_identifier: CONTACT_CURSOR + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - use_statement: + - keyword: USE + - database_reference: + - naked_identifier: ADVENTUREWORKS2022 + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: LASTNAME + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: FIRSTNAME + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: PERSON + - dot: . + - naked_identifier: PERSON + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: LASTNAME + - comma: ',' + - column_reference: + - naked_identifier: FIRSTNAME + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@contact_cursor' + - keyword: SCROLL + - keyword: CURSOR + - keyword: FOR + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '[LastName]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[FirstName]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '[Person]' + - dot: . + - quoted_identifier: '[Person]' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - quoted_identifier: '[LastName]' + - comma: ',' + - column_reference: + - quoted_identifier: '[FirstName]' + - statement_terminator: ; + - statement: + - open_cursor_statement: + - keyword: OPEN + - naked_identifier: contact_cursor + - statement_terminator: ; + - statement: + - fetch_cursor_statement: + - keyword: FETCH + - keyword: LAST + - keyword: FROM + - naked_identifier: contact_cursor + - statement_terminator: ; + - statement: + - fetch_cursor_statement: + - keyword: FETCH + - keyword: PRIOR + - keyword: FROM + - naked_identifier: contact_cursor + - statement_terminator: ; + - statement: + - fetch_cursor_statement: + - keyword: FETCH + - keyword: ABSOLUTE + - numeric_literal: '2' + - keyword: FROM + - naked_identifier: contact_cursor + - statement_terminator: ; + - statement: + - fetch_cursor_statement: + - keyword: FETCH + - keyword: RELATIVE + - numeric_literal: '3' + - keyword: FROM + - naked_identifier: contact_cursor + - statement_terminator: ; + - statement: + - fetch_cursor_statement: + - keyword: FETCH + - keyword: RELATIVE + - sign_indicator: '-' + - numeric_literal: '2' + - keyword: FROM + - naked_identifier: contact_cursor + - statement_terminator: ; + - statement: + - close_cursor_statement: + - keyword: CLOSE + - naked_identifier: contact_cursor + - statement_terminator: ; + - statement: + - deallocate_cursor_statement: + - keyword: DEALLOCATE + - naked_identifier: contact_cursor + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_default_params.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_default_params.sql new file mode 100644 index 000000000..b02046a82 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_default_params.sql @@ -0,0 +1,6 @@ +create or alter procedure name + @param1 nvarchar(10) = 'test', + @param2 int = 21 +as begin + return 1; +end diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_default_params.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_default_params.yml new file mode 100644 index 000000000..8bfd73cbc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_default_params.yml @@ -0,0 +1,44 @@ +file: +- batch: + - statement: + - create_procedure_statement: + - keyword: create + - keyword: or + - keyword: alter + - keyword: procedure + - object_reference: + - naked_identifier: name + - procedure_parameter_list: + - parameter: '@param1' + - data_type: + - keyword: nvarchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''test''' + - comma: ',' + - parameter: '@param2' + - data_type: + - keyword: int + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '21' + - keyword: as + - procedure_statement: + - statement: + - begin_end_block: + - keyword: begin + - statement: + - return_segment: + - keyword: return + - expression: + - integer_literal: '1' + - statement_terminator: ; + - keyword: end diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_no_return.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_no_return.sql new file mode 100644 index 000000000..c16c48867 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_no_return.sql @@ -0,0 +1,14 @@ +CREATE PROCEDURE findjobs @nm sysname = NULL +AS +IF @nm IS NULL + BEGIN + PRINT 'You must give a user name' + RETURN + END +ELSE + BEGIN + SELECT o.name, o.id, o.uid + FROM sysobjects o INNER JOIN master..syslogins l + ON o.uid = l.sid + WHERE l.name = @nm + END; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_no_return.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_no_return.yml new file mode 100644 index 000000000..07146e876 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_no_return.yml @@ -0,0 +1,109 @@ +file: +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - object_reference: + - naked_identifier: findjobs + - procedure_parameter_list: + - parameter: '@nm' + - data_type: + - data_type_identifier: sysname + - comparison_operator: + - raw_comparison_operator: = + - expression: + - null_literal: 'NULL' + - keyword: AS + - procedure_statement: + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - parameter: '@nm' + - keyword: IS + - null_literal: 'NULL' + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - print_statement: + - keyword: PRINT + - expression: + - quoted_literal: '''You must give a user name''' + - statement: + - return_segment: + - keyword: RETURN + - keyword: END + - keyword: ELSE + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: o + - dot: . + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: o + - dot: . + - naked_identifier: id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: o + - dot: . + - naked_identifier: uid + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sysobjects + - alias_expression: + - naked_identifier: o + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: master + - dot: . + - dot: . + - naked_identifier: syslogins + - alias_expression: + - naked_identifier: l + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: o + - dot: . + - naked_identifier: uid + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: l + - dot: . + - naked_identifier: sid + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: l + - dot: . + - naked_identifier: name + - comparison_operator: + - raw_comparison_operator: = + - parameter: '@nm' + - keyword: END + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_with_variable.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_with_variable.sql new file mode 100644 index 000000000..e0cee16d6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_with_variable.sql @@ -0,0 +1,8 @@ +CREATE OR ALTER FUNCTION [dbo].[CONVERT_ISO_WEEK_TO_UNIX] (@year INT, @week INT) +RETURNS BIGINT +AS + BEGIN + DECLARE @result BIGINT + SET @result=4 + RETURN @result + @year + @week + END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_with_variable.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_with_variable.yml new file mode 100644 index 000000000..16d3601db --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/function_with_variable.yml @@ -0,0 +1,55 @@ +file: +- batch: + - statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: FUNCTION + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[CONVERT_ISO_WEEK_TO_UNIX]' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@year' + - data_type: + - keyword: INT + - comma: ',' + - parameter: '@week' + - data_type: + - keyword: INT + - end_bracket: ) + - keyword: RETURNS + - data_type: + - keyword: BIGINT + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@result' + - data_type: + - keyword: BIGINT + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@result' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '4' + - statement: + - return_segment: + - keyword: RETURN + - expression: + - parameter: '@result' + - binary_operator: + + - parameter: '@year' + - binary_operator: + + - parameter: '@week' + - keyword: END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_a.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_a.sql new file mode 100644 index 000000000..12bdf5f6c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_a.sql @@ -0,0 +1,47 @@ +SELECT + DATE(t) AS t_date, + ROUND(b, 2) AS b_round, + LEFT(RIGHT(s, 5), LEN(s + 6)) AS compound, + DATEADD(month, -1, column1) AS column1_lastmonth, + convert(varchar, tbl_b.column1, 23) AS column1_varchar +FROM tbl_b +GO + +CREATE FUNCTION dbo.RandDate +( +@admit DATE +) +RETURNS TABLE +AS + RETURN +( + SELECT @admit + FROM dbo.[RandomDate] +); +GO + +CREATE FUNCTION dbo.no_paramters() RETURNS INT AS +BEGIN + RETURN 2; +END + +GO + +/* +SQLFluff should parse this FROM as a keyword and not as a function name + +*/ +SELECT a.* +FROM +( + SELECT + FIN + FROM enc +) AS a +LEFT JOIN b +ON a.FIN = b.FIN +WHERE b.FIN IS NULL + +; + +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_a.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_a.yml new file mode 100644 index 000000000..89ed54a25 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_a.yml @@ -0,0 +1,280 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: t + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: t_date + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: ROUND + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: b + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: b_round + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: LEFT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - keyword: RIGHT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: s + - comma: ',' + - expression: + - integer_literal: '5' + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: LEN + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: s + - binary_operator: + + - integer_literal: '6' + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: compound + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEADD + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: month + - comma: ',' + - expression: + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '1' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: column1 + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: column1_lastmonth + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: convert + - function_contents: + - bracketed: + - start_bracket: ( + - data_type: + - keyword: varchar + - comma: ',' + - expression: + - column_reference: + - naked_identifier: tbl_b + - dot: . + - naked_identifier: column1 + - comma: ',' + - numeric_literal: '23' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: column1_varchar + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl_b + - go_statement: + - keyword: GO +- batch: + - statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: RandDate + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@admit' + - data_type: + - keyword: DATE + - end_bracket: ) + - keyword: RETURNS + - data_type: + - keyword: TABLE + - keyword: AS + - procedure_statement: + - statement: + - return_segment: + - keyword: RETURN + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameter: '@admit' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - quoted_identifier: '[RandomDate]' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: no_paramters + - function_parameter_list: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: RETURNS + - data_type: + - keyword: INT + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - return_segment: + - keyword: RETURN + - expression: + - integer_literal: '2' + - statement_terminator: ; + - keyword: END + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - naked_identifier: a + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: FIN + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: enc + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - join_clause: + - keyword: LEFT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: b + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: FIN + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: FIN + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: b + - dot: . + - naked_identifier: FIN + - keyword: IS + - null_literal: 'NULL' + - statement_terminator: ; + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_agg.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_agg.sql new file mode 100644 index 000000000..8461f005e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_agg.sql @@ -0,0 +1,13 @@ +SELECT + string_agg(t.v, '; ') within group (order by v) as column_name1 + ,PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY t.Rate) + OVER (PARTITION BY Name) AS MedianCont + ,PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY t.Rate) + OVER (PARTITION BY Name) AS MedianDisc +from + table1 t +group by + employee_id +HAVING MIN([ArrivalDt]) <= MAX([DischargeDt]) + +DROP TABLE #Mercury; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_agg.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_agg.yml new file mode 100644 index 000000000..1595240ce --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/functions_agg.yml @@ -0,0 +1,158 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: string_agg + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: v + - comma: ',' + - expression: + - quoted_literal: '''; ''' + - end_bracket: ) + - within_group_clause: + - keyword: within + - keyword: group + - bracketed: + - start_bracket: ( + - orderby_clause: + - keyword: order + - keyword: by + - column_reference: + - naked_identifier: v + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: column_name1 + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: PERCENTILE_CONT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.5' + - end_bracket: ) + - within_group_clause: + - keyword: WITHIN + - keyword: GROUP + - bracketed: + - start_bracket: ( + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: Rate + - end_bracket: ) + - keyword: OVER + - bracketed: + - start_bracket: ( + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - column_reference: + - naked_identifier: Name + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: MedianCont + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: PERCENTILE_DISC + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - numeric_literal: '0.5' + - end_bracket: ) + - within_group_clause: + - keyword: WITHIN + - keyword: GROUP + - bracketed: + - start_bracket: ( + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: Rate + - end_bracket: ) + - keyword: OVER + - bracketed: + - start_bracket: ( + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - column_reference: + - naked_identifier: Name + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: MedianDisc + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - alias_expression: + - naked_identifier: t + - groupby_clause: + - keyword: group + - keyword: by + - column_reference: + - naked_identifier: employee_id + - having_clause: + - keyword: HAVING + - expression: + - function: + - function_name: + - function_name_identifier: MIN + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '[ArrivalDt]' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: MAX + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '[DischargeDt]' + - end_bracket: ) + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - hash_identifier: '#Mercury' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/go_delimiters.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/go_delimiters.sql new file mode 100644 index 000000000..9a38ae24d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/go_delimiters.sql @@ -0,0 +1,8 @@ +-- It's possible to have a file starting with GO +GO +-- It's possible to have multiple GO between batches. +SELECT foo FROM bar GO GO +SELECT foo FROM bar GO +GO +GO +SELECT foo FROM bar GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/go_delimiters.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/go_delimiters.yml new file mode 100644 index 000000000..d1034b232 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/go_delimiters.yml @@ -0,0 +1,64 @@ +file: +- batch: + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: foo + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar + - go_statement: + - keyword: GO +- batch: + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: foo + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar + - go_statement: + - keyword: GO +- batch: + - go_statement: + - keyword: GO +- batch: + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: foo + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: bar + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/goto_statement.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/goto_statement.sql new file mode 100644 index 000000000..2fe68e4bb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/goto_statement.sql @@ -0,0 +1,3 @@ +GOTO Branch_Three; +Branch_Three: + RETURN diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/goto_statement.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/goto_statement.yml new file mode 100644 index 000000000..4c13fed2e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/goto_statement.yml @@ -0,0 +1,14 @@ +file: +- batch: + - statement: + - goto_statement: + - keyword: GOTO + - naked_identifier: Branch_Three + - statement_terminator: ; + - statement: + - label_segment: + - naked_identifier: Branch_Three + - colon: ':' + - statement: + - return_segment: + - keyword: RETURN diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/grant_deny_revoke.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/grant_deny_revoke.sql new file mode 100644 index 000000000..f36d55566 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/grant_deny_revoke.sql @@ -0,0 +1,38 @@ +GRANT SELECT ON OBJECT::Person.Address TO RosaQdM; +GO + +USE AdventureWorks2012; +GRANT EXECUTE ON OBJECT::HumanResources.uspUpdateEmployeeHireInfo + TO Recruiting11; +GO + +GRANT REFERENCES (BusinessEntityID) ON OBJECT::HumanResources.vEmployee + TO Wanida WITH GRANT OPTION; +GO + +GRANT SELECT ON Person.Address TO RosaQdM; +GO + +GRANT SELECT ON Person.Address TO [AdventureWorks2012\RosaQdM]; +GO + +CREATE ROLE newrole ; +GRANT EXECUTE ON dbo.uspGetBillOfMaterials TO newrole ; +GO + +GRANT SELECT ON SCHEMA :: Sales TO Vendors; +GO + +REVOKE SELECT ON SCHEMA :: Sales TO Vendors; +GO + +DENY SELECT ON OBJECT::Person.Address TO RosaQdM; +GO + +DENY EXECUTE ON OBJECT::HumanResources.uspUpdateEmployeeHireInfo + TO Recruiting11; +GO + +DENY REFERENCES (BusinessEntityID) ON OBJECT::HumanResources.vEmployee + TO Wanida CASCADE; +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/grant_deny_revoke.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/grant_deny_revoke.yml new file mode 100644 index 000000000..37858c0be --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/grant_deny_revoke.yml @@ -0,0 +1,216 @@ +file: +- batch: + - statement: + - access_statement: + - keyword: GRANT + - keyword: SELECT + - keyword: ON + - keyword: OBJECT + - casting_operator: '::' + - object_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: Address + - keyword: TO + - role_reference: + - naked_identifier: RosaQdM + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - use_statement: + - keyword: USE + - database_reference: + - naked_identifier: AdventureWorks2012 + - statement_terminator: ; + - statement: + - access_statement: + - keyword: GRANT + - keyword: EXECUTE + - keyword: ON + - keyword: OBJECT + - casting_operator: '::' + - object_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: uspUpdateEmployeeHireInfo + - keyword: TO + - role_reference: + - naked_identifier: Recruiting11 + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - access_statement: + - keyword: GRANT + - keyword: REFERENCES + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: BusinessEntityID + - end_bracket: ) + - keyword: ON + - keyword: OBJECT + - casting_operator: '::' + - object_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: vEmployee + - keyword: TO + - role_reference: + - naked_identifier: Wanida + - keyword: WITH + - keyword: GRANT + - keyword: OPTION + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - access_statement: + - keyword: GRANT + - keyword: SELECT + - keyword: ON + - object_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: Address + - keyword: TO + - role_reference: + - naked_identifier: RosaQdM + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - access_statement: + - keyword: GRANT + - keyword: SELECT + - keyword: ON + - object_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: Address + - keyword: TO + - role_reference: + - quoted_identifier: '[AdventureWorks2012\RosaQdM]' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_role_statement: + - keyword: CREATE + - keyword: ROLE + - role_reference: + - naked_identifier: newrole + - statement_terminator: ; + - statement: + - access_statement: + - keyword: GRANT + - keyword: EXECUTE + - keyword: ON + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: uspGetBillOfMaterials + - keyword: TO + - role_reference: + - naked_identifier: newrole + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - access_statement: + - keyword: GRANT + - keyword: SELECT + - keyword: ON + - keyword: SCHEMA + - casting_operator: '::' + - object_reference: + - naked_identifier: Sales + - keyword: TO + - role_reference: + - naked_identifier: Vendors + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - access_statement: + - keyword: REVOKE + - keyword: SELECT + - keyword: ON + - keyword: SCHEMA + - casting_operator: '::' + - object_reference: + - naked_identifier: Sales + - keyword: TO + - role_reference: + - naked_identifier: Vendors + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - access_statement: + - keyword: DENY + - keyword: SELECT + - keyword: ON + - keyword: OBJECT + - casting_operator: '::' + - object_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: Address + - keyword: TO + - role_reference: + - naked_identifier: RosaQdM + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - access_statement: + - keyword: DENY + - keyword: EXECUTE + - keyword: ON + - keyword: OBJECT + - casting_operator: '::' + - object_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: uspUpdateEmployeeHireInfo + - keyword: TO + - role_reference: + - naked_identifier: Recruiting11 + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - access_statement: + - keyword: DENY + - keyword: REFERENCES + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: BusinessEntityID + - end_bracket: ) + - keyword: ON + - keyword: OBJECT + - casting_operator: '::' + - object_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: vEmployee + - keyword: TO + - role_reference: + - naked_identifier: Wanida + - keyword: CASCADE + - statement_terminator: ; + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/group_by.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/group_by.sql new file mode 100644 index 000000000..663a13422 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/group_by.sql @@ -0,0 +1,16 @@ +CREATE TABLE #n +WITH (DISTRIBUTION = ROUND_ROBIN) +AS +( Select acto.ActionDTS + FROM Orders_Action acto +) + +SELECT + t.actiondts +FROM #n t +GROUP BY t.ActionDTS; + +DROP TABLE #n; + +SELECT st, count(*), count(DISTINCT id) FROM #3 +GROUP BY st WITH ROLLUP; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/group_by.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/group_by.yml new file mode 100644 index 000000000..e9620693e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/group_by.yml @@ -0,0 +1,118 @@ +file: +- batch: + - statement: + - create_table_as_select_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - hash_identifier: '#n' + - table_distribution_index_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_distribution_clause: + - keyword: DISTRIBUTION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ROUND_ROBIN + - end_bracket: ) + - keyword: AS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: Select + - select_clause_element: + - column_reference: + - naked_identifier: acto + - dot: . + - naked_identifier: ActionDTS + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Orders_Action + - alias_expression: + - naked_identifier: acto + - end_bracket: ) + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: actiondts + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - hash_identifier: '#n' + - alias_expression: + - naked_identifier: t + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: ActionDTS + - statement_terminator: ; + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - hash_identifier: '#n' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: st + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: count + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: count + - function_contents: + - bracketed: + - start_bracket: ( + - keyword: DISTINCT + - expression: + - column_reference: + - naked_identifier: id + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - hash_identifier: '#3' + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: st + - with_rollup_clause: + - keyword: WITH + - keyword: ROLLUP + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/hints.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/hints.sql new file mode 100644 index 000000000..30ee2ebb1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/hints.sql @@ -0,0 +1,112 @@ +SELECT * +FROM Sales.Customer AS c +INNER JOIN Sales.CustomerAddress AS ca ON c.CustomerID = ca.CustomerID +WHERE TerritoryID = 5 +OPTION (MERGE JOIN); +GO + +CREATE PROCEDURE dbo.RetrievePersonAddress +@city_name NVARCHAR(30), + @postal_code NVARCHAR(15) +AS +SELECT * FROM Person.Address +WHERE City = @city_name AND PostalCode = @postal_code +OPTION ( OPTIMIZE FOR (@city_name = 'Seattle', @postal_code UNKNOWN) ); +GO + +--Creates an infinite loop +WITH cte (CustomerID, PersonID, StoreID) AS +( + SELECT CustomerID, PersonID, StoreID + FROM Sales.Customer + WHERE PersonID IS NOT NULL + UNION ALL + SELECT cte.CustomerID, cte.PersonID, cte.StoreID + FROM cte + JOIN Sales.Customer AS e + ON cte.PersonID = e.CustomerID +) +--Uses MAXRECURSION to limit the recursive levels to 2 +SELECT CustomerID, PersonID, StoreID +FROM cte +OPTION (MAXRECURSION 2); +GO + +SELECT * +FROM HumanResources.Employee AS e1 +UNION +SELECT * +FROM HumanResources.Employee AS e2 +OPTION (MERGE UNION); +GO + +SELECT ProductID, OrderQty, SUM(LineTotal) AS Total +FROM Sales.SalesOrderDetail +WHERE UnitPrice < 5 +GROUP BY ProductID, OrderQty +ORDER BY ProductID, OrderQty +OPTION (HASH GROUP, FAST 10); +GO + +SELECT ProductID, OrderQty, SUM(LineTotal) AS Total +FROM Sales.SalesOrderDetail +WHERE UnitPrice < 5 +GROUP BY ProductID, OrderQty +ORDER BY ProductID, OrderQty +OPTION (MAXDOP 2); +GO + +SELECT * FROM Person.Address +WHERE City = 'SEATTLE' AND PostalCode = 98104 +OPTION (RECOMPILE, USE HINT ('ASSUME_MIN_SELECTIVITY_FOR_FILTER_ESTIMATES', 'DISABLE_PARAMETER_SNIFFING')); +GO + +SELECT * FROM Person.Address +WHERE City = 'SEATTLE' AND PostalCode = 98104 +OPTION (QUERYTRACEON 4199); +GO + +SELECT * FROM Person.Address +WHERE City = 'SEATTLE' AND PostalCode = 98104 +OPTION (QUERYTRACEON 4199, QUERYTRACEON 4137); +GO + +UPDATE Production.Product +WITH (TABLOCK) +SET ListPrice = ListPrice * 1.10 +WHERE ProductNumber LIKE 'BK-%'; +GO + +SELECT * +FROM Sales.SalesOrderHeader AS h +INNER JOIN Sales.SalesOrderDetail AS d WITH (FORCESEEK) + ON h.SalesOrderID = d.SalesOrderID +WHERE h.TotalDue > 100 +AND (d.OrderQty > 5 OR d.LineTotal < 1000.00); +GO + +SELECT h.SalesOrderID, h.TotalDue, d.OrderQty +FROM Sales.SalesOrderHeader AS h + INNER JOIN Sales.SalesOrderDetail AS d + WITH (FORCESEEK (PK_SalesOrderDetail_SalesOrderID_SalesOrderDetailID (SalesOrderID))) + ON h.SalesOrderID = d.SalesOrderID +WHERE h.TotalDue > 100 +AND (d.OrderQty > 5 OR d.LineTotal < 1000.00); +GO + +SELECT h.SalesOrderID, h.TotalDue, d.OrderQty +FROM Sales.SalesOrderHeader AS h + INNER JOIN Sales.SalesOrderDetail AS d + WITH (FORCESCAN) + ON h.SalesOrderID = d.SalesOrderID +WHERE h.TotalDue > 100 +AND (d.OrderQty > 5 OR d.LineTotal < 1000.00); +GO + +SELECT ID +FROM dbo.tableX WITH(NOLOCK) +GO + +SELECT ID +FROM dbo.tableX (NOLOCK) +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/hints.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/hints.yml new file mode 100644 index 000000000..cd422f452 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/hints.yml @@ -0,0 +1,1023 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: Customer + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: c + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: CustomerAddress + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: ca + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: CustomerID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: ca + - dot: . + - naked_identifier: CustomerID + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: TerritoryID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '5' + - option_clause: + - keyword: OPTION + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: MERGE + - keyword: JOIN + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: RetrievePersonAddress + - procedure_parameter_list: + - parameter: '@city_name' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '30' + - end_bracket: ) + - comma: ',' + - parameter: '@postal_code' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '15' + - end_bracket: ) + - keyword: AS + - procedure_statement: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: Address + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: City + - comparison_operator: + - raw_comparison_operator: = + - parameter: '@city_name' + - binary_operator: AND + - column_reference: + - naked_identifier: PostalCode + - comparison_operator: + - raw_comparison_operator: = + - parameter: '@postal_code' + - option_clause: + - keyword: OPTION + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: OPTIMIZE + - keyword: FOR + - bracketed: + - start_bracket: ( + - parameter: '@city_name' + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Seattle''' + - comma: ',' + - parameter: '@postal_code' + - keyword: UNKNOWN + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - with_compound_statement: + - keyword: WITH + - common_table_expression: + - naked_identifier: cte + - cte_column_list: + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: CustomerID + - comma: ',' + - naked_identifier: PersonID + - comma: ',' + - naked_identifier: StoreID + - end_bracket: ) + - keyword: AS + - bracketed: + - start_bracket: ( + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: CustomerID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: PersonID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: StoreID + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: Customer + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: PersonID + - keyword: IS + - keyword: NOT + - null_literal: 'NULL' + - set_operator: + - keyword: UNION + - keyword: ALL + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: cte + - dot: . + - naked_identifier: CustomerID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: cte + - dot: . + - naked_identifier: PersonID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: cte + - dot: . + - naked_identifier: StoreID + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: cte + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: Customer + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: e + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: cte + - dot: . + - naked_identifier: PersonID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: e + - dot: . + - naked_identifier: CustomerID + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: CustomerID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: PersonID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: StoreID + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: cte + - option_clause: + - keyword: OPTION + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: MAXRECURSION + - numeric_literal: '2' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - set_expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: Employee + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: e1 + - set_operator: + - keyword: UNION + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: Employee + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: e2 + - option_clause: + - keyword: OPTION + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: MERGE + - keyword: UNION + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ProductID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: OrderQty + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: LineTotal + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Total + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderDetail + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: UnitPrice + - comparison_operator: + - raw_comparison_operator: < + - integer_literal: '5' + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: ProductID + - comma: ',' + - column_reference: + - naked_identifier: OrderQty + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: ProductID + - comma: ',' + - column_reference: + - naked_identifier: OrderQty + - option_clause: + - keyword: OPTION + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: HASH + - keyword: GROUP + - comma: ',' + - query_hint_segment: + - keyword: FAST + - numeric_literal: '10' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ProductID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: OrderQty + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: LineTotal + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Total + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderDetail + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: UnitPrice + - comparison_operator: + - raw_comparison_operator: < + - integer_literal: '5' + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: ProductID + - comma: ',' + - column_reference: + - naked_identifier: OrderQty + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: ProductID + - comma: ',' + - column_reference: + - naked_identifier: OrderQty + - option_clause: + - keyword: OPTION + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: MAXDOP + - numeric_literal: '2' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: Address + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: City + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''SEATTLE''' + - binary_operator: AND + - column_reference: + - naked_identifier: PostalCode + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '98104' + - option_clause: + - keyword: OPTION + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: RECOMPILE + - comma: ',' + - query_hint_segment: + - keyword: USE + - keyword: HINT + - bracketed: + - start_bracket: ( + - quoted_literal: '''ASSUME_MIN_SELECTIVITY_FOR_FILTER_ESTIMATES''' + - comma: ',' + - quoted_literal: '''DISABLE_PARAMETER_SNIFFING''' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: Address + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: City + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''SEATTLE''' + - binary_operator: AND + - column_reference: + - naked_identifier: PostalCode + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '98104' + - option_clause: + - keyword: OPTION + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: QUERYTRACEON + - numeric_literal: '4199' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: Address + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: City + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''SEATTLE''' + - binary_operator: AND + - column_reference: + - naked_identifier: PostalCode + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '98104' + - option_clause: + - keyword: OPTION + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: QUERYTRACEON + - numeric_literal: '4199' + - comma: ',' + - query_hint_segment: + - keyword: QUERYTRACEON + - numeric_literal: '4137' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: Product + - post_table_expression: + - keyword: WITH + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: TABLOCK + - end_bracket: ) + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: ListPrice + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: ListPrice + - binary_operator: '*' + - numeric_literal: '1.10' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ProductNumber + - keyword: LIKE + - quoted_literal: '''BK-%''' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderHeader + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: h + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderDetail + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: d + - post_table_expression: + - keyword: WITH + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: FORCESEEK + - end_bracket: ) + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: h + - dot: . + - naked_identifier: SalesOrderID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: SalesOrderID + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: h + - dot: . + - naked_identifier: TotalDue + - comparison_operator: + - raw_comparison_operator: '>' + - integer_literal: '100' + - binary_operator: AND + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: OrderQty + - comparison_operator: + - raw_comparison_operator: '>' + - integer_literal: '5' + - binary_operator: OR + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: LineTotal + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '1000.00' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: h + - dot: . + - naked_identifier: SalesOrderID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: h + - dot: . + - naked_identifier: TotalDue + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: OrderQty + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderHeader + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: h + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderDetail + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: d + - post_table_expression: + - keyword: WITH + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: FORCESEEK + - bracketed: + - start_bracket: ( + - index_reference: + - naked_identifier: PK_SalesOrderDetail_SalesOrderID_SalesOrderDetailID + - bracketed: + - start_bracket: ( + - naked_identifier: SalesOrderID + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: h + - dot: . + - naked_identifier: SalesOrderID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: SalesOrderID + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: h + - dot: . + - naked_identifier: TotalDue + - comparison_operator: + - raw_comparison_operator: '>' + - integer_literal: '100' + - binary_operator: AND + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: OrderQty + - comparison_operator: + - raw_comparison_operator: '>' + - integer_literal: '5' + - binary_operator: OR + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: LineTotal + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '1000.00' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: h + - dot: . + - naked_identifier: SalesOrderID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: h + - dot: . + - naked_identifier: TotalDue + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: OrderQty + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderHeader + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: h + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderDetail + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: d + - post_table_expression: + - keyword: WITH + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: FORCESCAN + - end_bracket: ) + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: h + - dot: . + - naked_identifier: SalesOrderID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: SalesOrderID + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: h + - dot: . + - naked_identifier: TotalDue + - comparison_operator: + - raw_comparison_operator: '>' + - integer_literal: '100' + - binary_operator: AND + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: OrderQty + - comparison_operator: + - raw_comparison_operator: '>' + - integer_literal: '5' + - binary_operator: OR + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: LineTotal + - comparison_operator: + - raw_comparison_operator: < + - numeric_literal: '1000.00' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ID + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: tableX + - post_table_expression: + - keyword: WITH + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: NOLOCK + - end_bracket: ) + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ID + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: tableX + - post_table_expression: + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: NOLOCK + - end_bracket: ) + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_hash_end.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_hash_end.sql deleted file mode 100644 index 7d9e00399..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_hash_end.sql +++ /dev/null @@ -1,11 +0,0 @@ --- SQL Server 2017+ allows # at the end of identifiers --- This test validates that the T-SQL dialect correctly parses these identifiers - --- Simple SELECT with # identifiers -SELECT orders#.id# FROM orders#; - --- Table alias with # -SELECT o#.total# FROM orders# AS o#; - --- Column alias with # -SELECT total AS amount# FROM orders#; \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_special_chars.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_special_chars.sql new file mode 100644 index 000000000..094f72887 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_special_chars.sql @@ -0,0 +1,30 @@ +-- Test special characters in T-SQL identifiers +-- According to Microsoft spec: +-- https://learn.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers +-- +-- First character: letter, underscore, @, or # +-- Subsequent characters: letters, numbers, @, $, #, underscore + +-- Variables with @ prefix can have $, #, _ in subsequent positions +DECLARE @variable INT = 1; +DECLARE @$variable INT = 2; +DECLARE @#variable INT = 3; +DECLARE @_variable INT = 4; +DECLARE @var$test INT = 5; +DECLARE @var#test INT = 6; +DECLARE @var_test INT = 7; + +-- Temp tables with # prefix can have @, $, _ in subsequent positions +CREATE TABLE #temp (id INT); +CREATE TABLE #$temp (id INT); +CREATE TABLE #@temp (id INT); +CREATE TABLE #_temp (id INT); +CREATE TABLE ##global (id INT); + +-- Regular identifiers can have @, $, # in subsequent positions +CREATE TABLE Table$name (Column@name INT, Column#test INT, Column_test INT); + +-- Using these identifiers in queries +SELECT @variable, @$variable, @#variable; +SELECT * FROM Table$name; +SELECT Column@name, Column#test FROM Table$name; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_special_chars.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_special_chars.yml new file mode 100644 index 000000000..6d52cb489 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/identifier_special_chars.yml @@ -0,0 +1,221 @@ +file: +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@variable' + - data_type: + - keyword: INT + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '1' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@$variable' + - data_type: + - keyword: INT + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '2' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@#variable' + - data_type: + - keyword: INT + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '3' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@_variable' + - data_type: + - keyword: INT + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '4' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@var$test' + - data_type: + - keyword: INT + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '5' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@var#test' + - data_type: + - keyword: INT + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '6' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@var_test' + - data_type: + - keyword: INT + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '7' + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - hash_identifier: '#temp' + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - keyword: INT + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - hash_identifier: '#$temp' + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - keyword: INT + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - hash_identifier: '#@temp' + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - keyword: INT + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - hash_identifier: '#_temp' + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - keyword: INT + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - hash_identifier: '##global' + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - keyword: INT + - end_bracket: ) + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: Table$name + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: Column@name + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: Column#test + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: Column_test + - data_type: + - keyword: INT + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameter: '@variable' + - comma: ',' + - select_clause_element: + - parameter: '@$variable' + - comma: ',' + - select_clause_element: + - parameter: '@#variable' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Table$name + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: Column@name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Column#test + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Table$name + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else.sql new file mode 100644 index 000000000..2c7035319 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else.sql @@ -0,0 +1,12 @@ +IF 1 <= (SELECT Weight from DimProduct WHERE ProductKey = 1) + SELECT ProductKey, EnglishDescription, Weight, 'This product is too heavy to ship and is only available for pickup.' + AS ShippingStatus + FROM DimProduct WHERE ProductKey = 1 +ELSE + SELECT ProductKey, EnglishDescription, Weight, 'This product is available for shipping or pickup.' + AS ShippingStatus + FROM DimProduct WHERE ProductKey = 1 + + +if exists (select * from #a union all select * from #b) + set @var = 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else.yml new file mode 100644 index 000000000..30024c485 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else.yml @@ -0,0 +1,161 @@ +file: +- batch: + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: Weight + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: DimProduct + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ProductKey + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - end_bracket: ) + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ProductKey + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: EnglishDescription + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Weight + - comma: ',' + - select_clause_element: + - quoted_literal: '''This product is too heavy to ship and is only available for pickup.''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: ShippingStatus + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: DimProduct + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ProductKey + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - keyword: ELSE + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ProductKey + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: EnglishDescription + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Weight + - comma: ',' + - select_clause_element: + - quoted_literal: '''This product is available for shipping or pickup.''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: ShippingStatus + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: DimProduct + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ProductKey + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - statement: + - if_then_statement: + - if_clause: + - keyword: if + - expression: + - keyword: exists + - bracketed: + - start_bracket: ( + - set_expression: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - hash_identifier: '#a' + - set_operator: + - keyword: union + - keyword: all + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - hash_identifier: '#b' + - end_bracket: ) + - statement: + - set_local_variable_segment: + - keyword: set + - parameter: '@var' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '1' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else_begin_end.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else_begin_end.sql new file mode 100644 index 000000000..93d51d3f3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else_begin_end.sql @@ -0,0 +1,12 @@ +IF 1 <= (SELECT Weight from DimProduct WHERE ProductKey = 1) + BEGIN + SELECT ProductKey, EnglishDescription, Weight, 'This product is too heavy to ship and is only available for pickup.' + AS ShippingStatus + FROM DimProduct WHERE ProductKey = 1 + END +ELSE + BEGIN + SELECT ProductKey, EnglishDescription, Weight, 'This product is available for shipping or pickup.' + AS ShippingStatus + FROM DimProduct WHERE ProductKey = 1 + END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else_begin_end.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else_begin_end.yml new file mode 100644 index 000000000..1f399e6d6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/if_else_begin_end.yml @@ -0,0 +1,119 @@ +file: +- batch: + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: Weight + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: DimProduct + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ProductKey + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - end_bracket: ) + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ProductKey + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: EnglishDescription + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Weight + - comma: ',' + - select_clause_element: + - quoted_literal: '''This product is too heavy to ship and is only available for pickup.''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: ShippingStatus + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: DimProduct + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ProductKey + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - keyword: END + - keyword: ELSE + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ProductKey + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: EnglishDescription + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Weight + - comma: ',' + - select_clause_element: + - quoted_literal: '''This product is available for shipping or pickup.''' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: ShippingStatus + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: DimProduct + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ProductKey + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - keyword: END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/ignore_nulls.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/ignore_nulls.sql new file mode 100644 index 000000000..b77721c8d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/ignore_nulls.sql @@ -0,0 +1,9 @@ +SELECT + FIRST_VALUE( + [entrypunt]) IGNORE NULLS + OVER + ( + PARTITION BY ([reisnummer]) + ORDER BY [reismutatie starttijdstip] + ) AS [entrypunt] +FROM [reizen] diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/ignore_nulls.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/ignore_nulls.yml new file mode 100644 index 000000000..a61a0b349 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/ignore_nulls.yml @@ -0,0 +1,49 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: FIRST_VALUE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '[entrypunt]' + - end_bracket: ) + - over_clause: + - keyword: IGNORE + - keyword: NULLS + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[reisnummer]' + - end_bracket: ) + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - quoted_identifier: '[reismutatie starttijdstip]' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[entrypunt]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '[reizen]' diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/implicit_alias_test.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/implicit_alias_test.sql deleted file mode 100644 index 852b725a1..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/implicit_alias_test.sql +++ /dev/null @@ -1,3 +0,0 @@ -SELECT - SUM(col1) implicit_alias -FROM table1 \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/inline_comments.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/inline_comments.sql deleted file mode 100644 index 3e8a31639..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/inline_comments.sql +++ /dev/null @@ -1,5 +0,0 @@ --- Test that # is NOT treated as inline comment in T-SQL --- Only -- should start inline comments - --- The following should parse correctly -SELECT column# FROM table#; \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_default.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_default.sql new file mode 100644 index 000000000..3a40a6ae9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_default.sql @@ -0,0 +1,3 @@ +-- Simple statement for setting default values +INSERT INTO mytable +DEFAULT VALUES; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_default.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_default.yml new file mode 100644 index 000000000..e743871a3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_default.yml @@ -0,0 +1,11 @@ +file: +- batch: + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: mytable + - keyword: DEFAULT + - keyword: VALUES + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_statement.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_statement.sql new file mode 100644 index 000000000..e0005477e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_statement.sql @@ -0,0 +1,57 @@ +INSERT INTO INTER.ECDC_CASES +( + [COUNTRY], + [COUNTRY_CODE], + [CONTINENT], + [POPULATION], + [INDICATOR], + [WEEKLY_COUNT], + [YEAR_WEEK], + [WEEK_START], + [WEEK_END], + [RATE_14_DAY], + [CUMULATIVE_COUNT], + [SOURCE] +) +SELECT + [COUNTRY], + [COUNTRY_CODE], + [CONTINENT], + CAST([POPULATION] AS BIGINT) AS [POPULATION], + [INDICATOR], + CAST([WEEKLY_COUNT] AS BIGINT) AS [WEEKLY_COUNT], + [YEAR_WEEK], + CAST([dbo].[CONVERT_ISO_WEEK_TO_DATETIME](LEFT(YEAR_WEEK,4),RIGHT(YEAR_WEEK,2)) AS DATE) AS [WEEK_START], + CAST([dbo].[WEEK_END]([dbo].[CONVERT_ISO_WEEK_TO_DATETIME](LEFT(YEAR_WEEK,4),RIGHT(YEAR_WEEK,2))) AS DATE ) AS [WEEK_END], + CAST([RATE_14_DAY] AS FLOAT) AS [RATE_14_DAY], + CAST([CUMULATIVE_COUNT] AS BIGINT) AS [CUMULATIVE_COUNT], + [SOURCE] +FROM + STAGE.ECDC_CASES +GO + +BEGIN + INSERT INTO HumanResources.NewEmployee + SELECT EmpID, LastName, FirstName, Phone, + Address, City, StateProvince, PostalCode, CurrentFlag + FROM EmployeeTemp; +END + +GO + +INSERT INTO HumanResources.NewEmployee + SELECT EmpID, LastName, FirstName, Phone, + Address, City, StateProvince, PostalCode, CurrentFlag + FROM EmployeeTemp; +GO + +INSERT INTO HumanResources.NewEmployee WITH(TABLOCK) +OUTPUT INSERTED.* INTO Results + EXEC FindEmployeesFunc @lastName = 'Picard' +GO + +INSERT HumanResources.NewEmployee + (LastName, FirstName) + values + ('Kirk', 'James') +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_statement.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_statement.yml new file mode 100644 index 000000000..c4bf18af2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_statement.yml @@ -0,0 +1,461 @@ +file: +- batch: + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: INTER + - dot: . + - naked_identifier: ECDC_CASES + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '[COUNTRY]' + - comma: ',' + - column_reference: + - quoted_identifier: '[COUNTRY_CODE]' + - comma: ',' + - column_reference: + - quoted_identifier: '[CONTINENT]' + - comma: ',' + - column_reference: + - quoted_identifier: '[POPULATION]' + - comma: ',' + - column_reference: + - quoted_identifier: '[INDICATOR]' + - comma: ',' + - column_reference: + - quoted_identifier: '[WEEKLY_COUNT]' + - comma: ',' + - column_reference: + - quoted_identifier: '[YEAR_WEEK]' + - comma: ',' + - column_reference: + - quoted_identifier: '[WEEK_START]' + - comma: ',' + - column_reference: + - quoted_identifier: '[WEEK_END]' + - comma: ',' + - column_reference: + - quoted_identifier: '[RATE_14_DAY]' + - comma: ',' + - column_reference: + - quoted_identifier: '[CUMULATIVE_COUNT]' + - comma: ',' + - column_reference: + - quoted_identifier: '[SOURCE]' + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '[COUNTRY]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[COUNTRY_CODE]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[CONTINENT]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '[POPULATION]' + - keyword: AS + - data_type: + - keyword: BIGINT + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[POPULATION]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[INDICATOR]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '[WEEKLY_COUNT]' + - keyword: AS + - data_type: + - keyword: BIGINT + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[WEEKLY_COUNT]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[YEAR_WEEK]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - quoted_identifier: '[dbo]' + - dot: . + - function_name_identifier: '[CONVERT_ISO_WEEK_TO_DATETIME]' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - keyword: LEFT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: YEAR_WEEK + - comma: ',' + - expression: + - integer_literal: '4' + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - keyword: RIGHT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: YEAR_WEEK + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - data_type: + - keyword: DATE + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[WEEK_START]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - quoted_identifier: '[dbo]' + - dot: . + - function_name_identifier: '[WEEK_END]' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - quoted_identifier: '[dbo]' + - dot: . + - function_name_identifier: '[CONVERT_ISO_WEEK_TO_DATETIME]' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - keyword: LEFT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: YEAR_WEEK + - comma: ',' + - expression: + - integer_literal: '4' + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - keyword: RIGHT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: YEAR_WEEK + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - data_type: + - keyword: DATE + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[WEEK_END]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '[RATE_14_DAY]' + - keyword: AS + - data_type: + - keyword: FLOAT + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[RATE_14_DAY]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '[CUMULATIVE_COUNT]' + - keyword: AS + - data_type: + - keyword: BIGINT + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[CUMULATIVE_COUNT]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[SOURCE]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: STAGE + - dot: . + - naked_identifier: ECDC_CASES + - go_statement: + - keyword: GO +- batch: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: NewEmployee + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: EmpID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: LastName + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: FirstName + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Phone + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Address + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: City + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: StateProvince + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: PostalCode + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: CurrentFlag + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: EmployeeTemp + - statement_terminator: ; + - keyword: END + - go_statement: + - keyword: GO +- batch: + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: NewEmployee + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: EmpID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: LastName + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: FirstName + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Phone + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Address + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: City + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: StateProvince + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: PostalCode + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: CurrentFlag + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: EmployeeTemp + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: NewEmployee + - post_table_expression: + - keyword: WITH + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: TABLOCK + - end_bracket: ) + - output_clause: + - keyword: OUTPUT + - keyword: INSERTED + - dot: . + - wildcard_identifier: + - star: '*' + - keyword: INTO + - table_reference: + - naked_identifier: Results + - execute_script_statement: + - keyword: EXEC + - object_reference: + - naked_identifier: FindEmployeesFunc + - parameter: '@lastName' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''Picard''' + - go_statement: + - keyword: GO +- batch: + - statement: + - insert_statement: + - keyword: INSERT + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: NewEmployee + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: LastName + - comma: ',' + - column_reference: + - naked_identifier: FirstName + - end_bracket: ) + - values_clause: + - keyword: values + - bracketed: + - start_bracket: ( + - quoted_literal: '''Kirk''' + - comma: ',' + - quoted_literal: '''James''' + - end_bracket: ) + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_with_identity_insert.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_with_identity_insert.sql new file mode 100644 index 000000000..9b67bb1c3 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_with_identity_insert.sql @@ -0,0 +1,8 @@ +SET IDENTITY_INSERT someTable ON; + +INSERT INTO someTable + (ID, Value) +VALUES + (1, 2); + +SET IDENTITY_INSERT someTable OFF; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_with_identity_insert.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_with_identity_insert.yml new file mode 100644 index 000000000..bbca5f5fc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/insert_with_identity_insert.yml @@ -0,0 +1,41 @@ +file: +- batch: + - statement: + - set_segment: + - keyword: SET + - keyword: IDENTITY_INSERT + - table_reference: + - naked_identifier: someTable + - keyword: ON + - statement_terminator: ; + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: someTable + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: ID + - comma: ',' + - column_reference: + - naked_identifier: Value + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - integer_literal: '1' + - comma: ',' + - integer_literal: '2' + - end_bracket: ) + - statement_terminator: ; + - statement: + - set_segment: + - keyword: SET + - keyword: IDENTITY_INSERT + - table_reference: + - naked_identifier: someTable + - keyword: OFF + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/join_hints.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/join_hints.sql new file mode 100644 index 000000000..e9f9de743 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/join_hints.sql @@ -0,0 +1,17 @@ +-- HASH JOIN +SELECT table1.col +FROM table1 +INNER HASH JOIN table2 + ON table1.col = table2.col; + +-- OUTER MERGE JOIN +SELECT table1.col +FROM table1 +FULL OUTER MERGE JOIN table2 + ON table1.col = table2.col; + +-- LEFT LOOP JOIN +SELECT table1.col +FROM table1 +LEFT LOOP JOIN table2 + ON table1.col = table2.col; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/join_hints.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/join_hints.yml new file mode 100644 index 000000000..27327f791 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/join_hints.yml @@ -0,0 +1,117 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - join_clause: + - keyword: INNER + - keyword: HASH + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: col + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: table2 + - dot: . + - naked_identifier: col + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - join_clause: + - keyword: FULL + - keyword: OUTER + - keyword: MERGE + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: col + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: table2 + - dot: . + - naked_identifier: col + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: col + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - join_clause: + - keyword: LEFT + - keyword: LOOP + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: col + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: table2 + - dot: . + - naked_identifier: col + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/json_functions.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/json_functions.sql new file mode 100644 index 000000000..1727b4b9a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/json_functions.sql @@ -0,0 +1,31 @@ +SELECT JSON_OBJECT(ABSENT ON NULL); + +SELECT JSON_ARRAY('a', 1, 'b', 2); + +SELECT JSON_ARRAY('a', 1, NULL, 2, NULL ON NULL); + +SELECT JSON_OBJECT('name': 'value', 'new': 1); + +SELECT JSON_OBJECT('name': 'value', 'type': NULL ABSENT ON NULL) + +SELECT JSON_OBJECT('name': 'value', 'type': JSON_ARRAY(1, 2)) + +SELECT JSON_OBJECT('name': 'value', 'type': JSON_OBJECT('type_id': 1, 'name': 'a')) + +DECLARE @id_key nvarchar(10) = N'id', @id_value nvarchar(64) = NEWID(); +SELECT JSON_OBJECT('user_name': USER_NAME(), @id_key: @id_value, 'sid': (SELECT @@SPID)); + +SELECT s.session_id, JSON_OBJECT('security_id': s.security_id, 'login': s.login_name, 'status': s.status) AS info +FROM sys.dm_exec_sessions AS s +WHERE s.is_user_process = 1; + +SELECT JSON_ARRAY('a', JSON_OBJECT('name': 'value', 'type': 1)); + +SELECT JSON_ARRAY('a', JSON_OBJECT('name': 'value', 'type': 1), JSON_ARRAY(1, NULL, 2 NULL ON NULL)); + +DECLARE @id_value nvarchar(64) = NEWID(); +SELECT JSON_ARRAY(1, @id_value, (SELECT @@SPID)); + +SELECT s.session_id, JSON_ARRAY(s.host_name, s.program_name, s.client_interface_name) +FROM sys.dm_exec_sessions AS s +WHERE s.is_user_process = 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/json_functions.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/json_functions.yml new file mode 100644 index 000000000..799786796 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/json_functions.yml @@ -0,0 +1,500 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: JSON_OBJECT + - function_contents: + - bracketed: + - start_bracket: ( + - keyword: ABSENT + - keyword: ON + - keyword: 'NULL' + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: JSON_ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''a''' + - comma: ',' + - expression: + - integer_literal: '1' + - comma: ',' + - expression: + - quoted_literal: '''b''' + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: JSON_ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - quoted_literal: '''a''' + - comma: ',' + - numeric_literal: '1' + - comma: ',' + - keyword: 'NULL' + - comma: ',' + - numeric_literal: '2' + - comma: ',' + - keyword: 'NULL' + - keyword: ON + - keyword: 'NULL' + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: JSON_OBJECT + - function_contents: + - bracketed: + - start_bracket: ( + - quoted_literal: '''name''' + - colon: ':' + - quoted_literal: '''value''' + - comma: ',' + - quoted_literal: '''new''' + - colon: ':' + - integer_literal: '1' + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: JSON_OBJECT + - function_contents: + - bracketed: + - start_bracket: ( + - quoted_literal: '''name''' + - colon: ':' + - quoted_literal: '''value''' + - comma: ',' + - quoted_literal: '''type''' + - colon: ':' + - null_literal: 'NULL' + - keyword: ABSENT + - keyword: ON + - keyword: 'NULL' + - end_bracket: ) + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: JSON_OBJECT + - function_contents: + - bracketed: + - start_bracket: ( + - quoted_literal: '''name''' + - colon: ':' + - quoted_literal: '''value''' + - comma: ',' + - quoted_literal: '''type''' + - colon: ':' + - function: + - function_name: + - function_name_identifier: JSON_ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '1' + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - end_bracket: ) + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: JSON_OBJECT + - function_contents: + - bracketed: + - start_bracket: ( + - quoted_literal: '''name''' + - colon: ':' + - quoted_literal: '''value''' + - comma: ',' + - quoted_literal: '''type''' + - colon: ':' + - function: + - function_name: + - keyword: JSON_OBJECT + - function_contents: + - bracketed: + - start_bracket: ( + - quoted_literal: '''type_id''' + - colon: ':' + - integer_literal: '1' + - comma: ',' + - quoted_literal: '''name''' + - colon: ':' + - quoted_literal: '''a''' + - end_bracket: ) + - end_bracket: ) + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@id_key' + - data_type: + - keyword: nvarchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: N'id' + - comma: ',' + - parameter: '@id_value' + - data_type: + - keyword: nvarchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '64' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: NEWID + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: JSON_OBJECT + - function_contents: + - bracketed: + - start_bracket: ( + - quoted_literal: '''user_name''' + - colon: ':' + - function: + - function_name: + - function_name_identifier: USER_NAME + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comma: ',' + - parameter: '@id_key' + - colon: ':' + - parameter: '@id_value' + - comma: ',' + - quoted_literal: '''sid''' + - colon: ':' + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - system_variable: '@@SPID' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: session_id + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: JSON_OBJECT + - function_contents: + - bracketed: + - start_bracket: ( + - quoted_literal: '''security_id''' + - colon: ':' + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: security_id + - comma: ',' + - quoted_literal: '''login''' + - colon: ':' + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: login_name + - comma: ',' + - quoted_literal: '''status''' + - colon: ':' + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: status + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: info + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sys + - dot: . + - naked_identifier: dm_exec_sessions + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: s + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: is_user_process + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: JSON_ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''a''' + - comma: ',' + - expression: + - function: + - function_name: + - keyword: JSON_OBJECT + - function_contents: + - bracketed: + - start_bracket: ( + - quoted_literal: '''name''' + - colon: ':' + - quoted_literal: '''value''' + - comma: ',' + - quoted_literal: '''type''' + - colon: ':' + - integer_literal: '1' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: JSON_ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''a''' + - comma: ',' + - expression: + - function: + - function_name: + - keyword: JSON_OBJECT + - function_contents: + - bracketed: + - start_bracket: ( + - quoted_literal: '''name''' + - colon: ':' + - quoted_literal: '''value''' + - comma: ',' + - quoted_literal: '''type''' + - colon: ':' + - integer_literal: '1' + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - keyword: JSON_ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - numeric_literal: '1' + - comma: ',' + - keyword: 'NULL' + - comma: ',' + - numeric_literal: '2' + - keyword: 'NULL' + - keyword: ON + - keyword: 'NULL' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@id_value' + - data_type: + - keyword: nvarchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '64' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: NEWID + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: JSON_ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '1' + - comma: ',' + - expression: + - parameter: '@id_value' + - comma: ',' + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - system_variable: '@@SPID' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: session_id + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: JSON_ARRAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: host_name + - comma: ',' + - expression: + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: program_name + - comma: ',' + - expression: + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: client_interface_name + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sys + - dot: . + - naked_identifier: dm_exec_sessions + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: s + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: is_user_process + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/keyword_identifier_usage.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/keyword_identifier_usage.sql new file mode 100644 index 000000000..d9eab15cc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/keyword_identifier_usage.sql @@ -0,0 +1,117 @@ +-- Test T-SQL keyword behavior as identifiers +-- In T-SQL, only RESERVED keywords require quoting as identifiers +-- UNRESERVED keywords and FUTURE_RESERVED keywords can be used as naked identifiers + +-- 1. UNRESERVED KEYWORDS - Can be used as naked identifiers +SELECT + Type, + Value, + Name, + Date, + Time, + Format, + Level, + Path, + Data, + Server, + Action, + Cache, + Edge, + Hash, + Filter, + Profile +FROM TestTable; + +-- 2. FUTURE RESERVED KEYWORDS - Can also be used as naked identifiers +-- These include: ALIAS, ARRAY, CLASS, DESTROY, END-EXEC, EVERY, LIKE_REGEX +SELECT + Class, + Array, + Alias +FROM GameData; + +-- 3. RESERVED KEYWORDS - Must be quoted or bracketed +SELECT + [SELECT], -- reserved, needs brackets + [FROM], -- reserved, needs brackets + [WHERE], -- reserved, needs brackets + [ORDER], -- reserved, needs brackets + Name -- not reserved, no brackets needed +FROM TestTable2; + +-- 4. Mixed usage in CREATE TABLE +CREATE TABLE MyTable ( + -- Unreserved keywords - no quotes needed + Type INT, + Value VARCHAR(50), + Format VARCHAR(20), + + -- Future reserved keywords - no quotes needed + Class VARCHAR(50), + Array VARCHAR(100), + + -- Reserved keywords - quotes/brackets required + [SELECT] INT, + [UPDATE] VARCHAR(50), + + -- Regular identifiers + Name VARCHAR(100) +); + +-- 5. Column references in various contexts +UPDATE MyTable +SET Type = 1, Value = 'test', Class = 'warrior' +WHERE Format = 'json'; + +INSERT INTO MyTable (Type, Value, Class, Name) +VALUES (1, 'test', 'wizard', 'player1'); + +SELECT Type, Value, Class +FROM MyTable +WHERE Type IN (1, 2, 3) +ORDER BY Class, Value; + +-- 6. Aliases using unreserved keywords +SELECT + t1.Type AS Type, + t1.Value AS Value, + t2.Class AS Class +FROM MyTable t1 +JOIN GameData t2 ON t1.Name = t2.Name; + +-- Example from user's issue +SELECT + Nation, Race, Class, HairColor, + Hp, Mp, Sp, Strong, Sta, Dex, Intel, Cha, Authority, Points, Gold, Bind, PX, PZ, PY, dwTime, strSkill, strItem,strSerial +FROM USERDATA; + +-- More examples with various unreserved keywords as identifiers +SELECT + Type, Value, Name, Date, Time, Path, Data, Format, Level, Server +FROM TestTable; + +-- Unreserved keywords in WHERE clause +SELECT * FROM TestTable WHERE Type = 'test' AND Value > 10; + +-- Unreserved keywords in JOIN +SELECT t1.Type, t2.Value +FROM Table1 t1 +JOIN Table2 t2 ON t1.Name = t2.Name; + +-- CREATE TABLE with unreserved keyword column names +CREATE TABLE MyTable ( + Type INT, + Value VARCHAR(50), + Name VARCHAR(100), + Data VARBINARY(MAX), + Format VARCHAR(20) +); + +-- INSERT with unreserved keyword column names +INSERT INTO MyTable (Type, Value, Name, Data, Format) +VALUES (1, 'test', 'example', 0x123456, 'json'); + +-- UPDATE with unreserved keyword column names +UPDATE MyTable +SET Value = 'updated', Format = 'xml' +WHERE Type = 1; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/keyword_identifier_usage.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/keyword_identifier_usage.yml new file mode 100644 index 000000000..118ec2adb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/keyword_identifier_usage.yml @@ -0,0 +1,753 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: Type + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Value + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Date + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Time + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Format + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Level + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Path + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Data + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Server + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Action + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Cache + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Edge + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Hash + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Filter + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Profile + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: TestTable + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: Class + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Array + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Alias + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: GameData + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '[SELECT]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[FROM]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[WHERE]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[ORDER]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Name + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: TestTable2 + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: MyTable + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: Type + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: Value + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: Format + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '20' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: Class + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: Array + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[SELECT]' + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - quoted_identifier: '[UPDATE]' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: Name + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: MyTable + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: Type + - assignment_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '1' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: Value + - assignment_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''test''' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: Class + - assignment_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''warrior''' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: Format + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''json''' + - statement_terminator: ; + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: MyTable + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: Type + - comma: ',' + - column_reference: + - naked_identifier: Value + - comma: ',' + - column_reference: + - naked_identifier: Class + - comma: ',' + - column_reference: + - naked_identifier: Name + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - integer_literal: '1' + - comma: ',' + - quoted_literal: '''test''' + - comma: ',' + - quoted_literal: '''wizard''' + - comma: ',' + - quoted_literal: '''player1''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: Type + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Value + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Class + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: MyTable + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: Type + - keyword: IN + - bracketed: + - start_bracket: ( + - integer_literal: '1' + - comma: ',' + - integer_literal: '2' + - comma: ',' + - integer_literal: '3' + - end_bracket: ) + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: Class + - comma: ',' + - column_reference: + - naked_identifier: Value + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: Type + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Type + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: Value + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Value + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: Class + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Class + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: MyTable + - alias_expression: + - naked_identifier: t1 + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: GameData + - alias_expression: + - naked_identifier: t2 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: Name + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: Name + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: Nation + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Race + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Class + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: HairColor + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Hp + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Mp + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Sp + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Strong + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Sta + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Dex + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Intel + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Cha + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Authority + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Points + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Gold + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Bind + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: PX + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: PZ + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: PY + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: dwTime + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: strSkill + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: strItem + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: strSerial + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: USERDATA + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: Type + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Value + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Date + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Time + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Path + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Data + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Format + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Level + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Server + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: TestTable + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: TestTable + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: Type + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''test''' + - binary_operator: AND + - column_reference: + - naked_identifier: Value + - comparison_operator: + - raw_comparison_operator: '>' + - integer_literal: '10' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: Type + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: Value + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Table1 + - alias_expression: + - naked_identifier: t1 + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Table2 + - alias_expression: + - naked_identifier: t2 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: t1 + - dot: . + - naked_identifier: Name + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: t2 + - dot: . + - naked_identifier: Name + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: MyTable + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: Type + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: Value + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: Name + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: Data + - data_type: + - keyword: VARBINARY + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: MAX + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: Format + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '20' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: MyTable + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: Type + - comma: ',' + - column_reference: + - naked_identifier: Value + - comma: ',' + - column_reference: + - naked_identifier: Name + - comma: ',' + - column_reference: + - naked_identifier: Data + - comma: ',' + - column_reference: + - naked_identifier: Format + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - integer_literal: '1' + - comma: ',' + - quoted_literal: '''test''' + - comma: ',' + - quoted_literal: '''example''' + - comma: ',' + - binary_literal: '0x123456' + - comma: ',' + - quoted_literal: '''json''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: MyTable + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: Value + - assignment_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''updated''' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: Format + - assignment_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''xml''' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: Type + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/merge.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/merge.sql new file mode 100644 index 000000000..33aa98128 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/merge.sql @@ -0,0 +1,202 @@ +merge + schema1.table1 dst +using + schema1.table1 src +on + src.rn = 1 + and dst.e_date_to is null + and dst.cc_id = src.cc_id +when matched + then update + set + dst.l_id = src.l_id, + dst.e_date_to = src.e_date_from +go + +with source_data as +( + select + cc_id + , cc_name + , cc_description + from + DW.sch1.tbl1 + where + e_date_to is null + and l_id >= dd + and l_id <= dd +) +merge + DM.sch1.tbl2 dst +using + source_data src +on + src.cc_id = dst.cc_id +when + matched + then + update + set + dst.cc_name = src.cc_name + , dst.cc_description = src.cc_description +when + not matched + then + insert + ( + cc_id + , cc_name + , cc_description + ) + values + ( + cc_id + , cc_name + , cc_description + ); +go + +merge + DW.tt.dd dst +using + LA.tt.dd src + on dst.s_id = src.s_id + and dst.c_id = src.c_id +when matched + then update + set + dst.c_name = src.c_name + , dst.col1 = src.col1 + , dst.col2 = src.col2 +when not matched by target and src.c_id is not null + then insert + ( + s_id + , c_id + , c_name + , col1 + , col2 + ) + values + ( + src.s_id + , src.c_id + , src.c_name + , src.col1 + , src.col2 + ) +when not matched by source and s_id =1 in + ( select s_id from LA.g.tbl3) + then update + set + dst.col1 = 'N' + , dst.col2 = col2 +; + +go + +MERGE Production.UnitMeasure AS tgt + USING (SELECT @UnitMeasureCode, @Name) as src (UnitMeasureCode, Name) + ON (tgt.UnitMeasureCode = src.UnitMeasureCode) + WHEN MATCHED THEN + UPDATE SET Name = src.Name + WHEN NOT MATCHED THEN + INSERT (UnitMeasureCode, Name) + VALUES (src.UnitMeasureCode, src.Name) + OUTPUT deleted.*, $action, inserted.* INTO #MyTempTable; +GO + +MERGE Production.ProductInventory AS tgt +USING (SELECT ProductID, SUM(OrderQty) FROM Sales.SalesOrderDetail AS sod + JOIN Sales.SalesOrderHeader AS soh + ON sod.SalesOrderID = soh.SalesOrderID + AND soh.OrderDate = @OrderDate + GROUP BY ProductID) as src (ProductID, OrderQty) +ON (tgt.ProductID = src.ProductID) +WHEN MATCHED AND tgt.Quantity - src.OrderQty <= 0 + THEN DELETE +WHEN MATCHED + THEN UPDATE SET tgt.Quantity = tgt.Quantity - src.OrderQty, + tgt.ModifiedDate = GETDATE() +OUTPUT $action, Inserted.ProductID, Inserted.Quantity, + Inserted.ModifiedDate, Deleted.ProductID, + Deleted.Quantity, Deleted.ModifiedDate; +GO + +MERGE Production.ProductInventory AS pi + USING (SELECT ProductID, SUM(OrderQty) + FROM Sales.SalesOrderDetail AS sod + JOIN Sales.SalesOrderHeader AS soh + ON sod.SalesOrderID = soh.SalesOrderID + AND soh.OrderDate BETWEEN '20030701' AND '20030731' + GROUP BY ProductID) AS src (ProductID, OrderQty) + ON pi.ProductID = src.ProductID + WHEN MATCHED AND pi.Quantity - src.OrderQty >= 0 + THEN UPDATE SET pi.Quantity = pi.Quantity - src.OrderQty + WHEN MATCHED AND pi.Quantity - src.OrderQty <= 0 + THEN DELETE + OUTPUT $action, Inserted.ProductID, Inserted.LocationID, + Inserted.Quantity AS NewQty, Deleted.Quantity AS PreviousQty; +GO + +insert into sch1.table1 +( + columnC +) +select + upd.columnC +from +( + merge + sch1.table1 trg + using + ( + select + gr.columnC + from + sch2.table2 as gr + ) src + on + trg.columnC = src.columnC + when matched + then update + set + columnC = src.columnC + output + inserted.columnC +) as upd +; +GO + +MERGE Production.UnitMeasure WITH (PAGLOCK) AS tgt + USING (SELECT @UnitMeasureCode, @Name) as src (UnitMeasureCode, Name) + ON (tgt.UnitMeasureCode = src.UnitMeasureCode) + WHEN MATCHED THEN + UPDATE SET Name = src.Name + WHEN NOT MATCHED THEN + INSERT (UnitMeasureCode, Name) + VALUES (src.UnitMeasureCode, src.Name) + OUTPUT deleted.*, $action, inserted.* INTO #MyTempTable; +GO + +MERGE INTO Production.ProductInventory WITH (ROWLOCK, INDEX(myindex, myindex2)) AS pi + USING (SELECT ProductID, SUM(OrderQty) + FROM Sales.SalesOrderDetail AS sod + JOIN Sales.SalesOrderHeader AS soh + ON sod.SalesOrderID = soh.SalesOrderID + AND soh.OrderDate BETWEEN '20030701' AND '20030731' + GROUP BY ProductID) AS src (ProductID, OrderQty) + ON pi.ProductID = src.ProductID + WHEN MATCHED AND pi.Quantity - src.OrderQty >= 0 + THEN UPDATE SET pi.Quantity = pi.Quantity - src.OrderQty + WHEN MATCHED AND pi.Quantity - src.OrderQty <= 0 + THEN DELETE + OUTPUT $action, Inserted.ProductID, Inserted.LocationID, + Inserted.Quantity AS NewQty, Deleted.Quantity AS PreviousQty; +GO + +MERGE INTO dbo.target +USING ( SELECT 1 AS i ) AS source +ON source.i = target.i +WHEN MATCHED +THEN UPDATE SET target.i = source.i; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/merge.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/merge.yml new file mode 100644 index 000000000..7067a0cac --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/merge.yml @@ -0,0 +1,1501 @@ +file: +- batch: + - statement: + - merge_statement: + - keyword: merge + - table_reference: + - naked_identifier: schema1 + - dot: . + - naked_identifier: table1 + - alias_expression: + - naked_identifier: dst + - keyword: using + - table_reference: + - naked_identifier: schema1 + - dot: . + - naked_identifier: table1 + - alias_expression: + - naked_identifier: src + - join_on_condition: + - keyword: on + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: rn + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - binary_operator: and + - column_reference: + - naked_identifier: dst + - dot: . + - naked_identifier: e_date_to + - keyword: is + - null_literal: 'null' + - binary_operator: and + - column_reference: + - naked_identifier: dst + - dot: . + - naked_identifier: cc_id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: cc_id + - merge_match: + - merge_when_matched_clause: + - keyword: when + - keyword: matched + - keyword: then + - merge_update_clause: + - keyword: update + - set_clause_list: + - keyword: set + - set_clause: + - column_reference: + - naked_identifier: dst + - dot: . + - naked_identifier: l_id + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: l_id + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: dst + - dot: . + - naked_identifier: e_date_to + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: e_date_from + - go_statement: + - keyword: go +- batch: + - statement: + - with_compound_statement: + - keyword: with + - common_table_expression: + - naked_identifier: source_data + - keyword: as + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: cc_id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: cc_name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: cc_description + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: DW + - dot: . + - naked_identifier: sch1 + - dot: . + - naked_identifier: tbl1 + - where_clause: + - keyword: where + - expression: + - column_reference: + - naked_identifier: e_date_to + - keyword: is + - null_literal: 'null' + - binary_operator: and + - column_reference: + - naked_identifier: l_id + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - column_reference: + - naked_identifier: dd + - binary_operator: and + - column_reference: + - naked_identifier: l_id + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - column_reference: + - naked_identifier: dd + - end_bracket: ) + - merge_statement: + - keyword: merge + - table_reference: + - naked_identifier: DM + - dot: . + - naked_identifier: sch1 + - dot: . + - naked_identifier: tbl2 + - alias_expression: + - naked_identifier: dst + - keyword: using + - table_reference: + - naked_identifier: source_data + - alias_expression: + - naked_identifier: src + - join_on_condition: + - keyword: on + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: cc_id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: dst + - dot: . + - naked_identifier: cc_id + - merge_match: + - merge_when_matched_clause: + - keyword: when + - keyword: matched + - keyword: then + - merge_update_clause: + - keyword: update + - set_clause_list: + - keyword: set + - set_clause: + - column_reference: + - naked_identifier: dst + - dot: . + - naked_identifier: cc_name + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: cc_name + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: dst + - dot: . + - naked_identifier: cc_description + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: cc_description + - merge_when_not_matched_clause: + - keyword: when + - keyword: not + - keyword: matched + - keyword: then + - merge_insert_clause: + - keyword: insert + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: cc_id + - comma: ',' + - column_reference: + - naked_identifier: cc_name + - comma: ',' + - column_reference: + - naked_identifier: cc_description + - end_bracket: ) + - keyword: values + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: cc_id + - comma: ',' + - expression: + - column_reference: + - naked_identifier: cc_name + - comma: ',' + - expression: + - column_reference: + - naked_identifier: cc_description + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: go +- batch: + - statement: + - merge_statement: + - keyword: merge + - table_reference: + - naked_identifier: DW + - dot: . + - naked_identifier: tt + - dot: . + - naked_identifier: dd + - alias_expression: + - naked_identifier: dst + - keyword: using + - table_reference: + - naked_identifier: LA + - dot: . + - naked_identifier: tt + - dot: . + - naked_identifier: dd + - alias_expression: + - naked_identifier: src + - join_on_condition: + - keyword: on + - expression: + - column_reference: + - naked_identifier: dst + - dot: . + - naked_identifier: s_id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: s_id + - binary_operator: and + - column_reference: + - naked_identifier: dst + - dot: . + - naked_identifier: c_id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: c_id + - merge_match: + - merge_when_matched_clause: + - keyword: when + - keyword: matched + - keyword: then + - merge_update_clause: + - keyword: update + - set_clause_list: + - keyword: set + - set_clause: + - column_reference: + - naked_identifier: dst + - dot: . + - naked_identifier: c_name + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: c_name + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: dst + - dot: . + - naked_identifier: col1 + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: col1 + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: dst + - dot: . + - naked_identifier: col2 + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: col2 + - merge_when_not_matched_clause: + - keyword: when + - keyword: not + - keyword: matched + - keyword: by + - keyword: target + - keyword: and + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: c_id + - keyword: is + - keyword: not + - null_literal: 'null' + - keyword: then + - merge_insert_clause: + - keyword: insert + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: s_id + - comma: ',' + - column_reference: + - naked_identifier: c_id + - comma: ',' + - column_reference: + - naked_identifier: c_name + - comma: ',' + - column_reference: + - naked_identifier: col1 + - comma: ',' + - column_reference: + - naked_identifier: col2 + - end_bracket: ) + - keyword: values + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: s_id + - comma: ',' + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: c_id + - comma: ',' + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: c_name + - comma: ',' + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: col1 + - comma: ',' + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: col2 + - end_bracket: ) + - merge_when_not_matched_clause: + - keyword: when + - keyword: not + - keyword: matched + - keyword: by + - keyword: source + - keyword: and + - expression: + - column_reference: + - naked_identifier: s_id + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - keyword: in + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: s_id + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: LA + - dot: . + - naked_identifier: g + - dot: . + - naked_identifier: tbl3 + - end_bracket: ) + - keyword: then + - merge_update_clause: + - keyword: update + - set_clause_list: + - keyword: set + - set_clause: + - column_reference: + - naked_identifier: dst + - dot: . + - naked_identifier: col1 + - assignment_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''N''' + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: dst + - dot: . + - naked_identifier: col2 + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: col2 + - statement_terminator: ; + - go_statement: + - keyword: go +- batch: + - statement: + - merge_statement: + - keyword: MERGE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: UnitMeasure + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tgt + - keyword: USING + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameter: '@UnitMeasureCode' + - comma: ',' + - select_clause_element: + - parameter: '@Name' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: src + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: UnitMeasureCode + - comma: ',' + - naked_identifier: Name + - end_bracket: ) + - join_on_condition: + - keyword: ON + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: tgt + - dot: . + - naked_identifier: UnitMeasureCode + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: UnitMeasureCode + - end_bracket: ) + - merge_match: + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: THEN + - merge_update_clause: + - keyword: UPDATE + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: Name + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: Name + - merge_when_not_matched_clause: + - keyword: WHEN + - keyword: NOT + - keyword: MATCHED + - keyword: THEN + - merge_insert_clause: + - keyword: INSERT + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: UnitMeasureCode + - comma: ',' + - column_reference: + - naked_identifier: Name + - end_bracket: ) + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: UnitMeasureCode + - comma: ',' + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: Name + - end_bracket: ) + - output_clause: + - keyword: OUTPUT + - keyword: deleted + - dot: . + - wildcard_identifier: + - star: '*' + - comma: ',' + - action_parameter: $action + - comma: ',' + - keyword: inserted + - dot: . + - wildcard_identifier: + - star: '*' + - keyword: INTO + - table_reference: + - hash_identifier: '#MyTempTable' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - merge_statement: + - keyword: MERGE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ProductInventory + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tgt + - keyword: USING + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ProductID + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderDetail + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sod + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderHeader + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: soh + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: sod + - dot: . + - naked_identifier: SalesOrderID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: soh + - dot: . + - naked_identifier: SalesOrderID + - binary_operator: AND + - column_reference: + - naked_identifier: soh + - dot: . + - naked_identifier: OrderDate + - comparison_operator: + - raw_comparison_operator: = + - parameter: '@OrderDate' + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: ProductID + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: src + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: ProductID + - comma: ',' + - naked_identifier: OrderQty + - end_bracket: ) + - join_on_condition: + - keyword: ON + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: tgt + - dot: . + - naked_identifier: ProductID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: ProductID + - end_bracket: ) + - merge_match: + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: AND + - expression: + - column_reference: + - naked_identifier: tgt + - dot: . + - naked_identifier: Quantity + - binary_operator: '-' + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: OrderQty + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - integer_literal: '0' + - keyword: THEN + - merge_delete_clause: + - keyword: DELETE + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: THEN + - merge_update_clause: + - keyword: UPDATE + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: tgt + - dot: . + - naked_identifier: Quantity + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: tgt + - dot: . + - naked_identifier: Quantity + - binary_operator: '-' + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: OrderQty + - comma: ',' + - set_clause: + - column_reference: + - naked_identifier: tgt + - dot: . + - naked_identifier: ModifiedDate + - assignment_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - output_clause: + - keyword: OUTPUT + - action_parameter: $action + - comma: ',' + - keyword: Inserted + - dot: . + - naked_identifier: ProductID + - comma: ',' + - keyword: Inserted + - dot: . + - naked_identifier: Quantity + - comma: ',' + - keyword: Inserted + - dot: . + - naked_identifier: ModifiedDate + - comma: ',' + - keyword: Deleted + - dot: . + - naked_identifier: ProductID + - comma: ',' + - keyword: Deleted + - dot: . + - naked_identifier: Quantity + - comma: ',' + - keyword: Deleted + - dot: . + - naked_identifier: ModifiedDate + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - merge_statement: + - keyword: MERGE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ProductInventory + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: pi + - keyword: USING + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ProductID + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderDetail + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sod + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderHeader + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: soh + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: sod + - dot: . + - naked_identifier: SalesOrderID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: soh + - dot: . + - naked_identifier: SalesOrderID + - binary_operator: AND + - column_reference: + - naked_identifier: soh + - dot: . + - naked_identifier: OrderDate + - keyword: BETWEEN + - quoted_literal: '''20030701''' + - keyword: AND + - quoted_literal: '''20030731''' + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: ProductID + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: src + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: ProductID + - comma: ',' + - naked_identifier: OrderQty + - end_bracket: ) + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: pi + - dot: . + - naked_identifier: ProductID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: ProductID + - merge_match: + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: AND + - expression: + - column_reference: + - naked_identifier: pi + - dot: . + - naked_identifier: Quantity + - binary_operator: '-' + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: OrderQty + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - integer_literal: '0' + - keyword: THEN + - merge_update_clause: + - keyword: UPDATE + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: pi + - dot: . + - naked_identifier: Quantity + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: pi + - dot: . + - naked_identifier: Quantity + - binary_operator: '-' + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: OrderQty + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: AND + - expression: + - column_reference: + - naked_identifier: pi + - dot: . + - naked_identifier: Quantity + - binary_operator: '-' + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: OrderQty + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - integer_literal: '0' + - keyword: THEN + - merge_delete_clause: + - keyword: DELETE + - output_clause: + - keyword: OUTPUT + - action_parameter: $action + - comma: ',' + - keyword: Inserted + - dot: . + - naked_identifier: ProductID + - comma: ',' + - keyword: Inserted + - dot: . + - naked_identifier: LocationID + - comma: ',' + - keyword: Inserted + - dot: . + - naked_identifier: Quantity + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: NewQty + - comma: ',' + - keyword: Deleted + - dot: . + - naked_identifier: Quantity + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: PreviousQty + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - insert_statement: + - keyword: insert + - keyword: into + - table_reference: + - naked_identifier: sch1 + - dot: . + - naked_identifier: table1 + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: columnC + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: upd + - dot: . + - naked_identifier: columnC + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - merge_statement: + - keyword: merge + - table_reference: + - naked_identifier: sch1 + - dot: . + - naked_identifier: table1 + - alias_expression: + - naked_identifier: trg + - keyword: using + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: gr + - dot: . + - naked_identifier: columnC + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sch2 + - dot: . + - naked_identifier: table2 + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: gr + - end_bracket: ) + - alias_expression: + - naked_identifier: src + - join_on_condition: + - keyword: on + - expression: + - column_reference: + - naked_identifier: trg + - dot: . + - naked_identifier: columnC + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: columnC + - merge_match: + - merge_when_matched_clause: + - keyword: when + - keyword: matched + - keyword: then + - merge_update_clause: + - keyword: update + - set_clause_list: + - keyword: set + - set_clause: + - column_reference: + - naked_identifier: columnC + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: columnC + - output_clause: + - keyword: output + - keyword: inserted + - dot: . + - naked_identifier: columnC + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: upd + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - merge_statement: + - keyword: MERGE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: UnitMeasure + - keyword: WITH + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: PAGLOCK + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tgt + - keyword: USING + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameter: '@UnitMeasureCode' + - comma: ',' + - select_clause_element: + - parameter: '@Name' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: src + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: UnitMeasureCode + - comma: ',' + - naked_identifier: Name + - end_bracket: ) + - join_on_condition: + - keyword: ON + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: tgt + - dot: . + - naked_identifier: UnitMeasureCode + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: UnitMeasureCode + - end_bracket: ) + - merge_match: + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: THEN + - merge_update_clause: + - keyword: UPDATE + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: Name + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: Name + - merge_when_not_matched_clause: + - keyword: WHEN + - keyword: NOT + - keyword: MATCHED + - keyword: THEN + - merge_insert_clause: + - keyword: INSERT + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: UnitMeasureCode + - comma: ',' + - column_reference: + - naked_identifier: Name + - end_bracket: ) + - keyword: VALUES + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: UnitMeasureCode + - comma: ',' + - expression: + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: Name + - end_bracket: ) + - output_clause: + - keyword: OUTPUT + - keyword: deleted + - dot: . + - wildcard_identifier: + - star: '*' + - comma: ',' + - action_parameter: $action + - comma: ',' + - keyword: inserted + - dot: . + - wildcard_identifier: + - star: '*' + - keyword: INTO + - table_reference: + - hash_identifier: '#MyTempTable' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - merge_statement: + - keyword: MERGE + - keyword: INTO + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ProductInventory + - keyword: WITH + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: ROWLOCK + - comma: ',' + - query_hint_segment: + - keyword: INDEX + - bracketed: + - start_bracket: ( + - index_reference: + - naked_identifier: myindex + - comma: ',' + - index_reference: + - naked_identifier: myindex2 + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: pi + - keyword: USING + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ProductID + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderDetail + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: sod + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderHeader + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: soh + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: sod + - dot: . + - naked_identifier: SalesOrderID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: soh + - dot: . + - naked_identifier: SalesOrderID + - binary_operator: AND + - column_reference: + - naked_identifier: soh + - dot: . + - naked_identifier: OrderDate + - keyword: BETWEEN + - quoted_literal: '''20030701''' + - keyword: AND + - quoted_literal: '''20030731''' + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: ProductID + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: src + - bracketed: + - start_bracket: ( + - identifier_list: + - naked_identifier: ProductID + - comma: ',' + - naked_identifier: OrderQty + - end_bracket: ) + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: pi + - dot: . + - naked_identifier: ProductID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: ProductID + - merge_match: + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: AND + - expression: + - column_reference: + - naked_identifier: pi + - dot: . + - naked_identifier: Quantity + - binary_operator: '-' + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: OrderQty + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - integer_literal: '0' + - keyword: THEN + - merge_update_clause: + - keyword: UPDATE + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: pi + - dot: . + - naked_identifier: Quantity + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: pi + - dot: . + - naked_identifier: Quantity + - binary_operator: '-' + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: OrderQty + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: AND + - expression: + - column_reference: + - naked_identifier: pi + - dot: . + - naked_identifier: Quantity + - binary_operator: '-' + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: OrderQty + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - integer_literal: '0' + - keyword: THEN + - merge_delete_clause: + - keyword: DELETE + - output_clause: + - keyword: OUTPUT + - action_parameter: $action + - comma: ',' + - keyword: Inserted + - dot: . + - naked_identifier: ProductID + - comma: ',' + - keyword: Inserted + - dot: . + - naked_identifier: LocationID + - comma: ',' + - keyword: Inserted + - dot: . + - naked_identifier: Quantity + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: NewQty + - comma: ',' + - keyword: Deleted + - dot: . + - naked_identifier: Quantity + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: PreviousQty + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - merge_statement: + - keyword: MERGE + - keyword: INTO + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: target + - keyword: USING + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: i + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: source + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: i + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: target + - dot: . + - naked_identifier: i + - merge_match: + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: THEN + - merge_update_clause: + - keyword: UPDATE + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: target + - dot: . + - naked_identifier: i + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: i + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function.sql new file mode 100644 index 000000000..5399c76c4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function.sql @@ -0,0 +1,5 @@ +CREATE OR ALTER FUNCTION [dbo].[add] (@add_1 int, @add_2 int) RETURNS integer +AS +BEGIN + RETURN @add_1 + @add_2 +END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function.yml new file mode 100644 index 000000000..2cf9d5171 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function.yml @@ -0,0 +1,39 @@ +file: +- batch: + - statement: + - create_function_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: FUNCTION + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[add]' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@add_1' + - data_type: + - keyword: int + - comma: ',' + - parameter: '@add_2' + - data_type: + - keyword: int + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: integer + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - return_segment: + - keyword: RETURN + - expression: + - parameter: '@add_1' + - binary_operator: + + - parameter: '@add_2' + - keyword: END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function_no_alter.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function_no_alter.sql new file mode 100644 index 000000000..e549b08c5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function_no_alter.sql @@ -0,0 +1,7 @@ +-- including just in case; Azure Synapse Analytics does not support OR ALTER +-- https://docs.microsoft.com/en-us/sql/t-sql/statements/create-function-sql-data-warehouse?view=aps-pdw-2016-au7 +CREATE FUNCTION [dbo].[add] (@add_1 int, @add_2 int) RETURNS integer +AS +BEGIN + RETURN @add_1 + @add_2 +END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function_no_alter.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function_no_alter.yml new file mode 100644 index 000000000..38136c4b1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/minimal_function_no_alter.yml @@ -0,0 +1,37 @@ +file: +- batch: + - statement: + - create_function_statement: + - keyword: CREATE + - keyword: FUNCTION + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[add]' + - function_parameter_list: + - bracketed: + - start_bracket: ( + - parameter: '@add_1' + - data_type: + - keyword: int + - comma: ',' + - parameter: '@add_2' + - data_type: + - keyword: int + - end_bracket: ) + - keyword: RETURNS + - data_type: + - data_type_identifier: integer + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - return_segment: + - keyword: RETURN + - expression: + - parameter: '@add_1' + - binary_operator: + + - parameter: '@add_2' + - keyword: END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement.sql new file mode 100644 index 000000000..622168ed9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement.sql @@ -0,0 +1,3 @@ +; +; +SELECT * FROM my_table; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement.yml new file mode 100644 index 000000000..3f72e06c7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement.yml @@ -0,0 +1,20 @@ +file: +- batch: + - statement_terminator: ; + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: my_table + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement_without_semicolon.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement_without_semicolon.sql new file mode 100644 index 000000000..1fcd19ff7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement_without_semicolon.sql @@ -0,0 +1,4 @@ +select a from tbl1 +GO +select b from tbl2 +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement_without_semicolon.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement_without_semicolon.yml new file mode 100644 index 000000000..a460d2a64 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multi_statement_without_semicolon.yml @@ -0,0 +1,35 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: a + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: b + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl2 + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multiple_semicolons.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multiple_semicolons.sql new file mode 100644 index 000000000..931d9f961 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multiple_semicolons.sql @@ -0,0 +1,17 @@ +-- Leading double semicolons before first statement +;;SELECT col1 FROM tbl1; + +-- Statement with trailing double semicolons +SELECT col2 FROM tbl2;; + +-- Multiple semicolons separating statements +SELECT col3 FROM tbl3;;;;SELECT col4 FROM tbl4; + +-- Mixed whitespace and semicolons +; ; ;SELECT col5 FROM tbl5; ; ; + +-- Many semicolons at end +SELECT col6 FROM tbl6;;;;;; + +-- Many semicolons at end and GOs +SELECT col6 FROM tbl6;GO;GO;; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multiple_semicolons.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multiple_semicolons.yml new file mode 100644 index 000000000..cfe947ee7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/multiple_semicolons.yml @@ -0,0 +1,132 @@ +file: +- batch: + - statement_terminator: ; + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl2 + - statement_terminator: ; + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col3 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl3 + - statement_terminator: ; + - statement_terminator: ; + - statement_terminator: ; + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col4 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl4 + - statement_terminator: ; + - statement_terminator: ; + - statement_terminator: ; + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col5 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl5 + - statement_terminator: ; + - statement_terminator: ; + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col6 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl6 + - statement_terminator: ; + - statement_terminator: ; + - statement_terminator: ; + - statement_terminator: ; + - statement_terminator: ; + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col6 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl6 + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement_terminator: ; + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/nested_joins.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/nested_joins.sql new file mode 100644 index 000000000..531ab4dc4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/nested_joins.sql @@ -0,0 +1,36 @@ +SELECT 1 AS RegionCode +FROM BA +LEFT OUTER JOIN I + LEFT OUTER JOIN P + ON I.Pcd = P.Iid + ON BA.Iid = I.Bcd; +GO + +SELECT 1 +FROM BA +RIGHT OUTER JOIN I + LEFT OUTER JOIN P AS P_1 + LEFT OUTER JOIN IP AS IP_1 + ON P_1.NID = IP_1.NID + ON I.PID = CAST(P_1.IDEID AS varchar) + LEFT OUTER JOIN P AS P_2 + LEFT OUTER JOIN IP AS IP_2 + ON P_2.NID = IP_2.NID + ON I.SecondaryPID = CAST(P_2.IDEID AS varchar) + ON CAST(BA.IDEID AS varchar) = I.BAID + +SELECT 1 AS RegionCode +FROM BA +LEFT OUTER JOIN ( + I JOIN P + ON I.Pcd = P.Iid +) ON BA.Iid = I.Bcd; +GO + +SELECT + tst1.Name, tst2.OtherName +FROM dbo.Test1 AS tst1 + LEFT OUTER JOIN (dbo.Test2 AS tst2 + INNER JOIN dbo.FilterTable AS fltr1 + ON tst2.Id = fltr1.Id) + ON tst1.id = tst2.id; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/nested_joins.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/nested_joins.yml new file mode 100644 index 000000000..db2b97856 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/nested_joins.yml @@ -0,0 +1,382 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: RegionCode + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: BA + - join_clause: + - keyword: LEFT + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: I + - join_clause: + - keyword: LEFT + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: P + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: I + - dot: . + - naked_identifier: Pcd + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: P + - dot: . + - naked_identifier: Iid + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: BA + - dot: . + - naked_identifier: Iid + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: I + - dot: . + - naked_identifier: Bcd + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: BA + - join_clause: + - keyword: RIGHT + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: I + - join_clause: + - keyword: LEFT + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: P + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: P_1 + - join_clause: + - keyword: LEFT + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: IP + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: IP_1 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: P_1 + - dot: . + - naked_identifier: NID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: IP_1 + - dot: . + - naked_identifier: NID + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: I + - dot: . + - naked_identifier: PID + - comparison_operator: + - raw_comparison_operator: = + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: P_1 + - dot: . + - naked_identifier: IDEID + - keyword: AS + - data_type: + - keyword: varchar + - end_bracket: ) + - join_clause: + - keyword: LEFT + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: P + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: P_2 + - join_clause: + - keyword: LEFT + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: IP + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: IP_2 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: P_2 + - dot: . + - naked_identifier: NID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: IP_2 + - dot: . + - naked_identifier: NID + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: I + - dot: . + - naked_identifier: SecondaryPID + - comparison_operator: + - raw_comparison_operator: = + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: P_2 + - dot: . + - naked_identifier: IDEID + - keyword: AS + - data_type: + - keyword: varchar + - end_bracket: ) + - join_on_condition: + - keyword: ON + - expression: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: BA + - dot: . + - naked_identifier: IDEID + - keyword: AS + - data_type: + - keyword: varchar + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: I + - dot: . + - naked_identifier: BAID + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: RegionCode + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: BA + - join_clause: + - keyword: LEFT + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - table_expression: + - bracketed: + - start_bracket: ( + - table_expression: + - table_reference: + - naked_identifier: I + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: P + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: I + - dot: . + - naked_identifier: Pcd + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: P + - dot: . + - naked_identifier: Iid + - end_bracket: ) + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: BA + - dot: . + - naked_identifier: Iid + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: I + - dot: . + - naked_identifier: Bcd + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: tst1 + - dot: . + - naked_identifier: Name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: tst2 + - dot: . + - naked_identifier: OtherName + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Test1 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tst1 + - join_clause: + - keyword: LEFT + - keyword: OUTER + - keyword: JOIN + - from_expression_element: + - bracketed: + - start_bracket: ( + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Test2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: tst2 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: FilterTable + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: fltr1 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: tst2 + - dot: . + - naked_identifier: Id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: fltr1 + - dot: . + - naked_identifier: Id + - end_bracket: ) + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: tst1 + - dot: . + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: tst2 + - dot: . + - naked_identifier: id + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/offset.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/offset.sql new file mode 100644 index 000000000..eb2ffe169 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/offset.sql @@ -0,0 +1,16 @@ +SELECT + client.reference, + client.name +FROM client +GROUP BY client.reference, client.name +ORDER BY client.reference +OFFSET 10 ROWS; + +SELECT + client.reference, + client.name +FROM client +GROUP BY client.reference, client.name +ORDER BY client.reference +OFFSET 10 ROWS +FETCH NEXT 10 ROWS ONLY; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/offset.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/offset.yml new file mode 100644 index 000000000..b1e9c4870 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/offset.yml @@ -0,0 +1,100 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: client + - dot: . + - naked_identifier: reference + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: client + - dot: . + - naked_identifier: name + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: client + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: client + - dot: . + - naked_identifier: reference + - comma: ',' + - column_reference: + - naked_identifier: client + - dot: . + - naked_identifier: name + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: client + - dot: . + - naked_identifier: reference + - offset_clause: + - keyword: OFFSET + - numeric_literal: '10' + - keyword: ROWS + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: client + - dot: . + - naked_identifier: reference + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: client + - dot: . + - naked_identifier: name + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: client + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: client + - dot: . + - naked_identifier: reference + - comma: ',' + - column_reference: + - naked_identifier: client + - dot: . + - naked_identifier: name + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: client + - dot: . + - naked_identifier: reference + - offset_clause: + - keyword: OFFSET + - numeric_literal: '10' + - keyword: ROWS + - fetch_clause: + - keyword: FETCH + - keyword: NEXT + - numeric_literal: '10' + - keyword: ROWS + - keyword: ONLY + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/open_symmetric_key.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/open_symmetric_key.sql new file mode 100644 index 000000000..b3bb834d0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/open_symmetric_key.sql @@ -0,0 +1,20 @@ +CREATE PROCEDURE dbo.procedure_name +AS +BEGIN + SET NOCOUNT ON; + + OPEN SYMMETRIC KEY [Key01] + DECRYPTION BY CERTIFICATE [Cert]; + + SELECT column1 FROM sys.tables; +END; +GO + +OPEN SYMMETRIC KEY [Key01] DECRYPTION BY CERTIFICATE [Cert]; +OPEN SYMMETRIC KEY [Key01] DECRYPTION BY CERTIFICATE [Cert] WITH PASSWORD = 'testPass123'; + +OPEN SYMMETRIC KEY [Key01] DECRYPTION BY ASYMMETRIC KEY [asym_key]; +OPEN SYMMETRIC KEY [Key01] DECRYPTION BY ASYMMETRIC KEY [asym_key] WITH PASSWORD = 'testPass123'; + +OPEN SYMMETRIC KEY [Key01] DECRYPTION BY SYMMETRIC KEY [sym_key]; +OPEN SYMMETRIC KEY [Key01] DECRYPTION BY PASSWORD = 'decryptPass123'; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/open_symmetric_key.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/open_symmetric_key.yml new file mode 100644 index 000000000..466bed974 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/open_symmetric_key.yml @@ -0,0 +1,148 @@ +file: +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: procedure_name + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - set_segment: + - keyword: SET + - keyword: NOCOUNT + - keyword: ON + - statement_terminator: ; + - statement: + - open_symmetric_key_statement: + - keyword: OPEN + - keyword: SYMMETRIC + - keyword: KEY + - object_reference: + - quoted_identifier: '[Key01]' + - keyword: DECRYPTION + - keyword: BY + - keyword: CERTIFICATE + - object_reference: + - quoted_identifier: '[Cert]' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: column1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sys + - dot: . + - naked_identifier: tables + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - open_symmetric_key_statement: + - keyword: OPEN + - keyword: SYMMETRIC + - keyword: KEY + - object_reference: + - quoted_identifier: '[Key01]' + - keyword: DECRYPTION + - keyword: BY + - keyword: CERTIFICATE + - object_reference: + - quoted_identifier: '[Cert]' + - statement_terminator: ; + - statement: + - open_symmetric_key_statement: + - keyword: OPEN + - keyword: SYMMETRIC + - keyword: KEY + - object_reference: + - quoted_identifier: '[Key01]' + - keyword: DECRYPTION + - keyword: BY + - keyword: CERTIFICATE + - object_reference: + - quoted_identifier: '[Cert]' + - keyword: WITH + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''testPass123''' + - statement_terminator: ; + - statement: + - open_symmetric_key_statement: + - keyword: OPEN + - keyword: SYMMETRIC + - keyword: KEY + - object_reference: + - quoted_identifier: '[Key01]' + - keyword: DECRYPTION + - keyword: BY + - keyword: ASYMMETRIC + - keyword: KEY + - object_reference: + - quoted_identifier: '[asym_key]' + - statement_terminator: ; + - statement: + - open_symmetric_key_statement: + - keyword: OPEN + - keyword: SYMMETRIC + - keyword: KEY + - object_reference: + - quoted_identifier: '[Key01]' + - keyword: DECRYPTION + - keyword: BY + - keyword: ASYMMETRIC + - keyword: KEY + - object_reference: + - quoted_identifier: '[asym_key]' + - keyword: WITH + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''testPass123''' + - statement_terminator: ; + - statement: + - open_symmetric_key_statement: + - keyword: OPEN + - keyword: SYMMETRIC + - keyword: KEY + - object_reference: + - quoted_identifier: '[Key01]' + - keyword: DECRYPTION + - keyword: BY + - keyword: SYMMETRIC + - keyword: KEY + - object_reference: + - quoted_identifier: '[sym_key]' + - statement_terminator: ; + - statement: + - open_symmetric_key_statement: + - keyword: OPEN + - keyword: SYMMETRIC + - keyword: KEY + - object_reference: + - quoted_identifier: '[Key01]' + - keyword: DECRYPTION + - keyword: BY + - keyword: PASSWORD + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''decryptPass123''' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openjson.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openjson.sql new file mode 100644 index 000000000..3b1eb26fc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openjson.sql @@ -0,0 +1,52 @@ +/* +https://learn.microsoft.com/en-us/sql/t-sql/functions/openjson-transact-sql?view=sql-server-ver16#examples +*/ + +SELECT * +FROM products +INNER JOIN OPENJSON(N'[1,2,3,4]') AS productTypes + ON product.productTypeID = productTypes.value +; + +SELECT * FROM OPENJSON(@json) + WITH ( month VARCHAR(3), + temp int, + month_id tinyint '$.sql:identity()') as months +; + +SELECT * +FROM OPENJSON ( @json ) +WITH ( + Number VARCHAR(200) '$.Order.Number', + Date DATETIME '$.Order.Date', + Customer VARCHAR(200) '$.AccountNumber', + Quantity INT '$.Item.Quantity', + [Order] NVARCHAR(MAX) AS JSON +); + +SELECT SalesOrderID, OrderDate, value AS Reason +FROM Sales.SalesOrderHeader + CROSS APPLY OPENJSON (SalesReasons) WITH (value NVARCHAR(100) '$') +; + +SELECT store.title, location.street, location.lat, location.long +FROM store +CROSS APPLY OPENJSON(store.jsonCol, 'lax $.location') + WITH (street VARCHAR(500) , postcode VARCHAR(500) '$.postcode' , + lon int '$.geo.longitude', lat int '$.geo.latitude') + AS location +; + +INSERT INTO Person +SELECT * +FROM OPENJSON(@json) +WITH (id INT, + firstName NVARCHAR(50), lastName NVARCHAR(50), + isAlive BIT, age INT, + dateOfBirth DATETIME, spouse NVARCHAR(50)) +; + +SELECT root.[key] AS [Order],TheValues.[key], TheValues.[value] +FROM OPENJSON ( @JSON ) AS root +CROSS APPLY OPENJSON ( root.value) AS TheValues +; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openjson.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openjson.yml new file mode 100644 index 000000000..731339dec --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openjson.yml @@ -0,0 +1,472 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: products + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: OPENJSON + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: N'[1,2,3,4]' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: productTypes + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: product + - dot: . + - naked_identifier: productTypeID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: productTypes + - dot: . + - naked_identifier: value + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openjson_segment: + - keyword: OPENJSON + - bracketed: + - start_bracket: ( + - column_reference: + - parameter: '@json' + - end_bracket: ) + - openjson_with_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: month + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '3' + - end_bracket: ) + - comma: ',' + - column_reference: + - naked_identifier: temp + - data_type: + - keyword: int + - comma: ',' + - column_reference: + - naked_identifier: month_id + - data_type: + - keyword: tinyint + - quoted_literal: '''$.sql:identity()''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: months + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openjson_segment: + - keyword: OPENJSON + - bracketed: + - start_bracket: ( + - column_reference: + - parameter: '@json' + - end_bracket: ) + - openjson_with_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: Number + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '200' + - end_bracket: ) + - quoted_literal: '''$.Order.Number''' + - comma: ',' + - column_reference: + - naked_identifier: Date + - data_type: + - keyword: DATETIME + - quoted_literal: '''$.Order.Date''' + - comma: ',' + - column_reference: + - naked_identifier: Customer + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '200' + - end_bracket: ) + - quoted_literal: '''$.AccountNumber''' + - comma: ',' + - column_reference: + - naked_identifier: Quantity + - data_type: + - keyword: INT + - quoted_literal: '''$.Item.Quantity''' + - comma: ',' + - column_reference: + - quoted_identifier: '[Order]' + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - keyword: MAX + - end_bracket: ) + - keyword: AS + - keyword: JSON + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: SalesOrderID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: OrderDate + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: value + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Reason + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderHeader + - join_clause: + - keyword: CROSS + - keyword: APPLY + - from_expression_element: + - table_expression: + - openjson_segment: + - keyword: OPENJSON + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: SalesReasons + - end_bracket: ) + - openjson_with_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: value + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - quoted_literal: '''$''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: store + - dot: . + - naked_identifier: title + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: location + - dot: . + - naked_identifier: street + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: location + - dot: . + - naked_identifier: lat + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: location + - dot: . + - naked_identifier: long + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: store + - join_clause: + - keyword: CROSS + - keyword: APPLY + - from_expression_element: + - table_expression: + - openjson_segment: + - keyword: OPENJSON + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: store + - dot: . + - naked_identifier: jsonCol + - comma: ',' + - quoted_literal: '''lax $.location''' + - end_bracket: ) + - openjson_with_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: street + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '500' + - end_bracket: ) + - comma: ',' + - column_reference: + - naked_identifier: postcode + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '500' + - end_bracket: ) + - quoted_literal: '''$.postcode''' + - comma: ',' + - column_reference: + - naked_identifier: lon + - data_type: + - keyword: int + - quoted_literal: '''$.geo.longitude''' + - comma: ',' + - column_reference: + - naked_identifier: lat + - data_type: + - keyword: int + - quoted_literal: '''$.geo.latitude''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: location + - statement_terminator: ; + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: Person + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openjson_segment: + - keyword: OPENJSON + - bracketed: + - start_bracket: ( + - column_reference: + - parameter: '@json' + - end_bracket: ) + - openjson_with_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: id + - data_type: + - keyword: INT + - comma: ',' + - column_reference: + - naked_identifier: firstName + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - comma: ',' + - column_reference: + - naked_identifier: lastName + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - comma: ',' + - column_reference: + - naked_identifier: isAlive + - data_type: + - keyword: BIT + - comma: ',' + - column_reference: + - naked_identifier: age + - data_type: + - keyword: INT + - comma: ',' + - column_reference: + - naked_identifier: dateOfBirth + - data_type: + - keyword: DATETIME + - comma: ',' + - column_reference: + - naked_identifier: spouse + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: root + - dot: . + - quoted_identifier: '[key]' + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[Order]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: TheValues + - dot: . + - quoted_identifier: '[key]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: TheValues + - dot: . + - quoted_identifier: '[value]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: OPENJSON + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - parameter: '@JSON' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: root + - join_clause: + - keyword: CROSS + - keyword: APPLY + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: OPENJSON + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: root + - dot: . + - naked_identifier: value + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: TheValues + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openquery.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openquery.sql new file mode 100644 index 000000000..6df0dffea --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openquery.sql @@ -0,0 +1,10 @@ +SELECT column1, column2 +FROM OPENQUERY ([testlinkedserver], 'select * from table_name'); + +UPDATE OPENQUERY (OracleSvr, 'SELECT name FROM joe.titles WHERE id = 101') +SET name = 'ADifferentName'; + +INSERT OPENQUERY (OracleSvr, 'SELECT name FROM joe.titles') +VALUES ('NewTitle'); + +DELETE OPENQUERY (OracleSvr, 'SELECT name FROM joe.titles WHERE name = ''NewTitle'''); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openquery.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openquery.yml new file mode 100644 index 000000000..445a31607 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openquery.yml @@ -0,0 +1,80 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: column1 + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: column2 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openquery_segment: + - keyword: OPENQUERY + - bracketed: + - start_bracket: ( + - object_reference: + - quoted_identifier: '[testlinkedserver]' + - comma: ',' + - quoted_literal: '''select * from table_name''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - update_statement: + - keyword: UPDATE + - openquery_segment: + - keyword: OPENQUERY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: OracleSvr + - comma: ',' + - quoted_literal: '''SELECT name FROM joe.titles WHERE id = 101''' + - end_bracket: ) + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: name + - assignment_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''ADifferentName''' + - statement_terminator: ; + - statement: + - insert_statement: + - keyword: INSERT + - openquery_segment: + - keyword: OPENQUERY + - bracketed: + - start_bracket: ( + - object_reference: + - naked_identifier: OracleSvr + - comma: ',' + - quoted_literal: '''SELECT name FROM joe.titles''' + - end_bracket: ) + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - quoted_literal: '''NewTitle''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - keyword: OPENQUERY + - bracketed: + - start_bracket: ( + - naked_identifier: OracleSvr + - comma: ',' + - quoted_literal: '''SELECT name FROM joe.titles WHERE name = ''''NewTitle''''''' + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openrowset.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openrowset.sql new file mode 100644 index 000000000..b0f331baf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openrowset.sql @@ -0,0 +1,74 @@ +SELECT a.* + FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', + 'C:\SAMPLES\Northwind.mdb'; + 'admin'; + 'password', + Customers) AS a; +GO + +SELECT d.* +FROM OPENROWSET('SQLNCLI', 'Server=Seattle1;Trusted_Connection=yes;', + Department) AS d; +GO + +SELECT d.* +FROM OPENROWSET('SQLNCLI', 'Server=Seattle1;Trusted_Connection=yes;', + AdventureWorks2012.HumanResources.Department) AS d; +GO + +SELECT a.* +FROM OPENROWSET('SQLNCLI', 'Server=Seattle1;Trusted_Connection=yes;', + 'SELECT TOP 10 GroupName, Name + FROM AdventureWorks2012.HumanResources.Department') AS a; +GO + +SELECT * FROM OPENROWSET( + BULK 'C:\DATA\inv-2017-01-19.csv', + SINGLE_CLOB) AS DATA; +GO + +SELECT * + FROM OPENROWSET(BULK N'C:\Text1.txt', SINGLE_NCLOB) AS Document; +GO + +SELECT * +FROM OPENROWSET(BULK N'D:\XChange\test-csv.csv', + FORMATFILE = N'D:\XChange\test-csv.fmt', + FIRSTROW=2, + FORMAT='CSV') AS cars; +GO + +SELECT TOP 10 * +from OPENROWSET(BULK 'https://pandemicdatalake.blob.core.windows.net/public/curated/covid-19/ecdc_cases/latest/ecdc_cases.parquet', + DATA_SOURCE = 'MyAzureBlobStorage', + FORMAT = 'PARQUET') as rows +GO + +SELECT TOP 10 * +FROM OPENROWSET( + BULK 'https://pandemicdatalake.blob.core.windows.net/public/curated/covid-19/ecdc_cases/latest/ecdc_cases.parquet', + FORMAT = 'PARQUET' + ) +WITH ( + [country_code] VARCHAR(5) COLLATE Latin1_General_BIN2, + [country_name] VARCHAR(100) COLLATE Latin1_General_BIN2 2, + [year] smallint, + [population] bigint +) as rows +GO + +SELECT + TOP 1 * +FROM OPENROWSET( + BULK 'https://azureopendatastorage.blob.core.windows.net/censusdatacontainer/release/us_population_county/year=20*/*.parquet', + FORMAT='PARQUET' + ) +WITH ( + [stateName] VARCHAR(50), + [stateName_explicit_path] VARCHAR(50) '$.stateName', + [COUNTYNAME] VARCHAR(50), + [countyName_explicit_path] VARCHAR(50) '$.COUNTYNAME', + [population] bigint 'strict $.population' +) +AS [r] +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openrowset.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openrowset.yml new file mode 100644 index 000000000..6e52f89cb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openrowset.yml @@ -0,0 +1,452 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - naked_identifier: a + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openrowset_segment: + - keyword: OPENROWSET + - bracketed: + - start_bracket: ( + - quoted_literal: '''Microsoft.Jet.OLEDB.4.0''' + - comma: ',' + - quoted_literal: '''C:\SAMPLES\Northwind.mdb''' + - statement_terminator: ; + - quoted_literal: '''admin''' + - statement_terminator: ; + - quoted_literal: '''password''' + - comma: ',' + - table_reference: + - naked_identifier: Customers + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - naked_identifier: d + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openrowset_segment: + - keyword: OPENROWSET + - bracketed: + - start_bracket: ( + - quoted_literal: '''SQLNCLI''' + - comma: ',' + - quoted_literal: '''Server=Seattle1;Trusted_Connection=yes;''' + - comma: ',' + - table_reference: + - naked_identifier: Department + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: d + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - naked_identifier: d + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openrowset_segment: + - keyword: OPENROWSET + - bracketed: + - start_bracket: ( + - quoted_literal: '''SQLNCLI''' + - comma: ',' + - quoted_literal: '''Server=Seattle1;Trusted_Connection=yes;''' + - comma: ',' + - table_reference: + - naked_identifier: AdventureWorks2012 + - dot: . + - naked_identifier: HumanResources + - dot: . + - naked_identifier: Department + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: d + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - naked_identifier: a + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openrowset_segment: + - keyword: OPENROWSET + - bracketed: + - start_bracket: ( + - quoted_literal: '''SQLNCLI''' + - comma: ',' + - quoted_literal: '''Server=Seattle1;Trusted_Connection=yes;''' + - comma: ',' + - quoted_literal: |- + 'SELECT TOP 10 GroupName, Name + FROM AdventureWorks2012.HumanResources.Department' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openrowset_segment: + - keyword: OPENROWSET + - bracketed: + - start_bracket: ( + - keyword: BULK + - quoted_literal: '''C:\DATA\inv-2017-01-19.csv''' + - comma: ',' + - keyword: SINGLE_CLOB + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: DATA + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openrowset_segment: + - keyword: OPENROWSET + - bracketed: + - start_bracket: ( + - keyword: BULK + - quoted_literal: N'C:\Text1.txt' + - comma: ',' + - keyword: SINGLE_NCLOB + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Document + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openrowset_segment: + - keyword: OPENROWSET + - bracketed: + - start_bracket: ( + - keyword: BULK + - quoted_literal: N'D:\XChange\test-csv.csv' + - comma: ',' + - keyword: FORMATFILE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: N'D:\XChange\test-csv.fmt' + - comma: ',' + - keyword: FIRSTROW + - comparison_operator: + - raw_comparison_operator: = + - numeric_literal: '2' + - comma: ',' + - keyword: FORMAT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''CSV''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: cars + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - expression: + - integer_literal: '10' + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - openrowset_segment: + - keyword: OPENROWSET + - bracketed: + - start_bracket: ( + - keyword: BULK + - quoted_literal: '''https://pandemicdatalake.blob.core.windows.net/public/curated/covid-19/ecdc_cases/latest/ecdc_cases.parquet''' + - comma: ',' + - keyword: DATA_SOURCE + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''MyAzureBlobStorage''' + - comma: ',' + - keyword: FORMAT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''PARQUET''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: rows + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - expression: + - integer_literal: '10' + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openrowset_segment: + - keyword: OPENROWSET + - bracketed: + - start_bracket: ( + - keyword: BULK + - quoted_literal: '''https://pandemicdatalake.blob.core.windows.net/public/curated/covid-19/ecdc_cases/latest/ecdc_cases.parquet''' + - comma: ',' + - keyword: FORMAT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''PARQUET''' + - end_bracket: ) + - openrowset_with_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - quoted_identifier: '[country_code]' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '5' + - end_bracket: ) + - keyword: COLLATE + - collation_reference: + - naked_identifier: Latin1_General_BIN2 + - comma: ',' + - quoted_identifier: '[country_name]' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - keyword: COLLATE + - collation_reference: + - naked_identifier: Latin1_General_BIN2 + - numeric_literal: '2' + - comma: ',' + - quoted_identifier: '[year]' + - data_type: + - keyword: smallint + - comma: ',' + - quoted_identifier: '[population]' + - data_type: + - keyword: bigint + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: rows + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - expression: + - integer_literal: '1' + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openrowset_segment: + - keyword: OPENROWSET + - bracketed: + - start_bracket: ( + - keyword: BULK + - quoted_literal: '''https://azureopendatastorage.blob.core.windows.net/censusdatacontainer/release/us_population_county/year=20*/*.parquet''' + - comma: ',' + - keyword: FORMAT + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''PARQUET''' + - end_bracket: ) + - openrowset_with_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - quoted_identifier: '[stateName]' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - comma: ',' + - quoted_identifier: '[stateName_explicit_path]' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - quoted_literal: '''$.stateName''' + - comma: ',' + - quoted_identifier: '[COUNTYNAME]' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - comma: ',' + - quoted_identifier: '[countyName_explicit_path]' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - quoted_literal: '''$.COUNTYNAME''' + - comma: ',' + - quoted_identifier: '[population]' + - data_type: + - keyword: bigint + - quoted_literal: '''strict $.population''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[r]' + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openxml.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openxml.sql new file mode 100644 index 000000000..1cc86b7b7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openxml.sql @@ -0,0 +1,39 @@ +-- https://learn.microsoft.com/en-us/sql/t-sql/functions/openxml-transact-sql +-- https://learn.microsoft.com/en-us/sql/relational-databases/xml/specify-metaproperties-in-openxml + +SELECT col1 +FROM + OPENXML (@iDoc, N'root/search', 1); + +SELECT col1 +FROM + OPENXML (@iDoc, N'root/search', 1) + WITH ( + CustomerID VARCHAR(10), + ContactName VARCHAR(20) + ); + +SELECT * +FROM OPENXML(@idoc, '/ROOT/Customer/Order/OrderDetail') +WITH ( + OrderID INT '../@OrderID', + CustomerID VARCHAR(10) '../@CustomerID', + OrderDate DATETIME '../@OrderDate', + ProdID INT '@ProductID', + Qty INT '@Quantity' +); + +-- Specifying TableName in the WITH clause +SELECT * +FROM OPENXML (@docHandle, '/root/Customer/Order', 1) +WITH T1; + +-- metaproperties example +SELECT * +FROM OPENXML (@idoc, '/root/Customer/Order', 9) +WITH (id int '@mp:id', + oid char(5), + date datetime, + amount real, + parentIDNo int '@mp:parentid', + parentLocalName varchar(40) '@mp:parentlocalname'); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openxml.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openxml.yml new file mode 100644 index 000000000..015ace8ba --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/openxml.yml @@ -0,0 +1,220 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openxml_segment: + - keyword: OPENXML + - bracketed: + - start_bracket: ( + - parameter: '@iDoc' + - comma: ',' + - quoted_literal: N'root/search' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openxml_segment: + - keyword: OPENXML + - bracketed: + - start_bracket: ( + - parameter: '@iDoc' + - comma: ',' + - quoted_literal: N'root/search' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - keyword: WITH + - bracketed: + - start_bracket: ( + - naked_identifier: CustomerID + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - comma: ',' + - naked_identifier: ContactName + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '20' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openxml_segment: + - keyword: OPENXML + - bracketed: + - start_bracket: ( + - parameter: '@idoc' + - comma: ',' + - quoted_literal: '''/ROOT/Customer/Order/OrderDetail''' + - end_bracket: ) + - keyword: WITH + - bracketed: + - start_bracket: ( + - naked_identifier: OrderID + - data_type: + - keyword: INT + - quoted_literal: '''../@OrderID''' + - comma: ',' + - naked_identifier: CustomerID + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - quoted_literal: '''../@CustomerID''' + - comma: ',' + - naked_identifier: OrderDate + - data_type: + - keyword: DATETIME + - quoted_literal: '''../@OrderDate''' + - comma: ',' + - naked_identifier: ProdID + - data_type: + - keyword: INT + - quoted_literal: '''@ProductID''' + - comma: ',' + - naked_identifier: Qty + - data_type: + - keyword: INT + - quoted_literal: '''@Quantity''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openxml_segment: + - keyword: OPENXML + - bracketed: + - start_bracket: ( + - parameter: '@docHandle' + - comma: ',' + - quoted_literal: '''/root/Customer/Order''' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - keyword: WITH + - table_reference: + - naked_identifier: T1 + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - openxml_segment: + - keyword: OPENXML + - bracketed: + - start_bracket: ( + - parameter: '@idoc' + - comma: ',' + - quoted_literal: '''/root/Customer/Order''' + - comma: ',' + - numeric_literal: '9' + - end_bracket: ) + - keyword: WITH + - bracketed: + - start_bracket: ( + - naked_identifier: id + - data_type: + - keyword: int + - quoted_literal: '''@mp:id''' + - comma: ',' + - naked_identifier: oid + - data_type: + - keyword: char + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '5' + - end_bracket: ) + - comma: ',' + - naked_identifier: date + - data_type: + - keyword: datetime + - comma: ',' + - naked_identifier: amount + - data_type: + - keyword: real + - comma: ',' + - naked_identifier: parentIDNo + - data_type: + - keyword: int + - quoted_literal: '''@mp:parentid''' + - comma: ',' + - naked_identifier: parentLocalName + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '40' + - end_bracket: ) + - quoted_literal: '''@mp:parentlocalname''' + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/outer_apply.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/outer_apply.sql new file mode 100644 index 000000000..c2abf84f4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/outer_apply.sql @@ -0,0 +1,7 @@ +-- JOIN should not be parsed as nested in OUTER APPLY +SELECT table1.* +FROM table1 +OUTER APPLY table2 +INNER JOIN table3 + ON table1.col = table3.col +WHERE table1.Column1 ='blah'; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/outer_apply.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/outer_apply.yml new file mode 100644 index 000000000..1f5d3fcbf --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/outer_apply.yml @@ -0,0 +1,57 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - naked_identifier: table1 + - dot: . + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - join_clause: + - keyword: OUTER + - keyword: APPLY + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table3 + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: col + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: table3 + - dot: . + - naked_identifier: col + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: table1 + - dot: . + - naked_identifier: Column1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''blah''' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/output_clause.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/output_clause.sql new file mode 100644 index 000000000..e15fa92cd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/output_clause.sql @@ -0,0 +1,165 @@ +-- OUTPUT clause tests +-- https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql + +-- Example 1: OUTPUT with DELETE (no INTO) - wildcard +DELETE Sales.ShoppingCartItem +OUTPUT DELETED.* +WHERE ShoppingCartID = 20621; +GO + +-- Example 2: OUTPUT with DELETE - specific columns +DELETE Sales.ShoppingCartItem +OUTPUT DELETED.ProductID, DELETED.Quantity +WHERE ShoppingCartID = 20621; +GO + +-- Example 3: OUTPUT with DELETE - column with alias +DELETE Sales.ShoppingCartItem +OUTPUT DELETED.ProductID AS RemovedProductID +WHERE ShoppingCartID = 20621; +GO + +-- Example 4: OUTPUT INTO with DELETE +DECLARE @DeletedRows TABLE ( + ProductID INT, + Quantity INT +); + +DELETE Sales.ShoppingCartItem +OUTPUT DELETED.ProductID, DELETED.Quantity +INTO @DeletedRows +WHERE ShoppingCartID = 20621; +GO + +-- Example 5: OUTPUT INTO with table variable and column list +DECLARE @MyTableVar TABLE ( + NewScrapReasonID SMALLINT, + Name VARCHAR(50), + ModifiedDate DATETIME +); + +INSERT Production.ScrapReason +OUTPUT INSERTED.ScrapReasonID, INSERTED.Name, INSERTED.ModifiedDate +INTO @MyTableVar +VALUES (N'Operator error', GETDATE()); +GO + +-- Example 6: OUTPUT with INSERT - no INTO +INSERT Production.ScrapReason +OUTPUT INSERTED.ScrapReasonID, INSERTED.Name +VALUES (N'Operator error', GETDATE()); +GO + +-- Example 7: OUTPUT with UPDATE - DELETED and INSERTED +DECLARE @UpdatedRows TABLE ( + EmpID INT NOT NULL, + OldVacationHours INT, + NewVacationHours INT +); + +UPDATE HumanResources.Employee +SET VacationHours = VacationHours * 1.25 +OUTPUT INSERTED.BusinessEntityID, + DELETED.VacationHours, + INSERTED.VacationHours +INTO @UpdatedRows +WHERE BusinessEntityID < 10; +GO + +-- Example 8: OUTPUT with expression +UPDATE HumanResources.Employee +SET VacationHours = VacationHours * 1.25 +OUTPUT INSERTED.BusinessEntityID, + DELETED.VacationHours AS OldValue, + INSERTED.VacationHours AS NewValue, + INSERTED.VacationHours - DELETED.VacationHours AS Difference +WHERE BusinessEntityID < 10; +GO + +-- Example 9: OUTPUT with from_table_name in UPDATE +DECLARE @MyTestVar TABLE ( + OldScrapReasonID INT, + NewScrapReasonID INT, + WorkOrderID INT, + ProductID INT, + ProductName NVARCHAR(50) +); + +UPDATE Production.WorkOrder +SET ScrapReasonID = 4 +OUTPUT DELETED.ScrapReasonID, + INSERTED.ScrapReasonID, + INSERTED.WorkOrderID, + INSERTED.ProductID, + p.Name +INTO @MyTestVar +FROM Production.WorkOrder AS wo +INNER JOIN Production.Product AS p + ON wo.ProductID = p.ProductID +WHERE wo.ScrapReasonID = 16; +GO + +-- Example 10: OUTPUT with MERGE and $ACTION +DECLARE @SummaryOfChanges TABLE ( + ChangeType NVARCHAR(10), + ProductID INT +); + +MERGE Production.ProductInventory AS target +USING (SELECT ProductID, SUM(OrderQty) AS TotalQty + FROM Sales.SalesOrderDetail + GROUP BY ProductID) AS source +ON target.ProductID = source.ProductID +WHEN MATCHED AND target.Quantity - source.TotalQty <= 0 THEN + DELETE +WHEN MATCHED THEN + UPDATE SET target.Quantity = target.Quantity - source.TotalQty +OUTPUT $ACTION, DELETED.ProductID +INTO @SummaryOfChanges; +GO + +-- Example 11: OUTPUT without INTO in MERGE +MERGE Production.ProductInventory AS target +USING (SELECT ProductID, SUM(OrderQty) AS TotalQty + FROM Sales.SalesOrderDetail + GROUP BY ProductID) AS source +ON target.ProductID = source.ProductID +WHEN MATCHED THEN + UPDATE SET target.Quantity = target.Quantity - source.TotalQty +OUTPUT $ACTION, INSERTED.ProductID, INSERTED.Quantity; +GO + +-- Example 12: OUTPUT with table reference (real table, not variable) +CREATE TABLE #OutputTable ( + ProductID INT, + DeletedQuantity INT +); + +DELETE Sales.ShoppingCartItem +OUTPUT DELETED.ProductID, DELETED.Quantity +INTO #OutputTable +WHERE ShoppingCartID = 20621; +GO + +-- Example 13: OUTPUT with INTO and column list +DECLARE @Results TABLE ( + ProdID INT, + Qty INT +); + +DELETE Sales.ShoppingCartItem +OUTPUT DELETED.ProductID, DELETED.Quantity +INTO @Results (ProdID, Qty) +WHERE ShoppingCartID = 20621; +GO + +-- Example 14: Multiple columns in OUTPUT with various expressions +UPDATE Production.Product +SET ListPrice = ListPrice * 1.1 +OUTPUT INSERTED.ProductID, + DELETED.ListPrice, + INSERTED.ListPrice, + GETDATE() AS UpdateDate, + SYSTEM_USER AS UpdatedBy +WHERE ProductID = 680; +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/output_clause.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/output_clause.yml new file mode 100644 index 000000000..f72cabf29 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/output_clause.yml @@ -0,0 +1,936 @@ +file: +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: ShoppingCartItem + - output_clause: + - keyword: OUTPUT + - keyword: DELETED + - dot: . + - wildcard_identifier: + - star: '*' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ShoppingCartID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '20621' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: ShoppingCartItem + - output_clause: + - keyword: OUTPUT + - keyword: DELETED + - dot: . + - naked_identifier: ProductID + - comma: ',' + - keyword: DELETED + - dot: . + - naked_identifier: Quantity + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ShoppingCartID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '20621' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: ShoppingCartItem + - output_clause: + - keyword: OUTPUT + - keyword: DELETED + - dot: . + - naked_identifier: ProductID + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: RemovedProductID + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ShoppingCartID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '20621' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@DeletedRows' + - keyword: TABLE + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: ProductID + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: Quantity + - data_type: + - keyword: INT + - end_bracket: ) + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: ShoppingCartItem + - output_clause: + - keyword: OUTPUT + - keyword: DELETED + - dot: . + - naked_identifier: ProductID + - comma: ',' + - keyword: DELETED + - dot: . + - naked_identifier: Quantity + - keyword: INTO + - parameter: '@DeletedRows' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ShoppingCartID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '20621' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@MyTableVar' + - keyword: TABLE + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: NewScrapReasonID + - data_type: + - keyword: SMALLINT + - comma: ',' + - column_definition: + - naked_identifier: Name + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: ModifiedDate + - data_type: + - keyword: DATETIME + - end_bracket: ) + - statement_terminator: ; + - statement: + - insert_statement: + - keyword: INSERT + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ScrapReason + - output_clause: + - keyword: OUTPUT + - keyword: INSERTED + - dot: . + - naked_identifier: ScrapReasonID + - comma: ',' + - keyword: INSERTED + - dot: . + - naked_identifier: Name + - comma: ',' + - keyword: INSERTED + - dot: . + - naked_identifier: ModifiedDate + - keyword: INTO + - parameter: '@MyTableVar' + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - quoted_literal: N'Operator error' + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - insert_statement: + - keyword: INSERT + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ScrapReason + - output_clause: + - keyword: OUTPUT + - keyword: INSERTED + - dot: . + - naked_identifier: ScrapReasonID + - comma: ',' + - keyword: INSERTED + - dot: . + - naked_identifier: Name + - values_clause: + - keyword: VALUES + - bracketed: + - start_bracket: ( + - quoted_literal: N'Operator error' + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@UpdatedRows' + - keyword: TABLE + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: EmpID + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: OldVacationHours + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: NewVacationHours + - data_type: + - keyword: INT + - end_bracket: ) + - statement_terminator: ; + - statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: Employee + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: VacationHours + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: VacationHours + - binary_operator: '*' + - numeric_literal: '1.25' + - output_clause: + - keyword: OUTPUT + - keyword: INSERTED + - dot: . + - naked_identifier: BusinessEntityID + - comma: ',' + - keyword: DELETED + - dot: . + - naked_identifier: VacationHours + - comma: ',' + - keyword: INSERTED + - dot: . + - naked_identifier: VacationHours + - keyword: INTO + - parameter: '@UpdatedRows' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: BusinessEntityID + - comparison_operator: + - raw_comparison_operator: < + - integer_literal: '10' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: Employee + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: VacationHours + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: VacationHours + - binary_operator: '*' + - numeric_literal: '1.25' + - output_clause: + - keyword: OUTPUT + - keyword: INSERTED + - dot: . + - naked_identifier: BusinessEntityID + - comma: ',' + - keyword: DELETED + - dot: . + - naked_identifier: VacationHours + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: OldValue + - comma: ',' + - keyword: INSERTED + - dot: . + - naked_identifier: VacationHours + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: NewValue + - comma: ',' + - expression: + - column_reference: + - naked_identifier: INSERTED + - dot: . + - naked_identifier: VacationHours + - binary_operator: '-' + - column_reference: + - naked_identifier: DELETED + - dot: . + - naked_identifier: VacationHours + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Difference + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: BusinessEntityID + - comparison_operator: + - raw_comparison_operator: < + - integer_literal: '10' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@MyTestVar' + - keyword: TABLE + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: OldScrapReasonID + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: NewScrapReasonID + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: WorkOrderID + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: ProductID + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: ProductName + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: WorkOrder + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: ScrapReasonID + - assignment_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '4' + - output_clause: + - keyword: OUTPUT + - keyword: DELETED + - dot: . + - naked_identifier: ScrapReasonID + - comma: ',' + - keyword: INSERTED + - dot: . + - naked_identifier: ScrapReasonID + - comma: ',' + - keyword: INSERTED + - dot: . + - naked_identifier: WorkOrderID + - comma: ',' + - keyword: INSERTED + - dot: . + - naked_identifier: ProductID + - comma: ',' + - naked_identifier: p + - dot: . + - naked_identifier: Name + - keyword: INTO + - parameter: '@MyTestVar' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: WorkOrder + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: wo + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: Product + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: p + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: wo + - dot: . + - naked_identifier: ProductID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: ProductID + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: wo + - dot: . + - naked_identifier: ScrapReasonID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '16' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@SummaryOfChanges' + - keyword: TABLE + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: ChangeType + - data_type: + - keyword: NVARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - comma: ',' + - column_definition: + - naked_identifier: ProductID + - data_type: + - keyword: INT + - end_bracket: ) + - statement_terminator: ; + - statement: + - merge_statement: + - keyword: MERGE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ProductInventory + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: target + - keyword: USING + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ProductID + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: TotalQty + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderDetail + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: ProductID + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: source + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: target + - dot: . + - naked_identifier: ProductID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: ProductID + - merge_match: + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: AND + - expression: + - column_reference: + - naked_identifier: target + - dot: . + - naked_identifier: Quantity + - binary_operator: '-' + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: TotalQty + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - integer_literal: '0' + - keyword: THEN + - merge_delete_clause: + - keyword: DELETE + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: THEN + - merge_update_clause: + - keyword: UPDATE + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: target + - dot: . + - naked_identifier: Quantity + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: target + - dot: . + - naked_identifier: Quantity + - binary_operator: '-' + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: TotalQty + - output_clause: + - keyword: OUTPUT + - action_parameter: $ACTION + - comma: ',' + - keyword: DELETED + - dot: . + - naked_identifier: ProductID + - keyword: INTO + - parameter: '@SummaryOfChanges' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - merge_statement: + - keyword: MERGE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ProductInventory + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: target + - keyword: USING + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ProductID + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: TotalQty + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderDetail + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: ProductID + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: source + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: target + - dot: . + - naked_identifier: ProductID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: ProductID + - merge_match: + - merge_when_matched_clause: + - keyword: WHEN + - keyword: MATCHED + - keyword: THEN + - merge_update_clause: + - keyword: UPDATE + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: target + - dot: . + - naked_identifier: Quantity + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: target + - dot: . + - naked_identifier: Quantity + - binary_operator: '-' + - column_reference: + - naked_identifier: source + - dot: . + - naked_identifier: TotalQty + - output_clause: + - keyword: OUTPUT + - action_parameter: $ACTION + - comma: ',' + - keyword: INSERTED + - dot: . + - naked_identifier: ProductID + - comma: ',' + - keyword: INSERTED + - dot: . + - naked_identifier: Quantity + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - hash_identifier: '#OutputTable' + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: ProductID + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: DeletedQuantity + - data_type: + - keyword: INT + - end_bracket: ) + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: ShoppingCartItem + - output_clause: + - keyword: OUTPUT + - keyword: DELETED + - dot: . + - naked_identifier: ProductID + - comma: ',' + - keyword: DELETED + - dot: . + - naked_identifier: Quantity + - keyword: INTO + - table_reference: + - hash_identifier: '#OutputTable' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ShoppingCartID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '20621' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@Results' + - keyword: TABLE + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: ProdID + - data_type: + - keyword: INT + - comma: ',' + - column_definition: + - naked_identifier: Qty + - data_type: + - keyword: INT + - end_bracket: ) + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: ShoppingCartItem + - output_clause: + - keyword: OUTPUT + - keyword: DELETED + - dot: . + - naked_identifier: ProductID + - comma: ',' + - keyword: DELETED + - dot: . + - naked_identifier: Quantity + - keyword: INTO + - parameter: '@Results' + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: ProdID + - comma: ',' + - column_reference: + - naked_identifier: Qty + - end_bracket: ) + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ShoppingCartID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '20621' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: Product + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: ListPrice + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: ListPrice + - binary_operator: '*' + - numeric_literal: '1.1' + - output_clause: + - keyword: OUTPUT + - keyword: INSERTED + - dot: . + - naked_identifier: ProductID + - comma: ',' + - keyword: DELETED + - dot: . + - naked_identifier: ListPrice + - comma: ',' + - keyword: INSERTED + - dot: . + - naked_identifier: ListPrice + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: UpdateDate + - comma: ',' + - expression: + - bare_function: SYSTEM_USER + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: UpdatedBy + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ProductID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '680' + - statement_terminator: ; + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/print.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/print.sql new file mode 100644 index 000000000..a246b0bc5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/print.sql @@ -0,0 +1,8 @@ +DECLARE @TestVal VARCHAR(20) = 'Test Print' + + +PRINT '#Dates' + +PRINT CAST(GETDATE() AS VARCHAR(50)); + +PRINT @TestVal diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/print.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/print.yml new file mode 100644 index 000000000..b30b3b0d8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/print.yml @@ -0,0 +1,57 @@ +file: +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@TestVal' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '20' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''Test Print''' + - statement: + - print_statement: + - keyword: PRINT + - expression: + - quoted_literal: '''#Dates''' + - statement: + - print_statement: + - keyword: PRINT + - expression: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - keyword: AS + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - print_statement: + - keyword: PRINT + - expression: + - parameter: '@TestVal' diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/raiserror.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/raiserror.sql new file mode 100644 index 000000000..8a6713b79 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/raiserror.sql @@ -0,0 +1,42 @@ +RAISERROR(15600, -1, -1, 'mysp_CreateCustomer'); + +RAISERROR('This is message %s %d.', 10, 1, 'number'); + +RAISERROR('Error raised in TRY block.', 16, 1); + +RAISERROR (N'Unicode error', 16, 1); + +RAISERROR ('WITH option', 16, 1) WITH LOG; + +RAISERROR ('Error with lots of arguments %a %b %c %d %e %f %g %h %i %j %k %l %m %n %o %p %q %r %s %t', 16, 1, + 'a', + N'b', + @c, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20); + +RAISERROR (@ErrorMessage, -- Message text. + @ErrorSeverity, -- Severity. + @ErrorState -- State. + ); + +RAISERROR ( + 'The specified table does not exist. Please enter @tableName in the following format: Schemaname.Tablename OR [Schemaname].[Tablename]' + ,11 + ,- 1 + ); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/raiserror.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/raiserror.yml new file mode 100644 index 000000000..a545f167e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/raiserror.yml @@ -0,0 +1,154 @@ +file: +- batch: + - statement: + - raiserror_statement: + - keyword: RAISERROR + - bracketed: + - start_bracket: ( + - numeric_literal: '15600' + - comma: ',' + - expression: + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '1' + - comma: ',' + - expression: + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '1' + - comma: ',' + - expression: + - quoted_literal: '''mysp_CreateCustomer''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - raiserror_statement: + - keyword: RAISERROR + - bracketed: + - start_bracket: ( + - quoted_literal: '''This is message %s %d.''' + - comma: ',' + - numeric_literal: '10' + - comma: ',' + - numeric_literal: '1' + - comma: ',' + - quoted_literal: '''number''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - raiserror_statement: + - keyword: RAISERROR + - bracketed: + - start_bracket: ( + - quoted_literal: '''Error raised in TRY block.''' + - comma: ',' + - numeric_literal: '16' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - statement_terminator: ; + - statement: + - raiserror_statement: + - keyword: RAISERROR + - bracketed: + - start_bracket: ( + - quoted_literal: N'Unicode error' + - comma: ',' + - numeric_literal: '16' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - statement_terminator: ; + - statement: + - raiserror_statement: + - keyword: RAISERROR + - bracketed: + - start_bracket: ( + - quoted_literal: '''WITH option''' + - comma: ',' + - numeric_literal: '16' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - keyword: WITH + - keyword: LOG + - statement_terminator: ; + - statement: + - raiserror_statement: + - keyword: RAISERROR + - bracketed: + - start_bracket: ( + - quoted_literal: '''Error with lots of arguments %a %b %c %d %e %f %g %h %i %j %k %l %m %n %o %p %q %r %s %t''' + - comma: ',' + - numeric_literal: '16' + - comma: ',' + - numeric_literal: '1' + - comma: ',' + - quoted_literal: '''a''' + - comma: ',' + - quoted_literal: N'b' + - comma: ',' + - parameter: '@c' + - comma: ',' + - numeric_literal: '4' + - comma: ',' + - numeric_literal: '5' + - comma: ',' + - numeric_literal: '6' + - comma: ',' + - numeric_literal: '7' + - comma: ',' + - numeric_literal: '8' + - comma: ',' + - numeric_literal: '9' + - comma: ',' + - numeric_literal: '10' + - comma: ',' + - numeric_literal: '11' + - comma: ',' + - numeric_literal: '12' + - comma: ',' + - numeric_literal: '13' + - comma: ',' + - numeric_literal: '14' + - comma: ',' + - numeric_literal: '15' + - comma: ',' + - numeric_literal: '16' + - comma: ',' + - numeric_literal: '17' + - comma: ',' + - numeric_literal: '18' + - comma: ',' + - numeric_literal: '19' + - comma: ',' + - numeric_literal: '20' + - end_bracket: ) + - statement_terminator: ; + - statement: + - raiserror_statement: + - keyword: RAISERROR + - bracketed: + - start_bracket: ( + - parameter: '@ErrorMessage' + - comma: ',' + - parameter: '@ErrorSeverity' + - comma: ',' + - parameter: '@ErrorState' + - end_bracket: ) + - statement_terminator: ; + - statement: + - raiserror_statement: + - keyword: RAISERROR + - bracketed: + - start_bracket: ( + - quoted_literal: '''The specified table does not exist. Please enter @tableName in the following format: Schemaname.Tablename OR [Schemaname].[Tablename]''' + - comma: ',' + - numeric_literal: '11' + - comma: ',' + - expression: + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '1' + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/reconfigure.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/reconfigure.sql new file mode 100644 index 000000000..9c2a4fcb0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/reconfigure.sql @@ -0,0 +1,3 @@ +RECONFIGURE; + +RECONFIGURE WITH OVERRIDE; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/reconfigure.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/reconfigure.yml new file mode 100644 index 000000000..0a0b5533e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/reconfigure.yml @@ -0,0 +1,12 @@ +file: +- batch: + - statement: + - reconfigure_statement: + - keyword: RECONFIGURE + - statement_terminator: ; + - statement: + - reconfigure_statement: + - keyword: RECONFIGURE + - keyword: WITH + - keyword: OVERRIDE + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/rename_table.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/rename_table.sql new file mode 100644 index 000000000..6f3cc625a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/rename_table.sql @@ -0,0 +1,2 @@ +--Azure Synapse Analytics specific +RENAME OBJECT [Reporting].[TABLE_NEW] to [TABLE_BASE]; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/rename_table.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/rename_table.yml new file mode 100644 index 000000000..fd6b7f944 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/rename_table.yml @@ -0,0 +1,13 @@ +file: +- batch: + - statement: + - rename_statement: + - keyword: RENAME + - keyword: OBJECT + - object_reference: + - quoted_identifier: '[Reporting]' + - dot: . + - quoted_identifier: '[TABLE_NEW]' + - keyword: to + - quoted_identifier: '[TABLE_BASE]' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/replicate.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/replicate.sql new file mode 100644 index 000000000..d6db2764f --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/replicate.sql @@ -0,0 +1,6 @@ +SELECT REPLICATE('0', 3 - DATALENGTH(c1)) + c1 AS 'Varchar Column', + REPLICATE('0', 3 - DATALENGTH(c2)) + c2 AS 'Char Column' +FROM t1; + +DECLARE @BinVar varbinary(128); +SET @BinVar = CAST(REPLICATE(0x20, 128) AS varbinary(128) ); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/replicate.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/replicate.yml new file mode 100644 index 000000000..fa74ca78e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/replicate.yml @@ -0,0 +1,129 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - function: + - function_name: + - keyword: REPLICATE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''0''' + - comma: ',' + - expression: + - integer_literal: '3' + - binary_operator: '-' + - function: + - function_name: + - function_name_identifier: DATALENGTH + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c1 + - end_bracket: ) + - end_bracket: ) + - binary_operator: + + - column_reference: + - naked_identifier: c1 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '''Varchar Column''' + - comma: ',' + - select_clause_element: + - expression: + - function: + - function_name: + - keyword: REPLICATE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - quoted_literal: '''0''' + - comma: ',' + - expression: + - integer_literal: '3' + - binary_operator: '-' + - function: + - function_name: + - function_name_identifier: DATALENGTH + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: c2 + - end_bracket: ) + - end_bracket: ) + - binary_operator: + + - column_reference: + - naked_identifier: c2 + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '''Char Column''' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: t1 + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@BinVar' + - data_type: + - keyword: varbinary + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '128' + - end_bracket: ) + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@BinVar' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - keyword: REPLICATE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - binary_literal: '0x20' + - comma: ',' + - expression: + - integer_literal: '128' + - end_bracket: ) + - keyword: AS + - data_type: + - keyword: varbinary + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '128' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select.sql index 4369aa91c..ad0bb1fa1 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select.sql +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select.sql @@ -1 +1,121 @@ +--For testing valid select clause elements +SELECT + CASE WHEN 1 = 1 THEN 'True' + WHEN 1 > 1 THEN 'False' + WHEN 1 < 1 THEN 'False' + WHEN 1 >= 1 THEN 'True' + WHEN 1 > = 1 THEN 'True' + WHEN 1 <= 1 THEN 'True' + WHEN 1 < = 1 THEN 'True' + WHEN 1 <> 1 THEN 'False' + WHEN 1 < > 1 THEN 'False' + WHEN 1 !< 1 THEN 'Why is this a thing?' + WHEN 1 ! + < 1 THEN 'Or this sort of thing?' + WHEN 1 != 1 THEN 'False' + WHEN 1 ! = 1 THEN 'False' + WHEN 1 !> 1 THEN 'NULL Handling, Probably' + WHEN 1 ! > 1 THEN 'NULL Handling, Probably' + ELSE 'Silly Tests' + END, + all_pop. [Arrival Date], + all_pop.Row#, + all_pop.b@nanas, + [# POAs], + 'TSQLs escaping quotes test', + 'TSQL''s escaping quotes test', + 'TSQL' 's escaping quotes test', + 'TSQL' AS 's escaping quotes test', + '', + '''', + + --unreserved words + all_pop.Language, + ANSI_DEFAULTS , + ANSI_NULL_DFLT_OFF , + ANSI_NULL_DFLT_ON , + ANSI_NULLS , + ANSI_PADDING , + ANSI_WARNINGS , + ARITHABORT , + ARITHIGNORE , + CONCAT_NULL_YIELDS_NULL , + CURSOR_CLOSE_ON_COMMIT , + DATEFIRST , + DATEFORMAT , + DEADLOCK_PRIORITY , + FIPS_FLAGGER , + FMTONLY , + FORCEPLAN , + IMPLICIT_TRANSACTIONS , + LOCK_TIMEOUT , + NOCOUNT , + NOEXEC , + NUMERIC_ROUNDABORT , + PARSEONLY , + PROPERTY , + QUERY_GOVERNOR_COST_LIMIT , + QUOTED_IDENTIFIER , + REMOTE_PROC_TRANSACTIONS , + SHOWPLAN_ALL , + SHOWPLAN_TEXT , + SHOWPLAN_XML , + XACT_ABORT, + + --TSQL non-keywords + Rows, + NaN, + Rlike, + Ilike, + Separator, + Auto_Increment, + Unsigned, + Describe, + Comment, + Ml, + Modify, + Minus, + + ROW_NUMBER()OVER(PARTITION BY [EventNM], [PersonID] ORDER BY [DateofEvent] desc) AS [RN], + RANK()OVER(PARTITION BY [EventNM] ORDER BY [DateofEvent] desc) AS [R], + DENSE_RANK()OVER(PARTITION BY [EventNM] ORDER BY [DateofEvent] desc) AS [DR], + NTILE(5)OVER(PARTITION BY [EventNM] ORDER BY [DateofEvent] desc) AS [NT], + sum(t.col1) over (partition by t.col2, t.col3), + + ROW_NUMBER() OVER (PARTITION BY (SELECT mediaty FROM dbo.MediaTypes ms WHERE ms.MediaTypeID = f.mediatypeid) ORDER BY AdjustedPriorityScore DESC) AS Subselect_Partition, + + ROW_NUMBER() OVER (PARTITION BY COALESCE(NPI1, NPI2) ORDER BY COALESCE(SystemEffectiveDTS1, SystemEffectiveDTS2) DESC) AS Coalesce_Partition, + + ROW_NUMBER() OVER (PARTITION BY (DayInMonth), (DaySuffix) ORDER BY Month ASC), + COUNT(*) OVER (PARTITION BY NULL), + + [preceding] = count(*) over(order by object_id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ), + [central] = count(*) over(order by object_id ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING ), + [following] = count(*) over(order by object_id ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING), + + EqualsAlias = ColumnName, + OtherColumnName AS AsAlias, + cast(1 as character varying(1)), + cast([central] as int), + + --unbracketed functions + CURRENT_TIMESTAMP, + CURRENT_USER, + SESSION_USER, + SYSTEM_USER, + USER, + + test(default, 2) + + +FROM dbo . all_pop; + SELECT DISTINCT TOP 5 some_value FROM some_table; + +select + 'Tabellen' as Objekt, + Count(*) as Anzahl +from dbo.sql_modules; + +-- naked identifier with extended Unicode characters +select field1 AS 日期差多少天; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select.yml index 0e3ae7aab..a2f329f86 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select.yml +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select.yml @@ -1,22 +1,983 @@ file: -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_modifier: - - keyword: DISTINCT - - keyword: TOP - - expression: - - numeric_literal: '5' - - select_clause_element: - - column_reference: - - naked_identifier: some_value - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''True''' + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: '>' + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''False''' + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: < + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''False''' + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''True''' + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: '>' + - raw_comparison_operator: = + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''True''' + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''True''' + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: = + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''True''' + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: '>' + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''False''' + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: '>' + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''False''' + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: '!' + - raw_comparison_operator: < + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''Why is this a thing?''' + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: '!' + - raw_comparison_operator: < + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''Or this sort of thing?''' + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: '!' + - raw_comparison_operator: = + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''False''' + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: '!' + - raw_comparison_operator: = + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''False''' + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: '!' + - raw_comparison_operator: '>' + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''NULL Handling, Probably''' + - when_clause: + - keyword: WHEN + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: '!' + - raw_comparison_operator: '>' + - integer_literal: '1' + - keyword: THEN + - expression: + - quoted_literal: '''NULL Handling, Probably''' + - else_clause: + - keyword: ELSE + - expression: + - quoted_literal: '''Silly Tests''' + - keyword: END + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: all_pop + - dot: . + - quoted_identifier: '[Arrival Date]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: all_pop + - dot: . + - naked_identifier: Row# + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: all_pop + - dot: . + - naked_identifier: b@nanas + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[# POAs]' + - comma: ',' + - select_clause_element: + - quoted_literal: '''TSQLs escaping quotes test''' + - comma: ',' + - select_clause_element: + - quoted_literal: '''TSQL''''s escaping quotes test''' + - comma: ',' + - select_clause_element: + - quoted_literal: '''TSQL''' + - alias_expression: + - quoted_identifier: '''s escaping quotes test''' + - comma: ',' + - select_clause_element: + - quoted_literal: '''TSQL''' + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '''s escaping quotes test''' + - comma: ',' + - select_clause_element: + - quoted_literal: '''''' + - comma: ',' + - select_clause_element: + - quoted_literal: '''''''''' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: all_pop + - dot: . + - naked_identifier: Language + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ANSI_DEFAULTS + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ANSI_NULL_DFLT_OFF + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ANSI_NULL_DFLT_ON + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ANSI_NULLS + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ANSI_PADDING + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ANSI_WARNINGS + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ARITHABORT + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ARITHIGNORE + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: CONCAT_NULL_YIELDS_NULL + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: CURSOR_CLOSE_ON_COMMIT + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: DATEFIRST + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: DATEFORMAT + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: DEADLOCK_PRIORITY + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: FIPS_FLAGGER + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: FMTONLY + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: FORCEPLAN + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: IMPLICIT_TRANSACTIONS + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: LOCK_TIMEOUT + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: NOCOUNT + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: NOEXEC + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: NUMERIC_ROUNDABORT + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: PARSEONLY + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: PROPERTY + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: QUERY_GOVERNOR_COST_LIMIT + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: QUOTED_IDENTIFIER + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: REMOTE_PROC_TRANSACTIONS + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: SHOWPLAN_ALL + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: SHOWPLAN_TEXT + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: SHOWPLAN_XML + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: XACT_ABORT + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Rows + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: NaN + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Rlike + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Ilike + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Separator + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Auto_Increment + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Unsigned + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Describe + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Comment + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Ml + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Modify + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Minus + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: ROW_NUMBER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - column_reference: + - quoted_identifier: '[EventNM]' + - comma: ',' + - column_reference: + - quoted_identifier: '[PersonID]' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - quoted_identifier: '[DateofEvent]' + - keyword: desc + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[RN]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: RANK + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - column_reference: + - quoted_identifier: '[EventNM]' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - quoted_identifier: '[DateofEvent]' + - keyword: desc + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[R]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: DENSE_RANK + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - column_reference: + - quoted_identifier: '[EventNM]' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - quoted_identifier: '[DateofEvent]' + - keyword: desc + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[DR]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: NTILE + - function_contents: + - bracketed: + - start_bracket: ( + - numeric_literal: '5' + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - column_reference: + - quoted_identifier: '[EventNM]' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - quoted_identifier: '[DateofEvent]' + - keyword: desc + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[NT]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: sum + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col1 + - end_bracket: ) + - over_clause: + - keyword: over + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: partition + - keyword: by + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col2 + - comma: ',' + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col3 + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: ROW_NUMBER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: mediaty + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: MediaTypes + - alias_expression: + - naked_identifier: ms + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ms + - dot: . + - naked_identifier: MediaTypeID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: f + - dot: . + - naked_identifier: mediatypeid + - end_bracket: ) + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: AdjustedPriorityScore + - keyword: DESC + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Subselect_Partition + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: ROW_NUMBER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - expression: + - function: + - function_name: + - keyword: COALESCE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: NPI1 + - comma: ',' + - expression: + - column_reference: + - naked_identifier: NPI2 + - end_bracket: ) + - orderby_clause: + - keyword: ORDER + - keyword: BY + - expression: + - function: + - function_name: + - keyword: COALESCE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: SystemEffectiveDTS1 + - comma: ',' + - expression: + - column_reference: + - naked_identifier: SystemEffectiveDTS2 + - end_bracket: ) + - keyword: DESC + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Coalesce_Partition + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: ROW_NUMBER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: DayInMonth + - end_bracket: ) + - comma: ',' + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: DaySuffix + - end_bracket: ) + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: Month + - keyword: ASC + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: COUNT + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - expression: + - null_literal: 'NULL' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - alias_expression: + - quoted_identifier: '[preceding]' + - alias_operator: + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: count + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - over_clause: + - keyword: over + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: order + - keyword: by + - column_reference: + - naked_identifier: object_id + - frame_clause: + - keyword: ROWS + - keyword: BETWEEN + - keyword: UNBOUNDED + - keyword: PRECEDING + - keyword: AND + - keyword: CURRENT + - keyword: ROW + - end_bracket: ) + - comma: ',' + - select_clause_element: + - alias_expression: + - quoted_identifier: '[central]' + - alias_operator: + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: count + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - over_clause: + - keyword: over + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: order + - keyword: by + - column_reference: + - naked_identifier: object_id + - frame_clause: + - keyword: ROWS + - keyword: BETWEEN + - numeric_literal: '2' + - keyword: PRECEDING + - keyword: AND + - numeric_literal: '2' + - keyword: FOLLOWING + - end_bracket: ) + - comma: ',' + - select_clause_element: + - alias_expression: + - quoted_identifier: '[following]' + - alias_operator: + - raw_comparison_operator: = + - function: + - function_name: + - function_name_identifier: count + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - over_clause: + - keyword: over + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: order + - keyword: by + - column_reference: + - naked_identifier: object_id + - frame_clause: + - keyword: ROWS + - keyword: BETWEEN + - keyword: CURRENT + - keyword: ROW + - keyword: AND + - keyword: UNBOUNDED + - keyword: FOLLOWING + - end_bracket: ) + - comma: ',' + - select_clause_element: + - alias_expression: + - naked_identifier: EqualsAlias + - alias_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: ColumnName + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: OtherColumnName + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: AsAlias + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: cast + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '1' + - keyword: as + - data_type: + - keyword: character + - keyword: varying + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '1' + - end_bracket: ) + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: cast + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '[central]' + - keyword: as + - data_type: + - keyword: int + - end_bracket: ) + - comma: ',' + - select_clause_element: + - bare_function: CURRENT_TIMESTAMP + - comma: ',' + - select_clause_element: + - bare_function: CURRENT_USER + - comma: ',' + - select_clause_element: + - bare_function: SESSION_USER + - comma: ',' + - select_clause_element: + - bare_function: SYSTEM_USER + - comma: ',' + - select_clause_element: + - bare_function: USER + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: test + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - keyword: default + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: all_pop + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: DISTINCT + - keyword: TOP + - expression: + - integer_literal: '5' + - select_clause_element: + - column_reference: + - naked_identifier: some_value + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: - naked_identifier: some_table -- statement_terminator: ; + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - quoted_literal: '''Tabellen''' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: Objekt + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: Count + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: Anzahl + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: sql_modules + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: field1 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: 日期差多少天 + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_assign_parameter.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_assign_parameter.sql new file mode 100644 index 000000000..a8ecaf09b --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_assign_parameter.sql @@ -0,0 +1,38 @@ +select userid = c.id +from + mydb.myschema.customer c +where + c.name = 'drjwelch'; + +select @userid_parameter = c.id +from + mydb.myschema.customer c +where + c.name = 'drjwelch'; + +-- Multiple variable assignments in one SELECT +SELECT TOP 1 + @potential_match = [id], + @full_name = CONCAT(first_name, ' ', surname) +FROM [dbo].[authors]; + +-- Compound assignment operators +SELECT @counter += 1, @sum += amount +FROM transactions; + +SELECT @result *= factor +FROM coefficients +WHERE id = 1; + +SELECT @text_concat = @text_concat + ', ' + description +FROM items; + +-- Variable assignment with subquery +SELECT @max_price = (SELECT MAX(price) FROM products) +FROM dual; + +-- Mix of variable assignment and regular select +DECLARE @var1 INT, @var2 VARCHAR(50); +SELECT @var1 = id, @var2 = name, description +FROM employees +WHERE emp_id = 100; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_assign_parameter.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_assign_parameter.yml new file mode 100644 index 000000000..85033dab0 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_assign_parameter.yml @@ -0,0 +1,311 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - alias_expression: + - naked_identifier: userid + - alias_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: id + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: mydb + - dot: . + - naked_identifier: myschema + - dot: . + - naked_identifier: customer + - alias_expression: + - naked_identifier: c + - where_clause: + - keyword: where + - expression: + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''drjwelch''' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - select_variable_assignment: + - parameter: '@userid_parameter' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: id + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: mydb + - dot: . + - naked_identifier: myschema + - dot: . + - naked_identifier: customer + - alias_expression: + - naked_identifier: c + - where_clause: + - keyword: where + - expression: + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''drjwelch''' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - expression: + - integer_literal: '1' + - select_clause_element: + - select_variable_assignment: + - parameter: '@potential_match' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - quoted_identifier: '[id]' + - comma: ',' + - select_clause_element: + - select_variable_assignment: + - parameter: '@full_name' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: CONCAT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: first_name + - comma: ',' + - expression: + - quoted_literal: ''' ''' + - comma: ',' + - expression: + - column_reference: + - naked_identifier: surname + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[authors]' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - select_variable_assignment: + - parameter: '@counter' + - assignment_operator: + - binary_operator: + + - raw_comparison_operator: = + - expression: + - integer_literal: '1' + - comma: ',' + - select_clause_element: + - select_variable_assignment: + - parameter: '@sum' + - assignment_operator: + - binary_operator: + + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: amount + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: transactions + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - select_variable_assignment: + - parameter: '@result' + - assignment_operator: + - binary_operator: '*' + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: factor + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: coefficients + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: id + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - select_variable_assignment: + - parameter: '@text_concat' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - parameter: '@text_concat' + - binary_operator: + + - quoted_literal: ''', ''' + - binary_operator: + + - column_reference: + - naked_identifier: description + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: items + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - select_variable_assignment: + - parameter: '@max_price' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: MAX + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: price + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: products + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dual + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@var1' + - data_type: + - keyword: INT + - comma: ',' + - parameter: '@var2' + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - select_variable_assignment: + - parameter: '@var1' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: id + - comma: ',' + - select_clause_element: + - select_variable_assignment: + - parameter: '@var2' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: description + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: employees + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: emp_id + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '100' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_cross_apply.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_cross_apply.sql new file mode 100644 index 000000000..63a876287 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_cross_apply.sql @@ -0,0 +1,25 @@ +SELECT DeptID, DeptName, DeptMgrID, EmpID, EmpLastName, EmpSalary +FROM Departments d +CROSS APPLY dbo.GetReports(d.DeptMgrID) ; + +SELECT d.DeptID, d.DeptName, DeptMgrID, reps.EmpID, reps.EmpLastName, reps.EmpSalary +FROM Departments AS d +CROSS APPLY dbo.GetReports(d.DeptMgrID) AS reps +WHERE d.DeptMgrID = 10; + +SELECT * FROM Department D +OUTER APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID); + + +SELECT * FROM Department D +OUTER APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID) AS AllEmp +WHERE D.DepartmentId = 10; + + +select + s.column_id + , sp.value +from + table1 as s +cross apply + string_split(replace(s.some_path, '->', '{'), '{') as sp; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_cross_apply.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_cross_apply.yml new file mode 100644 index 000000000..9d712ddc8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_cross_apply.yml @@ -0,0 +1,293 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: DeptID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: DeptName + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: DeptMgrID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: EmpID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: EmpLastName + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: EmpSalary + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Departments + - alias_expression: + - naked_identifier: d + - join_clause: + - keyword: CROSS + - keyword: APPLY + - from_expression_element: + - table_expression: + - function: + - function_name: + - naked_identifier: dbo + - dot: . + - function_name_identifier: GetReports + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: DeptMgrID + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: DeptID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: DeptName + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: DeptMgrID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: reps + - dot: . + - naked_identifier: EmpID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: reps + - dot: . + - naked_identifier: EmpLastName + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: reps + - dot: . + - naked_identifier: EmpSalary + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Departments + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: d + - join_clause: + - keyword: CROSS + - keyword: APPLY + - from_expression_element: + - table_expression: + - function: + - function_name: + - naked_identifier: dbo + - dot: . + - function_name_identifier: GetReports + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: DeptMgrID + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: reps + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: d + - dot: . + - naked_identifier: DeptMgrID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '10' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Department + - alias_expression: + - naked_identifier: D + - join_clause: + - keyword: OUTER + - keyword: APPLY + - from_expression_element: + - table_expression: + - function: + - function_name: + - naked_identifier: dbo + - dot: . + - function_name_identifier: fn_GetAllEmployeeOfADepartment + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: D + - dot: . + - naked_identifier: DepartmentID + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Department + - alias_expression: + - naked_identifier: D + - join_clause: + - keyword: OUTER + - keyword: APPLY + - from_expression_element: + - table_expression: + - function: + - function_name: + - naked_identifier: dbo + - dot: . + - function_name_identifier: fn_GetAllEmployeeOfADepartment + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: D + - dot: . + - naked_identifier: DepartmentID + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: AllEmp + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: D + - dot: . + - naked_identifier: DepartmentId + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '10' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: column_id + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: sp + - dot: . + - naked_identifier: value + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: s + - join_clause: + - keyword: cross + - keyword: apply + - from_expression_element: + - table_expression: + - function: + - function_name: + - function_name_identifier: string_split + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: replace + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: some_path + - comma: ',' + - expression: + - quoted_literal: '''->''' + - comma: ',' + - expression: + - quoted_literal: '''{''' + - end_bracket: ) + - comma: ',' + - expression: + - quoted_literal: '''{''' + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: sp + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_date_functions.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_date_functions.sql new file mode 100644 index 000000000..992f08e75 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_date_functions.sql @@ -0,0 +1,26 @@ +SELECT + [hello], + DATEDIFF(day, [mydate], GETDATE()) AS [test], + DATEPART(day, [mydate], GETDATE()) AS [test2], + DATEDIFF(year, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000'), + DATEDIFF(quarter, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000'), + DATEDIFF(month, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000'), + DATEDIFF(dayofyear, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000'), + DATEDIFF(day, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000'), + DATEDIFF(week, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000'), + DATEDIFF(hour, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000'), + DATEDIFF(minute, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000'), + DATEDIFF(second, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000'), + DATEDIFF(millisecond, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000'), + DATEDIFF(microsecond, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000'), + DATEDIFF_BIG(microsecond, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000'), + DATEADD(year,2147483647, '20060731'), + DATEADD(year,-2147483647, '20060731'), + DATENAME(year, '12:10:30.123'), + DATENAME(month, '12:10:30.123'), + DATENAME(day, '12:10:30.123'), + DATENAME(dayofyear, '12:10:30.123'), + DATENAME(weekday, '12:10:30.123'), + DAY(GetDate()) as today +FROM + mytable; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_date_functions.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_date_functions.yml new file mode 100644 index 000000000..aa1054390 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_date_functions.yml @@ -0,0 +1,383 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '[hello]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEDIFF + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: day + - comma: ',' + - expression: + - column_reference: + - quoted_identifier: '[mydate]' + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[test]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEPART + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: day + - comma: ',' + - expression: + - column_reference: + - quoted_identifier: '[mydate]' + - comma: ',' + - expression: + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[test2]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEDIFF + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: year + - comma: ',' + - expression: + - quoted_literal: '''2005-12-31 23:59:59.9999999''' + - comma: ',' + - expression: + - quoted_literal: '''2006-01-01 00:00:00.0000000''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEDIFF + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: quarter + - comma: ',' + - expression: + - quoted_literal: '''2005-12-31 23:59:59.9999999''' + - comma: ',' + - expression: + - quoted_literal: '''2006-01-01 00:00:00.0000000''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEDIFF + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: month + - comma: ',' + - expression: + - quoted_literal: '''2005-12-31 23:59:59.9999999''' + - comma: ',' + - expression: + - quoted_literal: '''2006-01-01 00:00:00.0000000''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEDIFF + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: dayofyear + - comma: ',' + - expression: + - quoted_literal: '''2005-12-31 23:59:59.9999999''' + - comma: ',' + - expression: + - quoted_literal: '''2006-01-01 00:00:00.0000000''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEDIFF + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: day + - comma: ',' + - expression: + - quoted_literal: '''2005-12-31 23:59:59.9999999''' + - comma: ',' + - expression: + - quoted_literal: '''2006-01-01 00:00:00.0000000''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEDIFF + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: week + - comma: ',' + - expression: + - quoted_literal: '''2005-12-31 23:59:59.9999999''' + - comma: ',' + - expression: + - quoted_literal: '''2006-01-01 00:00:00.0000000''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEDIFF + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: hour + - comma: ',' + - expression: + - quoted_literal: '''2005-12-31 23:59:59.9999999''' + - comma: ',' + - expression: + - quoted_literal: '''2006-01-01 00:00:00.0000000''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEDIFF + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: minute + - comma: ',' + - expression: + - quoted_literal: '''2005-12-31 23:59:59.9999999''' + - comma: ',' + - expression: + - quoted_literal: '''2006-01-01 00:00:00.0000000''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEDIFF + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: second + - comma: ',' + - expression: + - quoted_literal: '''2005-12-31 23:59:59.9999999''' + - comma: ',' + - expression: + - quoted_literal: '''2006-01-01 00:00:00.0000000''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEDIFF + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: millisecond + - comma: ',' + - expression: + - quoted_literal: '''2005-12-31 23:59:59.9999999''' + - comma: ',' + - expression: + - quoted_literal: '''2006-01-01 00:00:00.0000000''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEDIFF + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: microsecond + - comma: ',' + - expression: + - quoted_literal: '''2005-12-31 23:59:59.9999999''' + - comma: ',' + - expression: + - quoted_literal: '''2006-01-01 00:00:00.0000000''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEDIFF_BIG + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: microsecond + - comma: ',' + - expression: + - quoted_literal: '''2005-12-31 23:59:59.9999999''' + - comma: ',' + - expression: + - quoted_literal: '''2006-01-01 00:00:00.0000000''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEADD + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: year + - comma: ',' + - expression: + - integer_literal: '2147483647' + - comma: ',' + - expression: + - quoted_literal: '''20060731''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATEADD + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: year + - comma: ',' + - expression: + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '2147483647' + - comma: ',' + - expression: + - quoted_literal: '''20060731''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATENAME + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: year + - comma: ',' + - expression: + - quoted_literal: '''12:10:30.123''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATENAME + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: month + - comma: ',' + - expression: + - quoted_literal: '''12:10:30.123''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATENAME + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: day + - comma: ',' + - expression: + - quoted_literal: '''12:10:30.123''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATENAME + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: dayofyear + - comma: ',' + - expression: + - quoted_literal: '''12:10:30.123''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DATENAME + - function_contents: + - bracketed: + - start_bracket: ( + - date_part: weekday + - comma: ',' + - expression: + - quoted_literal: '''12:10:30.123''' + - end_bracket: ) + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DAY + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: GetDate + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: today + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: mytable + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_for.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_for.sql new file mode 100644 index 000000000..4b3b784e4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_for.sql @@ -0,0 +1,65 @@ +-- FOR JSON + +SELECT name, surname +FROM emp +FOR JSON AUTO; +GO + +SELECT 1 AS a +FOR JSON PATH; +GO + +SELECT 1 AS a +FOR JSON PATH, WITHOUT_ARRAY_WRAPPER +GO + +SELECT c.ClassName, + s.StudentName +FROM #tabClass AS c +RIGHT JOIN #tabStudent AS s ON s.ClassGuid = c.ClassGuid +ORDER BY c.ClassName, + s.StudentName +FOR JSON AUTO; +GO + +SELECT 1 AS a +FOR JSON PATH, ROOT ('RootName'), WITHOUT_ARRAY_WRAPPER, INCLUDE_NULL_VALUES; +GO + +-- FOR XML + +SELECT ProductModelID, Name +FROM Production.ProductModel +WHERE ProductModelID=122 or ProductModelID=119 +FOR XML RAW; + +SELECT ProductPhotoID, ThumbNailPhoto +FROM Production.ProductPhoto +WHERE ProductPhotoID=70 +FOR XML AUTO; + +SELECT 1 as Tag +FROM HumanResources.Employee AS E +FOR XML EXPLICIT; + +SELECT + ProductModelID, + Name +FROM Production.ProductModel +WHERE ProductModelID=122 OR ProductModelID=119 +FOR XML PATH ('root'); + +-- Per Issue #5567 +SELECT 0 ErrorCode +FOR XML PATH('Result'), TYPE + +SELECT 0 ErrorCode +FOR XML PATH('Result'), ROOT('RootName'), TYPE + +SELECT 0 ErrorCode +FOR XML PATH('Result'), TYPE, ROOT('RootName') + +-- FOR BROWSE +SELECT 1 AS a +FOR BROWSE +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_for.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_for.yml new file mode 100644 index 000000000..8eb4f8240 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_for.yml @@ -0,0 +1,387 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: name + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: surname + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: emp + - for_clause: + - keyword: FOR + - keyword: JSON + - keyword: AUTO + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - for_clause: + - keyword: FOR + - keyword: JSON + - keyword: PATH + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - for_clause: + - keyword: FOR + - keyword: JSON + - keyword: PATH + - comma: ',' + - keyword: WITHOUT_ARRAY_WRAPPER + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: ClassName + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: StudentName + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - hash_identifier: '#tabClass' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: c + - join_clause: + - keyword: RIGHT + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - hash_identifier: '#tabStudent' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: s + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: ClassGuid + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: ClassGuid + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: c + - dot: . + - naked_identifier: ClassName + - comma: ',' + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: StudentName + - for_clause: + - keyword: FOR + - keyword: JSON + - keyword: AUTO + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - for_clause: + - keyword: FOR + - keyword: JSON + - keyword: PATH + - comma: ',' + - keyword: ROOT + - bracketed: + - start_bracket: ( + - quoted_literal: '''RootName''' + - end_bracket: ) + - comma: ',' + - keyword: WITHOUT_ARRAY_WRAPPER + - comma: ',' + - keyword: INCLUDE_NULL_VALUES + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ProductModelID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Name + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ProductModel + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ProductModelID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '122' + - binary_operator: or + - column_reference: + - naked_identifier: ProductModelID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '119' + - for_clause: + - keyword: FOR + - keyword: XML + - keyword: RAW + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ProductPhotoID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ThumbNailPhoto + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ProductPhoto + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ProductPhotoID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '70' + - for_clause: + - keyword: FOR + - keyword: XML + - keyword: AUTO + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: Tag + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: Employee + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: E + - for_clause: + - keyword: FOR + - keyword: XML + - keyword: EXPLICIT + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: ProductModelID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: Name + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Production + - dot: . + - naked_identifier: ProductModel + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: ProductModelID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '122' + - binary_operator: OR + - column_reference: + - naked_identifier: ProductModelID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '119' + - for_clause: + - keyword: FOR + - keyword: XML + - keyword: PATH + - bracketed: + - start_bracket: ( + - quoted_literal: '''root''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '0' + - alias_expression: + - naked_identifier: ErrorCode + - for_clause: + - keyword: FOR + - keyword: XML + - keyword: PATH + - bracketed: + - start_bracket: ( + - quoted_literal: '''Result''' + - end_bracket: ) + - comma: ',' + - keyword: TYPE + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '0' + - alias_expression: + - naked_identifier: ErrorCode + - for_clause: + - keyword: FOR + - keyword: XML + - keyword: PATH + - bracketed: + - start_bracket: ( + - quoted_literal: '''Result''' + - end_bracket: ) + - comma: ',' + - keyword: ROOT + - bracketed: + - start_bracket: ( + - quoted_literal: '''RootName''' + - end_bracket: ) + - comma: ',' + - keyword: TYPE + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '0' + - alias_expression: + - naked_identifier: ErrorCode + - for_clause: + - keyword: FOR + - keyword: XML + - keyword: PATH + - bracketed: + - start_bracket: ( + - quoted_literal: '''Result''' + - end_bracket: ) + - comma: ',' + - keyword: TYPE + - comma: ',' + - keyword: ROOT + - bracketed: + - start_bracket: ( + - quoted_literal: '''RootName''' + - end_bracket: ) + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - for_clause: + - keyword: FOR + - keyword: BROWSE + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_into.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_into.sql new file mode 100644 index 000000000..d3df9dc06 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_into.sql @@ -0,0 +1,12 @@ +SELECT [ID] + ,[FIN] + ,[Unit] + ,[EventNM] + ,[Date] + ,[CHGFlag] +INTO #CHG +FROM Final +GROUP BY [FIN] + ,[EventNM] + ,[Unit] + ,[Date] diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_into.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_into.yml new file mode 100644 index 000000000..634048e32 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_into.yml @@ -0,0 +1,54 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '[ID]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[FIN]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[Unit]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[EventNM]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[Date]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[CHGFlag]' + - into_table_clause: + - keyword: INTO + - object_reference: + - hash_identifier: '#CHG' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Final + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - quoted_identifier: '[FIN]' + - comma: ',' + - column_reference: + - quoted_identifier: '[EventNM]' + - comma: ',' + - column_reference: + - quoted_identifier: '[Unit]' + - comma: ',' + - column_reference: + - quoted_identifier: '[Date]' diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_named_window.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_named_window.sql new file mode 100644 index 000000000..4fd276bc9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_named_window.sql @@ -0,0 +1,61 @@ +SELECT ROW_NUMBER() OVER win AS [Row Number], + p.LastName, + s.SalesYTD, + a.PostalCode +FROM Sales.SalesPerson AS s +INNER JOIN Person.Person AS p + ON s.BusinessEntityID = p.BusinessEntityID +INNER JOIN Person.Address AS a + ON a.AddressID = p.BusinessEntityID +WHERE TerritoryID IS NOT NULL + AND SalesYTD <> 0 +WINDOW win AS + ( + PARTITION BY PostalCode ORDER BY SalesYTD DESC + ) +ORDER BY PostalCode; + +SELECT SalesOrderID, + ProductID, + OrderQty, + SUM(OrderQty) OVER win AS [Total], + AVG(OrderQty) OVER win AS [Avg], + COUNT(OrderQty) OVER win AS [Count], + MIN(OrderQty) OVER win AS [Min], + MAX(OrderQty) OVER win AS [Max] +FROM Sales.SalesOrderDetail +WHERE SalesOrderID IN (43659, 43664) +WINDOW win AS (PARTITION BY SalesOrderID); + +SELECT SalesOrderID AS OrderNumber, + ProductID, + OrderQty AS Qty, + SUM(OrderQty) OVER win AS Total, + AVG(OrderQty) OVER (win PARTITION BY SalesOrderID) AS Avg, + COUNT(OrderQty) OVER ( + win ROWS BETWEEN UNBOUNDED PRECEDING + AND 1 FOLLOWING + ) AS Count +FROM Sales.SalesOrderDetail +WHERE SalesOrderID IN (43659, 43664) + AND ProductID LIKE '71%' +WINDOW win AS + ( + ORDER BY SalesOrderID, ProductID + ); + +SELECT SalesOrderID AS OrderNumber, ProductID, + OrderQty AS Qty, + SUM(OrderQty) OVER win2 AS Total, + AVG(OrderQty) OVER win1 AS Avg +FROM Sales.SalesOrderDetail +WHERE SalesOrderID IN(43659,43664) AND + ProductID LIKE '71%' +WINDOW win1 AS (win3), + win2 AS (ORDER BY SalesOrderID, ProductID), + win3 AS (win2 PARTITION BY SalesOrderID); + +select row_number() over win as x +from information_schema.tables +window win as (order by table_name) +; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_named_window.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_named_window.yml new file mode 100644 index 000000000..4e02a9141 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_named_window.yml @@ -0,0 +1,607 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: ROW_NUMBER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[Row Number]' + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: LastName + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: SalesYTD + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: PostalCode + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesPerson + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: s + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: Person + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: p + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: s + - dot: . + - naked_identifier: BusinessEntityID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: BusinessEntityID + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: Address + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: a + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: a + - dot: . + - naked_identifier: AddressID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: p + - dot: . + - naked_identifier: BusinessEntityID + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: TerritoryID + - keyword: IS + - keyword: NOT + - null_literal: 'NULL' + - binary_operator: AND + - column_reference: + - naked_identifier: SalesYTD + - comparison_operator: + - raw_comparison_operator: < + - raw_comparison_operator: '>' + - integer_literal: '0' + - named_window: + - keyword: WINDOW + - named_window_expression: + - naked_identifier: win + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - column_reference: + - naked_identifier: PostalCode + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: SalesYTD + - keyword: DESC + - end_bracket: ) + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: PostalCode + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: SalesOrderID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ProductID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: OrderQty + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[Total]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: AVG + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[Avg]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: COUNT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[Count]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: MIN + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[Min]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: MAX + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[Max]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderDetail + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: SalesOrderID + - keyword: IN + - bracketed: + - start_bracket: ( + - integer_literal: '43659' + - comma: ',' + - integer_literal: '43664' + - end_bracket: ) + - named_window: + - keyword: WINDOW + - named_window_expression: + - naked_identifier: win + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - column_reference: + - naked_identifier: SalesOrderID + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: SalesOrderID + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: OrderNumber + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ProductID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: OrderQty + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Qty + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Total + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: AVG + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - naked_identifier: win + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - column_reference: + - naked_identifier: SalesOrderID + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Avg + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: COUNT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - naked_identifier: win + - frame_clause: + - keyword: ROWS + - keyword: BETWEEN + - keyword: UNBOUNDED + - keyword: PRECEDING + - keyword: AND + - numeric_literal: '1' + - keyword: FOLLOWING + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Count + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderDetail + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: SalesOrderID + - keyword: IN + - bracketed: + - start_bracket: ( + - integer_literal: '43659' + - comma: ',' + - integer_literal: '43664' + - end_bracket: ) + - binary_operator: AND + - column_reference: + - naked_identifier: ProductID + - keyword: LIKE + - quoted_literal: '''71%''' + - named_window: + - keyword: WINDOW + - named_window_expression: + - naked_identifier: win + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: SalesOrderID + - comma: ',' + - column_reference: + - naked_identifier: ProductID + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: SalesOrderID + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: OrderNumber + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: ProductID + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: OrderQty + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Qty + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win2 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Total + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: AVG + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: OrderQty + - end_bracket: ) + - over_clause: + - keyword: OVER + - naked_identifier: win1 + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Avg + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: SalesOrderDetail + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: SalesOrderID + - keyword: IN + - bracketed: + - start_bracket: ( + - integer_literal: '43659' + - comma: ',' + - integer_literal: '43664' + - end_bracket: ) + - binary_operator: AND + - column_reference: + - naked_identifier: ProductID + - keyword: LIKE + - quoted_literal: '''71%''' + - named_window: + - keyword: WINDOW + - named_window_expression: + - naked_identifier: win1 + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - naked_identifier: win3 + - end_bracket: ) + - comma: ',' + - named_window_expression: + - naked_identifier: win2 + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: SalesOrderID + - comma: ',' + - column_reference: + - naked_identifier: ProductID + - end_bracket: ) + - comma: ',' + - named_window_expression: + - naked_identifier: win3 + - keyword: AS + - bracketed: + - start_bracket: ( + - window_specification: + - naked_identifier: win2 + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - column_reference: + - naked_identifier: SalesOrderID + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - function: + - function_name: + - keyword: row_number + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: over + - naked_identifier: win + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: x + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: information_schema + - dot: . + - naked_identifier: tables + - named_window: + - keyword: window + - named_window_expression: + - naked_identifier: win + - keyword: as + - bracketed: + - start_bracket: ( + - window_specification: + - orderby_clause: + - keyword: order + - keyword: by + - column_reference: + - naked_identifier: table_name + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_natural_join.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_natural_join.sql new file mode 100644 index 000000000..d578fb370 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_natural_join.sql @@ -0,0 +1,7 @@ +SELECT * +FROM table1 natural -- this should parse as an alias as TSQL does not have NATURAL joins +JOIN table2; + +SELECT * +FROM table1 natural -- this should parse as an alias as TSQL does not have NATURAL joins +INNER JOIN table2; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_natural_join.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_natural_join.yml new file mode 100644 index 000000000..874591a5e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_natural_join.yml @@ -0,0 +1,51 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - alias_expression: + - naked_identifier: natural + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - alias_expression: + - naked_identifier: natural + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table2 + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_pivot.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_pivot.sql new file mode 100644 index 000000000..89d4effd5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_pivot.sql @@ -0,0 +1,23 @@ +select [1], [2], [3] +from + table1 as t1 +pivot + (max(value) for rn in ([1], [2], [3]) ) as pvt; + +select [1], [2], [3] +from + table1 as t1 +pivot + (max(value) for rn in ([1], [2], [3]) ) pvt; +GO + +SELECT + unpvt.Program + , dd.[Month Number] AS Month +FROM p +UNPIVOT ( + MonthValue FOR MonthColumn IN (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec) + ) AS unpvt +INNER JOIN d + ON [Month Name] = unpvt.MonthColumn; +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_pivot.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_pivot.yml new file mode 100644 index 000000000..e59ba6efc --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_pivot.yml @@ -0,0 +1,223 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - quoted_identifier: '[1]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[2]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[3]' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: t1 + - from_pivot_expression: + - keyword: pivot + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: max + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: value + - end_bracket: ) + - keyword: for + - column_reference: + - naked_identifier: rn + - keyword: in + - bracketed: + - start_bracket: ( + - pivot_column_reference: + - quoted_identifier: '[1]' + - comma: ',' + - pivot_column_reference: + - quoted_identifier: '[2]' + - comma: ',' + - pivot_column_reference: + - quoted_identifier: '[3]' + - end_bracket: ) + - end_bracket: ) + - keyword: as + - table_reference: + - naked_identifier: pvt + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - quoted_identifier: '[1]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[2]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[3]' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: t1 + - from_pivot_expression: + - keyword: pivot + - bracketed: + - start_bracket: ( + - function: + - function_name: + - function_name_identifier: max + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: value + - end_bracket: ) + - keyword: for + - column_reference: + - naked_identifier: rn + - keyword: in + - bracketed: + - start_bracket: ( + - pivot_column_reference: + - quoted_identifier: '[1]' + - comma: ',' + - pivot_column_reference: + - quoted_identifier: '[2]' + - comma: ',' + - pivot_column_reference: + - quoted_identifier: '[3]' + - end_bracket: ) + - end_bracket: ) + - table_reference: + - naked_identifier: pvt + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: unpvt + - dot: . + - naked_identifier: Program + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: dd + - dot: . + - quoted_identifier: '[Month Number]' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Month + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: p + - from_pivot_expression: + - keyword: UNPIVOT + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: MonthValue + - keyword: FOR + - column_reference: + - naked_identifier: MonthColumn + - keyword: IN + - bracketed: + - start_bracket: ( + - pivot_column_reference: + - naked_identifier: Jan + - comma: ',' + - pivot_column_reference: + - naked_identifier: Feb + - comma: ',' + - pivot_column_reference: + - naked_identifier: Mar + - comma: ',' + - pivot_column_reference: + - naked_identifier: Apr + - comma: ',' + - pivot_column_reference: + - naked_identifier: May + - comma: ',' + - pivot_column_reference: + - naked_identifier: Jun + - comma: ',' + - pivot_column_reference: + - naked_identifier: Jul + - comma: ',' + - pivot_column_reference: + - naked_identifier: Aug + - comma: ',' + - pivot_column_reference: + - naked_identifier: Sep + - comma: ',' + - pivot_column_reference: + - naked_identifier: Oct + - comma: ',' + - pivot_column_reference: + - naked_identifier: Nov + - comma: ',' + - pivot_column_reference: + - naked_identifier: Dec + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - table_reference: + - naked_identifier: unpvt + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: d + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - quoted_identifier: '[Month Name]' + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: unpvt + - dot: . + - naked_identifier: MonthColumn + - statement_terminator: ; + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_top.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_top.yml index 6453f1997..f4a5b96c9 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_top.yml +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_top.yml @@ -1,255 +1,253 @@ file: -- statement: - - select_statement: - - select_clause: - - keyword: select - - select_clause_modifier: - - keyword: top - - expression: - - numeric_literal: '1' - - select_clause_element: - - column_reference: - - naked_identifier: t - - dot: . - - naked_identifier: date_column1 - - alias_expression: - - keyword: as - - naked_identifier: last_date_column1 - - from_clause: - - keyword: from - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_modifier: + - keyword: top + - expression: + - integer_literal: '1' + - select_clause_element: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: date_column1 + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: last_date_column1 + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: - naked_identifier: t1 - dot: . - naked_identifier: t2 - dot: . - naked_identifier: table_name - - alias_expression: - - naked_identifier: t - - orderby_clause: - - keyword: order - - keyword: by - - column_reference: - - naked_identifier: t - - dot: . - - naked_identifier: column1 - - keyword: desc -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_modifier: - - keyword: TOP - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '10' - - end_bracket: ) - - select_clause_element: - - column_reference: - - naked_identifier: JobTitle - - comma: ',' - - select_clause_element: + - alias_expression: + - naked_identifier: t + - orderby_clause: + - keyword: order + - keyword: by - column_reference: - - naked_identifier: HireDate - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: + - naked_identifier: t + - dot: . + - naked_identifier: column1 + - keyword: desc + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - select_clause_element: + - column_reference: + - naked_identifier: JobTitle + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: HireDate + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: - naked_identifier: HumanResources - dot: . - naked_identifier: Employee -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_modifier: - - keyword: TOP - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '10' - - end_bracket: ) - - select_clause_element: - - column_reference: - - naked_identifier: JobTitle - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: HireDate - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - select_clause_element: + - column_reference: + - naked_identifier: JobTitle + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: HireDate + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: - naked_identifier: HumanResources - dot: . - naked_identifier: Employee - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: HireDate - - keyword: DESC -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_modifier: - - keyword: TOP - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '5' - - end_bracket: ) - - keyword: PERCENT - - select_clause_element: - - column_reference: - - naked_identifier: JobTitle - - comma: ',' - - select_clause_element: + - orderby_clause: + - keyword: ORDER + - keyword: BY - column_reference: - naked_identifier: HireDate - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: + - keyword: DESC + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '5' + - end_bracket: ) + - keyword: PERCENT + - select_clause_element: + - column_reference: + - naked_identifier: JobTitle + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: HireDate + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: - naked_identifier: HumanResources - dot: . - naked_identifier: Employee - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: HireDate - - keyword: DESC -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_modifier: - - keyword: TOP - - bracketed: - - start_bracket: ( - - expression: - - numeric_literal: '10' - - end_bracket: ) - - keyword: PERCENT - - keyword: WITH - - keyword: TIES - - select_clause_element: - - column_reference: - - naked_identifier: pp - - dot: . - - naked_identifier: FirstName - - comma: ',' - - select_clause_element: + - orderby_clause: + - keyword: ORDER + - keyword: BY - column_reference: - - naked_identifier: pp - - dot: . - - naked_identifier: LastName - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: e - - dot: . - - naked_identifier: JobTitle - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: e - - dot: . - - naked_identifier: Gender - - comma: ',' - - select_clause_element: - - column_reference: - - naked_identifier: r - - dot: . - - naked_identifier: Rate - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: Person - - dot: . - - naked_identifier: Person - - alias_expression: - - keyword: AS + - naked_identifier: HireDate + - keyword: DESC + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_modifier: + - keyword: TOP + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - end_bracket: ) + - keyword: PERCENT + - keyword: WITH + - keyword: TIES + - select_clause_element: + - column_reference: + - naked_identifier: pp + - dot: . + - naked_identifier: FirstName + - comma: ',' + - select_clause_element: + - column_reference: - naked_identifier: pp - - join_clause: - - keyword: INNER - - keyword: JOIN + - dot: . + - naked_identifier: LastName + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - naked_identifier: JobTitle + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - dot: . + - naked_identifier: Gender + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: r + - dot: . + - naked_identifier: Rate + - from_clause: + - keyword: FROM + - from_expression: - from_expression_element: - table_expression: - table_reference: - - object_reference: + - naked_identifier: Person + - dot: . + - naked_identifier: Person + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: pp + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: - naked_identifier: HumanResources - dot: . - naked_identifier: Employee - - alias_expression: - - keyword: AS - - naked_identifier: e - - join_on_condition: - - keyword: ON - - expression: - - column_reference: - - naked_identifier: pp - - dot: . - - naked_identifier: BusinessEntityID - - comparison_operator: - - raw_comparison_operator: = - - column_reference: + - alias_expression: + - alias_operator: + - keyword: AS - naked_identifier: e - - dot: . - - naked_identifier: BusinessEntityID - - join_clause: - - keyword: INNER - - keyword: JOIN - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: pp + - dot: . + - naked_identifier: BusinessEntityID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: e + - dot: . + - naked_identifier: BusinessEntityID + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: - naked_identifier: HumanResources - dot: . - naked_identifier: EmployeePayHistory - - alias_expression: - - keyword: AS - - naked_identifier: r - - join_on_condition: - - keyword: ON - - expression: - - column_reference: + - alias_expression: + - alias_operator: + - keyword: AS - naked_identifier: r - - dot: . - - naked_identifier: BusinessEntityID - - comparison_operator: - - raw_comparison_operator: = - - column_reference: - - naked_identifier: e - - dot: . - - naked_identifier: BusinessEntityID - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: Rate - - keyword: DESC -- statement_terminator: ; + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: r + - dot: . + - naked_identifier: BusinessEntityID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: e + - dot: . + - naked_identifier: BusinessEntityID + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: Rate + - keyword: DESC + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_top_percent.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_top_percent.sql deleted file mode 100644 index 537fe5b13..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/select_top_percent.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT TOP 50 PERCENT * FROM sales; \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sequence.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sequence.sql new file mode 100644 index 000000000..0e5013654 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sequence.sql @@ -0,0 +1,14 @@ +CREATE SEQUENCE SEQ_MELDER +START WITH 1 +INCREMENT BY 1 +GO + +CREATE SEQUENCE Test.DecSeq + AS decimal(3,0) + START WITH 125 + INCREMENT BY 25 + MINVALUE 100 + MAXVALUE 200 + CYCLE + CACHE 3 +; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sequence.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sequence.yml new file mode 100644 index 000000000..1f20d9966 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sequence.yml @@ -0,0 +1,60 @@ +file: +- batch: + - statement: + - create_sequence_statement: + - keyword: CREATE + - keyword: SEQUENCE + - sequence_reference: + - naked_identifier: SEQ_MELDER + - create_sequence_options_segment: + - keyword: START + - keyword: WITH + - numeric_literal: '1' + - create_sequence_options_segment: + - keyword: INCREMENT + - keyword: BY + - numeric_literal: '1' + - go_statement: + - keyword: GO +- batch: + - statement: + - create_sequence_statement: + - keyword: CREATE + - keyword: SEQUENCE + - sequence_reference: + - naked_identifier: Test + - dot: . + - naked_identifier: DecSeq + - create_sequence_options_segment: + - keyword: AS + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '3' + - comma: ',' + - expression: + - integer_literal: '0' + - end_bracket: ) + - create_sequence_options_segment: + - keyword: START + - keyword: WITH + - numeric_literal: '125' + - create_sequence_options_segment: + - keyword: INCREMENT + - keyword: BY + - numeric_literal: '25' + - create_sequence_options_segment: + - keyword: MINVALUE + - numeric_literal: '100' + - create_sequence_options_segment: + - keyword: MAXVALUE + - numeric_literal: '200' + - create_sequence_options_segment: + - keyword: CYCLE + - create_sequence_options_segment: + - keyword: CACHE + - numeric_literal: '3' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_context_info.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_context_info.sql new file mode 100644 index 000000000..93fcaf1e4 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_context_info.sql @@ -0,0 +1,7 @@ +SET CONTEXT_INFO 0x01010101; + +DECLARE @BinVar varbinary(128); +SET @BinVar = CAST(REPLICATE(0x20, 128) AS varbinary(128) ); +SET CONTEXT_INFO @BinVar; + +SELECT CONTEXT_INFO() AS MyContextInfo; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_context_info.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_context_info.yml new file mode 100644 index 000000000..c0187db9e --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_context_info.yml @@ -0,0 +1,81 @@ +file: +- batch: + - statement: + - set_context_info_statement: + - keyword: SET + - keyword: CONTEXT_INFO + - numeric_literal: '0x01010101' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@BinVar' + - data_type: + - keyword: varbinary + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '128' + - end_bracket: ) + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@BinVar' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - keyword: REPLICATE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - binary_literal: '0x20' + - comma: ',' + - expression: + - integer_literal: '128' + - end_bracket: ) + - keyword: AS + - data_type: + - keyword: varbinary + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '128' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement: + - set_context_info_statement: + - keyword: SET + - keyword: CONTEXT_INFO + - parameter: '@BinVar' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: CONTEXT_INFO + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: MyContextInfo + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_language.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_language.sql new file mode 100644 index 000000000..e26522054 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_language.sql @@ -0,0 +1,4 @@ +SET LANGUAGE us_english; +SET LANGUAGE 'us_english'; +SET LANGUAGE [us_english]; +SET LANGUAGE British; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_language.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_language.yml new file mode 100644 index 000000000..82c24e3b8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_language.yml @@ -0,0 +1,26 @@ +file: +- batch: + - statement: + - set_language_statement: + - keyword: SET + - keyword: LANGUAGE + - naked_identifier: us_english + - statement_terminator: ; + - statement: + - set_language_statement: + - keyword: SET + - keyword: LANGUAGE + - quoted_literal: '''us_english''' + - statement_terminator: ; + - statement: + - set_language_statement: + - keyword: SET + - keyword: LANGUAGE + - quoted_identifier: '[us_english]' + - statement_terminator: ; + - statement: + - set_language_statement: + - keyword: SET + - keyword: LANGUAGE + - naked_identifier: British + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_local_variable.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_local_variable.sql new file mode 100644 index 000000000..d4d347c87 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_local_variable.sql @@ -0,0 +1,97 @@ +-- Print the value of a variable initialized by using SET +DECLARE @myVar CHAR(20); +SET @myVar = 'This is a test'; +SELECT @myVar; +GO + +-- Use a local variable assigned a value by using SET in a SELECT statement +DECLARE @state CHAR(25); +SET @state = N'Oregon'; +SELECT + CITY, + RTRIM(FIRSTNAME) + ' ' + RTRIM(LASTNAME) AS FULL_NAME +FROM HUMANRESOURCES.VEMPLOYEE +WHERE STATEPROVINCENAME = @state; + +-- Use a compound assignment for a local variable +DECLARE @NewBalance INT; +SET @NewBalance = 10; +SET @NewBalance = @NewBalance * 10; +SELECT @NewBalance; +GO + +-- Use SET with a global cursor +DECLARE MY_CURSOR CURSOR GLOBAL +FOR SELECT SHIP_DATE FROM PURCHASING.SHIPMETHOD +DECLARE @my_variable CURSOR; +SET @my_variable = MY_CURSOR; + +DEALLOCATE MY_CURSOR; +GO + +-- Define a cursor by using SET +DECLARE @CursorVar CURSOR; + +SET + @CursorVar = CURSOR SCROLL DYNAMIC + FOR + SELECT + LASTNAME, + FIRSTNAME + FROM ADVENTUREWORKS2022.HUMANRESOURCES.EMPLOYEE + WHERE LASTNAME LIKE 'B%'; + +OPEN @CursorVar; + +FETCH NEXT FROM @CursorVar; +WHILE @@FETCH_STATUS = 0 + BEGIN + FETCH NEXT FROM @CursorVar + END; + +CLOSE @CursorVar; +DEALLOCATE @CursorVar; +GO + +-- Assign a value from a query +USE ADVENTUREWORKS2022; +GO +DECLARE @rows INT; +SET @rows = (SELECT COUNT(*) FROM SALES.CUSTOMER); +SELECT @rows; +GO + +-- Single params +SET @param1 = 1 +; + +-- Multiple params +SET + @param1 = 1, + @param2 = 2 +; + +-- Comma separated params with comment with comma +SET @param1 = "test, test", + @param2 = 2 +; + +-- Params with expression +SET @param1 = ("test", "test"), + @param2 = 2 +; + +-- Assignment operators +SET @param1 += 1, + @param2 -= 2, + @param3 *= 3, + @param4 /= 4, + @param5 %= 5, + @param5 ^= 6, + @param5 &= 7, + @param5 |= 8 +; + +-- Param with sequence in expression +SET @param1 = (NEXT VALUE FOR [dbo].[sequence_name]) +; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_local_variable.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_local_variable.yml new file mode 100644 index 000000000..d0871a388 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_local_variable.yml @@ -0,0 +1,489 @@ +file: +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@myVar' + - data_type: + - keyword: CHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '20' + - end_bracket: ) + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@myVar' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''This is a test''' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameter: '@myVar' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@state' + - data_type: + - keyword: CHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '25' + - end_bracket: ) + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@state' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: N'Oregon' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: CITY + - comma: ',' + - select_clause_element: + - expression: + - function: + - function_name: + - function_name_identifier: RTRIM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: FIRSTNAME + - end_bracket: ) + - binary_operator: + + - quoted_literal: ''' ''' + - binary_operator: + + - function: + - function_name: + - function_name_identifier: RTRIM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: LASTNAME + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: FULL_NAME + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: HUMANRESOURCES + - dot: . + - naked_identifier: VEMPLOYEE + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: STATEPROVINCENAME + - comparison_operator: + - raw_comparison_operator: = + - parameter: '@state' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@NewBalance' + - data_type: + - keyword: INT + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@NewBalance' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '10' + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@NewBalance' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - parameter: '@NewBalance' + - binary_operator: '*' + - integer_literal: '10' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameter: '@NewBalance' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - naked_identifier: MY_CURSOR + - cursor_definition: + - keyword: CURSOR + - keyword: GLOBAL + - keyword: FOR + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: SHIP_DATE + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: PURCHASING + - dot: . + - naked_identifier: SHIPMETHOD + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@my_variable' + - data_type: + - keyword: CURSOR + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@my_variable' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - naked_identifier: MY_CURSOR + - statement_terminator: ; + - statement: + - deallocate_cursor_statement: + - keyword: DEALLOCATE + - naked_identifier: MY_CURSOR + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@CursorVar' + - data_type: + - keyword: CURSOR + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@CursorVar' + - comparison_operator: + - raw_comparison_operator: = + - cursor_definition: + - keyword: CURSOR + - keyword: SCROLL + - keyword: DYNAMIC + - keyword: FOR + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: LASTNAME + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: FIRSTNAME + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: ADVENTUREWORKS2022 + - dot: . + - naked_identifier: HUMANRESOURCES + - dot: . + - naked_identifier: EMPLOYEE + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: LASTNAME + - keyword: LIKE + - quoted_literal: '''B%''' + - statement_terminator: ; + - statement: + - open_cursor_statement: + - keyword: OPEN + - parameter: '@CursorVar' + - statement_terminator: ; + - statement: + - fetch_cursor_statement: + - keyword: FETCH + - keyword: NEXT + - keyword: FROM + - parameter: '@CursorVar' + - statement_terminator: ; + - statement: + - while_statement: + - keyword: WHILE + - expression: + - system_variable: '@@FETCH_STATUS' + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '0' + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - fetch_cursor_statement: + - keyword: FETCH + - keyword: NEXT + - keyword: FROM + - parameter: '@CursorVar' + - keyword: END + - statement_terminator: ; + - statement: + - close_cursor_statement: + - keyword: CLOSE + - parameter: '@CursorVar' + - statement_terminator: ; + - statement: + - deallocate_cursor_statement: + - keyword: DEALLOCATE + - parameter: '@CursorVar' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - use_statement: + - keyword: USE + - database_reference: + - naked_identifier: ADVENTUREWORKS2022 + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@rows' + - data_type: + - keyword: INT + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@rows' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: COUNT + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: SALES + - dot: . + - naked_identifier: CUSTOMER + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - parameter: '@rows' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@param1' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '1' + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@param1' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '1' + - comma: ',' + - parameter: '@param2' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '2' + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@param1' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - column_reference: + - quoted_identifier: '"test, test"' + - comma: ',' + - parameter: '@param2' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '2' + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@param1' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - column_reference: + - quoted_identifier: '"test"' + - comma: ',' + - column_reference: + - quoted_identifier: '"test"' + - end_bracket: ) + - comma: ',' + - parameter: '@param2' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '2' + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@param1' + - assignment_operator: + - binary_operator: + + - raw_comparison_operator: = + - expression: + - integer_literal: '1' + - comma: ',' + - parameter: '@param2' + - assignment_operator: + - binary_operator: '-' + - raw_comparison_operator: = + - expression: + - integer_literal: '2' + - comma: ',' + - parameter: '@param3' + - assignment_operator: + - binary_operator: '*' + - raw_comparison_operator: = + - expression: + - integer_literal: '3' + - comma: ',' + - parameter: '@param4' + - assignment_operator: + - binary_operator: / + - raw_comparison_operator: = + - expression: + - integer_literal: '4' + - comma: ',' + - parameter: '@param5' + - assignment_operator: + - binary_operator: '%' + - raw_comparison_operator: = + - expression: + - integer_literal: '5' + - comma: ',' + - parameter: '@param5' + - assignment_operator: + - binary_operator: ^ + - raw_comparison_operator: = + - expression: + - integer_literal: '6' + - comma: ',' + - parameter: '@param5' + - assignment_operator: + - binary_operator: + - ampersand: '&' + - raw_comparison_operator: = + - expression: + - integer_literal: '7' + - comma: ',' + - parameter: '@param5' + - assignment_operator: + - binary_operator: + - pipe: '|' + - raw_comparison_operator: = + - expression: + - integer_literal: '8' + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@param1' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - bracketed: + - start_bracket: ( + - expression: + - sequence_next_value: + - keyword: NEXT + - keyword: VALUE + - keyword: FOR + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[sequence_name]' + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_statements.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_statements.sql new file mode 100644 index 000000000..65c31ba19 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_statements.sql @@ -0,0 +1,3 @@ +SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; + +DECLARE @BinaryVariable2 BINARY(2) = 0xFA; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_statements.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_statements.yml new file mode 100644 index 000000000..e4c5cddfa --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/set_statements.yml @@ -0,0 +1,28 @@ +file: +- batch: + - statement: + - set_segment: + - keyword: SET + - keyword: TRANSACTION + - keyword: ISOLATION + - keyword: LEVEL + - keyword: READ + - keyword: UNCOMMITTED + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@BinaryVariable2' + - data_type: + - keyword: BINARY + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '2' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - expression: + - binary_literal: '0xFA' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sqlcmd_command.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sqlcmd_command.sql new file mode 100644 index 000000000..53268969a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sqlcmd_command.sql @@ -0,0 +1,13 @@ +/* +https://learn.microsoft.com/en-us/sql/tools/sqlcmd/sqlcmd-utility?view=sql-server-ver16#sqlcmd-commands +*/ + +-- reference / execute other SQL files +:r script.sql +:r script#01_a-b.sql +:r ...\folder\script.SQL +:r .\folder_1\folder_2\folder_3\folder_4\script.sql + +-- define *sqlcmd* scripting variable +:setvar variable_name variable_value +:setvar variable_name "variable_value" diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sqlcmd_command.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sqlcmd_command.yml new file mode 100644 index 000000000..34cce959a --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/sqlcmd_command.yml @@ -0,0 +1,36 @@ +file: +- batch: + - statement: + - sqlcmd_command_segment: + - colon: ':' + - sqlcmd_operator: r + - unquoted_relative_sql_file_path: script.sql + - statement: + - sqlcmd_command_segment: + - colon: ':' + - sqlcmd_operator: r + - unquoted_relative_sql_file_path: script#01_a-b.sql + - statement: + - sqlcmd_command_segment: + - colon: ':' + - sqlcmd_operator: r + - unquoted_relative_sql_file_path: '...\folder\script.SQL' + - statement: + - sqlcmd_command_segment: + - colon: ':' + - sqlcmd_operator: r + - unquoted_relative_sql_file_path: .\folder_1\folder_2\folder_3\folder_4\script.sql + - statement: + - sqlcmd_command_segment: + - colon: ':' + - sqlcmd_operator: setvar + - object_reference: + - naked_identifier: variable_name + - word: variable_value + - statement: + - sqlcmd_command_segment: + - colon: ':' + - sqlcmd_operator: setvar + - object_reference: + - naked_identifier: variable_name + - double_quote: '"variable_value"' diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/square_bracket_identifiers.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/square_bracket_identifiers.sql deleted file mode 100644 index f355d2a49..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/square_bracket_identifiers.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT [Customer Name], [Order Date] FROM [Sales Data]; \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/square_bracket_identifiers.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/square_bracket_identifiers.yml deleted file mode 100644 index 673a87bb1..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/square_bracket_identifiers.yml +++ /dev/null @@ -1,21 +0,0 @@ -file: -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - quoted_identifier: '[Customer Name]' - - comma: ',' - - select_clause_element: - - column_reference: - - quoted_identifier: '[Order Date]' - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - quoted_identifier: '[Sales Data]' -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedure_begin_end.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedure_begin_end.yml index 39a73b4e3..0ad14e668 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedure_begin_end.yml +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedure_begin_end.yml @@ -1,260 +1,277 @@ file: -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: PROCEDURE - - object_reference: - - naked_identifier: dbo - - dot: . - - naked_identifier: Test_Begin_End - - keyword: AS - - statement: - - keyword: BEGIN - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - quoted_literal: '''Weekend''' - - statement_terminator: ; - - select_statement: - - select_clause: - - keyword: select - - select_clause_element: - - column_reference: - - naked_identifier: a - - from_clause: - - keyword: from - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: tbl1 - - statement_terminator: ; - - select_statement: - - select_clause: - - keyword: select - - select_clause_element: - - column_reference: - - naked_identifier: b - - from_clause: - - keyword: from - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: tbl2 - - statement_terminator: ; - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[usp_process_tran_log]' - - tsql_variable: '@out_vchCode' - - data_type: - - data_type: - - data_type_identifier: uddt_output_code - - keyword: OUTPUT - - comma: ',' - - tsql_variable: '@out_vchMsg' - - data_type: - - data_type: - - data_type_identifier: uddt_output_msg - - keyword: OUTPUT - - comma: ',' - - tsql_variable: '@in_debug' - - data_type: - - data_type: - - data_type_identifier: INT - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1' - - keyword: AS - - statement: - - keyword: SET - - keyword: NOCOUNT - - keyword: ON -- statement_terminator: ; -- statement: - - keyword: BEGIN - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - quoted_literal: '''8''' - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: OR - - keyword: ALTER - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[usp_process_tran_log]' - - tsql_variable: '@out_vchCode' - - data_type: - - data_type: - - data_type_identifier: uddt_output_code - - keyword: OUTPUT - - comma: ',' - - tsql_variable: '@out_vchMsg' - - data_type: - - data_type: - - data_type_identifier: uddt_output_msg - - keyword: OUT - - comma: ',' - - tsql_variable: '@in_debug' - - data_type: - - data_type: - - data_type_identifier: INT - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1' - - keyword: READONLY - - keyword: AS - - statement: - - keyword: SET - - keyword: NOCOUNT - - keyword: ON -- statement_terminator: ; -- statement: - - keyword: BEGIN - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - quoted_literal: '''8''' - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO -- statement: - - create_procedure_statement: - - keyword: ALTER - - keyword: PROCEDURE - - object_reference: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[usp_process_tran_log]' - - tsql_variable: '@out_vchCode' - - data_type: - - data_type: - - data_type_identifier: uddt_output_code - - keyword: OUTPUT - - comma: ',' - - tsql_variable: '@out_vchMsg' - - data_type: - - data_type: - - data_type_identifier: uddt_output_msg - - keyword: OUTPUT - - comma: ',' - - tsql_variable: '@in_debug' - - data_type: - - data_type: - - data_type_identifier: INT - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1' - - keyword: AS - - statement: - - keyword: SET - - keyword: NOCOUNT - - keyword: ON -- statement_terminator: ; -- statement: - - keyword: BEGIN - - keyword: BEGIN - - keyword: TRY +- batch: - statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - quoted_literal: '''8''' - - statement_terminator: ; - - keyword: END - - keyword: TRY - - keyword: BEGIN - - keyword: CATCH + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Test_Begin_End + - keyword: AS + - procedure_statement: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''Weekend''' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: a + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl1 + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: b + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: tbl2 + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: - statement: - - keyword: SET - - tsql_variable: '@v_nSysErrorNum' - - assignment_operator: - - raw_comparison_operator: = - - expression: - - function: - - function_name: - - function_name_identifier: ERROR_NUMBER - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) - - statement_terminator: ; + - create_procedure_statement: + - keyword: CREATE + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[usp_process_tran_log]' + - procedure_parameter_list: + - parameter: '@out_vchCode' + - data_type: + - data_type_identifier: uddt_output_code + - keyword: OUTPUT + - comma: ',' + - parameter: '@out_vchMsg' + - data_type: + - data_type_identifier: uddt_output_msg + - keyword: OUTPUT + - comma: ',' + - parameter: '@in_debug' + - data_type: + - keyword: INT + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '1' + - keyword: AS + - procedure_statement: + - statement: + - set_segment: + - keyword: SET + - keyword: NOCOUNT + - keyword: ON + - statement_terminator: ; + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''8''' + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: - statement: - - keyword: SET - - tsql_variable: '@v_vchCode' - - assignment_operator: - - raw_comparison_operator: = - - expression: - - function: - - function_name: - - function_name_identifier: ERROR_LINE - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) - - statement_terminator: ; + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[usp_process_tran_log]' + - procedure_parameter_list: + - parameter: '@out_vchCode' + - data_type: + - data_type_identifier: uddt_output_code + - keyword: OUTPUT + - comma: ',' + - parameter: '@out_vchMsg' + - data_type: + - data_type_identifier: uddt_output_msg + - keyword: OUT + - comma: ',' + - parameter: '@in_debug' + - data_type: + - keyword: INT + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '1' + - keyword: READONLY + - keyword: AS + - procedure_statement: + - statement: + - set_segment: + - keyword: SET + - keyword: NOCOUNT + - keyword: ON + - statement_terminator: ; + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''8''' + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: - statement: - - keyword: SET - - tsql_variable: '@v_vchMsg' - - assignment_operator: - - raw_comparison_operator: = - - expression: - - data_type: - - data_type_identifier: N - - quoted_literal: '''Missing control type.''' - - statement_terminator: ; - - statement: - - keyword: SET - - tsql_variable: '@v_vchMsg' - - assignment_operator: - - raw_comparison_operator: = - - expression: - - parameterized_expression: - - tsql_variable: '@v_vchMsg' - - binary_operator: + - - data_type: - - data_type_identifier: N - - quoted_literal: ''' SQL Error = ''' - - binary_operator: + - - function: - - function_name: - - function_name_identifier: ERROR_MESSAGE - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) - - statement_terminator: ; - - statement: - - keyword: GOTO - - naked_identifier: ERROR_HANDLER - - statement_terminator: ; - - keyword: END - - keyword: CATCH - - keyword: END -- statement_terminator: ; -- statement: - - keyword: GO + - create_procedure_statement: + - keyword: ALTER + - keyword: PROCEDURE + - object_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[usp_process_tran_log]' + - procedure_parameter_list: + - parameter: '@out_vchCode' + - data_type: + - data_type_identifier: uddt_output_code + - keyword: OUTPUT + - comma: ',' + - parameter: '@out_vchMsg' + - data_type: + - data_type_identifier: uddt_output_msg + - keyword: OUTPUT + - comma: ',' + - parameter: '@in_debug' + - data_type: + - keyword: INT + - comparison_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '1' + - keyword: AS + - procedure_statement: + - statement: + - set_segment: + - keyword: SET + - keyword: NOCOUNT + - keyword: ON + - statement_terminator: ; + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - try_catch: + - keyword: BEGIN + - keyword: TRY + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - quoted_literal: '''8''' + - statement_terminator: ; + - keyword: END + - keyword: TRY + - keyword: BEGIN + - keyword: CATCH + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@v_nSysErrorNum' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: ERROR_NUMBER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@v_vchCode' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: ERROR_LINE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@v_vchMsg' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: N'Missing control type.' + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@v_vchMsg' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - parameter: '@v_vchMsg' + - binary_operator: + + - quoted_literal: N' SQL Error = ' + - binary_operator: + + - function: + - function_name: + - function_name_identifier: ERROR_MESSAGE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - statement_terminator: ; + - statement: + - goto_statement: + - keyword: GOTO + - naked_identifier: ERROR_HANDLER + - statement_terminator: ; + - keyword: END + - keyword: CATCH + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedure_simple.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedure_simple.yml index 28ce22806..0cff4c8ca 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedure_simple.yml +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedure_simple.yml @@ -1,20 +1,22 @@ file: -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: PROC - - object_reference: - - naked_identifier: ProcedureName - - keyword: AS - - statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - function: - - function_name: - - function_name_identifier: DB_NAME - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: PROC + - object_reference: + - naked_identifier: ProcedureName + - keyword: AS + - procedure_statement: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: DB_NAME + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedure_single_statement.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedure_single_statement.yml index b528254a3..bb6e57a63 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedure_single_statement.yml +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedure_single_statement.yml @@ -1,301 +1,308 @@ file: -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: OR - - keyword: ALTER - - keyword: PROCEDURE - - object_reference: - - naked_identifier: DBO - - dot: . - - naked_identifier: SP_ECDC_CASES_INTER - - bracketed: - - start_bracket: ( - - tsql_variable: '@Apple' - - data_type: - - data_type_identifier: '[int]' - - comma: ',' - - tsql_variable: '@Orange' - - data_type: - - data_type: - - data_type_identifier: varchar - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '100' - - end_bracket: ) - - end_bracket: ) - - keyword: AS - - statement: - - insert_statement: - - keyword: INSERT - - keyword: INTO - - table_reference: - - object_reference: - - naked_identifier: INTER - - dot: . - - naked_identifier: ECDC_CASES +- batch: + - statement: + - create_procedure_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: PROCEDURE + - object_reference: + - naked_identifier: DBO + - dot: . + - naked_identifier: SP_ECDC_CASES_INTER + - procedure_parameter_list: - bracketed: - start_bracket: ( - - column_reference: - - quoted_identifier: '[COUNTRY]' - - comma: ',' - - column_reference: - - quoted_identifier: '[COUNTRY_CODE]' - - comma: ',' - - column_reference: - - quoted_identifier: '[CONTINENT]' - - comma: ',' - - column_reference: - - quoted_identifier: '[POPULATION]' - - comma: ',' - - column_reference: - - quoted_identifier: '[INDICATOR]' - - comma: ',' - - column_reference: - - quoted_identifier: '[WEEKLY_COUNT]' - - comma: ',' - - column_reference: - - quoted_identifier: '[YEAR_WEEK]' - - comma: ',' - - column_reference: - - quoted_identifier: '[WEEK_START]' - - comma: ',' - - column_reference: - - quoted_identifier: '[WEEK_END]' + - parameter: '@Apple' + - data_type: + - data_type_identifier: '[int]' - comma: ',' - - column_reference: - - quoted_identifier: '[RATE_14_DAY]' - - comma: ',' - - column_reference: - - quoted_identifier: '[CUMULATIVE_COUNT]' - - comma: ',' - - column_reference: - - quoted_identifier: '[SOURCE]' + - parameter: '@Orange' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) - end_bracket: ) - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: + - keyword: AS + - procedure_statement: + - statement: + - insert_statement: + - keyword: INSERT + - keyword: INTO + - table_reference: + - naked_identifier: INTER + - dot: . + - naked_identifier: ECDC_CASES + - bracketed: + - start_bracket: ( - column_reference: - quoted_identifier: '[COUNTRY]' - - comma: ',' - - select_clause_element: + - comma: ',' - column_reference: - quoted_identifier: '[COUNTRY_CODE]' - - comma: ',' - - select_clause_element: + - comma: ',' - column_reference: - quoted_identifier: '[CONTINENT]' - - comma: ',' - - select_clause_element: - - function: - - function_name: - - function_name_identifier: CAST - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - quoted_identifier: '[POPULATION]' - - keyword: AS - - data_type: - - data_type_identifier: BIGINT - - end_bracket: ) - - alias_expression: - - keyword: AS + - comma: ',' + - column_reference: - quoted_identifier: '[POPULATION]' - - comma: ',' - - select_clause_element: + - comma: ',' - column_reference: - quoted_identifier: '[INDICATOR]' - - comma: ',' - - select_clause_element: - - function: - - function_name: - - function_name_identifier: CAST - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - quoted_identifier: '[WEEKLY_COUNT]' - - keyword: AS - - data_type: - - data_type_identifier: BIGINT - - end_bracket: ) - - alias_expression: - - keyword: AS + - comma: ',' + - column_reference: - quoted_identifier: '[WEEKLY_COUNT]' - - comma: ',' - - select_clause_element: + - comma: ',' - column_reference: - quoted_identifier: '[YEAR_WEEK]' - - comma: ',' - - select_clause_element: - - function: - - function_name: - - function_name_identifier: CAST - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[CONVERT_ISO_WEEK_TO_DATETIME]' - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: LEFT - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: YEAR_WEEK - - comma: ',' - - expression: - - numeric_literal: '4' - - end_bracket: ) - - comma: ',' - - expression: - - function: - - function_name: - - function_name_identifier: RIGHT - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: YEAR_WEEK - - comma: ',' - - expression: - - numeric_literal: '2' - - end_bracket: ) - - end_bracket: ) - - keyword: AS - - data_type: - - data_type_identifier: DATE - - end_bracket: ) - - alias_expression: - - keyword: AS + - comma: ',' + - column_reference: - quoted_identifier: '[WEEK_START]' - - comma: ',' - - select_clause_element: - - function: - - function_name: - - function_name_identifier: CAST - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[WEEK_END]' - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - quoted_identifier: '[dbo]' - - dot: . - - quoted_identifier: '[CONVERT_ISO_WEEK_TO_DATETIME]' - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: LEFT - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: YEAR_WEEK - - comma: ',' - - expression: - - numeric_literal: '4' - - end_bracket: ) - - comma: ',' - - expression: - - function: - - function_name: - - function_name_identifier: RIGHT - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: YEAR_WEEK - - comma: ',' - - expression: - - numeric_literal: '2' - - end_bracket: ) - - end_bracket: ) - - end_bracket: ) - - keyword: AS - - data_type: - - data_type_identifier: DATE - - end_bracket: ) - - alias_expression: - - keyword: AS + - comma: ',' + - column_reference: - quoted_identifier: '[WEEK_END]' - - comma: ',' - - select_clause_element: - - function: - - function_name: - - function_name_identifier: CAST - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - quoted_identifier: '[RATE_14_DAY]' - - keyword: AS - - data_type: - - data_type_identifier: FLOAT - - end_bracket: ) - - alias_expression: - - keyword: AS + - comma: ',' + - column_reference: - quoted_identifier: '[RATE_14_DAY]' - - comma: ',' - - select_clause_element: - - function: - - function_name: - - function_name_identifier: CAST - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - quoted_identifier: '[CUMULATIVE_COUNT]' - - keyword: AS - - data_type: - - data_type_identifier: BIGINT - - end_bracket: ) - - alias_expression: - - keyword: AS + - comma: ',' + - column_reference: - quoted_identifier: '[CUMULATIVE_COUNT]' - - comma: ',' - - select_clause_element: + - comma: ',' - column_reference: - quoted_identifier: '[SOURCE]' - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: STAGE - - dot: . - - naked_identifier: ECDC_CASES + - end_bracket: ) + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - quoted_identifier: '[COUNTRY]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[COUNTRY_CODE]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[CONTINENT]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '[POPULATION]' + - keyword: AS + - data_type: + - keyword: BIGINT + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[POPULATION]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[INDICATOR]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '[WEEKLY_COUNT]' + - keyword: AS + - data_type: + - keyword: BIGINT + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[WEEKLY_COUNT]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[YEAR_WEEK]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - quoted_identifier: '[dbo]' + - dot: . + - function_name_identifier: '[CONVERT_ISO_WEEK_TO_DATETIME]' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - keyword: LEFT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: YEAR_WEEK + - comma: ',' + - expression: + - integer_literal: '4' + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - keyword: RIGHT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: YEAR_WEEK + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - data_type: + - keyword: DATE + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[WEEK_START]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - quoted_identifier: '[dbo]' + - dot: . + - function_name_identifier: '[WEEK_END]' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - quoted_identifier: '[dbo]' + - dot: . + - function_name_identifier: '[CONVERT_ISO_WEEK_TO_DATETIME]' + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - keyword: LEFT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: YEAR_WEEK + - comma: ',' + - expression: + - integer_literal: '4' + - end_bracket: ) + - comma: ',' + - expression: + - function: + - function_name: + - keyword: RIGHT + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: YEAR_WEEK + - comma: ',' + - expression: + - integer_literal: '2' + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - keyword: AS + - data_type: + - keyword: DATE + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[WEEK_END]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '[RATE_14_DAY]' + - keyword: AS + - data_type: + - keyword: FLOAT + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[RATE_14_DAY]' + - comma: ',' + - select_clause_element: + - function: + - function_name: + - keyword: CAST + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - quoted_identifier: '[CUMULATIVE_COUNT]' + - keyword: AS + - data_type: + - keyword: BIGINT + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '[CUMULATIVE_COUNT]' + - comma: ',' + - select_clause_element: + - column_reference: + - quoted_identifier: '[SOURCE]' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: STAGE + - dot: . + - naked_identifier: ECDC_CASES diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedured_mixed_statements.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedured_mixed_statements.yml index c16779e88..f962ab0d5 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedured_mixed_statements.yml +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/stored_procedured_mixed_statements.yml @@ -1,127 +1,152 @@ file: -- statement: - - create_procedure_statement: - - keyword: CREATE - - keyword: PROC - - object_reference: - - quoted_identifier: '[Reporting]' - - dot: . - - quoted_identifier: '[PowerPlan]' - - keyword: AS - - statement: - - keyword: DECLARE - - tsql_variable: '@DATEFUNCTION' - - data_type: - - data_type_identifier: DATE - - assignment_operator: - - raw_comparison_operator: = - - expression: - - function: - - function_name: - - function_name_identifier: GETDATE - - function_contents: - - bracketed: - - start_bracket: ( - - end_bracket: ) - - statement: - - drop_table_statement: - - keyword: DROP - - keyword: TABLE - - table_reference: - - object_reference: - - quoted_identifier: '[Reporting]' - - dot: . - - quoted_identifier: '[PowerPlan_BASE]' -- statement_terminator: ; -- statement: - - keyword: DECLARE - - tsql_variable: '@deadlock_var' - - data_type: - - data_type_identifier: NCHAR - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '3' - - end_bracket: ) -- statement_terminator: ; -- statement: - - keyword: SET - - tsql_variable: '@deadlock_var' - - assignment_operator: - - raw_comparison_operator: = - - expression: - - data_type: - - data_type_identifier: N - - quoted_literal: '''LOW''' -- statement_terminator: ; -- statement: - - keyword: BEGIN - - keyword: SET - - keyword: NOCOUNT - - keyword: ON - - keyword: SET - - keyword: DEADLOCK_PRIORITY - - keyword: LOW - - keyword: SET - - keyword: DEADLOCK_PRIORITY - - keyword: NORMAL - - keyword: SET - - keyword: DEADLOCK_PRIORITY - - keyword: HIGH - - keyword: SET - - keyword: DEADLOCK_PRIORITY - - tsql_variable: '@deadlock_var' - - keyword: SET - - keyword: DEADLOCK_PRIORITY - - numeric_literal: '10' - - keyword: SET - - keyword: DEADLOCK_PRIORITY - - binary_operator: '-' - - numeric_literal: '5' - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '1' - - create_table_statement: - - create_table_statement: +- batch: + - statement: + - create_procedure_statement: - keyword: CREATE - - keyword: TABLE - - table_reference: - - object_reference: - - naked_identifier: '#TempTest' - - keyword: WITH - - bracketed: - - start_bracket: ( - - keyword: DISTRIBUTION - - comparison_operator: - - raw_comparison_operator: = - - keyword: ROUND_ROBIN - - comma: ',' - - keyword: HEAP - - end_bracket: ) + - keyword: PROC + - object_reference: + - quoted_identifier: '[Reporting]' + - dot: . + - quoted_identifier: '[PowerPlan]' - keyword: AS - - bracketed: - - start_bracket: ( - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - numeric_literal: '2' - - alias_expression: + - procedure_statement: + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@DATEFUNCTION' + - data_type: + - keyword: DATE + - comparison_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: GETDATE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - statement: + - drop_table_statement: + - keyword: DROP + - keyword: TABLE + - table_reference: + - quoted_identifier: '[Reporting]' + - dot: . + - quoted_identifier: '[PowerPlan_BASE]' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@deadlock_var' + - data_type: + - keyword: NCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '3' + - end_bracket: ) + - statement_terminator: ; + - statement: + - set_local_variable_segment: + - keyword: SET + - parameter: '@deadlock_var' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: N'LOW' + - statement_terminator: ; + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - set_segment: + - keyword: SET + - keyword: NOCOUNT + - keyword: ON + - statement: + - set_segment: + - keyword: SET + - keyword: DEADLOCK_PRIORITY + - keyword: LOW + - statement: + - set_segment: + - keyword: SET + - keyword: DEADLOCK_PRIORITY + - keyword: NORMAL + - statement: + - set_segment: + - keyword: SET + - keyword: DEADLOCK_PRIORITY + - keyword: HIGH + - statement: + - set_segment: + - keyword: SET + - keyword: DEADLOCK_PRIORITY + - parameter: '@deadlock_var' + - statement: + - set_segment: + - keyword: SET + - keyword: DEADLOCK_PRIORITY + - numeric_literal: '10' + - statement: + - set_segment: + - keyword: SET + - keyword: DEADLOCK_PRIORITY + - numeric_literal: + - sign_indicator: '-' + - numeric_literal: '5' + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - statement: + - create_table_as_select_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - hash_identifier: '#TempTest' + - table_distribution_index_clause: + - keyword: WITH + - bracketed: + - start_bracket: ( + - table_distribution_clause: + - keyword: DISTRIBUTION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ROUND_ROBIN + - comma: ',' + - table_index_clause: + - keyword: HEAP + - end_bracket: ) - keyword: AS - - naked_identifier: Two - - comma: ',' - - select_clause_element: - - numeric_literal: '3' - - alias_expression: - - keyword: AS - - naked_identifier: Three - - comma: ',' - - select_clause_element: - - numeric_literal: '4' - - alias_expression: - - keyword: AS - - naked_identifier: Four - - end_bracket: ) - - keyword: END + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '2' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Two + - comma: ',' + - select_clause_element: + - integer_literal: '3' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Three + - comma: ',' + - select_clause_element: + - integer_literal: '4' + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: Four + - end_bracket: ) + - keyword: END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/string_agg_within_group.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/string_agg_within_group.sql deleted file mode 100644 index c5d72b4fe..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/string_agg_within_group.sql +++ /dev/null @@ -1,46 +0,0 @@ --- T-SQL STRING_AGG with WITHIN GROUP clause tests - --- Basic STRING_AGG with WITHIN GROUP -SELECT STRING_AGG(FirstName, ', ') WITHIN GROUP (ORDER BY FirstName) -FROM Employees; - --- STRING_AGG with WITHIN GROUP and DESC order -SELECT STRING_AGG(ProductName, ' | ') WITHIN GROUP (ORDER BY Price DESC) -FROM Products; - --- GROUP BY with STRING_AGG and WITHIN GROUP -SELECT - Department, - STRING_AGG(EmployeeName, ', ') WITHIN GROUP (ORDER BY HireDate) -FROM Employees -GROUP BY Department; - --- Multiple aggregations with WITHIN GROUP -SELECT - CategoryID, - STRING_AGG(ProductName, ', ') WITHIN GROUP (ORDER BY ProductName), - COUNT(*) as ProductCount -FROM Products -GROUP BY CategoryID; - --- STRING_AGG with complex ORDER BY in WITHIN GROUP -SELECT - Region, - STRING_AGG(City, ', ') WITHIN GROUP (ORDER BY Population DESC, City ASC) -FROM Cities -GROUP BY Region; - --- STRING_AGG with CAST in WITHIN GROUP -SELECT STRING_AGG(CAST(ProductID AS VARCHAR(10)), '-') WITHIN GROUP (ORDER BY ProductID) -FROM Products -WHERE CategoryID = 1; - --- Nested in subquery -SELECT * -FROM ( - SELECT - DepartmentID, - STRING_AGG(EmployeeName, ', ') WITHIN GROUP (ORDER BY Salary DESC) as TopEarners - FROM Employees - GROUP BY DepartmentID -) AS DeptSummary; \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/string_agg_within_group.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/string_agg_within_group.yml deleted file mode 100644 index bbb986a3c..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/string_agg_within_group.yml +++ /dev/null @@ -1,368 +0,0 @@ -file: -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - function: - - function_name: - - function_name_identifier: STRING_AGG - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: FirstName - - comma: ',' - - expression: - - quoted_literal: ''', ''' - - end_bracket: ) - - withingroup_clause: - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: FirstName - - end_bracket: ) - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: Employees -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - function: - - function_name: - - function_name_identifier: STRING_AGG - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: ProductName - - comma: ',' - - expression: - - quoted_literal: ''' | ''' - - end_bracket: ) - - withingroup_clause: - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: Price - - keyword: DESC - - end_bracket: ) - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: Products -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: Department - - comma: ',' - - select_clause_element: - - function: - - function_name: - - function_name_identifier: STRING_AGG - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: EmployeeName - - comma: ',' - - expression: - - quoted_literal: ''', ''' - - end_bracket: ) - - withingroup_clause: - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: HireDate - - end_bracket: ) - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: Employees - - groupby_clause: - - keyword: GROUP - - keyword: BY - - column_reference: - - naked_identifier: Department -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: CategoryID - - comma: ',' - - select_clause_element: - - function: - - function_name: - - function_name_identifier: STRING_AGG - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: ProductName - - comma: ',' - - expression: - - quoted_literal: ''', ''' - - end_bracket: ) - - withingroup_clause: - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: ProductName - - end_bracket: ) - - comma: ',' - - select_clause_element: - - function: - - function_name: - - function_name_identifier: COUNT - - function_contents: - - bracketed: - - start_bracket: ( - - star: '*' - - end_bracket: ) - - alias_expression: - - keyword: as - - naked_identifier: ProductCount - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: Products - - groupby_clause: - - keyword: GROUP - - keyword: BY - - column_reference: - - naked_identifier: CategoryID -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: Region - - comma: ',' - - select_clause_element: - - function: - - function_name: - - function_name_identifier: STRING_AGG - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: City - - comma: ',' - - expression: - - quoted_literal: ''', ''' - - end_bracket: ) - - withingroup_clause: - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: Population - - keyword: DESC - - comma: ',' - - column_reference: - - naked_identifier: City - - keyword: ASC - - end_bracket: ) - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: Cities - - groupby_clause: - - keyword: GROUP - - keyword: BY - - column_reference: - - naked_identifier: Region -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - function: - - function_name: - - function_name_identifier: STRING_AGG - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - function: - - function_name: - - function_name_identifier: CAST - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: ProductID - - keyword: AS - - data_type: - - data_type_identifier: VARCHAR - - bracketed_arguments: - - bracketed: - - start_bracket: ( - - numeric_literal: '10' - - end_bracket: ) - - end_bracket: ) - - comma: ',' - - expression: - - quoted_literal: '''-''' - - end_bracket: ) - - withingroup_clause: - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: ProductID - - end_bracket: ) - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: Products - - where_clause: - - keyword: WHERE - - expression: - - column_reference: - - naked_identifier: CategoryID - - comparison_operator: - - raw_comparison_operator: = - - numeric_literal: '1' -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - wildcard_expression: - - wildcard_identifier: - - star: '*' - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - bracketed: - - start_bracket: ( - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: DepartmentID - - comma: ',' - - select_clause_element: - - function: - - function_name: - - function_name_identifier: STRING_AGG - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: EmployeeName - - comma: ',' - - expression: - - quoted_literal: ''', ''' - - end_bracket: ) - - withingroup_clause: - - keyword: WITHIN - - keyword: GROUP - - bracketed: - - start_bracket: ( - - orderby_clause: - - keyword: ORDER - - keyword: BY - - column_reference: - - naked_identifier: Salary - - keyword: DESC - - end_bracket: ) - - alias_expression: - - keyword: as - - naked_identifier: TopEarners - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: Employees - - groupby_clause: - - keyword: GROUP - - keyword: BY - - column_reference: - - naked_identifier: DepartmentID - - end_bracket: ) - - alias_expression: - - keyword: AS - - naked_identifier: DeptSummary -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/synonym.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/synonym.sql new file mode 100644 index 000000000..792767bbd --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/synonym.sql @@ -0,0 +1,14 @@ +-- Create a synonym +CREATE SYNONYM my_synonym FOR mytable; + +-- Create a synonym for a multi-part schema +CREATE SYNONYM my_synonym FOR otherdb.dbo.mytable; + +-- Drop a synonym +DROP SYNONYM my_synonym; + +-- Conditionally drop synonym +DROP SYNONYM IF EXISTS my_synonym; + +-- Conditionally drop synonym with schema +DROP SYNONYM IF EXISTS dbo.my_synonym; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/synonym.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/synonym.yml new file mode 100644 index 000000000..a2b371477 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/synonym.yml @@ -0,0 +1,53 @@ +file: +- batch: + - statement: + - create_synonym_statement: + - keyword: CREATE + - keyword: SYNONYM + - synonym_reference: + - naked_identifier: my_synonym + - keyword: FOR + - object_reference: + - naked_identifier: mytable + - statement_terminator: ; + - statement: + - create_synonym_statement: + - keyword: CREATE + - keyword: SYNONYM + - synonym_reference: + - naked_identifier: my_synonym + - keyword: FOR + - object_reference: + - naked_identifier: otherdb + - dot: . + - naked_identifier: dbo + - dot: . + - naked_identifier: mytable + - statement_terminator: ; + - statement: + - drop_synonym_statement: + - keyword: DROP + - keyword: SYNONYM + - synonym_reference: + - naked_identifier: my_synonym + - statement_terminator: ; + - statement: + - drop_synonym_statement: + - keyword: DROP + - keyword: SYNONYM + - keyword: IF + - keyword: EXISTS + - synonym_reference: + - naked_identifier: my_synonym + - statement_terminator: ; + - statement: + - drop_synonym_statement: + - keyword: DROP + - keyword: SYNONYM + - keyword: IF + - keyword: EXISTS + - synonym_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: my_synonym + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/system-variables.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/system-variables.sql new file mode 100644 index 000000000..5cabb0f03 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/system-variables.sql @@ -0,0 +1,19 @@ +UPDATE HumanResources.Employee +SET JobTitle = N'Executive' +WHERE NationalIDNumber = 123456789 +IF @@ROWCOUNT = 0 +PRINT 'Warning: No rows were updated'; +IF @@ERROR = 547 + BEGIN + PRINT N'A check constraint violation occurred.'; + END +GO + +SELECT @@IDENTITY AS 'Identity'; +GO + +PRINT @@TRANCOUNT +GO + +SELECT @@PACK_RECEIVED AS 'Packets Received'; +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/system-variables.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/system-variables.yml new file mode 100644 index 000000000..f64f089f2 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/system-variables.yml @@ -0,0 +1,98 @@ +file: +- batch: + - statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: Employee + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: JobTitle + - assignment_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: N'Executive' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: NationalIDNumber + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '123456789' + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - system_variable: '@@ROWCOUNT' + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '0' + - statement: + - print_statement: + - keyword: PRINT + - expression: + - quoted_literal: '''Warning: No rows were updated''' + - statement_terminator: ; + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - system_variable: '@@ERROR' + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '547' + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - print_statement: + - keyword: PRINT + - expression: + - quoted_literal: N'A check constraint violation occurred.' + - statement_terminator: ; + - keyword: END + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - system_variable: '@@IDENTITY' + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '''Identity''' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - print_statement: + - keyword: PRINT + - expression: + - system_variable: '@@TRANCOUNT' + - go_statement: + - keyword: GO +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - system_variable: '@@PACK_RECEIVED' + - alias_expression: + - alias_operator: + - keyword: AS + - quoted_identifier: '''Packets Received''' + - statement_terminator: ; + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_object_references.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_object_references.sql index 3b21a2bbe..9c61a8edd 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_object_references.sql +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_object_references.sql @@ -1,6 +1,7 @@ --- Test cases from sqlfluff for temp table references --- These ensure backward compatibility with sqlfluff's parsing +select column_1 from ."#my_table" -SELECT column_1 FROM [#my_table]; +select column_1 from .[#my_table]; -SELECT column_1 FROM dbo.[#my_table]; \ No newline at end of file +select column_1 from ..[#my_table]; + +select column_1 from ...[#my_table]; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_object_references.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_object_references.yml index 4af80f73b..b757caf86 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_object_references.yml +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_object_references.yml @@ -1,35 +1,68 @@ file: -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: column_1 - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: column_1 + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - leading_dot: . + - quoted_identifier: '"#my_table"' + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: column_1 + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - leading_dot: . - quoted_identifier: '[#my_table]' -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: column_1 - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: dbo + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: column_1 + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - leading_dot: . - dot: . - quoted_identifier: '[#my_table]' -- statement_terminator: ; + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: select + - select_clause_element: + - column_reference: + - naked_identifier: column_1 + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - leading_dot: . + - dot: . + - dot: . + - quoted_identifier: '[#my_table]' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variable_simple.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variable_simple.sql deleted file mode 100644 index 1cc27d286..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variable_simple.sql +++ /dev/null @@ -1 +0,0 @@ -SELECT [value] FROM @DepartmentCodes; \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables.sql index 9ff74cd1c..31247fe41 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables.sql +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables.sql @@ -1,3 +1,4 @@ -SELECT [value] FROM @DepartmentCodes; -SELECT ids.[value] FROM @DepartmentCodes AS ids; -SELECT * FROM @TableVariable WITH (NOLOCK); \ No newline at end of file +declare @queue table ( + id int, + url nvarchar(100) +) diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables.yml index a5fe98ecf..11cee2f66 100644 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables.yml +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables.yml @@ -1,57 +1,25 @@ file: -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - quoted_identifier: '[value]' - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - tsql_variable: '@DepartmentCodes' -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - column_reference: - - naked_identifier: ids - - dot: . - - quoted_identifier: '[value]' - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - tsql_variable: '@DepartmentCodes' - - alias_expression: - - keyword: AS - - naked_identifier: ids -- statement_terminator: ; -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - wildcard_expression: - - wildcard_identifier: - - star: '*' - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - tsql_variable: '@TableVariable' - - keyword: WITH - - bracketed: - - start_bracket: ( - - keyword: NOLOCK - - end_bracket: ) -- statement_terminator: ; +- batch: + - statement: + - declare_segment: + - keyword: declare + - parameter: '@queue' + - keyword: table + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: id + - data_type: + - keyword: int + - comma: ',' + - column_definition: + - naked_identifier: url + - data_type: + - keyword: nvarchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - end_bracket: ) diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables_comprehensive.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables_comprehensive.sql deleted file mode 100644 index 6d46274bb..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/table_variables_comprehensive.sql +++ /dev/null @@ -1,14 +0,0 @@ --- Basic table variable usage -SELECT [value] FROM @DepartmentCodes; - --- Table variable with alias -SELECT ids.[value] FROM @DepartmentCodes AS ids; - --- Table variable with WHERE clause -SELECT * FROM @TableVariable WHERE [value] > 0; - --- Table variable with table hints -SELECT * FROM @TableVariable WITH (NOLOCK); - --- Table variable in subquery -SELECT * FROM table1 WHERE id IN (SELECT [value] FROM @DepartmentCodes); \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tablesample.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tablesample.sql new file mode 100644 index 000000000..8856de43d --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tablesample.sql @@ -0,0 +1,11 @@ +SELECT * +FROM Sales.Customer TABLESAMPLE SYSTEM (10 PERCENT); + +SELECT * +FROM Sales.Customer TABLESAMPLE (10 ROWS); + +SELECT * +FROM Sales.Customer TABLESAMPLE (10); + +SELECT * +FROM Sales.Customer TABLESAMPLE SYSTEM (10 ROWS) REPEATABLE (100); diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tablesample.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tablesample.yml new file mode 100644 index 000000000..8c823d5bb --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tablesample.yml @@ -0,0 +1,108 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: Customer + - sample_expression: + - keyword: TABLESAMPLE + - keyword: SYSTEM + - bracketed: + - start_bracket: ( + - numeric_literal: '10' + - keyword: PERCENT + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: Customer + - sample_expression: + - keyword: TABLESAMPLE + - bracketed: + - start_bracket: ( + - numeric_literal: '10' + - keyword: ROWS + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: Customer + - sample_expression: + - keyword: TABLESAMPLE + - bracketed: + - start_bracket: ( + - numeric_literal: '10' + - end_bracket: ) + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: Customer + - sample_expression: + - keyword: TABLESAMPLE + - keyword: SYSTEM + - bracketed: + - start_bracket: ( + - numeric_literal: '10' + - keyword: ROWS + - end_bracket: ) + - keyword: REPEATABLE + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temp_tables.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temp_tables.sql new file mode 100644 index 000000000..fa34f4ce1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temp_tables.sql @@ -0,0 +1,9 @@ +SELECT a + ,b + ,c +FROM #UnionA; + +Select d + ,e + ,f +FROM ##UnionB; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temp_tables.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temp_tables.yml new file mode 100644 index 000000000..7d97571e7 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temp_tables.yml @@ -0,0 +1,48 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: a + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: b + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: c + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - hash_identifier: '#UnionA' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: Select + - select_clause_element: + - column_reference: + - naked_identifier: d + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: e + - comma: ',' + - select_clause_element: + - column_reference: + - naked_identifier: f + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - hash_identifier: '##UnionB' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temporal_tables.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temporal_tables.sql new file mode 100644 index 000000000..2fe3b2e23 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temporal_tables.sql @@ -0,0 +1,153 @@ +-- Select Query Temporal Tables + +SELECT * FROM Employee + FOR SYSTEM_TIME + BETWEEN '2021-01-01 00:00:00.0000000' AND '2022-01-01 00:00:00.0000000'; + +SELECT * FROM Employee + FOR SYSTEM_TIME ALL; + +SELECT * FROM Employee + FOR SYSTEM_TIME + FROM '2021-01-01 00:00:00.0000000' TO '2022-01-01 00:00:00.0000000'; + +SELECT * FROM Employee + FOR SYSTEM_TIME + AS OF '2021-01-01 00:00:00.0000000'; + +SELECT * FROM Employee + FOR SYSTEM_TIME + CONTAINED IN ('2021-01-01 00:00:00.0000000', '2022-01-01 00:00:00.0000000'); + +DECLARE @StartTime DATETIME2 = '2021-01-01 00:00:00'; +DECLARE @EndTime DATETIME2 = '2022-01-01 00:00:00'; +SELECT * FROM Employee + FOR SYSTEM_TIME + FROM @StartTime TO @EndTime; + +DECLARE @PointInTime DATETIME2 = '2021-01-01 00:00:00'; +SELECT * FROM Employee + FOR SYSTEM_TIME + AS OF @PointInTime; + +-- Create Temporal Tables + +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.EmployeeHistory), DURABILITY = SCHEMA_ONLY ); +; +GO + + +-- https://learn.microsoft.com/en-us/sql/relational-databases/tables/creating-a-system-versioned-temporal-table?view=sql-server-ver16#creating-a-temporal-table-with-a-default-history-table +CREATE TABLE Department +( + DeptID INT NOT NULL PRIMARY KEY CLUSTERED + , DeptName VARCHAR(50) NOT NULL + , ManagerID INT NULL + , ParentDeptID INT NULL + , ValidFrom DATETIME2 GENERATED ALWAYS AS ROW START NOT NULL + , ValidTo DATETIME2 GENERATED ALWAYS AS ROW END NOT NULL + , PERIOD FOR SYSTEM_TIME (ValidFrom, ValidTo) +) +WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.DepartmentHistory)) +; +GO + +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH (FILETABLE_PRIMARY_KEY_CONSTRAINT_NAME = COLUMNC ); +; +GO + +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH (DATA_DELETION = ON (FILTER_COLUMN = ColumnC, RETENTION_PERIOD = INFINITE)); +; +GO + +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH +( + MEMORY_OPTIMIZED = ON, + DURABILITY = SCHEMA_AND_DATA, + SYSTEM_VERSIONING = ON (HISTORY_TABLE = History.DepartmentHistory) +); +GO + +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH +( + REMOTE_DATA_ARCHIVE = OFF ( MIGRATION_STATE = PAUSED ), + LEDGER = ON (LEDGER_VIEW = dbo.ABC (TRANSACTION_ID_COLUMN_NAME = [ColumnC], SEQUENCE_NUMBER_COLUMN_NAME = [ColumnDecimal])) +); +GO + +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH +( + DATA_COMPRESSION = ROW + XML_COMPRESSION = ON ON PARTITIONS (2) +); +GO + +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH +( + DATA_COMPRESSION = PAGE ON PARTITIONS (3, 5) + XML_COMPRESSION = OFF +); +GO + +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH +( + XML_COMPRESSION = ON ON PARTITIONS (3 TO 5), + FILETABLE_DIRECTORY = '/path1/path2', + FILETABLE_COLLATE_FILENAME = constraint1, + FILETABLE_PRIMARY_KEY_CONSTRAINT_NAME = constraint2, + FILETABLE_STREAMID_UNIQUE_CONSTRAINT_NAME = constraint3, + FILETABLE_FULLPATH_UNIQUE_CONSTRAINT_NAME = constraint4 +); +GO + +CREATE TABLE [dbo].[EC DC] ( + [Column B] [varchar](100), + [ColumnC] varchar(100), + [ColumnDecimal] decimal(10,3) +) +WITH +( + REMOTE_DATA_ARCHIVE = ON ( FILTER_PREDICATE = NULL, MIGRATION_STATE = OUTBOUND), + LEDGER = ON (LEDGER_VIEW = dbo.ABC, APPEND_ONLY = ON) +); +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temporal_tables.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temporal_tables.yml new file mode 100644 index 000000000..b49097258 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/temporal_tables.yml @@ -0,0 +1,998 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Employee + - temporal_query: + - keyword: FOR + - keyword: SYSTEM_TIME + - keyword: BETWEEN + - quoted_literal: '''2021-01-01 00:00:00.0000000''' + - keyword: AND + - quoted_literal: '''2022-01-01 00:00:00.0000000''' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Employee + - temporal_query: + - keyword: FOR + - keyword: SYSTEM_TIME + - keyword: ALL + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Employee + - temporal_query: + - keyword: FOR + - keyword: SYSTEM_TIME + - keyword: FROM + - quoted_literal: '''2021-01-01 00:00:00.0000000''' + - keyword: TO + - quoted_literal: '''2022-01-01 00:00:00.0000000''' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Employee + - temporal_query: + - keyword: FOR + - keyword: SYSTEM_TIME + - keyword: AS + - keyword: OF + - quoted_literal: '''2021-01-01 00:00:00.0000000''' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Employee + - temporal_query: + - keyword: FOR + - keyword: SYSTEM_TIME + - keyword: CONTAINED + - keyword: IN + - bracketed: + - start_bracket: ( + - quoted_literal: '''2021-01-01 00:00:00.0000000''' + - comma: ',' + - quoted_literal: '''2022-01-01 00:00:00.0000000''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@StartTime' + - data_type: + - keyword: DATETIME2 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''2021-01-01 00:00:00''' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@EndTime' + - data_type: + - keyword: DATETIME2 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''2022-01-01 00:00:00''' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Employee + - temporal_query: + - keyword: FOR + - keyword: SYSTEM_TIME + - keyword: FROM + - parameter: '@StartTime' + - keyword: TO + - parameter: '@EndTime' + - statement_terminator: ; + - statement: + - declare_segment: + - keyword: DECLARE + - parameter: '@PointInTime' + - data_type: + - keyword: DATETIME2 + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''2021-01-01 00:00:00''' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Employee + - temporal_query: + - keyword: FOR + - keyword: SYSTEM_TIME + - keyword: AS + - keyword: OF + - parameter: '@PointInTime' + - statement_terminator: ; + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: HISTORY_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: EmployeeHistory + - end_bracket: ) + - comma: ',' + - keyword: DURABILITY + - comparison_operator: + - raw_comparison_operator: = + - keyword: SCHEMA_ONLY + - end_bracket: ) + - statement_terminator: ; + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - naked_identifier: Department + - bracketed: + - start_bracket: ( + - column_definition: + - naked_identifier: DeptID + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - column_constraint_segment: + - keyword: PRIMARY + - keyword: KEY + - keyword: CLUSTERED + - comma: ',' + - column_definition: + - naked_identifier: DeptName + - data_type: + - keyword: VARCHAR + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '50' + - end_bracket: ) + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: ManagerID + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: ParentDeptID + - data_type: + - keyword: INT + - column_constraint_segment: + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: ValidFrom + - data_type: + - keyword: DATETIME2 + - column_constraint_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - keyword: ROW + - keyword: START + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - column_definition: + - naked_identifier: ValidTo + - data_type: + - keyword: DATETIME2 + - column_constraint_segment: + - keyword: GENERATED + - keyword: ALWAYS + - keyword: AS + - keyword: ROW + - keyword: END + - column_constraint_segment: + - keyword: NOT + - keyword: 'NULL' + - comma: ',' + - period_segment: + - keyword: PERIOD + - keyword: FOR + - keyword: SYSTEM_TIME + - bracketed: + - start_bracket: ( + - column_reference: + - naked_identifier: ValidFrom + - comma: ',' + - column_reference: + - naked_identifier: ValidTo + - end_bracket: ) + - end_bracket: ) + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: HISTORY_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: DepartmentHistory + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: FILETABLE_PRIMARY_KEY_CONSTRAINT_NAME + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: COLUMNC + - end_bracket: ) + - statement_terminator: ; + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: DATA_DELETION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: FILTER_COLUMN + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: ColumnC + - comma: ',' + - keyword: RETENTION_PERIOD + - comparison_operator: + - raw_comparison_operator: = + - date_part: INFINITE + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: MEMORY_OPTIMIZED + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - comma: ',' + - keyword: DURABILITY + - comparison_operator: + - raw_comparison_operator: = + - keyword: SCHEMA_AND_DATA + - comma: ',' + - keyword: SYSTEM_VERSIONING + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: HISTORY_TABLE + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - naked_identifier: History + - dot: . + - naked_identifier: DepartmentHistory + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: REMOTE_DATA_ARCHIVE + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - bracketed: + - start_bracket: ( + - keyword: MIGRATION_STATE + - comparison_operator: + - raw_comparison_operator: = + - keyword: PAUSED + - end_bracket: ) + - comma: ',' + - keyword: LEDGER + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: LEDGER_VIEW + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ABC + - bracketed: + - start_bracket: ( + - keyword: TRANSACTION_ID_COLUMN_NAME + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - quoted_identifier: '[ColumnC]' + - comma: ',' + - keyword: SEQUENCE_NUMBER_COLUMN_NAME + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - quoted_identifier: '[ColumnDecimal]' + - end_bracket: ) + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: DATA_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ROW + - keyword: XML_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - keyword: ON + - keyword: PARTITIONS + - bracketed: + - start_bracket: ( + - numeric_literal: '2' + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: DATA_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - keyword: PAGE + - keyword: ON + - keyword: PARTITIONS + - bracketed: + - start_bracket: ( + - numeric_literal: '3' + - comma: ',' + - numeric_literal: '5' + - end_bracket: ) + - keyword: XML_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - keyword: OFF + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: XML_COMPRESSION + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - keyword: ON + - keyword: PARTITIONS + - bracketed: + - start_bracket: ( + - numeric_literal: '3' + - keyword: TO + - numeric_literal: '5' + - end_bracket: ) + - comma: ',' + - keyword: FILETABLE_DIRECTORY + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''/path1/path2''' + - comma: ',' + - keyword: FILETABLE_COLLATE_FILENAME + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: constraint1 + - comma: ',' + - keyword: FILETABLE_PRIMARY_KEY_CONSTRAINT_NAME + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: constraint2 + - comma: ',' + - keyword: FILETABLE_STREAMID_UNIQUE_CONSTRAINT_NAME + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: constraint3 + - comma: ',' + - keyword: FILETABLE_FULLPATH_UNIQUE_CONSTRAINT_NAME + - comparison_operator: + - raw_comparison_operator: = + - object_reference: + - naked_identifier: constraint4 + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_table_statement: + - keyword: CREATE + - keyword: TABLE + - table_reference: + - quoted_identifier: '[dbo]' + - dot: . + - quoted_identifier: '[EC DC]' + - bracketed: + - start_bracket: ( + - column_definition: + - quoted_identifier: '[Column B]' + - data_type: + - data_type_identifier: '[varchar]' + - bracketed: + - start_bracket: ( + - numeric_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnC]' + - data_type: + - keyword: varchar + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '100' + - end_bracket: ) + - comma: ',' + - column_definition: + - quoted_identifier: '[ColumnDecimal]' + - data_type: + - keyword: decimal + - bracketed_arguments: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '10' + - comma: ',' + - expression: + - integer_literal: '3' + - end_bracket: ) + - end_bracket: ) + - table_option_statement: + - keyword: WITH + - bracketed: + - start_bracket: ( + - keyword: REMOTE_DATA_ARCHIVE + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: FILTER_PREDICATE + - comparison_operator: + - raw_comparison_operator: = + - keyword: 'NULL' + - comma: ',' + - keyword: MIGRATION_STATE + - comparison_operator: + - raw_comparison_operator: = + - keyword: OUTBOUND + - end_bracket: ) + - comma: ',' + - keyword: LEDGER + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - bracketed: + - start_bracket: ( + - keyword: LEDGER_VIEW + - comparison_operator: + - raw_comparison_operator: = + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: ABC + - comma: ',' + - keyword: APPEND_ONLY + - comparison_operator: + - raw_comparison_operator: = + - keyword: ON + - end_bracket: ) + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/transaction.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/transaction.sql new file mode 100644 index 000000000..b7a778aa1 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/transaction.sql @@ -0,0 +1,17 @@ +BEGIN TRANSACTION; +DELETE FROM HumanResources.JobCandidate + WHERE JobCandidateID = 13; +COMMIT; + +BEGIN TRAN; +DELETE FROM HumanResources.JobCandidate + WHERE JobCandidateID = 13; +ROLLBACK TRAN; + +BEGIN TRAN; +SAVE TRANSACTION; + +BEGIN TRAN namey; +ROLLBACK namey; +SAVE TRAN @variable; +COMMIT @variable; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/transaction.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/transaction.yml new file mode 100644 index 000000000..de529d237 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/transaction.yml @@ -0,0 +1,87 @@ +file: +- batch: + - statement: + - transaction_statement: + - keyword: BEGIN + - keyword: TRANSACTION + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: JobCandidate + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: JobCandidateID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '13' + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: COMMIT + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: BEGIN + - keyword: TRAN + - statement_terminator: ; + - statement: + - delete_statement: + - keyword: DELETE + - keyword: FROM + - table_reference: + - naked_identifier: HumanResources + - dot: . + - naked_identifier: JobCandidate + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: JobCandidateID + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '13' + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: ROLLBACK + - keyword: TRAN + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: BEGIN + - keyword: TRAN + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: SAVE + - keyword: TRANSACTION + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: BEGIN + - keyword: TRAN + - naked_identifier: namey + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: ROLLBACK + - naked_identifier: namey + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: SAVE + - keyword: TRAN + - parameter: '@variable' + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: COMMIT + - parameter: '@variable' + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/triggers.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/triggers.sql new file mode 100644 index 000000000..5f942a463 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/triggers.sql @@ -0,0 +1,139 @@ +CREATE TRIGGER reminder1 +ON Sales.Customer +AFTER INSERT, UPDATE +AS RAISERROR ('Notify Customer Relations', 16, 10); +GO + +CREATE TRIGGER reminder2 +ON Sales.Customer +AFTER INSERT, UPDATE, DELETE +AS + EXEC msdb.dbo.sp_send_dbmail + @profile_name = 'AdventureWorks2012 Administrator', + @recipients = 'danw@Adventure-Works.com', + @body = 'Don''t forget to print a report for the sales force.', + @subject = 'Reminder'; +GO + +CREATE TRIGGER Purchasing.LowCredit ON Purchasing.PurchaseOrderHeader +AFTER INSERT +AS +IF (ROWCOUNT_BIG() = 0) +RETURN; +IF EXISTS (SELECT 1 + FROM inserted AS i + JOIN Purchasing.Vendor AS v + ON v.BusinessEntityID = i.VendorID + WHERE v.CreditRating = 5 + ) +BEGIN +RAISERROR ('A vendor''s credit rating is too low to accept new +purchase orders.', 16, 1); +ROLLBACK TRANSACTION; +RETURN +END; +GO + + +CREATE TRIGGER safety +ON DATABASE +FOR DROP_SYNONYM +AS +IF (@@ROWCOUNT = 0) +RETURN; + RAISERROR ('You must disable Trigger "safety" to remove synonyms!', 10, 1) + ROLLBACK +GO +DROP TRIGGER safety +ON DATABASE; +GO + +CREATE TRIGGER ddl_trig_database +ON ALL SERVER +FOR CREATE_DATABASE +AS + PRINT 'Database Created.' + SELECT 1 +GO + +CREATE TRIGGER ddl_trig_database +ON ALL SERVER +FOR CREATE_DATABASE +AS + PRINT 'Database Created.'; + SELECT 1 +GO + +DROP TRIGGER ddl_trig_database +ON ALL SERVER; +GO + +CREATE TRIGGER connection_limit_trigger +ON ALL SERVER WITH EXECUTE AS 'login_test' +FOR LOGON +AS +BEGIN +IF ORIGINAL_LOGIN()= 'login_test' AND + (SELECT COUNT(*) FROM sys.dm_exec_sessions + WHERE is_user_process = 1 AND + original_login_name = 'login_test') > 3 + ROLLBACK; +END; +GO + +Create TRIGGER dbo.tr_SP_BALS_L2_ATTRIBUTES +ON dbo.SP_BALS_L2_ATTRIBUTES + AFTER UPDATE + AS + UPDATE dbo.SP_BALS_L2_ATTRIBUTES + SET PDW_LAST_UPDATED = Getdate() + FROM dbo.SP_BALS_L2_ATTRIBUTES o + INNER JOIN Inserted i + ON + o.PK_L2_BALS = i.PK_L2_BALS +go + +disable trigger dbo.tr_SP_BALS_L2_ATTRIBUTES on dbo.SP_BALS_L2_ATTRIBUTES +go + + +Create TRIGGER dbo.tr_u_SP_BALS_L2_ATTRIBUTES +ON dbo.SP_BALS_L2_ATTRIBUTES + AFTER UPDATE + AS + UPDATE dbo.SP_BALS_L2_ATTRIBUTES + SET PDW_LAST_UPDATED = sysdatetime() + FROM dbo.SP_BALS_L2_ATTRIBUTES o + INNER JOIN Inserted i + ON + o.PK_L2_BALS = i.PK_L2_BALS +GO + +DROP TRIGGER employee_insupd; +GO + +DROP TRIGGER safety +ON DATABASE; +GO + +disable trigger dbo.tr_u_SP_BALS_L2_ATTRIBUTES on dbo.SP_BALS_L2_ATTRIBUTES +GO + +DISABLE TRIGGER safety ON DATABASE; +GO + +CREATE OR ALTER TRIGGER reminder1 +ON Sales.Customer +AFTER INSERT, UPDATE +AS RAISERROR ('Notify Customer Relations', 16, 10); +GO + +CREATE TRIGGER reminder +ON person.address +AFTER UPDATE +AS +IF (UPDATE(stateprovinceid) OR UPDATE(postalcode)) + BEGIN + RAISERROR (50009, 16, 10) + END; +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/triggers.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/triggers.yml new file mode 100644 index 000000000..62816fe61 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/triggers.yml @@ -0,0 +1,735 @@ +file: +- batch: + - statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: reminder1 + - keyword: ON + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: Customer + - keyword: AFTER + - keyword: INSERT + - comma: ',' + - keyword: UPDATE + - keyword: AS + - statement: + - raiserror_statement: + - keyword: RAISERROR + - bracketed: + - start_bracket: ( + - quoted_literal: '''Notify Customer Relations''' + - comma: ',' + - numeric_literal: '16' + - comma: ',' + - numeric_literal: '10' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: reminder2 + - keyword: ON + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: Customer + - keyword: AFTER + - keyword: INSERT + - comma: ',' + - keyword: UPDATE + - comma: ',' + - keyword: DELETE + - keyword: AS + - statement: + - execute_script_statement: + - keyword: EXEC + - object_reference: + - naked_identifier: msdb + - dot: . + - naked_identifier: dbo + - dot: . + - naked_identifier: sp_send_dbmail + - parameter: '@profile_name' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''AdventureWorks2012 Administrator''' + - comma: ',' + - parameter: '@recipients' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''danw@Adventure-Works.com''' + - comma: ',' + - parameter: '@body' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''Don''''t forget to print a report for the sales force.''' + - comma: ',' + - parameter: '@subject' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''Reminder''' + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: Purchasing + - dot: . + - naked_identifier: LowCredit + - keyword: ON + - table_reference: + - naked_identifier: Purchasing + - dot: . + - naked_identifier: PurchaseOrderHeader + - keyword: AFTER + - keyword: INSERT + - keyword: AS + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: ROWCOUNT_BIG + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '0' + - end_bracket: ) + - statement: + - return_segment: + - keyword: RETURN + - statement_terminator: ; + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - keyword: EXISTS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: inserted + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: i + - join_clause: + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Purchasing + - dot: . + - naked_identifier: Vendor + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: v + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: v + - dot: . + - naked_identifier: BusinessEntityID + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: i + - dot: . + - naked_identifier: VendorID + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: v + - dot: . + - naked_identifier: CreditRating + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '5' + - end_bracket: ) + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - raiserror_statement: + - keyword: RAISERROR + - bracketed: + - start_bracket: ( + - quoted_literal: |- + 'A vendor''s credit rating is too low to accept new + purchase orders.' + - comma: ',' + - numeric_literal: '16' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - statement_terminator: ; + - statement: + - transaction_statement: + - keyword: ROLLBACK + - keyword: TRANSACTION + - statement_terminator: ; + - statement: + - return_segment: + - keyword: RETURN + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: safety + - keyword: ON + - keyword: DATABASE + - keyword: FOR + - naked_identifier: DROP_SYNONYM + - keyword: AS + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - bracketed: + - start_bracket: ( + - expression: + - system_variable: '@@ROWCOUNT' + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '0' + - end_bracket: ) + - statement: + - return_segment: + - keyword: RETURN + - statement_terminator: ; + - statement: + - raiserror_statement: + - keyword: RAISERROR + - bracketed: + - start_bracket: ( + - quoted_literal: '''You must disable Trigger "safety" to remove synonyms!''' + - comma: ',' + - numeric_literal: '10' + - comma: ',' + - numeric_literal: '1' + - end_bracket: ) + - statement: + - transaction_statement: + - keyword: ROLLBACK + - go_statement: + - keyword: GO +- batch: + - statement: + - drop_trigger_statement: + - keyword: DROP + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: safety + - keyword: ON + - keyword: DATABASE + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: ddl_trig_database + - keyword: ON + - keyword: ALL + - keyword: SERVER + - keyword: FOR + - naked_identifier: CREATE_DATABASE + - keyword: AS + - statement: + - print_statement: + - keyword: PRINT + - expression: + - quoted_literal: '''Database Created.''' + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - go_statement: + - keyword: GO +- batch: + - statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: ddl_trig_database + - keyword: ON + - keyword: ALL + - keyword: SERVER + - keyword: FOR + - naked_identifier: CREATE_DATABASE + - keyword: AS + - statement: + - print_statement: + - keyword: PRINT + - expression: + - quoted_literal: '''Database Created.''' + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - integer_literal: '1' + - go_statement: + - keyword: GO +- batch: + - statement: + - drop_trigger_statement: + - keyword: DROP + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: ddl_trig_database + - keyword: ON + - keyword: ALL + - keyword: SERVER + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: connection_limit_trigger + - keyword: ON + - keyword: ALL + - keyword: SERVER + - keyword: WITH + - execute_as_clause: + - keyword: EXECUTE + - keyword: AS + - quoted_identifier: '''login_test''' + - keyword: FOR + - naked_identifier: LOGON + - keyword: AS + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - function: + - function_name: + - function_name_identifier: ORIGINAL_LOGIN + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''login_test''' + - binary_operator: AND + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: COUNT + - function_contents: + - bracketed: + - start_bracket: ( + - star: '*' + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: sys + - dot: . + - naked_identifier: dm_exec_sessions + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: is_user_process + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - binary_operator: AND + - column_reference: + - naked_identifier: original_login_name + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''login_test''' + - end_bracket: ) + - comparison_operator: + - raw_comparison_operator: '>' + - integer_literal: '3' + - statement: + - transaction_statement: + - keyword: ROLLBACK + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_trigger_statement: + - keyword: Create + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: tr_SP_BALS_L2_ATTRIBUTES + - keyword: ON + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: SP_BALS_L2_ATTRIBUTES + - keyword: AFTER + - keyword: UPDATE + - keyword: AS + - statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: SP_BALS_L2_ATTRIBUTES + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: PDW_LAST_UPDATED + - assignment_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: Getdate + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: SP_BALS_L2_ATTRIBUTES + - alias_expression: + - naked_identifier: o + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Inserted + - alias_expression: + - naked_identifier: i + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: o + - dot: . + - naked_identifier: PK_L2_BALS + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: i + - dot: . + - naked_identifier: PK_L2_BALS + - go_statement: + - keyword: go +- batch: + - statement: + - disable_trigger: + - keyword: disable + - keyword: trigger + - trigger_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: tr_SP_BALS_L2_ATTRIBUTES + - keyword: on + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: SP_BALS_L2_ATTRIBUTES + - go_statement: + - keyword: go +- batch: + - statement: + - create_trigger_statement: + - keyword: Create + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: tr_u_SP_BALS_L2_ATTRIBUTES + - keyword: ON + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: SP_BALS_L2_ATTRIBUTES + - keyword: AFTER + - keyword: UPDATE + - keyword: AS + - statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: SP_BALS_L2_ATTRIBUTES + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: PDW_LAST_UPDATED + - assignment_operator: + - raw_comparison_operator: = + - expression: + - function: + - function_name: + - function_name_identifier: sysdatetime + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: SP_BALS_L2_ATTRIBUTES + - alias_expression: + - naked_identifier: o + - join_clause: + - keyword: INNER + - keyword: JOIN + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: Inserted + - alias_expression: + - naked_identifier: i + - join_on_condition: + - keyword: ON + - expression: + - column_reference: + - naked_identifier: o + - dot: . + - naked_identifier: PK_L2_BALS + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: i + - dot: . + - naked_identifier: PK_L2_BALS + - go_statement: + - keyword: GO +- batch: + - statement: + - drop_trigger_statement: + - keyword: DROP + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: employee_insupd + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - drop_trigger_statement: + - keyword: DROP + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: safety + - keyword: ON + - keyword: DATABASE + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - disable_trigger: + - keyword: disable + - keyword: trigger + - trigger_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: tr_u_SP_BALS_L2_ATTRIBUTES + - keyword: on + - object_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: SP_BALS_L2_ATTRIBUTES + - go_statement: + - keyword: GO +- batch: + - statement: + - disable_trigger: + - keyword: DISABLE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: safety + - keyword: ON + - keyword: DATABASE + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: OR + - keyword: ALTER + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: reminder1 + - keyword: ON + - table_reference: + - naked_identifier: Sales + - dot: . + - naked_identifier: Customer + - keyword: AFTER + - keyword: INSERT + - comma: ',' + - keyword: UPDATE + - keyword: AS + - statement: + - raiserror_statement: + - keyword: RAISERROR + - bracketed: + - start_bracket: ( + - quoted_literal: '''Notify Customer Relations''' + - comma: ',' + - numeric_literal: '16' + - comma: ',' + - numeric_literal: '10' + - end_bracket: ) + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - create_trigger_statement: + - keyword: CREATE + - keyword: TRIGGER + - trigger_reference: + - naked_identifier: reminder + - keyword: ON + - table_reference: + - naked_identifier: person + - dot: . + - naked_identifier: address + - keyword: AFTER + - keyword: UPDATE + - keyword: AS + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - bracketed: + - start_bracket: ( + - expression: + - function: + - function_name: + - function_name_identifier: UPDATE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: stateprovinceid + - end_bracket: ) + - binary_operator: OR + - function: + - function_name: + - function_name_identifier: UPDATE + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: postalcode + - end_bracket: ) + - end_bracket: ) + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - raiserror_statement: + - keyword: RAISERROR + - bracketed: + - start_bracket: ( + - numeric_literal: '50009' + - comma: ',' + - numeric_literal: '16' + - comma: ',' + - numeric_literal: '10' + - end_bracket: ) + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/try_catch.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/try_catch.sql new file mode 100644 index 000000000..dcd46a890 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/try_catch.sql @@ -0,0 +1,21 @@ +BEGIN TRY + -- Table does not exist; object name resolution + -- error not caught. + SELECT * FROM NonexistentTable; +END TRY +BEGIN CATCH + SELECT + ERROR_NUMBER() AS ErrorNumber + ,ERROR_MESSAGE() AS ErrorMessage; + + THROW +END CATCH +GO + +THROW 50005, N'an error occurred', 1; + +BEGIN TRY + EXEC spSomeProc +END TRY +BEGIN CATCH +END CATCH; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/try_catch.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/try_catch.yml new file mode 100644 index 000000000..a25a0d541 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/try_catch.yml @@ -0,0 +1,89 @@ +file: +- batch: + - statement: + - try_catch: + - keyword: BEGIN + - keyword: TRY + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: NonexistentTable + - statement_terminator: ; + - keyword: END + - keyword: TRY + - keyword: BEGIN + - keyword: CATCH + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - function_name_identifier: ERROR_NUMBER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: ErrorNumber + - comma: ',' + - select_clause_element: + - function: + - function_name: + - function_name_identifier: ERROR_MESSAGE + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - alias_expression: + - alias_operator: + - keyword: AS + - naked_identifier: ErrorMessage + - statement_terminator: ; + - statement: + - throw_statement: + - keyword: THROW + - keyword: END + - keyword: CATCH + - go_statement: + - keyword: GO +- batch: + - statement: + - throw_statement: + - keyword: THROW + - numeric_literal: '50005' + - comma: ',' + - quoted_literal: N'an error occurred' + - comma: ',' + - numeric_literal: '1' + - statement_terminator: ; + - statement: + - try_catch: + - keyword: BEGIN + - keyword: TRY + - statement: + - execute_script_statement: + - keyword: EXEC + - object_reference: + - naked_identifier: spSomeProc + - keyword: END + - keyword: TRY + - keyword: BEGIN + - keyword: CATCH + - keyword: END + - keyword: CATCH + - statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_column_ref.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_column_ref.sql deleted file mode 100644 index 8ace6fdb9..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_column_ref.sql +++ /dev/null @@ -1,13 +0,0 @@ --- Test T-SQL alias equals syntax with column references -SELECT - -- Simple identifier - SimpleAlias = value, - -- Column reference with table prefix - QualifiedAlias = table1.column1, - -- Column reference with schema.table prefix - FullyQualifiedAlias = dbo.table1.column1, - -- Function call - FunctionAlias = SUM(quantity), - -- Complex expression - ExpressionAlias = table1.price * table1.quantity -FROM table1; \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_column_ref.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_column_ref.yml deleted file mode 100644 index 895770e51..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_column_ref.yml +++ /dev/null @@ -1,65 +0,0 @@ -file: -- statement: - - select_statement: - - select_clause: - - keyword: SELECT - - select_clause_element: - - naked_identifier: SimpleAlias - - raw_comparison_operator: = - - column_reference: - - naked_identifier: value - - comma: ',' - - select_clause_element: - - naked_identifier: QualifiedAlias - - raw_comparison_operator: = - - column_reference: - - naked_identifier: table1 - - dot: . - - naked_identifier: column1 - - comma: ',' - - select_clause_element: - - naked_identifier: FullyQualifiedAlias - - raw_comparison_operator: = - - column_reference: - - naked_identifier: dbo - - dot: . - - naked_identifier: table1 - - dot: . - - naked_identifier: column1 - - comma: ',' - - select_clause_element: - - naked_identifier: FunctionAlias - - raw_comparison_operator: = - - function: - - function_name: - - function_name_identifier: SUM - - function_contents: - - bracketed: - - start_bracket: ( - - expression: - - column_reference: - - naked_identifier: quantity - - end_bracket: ) - - comma: ',' - - select_clause_element: - - naked_identifier: ExpressionAlias - - raw_comparison_operator: = - - expression: - - column_reference: - - naked_identifier: table1 - - dot: . - - naked_identifier: price - - binary_operator: '*' - - column_reference: - - naked_identifier: table1 - - dot: . - - naked_identifier: quantity - - from_clause: - - keyword: FROM - - from_expression: - - from_expression_element: - - table_expression: - - table_reference: - - object_reference: - - naked_identifier: table1 -- statement_terminator: ; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_simple.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_simple.sql deleted file mode 100644 index 53291061d..000000000 --- a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/tsql_alias_simple.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Simple test for T-SQL alias syntax -SELECT TsqlAlias = value FROM table1; \ No newline at end of file diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/update.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/update.sql new file mode 100644 index 000000000..0dd2d7296 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/update.sql @@ -0,0 +1,19 @@ +update dbo.Cases +set [Flg] = 1 +where ID in (select distinct [ID] from dbo.CX) +OPTION (Label = 'Cases') ; + +update + tt +set + tt.rn += 1 +from + table1 as tt +join + src + on tt._id = src._id; + +UPDATE stuff SET + deleted = 1 +OUTPUT DELETED.* INTO trash +WHERE useless = 1 diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/update.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/update.yml new file mode 100644 index 000000000..6eb2c4fe6 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/update.yml @@ -0,0 +1,134 @@ +file: +- batch: + - statement: + - update_statement: + - keyword: update + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: Cases + - set_clause_list: + - keyword: set + - set_clause: + - column_reference: + - quoted_identifier: '[Flg]' + - assignment_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '1' + - where_clause: + - keyword: where + - expression: + - column_reference: + - naked_identifier: ID + - keyword: in + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: select + - select_clause_modifier: + - keyword: distinct + - select_clause_element: + - column_reference: + - quoted_identifier: '[ID]' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: dbo + - dot: . + - naked_identifier: CX + - end_bracket: ) + - option_clause: + - keyword: OPTION + - bracketed: + - start_bracket: ( + - query_hint_segment: + - keyword: Label + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Cases''' + - end_bracket: ) + - statement_terminator: ; + - statement: + - update_statement: + - keyword: update + - table_reference: + - naked_identifier: tt + - set_clause_list: + - keyword: set + - set_clause: + - column_reference: + - naked_identifier: tt + - dot: . + - naked_identifier: rn + - assignment_operator: + - binary_operator: + + - raw_comparison_operator: = + - expression: + - integer_literal: '1' + - from_clause: + - keyword: from + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: table1 + - alias_expression: + - alias_operator: + - keyword: as + - naked_identifier: tt + - join_clause: + - keyword: join + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: src + - join_on_condition: + - keyword: on + - expression: + - column_reference: + - naked_identifier: tt + - dot: . + - naked_identifier: _id + - comparison_operator: + - raw_comparison_operator: = + - column_reference: + - naked_identifier: src + - dot: . + - naked_identifier: _id + - statement_terminator: ; + - statement: + - update_statement: + - keyword: UPDATE + - table_reference: + - naked_identifier: stuff + - set_clause_list: + - keyword: SET + - set_clause: + - column_reference: + - naked_identifier: deleted + - assignment_operator: + - raw_comparison_operator: = + - expression: + - integer_literal: '1' + - output_clause: + - keyword: OUTPUT + - keyword: DELETED + - dot: . + - wildcard_identifier: + - star: '*' + - keyword: INTO + - table_reference: + - naked_identifier: trash + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: useless + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/waitfor.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/waitfor.sql new file mode 100644 index 000000000..a481d1ee5 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/waitfor.sql @@ -0,0 +1,14 @@ +EXECUTE sp_add_job @job_name = 'TestJob'; +BEGIN + WAITFOR TIME '22:20'; + EXECUTE sp_update_job @job_name = 'TestJob', + @new_name = 'UpdatedJob'; +END; +GO + + +BEGIN + WAITFOR DELAY '02:00'; + EXECUTE sp_helpdb; +END; +GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/waitfor.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/waitfor.yml new file mode 100644 index 000000000..69cca99e9 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/waitfor.yml @@ -0,0 +1,65 @@ +file: +- batch: + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: sp_add_job + - parameter: '@job_name' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''TestJob''' + - statement_terminator: ; + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - waitfor_statement: + - keyword: WAITFOR + - keyword: TIME + - expression: + - quoted_literal: '''22:20''' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: sp_update_job + - parameter: '@job_name' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''TestJob''' + - comma: ',' + - parameter: '@new_name' + - comparison_operator: + - raw_comparison_operator: = + - expression: + - quoted_literal: '''UpdatedJob''' + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO +- batch: + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - waitfor_statement: + - keyword: WAITFOR + - keyword: DELAY + - expression: + - quoted_literal: '''02:00''' + - statement_terminator: ; + - statement: + - execute_script_statement: + - keyword: EXECUTE + - object_reference: + - naked_identifier: sp_helpdb + - statement_terminator: ; + - keyword: END + - statement_terminator: ; + - go_statement: + - keyword: GO diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/while_statement.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/while_statement.sql new file mode 100644 index 000000000..4c8b760f8 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/while_statement.sql @@ -0,0 +1,9 @@ +WHILE (1=1) +BEGIN + IF EXISTS (SELECT * FROM ##MyTempTable WHERE EventCode = 'Done') + BEGIN + BREAK; -- 'Done' row has finally been inserted and detected, so end this loop. + END + + PRINT N'The other process is not yet done.'; -- Re-confirm the non-done status to the console. +END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/while_statement.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/while_statement.yml new file mode 100644 index 000000000..959316a7c --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/while_statement.yml @@ -0,0 +1,63 @@ +file: +- batch: + - statement: + - while_statement: + - keyword: WHILE + - expression: + - bracketed: + - start_bracket: ( + - expression: + - integer_literal: '1' + - comparison_operator: + - raw_comparison_operator: = + - integer_literal: '1' + - end_bracket: ) + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - if_then_statement: + - if_clause: + - keyword: IF + - expression: + - keyword: EXISTS + - bracketed: + - start_bracket: ( + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - wildcard_expression: + - wildcard_identifier: + - star: '*' + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - hash_identifier: '##MyTempTable' + - where_clause: + - keyword: WHERE + - expression: + - column_reference: + - naked_identifier: EventCode + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''Done''' + - end_bracket: ) + - statement: + - begin_end_block: + - keyword: BEGIN + - statement: + - break_statement: + - keyword: BREAK + - statement_terminator: ; + - keyword: END + - statement: + - print_statement: + - keyword: PRINT + - expression: + - quoted_literal: N'The other process is not yet done.' + - statement_terminator: ; + - keyword: END diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/window_functions.sql b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/window_functions.sql new file mode 100644 index 000000000..f2a7d9479 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/window_functions.sql @@ -0,0 +1,24 @@ +-- Classical partition/order by +SELECT ROW_NUMBER() OVER(PARTITION BY t.col1 ORDER BY t.col2) rn +FROM mytable t; + +-- Partition by constant +SELECT ROW_NUMBER() OVER(PARTITION BY 1 ORDER BY t.col2) rn +FROM mytable t; + +-- Partition by expression +SELECT ROW_NUMBER() OVER(PARTITION BY CASE WHEN t.col1 = 'value' THEN 1 END ORDER BY t.col2) rn +FROM mytable t; + +-- Partition by expression and column +SELECT ROW_NUMBER() OVER(PARTITION BY t.col3, CASE WHEN t.col1 = 'value' THEN 1 END, t.col4 ORDER BY t.col2) rn +FROM mytable t; + +-- Partition by select statement +SELECT ROW_NUMBER() OVER(PARTITION BY (SELECT col1 FROM othertable) ORDER BY t.col2) rn +FROM mytable t; + +-- Partition by aggregate +SELECT ROW_NUMBER() OVER(PARTITION BY SUM(t.col1) ORDER BY t.col2) rn +FROM mytable t +GROUP BY t.col2; diff --git a/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/window_functions.yml b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/window_functions.yml new file mode 100644 index 000000000..f1709b100 --- /dev/null +++ b/crates/lib-dialects/test/fixtures/dialects/tsql/sqlfluff/window_functions.yml @@ -0,0 +1,329 @@ +file: +- batch: + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: ROW_NUMBER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col1 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col2 + - end_bracket: ) + - alias_expression: + - naked_identifier: rn + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: mytable + - alias_expression: + - naked_identifier: t + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: ROW_NUMBER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - expression: + - integer_literal: '1' + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col2 + - end_bracket: ) + - alias_expression: + - naked_identifier: rn + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: mytable + - alias_expression: + - naked_identifier: t + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: ROW_NUMBER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value''' + - keyword: THEN + - expression: + - integer_literal: '1' + - keyword: END + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col2 + - end_bracket: ) + - alias_expression: + - naked_identifier: rn + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: mytable + - alias_expression: + - naked_identifier: t + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: ROW_NUMBER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col3 + - comma: ',' + - expression: + - case_expression: + - keyword: CASE + - when_clause: + - keyword: WHEN + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col1 + - comparison_operator: + - raw_comparison_operator: = + - quoted_literal: '''value''' + - keyword: THEN + - expression: + - integer_literal: '1' + - keyword: END + - comma: ',' + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col4 + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col2 + - end_bracket: ) + - alias_expression: + - naked_identifier: rn + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: mytable + - alias_expression: + - naked_identifier: t + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: ROW_NUMBER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - bracketed: + - start_bracket: ( + - expression: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - column_reference: + - naked_identifier: col1 + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: othertable + - end_bracket: ) + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col2 + - end_bracket: ) + - alias_expression: + - naked_identifier: rn + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: mytable + - alias_expression: + - naked_identifier: t + - statement_terminator: ; + - statement: + - select_statement: + - select_clause: + - keyword: SELECT + - select_clause_element: + - function: + - function_name: + - keyword: ROW_NUMBER + - function_contents: + - bracketed: + - start_bracket: ( + - end_bracket: ) + - over_clause: + - keyword: OVER + - bracketed: + - start_bracket: ( + - window_specification: + - partitionby_clause: + - keyword: PARTITION + - keyword: BY + - expression: + - function: + - function_name: + - function_name_identifier: SUM + - function_contents: + - bracketed: + - start_bracket: ( + - expression: + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col1 + - end_bracket: ) + - orderby_clause: + - keyword: ORDER + - keyword: BY + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col2 + - end_bracket: ) + - alias_expression: + - naked_identifier: rn + - from_clause: + - keyword: FROM + - from_expression: + - from_expression_element: + - table_expression: + - table_reference: + - naked_identifier: mytable + - alias_expression: + - naked_identifier: t + - groupby_clause: + - keyword: GROUP + - keyword: BY + - column_reference: + - naked_identifier: t + - dot: . + - naked_identifier: col2 + - statement_terminator: ; From 7147639c0be08dcde7e82e748643917682d709fd Mon Sep 17 00:00:00 2001 From: gvozdvmozgu Date: Fri, 26 Dec 2025 19:06:42 -0800 Subject: [PATCH 02/12] fix(tests): update expected indices in indented joins test cases --- crates/lib/src/tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/lib/src/tests.rs b/crates/lib/src/tests.rs index 541f9a7c1..9dc7c638b 100644 --- a/crates/lib/src/tests.rs +++ b/crates/lib/src/tests.rs @@ -237,11 +237,11 @@ fn test_dialect_ansi_parse_indented_joins() { let cases = [ ( "select field_1 from my_table as alias_1", - [1, 5, 8, 11, 15, 16, 17].as_slice(), + [1, 4, 8, 11, 15, 16, 17].as_slice(), ), ( "select field_1 from my_table as alias_1 join foo using (field_1)", - [1, 5, 8, 11, 15, 17, 19, 23, 24, 26, 29, 31, 33, 34, 35].as_slice(), + [1, 4, 8, 11, 15, 17, 19, 23, 24, 26, 29, 31, 33, 34, 35].as_slice(), ), ]; let lnt = Linter::new( From fe6f36eb69341f8a5961abcc52d077e15d9c6445 Mon Sep 17 00:00:00 2001 From: gvozdvmozgu Date: Fri, 26 Dec 2025 20:34:24 -0800 Subject: [PATCH 03/12] test: fix failing tests --- crates/lib-dialects/src/bigquery.rs | 4 ++-- .../sqlfluff/alter_table_add_column.yml | 6 +++--- .../create_js_function_complex_types.yml | 16 +++++++-------- ...eate_js_function_options_library_array.yml | 4 ++-- .../create_js_function_quoted_name.yml | 4 ++-- .../create_js_function_underscore_name.yml | 4 ++-- .../bigquery/sqlfluff/create_procedure.yml | 6 +++--- .../sqlfluff/create_table_column_options.yml | 6 +++--- .../bigquery/sqlfluff/declare_variable.yml | 18 ++++++++--------- .../bigquery/sqlfluff/pipe_statement.yml | 10 +++++----- .../select_mixture_of_array_literals.yml | 8 ++++---- .../bigquery/sqlfluff/select_struct.yml | 20 +++++++++---------- ...select_typeless_struct_inside_function.yml | 6 +++--- .../bigquery/sqlfluff/select_with_cast.yml | 4 ++-- .../bigquery/sqlfluff/typeless_struct.yml | 6 +++--- crates/lib/src/rules/aliasing/al02.rs | 13 ++++++------ crates/lib/src/rules/convention/cv10.rs | 2 +- crates/lib/src/rules/references/rf01.rs | 1 + crates/lib/src/rules/references/rf03.rs | 2 +- .../rules/std_rule_cases/LT02-indent.yml | 2 ++ .../fixtures/rules/std_rule_cases/LT04.yml | 1 + 21 files changed, 74 insertions(+), 69 deletions(-) diff --git a/crates/lib-dialects/src/bigquery.rs b/crates/lib-dialects/src/bigquery.rs index 07e40a5c4..165add36e 100644 --- a/crates/lib-dialects/src/bigquery.rs +++ b/crates/lib-dialects/src/bigquery.rs @@ -663,7 +663,7 @@ pub fn raw_dialect() -> Dialect { bigquery_dialect.add([ ( "ArrayTypeSegment".into(), - NodeMatcher::new(SyntaxKind::DataType, |_dialect| { + NodeMatcher::new(SyntaxKind::ArrayType, |_dialect| { Sequence::new(vec![ Ref::keyword("ARRAY").to_matchable(), Bracketed::new(vec![Ref::new("DatatypeSegment").to_matchable()]) @@ -1847,7 +1847,7 @@ pub fn raw_dialect() -> Dialect { ), ( "StructTypeSegment".into(), - NodeMatcher::new(SyntaxKind::DataType, |_dialect| { + NodeMatcher::new(SyntaxKind::StructType, |_dialect| { Sequence::new(vec![ Ref::keyword("STRUCT").to_matchable(), Ref::new("StructTypeSchemaSegment") diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_column.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_column.yml index deba0562f..855bd4184 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_column.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/alter_table_add_column.yml @@ -29,7 +29,7 @@ file: - column_definition: - naked_identifier: C - data_type: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -65,7 +65,7 @@ file: - column_definition: - naked_identifier: A - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -75,7 +75,7 @@ file: - comma: ',' - parameter: C - data_type: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_complex_types.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_complex_types.yml index 509b17175..b7fc5e4ef 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_complex_types.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_complex_types.yml @@ -15,7 +15,7 @@ file: - comma: ',' - parameter: foo2 - data_type: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -24,7 +24,7 @@ file: - comma: ',' - parameter: foo3 - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -35,7 +35,7 @@ file: - comma: ',' - parameter: foo4 - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -50,13 +50,13 @@ file: - comma: ',' - parameter: foo5 - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < - parameter: a - data_type: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -65,7 +65,7 @@ file: - comma: ',' - parameter: b - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -81,13 +81,13 @@ file: - end_bracket: ) - keyword: RETURNS - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < - parameter: product_id - data_type: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_options_library_array.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_options_library_array.yml index 79b6d7b6e..127571feb 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_options_library_array.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_options_library_array.yml @@ -15,11 +15,11 @@ file: - end_bracket: ) - keyword: RETURNS - data_type: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_quoted_name.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_quoted_name.yml index 1e533240c..d67cfeda2 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_quoted_name.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_quoted_name.yml @@ -15,13 +15,13 @@ file: - end_bracket: ) - keyword: RETURNS - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < - parameter: '`$=`' - data_type: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_underscore_name.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_underscore_name.yml index a026efa69..215607b6f 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_underscore_name.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_js_function_underscore_name.yml @@ -15,13 +15,13 @@ file: - end_bracket: ) - keyword: RETURNS - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < - parameter: _product_id - data_type: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_procedure.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_procedure.yml index 748fa9907..d3e27d992 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_procedure.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_procedure.yml @@ -609,7 +609,7 @@ file: - start_bracket: ( - parameter: _log - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -694,7 +694,7 @@ file: - start_bracket: ( - parameter: _log - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -833,7 +833,7 @@ file: - start_bracket: ( - parameter: _log - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_column_options.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_column_options.yml index 5ec47adb6..9504581eb 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_column_options.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/create_table_column_options.yml @@ -59,7 +59,7 @@ file: - column_definition: - naked_identifier: x - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -80,11 +80,11 @@ file: - column_definition: - naked_identifier: y - data_type: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/declare_variable.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/declare_variable.yml index 456f08010..0ad35ac6b 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/declare_variable.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/declare_variable.yml @@ -65,7 +65,7 @@ file: - keyword: declare - naked_identifier: arr1 - data_type: - - data_type: + - array_type: - keyword: array - start_angle_bracket: < - data_type: @@ -98,7 +98,7 @@ file: - keyword: declare - naked_identifier: arr4 - data_type: - - data_type: + - array_type: - keyword: array - start_angle_bracket: < - data_type: @@ -117,7 +117,7 @@ file: - keyword: declare - naked_identifier: arr5 - data_type: - - data_type: + - array_type: - keyword: array - start_angle_bracket: < - data_type: @@ -134,7 +134,7 @@ file: - keyword: declare - naked_identifier: str1 - data_type: - - data_type: + - struct_type: - keyword: struct - struct_type_schema: - start_angle_bracket: < @@ -152,7 +152,7 @@ file: - keyword: declare - naked_identifier: str2 - data_type: - - data_type: + - struct_type: - keyword: struct - struct_type_schema: - start_angle_bracket: < @@ -167,7 +167,7 @@ file: - keyword: default - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: struct - struct_literal: - bracketed: @@ -184,7 +184,7 @@ file: - keyword: default - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: struct - struct_literal: - bracketed: @@ -199,7 +199,7 @@ file: - keyword: declare - naked_identifier: str4 - data_type: - - data_type: + - struct_type: - keyword: struct - struct_type_schema: - start_angle_bracket: < @@ -225,7 +225,7 @@ file: - keyword: declare - naked_identifier: str5 - data_type: - - data_type: + - struct_type: - keyword: struct - struct_type_schema: - start_angle_bracket: < diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/pipe_statement.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/pipe_statement.yml index 908629bfb..8c698bac0 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/pipe_statement.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/pipe_statement.yml @@ -720,7 +720,7 @@ file: - start_bracket: ( - expression: - typed_array_literal: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -765,7 +765,7 @@ file: - start_bracket: ( - expression: - typed_array_literal: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -858,7 +858,7 @@ file: - start_bracket: ( - expression: - typed_array_literal: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -899,7 +899,7 @@ file: - start_bracket: ( - expression: - typed_array_literal: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -1201,7 +1201,7 @@ file: - start_bracket: ( - expression: - typed_array_literal: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_mixture_of_array_literals.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_mixture_of_array_literals.yml index 81641a2cb..633eed023 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_mixture_of_array_literals.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_mixture_of_array_literals.yml @@ -16,7 +16,7 @@ file: - comma: ',' - select_clause_element: - typed_array_literal: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -39,7 +39,7 @@ file: - comma: ',' - select_clause_element: - typed_array_literal: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -66,7 +66,7 @@ file: - comma: ',' - select_clause_element: - typed_array_literal: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: @@ -86,7 +86,7 @@ file: - start_square_bracket: '[' - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: STRUCT - struct_literal: - bracketed: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_struct.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_struct.yml index ad4811525..8c2c301d7 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_struct.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_struct.yml @@ -106,7 +106,7 @@ file: - select_clause_element: - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: struct - struct_literal: - bracketed: @@ -185,11 +185,11 @@ file: - start_bracket: ( - expression: - typed_array_literal: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -229,7 +229,7 @@ file: - select_clause_element: - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -245,7 +245,7 @@ file: - select_clause_element: - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -261,7 +261,7 @@ file: - select_clause_element: - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -287,7 +287,7 @@ file: - select_clause_element: - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: STRUCT - struct_type_schema: - start_angle_bracket: < @@ -308,7 +308,7 @@ file: - select_clause_element: - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: STRUCT - struct_literal: - bracketed: @@ -344,7 +344,7 @@ file: - start_bracket: ( - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: STRUCT - struct_literal: - bracketed: @@ -382,7 +382,7 @@ file: - bracketed: - start_bracket: ( - typed_struct_literal: - - data_type: + - struct_type: - keyword: STRUCT - struct_literal: - bracketed: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_typeless_struct_inside_function.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_typeless_struct_inside_function.yml index d9d4f622e..f05d43d29 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_typeless_struct_inside_function.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_typeless_struct_inside_function.yml @@ -6,14 +6,14 @@ file: - select_clause_element: - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: STRUCT - struct_literal: - bracketed: - start_bracket: ( - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: STRUCT - struct_literal: - bracketed: @@ -47,7 +47,7 @@ file: - start_bracket: ( - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: STRUCT - struct_literal: - bracketed: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_cast.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_cast.yml index 6e0a6ebc4..7652df7da 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_cast.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/select_with_cast.yml @@ -48,7 +48,7 @@ file: - start_bracket: ( - expression: - typed_array_literal: - - data_type: + - array_type: - keyword: ARRAY - array_literal: - start_square_bracket: '[' @@ -56,7 +56,7 @@ file: - end_square_bracket: ']' - keyword: AS - data_type: - - data_type: + - array_type: - keyword: ARRAY - start_angle_bracket: < - data_type: diff --git a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/typeless_struct.yml b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/typeless_struct.yml index 8e06bdec4..cc44f70bd 100644 --- a/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/typeless_struct.yml +++ b/crates/lib-dialects/test/fixtures/dialects/bigquery/sqlfluff/typeless_struct.yml @@ -15,7 +15,7 @@ file: - comma: ',' - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: STRUCT - struct_literal: - bracketed: @@ -35,7 +35,7 @@ file: - comma: ',' - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: STRUCT - struct_literal: - bracketed: @@ -96,7 +96,7 @@ file: - keyword: THEN - expression: - typed_struct_literal: - - data_type: + - struct_type: - keyword: STRUCT - struct_literal: - bracketed: diff --git a/crates/lib/src/rules/aliasing/al02.rs b/crates/lib/src/rules/aliasing/al02.rs index f0b78d202..89065ddba 100644 --- a/crates/lib/src/rules/aliasing/al02.rs +++ b/crates/lib/src/rules/aliasing/al02.rs @@ -83,12 +83,13 @@ FROM foo } fn eval(&self, context: &RuleContext) -> Vec { - if matches!( - context.segment - .child(&SyntaxSet::new(&[SyntaxKind::AliasOperator])), - Some(alias_operator) if alias_operator.raw() == "=" - ) { - return Vec::new(); + if let Some(alias_operator) = + context.segment.child(&SyntaxSet::new(&[SyntaxKind::AliasOperator])) + { + if alias_operator.raw() == "=" { + return Vec::new(); + } + } } self.base.eval(context) diff --git a/crates/lib/src/rules/convention/cv10.rs b/crates/lib/src/rules/convention/cv10.rs index f3558b093..8f32e3153 100644 --- a/crates/lib/src/rules/convention/cv10.rs +++ b/crates/lib/src/rules/convention/cv10.rs @@ -106,7 +106,7 @@ from foo if !(self.force_enable || matches!( context.dialect.name, - DialectKind::Bigquery | DialectKind::Sparksql + DialectKind::Bigquery | DialectKind::Hive | DialectKind::Sparksql )) { return Vec::new(); diff --git a/crates/lib/src/rules/references/rf01.rs b/crates/lib/src/rules/references/rf01.rs index 46b98bb62..33eedfae6 100644 --- a/crates/lib/src/rules/references/rf01.rs +++ b/crates/lib/src/rules/references/rf01.rs @@ -247,6 +247,7 @@ FROM foo DialectKind::Bigquery, DialectKind::Databricks, DialectKind::Duckdb, + DialectKind::Hive, DialectKind::Sparksql, ] } diff --git a/crates/lib/src/rules/references/rf03.rs b/crates/lib/src/rules/references/rf03.rs index 23ffeb4d9..f99de9ccf 100644 --- a/crates/lib/src/rules/references/rf03.rs +++ b/crates/lib/src/rules/references/rf03.rs @@ -355,7 +355,7 @@ FROM foo } fn dialect_skip(&self) -> &'static [DialectKind] { - &[DialectKind::Bigquery, DialectKind::Redshift] + &[DialectKind::Bigquery, DialectKind::Hive, DialectKind::Redshift] } fn eval(&self, context: &RuleContext) -> Vec { diff --git a/crates/lib/test/fixtures/rules/std_rule_cases/LT02-indent.yml b/crates/lib/test/fixtures/rules/std_rule_cases/LT02-indent.yml index 882695748..41ca213ae 100644 --- a/crates/lib/test/fixtures/rules/std_rule_cases/LT02-indent.yml +++ b/crates/lib/test/fixtures/rules/std_rule_cases/LT02-indent.yml @@ -869,6 +869,7 @@ test_fail_ignore_templated_whitespace_1: ignore_templated_areas: false test_fail_ignore_templated_whitespace_2: + ignored: "jinja is not set" fail_str: | SELECT c1, @@ -926,6 +927,7 @@ test_pass_ignore_templated_newline_last_line: from {{ "\n\nmy_table" }} test_fail_fix_template_indentation_1: + ignored: "jinja is not set" fail_str: | SELECT c1, diff --git a/crates/lib/test/fixtures/rules/std_rule_cases/LT04.yml b/crates/lib/test/fixtures/rules/std_rule_cases/LT04.yml index 62f2e4719..278e8d7c4 100644 --- a/crates/lib/test/fixtures/rules/std_rule_cases/LT04.yml +++ b/crates/lib/test/fixtures/rules/std_rule_cases/LT04.yml @@ -281,6 +281,7 @@ leading_comma_move_past_several_comment_lines: line_position: leading leading_comma_with_templated_column_1: + ignored: "jinja is not set" fail_str: | SELECT c1, From d7015530ba089f4745f224a4af68c82c70efe840 Mon Sep 17 00:00:00 2001 From: gvozdvmozgu Date: Fri, 26 Dec 2025 20:37:42 -0800 Subject: [PATCH 04/12] refactor: make clippy happy --- crates/lib-dialects/src/ansi.rs | 20 ++++++++++---------- crates/lib-dialects/src/databricks.rs | 6 +++--- crates/lib-dialects/src/tsql.rs | 14 +++++++------- crates/lib/src/rules/aliasing/al02.rs | 12 ++++++------ crates/lib/src/rules/references/rf03.rs | 6 +++++- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/crates/lib-dialects/src/ansi.rs b/crates/lib-dialects/src/ansi.rs index 037c93954..6e27c8d9c 100644 --- a/crates/lib-dialects/src/ansi.rs +++ b/crates/lib-dialects/src/ansi.rs @@ -1723,7 +1723,7 @@ pub fn raw_dialect() -> Dialect { NodeMatcher::new(SyntaxKind::TableReference, |_dialect| { _dialect .grammar("ObjectReferenceSegment") - .match_grammar(&_dialect) + .match_grammar(_dialect) .unwrap() }) .to_matchable() @@ -1734,7 +1734,7 @@ pub fn raw_dialect() -> Dialect { NodeMatcher::new(SyntaxKind::SchemaReference, |_dialect| { _dialect .grammar("ObjectReferenceSegment") - .match_grammar(&_dialect) + .match_grammar(_dialect) .unwrap() }) .to_matchable() @@ -1745,7 +1745,7 @@ pub fn raw_dialect() -> Dialect { NodeMatcher::new(SyntaxKind::DatabaseReference, |_dialect| { _dialect .grammar("ObjectReferenceSegment") - .match_grammar(&_dialect) + .match_grammar(_dialect) .unwrap() }) .to_matchable() @@ -1756,7 +1756,7 @@ pub fn raw_dialect() -> Dialect { NodeMatcher::new(SyntaxKind::IndexReference, |_dialect| { _dialect .grammar("ObjectReferenceSegment") - .match_grammar(&_dialect) + .match_grammar(_dialect) .unwrap() }) .to_matchable() @@ -1794,7 +1794,7 @@ pub fn raw_dialect() -> Dialect { NodeMatcher::new(SyntaxKind::TablespaceReference, |_dialect| { _dialect .grammar("ObjectReferenceSegment") - .match_grammar(&_dialect) + .match_grammar(_dialect) .unwrap() }) .to_matchable() @@ -1805,7 +1805,7 @@ pub fn raw_dialect() -> Dialect { NodeMatcher::new(SyntaxKind::ExtensionReference, |_dialect| { _dialect .grammar("ObjectReferenceSegment") - .match_grammar(&_dialect) + .match_grammar(_dialect) .unwrap() }) .to_matchable() @@ -1816,7 +1816,7 @@ pub fn raw_dialect() -> Dialect { NodeMatcher::new(SyntaxKind::ColumnReference, |_dialect| { _dialect .grammar("ObjectReferenceSegment") - .match_grammar(&_dialect) + .match_grammar(_dialect) .unwrap() }) .to_matchable() @@ -1827,7 +1827,7 @@ pub fn raw_dialect() -> Dialect { NodeMatcher::new(SyntaxKind::SequenceReference, |_dialect| { _dialect .grammar("ObjectReferenceSegment") - .match_grammar(&_dialect) + .match_grammar(_dialect) .unwrap() }) .to_matchable() @@ -1838,7 +1838,7 @@ pub fn raw_dialect() -> Dialect { NodeMatcher::new(SyntaxKind::TagReference, |_dialect| { _dialect .grammar("ObjectReferenceSegment") - .match_grammar(&_dialect) + .match_grammar(_dialect) .unwrap() }) .to_matchable() @@ -1849,7 +1849,7 @@ pub fn raw_dialect() -> Dialect { NodeMatcher::new(SyntaxKind::TriggerReference, |_dialect| { _dialect .grammar("ObjectReferenceSegment") - .match_grammar(&_dialect) + .match_grammar(_dialect) .unwrap() }) .to_matchable() diff --git a/crates/lib-dialects/src/databricks.rs b/crates/lib-dialects/src/databricks.rs index 75cb34b5f..494683909 100644 --- a/crates/lib-dialects/src/databricks.rs +++ b/crates/lib-dialects/src/databricks.rs @@ -797,7 +797,7 @@ pub fn raw_dialect() -> Dialect { NodeMatcher::new(SyntaxKind::DatabaseReference, |_dialect| { _dialect .grammar("ObjectReferenceSegment") - .match_grammar(&_dialect) + .match_grammar(_dialect) .unwrap() }) .to_matchable() @@ -808,7 +808,7 @@ pub fn raw_dialect() -> Dialect { NodeMatcher::new(SyntaxKind::TableReference, |_dialect| { _dialect .grammar("ObjectReferenceSegment") - .match_grammar(&_dialect) + .match_grammar(_dialect) .unwrap() }) .to_matchable() @@ -819,7 +819,7 @@ pub fn raw_dialect() -> Dialect { NodeMatcher::new(SyntaxKind::SchemaReference, |_dialect| { _dialect .grammar("ObjectReferenceSegment") - .match_grammar(&_dialect) + .match_grammar(_dialect) .unwrap() }) .to_matchable() diff --git a/crates/lib-dialects/src/tsql.rs b/crates/lib-dialects/src/tsql.rs index 923abb596..2421d57f7 100644 --- a/crates/lib-dialects/src/tsql.rs +++ b/crates/lib-dialects/src/tsql.rs @@ -1030,7 +1030,7 @@ pub fn raw_dialect() -> Dialect { ( "SchemaReferenceSegment".into(), NodeMatcher::new(SyntaxKind::SchemaReference, |_dialect| { - _dialect.grammar("ObjectReferenceSegment").match_grammar(&_dialect).unwrap() + _dialect.grammar("ObjectReferenceSegment").match_grammar(_dialect).unwrap() }) .to_matchable() .into() @@ -1038,7 +1038,7 @@ pub fn raw_dialect() -> Dialect { ( "DatabaseReferenceSegment".into(), NodeMatcher::new(SyntaxKind::DatabaseReference, |_dialect| { - _dialect.grammar("ObjectReferenceSegment").match_grammar(&_dialect).unwrap() + _dialect.grammar("ObjectReferenceSegment").match_grammar(_dialect).unwrap() }) .to_matchable() .into() @@ -1046,7 +1046,7 @@ pub fn raw_dialect() -> Dialect { ( "IndexReferenceSegment".into(), NodeMatcher::new(SyntaxKind::IndexReference, |_dialect| { - _dialect.grammar("ObjectReferenceSegment").match_grammar(&_dialect).unwrap() + _dialect.grammar("ObjectReferenceSegment").match_grammar(_dialect).unwrap() }) .to_matchable() .into() @@ -1054,7 +1054,7 @@ pub fn raw_dialect() -> Dialect { ( "ExtensionReferenceSegment".into(), NodeMatcher::new(SyntaxKind::ExtensionReference, |_dialect| { - _dialect.grammar("ObjectReferenceSegment").match_grammar(&_dialect).unwrap() + _dialect.grammar("ObjectReferenceSegment").match_grammar(_dialect).unwrap() }) .to_matchable() .into() @@ -1062,7 +1062,7 @@ pub fn raw_dialect() -> Dialect { ( "ColumnReferenceSegment".into(), NodeMatcher::new(SyntaxKind::ColumnReference, |_dialect| { - _dialect.grammar("ObjectReferenceSegment").match_grammar(&_dialect).unwrap() + _dialect.grammar("ObjectReferenceSegment").match_grammar(_dialect).unwrap() }) .to_matchable() .into() @@ -1070,7 +1070,7 @@ pub fn raw_dialect() -> Dialect { ( "SequenceReferenceSegment".into(), NodeMatcher::new(SyntaxKind::SequenceReference, |_dialect| { - _dialect.grammar("ObjectReferenceSegment").match_grammar(&_dialect).unwrap() + _dialect.grammar("ObjectReferenceSegment").match_grammar(_dialect).unwrap() }) .to_matchable() .into() @@ -1078,7 +1078,7 @@ pub fn raw_dialect() -> Dialect { ( "PivotColumnReferenceSegment".into(), NodeMatcher::new(SyntaxKind::PivotColumnReference, |_dialect| { - _dialect.grammar("ObjectReferenceSegment").match_grammar(&_dialect).unwrap() + _dialect.grammar("ObjectReferenceSegment").match_grammar(_dialect).unwrap() }) .to_matchable() .into() diff --git a/crates/lib/src/rules/aliasing/al02.rs b/crates/lib/src/rules/aliasing/al02.rs index 89065ddba..1dfc50a05 100644 --- a/crates/lib/src/rules/aliasing/al02.rs +++ b/crates/lib/src/rules/aliasing/al02.rs @@ -83,12 +83,12 @@ FROM foo } fn eval(&self, context: &RuleContext) -> Vec { - if let Some(alias_operator) = - context.segment.child(&SyntaxSet::new(&[SyntaxKind::AliasOperator])) - { - if alias_operator.raw() == "=" { - return Vec::new(); - } + if matches!( + context.segment + .child(&SyntaxSet::new(&[SyntaxKind::AliasOperator])), + Some(alias_operator) if alias_operator.raw() == "=" + ) { + return Vec::new(); } } diff --git a/crates/lib/src/rules/references/rf03.rs b/crates/lib/src/rules/references/rf03.rs index f99de9ccf..9a9da5870 100644 --- a/crates/lib/src/rules/references/rf03.rs +++ b/crates/lib/src/rules/references/rf03.rs @@ -355,7 +355,11 @@ FROM foo } fn dialect_skip(&self) -> &'static [DialectKind] { - &[DialectKind::Bigquery, DialectKind::Hive, DialectKind::Redshift] + &[ + DialectKind::Bigquery, + DialectKind::Hive, + DialectKind::Redshift, + ] } fn eval(&self, context: &RuleContext) -> Vec { From 2c11adae7440004153acdc43110a7e1df353330c Mon Sep 17 00:00:00 2001 From: gvozdvmozgu Date: Fri, 26 Dec 2025 20:40:46 -0800 Subject: [PATCH 05/12] Apply automatic changes --- docs/rules.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/rules.md b/docs/rules.md index 05d835a21..c4b029cc0 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -1897,7 +1897,7 @@ SELECT FROM foo ``` -**Dialects where this rule is skipped:** `athena`, `redshift`, `bigquery`, `databricks`, `duckdb`, `sparksql` +**Dialects where this rule is skipped:** `athena`, `redshift`, `bigquery`, `databricks`, `duckdb`, `hive`, `sparksql` ### references.qualification @@ -1969,7 +1969,7 @@ SELECT FROM foo ``` -**Dialects where this rule is skipped:** `bigquery`, `redshift` +**Dialects where this rule is skipped:** `bigquery`, `hive`, `redshift` ### references.keywords @@ -2453,4 +2453,3 @@ left join bar on foo.a = bar.a and foo.b = bar.b ``` - From 71c51b323a47651b2fb7616016212e46fd5bae13 Mon Sep 17 00:00:00 2001 From: gvozdvmozgu Date: Sat, 27 Dec 2025 05:34:06 -0800 Subject: [PATCH 06/12] fix: reorder dialect definitions for mysql and hive --- crates/lib-dialects/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/lib-dialects/src/lib.rs b/crates/lib-dialects/src/lib.rs index b2e17df29..6f6f491e9 100644 --- a/crates/lib-dialects/src/lib.rs +++ b/crates/lib-dialects/src/lib.rs @@ -72,9 +72,9 @@ pub fn kind_to_dialect(kind: &DialectKind) -> Option { DialectKind::Databricks => databricks::dialect(), #[cfg(feature = "duckdb")] DialectKind::Duckdb => duckdb::dialect(), - #[cfg(feature = "mysql")] #[cfg(feature = "hive")] DialectKind::Hive => hive::dialect(), + #[cfg(feature = "mysql")] DialectKind::Mysql => mysql::dialect(), #[cfg(feature = "postgres")] DialectKind::Postgres => postgres::dialect(), From dcb354a2743d9a9a90b874ec72687d5c5e93e80c Mon Sep 17 00:00:00 2001 From: gvozdvmozgu Date: Sat, 27 Dec 2025 05:46:20 -0800 Subject: [PATCH 07/12] fix: update dialect definitions for BigQuery, Postgres, and SQLite --- crates/lib-dialects/src/bigquery.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/lib-dialects/src/bigquery.rs b/crates/lib-dialects/src/bigquery.rs index 165add36e..d6aa985f9 100644 --- a/crates/lib-dialects/src/bigquery.rs +++ b/crates/lib-dialects/src/bigquery.rs @@ -1847,7 +1847,7 @@ pub fn raw_dialect() -> Dialect { ), ( "StructTypeSegment".into(), - NodeMatcher::new(SyntaxKind::StructType, |_dialect| { + NodeMatcher::new(SyntaxKind::DataType, |_dialect| { Sequence::new(vec![ Ref::keyword("STRUCT").to_matchable(), Ref::new("StructTypeSchemaSegment") From 73945bec8827a3d332792df9fd852a3e6df04495 Mon Sep 17 00:00:00 2001 From: gvozdvmozgu Date: Sat, 27 Dec 2025 06:47:53 -0800 Subject: [PATCH 08/12] fix: update syntax kind for StructTypeSegment in BigQuery dialect --- crates/lib-dialects/src/athena.rs | 41 ++++++++++++++++++++++------- crates/lib-dialects/src/bigquery.rs | 2 +- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/crates/lib-dialects/src/athena.rs b/crates/lib-dialects/src/athena.rs index cc73be003..48fe039df 100644 --- a/crates/lib-dialects/src/athena.rs +++ b/crates/lib-dialects/src/athena.rs @@ -507,11 +507,14 @@ pub fn raw_dialect() -> Dialect { ( "WithinGroupClauseSegment".into(), NodeMatcher::new(SyntaxKind::WithingroupClause, |_dialect| { - let dialect = super::trino::raw_dialect(); - dialect - .grammar("WithinGroupClauseSegment") - .match_grammar(&dialect) - .unwrap() + Sequence::new(vec![ + Ref::keyword("WITHIN").to_matchable(), + Ref::keyword("GROUP").to_matchable(), + Bracketed::new(vec![Ref::new("OrderByClauseSegment").to_matchable()]) + .to_matchable(), + Ref::new("FilterClauseGrammar").optional().to_matchable(), + ]) + .to_matchable() }) .to_matchable() .into(), @@ -519,11 +522,29 @@ pub fn raw_dialect() -> Dialect { ( "ListaggOverflowClauseSegment".into(), NodeMatcher::new(SyntaxKind::ListaggOverflowClause, |_dialect| { - let dialect = super::trino::raw_dialect(); - dialect - .grammar("ListaggOverflowClauseSegment") - .match_grammar(&dialect) - .unwrap() + Sequence::new(vec![ + Ref::keyword("ON").to_matchable(), + Ref::keyword("OVERFLOW").to_matchable(), + one_of(vec![ + Ref::keyword("ERROR").to_matchable(), + Sequence::new(vec![ + Ref::keyword("TRUNCATE").to_matchable(), + Ref::new("QuotedLiteralSegment").optional().to_matchable(), + one_of(vec![ + Ref::keyword("WITH").to_matchable(), + Ref::keyword("WITHOUT").to_matchable(), + ]) + .config(|this| { + this.optional(); + }) + .to_matchable(), + Ref::keyword("COUNT").optional().to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable(), + ]) + .to_matchable() }) .to_matchable() .into(), diff --git a/crates/lib-dialects/src/bigquery.rs b/crates/lib-dialects/src/bigquery.rs index d6aa985f9..165add36e 100644 --- a/crates/lib-dialects/src/bigquery.rs +++ b/crates/lib-dialects/src/bigquery.rs @@ -1847,7 +1847,7 @@ pub fn raw_dialect() -> Dialect { ), ( "StructTypeSegment".into(), - NodeMatcher::new(SyntaxKind::DataType, |_dialect| { + NodeMatcher::new(SyntaxKind::StructType, |_dialect| { Sequence::new(vec![ Ref::keyword("STRUCT").to_matchable(), Ref::new("StructTypeSchemaSegment") From 51fe56bbc37d2ae2be2ab43eabab2fe6c6a656de Mon Sep 17 00:00:00 2001 From: gvozdvmozgu Date: Sat, 27 Dec 2025 18:52:23 -0800 Subject: [PATCH 09/12] feat: add lexer matcher for SQLite blob literals and update grammar references --- crates/lib-dialects/src/sqlite.rs | 19 ++++++++++++++----- .../dialects/sqlite/sqruff/blob_literal.yml | 6 ++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/crates/lib-dialects/src/sqlite.rs b/crates/lib-dialects/src/sqlite.rs index 2b8457055..3d6962c3a 100644 --- a/crates/lib-dialects/src/sqlite.rs +++ b/crates/lib-dialects/src/sqlite.rs @@ -24,12 +24,12 @@ pub fn raw_dialect() -> Dialect { let mut sqlite_dialect = ansi_dialect.clone(); sqlite_dialect.name = DialectKind::Sqlite; - // Add lexer matchers for SQLite blob literals (X'...' or x'...') - // These must be inserted before single_quote to take precedence + // Add lexer matcher for SQLite blob literals (X'...' or x'...'). + // Insert before single_quote to take precedence over string literals. sqlite_dialect.insert_lexer_matchers( vec![Matcher::regex( "bytes_single_quote", - r"[xX]'([^'\\]|\\.)*'", + r#"[xX]'[0-9A-Fa-f]*'"#, SyntaxKind::BytesSingleQuote, )], "single_quote", @@ -127,7 +127,7 @@ pub fn raw_dialect() -> Dialect { sqlite_dialect .grammar("LiteralGrammar") .copy( - Some(vec_of_erased![Ref::new("BytesQuotedLiteralSegment")]), + Some(vec![Ref::new("BytesQuotedLiteralSegment").to_matchable()]), None, None, None, @@ -184,6 +184,12 @@ pub fn raw_dialect() -> Dialect { .to_matchable() .into(), ), + ( + "BytesQuotedLiteralSegment".into(), + TypedParser::new(SyntaxKind::BytesSingleQuote, SyntaxKind::BytesQuotedLiteral) + .to_matchable() + .into(), + ), ]); sqlite_dialect.replace_grammar( @@ -221,7 +227,10 @@ pub fn raw_dialect() -> Dialect { sqlite_dialect.replace_grammar( "LiteralGrammar", ansi_dialect.grammar("LiteralGrammar").copy( - Some(vec![Ref::new("ParameterizedSegment").to_matchable()]), + Some(vec![ + Ref::new("ParameterizedSegment").to_matchable(), + Ref::new("BytesQuotedLiteralSegment").to_matchable(), + ]), None, None, None, diff --git a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqruff/blob_literal.yml b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqruff/blob_literal.yml index 4308b4429..0a38d90bc 100644 --- a/crates/lib-dialects/test/fixtures/dialects/sqlite/sqruff/blob_literal.yml +++ b/crates/lib-dialects/test/fixtures/dialects/sqlite/sqruff/blob_literal.yml @@ -6,7 +6,8 @@ file: - select_clause_element: - bytes_quoted_literal: X'123456' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: @@ -16,7 +17,8 @@ file: - select_clause_element: - bytes_quoted_literal: x'ABCDEF' - alias_expression: - - keyword: AS + - alias_operator: + - keyword: AS - naked_identifier: col - statement_terminator: ; - statement: From 447957c6d719a21215c8b240ec675e81197bf1a8 Mon Sep 17 00:00:00 2001 From: gvozdvmozgu Date: Sun, 11 Jan 2026 03:03:39 -0800 Subject: [PATCH 10/12] test --- crates/lib/src/rules/aliasing/al02.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/lib/src/rules/aliasing/al02.rs b/crates/lib/src/rules/aliasing/al02.rs index 1dfc50a05..b82619570 100644 --- a/crates/lib/src/rules/aliasing/al02.rs +++ b/crates/lib/src/rules/aliasing/al02.rs @@ -83,13 +83,12 @@ FROM foo } fn eval(&self, context: &RuleContext) -> Vec { - if matches!( - context.segment - .child(&SyntaxSet::new(&[SyntaxKind::AliasOperator])), - Some(alias_operator) if alias_operator.raw() == "=" - ) { - return Vec::new(); - } + if let Some(alias_operator) = + context.segment.child(&SyntaxSet::new(&[SyntaxKind::AliasOperator])) + { + if alias_operator.raw() == "=" { + return Vec::new(); + } } self.base.eval(context) From 8759028a9dba64170695f56435222d2813b54625 Mon Sep 17 00:00:00 2001 From: gvozdvmozgu <131762131+gvozdvmozgu@users.noreply.github.com> Date: Sun, 11 Jan 2026 11:04:44 +0000 Subject: [PATCH 11/12] Apply automatic changes --- docs/rules.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/rules.md b/docs/rules.md index c4b029cc0..9c0eaec57 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -2453,3 +2453,4 @@ left join bar on foo.a = bar.a and foo.b = bar.b ``` + From e33c9bf2f94f969d8b6abb81e1b623fe7e948a7d Mon Sep 17 00:00:00 2001 From: gvozdvmozgu Date: Tue, 13 Jan 2026 09:21:25 -0800 Subject: [PATCH 12/12] fix: simplify alias operator evaluation in RuleAL02 --- crates/lib/src/rules/aliasing/al02.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/lib/src/rules/aliasing/al02.rs b/crates/lib/src/rules/aliasing/al02.rs index b82619570..1e0ae5088 100644 --- a/crates/lib/src/rules/aliasing/al02.rs +++ b/crates/lib/src/rules/aliasing/al02.rs @@ -83,12 +83,12 @@ FROM foo } fn eval(&self, context: &RuleContext) -> Vec { - if let Some(alias_operator) = - context.segment.child(&SyntaxSet::new(&[SyntaxKind::AliasOperator])) + if context + .segment + .child(&SyntaxSet::new(&[SyntaxKind::AliasOperator])) + .is_some_and(|alias_operator| alias_operator.raw() == "=") { - if alias_operator.raw() == "=" { - return Vec::new(); - } + return Vec::new(); } self.base.eval(context)