zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    asp.net调用mysql 存储过程 带 out 返回值,返回刚插入数据库中的自增的ID,LAST_INSERT_ID() 的使用
    如何俘获一个 IT 男的心,让他成为男友然后变成老公?
    MySqlHelper.cs mysql数据库助手类
    mysql 按年度、季度、月度、周、日SQL统计查询,mysql 存储过程 中 in 和 FIND_IN_SET 传递多个参数的使用
    奇怪的母版页里面的 form 表单里面的 enctype="multipart/formdata" html控件上传 FileUpload控件上传 一次多图片上传
    asp.net 连接 Mysql 代码生成器(下载地址)
    Convert.ToInt32、(int)和int.Parse,int.TryParse四者之间的区别:
    在web项目中 使用 WebService 根据IP地址来源搜索实际物理地址,常用的WebServices
    vc6控制台程序利用SoapToolkit3.0调用WebService
    浅议C++/CLI的gcnew关键字
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/11170105.html
Copyright © 2011-2022 走看看