AggregateFunction: GetDataTypeName, GetFieldType, GetSchemaTable and GetSchema("Columns") throw, and the message suggests a query that the server rejects
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
Research direction
Start with AggregateFunctionType.cs, then trace the metadata calls in ClickHouseDataReader.cs and SchemaDescriber.cs, plus header parsing in TupleType.cs. Review the AggregateFunction type parsing and the existing FrameworkType behavior to determine how metadata should represent this column. Done means metadata calls succeed with the server's type name, value reads still throw, and the suggested merge query preserves the function name and parameters.
Written by the indexing model from the issue text.
Description
Describe the bug
In the HTTP client, the metadata of an AggregateFunction column cannot be read. These calls throw AggregateFunctionException, the same exception as a read of a value:
ClickHouseDataReader.GetDataTypeName,GetFieldType, andGetSchemaTable()connection.GetSchema("Columns", ...)when a table in its scope has anAggregateFunctioncolumn. So the column list of a database, or of the whole server, fails because of oneAggregatingMergeTreetable.
GetName works. A query that returns a Tuple with an AggregateFunction element fails already in ExecuteReaderAsync.
The message also suggests a query that the server rejects:
- From server 26.10, the server writes the state version of
uniqin the type name (AggregateFunction(1, uniq, UInt64)), also for a column created asAggregateFunction(uniq, UInt64). The message then namesAggregateFunction(1)and1Merge(). - For a function with parameters, the message names
quantilesMerge()with no parameters.
The docs say that the values cannot be read ("AggregateFunction columns" in docs/http.mdx). This issue is about the metadata and the message. Not affected: the TCP client, whose message skips the version and keeps the parameters.
Steps to reproduce
- Start a ClickHouse 26.11 server.
- Put the code example in a directory one level below a clone of this repository (for example
repro/app.cs). - Run
CLICKHOUSE_CONNECTION="Host=localhost" dotnet run app.cs.
Expected behaviour
The metadata calls describe the column with the type name of the server, and only a read of a value throws. The server reports (curl, same table as the code example):
SELECT name, type FROM system.columns WHERE database = 'default' AND table = 't_agg'
k UInt8
u AggregateFunction(1, uniq, UInt64)
q AggregateFunction(quantiles(0.5, 0.9), Float64)
The ClickHouse docs: "A versioned aggregate function spells a non-zero state version out as the first argument of the type string", and "The function name may carry parameters" (Native format).
The message names a query that works. The two suggested queries fail on the server:
SELECT 1Merge(u) FROM t_agg
Code: 46. DB::Exception: Function with name `1Merge` does not exist. ... (UNKNOWN_FUNCTION)
SELECT quantilesMerge(q) FROM t_agg
Code: 42. DB::Exception: Aggregate function for calculation of multiple quantiles require at least one parameter. (NUMBER_OF_ARGUMENTS_DOESNT_MATCH)
SELECT uniqMerge(u), quantilesMerge(0.5, 0.9)(q) FROM t_agg
1 [1,1]
Code example
Reproduction program (C#, 26 lines)
#:project ../ClickHouse.Driver/ClickHouse.Driver.csproj
using ClickHouse.Driver.ADO;
using ClickHouse.Driver.Utility;
var cs = Environment.GetEnvironmentVariable("CLICKHOUSE_CONNECTION") ?? "Host=localhost";
using var connection = new ClickHouseConnection(cs);
await connection.ExecuteStatementAsync("CREATE OR REPLACE TABLE t_agg (k UInt8, u AggregateFunction(uniq, UInt64), q AggregateFunction(quantiles(0.5, 0.9), Float64)) ENGINE = AggregatingMergeTree ORDER BY k");
void Try(string label, Func<object> f)
{
try { Console.WriteLine($"{label}: {f()}"); }
catch (Exception e) { Console.WriteLine($"{label}: {e.GetType().Name}: {e.Message}"); }
}
using (var reader = await connection.ExecuteReaderAsync("SELECT k, u, q FROM t_agg"))
{
Try("GetName(1)", () => reader.GetName(1));
Try("GetDataTypeName(1)", () => reader.GetDataTypeName(1));
Try("GetDataTypeName(2)", () => reader.GetDataTypeName(2));
Try("GetFieldType(1)", () => reader.GetFieldType(1));
Try("GetSchemaTable()", () => reader.GetSchemaTable()!.Rows.Count);
}
Try("GetSchema(Columns, [default, t_agg])", () => connection.GetSchema("Columns", new[] { "default", "t_agg" }).Rows.Count);
Try("GetSchema(Columns, [default])", () => connection.GetSchema("Columns", new[] { "default" }).Rows.Count);
await connection.ExecuteStatementAsync("DROP TABLE t_agg");
Try("GetSchema(Columns, [default]) after DROP", () => connection.GetSchema("Columns", new[] { "default" }).Rows.Count);
Error log
GetName(1): u
GetDataTypeName(1): AggregateFunctionException: Unable to directly query column with type AggregateFunction(1). Use 1Merge() function to query this value
GetDataTypeName(2): AggregateFunctionException: Unable to directly query column with type AggregateFunction(quantiles). Use quantilesMerge() function to query this value
GetFieldType(1): AggregateFunctionException: Unable to directly query column with type AggregateFunction(1). Use 1Merge() function to query this value
GetSchemaTable(): AggregateFunctionException: Unable to directly query column with type AggregateFunction(1). Use 1Merge() function to query this value
GetSchema(Columns, [default, t_agg]): AggregateFunctionException: Unable to directly query column with type AggregateFunction(1). Use 1Merge() function to query this value
GetSchema(Columns, [default]): AggregateFunctionException: Unable to directly query column with type AggregateFunction(1). Use 1Merge() function to query this value
GetSchema(Columns, [default]) after DROP: 0
Root cause
AggregateFunctionType.ToString() and FrameworkType throw (ClickHouse.Driver/Types/AggregateFunctionType.cs:23 and :14). GetDataTypeName (ClickHouse.Driver/ADO/Readers/ClickHouseDataReader.cs:254), GetSchemaTable() (ClickHouse.Driver/Utility/SchemaDescriber.cs:47) and GetSchema("Columns") (SchemaDescriber.cs:132) call them, and TupleType reads FrameworkType when it parses the header (ClickHouse.Driver/Types/TupleType.cs:51). Parse keeps only the value of the first argument as the function (AggregateFunctionType.cs:18): for a versioned state that is the version, and the parameters are lost.
The fix needs a decision: which .NET type GetFieldType and the DataType of the schema rows give for such a column, because FrameworkType throws on purpose (ClickHouse.Driver/ADO/Readers/ColumnSlotFactory.cs:84). Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related
#804 (open): SimpleAggregateFunction drops the function parameters from the type name.
#506 (open): builds AggregateFunctionType from the binary type encoding with the function name only.
Configuration
Environment
- Client version: 1.7.0 (
mainat c58178ed) - .NET version: .NET SDK 11.0.100, runtime .NET 11.0.0
- OS: Linux (container)
ClickHouse server
- ClickHouse Server version: 26.11.7.10
- ClickHouse Server non-default settings, if any: none
Classification: impact: none · area: API & diagnostics (ADO.NET metadata)
Found by automated analysis (Polyglot AI) while working on clickhouse-cs#804. Verified against a live server.
- Dominant language
- C#
- Stars
- 102
- Forks
- 31
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 40
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ClickHouse/clickhouse-cs
-
bug documentation queries
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ClickHouse/clickhouse-cs#815 ·
Maintainers usually reply within 1 day
-
bug data-types native-format
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ClickHouse/clickhouse-cs#813 ·
Maintainers usually reply within 1 day
-
bug data-types documentation
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ClickHouse/clickhouse-cs#811 ·
Maintainers usually reply within 1 day
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ClickHouse/clickhouse-cs#809 ·
Maintainers usually reply within 1 day
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ClickHouse/clickhouse-cs#806 · 1 comment ·
Maintainers usually reply within 1 day
All issues in ClickHouse/clickhouse-cs
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
XML grammar: only the closing --> of a comment gets the scope comment.block.xmlPossibly taken @alexeyfala claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
danipen/TextMateSharp#145 · 2 comments ·
-
good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Klyroo/klyroo-dashboard#12 ·
Maintainers usually reply within 1 day
-
CONTRIBUTING rules Node out in step 0, then tells client-side contributors to run node --test, which is what CI gates onPossibly taken @yadavraj2001 claimed this today. Opendocumentation good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
juandresrodca/AdminForge#73 · 1 comment ·
Maintainers usually reply within 1 day
-
[辞書] VIVANTOpen要トリアージ 辞書
Difficulty 1/5 Under an hour Newbie friendliness 70/100
Maintainers usually reply within 1 day