microsoft / dbt-fabric

MIT License
79 stars 28 forks source link

Datetime2 error when materializing as table/incremental #123

Closed dbtFabricator closed 9 months ago

dbtFabricator commented 9 months ago

Hi.

Currently I have an issue when trying to materialize a table based on a column with the datatype datetime2. If the column is removed the code runs. This is only via dbt build in dbt cloud, i.e. when materializing it as a table - if I run it via preview/directly in a Fabric warehouse I get no error at all. Materializing it as a view works as intended. I've been in touch with the dbt support/engineers and they said they get the same issue with datetime2 when testing internally against fabric warehouse.

    select 
        cast("gLAccountNo" as varchar(20)) as glaccountno,
        cast("postingDate" as date) as postingdate,
        cast("documentNo" as varchar(20)) as documentno,
        cast("amount" as decimal(20, 5)) as amount,
        cast("globalDimension1Code" as varchar(20)) as globaldimension1code,
        cast("globalDimension2Code" as varchar(20)) as globaldimension2code,
        cast("sourceCode" as varchar(10)) as sourcecode,
        cast("journalBatchName" as varchar(10)) as journalbatchname,
        cast("debitAmount" as decimal(20, 5)) as debitamount,
        cast("creditAmount" as decimal(20, 5)) as creditamount,
        cast("sourceNo" as varchar(20)) as sourceno,
        cast("entryNo" as int) as entryno,
        cast("dimensionSetID" as int) as dimensionsetid,
        cast("documentType" as varchar(20)) as documenttype,

        cast("systemModifiedAt" as datetime2) as systemmodifiedat,

        cast("companyNo" as int) as companyno
      from  {{ source('bco', 'GLEntry') }}

console_log_dbt_run.txt

dbtFabricator commented 9 months ago

I realized only datetime2 with 6 digits of precision was supported. I resolved it by using datetime2(6) as datetype.

https://learn.microsoft.com/en-us/fabric/data-warehouse/data-types