Type-name parser (HTTP) accepts two type names in one place and extra arguments: ColumnTypes "Nullable String" stores NULL rows with no error
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 58/100
Research direction
Start with TypeConverter.ExtractTypeName in ClickHouse.Driver/Types/TypeConverter.cs and Parser.Parse in ClickHouse.Driver/Types/Grammar/Parser.cs, then inspect the named Parse methods in DecimalType.cs, DateTime64Type.cs, SimpleAggregateFunctionType.cs, and MapType.cs. Compare their handling of extra names and arguments with ArrayType and NullableType. Done means malformed type names raise ArgumentException before insertion; the issue gives examples to check.
Written by the indexing model from the issue text.
Description
Describe the bug
The HTTP client's type-name parser accepts three kinds of malformed type names that the server rejects, and reads each of them as another type with no error. The same defect was reported for clickhouse-cpp in https://github.com/ClickHouse/clickhouse-cpp/issues/646.
- Two type names in one place: the second name replaces the first.
Array Int32isInt32,Nullable StringisString,Nullable(Int32 String)isNullable(String), andMap(String Int64, Int32)isMap(Int64, Int32). The same occurs inArrayandLowCardinalityarguments, and at the top level (Int32 Int64isInt64). - A type name after the closing
): the last name replaces the type.Nullable(String) Int32isInt32, andDecimal(9, 2) Int32isInt32. - Too many arguments: the client ignores the extra arguments.
Decimal(9, 2, 3)isDecimal(9, 2),DateTime64(3, 'UTC', 'Asia/Tokyo')isDateTime64(3, 'UTC'),SimpleAggregateFunction(sum, UInt64, String)isSimpleAggregateFunction(sum, UInt64), andMap(String, Int32, Int64)isMap(String, Int32).
A malformed name in InsertOptions.ColumnTypes can store wrong rows with no error: InsertBinaryAsync writes the rows with the misread type, and the server reads the bytes with the real column type. With ColumnTypes["v"] = "Nullable String" (the parentheses missing), two rows "hello" and "world" are stored as 12 NULL rows, and the call returns 2.
Steps to reproduce
- Create a table with a
Nullable(String)column. - Insert two rows with
InsertBinaryAsync, withInsertOptions.ColumnTypesset toNullable String. - Read the table.
Expected behaviour
The client rejects a malformed type name with an ArgumentException that names the input, as it does for Map(String = Int32) (ArgumentException: Unknown type: String = Int32), and writes nothing. The server rejects these names (SELECT toTypeName(defaultValueOfTypeName('<name>')), messages cut):
Array Int32 Code: 62. Syntax error (data type): failed at position 7 (Int32): Int32. Expected end of query
Nullable String Code: 62. Syntax error (data type): failed at position 10 (String): String. Expected end of query
Nullable(Int32 String) Code: 62. Syntax error (data type): failed at position 16 (String)
Nullable(String) Int32 Code: 62. Syntax error (data type): failed at position 18 (Int32): Int32. Expected end of query
Decimal(9, 2, 3) Code: 42. Decimal data type family must have precision and optional scale arguments
DateTime64(3, 'UTC', 'Asia/Tokyo') Code: 42. DateTime64 data type can optionally have two argument - scale and time zone name
SimpleAggregateFunction(sum, UInt64, String) Code: 42. Aggregate function sum requires single argument
Map(String, Int32, Int64) Code: 42. Map data type family must have two arguments: key and value types
The server accepts an extra argument of DateTime and Time64 (DateTime('UTC', 'Asia/Tokyo') is DateTime('UTC')), and the client does the same. The TCP client of this repo rejects the names of the first two kinds (NotSupportedException, FormatException).
Code example
await client.ExecuteNonQueryAsync("CREATE TABLE t (v Nullable(String)) ENGINE = MergeTree ORDER BY tuple()");
var options = new InsertOptions { ColumnTypes = new Dictionary<string, string> { ["v"] = "Nullable String" } };
var n = await client.InsertBinaryAsync("t", new[] { "v" }, new[] { new object[] { "hello" }, new object[] { "world" } }, options);
Console.WriteLine(n); // 2, no exception
Console.WriteLine(await client.ExecuteScalarAsync("SELECT countIf(v IS NULL) FROM t")); // 12
await client.ExecuteNonQueryAsync("CREATE TABLE d (v Decimal(9, 3)) ENGINE = MergeTree ORDER BY tuple()");
options = new InsertOptions { ColumnTypes = new Dictionary<string, string> { ["v"] = "Decimal(9, 2, 3)" } };
await client.InsertBinaryAsync("d", new[] { "v" }, new[] { new object[] { 1.23m }, new object[] { 4.56m } }, options);
// SELECT v FROM d gives 0.123 and 0.456
Error log
InsertBinaryAsync, column Nullable(String), ColumnTypes "Nullable String", ["hello", "world"] -> returned 2; stored 12 rows, all NULL
InsertBinaryAsync, column Nullable(String), ColumnTypes "Nullable(String) String", ["hello", "world"] -> returned 2; stored 12 rows, all NULL
InsertBinaryAsync, column Nullable(Int32), ColumnTypes "Nullable(Int32 String)", ["hello", "world"] -> returned 2; stored 6 rows (1818585093, 1919907589, 4 x NULL)
InsertBinaryAsync, column Decimal(9, 3), ColumnTypes "Decimal(9, 2, 3)", [1.23, 4.56] -> returned 2; stored 0.123, 0.456
TypeConverter.ParseClickHouseType (the parser of ColumnTypes):
Array Int32 -> Int32
Nullable(Int32 String) -> Nullable(String)
Map(String Int64, Int32) -> Map(Int64, Int32)
LowCardinality(String Int32) -> LowCardinality(Int32)
Nullable(String) Int32 -> Int32
Decimal(9, 2, 3) -> Decimal32(2)
DateTime64(3, 'UTC', 'Asia/Tokyo') -> DateTime64(3, 'UTC')
SimpleAggregateFunction(sum, UInt64, String) -> SimpleAggregateFunction(sum, UInt64)
Map(String, Int32, Int64) -> Map(String, Int32)
Root cause:
TypeConverter.ExtractTypeName(ClickHouse.Driver/Types/TypeConverter.cs:257-266) removes the text before the first space as an element name on every node, not only on an element ofTuple,NestedorJSON.Parser.Parse(ClickHouse.Driver/Types/Grammar/Parser.cs:32) replacescurrentwith each new name, also after a)closed the node.DecimalType.Parse(DecimalType.cs:51-52),DateTime64Type.Parse(DateTime64Type.cs:29-34),SimpleAggregateFunctionType.Parse(SimpleAggregateFunctionType.cs:21-22) andMapType.Parse(MapType.cs:125-126) read the arguments by index and do not check their count, asArrayTypeandNullableTypedo withSingleChild.
The fix is in these three places. Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related: #806 (open) reports unbalanced parentheses in the same parser; its checks do not catch these names.
Configuration
Environment
- Client version: 1.7.0 (
mainat c58178ed) - Language version: C# (latest)
- .NET version: .NET 10 (
net10.0, SDK 11.0.100) - OS: Linux
ClickHouse server
- ClickHouse Server version: 26.11.7.10
Classification: impact: Data integrity · area: Data types & formats (type names, RowBinary insert)
Found by automated analysis (Polyglot AI) while checking clickhouse-cpp#646 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