cudf icon indicating copy to clipboard operation
cudf copied to clipboard

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

Open mythrocks opened this issue 3 years ago • 1 comments

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:

    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():

      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.

mythrocks avatar Sep 13 '22 18:09 mythrocks

Closing this as invalid; both hashCode() and equals() are correct.

  1. Scalar.hashCode() returns Objects.hashCode(type, valueHash). type includes the scale.
  2. Scalar.equals() compares type first, before proceeding to compare values. type, again, includes the scale.

Apologies for the noise. This bug is invalid.

mythrocks avatar Sep 14 '22 23:09 mythrocks

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

github-actions[bot] avatar Oct 15 '22 00:10 github-actions[bot]

This would sill be good to fix

revans2 avatar Oct 20 '22 14:10 revans2