ClickHouse / ClickHouse/clickhouse-java
[client-v2] getTableSchema and insert concatenate the raw table name into SQL — names needing backquotes cannot be used
- Ngôn ngữ chính
- Java
- Star
- 1.6k
- Fork
- 636
- Merge trung bình
- 2 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 29
Mô tả
### 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).
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu trong Client.java tại getTableSchema, khoảng dòng 2010, và insert, khoảng dòng 1592, sau đó lần theo cách SQL của chúng được ghép lại. Tái hiện vấn đề bằng ví dụ my-table được cung cấp và xác minh rằng các tên thông thường được đặt trong dấu ngoặc kép, các tên đã được đặt trong dấu ngoặc kép vẫn không thay đổi, và cả hai thao tác đều thành công đối với các tên yêu cầu backquotes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- clickhouse, java
- Lĩnh vực
- backend-api-design, databases
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 72/100