NVIDIA / NVIDIA/cudf

[BUG] Java `Scalar` does not consider Decimal scale for `.hashCode()`/`.equals()`

Open
#11,696 3 comments 0 reactions 0 assignees View on GitHub
bug invalid Java
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.