ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dma...@apache.org
Subject ignite git commit: IGNITE-4238: Added geospatial queries example
Date Thu, 17 Nov 2016 15:44:40 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 486f8900a -> 6287a0bee


IGNITE-4238: Added geospatial queries example


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6287a0be
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6287a0be
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6287a0be

Branch: refs/heads/master
Commit: 6287a0beeaa4b0dbb1f2393f98158c7a318ecc0f
Parents: 486f890
Author: Denis Magda <dmagda@gridgain.com>
Authored: Thu Nov 17 07:44:34 2016 -0800
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Thu Nov 17 07:44:34 2016 -0800

----------------------------------------------------------------------
 examples/pom-standalone-lgpl.xml                |  6 ++
 examples/pom.xml                                |  6 ++
 .../examples/datagrid/SpatialQueryExample.java  | 89 ++++++++++++++++++++
 .../SpatialQueryExampleMultiNodeSelfTest.java   | 14 +++
 .../examples/SpatialQueryExampleSelfTest.java   | 16 ++++
 .../IgniteLgplExamplesSelfTestSuite.java        |  4 +
 ...butedQueryStopOnCancelOrTimeoutSelfTest.java |  3 +-
 ...nCancelOrTimeoutDistributedJoinSelfTest.java |  3 +-
 8 files changed, 139 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6287a0be/examples/pom-standalone-lgpl.xml
----------------------------------------------------------------------
diff --git a/examples/pom-standalone-lgpl.xml b/examples/pom-standalone-lgpl.xml
index 7e7ccc2..3814672 100644
--- a/examples/pom-standalone-lgpl.xml
+++ b/examples/pom-standalone-lgpl.xml
@@ -165,6 +165,12 @@
                     <artifactId>ignite-schedule</artifactId>
                     <version>to_be_replaced_by_ignite_version</version>
                 </dependency>
+
+                <dependency>
+                    <groupId>org.apache.ignite</groupId>
+                    <artifactId>ignite-geospatial</artifactId>
+                    <version>to_be_replaced_by_ignite_version</version>
+                </dependency>
             </dependencies>
         </profile>
     </profiles>

http://git-wip-us.apache.org/repos/asf/ignite/blob/6287a0be/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index 5c4ead3..6f55560 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -74,6 +74,12 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-geospatial</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
             <groupId>com.google.code.simple-spring-memcached</groupId>
             <artifactId>spymemcached</artifactId>
             <version>2.7.3</version>

http://git-wip-us.apache.org/repos/asf/ignite/blob/6287a0be/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/SpatialQueryExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/SpatialQueryExample.java
b/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/SpatialQueryExample.java
new file mode 100644
index 0000000..cf484b2
--- /dev/null
+++ b/examples/src/main/java-lgpl/org/apache/ignite/examples/datagrid/SpatialQueryExample.java
@@ -0,0 +1,89 @@
+package org.apache.ignite.examples.datagrid;
+
+import com.vividsolutions.jts.geom.*;
+import com.vividsolutions.jts.io.*;
+import org.apache.ignite.*;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cache.query.annotations.*;
+import org.apache.ignite.configuration.*;
+
+import javax.cache.*;
+import java.util.*;
+import org.apache.ignite.examples.ExampleNodeStartup;
+
+/**
+ * This examples shows the usage of geospatial queries and indexes in Apache Ignite.
+ * For more information please refer to the following technical documentation:
+ * http://apacheignite.readme.io/docs/geospatial-queries
+ * <p>
+ * Remote nodes should be started using {@link ExampleNodeStartup} which will
+ * start node with {@code examples/config/example-ignite.xml} configuration.
+ */
+public class SpatialQueryExample {
+    /** Cache name. */
+    private static final String CACHE_NAME = SpatialQueryExample.class.getSimpleName();
+
+    /**
+     * @param args Command line arguments, none required.
+     */
+    public static void main(String[] args) throws Exception {
+        // Starting Ignite node.
+        try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
+            // Preparing the cache configuration.
+            CacheConfiguration<Integer, MapPoint> cc = new CacheConfiguration<>(CACHE_NAME);
+
+            // Setting the indexed types.
+            cc.setIndexedTypes(Integer.class, MapPoint.class);
+
+            // Starting the cache.
+            try (IgniteCache<Integer, MapPoint> cache = ignite.createCache(cc)) {
+                Random rnd = new Random();
+
+                WKTReader r = new WKTReader();
+
+                // Adding geometry points into the cache.
+                for (int i = 0; i < 1000; i++) {
+                    int x = rnd.nextInt(10000);
+                    int y = rnd.nextInt(10000);
+
+                    Geometry geo = r.read("POINT(" + x + " " + y + ")");
+
+                    cache.put(i, new MapPoint(geo));
+                }
+
+                // Query to fetch the points that fit into a specific polygon.
+                SqlQuery<Integer, MapPoint> query = new SqlQuery<>(MapPoint.class,
"coords && ?");
+
+                // Selecting points that fit into a specific polygon.
+                for (int i = 0; i < 10; i++) {
+                    // Defining the next polygon boundaries.
+                    Geometry cond = r.read("POLYGON((0 0, 0 " + rnd.nextInt(10000) + ", "
+
+                        rnd.nextInt(10000) + " " + rnd.nextInt(10000) + ", " +
+                        rnd.nextInt(10000) + " 0, 0 0))");
+
+                    // Executing the query.
+                    Collection<Cache.Entry<Integer, MapPoint>> entries = cache.query(query.setArgs(cond)).getAll();
+
+                    // Printing number of points that fit into the area defined by the polygon.
+                    System.out.println("Fetched points [cond=" + cond + ", cnt=" + entries.size()
+ ']');
+                }
+            }
+        }
+    }
+
+    /**
+     * MapPoint with indexed coordinates.
+     */
+    private static class MapPoint {
+        /** Coordinates. */
+        @QuerySqlField(index = true)
+        private Geometry coords;
+
+        /**
+         * @param coords Coordinates.
+         */
+        private MapPoint(Geometry coords) {
+            this.coords = coords;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/6287a0be/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleMultiNodeSelfTest.java
b/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleMultiNodeSelfTest.java
new file mode 100644
index 0000000..81a89c4
--- /dev/null
+++ b/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleMultiNodeSelfTest.java
@@ -0,0 +1,14 @@
+package org.apache.ignite.examples;
+
+import org.apache.ignite.examples.datagrid.SpatialQueryExample;
+
+/**
+ * * Tests {@link SpatialQueryExample} in the multi node mode.
+ */
+public class SpatialQueryExampleMultiNodeSelfTest extends SpatialQueryExampleSelfTest {
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        for (int i = 0; i < RMT_NODES_CNT; i++)
+            startGrid("node-" + i, "examples/config/example-ignite.xml");
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6287a0be/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleSelfTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleSelfTest.java
b/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleSelfTest.java
new file mode 100644
index 0000000..b5e1f40
--- /dev/null
+++ b/examples/src/test/java-lgpl/org/apache/ignite/examples/SpatialQueryExampleSelfTest.java
@@ -0,0 +1,16 @@
+package org.apache.ignite.examples;
+
+import org.apache.ignite.examples.datagrid.SpatialQueryExample;
+import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
+
+/**
+ * Tests {@link SpatialQueryExample}.
+ */
+public class SpatialQueryExampleSelfTest extends GridAbstractExamplesTest {
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSpatialQueryExample() throws Exception {
+        SpatialQueryExample.main(EMPTY_ARGS);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/6287a0be/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java
b/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java
index 7c99712..3c9101a 100644
--- a/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java
+++ b/examples/src/test/java-lgpl/org/apache/ignite/testsuites/IgniteLgplExamplesSelfTestSuite.java
@@ -20,6 +20,8 @@ package org.apache.ignite.testsuites;
 import junit.framework.TestSuite;
 import org.apache.ignite.examples.HibernateL2CacheExampleMultiNodeSelfTest;
 import org.apache.ignite.examples.HibernateL2CacheExampleSelfTest;
+import org.apache.ignite.examples.SpatialQueryExampleMultiNodeSelfTest;
+import org.apache.ignite.examples.SpatialQueryExampleSelfTest;
 import org.apache.ignite.testframework.GridTestUtils;
 
 import static org.apache.ignite.IgniteSystemProperties.IGNITE_OVERRIDE_MCAST_GRP;
@@ -39,9 +41,11 @@ public class IgniteLgplExamplesSelfTestSuite extends TestSuite {
         TestSuite suite = new TestSuite("Ignite Examples Test Suite");
 
         suite.addTest(new TestSuite(HibernateL2CacheExampleSelfTest.class));
+        suite.addTest(new TestSuite(SpatialQueryExampleSelfTest.class));
 
         // Multi-node.
         suite.addTest(new TestSuite(HibernateL2CacheExampleMultiNodeSelfTest.class));
+        suite.addTest(new TestSuite(SpatialQueryExampleMultiNodeSelfTest.class));
 
         return suite;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/6287a0be/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java
index 435cc59..87525f1 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest.java
@@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit;
 import javax.cache.CacheException;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.configuration.CacheConfiguration;
@@ -233,7 +234,7 @@ public class IgniteCacheDistributedQueryStopOnCancelOrTimeoutSelfTest
extends Gr
      * Validates clean state on all participating nodes after query cancellation.
      */
     @SuppressWarnings("unchecked")
-    private void checkCleanState() {
+    private void checkCleanState() throws IgniteCheckedException {
         for (int i = 0; i < GRIDS_CNT; i++) {
             IgniteEx grid = grid(i);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/6287a0be/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java
index c99837e..03a8d49 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest.java
@@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit;
 import javax.cache.CacheException;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.cache.query.QueryCancelledException;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
@@ -118,7 +119,7 @@ public class IgniteCacheQueryStopOnCancelOrTimeoutDistributedJoinSelfTest
extend
      * Validates clean state on all participating nodes after query cancellation.
      */
     @SuppressWarnings("unchecked")
-    private void checkCleanState() {
+    private void checkCleanState() throws IgniteCheckedException {
         for (int i = 0; i < GRID_CNT; i++) {
             IgniteEx grid = grid(i);
 


Mime
View raw message