Skip to content

Commit

Permalink
Fixes after CI find issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bgaidioz committed Aug 21, 2024
1 parent a4d015b commit a32ab38
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalTime;
import java.time.temporal.ChronoField;
import raw.runtime.truffle.runtime.exceptions.rdbms.JdbcExceptionHandler;
import raw.runtime.truffle.runtime.exceptions.rdbms.JdbcReaderRawTruffleException;
import raw.runtime.truffle.runtime.primitives.*;
Expand Down Expand Up @@ -173,8 +174,19 @@ DateObject getDate(String colName, Node node) {
@TruffleBoundary
TimeObject getTime(String colName, Node node) {
try {
// Extract the SQL time (a JDBC object) from the result set.
java.sql.Time sqlTime = rs.getTime(colName);
LocalTime localTime = LocalTime.ofNanoOfDay(sqlTime.getTime() * 1000000);
// Turn it into LocalTime. It does something proper with potential timezone conversion, but
// doesn't have the milliseconds (toLocalTime's doc says it sets the LocalTime nanoseconds
// field to zero).
java.time.LocalTime withoutMilliseconds = sqlTime.toLocalTime();
// Get the value as milliseconds (possibly shifted by a certain timezone) but we have the
// milliseconds.
long asMillis = sqlTime.getTime();
// Extract the actual milliseconds.
long millis = asMillis % 1000;
// Fix the LocalTime milliseconds.
LocalTime localTime = withoutMilliseconds.with(ChronoField.MILLI_OF_SECOND, millis);
return new TimeObject(localTime);
} catch (SQLException e) {
throw exceptionHandler.columnParseError(e, colName, node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import raw.client.utils.RecordFieldsNaming

import java.io.{IOException, OutputStream}
import java.sql.ResultSet
import java.time.LocalTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoField
import scala.annotation.tailrec

object TypedResultSetJsonWriter {
Expand Down Expand Up @@ -113,8 +113,17 @@ class TypedResultSetJsonWriter(os: OutputStream, maxRows: Option[Long]) {
val date = v.getDate(i).toLocalDate
gen.writeString(dateFormatter.format(date))
case _: RawTimeType =>
// Extract the SQL time (a JDBC object) from the result set.
val sqlTime = v.getTime(i)
val time = LocalTime.ofNanoOfDay(sqlTime.getTime * 1000000)
// Turn it into LocalTime. It does something proper with potential timezone conversion, but
// doesn't have the milliseconds (toLocalTime's doc says it sets the LocalTime nanoseconds field to zero).
val withoutMilliseconds = sqlTime.toLocalTime
// Get the value as milliseconds (possibly shifted by a certain timezone) but we have the milliseconds.
val asMillis = sqlTime.getTime
// Extract the actual milliseconds.
val millis = asMillis % 1000
// Fix the LocalTime milliseconds.
val time = withoutMilliseconds.`with`(ChronoField.MILLI_OF_SECOND, millis)
val formatted = timeFormatter.format(time)
gen.writeString(formatted)
case _: RawTimestampType =>
Expand Down

0 comments on commit a32ab38

Please sign in to comment.