@@ -25,27 +25,16 @@ import org.apache.spark.sql.types._
2525 * input format, therefore these functions extend `ExpectsInputTypes`.
2626 * @param name The short name of the function
2727 */
28- abstract class MathematicalExpression (name : String )
28+ abstract class MathematicalExpression (f : Double => Double , name : String )
2929 extends UnaryExpression with Serializable with ExpectsInputTypes {
3030 self : Product =>
3131 type EvaluatedType = Any
3232
33+ override def expectedChildTypes : Seq [DataType ] = Seq (DoubleType )
3334 override def dataType : DataType = DoubleType
3435 override def foldable : Boolean = child.foldable
3536 override def nullable : Boolean = true
3637 override def toString : String = s " $name( $child) "
37- }
38-
39- /**
40- * A unary expression specifically for math functions that take a `Double` as input and return
41- * a `Double`.
42- * @param f The math function.
43- * @param name The short name of the function
44- */
45- abstract class MathematicalExpressionForDouble (f : Double => Double , name : String )
46- extends MathematicalExpression (name) { self : Product =>
47-
48- override def expectedChildTypes : Seq [DataType ] = Seq (DoubleType )
4938
5039 override def eval (input : Row ): Any = {
5140 val evalE = child.eval(input)
@@ -58,111 +47,46 @@ abstract class MathematicalExpressionForDouble(f: Double => Double, name: String
5847 }
5948}
6049
61- /**
62- * A unary expression specifically for math functions that take an `Int` as input and return
63- * an `Int`.
64- * @param f The math function.
65- * @param name The short name of the function
66- */
67- abstract class MathematicalExpressionForInt (f : Int => Int , name : String )
68- extends MathematicalExpression (name) { self : Product =>
50+ case class Acos (child : Expression ) extends MathematicalExpression (math.acos, " ACOS" )
6951
70- override def dataType : DataType = IntegerType
71- override def expectedChildTypes : Seq [DataType ] = Seq (IntegerType )
52+ case class Asin (child : Expression ) extends MathematicalExpression (math.asin, " ASIN" )
7253
73- override def eval (input : Row ): Any = {
74- val evalE = child.eval(input)
75- if (evalE == null ) null else f(evalE.asInstanceOf [Int ])
76- }
77- }
54+ case class Atan (child : Expression ) extends MathematicalExpression (math.atan, " ATAN" )
7855
79- /**
80- * A unary expression specifically for math functions that take a `Float` as input and return
81- * a `Float`.
82- * @param f The math function.
83- * @param name The short name of the function
84- */
85- abstract class MathematicalExpressionForFloat (f : Float => Float , name : String )
86- extends MathematicalExpression (name) { self : Product =>
56+ case class Cbrt (child : Expression ) extends MathematicalExpression (math.cbrt, " CBRT" )
8757
88- override def dataType : DataType = FloatType
89- override def expectedChildTypes : Seq [DataType ] = Seq (FloatType )
58+ case class Ceil (child : Expression ) extends MathematicalExpression (math.ceil, " CEIL" )
9059
91- override def eval (input : Row ): Any = {
92- val evalE = child.eval(input)
93- if (evalE == null ) {
94- null
95- } else {
96- val result = f(evalE.asInstanceOf [Float ])
97- if (result.isNaN) null else result
98- }
99- }
100- }
101-
102- /**
103- * A unary expression specifically for math functions that take a `Long` as input and return
104- * a `Long`.
105- * @param f The math function.
106- * @param name The short name of the function
107- */
108- abstract class MathematicalExpressionForLong (f : Long => Long , name : String )
109- extends MathematicalExpression (name) { self : Product =>
110-
111- override def dataType : DataType = LongType
112- override def expectedChildTypes : Seq [DataType ] = Seq (LongType )
113-
114- override def eval (input : Row ): Any = {
115- val evalE = child.eval(input)
116- if (evalE == null ) null else f(evalE.asInstanceOf [Long ])
117- }
118- }
119-
120- case class Sin (child : Expression ) extends MathematicalExpressionForDouble (math.sin, " SIN" )
121-
122- case class Asin (child : Expression ) extends MathematicalExpressionForDouble (math.asin, " ASIN" )
123-
124- case class Sinh (child : Expression ) extends MathematicalExpressionForDouble (math.sinh, " SINH" )
125-
126- case class Cos (child : Expression ) extends MathematicalExpressionForDouble (math.cos, " COS" )
60+ case class Cos (child : Expression ) extends MathematicalExpression (math.cos, " COS" )
12761
128- case class Acos (child : Expression ) extends MathematicalExpressionForDouble (math.acos , " ACOS " )
62+ case class Cosh (child : Expression ) extends MathematicalExpression (math.cosh , " COSH " )
12963
130- case class Cosh (child : Expression ) extends MathematicalExpressionForDouble (math.cosh , " COSH " )
64+ case class Exp (child : Expression ) extends MathematicalExpression (math.exp , " EXP " )
13165
132- case class Tan (child : Expression ) extends MathematicalExpressionForDouble (math.tan , " TAN " )
66+ case class Expm1 (child : Expression ) extends MathematicalExpression (math.expm1 , " EXPM1 " )
13367
134- case class Atan (child : Expression ) extends MathematicalExpressionForDouble (math.atan , " ATAN " )
68+ case class Floor (child : Expression ) extends MathematicalExpression (math.floor , " FLOOR " )
13569
136- case class Tanh (child : Expression ) extends MathematicalExpressionForDouble (math.tanh , " TANH " )
70+ case class Log (child : Expression ) extends MathematicalExpression (math.log , " LOG " )
13771
138- case class Ceil (child : Expression ) extends MathematicalExpressionForDouble (math.ceil , " CEIL " )
72+ case class Log10 (child : Expression ) extends MathematicalExpression (math.log10 , " LOG10 " )
13973
140- case class Floor (child : Expression ) extends MathematicalExpressionForDouble (math.floor , " FLOOR " )
74+ case class Log1p (child : Expression ) extends MathematicalExpression (math.log1p , " LOG1P " )
14175
142- case class Rint (child : Expression ) extends MathematicalExpressionForDouble (math.rint, " ROUND" )
76+ case class Rint (child : Expression ) extends MathematicalExpression (math.rint, " ROUND" )
14377
144- case class Cbrt (child : Expression ) extends MathematicalExpressionForDouble (math.cbrt , " CBRT " )
78+ case class Signum (child : Expression ) extends MathematicalExpression (math.signum , " SIGNUM " )
14579
146- case class Signum (child : Expression ) extends MathematicalExpressionForDouble (math.signum , " SIGNUM " )
80+ case class Sin (child : Expression ) extends MathematicalExpression (math.sin , " SIN " )
14781
148- case class ISignum (child : Expression ) extends MathematicalExpressionForInt (math.signum , " ISIGNUM " )
82+ case class Sinh (child : Expression ) extends MathematicalExpression (math.sinh , " SINH " )
14983
150- case class FSignum (child : Expression ) extends MathematicalExpressionForFloat (math.signum , " FSIGNUM " )
84+ case class Tan (child : Expression ) extends MathematicalExpression (math.tan , " TAN " )
15185
152- case class LSignum (child : Expression ) extends MathematicalExpressionForLong (math.signum , " LSIGNUM " )
86+ case class Tanh (child : Expression ) extends MathematicalExpression (math.tanh , " TANH " )
15387
15488case class ToDegrees (child : Expression )
155- extends MathematicalExpressionForDouble (math.toDegrees, " DEGREES" )
89+ extends MathematicalExpression (math.toDegrees, " DEGREES" )
15690
15791case class ToRadians (child : Expression )
158- extends MathematicalExpressionForDouble (math.toRadians, " RADIANS" )
159-
160- case class Log (child : Expression ) extends MathematicalExpressionForDouble (math.log, " LOG" )
161-
162- case class Log10 (child : Expression ) extends MathematicalExpressionForDouble (math.log10, " LOG10" )
163-
164- case class Log1p (child : Expression ) extends MathematicalExpressionForDouble (math.log1p, " LOG1P" )
165-
166- case class Exp (child : Expression ) extends MathematicalExpressionForDouble (math.exp, " EXP" )
167-
168- case class Expm1 (child : Expression ) extends MathematicalExpressionForDouble (math.expm1, " EXPM1" )
92+ extends MathematicalExpression (math.toRadians, " RADIANS" )
0 commit comments