Skip to main content

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


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.1.0.tar.gz (9.6 kB view hashes)

Uploaded Source

Built Distribution

clickhouse_query-0.1.0-py3-none-any.whl (8.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page