rdblue commented on code in PR #7569: URL: https://github.com/apache/iceberg/pull/7569#discussion_r1199831398
########## core/src/main/java/org/apache/iceberg/rest/requests/CommitTransactionRequest.java: ########## @@ -0,0 +1,50 @@ +/* + * 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.rest.requests; + +import java.util.List; +import org.apache.iceberg.MetadataUpdate; +import org.apache.iceberg.catalog.TableIdentifier; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.rest.RESTRequest; +import org.immutables.value.Value; + [email protected] +public interface CommitTransactionRequest extends RESTRequest { + List<CommitTableRequest> tableChanges(); + + @Override + default void validate() { + check(); + } + + @Value.Check + default void check() { + Preconditions.checkArgument(!tableChanges().isEmpty(), "Invalid table changes: empty"); + } + + @Value.Immutable + interface CommitTableRequest { Review Comment: It seems confusing to have a `CommitTableRequest` and an `UpdateTableRequest` that are basically the same thing but with or without the identifier. Then there is also the [naming problem in the spec](https://github.com/apache/iceberg/pull/7569/files#r1189516857). Those issues are a bit of a red flag that we need to address duplication. I think there are two options. First, we could reuse the `UpdateTableRequest` directly and pull the identifier to a higher level, like this: ```json CommitTransactionRequest: type: array items: $ref: '#/components/schemas/TransactionCommit' TransactionCommit: type: object required: - identifier - commit properties: identifier: $ref: '#/components/schemas/TableIdentifier' request: $ref: '#/components/schemas/CommitTableRequest' CommitTableRequest: type: object required: - requirements - updates properties: requirements: type: array items: $ref: '#/components/schemas/TableRequirement' updates: type: array items: $ref: '#/components/schemas/TableUpdate' ``` That's okay, but still fairly awkward. The next option is to reuse the existing schema directly and just add an optional identifier field: ```json CommitTransactionRequest: type: array items: description: Each table commit request must provide an `identifier` $ref: '#/components/schemas/CommitTableRequest' CommitTableRequest: type: object required: - requirements - updates properties: identifier: description: Table identifier to update; must be present for CommitTransactionRequest $ref: '#/components/schemas/TableIdentifier' requirements: type: array items: $ref: '#/components/schemas/TableRequirement' updates: type: array items: $ref: '#/components/schemas/TableUpdate' ``` I prefer the second option. It's not a problem to add an optional field and ensure it is set when the object is used in a transaction. We'd also want to check that the identifier is either not set or is set to the same table in a normal table update. -- 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]
