Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Incremental Strategy - Edge Case Safeguarding on Merge Incremental Model #10440

Closed
2 tasks done
zvijayakumar opened this issue Jul 13, 2024 · 1 comment
Closed
2 tasks done
Labels
enhancement New feature or request wontfix Not a bug or out of scope for dbt-core

Comments

@zvijayakumar
Copy link

zvijayakumar commented Jul 13, 2024

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

Edge Case Safeguarding in dbt Core Incremental Merge Stragerty

Refer this Documentation

If the event_time column is NULL or the table is truncated, the following situation occurs:

• When event_time is NULL, the query select * from stg_source_table where event_time > NULL returns no results because the condition evaluates to NULL.
• This results in no data being loaded, and dbt considers it an incremental load, which can lead to model failure.

Currently, dbt does not handle this edge case, which can cause issues during incremental loads.

Thanks, @mirnawong1 for the advice to open an issue in dbt core as suggested in PR

Expected Behavior

dbt should handle this edge case by ensuring that if event_time is NULL or the table is truncated, the incremental load does not fail. Suggested improvements include adding logic to handle NULL values in the event_time column. As suggested by @mirnawong1 in the PR

Steps To Reproduce

{{
    config(
        materialized='incremental',
        unique_key='date_day'
    )
}}

select
    date_trunc('day', event_at) as date_day,
    count(distinct user_id) as daily_active_users

from {{ ref('app_data_events') }}


{% if is_incremental() %}

  -- this filter will only be applied on an incremental run
  -- (uses >= to include records arriving later on the same day as the last run of this model)
  where date_day >= (select event_time from {{ this }})

{% endif %}

group by 1
  1. Truncate the destination table.
  2. As the table already exists in the database schema. dbt considers it as the incremental load.
  3. Where condition date_day >= NULL it is always True and returns No result. It will leads to No data load
  4. It's edge case that has to handled in the dbt.
  5. To handle this case I have added the sample code in the dbt documentation Doc Link

Relevant log output

No response

Environment

- OS:
- Python:
- dbt:

Which database adapter are you using with dbt?

snowflake

Additional Context

No response

@zvijayakumar zvijayakumar added bug Something isn't working triage labels Jul 13, 2024
@dbeatty10 dbeatty10 added enhancement New feature or request and removed bug Something isn't working labels Jul 15, 2024
@dbeatty10 dbeatty10 changed the title Incremental Strategy - Edge Case Safeguarding on Merge Incremental Model [Feature] Incremental Strategy - Edge Case Safeguarding on Merge Incremental Model Jul 15, 2024
@dbeatty10
Copy link
Contributor

Thanks for reaching out @zvijayakumar !

This looks similar to #9997 which we closed in favor of updating the documentation (dbt-labs/docs.getdbt.com#5321):

Anything related to this particular edge case needs to be handled in dbt product documentation rather than in dbt-core.

There's two key reasons why:

  1. Changing when is_incremental() is True would be a breaking change, and we don't plan on doing it
  2. We also don't plan on modifying any Jinja logic that is provided by the user within is_incremental() conditional logic

@dbeatty10 dbeatty10 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 15, 2024
@dbeatty10 dbeatty10 added wontfix Not a bug or out of scope for dbt-core and removed triage labels Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix Not a bug or out of scope for dbt-core
Projects
None yet
Development

No branches or pull requests

2 participants