Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: dbt integration #19

Merged
merged 5 commits into from
Jul 26, 2022
Merged

Feature: dbt integration #19

merged 5 commits into from
Jul 26, 2022

Conversation

oscar60310
Copy link
Contributor

@oscar60310 oscar60310 commented Jul 12, 2022

Using the result of dbt (dbt build) as API schemas.

https://www.notion.so/canner/Integration-with-dbt-61427c0571e04d82b2696f4cc50f3ff1

Feature description

DBT

  1. Create some models and write some dbt models.

    --- models/example/1_table.sql
    
    {{ config(materialized='table') }}
    
    with source_data as (
        select 1 as id, 'Ivan' as name, 18 as age
    	UNION
        select 2 as id, 'William' as name, 80 as age
        UNION
        select 3 as id, 'Eason' as name, 18 as age
    )
    
    select * from source_data
  2. Run dbt models: dbt run

Vulcan

  1. Install DBT extension. yarn add @vulcan-sql/extension-dbt.

  2. Config extension set the path to dbt manifest files.

    extensions: ['@vulcan-sql/extension-dbt']
    templateEngine:
      dbt:
          modelFiles:
          - /path/to/manifest.json
  3. Reference dbt model in your SQL. (model.[project-name].[model-name])

    select * from {% dbt "model.test.1_table" %}

Result

Results are variavous by materialization

-- view table incremantal
select * from "postgres"."public"."1_table"
-- ephemeral (sub-query)
select sub.* from (
select *
from "postgres"."public"."1_table"
where age <= 18) as sub

Implementation

  1. I created two packages: extension-dbt for the extension and test-utility as a collection of testing tools like creating mock compilers ...etc.
  2. Add a hook "onInit" for template engine extension to execute some asynchronous jobs.
  3. Turn compiler.compile() function to async to wait onInit hooks.

@kokokuo kokokuo force-pushed the feature/serve-ioc-container branch from 553671e to fa3d166 Compare July 13, 2022 10:37
Base automatically changed from feature/serve-ioc-container to develop July 14, 2022 02:44
@oscar60310 oscar60310 force-pushed the feature/dbt branch 3 times, most recently from 1bffa12 to c60927e Compare July 15, 2022 03:44
@oscar60310 oscar60310 requested a review from kokokuo July 15, 2022 06:22
@oscar60310 oscar60310 marked this pull request as ready for review July 15, 2022 06:22
@oscar60310 oscar60310 changed the title [WIP] Feature: dbt integration Feature: dbt integration Jul 15, 2022
Copy link
Contributor

@kokokuo kokokuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent, really easy to understand, LGTM 👍


private loadModel(name: string, node: any) {
if (this.models.has(name)) throw Error(`Model name ${name} is unambiguous`);
this.models.set(name, node.relation_name || `(${node.compiled_sql})`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Maybe we could add the comment to mention other members to notice here, if not found relation_name or relation_name is null, then will read compiled_sql value, how do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll account for the logic here.

@oscar60310
Copy link
Contributor Author

Hi @kokokuo , all issues have been fixed.

@kokokuo kokokuo merged commit d9aff24 into develop Jul 26, 2022
@kokokuo kokokuo deleted the feature/dbt branch July 26, 2022 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants