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

Fix bigquery copy materialization #910

Merged
merged 5 commits into from
Oct 11, 2023
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230906-141819.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: 'Fix bigquery copy materialization #910'
time: 2023-09-06T14:18:19.445262+02:00
custom:
Author: m-sche
Issue: '#820'
dbeatty10 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion dbt/include/bigquery/macros/materializations/copy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{# cycle over ref() and source() to create source tables array #}
{% set source_array = [] %}
{% for ref_table in model.refs %}
{{ source_array.append(ref(*ref_table)) }}
{{ source_array.append(ref(ref_table.get('package'), ref_table.name, version=ref_table.get('version'))) }}
{% endfor %}

{% for src_table in model.sources %}
Expand Down
62 changes: 62 additions & 0 deletions tests/functional/adapter/test_copy_materialization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import pytest
from pathlib import Path
from dbt.tests.util import run_dbt, write_file, check_relations_equal

_SEED_A = """
load_date,id,first_name,last_name,email,gender,ip_address
2021-03-05,1,Jack,Hunter,[email protected],Male,59.80.20.168
2021-03-05,2,Kathryn,Walker,[email protected],Female,194.121.179.35
2021-03-05,3,Gerald,Ryan,[email protected],Male,11.3.212.243
""".lstrip()

_SEED_B = """
load_date,id,first_name,last_name,email,gender,ip_address
2021-03-05,4,Bonnie,Spencer,[email protected],Female,216.32.196.175
2021-03-05,5,Harold,Taylor,[email protected],Male,253.10.246.136
""".lstrip()

_EXPECTED_RESULT = """
load_date,id,first_name,last_name,email,gender,ip_address
2021-03-05,1,Jack,Hunter,[email protected],Male,59.80.20.168
2021-03-05,2,Kathryn,Walker,[email protected],Female,194.121.179.35
2021-03-05,3,Gerald,Ryan,[email protected],Male,11.3.212.243
2021-03-05,4,Bonnie,Spencer,[email protected],Female,216.32.196.175
2021-03-05,5,Harold,Taylor,[email protected],Male,253.10.246.136
""".lstrip()

_COPY_MODEL = """
{{ config(
materialized="copy",
copy_materialization="incremental",
) }}

SELECT * FROM {{ ref("seed") }}
"""


class BaseCopyModelConfig:
@pytest.fixture(scope="class")
def models(self):
return {"copy_model.sql": _COPY_MODEL}

@pytest.fixture(scope="class")
def seeds(self):
return {
"seed.csv": _SEED_A,
"expected_result.csv": _EXPECTED_RESULT,
}


class TestCopyMaterialization(BaseCopyModelConfig):
def test_incremental_copy(self, project):
run_dbt(["seed"])
run_dbt(["run"])

# Replace original seed _SEED_A with _SEED_B
seed_file = project.project_root / Path("seeds") / Path("seed.csv")
write_file(_SEED_B, seed_file)

run_dbt(["seed"])
run_dbt(["run"])

check_relations_equal(project.adapter, ["copy_model", "expected_result"])