[SQL] Rename MathematicalExpression UnaryMathExpression, and specify BinaryMathExpression's output data type as DoubleType.

Two minor changes.

cc brkyvz

Author: Reynold Xin <rxin@databricks.com>

Closes #6428 from rxin/math-func-cleanup and squashes the following commits:

5910df5 [Reynold Xin] [SQL] Rename MathematicalExpression UnaryMathExpression, and specify BinaryMathExpression's output data type as DoubleType.
This commit is contained in:
Reynold Xin 2015-05-27 01:13:57 -07:00
parent 9f48bf6b37
commit 3e7d7d6b3d
2 changed files with 23 additions and 32 deletions

View file

@ -17,7 +17,6 @@
package org.apache.spark.sql.catalyst.expressions.mathfuncs
import org.apache.spark.sql.catalyst.analysis.UnresolvedException
import org.apache.spark.sql.catalyst.expressions.{ExpectsInputTypes, BinaryExpression, Expression, Row}
import org.apache.spark.sql.types._
@ -41,13 +40,7 @@ abstract class BinaryMathExpression(f: (Double, Double) => Double, name: String)
left.dataType == right.dataType &&
!DecimalType.isFixed(left.dataType)
override def dataType: DataType = {
if (!resolved) {
throw new UnresolvedException(this,
s"datatype. Can not resolve due to differing types ${left.dataType}, ${right.dataType}")
}
left.dataType
}
override def dataType: DataType = DoubleType
override def eval(input: Row): Any = {
val evalE1 = left.eval(input)

View file

@ -25,7 +25,7 @@ import org.apache.spark.sql.types._
* input format, therefore these functions extend `ExpectsInputTypes`.
* @param name The short name of the function
*/
abstract class MathematicalExpression(f: Double => Double, name: String)
abstract class UnaryMathExpression(f: Double => Double, name: String)
extends UnaryExpression with Serializable with ExpectsInputTypes {
self: Product =>
@ -46,46 +46,44 @@ abstract class MathematicalExpression(f: Double => Double, name: String)
}
}
case class Acos(child: Expression) extends MathematicalExpression(math.acos, "ACOS")
case class Acos(child: Expression) extends UnaryMathExpression(math.acos, "ACOS")
case class Asin(child: Expression) extends MathematicalExpression(math.asin, "ASIN")
case class Asin(child: Expression) extends UnaryMathExpression(math.asin, "ASIN")
case class Atan(child: Expression) extends MathematicalExpression(math.atan, "ATAN")
case class Atan(child: Expression) extends UnaryMathExpression(math.atan, "ATAN")
case class Cbrt(child: Expression) extends MathematicalExpression(math.cbrt, "CBRT")
case class Cbrt(child: Expression) extends UnaryMathExpression(math.cbrt, "CBRT")
case class Ceil(child: Expression) extends MathematicalExpression(math.ceil, "CEIL")
case class Ceil(child: Expression) extends UnaryMathExpression(math.ceil, "CEIL")
case class Cos(child: Expression) extends MathematicalExpression(math.cos, "COS")
case class Cos(child: Expression) extends UnaryMathExpression(math.cos, "COS")
case class Cosh(child: Expression) extends MathematicalExpression(math.cosh, "COSH")
case class Cosh(child: Expression) extends UnaryMathExpression(math.cosh, "COSH")
case class Exp(child: Expression) extends MathematicalExpression(math.exp, "EXP")
case class Exp(child: Expression) extends UnaryMathExpression(math.exp, "EXP")
case class Expm1(child: Expression) extends MathematicalExpression(math.expm1, "EXPM1")
case class Expm1(child: Expression) extends UnaryMathExpression(math.expm1, "EXPM1")
case class Floor(child: Expression) extends MathematicalExpression(math.floor, "FLOOR")
case class Floor(child: Expression) extends UnaryMathExpression(math.floor, "FLOOR")
case class Log(child: Expression) extends MathematicalExpression(math.log, "LOG")
case class Log(child: Expression) extends UnaryMathExpression(math.log, "LOG")
case class Log10(child: Expression) extends MathematicalExpression(math.log10, "LOG10")
case class Log10(child: Expression) extends UnaryMathExpression(math.log10, "LOG10")
case class Log1p(child: Expression) extends MathematicalExpression(math.log1p, "LOG1P")
case class Log1p(child: Expression) extends UnaryMathExpression(math.log1p, "LOG1P")
case class Rint(child: Expression) extends MathematicalExpression(math.rint, "ROUND")
case class Rint(child: Expression) extends UnaryMathExpression(math.rint, "ROUND")
case class Signum(child: Expression) extends MathematicalExpression(math.signum, "SIGNUM")
case class Signum(child: Expression) extends UnaryMathExpression(math.signum, "SIGNUM")
case class Sin(child: Expression) extends MathematicalExpression(math.sin, "SIN")
case class Sin(child: Expression) extends UnaryMathExpression(math.sin, "SIN")
case class Sinh(child: Expression) extends MathematicalExpression(math.sinh, "SINH")
case class Sinh(child: Expression) extends UnaryMathExpression(math.sinh, "SINH")
case class Tan(child: Expression) extends MathematicalExpression(math.tan, "TAN")
case class Tan(child: Expression) extends UnaryMathExpression(math.tan, "TAN")
case class Tanh(child: Expression) extends MathematicalExpression(math.tanh, "TANH")
case class Tanh(child: Expression) extends UnaryMathExpression(math.tanh, "TANH")
case class ToDegrees(child: Expression)
extends MathematicalExpression(math.toDegrees, "DEGREES")
case class ToDegrees(child: Expression) extends UnaryMathExpression(math.toDegrees, "DEGREES")
case class ToRadians(child: Expression)
extends MathematicalExpression(math.toRadians, "RADIANS")
case class ToRadians(child: Expression) extends UnaryMathExpression(math.toRadians, "RADIANS")