@@ -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