Skip to content

Commit

Permalink
Merge pull request duckdb#440 from duckdb/jwills_110_updates
Browse files Browse the repository at this point in the history
Fixes to dbt-duckdb to work with DuckDB 1.1.0
  • Loading branch information
jwills authored Sep 9, 2024
2 parents 0bd8a90 + 5082d28 commit b9c46e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion dbt/include/duckdb/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ def materialize(df, con):
if pyarrow_available and isinstance(df, pyarrow.Table):
# https://github.com/duckdb/duckdb/issues/6584
import pyarrow.dataset
con.execute('create table {{ relation }} as select * from df')
tmp_name = '__dbt_python_model_df_' + '{{ relation.identifier }}'
con.register(tmp_name, df)
con.execute('create table {{ relation }} as select * from ' + tmp_name)
con.unregister(tmp_name)
{% endmacro %}

{% macro duckdb__create_view_as(relation, sql) -%}
Expand Down
11 changes: 10 additions & 1 deletion dbt/include/duckdb/macros/utils/datediff.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{% macro duckdb__datediff(first_date, second_date, datepart) -%}
date_diff('{{ datepart }}', {{ first_date }}::timestamp, {{ second_date}}::timestamp )
{% if datepart == 'week' %}
({{ datediff(first_date, second_date, 'day') }} // 7 + case
when date_part('dow', ({{first_date}})::timestamp) <= date_part('dow', ({{second_date}})::timestamp) then
case when {{first_date}} <= {{second_date}} then 0 else -1 end
else
case when {{first_date}} <= {{second_date}} then 1 else 0 end
end)
{% else %}
(date_diff('{{ datepart }}', {{ first_date }}::timestamp, {{ second_date}}::timestamp ))
{% endif %}
{%- endmacro %}

0 comments on commit b9c46e4

Please sign in to comment.