Skip to content

Commit

Permalink
Merge branch 'main' into fix/224/distkey-error-message
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare authored Aug 7, 2023
2 parents 137c72b + 73dfc82 commit 0e3dc8b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20230803-111146.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Support DISTSTYLE for seeds
time: 2023-08-03T11:11:46.571996-06:00
custom:
Author: WillAyd
Issue: "255"
24 changes: 24 additions & 0 deletions dbt/include/redshift/macros/materializations/seeds/helpers.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
{% macro redshift__create_csv_table(model, agate_table) %}
{%- set column_override = model['config'].get('column_types', {}) -%}
{%- set quote_seed_column = model['config'].get('quote_columns', None) -%}
{%- set _dist = model['config'].get('dist', None) -%}

{% set sql %}
create table {{ this.render() }} (
{%- for col_name in agate_table.column_names -%}
{%- set inferred_type = adapter.convert_type(agate_table, loop.index0) -%}
{%- set type = column_override.get(col_name, inferred_type) -%}
{%- set column_name = (col_name | string) -%}
{{ adapter.quote_seed_column(column_name, quote_seed_column) }} {{ type }} {%- if not loop.last -%}, {%- endif -%}
{%- endfor -%}
)
{{ dist(_dist) }}
{% endset %}

{% call statement('_') -%}
{{ sql }}
{%- endcall %}

{{ return(sql) }}
{% endmacro %}

{% macro redshift__get_batch_size() %}
{{ return(500) }}
{% endmacro %}
38 changes: 38 additions & 0 deletions tests/functional/adapter/test_simple_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@
""".lstrip()


properties__schema_yml = """
version: 2
seeds:
- name: seed_dist_all
config:
dist: all
"""


seeds__dist_all_csv = """
seed_id,weekday
1,Saturday
2,Sunday
3,Monday
""".lstrip()


class TestSimpleSeedColumnOverride(BaseSimpleSeedColumnOverride):
@pytest.fixture(scope="class")
def schema(self):
Expand Down Expand Up @@ -82,3 +100,23 @@ def test_redshift_simple_seed_with_column_override_redshift(self, project):
assert len(seed_results) == 2
test_results = run_dbt(["test"])
assert len(test_results) == 10


class BaseSimpleSeedDiststyleAll:
@pytest.fixture(scope="class")
def models(self):
return {
"schema.yml": properties__schema_yml,
}

@pytest.fixture(scope="class")
def seeds(self):
return {"seed_dist_all.csv": seeds__dist_all_csv}

def test_simple_seed_with_diststyle_all(self, project):
seed_results = run_dbt(["seed", "--show"])
assert len(seed_results) == 1


class TestSimpleSeedDiststyleAll(BaseSimpleSeedDiststyleAll):
pass

0 comments on commit 0e3dc8b

Please sign in to comment.