Skip to content

Commit

Permalink
use "direct" write for non-partitioned python model materializations (#…
Browse files Browse the repository at this point in the history
…1388)

* use dynamic schema in test_grant_access_to.py

* use dynamic schema in test_grant_access_to.py

* revert setup

* use "direct" write for non-partitioned python model materializations

* add changie log

* add code comment

* make code comment inline

* make code comment inline

* remove code comment

* use set write_method instead of inline conditional

* use set write_method instead of inline conditional
  • Loading branch information
colin-rogers-dbt authored Oct 29, 2024
1 parent 79fbd90 commit a09a8fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20241028-172719.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: use "direct" write for non-partitioned python model materializations
time: 2024-10-28T17:27:19.306348-07:00
custom:
Author: colin-rogers-dbt
Issue: "1318"
11 changes: 10 additions & 1 deletion dbt/include/bigquery/macros/materializations/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,19 @@ else:
msg = f"{type(df)} is not a supported type for dbt Python materialization"
raise Exception(msg)

# For writeMethod we need to use "indirect" if materializing a partitioned table
# otherwise we can use "direct". Note that indirect will fail if the GCS bucket has a retention policy set on it.
{%- if partition_config %}
{%- set write_method = 'indirect' -%}
{%- else %}
{% set write_method = 'direct' -%}
{%- endif %}

df.write \
.mode("overwrite") \
.format("bigquery") \
.option("writeMethod", "indirect").option("writeDisposition", 'WRITE_TRUNCATE') \
.option("writeMethod", "{{ write_method }}") \
.option("writeDisposition", 'WRITE_TRUNCATE') \
{%- if partition_config is not none %}
{%- if partition_config.data_type | lower in ('date','timestamp','datetime') %}
.option("partitionField", "{{- partition_config.field -}}") \
Expand Down

0 comments on commit a09a8fa

Please sign in to comment.