From ec1ac668283d575efb56a2add98edeeee988c67a Mon Sep 17 00:00:00 2001 From: Stefan Bischof Date: Sat, 31 Oct 2026 15:57:43 +0100 Subject: [PATCH] dialect: a DATE and a TIMESTAMP column are read with their own getters The default type map gives Types.DATE the column type DATE and Types.TIMESTAMP the column type TIMESTAMP. Oracle reports its DATE as TIMESTAMP, since it carries a time of day, and keeps it so: read as a date it would lose the time, and its members and segment predicates would miss the rows. Signed-off-by: Stefan Bischof --- .../daanse/sql/dialect/db/common/JdbcTypeMapper.java | 5 +++++ .../sql/dialect/db/common/JdbcDialectTypeMapTest.java | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/dialect/db/common/src/main/java/org/eclipse/daanse/sql/dialect/db/common/JdbcTypeMapper.java b/dialect/db/common/src/main/java/org/eclipse/daanse/sql/dialect/db/common/JdbcTypeMapper.java index 48bc3e0..2552bfa 100644 --- a/dialect/db/common/src/main/java/org/eclipse/daanse/sql/dialect/db/common/JdbcTypeMapper.java +++ b/dialect/db/common/src/main/java/org/eclipse/daanse/sql/dialect/db/common/JdbcTypeMapper.java @@ -34,6 +34,11 @@ final class JdbcTypeMapper { m.put(Types.DOUBLE, BestFitColumnType.DOUBLE); m.put(Types.FLOAT, BestFitColumnType.DOUBLE); m.put(Types.BIGINT, BestFitColumnType.DOUBLE); + // temporal columns are read with their own getter, not getObject: the class getObject returns is the driver's + // choice. Oracle reports its DATE as TIMESTAMP (it carries a time of day) and keeps it so: read as a date it + // would lose the time, and its members and segment predicates would miss the rows + m.put(Types.DATE, BestFitColumnType.DATE); + m.put(Types.TIMESTAMP, BestFitColumnType.TIMESTAMP); DEFAULT_TYPE_MAP = Collections.unmodifiableMap(m); } diff --git a/dialect/db/common/src/test/java/org/eclipse/daanse/sql/dialect/db/common/JdbcDialectTypeMapTest.java b/dialect/db/common/src/test/java/org/eclipse/daanse/sql/dialect/db/common/JdbcDialectTypeMapTest.java index 77e534e..6f17f28 100644 --- a/dialect/db/common/src/test/java/org/eclipse/daanse/sql/dialect/db/common/JdbcDialectTypeMapTest.java +++ b/dialect/db/common/src/test/java/org/eclipse/daanse/sql/dialect/db/common/JdbcDialectTypeMapTest.java @@ -39,6 +39,16 @@ void testNumericPrecisionFiveScaleZeroMapsToInt() throws SQLException { assertEquals(BestFitColumnType.INT, dialect.getType(rs, 0)); } + /** A date and a timestamp are read with their getters; getObject returns whatever class the driver picks. */ + @Test + void temporalColumnsAreReadAsDateAndTimestamp() throws SQLException { + ResultSetMetaData rs = mock(ResultSetMetaData.class); + when(rs.getColumnType(1)).thenReturn(Types.DATE); + when(rs.getColumnType(2)).thenReturn(Types.TIMESTAMP); + assertEquals(BestFitColumnType.DATE, dialect.getType(rs, 0)); + assertEquals(BestFitColumnType.TIMESTAMP, dialect.getType(rs, 1)); + } + @Test void testDecimalPrecisionFiveScaleZeroMapsToInt() throws SQLException { ResultSetMetaData rs = mock(ResultSetMetaData.class);