dbt-labs / dbt-external-tables

dbt macros to stage external sources
https://hub.getdbt.com/dbt-labs/dbt_external_tables/latest/
Apache License 2.0
314 stars 123 forks source link

Copy into functionality through dbt cloud #319

Open Mounika982 opened 2 months ago

Mounika982 commented 2 months ago

I'm reaching out for @joellabes assistance with an issue we're experiencing with dbt and Snowflake. We are attempting to use the Snowflake COPY command in dbt to load data from named stage files and have encountered the following scenarios:

      Could you please provide guidance on how to adapt the queries being sent from dbt to Snowflake to avoid data duplication? We'd appreciate any assistance or recommendations you can offer to resolve this issue. Below is the code used for loading the data from named stage to a target table. Macro : {% macro copy_files(stage_name, target_schema,table_name, pattern) %}
COPY INTO {{ target_schema }}.{{ table_name }} FROM @{{ stage_name }} pattern = '{{ pattern }}' FILE_FORMAT = (FORMAT_NAME= 'my_csv_format',error_on_column_count_mismatch=false) MATCH_BY_COLUMN_NAME = CASE_INSENSITIVE force=false;

{% endmacro %}

sql:

{{ config( materialized= 'table', or 'incremental' target_table = 'active_teller_accounttypes_full',

    pre_hook= [

        "{{ copy_files('dm_db.edw_stage.active_teller', 
        'dm_db.dbt_anbtx',
        'active_teller_accounttypes_full', 
         '.*ACTIVE_TELLER_ACCOUNTTYPES_.*\.csv') }}"
    ]
)

}}

select * from {{this}}