Skip to main content

CLI tool to execute SQL queries against a ClickHouse cluster with checkpointing and progress monitoring

Project description

clickhouse-query-runner

A CLI tool that executes SQL queries from a file against a ClickHouse cluster, running queries in parallel with round-robin distribution across nodes, checkpointing progress in Valkey, and providing a rich terminal UI showing both batch-level and query-level progress.

Features

  • Parallel query execution with configurable concurrency
  • Round-robin distribution across cluster nodes
  • Checkpoint/resume via Valkey for fault tolerance
  • Rich progress display with per-query monitoring
  • Dry-run mode for query validation

Installation

uv tool install clickhouse-query-runner

Or run directly without installing:

uvx clickhouse-query-runner queries.sql

Development

git clone https://github.com/gmr/clickhouse-query-runner.git
cd clickhouse-query-runner
uv sync --group dev

To run the tool during development:

uv run clickhouse-query-runner queries.sql

Quick Start

# Set connection environment variables
export CLICKHOUSE_HOST=clickhouse.example.com
export CLICKHOUSE_USER=default
export CLICKHOUSE_PASSWORD=secret
export CLICKHOUSE_DATABASE=mydb

# Run queries from a file
uvx clickhouse-query-runner queries.sql

# With explicit options
uvx clickhouse-query-runner \
  --host node1.example.com,node2.example.com \
  --concurrency 4 \
  --valkey-url redis://valkey:6379/0 \
  queries.sql

Command Reference

Option Env Var Default Description
--host CLICKHOUSE_HOST (required) ClickHouse hostname(s), comma-separated
--port CLICKHOUSE_PORT 9440 ClickHouse server port
--database CLICKHOUSE_DATABASE (required) Database name
--user CLICKHOUSE_USER (required) Username
--password CLICKHOUSE_PASSWORD (required) Password
--secure CLICKHOUSE_SECURE true Use secure connection
--concurrency 2 Max parallel queries
--run-id (auto) Override run ID
--valkey-url VALKEY_URL redis://localhost:6379/0 Valkey URL
--checkpoint-ttl 604800 Checkpoint TTL in seconds
--poll-interval 0.5 Progress poll interval
--cancel-on-failure false Cancel in-flight on failure
--dry-run false Parse without executing
--reset false Clear checkpoints and exit
--verbose false Debug logging

How It Works

  1. Parse - Split the SQL file into individual statements
  2. Checkpoint - Load completed query hashes from Valkey, skip already-done queries
  3. Dispatch - Send queries to nodes via round-robin, up to concurrency limit
  4. Monitor - Poll system.processes for per-query progress
  5. Record - Checkpoint each completed query to Valkey

Architecture

src/clickhouse_query_runner/
├── __init__.py        # Package initialization
├── cli.py             # Entry point, arg parsing
├── runner.py          # Core async execution engine
├── checkpoint.py      # Valkey checkpoint management
├── parser.py          # SQL file parsing
├── progress.py        # Rich progress display
└── settings.py        # Pydantic settings model

Code Quality

uv run ruff check src/
uv run ruff format --check src/

License

BSD 3-Clause License. See LICENSE for details.

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

clickhouse_query_runner-1.0.0.tar.gz (49.5 kB view details)

Uploaded Source

Built Distribution

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

clickhouse_query_runner-1.0.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file clickhouse_query_runner-1.0.0.tar.gz.

File metadata

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

File hashes

Hashes for clickhouse_query_runner-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9aa9bc6e43184b996520fb470e8e9bb0e5b7d2bb5532e2e183bbfe071555bfce
MD5 67f7ac09573fe840e36c9db5ffdb70b6
BLAKE2b-256 b85a8a190c018a59c80dacb881aff69441f60d1fae4adf8bf9d3793516cc7b2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickhouse_query_runner-1.0.0.tar.gz:

Publisher: publish.yaml on gmr/clickhouse-query-runner

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

File details

Details for the file clickhouse_query_runner-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for clickhouse_query_runner-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 efa8067be6c2ebb8728f4450e3e2c99d81171cf26ec0d957eed65796143508ca
MD5 24b249f42f99381d9deccb950f422127
BLAKE2b-256 5cf6ea0d5ff6f05a6cc4a84b11a68ed6ddf61afa915cec262634a36ebc785824

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickhouse_query_runner-1.0.0-py3-none-any.whl:

Publisher: publish.yaml on gmr/clickhouse-query-runner

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