ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [04/32] ignite git commit: IGNITE-1333 - SQL Group index can return wrong restult in half-bounded conditions - Fixes #50.
Date Mon, 07 Sep 2015 13:34:38 GMT
IGNITE-1333 - SQL Group index can return wrong restult in half-bounded conditions - Fixes #50.

Signed-off-by: S.Vladykin <svladykin@gridgain.com>


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 <svladykin@gridgain.com>
Authored: Fri Sep 4 10:48:03 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
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();


Mime
View raw message