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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file clickhouse_query-0.1.0.tar.gz.

File metadata

  • Download URL: clickhouse_query-0.1.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for clickhouse_query-0.1.0.tar.gz
Algorithm Hash digest
SHA256 05a7b91d092fa0c810b5628cddfccf28f306e8eac6c74b7a89d5a47a1de6ffc3
MD5 6c51ba5c0e2b238f81d5696bf6215243
BLAKE2b-256 375bc94f8e562a204896bede2ddccf7d1a42a717df822ea726f9a941bd818fc4

See more details on using hashes here.

File details

Details for the file clickhouse_query-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for clickhouse_query-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d6e810b877781eb069c8ebf0926ce4288af76df4c56969d9ec7c4df32681de51
MD5 c3e22b4502da175e43fc11e2e6eb0db2
BLAKE2b-256 41f82e4147a56684e5e2eb5d599a49a8d4f81db89d93120bf22f7f6a92905c52

See more details on using hashes here.

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