Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CORE] Fix incorrect precision of decimal literal #6954

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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") { _ => }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading