Skip to content

Commit

Permalink
feat(generator): custom readme generator via on project folder
Browse files Browse the repository at this point in the history
  • Loading branch information
duyet committed Apr 16, 2024
1 parent e4bd49a commit 7e7bd6d
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 72 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 45 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ $ ls -lhp target/release | grep -v '/\|\.d'

```bash
$ cd /var/lib/clickhouse/user_scripts/
$ wget https://github.com/duyet/clickhouse-udf-rs/releases/download/0.1.8/clickhouse_udf_wkt_v0.1.8_x86_64-unknown-linux-musl.tar.gz
$ tar zxvf clickhouse_udf_wkt_v0.1.8_x86_64-unknown-linux-musl.tar.gz
$ wget https://github.com/duyet/clickhouse-udf-rs/releases/download/<version>/clickhouse_udf_wkt_v<version>_x86_64-unknown-linux-musl.tar.gz
$ tar zxvf clickhouse_udf_wkt_v<version>_x86_64-unknown-linux-musl.tar.gz

read-wkt-linestring

Expand All @@ -60,15 +60,15 @@ $ ls -lhp target/release | grep -v '/\|\.d'
<functions>
<!-- wkt -->
<function>
<name>readWktLinestring</name>
<name>readWktLineString</name>
<type>executable_pool</type>
<command>read-wkt-linestring</command>
<format>tabseparated</format>
<format>TabSeparated</format>
<argument>
<type>string</type>
<type>String</type>
<name>value</name>
</argument>
<return_type>string</return_type>
<return_type>String</return_type>
</function>

</functions>
Expand All @@ -82,7 +82,7 @@ $ ls -lhp target/release | grep -v '/\|\.d'
<summary>ClickHouse example queries</summary>

```sql
SELECT readWktLinestring('value');
SELECT readWktLineString("LINESTRING (30 10, 10 30, 40 40)")
```
</details>

Expand All @@ -96,8 +96,8 @@ $ ls -lhp target/release | grep -v '/\|\.d'

```bash
$ cd /var/lib/clickhouse/user_scripts/
$ wget https://github.com/duyet/clickhouse-udf-rs/releases/download/0.1.8/clickhouse_udf_vin_v0.1.8_x86_64-unknown-linux-musl.tar.gz
$ tar zxvf clickhouse_udf_vin_v0.1.8_x86_64-unknown-linux-musl.tar.gz
$ wget https://github.com/duyet/clickhouse-udf-rs/releases/download/<version>/clickhouse_udf_vin_v<version>_x86_64-unknown-linux-musl.tar.gz
$ tar zxvf clickhouse_udf_vin_v<version>_x86_64-unknown-linux-musl.tar.gz

vin-cleaner
vin-cleaner-chunk-header
Expand Down Expand Up @@ -125,34 +125,34 @@ $ ls -lhp target/release | grep -v '/\|\.d'
<name>vinCleaner</name>
<type>executable_pool</type>
<command>vin-cleaner</command>
<format>tabseparated</format>
<format>TabSeparated</format>
<argument>
<type>string</type>
<type>String</type>
<name>value</name>
</argument>
<return_type>string</return_type>
<return_type>String</return_type>
</function>
<function>
<name>vinManuf</name>
<type>executable_pool</type>
<command>vin-manuf</command>
<format>tabseparated</format>
<format>TabSeparated</format>
<argument>
<type>string</type>
<type>String</type>
<name>value</name>
</argument>
<return_type>string</return_type>
<return_type>String</return_type>
</function>
<function>
<name>vinYear</name>
<type>executable_pool</type>
<command>vin-year</command>
<format>tabseparated</format>
<format>TabSeparated</format>
<argument>
<type>string</type>
<type>String</type>
<name>value</name>
</argument>
<return_type>string</return_type>
<return_type>String</return_type>
</function>

</functions>
Expand Down Expand Up @@ -227,9 +227,12 @@ $ ls -lhp target/release | grep -v '/\|\.d'
<summary>ClickHouse example queries</summary>

```sql
SELECT vinCleaner('value');
SELECT vinManuf('value');
SELECT vinYear('value');
SELECT vinCleaner("1G1JC1249Y7150000")
SELECT vinCleaner("1G1JC1249Y7150000 ...")

SELECT vinManuf("1G1JC1249Y7150000")

SELECT vinYear("1G1JC1249Y7150000")
```
</details>

Expand All @@ -243,8 +246,8 @@ $ ls -lhp target/release | grep -v '/\|\.d'

```bash
$ cd /var/lib/clickhouse/user_scripts/
$ wget https://github.com/duyet/clickhouse-udf-rs/releases/download/0.1.8/clickhouse_udf_url_v0.1.8_x86_64-unknown-linux-musl.tar.gz
$ tar zxvf clickhouse_udf_url_v0.1.8_x86_64-unknown-linux-musl.tar.gz
$ wget https://github.com/duyet/clickhouse-udf-rs/releases/download/<version>/clickhouse_udf_url_v<version>_x86_64-unknown-linux-musl.tar.gz
$ tar zxvf clickhouse_udf_url_v<version>_x86_64-unknown-linux-musl.tar.gz

extract-url
has-url
Expand All @@ -268,23 +271,23 @@ $ ls -lhp target/release | grep -v '/\|\.d'
<name>extractUrl</name>
<type>executable_pool</type>
<command>extract-url</command>
<format>tabseparated</format>
<format>TabSeparated</format>
<argument>
<type>string</type>
<type>String</type>
<name>value</name>
</argument>
<return_type>string</return_type>
<return_type>String</return_type>
</function>
<function>
<name>hasUrl</name>
<type>executable_pool</type>
<command>has-url</command>
<format>tabseparated</format>
<format>TabSeparated</format>
<argument>
<type>string</type>
<type>String</type>
<name>value</name>
</argument>
<return_type>string</return_type>
<return_type>String</return_type>
</function>

</functions>
Expand All @@ -299,8 +302,10 @@ $ ls -lhp target/release | grep -v '/\|\.d'
<summary>ClickHouse example queries</summary>

```sql
SELECT extractUrl('value');
SELECT hasUrl('value');
SELECT extractUrl("extract from this https://duyet.net")

SELECT hasUrl("extract from this https://duyet.net")
SELECT hasUrl("no url here")
```
</details>

Expand All @@ -314,8 +319,8 @@ $ ls -lhp target/release | grep -v '/\|\.d'

```bash
$ cd /var/lib/clickhouse/user_scripts/
$ wget https://github.com/duyet/clickhouse-udf-rs/releases/download/0.1.8/clickhouse_udf_array_v0.1.8_x86_64-unknown-linux-musl.tar.gz
$ tar zxvf clickhouse_udf_array_v0.1.8_x86_64-unknown-linux-musl.tar.gz
$ wget https://github.com/duyet/clickhouse-udf-rs/releases/download/<version>/clickhouse_udf_array_v<version>_x86_64-unknown-linux-musl.tar.gz
$ tar zxvf clickhouse_udf_array_v<version>_x86_64-unknown-linux-musl.tar.gz

array-topk

Expand All @@ -335,15 +340,15 @@ $ ls -lhp target/release | grep -v '/\|\.d'
<functions>
<!-- array -->
<function>
<name>arrayTopk</name>
<name>arrayTopK</name>
<type>executable_pool</type>
<command>array-topk</command>
<format>tabseparated</format>
<format>TabSeparated</format>
<argument>
<type>string</type>
<type>String</type>
<name>value</name>
</argument>
<return_type>string</return_type>
<return_type>String</return_type>
</function>

</functions>
Expand All @@ -357,7 +362,8 @@ $ ls -lhp target/release | grep -v '/\|\.d'
<summary>ClickHouse example queries</summary>

```sql
SELECT arrayTopk('value');
SELECT arrayTopK(3)([1, 1, 2, 2, 3, 4, 5])
SELECT arrayTopK(1)([2, 3, 4, 5])
```
</details>

Expand All @@ -367,3 +373,4 @@ $ ls -lhp target/release | grep -v '/\|\.d'

MIT

Done
32 changes: 17 additions & 15 deletions README.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $ cargo build --release

$ ls -lhp target/release | grep -v '/\|\.d'
{% for project in projects -%}{% for bin in project.bins -%}
-rwxr-xr-x 1 duet staff 434K Feb 24 21:26 {{ bin}}
-rwxr-xr-x 1 duet staff 434K Feb 24 21:26 {{ bin.name }}
{% endfor %}{% endfor %}
```

Expand All @@ -35,7 +35,7 @@ $ ls -lhp target/release | grep -v '/\|\.d'
$ tar zxvf clickhouse_udf_{{ project.name }}_v{{ version }}_x86_64-unknown-linux-musl.tar.gz

{% for bin in project.bins -%}
{{ bin }}
{{ bin.name }}
{% endfor %}
```
</details>
Expand All @@ -53,17 +53,17 @@ $ ls -lhp target/release | grep -v '/\|\.d'
<functions>
<!-- {{ project.name }} -->
{% for bin in project.bins -%}
{% if bin is ending_with("-chunk-header") %}{% continue %}{% endif -%}
{% if bin.name is ending_with("-chunk-header") %}{% continue %}{% endif -%}
<function>
<name>{{ bin | to_clickhouse_function }}</name>
<name>{{ bin.udf_name }}</name>
<type>executable_pool</type>
<command>{{ bin }}</command>
<format>tabseparated</format>
<command>{{ bin.name }}</command>
<format>TabSeparated</format>
<argument>
<type>string</type>
<type>String</type>
<name>value</name>
</argument>
<return_type>string</return_type>
<return_type>String</return_type>
</function>
{% endfor %}
</functions>
Expand All @@ -72,7 +72,7 @@ $ ls -lhp target/release | grep -v '/\|\.d'

{% set_global count = 0 -%}
{% for bin in project.bins -%}
{% if bin is ending_with("-chunk-header") %}{% set_global count = count + 1 %}{% endif %}
{% if bin.name is ending_with("-chunk-header") %}{% set_global count = count + 1 %}{% endif %}
{% endfor -%}

{% if count > 0 %}
Expand All @@ -83,12 +83,12 @@ $ ls -lhp target/release | grep -v '/\|\.d'
<functions>
<!-- {{ project.name }} -->
{% for bin in project.bins -%}
{% if bin is not ending_with("-chunk-header") %}{% continue %}{% endif %}
{% if bin.name is not ending_with("-chunk-header") %}{% continue %}{% endif %}
<function>
<name>{{ bin | trim_end_matches(pat="-chunk-header") | to_clickhouse_function }}</name>
<name>{{ bin.udf_name }}</name>
<type>executable_pool</type>

<command>{{ bin }}</command>
<command>{{ bin.name }}</command>
<send_chunk_header>1</send_chunk_header>

<format>TabSeparated</format>
Expand All @@ -109,9 +109,11 @@ $ ls -lhp target/release | grep -v '/\|\.d'
<summary>ClickHouse example queries</summary>

```sql
{% for bin in project.bins -%}
{% if bin is ending_with("-chunk-header") %}{% continue %}{% endif -%}
SELECT {{ bin | to_clickhouse_function }}('value');
{%- for bin in project.bins -%}
{%- if bin.name is ending_with("-chunk-header") %}{% continue %}{% endif -%}
{%- for usage in bin.usages %}
{{ usage -}}
{% endfor %}
{% endfor -%}
```
</details>
Expand Down
6 changes: 6 additions & 0 deletions array/udf_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[array-topk]
udf_name = 'arrayTopK'
usages = [
'SELECT arrayTopK(3)([1, 1, 2, 2, 3, 4, 5])',
'SELECT arrayTopK(1)([2, 3, 4, 5])',
]
1 change: 1 addition & 0 deletions shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ cargo_toml = "0.19.2"
change-case = "0.2.0"
serde = { version = "^1.0.197", features = ["derive"] }
tera = "1.19.1"
toml = "0.8.12"
10 changes: 0 additions & 10 deletions shared/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
# Shared crates

This crate contains all the shared functions for UDFs implementation.

# README generator

```bash
# From the workspace root
cargo r --bin readme-generator . > README.md
```
Loading

0 comments on commit 7e7bd6d

Please sign in to comment.