Github user wojtek-szymanski commented on a diff in the pull request:
https://github.com/apache/spark/pull/17075#discussion_r103864255
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/types/Decimal.scala ---
@@ -362,17 +374,13 @@ final class Decimal extends Ordered[Decimal] with
Serializable {
def abs: Decimal = if (this.compare(Decimal.ZERO) < 0) this.unary_- else
this
def floor: Decimal = if (scale == 0) this else {
- val value = this.clone()
- value.changePrecision(
- DecimalType.bounded(precision - scale + 1, 0).precision, 0,
ROUND_FLOOR)
- value
+ toPrecision(DecimalType.bounded(precision - scale + 1, 0).precision,
0, ROUND_FLOOR)
--- End diff --
Theoretically, it should be `Some`. On the other hand if something goes
wrong when setting new precision in `floor` or `ceil`, I would raise an
internal error:
def floor: Decimal = if (scale == 0) this else {
val newPrecision = DecimalType.bounded(precision - scale + 1,
0).precision
toPrecision(newPrecision, 0, ROUND_FLOOR).getOrElse(
throw new AnalysisException(s"Overflow when setting precision to
$newPrecision"))
}
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]