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 2022/01/05 07:49:42 UTC

[GitHub] [iceberg] huaxingao commented on a change in pull request #3845: Partition Metadata table breaks with a partition column named 'partitition'

huaxingao commented on a change in pull request #3845:
URL: https://github.com/apache/iceberg/pull/3845#discussion_r778606923



##########
File path: api/src/main/java/org/apache/iceberg/PartitionSpec.java
##########
@@ -337,16 +337,22 @@ private void checkAndAddPartitionName(String name) {
     }
 
     private void checkAndAddPartitionName(String name, Integer sourceColumnId) {
+      checkAndAddPartitionName(name, sourceColumnId, true);
+    }
+
+    private void checkAndAddPartitionName(String name, Integer sourceColumnId, boolean checkConflict) {
       Types.NestedField schemaField = schema.findField(name);
-      if (sourceColumnId != null) {
-        // for identity transform case we allow  conflicts between partition and schema field name as
-        //   long as they are sourced from the same schema field
-        Preconditions.checkArgument(schemaField == null || schemaField.fieldId() == sourceColumnId,
-            "Cannot create identity partition sourced from different field in schema: %s", name);
-      } else {
-        // for all other transforms we don't allow conflicts between partition name and schema field name
-        Preconditions.checkArgument(schemaField == null,
-            "Cannot create partition from name that exists in schema: %s", name);
+      if (checkConflict) {

Review comment:
       I agree it's a little odd that just the identity method has the `checkConflict` flag. But the only place that we don't need to check conflict and allow conflict between partition name and schema field name is `BaseMetadataTable#transformSpec`. All other transforms don't allow conflicts between partition name and schema field so the `checkConflict` flag defaults to true. Since it only can be false in `BaseMetadataTable#transformSpec`, I guess it might be ok to do it in the identity method than add to the builder?
   
   I tried to have a different function but couldn't come with a neat one. There are quite bit some code duplication. 
   
    I added some comment to explain a the flag. Hope it looks a little better now. 

##########
File path: spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/sql/TestPartitionedTable.java
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.spark.sql;
+
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.spark.SparkCatalogTestBase;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.List;
+import java.util.Map;
+
+public class TestPartitionedTable extends SparkCatalogTestBase {

Review comment:
       I moved the test to `TestMetadataTablesWithEvolution` and also add a test in `TestMetadataTableScans`.




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