zsxwing commented on a change in pull request #22282: [SPARK-23539][SS] Add 
support for Kafka headers in Structured Streaming
URL: https://github.com/apache/spark/pull/22282#discussion_r306013346
 
 

 ##########
 File path: 
external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaOffsetReader.scala
 ##########
 @@ -423,13 +423,20 @@ private[kafka010] class KafkaOffsetReader(
 
 private[kafka010] object KafkaOffsetReader {
 
-  def kafkaSchema: StructType = StructType(Seq(
-    StructField("key", BinaryType),
-    StructField("value", BinaryType),
-    StructField("topic", StringType),
-    StructField("partition", IntegerType),
-    StructField("offset", LongType),
-    StructField("timestamp", TimestampType),
-    StructField("timestampType", IntegerType)
-  ))
+  def kafkaSchema(includeHeaders: Boolean): StructType = {
 
 Review comment:
   nit: maybe use the following lazy creation to avoid creating the schema in 
every call.
   ```scala
     private lazy val schemaWithoutHeaders = new StructType(Array(
       StructField("key", BinaryType),
       StructField("value", BinaryType),
       StructField("topic", StringType),
       StructField("partition", IntegerType),
       StructField("offset", LongType),
       StructField("timestamp", TimestampType),
       StructField("timestampType", IntegerType)
     ))
   
     private lazy val schemaWithHeaders = {
       val headersType = ArrayType(StructType(Array(
         StructField("key", StringType),
         StructField("value", BinaryType))))
       new StructType(schemaWithoutHeaders.fields :+ StructField("headers", 
headersType))
     }
   
     def kafkaSchema(includeHeaders: Boolean): StructType = {
       if (includeHeaders) schemaWithHeaders else schemaWithoutHeaders
     }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to