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

[Bug] --empty flag generates SQL that conflicts with subquery aliases #9967

Closed
2 tasks done
khaledh opened this issue Apr 17, 2024 · 3 comments
Closed
2 tasks done

[Bug] --empty flag generates SQL that conflicts with subquery aliases #9967

khaledh opened this issue Apr 17, 2024 · 3 comments
Labels
bug Something isn't working empty Issues related to the --empty CLI flag pre-release Bug not yet in a stable release

Comments

@khaledh
Copy link

khaledh commented Apr 17, 2024

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

Running dbt run --empty generates SQL with a built-in alias like this (introduced here):

(select * from {rendered} where false limit 0) _dbt_limit_subq

If the original SQL already contains an alias, this causes a syntax error, e.g. this model:

SELECT ...
FROM {{ source('my_source', 'my_table') }} AS my_alias
JOIN ...

generates:

...
FROM (select * from `my_project`.`my_schema`.`my_table` where false limit 0) _dbt_limit_subq AS my_alias
...

-- Syntax error: Expected ")" but got keyword AS at [...]

Expected Behavior

I expect the --empty flag to generate valid subquery SQL that can be aliased for use in other parts of the query.

Steps To Reproduce

  1. Create a model that uses an aliased subquery (as shown above)
  2. Run dbt run --empty on the model

Relevant log output

No response

Environment

- OS: macOS Sonoma 14.4.1
- Python: 3.11.1
- dbt: 1.8.0-b2

Which database adapter are you using with dbt?

bigquery

Additional Context

No response

@khaledh khaledh added bug Something isn't working triage labels Apr 17, 2024
@dbeatty10 dbeatty10 added the pre-release Bug not yet in a stable release label Apr 18, 2024
@dbeatty10
Copy link
Contributor

Thanks for trying this out and reporting this @khaledh !

Do you get the same error when you run this?

dbt show -s your-model --limit 0

Also, are you installing dbt-core and dbt-bigquery from PyPI or from source (like either main or another branch)?

If PyPI, could you share your full output of dbt --version so we can see the versions of both dbt-core and dbt-bigquery that you have installed?

@dbeatty10
Copy link
Contributor

@khaledh This looks the same as dbt-labs/dbt-adapters#124, so I'm going to close this as a duplicate.

Do you want to join in on that issue and offer any unique perspectives or insights there?

@dbeatty10 dbeatty10 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 18, 2024
@dbeatty10 dbeatty10 removed the triage label Apr 18, 2024
@khaledh
Copy link
Author

khaledh commented Apr 18, 2024

@dbeatty10 Thanks for pointing out that other issue. Yes, it's the same issue, so no need for this one. I'll subscribe to the other issue.

@dbeatty10 dbeatty10 added the empty Issues related to the --empty CLI flag label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working empty Issues related to the --empty CLI flag pre-release Bug not yet in a stable release
Projects
None yet
Development

No branches or pull requests

2 participants