ClickHouse / ClickHouse/clickhouse-java

jdbc-v2: Issue with parameter data type

オープン
#2,674 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
area:data-type bug jdbc-v2
主要言語
Java
スター
1.6k
フォーク
636
平均マージ
2日 23時間
マージ済み PR(30日)
29

説明

## 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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

提供された JDBC の再現手順から始め、レポートで日付のシリアライズ箇所として特定されている PreparedStatementImpl#encodeObject を調査します。指定された ClickHouse Server バージョンに対してクエリを実行し、失敗の原因がパラメータのエンコード、サーバーのデシリアライズ、または COALESCE の型処理のいずれにあるかを判断します。クエリがエラーなく返れば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
databases
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。