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

    https://github.com/apache/spark/pull/11863#discussion_r60089024
  
    --- Diff: 
external/kafka-beta/src/main/scala/org/apache/spark/streaming/kafka/KafkaRDD.scala
 ---
    @@ -0,0 +1,259 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.streaming.kafka
    +
    +import java.{ util => ju }
    +
    +import scala.collection.mutable.ArrayBuffer
    +import scala.reflect.{classTag, ClassTag}
    +
    +import org.apache.kafka.clients.consumer.{ ConsumerConfig, ConsumerRecord }
    +import org.apache.kafka.common.TopicPartition
    +
    +import org.apache.spark.{Partition, SparkContext, SparkException, 
TaskContext}
    +import org.apache.spark.internal.Logging
    +import org.apache.spark.partial.{BoundedDouble, PartialResult}
    +import org.apache.spark.rdd.RDD
    +import org.apache.spark.scheduler.ExecutorCacheTaskLocation
    +import org.apache.spark.storage.StorageLevel
    +
    +/**
    + * A batch-oriented interface for consuming from Kafka.
    + * Starting and ending offsets are specified in advance,
    + * so that you can control exactly-once semantics.
    + * @param kafkaParams Kafka
    + * <a 
href="http://kafka.apache.org/documentation.htmll#newconsumerconfigs";>
    + * configuration parameters</a>. Requires "bootstrap.servers" to be set
    + * with Kafka broker(s) specified in host1:port1,host2:port2 form.
    + * @param offsetRanges offset ranges that define the Kafka data belonging 
to this RDD
    + */
    +
    +class KafkaRDD[
    +  K: ClassTag,
    +  V: ClassTag] private[spark] (
    +    sc: SparkContext,
    +    val kafkaParams: ju.Map[String, Object],
    +    val offsetRanges: Array[OffsetRange],
    +    val preferredHosts: ju.Map[TopicPartition, String]
    +) extends RDD[ConsumerRecord[K, V]](sc, Nil) with Logging with 
HasOffsetRanges {
    +
    +  assert("none" ==
    +    
kafkaParams.get(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG).asInstanceOf[String],
    +    ConsumerConfig.AUTO_OFFSET_RESET_CONFIG +
    +      " must be set to none for executor kafka params, else messages may 
not match offsetRange")
    +
    +  assert(false ==
    +    
kafkaParams.get(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG).asInstanceOf[Boolean],
    +    ConsumerConfig.AUTO_OFFSET_RESET_CONFIG +
    +      " must be set to false for executor kafka params, else offsets may 
commit before processing")
    +
    +  // TODO is it necessary to have separate configs for initial poll time 
vs ongoing poll time?
    +  private val pollTimeout = 
conf.getLong("spark.streaming.kafka.consumer.poll.ms", 256)
    +  private val cacheInitialCapacity =
    +    conf.getInt("spark.streaming.kafka.consumer.cache.initialCapacity", 16)
    +  private val cacheMaxCapacity =
    +    conf.getInt("spark.streaming.kafka.consumer.cache.maxCapacity", 64)
    +  private val cacheLoadFactor =
    +    conf.getDouble("spark.streaming.kafka.consumer.cache.loadFactor", 
0.75).toFloat
    +
    +  override def persist(newLevel: StorageLevel): this.type = {
    +    log.error("Kafka ConsumerRecord is not serializable. " +
    +      "Use .map to extract fields before calling .persist or .window")
    +    super.persist(newLevel)
    +  }
    +
    +  override def getPartitions: Array[Partition] = {
    +    offsetRanges.zipWithIndex.map { case (o, i) =>
    +        new KafkaRDDPartition(i, o.topic, o.partition, o.fromOffset, 
o.untilOffset)
    +    }.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[ConsumerRecord[K, V]] = {
    +    val nonEmptyPartitions = this.partitions
    +      .map(_.asInstanceOf[KafkaRDDPartition])
    +      .filter(_.count > 0)
    +
    +    if (num < 1 || nonEmptyPartitions.size < 1) {
    --- End diff --
    
    I don't really want to make style changes to code that's identical to the 
existing working consumer.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to