-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21041][SQL] SparkSession.range should be consistent with SparkContext.range #18257
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 2 commits
6ab9b6f
fe9d98b
c4ad4c5
84b87b7
89dd7ad
46f60f0
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 |
|---|---|---|
|
|
@@ -482,11 +482,17 @@ case class Sort( | |
|
|
||
| /** Factory for constructing new `Range` nodes. */ | ||
| object Range { | ||
| def apply(start: Long, end: Long, step: Long, numSlices: Option[Int]): Range = { | ||
| def apply(start: Long, end: Long, step: Long, numSlices: Option[Int]) | ||
| : LeafNode with MultiInstanceRelation = { | ||
| val output = StructType(StructField("id", LongType, nullable = false) :: Nil).toAttributes | ||
| new Range(start, end, step, numSlices, output) | ||
| if (start == end || (start < end ^ 0 < step)) { | ||
| LocalRelation(output) | ||
|
||
| } else { | ||
| new Range(start, end, step, numSlices, output) | ||
| } | ||
| } | ||
| def apply(start: Long, end: Long, step: Long, numSlices: Int): Range = { | ||
| def apply(start: Long, end: Long, step: Long, numSlices: Int) | ||
| : LeafNode with MultiInstanceRelation = { | ||
| Range(start, end, step, Some(numSlices)) | ||
| } | ||
| } | ||
|
|
@@ -500,6 +506,8 @@ case class Range( | |
| extends LeafNode with MultiInstanceRelation { | ||
|
|
||
| require(step != 0, s"step ($step) cannot be 0") | ||
| require(start != end, s"start ($step) cannot be equal to end ($end)") | ||
| require(start < end ^ step < 0, s"the sign of step ($step) is invalid for range ($start, $end)") | ||
|
||
|
|
||
| val numElements: BigInt = { | ||
| val safeStart = BigInt(start) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -191,6 +191,17 @@ class DataFrameRangeSuite extends QueryTest with SharedSQLContext with Eventuall | |
| checkAnswer(sql("SELECT * FROM range(3)"), Row(0) :: Row(1) :: Row(2) :: Nil) | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-21041 SparkSession.range()'s behavior is inconsistent with SparkContext.range()") { | ||
| val start = java.lang.Long.MAX_VALUE - 3 | ||
| val end = java.lang.Long.MIN_VALUE + 2 | ||
| Seq("false", "true").foreach { value => | ||
| withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> value) { | ||
| assert(spark.sparkContext.range(start, end, 1).collect.length == 0) | ||
| assert(spark.range(start, end, 1).collect.length == 0) | ||
|
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. Shall we also test the case
Member
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. Sure. |
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| object DataFrameRangeSuite { | ||
|
|
||
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.
this signature looks weird...