GithubHelp home page GithubHelp logo

dbt-inheritance's Introduction

dbt-inheritance

これはTwitterで たきもさんが呟いていたもののPoCコードです。

https://twitter.com/takimo/status/1596108180668366848?s=20&t=eGWiRIYSDY-ExfXIUINbog

使い方

dbtのbuiltinされているcreate_table_asというマクロを書き換えます。 

macros/override.sql

{% macro default__create_table_as(temporary, relation, sql) -%}
    {{ dbt.default__create_table_as(temporary, relation, dbt_inheritance.rewrite_sql(sql)) }}
{%- endmacro %}

packages.yml に以下を書く

packages:
  - git: "https://github.com/mashiike/dbt-inheritance"
    revision: v0.0.0

その後、クラス定義(ephemeral)に該当するものを以下のように書く

{{
    config(
        materialized='ephemeral'
    )
}}

select *
from {{ dbt_inheritance.abstruct_ref('base') }}

refを書き換えるのではなく、専用の抽象的なrefを用意することにした。

コレを外部(呼び出し側)では

{{
    config(
        materialized='table',
    )
}}
{{
    dbt_inheritance.resolve_abstruct_ref(
        base='yyyyyy',
    )
}}

with data as (
    select * from {{ ref('eph_model_a') }}
)
select *
from data

というように 呼び出し側のモデルで dbt_inheritance.resolve_abstruct_ref() マクロを呼び出して、実際のrefを遅延で解決する。

このままでは実用できない点

  • materialization table のみでしか動作確認してない。 (基本的には create_table_as を使うので多分動くとは思うが)
  • ephemeral側でtestが書けない。
  • compiled_codeにJinja templateが入っていて、2階建てテンプレートになっている。

dbt-inheritance's People

Contributors

mashiike avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.