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

Dag H. Wanvik commented on DERBY-6688:
--------------------------------------

It seems that in FromSubquery (used in the OK subquery) the phasing is 
different than in SubqueryNode (used in the failing query): the order by list 
is pushed down too late in the SubqueryNode (after the SelectNode#preprocess), 
so that the fact that the order by carries an implicit window definition isn't 
recorded, causing the "windows" field to be null, leading to missing rewriting 
in the getProjectRestrict phase, hence the error.

In FromSubquery, the order by list is pushed down into the child select node 
just before calling its preprocess method, i.e. the order by is present what 
that happens.

> NPE (or sane: ASSERT failure) with ROW_NUMBER in some subqueries
> ----------------------------------------------------------------
>
>                 Key: DERBY-6688
>                 URL: https://issues.apache.org/jira/browse/DERBY-6688
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>            Reporter: Dag H. Wanvik
>
> This subquery usage works:
> {code}
> select * from (select x from t order by row_number() over () fetch first 1 
> row only) tt;
> {code}
> but this one leads to NPE in insane mode, or a Sanity ASSERT failure in sane 
> mode:
> {code}
> select * from t where x =  (select x from t order by row_number() over () 
> fetch first row only);
> {code}
> leading to this error:
> {code}
> Exception in thread "main" java.sql.SQLException: Java exception: ': 
> java.lang.NullPointerException'.
>         at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>         at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
>         at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
>         at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
>         at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown 
> Source)
>         at 
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown 
> Source)
>         at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown 
> Source)
>         at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown 
> Source)
>         at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
>         at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
>         at derby6565.Derby6565.main(Derby6565.java:33)
> Caused by: ERROR XJ001: Java exception: ': java.lang.NullPointerException'.
>         at org.apache.derby.iapi.error.StandardException.newException(Unknown 
> Source)
>         at 
> org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown
>  Source)
>         ... 11 more
> Caused by: java.lang.NullPointerException
>         at 
> org.apache.derby.impl.sql.compile.UnaryOperatorNode.getReceiverInterfaceName(Unknown
>  Source)
>         at 
> org.apache.derby.impl.sql.compile.UnaryOperatorNode.generateExpression(Unknown
>  Source)
>         at 
> org.apache.derby.impl.sql.compile.ResultColumn.generateExpression(Unknown 
> Source)
>         at 
> org.apache.derby.impl.sql.compile.ResultColumnList.generateEvaluatedRow(Unknown
>  Source)
>         at 
> org.apache.derby.impl.sql.compile.ResultColumnList.generateCore(Unknown 
> Source)
>         at 
> org.apache.derby.impl.sql.compile.ProjectRestrictNode.generateMinion(Unknown 
> Source)
>         at 
> org.apache.derby.impl.sql.compile.ProjectRestrictNode.generate(Unknown Source)
>         at org.apache.derby.impl.sql.compile.OrderByList.generate(Unknown 
> Source)
>         at org.apache.derby.impl.sql.compile.OrderByNode.generate(Unknown 
> Source)
>         at 
> org.apache.derby.impl.sql.compile.ProjectRestrictNode.generateMinion(Unknown 
> Source)
>         at 
> org.apache.derby.impl.sql.compile.ProjectRestrictNode.generate(Unknown Source)
>         at org.apache.derby.impl.sql.compile.RowCountNode.generate(Unknown 
> Source)
>         at 
> org.apache.derby.impl.sql.compile.SubqueryNode.generateExpression(Unknown 
> Source)
>         at 
> org.apache.derby.impl.sql.compile.BinaryOperatorNode.generateExpression(Unknown
>  Source)
>         at 
> org.apache.derby.impl.sql.compile.ResultColumn.generateExpression(Unknown 
> Source)
>         at 
> org.apache.derby.impl.sql.compile.ResultColumnList.generateEvaluatedRow(Unknown
>  Source)
>         at 
> org.apache.derby.impl.sql.compile.ResultColumnList.generateCore(Unknown 
> Source)
>         at 
> org.apache.derby.impl.sql.compile.ProjectRestrictNode.generateMinion(Unknown 
> Source)
>         at 
> org.apache.derby.impl.sql.compile.ProjectRestrictNode.generate(Unknown Source)
>         at org.apache.derby.impl.sql.compile.UpdateNode.generate(Unknown 
> Source)
>         at org.apache.derby.impl.sql.compile.StatementNode.generate(Unknown 
> Source)
>         at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown 
> Source)
>         at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
>         at 
> org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown
>  Source)
>         ... 3 more
> {code}
> The immediate problem is that the field *#operand* is null.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to