Skip to content

Commit

Permalink
address comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
dongjoon-hyun committed Jun 12, 2017
1 parent 84b87b7 commit 89dd7ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,11 @@ case class Sort(

/** Factory for constructing new `Range` nodes. */
object Range {
def apply(start: Long, end: Long, step: Long, numSlices: Option[Int]): LogicalPlan = {
def apply(start: Long, end: Long, step: Long, numSlices: Option[Int]): Range = {
val output = StructType(StructField("id", LongType, nullable = false) :: Nil).toAttributes
if (start == end || (start < end ^ 0 < step)) {
LocalRelation(output)
} else {
new Range(start, end, step, numSlices, output)
}
new Range(start, end, step, numSlices, output)
}
def apply(start: Long, end: Long, step: Long, numSlices: Int): LogicalPlan = {
def apply(start: Long, end: Long, step: Long, numSlices: Int): Range = {
Range(start, end, step, Some(numSlices))
}
}
Expand All @@ -504,8 +500,6 @@ case class Range(
extends LeafNode with MultiInstanceRelation {

require(step != 0, s"step ($step) cannot be 0")
require(start != end, s"start ($start) 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.duration.Duration

import org.apache.spark.{InterruptibleIterator, SparkException, TaskContext}
import org.apache.spark.rdd.{PartitionwiseSampledRDD, RDD}
import org.apache.spark.rdd.{EmptyRDD, PartitionwiseSampledRDD, RDD}
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, ExprCode, ExpressionCanonicalizer}
Expand Down Expand Up @@ -347,8 +347,12 @@ case class RangeExec(range: org.apache.spark.sql.catalyst.plans.logical.Range)
}

override def inputRDDs(): Seq[RDD[InternalRow]] = {
sqlContext.sparkContext.parallelize(0 until numSlices, numSlices)
.map(i => InternalRow(i)) :: Nil
val rdd = if (start == end || (start < end ^ 0 < step)) {
new EmptyRDD[InternalRow](sqlContext.sparkContext)
} else {
sqlContext.sparkContext.parallelize(0 until numSlices, numSlices).map(i => InternalRow(i))
}
rdd :: Nil
}

protected override def doProduce(ctx: CodegenContext): String = {
Expand Down

0 comments on commit 89dd7ad

Please sign in to comment.