Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Features

- Add catalogs.yml v2 support (requires `use_catalogs_v2: true` in dbt-core) ([1440](https://github.com/databricks/dbt-databricks/pull/1440))
- Add `skip_optimize` model config to opt out of the post-materialization `OPTIMIZE` call without dropping `zorder` / `liquid_clustered_by` / `auto_liquid_cluster` from the table definition. Useful when `OPTIMIZE` is delegated to Predictive Optimization or scheduled out of band. Complements the existing run-wide `DATABRICKS_SKIP_OPTIMIZE` var by allowing project-, folder-, or model-level opt-out via standard dbt config inheritance ([#703](https://github.com/databricks/dbt-databricks/issues/703)).

### Under the Hood

Expand Down
1 change: 1 addition & 0 deletions dbt/adapters/databricks/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class DatabricksConfig(AdapterConfig):
query_tags: Optional[str] = None
tblproperties: Optional[dict[str, str]] = None
zorder: Optional[Union[list[str], str]] = None
skip_optimize: Optional[bool] = None
unique_tmp_table_suffix: bool = False
skip_non_matched_step: Optional[bool] = None
skip_matched_step: Optional[bool] = None
Expand Down
3 changes: 2 additions & 1 deletion dbt/include/databricks/macros/relations/optimize.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
{% endmacro %}

{%- macro databricks__optimize(relation) -%}
{%- if var('DATABRICKS_SKIP_OPTIMIZE', 'false')|lower != 'true' and
{%- if config.get('skip_optimize', false) -%}
Comment thread
sd-db marked this conversation as resolved.
Outdated
{%- elif var('DATABRICKS_SKIP_OPTIMIZE', 'false')|lower != 'true' and
var('databricks_skip_optimize', 'false')|lower != 'true' and
adapter.resolve_file_format(config) == 'delta' -%}
{%- if (config.get('zorder', False) or config.get('liquid_clustered_by', False)) or config.get('auto_liquid_cluster', False) -%}
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/macros/relations/test_optimize_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,20 @@ def test_macros_optimize_with_skip(self, key_val, var, template_bundle):
r = self.render_bundle(template_bundle, "optimize")

assert r == ""

@pytest.mark.parametrize(
"cluster_key,cluster_val",
[
("zorder", "foo"),
("liquid_clustered_by", ["foo"]),
("auto_liquid_cluster", True),
],
)
def test_macros_optimize_with_skip_optimize_config(
self, cluster_key, cluster_val, config, template_bundle
):
config[cluster_key] = cluster_val
config["skip_optimize"] = True
r = self.render_bundle(template_bundle, "optimize")

assert r == ""
Loading