@@ -104,6 +104,17 @@ class ArithmeticExpressionSuite extends SparkFunSuite with ExpressionEvalHelper
104104 checkEvaluation(Divide (Literal (Decimal (1.0 )), Literal (Decimal (2.0 ))), Decimal (0.5 ))
105105 }
106106
107+ test(" % (Remainder)" ) {
108+ testNumericDataTypes { convert =>
109+ val left = Literal (convert(1 ))
110+ val right = Literal (convert(2 ))
111+ checkEvaluation(Remainder (left, right), convert(1 ))
112+ checkEvaluation(Remainder (Literal .create(null , left.dataType), right), null )
113+ checkEvaluation(Remainder (left, Literal .create(null , right.dataType)), null )
114+ checkEvaluation(Remainder (left, Literal (convert(0 ))), null ) // mod by 0
115+ }
116+ }
117+
107118 test(" Abs" ) {
108119 testNumericDataTypes { convert =>
109120 checkEvaluation(Abs (Literal (convert(0 ))), convert(0 ))
@@ -112,38 +123,6 @@ class ArithmeticExpressionSuite extends SparkFunSuite with ExpressionEvalHelper
112123 }
113124 }
114125
115- test(" Divide" ) {
116- checkEvaluation(Divide (Literal (2 ), Literal (1 )), 2 )
117- checkEvaluation(Divide (Literal (1.0 ), Literal (2.0 )), 0.5 )
118- checkEvaluation(Divide (Literal (1 ), Literal (2 )), 0 )
119- checkEvaluation(Divide (Literal (1 ), Literal (0 )), null )
120- checkEvaluation(Divide (Literal (1.0 ), Literal (0.0 )), null )
121- checkEvaluation(Divide (Literal (0.0 ), Literal (0.0 )), null )
122- checkEvaluation(Divide (Literal (0 ), Literal .create(null , IntegerType )), null )
123- checkEvaluation(Divide (Literal (1 ), Literal .create(null , IntegerType )), null )
124- checkEvaluation(Divide (Literal .create(null , IntegerType ), Literal (0 )), null )
125- checkEvaluation(Divide (Literal .create(null , DoubleType ), Literal (0.0 )), null )
126- checkEvaluation(Divide (Literal .create(null , IntegerType ), Literal (1 )), null )
127- checkEvaluation(Divide (Literal .create(null , IntegerType ), Literal .create(null , IntegerType )),
128- null )
129- }
130-
131- test(" Remainder" ) {
132- checkEvaluation(Remainder (Literal (2 ), Literal (1 )), 0 )
133- checkEvaluation(Remainder (Literal (1.0 ), Literal (2.0 )), 1.0 )
134- checkEvaluation(Remainder (Literal (1 ), Literal (2 )), 1 )
135- checkEvaluation(Remainder (Literal (1 ), Literal (0 )), null )
136- checkEvaluation(Remainder (Literal (1.0 ), Literal (0.0 )), null )
137- checkEvaluation(Remainder (Literal (0.0 ), Literal (0.0 )), null )
138- checkEvaluation(Remainder (Literal (0 ), Literal .create(null , IntegerType )), null )
139- checkEvaluation(Remainder (Literal (1 ), Literal .create(null , IntegerType )), null )
140- checkEvaluation(Remainder (Literal .create(null , IntegerType ), Literal (0 )), null )
141- checkEvaluation(Remainder (Literal .create(null , DoubleType ), Literal (0.0 )), null )
142- checkEvaluation(Remainder (Literal .create(null , IntegerType ), Literal (1 )), null )
143- checkEvaluation(Remainder (Literal .create(null , IntegerType ), Literal .create(null , IntegerType )),
144- null )
145- }
146-
147126 test(" MaxOf" ) {
148127 checkEvaluation(MaxOf (1 , 2 ), 2 )
149128 checkEvaluation(MaxOf (2 , 1 ), 2 )
0 commit comments