Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19827#discussion_r153361531
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeCreator.scala
 ---
    @@ -351,24 +351,26 @@ case class CreateNamedStruct(children: 
Seq[Expression]) extends CreateNamedStruc
         val rowClass = classOf[GenericInternalRow].getName
         val values = ctx.freshName("values")
         ctx.addMutableState("Object[]", values, s"$values = null;")
    -
    -    ev.copy(code = s"""
    -      $values = new Object[${valExprs.size}];""" +
    -      ctx.splitExpressions(
    -        ctx.INPUT_ROW,
    -        valExprs.zipWithIndex.map { case (e, i) =>
    -          val eval = e.genCode(ctx)
    -          eval.code + s"""
    +    val valuesCode = ctx.splitExpressions(
    +      valExprs.zipWithIndex.map { case (e, i) =>
    +        val eval = e.genCode(ctx)
    +        s"""
    +          ${eval.code}
               if (${eval.isNull}) {
                 $values[$i] = null;
               } else {
                 $values[$i] = ${eval.value};
               }"""
    -        }) +
    +      })
    +    val code =
           s"""
    -        final InternalRow ${ev.value} = new $rowClass($values);
    -        $values = null;
    -      """, isNull = "false")
    +         |$values = new Object[${valExprs.size}];
    +         |$valuesCode
    +         |final InternalRow ${ev.value} = new $rowClass($values);
    +         |$values = null;
    +       """.stripMargin
    --- End diff --
    
    We are encouraging the use of `stripMargin` now. Previously we format the 
code by hand, so we have to write something like
    ```
    s"""
      the code
      line 2
    """
    ```
    to keep the indention. Now we have a code formatter, so we can use the 
standard multiline syntax in scala, which is
    ```
    s"""
      |code
      |line 2
    """. stripMargin
    ```
    This is also the easiest way to write multiline string in IDE, just type 
`s"""` and enter, the code structure is automatically generated.


---

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

Reply via email to