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 2021/10/22 10:19:03 UTC
[GitHub] [iceberg] openinx commented on a change in pull request #3349: Spark: Fix NPE if streaming read since an expired snapshot.
openinx commented on a change in pull request #3349:
URL: https://github.com/apache/iceberg/pull/3349#discussion_r734408115
##########
File path: core/src/test/java/org/apache/iceberg/TestSnapshotUtil.java
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.apache.iceberg.util.SnapshotUtil;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class TestSnapshotUtil extends TableTestBase {
+ @Parameterized.Parameters(name = "formatVersion = {0}")
+ public static Object[] parameters() {
+ return new Object[]{1, 2};
+ }
+
+ public TestSnapshotUtil(int formatVersion) {
+ super(formatVersion);
+ }
+
+ @Test
+ public void testSnapshotUtil() {
+ Assert.assertEquals("Table should start empty", 0, listManifestFiles().size());
Review comment:
Nit: "Table should start empty" -> "Table should have no manifest"
##########
File path: core/src/test/java/org/apache/iceberg/TestSnapshotUtil.java
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.apache.iceberg.util.SnapshotUtil;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class TestSnapshotUtil extends TableTestBase {
+ @Parameterized.Parameters(name = "formatVersion = {0}")
+ public static Object[] parameters() {
+ return new Object[]{1, 2};
+ }
+
+ public TestSnapshotUtil(int formatVersion) {
+ super(formatVersion);
+ }
+
+ @Test
+ public void testSnapshotUtil() {
+ Assert.assertEquals("Table should start empty", 0, listManifestFiles().size());
+ Snapshot oldestSnapshot = SnapshotUtil.oldestSnapshot(table);
+ Assert.assertNull("Table snapshot is should be null", oldestSnapshot);
+
+ table.newFastAppend()
+ .appendFile(FILE_A)
+ .commit();
+ Snapshot firstSnapshot = table.currentSnapshot();
+
+ table.newAppend()
+ .appendFile(FILE_B)
Review comment:
It does not make sense for me to add the same file into apache iceberg table twice.
##########
File path: core/src/test/java/org/apache/iceberg/TestSnapshotUtil.java
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.apache.iceberg.util.SnapshotUtil;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class TestSnapshotUtil extends TableTestBase {
+ @Parameterized.Parameters(name = "formatVersion = {0}")
+ public static Object[] parameters() {
+ return new Object[]{1, 2};
+ }
+
+ public TestSnapshotUtil(int formatVersion) {
+ super(formatVersion);
+ }
+
+ @Test
+ public void testSnapshotUtil() {
+ Assert.assertEquals("Table should start empty", 0, listManifestFiles().size());
+ Snapshot oldestSnapshot = SnapshotUtil.oldestSnapshot(table);
+ Assert.assertNull("Table snapshot is should be null", oldestSnapshot);
+
+ table.newFastAppend()
+ .appendFile(FILE_A)
+ .commit();
+ Snapshot firstSnapshot = table.currentSnapshot();
+
+ table.newAppend()
+ .appendFile(FILE_B)
+ .commit();
+
+ table.newFastAppend()
+ .appendFile(FILE_B)
+ .commit();
+ Snapshot secondSnapshot = table.currentSnapshot();
+
+ table.newFastAppend()
+ .appendFile(FILE_C)
+ .commit();
+ Snapshot thirdSnapshot = table.currentSnapshot();
+
+ oldestSnapshot = SnapshotUtil.oldestSnapshot(table);
+ Assert.assertEquals("Table oldest snapshot should be first snapshot",
+ firstSnapshot.snapshotId(), oldestSnapshot.snapshotId());
+
+ table.expireSnapshots().expireOlderThan(System.currentTimeMillis()).retainLast(2).commit();
Review comment:
Now this unit case is trying to address several complex cases, I will recommend to make it into several separate unit cases:
* Get the oldest snapshot from an empty table;
* Get the oldest snapshot from a table with 1 or 2 commits;
* Get the oldest snapshot from a table with 1 commits but retain to keep 1 snapshot after expire action;
* Get the oldest snapshot from a table with 3 commits but retain to keep 2 snapshot after expire action
##########
File path: core/src/test/java/org/apache/iceberg/TestSnapshotUtil.java
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.apache.iceberg.util.SnapshotUtil;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class TestSnapshotUtil extends TableTestBase {
+ @Parameterized.Parameters(name = "formatVersion = {0}")
+ public static Object[] parameters() {
+ return new Object[]{1, 2};
+ }
+
+ public TestSnapshotUtil(int formatVersion) {
+ super(formatVersion);
+ }
+
+ @Test
+ public void testSnapshotUtil() {
+ Assert.assertEquals("Table should start empty", 0, listManifestFiles().size());
+ Snapshot oldestSnapshot = SnapshotUtil.oldestSnapshot(table);
+ Assert.assertNull("Table snapshot is should be null", oldestSnapshot);
Review comment:
Nit: "Table snapshot is should be null" -> "The oldest snapshot should be null"
--
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: issues-unsubscribe@iceberg.apache.org
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