Skip to content

Commit

Permalink
nice overloads in Deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Dec 10, 2024
1 parent 52dc58b commit 1c03a14
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
43 changes: 41 additions & 2 deletions core/src/main/java/org/apache/iceberg/deletes/Deletes.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.types.Comparators;
import org.apache.iceberg.types.Types;
import org.apache.iceberg.util.CharSequenceMap;
import org.apache.iceberg.util.Filter;
import org.apache.iceberg.util.ParallelIterable;
import org.apache.iceberg.util.PathMap;
Expand Down Expand Up @@ -124,11 +125,49 @@ public static StructLikeSet toEqualitySet(
}
}

public static <T extends StructLike> PathMap<PositionDeleteIndex> toPositionIndexes(
/**
* Builds a map of position delete indexes by path.
*
* @deprecated since 1.8.0, will be removed in 1.9.0. Use {@link #toPathPositionIndexes}.
*/
@Deprecated
public static <T extends StructLike> CharSequenceMap<PositionDeleteIndex> toPositionIndexes(
CloseableIterable<T> posDeletes) {
return toPositionIndexes(posDeletes, null /* unknown delete file */);
}

/**
* Builds a map of position delete indexes by path.
*
* <p>Unlike {@link #toPositionIndex(CharSequence, List)}, this method builds a position delete
* index for each referenced data file and does not filter deletes. This can be useful when the
* entire delete file content is needed (e.g. caching).
*
* @param posDeletes position deletes
* @param file the source delete file for the deletes
* @return the map of position delete indexes by path
* @deprecated since 1.8.0, will be removed in 1.9.0. Use {@link #toPathPositionIndexes}.
*/
@Deprecated
public static <T extends StructLike> CharSequenceMap<PositionDeleteIndex> toPositionIndexes(
CloseableIterable<T> posDeletes, DeleteFile file) {
CharSequenceMap<PositionDeleteIndex> indexes = CharSequenceMap.create();

try (CloseableIterable<T> deletes = posDeletes) {
for (T delete : deletes) {
CharSequence filePath = (CharSequence) FILENAME_ACCESSOR.get(delete);
long position = (long) POSITION_ACCESSOR.get(delete);
PositionDeleteIndex index =
indexes.computeIfAbsent(filePath, () -> new BitmapPositionDeleteIndex(file));
index.delete(position);
}
} catch (IOException e) {
throw new UncheckedIOException("Failed to close position delete source", e);
}

return indexes;
}

/**
* Builds a map of position delete indexes by path.
*
Expand All @@ -140,7 +179,7 @@ public static <T extends StructLike> PathMap<PositionDeleteIndex> toPositionInde
* @param file the source delete file for the deletes
* @return the map of position delete indexes by path
*/
public static <T extends StructLike> PathMap<PositionDeleteIndex> toPositionIndexes(
public static <T extends StructLike> PathMap<PositionDeleteIndex> toPathPositionIndexes(
CloseableIterable<T> posDeletes, DeleteFile file) {
PathMap<PositionDeleteIndex> indexes = PathMap.create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private PositionDeleteIndex getOrReadPosDeletes(DeleteFile deleteFile, CharSeque

private PathMap<PositionDeleteIndex> readPosDeletes(DeleteFile deleteFile) {
CloseableIterable<Record> deletes = openDeletes(deleteFile, POS_DELETE_SCHEMA);
return Deletes.toPositionIndexes(deletes, deleteFile);
return Deletes.toPathPositionIndexes(deletes, deleteFile);
}

private PositionDeleteIndex readPosDeletes(DeleteFile deleteFile, CharSequence filePath) {
Expand Down

0 comments on commit 1c03a14

Please sign in to comment.