Github user wzhfy commented on a diff in the pull request: https://github.com/apache/spark/pull/18323#discussion_r123409299 --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathExpressionsSuite.scala --- @@ -644,4 +645,36 @@ class MathExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper { checkEvaluation(BRound(-0.35, 1), -0.4) checkEvaluation(BRound(-35, -1), -40) } + + test("width_bucket") { + def test( + expr: Double, + minValue: Double, + maxValue: Double, + numBucket: Long, + expected: Long): Unit = { + checkEvaluation(WidthBucket(Literal.create(expr, DoubleType), + Literal.create(minValue, DoubleType), + Literal.create(maxValue, DoubleType), + Literal.create(numBucket, LongType)), + expected) + } + + test(5.35, 0.024, 10.06, 5, 3) + + test(3.14, 0, 4, 3, 3) + test(2, 0, 4, 3, 2) + test(-1, 0, 3.2, 4, 0) + + test(3.14, 4, 0, 3, 1) + test(2, 4, 0, 3, 2) + test(-1, 3.2, 0, 4, 5) + + intercept[AnalysisException]{ --- End diff -- also add test cases for null input and wrong input type
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org