Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How call built-in functions in ClickHouse #16996

Closed
psharaev opened this issue Apr 12, 2023 · 2 comments
Closed

How call built-in functions in ClickHouse #16996

psharaev opened this issue Apr 12, 2023 · 2 comments

Comments

@psharaev
Copy link

Recently I had to make such a query:

select count(distinct group_id) from clickhouse.public.testtable;

But he worked very slowly, because not the most optimal execution plan was drawn up for him:

trino> explain select count(distinct group_id) from clickhouse.public.testtable;
                                                                                            Query Plan
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Trino version: testversion
 Fragment 0 [SOURCE]
     Output layout: [_pfgnrtd]
     Output partitioning: SINGLE []
     Output[columnNames = [_col0]]
     │   Layout: [_pfgnrtd:bigint]
     │   Estimates: {rows: ? (?), cpu: 0, memory: 0B, network: 0B}
     │   _col0 := _pfgnrtd
     └─ TableScan[table = clickhouse:Query[SELECT count("group_id") AS "_pfgnrtd_0" FROM (SELECT "group_id" FROM "public"."testtable" GROUP BY "group_id") o] columns=[_pfgnrtd_0:bigint:bigint]]
            Layout: [_pfgnrtd:bigint]
            Estimates: {rows: ? (?), cpu: ?, memory: 0B, network: 0B}
            _pfgnrtd := _pfgnrtd_0:bigint:bigint


(1 row)

But ClickHouse has a large number of built-in functions. One of them will allow me to execute my query much faster, namely uniqExact. And I would like to execute the following query:

trino> select uniq(val) from clickhouse.public.testtable;
Query 20230412_132742_00029_e9aab failed: line 1:7: Function 'uniq' not registered
LINE 1: select uniqExact(group_id) from clickhouse.public.testtable

But trino doesn't know anything about this function. Can I somehow call the built-in functions in ClickHouse (and basically any other data source)?

I found in the documentation how to create my own functions, but as I understand it, they allow you to implement my logic, but in no way provide access to existing functions

@psharaev
Copy link
Author

psharaev commented May 4, 2023

#1839 basically solves my problem

@ebyhr
Copy link
Member

ebyhr commented May 9, 2023

#1839 basically solves my problem

There's #16182 for ClickHouse connector.

@ebyhr ebyhr closed this as completed May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants