You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Chathura Widanage <ch...@gmail.com> on 2022/02/15 16:01:28 UTC

CoreRules not getting applied.

Hi devs,

When trying to optimize the below query with calcite 1.29.0, it's not
properly reducing the PLUS operation on date literal and interval literal.
I'm using CoreRules.PROJECT_REDUCE_EXPRESSIONS

select TIMESTAMPADD(DAY, 22, TIMESTAMP '1995-12-10 02:06:17') as
constant_col  from nation

LogicalProject(constant_col=[+(1995-12-10 02:06:17, *(86400000:INTERVAL
DAY, 22))])
  BindableTableScan(table=[[table-test-db, nation]], projects=[[]],
aliases=[[constant_col]])

However, the same query is getting optimized to, calcite 1.23.0.

LogicalProject(constant_col=[1996-01-01 02:06:17])
  BindableTableScan(table=[[table-test-db, nation]], projects=[[]],
aliases=[[constant_col]])

What could be the possible causes for this difference in the latest calcite
version?

Regards,
Chathura

Re: CoreRules not getting applied.

Posted by Stamatis Zampetakis <za...@gmail.com>.
Hi Chathura,

I added the following in RelOptRulesTest and the constant reduction seems
to work fine on master:

  @Test void testTimestampAddReduce() {
    String sql = "select TIMESTAMPADD(DAY, 22, TIMESTAMP '1995-12-10
02:06:17') as\n"
        + "constant_col  from emp";
    sql(sql).withRule(CoreRules.PROJECT_REDUCE_EXPRESSIONS).check();
  }

It is either some confirmation that you're missing on your side or it was
fixed very recently after 1.29.0.

Best,
Stamatis

On Wed, Feb 16, 2022 at 12:33 AM Chathura Widanage <
chathurawidanage@gmail.com> wrote:

> Hi devs,
>
> When trying to optimize the below query with calcite 1.29.0, it's not
> properly reducing the PLUS operation on date literal and interval literal.
> I'm using CoreRules.PROJECT_REDUCE_EXPRESSIONS
>
> select TIMESTAMPADD(DAY, 22, TIMESTAMP '1995-12-10 02:06:17') as
> constant_col  from nation
>
> LogicalProject(constant_col=[+(1995-12-10 02:06:17, *(86400000:INTERVAL
> DAY, 22))])
>   BindableTableScan(table=[[table-test-db, nation]], projects=[[]],
> aliases=[[constant_col]])
>
> However, the same query is getting optimized to, calcite 1.23.0.
>
> LogicalProject(constant_col=[1996-01-01 02:06:17])
>   BindableTableScan(table=[[table-test-db, nation]], projects=[[]],
> aliases=[[constant_col]])
>
> What could be the possible causes for this difference in the latest calcite
> version?
>
> Regards,
> Chathura
>