Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][SPARK-29228][SS] Adding the ability to add headers to the KafkaRecords published to Kafka from spark structured streaming #25916

Closed
wants to merge 3 commits into from

Conversation

jhsb25
Copy link

@jhsb25 jhsb25 commented Sep 24, 2019

What changes were proposed in this pull request?

The changes in the pull request allow a developer to provide a column within their structured streaming dataframe titled header and of type map<string, string> which when the dataframe is sinked to kafka the headers will be applied to the producer record. This can have many applications but the main reason we wanted this introduced was for tracing purposes.

Why are the changes needed?

Sometimes it is necessary to add custom headers to the kafka producer record but with the current spark-kafka sink this is not possible, these changes make it optional to add headers to the kafka records that will be produced.

Does this PR introduce any user-facing change?

If the user wants to apply headers in the records that will be published to kafka they can provide a new column of type map<string, string> with the title header:

df.selectExpr("topic", "CAST(key AS STRING)", "CAST(value AS STRING)", "map('custom-header-1', 'foo', 'custom-header-2', 'bar') as headers")
  .write
  .format("kafka")
  .option("kafka.bootstrap.servers", "host1:port1,host2:port2")
  .save()

How was this patch tested?

Unit tests have been added and it has been tested thoroughly on a cluster.

Randal Boyle added 2 commits September 24, 2019 12:59
# Conflicts:
#	external/kafka-0-10-sql/src/main/scala/org/apache/spark/sql/kafka010/KafkaStreamingWrite.scala
@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@jhsb25 jhsb25 changed the title [SPARK-29228][SS] Adding the ability to add headers to the KafkaRecords published to Kafka from spark structured streaming [WIP][SPARK-29228][SS] Adding the ability to add headers to the KafkaRecords published to Kafka from spark structured streaming Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants