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

Knut Anders Hatlen commented on DERBY-6735:
-------------------------------------------

Thanks, Thomas! That looks more useful.

I haven't been able to reproduce the NPE myself, but it looks like Derby gets 
confused if the select list contains both row_number() over () and a subquery, 
even if the query is much simpler than the one that failed for you.

For example:

{noformat}
ij> create table t1(x int);
0 rows inserted/updated/deleted
ij> select row_number() over (), (select x from t1 where x=1) from t1;
ERROR XJ001: Java exception: 
'org.apache.derby.impl.sql.compile.NumericConstantNode cannot be cast to 
org.apache.derby.impl.sql.compile.ColumnReference: 
java.lang.ClassCastException'.
{noformat}

or with debug jars:

{noformat}
ij> select row_number() over (), (select x from t1 where x=1) from t1;
ERROR XJ001: Java exception: 'ASSERT FAILED sourceResultSetNumber expected to 
be >= 0 for virtual column X: 
org.apache.derby.shared.common.sanity.AssertFailure'.
{noformat}

Even though it fails with a ClassCastException instead of a 
NullPointerException, I would suspect that the root cause is the same. The NPE 
seems to happen because BinaryRelationalOperatorNode.getExpressionOperand() 
returns null, which only happens if neither the left operand nor the right 
operand of the node is a ColumnReference. The ClassCastException happens 
because the right operand cannot be cast to ColumnReference. So both failures 
happen because the code expects an operand of BinaryRelationalOperatorNode to 
be a ColumnReference, whereas it isn't.

> NPE in org.apache.derby.client.am.ClientStatement.completeSqlca
> ---------------------------------------------------------------
>
>                 Key: DERBY-6735
>                 URL: https://issues.apache.org/jira/browse/DERBY-6735
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.11.1.1
>         Environment: Windows 7 64Bit, Java8_20 64Bit
>            Reporter: Thomas Meyer
>
> When using row_number() over() in an SQL I get this exception:
> ERROR XJ001: DERBY SQL error: ERRORCODE: 0, SQLSTATE: XJ001, SQLERRMC: 
> java.lang.NullPointerException¶¶XJ001.U
> java.sql.SQLException: DERBY SQL error: ERRORCODE: 0, SQLSTATE: XJ001, 
> SQLERRMC: java.lang.NullPointerException¶¶XJ001.U
>         at 
> org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown Source)
>         at org.apache.derby.client.am.SqlException.getSQLException(Unknown 
> Source)
>         at org.apache.derby.client.am.ClientStatement.execute(Unknown Source)
>         at org.apache.derby.impl.tools.ij.ij.executeImmediate(Unknown Source)
>         at org.apache.derby.impl.tools.ij.utilMain.doCatch(Unknown Source)
>         at org.apache.derby.impl.tools.ij.utilMain.runScriptGuts(Unknown 
> Source)
>         at org.apache.derby.impl.tools.ij.utilMain.go(Unknown Source)
>         at org.apache.derby.impl.tools.ij.Main.go(Unknown Source)
>         at org.apache.derby.impl.tools.ij.Main.mainCore(Unknown Source)
>         at org.apache.derby.impl.tools.ij.Main.main(Unknown Source)
>         at org.apache.derby.tools.ij.main(Unknown Source)
> Caused by: ERROR XJ001: DERBY SQL error: ERRORCODE: 0, SQLSTATE: XJ001, 
> SQLERRMC: java.lang.NullPointerException¶¶XJ001.U
>         at org.apache.derby.client.am.ClientStatement.completeSqlca(Unknown 
> Source)
>         at 
> org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown 
> Source)
>         at 
> org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown 
> Source)
>         at 
> org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown
>  Source)
>         at 
> org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown 
> Source)
>         at 
> org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown 
> Source)
>         at 
> org.apache.derby.client.am.ClientStatement.readPrepareDescribeOutput(Unknown 
> Source)
>         at org.apache.derby.client.am.ClientStatement.flowExecute(Unknown 
> Source)
>         at org.apache.derby.client.am.ClientStatement.executeX(Unknown Source)
>         ... 9 more
> ij>



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

Reply via email to