Skip to content

Commit

Permalink
Don't apply require_partition_filter to a temporary table (#65)
Browse files Browse the repository at this point in the history
* Don't apply `require_partition_filter` to a temporary table

* Correct the partition_expiration_days option

* Update CHANGELOG.md

* Move up changelog entry, add contributor

Co-authored-by: Jeremy Cohen <[email protected]>
  • Loading branch information
yu-iskw and jtcohen6 authored Nov 19, 2021
1 parent 7e496af commit 69f5cbf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
### Features
- Add optional `scopes` profile configuration argument to reduce the BigQuery OAuth scopes down to the minimal set needed. ([#23](https://github.com/dbt-labs/dbt-bigquery/issues/23), [#63](https://github.com/dbt-labs/dbt-bigquery/pull/63))

### Fixes
- Don't apply `require_partition_filter` to temporary tables, thereby fixing `insert_overwrite` strategy when partition filter is required ([#64](https://github.com/dbt-labs/dbt-bigquery/issues/64)), ([#65](https://github.com/dbt-labs/dbt-bigquery/pull/65))

### Under the hood
- Adding `execution_project` to `target` object ([#66](https://github.com/dbt-labs/dbt-bigquery/issues/66))

### Contributors
- [@pgoslatara](https://github.com/pgoslatara) ([#66](https://github.com/dbt-labs/dbt-bigquery/issues/66))
- [@bborysenko](https://github.com/bborysenko) ([#63](https://github.com/dbt-labs/dbt-bigquery/pull/63))
- [@yu-iskw](https://github.com/yu-iskw) ([#65](https://github.com/dbt-labs/dbt-bigquery/pull/65))

## dbt-bigquery 1.0.0rc1 (November 10, 2021)

Expand Down
24 changes: 13 additions & 11 deletions dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,20 +757,22 @@ def get_table_options(
) -> Dict[str, Any]:
opts = self.get_common_options(config, node, temporary)

if temporary:
expiration = 'TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 12 hour)'
opts['expiration_timestamp'] = expiration

if config.get('kms_key_name') is not None:
opts['kms_key_name'] = "'{}'".format(config.get('kms_key_name'))

if config.get('require_partition_filter'):
opts['require_partition_filter'] = config.get(
'require_partition_filter')

if config.get('partition_expiration_days') is not None:
opts['partition_expiration_days'] = config.get(
'partition_expiration_days')
if temporary:
expiration = 'TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 12 hour)'
opts['expiration_timestamp'] = expiration
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
# in the incremental model.
if config.get('require_partition_filter') is not None:
opts['require_partition_filter'] = config.get(
'require_partition_filter')
if config.get('partition_expiration_days') is not None:
opts['partition_expiration_days'] = config.get(
'partition_expiration_days')

return opts

Expand Down

0 comments on commit 69f5cbf

Please sign in to comment.