ClickHouse / clickhouse-java

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

Selecting huge numbers gives incorrect results #1083

Closed ne1r0n closed 1 year ago

ne1r0n commented 2 years ago

Driver version v0.3.2-patch11

Selecting some huge numbers gives incorrect results. For example: SELECT toUInt64(15369343623947579499) a, toNullable(15369343623947579499) b;

in dBeaver: image

in DataGrip: image

zhicwu commented 2 years ago

Thanks @ne1r0n for reporting the issue. I can reproduce the same issue on latest DBeaver but it works in other DB client like SQuirreL SQL.

Behind the scene, by default JDBC driver maps UInt64 to Java long so you may see negative value when calling ResultSet.getLong() but you should really call ResultSet.getObject() or ResultSet.getBigDecimal() instead.

zhicwu commented 1 year ago

In refactored version, I added Unsigned* classes for unsigned data types(e.g. com.clickhouse.client.data.UnsignedLong for UInt64). This was mainly to fix type conversion issues but it may resolve the display issue in most database clients using the driver as well(DataGrip now shows correct result and same for DBeaver).

zhicwu commented 1 year ago

The issue has been fixed in JDBC driver, but it looks like DBeaver has display issue - dbeaver/dbeaver#20014