Repository: spark
Updated Branches:
  refs/heads/branch-1.5 8c0a5a248 -> 1038f677b


[SPARK-10107] [SQL] fix NPE in format_number

Author: Davies Liu <[email protected]>

Closes #8305 from davies/format_number.

(cherry picked from commit e05da5cb5ea253e6372f648fc8203204f2a8df8d)
Signed-off-by: Reynold Xin <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/1038f677
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/1038f677
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/1038f677

Branch: refs/heads/branch-1.5
Commit: 1038f677be8ad0b7dac6e21e171ce1d88ccdee48
Parents: 8c0a5a2
Author: Davies Liu <[email protected]>
Authored: Wed Aug 19 13:43:04 2015 -0700
Committer: Reynold Xin <[email protected]>
Committed: Wed Aug 19 13:43:20 2015 -0700

----------------------------------------------------------------------
 .../apache/spark/sql/catalyst/expressions/stringOperations.scala | 2 +-
 .../test/scala/org/apache/spark/sql/StringFunctionsSuite.scala   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/1038f677/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
----------------------------------------------------------------------
diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
index 134f1aa..ca044d3 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
@@ -1306,8 +1306,8 @@ case class FormatNumber(x: Expression, d: Expression)
             $df $dFormat = new $df($pattern.toString());
             $lastDValue = $d;
             $numberFormat.applyPattern($dFormat.toPattern());
-            ${ev.primitive} = 
UTF8String.fromString($numberFormat.format(${typeHelper(num)}));
           }
+          ${ev.primitive} = 
UTF8String.fromString($numberFormat.format(${typeHelper(num)}));
         } else {
           ${ev.primitive} = null;
           ${ev.isNull} = true;

http://git-wip-us.apache.org/repos/asf/spark/blob/1038f677/sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala
----------------------------------------------------------------------
diff --git 
a/sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala 
b/sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala
index cc95eed..b91438b 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala
@@ -348,9 +348,9 @@ class StringFunctionsSuite extends QueryTest with 
SharedSQLContext {
     // it will still use the interpretProjection if projection follows by a 
LocalRelation,
     // hence we add a filter operator.
     // See the optimizer rule `ConvertToLocalRelation`
-    val df2 = Seq((5L, 4), (4L, 3), (3L, 2)).toDF("a", "b")
+    val df2 = Seq((5L, 4), (4L, 3), (4L, 3), (4L, 3), (3L, 2)).toDF("a", "b")
     checkAnswer(
       df2.filter("b>0").selectExpr("format_number(a, b)"),
-      Row("5.0000") :: Row("4.000") :: Row("3.00") :: Nil)
+      Row("5.0000") :: Row("4.000") :: Row("4.000") :: Row("4.000") :: 
Row("3.00") :: Nil)
   }
 }


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

Reply via email to