我正在设置一个新的 dbt 项目并尝试定义一个源,然后在下游模型中使用它。
这是我的
sources.yml
,位于models
文件夹下
version: 2
sources:
- name: raw
schema: my_schema
database: my_db
tables:
- name: my_table
description: my description
columns:
- name: op
description: desc
- name: id
description: id
......
在我的模型文件
my_downstream_table.sql
中,我输入了SQL:
{{ config(materialized='table', sort='...', dist='...') }}
SELECT
...
FROM
{{source('my_schema', 'my_table')}} p
......
在不引用源模型的情况下运行时,SQL 运行良好。
但是,参考源模型,当我通过运行
dbt compile
编译我的项目时,我收到错误:
6:10:14 Running with dbt=1.5.0
06:10:16 Encountered an error:
Compilation Error
Model 'model.myproj.my_downstream_table' (models/my_downstream_table.sql) depends on a source named 'my_schema.my_table' which was not found
我尝试将
sources.yml
放置在不同的位置或以不同的方式命名,但都失败并出现相同的错误。
这是我的
dbt_project.yml
,如果它有助于找出我的设置出了什么问题。
# Name your project! Project names should contain only lowercase characters
# and underscores. A good package name should reflect your organization's
# name or the intended use of these models
name: 'myproj'
version: '1.0.0'
config-version: 2
# This setting configures which "profile" dbt uses for this project.
profile: 'default'
# These configurations specify where dbt should look for different types of files.
# The `model-paths` config, for example, states that models in this project can be
# found in the "models/" directory. You probably won't need to change these!
model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]
target-path: "target" # directory which will store compiled SQL files
clean-targets: # directories to be removed by `dbt clean`
- "target"
- "dbt_packages"
# Configuring models
# Full documentation: https://docs.getdbt.com/docs/configuring-models
models:
myproj:
+materialized: table
source()
宏的第一个参数应该是源名称,而不是模式名称。
尝试:
{{ source('raw', 'my_table') }}