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

   ### What changes were proposed in this pull request?
   
   `SparkDateTimeUtils.getZoneId` runs two regex `replaceFirst` calls on every 
invocation to normalize the legacy `(+|-)h:mm` and `(+|-)hh:m` zone-offset 
formats (supported before Spark 3.0):
   
   ```scala
   var formattedZoneId = singleHourTz.matcher(timeZoneId).replaceFirst("$10$2:")
   formattedZoneId = 
singleMinuteTz.matcher(formattedZoneId).replaceFirst("$1$2:0$3")
   ZoneId.of(formattedZoneId, ZoneId.SHORT_IDS)
   ```
   
   Both patterns are anchored on a leading sign character `(+|-)`. This guards 
the normalization so the two regexes only run when the input starts with `+` or 
`-`, and otherwise passes the id straight to `ZoneId.of`.
   
   ### Why are the changes needed?
   
   Region-based IDs such as `UTC`, `America/New_York`, or `GMT+8` -- the 
overwhelming majority of inputs -- can never match the sign-anchored patterns, 
yet each call still allocates two `Matcher` instances and scans the string 
twice before `ZoneId.of` does the real work. The guard skips those allocations 
for the common case. It also makes explicit that the two regexes exist only to 
normalize the sign-prefixed legacy formats.
   
   This is a small clarity and allocation cleanup on the shared `getZoneId` 
helper, not a headline performance change.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. The change is behavior-preserving: both patterns are anchored on the 
leading sign, so an input that does not start with `+`/`-` is returned 
unchanged by `replaceFirst` today, which is exactly what the guarded `else` 
branch returns.
   
   ### How was this patch tested?
   
   A new test in `DateTimeUtilsSuite` asserts `getZoneId` directly:
   
   - sign-prefixed offsets are still normalized (`+7:30` -> `+07:30`, `+07:3` 
-> `+07:03`, `-1:0` -> `-01:00`)
   - already-canonical sign offsets are unaffected (`+07:30`, `-08:00`)
   - region-based / non-sign inputs pass through unchanged (`UTC`, `Z`, 
`America/New_York`, and `GMT+8` -- whose `+` is not the leading character, so 
it must not be rewritten)
   
   The existing `getZoneId` normalization is also covered indirectly by the 
"string to timestamp" test. `catalyst/testOnly *DateTimeUtilsSuite` passes.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Ducc
   


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