the-other-tim-brown commented on code in PR #596:
URL: https://github.com/apache/incubator-xtable/pull/596#discussion_r1878331049
##########
xtable-core/src/main/java/org/apache/xtable/delta/DeltaConversionSource.java:
##########
@@ -99,11 +101,16 @@ public TableChange getTableChangeForCommit(Long
versionNumber) {
Snapshot snapshotAtVersion = deltaLog.getSnapshotAt(versionNumber,
Option.empty());
FileFormat fileFormat =
actionsConverter.convertToFileFormat(snapshotAtVersion.metadata().format().provider());
- Set<InternalDataFile> addedFiles = new HashSet<>();
- Set<InternalDataFile> removedFiles = new HashSet<>();
+
+ // All 3 of the following maps use data file path as the key
Review Comment:
nitpick: there are two maps? maybe just saying `data structures` is better
here. Can you add whether the paths are absolute or relative in this case as
well?
##########
xtable-core/src/main/java/org/apache/xtable/delta/DeltaConversionSource.java:
##########
@@ -112,19 +119,47 @@ public TableChange getTableChangeForCommit(Long
versionNumber) {
tableAtVersion.getReadSchema().getFields(),
true,
DeltaPartitionExtractor.getInstance(),
- DeltaStatsExtractor.getInstance()));
+ DeltaStatsExtractor.getInstance());
+ addedFiles.put(dataFile.getPhysicalPath(), dataFile);
+ String deleteVectorPath =
+ actionsConverter.extractDeletionVectorFile(snapshotAtVersion,
(AddFile) action);
+ if (deleteVectorPath != null) {
+ deletionVectors.add(deleteVectorPath);
+ }
} else if (action instanceof RemoveFile) {
- removedFiles.add(
+ InternalDataFile dataFile =
actionsConverter.convertRemoveActionToInternalDataFile(
(RemoveFile) action,
snapshotAtVersion,
fileFormat,
tableAtVersion.getPartitioningFields(),
- DeltaPartitionExtractor.getInstance()));
+ DeltaPartitionExtractor.getInstance());
+ removedFiles.put(dataFile.getPhysicalPath(), dataFile);
+ }
+ }
+
+ // In Delta Lake if delete vector information is added for an existing
data file, as a result of
+ // a delete operation, then a new RemoveFile action is added to the commit
log to remove the old
+ // 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) {
+ // validate that a Remove action is also added for the data file
+ if (removedFiles.containsKey(deletionVector)) {
+ addedFiles.remove(deletionVector);
+ removedFiles.remove(deletionVector);
+ } else {
+ log.warn(
Review Comment:
Should we error out in this case? Just wondering if this will lead to data
consistency issues
##########
xtable-core/src/main/java/org/apache/xtable/delta/DeltaStatsExtractor.java:
##########
@@ -246,6 +246,7 @@ private static class DeltaStats {
Map<String, Object> minValues;
Map<String, Object> maxValues;
Map<String, Object> nullCount;
+ boolean tightBounds;
Review Comment:
When parsing, you can add an option to the Jackson ObjectMapper to ignore
unknown fields as well to avoid issues with future delta versions adding new
fields our code is not aware of.
##########
xtable-core/src/test/java/org/apache/xtable/delta/TestDeltaActionsConverter.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.delta;
+
+import java.net.URISyntaxException;
+
+import org.apache.hadoop.fs.Path;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import org.apache.spark.sql.delta.DeltaLog;
+import org.apache.spark.sql.delta.Snapshot;
+import org.apache.spark.sql.delta.actions.AddFile;
+import org.apache.spark.sql.delta.actions.DeletionVectorDescriptor;
+
+import scala.Option;
+
+class TestDeltaActionsConverter {
+
+ @Test
+ void extractDeletionVector() throws URISyntaxException {
+ DeltaActionsConverter actionsConverter =
DeltaActionsConverter.getInstance();
+
+ int size = 123;
+ long time = 234L;
+ boolean dataChange = true;
+ String stats = "";
+ String filePath = "file:///file_path";
+ Snapshot snapshot = Mockito.mock(Snapshot.class);
+ DeltaLog deltaLog = Mockito.mock(DeltaLog.class);
+
+ DeletionVectorDescriptor deletionVector = null;
+ AddFile addFileAction =
+ new AddFile(filePath, null, size, time, dataChange, stats, null,
deletionVector);
+ Assertions.assertNull(actionsConverter.extractDeletionVectorFile(snapshot,
addFileAction));
+
+ deletionVector =
+ DeletionVectorDescriptor.onDiskWithAbsolutePath(
+ filePath, size, 42, Option.empty(), Option.empty());
+
+ addFileAction =
+ new AddFile(filePath, null, size, time, dataChange, stats, null,
deletionVector);
+
+ Mockito.when(snapshot.deltaLog()).thenReturn(deltaLog);
+ Mockito.when(deltaLog.dataPath()).thenReturn(new Path("file:///"));
Review Comment:
nitpick: can we make the path something longer than just the scheme here to
make this more realistic
--
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]