William1104 commented on issue #24747: [SPARK-27772][SQL][TEST] Refactor 
SQLTestUtils to use `tryWithSafeFinally`
URL: https://github.com/apache/spark/pull/24747#issuecomment-500472917
 
 
   Before this patch, below test fails with a `NullPointerException` even 
though the test should fail with a ParserException instead. The 
`NullPointerException` throwing from the finally block mask what fails the test 
initially. 
   
   ```
   test("SPARK-27772") {
       spark.range(1, 10).toDF("key").withColumn("value", 'key * 2)
         .write.format("json").saveAsTable("t")
       withTempView("d1.t1", "d2.t2",null) {
         sql("CACHE TABLE t")
         sql("CACHE TABLE d1.t1 AS SELECT * FROM t WHERE key > 1")
         sql("CACHE TABLE d2.t2 AS SELECT * FROM d1.t1 WHERE value > 1")
   
         assert(spark.catalog.isCached("t"))
         assert(spark.catalog.isCached("d1.t1"))
         assert(spark.catalog.isCached("d2.t2"))
         sql("UNCACHE TABLE t")
         assert(!spark.catalog.isCached("t"))
         assert(!spark.catalog.isCached("d1.t1"))
         assert(!spark.catalog.isCached("d2.t2"))
       }
     }
   ```
   
   It is the exception stacktrace. 
   ```
   [info] - SPARK-27772 *** FAILED *** (3 seconds, 447 milliseconds)
   [info]   java.lang.NullPointerException:
   [info]   at 
org.apache.spark.sql.catalyst.catalog.SessionCatalog.formatTableName(SessionCatalog.scala:124)
   [info]   at 
org.apache.spark.sql.catalyst.catalog.SessionCatalog.getTempView(SessionCatalog.scala:536)
   [info]   at 
org.apache.spark.sql.internal.CatalogImpl.dropTempView(CatalogImpl.scala:366)
   [info]   at 
org.apache.spark.sql.test.SQLTestUtilsBase.$anonfun$withTempView$1(SQLTestUtils.scala:260)
   [info]   at 
scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
   ```
   
   After applying the patch, the `NullPointerException` would not mask the 
`ParserException` anymore. 
   
   ```
   [info] - SPARK-27772 *** FAILED *** (3 seconds, 617 milliseconds)
   [info]   org.apache.spark.sql.catalyst.parser.ParseException: It is not 
allowed to add database prefix `d1` to the table name in CACHE TABLE AS 
SELECT(line 1, pos 0)
   [info]
   [info] == SQL ==
   [info] CACHE TABLE d1.t1 AS SELECT * FROM t WHERE key > 1
   [info] ^^^
   [info]   at 
org.apache.spark.sql.execution.SparkSqlAstBuilder.$anonfun$visitCacheTable$1(SparkSqlParser.scala:283)
   [info]   at 
org.apache.spark.sql.catalyst.parser.ParserUtils$.withOrigin(ParserUtils.scala:108)
   [info]   at 
org.apache.spark.sql.execution.SparkSqlAstBuilder.visitCacheTable(SparkSqlParser.scala:277)
   [info]   at 
org.apache.spark.sql.execution.SparkSqlAstBuilder.visitCacheTable(SparkSqlParser.scala:55)
   [info]   at 
org.apache.spark.sql.catalyst.parser.SqlBaseParser$CacheTableContext.accept(SqlBaseParser.java:2296)
   [info]   at 
org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:18)
   [info]   at 
org.apache.spark.sql.catalyst.parser.AstBuilder.$anonfun$visitSingleStatement$1(AstBuilder.scala:75)
   [info]   at 
org.apache.spark.sql.catalyst.parser.ParserUtils$.withOrigin(ParserUtils.scala:108)
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to