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


##########
gluten-substrait/src/main/scala/org/apache/gluten/expression/DecimalCeilFloorTransformer.scala:
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gluten.expression
+
+import org.apache.gluten.backendsapi.BackendsApiManager
+import org.apache.gluten.exception.GlutenNotSupportException
+
+import org.apache.spark.sql.catalyst.expressions._
+import org.apache.spark.sql.types.{DataType, DecimalType}
+
+/**
+ * Transformer for Spark `RoundCeil(decimal, scale)` and `RoundFloor(decimal, 
scale)`. These power
+ * the 2-argument forms of `ceiling(x, scale)` / `floor(x, scale)` and 
dispatch to the Velox
+ * `decimal_ceil` / `decimal_floor` special forms (substrait names `ceil` / 
`floor`, remapped on the
+ * C++ side based on arity + decimal arg type).
+ *
+ * The output `DataType` is recomputed from the original Spark decimal input 
type and the constant
+ * folded scale, matching Spark's `RoundBase.dataType` formula. Mirrors the 
structure of
+ * `DecimalRoundTransformer`.
+ */
+case class DecimalCeilFloorTransformer(
+    substraitExprName: String,
+    child: ExpressionTransformer,
+    original: Expression,
+    scaleExpr: Expression)
+  extends BinaryExpressionTransformer {
+
+  private val toScale: Int = {
+    val evaluated = scaleExpr.eval(EmptyRow)
+    if (evaluated == null) {
+      throw new GlutenNotSupportException(
+        s"Scale expression evaluated to null for ${original.nodeName}. Falling 
back to Spark.")
+    }
+    evaluated.asInstanceOf[Int]
+  }

Review Comment:
   `toScale` is derived by `scaleExpr.eval(EmptyRow)` without checking 
`scaleExpr.foldable` or handling evaluation failures. If the user writes 
`ceiling(decimal_col, scale_col)` (non-literal scale) or a scale expression 
that can’t be evaluated on `EmptyRow`, this can throw (e.g., during 
`eval`/cast) and may abort transformation rather than cleanly triggering Spark 
fallback via `GlutenNotSupportException`.
   
   Consider explicitly requiring a foldable scale and wrapping evaluation/cast 
errors into `GlutenNotSupportException` so the operator can reliably fall back.



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