db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1524194 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ResultColumnList.java testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
Date Tue, 17 Sep 2013 19:52:19 GMT
Author: rhillegas
Date: Tue Sep 17 19:52:18 2013
New Revision: 1524194

URL: http://svn.apache.org/r1524194
Log:
DERBY-6346: Fix LEFT JOIN involving a table with a generated column; tests passed cleanly
on derby-6346-02-aa-generateNullForLeftJoins.diff.

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

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java?rev=1524194&r1=1524193&r2=1524194&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
Tue Sep 17 19:52:18 2013
@@ -1328,9 +1328,20 @@ class ResultColumnList extends QueryTree
             // method, which (like CHECK CONSTRAINTS) is explicitly called by
             // InsertResultSet and UpdateResultSet.
             //
+            // For LEFT JOINs, we may need to stuff a NULL into the generated column slot,
+            // just as we do for non-generated columns in a LEFT JOIN. We look at the source
+            // expression for the ResultColumn to determine whether this ResultColumnList
+            // represents an INSERT/UPDATE vs. a SELECT. If this ResultColumnList represents
a
+            // LEFT JOIN, then the source expression will be a VirtualColumnNode.
+            // See DERBY-6346.
+            //
 			if ( rc.hasGenerationClause() )
             {
-                continue;
+                ValueNode   expr = rc.getExpression();
+                if ( (expr != null) && !(expr instanceof VirtualColumnNode) )
+                {
+                    continue;
+                }
             }
             
 			// we need the expressions to be Columns exactly.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java?rev=1524194&r1=1524193&r2=1524194&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
Tue Sep 17 19:52:18 2013
@@ -5574,6 +5574,65 @@ public class GeneratedColumnsTest extend
 
     }
 
+    // Derby 6346
+    public void test_derby_6346()
+        throws Exception
+    {
+        Connection conn = getConnection();
+
+        goodStatement
+        (
+            conn,
+            "create table t1_6346( c1 int, c2 int generated always as ( -c1 ) )"
+        );
+        goodStatement
+        (
+            conn,
+            "create table t2_6346( c1 int )"
+        );
+        goodStatement
+        (
+            conn,
+            "create table t3_6346( c1 int, c2 int )"
+        );
+        goodStatement
+        (
+            conn,
+            "insert into t1_6346( c1 ) values ( 2 ), ( 20 )"
+        );
+        goodStatement
+        (
+            conn,
+            "insert into t3_6346( c1, c2 ) values ( 2, -2 ), ( 20, -20 )"
+        );
+        goodStatement
+        (
+            conn,
+            "insert into t2_6346( c1 ) values ( 2 ), ( 200 )"
+        );
+
+        String[][]  expectedResults = new String[][]
+        {
+            { "2", "2", "-2" },     
+            { "200", null, null },
+        };
+        
+        assertResults
+            (
+             conn,
+             "select * from t2_6346 left join t3_6346 on t3_6346.c1 = t2_6346.c1 order by
t2_6346.c1",
+             expectedResults,
+             false
+             );
+        assertResults
+            (
+             conn,
+             "select * from t2_6346 left join t1_6346 on t1_6346.c1 = t2_6346.c1 order by
t2_6346.c1",
+             expectedResults,
+             false
+             );
+    }
+    
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // MINIONS



Mime
View raw message