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

    https://github.com/apache/spark/pull/6632#discussion_r31771864
  
    --- Diff: 
external/kafka/src/main/scala/org/apache/spark/streaming/kafka/KafkaRDD.scala 
---
    @@ -60,6 +62,49 @@ class KafkaRDD[
         }.toArray
       }
     
    +  override def count(): Long = offsetRanges.map(_.count).sum
    +
    +  override def countApprox(
    +      timeout: Long,
    +      confidence: Double = 0.95
    +  ): PartialResult[BoundedDouble] = {
    +    val c = count
    +    new PartialResult(new BoundedDouble(c, 1.0, c, c), true)
    +  }
    +
    +  override def isEmpty(): Boolean = count == 0L
    +
    +  override def take(num: Int): Array[R] = {
    +    val nonEmpty = this.partitions
    +      .map(_.asInstanceOf[KafkaRDDPartition])
    +      .filter(_.count > 0)
    +
    +    if (num < 1 || nonEmpty.size < 1) {
    +      return new Array[R](0)
    +    }
    +
    +    var remain = num.toLong
    +    // Determine in advance how many messages need to be taken from each 
partition
    +    val parts = nonEmpty.flatMap { part =>
    --- End diff --
    
    Since we have to do this non-functional style counting down, better to use 
`while` loop or `for` loop for this.


---
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