You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In previous versions, the star() macro produced a comma-separated list of fields, such as
id,
date,
field
With #436 as part of 0.8.0 it now will produce a comma-separated list of fields and aliases, such that the output is
id as id,
date as date,
field as field
Steps to reproduce, expected results, actual results
We have a specific usage of a star() macro where
{% set upstream_model ='model1' %}
{% set partition_columns = star(from=ref(model1)) %}
select*,
first_value(category) over (partition by {{ partition_columns }}
order by start_date desc) as past_category
from {{ ref(model1) }}
Under dbt-utils 0.7.5 this is the generated output:
select*,
first_value(category) over (partition by
"FIELD1",
"FIELD2",
"FIELD3"order by start_date desc) as past_category
fromstaging.model1
Under dbt-utils 0.8.0 this is the generated output, which fails because we can't alias fields within an over() clause
select*,
first_value(category) over (partition by
"FIELD1"as"FIELD1",
"FIELD2"as"FIELD2",
"FIELD3"as"FIELD3"order by start_date desc) as past_category
fromstaging.model1
System information
The contents of your packages.yml file:
Which database are you using dbt with?
postgres
redshift
bigquery
snowflake
other (specify: ____________)
The output of dbt --version:
installed version: 1.0.0
latest version: 1.0.0
Up to date!
Plugins:
- snowflake: 1.0.0
Are you interested in contributing the fix?
I would be, I think what it needs is flags to see if prefix and suffix exist and if neither exist, don't append the as clause. This is the specific line:
{%- if relation_alias %}{{ relation_alias }}.{% else %}{%- endif -%}{{ adapter.quote(col)|trim }} as {{ adapter.quote(prefix ~ col ~ suffix)|trim }}
So in psuedocode it'd be something like:
{%- if relation_alias %}
{{ relation_alias }}.{% else %}{%- endif -%}{{ adapter.quote(col)|trim }}
--if prefix is not null or suffix is not null
as {{ adapter.quote(prefix ~ col ~ suffix)|trim }}
{%- if not loop.last %},{{ '\n ' }}{% endif %}
The text was updated successfully, but these errors were encountered:
Yes good call @foundinblank! Even if it wasn't breaking the partition, it's ugly to alias something to itself 😅 I should have thought about this in code review.
If/when you do have a crack at this, could I prevail upon you to add an integration test to the star macro that incorporates a window function or something similar, so that we can catch this sort of thing automatically in the future?
Describe the bug
In previous versions, the
star()
macro produced a comma-separated list of fields, such asWith #436 as part of 0.8.0 it now will produce a comma-separated list of fields and aliases, such that the output is
Steps to reproduce, expected results, actual results
We have a specific usage of a
star()
macro whereUnder dbt-utils 0.7.5 this is the generated output:
Under dbt-utils 0.8.0 this is the generated output, which fails because we can't alias fields within an
over()
clauseSystem information
The contents of your
packages.yml
file:Which database are you using dbt with?
The output of
dbt --version
:Are you interested in contributing the fix?
I would be, I think what it needs is flags to see if
prefix
andsuffix
exist and if neither exist, don't append theas
clause. This is the specific line:dbt-utils/macros/sql/star.sql
Line 27 in eb1ec81
So in psuedocode it'd be something like:
The text was updated successfully, but these errors were encountered: