MaxGekk commented on code in PR #59955:
URL: https://github.com/apache/spark/pull/59955#discussion_r4466563894
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala:
##########
@@ -1105,6 +1105,40 @@ object DateTimeUtils extends SparkDateTimeUtils {
}
}
+ /**
+ * Splits the seconds of a minute with a fraction of 6 digits (microseconds)
into the whole
+ * seconds and the nanos of the second, as `LocalTime.of` and
`LocalDateTime.of` take them,
+ * packed into a long, the seconds in the high 32 bits and the nanos in the
low 32 bits, so
+ * that nothing is allocated per row: `(packed >> 32).toInt` and
`packed.toInt`.
+ *
+ * The whole seconds are checked to be in the int range and not negative
before they are
+ * narrowed. A value outside of the int range would overflow when converted
from long to int,
+ * and could produce an int in the valid seconds range and return a wrong
value, or a misleading
+ * error message. A negative value is rejected here for a better error
message: `Math.floorDiv`
+ * gets the next lower integer for it, so the full seconds would not match
the value given.
+ * The message is the one that `LocalTime.of` and `LocalDateTime.of` throw
for invalid seconds,
+ * with the seconds given, truncated towards zero, or in full for a value
between -1 and 0,
+ * which the truncation would show as the valid 0. Any other value, such as
61 seconds, is
+ * left to them, which check their fields in order, so an invalid date or
hour is reported
+ * before such seconds, while a negative value or one above `Int.MaxValue`
is reported first.
Review Comment:
Right on both boundaries, thanks. In 9fdb332edd4 the scaladoc of
`splitSecsAndMicros`, the Javadoc and the comment of `makeTimestampMicros`, and
the test comment say that the seconds are reported first only when negative or
when their whole seconds exceed `Int.MaxValue` (2147483648 or more), so
`2147483647.5` passes the split, and that the 60-second branch runs before the
other fields are checked. A `2147483647.5` row with month 13, expecting
`MonthOfYear`, pins the first boundary. The PR description says the same.
--
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]