You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by bl...@apache.org on 2019/12/30 17:53:53 UTC

[incubator-iceberg] branch master updated: Project all DataFile columns for Snapshot.addedFiles (#718)

This is an automated email from the ASF dual-hosted git repository.

blue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new ca54729  Project all DataFile columns for Snapshot.addedFiles (#718)
ca54729 is described below

commit ca54729ab920ae47cf4fea8651d14b028693fea0
Author: Chen, Junjie <ch...@gmail.com>
AuthorDate: Tue Dec 31 01:53:45 2019 +0800

    Project all DataFile columns for Snapshot.addedFiles (#718)
---
 .../main/java/org/apache/iceberg/BaseSnapshot.java |  2 +-
 .../java/org/apache/iceberg/ManifestReader.java    |  2 +-
 .../test/java/org/apache/iceberg/TestSnapshot.java | 74 ++++++++++++++++++++++
 3 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/core/src/main/java/org/apache/iceberg/BaseSnapshot.java b/core/src/main/java/org/apache/iceberg/BaseSnapshot.java
index 9632623..c7b1559 100644
--- a/core/src/main/java/org/apache/iceberg/BaseSnapshot.java
+++ b/core/src/main/java/org/apache/iceberg/BaseSnapshot.java
@@ -163,7 +163,7 @@ class BaseSnapshot implements Snapshot {
         manifest -> Objects.equal(manifest.snapshotId(), snapshotId));
     try (CloseableIterable<ManifestEntry> entries = new ManifestGroup(io, changedManifests)
         .ignoreExisting()
-        .select(ManifestReader.CHANGE_WITH_STATS_COLUMNS)
+        .select(ManifestReader.ALL_COLUMNS)
         .entries()) {
       for (ManifestEntry entry : entries) {
         switch (entry.status()) {
diff --git a/core/src/main/java/org/apache/iceberg/ManifestReader.java b/core/src/main/java/org/apache/iceberg/ManifestReader.java
index e258d41..bb052ed 100644
--- a/core/src/main/java/org/apache/iceberg/ManifestReader.java
+++ b/core/src/main/java/org/apache/iceberg/ManifestReader.java
@@ -49,7 +49,7 @@ import static org.apache.iceberg.expressions.Expressions.alwaysTrue;
 public class ManifestReader extends CloseableGroup implements Filterable<FilteredManifest> {
   private static final Logger LOG = LoggerFactory.getLogger(ManifestReader.class);
 
-  private static final ImmutableList<String> ALL_COLUMNS = ImmutableList.of("*");
+  static final ImmutableList<String> ALL_COLUMNS = ImmutableList.of("*");
   static final ImmutableList<String> CHANGE_COLUMNS = ImmutableList.of(
       "file_path", "file_format", "partition", "record_count", "file_size_in_bytes");
   static final ImmutableList<String> CHANGE_WITH_STATS_COLUMNS = ImmutableList.<String>builder()
diff --git a/core/src/test/java/org/apache/iceberg/TestSnapshot.java b/core/src/test/java/org/apache/iceberg/TestSnapshot.java
new file mode 100644
index 0000000..1374fbe
--- /dev/null
+++ b/core/src/test/java/org/apache/iceberg/TestSnapshot.java
@@ -0,0 +1,74 @@
+/*
+ * 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 org.junit.Test;
+
+public class TestSnapshot extends TableTestBase {
+
+  @Test
+  public void testAppendFilesFromTable() {
+    table.newFastAppend()
+        .appendFile(FILE_A)
+        .appendFile(FILE_B)
+        .commit();
+
+    // collect data files from deserialization
+    Iterable<DataFile> filesToAdd = table.currentSnapshot().addedFiles();
+
+    table.newDelete().deleteFile(FILE_A).deleteFile(FILE_B).commit();
+
+    Snapshot oldSnapshot = table.currentSnapshot();
+
+    AppendFiles fastAppend = table.newFastAppend();
+    for (DataFile file : filesToAdd) {
+      fastAppend.appendFile(file);
+    }
+
+    Snapshot newSnapshot = fastAppend.apply();
+    validateSnapshot(oldSnapshot, newSnapshot, FILE_A, FILE_B);
+  }
+
+  @Test
+  public void testAppendFoundFiles() {
+    table.newFastAppend()
+        .appendFile(FILE_A)
+        .appendFile(FILE_B)
+        .commit();
+
+    Iterable<DataFile> filesToAdd = FindFiles.in(table)
+        .inPartition(table.spec(), StaticDataTask.Row.of(0))
+        .inPartition(table.spec(), StaticDataTask.Row.of(1))
+        .collect();
+
+    table.newDelete().deleteFile(FILE_A).deleteFile(FILE_B).commit();
+
+    Snapshot oldSnapshot = table.currentSnapshot();
+
+    AppendFiles fastAppend = table.newFastAppend();
+    for (DataFile file : filesToAdd) {
+      fastAppend.appendFile(file);
+    }
+
+    Snapshot newSnapshot = fastAppend.apply();
+    validateSnapshot(oldSnapshot, newSnapshot, FILE_A, FILE_B);
+  }
+
+}