-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-31518][CORE] Expose filterByRange in JavaPairRDD #28293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,6 +247,34 @@ public int getPartition(Object key) { | |
| Arrays.asList(new Tuple2<>(1, 3), new Tuple2<>(3, 8), new Tuple2<>(3, 8))); | ||
| } | ||
|
|
||
| @Test | ||
| public void filterByRange() { | ||
| List<Tuple2<Integer, Integer>> pairs = new ArrayList<>(); | ||
| pairs.add(new Tuple2<>(0, 5)); | ||
| pairs.add(new Tuple2<>(1, 8)); | ||
| pairs.add(new Tuple2<>(2, 6)); | ||
| pairs.add(new Tuple2<>(3, 8)); | ||
| pairs.add(new Tuple2<>(4, 8)); | ||
|
|
||
| JavaPairRDD<Integer, Integer> rdd = sc.parallelizePairs(pairs).sortByKey(); | ||
|
|
||
| // Default comparator | ||
| JavaPairRDD<Integer, Integer> filteredRDD = rdd.filterByRange(3, 11); | ||
| List<Tuple2<Integer, Integer>> filteredPairs = filteredRDD.collect(); | ||
| assertEquals(filteredPairs.size(), 2); | ||
| assertEquals(filteredPairs.get(0), new Tuple2<>(3, 8)); | ||
| assertEquals(filteredPairs.get(1), new Tuple2<>(4, 8)); | ||
|
|
||
| // Custom comparator | ||
| filteredRDD = rdd.filterByRange(Collections.reverseOrder(), 3, -2); | ||
| filteredPairs = filteredRDD.collect(); | ||
| assertEquals(filteredPairs.size(), 4); | ||
| assertEquals(filteredPairs.get(0), new Tuple2<>(0, 5)); | ||
| assertEquals(filteredPairs.get(1), new Tuple2<>(1, 8)); | ||
| assertEquals(filteredPairs.get(2), new Tuple2<>(2, 6)); | ||
| assertEquals(filteredPairs.get(3), new Tuple2<>(3, 9)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, @wetneb . Could you switch the parameters of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, sorry about this! I thought I had managed to run the test, but I obviously need to improve my set up. Many apologies! |
||
| } | ||
|
|
||
| @Test | ||
| public void emptyRDD() { | ||
| JavaRDD<String> rdd = sc.emptyRDD(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll want the
@Since("3.1.0")annotations on these methodsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I am also wondering whether it makes sense to backport this in 2.4 by the way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's not a bug fix per se. I wouldn't put it in 3.0 even necessarily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your first contribution, @wetneb ! +1 for @srowen 's answers.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for curiosity, of the two since marks, Spark's scala
@Sinceannotation and java@sincetag, how to choose them? IMHO,@sincetag seems better here to let the version show up in the generated Java API documentation. @dongjoon-hyun @srowen thanks.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the generated Java API doc, you should put
@sinceinto the comment.For example,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I have added that too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep that's right, my mistake, I was thinking of Scala