无法访问由createOrReplaceGlobalTempView创建的临时表

时间:2018-07-19 11:17:44

标签: apache-spark apache-spark-sql

我的代码在emr中不起作用

finalDF.createOrReplaceGlobalTempView("temp_visits")
spark.sql(s"insert overwrite table test PARTITION (date) SELECT * from temp_visits")

我遇到以下异常

Exception in thread "main" org.apache.spark.sql.AnalysisException: Table or view not found: temp_visits; line 1 pos 100
    at org.apache.spark.sql.catalyst.analysis.package$AnalysisErrorAt.failAnalysis(package.scala:42)
    at org.apache.spark.sql.catalyst.analysis.Analyzer$ResolveRelations$.org$apache$spark$sql$catalyst$analysis$Analyzer$ResolveRelations$$lookupTableFromCatalog(Analyzer.scala:663)

要识别该临时表,我需要添加任何设置吗?

1 个答案:

答案 0 :(得分:3)

需要在引用的全局视图中添加数据库名称。
默认的Spark设置具有数据库名称-global_temp

finalDF.createOrReplaceGlobalTempView("temp_visits")
spark.sql(s"insert overwrite table test PARTITION (date) SELECT * from global_temp.temp_visits")

您可以通过在sparkSession初始化期间提供配置来更改此名称-

  

spark.sql.globalTempDatabase