java—将数据流式传输到delta lake,读取过滤结果

8yparm6h  于 2021-05-19  发布在  Spark
关注(0)|答案(1)|浏览(382)

我的目标是不断地将传入的parquet文件放入delta lake,进行查询,并将结果放入restapi。所有文件都在s3存储桶中。

//listen for changes
val df = spark.readStream().parquet("s3a://myBucket/folder")

//write changes to delta lake
df.writeStream()
    .format("delta")
    .option("checkpointLocation", "s3a://myBucket-processed/checkpoint")
    .start("s3a://myBucket-processed/")
    .awaitTermination() //this call lives in another thread (because it's blocking)

//this is a bad example
val query = df.select(convertedColumnNames) 
query.show()

//another bad example:
spark.readStream().format("delta").load("s3a://myBucket-processed/").select(convertedColumnNames).show()

//org.apache.spark.sql.AnalysisException: Queries with streaming sources must be executed with writeStream.start();;

我如何从三角洲湖得到过滤后的数据?

balp4ylt

balp4ylt1#

你试过用foreachbatch吗?
它将所有类似批处理的特性引入流式处理,您还可以在某种程度上控制要写入delta-lake的文件数量。

相关问题