Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L026 rule (ansi) cannot find table/view aliases in the FROM clause with JOINS in subquery #1939

Closed
tkachenkomaria244 opened this issue Nov 19, 2021 · 1 comment · Fixed by #1948
Labels
bug Something isn't working enhancement to existing rule rule bug A rule is not working as intended, either missing errors or incorrectly highlighting non-errors

Comments

@tkachenkomaria244
Copy link
Contributor

Rule L026 finds violations in the code below, but actually all aliases exists in FROM statement.

select
	cc.c1
from
(
	select c.c1
	from
		table1 as c
	join
		table2 as ci
		on c.x_id = ci.x_id
	join
		table3 as pci
		on ci.y_id = pci.y_id
) as cc

Expected Behaviour

no violations of L026

Observed Behaviour

PS D:\py_code\sqlfluff> sqlfluff lint D:\py_code\sqlfluff\real_tests\v_v.sql --rules L026
== [D:\py_code\sqlfluff\real_tests\v_v.sql] FAIL
L:  10 | P:   6 | L026 | Reference 'c.x_id' refers to table/view not found in the
                       | FROM clause or found in parent subquery.
L:  10 | P:  15 | L026 | Reference 'ci.x_id' refers to table/view not found in
                       | the FROM clause or found in parent subquery.
L:  13 | P:   6 | L026 | Reference 'ci.y_id' refers to table/view not found in
                       | the FROM clause or found in parent subquery.
L:  13 | P:  16 | L026 | Reference 'pci.y_id' refers to table/view not found in
                       | the FROM clause or found in parent subquery.

Following scripts dosn't give these errors:

select c.c1
from
	table1 as c
join
	table2 as ci
	on c.x_id = ci.x_id
join
	table3 as pci
	on ci.y_id = pci.y_id
select
	cc.c1
from
(
	select c.c1
	from
		table1 as c,
		table2 as ci,
		table3 as pci
	where c.x_id = ci.x_id
		and ci.y_id = pci.y_id
) as cc

Dialect

Dialects = ansi, tsql

Version

Python 3.9.6
SQLFluff 0.8.1 and earlier.

Configuration

[sqlfluff]
exclude_rules = L007,L015,L017,L020,L021,L022,L023,L024,L029,L031,L032,L033,L034,L035,L037,L038,L041,L042,L043,L044,L045,L046,L047
sql_file_exts = .sql
dialect = tsql

[sqlfluff:indentation]
indented_joins = False
template_blocks_indent = True

[sqlfluff:rules]
tab_space_size = 4
max_line_length = 250
indent_unit = tab
comma_style = leading
single_table_references = qualified
allow_scalar = False

[sqlfluff:rules:L010] # Keywords
capitalisation_policy = lower

[sqlfluff:rules:L014]  # Unquoted identifiers
extended_capitalisation_policy = lower

[sqlfluff:rules:L016]
ignore_comment_lines = False

[sqlfluff:rules:L030] # Function names
capitalisation_policy = lower
[sqlfluff:rules:L040] # Null & Boolean Literals
capitalisation_policy = lower

[sqlfluff:rules:L019]
comma_style = leading

[sqlfluff:rules:L028]
single_table_references = qualified


@tkachenkomaria244 tkachenkomaria244 added the bug Something isn't working label Nov 19, 2021
@tunetheweb tunetheweb added enhancement to existing rule rule bug A rule is not working as intended, either missing errors or incorrectly highlighting non-errors labels Nov 19, 2021
@jpy-git
Copy link
Contributor

jpy-git commented Nov 20, 2021

looking into this 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement to existing rule rule bug A rule is not working as intended, either missing errors or incorrectly highlighting non-errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants