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
- Parse - Split the SQL file into individual statements
- Checkpoint - Load completed query hashes from Valkey, skip already-done queries
- Dispatch - Send queries to nodes via round-robin, up to concurrency limit
- Monitor - Poll
system.processesfor per-query progress - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9aa9bc6e43184b996520fb470e8e9bb0e5b7d2bb5532e2e183bbfe071555bfce
|
|
| MD5 |
67f7ac09573fe840e36c9db5ffdb70b6
|
|
| BLAKE2b-256 |
b85a8a190c018a59c80dacb881aff69441f60d1fae4adf8bf9d3793516cc7b2c
|
Provenance
The following attestation bundles were made for clickhouse_query_runner-1.0.0.tar.gz:
Publisher:
publish.yaml on gmr/clickhouse-query-runner
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clickhouse_query_runner-1.0.0.tar.gz -
Subject digest:
9aa9bc6e43184b996520fb470e8e9bb0e5b7d2bb5532e2e183bbfe071555bfce - Sigstore transparency entry: 931376198
- Sigstore integration time:
-
Permalink:
gmr/clickhouse-query-runner@0a0ec4280d3ffa2d9f50bf47f99600237687bfaa -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/gmr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@0a0ec4280d3ffa2d9f50bf47f99600237687bfaa -
Trigger Event:
release
-
Statement type:
File details
Details for the file clickhouse_query_runner-1.0.0-py3-none-any.whl.
File metadata
- Download URL: clickhouse_query_runner-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efa8067be6c2ebb8728f4450e3e2c99d81171cf26ec0d957eed65796143508ca
|
|
| MD5 |
24b249f42f99381d9deccb950f422127
|
|
| BLAKE2b-256 |
5cf6ea0d5ff6f05a6cc4a84b11a68ed6ddf61afa915cec262634a36ebc785824
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clickhouse_query_runner-1.0.0-py3-none-any.whl -
Subject digest:
efa8067be6c2ebb8728f4450e3e2c99d81171cf26ec0d957eed65796143508ca - Sigstore transparency entry: 931376250
- Sigstore integration time:
-
Permalink:
gmr/clickhouse-query-runner@0a0ec4280d3ffa2d9f50bf47f99600237687bfaa -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/gmr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@0a0ec4280d3ffa2d9f50bf47f99600237687bfaa -
Trigger Event:
release
-
Statement type: