ClickHouse / ClickHouse/clickhouse-java

[client-v2] getTableSchema and insert concatenate the raw table name into SQL — names needing backquotes cannot be used

Aperta
#3,089 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Java
Stelle
1.6k
Fork
636
Merge medio
2g 23h
PR unite (30g)
29

Descrizione

### Describe the bug

`Client.getTableSchema(table, database)` and `Client.insert(tableName, ...)` paste the table name into SQL as-is:

```java
"DESCRIBE TABLE " + table // Client.java:2010 (0.10.0)
"INSERT INTO " + tableName // Client.java:1592 (0.10.0)
```

So a valid table name that needs backquotes, like `my-table`, fails with a server syntax error even though the table exists.

### Steps to reproduce

```java
client.queryAll("CREATE TABLE `my-table` (id Int64) ENGINE = MergeTree ORDER BY id");
client.getTableSchema("my-table", "default"); // server syntax error
client.insert("my-table", data, settings); // same
```

### Expected behaviour

The parameter is documented as a table name, so the client should quote it when building the SQL:

```sql
DESCRIBE TABLE `my-table`
INSERT INTO `my-table`
```

Back-compat: pre-quoted names (`` `my-table` `` passed by the caller) work today as a workaround, so already-quoted input should be detected and passed through unchanged (like JDBC's `Statement.enquoteIdentifier`).

### Configuration

- client-v2 0.9.5 and 0.10.0 (latest) are both affected.

### Additional context

[flink-connector-clickhouse](https://github.com/ClickHouse/flink-connector-clickhouse) uses both methods and currently has to reject table names that need quoting; once this is fixed the connector can lift that restriction (a canary test watches for it).

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start in Client.java at getTableSchema around line 2010 and insert around line 1592, then trace how their SQL is assembled. Reproduce the issue with the provided my-table example and verify that ordinary names are quoted, pre-quoted names remain unchanged, and both operations succeed for names requiring backquotes.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
clickhouse, java
Ambito
backend-api-design, databases
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
72/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.