@@ -54,28 +54,16 @@ abstract class LeafMathExpression(c: Double, name: String)
54
54
* @param f The math function.
55
55
* @param name The short name of the function
56
56
*/
57
- abstract class AbstractUnaryMathExpression [ T , U ]( name : String )
57
+ abstract class UnaryMathExpression ( f : Double => Double , name : String )
58
58
extends UnaryExpression with Serializable with ExpectsInputTypes {
59
59
self : Product =>
60
60
61
+ override def expectedChildTypes : Seq [DataType ] = Seq (DoubleType )
62
+ override def dataType : DataType = DoubleType
61
63
override def foldable : Boolean = child.foldable
62
64
override def nullable : Boolean = true
63
65
override def toString : String = s " $name( $child) "
64
66
65
- // name of function in java.lang.Math
66
- def funcName : String = name.toLowerCase
67
- }
68
-
69
- /**
70
- * Base for [[AbstractUnaryMathExpression ]] that accepts a Double and returns a Double.
71
- */
72
- abstract class UnaryMathExpression (f : Double => Double , name : String )
73
- extends AbstractUnaryMathExpression [Double , Double ](name) {
74
- self : Product =>
75
-
76
- override def expectedChildTypes : Seq [DataType ] = Seq (DoubleType )
77
- override def dataType : DataType = DoubleType
78
-
79
67
override def eval (input : InternalRow ): Any = {
80
68
val evalE = child.eval(input)
81
69
if (evalE == null ) {
@@ -86,6 +74,9 @@ abstract class UnaryMathExpression(f: Double => Double, name: String)
86
74
}
87
75
}
88
76
77
+ // name of function in java.lang.Math
78
+ def funcName : String = name.toLowerCase
79
+
89
80
override def genCode (ctx : CodeGenContext , ev : GeneratedExpressionCode ): String = {
90
81
val eval = child.gen(ctx)
91
82
eval.code + s """
@@ -218,11 +209,19 @@ case class ToRadians(child: Expression) extends UnaryMathExpression(math.toRadia
218
209
}
219
210
220
211
case class Bin (child : Expression )
221
- extends AbstractUnaryMathExpression [Long , String ](" BIN" ) {
212
+ extends UnaryExpression with Serializable with ExpectsInputTypes {
213
+
214
+ val name : String = " BIN"
215
+
216
+ override def foldable : Boolean = child.foldable
217
+ override def nullable : Boolean = true
218
+ override def toString : String = s " $name( $child) "
222
219
223
220
override def expectedChildTypes : Seq [DataType ] = Seq (LongType )
224
221
override def dataType : DataType = StringType
225
222
223
+ def funcName : String = name.toLowerCase
224
+
226
225
override def eval (input : catalyst.InternalRow ): Any = {
227
226
val evalE = child.eval(input)
228
227
if (evalE == null ) {
0 commit comments