简体   繁体   English

如何使用 Databricks 的 Apache Spark 从 SQL 表中获取 stream 数据

[英]How to stream data from SQL Table with Apache Spark with Databricks

I am attempting to stream from sql table using the following:我正在尝试使用以下命令从 sql 表中获取 stream:

my_sales =  spark.read.jdbc(jdbcUrl, dbo.table)

static = spark.read.format("csv").load(my_sales)
dataSchema = static.schema

I am trying to read in the data from the table with the following:我正在尝试使用以下内容从表中读取数据:

rawdf = (spark.readStream 
      .format("csv") \
      .option("maxFilesPerTrigger", 1) \
      .schema(dataSchema) \
      .csv(dataPath)
           )

I am using the following to write the data to the following location我正在使用以下内容将数据写入以下位置

saveloc = '/mnt/raw/streaminglocation/'


streamingQuery = (
  rawdf
  .writeStream
  .format("csv")
  .outputMode("append")
  .option("checkpointLocation", f"{saveloc}/_checkpoints")
  .option("mergeSchema", "true")
  .start(saveloc)
)

However this failing.然而这失败了。

Is it possible to stream from a SQL table?是否可以从 SQL 表中获取 stream?

This is not possible.这是不可能的。 JDBC sources are not supported for Spark Structured Streaming. JDBC 源不支持 Spark 结构化流。

Not convinced of the upfront coding either.也不相信前期编码。

Use CDC with Kafka, or materialized updateable views with CDC with KAFKA, or Debezium.将 CDC 与 Kafka 一起使用,或将物化可更新视图与 KAFKA 或 Debezium 一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Apache Spark 在 Databricks 中使用 SQL 查询进行 CASTING 问题 - CASTING issue with SQL query in Databricks with Apache Spark 如何在 Databricks 的 Iceberg 表上执行 Spark SQL 合并语句? - How to execute a Spark SQL merge statement on an Iceberg table in Databricks? 如何使用 Databricks Data Explorer 从 Databricks 中删除表 - How to Delete Table from Databricks with Databricks Data Explorer 将 data.table 从 Databricks dbfs 导出到 azure sql 数据库 - Export data table from Databricks dbfs to azure sql database 使用 Databricks 上的 Apache Spark 将文件写入 delta lake 会产生与读取 Data Frame 不同的结果 - Writing out file to delta lake produces different results from Data Frame read using Apache Spark on Databricks 如何从 SQL 上的现有表在数据块中创建表 - How to create a table in databricks from an existing table on SQL 在Databricks中,SQL使用spark? - In Databricks, SQL uses spark? 如何从 Databricks 中的 JSON 或字典或键值对格式创建 Apache Spark DataFrame - How to Create an Apache Spark DataFrame from JSON or Dictonary or Key Value pairs format in Databricks 使用 Databricks(和 Apache Spark)从 AWS Redshift 读取 - Read from AWS Redshift using Databricks (and Apache Spark) 如何使用 Databricks 在 Apache Spark 上编译 PySpark 中的 While 循环语句 - How to Compile a While Loop statement in PySpark on Apache Spark with Databricks
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM