clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

[JDBC, Client] DateTime logic should be in the client

Open chernser opened this issue 6 months ago • 3 comments

Description

Date/Time data types are most complex in terms of working with them. First - there are different classes in Java that handles time. Second - conversion between them may lead to errors in data because of many parameters should be cared about. Maintaining good support for these types requires code to be well tested and coherent. We need to move all related code to the client.

Data Type Match to Java Class

ClickHouse Type Java Class
Date ZonedDateTime
Date32 ZonedDateTime
DateTime ZonedDateTime
DateTime64 ZonedDateTime
Time Integer
Time64 Long

Most of date/time types are represented with ZonedDateTime to carry timezone information. Time and Time64 are represented as Integer/Long because they have no timezone information.

JDBC Use Cases

There are several usecases in the JDBC driver that require ClickHouse data type conversion to one of Java Date/Time classes.

PreparedStatement interface has methods that require the conversion:

  • setTime(Time, Calendar)
  • setTimestamp(Timestamp, Calendar)
  • setDate(Date, Calendar)
  • setObject(Object, SQLType) - there are can be anything Instant, LocalTime event a string?.

ResultSet interface has next methods that require the conversion:

  • getDate(int columnIndex, Calendar cal)
  • getTime(int columnIndex, Calendar cal)
  • getTimestamp(int columnIndex, Calendar cal)

Other Use Cases

  • Formatting Java Date/Time classes into a string suitable for DB

chernser avatar Jun 04 '25 03:06 chernser

Also check magic in PreparedStatementImpl.

enqueue avatar Jul 27 '25 14:07 enqueue

@enqueue I would appreciate any help with this issue: ideas, code, tests. Goal is to cover this problem as much as we can.

As the first step we need to fill use-case, I think. To understand how better to approach the problem:

  • some cases is a good utility code
  • some cases can be only covered by documentation.

chernser avatar Jul 27 '25 20:07 chernser

@chernser Thank you. I am going to write down some assumptions and tests first. We can then discuss them.

enqueue avatar Aug 02 '25 16:08 enqueue