timothyw553 commented on code in PR #19104:
URL: https://github.com/apache/iceberg/pull/19104#discussion_r4707527053
##########
core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java:
##########
@@ -1039,6 +1040,34 @@ private static Pair<List<FileScanTask>, String>
planFilesFor(
}
}
+ private static Iterable<FileScanTask> limitToRows(Iterable<FileScanTask>
tasks, long minRows) {
+ return () ->
+ new Iterator<>() {
+ private final Iterator<FileScanTask> delegate = tasks.iterator();
+ private long remainingRows = minRows;
+
+ @Override
+ public boolean hasNext() {
+ return remainingRows > 0 && delegate.hasNext();
+ }
+
+ @Override
+ public FileScanTask next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+
+ FileScanTask task = delegate.next();
+ // only files whose rows are all returned have an exact row count
+ if (task.deletes().isEmpty() && task.residual().op() ==
Expression.Operation.TRUE) {
+ remainingRows -= Math.min(remainingRows, Math.max(0L,
task.file().recordCount()));
Review Comment:
all the test fixtures here have 1 row per file, so these tests would still
pass if we counted 1 per task instead of `recordCount()`. could we add a test
with multi-row files (e.g., 10 rows each) requesting 5, 10, and 15 rows to
verify it actually counts records?
```diff
+ @ParameterizedTest
+ @EnumSource(PlanningMode.class)
+ void minRowsRequestedCountsRecords(
+ Function<TestPlanningBehavior.Builder, TestPlanningBehavior.Builder>
planMode)
+ throws IOException {
+ configurePlanningBehavior(planMode);
+ Table table = createTableWithScanPlanning(restCatalog,
"min_rows_counts_records");
+ DataFile fileA =
DataFiles.builder(SPEC).copy(FILE_A).withRecordCount(10).build();
+ DataFile fileB =
DataFiles.builder(SPEC).copy(FILE_B).withRecordCount(10).build();
+ DataFile fileC =
DataFiles.builder(SPEC).copy(FILE_C).withRecordCount(10).build();
+
table.newAppend().appendFile(fileA).appendFile(fileB).appendFile(fileC).commit();
+ setParserContext(table);
+
+ for (long requestedRows : new long[] {5L, 10L, 15L}) {
+ int expectedTasks = (int) ((requestedRows + 9L) / 10L);
+ try (CloseableIterable<FileScanTask> tasks =
+ table.newScan().minRowsRequested(requestedRows).planFiles()) {
+ assertThat(tasks).hasSize(expectedTasks);
+ }
+ }
+ }
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]