{{ message }}
[SPARK-59507][SQL] Parse interval fractional seconds without building a padded string - #58796
Open
david-mollitor-db wants to merge 1 commit into
Open
david-mollitor-db wants to merge 1 commit into
david-mollitor-db wants to merge 1 commit into
Conversation
Member
… a padded string
`IntervalUtils.parseNanos` right-padded the fractional-second digits to 9 characters with a
string concatenation and a substring before parsing:
(nanos + "000000000").substring(0, maxNanosLen)
That allocated two throwaway strings per call purely to zero-pad ahead of an integer parse.
Since the fractional part is guaranteed to be 1-9 ASCII digits by the interval grammar,
parse it directly and scale by the corresponding power of ten instead. The result is
identical -- the parsed value stays in [0, 999999999], so the range check and error
behavior are unchanged -- and no intermediate string is allocated.
Co-authored-by: Isaac <no-reply@databricks.com>
david-mollitor-db
force-pushed
the
SPARK-59507
branch
from
September 15, 2026 12:48
cb434d5 to
ed64021
Compare
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What changes were proposed in this pull request?
IntervalUtils.parseNanosconverts the fractional-second digits of a day-time interval tonanoseconds. It right-padded the digits to 9 characters with a concatenation and a substring
before parsing:
This PR parses the digits directly and scales by the corresponding power of ten, removing
the intermediate strings:
nanosMultiplieris a small10^0 .. 10^8lookup 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 keepsit within that range, so the range check and error behavior are unchanged.
How was this patch tested?
Existing
IntervalUtilsSuiteandIntervalExpressionsSuitepass; they cover day-timeinterval 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.