luis4a0 commented on code in PR #13282:
URL: https://github.com/apache/gluten/pull/13282#discussion_r4561599520


##########
gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenIntegralRoundSuite.scala:
##########
@@ -0,0 +1,217 @@
+/*
+ * 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.spark.sql
+
+import org.apache.gluten.config.GlutenConfig
+import org.apache.gluten.execution.ProjectExecTransformer
+
+import org.apache.spark.SparkThrowable
+import org.apache.spark.sql.catalyst.expressions.Round
+import org.apache.spark.sql.catalyst.optimizer.{ConstantFolding, 
NullPropagation}
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.types._
+
+import scala.jdk.CollectionConverters._
+
+class GlutenIntegralRoundSuite extends GlutenSQLTestsTrait {
+  private def withInput(f: => Unit): Unit = {
+    val schema = new StructType()
+      .add("b", ByteType).add("s", ShortType).add("i", IntegerType).add("l", 
LongType)
+    val rows = Seq(127, -128, 25, -25, 0).map {
+      value => Row(value.toByte, value.toShort, value, value.toLong)
+    } :+ Row(null, null, null, null)
+    withSQLConf(
+      SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "false",
+      GlutenConfig.GLUTEN_ANSI_FALLBACK_ENABLED.key -> "false") {
+      withTempPath {
+        path =>
+          withSQLConf(GlutenConfig.GLUTEN_ENABLED.key -> "false") {
+            spark.createDataFrame(rows.asJava, 
schema).coalesce(1).write.parquet(path.toString)
+          }
+          withTempView("integral_round_input") {
+            
spark.read.parquet(path.toString).createOrReplaceTempView("integral_round_input")
+            f
+          }
+      }
+    }
+  }
+
+  private def assertExecution(df: DataFrame, native: Boolean): Unit = {
+    val plan = df.queryExecution.executedPlan
+    val locations = plan.collect {
+      case node if node.expressions.exists(_.exists(_.isInstanceOf[Round])) =>
+        node.isInstanceOf[ProjectExecTransformer]
+    }
+    assert(
+      locations.nonEmpty && locations.forall(_ == native),
+      s"Unexpected ROUND execution:\n$plan")
+  }
+
+  private def assertOverflow(df: DataFrame): Unit = {
+    val error = intercept[Exception](df.collect())
+    assert(Iterator.iterate[Throwable](error)(_.getCause).takeWhile(_ != 
null).exists {
+      case cause: SparkThrowable => cause.getCondition == "ARITHMETIC_OVERFLOW"
+      case _ => false
+    })
+  }
+
+  testGluten("integral ROUND uses the native identity path for every signed 
width") {
+    withInput {
+      for (ansi <- Seq("false", "true")) {
+        withSQLConf(SQLConf.ANSI_ENABLED.key -> ansi) {
+          for (scale <- Seq(0, 2, 400, 401, Int.MaxValue)) {

Review Comment:
   The current PR description already matches option (b): nonnegative INTEGER 
literal scales beyond 400 are eligible, and disabling native validation is 
documented as a debug bypass of the negative/nonliteral guard. The obsolete 
`[0, 400]` text was removed in verified head 
https://github.com/luis4a0/gluten/commit/0a56fafb48bf3a191902f75d8b7608cfeccb7d2b.



##########
cpp/velox/substrait/SubstraitToVeloxPlanValidator.h:
##########
@@ -149,8 +149,11 @@ class SubstraitToVeloxPlanValidator {
   /// Validate aggregate rel.
   bool validateAggRelFunctionType(const ::substrait::AggregateRel& 
substraitAgg);
 
-  /// Validate the round scalar function.
-  bool validateRound(const ::substrait::Expression::ScalarFunction& 
scalarFunction, const RowTypePtr& inputType);
+  /// Validate the round scalar function using its already-converted arguments.
+  /// The caller supplies one non-null expression for each Substrait argument.

Review Comment:
   Fixed in verified head 
https://github.com/luis4a0/gluten/commit/284c0aba633862ec10811e2d0741321a38b8d55c.
 The header now states that converted arguments may be missing or null when 
conversion is unavailable and that validation rejects them before inspecting 
their types.



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