harshmotw-db commented on code in PR #47473:
URL: https://github.com/apache/spark/pull/47473#discussion_r1691939585


##########
common/variant/src/main/java/org/apache/spark/types/variant/VariantUtil.java:
##########
@@ -377,11 +405,52 @@ public static long getLong(byte[] value, int pos) {
       case TIMESTAMP:
       case TIMESTAMP_NTZ:
         return readLong(value, pos + 1, 8);
+      case YEAR_MONTH_INTERVAL:
+        return readLong(value, pos + 2, 4);
+      case DAY_TIME_INTERVAL:
+        return readLong(value, pos + 2, 8);
       default:
         throw new IllegalStateException(exceptionMessage);
     }
   }
 
+  // Class used to pass around start and end fields of year-month and day-time 
interval values.
+  public static class IntervalFields {
+    public IntervalFields(byte startField, byte endField) {
+      this.startField = startField;
+      this.endField = endField;
+    }
+
+    public final byte startField;
+    public final byte endField;
+  }
+
+  // Get the start and end fields of a variant value representing a year-month 
interval value. The
+  // returned array contains the start field at the zeroth index and the end 
field at the first
+  // index.
+  public static IntervalFields getYearMonthIntervalFields(byte[] value, int 
pos) {
+    long fieldInfo = readLong(value, pos + 1, 1);
+    IntervalFields intervalFields = new IntervalFields((byte) (fieldInfo & 
0x1),
+            (byte) ((fieldInfo >> 1) & 0x1));
+    if (intervalFields.endField < intervalFields.startField) {

Review Comment:
   Yes, that would have been a good idea. `checkIndex` is performed by 
`readLong` anyway though. Done.



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to