Skip to content

Commit

Permalink
Extract a method to read timestamp in Oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Jan 20, 2022
1 parent 779d7f6 commit 84b210a
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.trino.plugin.jdbc.JdbcJoinCondition;
import io.trino.plugin.jdbc.JdbcTableHandle;
import io.trino.plugin.jdbc.JdbcTypeHandle;
import io.trino.plugin.jdbc.LongReadFunction;
import io.trino.plugin.jdbc.LongWriteFunction;
import io.trino.plugin.jdbc.SliceWriteFunction;
import io.trino.plugin.jdbc.WriteMapping;
Expand Down Expand Up @@ -412,18 +413,23 @@ public static ColumnMapping oracleTimestampColumnMapping()
{
return ColumnMapping.longMapping(
TIMESTAMP_MILLIS,
(resultSet, columnIndex) -> {
LocalDateTime timestamp = resultSet.getObject(columnIndex, LocalDateTime.class);
// Adjust years when the value is B.C. dates because Oracle returns +1 year unless converting to string in their server side
if (timestamp.getYear() <= 0) {
timestamp = timestamp.minusYears(1);
}
return timestamp.toInstant(ZoneOffset.UTC).toEpochMilli() * MICROSECONDS_PER_MILLISECOND;
},
oracleTimestampReadFunction(),
oracleTimestampWriteFunction(),
FULL_PUSHDOWN);
}

private static LongReadFunction oracleTimestampReadFunction()
{
return (resultSet, columnIndex) -> {
LocalDateTime timestamp = resultSet.getObject(columnIndex, LocalDateTime.class);
// Adjust years when the value is B.C. dates because Oracle returns +1 year unless converting to string in their server side
if (timestamp.getYear() <= 0) {
timestamp = timestamp.minusYears(1);
}
return timestamp.toInstant(ZoneOffset.UTC).toEpochMilli() * MICROSECONDS_PER_MILLISECOND;
};
}

public static ColumnMapping oracleTimestampWithTimeZoneColumnMapping()
{
return ColumnMapping.longMapping(
Expand Down

0 comments on commit 84b210a

Please sign in to comment.