spark-test commented on code in PR #60687:
URL: https://github.com/apache/spark/pull/60687#discussion_r4624156319


##########
sql/api/src/main/scala/org/apache/spark/sql/catalyst/util/TimeFormatter.scala:
##########
@@ -32,7 +33,8 @@ sealed trait TimeFormatter extends Serializable {
 
   // A non-throwing variant of `parse`, returning None instead of throwing 
when the input cannot be
   // parsed. Used by schema inference to probe the time type without paying an 
exception per
-  // non-time value; subclasses override it with a more efficient, 
exception-free implementation.
+  // non-time value. Subclasses override it to return None without throwing 
for input that does
+  // not match the time format; out-of-range fields may still raise an 
exception caught internally.

Review Comment:
   **Nit (P3):** Reading the code, two kinds of input besides out-of-range 
fields also raise and catch an exception inside `parseOptional`, and this 
sentence leaves both out:
   
   - With a pattern, fields that are each in range but conflict fail the strict 
resolver's cross-check. For `HH:mm a`, `13:00 AM` resolves to 13:00, the 
leftover AM field then fails that cross-check with a `DateTimeException`, and 
the `java.text.Format` wrapper from `toFormat` catches it and returns null. 
This case is new with the resolving parse.
   - With no `timeFormat`, `DefaultTimeFormatter.parseOptional` calls 
`stringToTime`. A time with seconds followed by text that is neither a valid 
zone nor an AM/PM marker, such as `12:13:14 abc` or `10:30:00 - 11:00:00`, 
makes `ZoneId.of` throw inside `getZoneId`, which rethrows it as a 
`SparkDateTimeException` before the `NonFatal` catch returns None, so a column 
of time ranges pays two exceptions per value. This behavior predates the PR, 
but the rewritten sentence still describes it as exception-free.
   
   Inference results are unaffected; only the exception cost that this comment 
documents is understated. A wording that covers both cases:
   
   ```suggestion
     // non-time value. Subclasses override it to return None instead of 
throwing, but some inputs
     // may still raise an exception that is caught internally, for example 
out-of-range or
     // conflicting fields, or a time followed by an invalid zone in the 
default formatter.
   ```
   
   **Verification:**
   - **Inspection:** Read the rewritten comment against 
Iso8601TimeFormatter.parseOptional and DefaultTimeFormatter.parseOptional. 
Confirm that it no longer limits internally caught exceptions to out-of-range 
fields, and that it covers fields that are each in range but conflict, such as 
"13:00 AM" under the pattern "HH:mm a", and a default-formatter time followed 
by text that is not a valid zone, such as "12:13:14 abc"; both inputs return 
None after an exception that is caught internally. Also confirm that it does 
not tie out-of-range fields to pattern-based formatting, since the default 
formatter also raises and catches an exception internally for an input such as 
"12:61:00".



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

Reply via email to