chdb-io / chdb

chDB is an in-process OLAP SQL Engine 🚀 powered by ClickHouse
https://clickhouse.com/docs/en/chdb
Apache License 2.0
2.03k stars 72 forks source link

Add formatQuery from Clickhouse “Other” Functions #185

Closed emirkmo closed 8 months ago

emirkmo commented 8 months ago

Use case

In CI, I want to check compiled/generated sql. (Say from DBT or from a tool to generate Clickhouse migrations). The main Clickhouse binary is way too large for this. Even the smallest docker image is nearly 1GB. Would be awesome to be able to run the ‘formatQuery’ function.

https://clickhouse.com/docs/en/sql-reference/functions/other-functions#formatquery

(clickhouse-format the tool still requires the full Clickhouse binary.)

Describe the solution you'd like

“Simply” add support for formatQuery function within the supported sql for chdb. That would be enough.

auxten commented 8 months ago

I think it's already supported:

Python 3.11.3 (v3.11.3:f3909b8bc8, Apr  4 2023, 20:12:10) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import chdb
>>> chdb.chdb_version
('1', '2', '0')
>>> chdb.query("SELECT formatQuery('select a,    b FRom tab WHERE a > 3 and  b < 3');")
"SELECT
    a,
    b
FROM tab
WHERE (a > 3) AND (b < 3)"