microsoft / dbt-synapse

dbt adapter for Azure Synapse Dedicated SQL Pools
https://dbt-msft.github.io/dbt-msft-docs/docs/dbt-synapse/overview
MIT License
70 stars 32 forks source link

Incorrect syntax near 'column' error renaming a Column with on_schema_change='sync_all_columns' #111

Closed AdamG30 closed 2 years ago

AdamG30 commented 2 years ago

Hi.

I'm running some test cases evaluating dbt using the Synapse provider. I came across this error when adding a new column:

Test Case - Rename Column

Model

{{ config(materialized='incremental'
, index='clustered index(OLDACNUM)'
, dist='REPLICATE'
, on_schema_change='sync_all_columns' )    }}

SELECT TOP (1000) 
      [RecordCreateRunId]
      ,[DEBTORNUM]
      ,[OLDACNUM]
      ,[CREDCOLACTION]
      ,[LASTSTMTDATE]
      ,[CUST_TYPE] AS CustomerType
      ,[LETTERDATE]
      ,[CHARGE_CODE]
      ,[NUM_REMINDERS]
      ,[PAYMENT_CODE]
      ,[CYCLE_GROUP]
      ,ODS_START_DATE
      ,1 AS NEW_COLUMN    
FROM [DBO].[DEBTOR]
{% if is_incremental() %}
  -- this filter will only be applied on an incremental run
  WHERE ODS_START_DATE > (select max(ODS_START_DATE) from {{ this }})
{% endif %}

Incremental Run

Generated Code from Log


Incremental update 

...

05:14:39.102035 [debug] [Thread-1 (]: SQLServer adapter: SQL status: OK in 0.04 seconds
05:14:39.120042 [debug] [Thread-1 (]: 
    In "DBNAME"."DBT"."STG_DEBTORS_NEW":
        Schema changed: True
        Source columns not in target: [<Column CustomerType (character varying(2))>]
        Target columns not in source: [<Column CUST_TYPE (character varying(2))>]
        New column types: []

...

    alter table "DBNAME"."DBT"."STG_DEBTORS_NEW"

               add column CustomerType character varying(2)
            ,

                drop column CUST_TYPE

Outcome

I would suggest a fix, but I couldn't find an SQL server or synapse macro specifically for "rename column" is this just defaulting to the default provider? Happy to submit a PR if someone can point me in the right direction.

Versions dbt=1=1=2, sqlserver=1.1.0, synapse=1.1.0

sdebruyn commented 2 years ago

Duplicate of #110