ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject ignite git commit: IGNITE-1333 - SQL Group index can return wrong restult in half-bounded conditions - Fixes #50.
Date Fri, 04 Sep 2015 08:04:15 GMT
Repository: ignite
Updated Branches:
  refs/heads/master a00721056 -> 94039ecd1


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/94039ecd
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/94039ecd
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/94039ecd

Branch: refs/heads/master
Commit: 94039ecd1a9b122eee0f50fe4ccd693a307451d6
Parents: a007210
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:48:03 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/94039ecd/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/94039ecd/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