[ 
https://issues.apache.org/jira/browse/CALCITE-4189?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Thomas Rebele updated CALCITE-4189:
-----------------------------------
    Description: 
Statements of the form 'P OR P IS NOT TRUE' to 'TRUE' should always be true 
(please correct me if I am wrong):
{code:java}
> select x, X='A' as EQ, 
            X='A' IS NOT TRUE as EQ_NOT_TRUE,
            (X='A') OR ((X='A') IS NOT TRUE) as EQ_OR_EQ_NOT_TRUE
from (values 'A', 'B', null) as t(x);
+---+-------+-------------+-------------------+
| X |  EQ   | EQ_NOT_TRUE | EQ_OR_EQ_NOT_TRUE |
+---+-------+-------------+-------------------+
| A | true  | false       | true              |
| B | false | true        | true              |
|   |       | true        | true              |
+---+-------+-------------+-------------------+
{code}
Here a test case for the expected behavior:
{code:java}
@Test void testSimplifyPOrPNotTrue() {
  checkSimplify(
      and(
          vBool(),
          or(
              eq(vInt(), literal(1)),
              isNotTrue(eq(vInt(), literal(1)))
          )),
      "?0.bool0");
}{code}

There are some other, similar expressions, such as 'P IS NOT FALSE OR NOT P', 
which can be reduced to true. Maybe there's a way to handle all of them?

  was:
Statements of the form 'P OR IS NOT TRUE P' to 'TRUE' should always be true 
(please correct me if I am wrong):
{code:java}
> select x, X='A' as EQ, 
            X='A' IS NOT TRUE as EQ_NOT_TRUE,
            (X='A') OR ((X='A') IS NOT TRUE) as EQ_OR_EQ_NOT_TRUE
from (values 'A', 'B', null) as t(x);
+---+-------+-------------+-------------------+
| X |  EQ   | EQ_NOT_TRUE | EQ_OR_EQ_NOT_TRUE |
+---+-------+-------------+-------------------+
| A | true  | false       | true              |
| B | false | true        | true              |
|   |       | true        | true              |
+---+-------+-------------+-------------------+
{code}
Here a test case for the expected behavior:
{code:java}
@Test void testSimplifyPOrPNotTrue() {
  checkSimplify(
      and(
          vBool(),
          or(
              eq(vInt(), literal(1)),
              isNotTrue(eq(vInt(), literal(1)))
          )),
      "?0.bool0");
}{code}

There are some other, similar expressions, such as 'P IS NOT FALSE OR NOT P', 
which can be reduced to true. Maybe there's a way to handle all of them?


> Simplify 'P OR P IS NOT TRUE' to 'TRUE'
> ---------------------------------------
>
>                 Key: CALCITE-4189
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4189
>             Project: Calcite
>          Issue Type: Improvement
>            Reporter: Thomas Rebele
>            Priority: Minor
>
> Statements of the form 'P OR P IS NOT TRUE' to 'TRUE' should always be true 
> (please correct me if I am wrong):
> {code:java}
> > select x, X='A' as EQ, 
>             X='A' IS NOT TRUE as EQ_NOT_TRUE,
>             (X='A') OR ((X='A') IS NOT TRUE) as EQ_OR_EQ_NOT_TRUE
> from (values 'A', 'B', null) as t(x);
> +---+-------+-------------+-------------------+
> | X |  EQ   | EQ_NOT_TRUE | EQ_OR_EQ_NOT_TRUE |
> +---+-------+-------------+-------------------+
> | A | true  | false       | true              |
> | B | false | true        | true              |
> |   |       | true        | true              |
> +---+-------+-------------+-------------------+
> {code}
> Here a test case for the expected behavior:
> {code:java}
> @Test void testSimplifyPOrPNotTrue() {
>   checkSimplify(
>       and(
>           vBool(),
>           or(
>               eq(vInt(), literal(1)),
>               isNotTrue(eq(vInt(), literal(1)))
>           )),
>       "?0.bool0");
> }{code}
> There are some other, similar expressions, such as 'P IS NOT FALSE OR NOT P', 
> which can be reduced to true. Maybe there's a way to handle all of them?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to