Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F17D817854 for ; Mon, 7 Sep 2015 13:34:41 +0000 (UTC) Received: (qmail 17844 invoked by uid 500); 7 Sep 2015 13:34:35 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 17763 invoked by uid 500); 7 Sep 2015 13:34:35 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 17657 invoked by uid 99); 7 Sep 2015 13:34:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Sep 2015 13:34:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7A298E01E0; Mon, 7 Sep 2015 13:34:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Mon, 07 Sep 2015 13:34:38 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [04/32] ignite git commit: IGNITE-1333 - SQL Group index can return wrong restult in half-bounded conditions - Fixes #50. IGNITE-1333 - SQL Group index can return wrong restult in half-bounded conditions - Fixes #50. Signed-off-by: S.Vladykin Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/bf64c6ed Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/bf64c6ed Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/bf64c6ed Branch: refs/heads/master Commit: bf64c6edc8f44a0f2d4ef2707d8bdd2a98589297 Parents: 8901575 Author: S.Vladykin Authored: Fri Sep 4 10:48:03 2015 +0300 Committer: S.Vladykin Committed: Fri Sep 4 10:50:47 2015 +0300 ---------------------------------------------------------------------- .../query/h2/opt/GridH2IndexBase.java | 42 ++++++++++++++++++++ .../query/IgniteSqlSplitterSelfTest.java | 35 ++++++++++++++-- 2 files changed, 74 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/bf64c6ed/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java index ff9aa23..39664ff 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java @@ -27,6 +27,8 @@ import org.h2.index.BaseIndex; import org.h2.message.DbException; import org.h2.result.Row; import org.h2.result.SearchRow; +import org.h2.result.SortOrder; +import org.h2.value.Value; import org.jetbrains.annotations.Nullable; /** @@ -106,6 +108,46 @@ public abstract class GridH2IndexBase extends BaseIndex { // No-op. } + /** {@inheritDoc} */ + @Override public int compareRows(SearchRow rowData, SearchRow compare) { + if (rowData == compare) + return 0; + + for (int i = 0, len = indexColumns.length; i < len; i++) { + int index = columnIds[i]; + + Value v1 = rowData.getValue(index); + Value v2 = compare.getValue(index); + + if (v1 == null || v2 == null) + return 0; + + int c = compareValues(v1, v2, indexColumns[i].sortType); + + if (c != 0) + return c; + } + return 0; + } + + /** + * @param a First value. + * @param b Second value. + * @param sortType Sort type. + * @return Comparison result. + */ + private int compareValues(Value a, Value b, int sortType) { + if (a == b) + return 0; + + int comp = table.compareTypeSave(a, b); + + if ((sortType & SortOrder.DESCENDING) != 0) + comp = -comp; + + return comp; + } + /** * Filters rows from expired ones and using predicate. * http://git-wip-us.apache.org/repos/asf/ignite/blob/bf64c6ed/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java index f70c218..75112fd 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java @@ -158,15 +158,44 @@ public class IgniteSqlSplitterSelfTest extends GridCommonAbstractTest { // Check results. assertEquals(1, columnQuery(c, qry + "where a = 1 and b = 1").size()); + assertEquals(0, columnQuery(c, qry + "where a = 1 and b = 2").size()); + assertEquals(1, columnQuery(c, qry + "where a = 1 and b = 3").size()); assertEquals(2, columnQuery(c, qry + "where a = 1 and b < 4").size()); assertEquals(2, columnQuery(c, qry + "where a = 1 and b <= 3").size()); assertEquals(1, columnQuery(c, qry + "where a = 1 and b < 3").size()); assertEquals(2, columnQuery(c, qry + "where a = 1 and b > 0").size()); assertEquals(1, columnQuery(c, qry + "where a = 1 and b > 1").size()); assertEquals(2, columnQuery(c, qry + "where a = 1 and b >= 1").size()); - assertEquals(4, columnQuery(c, qry + "where a > 0 and b > 0").size()); - assertEquals(4, columnQuery(c, qry + "where a > 0 and b >= 1").size()); - assertEquals(3, columnQuery(c, qry + "where a > 0 and b > 1").size()); + + assertEquals(4, columnQuery(c, qry + "where a > 0").size()); + assertEquals(4, columnQuery(c, qry + "where a >= 1").size()); + assertEquals(4, columnQuery(c, qry + "where b > 0").size()); + assertEquals(4, columnQuery(c, qry + "where b >= 1").size()); + + assertEquals(4, columnQuery(c, qry + "where a < 2").size()); + assertEquals(4, columnQuery(c, qry + "where a <= 1").size()); + assertEquals(4, columnQuery(c, qry + "where b < 3").size()); + assertEquals(5, columnQuery(c, qry + "where b <= 3").size()); + + assertEquals(3, columnQuery(c, qry + "where a > 0 and b > 0").size()); + assertEquals(2, columnQuery(c, qry + "where a > 0 and b >= 2").size()); + assertEquals(3, columnQuery(c, qry + "where a >= 1 and b > 0").size()); + assertEquals(2, columnQuery(c, qry + "where a >= 1 and b >= 2").size()); + + assertEquals(3, columnQuery(c, qry + "where a > 0 and b < 3").size()); + assertEquals(2, columnQuery(c, qry + "where a > 0 and b <= 1").size()); + assertEquals(3, columnQuery(c, qry + "where a >= 1 and b < 3").size()); + assertEquals(2, columnQuery(c, qry + "where a >= 1 and b <= 1").size()); + + assertEquals(2, columnQuery(c, qry + "where a < 2 and b < 3").size()); + assertEquals(2, columnQuery(c, qry + "where a < 2 and b <= 1").size()); + assertEquals(2, columnQuery(c, qry + "where a <= 1 and b < 3").size()); + assertEquals(2, columnQuery(c, qry + "where a <= 1 and b <= 1").size()); + + assertEquals(3, columnQuery(c, qry + "where a < 2 and b > 0").size()); + assertEquals(2, columnQuery(c, qry + "where a < 2 and b >= 3").size()); + assertEquals(3, columnQuery(c, qry + "where a <= 1 and b > 0").size()); + assertEquals(2, columnQuery(c, qry + "where a <= 1 and b >= 3").size()); } finally { c.destroy();