HeartSaVioR 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_r315357993
##########
File path:
external/kafka-0-10-sql/src/test/scala/org/apache/spark/sql/kafka010/KafkaSinkSuite.scala
##########
@@ -368,15 +370,52 @@ abstract class KafkaSinkBatchSuiteBase extends
KafkaSinkSuiteBase {
test("batch - write to kafka") {
val topic = newTopic()
testUtils.createTopic(topic)
- val df = Seq("1", "2", "3", "4", "5").map(v => (topic, v)).toDF("topic",
"value")
+ val data = Seq(
+ Row(topic, "1", Seq(
+ Row("a", "b".getBytes(UTF_8))
+ )),
+ Row(topic, "2", Seq(
+ Row("c", "d".getBytes(UTF_8)),
+ Row("e", "f".getBytes(UTF_8))
+ )),
+ Row(topic, "3", Seq(
+ Row("g", "h".getBytes(UTF_8)),
+ Row("g", "i".getBytes(UTF_8))
+ )),
+ Row(topic, "4", null),
+ Row(topic, "5", Seq(
+ Row("j", "k".getBytes(UTF_8)),
+ Row("j", "l".getBytes(UTF_8)),
+ Row("m", "n".getBytes(UTF_8))
+ ))
+ )
+
+ val df = spark.createDataFrame(
+ spark.sparkContext.parallelize(data),
+ StructType(Seq(StructField("topic", StringType), StructField("value",
StringType),
+ StructField("headers", KafkaOffsetReader.headersType)))
+ )
+
df.write
.format("kafka")
.option("kafka.bootstrap.servers", testUtils.brokerAddress)
.option("topic", topic)
.save()
checkAnswer(
- createKafkaReader(topic).selectExpr("CAST(value as STRING) value"),
- Row("1") :: Row("2") :: Row("3") :: Row("4") :: Row("5") :: Nil)
+ createKafkaReader(topic, includeHeaders = true).selectExpr(
+ "CAST(value as STRING) value",
+ "CAST(headers as ARRAY<STRUCT<key:STRING,value:BINARY>>) headers"
Review comment:
Just a sake of understanding, is the "cast" for headers mandatory? We casted
value as STRING because it's binary, and
`ARRAY<STRUCT<key:STRING,value:BINARY>>` seems to be expected type of headers,
so curious what's happening we don't cast.
----------------------------------------------------------------
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]