Apache spark 如何将流式查询结果写入多个数据库表?

Apache spark 如何将流式查询结果写入多个数据库表?,apache-spark,apache-spark-sql,spark-structured-streaming,Apache Spark,Apache Spark Sql,Spark Structured Streaming,我正在使用spark结构化流媒体和卡夫卡主题的阅读。目标是将消息写入PostgreSQL数据库的多个表中 消息架构是: root |-- id: string (nullable = true) |-- name: timestamp (nullable = true) |-- comment: string (nullable = true) |-- map_key_value: map (nullable = true) |-- key: string |-

我正在使用spark结构化流媒体和卡夫卡主题的阅读。目标是将消息写入PostgreSQL数据库的多个表中

消息架构是:

 root
  |-- id: string (nullable = true)
  |-- name: timestamp (nullable = true)
  |-- comment: string (nullable = true)
  |-- map_key_value: map (nullable = true)
    |-- key: string
    |-- value: string (valueContainsNull = true)
在删除map_key_值后写入一个表时,使用以下代码:

我的代码是:

message.writeStream.foreachBatch { (batchDF: DataFrame, batchId: Long) =>
    batchDF.write.format("jdbc").option("url", "url")
      .option("user", "username")
      .option("password", "password")
      .option(JDBCOptions.JDBC_TABLE_NAME, "table_1')
      .mode(SaveMode.Append).save();
  }.outputMode(OutputMode.Append()).start().awaitTermination()

我想将消息写入两个DB表表1(id、名称、注释),表2需要有map_key_值。

您将需要N个流式查询来查询N个接收器;t1和t2都算作一个单独的接收器

writeStream当前不写入jdbc,所以应该使用运算符