lriggs commented on code in PR #1541:
URL: https://github.com/apache/arrow-java/pull/1541#discussion_r4774207559


##########
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:
   I think the two parameters can allow conflicting nano settings.
   ```
   // 45_296_500 ms = 12:34:56.500, but nanos says .123456789
   ArrowFlightJdbcTime t = new ArrowFlightJdbcTime(45_296_500L, 123_456_789);
   
   t.getTime();      // 45_296_500             -> .500  (from milliseconds)
   t.toString();     // "12:34:56.123456789"   -> .123  (hh:mm:ss from millis, 
fraction from nanos)
   t.toLocalTime();  // 12:34:56.123456789     -> .123
   new Timestamp(t.getTime()).getNanos();  // 500_000_000
   t.equals(new Time(45_296_500L));        // true, because equals only 
compares millis
   ```
   Two ideas for fixing it:
   ```
   // 1. Reject values that disagree
   if (Math.floorMod(milliseconds, 1000L) != nanos / 1_000_000) {
     throw new IllegalArgumentException(...);
   }
   
   // 2. Let nanos decide, and rebuild the millis from it
   super(Math.floorDiv(milliseconds, 1000L) * 1000L + nanos / 1_000_000);
   ```



-- 
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]

Reply via email to