ClickHouse / ClickHouse/clickhouse-java

jdbc-v2: Issue with parameter data type

Đang mở
#2,674 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
area:data-type bug jdbc-v2
Ngôn ngữ chính
Java
Star
1.6k
Fork
637
Merge trung bình
2 ngày 23 giờ
Pull request đã merge (30 ngày)
29

Mô tả

## Description

When running a prepared statement with `COALESCE` and a date, the execution fails due to type.

Am not entirely sure whether it's an issue with the JDBC driver (which serializes the date as a String in `PreparedStatementImpl#encodeObject` - nothing wrong with that) or the server (which should deserialize it with the proper type, or `COALESCE` which should handle types better - see https://github.com/ClickHouse/ClickHouse/issues/57292 , although most other databases handle this use case).

### Steps to reproduce

See the code below.

### Error Log or Exception StackTrace

```
Caused by: com.clickhouse.client.api.ServerException: Code: 386. DB::Exception: There is no supertype for types Date32, String because some of them are String/FixedString/Enum and some of them are not: In scope SELECT COALESCE(date, '2025-12-31') FROM test_local_date. (NO_COMMON_TYPE) (version 25.8.7.3 (official build))
at com.clickhouse.client.api.internal.HttpAPIClientHelper.readError(HttpAPIClientHelper.java:403)

```

### Expected Behaviour

The query should return without error.

### Code Example

```java
@Test
void required_testJdbcWithLocalDate() throws Exception {
final String url = "jdbc:ch://localhost:" + SERVER.getFirstMappedPort();

final Properties info = new Properties();
info.put("user", SERVER.getClickhouseUser());
info.put("password", SERVER.getClickhousePassword());

try (final Connection conn = DriverManager.getConnection(url, info)) {
conn.prepareStatement("CREATE TABLE test_local_date"
+ " (id Int64, date Nullable(Date32)) ENGINE = MergeTree() ORDER BY id").execute();
conn.prepareStatement("INSERT INTO test_local_date VALUES (1, null)").execute();
try (final PreparedStatement preparedStatement = conn.prepareStatement("SELECT COALESCE(date, ?) FROM test_local_date")) {
preparedStatement.setObject(1, LocalDate.of(2025, 12, 31));
preparedStatement.executeQuery();
}
}
}

```

### Configuration

#### Client Configuration

#### Environment
* [ ] Cloud
* Client version: clickhouse-jdbc 0.9.4
* Language version:
* OS:

#### ClickHouse Server
* ClickHouse Server version: 25.8.7.3

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu với bản tái hiện JDBC được cung cấp và kiểm tra PreparedStatementImpl#encodeObject, được báo cáo xác định là điểm tuần tự hóa ngày tháng. Chạy truy vấn trên phiên bản ClickHouse Server đã nêu và xác định xem lỗi thuộc về việc mã hóa tham số, giải tuần tự ở máy chủ hay xử lý kiểu của COALESCE; hoàn tất khi truy vấn trả về mà không có lỗi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
databases
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.