Skip to content

A DECIMAL property does not equal a numerically-equal literal of a different scale: = 5.0 misses a stored 5 #7613

Closed

Description

@lvca

Split out of #7609 / PR #7612, where it was found but deliberately left out of scope.

The defect

Type.castComparableNumber() brings a BigDecimal and any other number to a common type, and QueryOperatorEquals then decides equality with couple[0].equals(couple[1]). BigDecimal.equals() is scale-sensitive: new BigDecimal("5").equals(new BigDecimal("5.0")) is false, even though compareTo answers 0.

So a DECIMAL property holding 5 does not equal the literal 5.0, and one holding 0.050 does not equal 0.05. The ordering operators (<, <=, >, >=) route through compareTo and are therefore correct on exactly the same pair of values, so >= and <= together answer rows that = does not.

Reproduction

Sweeping all 49 ordered pairs of the seven numeric types through castComparableNumber and checking compareTo(...) == 0 against .equals(...), four pairs disagree - every one of them a pair that ends as two BigDecimals of different scale:

Float      vs BigDecimal -> compareTo 0, equals false
Double     vs BigDecimal -> compareTo 0, equals false
BigDecimal vs Float      -> compareTo 0, equals false
BigDecimal vs Double     -> compareTo 0, equals false

castComparableNumber(5.0f, new BigDecimal("5")) returns BigDecimal("5.0") and BigDecimal("5").

Why it is not in #7609

#7609 is about a literal being read at the wrong precision. This is a different mechanism - the value is right and the equality test is wrong - and it predates that fix: BigDecimal.valueOf(5.0f) produced a scale-1 decimal before too. Fixing it means changing what = answers for DECIMAL properties, which deserves its own change and its own regression test rather than riding along.

Suggested fix

Type.normalizeNumberForKey() already solves this exact hazard for GROUP BY / DISTINCT keys, and its Javadoc spells out the reasoning (BigDecimal("1").equals(BigDecimal("1.0")) is false, so one logical group would split into several). The equality path wants the same treatment: either align the scales inside castComparableNumber when both sides land on BigDecimal, or have QueryOperatorEquals use compareTo(...) == 0 rather than .equals() for a BigDecimal couple.

The second is the narrower change and makes = agree with <=/>= by construction, but the first fixes every caller of castComparableNumber at once - BinaryComparator.equals() reaches the same .equals() on the returned couple. Worth deciding which contract the method is meant to offer.

Activity

  1. self-assigned this
    on Sep 15, 2026
  2. added
    engine
    on Sep 15, 2026
  3. added this to the 26.10.1 milestone on Sep 15, 2026
  4. added
    in progress
    on Sep 15, 2026
  5. added a commit that references this issue on Sep 16, 2026
  6. lvca commented on Sep 16, 2026

    @lvca
    MemberAuthor

    Fixed: a DECIMAL property could fail to match a numerically-equal literal of a different scale (e.g. a stored 5 did not equal 5.0 in an equality check, even though >=/<= worked correctly). Decimal values are now aligned to the same scale before comparing, so equality now agrees with the other comparison operators.

    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. removed
    in progress
    on Sep 16, 2026
  8. lvca commented on Sep 16, 2026

    @lvca
    MemberAuthor

    Fixed in #7627 (merged into main).

    The bug: a DECIMAL property holding 5 did not match = 5.0 in a query, even though >= and <= correctly did. = now agrees with the ordering operators for every numeric comparison.


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugenginesql

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions