Skip to content

Commit

Permalink
implement formatVersion() for PositionDeletesTable
Browse files Browse the repository at this point in the history
  • Loading branch information
nastra committed Nov 21, 2024
1 parent a3b14ba commit 8351248
Showing 1 changed file with 2 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.iceberg.BaseMetadataTable;
import org.apache.iceberg.DeleteFile;
import org.apache.iceberg.FileFormat;
import org.apache.iceberg.HasTableOperations;
import org.apache.iceberg.MetadataColumns;
import org.apache.iceberg.PartitionSpec;
import org.apache.iceberg.PositionDeletesTable;
import org.apache.iceberg.Schema;
import org.apache.iceberg.StructLike;
import org.apache.iceberg.Table;
import org.apache.iceberg.TableOperations;
import org.apache.iceberg.TableUtil;
import org.apache.iceberg.deletes.DeleteGranularity;
import org.apache.iceberg.deletes.PositionDelete;
import org.apache.iceberg.io.ClusteredPositionDeleteWriter;
Expand Down Expand Up @@ -350,7 +348,7 @@ private static class DeleteWriter implements DataWriter<InternalRow> {
this.io = table.io();
this.spec = table.specs().get(specId);
this.partition = partition;
this.formatVersion = formatVersion(table);
this.formatVersion = TableUtil.formatVersion(table);

this.fileOrdinal = dsSchema.fieldIndex(MetadataColumns.DELETE_FILE_PATH.name());
this.positionOrdinal = dsSchema.fieldIndex(MetadataColumns.DELETE_FILE_POS.name());
Expand All @@ -362,17 +360,6 @@ private static class DeleteWriter implements DataWriter<InternalRow> {
this.rowSize = ((StructType) type).size();
}

private int formatVersion(Table table) {
if (table instanceof BaseMetadataTable) {
return ((BaseMetadataTable) table).table().operations().current().formatVersion();
} else if (table instanceof HasTableOperations) {
TableOperations ops = ((HasTableOperations) table).operations();
return ops.current().formatVersion();
} else {
return 2;
}
}

@Override
public void write(InternalRow record) throws IOException {
String file = record.getString(fileOrdinal);
Expand Down

0 comments on commit 8351248

Please sign in to comment.