BigQuery - Unable to use the "set_sql_header" macro to declare variables for incremental models #2940
Closed
1 of 5 tasks
Labels
bigquery
bug
Something isn't working
good_first_issue
Straightforward + self-contained changes, good for new contributors!
Milestone
Describe the bug
I used the
set_sql_header
macro to declare a BigQuery scripting variable and initialize it so it can be used in the context of my model. The model materialization is of typeincremental
withincremental_strategy="insert_overwrite"
and creates a partitioned table.The initial run (i.e. not incremental) works fine. However a subsequent run (incremental) fails due to syntax error in the executed query.
Steps To Reproduce
Here is the model definition:
Here is the executed query for the initial run:
query
And here is the executed query for the incremental run that fails:
query
We can see that the definition and initialization of my variable happens after the ones for the
_dbt_max_partition
variable. Unfortunately, this is done in two steps for_dbt_max_partition
: first a DECLARE statement then a SET statement.However, as per the BigQuery documentation on variable definition:
Expected behavior
I should be able to declare variables that are available in my model, whether it's an initial or incremental run.
A simple solution to achieve this, could be merging the DECLARE and SET statements used for the
_dbt_max_partition
variable into one single statement (DECLARE + DEFAULT) as this:I can submit a PR with that change if the proposed solution is accepted.
Screenshots and log output
Completed with 1 error and 0 warnings: Database Error in model my_incremental_model (models/perso_test/my_incremental_model.sql) Variable declarations are allowed only at the start of a block or script at [14:1]
System information
Which database are you using dbt with?
The output of
dbt --version
:The text was updated successfully, but these errors were encountered: