@@ -19,7 +19,7 @@ package org.apache.spark.sql.catalyst.expressions
1919
2020import org .apache .spark .SparkFunSuite
2121import org .apache .spark .sql .catalyst .dsl .expressions ._
22- import org .apache .spark .sql .types .{ Decimal , DoubleType , IntegerType }
22+ import org .apache .spark .sql .types .Decimal
2323
2424
2525class ArithmeticExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
@@ -123,23 +123,39 @@ class ArithmeticExpressionSuite extends SparkFunSuite with ExpressionEvalHelper
123123 }
124124 }
125125
126- test(" MaxOf" ) {
127- checkEvaluation(MaxOf (1 , 2 ), 2 )
128- checkEvaluation(MaxOf (2 , 1 ), 2 )
129- checkEvaluation(MaxOf (1L , 2L ), 2L )
130- checkEvaluation(MaxOf (2L , 1L ), 2L )
126+ test(" MaxOf basic" ) {
127+ testNumericDataTypes { convert =>
128+ val small = Literal (convert(1 ))
129+ val large = Literal (convert(2 ))
130+ checkEvaluation(MaxOf (small, large), convert(2 ))
131+ checkEvaluation(MaxOf (large, small), convert(2 ))
132+ checkEvaluation(MaxOf (Literal .create(null , small.dataType), large), convert(2 ))
133+ checkEvaluation(MaxOf (large, Literal .create(null , small.dataType)), convert(2 ))
134+ }
135+ }
131136
132- checkEvaluation(MaxOf (Literal .create(null , IntegerType ), 2 ), 2 )
133- checkEvaluation(MaxOf (2 , Literal .create(null , IntegerType )), 2 )
137+ test(" MaxOf for atomic type" ) {
138+ checkEvaluation(MaxOf (true , false ), true )
139+ checkEvaluation(MaxOf (" abc" , " bcd" ), " bcd" )
140+ checkEvaluation(MaxOf (Array (1 .toByte, 2 .toByte), Array (1 .toByte, 3 .toByte)),
141+ Array (1 .toByte, 3 .toByte))
134142 }
135143
136- test(" MinOf" ) {
137- checkEvaluation(MinOf (1 , 2 ), 1 )
138- checkEvaluation(MinOf (2 , 1 ), 1 )
139- checkEvaluation(MinOf (1L , 2L ), 1L )
140- checkEvaluation(MinOf (2L , 1L ), 1L )
144+ test(" MinOf basic" ) {
145+ testNumericDataTypes { convert =>
146+ val small = Literal (convert(1 ))
147+ val large = Literal (convert(2 ))
148+ checkEvaluation(MinOf (small, large), convert(1 ))
149+ checkEvaluation(MinOf (large, small), convert(1 ))
150+ checkEvaluation(MinOf (Literal .create(null , small.dataType), large), convert(2 ))
151+ checkEvaluation(MinOf (small, Literal .create(null , small.dataType)), convert(1 ))
152+ }
153+ }
141154
142- checkEvaluation(MinOf (Literal .create(null , IntegerType ), 1 ), 1 )
143- checkEvaluation(MinOf (1 , Literal .create(null , IntegerType )), 1 )
155+ test(" MinOf for atomic type" ) {
156+ checkEvaluation(MinOf (true , false ), false )
157+ checkEvaluation(MinOf (" abc" , " bcd" ), " abc" )
158+ checkEvaluation(MinOf (Array (1 .toByte, 2 .toByte), Array (1 .toByte, 3 .toByte)),
159+ Array (1 .toByte, 2 .toByte))
144160 }
145161}
0 commit comments