ClickHouse / ClickHouse/clickhouse-java
[client-v2] getTableSchema and insert concatenate the raw table name into SQL — names needing backquotes cannot be used
- Langage dominant
- Java
- Étoiles
- 1.6k
- Forks
- 636
- Merge moyen
- 2 j 23 h
- PR mergées (30 j)
- 29
Description
### 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).
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez dans Client.java, à getTableSchema autour de la ligne 2010 et à insert autour de la ligne 1592, puis suivez la manière dont leur SQL est assemblé. Reproduisez le problème avec l’exemple my-table fourni et vérifiez que les noms ordinaires sont entourés de guillemets, que les noms déjà entourés de guillemets restent inchangés et que les deux opérations réussissent pour les noms nécessitant des backquotes.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- clickhouse, java
- Domaine
- backend-api-design, databases
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- Active
- Clarté
- Plutôt claire
- Accessibilité débutants
- 72/100