Skip to content

Commit

Permalink
For comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Jun 10, 2015
1 parent 0f78682 commit 4cb764d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions sql/core/src/main/scala/org/apache/spark/sql/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1300,15 +1300,17 @@ 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
*/
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

0 comments on commit 4cb764d

Please sign in to comment.