From 6f4aeccf8cdfe0b5bdf77165711a9062a52d9d90 Mon Sep 17 00:00:00 2001 From: Daoyuan Wang Date: Wed, 7 Sep 2016 13:01:27 +0200 Subject: [SPARK-17427][SQL] function SIZE should return -1 when parameter is null ## What changes were proposed in this pull request? `select size(null)` returns -1 in Hive. In order to be compatible, we should return `-1`. ## How was this patch tested? unit test in `CollectionFunctionsSuite` and `DataFrameFunctionsSuite`. Author: Daoyuan Wang Closes #14991 from adrian-wang/size. --- .../org/apache/spark/sql/DataFrameFunctionsSuite.scala | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'sql/core/src/test/scala') diff --git a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala index 0f6c49e759..45db61515e 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala @@ -324,15 +324,16 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext { val df = Seq( (Seq[Int](1, 2), "x"), (Seq[Int](), "y"), - (Seq[Int](1, 2, 3), "z") + (Seq[Int](1, 2, 3), "z"), + (null, "empty") ).toDF("a", "b") checkAnswer( df.select(size($"a")), - Seq(Row(2), Row(0), Row(3)) + Seq(Row(2), Row(0), Row(3), Row(-1)) ) checkAnswer( df.selectExpr("size(a)"), - Seq(Row(2), Row(0), Row(3)) + Seq(Row(2), Row(0), Row(3), Row(-1)) ) } @@ -340,15 +341,16 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext { val df = Seq( (Map[Int, Int](1 -> 1, 2 -> 2), "x"), (Map[Int, Int](), "y"), - (Map[Int, Int](1 -> 1, 2 -> 2, 3 -> 3), "z") + (Map[Int, Int](1 -> 1, 2 -> 2, 3 -> 3), "z"), + (null, "empty") ).toDF("a", "b") checkAnswer( df.select(size($"a")), - Seq(Row(2), Row(0), Row(3)) + Seq(Row(2), Row(0), Row(3), Row(-1)) ) checkAnswer( df.selectExpr("size(a)"), - Seq(Row(2), Row(0), Row(3)) + Seq(Row(2), Row(0), Row(3), Row(-1)) ) } -- cgit v1.2.3