david-mollitor-db opened a new pull request, #58796:
URL: https://github.com/apache/spark/pull/58796

   ### What changes were proposed in this pull request?
   
   `IntervalUtils.parseNanos` converts the fractional-second digits of a 
day-time interval to
   nanoseconds. It right-padded the digits to 9 characters with a concatenation 
and a substring
   before parsing:
   
   ```scala
   val alignedStr = if (nanos.length < maxNanosLen) {
     (nanos + "000000000").substring(0, maxNanosLen)
   } else nanos
   val nanoSecond = toLongWithRange(nanosStr, alignedStr, 0L, 999999999L)
   ```
   
   This PR parses the digits directly and scales by the corresponding power of 
ten, removing
   the intermediate strings:
   
   ```scala
   val raw = toLongWithRange(nanosStr, nanos, 0L, 999999999L)
   val nanoSecond = raw * nanosMultiplier(maxNanosLen - nanos.length)
   ```
   
   `nanosMultiplier` is a small `10^0 .. 10^8` lookup allocated once.
   
   ### Why are the changes needed?
   
   The old form allocated two throwaway strings per call (the concatenation and 
the substring)
   purely to zero-pad the value ahead of an integer parse. The fractional part 
is guaranteed to
   be 1-9 ASCII digits by the interval grammar, so it can be parsed and scaled 
arithmetically
   with no string allocation. JFR profiling of interval parsing attributed 
these allocations to
   `StringConcatHelper.newString`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. The result is identical: the parsed value is always in `[0, 999999999]` 
and scaling keeps
   it within that range, so the range check and error behavior are unchanged.
   
   ### How was this patch tested?
   
   Existing `IntervalUtilsSuite` and `IntervalExpressionsSuite` pass; they 
cover day-time
   interval casting with fractional seconds.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Isaac
   
   This pull request and its description were written by Isaac.
   


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