Repository navigation
Open
Labels
bugclientModule: the client (client-v2; with legacy: the v1 client)data-typesArea: type names, value encoding and decoding, row mapping, data formatsdocumentationImprovements or additions to documentationjdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)native-formatNative code: the Native format codec (blocks, type names, column bytes)
Description
Description
Problem Analysis:
Core issue: An error occurs when executing a query against the default.nm_advert_stats_daily table via the JDBC driver (DBeaver), whereas a direct query using the native ClickHouse client works correctly.
Key points:
- Error:
Unknown aggregate function: avgIfoccurs when querying via JDBC. - Direct query in the ClickHouse console executes successfully.
- The table uses aggregate functions in its columns:
position_avg_state AggregateFunction(avgIf, Float64, UInt8)position_quantiles_state AggregateFunction(quantilesTDigestIf(0.5, 0.9, 0.95), Float64, UInt8)
Software versions:
- ClickHouse Server: 24.8.8
- JDBC Driver: Official ClickHouse driver (server version 21.3+)
The Problem: There is an incompatibility between the JDBC driver version and the ClickHouse server version. The driver does not recognize the syntax of the aggregate functions (avgIf) that are supported by the server.
Solutions suggested by the participants:
- Fix JDBC driver is up to date due to we can't use native client for Trino and Dbeaver
Steps to reproduce
Error Log or Exception StackTrace
Trino try to select
select *
from table(ads_ch_ch.system.query(
query => 'select * from default.nm_advert_stats_daily limit 100'
)); -- this is native clickhouse execution
QL Error [65536]: Query failed (#20260407_141005_02502_hqy64): com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalArgumentException: Unknown aggregate function: avgIf
Expected Behaviour
Code Example
Configuration
Client Configuration
Environment
- Cloud
- Client version:
- Language version:
- OS:
ClickHouse Server
- ClickHouse Server version:
- ClickHouse Server non-default settings, if any:
CREATE TABLEstatements for tables involved:- Sample data for all these tables, use clickhouse-obfuscator if necessary
Reacted by ilyas, Michael Pavlov, navinweb and Ivan Uvarov
Metadata
Metadata
Assignees
Labels
bugclientModule: the client (client-v2; with legacy: the v1 client)data-typesArea: type names, value encoding and decoding, row mapping, data formatsdocumentationImprovements or additions to documentationjdbcModule: the JDBC driver (jdbc-v2; with legacy: the v1 driver)native-formatNative code: the Native format codec (blocks, type names, column bytes)
Activity
YuriyGavrilov commentedon Apr 12, 2026
Hi @den-crane may be you know somebody from java to tag here? thank you forward 🙏🏻
den-crane commentedon Apr 13, 2026
select *, it will return avgIf state (AggregateFunction), only ClickHouse server is able to read it.You should use avgIfMerge:
select avgIfMerge(x) from nm_advert_stats_daily=> 333.1Or finalizeAggregation:
select finalizeAggregation(x) from nm_advert_stats_daily=> 333.13. Nobody should use
AggregateFunction(avgIfit makes no sense. Instead ofavgIfStateone should useavgStateIf!!!!YuriyGavrilov commentedon Apr 13, 2026
Thx @den-crane I will refer this issue to trino. But strange think that direct connection from dbeaver got same. So only native works fine.
den-crane commentedon Apr 13, 2026
I see, then the issue is in ClickHouse jdbc. But it's a very minor issue. States are unusable anyway. You have to finalize them in ClickHouse server anyway.
den-crane commentedon Apr 13, 2026
BTW, all quantiles AggregateFunction states, including quantilesTDigest stores a state that can be evaluated to any quantile.
So
quantilesTDigest(0.5), Float64can be used with any quantilesTDigestMerge(0.01, 0.05, 0.5, 0.66661 ...)chernser commentedon Apr 13, 2026
@den-crane thank you for the detailed explanation. We need to add similar to our documentation.
@YuriyGavrilov thank you for reporting the issue. We plan to make partial support of
AggregateFunctionandSimpleAggregateFunctiontypes in the future. However as @den-crane state should be resolved on server side.I will keep the issue open because we have no clear documentation about usage of this type in JDBC/Client.
YuriyGavrilov commentedon Apr 13, 2026
Just put it here for history and logs and thanks a lot for the details and explanations
This is Trino way to connect:
Direct Dbeaver connection (second way)
Anoter clickhouse server and other bi tool ( not dbeaver )
den-crane commentedon Apr 13, 2026
@chernser about SimpleAggregateFunction, please discuss it with ClickHouse core team.
see ClickHouse/ClickHouse#27668
There is no need to return type
SimpleAggregateFunction(min, UInt64), ClickHouse server can returnUInt64instead.YuriyGavrilov commentedon Jul 28, 2026
Hi, any update on it Guys? @den-crane @chernser
chernser commentedon Jul 28, 2026
@YuriyGavrilov
we will look into it soon - but I have no exact estimates.
Sorry for the delay.
polyglotAI-bot commentedon Nov 27, 2026
Recommendation: Keep open — fix needed
Most of the docs part is on
main(docs/clickhouse-docs/jdbc.mdx:1343: onlygroupBitmapstates can be read, use-Merge). Left: the type-name parser rejects validAggregateFunctiontypes whose function has a combinator, so Trino cannot list such a table, and one docs row is wrong (Analysis).main: Reproduced on main — JDBC and client-v2 (RowBinaryWithNamesAndTypesandNative) fail withUnknown aggregate functionforavgIf,minIf, andquantilesTDigestIf.groupBitmap, a different limit).Analysis:
ClickHouseAggregateFunction.of(clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseAggregateFunction.java:188) accepts only the function names of its enum, so a name with a combinator such as-Iffails;ClickHouseColumn.java:477calls it for eachAggregateFunctiontype. Both readers parse the column types withClickHouseColumn.of(RowBinaryWithNamesAndTypesFormatReader.java:52,NativeFormatReader.java:204), and the Trino connector in the report calls it to list the columns. With no combinator (avg), the parse passes and the read fails, becauseBinaryStreamReader.java:291reads each state asgroupBitmap; the JDBC type table (docs/clickhouse-docs/jdbc.mdx:670) says thatAggregateFunctiongives a binary representation.Reproduction: complete program and output
Output on
main(8480ca001), ClickHouse 26.11.2.4:Automated triage by Polyglot AI. A maintainer makes the final decision.