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 2020/12/29 08:18:37 UTC

[GitHub] [iceberg] jun-he commented on a change in pull request #1993: Add additional partition spec update tests

jun-he commented on a change in pull request #1993:
URL: https://github.com/apache/iceberg/pull/1993#discussion_r549612154



##########
File path: core/src/test/java/org/apache/iceberg/TestTableUpdatePartitionSpec.java
##########
@@ -0,0 +1,182 @@
+/*
+ * 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.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.iceberg.expressions.Expressions.bucket;
+import static org.apache.iceberg.expressions.Expressions.truncate;
+
+@RunWith(Parameterized.class)
+public class TestTableUpdatePartitionSpec extends TableTestBase {
+
+  @Parameterized.Parameters
+  public static Object[][] parameters() {
+    return new Object[][] {
+        new Object[] { 1 },
+        new Object[] { 2 },
+    };
+  }
+
+  public TestTableUpdatePartitionSpec(int formatVersion) {
+    super(formatVersion);
+  }
+
+  @Before
+  public void verifyInitialSpec() {
+    PartitionSpec initialSpec = PartitionSpec.builderFor(table.schema()).bucket("data", 16).build();
+    Assert.assertEquals("Should use the expected initial spec", initialSpec, table.spec());
+    Assert.assertEquals(1000, table.spec().lastAssignedFieldId());
+    Assert.assertEquals(0, table.spec().specId());
+  }
+
+  @Test
+  public void testCommitUpdatedSpec() {
+    table.updateSpec()
+        .addField(bucket("id", 8))
+        .commit();
+
+    PartitionSpec evolvedSpec = PartitionSpec.builderFor(table.schema())
+        .withSpecId(1)
+        .bucket("data", 16)
+        .bucket("id", 8, "id_bucket_8")
+        .build();
+    Assert.assertEquals("Should append a partition field to the spec", evolvedSpec, table.spec());
+    Assert.assertEquals(1001, table.spec().lastAssignedFieldId());
+
+    table.updateSpec()
+        .removeField("id_bucket_8")
+        .removeField("data_bucket")
+        .addField(truncate("data", 8))
+        .commit();
+
+    V1Assert.assertEquals("Should soft delete id and data buckets", PartitionSpec.builderFor(table.schema())
+        .withSpecId(2)
+        .alwaysNull("data", "data_bucket")
+        .alwaysNull("id", "id_bucket_8")
+        .truncate("data", 8, "data_trunc_8")
+        .build(), table.spec());
+
+    V2Assert.assertEquals("Should hard delete id and data buckets", PartitionSpec.builderFor(table.schema())
+        .withSpecId(2)
+        .add(2, 1002, "data_trunc_8", "truncate[8]")
+        .build(), table.spec());
+
+    Assert.assertEquals(1002, table.spec().lastAssignedFieldId());
+  }
+
+  @Test
+  public void testNoopCommit() {
+    TableMetadata current = table.ops().current();
+    int currentVersion = TestTables.metadataVersion("test");
+
+    // no-op commit due to no-op
+    table.updateSpec().commit();
+    TableMetadata updated = table.ops().current();
+    Integer updatedVersion = TestTables.metadataVersion("test");
+    Assert.assertEquals(current, updated);
+    Assert.assertEquals(++currentVersion, updatedVersion.intValue());

Review comment:
       Thanks for the comments and updated the PR accordingly.




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



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