Skip to content

Falsely linted Bigquery sql using subquery with arrays #5471

@samir-

Description

@samir-

Search before asking

  • I searched the issues and found no similar issues.

What Happened

The linter fix with bigquery dialect applies a deletion on the alias t and renders the query un-executable due to missing t table.
original query:
with table_arr as (select [1,2,4,2] as arr) SELECT * REPLACE (ARRAY (SELECT DISTINCT el FROM t.arr AS el) AS arr) FROM table_arr t

Expected Behaviour

not applying any change on the alias.

with table_arr as (select [1,2,4,2] as arr) SELECT * REPLACE (ARRAY (SELECT DISTINCT el FROM t.arr AS el) AS arr) FROM table_arr t

Observed Behaviour

the linter deletes the t
with table_arr as (select [1,2,4,2] as arr) SELECT * REPLACE (ARRAY (SELECT DISTINCT el FROM t.arr AS el) AS arr) FROM table_arr

How to reproduce

apply sqlfull fix

Dialect

sqlfluff-fix with bigquery dialect

Version

2.0.2

Configuration

[sqlfluff]
dialect = bigquery
templater = dbt
runaway_limit = 10
indent_unit = space
large_file_skip_byte_limit = 0
max_line_length = 250
exclude_rules=L034,L029
processes = -1

[sqlfluff:templater:jinja]
apply_dbt_builtins = True
load_macros_from_path=macros

[sqlfluff:templater:dbt:context]
sqlfluff_ignore = true

[sqlfluff:indentation]
tab_space_size = 4
indented_joins = False

[sqlfluff:layout:type:comma]
spacing_before = touch
line_position = trailing

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

[sqlfluff:rules:aliasing.table] # Explicit table alias
aliasing = explicit

[sqlfluff:rules:aliasing.column] # Explicit column alias
aliasing = explicit

[sqlfluff:rules:aliasing.expression] # Column expressions must have alias
allow_scalar = False

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

[sqlfluff:rules:layout.long_lines]
ignore_comment_lines = True
ignore_comment_clauses = True

[sqlfluff:rules:capitalisation.functions] # Function names
capitalisation_policy = lower

[sqlfluff:rules:capitalisation.literals] # Boolean names
capitalisation_policy = lower

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

    bigqueryIssues relating to the BigQuery dialectbugSomething isn't working

    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