sathiyapk commented on a change in pull request #34729:
URL: https://github.com/apache/spark/pull/34729#discussion_r789879908



##########
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathExpressionsSuite.scala
##########
@@ -705,6 +818,42 @@ class MathExpressionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
     checkEvaluation(BRound(-3.5, 0), -4.0)
     checkEvaluation(BRound(-0.35, 1), -0.4)
     checkEvaluation(BRound(-35, -1), -40)
+    checkEvaluation(checkDataTypeAndCast(
+      FloorExpressionBuilder.build(Seq(Literal(2.5), Literal(0)))), 2L)
+    checkEvaluation(checkDataTypeAndCast(
+      FloorExpressionBuilder.build(Seq(Literal(3.5), Literal(0)))), 3L)
+    checkEvaluation(checkDataTypeAndCast(
+      FloorExpressionBuilder.build(Seq(Literal(-2.5), Literal(0)))), -3L)
+    checkEvaluation(checkDataTypeAndCast(
+      FloorExpressionBuilder.build(Seq(Literal(-3.5), Literal(0)))), -4L)
+    checkEvaluation(checkDataTypeAndCast(
+      FloorExpressionBuilder.build(Seq(Literal(-0.35), Literal(1)))), -0.4)
+    checkEvaluation(checkDataTypeAndCast(
+      FloorExpressionBuilder.build(Seq(Literal(-35), Literal(-1)))), -40L)
+    checkEvaluation(checkDataTypeAndCast(
+      CeilExpressionBuilder.build(Seq(Literal(2.5), Literal(0)))), 3L)
+    checkEvaluation(checkDataTypeAndCast(
+      CeilExpressionBuilder.build(Seq(Literal(3.5), Literal(0)))), 4L)
+    checkEvaluation(checkDataTypeAndCast(
+      CeilExpressionBuilder.build(Seq(Literal(-2.5), Literal(0)))), -2L)
+    checkEvaluation(checkDataTypeAndCast(
+      CeilExpressionBuilder.build(Seq(Literal(-3.5), Literal(0)))), -3L)
+    checkEvaluation(checkDataTypeAndCast(
+      CeilExpressionBuilder.build(Seq(Literal(-0.35), Literal(1)))), -0.3)
+    checkEvaluation(checkDataTypeAndCast(
+      CeilExpressionBuilder.build(Seq(Literal(-35), Literal(-1)))), -30L)
+    checkEvaluation(checkDataTypeAndCast(
+      FloorExpressionBuilder.build(Seq(Literal(-0.1), Literal(0)))), -1L)
+    checkEvaluation(checkDataTypeAndCast(
+      FloorExpressionBuilder.build(Seq(Literal(5), Literal(0)))), 5L)
+    checkEvaluation(checkDataTypeAndCast(
+      FloorExpressionBuilder.build(Seq(Literal(3.1411), Literal(-3)))), 0L)
+    checkEvaluation(checkDataTypeAndCast(
+      CeilExpressionBuilder.build(Seq(Literal(-0.1), Literal(0)))), 0L)
+    checkEvaluation(checkDataTypeAndCast(
+      CeilExpressionBuilder.build(Seq(Literal(5), Literal(0)))), 5L)
+    checkEvaluation(checkDataTypeAndCast(
+      CeilExpressionBuilder.build(Seq(Literal(3.1411), Literal(-3)))), 1000L)

Review comment:
       @cloud-fan with `def inputTypes = Seq(DecimalType, IntegerType)`, the 
framework will cast all inputs to DecimalType and `-ve` scale for decimals are 
not allowed by default. If we put negative scale for decimal, we will receive 
the following error: 
   `Negative scale is not allowed: -2. You can use 
spark.sql.legacy.allowNegativeScaleOfDecimal=true to enable legacy mode to 
allow it.`
   
   In the code actuel, i think it would be enough to add `math.min(scale, -18)` 
for the `scale < 0` something as bellow.
   
   (child.dataType, scaleV.asInstanceOf[Int]) match {
           case (_, 0) => Ceil(child)
           case (_, x) if x < 0 => RoundCeil(Cast(child, LongType), 
math.min(-18, scale))
           case (_: IntegralType, _) => RoundCeil(Cast(child, LongType), scale)
           case (_ : FloatType, _) => RoundCeil(Cast(child, DoubleType), scale)
           case _ => RoundCeil(child, scale)
         }
   
   What do you think ?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to