clickhouse query
Project description
ClickHouse Query
Clickhouse Query is a Python library for building complex ClickHouse queries by a fluent API and a set of functions.
Installation
pip install clickhouse-query
Usage
import clickhouse_query as ch
q = (
ch.QuerySet()
.from_("my_table")
.prewhere(date__year__gte="2024")
.select(count=ch.Count())
.limit(10)
)
sql, sql_params = ch.get_sql(q)
# sql = 'SELECT count() AS count FROM click PREWHERE (greaterOrEquals(toYear(date), %(__U_1)s)) LIMIT %(__U_2)f'
# sql_params = {'__U_1': 2024, '__U_2': 10}
data = q.execute()
# data = [{'count': 100}]
Custom Functions
If there is not a function that you need, you can easily create it by extending the Function
class. like this:
class MyFunction(ch.Function):
function = "my_function"
Custom Aggregation Functions
If there is not a aggregation function that you need, you can easily create it by extending the AggregationFunction
class. like this:
class MyAggregationFunction(ch.AggregationFunction):
function = "my_aggregation_function"
License
This project is licensed under the MIT License - see the LICENSE file 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-0.0.3.tar.gz
(6.4 kB
view hashes)