Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10335#discussion_r47829265
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/basicOperators.scala ---
    @@ -126,6 +127,69 @@ case class Sample(
       }
     }
     
    +case class Range(
    +    start: Long,
    +    step: Long,
    +    numSlices: Int,
    +    numElements: BigInt,
    +    output: Seq[Attribute])
    +  extends LeafNode
    +{
    +  override def outputsUnsafeRows: Boolean = true
    +
    +  protected override def doExecute(): RDD[InternalRow] = {
    +    sqlContext
    +      .sparkContext
    +      .parallelize(0 until numSlices, numSlices)
    +      .mapPartitionsWithIndex((i, _) => {
    +        val partitionStart = (i * numElements) / numSlices * step + start
    +        val partitionEnd = (((i + 1) * numElements) / numSlices) * step + 
start
    +        def getSafeMargin(bi: BigInt): Long =
    +          if (bi.isValidLong) {
    +            bi.toLong
    +          } else if (bi > 0) {
    +            Long.MaxValue
    +          } else {
    +            Long.MinValue
    +          }
    +        val safePartitionStart = getSafeMargin(partitionStart)
    +        val safePartitionEnd = getSafeMargin(partitionEnd)
    +        val bufferHolder = new BufferHolder(LongType.defaultSize)
    +        val unsafeRow = new UnsafeRow
    +
    +        new Iterator[InternalRow] {
    +          private[this] var number: Long = safePartitionStart
    +          private[this] var overflow: Boolean = false
    +
    +          override def hasNext =
    +            if (!overflow) {
    --- End diff --
    
    To be honest, this is copied from RDD.range APIs. I have the same question 
like you. For safety, I keep it. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to