ClickHouse / ClickHouse/clickhouse-java

jdbc-v2: Issue with parameter data type

Aperta
#2,674 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
area:data-type bug jdbc-v2
Lingua principale
Java
Stelle
1.6k
Fork
636
Merge medio
2g 23h
PR unite (30g)
29

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con la riproduzione JDBC fornita e ispeziona PreparedStatementImpl#encodeObject, che il report identifica come il punto di serializzazione delle date. Esegui la query sulla versione di ClickHouse Server indicata e determina se il problema riguarda la codifica dei parametri, la deserializzazione del server o la gestione dei tipi di COALESCE; il lavoro è completato quando la query restituisce il risultato senza errori.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
databases
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.