[
https://issues.apache.org/jira/browse/CALCITE-2348?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16501251#comment-16501251
]
godfrey he commented on CALCITE-2348:
-------------------------------------
Sorry I did not express clearly.
Yes, I totally agree with you. There are two examples that I am thinking of now
for different scenarios:
1. case that the non-deterministic operator should not be pushed down:
{code:java}
// rand_substr is a non-deterministic udf
select ename, deptno from
(select rand_substr(ename, 1, 3) as ename, deptno from emp) t
where deptno > 10 and ename <> 'Tom';
before FilterProjectTransposeRule applied:
LogicalProject(ENAME=[$0], DEPTNO=[$1])
LogicalFilter(condition=[AND(>($1, 10), <>($0, 'Tom'))])
LogicalProject(ENAME=[RAND_SUBSTR($1, 1, 3)], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
after FilterProjectTransposeRule applied:
LogicalProject(ENAME=[$0], DEPTNO=[$1])
LogicalProject(ENAME=[RAND_SUBSTR($1, 1, 3)], DEPTNO=[$7])
LogicalFilter(condition=[AND(>($7, 10), <>(RAND_SUBSTR($1, 1, 3), 'Tom'))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
{code}
The values of 'ename' should not contain 'Tom'. However after
FilterProjectTransposeRule applied, 'Tom' may be in the result.
2. case that the non-deterministic operator can be pushed down:
{code:java}
// rand_substr is a non-deterministic udf
select ename, deptno from
(select ename, deptno from emp) t
where deptno > 10 and rand_substr(ename, 1, 3) <> 'Tom';
before FilterProjectTransposeRule applied:
LogicalProject(ENAME=[$0], DEPTNO=[$1])
LogicalFilter(condition=[AND(>($1, 10), <>($0, 'Tom'))])
LogicalProject(ENAME=[RAND_SUBSTR($1, 1, 3)], DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
after FilterProjectTransposeRule applied:
LogicalProject(ENAME=[$0], DEPTNO=[$1])
LogicalProject(ENAME=[$1], DEPTNO=[$7])
LogicalFilter(condition=[AND(<>(RAND_SUBSTR($1, 1, 3), 'Tom'), >($7, 10))])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
{code}
> handling non-deterministic operator in rules
> --------------------------------------------
>
> Key: CALCITE-2348
> URL: https://issues.apache.org/jira/browse/CALCITE-2348
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.17.0
> Reporter: godfrey he
> Assignee: Julian Hyde
> Priority: Major
>
> Currently, rules do not handle non-deterministic operator,
> e.g. FilterAggregateTransposeRule can't push down a non-deterministic filter
> through an aggregate.
> {code:java}
> // rand_substr is a non-deterministic udf
> @Test public void testPushFilterPastAggWithNondeterministicFilter() {
> final String sql = "select ename, empno, c from\n"
> + " (select ename, empno, count(*) as c from emp group by ename, empno)
> t\n"
> + " where rand_substr(ename, 1, 3) = 'Tom' and empno = 10";
> checkPlanning(FilterAggregateTransposeRule.INSTANCE, sql);
> }{code}
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)