You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Li Xian (Jira)" <ji...@apache.org> on 2019/12/20 08:01:00 UTC

[jira] [Updated] (CALCITE-3618) WindowedAggRelSplitter.isDependent is incorrect

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

Li Xian updated CALCITE-3618:
-----------------------------
    Description: 
WindowedAggRelSplitter isDependent is incorrect 

```
      while (!dfs.isEmpty()) {
        int source = dfs.pop();
        if (visited.contains(source)) {
          continue;
        }

        if (source == ordinal1) {
          return true;
        }

        visited.add(source);
        for (DefaultEdge e : graph.getOutwardEdges(source)) {
          int target = (int) e.target;
          if (rank.get(target) < rank.get(ordinal1)) {
            dfs.push(target);
          }
        }
      }
```
It only pushes target into dfs queue if target rank is smaller than ordinal1's rank, which makes it impossible to find the dependency.

For SQL like
```sql
select 
 lag(a2, 1, 0) over (partition by "deptno" order by a1) as lagx 
from 
 (
  select 
   "deptno", 
   "salary" / "commission" as a1, 
   sum("commission") over ( partition by "deptno" order by "salary" / "commission") / sum("commission") over (partition by "deptno") as a2 
  from 
   "hr"."emps"
 )
```
It generates levels of exprs like the attached picture below which is incorrect. And will cause error `Error while applying rule ProjectToWindowRule:project` 


  was:
WindowedAggRelSplitter isDependent is incorrect 
```
      while (!dfs.isEmpty()) {
        int source = dfs.pop();
        if (visited.contains(source)) {
          continue;
        }

        if (source == ordinal1) {
          return true;
        }

        visited.add(source);
        for (DefaultEdge e : graph.getOutwardEdges(source)) {
          int target = (int) e.target;
          if (rank.get(target) < rank.get(ordinal1)) {
            dfs.push(target);
          }
        }
      }
```
It only pushes target into dfs queue if target rank is smaller than ordinal1's rank, which makes it impossible to find the dependency.

For SQL like
```sql
select 
 lag(a2, 1, 0) over (partition by "deptno" order by a1) as lagx 
from 
 (
  select 
   "deptno", 
   "salary" / "commission" as a1, 
   sum("commission") over ( partition by "deptno" order by "salary" / "commission") / sum("commission") over (partition by "deptno") as a2 
  from 
   "hr"."emps"
 )
```
It generates levels of exprs like the attached picture below which is incorrect. And will cause error `Error while applying rule ProjectToWindowRule:project` 



> WindowedAggRelSplitter.isDependent is incorrect
> -----------------------------------------------
>
>                 Key: CALCITE-3618
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3618
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.21.0
>            Reporter: Li Xian
>            Priority: Major
>         Attachments: Screen Shot 2019-12-20 at 3.49.09 PM.png
>
>
> WindowedAggRelSplitter isDependent is incorrect 
> ```
>       while (!dfs.isEmpty()) {
>         int source = dfs.pop();
>         if (visited.contains(source)) {
>           continue;
>         }
>         if (source == ordinal1) {
>           return true;
>         }
>         visited.add(source);
>         for (DefaultEdge e : graph.getOutwardEdges(source)) {
>           int target = (int) e.target;
>           if (rank.get(target) < rank.get(ordinal1)) {
>             dfs.push(target);
>           }
>         }
>       }
> ```
> It only pushes target into dfs queue if target rank is smaller than ordinal1's rank, which makes it impossible to find the dependency.
> For SQL like
> ```sql
> select 
>  lag(a2, 1, 0) over (partition by "deptno" order by a1) as lagx 
> from 
>  (
>   select 
>    "deptno", 
>    "salary" / "commission" as a1, 
>    sum("commission") over ( partition by "deptno" order by "salary" / "commission") / sum("commission") over (partition by "deptno") as a2 
>   from 
>    "hr"."emps"
>  )
> ```
> It generates levels of exprs like the attached picture below which is incorrect. And will cause error `Error while applying rule ProjectToWindowRule:project` 



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