You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2018/11/09 18:31:45 UTC

[geode] branch feature/GEODE-5998 created (now b03f8f6)

This is an automated email from the ASF dual-hosted git repository.

bschuchardt pushed a change to branch feature/GEODE-5998
in repository https://gitbox.apache.org/repos/asf/geode.git.


      at b03f8f6  GEODE-5998 geospatial support

This branch includes the following new commits:

     new b03f8f6  GEODE-5998 geospatial support

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[geode] 01/01: GEODE-5998 geospatial support

Posted by bs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bschuchardt pushed a commit to branch feature/GEODE-5998
in repository https://gitbox.apache.org/repos/asf/geode.git

commit b03f8f64c0c025440b502d0e9dadd57b78e3d7bb
Author: Bruce Schuchardt <bs...@pivotal.io>
AuthorDate: Fri Nov 9 10:29:58 2018 -0800

    GEODE-5998 geospatial support
    
    Fixing LGTM complaints
---
 .../org/apache/geode/redis/internal/Coder.java     |  6 ++--
 .../org/apache/geode/redis/internal/GeoCoder.java  | 35 ++++++++++++----------
 .../sortedset/GeoRadiusByMemberExecutor.java       |  8 +++--
 .../executor/sortedset/GeoRadiusExecutor.java      |  2 +-
 .../src/test/resources/expected-pom.xml            | 18 +++++------
 5 files changed, 38 insertions(+), 31 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/redis/internal/Coder.java b/geode-core/src/main/java/org/apache/geode/redis/internal/Coder.java
index 00d5619..c2586aa 100644
--- a/geode-core/src/main/java/org/apache/geode/redis/internal/Coder.java
+++ b/geode-core/src/main/java/org/apache/geode/redis/internal/Coder.java
@@ -162,7 +162,9 @@ public class Coder {
           response.writeBytes(tmp);
         }
       } finally {
-        tmp.release();
+        if (tmp != null) {
+          tmp.release();
+        }
       }
     }
 
@@ -480,7 +482,7 @@ public class Coder {
    * @return Parsed value
    * @throws NumberFormatException if bytes to string does not yield a convertible double
    */
-  public static Double bytesToDouble(byte[] bytes) {
+  public static double bytesToDouble(byte[] bytes) {
     return stringToDouble(bytesToString(bytes));
   }
 
diff --git a/geode-core/src/main/java/org/apache/geode/redis/internal/GeoCoder.java b/geode-core/src/main/java/org/apache/geode/redis/internal/GeoCoder.java
index f71dc2e..9125e05 100644
--- a/geode-core/src/main/java/org/apache/geode/redis/internal/GeoCoder.java
+++ b/geode-core/src/main/java/org/apache/geode/redis/internal/GeoCoder.java
@@ -19,6 +19,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
+import java.util.Objects;
 import java.util.Set;
 
 import com.github.davidmoten.geo.GeoHash;
@@ -89,16 +90,18 @@ public class GeoCoder {
         hash = element.getHash().get();
       }
 
-      if (distStr != "" || !coord.isEmpty() || hash != "") {
+      if (!Objects.equals(distStr, "") || !coord.isEmpty() || !Objects.equals(hash, "")) {
         List<Object> elementData = new ArrayList<>();
         elementData.add(name);
-        if (distStr != "")
+        if (!Objects.equals(distStr, "")) {
           elementData.add(distStr);
-        if (!coord.isEmpty())
+        }
+        if (!coord.isEmpty()) {
           elementData.add(coord);
-        if (hash != "")
+        }
+        if (!Objects.equals(hash, "")) {
           elementData.add(hash);
-
+        }
         responseElements.add(elementData);
       } else {
         responseElements.add(name);
@@ -125,14 +128,14 @@ public class GeoCoder {
    * @param hash2 geohash of second point
    * @return distance in meters
    */
-  public static Double geoDist(String hash1, String hash2) {
+  public static double geoDist(String hash1, String hash2) {
     LatLong coord1 = geoPos(hash1);
     LatLong coord2 = geoPos(hash2);
 
-    Double lat1 = Math.toRadians(coord1.getLat());
-    Double long1 = Math.toRadians(coord1.getLon());
-    Double lat2 = Math.toRadians(coord2.getLat());
-    Double long2 = Math.toRadians(coord2.getLon());
+    double lat1 = Math.toRadians(coord1.getLat());
+    double long1 = Math.toRadians(coord1.getLon());
+    double lat2 = Math.toRadians(coord2.getLat());
+    double long2 = Math.toRadians(coord2.getLon());
 
     return dist(long1, lat1, long2, lat2);
   }
@@ -145,8 +148,8 @@ public class GeoCoder {
    * @return geohash as base32
    */
   public static String geohash(byte[] lon, byte[] lat) throws IllegalArgumentException {
-    Double longitude = Coder.bytesToDouble(lon);
-    Double latitude = Coder.bytesToDouble(lat);
+    double longitude = Coder.bytesToDouble(lon);
+    double latitude = Coder.bytesToDouble(lat);
     return GeoHash.encodeHash(latitude, longitude);
   }
 
@@ -184,15 +187,15 @@ public class GeoCoder {
     return new HashArea(minlon, maxlon, minlat, maxlat);
   }
 
-  public static Double dist(Double long1, Double lat1, Double long2, Double lat2) {
-    Double hav =
+  public static double dist(double long1, double lat1, double long2, double lat2) {
+    double hav =
         haversine(lat2 - lat1) + (Math.cos(lat1) * Math.cos(lat2) * haversine(long2 - long1));
-    Double distAngle = Math.acos(1 - (2 * hav));
+    double distAngle = Math.acos(1 - (2 * hav));
 
     return EARTH_RADIUS_IN_METERS * distAngle;
   }
 
-  public static double haversine(Double rad) {
+  public static double haversine(double rad) {
     return 0.5 * (1 - Math.cos(rad));
   }
 
diff --git a/geode-core/src/main/java/org/apache/geode/redis/internal/executor/sortedset/GeoRadiusByMemberExecutor.java b/geode-core/src/main/java/org/apache/geode/redis/internal/executor/sortedset/GeoRadiusByMemberExecutor.java
index 6579236..86fb115 100644
--- a/geode-core/src/main/java/org/apache/geode/redis/internal/executor/sortedset/GeoRadiusByMemberExecutor.java
+++ b/geode-core/src/main/java/org/apache/geode/redis/internal/executor/sortedset/GeoRadiusByMemberExecutor.java
@@ -87,11 +87,12 @@ public class GeoRadiusByMemberExecutor extends GeoSortedSetExecutor {
           String name = point.get("key").toString();
           String hash = point.get("value").toString();
 
-          Double dist = GeoCoder.geoDist(params.centerHashPrecise, hash) * params.distScale;
+          double dist = GeoCoder.geoDist(params.centerHashPrecise, hash) * params.distScale;
 
           // Post-filter for accuracy
-          if (dist > (params.radius * params.distScale))
+          if (dist > (params.radius * params.distScale)) {
             continue;
+          }
 
           Optional<LatLong> coord =
               params.withCoord ? Optional.of(GeoCoder.geoPos(hash)) : Optional.empty();
@@ -100,8 +101,9 @@ public class GeoRadiusByMemberExecutor extends GeoSortedSetExecutor {
 
           // Because of the way hashing works, sometimes you can get the same requested member back
           // in the results
-          if (!name.equals(params.member))
+          if (!name.equals(params.member)) {
             results.add(new GeoRadiusResponseElement(name, coord, dist, params.withDist, hashOpt));
+          }
         }
       } catch (Exception e) {
         command.setResponse(Coder.getErrorResponse(context.getByteBufAllocator(), e.getMessage()));
diff --git a/geode-core/src/main/java/org/apache/geode/redis/internal/executor/sortedset/GeoRadiusExecutor.java b/geode-core/src/main/java/org/apache/geode/redis/internal/executor/sortedset/GeoRadiusExecutor.java
index 6b160b6..7435758 100644
--- a/geode-core/src/main/java/org/apache/geode/redis/internal/executor/sortedset/GeoRadiusExecutor.java
+++ b/geode-core/src/main/java/org/apache/geode/redis/internal/executor/sortedset/GeoRadiusExecutor.java
@@ -85,7 +85,7 @@ public class GeoRadiusExecutor extends GeoSortedSetExecutor {
           String name = point.get("key").toString();
           String hash = point.get("value").toString();
 
-          Double dist = GeoCoder.geoDist(params.centerHashPrecise, hash) * params.distScale;
+          double dist = GeoCoder.geoDist(params.centerHashPrecise, hash) * params.distScale;
 
           // Post-filter for accuracy
           if (dist > (params.radius * params.distScale))
diff --git a/geode-rebalancer/src/test/resources/expected-pom.xml b/geode-rebalancer/src/test/resources/expected-pom.xml
index a693457..38bee0d 100644
--- a/geode-rebalancer/src/test/resources/expected-pom.xml
+++ b/geode-rebalancer/src/test/resources/expected-pom.xml
@@ -19,7 +19,7 @@
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.apache.geode</groupId>
   <artifactId>geode-rebalancer</artifactId>
-  <version>1.8.0-SNAPSHOT</version>
+  <version>1.9.0-SNAPSHOT</version>
   <name>Apache Geode</name>
   <description>Apache Geode provides a database-like consistency model, reliable transaction processing and a shared-nothing architecture to maintain very low latency performance with high concurrency processing</description>
   <url>http://geode.apache.org</url>
@@ -36,21 +36,21 @@
   </scm>
   <dependencies>
     <dependency>
-      <groupId>org.apache.logging.log4j</groupId>
-      <artifactId>log4j-api</artifactId>
-      <version>2.11.0</version>
-      <scope>compile</scope>
-    </dependency>
-    <dependency>
       <groupId>org.apache.geode</groupId>
       <artifactId>geode-common</artifactId>
-      <version>1.8.0-SNAPSHOT</version>
+      <version>1.9.0-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.geode</groupId>
       <artifactId>geode-core</artifactId>
-      <version>1.8.0-SNAPSHOT</version>
+      <version>1.9.0-SNAPSHOT</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-api</artifactId>
+      <version>2.11.0</version>
       <scope>compile</scope>
     </dependency>
     <dependency>