Skip to content

fix: emit query_options on table_refresh_method=dml refresh path#753

Open
Benjamin-Knight wants to merge 1 commit into
dbt-msft:masterfrom
Benjamin-Knight:fix/dml-refresh-query-options
Open

fix: emit query_options on table_refresh_method=dml refresh path#753
Benjamin-Knight wants to merge 1 commit into
dbt-msft:masterfrom
Benjamin-Knight:fix/dml-refresh-query-options

Conversation

@Benjamin-Knight

Copy link
Copy Markdown
Collaborator

Emit query_options on the table_refresh_method: dml refresh path, resolve #752

The DML refresh materialization was dropping query_options / query_options_raw (and the LABEL query tag) on its two data-movement statements, so hints configured on a model only applied on the initial create and vanished on every steady-state refresh.

Changes:

  • Resolve the hint once via get_query_options(parse_options=True) in table_dml_refresh.sql.
  • Append the resulting OPTION (...) clause to both the main scratch-build (SELECT * INTO) and the dml_refresh_swap (INSERT ... SELECT), matching how create_table_as appends it.
  • Add a functional test (TestQueryOptionsOnDmlRefresh) that forces the second run down the DML refresh path and asserts the hint renders on both statements.
  • CHANGELOG entry.

No behavior change for models not using query_options or not on the DML path.

sqlserver__table_dml_refresh never called get_query_options(), so
query_options / query_options_raw (and the LABEL query tag) were
silently dropped on every steady-state DML refresh — inconsistent with
create_table_as, which honors them. Both grant-taking statements are
affected: the scratch-build SELECT ... INTO and the swap INSERT ... SELECT.

Hoist get_query_options(parse_options=True) once and append it to both
statements (matching how create_table_as attaches it, including the
trailing ';' it supplies).

Add a regression test asserting the OPTION hint renders on BOTH DML
statements. Only 'main' reaches target/run, so the test drives off the
captured debug log and checks each statement bounded by its terminator,
so a hint on one can't be mistaken for the other.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

query_options dropped on table_refresh_method: dml refresh path

1 participant