ClickHouse / clickhouse-java

ClickHouse Java Clients & JDBC Driver
https://clickhouse.com
Apache License 2.0
1.45k stars 535 forks source link

[client-v2] BinaryStreamReader does not use column scale for DateTime64 #1851

Closed alniks closed 1 month ago

alniks commented 1 month ago

Describe the bug

BinaryStreamReader does not use scale of a column when parsing DateTime64 value

Steps to reproduce

  1. create table with DateTime64 column
  2. read DateTime64 values

Expected behaviour

correct dates are read by client

Code example

            ClickHouseBinaryFormatReader reader = chDirectClient.newBinaryFormatReader(response);
            while (reader.hasNext()) {
                Map<String, Object> tuple = reader.next();
                assertEquals("2024-10-07 06:59:35.107361000", tuple.get("event_time"));
           }

Problematic code in BinaryStreamReader

constant 3 is used instead of column.getScale()

                case DateTime64:
                    return convertDateTime(readDateTime64(3, column.getTimeZone() == null ? timeZone :
                            column.getTimeZone()), typeHint);
chernser commented 1 month ago

@alniks Thank you for reporting! Will fix.