You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Ian Bertolacci (Jira)" <ji...@apache.org> on 2023/05/24 21:31:00 UTC

[jira] [Comment Edited] (CALCITE-5722) Sarg.isComplementedPoints fails with anti-points which are equal under `compareTo` but not `equals`

    [ https://issues.apache.org/jira/browse/CALCITE-5722?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17725957#comment-17725957 ] 

Ian Bertolacci edited comment on CALCITE-5722 at 5/24/23 9:30 PM:
------------------------------------------------------------------

Pertinent line from the [`Comparable` documents|https://docs.oracle.com/javase/8/docs/api/java/lang/Comparable.html#:~:text=Virtually%20all%20Java%20core%20classes%20that%20implement%20Comparable%20have%20natural%20orderings%20that%20are%20consistent%20with%20equals.%20One%20exception%20is%20java.math.BigDecimal%2C%20whose%20natural%20ordering%20equates%20BigDecimal%20objects%20with%20equal%20values%20and%20different%20precisions%20(such%20as%204.0%20and%204.00).]:
{quote}Virtually all Java core classes that implement {{Comparable}} have natural orderings that are consistent with equals. One exception is {*}{{java.math.BigDecimal}}{*}, whose natural ordering equates {{BigDecimal}} objects with equal values and different precisions (such as 4.0 and 4.00).
{quote}


was (Author: ian.bertolacci):
Pertinent line from the `Comparable` documents:
{quote}Virtually all Java core classes that implement {{Comparable}} have natural orderings that are consistent with equals. One exception is {*}{{java.math.BigDecimal}}{*}, whose natural ordering equates {{BigDecimal}} objects with equal values and different precisions (such as 4.0 and 4.00).
{quote}

> Sarg.isComplementedPoints fails with anti-points which are equal under `compareTo` but not `equals`
> ---------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-5722
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5722
>             Project: Calcite
>          Issue Type: Bug
>    Affects Versions: 1.34.0
>            Reporter: Ian Bertolacci
>            Priority: Minor
>
> Example:
> {code:java}
> final Sarg<BigDecimal> badComplimentPointsSarg =
>   Sarg.of(
>     RexUnknownAs.UNKNOWN,
>     TreeRangeSet.create(
>       Arrays.asList(
>         // Create anti-point around 1, with different scales
>         Range.lessThan(new BigDecimal("1")),
>         Range.greaterThan(new BigDecimal("1.00000000000"))
>       )
>     )
>   );
> assertThat(badComplimentPointsSarg.isComplementedPoints(), is(true));
> {code}
> will fail.
> This is because [RangeSets.isPoints uses direct equality and not `Comparable.compareTo` equality|https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/util/RangeSets.java#LL132C1-L133C1]
> The values {{`1`}} and {{`1.00000000000`}} are not equal under `BigDecimal.equals` but are equal under `BigDecimal.compareTo`.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)