duckdb / dbt-duckdb

dbt (http://getdbt.com) adapter for DuckDB (http://duckdb.org)
Apache License 2.0
790 stars 70 forks source link

Bug - Issue with dateadd since 1.7.2 and the update of `date_diff` #346

Closed b-per closed 4 months ago

b-per commented 4 months ago

The following model worked in <1.7.2 but fails in 1.7.2

{{
    config(
        materialized = 'table',
    )
}}

{% set date_expr = "current_date()" if target.type in ["duckdb"] else dbt.current_timestamp() %}
with days as (

    {{
        dbt_utils.date_spine(
            'day',
            date_expr,
            dbt.dateadd('day', 1, date_expr),
        )
    }}

),

final as (
    select cast(date_day as date) as date_day
    from days
)

select * from final

The error is

  Runtime Error in model spine (models/spine.sql)
    Binder Error: No function matches the given name and argument types '+(DATE, TIMESTAMP)'. You might need to add explicit type casts.
        Candidate functions:
        +(TINYINT) -> TINYINT
        +(TINYINT, TINYINT) -> TINYINT
        +(SMALLINT) -> SMALLINT
        +(SMALLINT, SMALLINT) -> SMALLINT
        +(INTEGER) -> INTEGER
        +(INTEGER, INTEGER) -> INTEGER
        +(BIGINT) -> BIGINT
        +(BIGINT, BIGINT) -> BIGINT
        +(HUGEINT) -> HUGEINT
        +(HUGEINT, HUGEINT) -> HUGEINT
        +(FLOAT) -> FLOAT
        +(FLOAT, FLOAT) -> FLOAT
        +(DOUBLE) -> DOUBLE
        +(DOUBLE, DOUBLE) -> DOUBLE
        +(DECIMAL) -> DECIMAL
        +(DECIMAL, DECIMAL) -> DECIMAL
        +(UTINYINT) -> UTINYINT
        +(UTINYINT, UTINYINT) -> UTINYINT
        +(USMALLINT) -> USMALLINT
        +(USMALLINT, USMALLINT) -> USMALLINT
        +(UINTEGER) -> UINTEGER
        +(UINTEGER, UINTEGER) -> UINTEGER
        +(UBIGINT) -> UBIGINT
        +(UBIGINT, UBIGINT) -> UBIGINT
        +(DATE, INTEGER) -> DATE
        +(INTEGER, DATE) -> DATE
        +(INTERVAL, INTERVAL) -> INTERVAL
        +(DATE, INTERVAL) -> DATE
        +(INTERVAL, DATE) -> DATE
        +(TIME, INTERVAL) -> TIME
        +(INTERVAL, TIME) -> TIME
        +(TIMESTAMP, INTERVAL) -> TIMESTAMP
        +(INTERVAL, TIMESTAMP) -> TIMESTAMP
        +(TIME, DATE) -> TIMESTAMP
        +(DATE, TIME) -> TIMESTAMP
        +(ANY[], ANY[]) -> ANY[]
        +(TIMESTAMP WITH TIME ZONE, INTERVAL) -> TIMESTAMP WITH TIME ZONE
        +(INTERVAL, TIMESTAMP WITH TIME ZONE) -> TIMESTAMP WITH TIME ZONE

    LINE 6:     current_date() + ((interval '1 day') * (1))

After some troubleshooting, it seems to be related to the update version of duckdb__datediff in 1.7.2

jwills commented 4 months ago

Ah I was worried about stuff like that-- the datediff macro has been causing me fits and with every duckdb upgrade and I was hoping to rip it out cleanly and quietly, no such luck. Thanks for finding it Benoit!