[BUG] Java `Scalar` does not consider Decimal scale for `.hashCode()`/`.equals()`
- Dominant language
- C++
- Stars
- 9.8k
- Forks
- 1.1k
- Avg merge
- 3d 6m
- Merged PRs (30d)
- 278
Description
In its current implementation, the `Scalar` Java class does not consider the `scale` of a scalar value, when comparing two `DECIMAL` scalars.
Here is the section of `Scalar.equals()` that compares `DECIMAL64` values:
```java
case DECIMAL64:
return getLong() == other.getLong();
```
`getLong()` does not rescale the representative value of the scalar, based on a common scale. This implementation will equate two `DECIMAL64` scalars of different scales, if their `rep` values are equal.
A similar argument could be made for `Scalar.hashCode()`:
```java
case DECIMAL64:
// ...
valueHash = Long.hashCode(getLong());
break;
```
AFAICT, the problem applies to `DECIMAL32` and `DECIMAL64`, but not `DECIMAL128`. In adding support for `DECIMAL128` in #11645, the comparisons are made using `BigDecimal`, rather than `BigInteger`.
Contributor guide
Assessment
This issue has not been assessed yet.