Skip to content

Commit 30d08ca

Browse files
committed
Address comments.
1 parent 91978e7 commit 30d08ca

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ case class Reverse(child: Expression) extends UnaryExpression with ImplicitCastI
12531253
val initialization = if (isPrimitiveType) {
12541254
ctx.createUnsafeArray(arrayData, numElements, elementType, s" $prettyName failed.")
12551255
} else {
1256-
val arrayDataClass = classOf[GenericArrayData].getName()
1256+
val arrayDataClass = classOf[GenericArrayData].getName
12571257
s"$arrayDataClass $arrayData = new $arrayDataClass(new Object[$numElements]);"
12581258
}
12591259

sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,7 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {
901901
}
902902
}
903903

904-
test("reverse function") {
905-
// String test cases
904+
test("reverse function - string") {
906905
val oneRowDF = Seq(("Spark", 3215)).toDF("s", "i")
907906
def testString(): Unit = {
908907
checkAnswer(oneRowDF.select(reverse('s)), Seq(Row("krapS")))
@@ -917,8 +916,9 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {
917916
// Test with cached relation, the Project will be evaluated with codegen
918917
oneRowDF.cache()
919918
testString()
919+
}
920920

921-
// Array test cases (primitive-type elements, containsNull = false)
921+
test("reverse function - array for primitive type not containing null") {
922922
val idfNotContainsNull = Seq(
923923
Seq(1, 9, 8, 7),
924924
Seq(5, 8, 9, 7, 2),
@@ -942,8 +942,9 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {
942942
// Test with cached relation, the Project will be evaluated with codegen
943943
idfNotContainsNull.cache()
944944
testArrayOfPrimitiveTypeNotContainsNull()
945+
}
945946

946-
// Array test cases (primitive-type elements, containsNull = true)
947+
test("reverse function - array for primitive type containing null") {
947948
val idfContainsNull = Seq[Seq[Integer]](
948949
Seq(1, 9, 8, null, 7),
949950
Seq(null, 5, 8, 9, 7, 2),
@@ -967,8 +968,9 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {
967968
// Test with cached relation, the Project will be evaluated with codegen
968969
idfContainsNull.cache()
969970
testArrayOfPrimitiveTypeContainsNull()
971+
}
970972

971-
// Array test cases (non-primitive-type elements)
973+
test("reverse function - array for non-primitive type") {
972974
val sdf = Seq(
973975
Seq("c", "a", "b"),
974976
Seq("b", null, "c", null),
@@ -996,14 +998,18 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {
996998
// Test with cached relation, the Project will be evaluated with codegen
997999
sdf.cache()
9981000
testArrayOfNonPrimitiveType()
1001+
}
9991002

1000-
// Error test cases
1001-
intercept[AnalysisException] {
1002-
oneRowDF.selectExpr("reverse(struct(1, 'a'))")
1003+
test("reverse function - data type mismatch") {
1004+
val ex1 = intercept[AnalysisException] {
1005+
sql("select reverse(struct(1, 'a'))")
10031006
}
1004-
intercept[AnalysisException] {
1005-
oneRowDF.selectExpr("reverse(map(1, 'a'))")
1007+
assert(ex1.getMessage.contains("data type mismatch"))
1008+
1009+
val ex2 = intercept[AnalysisException] {
1010+
sql("select reverse(map(1, 'a'))")
10061011
}
1012+
assert(ex2.getMessage.contains("data type mismatch"))
10071013
}
10081014

10091015
test("array position function") {

0 commit comments

Comments
 (0)