Skip to main content

Parse and explore ClickHouse SQL queries

Project description

ClickShack

PyPI - Version | GitHub Actions Workflow Status

A collection of ClickHouse query parsing and analysis tools built on a rickety, hollowed-out version of ClickHouse.

One of the challenges of building tooling around SQL is that some dialects provide a large set of features beyond standard ANSI SQL. ClickHouse is one of these, providing a rich SQL dialect that is difficult for generic tooling to keep up with.

This project builds more reliable tooling for ClickHouse queries by providing abstractions over the actual ClickHouse parser.

Note: Parsing is currently limited to SELECT queries, other query types are on the roadmap.

Usage

The primary entrypoint is a Python package, clickshack. Features include:

  • A near like-for-like port of the actual ClickHouse SQL parser (currently supports version 26.2)
  • Converters for integrating with SQLGlot — parse with clickshack, then reach for SQLGlot's growing library of SQL utilities.
  • (Experimental) - A minimal Python library for writing custom SQL linting rules.
    • Note: I am not entirely sure where this one is headed, but it might make a useful counterpart to something like sqlcheck for ClickHouse.

Install from PyPI with:

pip install clickshack

Then parse a query with:

from clickshack import parse_sql

envelope = parse_sql("SELECT id, name FROM users WHERE active = 1")
print(envelope.ir_version)  # "1"
print(envelope.query)       # SelectNode(...)

Integrate with SQLGlot:

from sqlglot.lineage import lineage
from clickshack import parse_sql
from clickshack.ir.adapter import to_sqlglot

envelope = parse_sql("SELECT id, name FROM users WHERE active = 1")
sqlglot_expr = to_sqlglot(envelope.query)

# Trace which source column feeds 'name' in the output
node = lineage("name", sqlglot_expr)
for n in node.walk():
    print(n.name)
# name
# users.name

Or run one of the experimental linters with:

from clickshack import parse_sql
from clickshack.ir.models import StarNode
from clickshack.linter.base import LintRunner, LintViolation


class NoSelectStar:
    """Prohibit SELECT *."""
    def check(self, node) -> list[LintViolation]:
        if isinstance(node, StarNode):
            return [LintViolation(rule="no-star", message="SELECT * is not allowed", span=node.span)]
        return []


envelope = parse_sql("SELECT * FROM events")
runner = LintRunner(rules=[NoSelectStar()])
violations = runner.run(envelope.query)
for v in violations:
    print(f"{v.rule} at offset {v.span.start}: {v.message}")
# no-star at offset 7: SELECT * is not allowed

See the modules under ./clickshack/ for more details (docs are still in the works).

Development

Prerequisites

  • bazel, just, uv
  • Python 3.11+ (managed automatically by uv)

Setup

# Install Python dependencies (creates .venv automatically)
just sync

Project Structure

ported_clickhouse/   C++ parser (ported ClickHouse SELECT dialect)
ir/                  C++ IR serializer (AST → JSON, uses nlohmann/json)
examples/bootstrap/  Smoke binaries incl. ir_dump (SQL stdin → JSON IR stdout)
clickshack/
  ir/                Pydantic v2 models + SQLGlot adapter for the JSON IR
  linter/            LintRule protocol + LintRunner for IR-based linting
tests/               Python tests (pytest)
testdata/            Parser workload fixtures and manifest

Common Commands

Command What it does
just build Build primary binary (hello_clickshack)
just build-all Build all example binaries
just build-ir Build IR serializer and ir_dump binary
just run-ported-smokes Run C++ parser smoke tests
just sync Install / sync Python dependencies
just test-python Run Python tests
just clean Remove Bazel build outputs
just clean-expunge Fully reset Bazel output state

IR Dump

Parse SQL and emit the JSON IR:

echo "SELECT id FROM users WHERE active = 1" | \
  bazel-bin/examples/bootstrap/ir_dump

(Build with just build-ir first.)

License

The clickshack Python package and original C++ code are licensed under the MIT License.

The C++ parser in ported_clickhouse/ is derived from ClickHouse and is licensed under the Apache License 2.0. See NOTICE for attribution details and a description of modifications.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

clickshack-0.1.1-cp313-cp313-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

clickshack-0.1.1-cp313-cp313-musllinux_1_2_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

clickshack-0.1.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (258.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

clickshack-0.1.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (260.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

clickshack-0.1.1-cp313-cp313-macosx_14_0_arm64.whl (267.8 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

clickshack-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

clickshack-0.1.1-cp312-cp312-musllinux_1_2_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

clickshack-0.1.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (258.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

clickshack-0.1.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (260.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

clickshack-0.1.1-cp312-cp312-macosx_14_0_arm64.whl (267.8 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

clickshack-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

clickshack-0.1.1-cp311-cp311-musllinux_1_2_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ ARM64

clickshack-0.1.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (258.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

clickshack-0.1.1-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (260.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

clickshack-0.1.1-cp311-cp311-macosx_14_0_arm64.whl (267.8 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

File details

Details for the file clickshack-0.1.1-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 76f16e8763f6bb3c7e85dcc48eddc907b161f9a400a192df4469dce51293f308
MD5 e2cd151059794a70cd0614a759c1e46d
BLAKE2b-256 a144c85d4ae08d8f8831eb542851aeb592e7c4237032c50f53bb705484bf461d

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp313-cp313-musllinux_1_2_x86_64.whl:

Publisher: ci.yml on dorranh/ClickShack

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

File details

Details for the file clickshack-0.1.1-cp313-cp313-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 33bfa9918d4fc79533fcc792753d1022e7bdeb96752b3e88657d3fff7998b8e9
MD5 86266d519bac37de689ad3b4e4cd50f0
BLAKE2b-256 c1b22d3810ceac4a3a970f698e6e6d9cc30ff1ecda512a7ad37ff4371f26f8de

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp313-cp313-musllinux_1_2_aarch64.whl:

Publisher: ci.yml on dorranh/ClickShack

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

File details

Details for the file clickshack-0.1.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 16c052b81774864aff9030adfaf0ab97fcc645204a9a0146703e016d860008cf
MD5 7c507f63bf5c57ebb62dfc2456bc4204
BLAKE2b-256 1c99d5dbe9168c3de1129cc4dfcc7922d78be80e240aa71c3d6fc766bbcf14b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: ci.yml on dorranh/ClickShack

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

File details

Details for the file clickshack-0.1.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5808be2a2fa0d8d1440994e105d1023ee5e0d4d8b131cb53d8a4cd7664d288ad
MD5 f4391c60cfc048eba26e43f828f5e8d0
BLAKE2b-256 dc2175ecf5547ff6c3b74912be20108cb4dccfd4598ac0658433e3fdfe24d0cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:

Publisher: ci.yml on dorranh/ClickShack

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

File details

Details for the file clickshack-0.1.1-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c19133a8a09e8b21999eb6ee74a63f8f9b7931b835fe4f27affb10d79e0e3d5c
MD5 1e91a73768aa94a765cbd3d99b7f06f3
BLAKE2b-256 8c7a35225e02f0dba5a72e329fcff1361036a1cfcd5590dab1cca781b479c0c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp313-cp313-macosx_14_0_arm64.whl:

Publisher: ci.yml on dorranh/ClickShack

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

File details

Details for the file clickshack-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3319c17bb9ab2342df99362bd3aa83095cdda081476fb38516228daaae261fd8
MD5 38a59a7574072293c116e4fda17bab9f
BLAKE2b-256 1bfb8deab554ce06ffef74c5d2de251555e00f2e21abfd1ba03cf82b65a83919

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: ci.yml on dorranh/ClickShack

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

File details

Details for the file clickshack-0.1.1-cp312-cp312-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 42a864d224c389a1bfcf76cabdf8d38be97214b1b2d581a2aa68fa42d6abd0f5
MD5 4451c3523ea623298f425cc41f7b1de3
BLAKE2b-256 8a75cd0d542fc7c2dde02139cc3f696f55ed3a262c1874353fdc7714814370d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp312-cp312-musllinux_1_2_aarch64.whl:

Publisher: ci.yml on dorranh/ClickShack

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

File details

Details for the file clickshack-0.1.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1b84bc22b1a1ad25103c253456c82ffc5de7ce9095f0ebc9c3b02de1d63c2143
MD5 ba2fbbefe5cfb1652a4332f8c66c5662
BLAKE2b-256 03dc33b34b0167003e81e1a5ffb363f5d43ac482af7ec201b318f292a8bde26f

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: ci.yml on dorranh/ClickShack

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

File details

Details for the file clickshack-0.1.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 15f52e2928d37833690e342cb03ed48d0e2772a222e0be85dd13e1749787e3ee
MD5 224a59aa0ab2542dea954578f060bfe0
BLAKE2b-256 26b42e331666a409587669d559ce5a30a4ce7c6175606a36ac4bf44719d816e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:

Publisher: ci.yml on dorranh/ClickShack

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

File details

Details for the file clickshack-0.1.1-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 baf7ccd0aad62d5f8cfe475641561bf13d93975f6f7d9d458c936705ede41b2d
MD5 9c49224dc5c86848a665e05b403573ff
BLAKE2b-256 c6f65acedb8754f3869ade50c6f0610ae7bc5e23c2cb8b83c0adf9d4cded9883

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: ci.yml on dorranh/ClickShack

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

File details

Details for the file clickshack-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1db7e6441a82ecd65b15318517ba83e120c84fa29fedceda253d7f88fc79e414
MD5 7a7172b8ed7e109e82da12cb0dce31a3
BLAKE2b-256 bb4d86b69279f7f1088f68b66475432b0761f3ef385dc4fccc0d43bd3c7e0a60

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: ci.yml on dorranh/ClickShack

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

File details

Details for the file clickshack-0.1.1-cp311-cp311-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 45f2d5b051bc0597f1bb76b4c41f598bf8a840bc18bf5c68d3e2a10c2f7fe7d3
MD5 ce0a310fd8285ae281b955acaf6b634c
BLAKE2b-256 170b0b1f0dcd81575c09edd563c32e6002bad6991764f001f468d9f5b0dde59f

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp311-cp311-musllinux_1_2_aarch64.whl:

Publisher: ci.yml on dorranh/ClickShack

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

File details

Details for the file clickshack-0.1.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6fb68bb13c3157da86a229439babbb4b301d1e13d1e9ebbe4a511f71e025f134
MD5 3dc0ff60b05109be865c93d356265a12
BLAKE2b-256 2d9838085cff6c90b9e3a9bdc2e70d7c065d3e500ab01889f8e630b4987450a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: ci.yml on dorranh/ClickShack

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

File details

Details for the file clickshack-0.1.1-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2c9a12678fb8fbdd63b1cc1bc2342862d9e5fd4a23e05ba74912948f24a48f07
MD5 94d14cf73a553854a7c00b939ed404d6
BLAKE2b-256 2df27e50cedc8d5bb8fa378cd9742cdf3c37732c4aea60dd58e42d2c39ad2349

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:

Publisher: ci.yml on dorranh/ClickShack

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

File details

Details for the file clickshack-0.1.1-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for clickshack-0.1.1-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c744c686ff4fb175338b459b7fa637db09ab0b019779af824008aae26855fb0d
MD5 4a753f567c66f29f24309caa8398bc86
BLAKE2b-256 bb76b513cec4f6c975b38f2c73a73f5e914c49b77d08305635d53b13225eb00e

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickshack-0.1.1-cp311-cp311-macosx_14_0_arm64.whl:

Publisher: ci.yml on dorranh/ClickShack

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