dbt_utils union_relations column_override not working

huangapple go评论68阅读模式
英文:

dbt_utils union_relations column_override not working

问题

{{ dbt_utils.union_relations(
    relations=[
        ref('base_consumer_digital_ad_performance_apple_ads_spend'), 
        ref('base_consumer_digital_ad_performance_facebook_spend'),  
        ref('base_consumer_digital_ad_performance_tiktok_spend'), 
        ref('base_consumer_digital_ad_performance_google_spend')
    ],
    column_override={"digital_campaign_id": "TEXT"}
) }}

I am trying to use the column_override arg in the dbt_utils union_relations macro, but it doesn't seem to work when my code compiles.

(
select
cast('DBT_CCARREL.staging.base_consumer_digital_ad_performance_apple_ads_spend' as TEXT) as _dbt_source_relation,

    cast("AD_DATE" as DATE) as "AD_DATE",
    cast("ACQUISITION_PARTNER" as character varying(9)) as "ACQUISITION_PARTNER",
    cast("DIGITAL_CAMPAIGN_ID" as NUMBER(38,0)) as "DIGITAL_CAMPAIGN_ID",
    cast("DIGITAL_ADSET_ID" as NUMBER(38,0)) as "DIGITAL_ADSET_ID",
    cast("DIGITAL_AD_ID" as NUMBER(38,0)) as "DIGITAL_AD_ID",
    cast("IMPRESSIONS" as NUMBER(38,0)) as "IMPRESSIONS",
    cast("CLICKS" as NUMBER(38,0)) as "CLICKS",
    cast("SPEND" as NUMBER(18,4)) as "SPEND",
    cast("AD_PERFORMANCE_UUID" as character varying(32)) as "AD_PERFORMANCE_UUID"

from DBT_CCARREL.staging.base_consumer_digital_ad_performance_apple_ads_spend

)
union all

Would love some help to understand what I am missing.


<details>
<summary>英文:</summary>

    {{ dbt_utils.union_relations(
        relations=[
            ref(&#39;base_consumer_digital_ad_performance_apple_ads_spend&#39;), 
            ref(&#39;base_consumer_digital_ad_performance_facebook_spend&#39;),  
            ref(&#39;base_consumer_digital_ad_performance_tiktok_spend&#39;), 
            ref(&#39;base_consumer_digital_ad_performance_google_spend&#39;)
            ],
        column_override={&quot;digital_campaign_id&quot;:&quot;TEXT&quot;}
    ) }}


I am trying to use the `column_override` arg in the dbt_utils `union_relations` macro, but it doesn&#39;t seem to work when my code compiles. 

    (
                select
                    cast(&#39;DBT_CCARREL.staging.base_consumer_digital_ad_performance_apple_ads_spend&#39; as TEXT) as _dbt_source_relation,
    
                    
                        cast(&quot;AD_DATE&quot; as DATE) as &quot;AD_DATE&quot; ,
                        cast(&quot;ACQUISITION_PARTNER&quot; as character varying(9)) as &quot;ACQUISITION_PARTNER&quot; ,
                        cast(&quot;DIGITAL_CAMPAIGN_ID&quot; as NUMBER(38,0)) as &quot;DIGITAL_CAMPAIGN_ID&quot; ,
                        cast(&quot;DIGITAL_ADSET_ID&quot; as NUMBER(38,0)) as &quot;DIGITAL_ADSET_ID&quot; ,
                        cast(&quot;DIGITAL_AD_ID&quot; as NUMBER(38,0)) as &quot;DIGITAL_AD_ID&quot; ,
                        cast(&quot;IMPRESSIONS&quot; as NUMBER(38,0)) as &quot;IMPRESSIONS&quot; ,
                        cast(&quot;CLICKS&quot; as NUMBER(38,0)) as &quot;CLICKS&quot; ,
                        cast(&quot;SPEND&quot; as NUMBER(18,4)) as &quot;SPEND&quot; ,
                        cast(&quot;AD_PERFORMANCE_UUID&quot; as character varying(32)) as &quot;AD_PERFORMANCE_UUID&quot; 
    
                from DBT_CCARREL.staging.base_consumer_digital_ad_performance_apple_ads_spend
    
                
            )
    
            union all

Would love some help to understand what I am missing. 

</details>


# 答案1
**得分**: 0

从[源代码][1]中,我认为`column_override`是区分大小写的(因为在Python和Jinja中,字典访问是区分大小写的)。所以这应该可以工作:

```python
{{ dbt_utils.union_relations(
    relations=[
        ref('base_consumer_digital_ad_performance_apple_ads_spend'),
        ref('base_consumer_digital_ad_performance_facebook_spend'),
        ref('base_consumer_digital_ad_performance_tiktok_spend'),
        ref('base_consumer_digital_ad_performance_google_spend')
    ],
    column_override={"DIGITAL_CAMPAIGN_ID": "TEXT"}
) }}
英文:

From the source, I think column_override is case-sensitve (since in Python and Jinja, dictionary access is case-sensitive). So this should work:

{{ dbt_utils.union_relations(
    relations=[
        ref(&#39;base_consumer_digital_ad_performance_apple_ads_spend&#39;), 
        ref(&#39;base_consumer_digital_ad_performance_facebook_spend&#39;),  
        ref(&#39;base_consumer_digital_ad_performance_tiktok_spend&#39;), 
        ref(&#39;base_consumer_digital_ad_performance_google_spend&#39;)
        ],
    column_override={&quot;DIGITAL_CAMPAIGN_ID&quot;:&quot;TEXT&quot;}
) }}

huangapple
  • 本文由 发表于 2023年6月12日 21:14:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76457032.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定