sqlfluff / sqlfluff

A modular SQL linter and auto-formatter with support for multiple dialects and templated code.

Home Page:https://www.sqlfluff.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unparsable section error in DBT project in sqlfluff 3.0.2 version (Databricks dialect)

mstfkmlbsbdk2023 opened this issue · comments

Search before asking

  • I searched the issues and found no similar issues.

What Happened

I have a piece of sql code for my dbt project. I wanted to lint this sql code. When I run sqlfluff lint I get an unparseable section error. If I run the same code with sqlfluff in version 2.3.5 it works very well.

Here is the piece of sql code which I took from your repo: (

)

SELECT
    c_age,
    COUNT(*) AS record_count
FROM person
    LATERAL VIEW EXPLODE(ARRAY(30, 60)) AS c_age
    LATERAL VIEW EXPLODE(ARRAY(40, 80)) AS d_age
GROUP BY c_age;

Expected Behaviour

I was expecting the code, which worked without errors in version 2.3.5, to run without errors in version 3.0.2 as well.
in addition I have another issue. if I run above code in the sqlfluff online with using databricks as dialect, I am getting an unparseable section error. but If I choose sparksql as dialect, there is no error appear there. In my opinion, the problem is caused by group by with using lateral view.

Observed Behaviour

The error I get is as follows :(Databricks dialect)

Line 7, Position 7: Found unparsable section: 'BY c_age'

Screenshot 2024-04-03 at 12 01 37

there is no error is as follows : (sparksql dialect)

Screenshot 2024-04-03 at 12 03 26

The error I get with my real SQL code :(Databricks dialect)

Screenshot 2024-04-03 at 11 01 31

How to reproduce

  1. Use similar sql code which is provided in the "What Happened" box.
  2. Execute sqlfluff lint <your file path>

Dialect

Databricks

Version

sqlfluff==3.0.2
sqlfluff-templater-dbt==3.0.2

Configuration

[tool.sqlfluff.core]
templater = "dbt"
dialect = "databricks"
max_line_length = 90

[tool.sqlfluff.templater.dbt]
project_dir = "dbt_transform"
apply_dbt_builtins = true

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