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

ADAP-464: Add allow_non_incremental_definition option to BigQuery materialized views #1011

Closed
wants to merge 10 commits into from
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20231108-140752.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Support allow_non_incremental_definition option in BigQuery materialized views
time: 2023-11-08T14:07:52.28972-05:00
custom:
Author: bnaul
Issue: "672"
1 change: 1 addition & 0 deletions dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class BigqueryConfig(AdapterConfig):
max_staleness: Optional[str] = None
enable_list_inference: Optional[bool] = None
intermediate_format: Optional[str] = None
allow_non_incremental_definition: Optional[bool] = None


class BigQueryAdapter(BaseAdapter):
Expand Down
10 changes: 9 additions & 1 deletion dbt/adapters/bigquery/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,16 @@ def materialized_view_config_changeset(
new_materialized_view = cls.materialized_view_from_relation_config(relation_config)

if new_materialized_view.options != existing_materialized_view.options:
# allow_non_incremental_definition cannot be changed via ALTER, must recreate
if (
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
new_materialized_view.options.allow_non_incremental_definition
== existing_materialized_view.options.allow_non_incremental_definition
):
action = RelationConfigChangeAction.alter
else:
action = RelationConfigChangeAction.create
config_change_collection.options = BigQueryOptionsConfigChange(
action=RelationConfigChangeAction.alter,
action=action,
context=new_materialized_view.options,
)

Expand Down
14 changes: 12 additions & 2 deletions dbt/adapters/bigquery/relation_configs/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from dbt.adapters.bigquery.relation_configs._base import BigQueryBaseRelationConfig
from dbt.adapters.bigquery.utility import bool_setting, float_setting, sql_escape
from dbt.adapters.relation_configs import RelationConfigChangeAction


@dataclass(frozen=True, eq=True, unsafe_hash=True)
Expand All @@ -22,6 +23,7 @@ class BigQueryOptionsConfig(BigQueryBaseRelationConfig):
refresh_interval_minutes: Optional[float] = 30
expiration_timestamp: Optional[datetime] = None
max_staleness: Optional[str] = None
allow_non_incremental_definition: Optional[bool] = False
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
kms_key_name: Optional[str] = None
description: Optional[str] = None
labels: Optional[Dict[str, str]] = None
Expand Down Expand Up @@ -58,6 +60,7 @@ def array(x):
"refresh_interval_minutes": numeric,
"expiration_timestamp": interval,
"max_staleness": interval,
"allow_non_incremental_definition": boolean,
"kms_key_name": string,
"description": escaped_string,
"labels": array,
Expand Down Expand Up @@ -85,6 +88,7 @@ def from_dict(cls, config_dict: Dict[str, Any]) -> Self:
"refresh_interval_minutes": float_setting,
"expiration_timestamp": None,
"max_staleness": None,
"allow_non_incremental_definition": bool_setting,
"kms_key_name": None,
"description": None,
"labels": None,
Expand Down Expand Up @@ -115,6 +119,7 @@ def parse_relation_config(cls, relation_config: RelationConfig) -> Dict[str, Any
"refresh_interval_minutes",
"expiration_timestamp",
"max_staleness",
"allow_non_incremental_definition",
"kms_key_name",
"description",
"labels",
Expand All @@ -139,7 +144,12 @@ def parse_bq_table(cls, table: BigQueryTable) -> Dict[str, Any]:
"enable_refresh": table.mview_enable_refresh,
"refresh_interval_minutes": table.mview_refresh_interval.seconds / 60,
"expiration_timestamp": table.expires,
"max_staleness": None,
"max_staleness": (
f"INTERVAL '{table._properties.get('maxStaleness')}' YEAR TO SECOND"
if table._properties.get('maxStaleness')
else None
),
"allow_non_incremental_definition": table._properties.get("materializedView", {}).get("allowNonIncrementalDefinition"),
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
"description": table.description,
}

Expand All @@ -158,4 +168,4 @@ class BigQueryOptionsConfigChange(RelationConfigChange):

@property
def requires_full_refresh(self) -> bool:
return False
return self.action != RelationConfigChangeAction.alter
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
cluster_by=["id", "value"],
enable_refresh=True,
refresh_interval_minutes=60,
max_staleness="INTERVAL 45 MINUTE"
max_staleness="INTERVAL 45 MINUTE",
allow_non_incremental_definition=True
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
) }}
select
id,
Expand Down
Loading