rdblue commented on a change in pull request #2358: URL: https://github.com/apache/iceberg/pull/2358#discussion_r639147092
########## File path: core/src/main/java/org/apache/iceberg/PartitionsTable.java ########## @@ -80,21 +88,51 @@ private DataTask task(TableScan scan) { return StaticDataTask.Row.of(partition.key, partition.recordCount, partition.fileCount); } - private static Iterable<Partition> partitions(Table table, Long snapshotId) { - PartitionMap partitions = new PartitionMap(table.spec().partitionType()); - TableScan scan = table.newScan(); + private Iterable<Partition> partitions(StaticTableScan scan) { + CloseableIterable<FileScanTask> tasks = planTasks(scan); - if (snapshotId != null) { - scan = scan.useSnapshot(snapshotId); + PartitionMap partitions = new PartitionMap(table().spec().partitionType()); + for (FileScanTask task : tasks) { + partitions.get(task.file().partition()).update(task.file()); } + return partitions.all(); + } - for (FileScanTask task : scan.planFiles()) { - partitions.get(task.file().partition()).update(task.file()); + @VisibleForTesting + CloseableIterable<FileScanTask> planTasks(StaticTableScan scan) { + boolean caseSensitive = scan.isCaseSensitive(); + boolean ignoreResiduals = scan.shouldIgnoreResiduals(); + long snapshotId = scan.snapshot().snapshotId(); + + PartitionSpec tableSpec = table().spec(); + PartitionSpec.Builder identitySpecBuilder = PartitionSpec.builderFor(schema()); + tableSpec.fields().stream().forEach(pf -> identitySpecBuilder.identity(PARTITION_FIELD_PREFIX + pf.name())); + PartitionSpec identitySpec = identitySpecBuilder.build(); + + ManifestEvaluator eval = ManifestEvaluator.forPartitionFilter( + Projections.inclusive(identitySpec, caseSensitive).project(scan.filter()), + identitySpec, + caseSensitive); + ManifestGroup manifestGroup = new ManifestGroup( + table().io(), table().snapshot(snapshotId).dataManifests(), table().snapshot(snapshotId).deleteManifests()) + .caseSensitive(caseSensitive) + .filterManifests(manifestFile -> eval.eval(manifestFile)) + .select(DataTableScan.SCAN_COLUMNS) + .specsById(table().specs()) + .ignoreDeleted(); + + if (ignoreResiduals) { + manifestGroup = manifestGroup.ignoreResiduals(); } - return partitions.all(); + if (PLAN_SCANS_WITH_WORKER_POOL && scan.snapshot().dataManifests().size() > 1) { + manifestGroup = manifestGroup.planWith(ThreadPools.getWorkerPool()); + } + + return manifestGroup.planFiles(); } + Review comment: Nit: unnecessary newline addition. -- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org