首页 > 解决方案 > 使用 DBT 创建 Join 查询,但结果省略了一些列

问题描述

我有以下代码使用右连接将我的数据从表 1 连接到表 2。DBT 成功编译代码而没有错误,但我没有得到我需要的列...

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

with incremental_salesorder as (
  select * from {{ source('db_warehouse', 'sale_order_line') }} 
),

final as (
  select 
    distinct incremental_salesorder.product_code_cust, 
    incremental_salesorder.order_id as id,
    incremental_salesorder.create_date, 
    incremental_salesorder.name as product_name, 
    incremental_salesorder.product_name_cust, 
    sale_order.name as sale_order_ref
  from incremental_salesorder 
  right join {{ source('db_warehouse', 'sale_order')}} using (id)
  ORDER BY incremental_salesorder.create_date
)

{% if is_incremental() %}
  where incremental_salesorder.create_date >= (select max(create_date) from {{ this }} )

{% endif %}

select * from final

incremental_salesorder.order_idincremental_salesorder.name没有在代码编译成功后的结果中

在此处输入图像描述

我在这里做错了什么......?

标签: sqljinja2dbt

解决方案


菜鸟错误:

确保定义的模型名称相同:

models:
    dbt_test:
      # Applies to all files under models/example/
        example:
            materialized: view
            +schema: staging
            +enabled: false
        sales_order_unique_incremental: <- this line must match the folder name
            materialized: table
            +schema: datastudio

在此处输入图像描述

我完全错过了警告。一旦这被纠正,我就能够编译查询并得到我需要的结果。如果有人需要如何进行连接的示例,这是一种工作方法:)


推荐阅读