RussellSpitzer commented on a change in pull request #2936:
URL: https://github.com/apache/iceberg/pull/2936#discussion_r682956450



##########
File path: core/src/main/java/org/apache/iceberg/Partitioning.java
##########
@@ -177,4 +184,35 @@ public Void alwaysNull(int fieldId, String sourceName, int 
sourceId) {
       return null;
     }
   }
+
+  /**
+   * Builds a common partition type for all specs in a table.

Review comment:
       Could we add some detail in here? Seems like we are building a Struct 
which contains every field which has been part of a partitionspec in the past. 
So I would probably just write "Builds a struct containing all columns which 
have been ever been a part of a partition spec in this table"

##########
File path: core/src/main/java/org/apache/iceberg/Partitioning.java
##########
@@ -177,4 +184,35 @@ public Void alwaysNull(int fieldId, String sourceName, int 
sourceId) {
       return null;
     }
   }
+
+  /**
+   * Builds a common partition type for all specs in a table.
+   *
+   * @param table a table with one or many specs
+   * @return the constructed common partition type
+   */
+  public static StructType partitionType(Table table) {
+    Map<Integer, NestedField> commonFields = Maps.newHashMap();
+
+    for (PartitionSpec spec : table.specs().values()) {
+      List<NestedField> fields = spec.partitionType().fields();
+
+      for (NestedField field : fields) {
+        int fieldId = field.fieldId();
+        NestedField existingField = commonFields.get(fieldId);
+
+        // partition fields may conflict in v1 tables
+        ValidationException.check(existingField == null || 
existingField.equals(field),
+            "Specs contain conflicting partition fields with ID %d",

Review comment:
       Could output the existing field here as well to illustrate the conflict?

##########
File path: core/src/test/java/org/apache/iceberg/TestPartitioning.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 java.io.File;
+import java.io.IOException;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.types.Types;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import static org.apache.iceberg.types.Types.NestedField.required;
+
+public class TestPartitioning {
+
+  private static final Schema SCHEMA = new Schema(
+      required(1, "id", Types.IntegerType.get()),
+      required(2, "data", Types.StringType.get()),
+      required(3, "category", Types.StringType.get())
+  );
+
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+  private File tableDir = null;
+
+  @Before
+  public void setupTableDir() throws IOException {
+    this.tableDir = temp.newFolder();
+  }
+
+  @After
+  public void cleanupTables() {
+    TestTables.clearTables();
+  }
+
+  @Test

Review comment:
       Should we add a "works as expected" test here as well? I know we have it 
covered in the test metadata tables suite below but since we made this new file 
I thought might as well?




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

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