db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1616365 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/GenerationClauseNode.java engine/org/apache/derby/impl/sql/compile/TableElementList.java testing/org/apache/derbyTesting/functionTests/tests/lang/OLAPTest.java
Date Wed, 06 Aug 2014 22:19:26 GMT
Author: dag
Date: Wed Aug  6 22:19:26 2014
New Revision: 1616365

URL: http://svn.apache.org/r1616365
Log:
DERBY-6690 ROW_NUMBER should not be allowed in generation clause

Patch *derby-6690* makes this illegal by adding a check in
TableElementList#bindAndValidateGeneration. I had to add an
acceptChildren method to GenerationClauseNode for the visitor to reach
down into the generation clause. Added a test to
OLAPTest#testBasicOperations for both CREATE TABLE and ALTER TABLE ADD
COLUMN.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GenerationClauseNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.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/GenerationClauseNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GenerationClauseNode.java?rev=1616365&r1=1616364&r2=1616365&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GenerationClauseNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/GenerationClauseNode.java
Wed Aug  6 22:19:26 2014
@@ -26,6 +26,7 @@ import org.apache.derby.iapi.error.Stand
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.services.compiler.MethodBuilder;
 import org.apache.derby.iapi.services.context.ContextManager;
+import org.apache.derby.iapi.sql.compile.Visitor;
 import org.apache.derby.shared.common.sanity.SanityManager;
 import org.apache.derby.iapi.sql.depend.ProviderList;
 
@@ -146,7 +147,28 @@ class GenerationClauseNode extends Value
         return visitor.getList();
     }
 
-	/*
+    /**
+     * Accept the visitor for all visitable children of this node.
+     *
+     * @param v the visitor
+     *
+     * @exception StandardException on error
+     */
+    @Override
+    void acceptChildren(Visitor v) throws StandardException {
+
+        super.acceptChildren(v);
+
+        if (_generationExpression != null) {
+            _generationExpression = (ValueNode)_generationExpression.accept(v);
+        }
+
+        if (_boundExpression != null) {
+            _boundExpression = (ValueNode)_boundExpression.accept(v);
+        }
+    }
+
+    /*
 		Stringify.
 	 */
     @Override

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java?rev=1616365&r1=1616364&r2=1616365&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
Wed Aug  6 22:19:26 2014
@@ -731,6 +731,8 @@ class TableElementList extends QueryTree
                 generationTree = generationClauseNode.bindExpression(
                         fromList, (SubqueryList) null, aggregates);
 
+                SelectNode.checkNoWindowFunctions(generationClauseNode, "generation clause");
+
                 //
                 // If the user did not declare a type for this column, then the column type
defaults
                 // to the type of the generation clause.

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=1616365&r1=1616364&r2=1616365&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
Wed Aug  6 22:19:26 2014
@@ -633,6 +633,18 @@ public class OLAPTest extends BaseJDBCTe
             s,
             "call syscs_util.syscs_compress_table(" + 
             "    'APP', 'T2', row_number() over ())");
+
+        // DERBY-6690: a window function in generated clause was not detected
+        // before
+        assertStatementError(LANG_WINDOW_FUNCTION_CONTEXT_ERROR,
+            s,
+            "create table t (x int generated always as " +
+            "    (row_number() over ()))");
+
+        assertStatementError(LANG_WINDOW_FUNCTION_CONTEXT_ERROR,
+            s,
+            "alter table t2 add column foo int generated always as " +
+            "    (row_number() over ())");
     }
 
 



Mime
View raw message