aokolnychyi commented on code in PR #6365:
URL: https://github.com/apache/iceberg/pull/6365#discussion_r1084802235
##########
core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java:
##########
@@ -1040,4 +1047,195 @@ public void testAllManifestsTableSnapshotNot() {
expectedManifestListPaths(table.snapshots(), 1L, 3L, 4L),
actualManifestListPaths(manifestsTableScan));
}
+
+ @Test
+ public void testPositionDeletesWithFilter() {
+ Assume.assumeTrue("Position deletes supported only for v2 tables",
formatVersion == 2);
+ preparePartitionedTable();
+
+ PositionDeletesTable positionDeletesTable = new
PositionDeletesTable(table);
+
+ Expression expression =
+ Expressions.and(
+ Expressions.equal("partition.data_bucket", 1),
Expressions.greaterThan("pos", 0));
+ BatchScan scan = positionDeletesTable.newBatchScan().filter(expression);
+
assertThat(scan).isExactlyInstanceOf(PositionDeletesTable.PositionDeletesBatchScan.class);
+
+ List<ScanTask> tasks = Lists.newArrayList(scan.planFiles());
+
+ Assert.assertEquals(
+ "Expected to scan one delete manifest",
+ 1,
+ ((PositionDeletesTable.PositionDeletesBatchScan) scan)
+ .scanMetrics()
+ .scannedDeleteManifests()
+ .value());
+ Assert.assertEquals(
+ "Expected to skip three delete manifests",
+ 3,
+ ((PositionDeletesTable.PositionDeletesBatchScan) scan)
Review Comment:
It may be easier to read if you did the cast prior to this call.
##########
core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java:
##########
@@ -1040,4 +1047,195 @@ public void testAllManifestsTableSnapshotNot() {
expectedManifestListPaths(table.snapshots(), 1L, 3L, 4L),
actualManifestListPaths(manifestsTableScan));
}
+
+ @Test
+ public void testPositionDeletesWithFilter() {
+ Assume.assumeTrue("Position deletes supported only for v2 tables",
formatVersion == 2);
+ preparePartitionedTable();
+
+ PositionDeletesTable positionDeletesTable = new
PositionDeletesTable(table);
+
+ Expression expression =
+ Expressions.and(
+ Expressions.equal("partition.data_bucket", 1),
Expressions.greaterThan("pos", 0));
+ BatchScan scan = positionDeletesTable.newBatchScan().filter(expression);
+
assertThat(scan).isExactlyInstanceOf(PositionDeletesTable.PositionDeletesBatchScan.class);
+
+ List<ScanTask> tasks = Lists.newArrayList(scan.planFiles());
+
+ Assert.assertEquals(
+ "Expected to scan one delete manifest",
+ 1,
+ ((PositionDeletesTable.PositionDeletesBatchScan) scan)
+ .scanMetrics()
+ .scannedDeleteManifests()
+ .value());
+ Assert.assertEquals(
+ "Expected to skip three delete manifests",
+ 3,
+ ((PositionDeletesTable.PositionDeletesBatchScan) scan)
+ .scanMetrics()
+ .skippedDeleteManifests()
+ .value());
+
+ assertThat(tasks).hasSize(1);
+
+ ScanTask task = tasks.get(0);
+ assertThat(task).isInstanceOf(PositionDeletesScanTask.class);
+
+ Types.StructType partitionType = Partitioning.partitionType(table);
+ PositionDeletesScanTask posDeleteTask = (PositionDeletesScanTask) task;
+
+ Assert.assertEquals(
+ "Expected correct partition on task",
+ 1,
+ (int) posDeleteTask.file().partition().get(0, Integer.class));
+ Assert.assertEquals(
+ "Expected correct partition on constant column",
+ 1,
+ (int)
+ ((StructLike)
Review Comment:
Same here and a few other places in this class.
##########
core/src/main/java/org/apache/iceberg/PositionDeletesTable.java:
##########
@@ -0,0 +1,252 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg;
+
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.LoadingCache;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.expressions.ManifestEvaluator;
+import org.apache.iceberg.expressions.ResidualEvaluator;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.CloseableIterator;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.apache.iceberg.types.TypeUtil;
+import org.apache.iceberg.types.Types;
+import org.apache.iceberg.util.ParallelIterable;
+import org.apache.iceberg.util.TableScanUtil;
+
+/**
+ * A {@link Table} implementation whose {@link Scan} provides {@link
PositionDeletesScanTask}, for
+ * reading of position delete files.
+ */
+public class PositionDeletesTable extends BaseMetadataTable {
+
+ private final Schema schema;
+
+ PositionDeletesTable(Table table) {
+ super(table, table.name() + ".position_deletes");
+ this.schema = calculateSchema();
+ }
+
+ PositionDeletesTable(Table table, String name) {
+ super(table, name);
+ this.schema = calculateSchema();
+ }
+
+ @Override
+ MetadataTableType metadataTableType() {
+ return MetadataTableType.POSITION_DELETES;
+ }
+
+ @Override
+ public TableScan newScan() {
+ throw new UnsupportedOperationException(
+ "Cannot create TableScan from table of type POSITION_DELETES");
+ }
+
+ @Override
+ public BatchScan newBatchScan() {
+ return new PositionDeletesBatchScan(table(), schema());
+ }
+
+ @Override
+ public Schema schema() {
+ return schema;
+ }
+
+ private Schema calculateSchema() {
+ Types.StructType partitionType = Partitioning.partitionType(table());
+ Schema result =
+ new Schema(
+ MetadataColumns.DELETE_FILE_PATH,
+ MetadataColumns.DELETE_FILE_POS,
+ Types.NestedField.optional(
+ MetadataColumns.DELETE_FILE_ROW_FIELD_ID,
+ MetadataColumns.DELETE_FILE_ROW_FIELD_NAME,
+ table().schema().asStruct(),
+ MetadataColumns.DELETE_FILE_ROW_DOC),
+ Types.NestedField.required(
+ MetadataColumns.PARTITION_COLUMN_ID,
+ "partition",
+ partitionType,
+ "Partition that position delete row belongs to"),
+ Types.NestedField.required(
+ MetadataColumns.SPEC_ID_COLUMN_ID,
+ "spec_id",
+ Types.IntegerType.get(),
+ MetadataColumns.SPEC_ID_COLUMN_DOC),
+ Types.NestedField.required(
+ MetadataColumns.FILE_PATH_COLUMN_ID,
+ "delete_file_path",
+ Types.StringType.get(),
+ MetadataColumns.FILE_PATH_COLUMN_DOC));
+
+ if (partitionType.fields().size() > 0) {
+ return result;
+ } else {
+ // avoid returning an empty struct, which is not always supported.
+ // instead, drop the partition field
+ return TypeUtil.selectNot(result,
Sets.newHashSet(MetadataColumns.PARTITION_COLUMN_ID));
+ }
+ }
+
+ public static class PositionDeletesBatchScan
+ extends SnapshotScan<BatchScan, ScanTask, ScanTaskGroup<ScanTask>>
implements BatchScan {
+
+ protected PositionDeletesBatchScan(Table table, Schema schema) {
+ super(table, schema, new TableScanContext());
+ }
+
+ protected PositionDeletesBatchScan(Table table, Schema schema,
TableScanContext context) {
+ super(table, schema, context);
+ }
+
+ @Override
+ protected PositionDeletesBatchScan newRefinedScan(
+ Table newTable, Schema newSchema, TableScanContext newContext) {
+ return new PositionDeletesBatchScan(newTable, newSchema, newContext);
+ }
+
+ @Override
+ public CloseableIterable<ScanTaskGroup<ScanTask>> planTasks() {
+ return TableScanUtil.planTaskGroups(
+ planFiles(), targetSplitSize(), splitLookback(),
splitOpenFileCost());
+ }
+
+ @Override
+ protected List<String> scanColumns() {
+ return context().returnColumnStats() ? DELETE_SCAN_WITH_STATS_COLUMNS :
DELETE_SCAN_COLUMNS;
+ }
+
+ @Override
+ protected CloseableIterable<ScanTask> doPlanFiles() {
+ String schemaString = SchemaParser.toJson(tableSchema());
+
+ // prepare transformed partition specs and caches
+ Map<Integer, PartitionSpec> transformedSpecs =
+ table().specs().values().stream()
+ .map(spec -> transformSpec(tableSchema(), spec))
+ .collect(Collectors.toMap(PartitionSpec::specId, spec -> spec));
+
+ LoadingCache<Integer, ResidualEvaluator> residualCache =
+ partitionCacheOf(
+ transformedSpecs,
+ spec ->
+ ResidualEvaluator.of(
+ spec,
+ shouldIgnoreResiduals() ? Expressions.alwaysTrue() :
filter(),
+ isCaseSensitive()));
+
+ LoadingCache<Integer, String> specStringCache =
+ partitionCacheOf(transformedSpecs, PartitionSpecParser::toJson);
+
+ LoadingCache<Integer, ManifestEvaluator> evalCache =
+ partitionCacheOf(
+ transformedSpecs,
+ spec -> ManifestEvaluator.forRowFilter(filter(), spec,
isCaseSensitive()));
+
+ // iterate through delete manifests
+ CloseableIterable<ManifestFile> deleteManifests =
Review Comment:
nit: This logic looks good but the Spotless formatting makes it a bit hard
to read as lots of calls end up on separate lines, which makes them chunky.
Maybe, adding empty lines between these calls and restructuring the code can
help a bit.
```
List<ManifestFile> manifests = snapshot().deleteManifests(table().io());
CloseableIterable<ManifestFile> matchingManifests =
CloseableIterable.filter(
scanMetrics().skippedDeleteManifests(),
CloseableIterable.withNoopClose(manifests),
manifest ->
evalCache.get(manifest.partitionSpecId()).eval(manifest));
matchingManifests =
CloseableIterable.count(scanMetrics().scannedDeleteManifests(),
matchingManifests);
Iterable<CloseableIterable<ScanTask>> tasks =
CloseableIterable.transform(
matchingManifests,
manifest ->
posDeletesScanTasks(
manifest,
tableSchemaString,
transformedSpecs,
residualCache,
specStringCache));
```
This is completely up to you, @szehon-ho.
##########
core/src/main/java/org/apache/iceberg/PositionDeletesTable.java:
##########
@@ -0,0 +1,252 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg;
+
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.LoadingCache;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.expressions.ManifestEvaluator;
+import org.apache.iceberg.expressions.ResidualEvaluator;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.CloseableIterator;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.apache.iceberg.types.TypeUtil;
+import org.apache.iceberg.types.Types;
+import org.apache.iceberg.util.ParallelIterable;
+import org.apache.iceberg.util.TableScanUtil;
+
+/**
+ * A {@link Table} implementation whose {@link Scan} provides {@link
PositionDeletesScanTask}, for
+ * reading of position delete files.
+ */
+public class PositionDeletesTable extends BaseMetadataTable {
+
+ private final Schema schema;
+
+ PositionDeletesTable(Table table) {
+ super(table, table.name() + ".position_deletes");
+ this.schema = calculateSchema();
+ }
+
+ PositionDeletesTable(Table table, String name) {
+ super(table, name);
+ this.schema = calculateSchema();
+ }
+
+ @Override
+ MetadataTableType metadataTableType() {
+ return MetadataTableType.POSITION_DELETES;
+ }
+
+ @Override
+ public TableScan newScan() {
+ throw new UnsupportedOperationException(
+ "Cannot create TableScan from table of type POSITION_DELETES");
+ }
+
+ @Override
+ public BatchScan newBatchScan() {
+ return new PositionDeletesBatchScan(table(), schema());
+ }
+
+ @Override
+ public Schema schema() {
+ return schema;
+ }
+
+ private Schema calculateSchema() {
+ Types.StructType partitionType = Partitioning.partitionType(table());
+ Schema result =
+ new Schema(
+ MetadataColumns.DELETE_FILE_PATH,
+ MetadataColumns.DELETE_FILE_POS,
+ Types.NestedField.optional(
+ MetadataColumns.DELETE_FILE_ROW_FIELD_ID,
+ MetadataColumns.DELETE_FILE_ROW_FIELD_NAME,
+ table().schema().asStruct(),
+ MetadataColumns.DELETE_FILE_ROW_DOC),
+ Types.NestedField.required(
+ MetadataColumns.PARTITION_COLUMN_ID,
+ "partition",
+ partitionType,
+ "Partition that position delete row belongs to"),
+ Types.NestedField.required(
+ MetadataColumns.SPEC_ID_COLUMN_ID,
+ "spec_id",
+ Types.IntegerType.get(),
+ MetadataColumns.SPEC_ID_COLUMN_DOC),
+ Types.NestedField.required(
+ MetadataColumns.FILE_PATH_COLUMN_ID,
+ "delete_file_path",
+ Types.StringType.get(),
+ MetadataColumns.FILE_PATH_COLUMN_DOC));
+
+ if (partitionType.fields().size() > 0) {
+ return result;
+ } else {
+ // avoid returning an empty struct, which is not always supported.
+ // instead, drop the partition field
+ return TypeUtil.selectNot(result,
Sets.newHashSet(MetadataColumns.PARTITION_COLUMN_ID));
+ }
+ }
+
+ public static class PositionDeletesBatchScan
+ extends SnapshotScan<BatchScan, ScanTask, ScanTaskGroup<ScanTask>>
implements BatchScan {
+
+ protected PositionDeletesBatchScan(Table table, Schema schema) {
+ super(table, schema, new TableScanContext());
+ }
+
+ protected PositionDeletesBatchScan(Table table, Schema schema,
TableScanContext context) {
+ super(table, schema, context);
+ }
+
+ @Override
+ protected PositionDeletesBatchScan newRefinedScan(
+ Table newTable, Schema newSchema, TableScanContext newContext) {
+ return new PositionDeletesBatchScan(newTable, newSchema, newContext);
+ }
+
+ @Override
+ public CloseableIterable<ScanTaskGroup<ScanTask>> planTasks() {
+ return TableScanUtil.planTaskGroups(
+ planFiles(), targetSplitSize(), splitLookback(),
splitOpenFileCost());
+ }
+
+ @Override
+ protected List<String> scanColumns() {
+ return context().returnColumnStats() ? DELETE_SCAN_WITH_STATS_COLUMNS :
DELETE_SCAN_COLUMNS;
+ }
+
+ @Override
+ protected CloseableIterable<ScanTask> doPlanFiles() {
+ String schemaString = SchemaParser.toJson(tableSchema());
+
+ // prepare transformed partition specs and caches
+ Map<Integer, PartitionSpec> transformedSpecs =
+ table().specs().values().stream()
+ .map(spec -> transformSpec(tableSchema(), spec))
+ .collect(Collectors.toMap(PartitionSpec::specId, spec -> spec));
+
+ LoadingCache<Integer, ResidualEvaluator> residualCache =
+ partitionCacheOf(
+ transformedSpecs,
+ spec ->
+ ResidualEvaluator.of(
+ spec,
+ shouldIgnoreResiduals() ? Expressions.alwaysTrue() :
filter(),
+ isCaseSensitive()));
+
+ LoadingCache<Integer, String> specStringCache =
+ partitionCacheOf(transformedSpecs, PartitionSpecParser::toJson);
+
+ LoadingCache<Integer, ManifestEvaluator> evalCache =
+ partitionCacheOf(
+ transformedSpecs,
+ spec -> ManifestEvaluator.forRowFilter(filter(), spec,
isCaseSensitive()));
+
+ // iterate through delete manifests
+ CloseableIterable<ManifestFile> deleteManifests =
+
CloseableIterable.withNoopClose(snapshot().deleteManifests(table().io()));
+ CloseableIterable<ManifestFile> filteredManifests =
+ CloseableIterable.filter(
+ scanMetrics().skippedDeleteManifests(),
+ deleteManifests,
+ manifest ->
evalCache.get(manifest.partitionSpecId()).eval(manifest));
+ filteredManifests =
Review Comment:
Either call them `manifests/filteredManifests` or
`deleteManifests/filteredDeleteManifests` to be consistent.
##########
core/src/test/java/org/apache/iceberg/TestMetadataTableScans.java:
##########
@@ -1040,4 +1047,195 @@ public void testAllManifestsTableSnapshotNot() {
expectedManifestListPaths(table.snapshots(), 1L, 3L, 4L),
actualManifestListPaths(manifestsTableScan));
}
+
+ @Test
+ public void testPositionDeletesWithFilter() {
+ Assume.assumeTrue("Position deletes supported only for v2 tables",
formatVersion == 2);
+ preparePartitionedTable();
+
+ PositionDeletesTable positionDeletesTable = new
PositionDeletesTable(table);
+
+ Expression expression =
+ Expressions.and(
+ Expressions.equal("partition.data_bucket", 1),
Expressions.greaterThan("pos", 0));
+ BatchScan scan = positionDeletesTable.newBatchScan().filter(expression);
+
assertThat(scan).isExactlyInstanceOf(PositionDeletesTable.PositionDeletesBatchScan.class);
+
+ List<ScanTask> tasks = Lists.newArrayList(scan.planFiles());
+
+ Assert.assertEquals(
+ "Expected to scan one delete manifest",
+ 1,
+ ((PositionDeletesTable.PositionDeletesBatchScan) scan)
+ .scanMetrics()
+ .scannedDeleteManifests()
+ .value());
+ Assert.assertEquals(
+ "Expected to skip three delete manifests",
+ 3,
+ ((PositionDeletesTable.PositionDeletesBatchScan) scan)
+ .scanMetrics()
+ .skippedDeleteManifests()
+ .value());
+
+ assertThat(tasks).hasSize(1);
+
+ ScanTask task = tasks.get(0);
+ assertThat(task).isInstanceOf(PositionDeletesScanTask.class);
+
+ Types.StructType partitionType = Partitioning.partitionType(table);
+ PositionDeletesScanTask posDeleteTask = (PositionDeletesScanTask) task;
+
+ Assert.assertEquals(
+ "Expected correct partition on task",
+ 1,
+ (int) posDeleteTask.file().partition().get(0, Integer.class));
+ Assert.assertEquals(
+ "Expected correct partition on constant column",
+ 1,
+ (int)
+ ((StructLike)
+ constantsMap(posDeleteTask, partitionType)
+ .get(MetadataColumns.PARTITION_COLUMN_ID))
+ .get(0, Integer.class));
+
+ Assert.assertEquals(
+ "Expected correct partition spec id on task", 0,
posDeleteTask.file().specId());
+ Assert.assertEquals(
+ "Expected correct partition spec id on constant column",
+ 0,
+ (constantsMap(posDeleteTask,
partitionType).get(MetadataColumns.SPEC_ID.fieldId())));
+
+ Assert.assertEquals(
+ "Expected correct delete file on task", FILE_B_DELETES.path(),
posDeleteTask.file().path());
+ Assert.assertEquals(
+ "Expected correct delete file on constant column",
+ FILE_B_DELETES.path(),
+ (constantsMap(posDeleteTask,
partitionType).get(MetadataColumns.FILE_PATH.fieldId())));
Review Comment:
Do we need these extra `()` in quite a few calls in this class?
##########
core/src/main/java/org/apache/iceberg/PositionDeletesTable.java:
##########
@@ -0,0 +1,252 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg;
+
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.github.benmanes.caffeine.cache.LoadingCache;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.expressions.ManifestEvaluator;
+import org.apache.iceberg.expressions.ResidualEvaluator;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.CloseableIterator;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.apache.iceberg.types.TypeUtil;
+import org.apache.iceberg.types.Types;
+import org.apache.iceberg.util.ParallelIterable;
+import org.apache.iceberg.util.TableScanUtil;
+
+/**
+ * A {@link Table} implementation whose {@link Scan} provides {@link
PositionDeletesScanTask}, for
+ * reading of position delete files.
+ */
+public class PositionDeletesTable extends BaseMetadataTable {
+
+ private final Schema schema;
+
+ PositionDeletesTable(Table table) {
+ super(table, table.name() + ".position_deletes");
+ this.schema = calculateSchema();
+ }
+
+ PositionDeletesTable(Table table, String name) {
+ super(table, name);
+ this.schema = calculateSchema();
+ }
+
+ @Override
+ MetadataTableType metadataTableType() {
+ return MetadataTableType.POSITION_DELETES;
+ }
+
+ @Override
+ public TableScan newScan() {
+ throw new UnsupportedOperationException(
+ "Cannot create TableScan from table of type POSITION_DELETES");
+ }
+
+ @Override
+ public BatchScan newBatchScan() {
+ return new PositionDeletesBatchScan(table(), schema());
+ }
+
+ @Override
+ public Schema schema() {
+ return schema;
+ }
+
+ private Schema calculateSchema() {
+ Types.StructType partitionType = Partitioning.partitionType(table());
+ Schema result =
+ new Schema(
+ MetadataColumns.DELETE_FILE_PATH,
+ MetadataColumns.DELETE_FILE_POS,
+ Types.NestedField.optional(
+ MetadataColumns.DELETE_FILE_ROW_FIELD_ID,
+ MetadataColumns.DELETE_FILE_ROW_FIELD_NAME,
+ table().schema().asStruct(),
+ MetadataColumns.DELETE_FILE_ROW_DOC),
+ Types.NestedField.required(
+ MetadataColumns.PARTITION_COLUMN_ID,
+ "partition",
+ partitionType,
+ "Partition that position delete row belongs to"),
+ Types.NestedField.required(
+ MetadataColumns.SPEC_ID_COLUMN_ID,
+ "spec_id",
+ Types.IntegerType.get(),
+ MetadataColumns.SPEC_ID_COLUMN_DOC),
+ Types.NestedField.required(
+ MetadataColumns.FILE_PATH_COLUMN_ID,
+ "delete_file_path",
+ Types.StringType.get(),
+ MetadataColumns.FILE_PATH_COLUMN_DOC));
+
+ if (partitionType.fields().size() > 0) {
+ return result;
+ } else {
+ // avoid returning an empty struct, which is not always supported.
+ // instead, drop the partition field
+ return TypeUtil.selectNot(result,
Sets.newHashSet(MetadataColumns.PARTITION_COLUMN_ID));
+ }
+ }
+
+ public static class PositionDeletesBatchScan
+ extends SnapshotScan<BatchScan, ScanTask, ScanTaskGroup<ScanTask>>
implements BatchScan {
+
+ protected PositionDeletesBatchScan(Table table, Schema schema) {
+ super(table, schema, new TableScanContext());
+ }
+
+ protected PositionDeletesBatchScan(Table table, Schema schema,
TableScanContext context) {
+ super(table, schema, context);
+ }
+
+ @Override
+ protected PositionDeletesBatchScan newRefinedScan(
+ Table newTable, Schema newSchema, TableScanContext newContext) {
+ return new PositionDeletesBatchScan(newTable, newSchema, newContext);
+ }
+
+ @Override
+ public CloseableIterable<ScanTaskGroup<ScanTask>> planTasks() {
+ return TableScanUtil.planTaskGroups(
+ planFiles(), targetSplitSize(), splitLookback(),
splitOpenFileCost());
+ }
+
+ @Override
+ protected List<String> scanColumns() {
+ return context().returnColumnStats() ? DELETE_SCAN_WITH_STATS_COLUMNS :
DELETE_SCAN_COLUMNS;
+ }
+
+ @Override
+ protected CloseableIterable<ScanTask> doPlanFiles() {
+ String schemaString = SchemaParser.toJson(tableSchema());
+
+ // prepare transformed partition specs and caches
+ Map<Integer, PartitionSpec> transformedSpecs =
+ table().specs().values().stream()
+ .map(spec -> transformSpec(tableSchema(), spec))
+ .collect(Collectors.toMap(PartitionSpec::specId, spec -> spec));
+
+ LoadingCache<Integer, ResidualEvaluator> residualCache =
+ partitionCacheOf(
+ transformedSpecs,
+ spec ->
+ ResidualEvaluator.of(
+ spec,
+ shouldIgnoreResiduals() ? Expressions.alwaysTrue() :
filter(),
+ isCaseSensitive()));
+
+ LoadingCache<Integer, String> specStringCache =
+ partitionCacheOf(transformedSpecs, PartitionSpecParser::toJson);
+
+ LoadingCache<Integer, ManifestEvaluator> evalCache =
+ partitionCacheOf(
+ transformedSpecs,
+ spec -> ManifestEvaluator.forRowFilter(filter(), spec,
isCaseSensitive()));
+
+ // iterate through delete manifests
+ CloseableIterable<ManifestFile> deleteManifests =
+
CloseableIterable.withNoopClose(snapshot().deleteManifests(table().io()));
+ CloseableIterable<ManifestFile> filteredManifests =
+ CloseableIterable.filter(
+ scanMetrics().skippedDeleteManifests(),
+ deleteManifests,
+ manifest ->
evalCache.get(manifest.partitionSpecId()).eval(manifest));
+ filteredManifests =
+ CloseableIterable.count(scanMetrics().scannedDeleteManifests(),
filteredManifests);
+ Iterable<CloseableIterable<ScanTask>> results =
Review Comment:
nit: Call it `tasks`?
##########
core/src/test/java/org/apache/iceberg/TestSplitPlanning.java:
##########
@@ -234,6 +234,22 @@ public void testSplitPlanningWithOffsetsUnableToSplit() {
"We should still only get 2 tasks per file", 32,
Iterables.size(scan.planTasks()));
}
+ @Test
+ public void testBasicSplitPlanningDeleteFiles() {
Review Comment:
I don't see a reason why we wouldn't store that. I think it was overlooked.
@szehon-ho, can we do that in a follow-up PR? Not urgent, at least we should
create an issue.
--
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]