usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [14/42] git commit: Fixes advance logic and page count in merge iterator. Fixes reset in Union iterator
Date Wed, 05 Feb 2014 01:21:24 GMT
Fixes advance logic and page count in merge iterator.  Fixes reset in Union iterator


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2303624a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2303624a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2303624a

Branch: refs/pull/29/merge
Commit: 2303624a1e428201072f5fce1464dd2a45b07d36
Parents: 16455b8
Author: Todd Nine <tnine@apigee.com>
Authored: Fri Jan 24 13:01:33 2014 -0800
Committer: Todd Nine <tnine@apigee.com>
Committed: Tue Jan 28 18:36:11 2014 -0700

----------------------------------------------------------------------
 .../query/ir/result/MergeIterator.java          | 19 +++--
 .../query/ir/result/UnionIterator.java          | 15 ++++
 .../query/ir/result/UnionIteratorTest.java      | 88 ++++++++++++++++++++
 3 files changed, 114 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2303624a/stack/core/src/main/java/org/usergrid/persistence/query/ir/result/MergeIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/query/ir/result/MergeIterator.java
b/stack/core/src/main/java/org/usergrid/persistence/query/ir/result/MergeIterator.java
index 46807e1..e09cff5 100644
--- a/stack/core/src/main/java/org/usergrid/persistence/query/ir/result/MergeIterator.java
+++ b/stack/core/src/main/java/org/usergrid/persistence/query/ir/result/MergeIterator.java
@@ -62,24 +62,27 @@ public abstract class MergeIterator implements ResultIterator {
     @Override
     public boolean hasNext() {
         //if next isn't set, try to advance
-        if ( next == null ) {
-            doAdvance();
+        if(next != null){
+            return true;
         }
 
-        boolean results = next != null && next.size() > 0;
 
-        if ( results ) {
-            last = next;
-            loadCount++;
-        }
+        doAdvance();
+
 
-        return results;
+        return next != null;
     }
 
 
     /** Advance to the next page */
     protected void doAdvance() {
         next = advance();
+
+
+        if ( next != null && next.size() > 0 ) {
+            last = next;
+            loadCount++;
+        }
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2303624a/stack/core/src/main/java/org/usergrid/persistence/query/ir/result/UnionIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/usergrid/persistence/query/ir/result/UnionIterator.java
b/stack/core/src/main/java/org/usergrid/persistence/query/ir/result/UnionIterator.java
index c7b31d1..01daf36 100644
--- a/stack/core/src/main/java/org/usergrid/persistence/query/ir/result/UnionIterator.java
+++ b/stack/core/src/main/java/org/usergrid/persistence/query/ir/result/UnionIterator.java
@@ -120,6 +120,16 @@ public class UnionIterator extends MultiIterator {
     }
 
 
+    @Override
+    public void doReset() {
+        //reset sub iterators if we need to
+        super.doReset();
+
+        list.reset();
+
+    }
+
+
     /**
      * A Sorted Set with a max size. When a new entry is added, the max is removed.  You
can mark the next "min" by
      * calling the mark method.  Values > min are accepted.  Values > min and that
are over size are discarded
@@ -224,6 +234,11 @@ public class UnionIterator extends MultiIterator {
         public void clear() {
             this.list.clear();
         }
+
+        public void reset(){
+            clear();
+            this.min = null;
+        }
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2303624a/stack/core/src/test/java/org/usergrid/persistence/query/ir/result/UnionIteratorTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/usergrid/persistence/query/ir/result/UnionIteratorTest.java
b/stack/core/src/test/java/org/usergrid/persistence/query/ir/result/UnionIteratorTest.java
index 8fd9ea8..24851e3 100644
--- a/stack/core/src/test/java/org/usergrid/persistence/query/ir/result/UnionIteratorTest.java
+++ b/stack/core/src/test/java/org/usergrid/persistence/query/ir/result/UnionIteratorTest.java
@@ -365,6 +365,94 @@ public class UnionIteratorTest {
     }
 
 
+    @Test
+    public void resetCorrect() {
+
+        UUID id1 = UUIDUtils.minTimeUUID( 1 );
+        UUID id2 = UUIDUtils.minTimeUUID( 2 );
+        UUID id3 = UUIDUtils.minTimeUUID( 3 );
+        UUID id4 = UUIDUtils.minTimeUUID( 4 );
+        UUID id5 = UUIDUtils.minTimeUUID( 5 );
+        UUID id6 = UUIDUtils.minTimeUUID( 6 );
+        UUID id7 = UUIDUtils.minTimeUUID( 75 );
+
+
+        UnionIterator union = new UnionIterator( 5, 0, null );
+
+        InOrderIterator first = new InOrderIterator( 100 );
+        first.add( id3 );
+        first.add( id6 );
+        first.add( id4 );
+
+
+        InOrderIterator second = new InOrderIterator( 100 );
+        second.add( id7 );
+        second.add( id1 );
+        second.add( id2 );
+        second.add( id5 );
+
+
+        union.addIterator( first );
+        union.addIterator( second );
+
+
+        // now make sure it's right, only 1, 3 and 8 intersect
+        assertTrue( union.hasNext() );
+
+        Set<ScanColumn> ids = union.next();
+
+
+        assertEquals(5, ids.size());
+
+        // now make sure it's right, only 1, 3 and 8 intersect
+        assertTrue( ids.contains( uuidColumn( id1 ) ) );
+        assertTrue( ids.contains( uuidColumn( id2 ) ) );
+        assertTrue( ids.contains( uuidColumn( id3 ) ) );
+        assertTrue( ids.contains( uuidColumn( id4 ) ) );
+        assertTrue( ids.contains( uuidColumn( id5 ) ) );
+
+        ids = union.next();
+
+
+        assertEquals(2, ids.size());
+
+        assertTrue( ids.contains( uuidColumn( id6 ) ) );
+        assertTrue( ids.contains( uuidColumn( id7 ) ) );
+
+        //now try to get the next page
+        ids = union.next();
+        assertNull( ids );
+
+        //now reset and re-test
+        union.reset();
+
+        ids = union.next();
+
+        assertEquals(5, ids.size());
+
+
+        // now make sure it's right, only 1, 3 and 8 intersect
+        assertTrue( ids.contains( uuidColumn( id1 ) ) );
+        assertTrue( ids.contains( uuidColumn( id2 ) ) );
+        assertTrue( ids.contains( uuidColumn( id3 ) ) );
+        assertTrue( ids.contains( uuidColumn( id4 ) ) );
+        assertTrue( ids.contains( uuidColumn( id5 ) ) );
+
+
+        ids = union.next();
+
+        assertEquals(2, ids.size());
+
+        assertTrue( ids.contains( uuidColumn( id6 ) ) );
+        assertTrue( ids.contains( uuidColumn( id7 ) ) );
+
+
+        //now try to get the next page
+        ids = union.next();
+        assertNull( ids );
+    }
+
+
     private void reverse( UUID[] array ) {
 
         UUID temp = null;


Mime
View raw message