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

Parsing error on Duckdb QUALIFY #5051

Closed
5 of 9 tasks
bgarcevic opened this issue Aug 4, 2023 · 5 comments · Fixed by #5514
Closed
5 of 9 tasks

Parsing error on Duckdb QUALIFY #5051

bgarcevic opened this issue Aug 4, 2023 · 5 comments · Fixed by #5514
Labels
bug Something isn't working duckdb Issue relating to the dbduck dialect good first issue Good for newcomers

Comments

@bgarcevic
Copy link

bgarcevic commented Aug 4, 2023

This ticket requests several things. Checked when they are done

Search before asking

  • I searched the issues and found no similar issues.

What Happened

This is a valid duckdb query

with

source as (

    select * from {{ source('danish_parliament', 'raw_aktoer_type') }}
    qualify row_number() over (partition by id order by opdateringsdato desc) = 1
),

renamed as (

    select
        id as actor_type_id,
        type as actor_type,
        opdateringsdato as updated_at
    from source

)

select * from renamed

I get an unparseble error using both dbt and jinja templater.

Expected Behaviour

Should be able to be parsed and not return error

Observed Behaviour

sqlfluff lint models\staging\stg_actor_types.sql
=== [dbt templater] Sorting Nodes...
20:35:22  [WARNING]: Configuration paths exist in your dbt_project.yml file which do not apply to any resources.
There are 1 unused configuration paths:
- models.danish_democracy_data.intermediate
=== [dbt templater] Compiling dbt project...
=== [dbt templater] Project Compiled.
== [models\staging\stg_actor_types.sql] FAIL
L:   6 | P:   5 |  PRS | Line 6, Position 5: Found unparsable section: 'qualify
                       | row_number() over (partition by ...'

How to reproduce

  1. save the sample sql into file example.sql
  2. use the sample .sqlfluff file
  3. Run sqlfluff lint against example.sql

Dialect

DuckDB

Version

sqlfluff, version 2.2.0

Configuration

.sqlfluff

[sqlfluff]
dialect = duckdb
templater = dbt
runaway_limit = 10
max_line_length = 80
indent_unit = space
exclude_rules = RF05

[sqlfluff:indentation]
tab_space_size = 4

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

[sqlfluff:rules:capitalisation.keywords] 
capitalisation_policy = lower

[sqlfluff:rules:aliasing.table]
aliasing = explicit

[sqlfluff:rules:aliasing.column]
aliasing = explicit

[sqlfluff:rules:aliasing.expression]
allow_scalar = False

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

[sqlfluff:rules:capitalisation.functions]
capitalisation_policy = lower

[sqlfluff:rules:capitalisation.literals]
capitalisation_policy = lower

[sqlfluff:rules:ambiguous.column_references]  # Number in group by
group_by_and_order_by_style = implicit

.sqlfluffignore

reports
target
dbt_packages
macros
extract-load
.dbtenv
.vscode
logs

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

@bgarcevic bgarcevic added the bug Something isn't working label Aug 4, 2023
@github-actions github-actions bot added the duckdb Issue relating to the dbduck dialect label Aug 4, 2023
@bgarcevic bgarcevic changed the title Parsing error on Duckdb qualify Parsing error on Duckdb QUALIFY Aug 4, 2023
@WittierDinosaur WittierDinosaur added the good first issue Good for newcomers label Aug 10, 2023
@droher
Copy link

droher commented Aug 10, 2023

There are a number of newer DuckDB syntax features which cause parsing errors - the ones I know of are UNION ALL BY NAME, PIVOT, EXCLUDE, REPLACE, and //. Would it be better to include them in this ticket, open up a new ticket for these five, or open up new tickets for each one?

@alanmcruickshank
Copy link
Member

alanmcruickshank commented Aug 11, 2023 via email

@bgarcevic
Copy link
Author

bgarcevic commented Aug 11, 2023

Here are the links i could for some of the features @droher mentioned:

I could not find the // in the docs. Is that a comment thing?

Should I add them to this issue or create a new?

@droher
Copy link

droher commented Aug 11, 2023

// is integer division: https://duckdb.org/docs/sql/functions/numeric.html

This was referenced Sep 4, 2023
@keraion
Copy link
Contributor

keraion commented Dec 21, 2023

DuckDB supports a from-first syntax which allows the FROM clause to be stated either without or in front of a SELECT clause. https://duckdb.org/docs/archive/0.9.2/sql/query_syntax/from

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duckdb Issue relating to the dbduck dialect good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants