Issue Details (XML | Word | Printable)

Key: DERBY-4145
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Rick Hillegas
Reporter: Knut Anders Hatlen
Votes: 0
Watchers: 0
Operations

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

NullPointerException on CREATE TABLE when generated column depends on another generated column

Created: 05/Apr/09 08:31 PM   Updated: 04/May/09 06:24 PM
Component/s: SQL
Affects Version/s: None
Fix Version/s: 10.5.1.1, 10.6.0.0

Time Tracking:
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works derby-4145-01-aa-forwardReference.diff 2009-04-06 07:04 PM Rick Hillegas 9 kB

Resolution Date: 07/Apr/09 07:09 AM


 Description  « Hide
ij> create table t (c1 int, c2 int, c3 generated always as (c1 + c4), c4 generated always as (-c1));
ERROR XJ001: Java exception: ': java.lang.NullPointerException'.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Knut Anders Hatlen added a comment - 05/Apr/09 08:32 PM
Full stack trace:

java.lang.NullPointerException
at org.apache.derby.impl.sql.compile.BinaryOperatorNode.genSQLJavaSQLTree(BinaryOperatorNode.java:416)
at org.apache.derby.impl.sql.compile.BinaryOperatorNode.bindExpression(BinaryOperatorNode.java:329)
at org.apache.derby.impl.sql.compile.BinaryArithmeticOperatorNode.bindExpression(BinaryArithmeticOperatorNode.java:129)
at org.apache.derby.impl.sql.compile.GenerationClauseNode.bindExpression(GenerationClauseNode.java:117)
at org.apache.derby.impl.sql.compile.TableElementList.bindAndValidateGenerationClauses(TableElementList.java:803)
at org.apache.derby.impl.sql.compile.CreateTableNode.bindStatement(CreateTableNode.java:441)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(GenericStatement.java:316)
at org.apache.derby.impl.sql.GenericStatement.prepare(GenericStatement.java:88)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(GenericLanguageConnectionContext.java:802)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:606)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(EmbedStatement.java:555)
at org.apache.derby.impl.tools.ij.ij.executeImmediate(ij.java:329)
at org.apache.derby.impl.tools.ij.utilMain.doCatch(utilMain.java:505)
at org.apache.derby.impl.tools.ij.utilMain.runScriptGuts(utilMain.java:347)
at org.apache.derby.impl.tools.ij.utilMain.go(utilMain.java:245)
at org.apache.derby.impl.tools.ij.Main.go(Main.java:210)
at org.apache.derby.impl.tools.ij.Main.mainCore(Main.java:177)
at org.apache.derby.impl.tools.ij.Main.main(Main.java:73)
at org.apache.derby.tools.ij.main(ij.java:59)

Rick Hillegas added a comment - 06/Apr/09 07:03 PM
The bug occurs when a generation clause includes a forward reference to a generated column which is declared later on in the table's signature. The bug occurs because we look for the referenced columns after we bind the generation clauses. When we bind the earlier generated columns, we trip across references to columns which haven't been bound yet. This raises an npe. The fix is to bind the generation clauses after we look for illegal references.

Rick Hillegas added a comment - 06/Apr/09 07:04 PM
Attaching derby-4145-01-aa-forwardReference.diff. This changes the way that we find generation clauses which reference other generated columns.

Previously, we bound the generation clauses before looking for illegal references. This failed if a generation clause had a forward reference to another generated column declared later in the table's signature. Now we look for illegal references before binding the generation clauses.

Touches the following files:

M java/engine/org/apache/derby/impl/sql/compile/GenerationClauseNode.java

Add a new method so that a generation clause can find the columns it references.


M java/engine/org/apache/derby/impl/sql/compile/AlterTableNode.java
M java/engine/org/apache/derby/impl/sql/compile/CreateTableNode.java
M java/engine/org/apache/derby/impl/sql/compile/TableElementList.java

Relocate the search for illegal references so that it happens just before we bind the generation clauses.


M java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java

Add a test case for this bug.

Rick Hillegas added a comment - 06/Apr/09 09:42 PM
Committed derby-4145-01-aa-forwardReference.diff at subversion revision 762520.

Rick Hillegas added a comment - 06/Apr/09 09:47 PM
Ported 762520 from trunk to 10.5 branch at subversion revision 762521.

Knut Anders Hatlen added a comment - 07/Apr/09 07:09 AM
Thanks, Rick! I've verified that it now works on trunk and on the 10.5 branch. Closing the issue.