You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (JIRA)" <ji...@apache.org> on 2015/07/07 02:45:04 UTC

[jira] [Commented] (CALCITE-783) Project's collation infering logic doesn't handle monotonic expressions

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

Julian Hyde commented on CALCITE-783:
-------------------------------------

Yes, this is a problem. The "TODO: also monotonic expressions" comment in the method you patched acknowledges this.

However I wouldn't put the logic into RelMdCollation as you have done. It needs to be possible to extend the logic when new functions (possibly user-defined) are added. We have a good start in the SqlOperator method 

{code}
  public SqlMonotonicity getMonotonicity(
      SqlCall call,
      SqlValidatorScope scope) {
    return SqlMonotonicity.NOT_MONOTONIC;
  }
{code}

which is used by the validator and has overrides for functions including EXTRACT, CAST, FLOOR, SUBSTRING, +, all of which can be monotonic in some circumstances. SqlValidatorTest.testMonotonic has quite a long list of test cases. However that method only works on a SqlCall (i.e. a parse tree) whereas we need to apply the same logic to a RexNode. 

So I think the solution is to change the first parameter of that method from SqlCall to SqlOperatorBinding. SqlCallBinding is an interface which has an implementation that wraps a SqlCall, and another implementation that wraps a RexCall.

I have made a start on this in my branch https://github.com/julianhyde/incubator-calcite/tree/783-monotonicity. [~milinda], could you finish RelMdCollation.project?

> Project's collation infering logic doesn't handle monotonic expressions
> -----------------------------------------------------------------------
>
>                 Key: CALCITE-783
>                 URL: https://issues.apache.org/jira/browse/CALCITE-783
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Milinda Lakmal Pathirage
>            Assignee: Julian Hyde
>         Attachments: CALCITE-783-0.patch
>
>
> Current implementation of RelMdCollation#project doesn't handle function expressions and because of that we loose any collation metadata related to monotonic expressions which can be useful generating streaming query execution plans involving tumbling windows.
> Following is how current code looks like (RelMdCollation):
> 185: for (Ord<RexNode> project : Ord.zip(projects)) {
> 186:       if (project.e instanceof RexInputRef) {
> 187:         targets.put(((RexInputRef) project.e).getIndex(), project.i);
> 188:       } 
> 189: }
> We only handle projects of type RexInputRef. But to support monotonic expressions we should laso handle projects of type RexCall.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)