You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2014/08/29 19:31:07 UTC

[02/19] git commit: New GeoQueryOrTest to test using or in a geo query.

New GeoQueryOrTest to test using or in a geo query.


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

Branch: refs/heads/USERGRID-188
Commit: 718c0fe08a762e9b76e7f3ca2c6bde1b89399e5f
Parents: f22d67a
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Aug 26 16:12:32 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Aug 26 16:12:32 2014 -0400

----------------------------------------------------------------------
 .../org/apache/usergrid/persistence/GeoIT.java  |   1 -
 .../usergrid/persistence/GeoQueryOrTest.java    | 111 +++++++++++++++++++
 2 files changed, 111 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/718c0fe0/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
index 42e5c2b..36b288b 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
@@ -30,7 +30,6 @@ import org.slf4j.LoggerFactory;
 
 import org.apache.usergrid.AbstractCoreIT;
 import org.apache.usergrid.cassandra.Concurrent;
-import org.apache.usergrid.persistence.geo.EntityLocationRef;
 import org.apache.usergrid.persistence.geo.model.Point;
 import org.apache.usergrid.persistence.index.query.Query;
 import org.apache.usergrid.utils.MapUtils;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/718c0fe0/stack/core/src/test/java/org/apache/usergrid/persistence/GeoQueryOrTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoQueryOrTest.java b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoQueryOrTest.java
new file mode 100644
index 0000000..7acc4f7
--- /dev/null
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoQueryOrTest.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.persistence;
+
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.AbstractCoreIT;
+import org.apache.usergrid.cassandra.Concurrent;
+import org.apache.usergrid.persistence.geo.model.Point;
+import org.apache.usergrid.persistence.index.query.Query;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+
+@Concurrent()
+public class GeoQueryOrTest extends AbstractCoreIT {
+    private static final Logger LOG = LoggerFactory.getLogger( GeoQueryOrTest.class );
+
+
+    public GeoQueryOrTest() {
+        super();
+    }
+
+
+    @Test
+    public void testGeoQueryWithOr() throws Exception {
+
+        LOG.info( "GeoIT.testGeoQueryWithOr" );
+
+        UUID applicationId = setup.createApplication( "testOrganization", "testGeoQueryWithOr" );
+        assertNotNull( applicationId );
+
+        EntityManager em = setup.getEmf().getEntityManager( applicationId );
+        assertNotNull( em );
+
+        // create two users at a location
+
+        Map<String, Object> properties = new LinkedHashMap<String, Object>() {{
+            put( "username", "ed" );
+            put( "employer", "Apigee" );
+            put( "email", "ed@example.com" );
+            put( "location", new LinkedHashMap<String, Object>() {{
+                put("latitude", 37.776753 );
+                put("longitude", -122.407846 );
+            }} ); 
+        }};
+
+        Entity user1 = em.create( "user", properties );
+        assertNotNull( user1 );
+
+        properties = new LinkedHashMap<String, Object>() {{
+            put( "username", "fred" );
+            put( "employer", "Microsoft" );
+            put( "email", "fred@example.com" );
+            put( "location", new LinkedHashMap<String, Object>() {{
+                put("latitude", 37.776753 );
+                put("longitude", -122.407846 );
+            }} ); 
+        }};
+
+        Entity user2 = em.create( "user", properties );
+        assertNotNull( user2 );
+
+        em.refreshIndex();
+
+        // define center point about 300m from that location
+        Point center = new Point( 37.774277, -122.404744 );
+
+        Query query = Query.fromQL( "select * where location within 400 of " 
+                                    + center.getLat() + "," + center.getLon());
+        Results listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+        assertEquals( 2, listResults.size() );
+
+        query = Query.fromQL( "select * where employer='Apigee' or location within 100 of " 
+                                    + center.getLat() + "," + center.getLon());
+        listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+
+        // no results because geo filter applied after query even in the case or 'or'
+        assertEquals( 0, listResults.size() );
+
+        query = Query.fromQL( "select * where employer='Apigee' or location within 400 of " 
+                                    + center.getLat() + "," + center.getLon());
+        listResults = em.searchCollection( em.getApplicationRef(), "users", query );
+
+        // only one result because geo filter applied after query even in the case or 'or'
+        assertEquals( 1, listResults.size() );
+    }
+
+}