Geometry: both clients throw for a Geometry value that holds a MultiPoint (discriminator 6), and MultiPoint is an unknown type
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 57/100
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
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 theGeometryis insideArray,TupleorMap. - TCP client (
QueryAsync):ClickHouseTcpProtocolException("has discriminator 6 ... declares only 6 alternative(s)"), also insideArray,TupleorMap. - A
MultiPointcolumn 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
- Start ClickHouse 26.8 or later.
- Run the program below in a
net10.0console project that referencesClickHouse.Driver(with<NoWarn>CHTCP0001</NoWarn>for the TCP client).CLICKHOUSE_HOSTdefaults tolocalhost.
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, andVariantType.Read(ClickHouse.Driver/Types/VariantType.cs:54) indexes that array with the discriminator. There is noMultiPointtype inTypeConverter(ClickHouse.Driver/Types/TypeConverter.cs:179). - TCP:
GeometryStructure(ClickHouse.Driver.Tcp/Types/Codecs/GeoColumnCodecs.cs:42) is aVariantof the six older alternatives, soVariantColumnCodecrejects the discriminator 6.ColumnCodecRegistry(ClickHouse.Driver.Tcp/Types/ColumnCodecRegistry.cs:238) has noMultiPointentry.
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:
mainat 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
MultiPointtype; 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
- 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