From 4e235d5438bf3cb21c59f5e2b9e0a09952a3c254 Mon Sep 17 00:00:00 2001 From: Lorenzo Mangani Date: Fri, 25 Oct 2024 16:27:26 +0200 Subject: [PATCH 1/5] Update function_descriptions.csv --- extensions/chsql/docs/function_descriptions.csv | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/extensions/chsql/docs/function_descriptions.csv b/extensions/chsql/docs/function_descriptions.csv index 35154b4..6757619 100644 --- a/extensions/chsql/docs/function_descriptions.csv +++ b/extensions/chsql/docs/function_descriptions.csv @@ -87,3 +87,20 @@ function,fun_type,description,comment,example "tupleMultiplyByNumber","macro","Multiplies each element of a tuple by a number","","SELECT tupleMultiplyByNumber((10, 20), 3);" "tuplePlus","macro","Performs element-wise addition between two tuples","","SELECT tuplePlus((1, 2), (3, 4));" "url","table_macro","Performs queries against remote URLs using the specified format","Supports JSON, CSV, PARQUET, TEXT, BLOB","SELECT url('https://urleng.com/test','JSON');" +"JSONExtract","macro","Extracts JSON data based on key from a JSON object","","SELECT JSONExtract(json_column, 'user.name');" +"JSONExtractString","macro","Extracts JSON data as a VARCHAR from a JSON object","","SELECT JSONExtractString(json_column, 'user.email');" +"JSONExtractUInt","macro","Extracts JSON data as an unsigned integer from a JSON object","","SELECT JSONExtractUInt(json_column, 'user.age');" +"JSONExtractInt","macro","Extracts JSON data as a 32-bit integer from a JSON object","","SELECT JSONExtractInt(json_column, 'user.balance');" +"JSONExtractFloat","macro","Extracts JSON data as a double from a JSON object","","SELECT JSONExtractFloat(json_column, 'user.score');" +"JSONExtractRaw","macro","Extracts raw JSON data based on key from a JSON object","","SELECT JSONExtractRaw(json_column, 'user.address');" +"JSONHas","macro","Checks if a JSON key exists and is not null","","SELECT JSONHas(json_column, 'user.active');" +"JSONLength","macro","Returns the length of a JSON array","","SELECT JSONLength(json_column, 'items');" +"JSONType","macro","Determines the type of JSON element at the given path","","SELECT JSONType(json_column, 'user.data');" +"JSONExtractKeys","macro","Extracts keys from a JSON object","","SELECT JSONExtractKeys(json_column);" +"JSONExtractValues","macro","Extracts all values as text from a JSON object","","SELECT JSONExtractValues(json_column);" +"equals","macro","Checks if two values are equal","","SELECT equals(column_a, column_b);" +"notEquals","macro","Checks if two values are not equal","","SELECT notEquals(column_a, column_b);" +"less","macro","Checks if one value is less than another","","SELECT less(column_a, column_b);" +"greater","macro","Checks if one value is greater than another","","SELECT greater(column_a, column_b);" +"lessOrEquals","macro","Checks if one value is less than or equal to another","","SELECT lessOrEquals(column_a, column_b);" +"greaterOrEquals","macro","Checks if one value is greater than or equal to another","","SELECT greaterOrEquals(column_a, column_b);" From 6c17e595b8daef8271e46965b6c536d67bc44e28 Mon Sep 17 00:00:00 2001 From: Lorenzo Mangani Date: Fri, 25 Oct 2024 16:29:06 +0200 Subject: [PATCH 2/5] Update function_descriptions.csv --- extensions/chsql/docs/function_descriptions.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/chsql/docs/function_descriptions.csv b/extensions/chsql/docs/function_descriptions.csv index 6757619..fa0d821 100644 --- a/extensions/chsql/docs/function_descriptions.csv +++ b/extensions/chsql/docs/function_descriptions.csv @@ -104,3 +104,4 @@ function,fun_type,description,comment,example "greater","macro","Checks if one value is greater than another","","SELECT greater(column_a, column_b);" "lessOrEquals","macro","Checks if one value is less than or equal to another","","SELECT lessOrEquals(column_a, column_b);" "greaterOrEquals","macro","Checks if one value is greater than or equal to another","","SELECT greaterOrEquals(column_a, column_b);" +"dictGet","macro","Retrieves an attribute from a VARIABLE string or MAP","","SELECT dictGet('dictionary_name', 'attribute');" From be0785f1cc7b845b2bb2c440f11c413c74baacf4 Mon Sep 17 00:00:00 2001 From: Lorenzo Mangani Date: Thu, 7 Nov 2024 19:57:11 +0100 Subject: [PATCH 3/5] Update chsql docs --- extensions/chsql/docs/function_descriptions.csv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/chsql/docs/function_descriptions.csv b/extensions/chsql/docs/function_descriptions.csv index fa0d821..d0907f0 100644 --- a/extensions/chsql/docs/function_descriptions.csv +++ b/extensions/chsql/docs/function_descriptions.csv @@ -5,7 +5,7 @@ function,fun_type,description,comment,example "arrayJoin","macro","Unroll an array into multiple rows","","SELECT arrayJoin([1, 2, 3]);" "arrayMap","macro","Applies a function to each element of an array","","SELECT arrayMap(x -> x + 1, [1, 2, 3]);" "bitCount","macro","Counts the number of set bits in an integer","","SELECT bitCount(15);" -"ch_scan","table_macro","Query a remote ClickHouse server using HTTP/s API","Returns the query results","SELECT * FROM ch_scan('SELECT version()','https://play.clickhouse.com');;" +"ch_scan","table_macro","Query a remote ClickHouse server using HTTP/s API","Returns the query results","SELECT * FROM ch_scan('SELECT version()','https://play.clickhouse.com', format := 'parquet');" "domain","macro","Extracts the domain from a URL","","SELECT domain('https://clickhouse.com/docs');" "empty","macro","Check if a string is empty","","SELECT empty('');" "extractAllGroups","macro","Extracts all matching groups from a string using a regular expression","","SELECT extractAllGroups('(\\d+)', 'abc123');" @@ -86,7 +86,7 @@ function,fun_type,description,comment,example "tupleMultiply","macro","Performs element-wise multiplication between two tuples","","SELECT tupleMultiply((10, 20), (2, 5));" "tupleMultiplyByNumber","macro","Multiplies each element of a tuple by a number","","SELECT tupleMultiplyByNumber((10, 20), 3);" "tuplePlus","macro","Performs element-wise addition between two tuples","","SELECT tuplePlus((1, 2), (3, 4));" -"url","table_macro","Performs queries against remote URLs using the specified format","Supports JSON, CSV, PARQUET, TEXT, BLOB","SELECT url('https://urleng.com/test','JSON');" +"url","table_macro","Performs queries against remote URLs using the specified format","Supports JSON, CSV, PARQUET, TEXT, BLOB","SELECT * FROM url('https://urleng.com/test','JSON');" "JSONExtract","macro","Extracts JSON data based on key from a JSON object","","SELECT JSONExtract(json_column, 'user.name');" "JSONExtractString","macro","Extracts JSON data as a VARCHAR from a JSON object","","SELECT JSONExtractString(json_column, 'user.email');" "JSONExtractUInt","macro","Extracts JSON data as an unsigned integer from a JSON object","","SELECT JSONExtractUInt(json_column, 'user.age');" From 840f0d288a02a08eb1183dec9fcecd251d81bf83 Mon Sep 17 00:00:00 2001 From: Lorenzo Mangani Date: Thu, 7 Nov 2024 19:59:14 +0100 Subject: [PATCH 4/5] Update ref to chsql 1.0.6 --- extensions/chsql/description.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/extensions/chsql/description.yml b/extensions/chsql/description.yml index e9c3476..cff8e8e 100644 --- a/extensions/chsql/description.yml +++ b/extensions/chsql/description.yml @@ -1,20 +1,21 @@ extension: name: chsql description: ClickHouse SQL Macros for DuckDB - version: 1.0.5 + version: 1.0.6 language: SQL & C++ build: cmake license: MIT maintainers: - lmangani + - akvlad repo: github: quackscience/duckdb-extension-clickhouse-sql - ref: a000d4f2a5f9e1c13cddcd75ea2d3351466f1706 + ref: 9ab2e8118dbb9e429fa8d2a9026ad019f5bf7706 docs: hello_world: | - -- Use ClickHouse SQL function macros in DuckDB SQL queries + -- Use boring ClickHouse SQL function macros in DuckDB SQL queries. Examples: SELECT toString('world') AS hello, toInt8OrZero('world') AS zero; ┌─────────┬───────┐ @@ -32,8 +33,8 @@ docs: │ 10.0.0.1 │ 167772161 │ └────────────────────────────┴─────────────────────────────┘ - -- Query a remote ClickHouse instance via HTTP/S API - SELECT * FROM ch_scan("SELECT number * 100 FROM numbers(3)","https://play.clickhouse.com"); + -- Query a remote ClickHouse instance via HTTP/S API using multiple formats + SELECT * FROM ch_scan("SELECT number * 100 FROM numbers(3)","https://play.clickhouse.com", format := 'Parquet'); ┌───────────────────────┐ │ multiply(number, 100) │ │ varchar │ From 572bb563022844960911d827f2748d054a66b2f4 Mon Sep 17 00:00:00 2001 From: Lorenzo Mangani Date: Sat, 4 Jan 2025 23:35:31 +0100 Subject: [PATCH 5/5] update chsql 1.0.7 --- extensions/chsql/description.yml | 52 +++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/extensions/chsql/description.yml b/extensions/chsql/description.yml index cff8e8e..9043e74 100644 --- a/extensions/chsql/description.yml +++ b/extensions/chsql/description.yml @@ -1,7 +1,7 @@ extension: name: chsql description: ClickHouse SQL Macros for DuckDB - version: 1.0.6 + version: 1.0.7 language: SQL & C++ build: cmake license: MIT @@ -11,13 +11,12 @@ extension: repo: github: quackscience/duckdb-extension-clickhouse-sql - ref: 9ab2e8118dbb9e429fa8d2a9026ad019f5bf7706 + ref: 16bcb5b0fda0ccca22f42695295f9bb4171190fb docs: hello_world: | -- Use boring ClickHouse SQL function macros in DuckDB SQL queries. Examples: - SELECT toString('world') AS hello, toInt8OrZero('world') AS zero; - + D SELECT toString('world') AS hello, toInt8OrZero('world') AS zero; ┌─────────┬───────┐ │ hello │ zero │ │ varchar │ int64 │ @@ -25,7 +24,7 @@ docs: │ world │ 0 │ └─────────┴───────┘ - SELECT IPv4NumToString(167772161), IPv4StringToNum('10.0.0.1'); + D SELECT IPv4NumToString(167772161), IPv4StringToNum('10.0.0.1'); ┌────────────────────────────┬─────────────────────────────┐ │ ipv4numtostring(167772161) │ ipv4stringtonum('10.0.0.1') │ │ varchar │ int32 │ @@ -34,7 +33,7 @@ docs: └────────────────────────────┴─────────────────────────────┘ -- Query a remote ClickHouse instance via HTTP/S API using multiple formats - SELECT * FROM ch_scan("SELECT number * 100 FROM numbers(3)","https://play.clickhouse.com", format := 'Parquet'); + D SELECT * FROM ch_scan("SELECT number * 100 FROM numbers(3)","https://play.clickhouse.com", format := 'Parquet'); ┌───────────────────────┐ │ multiply(number, 100) │ │ varchar │ @@ -44,6 +43,45 @@ docs: │ 200 │ └───────────────────────┘ + -- Query the emulated system tables to explore columns, rows, types, storage, etc + D SELECT * FROM system.tables; + D SELECT * FROM system.columns; + D SELECT * FROM system.functions; + D SELECT * FROM system.uptime; + D SELECT * FROM system.disks; + ┌──────────┬──────────────┬────────────┬─────────────┬──────────────────┬─────────────────┬─────────┬─────────────────────┬───────────────┬──────────────┬──────────────┬───────────────┬───────────┬───────────┬────────────┐ + │ name │ path │ free_space │ total_space │ unreserved_space │ keep_free_space │ type │ object_storage_type │ metadata_type │ is_encrypted │ is_read_only │ is_write_once │ is_remote │ is_broken │ cache_path │ + │ varchar │ varchar │ int64 │ int64 │ int64 │ int64 │ varchar │ varchar │ varchar │ boolean │ boolean │ boolean │ boolean │ boolean │ varchar │ + ├──────────┼──────────────┼────────────┼─────────────┼──────────────────┼─────────────────┼─────────┼─────────────────────┼───────────────┼──────────────┼──────────────┼───────────────┼───────────┼───────────┼────────────┤ + │ localdb │ test.db │ 0 │ 262144 │ 0 │ 0 │ Local │ None │ None │ false │ false │ false │ false │ false │ │ + │ memory │ NULL │ 0 │ 0 │ 0 │ 0 │ Local │ None │ None │ false │ false │ false │ false │ false │ │ + │ testduck │ /tmp/duck.db │ 262144 │ 786432 │ 262144 │ 0 │ Local │ None │ None │ false │ false │ false │ false │ false │ │ + └──────────┴──────────────┴────────────┴─────────────┴──────────────────┴─────────────────┴─────────┴─────────────────────┴───────────────┴──────────────┴──────────────┴───────────────┴───────────┴───────────┴────────────┘ extended_description: | - This extension implements a growing number of [ClickHouse SQL Macros](https://duckdb.org/community_extensions/extensions/chsql#added-functions) and functions for DuckDB. + + ## DuckDB ClickHouse SQL extension + The DuckDB chsql community extension implements 100+ popular [ClickHouse SQL Macros](https://duckdb.org/community_extensions/extensions/chsql#added-functions), functions and helpers making it easier for users to transition between OLAP systems ⭐ + + ### Motivation + DuckDB is our favourite OLAP engine but ClickHouse has lots of integrations and users. This extension is dedicated to ClickHouse refugeess. + + ``` + ✔ DuckDB SQL is awesome and full of great functions.
+ ✔ ClickHouse SQL is awesome and full of great functions. + + ✔ The DuckDB library is ~51M and modular. Can LOAD extensions.
+ ❌ The ClickHouse monolith is ~551M and growing. No extensions. + + ✔ DuckDB is open source and protected by a no-profit foundation.
+ ❌ ClickHouse is open core and controlled by for-profit corporation. + + ✔ DuckDB embedded is fast, mature and elegantly integrated in many languages.
+ ❌ chdb is still experimental, unstable and currently only supports Python. + ``` + + ### Extensions + - [chsql_native](https://duckdb.org/community_extensions/extensions/chsql_native) provides a native clickhouse client (binary) and a reader for ClickHouse Native format files + + #### Legal Disclaimer + > DuckDB ® is a trademark of DuckDB Foundation. ClickHouse® is a trademark of ClickHouse Inc. All trademarks, service marks, and logos mentioned or depicted are the property of their respective owners. The use of any third-party trademarks, brand names, product names, and company names is purely informative or intended as parody and does not imply endorsement, affiliation, or association with the respective owners.