From 4cb764d312c0eb406d87d86cbd2faffe1bcf3350 Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Wed, 10 Jun 2015 15:52:50 +0800 Subject: [PATCH] For comments. --- .../org/apache/spark/sql/catalyst/expressions/math.scala | 3 +++ .../spark/sql/catalyst/expressions/MathFunctionsSuite.scala | 3 ++- .../src/main/scala/org/apache/spark/sql/functions.scala | 6 ++++-- .../org/apache/spark/sql/DataFrameFunctionsSuite.scala | 5 +++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala index 5938c8105f56d..2327836426379 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala @@ -39,6 +39,9 @@ abstract class AbstractUnaryMathExpression[T, U](name: String) def funcName: String = name.toLowerCase } +/** + * Base for [[AbstractUnaryMathExpression]] that accepts a Double and returns a Double. + */ abstract class UnaryMathExpression(f: Double => Double, name: String) extends AbstractUnaryMathExpression[Double, Double](name) { self: Product => diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathFunctionsSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathFunctionsSuite.scala index 6bf9b933c6679..77163fb25e338 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathFunctionsSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathFunctionsSuite.scala @@ -26,10 +26,11 @@ class MathFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper { * Used for testing unary math expressions. * * @param c expression - * @param f The functions in scala.math + * @param f The functions in scala.math or elsewhere used to generate expected results * @param domain The set of values to run the function with * @param expectNull Whether the given values should return null or not * @tparam T Generic type for primitives + * @tparam U Generic type for the output of the given function `f` */ private def testUnary[T, U]( c: Expression => Expression, 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 e401eb864583f..ef6a31ed3c56f 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 @@ -1300,7 +1300,8 @@ object functions { def toRadians(columnName: String): Column = toRadians(Column(columnName)) /** - * Computes the binary format of the given value. + * An expression that returns the string representation of the binary value of the given long + * column. For example, bin("12") returns "1100". * * @group math_funcs * @since 1.4.0 @@ -1308,7 +1309,8 @@ object functions { def bin(e: Column): Column = Bin(e.expr) /** - * Computes the binary format of the given value. + * An expression that returns the string representation of the binary value of the given long + * column. For example, bin("12") returns "1100". * * @group math_funcs * @since 1.4.0 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 10fd3c846874b..34f1ec8c2b357 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 @@ -94,8 +94,9 @@ class DataFrameFunctionsSuite extends QueryTest { } test("bin") { + val df = Seq[(Integer, Integer)]((12, null)).toDF("a", "b") checkAnswer( - testData2.select(bin($"a")), - testData2.collect().toSeq.map(r => Row(JLong.toBinaryString(r.getInt(0).toLong)))) + df.select(bin("a"), bin("b")), + Row("1100", null)) } }