Skip to content

Commit ef7e20e

Browse files
authored
Core: Refactor validation in TableScanUtil (apache#6791)
1 parent 775b3ce commit ef7e20e

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

core/src/main/java/org/apache/iceberg/util/TableScanUtil.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static boolean hasDeletes(FileScanTask task) {
7171

7272
public static CloseableIterable<FileScanTask> splitFiles(
7373
CloseableIterable<FileScanTask> tasks, long splitSize) {
74-
Preconditions.checkArgument(splitSize > 0, "Invalid split size (negative or 0): %s", splitSize);
74+
Preconditions.checkArgument(splitSize > 0, "Split size must be > 0: %s", splitSize);
7575

7676
Iterable<FileScanTask> splitTasks =
7777
FluentIterable.from(tasks).transformAndConcat(input -> input.split(splitSize));
@@ -81,11 +81,8 @@ public static CloseableIterable<FileScanTask> splitFiles(
8181

8282
public static CloseableIterable<CombinedScanTask> planTasks(
8383
CloseableIterable<FileScanTask> splitFiles, long splitSize, int lookback, long openFileCost) {
84-
Preconditions.checkArgument(splitSize > 0, "Invalid split size (negative or 0): %s", splitSize);
85-
Preconditions.checkArgument(
86-
lookback > 0, "Invalid split planning lookback (negative or 0): %s", lookback);
87-
Preconditions.checkArgument(
88-
openFileCost >= 0, "Invalid file open cost (negative): %s", openFileCost);
84+
85+
validatePlanningArguments(splitSize, lookback, openFileCost);
8986

9087
// Check the size of delete file as well to avoid unbalanced bin-packing
9188
Function<FileScanTask, Long> weightFunc =
@@ -106,11 +103,7 @@ public static CloseableIterable<CombinedScanTask> planTasks(
106103
public static <T extends ScanTask> CloseableIterable<ScanTaskGroup<T>> planTaskGroups(
107104
CloseableIterable<T> tasks, long splitSize, int lookback, long openFileCost) {
108105

109-
Preconditions.checkArgument(splitSize > 0, "Invalid split size (negative or 0): %s", splitSize);
110-
Preconditions.checkArgument(
111-
lookback > 0, "Invalid split planning lookback (negative or 0): %s", lookback);
112-
Preconditions.checkArgument(
113-
openFileCost >= 0, "Invalid file open cost (negative): %s", openFileCost);
106+
validatePlanningArguments(splitSize, lookback, openFileCost);
114107

115108
// capture manifests which can be closed after scan planning
116109
CloseableIterable<T> splitTasks =
@@ -144,11 +137,7 @@ public static <T extends PartitionScanTask> List<ScanTaskGroup<T>> planTaskGroup
144137
long openFileCost,
145138
Types.StructType groupingKeyType) {
146139

147-
Preconditions.checkArgument(splitSize > 0, "Invalid split size (negative or 0): %s", splitSize);
148-
Preconditions.checkArgument(
149-
lookback > 0, "Invalid split planning lookback (negative or 0): %s", lookback);
150-
Preconditions.checkArgument(
151-
openFileCost >= 0, "Invalid file open cost (negative): %s", openFileCost);
140+
validatePlanningArguments(splitSize, lookback, openFileCost);
152141

153142
Function<T, Long> weightFunc =
154143
task -> Math.max(task.sizeBytes(), task.filesCount() * openFileCost);
@@ -250,4 +239,10 @@ public static <T extends ScanTask> List<T> mergeTasks(List<T> tasks) {
250239

251240
return mergedTasks;
252241
}
242+
243+
private static void validatePlanningArguments(long splitSize, int lookback, long openFileCost) {
244+
Preconditions.checkArgument(splitSize > 0, "Split size must be > 0: %s", splitSize);
245+
Preconditions.checkArgument(lookback > 0, "Split planning lookback must be > 0: %s", lookback);
246+
Preconditions.checkArgument(openFileCost >= 0, "File open cost must be >= 0: %s", openFileCost);
247+
}
253248
}

core/src/test/java/org/apache/iceberg/TestSplitPlanning.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,23 @@ public void testSplitPlanningWithNegativeValues() {
180180
AssertHelpers.assertThrows(
181181
"User provided split size should be validated",
182182
IllegalArgumentException.class,
183-
"Invalid split size (negative or 0): -10",
183+
"Split size must be > 0: -10",
184184
() -> {
185185
table.newScan().option(TableProperties.SPLIT_SIZE, String.valueOf(-10)).planTasks();
186186
});
187187

188188
AssertHelpers.assertThrows(
189189
"User provided split planning lookback should be validated",
190190
IllegalArgumentException.class,
191-
"Invalid split planning lookback (negative or 0): -10",
191+
"Split planning lookback must be > 0: -10",
192192
() -> {
193193
table.newScan().option(TableProperties.SPLIT_LOOKBACK, String.valueOf(-10)).planTasks();
194194
});
195195

196196
AssertHelpers.assertThrows(
197197
"User provided split open file cost should be validated",
198198
IllegalArgumentException.class,
199-
"Invalid file open cost (negative): -10",
199+
"File open cost must be >= 0: -10",
200200
() -> {
201201
table
202202
.newScan()

0 commit comments

Comments
 (0)