标签:ase dma osi efault 创建 mode material height project
dbt 包含一个自己的包管理,可以使用git 等工具,还是很方便的,可以方便的进行代码共享,实现复用
实际上就是一个简单的dbt 项目,参考项目 https://gitlab.com/dalongrong/dbt-gitlab-demo
dbt init gitlab-demo
get_versions_schema.sql:
{% macro get_versions_schema() -%}
{%- set defaultname =demo -%}
dalongdemo
{%- endmacro %}
gitlab_projectinfo_info.sql:
{% macro gitlab_projectinfo_info() -%}
projects
{%- endmacro %}
创建方式同上,就是一个包地址的配置,以及调用,参考项目 https://gitlab.com/dalongrong/dbt-package-demo
dbt init package-demo
主要是名称,以及版本信息,可以直接使用默认的,但是建议按照有意义的名称命名
dbt_project.yml文件:
name: ‘packageapp‘
version: ‘1.0‘
profile: ‘demo‘
source-paths: ["models"]
analysis-paths: ["analysis"]
test-paths: ["tests"]
data-paths: ["data"]
macro-paths: ["macros"]
target-path: "target" # directory which will store compiled SQL files
clean-targets: # directories to be removed by `dbt clean`
- "target"
- "dbt_modules"
models:
packageapp:
base:
materialized: view
dbt_project.yml 文件:
name: ‘packageapp‘
version: ‘1.0‘
profile: ‘demo‘
source-paths: ["models"]
analysis-paths: ["analysis"]
test-paths: ["tests"]
data-paths: ["data"]
macro-paths: ["macros"]
target-path: "target" # directory which will store compiled SQL files
clean-targets: # directories to be removed by `dbt clean`
- "target"
- "dbt_modules"
repositories:
- https://gitlab.com/dalongrong/dbt-gitlab-demo.git
models:
packageapp:
base:
materialized: view
主要是调用包的macro
models/packageapp/base/packageapp_projectinfo.sql:
{{ config(materialized=‘view‘) }}
select * from {{ref(gitlab.gitlab_projectinfo_info())}} # 使用ref 进行包macro 的引用,使用使用ref 的方式调用,保证依赖顺序
dbt deps
dbt run && dbt docs generate && dbt docs serve
对于profile 的配置,上面没有写,参考基本配置就可以了,数据库可以直接使用项目中的docker-compose 运行即可
https://gitlab.com/dalongrong/dbt-package-demo
https://gitlab.com/dalongrong/dbt-gitlab-demo
https://docs.getdbt.com/docs/macros
https://docs.getdbt.com/docs/building-packages
https://docs.getdbt.com/docs/package-management
标签:ase dma osi efault 创建 mode material height project
原文地址:https://www.cnblogs.com/rongfengliang/p/9830214.html