dbt-server 简单说明

dbt-server 是dbt 团队对于dbt-rpc 调整之后开源的dbt api 服务,内部基于了dbt-core 提供的cli 编程调用能力

使用到的一些框架

  • fastapi 提供api 能力
  • dbt core 进行dbt 任务的执行
  • celery 基于celery 的任务调度(代码中的worker)

dbt core cli 调用

  • 参考代码
from dbt.cli.main import dbtRunner, dbtRunnerResult
 
# initialize
dbt = dbtRunner()
 
# create CLI args as a list of strings
cli_args = ["run", "--select", "tag:my_tag"]
 
# run the command
res: dbtRunnerResult = dbt.invoke(cli_args)
 
# inspect the results
for r in res.result:
    print(f"{r.node.name}: {r.status}")
  • 状态服用
    可以基于Manifest对象
 
from dbt.cli.main import dbtRunner, dbtRunnerResult
from dbt.contracts.graph.manifest import Manifest
 
# use 'parse' command to load a Manifest
res: dbtRunnerResult = dbtRunner().invoke(["parse"])
manifest: Manifest = res.result
 
# introspect manifest
# e.g. assert every public model has a description
for node in manifest.nodes.values():
    if node.resource_type == "model" and node.access == "public":
        assert node.description != "", f"{node.name} is missing a description"
 
# reuse this manifest in subsequent commands to skip parsing
dbt = dbtRunner(manifest=manifest)
cli_args = ["run", "--select", "tag:my_tag"]
res = dbt.invoke(cli_args)

当然dbt-core 还支持了回调,可以进行一些状态的维护处理

dbt cloud 参考架构

如下图,可以看到dbt cloud 的一些设计

 

说明

注意dbt-server license 许可是有一些限制的,但是因为是基于了dbt-core 提供的cli 能力,我们也可以很好的自己开发一个
同时dbt 也提供了自己cloud 的架构设计,可以参考学习,实际上有一篇有点老的完整介绍,也值得学习下

参考资料

https://github.com/dbt-labs/dbt-server/blob/main/CONTRIBUTING.md#developer-setup
https://github.com/dbt-labs/dbt-core
https://docs.getdbt.com/reference/programmatic-invocations
https://docs.getdbt.com/docs/cloud/about-cloud/architecture
https://drive.google.com/uc?export=download&id=1lktNuMZybXfqFtr24J8zAssEfoL9r51S

posted on   荣锋亮  阅读(122)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-07-31 genie 来自netflix 的分布式大数据调度服务
2018-07-31 Cannot find name 'AsyncIterator' error in Typescript compilation process 问题解决
2017-07-31 使用 lego生成 Let's Encrypt 证书

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示