Copilot commented on code in PR #13229:
URL: https://github.com/apache/gluten/pull/13229#discussion_r4521642873


##########
backends-velox/src/main/scala/org/apache/gluten/backendsapi/velox/VeloxSparkPlanExecApi.scala:
##########
@@ -1392,6 +1393,75 @@ class VeloxSparkPlanExecApi extends SparkPlanExecApi 
with Logging {
     }
   }
 
+  /**
+   * Spark replaces `right(str, len)` with
+   * `If(IsNull(str), null, If(len <= 0, "", Substring(str, -len, 
Int.MaxValue)))` before physical
+   * planning. Convert that shape to `If(IsNull(str), null, right(str, len))` 
so that Velox runs the
+   * Spark `right` function directly instead of `if` and `substring`.
+   */
+  private object SparkRightShape {
+    private def unwrapKnownNotNull(expression: Expression): Expression = 
expression match {
+      case KnownNotNull(child) => unwrapKnownNotNull(child)
+      case other => other
+    }
+
+    def unapply(expression: Expression): Option[(Expression, Expression, If)] 
= expression match {
+      case outer @ If(
+            IsNull(nullCheckedStr),
+            Literal(null, _),
+            If(
+              LessThanOrEqual(nonPositiveLen, Literal(0, IntegerType)),
+              Literal(empty: UTF8String, StringType),
+              Substring(substringStr, UnaryMinus(substringLen, _), 
Literal(Int.MaxValue, _))
+            )
+          )
+          if empty == UTF8String.EMPTY_UTF8 &&
+            unwrapKnownNotNull(nullCheckedStr).semanticEquals(
+              unwrapKnownNotNull(substringStr)) &&
+            nonPositiveLen.semanticEquals(substringLen) =>
+        Some((nullCheckedStr, nonPositiveLen, outer))
+      case _ => None
+    }
+  }
+
+  override def extraExpressionConverter(
+      substraitExprName: String,
+      expr: Expression,
+      attributeSeq: Seq[Attribute]): Option[ExpressionTransformer] = expr 
match {

Review Comment:
   `VeloxSparkPlanExecApi` already defines `extraExpressionConverter` with this 
exact signature below `extraExpressionMappings` (line 1486). Adding a second 
definition in the same class causes a Scala compilation error, so the Velox 
backend cannot build. Merge the `SparkRightShape` case into the existing 
converter, retaining its `RoundCeil` and `RoundFloor` cases.



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