WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 9c3fe16

Browse files
committed
fixed scale conversion in time64
1 parent bda902e commit 9c3fe16

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcUtils.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.clickhouse.jdbc.internal;
22

3+
import com.clickhouse.client.api.DataTypeUtils;
34
import com.clickhouse.client.api.data_formats.internal.BinaryStreamReader;
45
import com.clickhouse.client.api.data_formats.internal.InetAddressConverter;
56
import com.clickhouse.data.ClickHouseColumn;
@@ -294,10 +295,10 @@ public static Object convert(Object value, Class<?> type, ClickHouseColumn colum
294295
return new Array(column, arrayValue.getArrayOfObjects());
295296
}
296297

297-
return convertObject(value, type);
298+
return convertObject(value, type, column);
298299
}
299300

300-
public static Object convertObject(Object value, Class<?> type) throws SQLException {
301+
public static Object convertObject(Object value, Class<?> type, ClickHouseColumn column) throws SQLException {
301302
if (value == null || type == null) {
302303
return value;
303304
}
@@ -343,7 +344,8 @@ public static Object convertObject(Object value, Class<?> type) throws SQLExcept
343344
} else if (type == Time.class && value instanceof Integer) { // Time
344345
return new Time((Integer) value * 1000L);
345346
} else if (type == Time.class && value instanceof Long) { // Time64
346-
return new Time((Long) value / 1_000_000);
347+
Instant instant = DataTypeUtils.instantFromTime64Integer(column.getScale(), (Long) value);
348+
return new Time(instant.getEpochSecond() * 1000L + instant.getNano() / 1_000_000);
347349
} else if (type == Inet4Address.class && value instanceof Inet6Address) {
348350
// Convert Inet6Address to Inet4Address
349351
return InetAddressConverter.convertToIpv4((InetAddress) value);

jdbc-v2/src/test/java/com/clickhouse/jdbc/DataTypeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ public void testTimeTypes() throws SQLException {
659659
assertThrows(SQLException.class, () -> rs.getTimestamp(col));
660660
assertThrows(SQLException.class, () -> rs.getObject(col, Date.class));
661661
assertThrows(SQLException.class, () -> rs.getObject(col, Timestamp.class));
662-
// LocalTime requires ZoneId and date part
662+
// LocalTime conversion is not supported
663663
assertThrows(SQLException.class, () -> rs.getObject(col, LocalTime.class));
664664
}
665665
assertFalse(rs.next());

0 commit comments

Comments
 (0)