Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.apache.iceberg.types.Types;

/**
* @deprecated will be removed in 2.0.0; use {@link PlannedDataReader} instead.
* @deprecated will be removed in 1.12.0; use {@link PlannedDataReader} instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to ask you to check this with the community first.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecating this earlier makes sense to me

*/
@Deprecated
public class DataReader<T> implements DatumReader<T>, SupportsRowPosition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
import org.apache.iceberg.actions.RewriteTablePath;
import org.apache.iceberg.avro.Avro;
import org.apache.iceberg.data.Record;
import org.apache.iceberg.data.avro.DataReader;
import org.apache.iceberg.data.avro.DataWriter;
import org.apache.iceberg.data.avro.PlannedDataReader;
import org.apache.iceberg.data.orc.GenericOrcReader;
import org.apache.iceberg.data.orc.GenericOrcWriter;
import org.apache.iceberg.data.parquet.GenericParquetReaders;
Expand Down Expand Up @@ -725,7 +725,7 @@ private static CloseableIterable<Record> positionDeletesReader(
return Avro.read(inputFile)
.project(deleteSchema)
.reuseContainers()
.createReaderFunc(DataReader::create)
.createReaderFunc(fileSchema -> PlannedDataReader.create(deleteSchema))
.build();

case PARQUET:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,28 +387,59 @@ public void testDeleteDataFile() throws Exception {
}

@Test
public void testPositionDeletes() throws Exception {
public void testPositionDeletesParquet() throws Exception {
runPositionDeletesTest("parquet");
}

@Test
public void testPositionDeletesAvro() throws Exception {
runPositionDeletesTest("avro");
}

@Test
public void testPositionDeletesOrc() throws Exception {
runPositionDeletesTest("orc");
}

private void runPositionDeletesTest(String fileFormat) throws Exception {
Table tableWithPosDeletes =
createTableWithSnapshots(
tableDir.toFile().toURI().toString().concat("tableWithPosDeletes").concat(fileFormat),
2,
Map.of(TableProperties.DELETE_DEFAULT_FILE_FORMAT, fileFormat));

List<Pair<CharSequence, Long>> deletes =
Lists.newArrayList(
Pair.of(
table.currentSnapshot().addedDataFiles(table.io()).iterator().next().location(),
tableWithPosDeletes
.currentSnapshot()
.addedDataFiles(tableWithPosDeletes.io())
.iterator()
.next()
.location(),
0L));

File file = new File(removePrefix(table.location() + "/data/deeply/nested/deletes.parquet"));
File file =
new File(
removePrefix(
tableWithPosDeletes.location() + "/data/deeply/nested/deletes." + fileFormat));
DeleteFile positionDeletes =
FileHelpers.writeDeleteFile(
table, table.io().newOutputFile(file.toURI().toString()), deletes)
tableWithPosDeletes,
tableWithPosDeletes.io().newOutputFile(file.toURI().toString()),
deletes)
.first();

table.newRowDelta().addDeletes(positionDeletes).commit();
tableWithPosDeletes.newRowDelta().addDeletes(positionDeletes).commit();

assertThat(spark.read().format("iceberg").load(table.location()).collectAsList()).hasSize(1);
assertThat(spark.read().format("iceberg").load(tableWithPosDeletes.location()).collectAsList())
.hasSize(1);

RewriteTablePath.Result result =
actions()
.rewriteTablePath(table)
.rewriteTablePath(tableWithPosDeletes)
.stagingLocation(stagingLocation())
.rewriteLocationPrefix(table.location(), targetTableLocation())
.rewriteLocationPrefix(tableWithPosDeletes.location(), targetTableLocation())
.execute();

// We have one more snapshot, an additional manifest list, and a new (delete) manifest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
import org.apache.iceberg.actions.RewriteTablePath;
import org.apache.iceberg.avro.Avro;
import org.apache.iceberg.data.Record;
import org.apache.iceberg.data.avro.DataReader;
import org.apache.iceberg.data.avro.DataWriter;
import org.apache.iceberg.data.avro.PlannedDataReader;
import org.apache.iceberg.data.orc.GenericOrcReader;
import org.apache.iceberg.data.orc.GenericOrcWriter;
import org.apache.iceberg.data.parquet.GenericParquetReaders;
Expand Down Expand Up @@ -725,7 +725,7 @@ private static CloseableIterable<Record> positionDeletesReader(
return Avro.read(inputFile)
.project(deleteSchema)
.reuseContainers()
.createReaderFunc(DataReader::create)
.createReaderFunc(fileSchema -> PlannedDataReader.create(deleteSchema))
.build();

case PARQUET:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,28 +387,59 @@ public void testDeleteDataFile() throws Exception {
}

@Test
public void testPositionDeletes() throws Exception {
public void testPositionDeletesParquet() throws Exception {
runPositionDeletesTest("parquet");
}

@Test
public void testPositionDeletesAvro() throws Exception {
runPositionDeletesTest("avro");
}

@Test
public void testPositionDeletesOrc() throws Exception {
runPositionDeletesTest("orc");
}

private void runPositionDeletesTest(String fileFormat) throws Exception {
Table tableWithPosDeletes =
createTableWithSnapshots(
tableDir.toFile().toURI().toString().concat("tableWithPosDeletes").concat(fileFormat),
2,
Map.of(TableProperties.DELETE_DEFAULT_FILE_FORMAT, fileFormat));

List<Pair<CharSequence, Long>> deletes =
Lists.newArrayList(
Pair.of(
table.currentSnapshot().addedDataFiles(table.io()).iterator().next().location(),
tableWithPosDeletes
.currentSnapshot()
.addedDataFiles(tableWithPosDeletes.io())
.iterator()
.next()
.location(),
0L));

File file = new File(removePrefix(table.location() + "/data/deeply/nested/deletes.parquet"));
File file =
new File(
removePrefix(
tableWithPosDeletes.location() + "/data/deeply/nested/deletes." + fileFormat));
DeleteFile positionDeletes =
FileHelpers.writeDeleteFile(
table, table.io().newOutputFile(file.toURI().toString()), deletes)
tableWithPosDeletes,
tableWithPosDeletes.io().newOutputFile(file.toURI().toString()),
deletes)
.first();

table.newRowDelta().addDeletes(positionDeletes).commit();
tableWithPosDeletes.newRowDelta().addDeletes(positionDeletes).commit();

assertThat(spark.read().format("iceberg").load(table.location()).collectAsList()).hasSize(1);
assertThat(spark.read().format("iceberg").load(tableWithPosDeletes.location()).collectAsList())
.hasSize(1);

RewriteTablePath.Result result =
actions()
.rewriteTablePath(table)
.rewriteTablePath(tableWithPosDeletes)
.stagingLocation(stagingLocation())
.rewriteLocationPrefix(table.location(), targetTableLocation())
.rewriteLocationPrefix(tableWithPosDeletes.location(), targetTableLocation())
.execute();

// We have one more snapshot, an additional manifest list, and a new (delete) manifest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
import org.apache.iceberg.actions.RewriteTablePath;
import org.apache.iceberg.avro.Avro;
import org.apache.iceberg.data.Record;
import org.apache.iceberg.data.avro.DataReader;
import org.apache.iceberg.data.avro.DataWriter;
import org.apache.iceberg.data.avro.PlannedDataReader;
import org.apache.iceberg.data.orc.GenericOrcReader;
import org.apache.iceberg.data.orc.GenericOrcWriter;
import org.apache.iceberg.data.parquet.GenericParquetReaders;
Expand Down Expand Up @@ -725,7 +725,7 @@ private static CloseableIterable<Record> positionDeletesReader(
return Avro.read(inputFile)
.project(deleteSchema)
.reuseContainers()
.createReaderFunc(DataReader::create)
.createReaderFunc(fileSchema -> PlannedDataReader.create(deleteSchema))
.build();

case PARQUET:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,28 +387,59 @@ public void testDeleteDataFile() throws Exception {
}

@Test
public void testPositionDeletes() throws Exception {
public void testPositionDeletesParquet() throws Exception {
runPositionDeletesTest("parquet");
}

@Test
public void testPositionDeletesAvro() throws Exception {
runPositionDeletesTest("avro");
}

@Test
public void testPositionDeletesOrc() throws Exception {
runPositionDeletesTest("orc");
}

private void runPositionDeletesTest(String fileFormat) throws Exception {
Table tableWithPosDeletes =
createTableWithSnapshots(
tableDir.toFile().toURI().toString().concat("tableWithPosDeletes").concat(fileFormat),
2,
Map.of(TableProperties.DELETE_DEFAULT_FILE_FORMAT, fileFormat));

List<Pair<CharSequence, Long>> deletes =
Lists.newArrayList(
Pair.of(
table.currentSnapshot().addedDataFiles(table.io()).iterator().next().location(),
tableWithPosDeletes
.currentSnapshot()
.addedDataFiles(tableWithPosDeletes.io())
.iterator()
.next()
.location(),
0L));

File file = new File(removePrefix(table.location() + "/data/deeply/nested/deletes.parquet"));
File file =
new File(
removePrefix(
tableWithPosDeletes.location() + "/data/deeply/nested/deletes." + fileFormat));
DeleteFile positionDeletes =
FileHelpers.writeDeleteFile(
table, table.io().newOutputFile(file.toURI().toString()), deletes)
tableWithPosDeletes,
tableWithPosDeletes.io().newOutputFile(file.toURI().toString()),
deletes)
.first();

table.newRowDelta().addDeletes(positionDeletes).commit();
tableWithPosDeletes.newRowDelta().addDeletes(positionDeletes).commit();

assertThat(spark.read().format("iceberg").load(table.location()).collectAsList()).hasSize(1);
assertThat(spark.read().format("iceberg").load(tableWithPosDeletes.location()).collectAsList())
.hasSize(1);

RewriteTablePath.Result result =
actions()
.rewriteTablePath(table)
.rewriteTablePath(tableWithPosDeletes)
.stagingLocation(stagingLocation())
.rewriteLocationPrefix(table.location(), targetTableLocation())
.rewriteLocationPrefix(tableWithPosDeletes.location(), targetTableLocation())
.execute();

// We have one more snapshot, an additional manifest list, and a new (delete) manifest,
Expand Down