You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2020/09/12 00:17:23 UTC
[GitHub] [iceberg] chenjunjiedada commented on a change in pull request #1444: Spark: Apply row-level delete files when reading
chenjunjiedada commented on a change in pull request #1444:
URL: https://github.com/apache/iceberg/pull/1444#discussion_r487340953
##########
File path: data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
##########
@@ -0,0 +1,231 @@
+/*
+ * Licensed 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.data;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.iceberg.Accessor;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.DeleteFile;
+import org.apache.iceberg.FileContent;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.MetadataColumns;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.StructLike;
+import org.apache.iceberg.avro.Avro;
+import org.apache.iceberg.data.avro.DataReader;
+import org.apache.iceberg.data.parquet.GenericParquetReaders;
+import org.apache.iceberg.deletes.Deletes;
+import org.apache.iceberg.expressions.Expressions;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.parquet.Parquet;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.relocated.com.google.common.collect.Multimap;
+import org.apache.iceberg.relocated.com.google.common.collect.Multimaps;
+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.StructLikeSet;
+import org.apache.iceberg.util.StructProjection;
+import org.apache.parquet.Preconditions;
+
+public abstract class DeleteFilter<T> {
+ private static final long DEFAULT_SET_FILTER_THRESHOLD = 100_000L;
+ private static final Schema POS_DELETE_SCHEMA = new Schema(
+ MetadataColumns.DELETE_FILE_PATH,
+ MetadataColumns.DELETE_FILE_POS);
+
+ private final long setFilterThreshold;
+ private final FileIO io;
+ private final DataFile dataFile;
+ private final List<DeleteFile> posDeletes;
+ private final List<DeleteFile> eqDeletes;
+ private final Schema requiredSchema;
+ private final Accessor<StructLike> posAccessor;
+
+ public DeleteFilter(FileIO io, FileScanTask task, Schema tableSchema, Schema requestedSchema) {
+ this.setFilterThreshold = DEFAULT_SET_FILTER_THRESHOLD;
+ this.io = io;
+ this.dataFile = task.file();
+
+ ImmutableList.Builder<DeleteFile> posDeleteBuilder = ImmutableList.builder();
+ ImmutableList.Builder<DeleteFile> eqDeleteBuilder = ImmutableList.builder();
+ for (DeleteFile delete : task.deletes()) {
+ switch (delete.content()) {
+ case POSITION_DELETES:
+ posDeleteBuilder.add(delete);
+ break;
+ case EQUALITY_DELETES:
+ eqDeleteBuilder.add(delete);
+ break;
+ default:
+ throw new UnsupportedOperationException("Unknown delete file content: " + delete.content());
+ }
+ }
+
+ this.posDeletes = posDeleteBuilder.build();
+ this.eqDeletes = eqDeleteBuilder.build();
+ this.requiredSchema = fileProjection(tableSchema, requestedSchema, posDeletes, eqDeletes);
+ this.posAccessor = requiredSchema.accessorForField(MetadataColumns.ROW_POSITION.fieldId());
+ }
+
+ public Schema requiredSchema() {
+ return requiredSchema;
+ }
+
+ Accessor<StructLike> posAccessor() {
+ return posAccessor;
+ }
+
+ protected abstract StructLike asStructLike(T record);
+
+ protected long pos(T record) {
+ return (Long) posAccessor.get(asStructLike(record));
+ }
+
+ public CloseableIterable<T> filter(CloseableIterable<T> records) {
+ return applyEqDeletes(applyPosDeletes(records));
Review comment:
We might want to do minor compaction to transform the equality delete files to position delete files, so I guess position deletes should be more than equality deletes as time goes on.
The records in position deletes are ordered, so the sorted merge-base check wouldn't be more expensive than set based check consider the cost of building the hash set. Right?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org