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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to