Datavault stage model using datavault4dbt

hemanathgoud
Sat, 18 May 2024 10:25:15 +0000
Help

Hi All,
I am new to using data vault design using the automate_Dv and datavault4dbt packages.
I can able to create the data vault tables using the automate_dv package. while trying to create the data vault tables using the datavault4dbt package I am getting below error

Command failed

Compilation Error in model v_stg_clicks_conversions (models/advertisex_datavault/v_stg/v_stg_clicks_conversions.sql)
  The name argument to ref() must be a string, got <class 'dbt.clients.jinja.create_undefined.<locals>.Undefined'>

  > in macro snowflake__stage (macros/staging/snowflake/stage.sql)
  > called by macro stage (macros/staging/stage.sql)
  > called by model v_stg_clicks_conversions (models/advertisex_datavault/v_stg/v_stg_clicks_conversions.sql)

I don’t know exactly where I made the mistake.

Can someone help me to resolve this issue?
Below is the code that I tried based on the documentation provided by the datavault4dbt package.
By pointing the source table from the source_table.yml file.

    {{ config(materialized='view') }}

    {%- set yaml_metadata -%}
    source_model:
        'advertisex': 'clicks_conversions'
    hashed_columns:
        clicks_conversions_hk :
            - AD_CAMPAIGN_ID
        clicks_conversions_hashdiff:
            is_hashdiff: true
            columns:
                - id
                - user_id
                - ad_campaign_id
                - event_timestamp
                - conversion_type
                - load_date
    derived_columns:
        source:
            value: '!1'
            datatype: 'string'
        record_source:
            value: "'S3'"
            datatype: 'STRING'
        load_date:
            value: 'load_date'
            datatype: 'timestamp'

    {%- endset -%}

    {%- set metadata_dict = fromyaml(yaml_metadata) -%}

    {%- set source_model = metadata_dict.get('source_model') -%}
    {%- set hashed_columns = metadata_dict.get('hashed_columns') -%}
    {%- set derived_columns = metadata_dict.get('derived_columns') -%}

    {{ datavault4dbt.stage(include_source_columns=true,
        source_model=source_model,
                        hashed_columns=hashed_columns,
                        derived_columns=derived_columns) }}

I have also tried this code as well for creating the data vault tables using datavault4dbt
by pointing model name

    {{ config(materialized='view') }}

    {%- set yaml_metadata -%}
    source_model: 'raw_clicks_conversions'
    hashed_columns:
        clicks_conversions_hk :
            - AD_CAMPAIGN_ID
        clicks_conversions_hashdiff:
            is_hashdiff: true
            columns:
                - id
                - user_id
                - ad_campaign_id
                - event_timestamp
                - conversion_type
                - load_date
    derived_columns:
        source:
            value: '!1'
            datatype: 'string'
        record_source:
            value: "'S3'"
            datatype: 'STRING'
        load_date:
            value: 'load_date'
            datatype: 'timestamp'

    {%- endset -%}

    {%- set metadata_dict = fromyaml(yaml_metadata) -%}

    {%- set source_model = metadata_dict.get('source_model') -%}
    {%- set hashed_columns = metadata_dict.get('hashed_columns') -%}
    {%- set derived_columns = metadata_dict.get('derived_columns') -%}

    {{ datavault4dbt.stage(include_source_columns=true,
        source_model=source_model,
                        hashed_columns=hashed_columns,
                        derived_columns=derived_columns) }}

1 post - 1 participant