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

    https://github.com/apache/spark/pull/6775#discussion_r32379216
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
 ---
    @@ -315,4 +315,65 @@ case class StringLength(child: Expression) extends 
UnaryExpression with ExpectsI
       }
     }
     
    +/**
    + * Like ConcatWS below, but taking an array of strings.
    + */
    +case class ConcatWS(sep: Expression, child: Expression)
    +  extends Expression with ExpectsInputTypes {
    +  override def dataType: DataType = StringType
    +  override def nullable: Boolean = true
    +  override def foldable: Boolean = child.foldable && sep.foldable
    +  override def children: Seq[Expression] = sep :: child :: Nil
    +  override def expectedChildTypes: Seq[DataType] = StringType :: 
ArrayType(StringType) :: Nil
    +  override def toString: String = s"""CONCAT_WS($sep, $child)"""
     
    +  override def eval(input: Row): Any = {
    +    val sepEval = sep.eval(input)
    +    val childArr = child.eval(input)
    +    if (sepEval != null && childArr != null) {
    +      val separator = sepEval.asInstanceOf[UTF8String].toString
    +      val validSeq = childArr.asInstanceOf[Seq[UTF8String]]
    +      if (!validSeq.contains(null)) {
    +        return UTF8String.fromString(validSeq.mkString(separator))
    +      }
    +    }
    +    null
    +  }
    +}
    +
    +/**
    + * Like Concat below, but with custom separator SEP.
    + */
    +object ConcatWS {
    +  def apply(sep: Expression, exprs: Expression*): ConcatWS = {
    --- End diff --
    
    We now support multiple constructors for `Expression` 
https://github.com/apache/spark/pull/6806/files#diff-d788f93e29b4d25cdd7d60328587678bL225
    So we'd better move this into the case class.


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