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


##########
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:
   Velox and Bolt keep their own `supportWindowExec`, and the existing DESC and 
sort-key checks right above are already duplicated the same way, so I kept the 
new check next to them rather than pulling only this one into shared code.



##########
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:
   Changed in 6ed03917b: the test now checks that the message ends with the 
evaluated value and the bound's type.



##########
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:
   Done in 6ed03917b. The message now ends with the bound's type, e.g. `-10.00 
(decimal(10,2))`.



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