Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/21193#discussion_r185794875
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/javaCode.scala
 ---
    @@ -112,6 +112,102 @@ object JavaCode {
       def isNullExpression(code: String): SimpleExprValue = {
         expression(code, BooleanType)
       }
    +
    +  def block(code: String): Block = {
    +    CodeBlock(codeParts = Seq(code), exprValues = Seq.empty)
    +  }
    +}
    +
    +/**
    + * A block of java code which involves some expressions represented by 
`ExprValue`.
    + */
    +trait Block extends JavaCode {
    +  def exprValues: Seq[Any]
    +
    +  // This will be called during string interpolation.
    +  override def toString: String = _marginChar match {
    +    case Some(c) => code.stripMargin(c)
    +    case _ => code
    +  }
    +
    +  var _marginChar: Option[Char] = None
    +
    +  def stripMargin(c: Char): this.type = {
    +    _marginChar = Some(c)
    +    this
    +  }
    +
    +  def stripMargin: this.type = {
    +    _marginChar = Some('|')
    +    this
    +  }
    +
    +  def + (other: Block): Block
    +}
    +
    +object Block {
    +  implicit def blockToString(block: Block): String = block.toString
    +
    +  implicit def blocksToBlock(blocks: Seq[Block]): Block = Blocks(blocks)
    +
    +  implicit class BlockHelper(val sc: StringContext) extends AnyVal {
    +    def code(args: Any*): Block = {
    --- End diff --
    
    Ok.


---

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

Reply via email to