Github user chenghao-intel commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7034#discussion_r34651846
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
 ---
    @@ -668,3 +673,74 @@ case class Encode(value: Expression, charset: 
Expression)
       }
     }
     
    +/**
    + * Formats the number X to a format like '#,###,###.##', rounded to D 
decimal places,
    + * and returns the result as a string. If D is 0, the result has no 
decimal point or
    + * fractional part.
    + */
    +case class FormatNumber(x: Expression, d: Expression)
    +  extends BinaryExpression with ExpectsInputTypes {
    +
    +  override def left: Expression = x
    +  override def right: Expression = d
    +  override def dataType: DataType = StringType
    +  override def inputTypes: Seq[AbstractDataType] = Seq(NumericType, 
IntegerType)
    +  override def foldable: Boolean = x.foldable && d.foldable
    +  override def nullable: Boolean = x.nullable || d.nullable
    +
    +  @transient
    +  private var lastDValue: Int = -100
    +
    +  @transient
    +  private val pattern: StringBuffer = new StringBuffer()
    +
    +  @transient
    +  private val numberFormat: DecimalFormat = new DecimalFormat("")
    +
    +  override def eval(input: InternalRow): Any = {
    +    val xObject = x.eval(input)
    +    if (xObject == null) {
    +      return null
    +    }
    +
    +    val dObject = d.eval(input)
    +
    +    if (dObject == null || dObject.asInstanceOf[Int] < 0) {
    +      throw new IllegalArgumentException(
    --- End diff --
    
    The logic is copied from Hive. Let's keep the same behavior?


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to