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

Add a fast-path option for loading dbt's seed files via a DuckDB COPY operation #169

Merged
merged 3 commits into from
May 21, 2023
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
4 changes: 4 additions & 0 deletions dbt/adapters/duckdb/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def convert_datetimes_to_strs(self, table: agate.Table) -> agate.Table:
)
return table

@available
def get_seed_file_path(self, model) -> str:
return os.path.join(model["root_path"], model["original_file_path"])

@available
def location_exists(self, location: str) -> bool:
try:
Expand Down
9 changes: 9 additions & 0 deletions dbt/include/duckdb/macros/seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
{% endmacro %}

{% macro duckdb__load_csv_rows(model, agate_table) %}
{% if config.get('fast') %}
{% set seed_file_path = adapter.get_seed_file_path(model) %}
{% set sql %}
COPY {{ this.render() }} FROM '{{ seed_file_path }}' (FORMAT CSV, HEADER TRUE)
{% endset %}
{% do adapter.add_query(sql, abridge_sql_log=True) %}
{{ return(sql) }}
{% endif %}

{% set batch_size = get_batch_size() %}
{% set agate_table = adapter.convert_datetimes_to_strs(agate_table) %}
{% set cols_sql = get_seed_column_quoted_csv(model, agate_table.column_names) %}
Expand Down
17 changes: 17 additions & 0 deletions tests/functional/adapter/simple_seed/test_fast_seed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

from dbt.tests.adapter.simple_seed.test_seed import SeedTestBase
from dbt.tests.util import (
run_dbt,
)

class TestSeedConfigFast(SeedTestBase):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"seeds": {"quote_columns": False, "fast": True}
}

def test_simple_seed_fast(self, project):
self._build_relations_for_test(project)
self._check_relation_end_state(run_result=run_dbt(["seed"]), project=project, exists=True)
16 changes: 0 additions & 16 deletions tests/functional/adapter/simple_seed/test_simple_seed.py

This file was deleted.