Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename
  • Loading branch information
zhichao-li committed Jun 24, 2015
commit 9ff6d2d30274fd73faae58a033face1d98e94ebe
Original file line number Diff line number Diff line change
Expand Up @@ -317,35 +317,35 @@ case class Logarithm(left: Expression, right: Expression)
}
}

case class Round(left: Expression, right: Expression)
extends Expression with trees.BinaryNode[Expression] with Serializable {
case class Round(valueExpr: Expression, scaleExpr: Expression)
extends Expression with trees.BinaryNode[Expression] {

def this(left: Expression) = {
this(left, Literal(0))
}

override def nullable: Boolean = left.nullable || right.nullable
override def nullable: Boolean = valueExpr.nullable || scaleExpr.nullable

override lazy val resolved =
childrenResolved && checkInputDataTypes().isSuccess && !DecimalType.isFixed(dataType)

override def checkInputDataTypes(): TypeCheckResult = {
if ((left.dataType.isInstanceOf[NumericType] || left.dataType.isInstanceOf[NullType])
&& (right.dataType.isInstanceOf[IntegerType] || right.dataType.isInstanceOf[NullType])) {
if ((valueExpr.dataType.isInstanceOf[NumericType] || valueExpr.dataType.isInstanceOf[NullType])
&& (scaleExpr.dataType.isInstanceOf[IntegerType] || scaleExpr.dataType.isInstanceOf[NullType])) {
TypeCheckResult.TypeCheckSuccess
} else {
TypeCheckResult.TypeCheckFailure(
s"round accepts numeric types as the value and integer type as the scale")
}
}

override def toString: String = s"round($left, $right)"
override def toString: String = s"round($valueExpr, $scaleExpr)"

override def dataType: DataType = left.dataType
override def dataType: DataType = valueExpr.dataType

override def eval(input: InternalRow): Any = {
val valueEval = left.eval(input)
val scaleEval = right.eval(input)
val valueEval = valueExpr.eval(input)
val scaleEval = scaleExpr.eval(input)
if (valueEval == null || scaleEval == null) {
null
} else {
Expand Down Expand Up @@ -384,4 +384,8 @@ case class Round(left: Expression, right: Expression)
private def round(value: Decimal, scale: Int): Decimal = {
value.set(value.toBigDecimal, value.precision, scale.asInstanceOf[Integer])
}

override def left: Expression = valueExpr

override def right: Expression = scaleExpr
}