rdblue commented on a change in pull request #2275:
URL: https://github.com/apache/iceberg/pull/2275#discussion_r642705036



##########
File path: core/src/test/java/org/apache/iceberg/TestSchemaID.java
##########
@@ -0,0 +1,131 @@
+/*
+ * 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 java.util.List;
+import java.util.stream.IntStream;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.types.Types;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.iceberg.TestHelpers.assertSameSchemaMap;
+import static org.apache.iceberg.types.Types.NestedField.optional;
+import static org.apache.iceberg.types.Types.NestedField.required;
+
+@RunWith(Parameterized.class)
+public class TestSchemaID extends TableTestBase {
+
+  @Parameterized.Parameters(name = "formatVersion = {0}")
+  public static Object[] parameters() {
+    return new Object[] { 1, 2 };
+  }
+
+  public TestSchemaID(int formatVersion) {
+    super(formatVersion);
+  }
+
+  @Test
+  public void testNoChange() {
+    // add files to table
+    table.newAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+
+    validateSingleSchema();
+    validateSnapshotsAndHistoryEntries(ImmutableList.of(0));

Review comment:
       It isn't very obvious what is being validated by these methods. I think 
it would be better to make them more readable so that the context is obvious. I 
think I would write it more like this:
   
   ```
   Map<Integer, Schema> schemaMap(Schema... schemas);
   
   ...
   assertEquals("Should have only one defined schema", 
schemaMap(table.schema()), table);
   assertEquals("Schema id should be the current", table.schema().schemaId(), 
table.currentSnapshot().schemaId());
   ```
   
   I think that what you're doing in `validateSnapshotAndHistoryEntries` does 
make sense, but it would be more readable if you did more of the work in this 
method:
   
   ```java
   int onlyId = table.schema().schemaId();
   assertEquals("Schema ids should be correct in snapshots",
       ImmutableList.of(onlyId, onlyId),
       Iterables.transform(table.snapshots(), Snapshot::schemaId);
   ```
   
   I think the extra work of extracting the schema ids is worth the 
readability. I can see where the ids in the expected list are coming from, and 
I can see that we're validating that list against the schema ids of the 
snapshots. If you wanted to save room, you could make a method (`schemaIds`) to 
reuse the `Iterables.transform` or `Lists.transform` part.




-- 
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to