Skip to content
Open
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 @@ -768,26 +768,30 @@ private static PositionDeleteWriter<Record> positionDeletesWriter(
format, EncryptedFiles.plainAsEncryptedOutput(outputFile))
.partition(partition)
.spec(spec)
.overwrite()
.build();
} else {
return switch (format) {
case AVRO ->
Avro.writeDeletes(outputFile)
.createWriterFunc(DataWriter::create)
.overwrite()
.withPartition(partition)
.rowSchema(rowSchema)
.withSpec(spec)
.buildPositionWriter();
case PARQUET ->
Parquet.writeDeletes(outputFile)
.createWriterFunc(GenericParquetWriter::create)
.overwrite()
.withPartition(partition)
.rowSchema(rowSchema)
.withSpec(spec)
.buildPositionWriter();
case ORC ->
ORC.writeDeletes(outputFile)
.createWriterFunc(GenericOrcWriter::buildWriter)
.overwrite()
.withPartition(partition)
.rowSchema(rowSchema)
.withSpec(spec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,53 @@ public void testPositionDeletesOrc() throws Exception {
runPositionDeletesTest("orc");
}

@TestTemplate
public void testRerunWithPositionDeletesReusingStagingLocation() throws Exception {
assumeThat(formatVersion).isEqualTo(2);

Table tableWithPosDeletes =
createTableWithSnapshots(
tableDir.toFile().toURI().toString().concat("tableWithPosDeletesRerun"),
2,
Map.of(TableProperties.DELETE_DEFAULT_FILE_FORMAT, "parquet"));

List<Pair<CharSequence, Long>> deletes =
Lists.newArrayList(
Pair.of(
SnapshotChanges.builderFor(tableWithPosDeletes)
.build()
.addedDataFiles()
.iterator()
.next()
.location(),
0L));
File file =
new File(
removePrefix(tableWithPosDeletes.location() + "/data/deeply/nested/deletes.parquet"));
DeleteFile positionDeletes =
FileHelpers.writeDeleteFile(
tableWithPosDeletes,
tableWithPosDeletes.io().newOutputFile(file.toURI().toString()),
deletes,
formatVersion)
.first();
tableWithPosDeletes.newRowDelta().addDeletes(positionDeletes).commit();

actions()
.rewriteTablePath(tableWithPosDeletes)
.stagingLocation(stagingLocation())
.rewriteLocationPrefix(tableWithPosDeletes.location(), targetTableLocation())
.execute();

RewriteTablePath.Result rerun =
actions()
.rewriteTablePath(tableWithPosDeletes)
.stagingLocation(stagingLocation())
.rewriteLocationPrefix(tableWithPosDeletes.location(), targetTableLocation())
.execute();
assertThat(rerun.rewrittenDeleteFilePathsCount()).isEqualTo(1);
}

private void runPositionDeletesTest(String fileFormat) throws Exception {
Table tableWithPosDeletes =
createTableWithSnapshots(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,26 +768,30 @@ private static PositionDeleteWriter<Record> positionDeletesWriter(
format, EncryptedFiles.plainAsEncryptedOutput(outputFile))
.partition(partition)
.spec(spec)
.overwrite()
.build();
} else {
return switch (format) {
case AVRO ->
Avro.writeDeletes(outputFile)
.createWriterFunc(DataWriter::create)
.overwrite()
.withPartition(partition)
.rowSchema(rowSchema)
.withSpec(spec)
.buildPositionWriter();
case PARQUET ->
Parquet.writeDeletes(outputFile)
.createWriterFunc(GenericParquetWriter::create)
.overwrite()
.withPartition(partition)
.rowSchema(rowSchema)
.withSpec(spec)
.buildPositionWriter();
case ORC ->
ORC.writeDeletes(outputFile)
.createWriterFunc(GenericOrcWriter::buildWriter)
.overwrite()
.withPartition(partition)
.rowSchema(rowSchema)
.withSpec(spec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,53 @@ public void testPositionDeletesOrc() throws Exception {
runPositionDeletesTest("orc");
}

@TestTemplate
public void testRerunWithPositionDeletesReusingStagingLocation() throws Exception {
assumeThat(formatVersion).isEqualTo(2);

Table tableWithPosDeletes =
createTableWithSnapshots(
tableDir.toFile().toURI().toString().concat("tableWithPosDeletesRerun"),
2,
Map.of(TableProperties.DELETE_DEFAULT_FILE_FORMAT, "parquet"));

List<Pair<CharSequence, Long>> deletes =
Lists.newArrayList(
Pair.of(
SnapshotChanges.builderFor(tableWithPosDeletes)
.build()
.addedDataFiles()
.iterator()
.next()
.location(),
0L));
File file =
new File(
removePrefix(tableWithPosDeletes.location() + "/data/deeply/nested/deletes.parquet"));
DeleteFile positionDeletes =
FileHelpers.writeDeleteFile(
tableWithPosDeletes,
tableWithPosDeletes.io().newOutputFile(file.toURI().toString()),
deletes,
formatVersion)
.first();
tableWithPosDeletes.newRowDelta().addDeletes(positionDeletes).commit();

actions()
.rewriteTablePath(tableWithPosDeletes)
.stagingLocation(stagingLocation())
.rewriteLocationPrefix(tableWithPosDeletes.location(), targetTableLocation())
.execute();

RewriteTablePath.Result rerun =
actions()
.rewriteTablePath(tableWithPosDeletes)
.stagingLocation(stagingLocation())
.rewriteLocationPrefix(tableWithPosDeletes.location(), targetTableLocation())
.execute();
assertThat(rerun.rewrittenDeleteFilePathsCount()).isEqualTo(1);
}

private void runPositionDeletesTest(String fileFormat) throws Exception {
Table tableWithPosDeletes =
createTableWithSnapshots(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,26 +768,30 @@ private static PositionDeleteWriter<Record> positionDeletesWriter(
format, EncryptedFiles.plainAsEncryptedOutput(outputFile))
.partition(partition)
.spec(spec)
.overwrite()
.build();
} else {
return switch (format) {
case AVRO ->
Avro.writeDeletes(outputFile)
.createWriterFunc(DataWriter::create)
.overwrite()
.withPartition(partition)
.rowSchema(rowSchema)
.withSpec(spec)
.buildPositionWriter();
case PARQUET ->
Parquet.writeDeletes(outputFile)
.createWriterFunc(GenericParquetWriter::create)
.overwrite()
.withPartition(partition)
.rowSchema(rowSchema)
.withSpec(spec)
.buildPositionWriter();
case ORC ->
ORC.writeDeletes(outputFile)
.createWriterFunc(GenericOrcWriter::buildWriter)
.overwrite()
.withPartition(partition)
.rowSchema(rowSchema)
.withSpec(spec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,53 @@ public void testPositionDeletesOrc() throws Exception {
runPositionDeletesTest("orc");
}

@TestTemplate
public void testRerunWithPositionDeletesReusingStagingLocation() throws Exception {
assumeThat(formatVersion).isEqualTo(2);

Table tableWithPosDeletes =
createTableWithSnapshots(
tableDir.toFile().toURI().toString().concat("tableWithPosDeletesRerun"),
2,
Map.of(TableProperties.DELETE_DEFAULT_FILE_FORMAT, "parquet"));

List<Pair<CharSequence, Long>> deletes =
Lists.newArrayList(
Pair.of(
SnapshotChanges.builderFor(tableWithPosDeletes)
.build()
.addedDataFiles()
.iterator()
.next()
.location(),
0L));
File file =
new File(
removePrefix(tableWithPosDeletes.location() + "/data/deeply/nested/deletes.parquet"));
DeleteFile positionDeletes =
FileHelpers.writeDeleteFile(
tableWithPosDeletes,
tableWithPosDeletes.io().newOutputFile(file.toURI().toString()),
deletes,
formatVersion)
.first();
tableWithPosDeletes.newRowDelta().addDeletes(positionDeletes).commit();

actions()
.rewriteTablePath(tableWithPosDeletes)
.stagingLocation(stagingLocation())
.rewriteLocationPrefix(tableWithPosDeletes.location(), targetTableLocation())
.execute();

RewriteTablePath.Result rerun =
actions()
.rewriteTablePath(tableWithPosDeletes)
.stagingLocation(stagingLocation())
.rewriteLocationPrefix(tableWithPosDeletes.location(), targetTableLocation())
.execute();
assertThat(rerun.rewrittenDeleteFilePathsCount()).isEqualTo(1);
}

private void runPositionDeletesTest(String fileFormat) throws Exception {
Table tableWithPosDeletes =
createTableWithSnapshots(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,26 +768,30 @@ private static PositionDeleteWriter<Record> positionDeletesWriter(
format, EncryptedFiles.plainAsEncryptedOutput(outputFile))
.partition(partition)
.spec(spec)
.overwrite()
.build();
} else {
return switch (format) {
case AVRO ->
Avro.writeDeletes(outputFile)
.createWriterFunc(DataWriter::create)
.overwrite()
.withPartition(partition)
.rowSchema(rowSchema)
.withSpec(spec)
.buildPositionWriter();
case PARQUET ->
Parquet.writeDeletes(outputFile)
.createWriterFunc(GenericParquetWriter::create)
.overwrite()
.withPartition(partition)
.rowSchema(rowSchema)
.withSpec(spec)
.buildPositionWriter();
case ORC ->
ORC.writeDeletes(outputFile)
.createWriterFunc(GenericOrcWriter::buildWriter)
.overwrite()
.withPartition(partition)
.rowSchema(rowSchema)
.withSpec(spec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,53 @@ public void testPositionDeletesOrc() throws Exception {
runPositionDeletesTest("orc");
}

@TestTemplate
public void testRerunWithPositionDeletesReusingStagingLocation() throws Exception {
assumeThat(formatVersion).isEqualTo(2);

Table tableWithPosDeletes =
createTableWithSnapshots(
tableDir.toFile().toURI().toString().concat("tableWithPosDeletesRerun"),
2,
Map.of(TableProperties.DELETE_DEFAULT_FILE_FORMAT, "parquet"));

List<Pair<CharSequence, Long>> deletes =
Lists.newArrayList(
Pair.of(
SnapshotChanges.builderFor(tableWithPosDeletes)
.build()
.addedDataFiles()
.iterator()
.next()
.location(),
0L));
File file =
new File(
removePrefix(tableWithPosDeletes.location() + "/data/deeply/nested/deletes.parquet"));
DeleteFile positionDeletes =
FileHelpers.writeDeleteFile(
tableWithPosDeletes,
tableWithPosDeletes.io().newOutputFile(file.toURI().toString()),
deletes,
formatVersion)
.first();
tableWithPosDeletes.newRowDelta().addDeletes(positionDeletes).commit();

actions()
.rewriteTablePath(tableWithPosDeletes)
.stagingLocation(stagingLocation())
.rewriteLocationPrefix(tableWithPosDeletes.location(), targetTableLocation())
.execute();

RewriteTablePath.Result rerun =
actions()
.rewriteTablePath(tableWithPosDeletes)
.stagingLocation(stagingLocation())
.rewriteLocationPrefix(tableWithPosDeletes.location(), targetTableLocation())
.execute();
assertThat(rerun.rewrittenDeleteFilePathsCount()).isEqualTo(1);
}

private void runPositionDeletesTest(String fileFormat) throws Exception {
Table tableWithPosDeletes =
createTableWithSnapshots(
Expand Down