Geometry: both clients throw for a Geometry value that holds a MultiPoint (discriminator 6), and MultiPoint is an unknown type

Open
#801 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
57/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
clickhouse, csharp, postgresql
Domain
backend, databases

Research direction

Start with ClickHouse.Driver/Types/GeometryType.cs, Types/TypeConverter.cs, Tcp/Types/Codecs/GeoColumnCodecs.cs, and Tcp/Types/ColumnCodecRegistry.cs, then inspect the existing Ring handling and the [type-multipoint] tests in tests/clickhouse-test-runner/allowlist.txt. Add MultiPoint support to both clients and as the seventh Geometry alternative; done means the supplied HTTP and TCP reproductions, including nested values and direct MultiPoint reads and inserts, work.

Written by the indexing model from the issue text.

Description

bug data-types native-format
Describe the bug

Both clients fail on a Geometry value that holds a MultiPoint. Since ClickHouse 26.8, MultiPoint is a geo type and the seventh alternative of Geometry. One such row makes the whole result fail:

  • HTTP client (ExecuteReaderAsync): IndexOutOfRangeException, also when the Geometry is inside Array, Tuple or Map.
  • TCP client (QueryAsync): ClickHouseTcpProtocolException ("has discriminator 6 ... declares only 6 alternative(s)"), also inside Array, Tuple or Map.
  • A MultiPoint column cannot be read or inserted in either client (Unknown type: MultiPoint, ClickHouse type 'MultiPoint' is not supported by this client).

Geometry values of the other six geo types read correctly. The same defect was reported for clickhouse-js in https://github.com/ClickHouse/clickhouse-js/issues/1282.

A tested workaround: relabel the member in SQL, if(variantType(g) = 'MultiPoint', CAST(CAST(variantElement(g, 'MultiPoint'), 'LineString'), 'Geometry'), g). Both clients then read the coordinates.

Steps to reproduce
  1. Start ClickHouse 26.8 or later.
  2. Run the program below in a net10.0 console project that references ClickHouse.Driver (with <NoWarn>CHTCP0001</NoWarn> for the TCP client). CLICKHOUSE_HOST defaults to localhost.
Expected behaviour

The clients return the rows that the server returns. In JSONEachRow the server returns {"id":1,"g":[1,2]} and {"id":2,"g":[[3,4],[5,6]]}. In RowBinary it sends the MultiPoint row as the discriminator 06, then an Array(Point) value (06 02 and four Float64). The RowBinary docs list the Geometry discriminators 0 to 6, with 6 = MultiPoint. The Native format docs say that the Geometry discriminators are fixed and that new geo types are only added at the end, so 0 to 5 keep their meaning.

Code example
Reproduction program (C#, 49 lines)
using ClickHouse.Driver;
using ClickHouse.Driver.Tcp;
using ClickHouse.Driver.Utility;

var host = Environment.GetEnvironmentVariable("CLICKHOUSE_HOST") ?? "localhost";
using var http = new ClickHouseClient($"Host={host};Port=8123");
await using var tcp = new ClickHouseTcpClient($"Host={host};Port=9000");

async Task Run(string label, Func<Task<List<string>>> read)
{
    try { Console.WriteLine($"{label}: {string.Join("; ", await read())}"); }
    catch (Exception e) { Console.WriteLine($"{label}: {e.GetType().Name}: {e.Message}"); }
}

async Task<List<string>> ReadHttp(string sql)
{
    var rows = new List<string>();
    using var reader = await http.ExecuteReaderAsync(sql);
    while (reader.Read()) rows.Add($"{reader.GetValue(0)} | {reader.GetValue(1)}");
    return rows;
}

async Task<List<string>> ReadTcp(string sql)
{
    var rows = new List<string>();
    await foreach (object[] row in tcp.QueryAsync(sql)) rows.Add($"{row[0]} | {row[1]}");
    return rows;
}

await http.ExecuteNonQueryAsync("DROP TABLE IF EXISTS geo_repro");
await http.ExecuteNonQueryAsync("CREATE TABLE geo_repro (id UInt8, g Geometry) ENGINE = MergeTree ORDER BY id");
await http.ExecuteNonQueryAsync("""
    INSERT INTO geo_repro SELECT 1, CAST(CAST((1, 2) AS Point) AS Geometry)
    UNION ALL SELECT 2, CAST(CAST([(3, 4), (5, 6)] AS MultiPoint) AS Geometry)
    """);

const string All = "SELECT id, g FROM geo_repro ORDER BY id";
const string PointOnly = "SELECT id, g FROM geo_repro WHERE id = 1";
const string MultiPoint = "SELECT 1 AS id, CAST([(3, 4), (5, 6)] AS MultiPoint) AS m";

await Run("server, variantType", () => ReadHttp("SELECT id, toString(variantType(g)) FROM geo_repro ORDER BY id"));
await Run("HTTP, Geometry column", () => ReadHttp(All));
await Run("HTTP, contrast without the MultiPoint row", () => ReadHttp(PointOnly));
await Run("HTTP, MultiPoint column", () => ReadHttp(MultiPoint));
await Run("TCP, Geometry column", () => ReadTcp(All));
await Run("TCP, contrast without the MultiPoint row", () => ReadTcp(PointOnly));
await Run("TCP, MultiPoint column", () => ReadTcp(MultiPoint));

await http.ExecuteNonQueryAsync("DROP TABLE geo_repro");
Error log
server, variantType: 1 | Point; 2 | MultiPoint
HTTP, Geometry column: IndexOutOfRangeException: Index was outside the bounds of the array.
HTTP, contrast without the MultiPoint row: 1 | (1, 2)
HTTP, MultiPoint column: ArgumentException: Unknown type: MultiPoint
TCP, Geometry column: ClickHouseTcpProtocolException: Variant column 'g' (Geometry) has discriminator 6 at row 1, but the type declares only 6 alternative(s).
TCP, contrast without the MultiPoint row: 1 | (1, 2)
TCP, MultiPoint column: ClickHouseTcpProtocolException: Column 'm' has type 'MultiPoint', which this client cannot read: ClickHouse type 'MultiPoint' is not supported by this client.
Root cause
  • HTTP: GeometryType (ClickHouse.Driver/Types/GeometryType.cs:8) lists only the six older alternatives, and VariantType.Read (ClickHouse.Driver/Types/VariantType.cs:54) indexes that array with the discriminator. There is no MultiPoint type in TypeConverter (ClickHouse.Driver/Types/TypeConverter.cs:179).
  • TCP: GeometryStructure (ClickHouse.Driver.Tcp/Types/Codecs/GeoColumnCodecs.cs:42) is a Variant of the six older alternatives, so VariantColumnCodec rejects the discriminator 6. ColumnCodecRegistry (ClickHouse.Driver.Tcp/Types/ColumnCodecRegistry.cs:238) has no MultiPoint entry.

The fix is a MultiPoint type in each client (the wire is Array(Point), as for Ring) and a seventh Geometry alternative at the end. The comments at GeometryType.cs:7 and ColumnCodecRegistry.cs:246 say that the order is name-sorted, but MultiPoint is 6, not between MultiLineString and MultiPolygon.

Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.

Related: tests/clickhouse-test-runner/allowlist.txt records these failures in the group [type-multipoint] (4 tests, both protocols) with "Issue: not filed yet".

Configuration
Environment
  • Client version: main at c58178ed (after 1.7.0)
  • Language version: C# 14
  • .NET version: .NET SDK 11.0.100, target net10.0
  • OS: Linux (container)
ClickHouse server
  • ClickHouse Server version: 26.11.7.10. ClickHouse 26.7 has no MultiPoint type; 26.8 sends the discriminator 6.
  • ClickHouse Server non-default settings, if any: none

Classification: impact: none · area: Data types & formats (Geometry, MultiPoint) · native: format


Found by automated analysis (Polyglot AI) while checking clickhouse-js#1282 against the other client repos. 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.