Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#12081: "Add deleteFileThreshold parameter to SizeBasedDataRewriter, update logic, and include tests" #12133

Closed
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 @@ -47,12 +47,14 @@ public abstract class SizeBasedDataRewriter extends SizeBasedFileRewriter<FileSc
public static final String DELETE_FILE_THRESHOLD = "delete-file-threshold";

public static final int DELETE_FILE_THRESHOLD_DEFAULT = Integer.MAX_VALUE;
private static final double DELETE_RATIO_THRESHOLD = 0.3;
private static final double DEFAULT_DELETE_THRESHOLD = 0.3;

private int deleteFileThreshold;
private int deleteRatioThreshold;

// Default constructor
protected SizeBasedDataRewriter(Table table) {
super(table);
this(table); // Providing default deleteRatioThreshold
}

@Override
Expand All @@ -67,6 +69,8 @@ public Set<String> validOptions() {
public void init(Map<String, String> options) {
super.init(options);
this.deleteFileThreshold = deleteFileThreshold(options);
this.deleteRatioThreshold = PropertyUtil.propertyAsDouble(
Copy link
Contributor

Choose a reason for hiding this comment

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

we also need to validate that 0.0 > threshold <= 1.0. That would also require some additional unit tests that check for valid/invalid parameters

Copy link
Contributor

Choose a reason for hiding this comment

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

also this.deleteRatioThreshold needs to be used in tooHighDeleteRatio()

options, DELETE_FILE_THRESHOLD, DEFAULT_DELETE_THRESHOLD);
}

@Override
Expand Down Expand Up @@ -116,7 +120,7 @@ private boolean tooHighDeleteRatio(FileScanTask task) {

double deletedRecords = (double) Math.min(knownDeletedRecordCount, task.file().recordCount());
double deleteRatio = deletedRecords / task.file().recordCount();
return deleteRatio >= DELETE_RATIO_THRESHOLD;
return deleteRatio >= this.deleteRatioThreshold;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,34 @@ public void testSplitSizeLowerBound() {
assertThat(splitSize).isLessThan(maxFileSize);
}

@TestTemplate
public void testDeleteFileThresholdOption() {
SizeBasedDataFileRewriterImpl rewriter = new SizeBasedDataFileRewriterImpl(table);

Map<String, String> options = ImmutableMap.of(
SizeBasedDataRewriter.DEFAULT_DELETE_THRESHOLD, "5"
);
rewriter.init(options);

assertThat(rewriter.getDeleteFileThreshold()).isEqualTo(5);
}

@TestTemplate
public void testHighDeleteRatioTriggersRewrite() {
SizeBasedDataFileRewriterImpl rewriter = new SizeBasedDataFileRewriterImpl(table);

FileScanTask task = new MockFileScanTask(100L * 1024 * 1024, 80); // 80% delete ratio

assertThat(rewriter.tooHighDeleteRatio(task)).isTrue();
}

@Test
private void validateThreshold(double threshold) {
if (threshold <= 0.0 || threshold > 1.0) {
throw new IllegalArgumentException("Threshold must be greater than 0.0 and less than or equal to 1.0");
}
}

private static class SizeBasedDataFileRewriterImpl extends SizeBasedDataRewriter {

SizeBasedDataFileRewriterImpl(Table table) {
Expand Down
Loading