clickhouse query
Project description
ClickHouse Query
ClickHouse Query is a Python library designed to simplify the construction of complex ClickHouse queries. It provides a fluent API and a comprehensive set of functions for this purpose.
Installation
You can install the ClickHouse Query library using pip. Run the following command in your terminal:
pip install clickhouse-query
Usage
Here’s an example of how to use the ClickHouse Query library:
import clickhouse_query as ch
from clickhouse_query import functions as chf
# Create a QuerySet instance for your table
q = (
ch.QuerySet("my_table", clickhouse_client=...)
.prewhere(date__year__gte=2020) # Add a prewhere condition
.group_by("status") # Group by status
.select("status", s=chf.sum("price")) # Select status and sum
.order_by("-s") # Order by sum in descending order
.limit(10) # Limit the results to 10
)
# Get the SQL query and parameters
sql, sql_params = ch.get_sql(q)
# sql = 'SELECT status, sum(price) AS cnt FROM my_table PREWHERE (greaterOrEquals(toYear(date), %(__U_1)f)) GROUP BY status ORDER BY cnt DESC LIMIT %(__U_2)f'
# sql_params = {'__U_1': 2020, '__U_2': 10}
# Execute the query
data = q.execute()
# data = [{"status": "status1", "s": 200}, {"status": "status2", "s": 100}, ...]
In this example, sql will contain the generated SQL query and sql_params will contain its parameters. The execute method will execute the query and return the data.
Docs
For more detailed information on how to use the ClickHouse Query library, please refer to the documentation in the docs directory.
License
This project is licensed under the MIT License - see the LICENSE file 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-0.1.1.tar.gz.
File metadata
- Download URL: clickhouse_query-0.1.1.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e455d57d99bb4a32c2c06431fb47052e2e9bc38acfc946307f451decb276ffac
|
|
| MD5 |
2ea6714b82cdab1565456d0b70ff2b0d
|
|
| BLAKE2b-256 |
4b340c809349da5d67fe1b10433f5b211b42af8d6914783a39772e067dbc48b1
|
File details
Details for the file clickhouse_query-0.1.1-py3-none-any.whl.
File metadata
- Download URL: clickhouse_query-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
363f175f44803407b263c06a220db8bba6325dff09a2270f9e7f88d90e9cb76b
|
|
| MD5 |
f42c29f0b704f50f013c17766dc7ee7f
|
|
| BLAKE2b-256 |
b85586028d09fc5fa8634f2b78c19455ec90da020c69c94008bdf3e9526f83d5
|