dbt-labs / dbt-adapters

Apache License 2.0
28 stars 38 forks source link

Always ensure valid incremental strategy #331

Closed QMalcolm closed 1 month ago

QMalcolm commented 1 month ago

resolves #330

Problem

Previously if you set an invalid incremental_strategy for an incremental model, it'll succeed on the first run, and then fail on the second run I.e. if you have

{{config(materialized="incremental", incremental_strategy="bad_strategy")}}

select * from {{ ref("input_model") }}

{% if is_incremental() %}
where event_time >= (select coalesce(max(event_time),'1900-01-01') from {{ this }} )
{% endif %}

That was always succeeding when the model was either built for the first time or rebuilt via --full-refresh. You only got an error about the strategy the next time the model was run.

Solution

Change the order of operations in incremental.sql to ensure that a incremental model's incremental_strategy is always validated

Checklist