You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2021/07/23 21:26:29 UTC

[GitHub] [pinot] Jackie-Jiang commented on a change in pull request #7182: Add the support of get_hexagon_addr function

Jackie-Jiang commented on a change in pull request #7182:
URL: https://github.com/apache/pinot/pull/7182#discussion_r675872695



##########
File path: pinot-core/src/main/java/org/apache/pinot/core/geospatial/transform/function/GeoToH3Function.java
##########
@@ -0,0 +1,119 @@
+/**
+ * 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.pinot.core.geospatial.transform.function;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.core.operator.transform.function.BaseTransformFunction;
+import org.apache.pinot.core.operator.transform.function.LiteralTransformFunction;
+import org.apache.pinot.core.operator.transform.function.TransformFunction;
+import org.apache.pinot.core.plan.DocIdSetPlanNode;
+import org.apache.pinot.segment.local.utils.GeometrySerializer;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.locationtech.jts.geom.Geometry;
+
+
+/**
+ *  A function that returns the H3 index address of a given geolocation.
+ */
+public class GeoToH3Function extends BaseTransformFunction {
+  public static final String FUNCTION_NAME = "geoToH3";
+  private TransformFunction _firstArgument;
+  private TransformFunction _secondArgument;
+  private TransformFunction _thirdArgument;
+  private long[] _results;

Review comment:
       You should be able to directly use the `_longValuesSV` within the `BaseTransformFunction`

##########
File path: pinot-common/src/main/java/org/apache/pinot/common/function/TransformFunctionType.java
##########
@@ -87,7 +87,10 @@
 
   // Geo relationship
   ST_CONTAINS("ST_Contains"),
-  ST_EQUALS("ST_Equals");
+  ST_EQUALS("ST_Equals"),
+
+  // Geo indexing
+  geoToH3("geoToH3");

Review comment:
       We need all capital case without underscore to make the `getTransformFunctionType()` work
   ```suggestion
     GEOTOH3("geoToH3");
   ```

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/geospatial/transform/function/ScalarFunctions.java
##########
@@ -98,4 +99,16 @@ public static String stAsText(byte[] bytes) {
     GeometryUtils.setGeometry(geometry);
     return GeometrySerializer.serialize(geometry);
   }
+
+  /**
+   * Gets the H3 hexagon address from the location
+   * @param latitude latitude of the location
+   * @param longitude longitude of the location
+   * @param resolution H3 index resolution
+   * @return the H3 index address
+   */
+  @ScalarFunction
+  public static long geoToH3(double longitude, double latitude, int resolution) {
+    return H3Utils.H3_CORE.geoToH3(latitude, longitude, resolution);
+  }

Review comment:
       We should also add the version with 2 arguments: `geoToH3(byte[] bytes, int resolution)`

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/geospatial/transform/function/GeoToH3Function.java
##########
@@ -0,0 +1,119 @@
+/**
+ * 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.pinot.core.geospatial.transform.function;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.core.operator.blocks.ProjectionBlock;
+import org.apache.pinot.core.operator.transform.TransformResultMetadata;
+import org.apache.pinot.core.operator.transform.function.BaseTransformFunction;
+import org.apache.pinot.core.operator.transform.function.LiteralTransformFunction;
+import org.apache.pinot.core.operator.transform.function.TransformFunction;
+import org.apache.pinot.core.plan.DocIdSetPlanNode;
+import org.apache.pinot.segment.local.utils.GeometrySerializer;
+import org.apache.pinot.segment.spi.datasource.DataSource;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.locationtech.jts.geom.Geometry;
+
+
+/**
+ *  A function that returns the H3 index address of a given geolocation.

Review comment:
       Put some javadoc on for the supported arguments




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org