fix array_repeat above Presto repeat limit - #797
Open
JinyuanZhang617 wants to merge 1 commit into
Open
Conversation
JinyuanZhang617
force-pushed
the
enlarge_array_repeat_github_main
branch
from
July 28, 2026 14:14
4461e72 to
4b866b0
Compare
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 problem does this PR solve?
Issue Number: #652
This PR fixes a compatibility issue in the Spark-compatible
array_repeatimplementation.Previously,
repeat_allow_negative_count, which is used to provide Spark-compatible behavior, reused the same 10,000-result-entry-per-row limit as Prestorepeat. However, Sparkarray_repeatdoes not enforce this Presto-specific limit. As a result, valid Spark queries such as repeating an element more than 10,000 times could fail unexpectedly.This PR separates the Presto
repeatbehavior from the Spark-compatiblerepeat_allow_negative_countbehavior:repeatstill enforces the 10,000 entries per row limit.repeat_allow_negative_countallows counts greater than 10,000.Type of Change
Description
Describe your changes in detail.
For complex logic, explain the "Why" and "How".
This PR updates the implementation of the repeat array function to distinguish between Presto-compatible and Spark-compatible semantics.
Previously,
RepeatFunction::checkCountalways enforcedkMaxResultEntries = 10,000, regardless of whether the function was used for Prestorepeator Spark-compatiblerepeat_allow_negative_count.The change introduces a new
enforceMaxResultEntriesflag inRepeatFunction:makeRepeatcreatesRepeatFunction(false, true), so Prestorepeatkeeps enforcing the 10,000 limit.makeRepeatAllowNegativeCountcreatesRepeatFunction(true, false), so Spark-compatiblerepeat_allow_negative_countallows counts greater than 10,000.In addition, this PR adds
checkTotalCountto validate the total number of output entries before allocating result buffers. This prevents the total repeated result size from exceeding the maximum supportedvector_size_tsize.The implementation also changes the accumulated total count in the non-constant count path from
int32_ttoint64_t, avoiding integer overflow when summing large repeat counts across rows.A new unit test is added to verify that
repeat_allow_negative_countworks when the repeat count is above the Presto limit. The test covers both:Performance Impact
No Impact: This is a correctness fix for function semantics. It only adds a configuration flag and a total-size safety check, and does not introduce algorithmic changes to the repeat execution path.
Positive Impact: I have run benchmarks.
Click to view Benchmark Results
Negative Impact: Explained below (e.g., trade-off for correctness).
Release Note
Checklist (For Author)
Breaking Changes