This is an automated email from the ASF dual-hosted git repository.
rui pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git
The following commit(s) were added to refs/heads/main by this push:
new 7e800f6c3 [CORE] Fix incorrect precision of decimal literal (#6954)
7e800f6c3 is described below
commit 7e800f6c3b2cfa8981f63d1bdff643f450e07c00
Author: jiangjiangtian <[email protected]>
AuthorDate: Wed Aug 28 12:50:49 2024 +0800
[CORE] Fix incorrect precision of decimal literal (#6954)
---
.../scala/org/apache/gluten/execution/MiscOperatorSuite.scala | 8 ++++++++
.../scala/org/apache/gluten/utils/DecimalArithmeticUtil.scala | 2 +-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git
a/backends-velox/src/test/scala/org/apache/gluten/execution/MiscOperatorSuite.scala
b/backends-velox/src/test/scala/org/apache/gluten/execution/MiscOperatorSuite.scala
index fa7eae37b..296e98ca9 100644
---
a/backends-velox/src/test/scala/org/apache/gluten/execution/MiscOperatorSuite.scala
+++
b/backends-velox/src/test/scala/org/apache/gluten/execution/MiscOperatorSuite.scala
@@ -2086,4 +2086,12 @@ class MiscOperatorSuite extends
VeloxWholeStageTransformerSuite with AdaptiveSpa
val df2 = runQueryAndCompare("SELECT round(cast(0.19324999999999998 as
double), 2)") { _ => }
checkLengthAndPlan(df2, 1)
}
+
+ test("Fix wrong rescale") {
+ withTable("t") {
+ sql("create table t (col0 decimal(10, 0), col1 decimal(10, 0)) using
parquet")
+ sql("insert into t values (0, 0)")
+ runQueryAndCompare("select col0 / (col1 + 1E-8) from t") { _ => }
+ }
+ }
}
diff --git
a/gluten-core/src/main/scala/org/apache/gluten/utils/DecimalArithmeticUtil.scala
b/gluten-core/src/main/scala/org/apache/gluten/utils/DecimalArithmeticUtil.scala
index d3a3373aa..6fe52aa56 100644
---
a/gluten-core/src/main/scala/org/apache/gluten/utils/DecimalArithmeticUtil.scala
+++
b/gluten-core/src/main/scala/org/apache/gluten/utils/DecimalArithmeticUtil.scala
@@ -99,7 +99,7 @@ object DecimalArithmeticUtil {
// For decimal * 10 case, dec will be Decimal(38, 18), then the result
precision is wrong,
// so here we will get the real precision and scale of the literal.
private def getNewPrecisionScale(dec: Decimal): (Integer, Integer) = {
- val input = dec.abs.toString()
+ val input = dec.abs.toJavaBigDecimal.toPlainString()
val dotIndex = input.indexOf(".")
if (dotIndex == -1) {
return (input.length, 0)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]