holdenk opened a new pull request, #60687:
URL: https://github.com/apache/spark/pull/60687

   
   ### What changes were proposed in this pull request?
   
   SPARK-59546 added a non-throwing `TimeFormatter.parseOptional` and switched 
JSON, CSV and XML schema inference to it. That changed behavior in two ways, 
which this PR fixes:
   
   1. `Iso8601TimeFormatter.parseOptional` built the time from the *unresolved* 
result of `DateTimeFormatter.parseUnresolved`, skipping the resolver. 
Clock-hour and AM/PM fields (`hh`, `KK`, `kk`, `a`) were therefore not resolved 
or validated like `parse` does, so for example `timeFormat = "hh:mm:ss"` 
inferred `17:30:01` as TIME although `parse` rejects it. `parseOptional` now 
parses once with `formatter.toFormat.parseObject(s, ParsePosition)` (which 
resolves fields and reports failure without throwing), still requiring the 
whole input to be consumed, and converts the resolved result.
   2. The inference probe used to be `allCatch opt timeFormatter.parse(field)`, 
which also caught an exception from the lazy construction of the formatter for 
an unusable `timeFormat` (e.g. `"EEE HH:mm"`). With 
`timeFormatter.parseOptional(field)` that exception escaped and broke inference 
(a failed query or a corrupt record). The formatter is now built as `allCatch 
opt TimeFormatter(...)`, and TIME is skipped when it cannot be built.
   
   ### Why are the changes needed?
   
   To keep `parseOptional` equivalent to `parse` and keep schema inference 
results the same as before SPARK-59546, as that PR intended.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No, compared to the last release. It fixes an unreleased behavior change 
from SPARK-59546.
   
   ### How was this patch tested?
   
   New tests in `TimeFormatterSuite`, `CSVInferSchemaSuite`, 
`JsonInferSchemaSuite`, `XmlInferSchemaTypeCastingSuite`, `CSVSuite`, 
`JsonSuite` and `XmlSuite`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Opus 5.5)


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