From 1b345fd2197dcab6ab639a7fbc172964b262d467 Mon Sep 17 00:00:00 2001 From: Vipul Vaibhaw Date: Tue, 28 May 2024 21:41:28 +0530 Subject: [PATCH] using withTempDir and checkSparkAnswerAndOperator --- .../apache/comet/CometExpressionSuite.scala | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala b/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala index 280ecb879..a4c81d1e6 100644 --- a/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala +++ b/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala @@ -1470,36 +1470,34 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper { } } test("unary negative integer overflow test") { + withTempDir { dir => + val path = new Path(dir.toURI.toString, "int.parquet") + val df = Seq(Int.MaxValue, Int.MinValue).toDF("a") + df.write.mode("overwrite").parquet(path.toString) + spark.read.parquet(path.toString).createTempView("t") - val df = Seq(Int.MaxValue, Int.MinValue).toDF("a") - df.write.mode("overwrite").parquet("/tmp/int.parquet") - spark.read.parquet("/tmp/int.parquet").createTempView("t") - - // without ANSI mode - withSQLConf( - SQLConf.ANSI_ENABLED.key -> "false", - CometConf.COMET_ANSI_MODE_ENABLED.key -> "false", - CometConf.COMET_ENABLED.key -> "true", - CometConf.COMET_EXEC_ENABLED.key -> "true") { - checkSparkMaybeThrows(sql("select a, -a from t")) match { - case (None, None) => // no exception - case _ => - fail("No exception should be thrown") + // without ANSI mode + withSQLConf( + SQLConf.ANSI_ENABLED.key -> "false", + CometConf.COMET_ANSI_MODE_ENABLED.key -> "false", + CometConf.COMET_ENABLED.key -> "true", + CometConf.COMET_EXEC_ENABLED.key -> "true") { + checkSparkAnswerAndOperator(sql("select a, -a from t")) } - } - // with ANSI mode - withSQLConf( - SQLConf.ANSI_ENABLED.key -> "true", - CometConf.COMET_ANSI_MODE_ENABLED.key -> "true", - CometConf.COMET_ENABLED.key -> "true", - CometConf.COMET_EXEC_ENABLED.key -> "true") { - checkSparkMaybeThrows(sql("select a, -a from t")) match { - case (Some(sparkException), Some(cometException)) => - assert(sparkException.getMessage.contains("integer overflow")) - assert(cometException.getMessage.contains("integer overflow")) - case _ => - fail("Exception should be thrown") + // with ANSI mode + withSQLConf( + SQLConf.ANSI_ENABLED.key -> "true", + CometConf.COMET_ANSI_MODE_ENABLED.key -> "true", + CometConf.COMET_ENABLED.key -> "true", + CometConf.COMET_EXEC_ENABLED.key -> "true") { + checkSparkMaybeThrows(sql("select a, -a from t")) match { + case (Some(sparkException), Some(cometException)) => + assert(sparkException.getMessage.contains("integer overflow")) + assert(cometException.getMessage.contains("integer overflow")) + case _ => + fail("Exception should be thrown") + } } } }