SimpleAggregateFunction: GetDataTypeName and GetSchema drop the parameters of the aggregate function (groupUniqArrayArray(10) becomes groupUniqArrayArray)

Open Beginner friendly
#804 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
clickhouse, csharp

Research direction

Start with ClickHouse.Driver/Types/SimpleAggregateFunctionType.cs, especially Parse and ToString; the issue identifies where function parameters are dropped and which reader and schema paths use the result. Reproduce with the provided C# program against ClickHouse 26.11 and check GetDataTypeName, GetSchemaTable() and GetSchema("Columns"). Done when all report SimpleAggregateFunction(groupUniqArrayArray(10), Array(UInt8)) and the reproduction preserves the limit.

Written by the indexing model from the issue text.

Description

bug data-types
Describe the bug

For a SimpleAggregateFunction column whose aggregate function has parameters, the HTTP client reports the type name without the parameters. For the server type SimpleAggregateFunction(groupUniqArrayArray(10), Array(UInt8)), these give SimpleAggregateFunction(groupUniqArrayArray, Array(UInt8)):

  • ClickHouseDataReader.GetDataTypeName
  • the ProviderType of GetSchemaTable()
  • the ProviderType of connection.GetSchema("Columns", ...)

The reported name is a different type: a table created from it uses groupUniqArrayArray with no limit. In the code example, after 20 inserts and a merge, the original table keeps 10 values and the table created from the reported name keeps 20.

The values read correctly. Not affected: functions with no parameters (SimpleAggregateFunction(sum, UInt64)), and the TCP client (IColumn.TypeName gives the name of the server).

Steps to reproduce
  1. Start a ClickHouse 26.11 server.
  2. Put the code example in a directory one level below a clone of this repository (for example repro/app.cs).
  3. Run CLICKHOUSE_CONNECTION="Host=localhost" dotnet run app.cs.
Expected behaviour

The name that the server reports for the column (curl, same table as the code example):

SELECT type FROM system.columns WHERE database = 'default' AND table = 't_saf_src' AND name = 's'
SimpleAggregateFunction(groupUniqArrayArray(10), Array(UInt8))

The parameters are part of the type. The ClickHouse docs write the type as SimpleAggregateFunction(function_name(param_1, ..., param_N), arg_T1, ..., arg_TN) (Data types binary encoding).

Code example
Reproduction program (C#, 30 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);
const string type = "SimpleAggregateFunction(groupUniqArrayArray(10), Array(UInt8))";
await connection.ExecuteStatementAsync($"CREATE OR REPLACE TABLE t_saf_src (k UInt8, s {type}) ENGINE = AggregatingMergeTree ORDER BY k");

string name;
using (var reader = await connection.ExecuteReaderAsync("SELECT s FROM t_saf_src"))
{
    name = reader.GetDataTypeName(0);
    Console.WriteLine($"GetDataTypeName:    {name}");
    Console.WriteLine($"GetSchemaTable:     {reader.GetSchemaTable().Rows[0]["ProviderType"]}");
}
var columns = connection.GetSchema("Columns", new[] { "default", "t_saf_src" });
Console.WriteLine($"GetSchema(Columns): {columns.Rows[1]["ProviderType"]}");

// A table created from the reported name gets another aggregate function.
await connection.ExecuteStatementAsync($"CREATE OR REPLACE TABLE t_saf_copy (k UInt8, s {name}) ENGINE = AggregatingMergeTree ORDER BY k");
foreach (var table in new[] { "t_saf_src", "t_saf_copy" })
{
    for (var i = 0; i < 20; i++)
        await connection.ExecuteStatementAsync($"INSERT INTO {table} VALUES (1, [{i}])");
    await connection.ExecuteStatementAsync($"OPTIMIZE TABLE {table} FINAL");
    Console.WriteLine($"{table}: length(s) = {await connection.ExecuteScalarAsync($"SELECT length(s) FROM {table}")}");
}
await connection.ExecuteStatementAsync("DROP TABLE t_saf_src");
await connection.ExecuteStatementAsync("DROP TABLE t_saf_copy");
Error log

Output, the same in 2 of 2 runs:

GetDataTypeName:    SimpleAggregateFunction(groupUniqArrayArray, Array(UInt8))
GetSchemaTable:     SimpleAggregateFunction(groupUniqArrayArray, Array(UInt8))
GetSchema(Columns): SimpleAggregateFunction(groupUniqArrayArray, Array(UInt8))
t_saf_src: length(s) = 10
t_saf_copy: length(s) = 20
Root cause

SimpleAggregateFunctionType.Parse keeps only node.ChildNodes[0].Value, the bare function name, and drops the arguments of that node (ClickHouse.Driver/Types/SimpleAggregateFunctionType.cs:21). ToString() (line 28) builds the name from it, and GetDataTypeName (ClickHouse.Driver/ADO/Readers/ClickHouseDataReader.cs:254) and GetSchema("Columns") (ClickHouse.Driver/Utility/SchemaDescriber.cs:132) use ToString().

The fix is in the HTTP client only. Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.

Related

#506 (open) adds the binary type decoder of SimpleAggregateFunction (Dynamic, JSON); it also keeps only the function name.

Configuration
Environment
  • Client version: 1.7.0 (main at 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: Data types & formats (SimpleAggregateFunction)


Found by automated analysis (Polyglot AI) while working on clickhouse-rs#576. Verified against a live server.

Dominant language
C#
Stars
102
Forks
31
Avg merge
2d 13h
Merged PRs (30d)
40

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ClickHouse/clickhouse-cs

All issues in ClickHouse/clickhouse-cs

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.