rapidsai / cudf

cuDF - GPU DataFrame Library
https://docs.rapids.ai/api/cudf/stable/
Apache License 2.0
8.08k stars 875 forks source link

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

Open mythrocks opened 1 year ago

mythrocks commented 1 year ago

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 commented 1 year ago

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.

github-actions[bot] commented 1 year ago

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.

revans2 commented 1 year ago

This would sill be good to fix