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

fengYu commented on KYLIN-1480:
-------------------------------

this is my analysis after trace this error :
Kylin use Calcite explain sql and generate AST, then traverse all 
relNode.implementOLAP() in OLAPToEnumerableConverter, kylin will create a new 
OLAPContext in those situation:
1. top JOIN relNode
2.TableScan while father node is not JOIN
in this SQL, Kylin will create throw OLAPContext, However, in 
OLAPJoinRel.implementOLAP() function, it will check whether OLAPContext is 
created in left child and right child, if it is true, hasSubquery will be set 
to true and release the OLAPContext in the top of stack. code is :

implementor.visitChild(this.left, this);
if (this.context != implementor.getContext() || ((OLAPRel) 
this.left).hasSubQuery())
{ this.hasSubQuery = true; implementor.freeContext(); }
implementor.visitChild(this.right, this);
if (this.context != implementor.getContext() || ((OLAPRel) 
this.right).hasSubQuery()) { this.hasSubQuery = true; 
implementor.freeContext(); }

However, when traverse to Top Join node, the left and the right child has 
hasSubquery=true, which will cause OLAPContext free twice, and No nore 
OLAPContext in the stack and the father relNode(in this query, the Node is 
OLAPProjectRel ) of top JOIN will encounter NPE.

I has solve this problem simplely modify the logic of setting hasQuery=true, 
and I upload my patch, please review whether it has some more impacts. 

> NPE throws while execute sql with more than two join.
> -----------------------------------------------------
>
>                 Key: KYLIN-1480
>                 URL: https://issues.apache.org/jira/browse/KYLIN-1480
>             Project: Kylin
>          Issue Type: Bug
>          Components: Query Engine
>    Affects Versions: v2.0, v1.2, v1.1, v1.0
>            Reporter: fengYu
>            Assignee: liyang
>
> Hi, I encounter NPE while execute sql more than two join, for example : 
> select A.type, A.cmd, count(1) from fact as A inner join (select type, 
> count(1) from fact group by type having count(1) > 2) as B on A.type = B.type 
> inner join (select cmd, count(1) from fact group by cmd having count(1) > 2) 
> as C on A.cmd = C.cmd group by A.type, A.cmd;
> the fact table is create like this : 
> CREATE TABLE `fact`(
>   `fname` string, 
>   `lname` string, 
>   `dt` date, 
>   `cost` int, 
>   `type` string, 
>   `cmd` string);
> Kylin throws exception like this : 
> Caused by: java.lang.NullPointerException
>         at 
> org.apache.kylin.query.relnode.OLAPProjectRel.implementOLAP(OLAPProjectRel.java:103)
>         at 
> org.apache.kylin.query.relnode.OLAPRel$OLAPImplementor.visitChild(OLAPRel.java:81)
>         at 
> org.apache.kylin.query.relnode.OLAPAggregateRel.implementOLAP(OLAPAggregateRel.java:132)
>         at 
> org.apache.kylin.query.relnode.OLAPRel$OLAPImplementor.visitChild(OLAPRel.java:81)
>         at 
> org.apache.kylin.query.relnode.OLAPLimitRel.implementOLAP(OLAPLimitRel.java:73)
>         at 
> org.apache.kylin.query.relnode.OLAPRel$OLAPImplementor.visitChild(OLAPRel.java:81)
>         at 
> org.apache.kylin.query.relnode.OLAPToEnumerableConverter.implement(OLAPToEnumerableConverter.java:67)
>         at 
> org.apache.calcite.adapter.enumerable.EnumerableRelImplementor.implementRoot(EnumerableRelImplementor.java:99)
>         at 
> org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:92)
>         at 
> org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.implement(CalcitePrepareImpl.java:1050)
>         at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:293)
>         at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:188)
>         at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:671)
>         at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:572)
>         at 
> org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:541)
>         at 
> org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:173)
>         at 
> org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:561)
>         at 
> org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:477)
>         at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:109)
> I try it in kylin-1.0 and kylin-2.x-staging, the same exception throws.



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

Reply via email to