You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "cloud-fan (via GitHub)" <gi...@apache.org> on 2023/05/09 01:49:50 UTC

[GitHub] [spark] cloud-fan commented on a diff in pull request #40989: [SPARK-43316][SQL][TESTS] Add more CTE SQL tests

cloud-fan commented on code in PR #40989:
URL: https://github.com/apache/spark/pull/40989#discussion_r1188038273


##########
sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala:
##########
@@ -418,6 +433,44 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession with SQLHelper
     }
   }
 
+  def expandCTEQueryAndCompareResult(
+      session: SparkSession,
+      query: String,
+      output: ExecutionOutput): Unit = {
+    val logicalPlan: LogicalPlan = session.sessionState.sqlParser.parsePlan(query)
+    // For non-command query with CTE, compare the results of selecting from view created on the
+    // original query.
+    if (!logicalPlan.isInstanceOf[Command] && output.schema.get != emptySchema) {
+      val createView = s"CREATE temporary VIEW cte_view AS $query"
+      val selectFromView = "SELECT * FROM cte_view"
+      val dropViewIfExists = "DROP VIEW IF EXISTS cte_view"
+      try {
+        session.sql(createView)
+      }
+      catch {
+        case e: AnalysisException =>
+          if (e.getMessage.contains("already exists")) {

Review Comment:
   catching the exception and checking the error message is unreliable. Can you follow https://github.com/apache/spark/pull/40989/files#r1188008135 ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org