Issue Details (XML | Word | Printable)

Key: DERBY-2008
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Yip Ng
Reporter: A B
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Derby

NullPointerException with LTRIM, RTRIM and 2-argument SUBSTR() call in GROUP BY clause.

Created: 26/Oct/06 10:30 PM   Updated: 21/Feb/07 06:57 PM
Return to search
Component/s: SQL
Affects Version/s: 10.2.1.6, 10.3.1.4
Fix Version/s: 10.2.2.0, 10.3.1.4

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works derby2008-trunk-diff01.txt 2006-10-27 07:14 AM Yip Ng 3 kB
Text File Licensed for inclusion in ASF works derby2008-trunk-stat01.txt 2006-10-27 07:14 AM Yip Ng 0.3 kB
Issue Links:
Reference
 

Resolution Date: 28/Oct/06 04:15 PM


 Description  « Hide
The following query, which fails with a syntax error in 10.1.3 (because functions are not allowed in a GROUP BY expression for 10.1) fails with a NullPointerException in 10.2 and in the codeline (10.3):

create table dt (vc varchar(30));
insert into dt values ('1928-09-21'), ('1903-12-08');
select substr(vc, 3) from dt group by substr(vc, 3);

Result (on trunk) is:

java.lang.NullPointerException
at org.apache.derby.impl.sql.compile.TernaryOperatorNode.isEquivalent(TernaryOperatorNode.java:924)
at org.apache.derby.impl.sql.compile.GroupByList.findGroupingColumn(GroupByList.java:244)
at org.apache.derby.impl.sql.compile.VerifyAggregateExpressionsVisitor.skipChildren(VerifyAggregateExpressionsVisitor.java:146)
at org.apache.derby.impl.sql.compile.TernaryOperatorNode.accept(TernaryOperatorNode.java:497)
at org.apache.derby.impl.sql.compile.ResultColumn.accept(ResultColumn.java:1515)
at org.apache.derby.impl.sql.compile.QueryTreeNodeVector.accept(QueryTreeNodeVector.java:159)
at org.apache.derby.impl.sql.compile.SelectNode.bindExpressions(SelectNode.java:619)
at org.apache.derby.impl.sql.compile.FromSubquery.bindExpressions(FromSubquery.java:262)
at org.apache.derby.impl.sql.compile.FromList.bindExpressions(FromList.java:337)
at org.apache.derby.impl.sql.compile.SelectNode.bindExpressions(SelectNode.java:500)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bindExpressions(DMLStatementNode.java:249)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(DMLStatementNode.java:162)
at org.apache.derby.impl.sql.compile.CursorNode.bind(CursorNode.java:253)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(GenericStatement.java:345)
at org.apache.derby.impl.sql.GenericStatement.prepare(GenericStatement.java:119)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(GenericLanguageConnectionContext.java:745)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:568)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:517)

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #468696 Sat Oct 28 16:15:09 UTC 2006 bpendleton DERBY-2008: NPE with 2-arg SUBSTR call in GROUP BY clause

This patch was contributed by Yip Ng (yipng168@gmail.com)

For SUBSTR function, there can be 2 or 3 arguments, and in the
case of 2-args, the rightOperand of the TernaryOperatorNode will
be null. In its isEquivalent() method, it did not take care of
this case; thus, the NPE.
Files Changed
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/groupBy.sql
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/groupBy.out

Repository Revision Date User Message
ASF #471459 Sun Nov 05 16:45:24 UTC 2006 bpendleton DERBY-2014: NullPointerException with NULLIF in GROUP BY clause

This change was contributed by Yip Ng (yipng168@gmail.com)

The NPE happens in isEquivalent() method where it does not handle
value is null. (same symptom as DERBY-2008) and the patch addresses
this + additonal testcases.

The isEquivalent() method is used to compare the select column
against the group by with expression. Note that it is comparing
the structural form of the two expressions for equivalence at bind phase
and not comparing the actual row values at runtime to produce a result.

This patch converts all the tests in the previous patch into junit.
Also the javadoc for ValueNode.isEquivalent() method has been updated.
Files Changed
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ValueNode.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/groupBy.sql
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GroupByExpressionTest.java
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstantNode.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/groupBy.out

Repository Revision Date User Message
ASF #480219 Tue Nov 28 21:41:45 UTC 2006 rhillegas DERBY-2008: Ported to 10.2 branch.
Files Changed
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/groupBy.sql
MODIFY /db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/compile/TernaryOperatorNode.java
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/groupBy.out