-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
There was a problem hiding this 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)) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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?
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)
backward-incompat
, and complete the section below on Release Notes)Does this PR fix a zero-downtime upgrade introduced earlier?
backward-incompat
, and complete the section below on Release Notes)Does this PR otherwise need attention when creating release notes? Things to consider:
release-notes
and complete the section on Release Notes)Release Notes
Documentation