In answer to a github ticket regarding UDF of clickhouse, they answered in 2017 that UDF can't be created in clickhouse. I want to know Is there any way to do it now in 2020?
Asked
Active
Viewed 4,097 times
3
-
2At this moment UDF (user-defined functions) have not supported - see the reasons and actual discussions about it [UDF support #11](https://github.com/ClickHouse/ClickHouse/issues/11). – vladimir Jun 25 '20 at 22:25
-
1One workaround is to use executable dictionary source https://clickhouse.tech/docs/en/sql-reference/dictionaries/external-dictionaries/external-dicts-dict-sources/#dicts-external_dicts_dict_sources-executable. It is available since 21.3 release. You can create executable file, and call it as dictionary. – ice Mar 31 '21 at 11:26
-
+ look at this one https://stackoverflow.com/questions/71236415/how-to-send-multiple-arguments-to-executable-udf-in-clickhouse – vladimir Jul 24 '22 at 22:01
1 Answers
5
UDFs for ClickHouse came in September, 2021. There are two PRs introducing UDFs:
- UDF as an SQL expression, example:
CREATE FUNCTION plus_one as (a) -> a + 1
. I have tested this on ClickHouse v21.10.2.15 and it works (should be supported starting from v21.10). - UDF as an executable script. Such a function is defined within ClickHouse server configuration, see an example in the PR. This is an arbitrary script that reads data from stdin and outputs data to stdout in a supported format: CSV, TabSeparated, or others. The example uses
clickhouse-local
to process data incoming from ClickHouse server.
As a presentation from 2021 says, ClickHouse team considers five ways to define a UDF. One of alternative ways mentioned in an older presentation is a cache dictionary with an executable source.

Anton Bryzgalov
- 1,065
- 12
- 23