[SPARK-58947][CORE] Handle Char in createArray and add tests for SparkCollectionUtils - #58227
Open
uros-b wants to merge 3 commits into
Open
[SPARK-58947][CORE] Handle Char in createArray and add tests for SparkCollectionUtils#58227uros-b wants to merge 3 commits into
uros-b wants to merge 3 commits into
Conversation
dongjoon-hyun
left a comment
Member
There was a problem hiding this comment.
Thanks for filling this gap. CI is green, the suite matches the AnyFunSuite style used by SparkStringUtilsSuite in the same module, and I confirmed none of these methods had prior coverage anywhere.
One substantive comment inline about the Char case, plus two nits:
- Line 62:
createArray(0, 7)is anInt, i.e. a primitive case, but it sits in the test namedcreateArray fills reference-typed arrays and returns empty for size 0. Moving it up to the primitive test (or renaming) would keep the two tests cleanly split. - Optional: ScalaTest's
===compares arrays structurally and prints both sides on failure, soassert(SparkCollectionUtils.createArray(3, 7) === Array(7, 7, 7))debugs a bit more easily thansameElements. Not a blocker.
Member
Author
|
Thank you @dongjoon-hyun for the careful review. I addressed all comments/concerns. |
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?
Adds a unit test suite for
SparkCollectionUtils(common/utils,org.apache.spark.util), which had no test coverage, and fixes a gap the tests surfaced.Tests cover all four methods:
toMapWithIndex(empty input, duplicate keys, equivalence tozipWithIndex.toMap);isEmpty/isNotEmpty(null, empty, non-emptyjava.util.Map); andcreateArrayfor every primitive type plus reference types andsize == 0.Adding the
createArraycoverage exposed a latent bug: it dispatched on 7 of the 8 primitiveclassOftypes (Boolean/Byte/Short/Int/Long/Float/Double) but notChar, so aCharargument fell through to theArray[AnyRef]cast and threwClassCastException(achar[]is not anObject[]). This adds the missingCharcase socreateArray[Char]fills the array like the other primitives.Why are the changes needed?
SparkCollectionUtilsis used in production (e.g.StructTypefield indexing viatoMapWithIndex) but had no tests. TheChargap is currently unreachable (no caller passesChar), but it is a latent crash for any futureCharcaller; adding the case makes the dispatch complete and symmetric with the other primitives.Does this PR introduce any user-facing change?
No.
SparkCollectionUtilsisprivate[spark]; this adds tests and a missing internalCharcase.How was this patch tested?
New
SparkCollectionUtilsSuite(extendsAnyFunSuite, the base used by the siblingcommon/utilssuites), covering all four methods includingcreateArrayfor all eight primitive types, reference types, andsize == 0.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)