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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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 @@ -47,12 +47,13 @@ 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;

protected SizeBasedDataRewriter(Table table) {
super(table);
// Default constructor
public SizeBasedDataRewriter(Table table) {
jangalasriramd7 marked this conversation as resolved.
Show resolved Hide resolved
this(table); // Providing default deleteRatioThreshold
}

@Override
Expand All @@ -67,6 +68,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-ratio-threshold", DEFAULT_DELETE_THRESHOLD);
jangalasriramd7 marked this conversation as resolved.
Show resolved Hide resolved
}

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

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

Map<String, String> options = ImmutableMap.of(
SizeBasedDataRewriter.DELETE_FILE_THRESHOLD, "5"
jangalasriramd7 marked this conversation as resolved.
Show resolved Hide resolved
);
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();
}

private static class SizeBasedDataFileRewriterImpl extends SizeBasedDataRewriter {

SizeBasedDataFileRewriterImpl(Table table) {
Expand Down
Loading