Skip to content

AL05 is capitalisation-sensitive, corrupting fixes #4801

@WittierDinosaur

Description

@WittierDinosaur

Search before asking

  • I searched the issues and found no similar issues.

What Happened

Consider:

SELECT
  a.foo
  , b.bar
FROM foo.baz a
INNER JOIN foo.baz B
  ON a.thing = b.thing
;

In this example, aliases should be lowercase.
sqlfluff fix raises this error
image

Expected Behaviour

I would expect it to correct the capitalisation of the alias, leaving:

SELECT
  a.foo
  , b.bar
FROM foo.baz a
INNER JOIN foo.baz b
  ON a.thing = b.thing
;

Observed Behaviour

It strips the alias, corrupting the SQL

SELECT
  a.foo
  , b.bar
FROM foo.baz a
INNER JOIN foo.baz
  ON a.thing = b.thing
;

How to reproduce

As above, sqlfluff fix the example

Dialect

Snowflake

Version

2.0.7

Configuration

I don't think the config is relevant here, but:

[sqlfluff]
# https://docs.sqlfluff.com/en/stable/configuration.html#default-configuration
verbose = 0
nocolor = False
dialect = snowflake
templater = jinja
rules = None
exclude_rules = AL01,AM04,LT05,RF06,ST01,ST06
recurse = 0
output_line_length = 120
runaway_limit = 10
ignore = None
ignore_templated_areas = True
encoding = autodetect
disable_noqa = False
sql_file_exts = .sql,.sql.j2,.dml
fix_even_unparsable = False
large_file_skip_byte_limit = 200000
max_line_length = 120

[sqlfluff:indentation]
indented_joins = False
indented_ctes = False
indented_using_on = True
indent_unit = space
tab_space_size = 2
template_blocks_indent = True
allow_implicit_indents = True

[sqlfluff:templater]
unwrap_wrapped_queries = True

[sqlfluff:templater:jinja]
apply_dbt_builtins = True

[sqlfluff:templater:jinja:macros]
# Macros provided as builtins for dbt projects
dbt_ref = {% macro ref(model_ref) %}{{model_ref}}{% endmacro %}
dbt_source = {% macro source(source_name, table) %}{{source_name}}_{{table}}{% endmacro %}
dbt_config = {% macro config() %}{% for k in kwargs %}{% endfor %}{% endmacro %}
dbt_var = {% macro var(variable, default='') %}item{% endmacro %}
dbt_is_incremental = {% macro is_incremental() %}True{% endmacro %}

# Some rules can be configured directly from the config common to other rules.
[sqlfluff:rules]
allow_scalar = True
single_table_references = consistent
unquoted_identifiers_policy = all

[sqlfluff:layout:type:comma]
line_position = leading

[sqlfluff:layout:type:binary_operator]
line_position = leading

[sqlfluff:rules:aliasing.column]
aliasing = explicit

[sqlfluff:rules:aliasing.expression]
allow_scalar = False

[sqlfluff:rules:aliasing.table]
aliasing = implicit

[sqlfluff:rules:capitalisation.functions]
extended_capitalisation_policy = upper

[sqlfluff:rules:capitalisation.identifiers]
extended_capitalisation_policy = lower

[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = upper

[sqlfluff:rules:capitalisation.literals]
capitalisation_policy = upper

[sqlfluff:rules:capitalisation.types]
extended_capitalisation_policy = upper

[sqlfluff:rules:convention.count_rows]
prefer_count_1 = False
prefer_count_0 = False

[sqlfluff:rules:convention.select_trailing_comma]
select_clause_trailing_comma = forbid

[sqlfluff:rules:convention.terminator]
multiline_newline = True
require_final_semicolon = True

[sqlfluff:rules:layout.long_lines]
ignore_comment_lines = False

[sqlfluff:rules:references.keywords]
unquoted_identifiers_policy = aliases
ignore_words = timestamp

[sqlfluff:rules:references.quoting]
ignore_words = date

[sqlfluff:rules:structure.subquery]
# By default, allow subqueries in FROM clauses, but not JOIN clauses.
forbid_subquery_in = join

Are you willing to work on and submit a PR to address the issue?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfix corrupts sqlFor identifying issues where running the fix command actually breaks the SQL - bad!

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions