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 2019/12/27 21:57:48 UTC

[GitHub] [incubator-iceberg] rdblue commented on a change in pull request #315: [WIP] Incremental processing prototype

rdblue commented on a change in pull request #315: [WIP] Incremental processing prototype
URL: https://github.com/apache/incubator-iceberg/pull/315#discussion_r361752394
 
 

 ##########
 File path: core/src/test/java/org/apache/iceberg/TestIncrementalDataScan.java
 ##########
 @@ -0,0 +1,198 @@
+/*
+ * 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.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import java.util.List;
+import java.util.Set;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestIncrementalDataScan extends TableTestBase {
+
+  @Before
+  public void setupTableProperties() {
+    table.updateProperties().set(TableProperties.MANIFEST_MIN_MERGE_COUNT, "2").commit();
+  }
+
+  @Test
+  public void testInvalidScans() {
+    add(table.newAppend(), files("A"));
+    AssertHelpers.assertThrows(
+        "from and to snapshots cannot be the same, since from snapshot is exclusive and not part of the scan",
+        IllegalArgumentException.class, "from and to snapshots cannot be the same", () -> appendsBetweenScan(1, 1));
+  }
+
+  @Test
+  public void testAppends() {
+    add(table.newAppend(), files("A")); // 1
+    add(table.newAppend(), files("B"));
+    add(table.newAppend(), files("C"));
+    add(table.newAppend(), files("D"));
+    add(table.newAppend(), files("E")); // 5
+    Assert.assertEquals(Sets.newHashSet("B", "C", "D", "E"), appendsBetweenScan(1, 5));
+    Assert.assertEquals(Sets.newHashSet("C", "D", "E"), appendsBetweenScan(2, 5));
+  }
+
+  @Test
+  public void testReplaceOverwritesDeletes() {
+    add(table.newAppend(), files("A")); // 1
+    add(table.newAppend(), files("B"));
+    add(table.newAppend(), files("C"));
+    add(table.newAppend(), files("D"));
+    add(table.newAppend(), files("E")); // 5
+    Assert.assertEquals(Sets.newHashSet("B", "C", "D", "E"), appendsBetweenScan(1, 5));
+
+    replace(table.newRewrite(), files("A", "B", "C"), files("F", "G")); // 6
+    Assert.assertEquals("Replace commits are ignored", Sets.newHashSet("B", "C", "D", "E"), appendsBetweenScan(1, 6));
+    Assert.assertEquals(Sets.newHashSet("E"), appendsBetweenScan(4, 6));
+    // 6th snapshot is a replace. No new content is added
+    Assert.assertTrue("Replace commits are ignored", appendsBetweenScan(5, 6).isEmpty());
+    delete(table.newDelete(), files("D")); // 7
+    // 7th snapshot is a delete.
+    Assert.assertTrue("Replace and delete commits are ignored", appendsBetweenScan(5, 7).isEmpty());
+    Assert.assertTrue("Delete commits are ignored", appendsBetweenScan(6, 7).isEmpty());
+    // 8th snapshot is an overwrite
+    overwrite(table.newOverwrite(), files("H"), files("E"));
+
+    add(table.newAppend(), files("I")); // 9
+    // snapshots 6, 7 and 8 are ignored
+    Assert.assertEquals(Sets.newHashSet("B", "C", "D", "E", "I"), appendsBetweenScan(1, 9));
+    Assert.assertEquals(Sets.newHashSet("I"), appendsBetweenScan(6, 9));
+    Assert.assertEquals(Sets.newHashSet("I"), appendsBetweenScan(7, 9));
+    Assert.assertEquals(Sets.newHashSet("I"), appendsBetweenScan(8, 9));
+  }
+
+  @Test
+  public void testTransactions() {
+    Transaction transaction = table.newTransaction();
+
+    add(transaction.newAppend(), files("A")); // 1
+    add(transaction.newAppend(), files("B"));
+    add(transaction.newAppend(), files("C"));
+    add(transaction.newAppend(), files("D"));
+    add(transaction.newAppend(), files("E")); // 5
+    transaction.commitTransaction();
+    Assert.assertEquals(Sets.newHashSet("B", "C", "D", "E"), appendsBetweenScan(1, 5));
+
+    transaction = table.newTransaction();
+    replace(transaction.newRewrite(), files("A", "B", "C"), files("F", "G")); // 6
+    transaction.commitTransaction();
+    Assert.assertEquals("Replace commits are ignored", Sets.newHashSet("B", "C", "D", "E"), appendsBetweenScan(1, 6));
+    Assert.assertEquals(Sets.newHashSet("E"), appendsBetweenScan(4, 6));
+    // 6th snapshot is a replace. No new content is added
+    Assert.assertTrue("Replace commits are ignored", appendsBetweenScan(5, 6).isEmpty());
+
+    transaction = table.newTransaction();
+    delete(transaction.newDelete(), files("D")); // 7
+    transaction.commitTransaction();
+    // 7th snapshot is a delete.
+    Assert.assertTrue("Replace and delete commits are ignored", appendsBetweenScan(5, 7).isEmpty());
+    Assert.assertTrue("Delete commits are ignored", appendsBetweenScan(6, 7).isEmpty());
+
+    transaction = table.newTransaction();
+    // 8th snapshot is an overwrite
+    overwrite(transaction.newOverwrite(), files("H"), files("E"));
+    add(transaction.newAppend(), files("I")); // 9
+    transaction.commitTransaction();
+    // snapshots 6, 7 and 8 are ignored
+    Assert.assertEquals(Sets.newHashSet("B", "C", "D", "E", "I"), appendsBetweenScan(1, 9));
+    Assert.assertEquals(Sets.newHashSet("I"), appendsBetweenScan(6, 9));
+    Assert.assertEquals(Sets.newHashSet("I"), appendsBetweenScan(7, 9));
+    Assert.assertEquals(Sets.newHashSet("I"), appendsBetweenScan(8, 9));
+  }
+
+  @Test
+  public void testRollbacks() {
+    add(table.newAppend(), files("A"));
+    add(table.newAppend(), files("B"));
+    add(table.newAppend(), files("C"));
+    // Go back to snapshot "B"
+    table.rollback().toSnapshotId(2).commit();
+    Assert.assertEquals(2, table.currentSnapshot().snapshotId());
+    Assert.assertEquals(Sets.newHashSet("B"), appendsBetweenScan(1, 2));
+
+    Transaction transaction = table.newTransaction();
+    add(transaction.newAppend(), files("D"));
+    add(transaction.newAppend(), files("E"));
+    add(transaction.newAppend(), files("F"));
+    transaction.commitTransaction();
+    // Go back to snapshot "E"
+    table.rollback().toSnapshotId(5).commit();
+    Assert.assertEquals(5, table.currentSnapshot().snapshotId());
+    Assert.assertEquals(Sets.newHashSet("B", "D", "E"), appendsBetweenScan(1, 5));
+  }
+
+  private static DataFile file(String name) {
+    return DataFiles.builder(SPEC)
+            .withPath(name + ".parquet")
+            .withFileSizeInBytes(0)
+            .withPartitionPath("data_bucket=0") // easy way to set partition data for now
+            .withRecordCount(0)
 
 Review comment:
   I recommend making this at least 1. Otherwise, the files will be filtered out by some scan code.

----------------------------------------------------------------
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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org