This is an automated email from the ASF dual-hosted git repository.

rui-mo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new e215cb2686 [VL] Enable guarded decimal ROUND with cross-version 
coverage (#13103)
e215cb2686 is described below

commit e215cb2686613f8e4773f4369a89c44bce9d57ed
Author: Luis PeƱaranda <[email protected]>
AuthorDate: Mon Nov 23 18:46:26 2026 +0100

    [VL] Enable guarded decimal ROUND with cross-version coverage (#13103)
    
    Co-authored-by: Luis Penaranda <[email protected]>
---
 .../backendsapi/velox/VeloxDecimalRoundSuite.scala |  59 +++++++
 .../substrait/SubstraitToVeloxPlanValidator.cc     |  19 ++-
 .../substrait/SubstraitToVeloxPlanValidator.h      |   7 +-
 cpp/velox/tests/SparkFunctionTest.cc               |  56 ++++++
 .../velox/velox-backend-scalar-function-support.md |   2 +-
 .../org/apache/gluten/config/GlutenConfig.scala    |   3 +-
 .../expression/DecimalRoundTransformer.scala       |   8 +-
 .../spark/sql/GlutenDecimalRoundSuiteBase.scala    | 190 +++++++++++++++++++++
 .../gluten/utils/velox/VeloxTestSettings.scala     |   1 +
 .../apache/spark/sql/GlutenDecimalRoundSuite.scala |  19 +++
 .../gluten/utils/velox/VeloxTestSettings.scala     |   1 +
 .../apache/spark/sql/GlutenDecimalRoundSuite.scala |  19 +++
 .../gluten/utils/velox/VeloxTestSettings.scala     |   1 +
 .../apache/spark/sql/GlutenDecimalRoundSuite.scala |  19 +++
 .../gluten/utils/velox/VeloxTestSettings.scala     |   1 +
 .../apache/spark/sql/GlutenDecimalRoundSuite.scala |  19 +++
 .../gluten/utils/velox/VeloxTestSettings.scala     |   1 +
 .../apache/spark/sql/GlutenDecimalRoundSuite.scala |  19 +++
 18 files changed, 435 insertions(+), 9 deletions(-)

diff --git 
a/backends-velox/src/test/scala/org/apache/gluten/backendsapi/velox/VeloxDecimalRoundSuite.scala
 
b/backends-velox/src/test/scala/org/apache/gluten/backendsapi/velox/VeloxDecimalRoundSuite.scala
new file mode 100644
index 0000000000..8918a07669
--- /dev/null
+++ 
b/backends-velox/src/test/scala/org/apache/gluten/backendsapi/velox/VeloxDecimalRoundSuite.scala
@@ -0,0 +1,59 @@
+/*
+ * 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.backendsapi.velox
+
+import org.apache.gluten.expression.{DecimalRoundTransformer, 
LiteralTransformer}
+import org.apache.gluten.substrait.SubstraitContext
+
+import org.apache.spark.sql.catalyst.expressions.{Add, BoundReference, Cast, 
Literal, Round}
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.types._
+
+import org.scalatest.funsuite.AnyFunSuite
+
+class VeloxDecimalRoundSuite extends AnyFunSuite {
+  test("decimal round preserves a typed NULL scale") {
+    val value = Literal.create(Decimal(new java.math.BigDecimal("2.5")), 
DecimalType(3, 1))
+    val scale = Literal.create(null, IntegerType)
+    val original = Round(value, scale)
+    val transformer = DecimalRoundTransformer("round", 
LiteralTransformer(value), original)
+    val scalar = transformer.doTransform(new 
SubstraitContext).toProtobuf.getScalarFunction
+    assert(scalar.getArgumentsCount == 2)
+    assert(scalar.getArguments(1).getValue.getLiteral.hasNull)
+    assert(transformer.dataType == DecimalType(3, 0))
+  }
+
+  test("decimal round eligibility defers to native validation") {
+    val validator = new VeloxValidatorApi
+    val value = BoundReference(0, DecimalType(38, 38), nullable = true)
+    val scales = Seq(
+      Literal(-401),
+      Literal(401),
+      BoundReference(1, IntegerType, nullable = false),
+      Add(Literal(400), Literal(1)))
+    scales.foreach {
+      scale => assert(validator.doExprValidate("round", Round(value, scale)))
+    }
+    val conf = new SQLConf
+    conf.setConfString(SQLConf.ANSI_ENABLED.key, "true")
+    SQLConf.withExistingConf(conf) {
+      val scale = Cast(Literal("invalid-scale"), IntegerType)
+      intercept[Exception](scale.eval())
+      assert(validator.doExprValidate("round", Round(value, scale)))
+    }
+  }
+}
diff --git a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc 
b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
index c5e585be4d..1628c2dea7 100644
--- a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
+++ b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
@@ -18,6 +18,7 @@
 #include "SubstraitToVeloxPlanValidator.h"
 #include <google/protobuf/wrappers.pb.h>
 #include <re2/re2.h>
+#include <limits>
 #include <string>
 #include "TypeUtils.h"
 #include "udf/UdfLoader.h"
@@ -141,7 +142,7 @@ bool SubstraitToVeloxPlanValidator::flattenDualLevel(const 
TypePtr& type, std::v
 
 bool SubstraitToVeloxPlanValidator::validateRound(
     const ::substrait::Expression::ScalarFunction& scalarFunction,
-    const RowTypePtr& inputType) {
+    const std::vector<core::TypedExprPtr>& params) {
   const auto& arguments = scalarFunction.arguments();
   if (arguments.size() < 2) {
     return false;
@@ -152,6 +153,20 @@ bool SubstraitToVeloxPlanValidator::validateRound(
     return false;
   }
 
+  const auto& valueType = params[0]->type();
+  if (valueType->isDecimal()) {
+    const auto& scale = arguments[1].value().literal();
+    if (scale.has_null() && scale.null().has_i32()) {
+      return true;
+    }
+    if (scale.has_i32() && scale.i32() != std::numeric_limits<int32_t>::min() 
&&
+        scale.i32() != std::numeric_limits<int32_t>::min() + 1) {
+      return true;
+    }
+    LOG_VALIDATION_MSG("Decimal ROUND does not support INTEGER scales INT_MIN 
and INT_MIN + 1.");
+    return false;
+  }
+
   // Velox has different result with Spark on negative scale.
   auto typeCase = arguments[1].value().literal().literal_type_case();
   switch (typeCase) {
@@ -260,7 +275,7 @@ bool SubstraitToVeloxPlanValidator::validateScalarFunction(
   std::vector<std::string> types = 
SubstraitParser::getSubFunctionTypes(function);
 
   if (name == "round") {
-    return validateRound(scalarFunction, inputType);
+    return validateRound(scalarFunction, params);
   }
   if (name == "extract") {
     return validateExtractExpr(params);
diff --git a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.h 
b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.h
index 2cb7518e84..959cb35aba 100644
--- a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.h
+++ b/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.
+  bool validateRound(
+      const ::substrait::Expression::ScalarFunction& scalarFunction,
+      const std::vector<core::TypedExprPtr>& params);
 
   /// Validate extract function.
   bool validateExtractExpr(const std::vector<core::TypedExprPtr>& params);
diff --git a/cpp/velox/tests/SparkFunctionTest.cc 
b/cpp/velox/tests/SparkFunctionTest.cc
index 0384a69bee..f82d3e5453 100644
--- a/cpp/velox/tests/SparkFunctionTest.cc
+++ b/cpp/velox/tests/SparkFunctionTest.cc
@@ -15,10 +15,13 @@
  * limitations under the License.
  */
 
+#include <limits>
+#include <optional>
 #include <string>
 #include <vector>
 
 #include "operators/functions/RegistrationAllFunctions.h"
+#include "substrait/SubstraitToVeloxPlanValidator.h"
 #include "velox/common/base/tests/GTestUtils.h"
 #include "velox/core/Expressions.h"
 #include "velox/functions/sparksql/SparkQueryConfig.h"
@@ -125,6 +128,59 @@ TEST_F(SparkFunctionTest, roundWithDecimal) {
   runRoundWithDecimalTest<int8_t>(testRoundWithDecIntegralData<int8_t>());
 }
 
+TEST_F(SparkFunctionTest, decimalRoundScaleValidation) {
+  const auto validate = [&](std::optional<int32_t> scale, bool castInput) {
+    ::substrait::Expression expression;
+    auto* function = expression.mutable_scalar_function();
+    function->set_function_reference(1);
+    auto* value = function->add_arguments()->mutable_value();
+    if (castInput) {
+      auto* cast = value->mutable_cast();
+      auto* type = cast->mutable_type()->mutable_decimal();
+      type->set_precision(38);
+      type->set_scale(0);
+      
type->set_nullability(::substrait::Type_Nullability_NULLABILITY_NULLABLE);
+      value = cast->mutable_input();
+    }
+    
value->mutable_selection()->mutable_direct_reference()->mutable_struct_field()->set_field(0);
+    auto* literal = 
function->add_arguments()->mutable_value()->mutable_literal();
+    if (scale.has_value()) {
+      literal->set_i32(scale.value());
+    } else {
+      
literal->mutable_null()->mutable_i32()->set_nullability(::substrait::Type_Nullability_NULLABILITY_NULLABLE);
+    }
+    auto* output = function->mutable_output_type()->mutable_decimal();
+    output->set_precision(38);
+    output->set_scale(0);
+    
output->set_nullability(::substrait::Type_Nullability_NULLABILITY_NULLABLE);
+    gluten::SubstraitToVeloxPlanValidator validator(pool());
+    return validator.validate(
+        expression, ROW({"value"}, {castInput ? VARCHAR() : DECIMAL(38, 0)}), 
{{1, "round:opt_dec<38,0>_i32"}});
+  };
+  for (const auto scale :
+       {std::numeric_limits<int32_t>::min() + 2,
+        -401,
+        -400,
+        -39,
+        -38,
+        -1,
+        0,
+        38,
+        400,
+        401,
+        std::numeric_limits<int32_t>::max()}) {
+    SCOPED_TRACE(scale);
+    EXPECT_TRUE(validate(scale, false));
+  }
+  EXPECT_TRUE(validate(std::nullopt, false));
+  EXPECT_TRUE(validate(-1, true));
+  EXPECT_TRUE(validate(std::nullopt, true));
+  for (const auto scale : {std::numeric_limits<int32_t>::min(), 
std::numeric_limits<int32_t>::min() + 1}) {
+    SCOPED_TRACE(scale);
+    EXPECT_FALSE(validate(scale, false));
+  }
+}
+
 TEST_F(SparkFunctionTest, expressionLevelAnsiCastIgnoresSessionAnsiOff) {
   queryCtx_->testingOverrideConfigUnsafe({{sparkAnsiEnabledConfigKey(), 
"false"}});
   auto input = makeRowVector({makeFlatVector<std::string>({"2147483648"})});
diff --git a/docs/backends/velox/velox-backend-scalar-function-support.md 
b/docs/backends/velox/velox-backend-scalar-function-support.md
index 0ce993e2c5..1b229fd759 100644
--- a/docs/backends/velox/velox-backend-scalar-function-support.md
+++ b/docs/backends/velox/velox-backend-scalar-function-support.md
@@ -297,7 +297,7 @@ The status applies to `spark.sql.ansi.enabled=false`. When 
ANSI mode is enabled,
 | randn             | Randn                  | S        |                |
 | random            | Rand                   | S        |                |
 | rint              | Rint                   | S        |                |
-| round             | Round                  | S        |                |
+| round             | Round                  | PS       | Decimal inputs 
support foldable INTEGER scales except INT_MIN and INT_MIN + 1, plus NULL. The 
two excluded scales fall back to Spark because Spark resolves incompatible 
result metadata. Integral and floating-point negative scales retain their 
existing validated fallback. |
 | sec               | Sec                    | S        |                |
 | sign              | Signum                 | S        |                |
 | signum            | Signum                 | S        |                |
diff --git 
a/gluten-substrait/src/main/scala/org/apache/gluten/config/GlutenConfig.scala 
b/gluten-substrait/src/main/scala/org/apache/gluten/config/GlutenConfig.scala
index a1e6051d9d..ad73a1a85c 100644
--- 
a/gluten-substrait/src/main/scala/org/apache/gluten/config/GlutenConfig.scala
+++ 
b/gluten-substrait/src/main/scala/org/apache/gluten/config/GlutenConfig.scala
@@ -894,7 +894,8 @@ object GlutenConfig extends ConfigRegistry {
       .doc(
         "This is tmp config to specify whether to enable the native validation 
based on " +
           "Substrait plan. After the validations in all backends are correctly 
implemented, " +
-          "this config should be removed.")
+          "this config should be removed. Disabling native validation is 
intended for debugging " +
+          "and may cause unsupported operations to fail at runtime instead of 
falling back.")
       .booleanConf
       .createWithDefault(true)
 
diff --git 
a/gluten-substrait/src/main/scala/org/apache/gluten/expression/DecimalRoundTransformer.scala
 
b/gluten-substrait/src/main/scala/org/apache/gluten/expression/DecimalRoundTransformer.scala
index a8ccd2635c..e5cf7c1d7d 100644
--- 
a/gluten-substrait/src/main/scala/org/apache/gluten/expression/DecimalRoundTransformer.scala
+++ 
b/gluten-substrait/src/main/scala/org/apache/gluten/expression/DecimalRoundTransformer.scala
@@ -20,7 +20,7 @@ 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}
+import org.apache.spark.sql.types.{DataType, DecimalType, IntegerType}
 
 case class DecimalRoundTransformer(
     substraitExprName: String,
@@ -28,7 +28,8 @@ case class DecimalRoundTransformer(
     original: Round)
   extends BinaryExpressionTransformer {
 
-  val toScale: Int = original.scale.eval(EmptyRow).asInstanceOf[Int]
+  private val scaleValue = original.scale.eval(EmptyRow)
+  val toScale: Int = if (scaleValue == null) 0 else 
scaleValue.asInstanceOf[Int]
 
   // Use the same result type for different Spark versions in velox.
   // The same result type with spark in ch.
@@ -43,5 +44,6 @@ case class DecimalRoundTransformer(
   }
 
   override def left: ExpressionTransformer = child
-  override def right: ExpressionTransformer = LiteralTransformer(toScale)
+  override def right: ExpressionTransformer =
+    LiteralTransformer(Literal.create(scaleValue, IntegerType))
 }
diff --git 
a/gluten-ut/common/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuiteBase.scala
 
b/gluten-ut/common/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuiteBase.scala
new file mode 100644
index 0000000000..323fc5542d
--- /dev/null
+++ 
b/gluten-ut/common/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuiteBase.scala
@@ -0,0 +1,190 @@
+/*
+ * 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.sql.catalyst.expressions.{Literal, 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.collection.JavaConverters._
+
+abstract class GlutenDecimalRoundSuiteBase extends GlutenSQLTestsTrait {
+  private def withInput(dataType: DecimalType, values: Seq[String])(f: => 
Unit): Unit = {
+    val schema = new StructType().add("value", dataType)
+    val rows = values.map(value => Row(new java.math.BigDecimal(value))) :+ 
Row(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("decimal_round_input") {
+            
spark.read.parquet(path.toString).createOrReplaceTempView("decimal_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 checkRound(scale: String, native: Boolean = true): Unit = {
+    val query = s"SELECT round(value, $scale) FROM decimal_round_input"
+    withSQLConf(GlutenConfig.GLUTEN_ENABLED.key -> "false") {
+      val vanilla = sql(query)
+      val expectedSchema = vanilla.schema
+      val expected = vanilla.collect().toSeq
+      withSQLConf(GlutenConfig.GLUTEN_ENABLED.key -> "true") {
+        val df = sql(query)
+        assertExecution(df, native)
+        assert(df.schema == expectedSchema)
+        checkAnswer(df, expected)
+      }
+    }
+  }
+
+  testGluten("decimal ROUND preserves schemas and HALF_UP results across 
storage boundaries") {
+    val cases = Seq(
+      (DecimalType(3, 1), Seq("2.5", "-2.5", "0")),
+      (DecimalType(18, 0), Seq("999999999999999999", "-999999999999999999")),
+      (DecimalType(19, 0), Seq("9999999999999999999", "-9999999999999999999")),
+      (DecimalType(38, 1), Seq("9" * 37 + ".9", "-" + "9" * 37 + ".9")),
+      (DecimalType(38, 38), Seq("0.6", "-0.6", "0.5", "-0.5"))
+    )
+    for ((dataType, values) <- cases) {
+      withInput(dataType, values) {
+        for (ansi <- Seq("false", "true")) {
+          withSQLConf(SQLConf.ANSI_ENABLED.key -> ansi) {
+            Seq(-401, -400, -39, -1, 0, 1, 38, 400, 401, Int.MaxValue)
+              .foreach(scale => checkRound(scale.toString))
+            checkRound("-1 + 0")
+          }
+        }
+      }
+    }
+  }
+
+  testGluten("decimal ROUND handles the 38-digit HALF_UP tie and precision 
overflow") {
+    withInput(DecimalType(38, 0), Seq("4" + "9" * 37, "-4" + "9" * 37)) {
+      checkRound("-38")
+    }
+    for ((value, scale) <- Seq(("9" * 38, -1), ("5" + "0" * 37, -38), ("-5" + 
"0" * 37, -38))) {
+      withInput(DecimalType(38, 0), Seq(value)) {
+        for (ansi <- Seq("false", "true")) {
+          withSQLConf(SQLConf.ANSI_ENABLED.key -> ansi) {
+            val query = s"SELECT round(value, $scale) FROM decimal_round_input"
+            withSQLConf(GlutenConfig.GLUTEN_ENABLED.key -> "false") {
+              val error = intercept[Exception](sql(query).collect())
+              
assert(Iterator.iterate[Throwable](error)(_.getCause).takeWhile(_ != 
null).exists {
+                cause =>
+                  Option(cause.getMessage).exists {
+                    message =>
+                      message.contains("NUMERIC_VALUE_OUT_OF_RANGE") ||
+                      
message.contains("DECIMAL_PRECISION_EXCEEDS_MAX_PRECISION")
+                  }
+              })
+            }
+            val df = sql(query)
+            assertExecution(df, native = true)
+            val error = intercept[Exception](df.collect())
+            assert(Iterator.iterate[Throwable](error)(_.getCause).takeWhile(_ 
!= null).exists {
+              cause => Option(cause.getMessage).exists(_.contains("Decimal 
overflow"))
+            })
+          }
+        }
+      }
+    }
+  }
+
+  testGluten("decimal ROUND NULL scale skips an overflowing child natively") {
+    withInput(DecimalType(38, 0), Seq("9" * 38)) {
+      for (ansi <- Seq("false", "true")) {
+        withSQLConf(
+          SQLConf.ANSI_ENABLED.key -> ansi,
+          GlutenConfig.NATIVE_VALIDATION_ENABLED.key -> "true",
+          SQLConf.OPTIMIZER_EXCLUDED_RULES.key ->
+            s"${ConstantFolding.ruleName},${NullPropagation.ruleName}"
+        ) {
+          val query =
+            "SELECT round(round(value, -1), CAST(NULL AS INT)) FROM 
decimal_round_input"
+          var expectedSchema: StructType = null
+          var expected: Seq[Row] = Nil
+          withSQLConf(GlutenConfig.GLUTEN_ENABLED.key -> "false") {
+            val vanilla = sql(query)
+            expectedSchema = vanilla.schema
+            expected = vanilla.collect().toSeq
+          }
+          val df = sql(query)
+          assertExecution(df, native = true)
+          assert(df.schema == expectedSchema)
+          checkAnswer(df, expected)
+        }
+      }
+    }
+  }
+
+  testGluten("decimal ROUND excludes Spark metadata-overflow scales") {
+    withInput(DecimalType(3, 1), Seq("2.5", "-2.5", "0")) {
+      withSQLConf(GlutenConfig.NATIVE_VALIDATION_ENABLED.key -> "true") {
+        for (scale <- Seq(Int.MinValue, Int.MinValue + 1)) {
+          val df = sql(s"SELECT round(value, CAST($scale AS INT)) FROM 
decimal_round_input")
+          assertExecution(df, native = false)
+        }
+      }
+    }
+  }
+
+  testGluten("decimal ROUND accepts foldable scales with constant folding 
disabled") {
+    withInput(DecimalType(3, 1), Seq("2.5", "-2.5", "0")) {
+      for (nativeValidation <- Seq("false", "true")) {
+        withSQLConf(
+          GlutenConfig.NATIVE_VALIDATION_ENABLED.key -> nativeValidation,
+          SQLConf.OPTIMIZER_EXCLUDED_RULES.key ->
+            s"${ConstantFolding.ruleName},${NullPropagation.ruleName}"
+        ) {
+          val scales = sql("SELECT round(value, 1 - 2) FROM 
decimal_round_input")
+            .queryExecution.optimizedPlan.collect {
+              case node => node.expressions.flatMap(_.collect { case round: 
Round => round.scale })
+            }.flatten
+          assert(scales.nonEmpty)
+          assert(scales.forall(scale => scale.foldable && 
!scale.isInstanceOf[Literal]))
+          checkRound("1 - 2")
+          checkRound("-200 - 200")
+          checkRound("200 + 200")
+          checkRound("CAST(NULL AS INT)")
+          checkRound("400 + 1")
+          checkRound("-400 - 1")
+        }
+      }
+    }
+  }
+}
diff --git 
a/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
 
b/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
index 104461c2a3..19ab0a0715 100644
--- 
a/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
+++ 
b/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
@@ -49,6 +49,7 @@ import 
org.apache.spark.sql.sources.{GlutenBucketedReadWithoutHiveSupportSuite,
 class VeloxTestSettings extends BackendTestSettings {
   import SuiteSettings._
   enableSuite[GlutenStringFunctionsSuite]
+  enableSuite[GlutenDecimalRoundSuite]
   enableSuite[GlutenBloomFilterAggregateQuerySuite]
   enableSuite[GlutenDataSourceV2DataFrameSessionCatalogSuite]
   enableSuite[GlutenDataSourceV2DataFrameSuite]
diff --git 
a/gluten-ut/spark34/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
 
b/gluten-ut/spark34/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
new file mode 100644
index 0000000000..ba53038ee7
--- /dev/null
+++ 
b/gluten-ut/spark34/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
@@ -0,0 +1,19 @@
+/*
+ * 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
+
+class GlutenDecimalRoundSuite extends GlutenDecimalRoundSuiteBase
diff --git 
a/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
 
b/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
index 1ae8f00050..6efe11507d 100644
--- 
a/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
+++ 
b/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
@@ -59,6 +59,7 @@ class VeloxTestSettings extends BackendTestSettings {
   // @DoNotDiscover keeps the longer stress run separate; CI selects it 
explicitly.
   enableSuite("org.apache.spark.sql.kafka010.GlutenKafkaSourceStressSuite")
   enableSuite[GlutenStringFunctionsSuite]
+  enableSuite[GlutenDecimalRoundSuite]
   enableSuite[GlutenBloomFilterAggregateQuerySuite]
   enableSuite[GlutenBloomFilterAggregateQuerySuiteCGOff]
   enableSuite[GlutenDataSourceV2DataFrameSessionCatalogSuite]
diff --git 
a/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
 
b/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
new file mode 100644
index 0000000000..ba53038ee7
--- /dev/null
+++ 
b/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
@@ -0,0 +1,19 @@
+/*
+ * 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
+
+class GlutenDecimalRoundSuite extends GlutenDecimalRoundSuiteBase
diff --git 
a/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
 
b/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
index b29a3ffc06..7114414262 100644
--- 
a/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
+++ 
b/gluten-ut/spark40/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
@@ -53,6 +53,7 @@ class VeloxTestSettings extends BackendTestSettings {
   private val ansiNoFallback: Boolean =
     
sys.props.get(GlutenConfig.GLUTEN_ANSI_FALLBACK_ENABLED.key).contains("false")
   enableSuite[GlutenStringFunctionsSuite]
+  enableSuite[GlutenDecimalRoundSuite]
   enableSuite[GlutenBloomFilterAggregateQuerySuite]
   enableSuite[GlutenBloomFilterAggregateQuerySuiteCGOff]
   enableSuite[GlutenDataSourceV2DataFrameSessionCatalogSuite]
diff --git 
a/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
 
b/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
new file mode 100644
index 0000000000..ba53038ee7
--- /dev/null
+++ 
b/gluten-ut/spark40/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
@@ -0,0 +1,19 @@
+/*
+ * 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
+
+class GlutenDecimalRoundSuite extends GlutenDecimalRoundSuiteBase
diff --git 
a/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
 
b/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
index 185be7f705..e378f64243 100644
--- 
a/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
+++ 
b/gluten-ut/spark41/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
@@ -53,6 +53,7 @@ class VeloxTestSettings extends BackendTestSettings {
   private val ansiNoFallback: Boolean =
     
sys.props.get(GlutenConfig.GLUTEN_ANSI_FALLBACK_ENABLED.key).contains("false")
   enableSuite[GlutenStringFunctionsSuite]
+  enableSuite[GlutenDecimalRoundSuite]
   enableSuite[GlutenBloomFilterAggregateQuerySuite]
   enableSuite[GlutenBloomFilterAggregateQuerySuiteCGOff]
   enableSuite[GlutenDataSourceV2DataFrameSessionCatalogSuite]
diff --git 
a/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
 
b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
new file mode 100644
index 0000000000..ba53038ee7
--- /dev/null
+++ 
b/gluten-ut/spark41/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
@@ -0,0 +1,19 @@
+/*
+ * 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
+
+class GlutenDecimalRoundSuite extends GlutenDecimalRoundSuiteBase
diff --git 
a/gluten-ut/spark42/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
 
b/gluten-ut/spark42/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
index 2a14b80479..cf2bf7df27 100644
--- 
a/gluten-ut/spark42/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
+++ 
b/gluten-ut/spark42/src/test/scala/org/apache/gluten/utils/velox/VeloxTestSettings.scala
@@ -53,6 +53,7 @@ class VeloxTestSettings extends BackendTestSettings {
   private val ansiNoFallback: Boolean =
     
sys.props.get(GlutenConfig.GLUTEN_ANSI_FALLBACK_ENABLED.key).contains("false")
   enableSuite[GlutenStringFunctionsSuite]
+  enableSuite[GlutenDecimalRoundSuite]
   enableSuite[GlutenBloomFilterAggregateQuerySuite]
   enableSuite[GlutenBloomFilterAggregateQuerySuiteCGOff]
   enableSuite[GlutenDataSourceV2DataFrameSessionCatalogSuite]
diff --git 
a/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
 
b/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
new file mode 100644
index 0000000000..ba53038ee7
--- /dev/null
+++ 
b/gluten-ut/spark42/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala
@@ -0,0 +1,19 @@
+/*
+ * 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
+
+class GlutenDecimalRoundSuite extends GlutenDecimalRoundSuiteBase


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to