Skip to content

Commit

Permalink
upgrade h3 lib from 3.7.2 to 4.0.0 to lower glibc requirement (#9335)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangfu0 committed Sep 4, 2022
1 parent f652609 commit dd5f5d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
*/
package org.apache.pinot.segment.local.utils;

import com.uber.h3core.H3Core;
import com.uber.h3core.exceptions.LineUndefinedException;
import com.uber.h3core.util.GeoCoord;
import com.uber.h3core.H3CoreV3;
import com.uber.h3core.util.LatLng;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import it.unimi.dsi.fastutil.longs.LongList;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
Expand All @@ -44,13 +43,13 @@ public class H3Utils {
private H3Utils() {
}

public static final H3Core H3_CORE;
public static final H3CoreV3 H3_CORE;

static {
try {
H3_CORE = H3Core.newInstance();
H3_CORE = H3CoreV3.newInstance();
} catch (IOException e) {
throw new RuntimeException("Failed to instantiate H3 instance", e);
throw new RuntimeException("Failed to instantiate H3 V3 instance", e);
}
}

Expand All @@ -63,7 +62,7 @@ private static LongSet coverLineInH3(LineString lineString, int resolution) {
for (int i = 0; i < endpointH3Cells.size() - 1; i++) {
try {
coveringH3Cells.addAll(H3_CORE.h3Line(endpointH3Cells.getLong(i), endpointH3Cells.getLong(i + 1)));
} catch (LineUndefinedException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Expand All @@ -72,7 +71,7 @@ private static LongSet coverLineInH3(LineString lineString, int resolution) {

private static Pair<LongSet, LongSet> coverPolygonInH3(Polygon polygon, int resolution) {
List<Long> polyfillCells = H3_CORE.polyfill(Arrays.stream(polygon.getExteriorRing().getCoordinates())
.map(coordinate -> new GeoCoord(coordinate.y, coordinate.x)).collect(Collectors.toList()),
.map(coordinate -> new LatLng(coordinate.y, coordinate.x)).collect(Collectors.toList()),
Collections.emptyList(), resolution);
// TODO: this can be further optimized to use native H3 implementation. They have plan to support natively.
// https://github.com/apache/pinot/issues/8547
Expand All @@ -96,7 +95,7 @@ private static Pair<LongSet, LongSet> coverPolygonInH3(Polygon polygon, int reso
}

private static Polygon createPolygonFromH3Cell(long h3Cell) {
List<GeoCoord> boundary = H3_CORE.h3ToGeoBoundary(h3Cell);
List<LatLng> boundary = H3_CORE.h3ToGeoBoundary(h3Cell);
boundary.add(boundary.get(0));
return GeometryUtils.GEOMETRY_FACTORY.createPolygon(
boundary.stream().map(geoCoord -> new Coordinate(geoCoord.lng, geoCoord.lat)).toArray(Coordinate[]::new));
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<netty.version>4.1.79.Final</netty.version>
<reactivestreams.version>1.0.3</reactivestreams.version>
<jts.version>1.16.1</jts.version>
<h3.version>3.7.2</h3.version>
<h3.version>4.0.0</h3.version>
<jmh.version>1.26</jmh.version>
<audienceannotations.version>0.13.0</audienceannotations.version>

Expand Down

0 comments on commit dd5f5d9

Please sign in to comment.