luis4a0 commented on code in PR #13103: URL: https://github.com/apache/gluten/pull/13103#discussion_r4269482416
########## ep/build-velox/src/get-velox.sh: ########## @@ -25,7 +25,7 @@ RUN_SETUP_SCRIPT=ON ENABLE_ENHANCED_FEATURES=OFF # Developer use only for testing Velox PR. -UPSTREAM_VELOX_PR_ID="" +UPSTREAM_VELOX_PR_ID="19141" Review Comment: Agreed that this must not become the normal merged dependency. This revision is intentionally a dependency-blocked validation companion: Rui explicitly requested exercising the upstream PR through the existing developer hook at https://github.com/facebookincubator/velox/pull/19141#discussion_r4264992214 . Clearing the hook now would test the stock dependency without the decimal fix. The PR description records the merge gate: land the upstream fix, qualify a normal dependency containing it, then restore the empty hook before merging. Keeping this thread open to track that required dependency step. ########## gluten-ut/common/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala: ########## @@ -0,0 +1,137 @@ +/* + * 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.Round +import org.apache.spark.sql.catalyst.optimizer.NullPropagation +import org.apache.spark.sql.internal.SQLConf +import org.apache.spark.sql.types._ + +import scala.collection.JavaConverters._ + +class GlutenDecimalRoundSuite 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 => + 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(-400, -39, -1, 0, 1, 38, 400).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")) + }) Review Comment: Keeping the narrow assertion intentionally. The upstream implementation under test explicitly reports `Decimal overflow in ...`: https://github.com/facebookincubator/velox/blob/d36b87cc2688500d8b646cc30bc998a13aca8947/velox/functions/sparksql/specialforms/DecimalRound.cpp#L171-L177 . Its structured status is a generic user error, which would also admit unrelated conversion or metadata failures. The Spark-side allowlist covers two diagnostic identifiers actually observed across supported releases; there is no corresponding native diagnostic variation in this dependency. A future native diagnostic-contract change should update this focused assertion deliberately rather than silently accepting unrelated failures. ########## gluten-ut/common/src/test/scala/org/apache/spark/sql/GlutenDecimalRoundSuite.scala: ########## @@ -0,0 +1,137 @@ +/* + * 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.Round +import org.apache.spark.sql.catalyst.optimizer.NullPropagation +import org.apache.spark.sql.internal.SQLConf +import org.apache.spark.sql.types._ + +import scala.collection.JavaConverters._ Review Comment: This shared suite is also compiled on Scala 2.12 for Spark 3.4/3.5. `JavaConverters` works on both Scala 2.12 and 2.13 and matches the existing common-test convention: https://github.com/apache/gluten/blob/d66fbf998a83cac065e3275ba1e3503494a3862c/gluten-ut/common/src/test/scala/org/apache/spark/sql/GlutenSQLTestsTrait.scala#L34 . Keeping that cross-version common-module convention intentionally; the deprecation is a compatibility tradeoff here. The maintained suite was compiled and run on Spark 3.4.4, 3.5.5, 4.0.2 and 4.1.1. -- 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]
