Skip to content

Commit

Permalink
Add more test case
Browse files Browse the repository at this point in the history
  • Loading branch information
qiansl127 committed Jun 17, 2015
1 parent b8c73b4 commit 60ccde1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import org.apache.spark.sql.types.{BinaryType, StringType, DataType}
import org.apache.spark.unsafe.types.UTF8String

/**
* A function that calculates an MD5 128-bit checksum for the string or binary.
* Defined for String and Binary types.
* A function that calculates an MD5 128-bit checksum and returns it as a hex string
* For input of type [[StringType]] or [[BinaryType]]
*/
case class Md5(child: Expression) extends UnaryExpression {

Expand All @@ -43,7 +43,7 @@ case class Md5(child: Expression) extends UnaryExpression {

override def children: Seq[Expression] = child :: Nil

override def eval(input: Row): Any = {
override def eval(input: InternalRow): Any = {
val value = child.eval(input)
if (value == null) {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
package org.apache.spark.sql.catalyst.expressions

import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.types.{StringType, BinaryType}

class MiscFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper {

test("md5") {
val s1 = 'a.string.at(0)
val s2 = 'a.binary.at(0)
checkEvaluation(Md5(s1), "902fbdd2b1df0c4f70b4a5d23525e932", create_row("ABC"))
checkEvaluation(Md5(s2), "6ac1e56bc78f031059be7be854522c4c",
create_row(Array[Byte](1, 2, 3, 4, 5, 6)))
checkEvaluation(Md5(Literal("ABC")), "902fbdd2b1df0c4f70b4a5d23525e932")
checkEvaluation(Md5(Literal.create(Array[Byte](1, 2, 3, 4, 5, 6), BinaryType)), "6ac1e56bc78f031059be7be854522c4c")
checkEvaluation(Md5(Literal.create(null, BinaryType)), null)
checkEvaluation(Md5(Literal.create(null, StringType)), null)
}

}
2 changes: 2 additions & 0 deletions sql/core/src/main/scala/org/apache/spark/sql/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1341,13 +1341,15 @@ object functions {

/**
* Calculates the MD5 digest and returns the value as a 32 character hex string.
*
* @group misc_funcs
* @since 1.5.0
*/
def md5(e: Column): Column = Md5(e.expr)

/**
* Calculates the MD5 digest and returns the value as a 32 character hex string.
*
* @group misc_funcs
* @since 1.5.0
*/
Expand Down

0 comments on commit 60ccde1

Please sign in to comment.