db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1524385 - in /db/derby/code/branches/10.10: ./ java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
Date Wed, 18 Sep 2013 12:12:40 GMT
Author: rhillegas
Date: Wed Sep 18 12:12:39 2013
New Revision: 1524385

URL: http://svn.apache.org/r1524385
Log:
DERBY-6346: Port 1524194 from trunk to 10.10 branch.

Modified:
    db/derby/code/branches/10.10/   (props changed)
    db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
    db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java

Propchange: db/derby/code/branches/10.10/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1524194

Modified: db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java?rev=1524385&r1=1524384&r2=1524385&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
(original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/compile/ResultColumnList.java
Wed Sep 18 12:12:39 2013
@@ -1350,9 +1350,20 @@ public class ResultColumnList extends Qu
             // 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/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java?rev=1524385&r1=1524384&r2=1524385&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
(original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
Wed Sep 18 12:12:39 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