From dd5f5d92d69d831339b59e3debaae285b831ccbb Mon Sep 17 00:00:00 2001 From: Xiang Fu Date: Sun, 4 Sep 2022 06:12:34 -0700 Subject: [PATCH] upgrade h3 lib from 3.7.2 to 4.0.0 to lower glibc requirement (#9335) --- .../pinot/segment/local/utils/H3Utils.java | 17 ++++++++--------- pom.xml | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/H3Utils.java b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/H3Utils.java index 7fab9bd3aa20..706a85e38886 100644 --- a/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/H3Utils.java +++ b/pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/H3Utils.java @@ -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; @@ -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); } } @@ -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); } } @@ -72,7 +71,7 @@ private static LongSet coverLineInH3(LineString lineString, int resolution) { private static Pair coverPolygonInH3(Polygon polygon, int resolution) { List 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 @@ -96,7 +95,7 @@ private static Pair coverPolygonInH3(Polygon polygon, int reso } private static Polygon createPolygonFromH3Cell(long h3Cell) { - List boundary = H3_CORE.h3ToGeoBoundary(h3Cell); + List 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)); diff --git a/pom.xml b/pom.xml index 53318fcd4e9f..f87f07144b58 100644 --- a/pom.xml +++ b/pom.xml @@ -153,7 +153,7 @@ 4.1.79.Final 1.0.3 1.16.1 - 3.7.2 + 4.0.0 1.26 0.13.0