【问题标题】:Using DBT to create Join queries, but result omits some columns使用 DBT 创建 Join 查询,但结果省略了一些列
【发布时间】:2021-07-20 12:08:37
【问题描述】:

我有以下代码,它使用右连接将我的数据从表 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不在结果中

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

【问题讨论】:

  • 您之前是否有可能在没有这些列的情况下运行它并且没有使用 --full-refresh 标志重新运行? docs.getdbt.com/reference/commands/…
  • @dylanbaker 我解决了!我重命名了模型,但没有用新名称更新 dbt_project.yml 文件,因此整个查询根本没有运行,菜鸟错误!

标签: sql jinja2 dbt


【解决方案1】:

菜鸟失误:

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

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

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

【讨论】:

    猜你喜欢
    • 2022-01-16
    • 2020-08-23
    • 1970-01-01
    • 2015-02-07
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 2019-09-19
    相关资源
    最近更新 更多