-
Notifications
You must be signed in to change notification settings - Fork 188
Extract Delta Lake deletion vectors #661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * 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.xtable.model.storage; | ||
|
|
||
| import java.util.Iterator; | ||
| import java.util.function.Supplier; | ||
|
|
||
| import lombok.AccessLevel; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.NonNull; | ||
| import lombok.ToString; | ||
| import lombok.experimental.Accessors; | ||
| import lombok.experimental.FieldDefaults; | ||
| import lombok.experimental.SuperBuilder; | ||
|
|
||
| @Accessors(fluent = true) | ||
| @SuperBuilder(toBuilder = true) | ||
| @FieldDefaults(makeFinal = true, level = lombok.AccessLevel.PRIVATE) | ||
| @Getter | ||
| @ToString(callSuper = true) | ||
| @EqualsAndHashCode(callSuper = true) | ||
| public class InternalDeletionVector extends InternalFile { | ||
| // path (absolute with scheme) of data file to which this deletion vector belongs | ||
| @NonNull String dataFilePath; | ||
|
|
||
| // super.getFileSizeBytes() is the size of the deletion vector file | ||
| // super.getPhysicalPath() is the absolute path (with scheme) of the deletion vector file | ||
| // super.getRecordCount() is the count of records in the deletion vector file | ||
|
|
||
| // offset of deletion vector start in a deletion vector file | ||
| int offset; | ||
|
|
||
| /** | ||
| * binary representation of the deletion vector. The consumer can use the {@link | ||
| * #ordinalsIterator()} to extract the ordinals represented in the binary format. | ||
| */ | ||
| byte[] binaryRepresentation; | ||
|
|
||
| /** | ||
| * Supplier for an iterator that returns the ordinals of records deleted by this deletion vector | ||
| * in the linked data file, identified by {@link #dataFilePath}. | ||
| * | ||
| * <p>The {@link InternalDeletionVector} instance does not guarantee that a new or distinct result | ||
| * will be returned each time the supplier is invoked. However, the supplier is expected to return | ||
| * a new iterator for each call. | ||
| */ | ||
| @Getter(AccessLevel.NONE) | ||
| Supplier<Iterator<Long>> ordinalsSupplier; | ||
|
|
||
| /** | ||
| * @return An iterator that returns the ordinals of records deleted by this deletion vector in the | ||
| * linked data file. There is no guarantee that a new or distinct iterator will be returned | ||
| * each time the iterator is invoked. | ||
| */ | ||
| public Iterator<Long> ordinalsIterator() { | ||
| return ordinalsSupplier.get(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,11 +22,11 @@ | |
| import java.time.Instant; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.extern.log4j.Log4j2; | ||
|
|
@@ -53,6 +53,8 @@ | |
| import org.apache.xtable.model.schema.InternalSchema; | ||
| import org.apache.xtable.model.storage.FileFormat; | ||
| import org.apache.xtable.model.storage.InternalDataFile; | ||
| import org.apache.xtable.model.storage.InternalDeletionVector; | ||
| import org.apache.xtable.model.storage.InternalFile; | ||
| import org.apache.xtable.model.storage.InternalFilesDiff; | ||
| import org.apache.xtable.model.storage.PartitionFileGroup; | ||
| import org.apache.xtable.spi.extractor.ConversionSource; | ||
|
|
@@ -113,8 +115,8 @@ public TableChange getTableChangeForCommit(Long versionNumber) { | |
| // All 3 of the following data structures use data file's absolute path as the key | ||
| Map<String, InternalDataFile> addedFiles = new HashMap<>(); | ||
| Map<String, InternalDataFile> removedFiles = new HashMap<>(); | ||
| // Set of data file paths for which deletion vectors exists. | ||
| Set<String> deletionVectors = new HashSet<>(); | ||
| // Map of data file paths for which deletion vectors exists. | ||
| Map<String, InternalDeletionVector> deletionVectors = new HashMap<>(); | ||
|
|
||
| for (Action action : actionsForVersion) { | ||
| if (action instanceof AddFile) { | ||
|
|
@@ -129,10 +131,10 @@ public TableChange getTableChangeForCommit(Long versionNumber) { | |
| DeltaPartitionExtractor.getInstance(), | ||
| DeltaStatsExtractor.getInstance()); | ||
| addedFiles.put(dataFile.getPhysicalPath(), dataFile); | ||
| String deleteVectorPath = | ||
| actionsConverter.extractDeletionVectorFile(snapshotAtVersion, (AddFile) action); | ||
| if (deleteVectorPath != null) { | ||
| deletionVectors.add(deleteVectorPath); | ||
| InternalDeletionVector deletionVector = | ||
| actionsConverter.extractDeletionVector(snapshotAtVersion, (AddFile) action); | ||
| if (deletionVector != null) { | ||
| deletionVectors.put(deletionVector.dataFilePath(), deletionVector); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deletionVector.dataFilePath() points to the path of the associated Parquet Data File. We should use deletionVector.getPhysicalPath() instead. Thoughts? @ashvina There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the review @piyushdubey There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. I see on line 168, you are concatenating the deletion vectors to the Internal files, which will not add dv and data file both without skipping. Thanks for the clarification. |
||
| } | ||
| } else if (action instanceof RemoveFile) { | ||
| InternalDataFile dataFile = | ||
|
|
@@ -151,7 +153,7 @@ public TableChange getTableChangeForCommit(Long versionNumber) { | |
| // entry which is replaced by a new entry, AddFile with delete vector information. Since the | ||
| // same data file is removed and added, we need to remove it from the added and removed file | ||
| // maps which are used to track actual added and removed data files. | ||
| for (String deletionVector : deletionVectors) { | ||
| for (String deletionVector : deletionVectors.keySet()) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: the name |
||
| // validate that a Remove action is also added for the data file | ||
| if (removedFiles.containsKey(deletionVector)) { | ||
| addedFiles.remove(deletionVector); | ||
|
|
@@ -163,11 +165,15 @@ public TableChange getTableChangeForCommit(Long versionNumber) { | |
| } | ||
| } | ||
|
|
||
| List<InternalFile> allAddedFiles = | ||
| Stream.concat(addedFiles.values().stream(), deletionVectors.values().stream()) | ||
| .collect(Collectors.toList()); | ||
| InternalFilesDiff internalFilesDiff = | ||
| InternalFilesDiff.builder() | ||
| .filesAdded(addedFiles.values()) | ||
| .filesAdded(allAddedFiles) | ||
| .filesRemoved(removedFiles.values()) | ||
| .build(); | ||
|
|
||
| return TableChange.builder() | ||
| .tableAsOfChange(tableAtVersion) | ||
| .filesDiff(internalFilesDiff) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently when this field is set to a non-null value the
ordinalsIteratoris also set. I think it may be cleaner to remove this and rely directly on theordinalsIterator. Is there something in the future though where this may be used directly?My main worry is that future developers implementing support for deletion vectors may eagerly parse the data into this field.