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

Feature/customize timestamp expiration #806

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Make expiration of temp table dynamic, based on model timeout.
time: 2025-02-09T12:37:50.314467072+01:00
custom:
Author: gjskibinski
Issue: "805"
7 changes: 6 additions & 1 deletion dbt-bigquery/src/dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ class BigQueryAdapter(BaseAdapter):
def __init__(self, config, mp_context: SpawnContext) -> None:
super().__init__(config, mp_context)
self.connections: BigQueryConnectionManager = self.connections
self.job_execution_timeout_seconds: int = int(
self.config.credentials.job_execution_timeout_seconds or 60 * 60 * 12
)

###
# Implementations of abstract methods
Expand Down Expand Up @@ -774,7 +777,9 @@ def get_table_options(
opts["kms_key_name"] = f"'{config.get('kms_key_name')}'"

if temporary:
opts["expiration_timestamp"] = "TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 12 hour)"
opts["expiration_timestamp"] = (
f"TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL {self.job_execution_timeout_seconds} second)"
)
else:
# It doesn't apply the `require_partition_filter` option for a temporary table
# so that we avoid the error by not specifying a partition with a temporary table
Expand Down
4 changes: 2 additions & 2 deletions dbt-bigquery/tests/unit/test_bigquery_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,14 +775,14 @@ def test_hours_to_expiration(self):
actual = adapter.get_table_options(mock_config, node={}, temporary=False)
self.assertEqual(expected, actual)

def test_hours_to_expiration_temporary(self):
def test_seconds_to_expiration_temporary(self):
adapter = self.get_adapter("oauth")
mock_config = create_autospec(RuntimeConfigObject)
config = {"hours_to_expiration": 4}
mock_config.get.side_effect = lambda name: config.get(name)

expected = {
"expiration_timestamp": ("TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 12 hour)"),
"expiration_timestamp": ("TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 43200 second)"),
}
actual = adapter.get_table_options(mock_config, node={}, temporary=True)
self.assertEqual(expected, actual)
Expand Down
Loading