mindsdb dbt 扩展简单说明

mindsdb 提供了dbt 的adapter 利用了dbt 自定义物化的macro 实现一些资源的创建

目前提供的能力

  • 支持integration
  • predictor
  • table

参考使用

一个简单示例

{{
config(
  materialized='integration',
  engine='trino',
  parameters={
    "user": env_var('TRINO_USER'),
    "auth": "basic",
    "http_scheme": "https",
    "port": 443,
    "password": env_var('TRINO_PASSWORD'),
    "host": "trino.company.com",
    "catalog": "hive",
    "schema": "photorep_schema",
    "with": "with (transactional = true)"
  }
)
}}

内部处理简单说明

以简单的integration 作为例子说明

  • adapter python 处理

内部基于了mysql connector 处理

  • 参考macro 定义

此macro 的定义实际上就是sql 中的database 数据源的处理,只是因为特殊基于了内部的sql 进行包装

{% materialization integration, adapter='mindsdb' %}
  {%- set database = model['alias'] -%}
  {%- set engine = config.get('engine') -%}
  {%- set prefix = config.get('prefix') -%}
  {%- set parameters = config.get('parameters') -%}

  {% if prefix is none %}
    {%- set connector = database %}
  {% else %}
    {%- set connector =  prefix ~ "_" ~ database %}
  {% endif %}
  

  -- build model

  -- WA for https://github.com/mindsdb/mindsdb/issues/4152
  {%- call statement('tables', fetch_result = True) -%}
  SHOW DATABASES
  {%- endcall -%}
  {%- set tables = load_result('tables') -%}
  {%- set tables_data = tables['data'] -%}
  
  {%- set found_table = False -%}
  {% for item in tables_data %}
    {% if item[0] == connector %}
    {%- call statement('main') -%}
      DROP DATABASE IF EXISTS {{ connector }}
    {%- endcall -%}
    {% endif %}
  {% endfor %}

  -- end WA


  {%- call statement('main') -%}
    CREATE DATABASE {{ connector }} WITH ENGINE='{{engine}}',
    PARAMETERS={{parameters}}
  {%- endcall -%}

  {{ log("Create mindsdb database(integration) \"" ~ connector ~ "\" with engine \"" ~ engine ~ "\"", True) }}

  -- Return the relations created in this materialization
  {{ return({'relations': []}) }}
{%- endmaterialization -%}

说明

mindsdb dbt 实现起来并不难,就是利用了标准的macro 扩展了物化macro,方便业务使用

参考资料

https://github.com/mindsdb/dbt-mindsdb

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

相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· spring官宣接入deepseek,真的太香了~
历史上的今天:
2024-02-22 unpkg 淘宝registry 不能使用的问题
2024-02-22 dremio SupportsExternalQuery 简单说明
2023-02-22 使用tmpfs 进行nginx proxy_cache 加速
2023-02-22 nodejs error:03000086:digital envelope routines::initialization error 问题
2022-02-22 几款开源git server ssh 协议forced command 参考格式
2022-02-22 基于golang+openssh 服务实现一个简单的git over ssh 服务
2021-02-22 dremio sql server 查询中文的问题

导航

< 2025年2月 >
26 27 28 29 30 31 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 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示