Github user yijieshen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6836#discussion_r33056496
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala
 ---
    @@ -255,3 +262,121 @@ case class Pow(left: Expression, right: Expression)
           """
       }
     }
    +
    +case class Round(left: Expression, right: Expression)
    +  extends Expression with trees.BinaryNode[Expression] with Serializable {
    +
    +  def this(left: Expression) = {
    +    this(left, Literal.create(0, IntegerType))
    +  }
    +
    +  override def nullable: Boolean = left.nullable || right.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])) {
    +      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 dataType: DataType = left.dataType
    +
    +  override def eval(input: InternalRow): Any = {
    +    val value = left.eval(input)
    +    val scale = right.eval(input)
    +    if (value == null || scale == null) {
    +      null
    +    } else {
    +      dataType match {
    +        case _: DecimalType => {
    +          val result = value.asInstanceOf[Decimal]
    +          result.set(result.toBigDecimal, result.precision, 
scale.asInstanceOf[Integer])
    +          result
    +        }
    +        case FloatType => {
    --- End diff --
    
    GenericUDFRound would return `null` if `Float.isNaN(f)` or 
`Float.isInfinite(f)`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to