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

    https://github.com/apache/spark/pull/6775#discussion_r32400671
  
    --- 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 = {
    +    apply(sep, CreateArray(exprs))
    +  }
    +}
    +
    +/**
    + * A function that returns the string or bytes resulting from 
concatenating the strings or bytes
    + * passed in as parameters in order. For example, concat('foo', 'bar') 
results in 'foobar'. Note
    + * that this function can take any number of input strings.
    + */
    +case class Concat(child: Expression*)
    +  extends Expression with ExpectsInputTypes {
    +  override def dataType: DataType = StringType
    +  override def nullable: Boolean = child.exists(_.nullable)
    +  override def foldable: Boolean = child.forall(_.foldable)
    +  override def children: Seq[Expression] = child
    +  override def expectedChildTypes: Seq[DataType] = 
Seq.fill(child.size)(StringType)
    +  override def toString: String = s"""CONCAT($child)"""
    +
    +  override def eval(input: Row): Any = {
    +    val validSeq = if (child != null && !child.contains(null)) {
    --- End diff --
    
    We don't need to check null for children.


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