diff --git a/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala b/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala index 5a3c4089793..ef97412df61 100644 --- a/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala +++ b/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala @@ -742,7 +742,9 @@ class VeloxTestSettings extends BackendTestSettings { enableSuite[GlutenSQLFunctionSuite] enableSuite[GlutenSQLJsonProtocolSuite] enableSuite[GlutenShufflePartitionsUtilSuite] - // TODO: 4.x enableSuite[GlutenSimpleSQLViewSuite] // 1 failure + enableSuite[GlutenSimpleSQLViewSuite] + // Velox returns a native FILE_NOT_FOUND error instead of Spark's structured error condition. + .exclude("alter temporary view should follow current storeAnalyzedPlanForView config") enableSuite[GlutenSparkPlanSuite] .exclude("SPARK-37779: ColumnarToRowExec should be canonicalizable after being (de)serialized") enableSuite[GlutenSparkPlannerSuite] diff --git a/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/execution/GlutenSQLViewSuite.scala b/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/execution/GlutenSQLViewSuite.scala index ed79f3cb3fe..ab45a73803e 100644 --- a/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/execution/GlutenSQLViewSuite.scala +++ b/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/execution/GlutenSQLViewSuite.scala @@ -16,6 +16,45 @@ */ package org.apache.spark.sql.execution -import org.apache.spark.sql.GlutenSQLTestsTrait +import org.apache.spark.SparkException +import org.apache.spark.sql.{GlutenSQLTestsTrait, Row} +import org.apache.spark.sql.internal.SQLConf.STORE_ANALYZED_PLAN_FOR_VIEW -class GlutenSimpleSQLViewSuite extends SimpleSQLViewSuite with GlutenSQLTestsTrait {} +class GlutenSimpleSQLViewSuite extends SimpleSQLViewSuite with GlutenSQLTestsTrait { + import testImplicits._ + + private def assertMissingFileError(f: => Unit): Unit = { + val exception = intercept[SparkException](f) + val messages = Iterator + .iterate[Throwable](exception)(_.getCause) + .takeWhile(_ != null) + .flatMap(e => Option(e.getMessage)) + + assert(messages.exists(_.contains("FILE_NOT_FOUND"))) + } + + testGluten("alter temporary view should follow current storeAnalyzedPlanForView config") { + withTable("t") { + Seq(2, 3, 1).toDF("c1").write.format("parquet").saveAsTable("t") + withView("v1") { + withSQLConf(STORE_ANALYZED_PLAN_FOR_VIEW.key -> "true") { + sql("CREATE TEMPORARY VIEW v1 AS SELECT * FROM t") + Seq(4, 6, 5).toDF("c1").write.mode("overwrite").format("parquet").saveAsTable("t") + assertMissingFileError(sql("SELECT * FROM v1").collect()) + } + + withSQLConf(STORE_ANALYZED_PLAN_FOR_VIEW.key -> "false") { + sql("ALTER VIEW v1 AS SELECT * FROM t") + Seq(1, 3, 5).toDF("c1").write.mode("overwrite").format("parquet").saveAsTable("t") + checkAnswer(sql("SELECT * FROM v1"), Seq(Row(1), Row(3), Row(5))) + } + + withSQLConf(STORE_ANALYZED_PLAN_FOR_VIEW.key -> "true") { + sql("ALTER VIEW v1 AS SELECT * FROM t") + Seq(2, 4, 6).toDF("c1").write.mode("overwrite").format("parquet").saveAsTable("t") + assertMissingFileError(sql("SELECT * FROM v1").collect()) + } + } + } + } +} diff --git a/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala b/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala index 6aa17584f30..cfde4c291c2 100644 --- a/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala +++ b/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala @@ -721,7 +721,9 @@ class VeloxTestSettings extends BackendTestSettings { enableSuite[GlutenSQLFunctionSuite] enableSuite[GlutenSQLJsonProtocolSuite] enableSuite[GlutenShufflePartitionsUtilSuite] - // TODO: 4.x enableSuite[GlutenSimpleSQLViewSuite] // 1 failure remains after GLUTEN-11917 fix + enableSuite[GlutenSimpleSQLViewSuite] + // Velox returns a native FILE_NOT_FOUND error instead of Spark's structured error condition. + .exclude("alter temporary view should follow current storeAnalyzedPlanForView config") enableSuite[GlutenSparkPlanSuite] .exclude("SPARK-37779: ColumnarToRowExec should be canonicalizable after being (de)serialized") enableSuite[GlutenSparkPlannerSuite] diff --git a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/GlutenSQLViewSuite.scala b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/GlutenSQLViewSuite.scala index ed79f3cb3fe..ab45a73803e 100644 --- a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/GlutenSQLViewSuite.scala +++ b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/execution/GlutenSQLViewSuite.scala @@ -16,6 +16,45 @@ */ package org.apache.spark.sql.execution -import org.apache.spark.sql.GlutenSQLTestsTrait +import org.apache.spark.SparkException +import org.apache.spark.sql.{GlutenSQLTestsTrait, Row} +import org.apache.spark.sql.internal.SQLConf.STORE_ANALYZED_PLAN_FOR_VIEW -class GlutenSimpleSQLViewSuite extends SimpleSQLViewSuite with GlutenSQLTestsTrait {} +class GlutenSimpleSQLViewSuite extends SimpleSQLViewSuite with GlutenSQLTestsTrait { + import testImplicits._ + + private def assertMissingFileError(f: => Unit): Unit = { + val exception = intercept[SparkException](f) + val messages = Iterator + .iterate[Throwable](exception)(_.getCause) + .takeWhile(_ != null) + .flatMap(e => Option(e.getMessage)) + + assert(messages.exists(_.contains("FILE_NOT_FOUND"))) + } + + testGluten("alter temporary view should follow current storeAnalyzedPlanForView config") { + withTable("t") { + Seq(2, 3, 1).toDF("c1").write.format("parquet").saveAsTable("t") + withView("v1") { + withSQLConf(STORE_ANALYZED_PLAN_FOR_VIEW.key -> "true") { + sql("CREATE TEMPORARY VIEW v1 AS SELECT * FROM t") + Seq(4, 6, 5).toDF("c1").write.mode("overwrite").format("parquet").saveAsTable("t") + assertMissingFileError(sql("SELECT * FROM v1").collect()) + } + + withSQLConf(STORE_ANALYZED_PLAN_FOR_VIEW.key -> "false") { + sql("ALTER VIEW v1 AS SELECT * FROM t") + Seq(1, 3, 5).toDF("c1").write.mode("overwrite").format("parquet").saveAsTable("t") + checkAnswer(sql("SELECT * FROM v1"), Seq(Row(1), Row(3), Row(5))) + } + + withSQLConf(STORE_ANALYZED_PLAN_FOR_VIEW.key -> "true") { + sql("ALTER VIEW v1 AS SELECT * FROM t") + Seq(2, 4, 6).toDF("c1").write.mode("overwrite").format("parquet").saveAsTable("t") + assertMissingFileError(sql("SELECT * FROM v1").collect()) + } + } + } + } +}