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

backport 1122 to 1.8.latest #1380

Merged
merged 2 commits into from
Oct 22, 2024
Merged
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240226-233024.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: make seed delimiter configurable via `field_delimeter` in model config
time: 2024-02-26T23:30:24.141213+01:00
custom:
Author: salimmoulouel
Issue: "1119"
6 changes: 4 additions & 2 deletions dbt/adapters/bigquery/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,9 @@ def alter_table_add_columns(self, relation, columns):
client.update_table(new_table, ["schema"])

@available.parse_none
def load_dataframe(self, database, schema, table_name, agate_table, column_override):
def load_dataframe(
self, database, schema, table_name, agate_table, column_override, field_delimiter
):
bq_schema = self._agate_to_schema(agate_table, column_override)
conn = self.connections.get_thread_connection()
client = conn.handle
Expand All @@ -664,7 +666,7 @@ def load_dataframe(self, database, schema, table_name, agate_table, column_overr
load_config = google.cloud.bigquery.LoadJobConfig()
load_config.skip_leading_rows = 1
load_config.schema = bq_schema

load_config.field_delimiter = field_delimiter
with open(agate_table.original_abspath, "rb") as f:
job = client.load_table_from_file(f, table_ref, rewind=True, job_config=load_config)

Expand Down
2 changes: 1 addition & 1 deletion dbt/include/bigquery/macros/materializations/seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

{%- set column_override = model['config'].get('column_types', {}) -%}
{{ adapter.load_dataframe(model['database'], model['schema'], model['alias'],
agate_table, column_override) }}
agate_table, column_override, model['config']['delimiter']) }}

{% call statement() %}
alter table {{ this.render() }} set {{ bigquery_table_options(config, model) }}
Expand Down
36 changes: 35 additions & 1 deletion tests/functional/adapter/test_simple_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from dbt.tests.adapter.simple_seed.test_seed import BaseTestEmptySeed
from dbt.tests.adapter.utils.base_utils import run_dbt


_SEED_CONFIGS_CSV = """
seed_id,stuff
1,a
Expand Down Expand Up @@ -156,3 +155,38 @@ def test__bigquery_seed_table_with_labels_config_bigquery(self, project):

class TestBigQueryEmptySeed(BaseTestEmptySeed):
pass


class TestBigQuerySeedWithUniqueDelimiter(TestSimpleSeedConfigs):
@pytest.fixture(scope="class")
def seeds(self):
return {
"seed_enabled.csv": seeds__enabled_in_config_csv.replace(",", "|"),
"seed_tricky.csv": seeds__tricky_csv.replace(",", "\t"),
"seed_configs.csv": _SEED_CONFIGS_CSV,
}

@pytest.fixture(scope="class")
def project_config_update(self):
return {
"config-version": 2,
"seeds": {
"test": {
"enabled": False,
"quote_columns": True,
"seed_enabled": {
"enabled": True,
"+column_types": self.seed_enabled_types(),
"delimiter": "|",
},
"seed_tricky": {
"enabled": True,
"+column_types": self.seed_tricky_types(),
"delimiter": "\t",
},
"seed_configs": {
"enabled": True,
},
},
},
}
Loading