sqlfluff: Snowflake: Interaction between L025 and L028 corrupts SQL

Search before asking

  • I searched the issues and found no similar issues.

What Happened

sqfluff fix

SELECT
  r.rec:foo::string AS foo
  , value:bar::string AS bar
FROM foo.bar r, LATERAL FLATTEN(input => rec:result) x
;

Produces:

L:   3 | P:   5 | L028 | Unqualified reference 'value' found in single table select.
L:   4 | P:  54 | L025 | Alias 'x' is never used in SELECT statement.

SELECT
  r.rec:foo::string AS foo
  , r.value:bar::string AS bar
FROM foo.bar r, LATERAL FLATTEN(input => rec:result)
;

The issue here is it doesn’t recognise the LATERAL FLATTEN as a table entity. Replacing the LATERAL FLATTEN with bar gives

SELECT
  r.rec:foo::string AS foo
  , value:bar::string AS bar
FROM foo.bar r, bar x
;

L:   4 | P:  21 | L025 | Alias 'x' is never used in SELECT statement.

Expected Behaviour

LATERAL FLATTEN should be treated like a table

Observed Behaviour

How to reproduce

Dialect

Snowflake

Version

0.13.0

Configuration

Unaffected by config

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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (17 by maintainers)

Most upvoted comments

I agree lint is bang on - the issue is the L028 that is firing for fix. It’s not recognising the multiple tables. The second problem I suppose is that it’s behaving differently in lint and fix