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

    https://github.com/apache/spark/pull/6938#discussion_r34408758
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala
 ---
    @@ -520,3 +522,127 @@ case class Logarithm(left: Expression, right: 
Expression)
         """
       }
     }
    +
    +case class Round(child: Expression, scale: Expression)
    +  extends BinaryExpression with ExpectsInputTypes {
    +
    +  import BigDecimal.RoundingMode.HALF_UP
    +
    +  def this(child: Expression) = this(child, Literal(0))
    +
    +  override def left: Expression = child
    +  override def right: Expression = scale
    +
    +  override def children: Seq[Expression] = Seq(child, scale)
    +
    +  // round of Decimal would eval to null if it fails to `changePrecision`
    +  override def nullable: Boolean = true
    +
    +  override def foldable: Boolean = child.foldable
    +
    +  override lazy val dataType: DataType = child.dataType match {
    +    case DecimalType.Fixed(p, s) => DecimalType(p, _scale)
    +    case t => t
    +  }
    +
    +  override def inputTypes: Seq[AbstractDataType] = Seq(NumericType, 
IntegerType)
    +
    +  override def checkInputDataTypes(): TypeCheckResult = {
    +    super.checkInputDataTypes() match {
    +      case TypeCheckSuccess =>
    +        if (scale.foldable) {
    +          TypeCheckSuccess
    +        } else {
    +          TypeCheckFailure("Only foldable Expression is allowed for scale 
arguments")
    +        }
    +      case f => f
    +    }
    +  }
    +
    +  private lazy val scaleV = scale.eval(EmptyRow)
    --- End diff --
    
    Oh, I check the code again and find it no more needed since implicit cast 
caused by `inputTypes`


---
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