You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Michael Mior (JIRA)" <ji...@apache.org> on 2019/03/06 14:41:00 UTC

[jira] [Commented] (CALCITE-2894) NullPointerException thrown by RelMdPercentageOriginalRows when explaining plan with all attributes

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

Michael Mior commented on CALCITE-2894:
---------------------------------------

Fixed in [c3fa21b|https://github.com/apache/calcite/commit/c3fa21b805edf5be79ef4a4992d7b5213488cbaa].

> NullPointerException thrown by RelMdPercentageOriginalRows when explaining plan with all attributes
> ---------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-2894
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2894
>             Project: Calcite
>          Issue Type: Bug
>    Affects Versions: 1.18.0
>            Reporter: Ruben Quesada Lopez
>            Assignee: Ruben Quesada Lopez
>            Priority: Minor
>              Labels: pull-request-available
>         Attachments: exception.txt
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> {{RelMdPercentageOriginalRows}} methods use several times {{double}} variables to store the result of {{getPercentageOriginalRows}}. However, this method returns an object {{Double}}, as {{RelMetadataQuery#getPercentageOriginalRows}} javadoc says: "return estimated percentage (between 0.0 and 1.0), *or null if no reliable estimate can be determined*". 
> Therefore, {{null}} can (and will) be returned in some cases, leading to NullPointerException, for example here:
> {code:java}
>   public Double getPercentageOriginalRows(Union rel, RelMetadataQuery mq) {
>     double numerator = 0.0;
>     double denominator = 0.0;
>     for (RelNode input : rel.getInputs()) {
>       double rowCount = mq.getRowCount(input);
>       double percentage = mq.getPercentageOriginalRows(input);  // !!! NullPointerException
>       if (percentage != 0.0) {
>         denominator += rowCount / percentage;
>         numerator += rowCount;
>       }
>     }
>     return quotientForPercentage(numerator, denominator);
>   }
> {code}
> In my case, I arrived to this situation by explaining a plan (including all attributes) that contained a SemiJoin, with an Union inside, with a Correlate inside:
> {code:java}
>   @Test public void testExplainAllAttributesSemiJoinUnionCorrelate() {
>     CalciteAssert.that()
>             .with(CalciteConnectionProperty.LEX, Lex.JAVA)
>             .with(CalciteConnectionProperty.FORCE_DECORRELATE, false)
>             .withSchema("s", new ReflectiveSchema(new JdbcTest.HrSchema()))
>             .query(
>                     "select deptno, name from depts where deptno in (\n"
>                             + " select e.deptno from emps e where exists (select 1 from depts d where d.deptno=e.deptno)\n"
>                             + " union select e.deptno from emps e where e.salary > 10000) ")
>             .explainMatches("including all attributes ",
>                     CalciteAssert.checkResultContains("EnumerableSemiJoin"));
>   }
> {code}



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