perf: reuse columns from process_schema_changes in incremental materialization#1412
Open
moomindani wants to merge 1 commit intodatabricks:mainfrom
Open
perf: reuse columns from process_schema_changes in incremental materialization#1412moomindani wants to merge 1 commit intodatabricks:mainfrom
moomindani wants to merge 1 commit intodatabricks:mainfrom
Conversation
…alization Incremental materialization previously discarded the return value of `process_schema_changes`, causing each strategy macro (`merge`, `append`, `delete+insert`) to issue a second `DESCRIBE TABLE EXTENDED` on the target relation even though `check_for_schema_changes` had just DESCRIBEd it. This change: - captures the columns returned by `process_schema_changes` in both V1 and V2 paths - falls back to a single `adapter.get_columns_in_relation(existing_relation)` when `on_schema_change == 'ignore'` - threads the result through `strategy_arg_dict['dest_columns']` - teaches `databricks__get_merge_sql`, `get_delete_insert_sql`, and `get_insert_into_sql` to honor a pre-supplied `dest_columns` and skip their own `DESCRIBE` when provided Net effect: one fewer `DESCRIBE TABLE EXTENDED … AS JSON` round-trip per incremental model, per run. Verified on a project with 9 incremental stg models (V1 path, `on_schema_change: 'fail'`): target DESCRIBE count drops from 2 to 1 per model across merge, append, and delete+insert strategies. Resolves databricks#1411 Co-authored-by: Isaac
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
Closes #1411.
The incremental materialization currently discards the return value of
process_schema_changes, so each downstream strategy macro (merge,append,delete+insert) re-issues anotherDESCRIBE TABLE EXTENDEDon the target relation even though
check_for_schema_changeshas justDESCRIBEd it. This PR reuses those columns, eliminating one metadata
round-trip per incremental model, per run.
Changes
dbt/include/databricks/macros/materializations/incremental/incremental.sqlprocess_schema_changesin both V1 and V2 paths.on_schema_change == 'ignore'(returns{}), fall back to asingle
adapter.get_columns_in_relation(existing_relation).strategy_arg_dict['dest_columns'](previously hard-coded to
none).get_build_sqlwith adest_columns=noneparameter so theV2 path can pass through.
dbt/include/databricks/macros/materializations/incremental/strategies.sqldatabricks__get_merge_sql: only DESCRIBE the target whendest_columns is none.get_delete_insert_sql: honorarg_dict['dest_columns']when set.get_insert_into_sql: accept adest_columns=noneparameter andhonor it;
databricks__get_incremental_append_sqlnow passesarg_dict['dest_columns']through.CHANGELOG.md: new entry under## dbt-databricks next→Under the Hood.Behavior
on_schema_changeis'fail','sync_all_columns', or'append_new_columns':process_schema_changesalready DESCRIBEdboth relations, so we reuse its result — one fewer DESCRIBE.
on_schema_change == 'ignore': we issue exactly one DESCRIBE onthe existing relation, matching today's total count for that path.
get_build_sqlgainsan optional keyword argument that defaults to
none.Test plan
Manually verified on a live Databricks SQL Warehouse with a project of
9 incremental stg models (
on_schema_change: 'fail', 7merge+ 2appendstrategies).Target
DESCRIBE TABLE EXTENDED … AS JSONcount per incremental model:use_materialization_v2: false)use_materialization_v2: true)Wall-clock impact on a full
dbt runis within measurement noise atthis scale (9 small models, 16 threads); the saved round-trips get
absorbed by parallelism. The win here is fewer metadata round-trips
(lower warehouse load, less API traffic), not a dramatic wall-clock
speedup.