chenhao-db commented on code in PR #47473:
URL: https://github.com/apache/spark/pull/47473#discussion_r1690378462
##########
common/variant/src/main/java/org/apache/spark/types/variant/VariantUtil.java:
##########
@@ -377,11 +402,51 @@ 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);
}
}
+ public static class IntervalFields {
+ public IntervalFields(byte startField, byte endField) {
+ this.startField = startField;
+ this.endField = endField;
+ }
+
+ public byte startField;
Review Comment:
Can be `final`.
##########
common/variant/src/main/java/org/apache/spark/types/variant/Variant.java:
##########
@@ -316,6 +334,22 @@ static void toJsonImpl(byte[] value, byte[] metadata, int
pos, StringBuilder sb,
case BINARY:
appendQuoted(sb,
Base64.getEncoder().encodeToString(VariantUtil.getBinary(value, pos)));
break;
+ case YEAR_MONTH_INTERVAL:
+ IntervalFields ymFields =
VariantUtil.getYearMonthIntervalFields(value, pos);
+ int ymValue = (int) VariantUtil.getLong(value, pos);
+ appendQuoted(sb, YearMonthIntervalUtils
+ .toYearMonthIntervalANSIString(ymValue, ymFields.startField,
ymFields.endField));
+ break;
+ case DAY_TIME_INTERVAL:
+ IntervalFields dtFields = VariantUtil.getDayTimeIntervalFields(value,
pos);
+ long dtValue = VariantUtil.getLong(value, pos);
+ try {
Review Comment:
Why is this block in a `try` statement, but the year-month code is not?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]