ClickHouse / ClickHouse/clickhouse-java
[client-v2] getTableSchema and insert concatenate the raw table name into SQL — names needing backquotes cannot be used
- 主要语言
- Java
- 星标
- 1.6k
- 派生
- 636
- 平均合并
- 2 天 23 小时
- 30 天内合并 PR
- 29
描述
### 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).
贡献指南
调研方向
从 Client.java 中 2010 行左右的 getTableSchema 和 1592 行左右的 insert 开始,然后跟踪它们的 SQL 是如何组装的。使用提供的 my-table 示例重现该问题,并验证普通名称会被加引号、预先加引号的名称保持不变,以及对于需要 backquotes 的名称,两种操作都能成功。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- clickhouse, java
- 领域
- backend-api-design, databases
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 72/100