[Bug] Constant Expressions Error for Redshift #32
Labels
error:unforced
good first issue
Good for newcomers
status:in_review
Currently in review
type:bug
Something is broken or incorrect
type:wontfix
This will not be worked on
Is there an existing issue for this?
Describe the issue
Issue Details
Since the introduction of the union data feature in v0.10.0 we have seen an issue be introduced where Redshift users who are not leveraging the union data feature are seeing a constant expression error (see relevant error log for full error output). This error is caused because the union data macro will create the
source_relation
field and will insert an empty string if no union schemas/databases are provided in the respective variables. Therefore, since we have the empty string for all fields it is treated as a constant expression and therefore is not able to be included in a partition statement.This issue commonly only happens when the upstream source table is not present (the package creates an empty staging model), but it can also happen when the upstream source table is present. We previously addressed this issue by applying the following code update in other Ad Reporting packages.
While this does seem to work to address this constant expression issue when the upstream table is not present, it has been found to not address the issue when the constant expression issue is persisting even when the upstream source table is present.
Thankfully, in the recent release of the dbt_aws_cloud_cost dbt package we found a creative solution to this issue! Instead of the lengthy case when statement from before, we found that we can remove the
source_relation
field from the partition if the respective union schemas/databases variable is empty (since this issue does not occur when using the union schema variable. Therefore, the following code update in dbt_aws_cloud_cost addressed this very issue.Solution
We found that in some cases one solution works but the other doesn't. Fortunately, in the latest Twitter Organic PR #11 we found a solution to this very problem. To completely address the constant expression issue we will do the following:
pinterest_source
.pinterest_source
.This will then need to be applied to all other window functions in this package. Please ensure all window functions receive this update. From my initial scope I imagine this only needs to be applied to the
is_most_recent_record
fields in the*_history
staging models.Relevant error log or model output
constant expressions are not supported in partition by clauses compiled code
Expected behavior
The models are able to compile successfully on Redshift regardless of the constant expressions generated from the union data feature.
dbt Project configurations
Normal schema and database variables. No other custom configuration.
Package versions
What database are you using dbt with?
redshift
dbt Version
v1.8.x
Additional Context
It may also be worthwhile to inspect the downstream models to ensure we do or do not need to make similar updates there.
Are you willing to open a PR to help address this issue?
The text was updated successfully, but these errors were encountered: