db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1631604 - in /db/derby/code/branches/10.10: ./ java/engine/org/apache/derby/impl/sql/execute/GroupedAggregateResultSet.java java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Date Tue, 14 Oct 2014 02:04:07 GMT
Author: mamta
Date: Tue Oct 14 02:04:06 2014
New Revision: 1631604

URL: http://svn.apache.org/r1631604
Log:
DERBY-6227(Distinct aggregates don't work well with territory-based collation)

Backporting to 10.10

Had to hand tweek the changes in GroupedAggregateResultSet.java but there weren't too many
changes. derbyall and junit suite ran fine.


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

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

Modified: db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/execute/GroupedAggregateResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/execute/GroupedAggregateResultSet.java?rev=1631604&r1=1631603&r2=1631604&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/execute/GroupedAggregateResultSet.java
(original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/execute/GroupedAggregateResultSet.java
Tue Oct 14 02:04:06 2014
@@ -760,13 +760,13 @@ class GroupedAggregateResultSet extends 
 				// A NULL value is always distinct, so we only
 				// have to check for duplicate values for
 				// non-NULL values.
-				if (newValue.getString() != null)
+				if (!newValue.isNull())
 				{
 					if (distinctValues[level][i].contains(
-						    newValue.getString()))
+						    newValue))
 						continue;
 					distinctValues[level][i].add(
-						newValue.getString());
+						newValue);
 				}
 			}
 
@@ -790,35 +790,8 @@ class GroupedAggregateResultSet extends 
 					distinctValues[r][a].clear();
 				DataValueDescriptor newValue =
 					aggregates[a].getInputColumnValue(resultRows[r]);
-				distinctValues[r][a].add(newValue.getString());
+				distinctValues[r][a].add(newValue);
 			}
 		}
 	}
-
-        private void dumpAllRows(int cR)
-            throws StandardException
-        {
-            System.out.println("dumpAllRows("+cR+"/"+resultRows.length+"):");
-            for (int r = 0; r < resultRows.length; r++)
-                System.out.println(dumpRow(resultRows[r]));
-        }
-	private String dumpRow(ExecRow r)
-		throws StandardException
-	{
-            if (r == null)
-                return "<NULL ROW>";
-	    StringBuffer buf = new StringBuffer();
-	    int nCols = r.nColumns();
-	    for (int d = 0; d < nCols; d++)
-	    {
-		if (d > 0) buf.append(",");
-                DataValueDescriptor o = r.getColumn(d+1);
-                buf.append(o.getString());
-                if (o instanceof ExecAggregator)
-                    buf.append("[").
-                        append(((ExecAggregator)o).getResult().getString()).
-                        append("]");
-	    }
-	    return buf.toString();
-	}
 }

Modified: db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java?rev=1631604&r1=1631603&r2=1631604&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
(original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/lang/CollationTest.java
Tue Oct 14 02:04:06 2014
@@ -76,6 +76,7 @@ public class CollationTest extends BaseJ
     private final static String[] ENGLISH_CASE_INSENSITIVE = {
         "testUsingClauseAndNaturalJoin",
         "testNullColumnInInsert",
+        "testDerby6227",
     };
 
     /** Test cases to run with Norwegian case-sensitive collation. */
@@ -2264,4 +2265,29 @@ public void testMissingCollatorSupport()
         assertStatementError(INVALID_ESCAPE, s,
                 "select * from d6030 where x like y escape 'aa'");
     }
+
+    /**
+     * Regression test case for DERBY-6227. Distinct grouped aggregates used
+     * to eliminate duplicates by comparing the string representation of the
+     * values using {@code String.equals()}. That does not give the right
+     * results if the database collation defines equality in a different way
+     * than {@code String.equals()}, for example when running with case
+     * insensitive collation ({@code collation=TERRITORY_BASED:PRIMARY}).
+     */
+    public void testDerby6227() throws SQLException {
+        String sql = "select i, count(distinct s) "
+                + "from (values (1, 'a'), (1, 'a'), (2, 'b'), (2, 'B'), "
+                + "(3, 'a'), (3, 'A'), (3, 'b'), (3, 'B'), (3, 'c')) v(i, s) "
+                + "group by i order by i";
+
+        // These are the expected results of the query when running with
+        // case-insensitive collation. Before the fix, the query would return
+        // (1, 1), (2, 2), (3, 5).
+        String[][] expectedRows = {
+            { "1", "1" }, { "2", "1" }, { "3", "3" }
+        };
+
+        Statement s = createStatement();
+        JDBC.assertFullResultSet(s.executeQuery(sql), expectedRows);
+    }
 }



Mime
View raw message