Skip to content

Commit 07e1c8f

Browse files
committed
Remove AbstractUnaryMathExpression and let BIN inherit UnaryExpression.
1 parent 0677f1a commit 07e1c8f

File tree

1 file changed

+15
-16
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions

1 file changed

+15
-16
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,16 @@ abstract class LeafMathExpression(c: Double, name: String)
5454
* @param f The math function.
5555
* @param name The short name of the function
5656
*/
57-
abstract class AbstractUnaryMathExpression[T, U](name: String)
57+
abstract class UnaryMathExpression(f: Double => Double, name: String)
5858
extends UnaryExpression with Serializable with ExpectsInputTypes {
5959
self: Product =>
6060

61+
override def expectedChildTypes: Seq[DataType] = Seq(DoubleType)
62+
override def dataType: DataType = DoubleType
6163
override def foldable: Boolean = child.foldable
6264
override def nullable: Boolean = true
6365
override def toString: String = s"$name($child)"
6466

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-
7967
override def eval(input: InternalRow): Any = {
8068
val evalE = child.eval(input)
8169
if (evalE == null) {
@@ -86,6 +74,9 @@ abstract class UnaryMathExpression(f: Double => Double, name: String)
8674
}
8775
}
8876

77+
// name of function in java.lang.Math
78+
def funcName: String = name.toLowerCase
79+
8980
override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {
9081
val eval = child.gen(ctx)
9182
eval.code + s"""
@@ -218,11 +209,19 @@ case class ToRadians(child: Expression) extends UnaryMathExpression(math.toRadia
218209
}
219210

220211
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)"
222219

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

223+
def funcName: String = name.toLowerCase
224+
226225
override def eval(input: catalyst.InternalRow): Any = {
227226
val evalE = child.eval(input)
228227
if (evalE == null) {

0 commit comments

Comments
 (0)