dbt 0.14.0 试用
dbt 0.14.0 在最近已经发布了,dbt server 的还是很不错的特性,以下安装试用下几个新功能
环境准备
安装
如果没有安装的:
pip install dbt
已经安装的:
pip install -U dbt
pg 数据库环境准备
使用docker-compose 运行
- docker-compose 文件
version: "3"
services:
database:
image: postgres
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "dalong"
ports:
- "5432:5432"
database2:
image: postgres
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "dalong"
ports:
- "5433:5432"
rpc
创建简单项目
- dbt init
dbt init 14demo
- 配置profile
profiles.yml 文件
# For more information on how to configure this file, please see:
# https://github.com/fishtown-analytics/dbt/blob/master/sample.profiles.yml
default:
target: dev
outputs:
dev:
type: postgres
host: 127.0.0.1
user: postgres
pass: password
port: 5432
dbname: postgres
schema: dalong
threads: 3
pg:
target: dev
outputs:
dev:
type: postgres
host: 127.0.0.1
user: postgres
pass: dalong
port: 5432
dbname: postgres
schema: public
threads: 3
demo:
target: dev
outputs:
dev:
type: postgres
host: 127.0.0.1
user: postgres
pass: dalong
port: 5432
dbname: postgres
schema: demo
threads: 3
基本使用
- 启动pg
docker-compose up -d
- 启动dbt server rpc 服务
dbt rpc
效果
dbt rpc
Running with dbt=0.14.0
Found 116 macros, 0 analyses, 0 sources, 0 seed files, 0 snapshots, 0 tests, 1 models, 0 operations
14:39:08 | Concurrency: 3 threads (target='dev')
14:39:08 |
14:39:08 | Done.
Serving RPC server at 0.0.0.0:8580
Supported methods: ['compile', 'run', 'ps', 'kill']
Send requests to http://localhost:8580/jsonrpc
- rpc 服务请求格式
{
"jsonrpc": "2.0",
"method": "{ a valid rpc server command }",
"id": "{ a unique identifier for this query }",
"params": {
"timeout": { timeout for the query in seconds },
"sql": "{ base64 encoded dbt-sql query }",
"name": "{ an identifying name for this query }"
}
}
- 一个rpc 服务参考例子
{
"jsonrpc": "2.0",
"method": "compile",
"id": "2db9a2fe-9a39-41ef-828c-25e04dd6b07d",
"params": {
"timeout": 60,
"sql": "c2VsZWN0IHt7IDEgKyAxIH19IGFzIGlk",
"name": "my_first_query"
}
}
curl 格式
curl -X GET \
http://localhost:8580/jsonrpc \
-H 'Accept: */*' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Type: text/plain' \
-H 'Host: localhost:8580' \
-H 'accept-encoding: gzip, deflate' \
-H 'cache-control: no-cache' \
-H 'content-length: 229' \
-H 'cookie: Cookie_6=value; platform=order' \
-b 'Cookie_6=value; platform=order' \
-d '{
"jsonrpc": "2.0",
"method": "compile",
"id": "2db9a2fe-9a39-41ef-828c-25e04dd6b07d",
"params": {
"timeout": 60,
"sql": "c2VsZWN0IHt7IDEgKyAxIH19IGFzIGlk",
"name": "my_first_query"
}
}'
返回数据
{
"jsonrpc": "2.0",
"result": {
"timing": [
{
"completed_at": "2019-07-11T06:55:53.542902Z",
"started_at": "2019-07-11T06:55:53.531315Z",
"name": "compile"
},
{
"completed_at": "2019-07-11T06:55:53.543440Z",
"started_at": "2019-07-11T06:55:53.543151Z",
"name": "execute"
}
],
"raw_sql": "select {{ 1 + 1 }} as id",
"compiled_sql": "select 2 as id",
"logs": [
{
"timestamp": "2019-07-11 14:55:53,428",
"message": "Parsing rpc.my_new_package.my_first_query",
"levelname": "DEBUG",
"level": 10
},
{
"timestamp": "2019-07-11 14:55:53,432",
"message": "Acquiring new postgres connection \"my_first_query\".",
"levelname": "DEBUG",
"level": 10
},
{
"timestamp": "2019-07-11 14:55:53,433",
"message": "Opening a new connection, currently in state init",
"levelname": "DEBUG",
"level": 10
},
{
"timestamp": "2019-07-11 14:55:53,522",
"message": "Found 116 macros, 0 analyses, 0 sources, 1 None, 0 seed files, 0 snapshots, 0 tests, 1 models, 0 operations",
"levelname": "NOTICE",
"level": 15
},
{
"timestamp": "2019-07-11 14:55:53,523",
"message": "Acquiring new postgres connection \"my_first_query\".",
"levelname": "DEBUG",
"level": 10
},
{
"timestamp": "2019-07-11 14:55:53,524",
"message": "Opening a new connection, currently in state init",
"levelname": "DEBUG",
"level": 10
},
{
"timestamp": "2019-07-11 14:55:53,531",
"message": "Compiling rpc.my_new_package.my_first_query",
"levelname": "DEBUG",
"level": 10
}
]
},
"id": "2db9a2fe-9a39-41ef-828c-25e04dd6b07d"
}
ls 命令
dbt ls
效果:
dbt ls
my_new_package.example.my_first_dbt_model
说明
dbt 0.14.0 的好多新特性还是很不错的
参考资料
https://docs.getdbt.com/docs/rpc
https://docs.getdbt.com/v0.14/docs/run-operation
https://docs.getdbt.com/docs/list
https://github.com/rongfengliang/dbt-0.14.0-learning
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2018-07-11 purescript 基本试用
2017-07-11 “VT-x is not available. (VERR_VMX_NO_VMX)” in VirtualBox