ajantha-bhat 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_r356546052
 
 

 ##########
 File path: geo/src/main/java/org/apache/carbondata/geo/GeoHashImpl.java
 ##########
 @@ -168,20 +238,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 (NumberFormatException e) {
+            throw new RuntimeException("can not covert the string data to 
double", e);
+          }
+        }
+      }
+      if (3 > queryList.size()) {
 
 Review comment:
   already validated in line 260,  why again need to validate ?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to