Skip to content

Commit

Permalink
using withTempDir and checkSparkAnswerAndOperator
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhawvipul committed May 28, 2024
1 parent dcd1686 commit 1b345fd
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
}
Expand Down

0 comments on commit 1b345fd

Please sign in to comment.