Skip to content

Commit

Permalink
fix ut
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoyangxiaozhu committed Jul 6, 2024
1 parent e667e65 commit 369170e
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ class VeloxTestSettings extends BackendTestSettings {
.exclude("sliding range between with aggregation")
.exclude("store and retrieve column stats in different time zones")
enableSuite[GlutenColumnExpressionSuite]
// Velox raise_error('errMsg') throws a velox_user_error exception with the message 'errMsg'.
// The final caught Spark exception's getCause().getMessage() contains 'errMsg' but does not
// equal 'errMsg' exactly. The following two tests will be skipped and overridden in Gluten.
.exclude("raise_error")
.exclude("assert_true")
enableSuite[GlutenDataFrameImplicitsSuite]
enableSuite[GlutenGeneratorFunctionSuite]
enableSuite[GlutenDataFrameTimeWindowingSuite]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,61 @@
*/
package org.apache.spark.sql

import org.apache.spark.SparkException
import org.apache.spark.sql.execution.ProjectExec
import org.apache.spark.sql.functions.{expr, input_file_name}
import org.apache.spark.sql.functions.{assert_true, expr, input_file_name, lit, raise_error}
import org.apache.spark.sql.types.{ArrayType, IntegerType, StringType, StructField, StructType}

class GlutenColumnExpressionSuite extends ColumnExpressionSuite with GlutenSQLTestsTrait {
import testImplicits._
testGluten("raise_error") {
val strDf = Seq(("hello")).toDF("a")

val e1 = intercept[SparkException] {
strDf.select(raise_error(lit(null.asInstanceOf[String]))).collect()
}
assert(e1.getCause.isInstanceOf[RuntimeException])

val e2 = intercept[SparkException] {
strDf.select(raise_error($"a")).collect()
}
assert(e2.getCause.isInstanceOf[RuntimeException])
assert(e2.getCause.getMessage contains "hello")
}

testGluten("assert_true") {
// assert_true(condition, errMsgCol)
val booleanDf = Seq((true), (false)).toDF("cond")
checkAnswer(
booleanDf.filter("cond = true").select(assert_true($"cond")),
Row(null) :: Nil
)
val e1 = intercept[SparkException] {
booleanDf.select(assert_true($"cond", lit(null.asInstanceOf[String]))).collect()
}
assert(e1.getCause.isInstanceOf[RuntimeException])

val nullDf = Seq(("first row", None), ("second row", Some(true))).toDF("n", "cond")
checkAnswer(
nullDf.filter("cond = true").select(assert_true($"cond", $"cond")),
Row(null) :: Nil
)
val e2 = intercept[SparkException] {
nullDf.select(assert_true($"cond", $"n")).collect()
}
assert(e2.getCause.isInstanceOf[RuntimeException])
assert(e2.getCause.getMessage contains "first row")

// assert_true(condition)
val intDf = Seq((0, 1)).toDF("a", "b")
checkAnswer(intDf.select(assert_true($"a" < $"b")), Row(null) :: Nil)
val e3 = intercept[SparkException] {
intDf.select(assert_true($"a" > $"b")).collect()
}
assert(e3.getCause.isInstanceOf[RuntimeException])
assert(e3.getCause.getMessage contains "'('a > 'b)' is not true!")
}

testGluten("input_file_name with scan is fallback") {
withTempPath {
dir =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,11 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenFileSourceCharVarcharTestSuite]
enableSuite[GlutenDSV2CharVarcharTestSuite]
enableSuite[GlutenColumnExpressionSuite]
// Velox raise_error('errMsg') throws a velox_user_error exception with the message 'errMsg'.
// The final caught Spark exception's getCause().getMessage() contains 'errMsg' but does not
// equal 'errMsg' exactly. The following two tests will be skipped and overridden in Gluten.
.exclude("raise_error")
.exclude("assert_true")
enableSuite[GlutenComplexTypeSuite]
enableSuite[GlutenConfigBehaviorSuite]
// Will be fixed by cleaning up ColumnarShuffleExchangeExec.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,61 @@
*/
package org.apache.spark.sql

import org.apache.spark.SparkException
import org.apache.spark.sql.execution.ProjectExec
import org.apache.spark.sql.functions.{expr, input_file_name}
import org.apache.spark.sql.functions.{assert_true, expr, input_file_name, lit, raise_error}
import org.apache.spark.sql.types.{ArrayType, IntegerType, StringType, StructField, StructType}

class GlutenColumnExpressionSuite extends ColumnExpressionSuite with GlutenSQLTestsTrait {
import testImplicits._
testGluten("raise_error") {
val strDf = Seq(("hello")).toDF("a")

val e1 = intercept[SparkException] {
strDf.select(raise_error(lit(null.asInstanceOf[String]))).collect()
}
assert(e1.getCause.isInstanceOf[RuntimeException])

val e2 = intercept[SparkException] {
strDf.select(raise_error($"a")).collect()
}
assert(e2.getCause.isInstanceOf[RuntimeException])
assert(e2.getCause.getMessage contains "hello")
}

testGluten("assert_true") {
// assert_true(condition, errMsgCol)
val booleanDf = Seq((true), (false)).toDF("cond")
checkAnswer(
booleanDf.filter("cond = true").select(assert_true($"cond")),
Row(null) :: Nil
)
val e1 = intercept[SparkException] {
booleanDf.select(assert_true($"cond", lit(null.asInstanceOf[String]))).collect()
}
assert(e1.getCause.isInstanceOf[RuntimeException])

val nullDf = Seq(("first row", None), ("second row", Some(true))).toDF("n", "cond")
checkAnswer(
nullDf.filter("cond = true").select(assert_true($"cond", $"cond")),
Row(null) :: Nil
)
val e2 = intercept[SparkException] {
nullDf.select(assert_true($"cond", $"n")).collect()
}
assert(e2.getCause.isInstanceOf[RuntimeException])
assert(e2.getCause.getMessage contains "first row")

// assert_true(condition)
val intDf = Seq((0, 1)).toDF("a", "b")
checkAnswer(intDf.select(assert_true($"a" < $"b")), Row(null) :: Nil)
val e3 = intercept[SparkException] {
intDf.select(assert_true($"a" > $"b")).collect()
}
assert(e3.getCause.isInstanceOf[RuntimeException])
assert(e3.getCause.getMessage contains "'('a > 'b)' is not true!")
}

testGluten("input_file_name with scan is fallback") {
withTempPath {
dir =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,11 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenFileSourceCharVarcharTestSuite]
enableSuite[GlutenDSV2CharVarcharTestSuite]
enableSuite[GlutenColumnExpressionSuite]
// Velox raise_error('errMsg') throws a velox_user_error exception with the message 'errMsg'.
// The final caught Spark exception's getCause().getMessage() contains 'errMsg' but does not
// equal 'errMsg' exactly. The following two tests will be skipped and overridden in Gluten.
.exclude("raise_error")
.exclude("assert_true")
enableSuite[GlutenComplexTypeSuite]
enableSuite[GlutenConfigBehaviorSuite]
// Will be fixed by cleaning up ColumnarShuffleExchangeExec.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,61 @@
*/
package org.apache.spark.sql

import org.apache.spark.SparkException
import org.apache.spark.sql.execution.ProjectExec
import org.apache.spark.sql.functions.{expr, input_file_name}
import org.apache.spark.sql.functions.{assert_true, expr, input_file_name, lit, raise_error}
import org.apache.spark.sql.types.{ArrayType, IntegerType, StringType, StructField, StructType}

class GlutenColumnExpressionSuite extends ColumnExpressionSuite with GlutenSQLTestsTrait {
import testImplicits._
testGluten("raise_error") {
val strDf = Seq(("hello")).toDF("a")

val e1 = intercept[SparkException] {
strDf.select(raise_error(lit(null.asInstanceOf[String]))).collect()
}
assert(e1.getCause.isInstanceOf[RuntimeException])

val e2 = intercept[SparkException] {
strDf.select(raise_error($"a")).collect()
}
assert(e2.getCause.isInstanceOf[RuntimeException])
assert(e2.getCause.getMessage contains "hello")
}

testGluten("assert_true") {
// assert_true(condition, errMsgCol)
val booleanDf = Seq((true), (false)).toDF("cond")
checkAnswer(
booleanDf.filter("cond = true").select(assert_true($"cond")),
Row(null) :: Nil
)
val e1 = intercept[SparkException] {
booleanDf.select(assert_true($"cond", lit(null.asInstanceOf[String]))).collect()
}
assert(e1.getCause.isInstanceOf[RuntimeException])

val nullDf = Seq(("first row", None), ("second row", Some(true))).toDF("n", "cond")
checkAnswer(
nullDf.filter("cond = true").select(assert_true($"cond", $"cond")),
Row(null) :: Nil
)
val e2 = intercept[SparkException] {
nullDf.select(assert_true($"cond", $"n")).collect()
}
assert(e2.getCause.isInstanceOf[RuntimeException])
assert(e2.getCause.getMessage contains "first row")

// assert_true(condition)
val intDf = Seq((0, 1)).toDF("a", "b")
checkAnswer(intDf.select(assert_true($"a" < $"b")), Row(null) :: Nil)
val e3 = intercept[SparkException] {
intDf.select(assert_true($"a" > $"b")).collect()
}
assert(e3.getCause.isInstanceOf[RuntimeException])
assert(e3.getCause.getMessage contains "'('a > 'b)' is not true!")
}

testGluten("input_file_name with scan is fallback") {
withTempPath {
dir =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,11 @@ class VeloxTestSettings extends BackendTestSettings {
enableSuite[GlutenFileSourceCharVarcharTestSuite]
enableSuite[GlutenDSV2CharVarcharTestSuite]
enableSuite[GlutenColumnExpressionSuite]
// Velox raise_error('errMsg') throws a velox_user_error exception with the message 'errMsg'.
// The final caught Spark exception's getCause().getMessage() contains 'errMsg' but does not
// equal 'errMsg' exactly. The following two tests will be skipped and overridden in Gluten.
.exclude("raise_error")
.exclude("assert_true")
enableSuite[GlutenComplexTypeSuite]
enableSuite[GlutenConfigBehaviorSuite]
// Will be fixed by cleaning up ColumnarShuffleExchangeExec.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,61 @@
*/
package org.apache.spark.sql

import org.apache.spark.SparkException
import org.apache.spark.sql.execution.ProjectExec
import org.apache.spark.sql.functions.{expr, input_file_name}
import org.apache.spark.sql.functions.{assert_true, expr, input_file_name, lit, raise_error}
import org.apache.spark.sql.types._

class GlutenColumnExpressionSuite extends ColumnExpressionSuite with GlutenSQLTestsTrait {
import testImplicits._
testGluten("raise_error") {
val strDf = Seq(("hello")).toDF("a")

val e1 = intercept[SparkException] {
strDf.select(raise_error(lit(null.asInstanceOf[String]))).collect()
}
assert(e1.getCause.isInstanceOf[RuntimeException])

val e2 = intercept[SparkException] {
strDf.select(raise_error($"a")).collect()
}
assert(e2.getCause.isInstanceOf[RuntimeException])
assert(e2.getCause.getMessage contains "hello")
}

testGluten("assert_true") {
// assert_true(condition, errMsgCol)
val booleanDf = Seq((true), (false)).toDF("cond")
checkAnswer(
booleanDf.filter("cond = true").select(assert_true($"cond")),
Row(null) :: Nil
)
val e1 = intercept[SparkException] {
booleanDf.select(assert_true($"cond", lit(null.asInstanceOf[String]))).collect()
}
assert(e1.getCause.isInstanceOf[RuntimeException])

val nullDf = Seq(("first row", None), ("second row", Some(true))).toDF("n", "cond")
checkAnswer(
nullDf.filter("cond = true").select(assert_true($"cond", $"cond")),
Row(null) :: Nil
)
val e2 = intercept[SparkException] {
nullDf.select(assert_true($"cond", $"n")).collect()
}
assert(e2.getCause.isInstanceOf[RuntimeException])
assert(e2.getCause.getMessage contains "first row")

// assert_true(condition)
val intDf = Seq((0, 1)).toDF("a", "b")
checkAnswer(intDf.select(assert_true($"a" < $"b")), Row(null) :: Nil)
val e3 = intercept[SparkException] {
intDf.select(assert_true($"a" > $"b")).collect()
}
assert(e3.getCause.isInstanceOf[RuntimeException])
assert(e3.getCause.getMessage contains "'('a > 'b)' is not true!")
}

testGluten("input_file_name with scan is fallback") {
withTempPath {
dir =>
Expand Down

0 comments on commit 369170e

Please sign in to comment.