spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davies <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-8241][SQL] string function: concat_ws.
Date Sun, 19 Jul 2015 06:54:16 GMT
Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7504#discussion_r34955580
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
---
    @@ -56,15 +51,76 @@ case class Concat(children: Seq[Expression]) extends Expression with
ImplicitCas
     
       override protected def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String
= {
         val evals = children.map(_.gen(ctx))
    -    val inputs = evals.map { eval => s"${eval.isNull} ? null : ${eval.primitive}"
}.mkString(", ")
    +    val inputs = evals.map { eval =>
    +      s"${eval.isNull} ? (UTF8String)null : ${eval.primitive}"
    +    }.mkString(", ")
         evals.map(_.code).mkString("\n") + s"""
           boolean ${ev.isNull} = false;
           UTF8String ${ev.primitive} = UTF8String.concat($inputs);
    +      if (${ev.primitive} == null) {
    +        ${ev.isNull} = true;
    +      }
         """
       }
     }
     
     
    +/**
    + * An expression that concatenates multiple input strings or array of strings into a
single string,
    + * using a given separator (the first child).
    + *
    + * Returns null if the separator is null. Otherwise, concat_ws skips all null values.
    + */
    +case class ConcatWs(children: Seq[Expression])
    +  extends Expression with ImplicitCastInputTypes with CodegenFallback {
    +
    +  require(children.nonEmpty, s"$prettyName requires at least one argument.")
    +
    +  override def prettyName: String = "concat_ws"
    +
    +  /** The 1st child (separator) is str, and rest are either str or array of str. */
    +  override def inputTypes: Seq[AbstractDataType] = {
    +    val arrayOrStr = TypeCollection(ArrayType(StringType), StringType)
    +    StringType +: Seq.fill(children.size - 1)(arrayOrStr)
    +  }
    +
    +  override def dataType: DataType = StringType
    +
    +  override def nullable: Boolean = children.head.nullable
    +  override def foldable: Boolean = children.forall(_.foldable)
    +
    +  override def eval(input: InternalRow): Any = {
    +    val flatInputs = children.flatMap { child =>
    +      child.eval(input) match {
    +        case s: UTF8String => Iterator(s)
    +        case arr: Seq[_] => arr.asInstanceOf[Seq[UTF8String]]
    +        case null => Iterator(null.asInstanceOf[UTF8String])
    --- End diff --
    
    minor: Can we just ignore the `null`?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message