-
Notifications
You must be signed in to change notification settings - Fork 242
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
Add support for DecimalType in Remainder for Spark 3.4 and DB 11.3 [databricks] #8302
Add support for DecimalType in Remainder for Spark 3.4 and DB 11.3 [databricks] #8302
Conversation
…3.4 and Databricks 11.3 Signed-off-by: Navin Kumar <[email protected]>
…cimal-remainder-340
Signed-off-by: Navin Kumar <[email protected]>
build |
...gin/src/main/spark330db/scala/com/nvidia/spark/rapids/shims/DecimalArithmeticOverrides.scala
Show resolved
Hide resolved
...gin/src/main/spark330db/scala/com/nvidia/spark/rapids/shims/DecimalArithmeticOverrides.scala
Outdated
Show resolved
Hide resolved
...gin/src/main/spark330db/scala/com/nvidia/spark/rapids/shims/DecimalArithmeticOverrides.scala
Show resolved
Hide resolved
sql-plugin/src/main/spark330db/scala/org/apache/spark/sql/rapids/arithmetic.scala
Outdated
Show resolved
Hide resolved
sql-plugin/src/main/spark330db/scala/org/apache/spark/sql/rapids/arithmetic.scala
Show resolved
Hide resolved
Signed-off-by: Navin Kumar <[email protected]>
…der normal circumstances would cause an overflow. Spark 3.4 handles this differently and produces a correct value Signed-off-by: Navin Kumar <[email protected]>
build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to ignore the nit if it means we can be faster at getting the full fix in by 23.06.
("lhs", TypeSig.integral + TypeSig.fp, TypeSig.cpuNumeric), | ||
("rhs", TypeSig.integral + TypeSig.fp, TypeSig.cpuNumeric)), | ||
("lhs", TypeSig.gpuNumeric, TypeSig.cpuNumeric), | ||
("rhs", TypeSig.gpuNumeric, TypeSig.cpuNumeric)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it would be nice to add in a psNote for DECIMAL128 here to explain what we don't fully support. This is really minor if we think we can get full remainder support in before we ship 23.06. (especially minor because we don't generate the support docs for anything but the oldest version of Spark that we support) Oh well....
Looks like you have some lines over 100 chars that need to be fixed. |
Signed-off-by: Navin Kumar <[email protected]>
build |
build |
Follow up for Decimal128 support is here: #8330 |
if (a.left.dataType.isInstanceOf[DecimalType] && | ||
a.right.dataType.isInstanceOf[DecimalType]) { | ||
val lhsType = a.left.dataType.asInstanceOf[DecimalType] | ||
val rhsType = a.right.dataType.asInstanceOf[DecimalType] | ||
val needed = DecimalRemainderChecks.neededPrecision(lhsType, rhsType) | ||
if (needed > DType.DECIMAL128_MAX_PRECISION) { | ||
willNotWorkOnGpu(s"needed intermediate precision ($needed) will overflow " + | ||
s"outside of the maximum available decimal128 precision") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (a.left.dataType.isInstanceOf[DecimalType] && | |
a.right.dataType.isInstanceOf[DecimalType]) { | |
val lhsType = a.left.dataType.asInstanceOf[DecimalType] | |
val rhsType = a.right.dataType.asInstanceOf[DecimalType] | |
val needed = DecimalRemainderChecks.neededPrecision(lhsType, rhsType) | |
if (needed > DType.DECIMAL128_MAX_PRECISION) { | |
willNotWorkOnGpu(s"needed intermediate precision ($needed) will overflow " + | |
s"outside of the maximum available decimal128 precision") | |
} | |
} | |
(a.left.dataType, a.right.dataType) match { | |
case (lhsType: DecimalType, rhsType: DecimalType) => | |
val needed = DecimalRemainderChecks.neededPrecision(lhsType, rhsType) | |
if (needed > DType.DECIMAL128_MAX_PRECISION) { | |
willNotWorkOnGpu(s"needed intermediate precision ($needed) will overflow " + | |
s"outside of the maximum available decimal128 precision") | |
} | |
case _ => () | |
} |
Fixes #8161.
This reverts the changes to integration tests made in #7609, and adds support for Remainder with DecimalType in Spark 3.4 and Databricks 11.3.
This does this by casting the operands using the following formula:
This enables just enough precision and scale to compute the remainder. This gives enough scale to produce the part of the output that is < 1, and enough precision to contain the values of both operands.
The output type is actually this formula:
Which is only just enough precision and scale to store the remainder.