Skip to content

Commit

Permalink
Remove AbstractUnaryMathExpression and let BIN inherit UnaryExpression.
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Jun 18, 2015
1 parent 0677f1a commit 07e1c8f
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,16 @@ abstract class LeafMathExpression(c: Double, name: String)
* @param f The math function.
* @param name The short name of the function
*/
abstract class AbstractUnaryMathExpression[T, U](name: String)
abstract class UnaryMathExpression(f: Double => Double, name: String)
extends UnaryExpression with Serializable with ExpectsInputTypes {
self: Product =>

override def expectedChildTypes: Seq[DataType] = Seq(DoubleType)
override def dataType: DataType = DoubleType
override def foldable: Boolean = child.foldable
override def nullable: Boolean = true
override def toString: String = s"$name($child)"

// name of function in java.lang.Math
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 =>

override def expectedChildTypes: Seq[DataType] = Seq(DoubleType)
override def dataType: DataType = DoubleType

override def eval(input: InternalRow): Any = {
val evalE = child.eval(input)
if (evalE == null) {
Expand All @@ -86,6 +74,9 @@ abstract class UnaryMathExpression(f: Double => Double, name: String)
}
}

// name of function in java.lang.Math
def funcName: String = name.toLowerCase

override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
val eval = child.gen(ctx)
eval.code + s"""
Expand Down Expand Up @@ -218,11 +209,19 @@ case class ToRadians(child: Expression) extends UnaryMathExpression(math.toRadia
}

case class Bin(child: Expression)
extends AbstractUnaryMathExpression[Long, String]("BIN") {
extends UnaryExpression with Serializable with ExpectsInputTypes {

val name: String = "BIN"

override def foldable: Boolean = child.foldable
override def nullable: Boolean = true
override def toString: String = s"$name($child)"

override def expectedChildTypes: Seq[DataType] = Seq(LongType)
override def dataType: DataType = StringType

def funcName: String = name.toLowerCase

override def eval(input: catalyst.InternalRow): Any = {
val evalE = child.eval(input)
if (evalE == null) {
Expand Down

0 comments on commit 07e1c8f

Please sign in to comment.