Skip to content

SPARK-1240: handle the case of empty RDD when takeSample - #135

Closed
CodingCat wants to merge 5 commits into
apache:masterfrom
CodingCat:SPARK-1240
Closed

SPARK-1240: handle the case of empty RDD when takeSample#135
CodingCat wants to merge 5 commits into
apache:masterfrom
CodingCat:SPARK-1240

Conversation

@CodingCat

Copy link
Copy Markdown
Contributor

https://spark-project.atlassian.net/browse/SPARK-1240

It seems that the current implementation does not handle the empty RDD case when run takeSample

In this patch, before calling sample() inside takeSample API, I add a checker for this case and returns an empty Array when it's a empty RDD; also in sample(), I add a checker for the invalid fraction value

In the test case, I also add several lines for this case

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use require. i.e.

require(fraction >Double.MinValue&& fraction <Double.MaxValue, "...")

Shouldn't you just check for fraction > 0 but < 1?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lower bound should be >= 0.0. Sample with replacement can have a faction greater than 1.0.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @rxin , I'm also a bit confused here, I think the name of the argument is a bit confusing

https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/rdd/RDD.scala#L357

The above line contains a multiplier to ensure that the sampling can return enough sample points in most of cases..(I think so), so the fraction value can actually be larger than 1

also, this value actually determines the mean value of Poisson/Bernoulli distribution

https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/rdd/RDD.scala#L314

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require(fraction >= 0.0) should be sufficient here.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished.

@AmplabJenkins

Copy link
Copy Markdown

All automated tests passed.
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/13164/

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us create a separate test "takeSample from an empty rdd" and construct an empty rdd directly:

val emptyRdd = sc.parallelize(Seq.empty[Int], 2)

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished.

@AmplabJenkins

Copy link
Copy Markdown

All automated tests passed.
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/13167/

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

@mengxr

Copy link
Copy Markdown
Contributor

LGTM. Waiting for Jenkins.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished.

@AmplabJenkins

Copy link
Copy Markdown

All automated tests passed.
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/13169/

@CodingCat

Copy link
Copy Markdown
ContributorAuthor

Ah, good, thank you very much for the comments @rxin@mengxr

@mateiz

Copy link
Copy Markdown
Contributor

Can you check whether this is broken in Python too, and fix it there as well?

@CodingCat

Copy link
Copy Markdown
ContributorAuthor

sure, will do that this evening~

@AmplabJenkins

Copy link
Copy Markdown

Merged build triggered.

@AmplabJenkins

Copy link
Copy Markdown

Merged build started.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished.

@AmplabJenkins

Copy link
Copy Markdown

All automated tests passed.
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/13186/

@CodingCat

Copy link
Copy Markdown
ContributorAuthor

@mateiz, done~

@mateiz

Copy link
Copy Markdown
Contributor

Actually sorry, one other thought -- instead of throwing an error when fraction == 0, just return the empty array there too. Some code might pass 0 for a valid reason (e.g. if the sampling rate is coming from a user, or whatever).

Anyway both this and the empty RDD case are good catches.

@CodingCat

Copy link
Copy Markdown
ContributorAuthor

Hi, @mateiz , I think the current implementation allows fraction == 0 case, or I misunderstood something?

@mateiz

Copy link
Copy Markdown
Contributor

Ah, thanks, I missed that. Merged this in.

asfgit pushed a commit that referenced this pull request Mar 17, 2014
https://spark-project.atlassian.net/browse/SPARK-1240
It seems that the current implementation does not handle the empty RDD case when run takeSample
In this patch, before calling sample() inside takeSample API, I add a checker for this case and returns an empty Array when it's a empty RDD; also in sample(), I add a checker for the invalid fraction value
In the test case, I also add several lines for this case
Author: CodingCat <zhunansjtu@gmail.com>
Closes#135 from CodingCat/SPARK-1240 and squashes the following commits:
fef57d4 [CodingCat] fix the same problem in PySpark
36db06b [CodingCat] create new test cases for takeSample from an empty red
810948d [CodingCat] further fix
a40e8fb [CodingCat] replace if with require
ad483fd [CodingCat] handle the case with empty RDD when take sample
Conflicts:
core/src/main/scala/org/apache/spark/rdd/RDD.scala
core/src/test/scala/org/apache/spark/rdd/RDDSuite.scala
@CodingCat
CodingCat deleted the SPARK-1240 branch March 17, 2014 17:21
gzm55 pushed a commit to MediaV/spark that referenced this pull request Jul 17, 2014
https://spark-project.atlassian.net/browse/SPARK-1240
It seems that the current implementation does not handle the empty RDD case when run takeSample
In this patch, before calling sample() inside takeSample API, I add a checker for this case and returns an empty Array when it's a empty RDD; also in sample(), I add a checker for the invalid fraction value
In the test case, I also add several lines for this case
Author: CodingCat <zhunansjtu@gmail.com>
Closesapache#135 from CodingCat/SPARK-1240 and squashes the following commits:
fef57d4 [CodingCat] fix the same problem in PySpark
36db06b [CodingCat] create new test cases for takeSample from an empty red
810948d [CodingCat] further fix
a40e8fb [CodingCat] replace if with require
ad483fd [CodingCat] handle the case with empty RDD when take sample
Conflicts:
core/src/main/scala/org/apache/spark/rdd/RDD.scala
core/src/test/scala/org/apache/spark/rdd/RDDSuite.scala
ericl pushed a commit to ericl/spark that referenced this pull request Dec 21, 2016
Previous merge with upstream broke the build.
Author: Herman van Hovell <hvanhovell@databricks.com>
Closesapache#135 from hvanhovell/fix-hook-calling-external-catalog.
cenyuhai added a commit to cenyuhai/spark that referenced this pull request Nov 14, 2017
[ESPARK-135] 解决当不需要合并的时候仍然更换临时目录,导致最终结束为空的问题
解决当不需要合并的时候仍然更换临时目录,导致最终结束为空的问题 . resolveapache#135
See merge request !82
jamesrgrinter pushed a commit to jamesrgrinter/spark that referenced this pull request Apr 22, 2018
bzhaoopenstack pushed a commit to bzhaoopenstack/spark that referenced this pull request Sep 11, 2019
* Support k8s E2E test against specified k8s version
- Create install-k8s role
- Support to specify version of k8s and etcd
- Add new job
cloud-provider-openstack-acceptance-test-e2e-conformance-latest-release
- Skip to copy 0 size test_results.html
- Add post.yaml in
cloud-provider-openstack-acceptance-test-e2e-conformance
as a placeholder to upload test result to testgrid, but
upload_e2e.py can not be found, implement it in following
patchset.
Partial-Bug: kubernetes/cloud-provider-openstack#103
fishcus pushed a commit to fishcus/spark that referenced this pull request Jul 8, 2020
* apache#135 bump jackson version to 2.10.4
* apache#135 update spark version r41
Co-authored-by: Yu Gan <yu.gan@kyligence.io>
fishcus pushed a commit to fishcus/spark that referenced this pull request Jul 8, 2020
Co-authored-by: Yu Gan <yu.gan@kyligence.io>
arjunshroff pushed a commit to arjunshroff/spark that referenced this pull request Nov 24, 2020
microbearz pushed a commit to microbearz/spark that referenced this pull request Dec 15, 2020
* apache#135 bump jackson version to 2.10.4
* apache#135 update spark version r41
Co-authored-by: Yu Gan <yu.gan@kyligence.io>
microbearz pushed a commit to microbearz/spark that referenced this pull request Dec 15, 2020
Co-authored-by: Yu Gan <yu.gan@kyligence.io>
dongjoon-hyun pushed a commit that referenced this pull request Jun 23, 2023
### What changes were proposed in this pull request?
The pr aims to upgrade commons-codec from 1.15 to 1.16.0.
### Why are the changes needed?
1.The new version brings some bug fixed, eg:
- Fix byte-skipping in Base16 decoding #135. Fixes CODEC-305.
- BaseNCodecOutputStream.eof() should not throw IOException.
- Add support for Blake3 family of hashes. Fixes [CODEC-296](https://issues.apache.org/jira/browse/CODEC-296).
2.The full release notes:
https://commons.apache.org/proper/commons-codec/changes-report.html#a1.16.0
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Pass GA.
Closes#41707 from panbingkun/SPARK-44151.
Authored-by: panbingkun <pbk1982@gmail.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Sep 6, 2026
### What changes were proposed in this pull request?
Plan files only, no code. `PLAN_TASK_63.md` for task 63, milestone 4's `Add`, `Subtract`, `Multiply` and `UnaryMinus` over fused int fields, int columns and int literals, in Spark's three evaluation modes: `LEGACY` wraps as the lanewise op does; `ANSI` detects an overflowing lane with a sign test (two XORs, an AND, a compare - two compares for a literal multiplier) ORed into task 52's accumulator, so the batch declines through the existing route and the row engine raises Spark's own `ARITHMETIC_OVERFLOW` for the same row; `TRY` clears the lane's validity and forfeits the dense body under task 42's rule. Two IR records carry the op and the mode as shape-bearing enums; a dedicated int-operand function keeps the int column entering only through arithmetic and comparisons, preserving task 38's leaf rule; `date_add` over an arithmetic offset goes through the existing column-shifted range analysis unchanged. The column-by-column multiply under `ANSI`/`TRY` declines in this task - the exact overflow test needs a product's high half, which is milestone 5's widening.
`PLAN_MILESTONE_4.md` row 63 gains a `**Planned**` marker pointing at the plan.
### Why are the changes needed?
The admission check, the register, the tests and the measurement plan are written and reviewed now so the task is ready the moment its prerequisites land, following the precedent set by task 67's plan PR. The code itself is intentionally not part of this PR: every file the implementation touches - `VarkaExpressionCompiler`, `VarkaVectorIR`, `VarkaLoopEmitter`, `VarkaEmitOptions` - is also being edited by the still-open task 59/60/61 stack (apache#126, apache#128, apache#130), so starting the code now would mean rebasing through three more merges before it could land. The plan records that gate explicitly: "the code starts after the task 61 stack lands."
### Does this PR introduce _any_ user-facing change?
No. Documentation only.
### How was this patch tested?
N/A - no code in this PR. `PLAN_TASK_63.md` was reviewed against the current compiler, emitter and evaluator sources on this branch as its admission check (section 2), tracing each of the four operations and three evaluation modes to Spark's own `BinaryArithmetic`/`UnaryMinus` semantics.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Sonnet 5)
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Sep 6, 2026
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Sep 6, 2026
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Sep 6, 2026
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Sep 6, 2026
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Sep 6, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@CodingCat@AmplabJenkins@mengxr@mateiz@rxin