Skip to main content

YDB dialect plugin for sqlglot

Project description

ydb-sqlglot-plugin

YDB dialect plugin for sqlglot.

This package provides a YDB dialect for sqlglot, enabling SQL parsing and generation with YDB-specific syntax and features.

Installation

pip install ydb-sqlglot-plugin

Usage

After installing the package, the ydb dialect is automatically registered with sqlglot:

import sqlglot

# Transpile from another dialect to YDB
sql = "SELECT * FROM users WHERE id = 1"
result = sqlglot.transpile(sql, read="mysql", write="ydb")[0]
print(result)
# Output: SELECT * FROM `users` WHERE id = 1

# Parse directly with YDB dialect
parsed = sqlglot.parse_one("SELECT * FROM `users`", dialect="ydb")
print(parsed.sql(dialect="ydb"))

Features

  • Table name escaping: Table names are automatically wrapped in backticks
  • CTE to variables: Common Table Expressions are converted to YDB-style variables ($name = (...))
  • Date/Time functions: Proper mapping of date/time functions to YDB's DateTime module
  • Type mapping: SQL types are mapped to YDB-specific types (e.g., VARCHARUtf8, INTINT32)
  • Subquery decorrelation: Correlated subqueries are transformed into JOINs for better YDB compatibility
  • Lambda expressions: Support for YDB-style lambda expressions in array operations

Development

Prerequisites

  • Python 3.9+
  • pip

Setup

Clone the repository and install in development mode:

git clone https://github.com/ydb-platform/ydb-sqlglot-plugin.git
cd ydb-sqlglot-plugin

# Create virtual environment (optional but recommended)
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install with dev dependencies
pip install -e ".[dev]"

Running Tests

pytest

Project details


Download files

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

Source Distribution

ydb_sqlglot_plugin-0.1.0.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

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

ydb_sqlglot_plugin-0.1.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file ydb_sqlglot_plugin-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for ydb_sqlglot_plugin-0.1.0.tar.gz
Algorithm Hash digest
SHA256 14c92bad99b635d2140d26c8481588675d02a7bff5113b37d0382f445ee37be5
MD5 d3d88d16174f238695411591c9d2640e
BLAKE2b-256 20c4ba90907b599e6c28dbbb554bda6ed4f96bee7f743d308d9aa0ecc4c92636

See more details on using hashes here.

Provenance

The following attestation bundles were made for ydb_sqlglot_plugin-0.1.0.tar.gz:

Publisher: python-publish.yml on ydb-platform/ydb-sqlglot-plugin

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

File details

Details for the file ydb_sqlglot_plugin-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ydb_sqlglot_plugin-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7b4c467269f4170d3d508d42521487a5cbfd95993dc2128d2e51f8dc35d6cec
MD5 81e9d6c909697ed0b3d660993355237f
BLAKE2b-256 fafe536027f054d42df8132e4434db6ae409080609a99e01213e80886874becd

See more details on using hashes here.

Provenance

The following attestation bundles were made for ydb_sqlglot_plugin-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on ydb-platform/ydb-sqlglot-plugin

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page