Skip to content

Commit c782c68

Browse files
authored
Create DEVELOPMENT.md
1 parent 17c249b commit c782c68

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

DEVELOPMENT.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# chsql for DuckDB
2+
3+
Hello stranger!
4+
5+
This DuckDB extension implements various macros using ClickHouse SQL syntax, making it easier to transition knowledge, users and scripts between the two database systems. Since ClickHouse has hundreds of commands, this extension is a perpetual WIP.
6+
7+
## JOIN & HELP
8+
9+
Here's how you can help this extension by adding, fixing or extending its scope of SQL macros:
10+
11+
1) Find a ClickHouse function you are interested into the in [functions list](https://clickhouse.com/docs/en/sql-reference/functions)
12+
2) Find if [DuckDB functions](https://duckdb.org/docs/sql/functions/) offer a viable method to alias the target function
13+
3) Create the macro and extend to neighboring class functions with similar scope
14+
15+
16+
## Examples
17+
18+
Here's a couple random examples:
19+
20+
#### ClickHouse [`tuplePlus`](https://clickhouse.com/docs/en/sql-reference/functions/tuple-functions#tupleplus)
21+
Calculates the sum of corresponding values of two tuples of the same size.
22+
23+
##### Syntax
24+
```
25+
tuplePlus(tuple1, tuple2)
26+
27+
```
28+
29+
##### Arguments
30+
31+
```
32+
tuple1 — First tuple. [Tuple](https://clickhouse.com/docs/en/sql-reference/data-types/tuple).
33+
tuple2 — Second tuple. [Tuple](https://clickhouse.com/docs/en/sql-reference/data-types/tuple).
34+
```
35+
##### Returned value
36+
37+
Tuple with the sum. [Tuple](https://clickhouse.com/docs/en/sql-reference/data-types/tuple).
38+
39+
##### Example
40+
41+
42+
Query:
43+
```
44+
SELECT tuplePlus((1, 2), (2, 3));
45+
46+
```
47+
Result:
48+
49+
```
50+
┌─tuplePlus((1, 2), (2, 3))─┐
51+
│ (3,5) │
52+
└───────────────┘
53+
```
54+
55+
### DuckDB Macro
56+
57+
Let's convert our function to a DuckDB equivalent macro using a lambda function or any other method:
58+
59+
```
60+
CREATE OR REPLACE MACRO tuplePlus(a, b) AS (apply(a, (x,i) -> apply(b, x -> CAST(x AS BIGINT))[i] + CAST(x AS BIGINT)));
61+
```
62+
63+
64+
#### Example
65+
Query:
66+
```
67+
SELECT tuplePlus([1, 2], [2, 3]);
68+
69+
```
70+
Result:
71+
72+
```
73+
tupleplus(main.list_value(1, 2), main.list_value(2, 3))
74+
--
75+
[3,5]
76+
```
77+
78+
79+
<br>
80+
81+
### Submit a PR
82+
83+
- If you're an SQL wizard, just add your new function(s) to the `aliases.sql` index for testing and validation.
84+
- If you're a developer, implement the new function(s) directly in the [source code](chsql_macros) and submit a full PR.
85+
- If you're a pro, you can also implement a test case for your new function(s) in the `tests/sql` directory.
86+
87+
<br>
88+
89+
👍 That's it! Simpler functions are trivial while others are puzzles. Have fun!

0 commit comments

Comments
 (0)