rinchinov / ij-dbt-plugin

intelllij Idea plugin for DBT
https://plugins.jetbrains.com/plugin/23789-dbt
GNU General Public License v3.0
16 stars 1 forks source link

ij-dbt-plugin

Build Version Downloads

Alt text Alt text

Table of contents

  1. Key features
  2. Quick start
  3. Full Setup instructions
  4. Configuration options reference
  5. Query execution mechanism explanation

    DBT for idea IDEs

Elevate Your Data Engineering Workflow

The DBT plugin for PyCharm revolutionizes the interaction with DBT projects for data engineers and analysts. This indispensable tool integrates advanced DBT navigation and documentation preview directly into your IDE.

Key Features

Leverage these features to transform your navigation and documentation review processes, boosting productivity and understanding of DBT projects.

Quick start

Full Setup Instructions

Prerequisites

Ensure you have a Python SDK configured in IDE with DBT installed. This setup is essential for the correct functioning of the plugin.

Install the DBT Plugin

Configure Python SDK

  1. Navigate: Go to File > Project Structure > Project.
  2. Set SDK: Choose a Python interpreter where DBT is installed. If DBT is not installed, install DBT accordingly.

Specify DBT Project Paths

Open and Navigate Projects

Optional: Restart PyCharm/IntelliJ IDEA

Configuration options reference

Main settings

Settings name Description By default Examples
dbt_project.yml File Path Path to dbt project file(dbt_project.yml).
DBT docs link
dbt_project.yml
dbt Profile Directory Path to directory where dbt profile file is placed.
DBT docs link
~/.dbt
DBT runner import Import string, will be used to call dbt commands see programmatic invocations from dbt.cli.main import dbtRunner from custom_package import customDbtRunner
DBT interpreter path Python interpreter SDK where DBT is installed, if empty it takes current project's sdk
DBT environment variables Environment variables that will be used for dbt calls DB_PASS=secret1@;DB_USER=dbt
Collect usage statistic Statistics help to analyze which features most used, which adapters and environments are most popular to prioritize plugin development. privacy policy unchecked

Query execution settings

String templates are used for query formatting during execution, %s -- selected text. See section with query execution description

Settings name Description By default
Query paginated template for pagination to get paginated result %s LIMIT ? OFFSET ?
Query count template for pagination to get count of pages SELECT COUNT(*) FROM (%s)
Query plan template for getting query plan EXPLAIN %s
Query dry run template for dry run query, if adapter supports %s LIMIT 10

Query execution mechanism

Probably query execution is the most difficult and not obvious part of the plugin. It is adapter specific, so it can be different in different adapters.

Now there is two ways how to execute query:

How to run query for selected text in editor:

Alt text

  1. If your adapter is postgres then set up datasource to with name {project name}__{target}, e.x. jaffle_shop__dev, plugin will use it.
  2. Select query in editor and one of:
    • Right click and select Run Selected Query
    • Or click on top in run configurations
  3. Choose one of:
    • Run with database tools: {your desired target} to run query in IDEA's database tools
    • Run: {your desired target} to run query with pagination
    • Query plan: {your desired target} to get query plan
    • Dry run: {your desired target} to dry run query
  4. Plugin should replace refs and sources and show query execution results in plugins tool window

Note: It formats queries with query templates from plugin's settings.

If your adapter is postgres then plugin takes JDBC connection from IDEA's database tools, and runs query with JDBC.

For the rest adapters it uses dbt some tricky logic to run query with dbt cli(it works much slower than JDBC).


Plugin based on the IntelliJ Platform Plugin Template.