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 2018/02/26 20:21:00 UTC

[jira] [Resolved] (CALCITE-2081) Query with windowed aggregates under both sides of a JOIN throws NullPointerException

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

Julian Hyde resolved CALCITE-2081.
----------------------------------
       Resolution: Fixed
    Fix Version/s: 1.16.0

Fixed in [a1fe7691|http://git-wip-us.apache.org/repos/asf/calcite/commit/a1fe7691]; thanks for the PR, [~zhenw]!

> Query with windowed aggregates under both sides of a JOIN throws NullPointerException
> -------------------------------------------------------------------------------------
>
>                 Key: CALCITE-2081
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2081
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Luis Fernando Kauer
>            Assignee: Julian Hyde
>            Priority: Major
>             Fix For: 1.16.0
>
>
> NPE when joining 2 subqueries that use window functions.
> Testing with a new test case in JdbcTest:
> {code}
>   /** Tests for a join of subqueries using Window Functions */
>   @Test public void testJoinWithWinAgg() {
>     final String sql = "select a.*, b.r from\n"
>         + "(select \"deptno\", first_value(\"empid\") over \n"
>         + "(partition by \"deptno\" order by \"commission\") as r\n"
>         + "from \"hr\".\"emps\") a\n"
>         + "left join\n"
>         + "(select \"deptno\", last_value(\"empid\") over \n"
>         + "(partition by \"deptno\" order by \"commission\") as r\n"
>         + "from \"hr\".\"emps\") b\n"
>         + "on a.\"deptno\" = b.\"deptno\"";
>         CalciteAssert.hr()
>         .query(sql)
>         .runs();
>   }
> {code}
> Debugging this I found out that the NPE occurs at Expressions.declare (line 2937) in initializer.getType() because initializer is null.  The statement is
> {code}
> int prevStart;
> {code}
> This statement does not have an initializer, but the method "declare" is trying to get the initializer's type, generating NPE.
> This happens when joining 2 subqueries that use window functions because they end up using the same variables.  In BlockBuilder.append (line 124) it checks if the variable already exists and the problem starts there.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)