devanshu0987 commented on PR #20059:
URL: https://github.com/apache/datafusion/pull/20059#issuecomment-3821298661
Hi @comphead and @masonh22
- Preimage result is a `Interval::try_new(lower, upper)`
- Inside `Interval::try_new`, it does a data type assert
```
assert_eq_or_internal_err!(
lower.data_type(),
upper.data_type(),
"Endpoints of an Interval should have the same type"
);
```
- Data type asserts for Decimal types also include checking precision and
scale.
```
ScalarValue::Decimal32(_, precision, scale) => {
DataType::Decimal32(*precision, *scale)
}
```
- When we add 2 Decimals, the precision changes `result_precision = max(s1,
s2) + max(p1-s1, p2-s2) + 1`
- Which makes sense to handle the overflow case: 99 + 1 = 100
- Hence, when we add 1 to find the upper bound, the resulting data type is 1
more than the lower bound, and the Interval::try_new fails.
```
SELECT arrow_typeof(CAST(100.00 AS DECIMAL(5,2)) + CAST(1.00 AS
DECIMAL(5,2)));
+-----------------------------------------+
| arrow_typeof(Float64(100) + Float64(1)) |
+-----------------------------------------+
| Decimal128(6, 2) |
+-----------------------------------------+
```
- I am hesitant about the idea of writing my own manual calculation to keep
the precision the same post addition.
- Scale < 0, Scale > 0 etc.
- Can you advise on what I should do?
--
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]