Pyspark Spark结构流中的临时视图

Pyspark Spark结构流中的临时视图,pyspark,apache-spark-sql,spark-streaming,spark-structured-streaming,pyspark-dataframes,Pyspark,Apache Spark Sql,Spark Streaming,Spark Structured Streaming,Pyspark Dataframes,在ForeachBatch函数Straming中,我想创建在微批处理中接收的数据帧的临时视图 func(tabdf, epoch_id): tabaDf.createOrReplaceView("taba") 但我得到了以下错误: org.apache.spark.sql.streaming.StreamingQueryException: Table or view not found: taba Caused by: org.apache.spark.sql.c

在ForeachBatch函数Straming中,我想创建在微批处理中接收的数据帧的临时视图

func(tabdf, epoch_id):
    tabaDf.createOrReplaceView("taba")
但我得到了以下错误:

org.apache.spark.sql.streaming.StreamingQueryException: Table or view not found: taba
Caused by: org.apache.spark.sql.catalyst.analysis.NoSuchTableException: Table or view 'taba' not found

请任何人帮助我解决此问题。

流式查询使用自己的SparkSession,它是从启动查询的SparkSession克隆而来的。由
foreachBatch
提供的
DataFrame
是从流式查询的SparkSession创建的。因此,您无法使用原始SparkSession访问临时视图


一种解决方法是使用
createGlobalTempView/createOrReplaceGlobalTempView
创建全局临时视图。请注意,全局临时视图绑定到系统保留的数据库
global\u temp
,您需要使用限定名称来引用全局临时视图,例如
SELECT*FROM global\u temp.view1

尝试使用“createOrReplaceTempView”功能我使用了相同的功能,但它不起作用。未获取在当前spark会话中创建的视图