usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [33/50] [abbrv] git commit: Updated count logic
Date Fri, 13 Jun 2014 18:54:12 GMT
Updated count logic


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

Branch: refs/heads/master
Commit: cb4dfa02c6e324999c0b439074be0020125d7e64
Parents: 19cf0cd
Author: Todd Nine <tnine@apigee.com>
Authored: Thu Jun 12 10:03:16 2014 -0600
Committer: Todd Nine <tnine@apigee.com>
Committed: Thu Jun 12 10:03:16 2014 -0600

----------------------------------------------------------------------
 .../persistence/cassandra/QueryProcessor.java   | 68 ++++++++++----------
 .../usergrid/persistence/CollectionIT.java      | 61 ++++++++++++++++++
 2 files changed, 95 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb4dfa02/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/QueryProcessor.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/QueryProcessor.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/QueryProcessor.java
index 6c655d8..f6d5bd6 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/QueryProcessor.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/QueryProcessor.java
@@ -26,6 +26,7 @@ import java.util.UUID;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
 import org.apache.usergrid.persistence.EntityManager;
 import org.apache.usergrid.persistence.Identifier;
 import org.apache.usergrid.persistence.Query;
@@ -245,10 +246,8 @@ public class QueryProcessor {
 
     /**
      * Return the node id from the cursor cache
-     * @param nodeId
-     * @return
      */
-    public ByteBuffer getCursorCache(int nodeId){
+    public ByteBuffer getCursorCache( int nodeId ) {
         return cursorCache.getCursorBytes( nodeId );
     }
 
@@ -263,7 +262,9 @@ public class QueryProcessor {
     }
 
 
-    /** Return the iterator results, ordered if required */
+    /**
+     * Return the iterator results, ordered if required
+     */
     public Results getResults( SearchVisitor visitor ) throws Exception {
         // if we have no order by just load the results
 
@@ -292,8 +293,9 @@ public class QueryProcessor {
                 itr.finalizeCursor( resultsCursor, entityIds.get( resultSize - 1 ).getUUID()
);
             }
         }
-        if (logger.isDebugEnabled()) {
-        	logger.debug("Getting result for query: [{}],  returning entityIds size: {}", getQuery(),
entityIds.size());
+        if ( logger.isDebugEnabled() ) {
+            logger.debug( "Getting result for query: [{}],  returning entityIds size: {}",
getQuery(),
+                    entityIds.size() );
         }
 
         final ResultsLoader loader = loaderFactory.getResultsLoader( em, query, query.getResultsLevel()
);
@@ -324,7 +326,9 @@ public class QueryProcessor {
         private int contextCount = -1;
 
 
-        /** Get the root node in our tree for runtime evaluation */
+        /**
+         * Get the root node in our tree for runtime evaluation
+         */
         public QueryNode getRootNode() {
             return nodes.peek();
         }
@@ -395,7 +399,7 @@ public class QueryProcessor {
             QueryNode leftResult = nodes.pop();
 
             // rewrite with the new Or operand
-            OrNode orNode = new OrNode( leftResult, rightResult,  ++contextCount );
+            OrNode orNode = new OrNode( leftResult, rightResult, ++contextCount );
 
             nodes.push( orNode );
         }
@@ -597,7 +601,9 @@ public class QueryProcessor {
         }
 
 
-        /** The new slice node */
+        /**
+         * The new slice node
+         */
         private SliceNode newSliceNode() {
             SliceNode sliceNode = new SliceNode( ++contextCount );
 
@@ -607,7 +613,9 @@ public class QueryProcessor {
         }
 
 
-        /** Create a new slice if one will be required within the context of this node */
+        /**
+         * Create a new slice if one will be required within the context of this node
+         */
         private void createNewSlice( Operand child ) {
             if ( child instanceof EqualityOperand || child instanceof AndOperand || child
instanceof ContainsOperand ) {
                 newSliceNode();
@@ -627,48 +635,38 @@ public class QueryProcessor {
         private static final long serialVersionUID = 1L;
 
 
-        /* (non-Javadoc)
-         * @see java.util.Stack#pop()
-         */
         @Override
-        public synchronized T pop() {
-            T entry = super.pop();
-
+        public T push( final T entry ) {
             if ( entry instanceof SliceNode ) {
-                count += ( ( SliceNode ) entry ).getAllSlices().size();
+                //by definition a slicenode has a size.  Some have nothing to indicate full
range scans, but they still count
+                //as an operand
+                count += Math.max(( ( SliceNode ) entry ).getAllSlices().size(), 1);
+            }
+            //not node creates a subraction, this needs to increase the count
+            else if ( entry instanceof NotNode ) {
+                count ++;
             }
 
-            return entry;
+            return super.push( entry );    //To change body of overridden methods use File
| Settings | File Templates.
         }
 
 
         public int getSliceCount() {
-
-            Iterator<T> itr = this.iterator();
-
-            T entry;
-
-            while ( itr.hasNext() ) {
-                entry = itr.next();
-
-                if ( entry instanceof SliceNode ) {
-                    count += ( ( SliceNode ) entry ).getAllSlices().size();
-                }
-            }
-
             return count;
         }
     }
 
 
-    /** @return the pageSizeHint */
+    /**
+     * @return the pageSizeHint
+     */
     public int getPageSizeHint( QueryNode node ) {
         /*****
          * DO NOT REMOVE THIS PIECE OF CODE!!!!!!!!!!!
          * It is crucial that the root iterator only needs the result set size per page
          * otherwise our cursor logic will fail when passing cursor data to the leaf nodes
          *******/
-        if(node == rootNode){
+        if ( node == rootNode ) {
             return size;
         }
 
@@ -676,7 +674,9 @@ public class QueryProcessor {
     }
 
 
-    /** Generate a slice node with scan ranges for all the properties in our sort cache */
+    /**
+     * Generate a slice node with scan ranges for all the properties in our sort cache
+     */
     private OrderByNode generateSorts( int opCount ) throws NoIndexException {
 
         // the value is irrelevant since we'll only ever have 1 slice node

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb4dfa02/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
index a09e696..ac58bd7 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
@@ -744,6 +744,67 @@ public class CollectionIT extends AbstractCoreIT {
         query = Query.fromQL( "select * where keywords contains 'foobar' AND NOT keywords
contains 'test'" );
         r = em.searchCollection( em.getApplicationRef(), "games", query );
         assertEquals( 0, r.size() );
+
+        //search where we don't have a value, should return no results and no cursor
+        query = Query.fromQL( "select * where NOT title = 'FooBar'" );
+        r = em.searchCollection( em.getApplicationRef(), "games", query);
+        assertEquals(2, r.size());
+        assertNull(r.getCursor());
+
+    }
+
+
+    @Test
+    public void notSubObjectQuery() throws Exception {
+        UUID applicationId = setup.createApplication( "testOrganization", "notSubObjectQuery"
);
+        assertNotNull( applicationId );
+
+        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+        assertNotNull( em );
+
+
+        Map<String, Object> subObject = new LinkedHashMap<String, Object>();
+        subObject.put( "subField", "Foo" );
+
+        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+        properties.put( "subObjectArray", new Map[] { subObject } );
+
+        Entity entity1 = em.create( "game", properties );
+        assertNotNull( entity1 );
+
+
+        Entity entity2 = em.create( "game", properties );
+        assertNotNull( entity2 );
+
+
+        // simple not
+        Query query = Query.fromQL( "select * where NOT subObjectArray.subField = 'Foo'"
).withLimit( 1 );
+        Results r = em.searchCollection( em.getApplicationRef(), "games", query );
+        assertEquals( 0, r.size() );
+        assertNull( r.getCursor() );
+
+
+        // full negation in simple with lower limit
+        query = Query.fromQL( "select * where NOT subObjectArray.subField = 'Bar'" ).withLimit(
1 );
+        r = em.searchCollection( em.getApplicationRef(), "games", query );
+        assertEquals( 1, r.size() );
+        assertNotNull( r.getCursor() );
+        assertEquals( entity1, r.getEntities().get( 0 ) );
+
+
+        query = Query.fromQL( "select * where NOT subObjectArray.subField = 'Bar'" ).withLimit(
1 )
+                     .withCursor( r.getCursor() );
+        r = em.searchCollection( em.getApplicationRef(), "games", query );
+        assertEquals( 1, r.size() );
+        assertNotNull( r.getCursor() );
+        assertEquals( entity2, r.getEntities().get( 0 ) );
+
+        query = Query.fromQL( "select * where NOT subObjectArray.subField = 'Bar'" ).withLimit(
1 )
+                     .withCursor( r.getCursor() );
+        r = em.searchCollection( em.getApplicationRef(), "games", query );
+        assertEquals( 0, r.size() );
+        assertNull( r.getCursor() );
+
     }
 
 


Mime
View raw message