This is an automated email from the ASF dual-hosted git repository. gurwls223 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push: new 692e4b036 [SPARK-38604][SQL] Keep ceil and floor with only a single argument the same as before 692e4b036 is described below commit 692e4b0360202f6849de53fb179cddaa3dd3f090 Author: Robert (Bobby) Evans <bo...@apache.org> AuthorDate: Tue Mar 22 09:21:51 2022 +0900 [SPARK-38604][SQL] Keep ceil and floor with only a single argument the same as before This is just the fix. I didn't add any tests yet. I am happy to do it, I just wasn't sure where the right place to put the tests would be. Once I have tests I will cherry-pick this back to the 3.3 branch and put up a PR for that too. I am also happy to update the comments because this is a bit confusing that there is no indication that things have changed. Closes #35913 from revans2/ceil_floor_no_arg_behavior. Authored-by: Robert (Bobby) Evans <bo...@apache.org> Signed-off-by: Hyukjin Kwon <gurwls...@apache.org> --- .../src/main/scala/org/apache/spark/sql/functions.scala | 8 ++++++-- .../scala/org/apache/spark/sql/MathFunctionsSuite.scala | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala index 58e855e..17e1d48 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala @@ -1783,7 +1783,9 @@ object functions { * @group math_funcs * @since 1.4.0 */ - def ceil(e: Column): Column = ceil(e, lit(0)) + def ceil(e: Column): Column = withExpr { + UnresolvedFunction(Seq("ceil"), Seq(e.expr), isDistinct = false) + } /** * Computes the ceiling of the given value of `e` to 0 decimal places. @@ -1913,7 +1915,9 @@ object functions { * @group math_funcs * @since 1.4.0 */ - def floor(e: Column): Column = floor(e, lit(0)) + def floor(e: Column): Column = withExpr { + UnresolvedFunction(Seq("floor"), Seq(e.expr), isDistinct = false) + } /** * Computes the floor of the given column value to 0 decimal places. diff --git a/sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala index ab52cb9..1a00491 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala @@ -202,6 +202,13 @@ class MathFunctionsSuite extends QueryTest with SharedSparkSession { test("ceil and ceiling") { testOneToOneMathFunction(ceil, (d: Double) => math.ceil(d).toLong) + // testOneToOneMathFunction does not validate the resulting data type + assert( + spark.range(1).select(ceil(col("id")).alias("a")).schema == + types.StructType(Seq(types.StructField("a", types.LongType)))) + assert( + spark.range(1).select(ceil(col("id"), lit(0)).alias("a")).schema == + types.StructType(Seq(types.StructField("a", types.DecimalType(20, 0))))) checkAnswer( sql("SELECT ceiling(0), ceiling(1), ceiling(1.5)"), Row(0L, 1L, 2L)) @@ -250,6 +257,13 @@ class MathFunctionsSuite extends QueryTest with SharedSparkSession { test("floor") { testOneToOneMathFunction(floor, (d: Double) => math.floor(d).toLong) + // testOneToOneMathFunction does not validate the resulting data type + assert( + spark.range(1).select(floor(col("id")).alias("a")).schema == + types.StructType(Seq(types.StructField("a", types.LongType)))) + assert( + spark.range(1).select(floor(col("id"), lit(0)).alias("a")).schema == + types.StructType(Seq(types.StructField("a", types.DecimalType(20, 0))))) } test("factorial") { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org