Skip to content

Commit

Permalink
L026: check standalone aliases as well as table aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
tunetheweb committed Jun 20, 2022
1 parent 22de3dc commit 14e34c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/sqlfluff/rules/L026.py
Expand Up @@ -24,6 +24,7 @@ class L026Query(SelectCrawlerQuery):
"""SelectCrawler Query with custom L026 info."""

aliases: List[AliasInfo] = field(default_factory=list)
standalone_aliases: List[str] = field(default_factory=list)


@document_groups
Expand Down Expand Up @@ -125,6 +126,7 @@ def _analyze_table_references(
if select_info:
# Record the available tables.
query.aliases += select_info.table_aliases
query.standalone_aliases += select_info.standalone_aliases

# Try and resolve each reference to a value in query.aliases (or
# in an ancestor query).
Expand Down Expand Up @@ -194,6 +196,8 @@ def _resolve_reference(
targets = []
for alias in query.aliases:
targets += self._alias_info_as_tuples(alias)
for standalone_alias in query.standalone_aliases:
targets.append((standalone_alias,))
if not object_ref_matches_table(possible_references, targets):
# No. Check the parent query, if there is one.
if query.parent:
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/rules/std_rule_cases/L026.yml
Expand Up @@ -265,3 +265,14 @@ test_soql_ignore_rule:
configs:
core:
dialect: soql

test_postgres_value_table_alias:
pass_str: |
select
sc.col1 as colx
, pn.col1 as coly
from sch1.tbl1 as sc
cross join unnest(array[111, 222]) as pn(col1)
configs:
core:
dialect: postgres

0 comments on commit 14e34c9

Please sign in to comment.