feat: add skip_merge_on_empty_source incremental config#1410
Open
moomindani wants to merge 1 commit intodatabricks:mainfrom
Open
feat: add skip_merge_on_empty_source incremental config#1410moomindani wants to merge 1 commit intodatabricks:mainfrom
moomindani wants to merge 1 commit intodatabricks:mainfrom
Conversation
Adds an opt-in incremental config that bypasses MERGE and all associated metadata queries (DESCRIBE, SHOW TBLPROPERTIES, constraint/tag/mask lookups) when the compiled source SELECT returns zero rows. Motivating case: customers who run `dbt run` on a schedule against source tables that receive deltas sporadically. Today, each incremental model still pays ~4-7s per run on temp view creation + metadata queries + MERGE planning even when there is nothing to merge. With `skip_merge_on_empty_source: true`, the materialization runs a cheap `SELECT 1 FROM (<compiled>) LIMIT 1` probe and, if empty, returns early after firing pre/post hooks and a no-op `main` statement. Scope: - V1 (`use_materialization_v2: false`) and V2 paths both honor the flag - Default is `false` (opt-in, no behavior change for existing projects) - SQL language only (Python models fall through to the standard path) Files: - `dbt/adapters/databricks/impl.py`: new `skip_merge_on_empty_source` field on `DatabricksConfig` - `dbt/include/databricks/macros/materializations/incremental/incremental.sql`: two helper macros (`source_has_rows`, `should_skip_merge_on_empty_source`) and short-circuit calls in the V1/V2 merge branches - `tests/functional/adapter/incremental/test_incremental_skip_on_empty_source.py`: functional tests covering the short-circuit path and the default-off behavior under both V1 and V2 - `CHANGELOG.md`: Features entry Co-authored-by: Isaac
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Adds an opt-in incremental config
skip_merge_on_empty_sourcethatbypasses MERGE and all associated metadata queries (DESCRIBE, SHOW
TBLPROPERTIES, constraint/tag/mask lookups) when the compiled source
SELECT returns zero rows.
Motivation
Customers running
dbt runon a cadence against sources that receivedeltas sporadically pay ~4–7 s per incremental model per run on:
CREATE OR REPLACE TEMPORARY VIEWfor the compiled source SELECTDESCRIBE TABLE EXTENDED … AS JSONSHOW TBLPROPERTIESEven with
incremental_apply_config_changes: false, the structuraloverhead (temp view, DESCRIBE, MERGE planning) remains. On a real workload
with 11 light incremental stg models, this totals ~30–50 s of wall-clock
time per no-op run.
Snowflake short-circuits empty MERGE sources in ~1–2 s; this flag closes
the gap for workloads where deltas are often empty.
Design
DatabricksConfig.skip_merge_on_empty_source: Optional[bool] = None(default
false– opt-in, no behavior change for existing projects).source_has_rows(compiled_code): issuesSELECT 1 FROM (<compiled_code>) LIMIT 1.should_skip_merge_on_empty_source(...): checks the flag, SQLlanguage,
executemode, then callssource_has_rows. On emptysource, fires a no-op
mainstatement +apply_grants+ logs.placed before
create_temp_relation/get_relation_configso we skipall metadata queries too; V2 is placed after the intermediate table
creation (kept conservative to preserve pre-hook side-effects).
Measured impact
On a light merge model with ~0 row delta, wall-clock goes from ~7 s to
~1 s. For a project with 11 such models, saves ~60 s / run on the
incremental path without changing any other behavior.
Test plan
tests/functional/adapter/incremental/test_incremental_skip_on_empty_source.pyreal incremental merge model: 7.0 s → 1.17 s on no-op run