Skip to main content

TiDB logo dbt logo

dbt-tidb

PyPI PyPI - Python Version PyPI - Downloads Integration Test

The dbt-tidb package contains all of the code enabling dbt to work with TiDB.

This repository is partly based on dbt-mysql. Thanks to them for their excellent work.

Table of Contents

Installation

Compile by source code.

$ git clone https://github.com/pingcap/dbt-tidb.git
$ cd dbt-tidb
$ pip install .

Also, you can get it from pypi.

$ pip install dbt-tidb

Supported features

TiDB 4.X TiDB 5.0 ~ 5.2 TiDB >= 5.3 Feature
✅ ✅ ✅ Table materialization
✅ ✅ ✅ View materialization
❌ ❌ ✅ Incremental materialization
❌ ✅ ✅ Ephemeral materialization
✅ ✅ ✅ Seeds
✅ ✅ ✅ Sources
✅ ✅ ✅ Custom data tests
✅ ✅ ✅ Docs generate
❌ ❌ ✅ Snapshots
✅ ✅ ✅ Connection retry
✅ ✅ ✅ Grant

Note:

  • TiDB 4.0 ~ 5.0 does not support CTE, you should avoid using WITH in your SQL code.
  • TiDB 4.0 ~ 5.2 does not support creating a temporary table or view.
  • TiDB 4.X does not support using SQL func in CREATE VIEW, avoid it in your SQL code. You can find more detail here.

Supported functions

cross-db macros are moved from dbt-utils into dbt-core, so you can use the following functions directly, see dbt-util on how to use them.

  • bool_or
  • cast_bool_to_text
  • dateadd
  • datediff
  • date_trunc
  • hash
  • safe_cast
  • split_part
  • last_day
  • cast_bool_to_text
  • concat
  • escape_single_quotes
  • except
  • intersect
  • length
  • position
  • replace
  • right
  • listagg (not support yet)

pay attention that datediff is a little different from dbt-util that it will round down rather than round up.

Profile Configuration

TiDB targets should be set up using the following configuration in your profiles.yml file.

Example entry for profiles.yml:

your_profile_name:
  target: dev
  outputs:
    dev:
      type: tidb
      server: 127.0.0.1
      port: 4000
      schema: database_name
      username: tidb_username
      password: tidb_password
      retries: 2
Option Description Required? Example
type The specific adapter to use Required tidb
server The server (hostname) to connect to Required yourorg.tidb.com
port The port to use Required 4000
schema Specify the schema (database) to build models into Required analytics
username The username to use to connect to the server Required dbt_admin
password The password to use for authenticating to the server Required correct-horse-battery-staple
retries The retry times for connection to TiDB (1 in default) Optional 2

Database User Privileges

Your database user would be able to have some abilities to read or write, such as SELECT, CREATE, and so on. You can find some help here with TiDB privileges management.

Required Privilege
SELECT
CREATE
CREATE TEMPORARY TABLE
CREATE VIEW
INSERT
DROP
SHOW DATABASE
SHOW VIEW
SUPER

Running Tests

See tests/README.md for details on running the integration tests.

Example

Click here to see a simple example about using dbt with dbt-tidb.

Contributing

Welcome to contribute for dbt-tidb. See Contributing Guide for more information.

Metadata

Release files for dbt-tidb 1.6.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dbt-tidb 1.6.4
File Size Uploaded Provenance
dbt-tidb-1.6.4.tar.gz 22.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dbt-tidb 1.6.4
File Interpreter ABI Platform
dbt_tidb-1.6.4-py3-none-any.whl Python 3 none any Details

Total release size: 49.2 kB

Release files / dbt-tidb-1.6.4.tar.gz

Download URL dbt-tidb-1.6.4.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
88b8ac1f8a9e48298a2604aec5a83f648e4d4e1a1207d7d1efe503e820c17e53
BLAKE2b-256 checksum
How to use checksums
027e9856f2ea8b3bf5604c4aa5a5b55d9802766851063641589774432dde4eb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / dbt_tidb-1.6.4-py3-none-any.whl

Download URL dbt_tidb-1.6.4-py3-none-any.whl
Size 26.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8387f0c77215d42af8ce680004d087c35d065b4409edc75540eb4a86f177add1
BLAKE2b-256 checksum
How to use checksums
1e75e4b291186a192e90f60696aedf068e1a03b4c783af9b72fe5ef0073cd089
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Security for dbt-tidb 1.6.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page