Skip to main content

dbt logo

dbt-ydb

dbt-ydb is a plugin for dbt that provides support for working with YDB. dbt-ydb adapter is in preview stage and does not currently support all dbt features. The sections below list the supported features and known limitations.

Installation

To install plugin, execute the following command:

pip install dbt-ydb

Supported features

  • Table materialization
  • View materialization
  • Seeds
  • Docs generate
  • Tests
  • Incremental materializations (merge strategy only)
  • Snapshots
  • Cross-database (dbt "utils") macros: dateadd, datediff, date_trunc, last_day, hash, split_part, concat, length, position, right, replace, bool_or, any_value, safe_cast, cast_bool_to_text, escape_single_quotes, type_*, except, intersect, array_construct, array_append, array_concat (YDB List<T>)

Limitations

  • datediff on sub-second dateparts (microsecond/millisecond) requires Timestamp inputs; Date/Datetime columns carry only second precision.

  • type_float / type_numeric / type_boolean / type_timestamp macros are available, but casting arbitrary string literals to these types follows YQL rules (e.g. a Double column cannot be a primary key).

  • YDB does not support CTE

  • YDB requires a primary key to be specified for its tables. See the configuration section for instructions on how to set it.

  • source() macro requires you to specify a schema. Use / if your source is in root folder.

Usage

Profile Configuration

To configure YDB connection, fill profile.yml file as below:

profile_name:
  target: dev
  outputs:
    dev:
      type: ydb
      host: [localhost] # YDB host
      port: [2136] # YDB port
      database: [/local] # YDB database
      schema: [<empty string>] # Optional subfolder for DBT models
      secure: [False] # If enabled, grpcs protocol will be used
      root_certificates_path: [<empty string>] # Optional path to root certificates file

      # Static Credentials
      username: [<empty string>]
      password: [<empty string>]

      # Access Token Credentials
      token: [<empty string>]

      # Service Account Credentials
      service_account_credentials_file: [<empty string>]

Model Configuration

View

Option Description Required Default

Table

Option Description Required Default
primary_key Primary key expression to use during table creation yes
store_type Type of table. Available options are row and column no row
partition_by Columns for the PARTITION BY <method> (...) clause. Column-oriented tables only (store_type='column') no
partition_method Partitioning method for partition_by. Currently YDB supports only hash no hash
auto_partitioning_by_size Enable automatic partitioning by size. Available options are ENABLED and DISABLED no
auto_partitioning_by_load Enable automatic partitioning by load. Available options are ENABLED and DISABLED no
auto_partitioning_partition_size_mb Partition size in megabytes for automatic partitioning no
auto_partitioning_min_partitions_count Minimum number of partitions no
auto_partitioning_max_partitions_count Maximum number of partitions no
uniform_partitions Number of pre-created uniform partitions (Uint32/Uint64 keys) no
partition_at_keys Explicit partition boundary keys, e.g. (100, 200, 300) no
ttl Time-to-live (TTL) expression for automatic data expiration no

Incremental

Option Description Required Default
incremental_strategy Strategy of incremental materialization. Current adapter supports only merge strategy, which will use YDB's UPSERT operation. no default
primary_key Primary key expression to use during table creation yes
store_type Type of table. Available options are row and column no row
partition_by Columns for the PARTITION BY <method> (...) clause. Column-oriented tables only (store_type='column') no
partition_method Partitioning method for partition_by. Currently YDB supports only hash no hash
auto_partitioning_by_size Enable automatic partitioning by size. Available options are ENABLED and DISABLED no
auto_partitioning_by_load Enable automatic partitioning by load. Available options are ENABLED and DISABLED no
auto_partitioning_partition_size_mb Partition size in megabytes for automatic partitioning no
auto_partitioning_min_partitions_count Minimum number of partitions no
auto_partitioning_max_partitions_count Maximum number of partitions no
uniform_partitions Number of pre-created uniform partitions (Uint32/Uint64 keys) no
partition_at_keys Explicit partition boundary keys, e.g. (100, 200, 300) no
ttl Time-to-live (TTL) expression for automatic data expiration no
tmp_relation_type How the rows are staged for the UPSERT: as a view (the model query is read once, straight into the target) or as a table (the result set is materialized first, then copied) no view
merge_sql_header SQL header for the UPSERT statement. Replaces sql_header for that statement only no value of sql_header
tmp_sql_header SQL header for the statement that creates the temp relation. Replaces sql_header for that statement only no value of sql_header
Staging: view or table

On an incremental run the adapter first stages the model's result set and then UPSERTs it into the target. By default the staging relation is a view, so the model query is planned into the UPSERT itself and the data is written exactly once:

create view `schema/model__dbt_tmp` with (security_invoker = TRUE) as select ... ;
upsert into `schema/model` select `a`, `b` from `schema/model__dbt_tmp`;

Set tmp_relation_type='table' to go back to staging into a real table (create table ... as select, then upsert ... from it). That costs one extra full write plus a read of the same volume, but it reads the sources before the target is touched, which is what you want if:

  • the model query is non-deterministic or reads a source that keeps changing, and you would rather it be snapshotted before the write starts;
  • the model reads {{ this }} and you do not want the read and the write of the target to happen inside one query;
  • the single query that reads the sources and writes the target runs into transaction limits.

Model contracts always stage into a table -- a view carries no column definitions to assert the contract against.

View staging needs a cluster with CREATE VIEW support; where views are not enabled, incremental models need tmp_relation_type='table'.

Per-statement SQL headers

Building a model takes more than one statement, and sql_header goes in front of every one of them. Statements differ in what they do and how they are planned, so a header that fits one of them is not necessarily valid for the next. merge_sql_header and tmp_sql_header replace sql_header for their own statement; an empty string means "no header here":

{{ config(
    materialized='incremental',
    unique_key='id',
    primary_key='id',
    sql_header='PRAGMA ydb.DisableBlockExecution = "true";',
    merge_sql_header='',
    tmp_sql_header=''
) }}
Example table configuration
{{ config(
    primary_key='id, created_at',
    store_type='row',
    auto_partitioning_by_size='ENABLED',
    auto_partitioning_partition_size_mb=256,
    ttl='Interval("P30D") on created_at'
) }}

select
    id,
    name,
    created_at
from {{ ref('source_table') }}
Example column-oriented table with partitioning
{{ config(
    primary_key='id',
    store_type='column',
    partition_by='id',
    auto_partitioning_min_partitions_count=4
) }}

select id, name, created_at from {{ ref('source_table') }}

Seed

Option Description Required Default
primary_key Primary key expression to use during table creation no The first column of CSV will be used as default.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbt_ydb-0.0.16.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbt_ydb-0.0.16-py3-none-any.whl (32.5 kB view details)

Uploaded Python 3

File details

Details for the file dbt_ydb-0.0.16.tar.gz.

File metadata

  • Download URL: dbt_ydb-0.0.16.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dbt_ydb-0.0.16.tar.gz
Algorithm Hash digest
SHA256 e7b2cc86c537e3ee820054ecfeb2dda9d2ae9eb3960aa33fcc0943e65b4d8f3a
MD5 60c05409fa3f711c58bd26a305ea637c
BLAKE2b-256 74345a08b927467e88b95fe589e6fb1043d81f1a427b7f10491c2bdcc3cecb85

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbt_ydb-0.0.16.tar.gz:

Publisher: python-publish.yml on ydb-platform/dbt-ydb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dbt_ydb-0.0.16-py3-none-any.whl.

File metadata

  • Download URL: dbt_ydb-0.0.16-py3-none-any.whl
  • Upload date:
  • Size: 32.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dbt_ydb-0.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 86812236470c474d08e6a85c0c0804ca5c4b69a3721104d72d8fbe230ef46351
MD5 64dbd705777ff97c357a356f0fa2862d
BLAKE2b-256 812bfa774aa7d83e49abe352a478be47343d4b504e5f6f84dd67d7abec8ef84d

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbt_ydb-0.0.16-py3-none-any.whl:

Publisher: python-publish.yml on ydb-platform/dbt-ydb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.0.17

2 files

This release

0.0.16 This release

2 files

0.0.15

2 files

0.0.14

2 files

0.0.13

2 files

0.0.12

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

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