xxlaykxx commented on code in PR #1541:
URL: https://github.com/apache/arrow-java/pull/1541#discussion_r4774421337
##########
flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeVectorAccessorTest.java:
##########
@@ -265,6 +269,81 @@ public void testValidateGetStringTimeZoneConsistency(
});
}
+ @Test
Review Comment:
Added as `testGetTimeWithCalendarInNonUtcDefaultZone`, thanks. It passes as
written, including the `getTimestamp(vancouver)` assertion.
##########
flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcTime.java:
##########
@@ -32,74 +27,73 @@
* this#toString.
*/
public class ArrowFlightJdbcTime extends Time {
- private static final List<String> LEADING_ZEROES = ImmutableList.of("", "0",
"00");
-
- // Desired length of the millisecond portion should be 3
- private static final int DESIRED_MILLIS_LENGTH = 3;
+ private static final int NANOS_PER_SECOND = 1_000_000_000;
- // Millis of the date time object.
- private final int millisReprValue;
+ // Fraction of the second in nanoseconds. java.sql.Time itself only holds
milliseconds.
+ private final int nanos;
/**
* Constructs this object based on epoch millis.
*
* @param milliseconds milliseconds representing Time.
*/
public ArrowFlightJdbcTime(final long milliseconds) {
+ this(milliseconds, (int)
TimeUnit.MILLISECONDS.toNanos(Math.floorMod(milliseconds, 1000L)));
+ }
+
+ /**
+ * Constructs this object based on epoch millis and the full fraction of the
second.
+ *
+ * @param milliseconds milliseconds representing Time.
+ * @param nanos fraction of the second in nanoseconds, including the
millisecond part.
+ */
+ public ArrowFlightJdbcTime(final long milliseconds, final int nanos) {
Review Comment:
Good point. I went with the first idea: the constructor now throws
`IllegalArgumentException` when the millisecond part of `nanos` differs from
the one of `milliseconds`, so a mismatch fails loudly rather than being
silently rewritten. The check uses `Math.floorMod`, so values before the epoch
work too.
While there I also fixed the test-only `LocalTime` constructor, which had
the same problem the other way round: it kept the fraction in `nanos` but
dropped it from `getTime()`. Tests cover both.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]