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


##########
spark/src/main/scala/org/apache/comet/serde/conditional.scala:
##########
@@ -91,3 +91,48 @@ 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 = Some(expr.children.last)
+    var allBranches: Seq[Expression] = Seq()
+    val whenSeq = branches.map(elements => {
+      allBranches = allBranches :+ elements._1
+      exprToProtoInternal(elements._1, inputs, binding)
+    })
+    val thenSeq = branches.map(elements => {
+      allBranches = allBranches :+ elements._2
+      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)
+      if (elseValue.isDefined) {

Review Comment:
   `elseValue` is explicitly set to `Some` earlier, so the condition 
`elseValue.isDefined` is always true. I don't think that `elseValue` needs to 
be an `Option`?



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