Type parser: malformed names give a column of another type ("Array Int32" gives Int32, "Array(Int32, String)" gives Array(Int32))
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
Start with clickhouse/types/type_parser.cpp at the TypeParser::Parse branches for Token::Assign, Token::Comma, and Token::Name, then inspect the argument checks in clickhouse/columns/factory.cpp for Array, Decimal, and SimpleAggregateFunction. Compare the parser and factory behavior with the malformed names in the reproduction program; done means each is rejected with nullptr or ValidationError, as the issue describes.
由索引模型根據 Issue 內容生成。
描述
Describe the bug
CreateColumnByType() accepts three kinds of malformed type names that the server rejects, and returns a column of another type with no error:
=in place of,:Map(String = Int32)givesMap(String, Int32), andDecimal(9 = 2)givesDecimal(9,2). The same occurs inTupleandDateTime64.- Two type names in one place: the second name replaces the first.
Array Int32givesInt32, andNullable(Int32 String)givesNullable(String). The same occurs at the top level (Int32 Int64givesInt64) and inMapandLowCardinalityarguments. - Too many arguments: the client ignores the extra arguments, or uses the last one.
Array(Int32, String)givesArray(Int32),Decimal(9, 2, 3)givesDecimal(9,3), andSimpleAggregateFunction(sum, UInt64, String)givesString. The same occurs inNullable,LowCardinality,FixedString,DateTime64, andDecimal32.
Thus a typo in a type name gives a column of another type, while other names that do not parse give nullptr (Array(Int32) or a ValidationError (too few arguments: Map(String), Array()). The read path of Select() (clickhouse/client.cpp:862) uses the same parser, but a correct server sends only valid type names.
Steps to reproduce
Reproduction program (C++, 15 lines)
// Prints the column type that CreateColumnByType returns for each argument.
#include <clickhouse/columns/factory.h>
#include <cstdio>
#include <exception>
int main(int argc, char** argv) {
for (int i = 1; i < argc; ++i) {
try {
auto col = clickhouse::CreateColumnByType(argv[i]);
std::printf("%-46s -> %s\n", argv[i], col ? col->Type()->GetName().c_str() : "nullptr");
} catch (const std::exception& e) {
std::printf("%-46s -> exception: %s\n", argv[i], e.what());
}
}
}
Linked with libclickhouse-cpp-lib.a of a Debug build with -fsanitize=address,undefined (no sanitizer report):
$ ./type_names 'Map(String = Int32)' 'Decimal(9 = 2)' 'Array Int32' 'Nullable(Int32 String)' \
'Array(Int32, String)' 'Decimal(9, 2, 3)' 'SimpleAggregateFunction(sum, UInt64, String)' 'Array(Int32'
Map(String = Int32) -> Map(String, Int32)
Decimal(9 = 2) -> Decimal(9,2)
Array Int32 -> Int32
Nullable(Int32 String) -> Nullable(String)
Array(Int32, String) -> Array(Int32)
Decimal(9, 2, 3) -> Decimal(9,3)
SimpleAggregateFunction(sum, UInt64, String) -> String
Array(Int32 -> nullptr
Expected behavior
CreateColumnByType() returns nullptr or throws ValidationError for each of these names, as it does for Array(Int32 and Map(String). The server rejects all of them (SELECT defaultValueOfTypeName('<name>'), messages cut):
Map(String = Int32) Code: 62. Syntax error (data type): failed at position 12 (=)
Decimal(9 = 2) Code: 43. Decimal argument precision is invalid
Array Int32 Code: 62. Syntax error (data type): failed at position 7 (Int32): Int32. Expected end of query
Nullable(Int32 String) Code: 62. Syntax error (data type): failed at position 16 (String)
Array(Int32, String) Code: 42. Array data type family must have exactly one argument - type of elements
Decimal(9, 2, 3) Code: 42. Decimal data type family must have precision and optional scale arguments
SimpleAggregateFunction(sum, UInt64, String) Code: 42. Aggregate function sum requires single argument
Root cause
TypeParser::ParsehandlesToken::AssignandToken::Commain one branch (clickhouse/types/type_parser.cpp:232-233), so=separates arguments in every type, not only inEnumitems.- The
Token::Namebranch (type_parser.cpp:199-204) moves the first name intoelement_namewhen a second name follows, on every node, not only on aTupleelement. OutsideTuple, the factory ignoreselement_name. CreateColumnFromAstandCreateTerminalColumn(clickhouse/columns/factory.cpp) read the arguments by position withGetASTChildElement(for exampleArrayat:163,Decimalthe first and the last argument at:94,SimpleAggregateFunctionthe last at:285) and do not check the argument count, as theMapcase does.
The fix is in TypeParser::Parse and in the argument checks of the factory. Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related
- #616 (open) changes the
Enumparsing, which uses the same=/,branch. - #643 (open): another malformed name,
(Int32), with another cause (uninitialized root node).
Environment
- clickhouse-cpp:
master6049285 (v2.6.2 has the same parser code) - ClickHouse server: 26.11.7.10
- clang 18.1.3, Linux x86_64 (Ubuntu 24.04)
Classification: impact: none · area: Data types & formats (type names) · native: format
Found by automated analysis (Polyglot AI) while working on ClickHouse/clickhouse-rs#578. Verified against a live server.
- 主要語言
- C
- 星號
- 388
- 分支
- 220
- 平均合併
- 1 天 25 分鐘
- 30 天內合併 PR
- 16
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
ClickHouse/clickhouse-cpp 的其他 Issue
-
bug data-types
難度 2/5 1-3 小時 新手友好度 76/100
ClickHouse/clickhouse-cpp#645 ·
維護者通常 1 天內回覆
-
bug queries
難度 2/5 1-3 小時 新手友好度 79/100
ClickHouse/clickhouse-cpp#644 ·
維護者通常 1 天內回覆
-
bug data-types native-format
難度 2/5 1-3 小時 新手友好度 82/100
ClickHouse/clickhouse-cpp#643 ·
維護者通常 1 天內回覆
-
bug connectivity native-protocol
難度 2/5 1-3 小時 新手友好度 78/100
ClickHouse/clickhouse-cpp#638 ·
維護者通常 1 天內回覆
-
Core SQL test harness: ParseSetAssignments does not skip comments inside SET可能已有人在做 @puretechteam 於 12 天前認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 85/100
ClickHouse/clickhouse-cpp#626 · 1 則留言 ·
維護者通常 1 天內回覆
查看 ClickHouse/clickhouse-cpp 的全部 Issue
相似的 Issue
-
CF_CFDP_S_SendFileData computes the file checksum from the SB buffer after CFE_SB_TransmitBuffer未關閉
難度 2/5 1-3 小時 新手友好度 78/100
-
needs triage
難度 2/5 1-3 小時 新手友好度 72/100
389ds/389-ds-base#8251 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 70/100
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100