Repository navigation
Description
Found during the review of PR #7750 (the #7628 comparator work), deliberately left out of it because it is a different question with a different answer, and because it fails loudly rather than silently.
The defect
BinaryComparator.compare answers a BOOLEAN-versus-timestamp comparison correctly in one direction and throws NullPointerException in the other, for all five temporal types:
final BinaryComparator comparator = new BinaryComparator();
// BOOLEAN first: fine. The BOOLEAN branch delegates to compareNarrowIntegral, which treats true as 1.
comparator.compare(true, BinaryTypes.TYPE_BOOLEAN, 5L, BinaryTypes.TYPE_DATETIME); // -1
// Timestamp first: NullPointerException
comparator.compare(5L, BinaryTypes.TYPE_DATETIME, true, BinaryTypes.TYPE_BOOLEAN); // throwsReproduced against TYPE_DATE, TYPE_DATETIME, TYPE_DATETIME_SECOND, TYPE_DATETIME_MICROS and TYPE_DATETIME_NANOS.
Why
The DATE/DATETIME* arm of compare converts both operands with DateUtils.dateTimeToTimestampInferringStringPrecision, which has no Boolean case and returns null; unboxing that Long into the long local NPEs. The opposite direction never reaches it, because the TYPE_BOOLEAN arm of compare maps the boolean to 1/0 and hands it to compareNarrowIntegral.
So the two directions disagree about whether the comparison is meaningful at all - one of them answers, the other crashes.
Why it is not simply a missing case
Deciding what boolean versus timestamp should MEAN is the actual question, and it is not obvious:
- the forward direction has already picked an answer (
trueis 1, so it sits one millisecond/second/nanosecond after the epoch), which is defensible only in the sense that every other numeric-versus-temporal comparison in this class is equally raw; - refusing the comparison outright - an
IllegalArgumentExceptionnaming both types, as the bottom ofcomparealready does for unsupported pairs - is the other coherent answer, and arguably the better one, but it would change the forward direction's current behaviour and so is not a pure bug fix; - whichever is chosen, both directions have to agree, since a comparator that is not antisymmetric breaks index range cursors (this is the failure mode of BinaryComparator narrows the wider operand and parseInt()s string operands: NumberFormatException on numeric-vs-string (via SQL) and a non-antisymmetric order #5900, BinaryComparator.compare(): TYPE_STRING vs DATE/DATETIME still falls through to lexicographic comparison #5947 and BinaryComparator orders two STRINGs by UTF-16 code units while LSM pages order them by UTF-8 bytes, so an indexed range scan can return zero rows #6997).
Suggested fix
Pick one of the two answers deliberately, then make both directions implement it:
- if the comparison stays meaningful, give the
DATE/DATETIME*arm aBOOLEANcase mapping to 1/0, mirroring theTYPE_BOOLEANarm; - if it does not, refuse it from both arms with the
IllegalArgumentExceptionthe unsupported-pair fall-through already raises, and dropTYPE_BOOLEANfromcompareNarrowIntegral/compareWideningLong's accepted set.
Either way the regression test should assert both directions for all five temporal types, the way Issue7628ExactIntegralComparisonTest does for the numeric ones.
Scope
Pre-existing: it predates PR #7750 and affects the untouched DATE/DATETIME arms identically, so it is not a regression from that work.
Activity
docs: file the BOOLEAN-vs-timestamp gap as #7754, and drop the self-r…
fix(#7754): refuse BOOLEAN vs temporal in the untyped compareTo too, …
fix(#7754,#7937): native Select operators read an unordered pair as n…
fix(#7754,#7760): native orderBy falls back to string order on an uno…
fix(#7754): keep the loud refusal for native orderBy on an unordered …
Merge pull request #8742 from ArcadeData/fix/issues-7754-7760-7937
lvca commentedon Sep 30, 2026
Fixed in #8742 (26.10.1). Comparing a BOOLEAN with a date or timestamp now fails the same way in both directions, with a clear "Comparison between type ... not supported" error instead of a
NullPointerExceptionin one direction. SQL<,>,<=,>=andBETWEEN, and the nativeselect()API, treat such a pair as "no match". A nativeorderByon a column mixing booleans and timestamps now raises the error instead of sorting arbitrarily.❤️ 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.
fix(ArcadeData#7754,ArcadeData#7760,ArcadeData#7937): refuse BOOLEAN …
fix(#7754,#7760,#7937): refuse BOOLEAN vs timestamp in both direction…
fix(#7754): refuse BOOLEAN vs temporal in the untyped compareTo too, …
fix(#7754,#7937): native Select operators read an unordered pair as n…
fix(#7754,#7760): native orderBy falls back to string order on an uno…
fix(#7754): keep the loud refusal for native orderBy on an unordered …