db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1378206 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/store/access/btree/OpenBTree.java testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Date Tue, 28 Aug 2012 16:24:19 GMT
Author: mamta
Date: Tue Aug 28 16:24:19 2012
New Revision: 1378206

URL: http://svn.apache.org/viewvc?rev=1378206&view=rev
Log:
DERBY-5531 Assert failure when inserting NULL into indexed column with territory-based collation

At bind time of insert node, we go through the individual columns in the insert statement
to determine if there is a need for normalization or not. In case if the insert resultset
has all null values, we conclude that we do not need normalization. At execution time, as
part of normalization, the data type conversion from datatypes like SQLVarchar to CollatorSQLVarchar
will happen if we are dealing with territory based database. But this never happens if insert
resultset has all null values and hence a later assert check in OpenBTree fails because the
datatypes do not match(in the example given in this jira, SQLVarchar and CollatorSQLVarchar
mismatch at runtime will cause an assert failure). Here is the relevant code in InsertNode.bindStatement()

/* Insert a NormalizeResultSetNode above the source if the source 
* and target column types and lengths do not match. 
  */ 
if (! resultColumnList.columnTypesAndLengthsMatch( 
resultSet.getResultColumns())) 
{ 
             
   resultSet = 
          (ResultSetNode) getNodeFactory().getNode( 
              C_NodeTypes.NORMALIZE_RESULT_SET_NODE, resultSet, 
              resultColumnList, null, Boolean.FALSE, 
              getContextManager()); 
} 

To fix this problem, we are changing OpenBTree.isIndexableRowConsistent to not throw an assert
failure if dealing with null values. If the value is null, then we will not assert the column
datatypes. As it is, this method is meaningful only in sane mode. Insane jars do not give
any error for the test case provided in the jira because assertion only happens with sane
jars.

In short, the fix is, if the row column's value is null, then don't worry about the data type
match at execution time.



Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/OpenBTree.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/OpenBTree.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/OpenBTree.java?rev=1378206&r1=1378205&r2=1378206&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/OpenBTree.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/access/btree/OpenBTree.java
Tue Aug 28 16:24:19 2012
@@ -508,6 +508,10 @@ public class OpenBTree 
 
             for (int i = 0; i < row.length; i++)
             {
+            	//DERBY-5531 If the row column's value is null, then 
+            	// don't worry about the data type match.
+            	if (row[i].isNull())
+            		continue;
                 // Compare class's rather than format id's to pick up 
                 // different problems with wrong collation implementation.
 				if (!row[i].getClass().equals(template[i].getClass()))

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java?rev=1378206&r1=1378205&r2=1378206&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Tue Aug 28 16:24:19 2012
@@ -477,6 +477,40 @@ public void testNorwayCollation() throws
 
       }
 
+/**
+ * DERBY-5531 Assert failure when inserting NULL into indexed column with 
+ *  territory-based collation
+ * Make sure that when the row being inserted has all nulls, we do not run
+ *  into assert failure 
+ * @throws SQLException
+ */
+public void testNullColumnInInsert() throws SQLException {
+    Statement s = createStatement();
+    String collation; 
+
+    ResultSet rs = null;
+    s.executeUpdate("CREATE TABLE derby5531_t1(x varchar(10) unique, y varchar(10))");
+    s.executeUpdate("INSERT INTO derby5531_t1 VALUES(NULL, 'a')");
+    s.executeUpdate("INSERT INTO derby5531_t1 VALUES('1', 'a')");
+    s.executeUpdate("INSERT INTO derby5531_t1 VALUES('2', NULL)");
+    s.executeUpdate("INSERT INTO derby5531_t1 VALUES(NULL, NULL)");
+    s.executeUpdate("INSERT INTO derby5531_t1(x) VALUES(NULL)");
+    s.executeUpdate("INSERT INTO derby5531_t1 VALUES('3', 'b')");
+    rs = s.executeQuery("select * from derby5531_t1 order by x");
+    JDBC.assertFullResultSet(rs,
+      		new String[][] {{"1","a"}, {"2",null}, {"3","b"}, {null,null}, {null,null}, {null,"a"}});
+    s.executeUpdate("DROP TABLE derby5531_t1");
+
+    s.executeUpdate("CREATE TABLE derby5531_t2(x varchar(10) unique)");
+    s.executeUpdate("INSERT INTO derby5531_t2 VALUES(NULL)");
+    s.executeUpdate("INSERT INTO derby5531_t2(x) VALUES(NULL)");
+    s.executeUpdate("INSERT INTO derby5531_t2 VALUES('a')");
+    rs = s.executeQuery("select * from derby5531_t2 order by x");
+    JDBC.assertFullResultSet(rs,
+      		new String[][] {{"a"}, {null}, {null}});
+    s.executeUpdate("DROP TABLE derby5531_t2");
+}
+
   /**
    * Test USING clause and NATURAL JOIN for case insensitive and
    * 	case sensitive collations.
@@ -2012,6 +2046,8 @@ public void testMissingCollatorSupport()
         suite.addTest(collatedSuite("en", false, "testEnglishCollation"));
         suite.addTest(collatedSuite("en", true, "testUsingClauseAndNaturalJoin"));
         suite.addTest(collatedSuite("en", false, "testUsingClauseAndNaturalJoin"));
+        suite.addTest(collatedSuite("en", true, "testNullColumnInInsert"));
+        suite.addTest(collatedSuite("en", false, "testNullColumnInInsert"));
          
         // Only add tests for other locales if they are in fact supported 
         // by the jvm.



Mime
View raw message