[client-v2] insert(table, columnNames, ...) does not backtick-quote column identifiers with spaces or special characters
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
從 client-v2/src/main/java/com/clickhouse/client/api/Client.java 的1846–1857行附近開始,這裡會將欄位清單加入INSERT陳述式。檢查其他地方如何引用識別子,並檢視呼叫端已傳入帶引號名稱時的相容性問題。為包含空格和內嵌反引號的名稱新增或更新測試,然後確認產生的陳述式可與ClickHouse搭配使用。
由索引模型根據 Issue 內容生成。
描述
Description
Client.insert(String tableName, List<String> columnNames, ...) builds the INSERT INTO ... (cols) FORMAT ... statement by concatenating the caller-supplied column names verbatim, with no identifier quoting. Column names that require quoting in ClickHouse SQL (spaces, punctuation, etc.) produce an unparsable statement and the server rejects the insert with Code: 62 ... SYNTAX_ERROR.
client-v2/src/main/java/com/clickhouse/client/api/Client.java:1846-1857:
StringBuilder sqlStmt = new StringBuilder("INSERT INTO ").append(tableName);
if (columnNames != null && !columnNames.isEmpty()) {
sqlStmt.append(" (");
for (String columnName : columnNames) {
sqlStmt.append(columnName).append(", ");
}
sqlStmt.deleteCharAt(sqlStmt.length() - 2);
sqlStmt.append(")");
}
sqlStmt.append(" FORMAT ").append(format.name());
This affects all insert(...) overloads that take a List<String> columnNames (the InputStream overloads at Client.java:1720/1735 and the DataStreamWriter overloads at Client.java:1793/1810, which all funnel into the method above).
Inserts that do not pass columnNames are unaffected.
ClickHouse server version
26.11.2.4 (official build) — verified against a running server.
Reproduction
TestNG test (run in client-v2, pointed at a local server):
Client client = new Client.Builder()
.addEndpoint("http://localhost:8123")
.setUsername("default").setPassword("")
.compressClientRequest(false)
.build();
final String table = "scratch_quoting_table";
client.execute("DROP TABLE IF EXISTS " + table, new CommandSettings()).get(10, TimeUnit.SECONDS);
client.execute("CREATE TABLE " + table + " (`test id` UInt64, name String) ENGINE = Memory",
new CommandSettings()).get(10, TimeUnit.SECONDS);
List<String> columnNames = Arrays.asList("test id", "name");
byte[] data = "1\tone\n".getBytes(StandardCharsets.UTF_8);
InsertResponse response = client.insert(table, columnNames, new ByteArrayInputStream(data),
ClickHouseFormat.TSV, new InsertSettings()).get(30, TimeUnit.SECONDS);
Expected: the row is inserted (writtenRows == 1).
Actual: the statement sent is INSERT INTO scratch_quoting_table (test id, name) FORMAT TSV, and the call fails:
com.clickhouse.client.api.ServerException: Code: 62. DB::Exception: Syntax error: failed at position 41 (id)
(line 1, col 41): id, name ) FORMAT TSV 1 one . Expected one of: token sequence, Dot, token, Comma,
ClosingRoundBracket, end of query. (SYNTAX_ERROR) (version 26.11.2.4 (official build))
Workaround today: pre-quote the names, e.g. Arrays.asList("`test id`", "name").
Suggested fix
In Client.java:1846-1857, wrap each column name in backticks and double any embedded backtick before joining, e.g. "`" + name.replace("`", "") + "`" ``.
Note on compatibility: existing callers may already be pre-quoting as a workaround (the module's own InsertTests pre-quotes table names in a data provider), so the fix should either detect and pass through already-backticked input, or ship as a documented behavior change.
Link
Relayed from https://github.com/ClickHouse/clickhouse-js/issues/1210
- 主要語言
- Java
- 星號
- 1.6k
- 分支
- 657
- 平均合併
- 2 天 6 小時
- 30 天內合併 PR
- 36
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
ClickHouse/clickhouse-java 的其他 Issue
-
api-diagnostics bug jdbc
難度 2/5 1-3 小時 新手友好度 75/100
ClickHouse/clickhouse-java#3464 ·
維護者通常 1 天內回覆
-
tests
難度 2/5 1-3 小時 新手友好度 76/100
ClickHouse/clickhouse-java#3452 ·
維護者通常 1 天內回覆
-
bug jdbc performance queries sql-parser
難度 2/5 1-3 小時 新手友好度 77/100
ClickHouse/clickhouse-java#3451 ·
維護者通常 1 天內回覆
-
bug jdbc legacy queries
難度 2/5 1-3 小時 新手友好度 70/100
ClickHouse/clickhouse-java#3444 ·
維護者通常 1 天內回覆
-
api-diagnostics bug client jdbc
難度 2/5 1-3 小時 新手友好度 76/100
ClickHouse/clickhouse-java#3439 · 1 則留言 ·
維護者通常 1 天內回覆
查看 ClickHouse/clickhouse-java 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 60/100
quelea-projection/Quelea#749 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 92/100
erkamyaman/rust-anything#963 ·
維護者通常 1 天內回覆
-
難度 2/5 半天 新手友好度 76/100
-
Deferred
難度 2/5 1-3 小時 新手友好度 78/100
Sanne/incus-spawn#2768 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆