db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1615982 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/UpdateNode.java engine/org/apache/derby/impl/sql/compile/WindowResultSetNode.java testing/org/apache/derbyTesting/functionTests/tests/lang/OLAPTest.java
Date Tue, 05 Aug 2014 19:20:51 GMT
Author: dag
Date: Tue Aug  5 19:20:50 2014
New Revision: 1615982

URL: http://svn.apache.org/r1615982
Log:
DERBY-6565 ROW_NUMBER function throws NullPointerException in UPDATE statement

Patch *derby-6565-forbid.diff* which makes it illegal to use window
functions in the update source. Adds a new test for this error
condition. Also cleans up some Javadocs and modernizes some loops.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/WindowResultSetNode.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OLAPTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java?rev=1615982&r1=1615981&r2=1615982&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/UpdateNode.java Tue
Aug  5 19:20:50 2014
@@ -35,13 +35,11 @@ import org.apache.derby.iapi.services.cl
 import org.apache.derby.iapi.services.compiler.MethodBuilder;
 import org.apache.derby.iapi.services.context.ContextManager;
 import org.apache.derby.iapi.services.io.FormatableBitSet;
-import org.apache.derby.shared.common.sanity.SanityManager;
 import org.apache.derby.iapi.sql.StatementType;
 import org.apache.derby.iapi.sql.compile.CompilerContext;
 import org.apache.derby.iapi.sql.compile.TagFilter;
 import org.apache.derby.iapi.sql.conn.Authorizer;
 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
-import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
 import org.apache.derby.iapi.sql.dictionary.CheckConstraintDescriptor;
 import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor;
 import org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList;
@@ -49,16 +47,16 @@ import org.apache.derby.iapi.sql.diction
 import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;
 import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList;
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
-import org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList;
 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
 import org.apache.derby.iapi.sql.dictionary.TriggerDescriptor;
+import org.apache.derby.iapi.sql.dictionary.TriggerDescriptorList;
 import org.apache.derby.iapi.sql.execute.ConstantAction;
 import org.apache.derby.iapi.sql.execute.ExecPreparedStatement;
 import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;
 import org.apache.derby.iapi.store.access.TransactionController;
-import org.apache.derby.iapi.types.DataTypeDescriptor;
 import org.apache.derby.iapi.types.TypeId;
 import org.apache.derby.iapi.util.ReuseFactory;
+import org.apache.derby.shared.common.sanity.SanityManager;
 import org.apache.derby.vti.DeferModification;
 
 /**
@@ -549,6 +547,9 @@ public final class UpdateNode extends DM
         //
         if ( inMatchingClause() ) { associateAddedColumns(); }
 
+        // SQL 2011, section 6.10, SR 4b.
+        SelectNode.checkNoWindowFunctions(resultSet, "<update source>");
+
 		/* Bind the expressions */
 		super.bindExpressions();
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/WindowResultSetNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/WindowResultSetNode.java?rev=1615982&r1=1615981&r2=1615982&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/WindowResultSetNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/WindowResultSetNode.java
Tue Aug  5 19:20:50 2014
@@ -21,6 +21,7 @@
 package org.apache.derby.impl.sql.compile;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.ClassName;
@@ -58,6 +59,7 @@ class WindowResultSetNode extends Single
      *
      * @exception StandardException     Thrown on error
      */
+    @SuppressWarnings("LeakingThisInConstructor")
     WindowResultSetNode(ResultSetNode            bottomPR,
                         WindowDefinitionNode     windowDef,
                         List<WindowFunctionNode> windowFuncCalls,
@@ -82,7 +84,7 @@ class WindowResultSetNode extends Single
         setResultColumns( childResult.getResultColumns() );
         childResult.setResultColumns(newBottomRCL);
 
-        // Wrao purselved int a project/restrict as per convention.
+        // Wrap ourselves in a project/restrict as per convention.
         addNewPRNode();
 
         // Add the extra result columns required
@@ -92,7 +94,7 @@ class WindowResultSetNode extends Single
     /**
      * Add a new PR node.  Put the new PR under any sort.
      *
-     * @exception standard exception
+     * @throws StandardException standard error policy
      */
     private void addNewPRNode()
         throws StandardException
@@ -167,9 +169,7 @@ class WindowResultSetNode extends Single
         ResultColumnList bottomRCL  = childResult.getResultColumns();
         ResultColumnList windowingRCL = getResultColumns();
 
-        for (int i= 0; i< uniqueCols.size(); i++) {
-            ValueNode crOrVcn = uniqueCols.get(i);
-
+        for (ValueNode crOrVcn : uniqueCols) {
             ResultColumn newRC = new ResultColumn(
                     "##UnWindowingColumn",
                     crOrVcn,
@@ -209,15 +209,18 @@ class WindowResultSetNode extends Single
 
 
     /**
+     * @param uniqueColRefs list of unique column references
+     * @param cand the candidate to check is present in list
      * @return {@code true} if an equivalent column reference to {@code cand}
      *         is already present in {@code uniqueColRefs}
+     * @throws StandardException standard error policy
      */
     private boolean colRefAlreadySeen(List<ValueNode> uniqueColRefs,
                                       ColumnReference cand)
             throws StandardException {
 
-        for (int i= 0; i< uniqueColRefs.size(); i++) {
-            ColumnReference cr = (ColumnReference)uniqueColRefs.get(i);
+        for (ValueNode uniqueColRef : uniqueColRefs) {
+            ColumnReference cr = (ColumnReference) uniqueColRef;
 
             if (cr.isEquivalent(cand)) {
                 return true;
@@ -229,6 +232,8 @@ class WindowResultSetNode extends Single
     /**
      * Substitute new result columns for window function calls and add the
      * result columns to childResult's list of columns.
+     *
+     * @throws StandardException standard error policy
      */
     private void addNewColumns() throws StandardException {
         /*
@@ -246,8 +251,7 @@ class WindowResultSetNode extends Single
                 ResultSetNode.class);
         parent.getResultColumns().accept(replaceCallsVisitor);
 
-        for (int i=0; i < windowFuncCalls.size(); i++) {
-            WindowFunctionNode winFunc = windowFuncCalls.get(i);
+        for (WindowFunctionNode winFunc : windowFuncCalls) {
 
             if (SanityManager.DEBUG) {
                 SanityManager.ASSERT(
@@ -307,10 +311,6 @@ class WindowResultSetNode extends Single
     }
 
 
-    /**
-     * override
-     * @see QueryTreeNode#generate
-     */
     @Override
     void generate(ActivationClassBuilder acb, MethodBuilder mb)
             throws StandardException

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OLAPTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OLAPTest.java?rev=1615982&r1=1615981&r2=1615982&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OLAPTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OLAPTest.java
Tue Aug  5 19:20:50 2014
@@ -587,6 +587,12 @@ public class OLAPTest extends BaseJDBCTe
             s,
             "select * from t4 t_1 join t4 t_2 on " +
             "                     t_1.a = row_number() over () + t_2.a");
+
+        // DERBY-6565
+        assertStatementError(
+                LANG_WINDOW_FUNCTION_CONTEXT_ERROR,
+                s,
+                "update t3 set y = y - row_number() over ()");
     }
 
 



Mime
View raw message