Copilot commented on code in PR #13282:
URL: https://github.com/apache/gluten/pull/13282#discussion_r4551544448
##########
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:
The contract comment says the caller supplies a non-null expression for each
argument, but the implementation in `SubstraitToVeloxPlanValidator.cc`
explicitly handles missing/unavailable converted expressions (e.g., checks for
`params.empty()` / `!params[0]`). Update this comment to reflect that `params`
entries may be null when conversion fails/unavailable, or alternatively make
the conversion guarantee non-null entries and remove the null-handling path.
##########
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 PR description states integral native eligibility remains literal-only
in `[0, 400]` (and that disabling native validation should *not* change
negative-scale fallback behavior), but this test asserts native execution for
`401` and `Int.MaxValue` (and the suite later expects negative scales to be
natively executed when native validation is disabled). Please either (a)
enforce the `[0, 400]` limit / keep negative-scale fallback even when
validation is disabled (and update tests/docs accordingly), or (b) update the
PR description to match the implemented behavior (nonnegative literal scales
beyond 400 being eligible, and debug mode bypassing the guard).
--
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]