Skip to content

Commit

Permalink
feat: add duckdb macros in cross db utils
Browse files Browse the repository at this point in the history
  • Loading branch information
nhat.nguyent committed Oct 24, 2023
1 parent 5679782 commit 7e7d906
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion macros/utils/cross_db_utils/contains.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{ adapter.dispatch('contains', 'elementary') (string, string_to_search, case_sensitive) }}
{%- endmacro %}

{# Snowflake, Databricks #}
{# Snowflake, Databricks and DuckDB #}
{% macro default__contains(string, string_to_search, case_sensitive) %}
{%- if case_sensitive %}
contains({{ string }}, '{{ string_to_search }}')
Expand Down
2 changes: 1 addition & 1 deletion macros/utils/cross_db_utils/datediff.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{ return(adapter.dispatch('edr_datediff', 'elementary')(first_date, second_date, date_part)) }}
{% endmacro %}

{# For Snowflake, Databricks, Redshift, Postgres #}
{# For Snowflake, Databricks, Redshift, Postgres, DuckDB #}
{# the dbt adapter implementation supports both timestamp and dates #}
{% macro default__edr_datediff(first_date, second_date, date_part) %}
{% set macro = dbt.datediff or dbt_utils.datediff %}
Expand Down
4 changes: 4 additions & 0 deletions macros/utils/cross_db_utils/day_of_week.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@
0 , 'Sunday'
)
{% endmacro %}

{% macro duckdb__edr_day_of_week_expression(date_expr) %}
dayname({{ date_expr }})
{% endmacro %}
2 changes: 1 addition & 1 deletion macros/utils/cross_db_utils/get_profile_creation_query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ALTER DEFAULT PRIVILEGES IN SCHEMA {{ parameters["schema"] }} GRANT SELECT ON TA
{% endmacro %}


{# Databricks, BigQuery, Spark #}
{# Databricks, BigQuery, Spark, DuckDB #}
{% macro default__get_profile_creation_query(parameters) %}
{% do exceptions.raise_compiler_error('User creation not supported through sql using ' ~ target.type) %}
{% endmacro %}
4 changes: 4 additions & 0 deletions macros/utils/cross_db_utils/hour_of_day.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@
{% macro snowflake__edr_hour_of_day_expression(date_expr) %}
HOUR({{ date_expr }})
{% endmacro %}

{% macro duckdb__edr_hour_of_day_expression(date_expr) %}
EXTRACT('hour' FROM {{ date_expr }})
{% endmacro %}
4 changes: 4 additions & 0 deletions macros/utils/cross_db_utils/hour_of_week.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@
0 , 'Sunday'
) as {{ elementary.edr_type_string() }}), cast(HOUR({{ date_expr }}) as {{ elementary.edr_type_string() }}))
{% endmacro %}

{% macro duckdb__edr_hour_of_week_expression(date_expr) %}
concat(cast(dayname({{ date_expr }}) as {{ elementary.edr_type_string() }}), cast(EXTRACT('hour' FROM {{ date_expr }}) as {{ elementary.edr_type_string() }}))
{% endmacro %}
6 changes: 5 additions & 1 deletion macros/utils/cross_db_utils/to_char.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@

{% macro spark__edr_to_char(column, format) %}
date_format({{ column }} {%- if format %}, '{{ format }}'){%- else %}, 'YYYY-MM-DD HH:MI:SS'){%- endif %}
{% endmacro %}
{% endmacro %}

{% macro duckdb__edr_to_char(column, format) %}
strftime({{ column }} {%- if format %}, '{{ format }}'){%- else %}, 'YYYY-MM-DD HH:MI:SS'){%- endif %}
{% endmacro %}

0 comments on commit 7e7d906

Please sign in to comment.