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

Microbatch generates invalid SQL when using aliases #255

Open
M4Al opened this issue Jan 24, 2025 · 1 comment
Open

Microbatch generates invalid SQL when using aliases #255

M4Al opened this issue Jan 24, 2025 · 1 comment
Assignees
Labels
bug Something isn't working dependencies Pull requests that update a dependency file

Comments

@M4Al
Copy link

M4Al commented Jan 24, 2025

I have a model similar like this
select A.id, B.id from {{ref('sometable'}} A inner join {{ref'someOtherTable')}} B on A.id = B.id

If this is configured as a microbatch model,, it gets compiled to

select A.id, B.id from (select * from someTable where lastModifiedAt >= ''2025-01-21 00:00:00+00:00'' and lastModifiedAt < ''2025-01-22 00:00:00+00:00'') _dbt_et_filter_subq_sometable A inner join someOtherTable B on A.id = B.id

as you can see there is a extra unexpected alias _dbt_et_filter_subq_sometable inserted that causes the sql to break.

I know that these kind of subqueries need an alias to be accepted as valid SQL, so that's probably the reason they are added automatically.

The workaround in my case is to wrap the table in an extra select statement like this

select A.id, B.id from ( select * from {{ref('sometable'}} ) A inner join {{ref'someOtherTable')}} B on A.id = B.id

Running dbt-core 1.9.1 and dbt-fabric 1.9.0

@prdpsvs prdpsvs self-assigned this Feb 10, 2025
@prdpsvs
Copy link
Collaborator

prdpsvs commented Feb 10, 2025

@M4Al , Could you please share a repro, of your model and config?

It looks like dbt is adding alias by default using _render_subquery_alias(). https://github.com/dbt-labs/dbt-adapters/blob/999dd7fd8238259538e271938cb5d1fc7e65c335/dbt-adapters/src/dbt/adapters/base/relation.py#L252

I am trying to find out if alias is optional or not
dbt-labs/dbt-adapters#807

@prdpsvs prdpsvs added bug Something isn't working dependencies Pull requests that update a dependency file labels Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

2 participants