Skip to content

Commit

Permalink
Increment nextDocId even if geo indexing fails (apache#11158)
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhd336 authored Jul 25, 2023
1 parent a753025 commit 7231ecf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ public MutableH3Index(H3IndexResolution resolution)

@Override
public void add(@Nonnull Object value, int dictId, int docId) {
Geometry geometry = GeometrySerializer.deserialize((byte[]) value);
add(geometry);
try {
Geometry geometry = GeometrySerializer.deserialize((byte[]) value);
add(geometry);
} finally {
_nextDocId++;
}
}

@Override
Expand All @@ -73,7 +77,7 @@ public void add(Geometry geometry) {
Coordinate coordinate = geometry.getCoordinate();
// TODO: support multiple resolutions
long h3Id = H3Utils.H3_CORE.geoToH3(coordinate.y, coordinate.x, _lowestResolution);
_bitmaps.computeIfAbsent(h3Id, k -> new ThreadSafeMutableRoaringBitmap()).add(_nextDocId++);
_bitmaps.computeIfAbsent(h3Id, k -> new ThreadSafeMutableRoaringBitmap()).add(_nextDocId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.pinot.segment.local.segment.creator.impl.inv.geospatial.OnHeapH3IndexCreator;
import org.apache.pinot.segment.local.segment.index.h3.H3IndexType;
import org.apache.pinot.segment.local.segment.index.readers.geospatial.ImmutableH3IndexReader;
import org.apache.pinot.segment.local.utils.GeometrySerializer;
import org.apache.pinot.segment.local.utils.GeometryUtils;
import org.apache.pinot.segment.local.utils.H3Utils;
import org.apache.pinot.segment.spi.V1Constants;
Expand Down Expand Up @@ -89,13 +90,14 @@ public void testH3Index()
h3IndexResolution);
GeoSpatialIndexCreator offHeapCreator = new OffHeapH3IndexCreator(TEMP_DIR, offHeapColumnName,
h3IndexResolution)) {
int docId = 0;
while (expectedCardinalities.size() < numUniqueH3Ids) {
double longitude = RANDOM.nextDouble() * 360 - 180;
double latitude = RANDOM.nextDouble() * 180 - 90;
Point point = GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(longitude, latitude));
onHeapCreator.add(point);
offHeapCreator.add(point);
mutableH3Index.add(point);
mutableH3Index.add(GeometrySerializer.serialize(point), -1, docId++);
long h3Id = H3Utils.H3_CORE.geoToH3(latitude, longitude, resolution);
expectedCardinalities.merge(h3Id, 1, Integer::sum);
}
Expand Down

0 comments on commit 7231ecf

Please sign in to comment.