You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BinaryComparator.compare(): TYPE_STRING vs DATE/DATETIME still falls through to lexicographic comparison #5947
BinaryComparator.compare()'s TYPE_STRING branch (fixed for numeric/boolean type2 by PR #5922, closing #5900) still falls through to an unconditional lexicographic ((String) value1).compareTo(value2.toString()) when type2 is TYPE_DATE, TYPE_DATETIME, TYPE_DATETIME_SECOND, TYPE_DATETIME_MICROS, or TYPE_DATETIME_NANOS:
This is pre-existing behavior, not a regression from #5922 - the old code did the same unconditional lexicographic comparison for every type2, including dates. It's called out here because #5922 explicitly closed the equivalent gap for every other type2 category (numeric, boolean), so this is the one category left with the old, potentially-inconsistent behavior.
Scope note
Unlike the numeric/boolean fix (a mechanical "delegate to the numeric widening comparator and negate"), fixing this properly requires actual date-string parsing with all the format/timezone ambiguity that implies, so it's a meaningfully different and larger piece of work - not a good fit to fold into #5922's mechanical fix. Filed separately per the review discussion on that PR.
Suggested approach
Decide what a TYPE_STRING vs TYPE_DATE/TYPE_DATETIME comparison should mean (likely: attempt to parse value1 as a date using the same parsing DateConstructorFunction/DateTimeConstructorFunction use, then delegate to the existing TYPE_DATE/TYPE_DATETIME branch's DateUtils.dateTimeToTimestamp comparison; fall back to lexicographic - or a defined error - if the string doesn't parse as a date). Whatever is chosen should be antisymmetric with compare(dateValue, TYPE_DATETIME, dateString, TYPE_STRING), matching the contract #5900/#5922 established for every other branch in this class.
Context
Raised during code review on PR #5922 (fixing #5900). See that PR and BinaryComparatorNarrowingTest for the established test patterns (direct sgn(compare(a,b)) == -sgn(compare(b,a)) assertions) this fix should follow.
Activity
fix(#5947): BinaryComparator STRING-vs-DATE/DATETIME delegates instea…
fix(#7628): order the sub-millisecond timestamp types instead of answ…