Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4E0A6172C8 for ; Tue, 14 Oct 2014 02:04:29 +0000 (UTC) Received: (qmail 80165 invoked by uid 500); 14 Oct 2014 02:04:29 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 80136 invoked by uid 500); 14 Oct 2014 02:04:29 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 80127 invoked by uid 99); 14 Oct 2014 02:04:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Oct 2014 02:04:28 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Oct 2014 02:04:27 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 4870523889DA; Tue, 14 Oct 2014 02:04:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: derby-commits@db.apache.org From: mamta@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20141014020407.4870523889DA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 ""; - 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); + } }