db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r960285 - in /db/derby/code/branches/10.5: ./ java/engine/org/apache/derby/impl/sql/ java/engine/org/apache/derby/impl/sql/execute/ java/engine/org/apache/derby/impl/store/access/sort/ java/testing/org/apache/derbyTesting/functionTests/test...
Date Sat, 03 Jul 2010 23:47:46 GMT
Author: mikem
Date: Sat Jul  3 23:47:45 2010
New Revision: 960285

URL: http://svn.apache.org/viewvc?rev=960285&view=rev
Log:
DERBY-4413 INSERT from SELECT DISTINCT gives assertFailure (sane), or NPE (insane) in presence
of generated columns

back porting svn #829410 from trunk to 10.5 branch.

Patch DERBY-4413-2 makes sort accept columns that are null. In sane mode, it is checked that
in such a case, the
empty column is not part of the sort key. 


Modified:
    db/derby/code/branches/10.5/   (props changed)
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericColumnDescriptor.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/BasicSortObserver.java
    db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/store/access/sort/MergeSort.java
    db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Jul  3 23:47:45 2010
@@ -1,2 +1,2 @@
 /db/derby/code/branches/10.6:957000
-/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,898635,901165,901648,901760,903108,908418,909176,911315,915733,916075,916897,918359,921028,927430,928065,942286,942476,942480,942587,946794,948045,948069,951346,954748,955001,955634,956075,956445,956659,958163,959550
+/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,829410,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,898635,901165,901648,901760,903108,908418,909176,911315,915733,916075,916897,918359,921028,927430,928065,942286,942476,942480,942587,946794,948045,948069,951346,954748,955001,955634,956075,956445,956659,958163,959550

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericColumnDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericColumnDescriptor.java?rev=960285&r1=960284&r2=960285&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericColumnDescriptor.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/GenericColumnDescriptor.java
Sat Jul  3 23:47:45 2010
@@ -239,7 +239,9 @@ public final class GenericColumnDescript
 			return "GenericColumnDescriptor\n\tname: "+name+
 				"\n\tTable: "+schemaName+"."+tableName+
 				"\n\tcolumnPos: "+columnPos+
-				"\n\tType: "+type;
+				"\n\tType: "+type+
+				"\n\tisAutoincrement: " + isAutoincrement +
+				"\n\thasGenerationClause: " + hasGenerationClause;
 		}
 		else
 		{

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/BasicSortObserver.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/BasicSortObserver.java?rev=960285&r1=960284&r2=960285&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/BasicSortObserver.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/sql/execute/BasicSortObserver.java
Sat Jul  3 23:47:45 2010
@@ -168,7 +168,12 @@ public class BasicSortObserver implement
 		{
 			// the only difference between getClone and cloneObject is cloneObject does
 			// not objectify a stream.  We use getClone here.  Beetle 4896.
-			newArray[i] = origArray[i].getClone();
+
+			// DERBY-4413 shows that the value for a generated column will be
+			// null as the result set is computed as part of an INSERT INTO, so
+			// accept a null also.
+			newArray[i] =
+				(origArray[i] != null ? origArray[i].getClone() : null);
 		}
 
 		return newArray;

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/store/access/sort/MergeSort.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/store/access/sort/MergeSort.java?rev=960285&r1=960284&r2=960285&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/store/access/sort/MergeSort.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/store/access/sort/MergeSort.java
Sat Jul  3 23:47:45 2010
@@ -126,6 +126,12 @@ class MergeSort implements Sort
 	**/
 	protected boolean columnOrderingNullsLowMap[];
 
+
+	/**
+    Determine whether a column is used for ordering or not.
+	**/
+	private boolean isOrderingColumn[];
+
 	/**
 	The sort observer.  May be null.  Used as a callback.
 	**/
@@ -455,8 +461,18 @@ class MergeSort implements Sort
                 Object col2 = template[colid];
                 if (col1 == null)
 				{
-					SanityManager.THROWASSERT(
-						"col[" + colid + "]  is null");
+					if (!isOrderingColumn[colid]) {
+
+						// DERBY-4413 shows that the value for a generated
+						// column will be null as the result set is computed as
+						// part of an INSERT INTO, so accept a null also.
+						// This column would not be part of the sort key.
+
+						continue;
+
+					} else {
+						SanityManager.THROWASSERT("col[" + colid + "] is null");
+					}
 				}
 						
                 if (!(col1 instanceof CloneableObject))
@@ -546,13 +562,27 @@ class MergeSort implements Sort
         columnOrderingMap          = new int[columnOrdering.length];
         columnOrderingAscendingMap = new boolean[columnOrdering.length];
         columnOrderingNullsLowMap  = new boolean[columnOrdering.length];
-        for (int i = 0; i < columnOrdering.length; i++)
+
+		if (SanityManager.DEBUG) {
+			isOrderingColumn = new boolean[template.length];
+
+			for (int i = 0; i < isOrderingColumn.length; i++) {
+				isOrderingColumn[i] = false;
+			}
+		}
+
+		for (int i = 0; i < columnOrdering.length; i++)
         {
             columnOrderingMap[i] = columnOrdering[i].getColumnId();
             columnOrderingAscendingMap[i] = columnOrdering[i].getIsAscending();
             columnOrderingNullsLowMap[i] = columnOrdering[i].getIsNullsOrderedLow();
+
+			if (SanityManager.DEBUG) {
+				isOrderingColumn[columnOrderingMap[i]] = true;
+			}
         }
 
+
 		// No inserter or scan yet.
 		this.inserter = null;
 		this.scan = null;

Modified: db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java?rev=960285&r1=960284&r2=960285&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
(original)
+++ db/derby/code/branches/10.5/java/testing/org/apache/derbyTesting/functionTests/tests/lang/GeneratedColumnsTest.java
Sat Jul  3 23:47:45 2010
@@ -5370,9 +5370,55 @@ public class GeneratedColumnsTest extend
              );
 
     }
-    
 
 
+   /**
+    * Test INSERT INTO .. select distinct in presence of generated column.
+    * Cf DERBY-4413.
+    */
+    public  void    test_031_derby_4413()
+            throws Exception
+    {
+        Connection  conn = getConnection();
+
+        //
+        // Schema
+        //
+        goodStatement
+            (
+                conn,
+                "create table t_4413 (" +
+                "     i integer, " +
+                "     j integer not null generated always as (i*2))"
+            );
+        goodStatement
+            (
+                conn,
+                "insert into t_4413(i) values 1,2,1"
+            );
+
+        goodStatement
+            (
+                conn,
+                "insert into t_4413(i) select distinct i from t_4413"
+            );
+        assertResults
+            (
+                conn,
+                "select * from t_4413",
+                new String[][]
+                {
+                    { "1", "2", },
+                    { "2", "4", },
+                    { "1", "2", },
+                    { "1", "2", },
+                    { "2", "4", },
+                },
+                false
+            );
+
+    }
+
 
     ///////////////////////////////////////////////////////////////////////////////////
     //
@@ -5550,4 +5596,4 @@ public class GeneratedColumnsTest extend
     }
 
 
-}
\ No newline at end of file
+}



Mime
View raw message