Skip to content

Commit fe9d98b

Browse files
committed
address comments
1 parent 6ab9b6f commit fe9d98b

File tree

3 files changed

+11
-63
lines changed

3 files changed

+11
-63
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ abstract class Optimizer(sessionCatalog: SessionCatalog, conf: SQLConf)
110110
EliminateSerialization,
111111
RemoveRedundantAliases,
112112
RemoveRedundantProject,
113-
RemoveInvalidRange,
114113
SimplifyCreateStructOps,
115114
SimplifyCreateArrayOps,
116115
SimplifyCreateMapOps,
@@ -271,16 +270,6 @@ object RemoveRedundantProject extends Rule[LogicalPlan] {
271270
}
272271
}
273272

274-
/**
275-
* Replace invalid `range` with emtpy range.
276-
*/
277-
object RemoveInvalidRange extends Rule[LogicalPlan] {
278-
def apply(plan: LogicalPlan): LogicalPlan = plan transform {
279-
case p @ Range(start, end, step, a, b) if (start == end) || (start < end ^ 0 < step) =>
280-
LocalRelation(p.output, data = Seq.empty)
281-
}
282-
}
283-
284273
/**
285274
* Pushes down [[LocalLimit]] beneath UNION ALL and beneath the streamed inputs of outer joins.
286275
*/

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,17 @@ case class Sort(
482482

483483
/** Factory for constructing new `Range` nodes. */
484484
object Range {
485-
def apply(start: Long, end: Long, step: Long, numSlices: Option[Int]): Range = {
485+
def apply(start: Long, end: Long, step: Long, numSlices: Option[Int])
486+
: LeafNode with MultiInstanceRelation = {
486487
val output = StructType(StructField("id", LongType, nullable = false) :: Nil).toAttributes
487-
new Range(start, end, step, numSlices, output)
488+
if (start == end || (start < end ^ 0 < step)) {
489+
LocalRelation(output)
490+
} else {
491+
new Range(start, end, step, numSlices, output)
492+
}
488493
}
489-
def apply(start: Long, end: Long, step: Long, numSlices: Int): Range = {
494+
def apply(start: Long, end: Long, step: Long, numSlices: Int)
495+
: LeafNode with MultiInstanceRelation = {
490496
Range(start, end, step, Some(numSlices))
491497
}
492498
}
@@ -500,6 +506,8 @@ case class Range(
500506
extends LeafNode with MultiInstanceRelation {
501507

502508
require(step != 0, s"step ($step) cannot be 0")
509+
require(start != end, s"start ($step) cannot be equal to end ($end)")
510+
require(start < end ^ step < 0, s"the sign of step ($step) is invalid for range ($start, $end)")
503511

504512
val numElements: BigInt = {
505513
val safeStart = BigInt(start)

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/RemoveInvalidRangeSuite.scala

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)