[client-v2] insert(table, columnNames, ...) does not backtick-quote column identifiers with spaces or special characters
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
Direzione di ricerca
Inizia da client-v2/src/main/java/com/clickhouse/client/api/Client.java, intorno alle righe 1846–1857, dove l’elenco delle colonne viene aggiunto all’istruzione INSERT. Controlla come vengono racchiusi tra virgolette gli identificatori altrove ed esamina il problema di compatibilità relativo ai chiamanti che passano già nomi tra virgolette. Aggiungi o aggiorna test per i nomi contenenti spazi e backtick incorporati, quindi conferma che l’istruzione generata funziona con ClickHouse.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Java
- Stelle
- 1.6k
- Fork
- 657
- Merge medio
- 2g 6h
- PR unite (30g)
- 36
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ClickHouse/clickhouse-java
-
api-diagnostics bug jdbc
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
ClickHouse/clickhouse-java#3464 ·
I maintainer di solito rispondono entro 1 giorno
-
tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
ClickHouse/clickhouse-java#3452 ·
I maintainer di solito rispondono entro 1 giorno
-
bug jdbc performance queries sql-parser
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
ClickHouse/clickhouse-java#3451 ·
I maintainer di solito rispondono entro 1 giorno
-
bug jdbc legacy queries
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
ClickHouse/clickhouse-java#3444 ·
I maintainer di solito rispondono entro 1 giorno
-
api-diagnostics bug client jdbc
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
ClickHouse/clickhouse-java#3439 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di ClickHouse/clickhouse-java
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 60/100
quelea-projection/Quelea#749 ·
I maintainer di solito rispondono entro 1 giorno
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
erkamyaman/rust-anything#963 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 76/100
-
Deferred
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Sanne/incus-spawn#2768 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
morluto/rea#15041 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno