code show as below:
val sparkSession = DataExtract.getSparkSession("testName")
sparkSession.sql("use hive")
val df1 = sparkSession.sql("SELECT * from test1 ")
df1.createOrReplaceTempView("test1")
df1.createOrReplaceTempView("test1")
val df = sparkSession.sql("SELECT * from test1 ")
df.createOrReplaceTempView("test1")
When I execute this code, the first time I execute the createOrReplaceTempView method is successful, and then use the same dataframe to execute the createOrReplaceTempView method again is also successful, but when I use another dataframe to createOrReplaceTempView with the same name Report an error, the error is as follows:
Exception in thread "main" org.apache.spark.sql.AnalysisException: Recursive view `test1` detected (cycle: `test1` -> `test1`)
at org.apache.spark.sql.errors.QueryCompilationErrors$.recursiveViewDetectedError(QueryCompilationErrors.scala:2045)
at org.apache.spark.sql.execution.command.ViewHelper$.checkCyclicViewReference(views.scala:515)
at org.apache.spark.sql.execution.command.ViewHelper$.$anonfun$checkCyclicViewReference$2(views.scala:522)
at org.apache.spark.sql.execution.command.ViewHelper$.$anonfun$checkCyclicViewReference$2$adapted(views.scala:522)
at scala.collection.Iterator.foreach(Iterator.scala:944)
at scala.collection.Iterator.foreach$(Iterator.scala:944)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1432)
This problem has troubled me for a long time. There was no such problem in the previous version of spark3.1.1. It suddenly appeared after the upgraded version. I hope someone can help me. I'm very grateful. Thank you.