Fix column order in incremental materialization when using contracts #575
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When using dbt contracts on incremental models, the column order is not correctly set. This was fixed for table materializations in version 1.5.0, but was never implemented for incremental materializations.
The problem only surfaces when a different ordering is used for the columns in the contract (so in the yaml) compared to the ordering of columns in the actual user sql query. I suspect a relatively low amount of users are using all of contracts, incremental materializations and a non-consistent column order.
With this change, the
has_contractvariable is added to the incremental materializations, in a similar fashion to the table materialization. The variable is then passed through to theinsert_intomacro, which already supports correcting inconsistent column ordering by wrapping the user sql in an extraselectstatement.