[GitHub] [carbondata] kumarvishal09 commented on a change in pull request #3481: [CARBONDATA-3548]Geospatial Support: add hash id create,query condition analyze and generate hash id list

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] [carbondata] kumarvishal09 commented on a change in pull request #3481: [CARBONDATA-3548]Geospatial Support: add hash id create,query condition analyze and generate hash id list

GitBox
kumarvishal09 commented on a change in pull request #3481: [CARBONDATA-3548]Geospatial Support: add hash id create,query condition analyze and generate hash id list
URL: https://github.com/apache/carbondata/pull/3481#discussion_r355848837
 
 

 ##########
 File path: geo/src/main/java/org/apache/carbondata/geo/GeoHashImpl.java
 ##########
 @@ -164,20 +231,151 @@ public String generate(List<?> sources) throws Exception {
     if (!(sources.get(0) instanceof Long) || !(sources.get(1) instanceof Long)) {
       throw new RuntimeException("Source columns must be of Long type.");
     }
-    //TODO: generate geohashId
-    return String.valueOf(0);
+    Long longitude = (Long) sources.get(0);
+    Long latitude  = (Long) sources.get(1);
+    // generate the hash code
+    int[] gridPoint = calculateID(longitude, latitude);
+    Long hashId = createHashID(gridPoint[0], gridPoint[1]);
+    return String.valueOf(hashId);
   }
 
   /**
    * Query processor for GeoHash.
-   * @param polygon
+   * example: (`LONGITUDE`, `LATITUDE`, '116270714,40112476;116217155,40028403;
+   * 116337318,39927378;116459541,39966859;116447868,40076233;116385384,40129279;')
+   * @param polygon a group of pints, close out to form an area
    * @return Returns list of ranges of GeoHash IDs
    * @throws Exception
    */
   @Override
   public List<Long[]> query(String polygon) throws Exception {
-    List<Long[]> rangeList = new ArrayList<Long[]>();
-    // TODO: process the polygon coordinates and generate the list of ranges of GeoHash IDs
-    return rangeList;
+    String[] pointList = polygon.split(";");
+    if (3  > pointList.length) {
+      throw new RuntimeException("polygon need at least 3 points, really has " + pointList.length);
+    } else {
+      List<double[]> queryList = new ArrayList<>();
+      for (String str: pointList) {
+        String[] points = str.split(",");
+        if (2 != points.length) {
+          throw new RuntimeException("longitude and latitude is a pair need 2 data");
+        } else {
+          try {
+            queryList.add(new double[] {Double.valueOf(points[0]), Double.valueOf(points[1])});
+          } catch (ClassCastException e) {
 
 Review comment:
   Catch NumberFormatException , Double.valueOf will throw Number format exception if data is not valid double value

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services