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

check-script-has-no-table-name fails with subqueries referencing CTEs #16

Closed
MartinGuindon opened this issue Mar 16, 2021 · 1 comment · Fixed by #19
Closed

check-script-has-no-table-name fails with subqueries referencing CTEs #16

MartinGuindon opened this issue Mar 16, 2021 · 1 comment · Fixed by #19
Assignees
Labels
bug Something isn't working

Comments

@MartinGuindon
Copy link

Describe the bug
check-script-has-no-table-name fails with subqueries referencing CTEs if there is no space between the CTE name and the closing parenthesis .

To Reproduce
The following fails with the error models/staging/intermediate/assets_enriched.sql: does not use source() or ref() macros for tables: - asset_category)

with assets as (
    select * from {{ ref('stg_rse__assets') }}
),

asset_category as (
    select * from {{ ref('data_asset_category') }}
),

final as (
    select 
        assets.*,
        case
            when assets.category = 'cars' then assets.category
            when assets.category = 'wine-spirits' then assets.category
            when assets.ticker in (select ticker from asset_category) then asset_category.asset_category
            else 'unknown'
        end as asset_category
        
    from assets

    left join asset_category using (ticker)
)

select * from final

Changing the subquery on line 15 to (select ticker from asset_category ), essentially adding a space between the CTE name and closing parenthesis fixes the issue, but breaks the SQL style guide.

Version:
v0.1.1 bleeding edge

@tomsej
Copy link
Contributor

tomsej commented Apr 7, 2021

Thanks again @MartinGuindon for reporting this bug. Think I fixed that. Once again it is only in bleeding edge version. Hopefully I will release new version soon, since I have added some new hooks :D. To upgrade to bleeding edge - pre-commit autoupdate --bleeding-edge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants