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


##########
backends-velox/src/main/scala/org/apache/gluten/backendsapi/velox/VeloxBackend.scala:
##########
@@ -448,6 +448,12 @@ object VeloxBackendSettings extends BackendSettingsApi {
                             "Only integral type & date type are" +
                               " supported for sort key when literal bound type 
is used!")
                       })
+                  e.dataType match {
+                    case ByteType | ShortType | IntegerType | LongType =>
+                    case other =>
+                      throw new GlutenNotSupportException(
+                        s"Only integral literal bounds are supported for a 
RANGE frame, got $other")
+                  }

Review Comment:
   This literal-bound type check appears duplicated in both Velox and Bolt 
backends (same logic/message). To avoid drift between backends, consider 
extracting a shared helper (e.g., in a common backend settings utility/trait) 
that validates literal RANGE bounds and throws a consistent 
`GlutenNotSupportException`.



##########
gluten-substrait/src/main/java/org/apache/gluten/substrait/expression/WindowFunctionNode.java:
##########
@@ -72,6 +73,19 @@ public class WindowFunctionNode implements Serializable {
     this.originalInputAttributes = originalInputAttributes;
   }
 
+  // A bound that does not parse as a long, such as the -1.50 of RANGE BETWEEN 
1.5 PRECEDING on a
+  // decimal key, throws GlutenNotSupportException so the window falls back; a
+  // NumberFormatException would fail the query instead.
+  private static Long 
parseOffset(org.apache.spark.sql.catalyst.expressions.Expression boundType) {
+    String raw = String.valueOf(boundType.eval(null));
+    try {
+      return Long.parseLong(raw);
+    } catch (NumberFormatException e) {
+      throw new GlutenNotSupportException(
+          "Window frame bound is not a long offset: " + raw + " (" + 
boundType.sql() + ")");

Review Comment:
   The new error message is helpful, but it omits the bound’s data type, which 
is often the key clue when diagnosing RANGE-bound issues (e.g., 
decimal/interval types). Consider including `boundType.dataType()` (or a short 
form) in the message to make fallback reasons easier to debug from logs.



##########
gluten-substrait/src/test/java/org/apache/gluten/substrait/expression/WindowFunctionNodeTest.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.substrait.expression;
+
+import org.apache.gluten.exception.GlutenNotSupportException;
+import org.apache.gluten.substrait.type.TypeBuilder;
+
+import org.apache.spark.sql.catalyst.expressions.Literal;
+import org.apache.spark.sql.types.DataTypes;
+import org.junit.Test;
+
+import java.math.BigDecimal;
+import java.util.Collections;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+
+public class WindowFunctionNodeTest {
+
+  private WindowFunctionNode nodeWithLowerBound(Literal lowerBound) {
+    return new WindowFunctionNode(
+        0,
+        Collections.emptyList(),
+        "w",
+        TypeBuilder.makeFP64(false),
+        Literal.create(1L, DataTypes.LongType),
+        lowerBound,
+        "RANGE",
+        false,
+        Collections.emptyList());
+  }
+
+  @Test
+  public void nonIntegralBoundFailsValidation() {
+    // Spark casts a RANGE bound to the order key type, so on a decimal key 
even 10 PRECEDING
+    // arrives as -10.00.
+    Literal[] bounds = {
+      Literal.create(new BigDecimal("-1.50"), DataTypes.createDecimalType(10, 
2)),
+      Literal.create(new BigDecimal("-10.00"), DataTypes.createDecimalType(10, 
2)),
+      Literal.create(-0.5d, DataTypes.DoubleType)
+    };
+    for (Literal bound : bounds) {
+      WindowFunctionNode node = nodeWithLowerBound(bound);
+      GlutenNotSupportException e = 
assertThrows(GlutenNotSupportException.class, node::toProtobuf);
+      assertTrue(e.getMessage(), e.getMessage().contains(bound.toString()));

Review Comment:
   The assertion `e.getMessage().contains(bound.toString())` is likely brittle 
and may fail because `WindowFunctionNode.parseOffset` builds the message from 
`raw` and `boundType.sql()`, not `Literal.toString()`. A more stable assertion 
would check for a consistent substring (e.g., the `raw` value like `-10.00` / 
`-0.5`, or `"Window frame bound is not a long offset"`), and optionally also 
check `bound.sql()` if available.



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