andygrove commented on code in PR #2270:
URL: https://github.com/apache/datafusion-comet/pull/2270#discussion_r2319788887


##########
spark/src/main/scala/org/apache/comet/serde/conditional.scala:
##########
@@ -91,3 +91,42 @@ object CometCaseWhen extends CometExpressionSerde[CaseWhen] {
     }
   }
 }
+
+object CometCoalesce extends CometExpressionSerde[Coalesce] {
+  override def convert(
+      expr: Coalesce,
+      inputs: Seq[Attribute],
+      binding: Boolean): Option[ExprOuterClass.Expr] = {
+    val branches = expr.children.dropRight(1).map { child =>
+      (IsNotNull(child), child)
+    }
+    val elseValue = expr.children.last
+    val whenSeq = branches.map(elements => {
+      exprToProtoInternal(elements._1, inputs, binding)
+    })
+    val thenSeq = branches.map(elements => {
+      exprToProtoInternal(elements._2, inputs, binding)
+    })
+    assert(whenSeq.length == thenSeq.length)
+    if (whenSeq.forall(_.isDefined) && thenSeq.forall(_.isDefined)) {
+      val builder = ExprOuterClass.CaseWhen.newBuilder()
+      builder.addAllWhen(whenSeq.map(_.get).asJava)
+      builder.addAllThen(thenSeq.map(_.get).asJava)
+      val elseValueExpr = exprToProtoInternal(elseValue, inputs, binding)
+      if (elseValueExpr.isDefined) {
+          builder.setElseExpr(elseValueExpr.get)
+      } else {
+          withInfo(expr, elseValue)
+          return None
+        }

Review Comment:
   Indentation seems off?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to