Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support ST_Contains with H3 optimization #7252

Closed
wants to merge 5 commits into from

Conversation

vishwa35
Copy link

@vishwa35 vishwa35 commented Aug 4, 2021

Description

Adds a second H3IndexFilterOperator specifically for inclusions; the former was designed for distance/radius calculations.

As a part of this change, a number of functions and logic to estimate a resolution were added to the ScalarFunctions. A hardcoded value currently exists in L71 of H3InclusionIndexFilterOperator that should probably we sorted out.

It also enables ST_Contains on geography coordinates, as there isn't anything different about that from geometry that should prohibit that? The geo coords are isomorphic wrt cartesian coords.

Upgrade Notes

Does this PR prevent a zero down-time upgrade? (Assume upgrade order: Controller, Broker, Server, Minion)

  • Yes (Please label as backward-incompat, and complete the section below on Release Notes)

Does this PR fix a zero-downtime upgrade introduced earlier?

  • Yes (Please label this as backward-incompat, and complete the section below on Release Notes)

Does this PR otherwise need attention when creating release notes? Things to consider:

  • New configuration options
  • Deprecation of configurations
  • Signature changes to public methods/interfaces
  • New plugins added or old plugins removed
  • Yes (Please label this PR as release-notes and complete the section on Release Notes)

Release Notes

Documentation

@kishoreg kishoreg requested a review from yupeng9 August 5, 2021 06:42
Copy link
Member

@kishoreg kishoreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vishwa35 thank you for submitting this PR. Can you please add some test cases and also list sample queries in the PR description. We will also need to update the docs.

@@ -83,9 +82,6 @@ public TransformResultMetadata getResultMetadata() {
for (int i = 0; i < projectionBlock.getNumDocs(); i++) {
Geometry firstGeometry = GeometrySerializer.deserialize(firstValues[i]);
Geometry secondGeometry = GeometrySerializer.deserialize(secondValues[i]);
if (GeometryUtils.isGeography(firstGeometry) || GeometryUtils.isGeography(secondGeometry)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you remove this? performance?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is needed, the current implementation does not handle geography correctly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does it not work for geography?

@@ -33,6 +40,26 @@
*/
public class ScalarFunctions {

// from https://h3geo.org/docs/core-library/restable
private static final ImmutableMap<Double, Integer> RESOLUTIONS = ImmutableMap.<Double, Integer>builder()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz move this to geo util class

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add more comments about the meaning of the value

@@ -111,4 +138,35 @@ public static String stAsText(byte[] bytes) {
public static long geoToH3(double longitude, double latitude, int resolution) {
return H3Utils.H3_CORE.geoToH3(latitude, longitude, resolution);
}

public static List<Long> polygonToH3(List<Coordinate> region, int res) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadocs

return Math.sqrt(max);
}

public static double dist(Coordinate a, Coordinate b) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either make the unit an argument or add the unit as part of the func name

@@ -83,9 +82,6 @@ public TransformResultMetadata getResultMetadata() {
for (int i = 0; i < projectionBlock.getNumDocs(); i++) {
Geometry firstGeometry = GeometrySerializer.deserialize(firstValues[i]);
Geometry secondGeometry = GeometrySerializer.deserialize(secondValues[i]);
if (GeometryUtils.isGeography(firstGeometry) || GeometryUtils.isGeography(secondGeometry)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is needed, the current implementation does not handle geography correctly.

import org.roaringbitmap.buffer.MutableRoaringBitmap;

/**
* A filter operator that uses H3 index for geospatial data inclusion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz add comments about the algorithm used in this operator

// return filtered num_docs
MutableRoaringBitmap fullMatchDocIds = new MutableRoaringBitmap();
for (long docId : _h3Ids) {
fullMatchDocIds.or(_h3IndexReader.getDocIds(docId));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do you determine full matches?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add unit tests to verify the algorithm

* A filter operator that uses H3 index for geospatial data inclusion
*/
public class H3InclusionIndexFilterOperator extends BaseFilterOperator {
private static final String OPERATOR_NAME = "H3IndexFilterOperator";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make operator name consistent with the class name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants