Skip to content

Commit

Permalink
infer type from location, default to parquet if not set
Browse files Browse the repository at this point in the history
  • Loading branch information
Arno Roos authored and Arno Roos committed Oct 17, 2024
1 parent 1a5155a commit 1cf821e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion dbt/include/duckdb/macros/materializations/external.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@

{%- set location = render(config.get('location', default=external_location(this, config))) -%})
{%- set rendered_options = render_write_options(config) -%}
{%- set format = config.get('format', 'parquet') -%}

{%- set format = config.get('format') -%}
{%- set allowed_formats = ['csv', 'parquet', 'json'] -%}

{%- if format -%}
{%- set format = format if format in allowed_formats else 'parquet' -%}
{%- else -%}
{%- set format = location.split('.')[-1] if '.' in location else 'parquet' -%}
{%- set format = format if format in allowed_formats else 'parquet' -%}
{%- endif -%}

{%- set write_options = adapter.external_write_options(location, rendered_options) -%}
{%- set read_location = adapter.external_read_location(location, rendered_options) -%}
{%- set parquet_read_options = config.get('parquet_read_options', {'union_by_name': False}) -%}
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/adapter/test_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"""

config_materialized_parquet_location = """
{{ config(materialized="external", location="{{ adapter.external_root() }}/test.parquet", format="parquet") }}
{{ config(materialized="external", location="{{ adapter.external_root() }}/test.parquet") }}
"""

config_materialized_csv_location_delim = """
{{ config(materialized="external", location="{{ adapter.external_root() }}/test_delim.csv", delimiter="|", format="csv") }}
{{ config(materialized="external", location="{{ adapter.external_root() }}/test_delim.csv", delimiter="|") }}
"""

config_json = """
Expand Down

0 comments on commit 1cf821e

Please sign in to comment.