rdblue commented on a change in pull request #922: URL: https://github.com/apache/incubator-iceberg/pull/922#discussion_r430019241
########## File path: api/src/test/java/org/apache/iceberg/TestPartitionSpecValidation.java ########## @@ -241,11 +241,25 @@ public void testAddPartitionFieldsWithAndWithoutFieldIds() { .add(1, "id_partition2", "bucket[5]") .add(1, 1005, "id_partition1", "bucket[4]") .truncate("s", 1, "custom_truncate") + .add(1, 1002, "id_partition3", "bucket[3]") .build(); Assert.assertEquals(1000, spec.fields().get(0).fieldId()); Assert.assertEquals(1005, spec.fields().get(1).fieldId()); Assert.assertEquals(1006, spec.fields().get(2).fieldId()); + Assert.assertEquals(1002, spec.fields().get(3).fieldId()); Assert.assertEquals(1006, spec.lastAssignedFieldId()); } + + @Test + public void testAddPartitionFieldsWithInvalidFieldId() { Review comment: Good call adding this test and the fix. ########## File path: core/src/main/java/org/apache/iceberg/PartitionSpecUpdate.java ########## @@ -0,0 +1,189 @@ +/* + * 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 com.google.common.base.Preconditions; +import com.google.common.collect.Maps; +import java.util.Map; + +/** + * PartitionSpec evolution API implementation. + */ +class PartitionSpecUpdate implements UpdatePartitionSpec { + + private final TableMetadata base; + private final TableOperations ops; + private PartitionSpec.Builder newSpecBuilder = null; + + PartitionSpecUpdate(TableOperations ops) { + this.ops = ops; + this.base = ops.current(); + } + + @Override + public PartitionSpec apply() { + Preconditions.checkNotNull(newSpecBuilder, "new partition spec is not set"); + return newSpecBuilder.build(); + } + + @Override + public UpdatePartitionSpec newSpec() { Review comment: I don't think it is a good idea to have a new spec "mode" in this API. By adding `newSpec`, we are splitting the API into two: one that is change-based and one that is a complete replacement. The methods added for the replacement mode aren't used for the change-based mode, which we can see from the `Preconditions` here. I think this is going to cause unnecessary confusion for callers. If we want to support the use case of completely replacing the current spec, then all we need is a `clear` method and then we can use the change-based methods: ```java table.updateSpec() .clear() .addField(date("ts")) .addField(bucket("id", 24)) .commit(); ``` I'm not sure we want to completely replace a spec, but I don't think we want to have two APIs in this update operation either way. ---------------------------------------------------------------- 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: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org