kumarpritam863 commented on code in PR #18739: URL: https://github.com/apache/iceberg/pull/18739#discussion_r4520136108
########## flink/v2.3/flink/src/test/java/org/apache/iceberg/flink/sink/dynamic/TestDynamicSinkUtil.java: ########## @@ -0,0 +1,82 @@ +/* + * 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.flink.sink.dynamic; + +import static org.apache.iceberg.types.Types.NestedField.optional; +import static org.apache.iceberg.types.Types.NestedField.required; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.util.Collections; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Schema; +import org.apache.iceberg.relocated.com.google.common.collect.Sets; +import org.apache.iceberg.types.Types; +import org.junit.jupiter.api.Test; + +class TestDynamicSinkUtil { + + private static final Schema SCHEMA = + new Schema( + required(1, "id", Types.IntegerType.get()), optional(2, "data", Types.StringType.get())); + + @Test + void testValidateUpsertSkippedWhenNotUpsert() { + assertThatCode( + () -> + DynamicSinkUtil.validateUpsert( + false, PartitionSpec.unpartitioned(), Collections.emptySet())) + .doesNotThrowAnyException(); + } + + @Test + void testValidateUpsertFailsWithoutEqualityFields() { + assertThatThrownBy( + () -> + DynamicSinkUtil.validateUpsert( + true, PartitionSpec.unpartitioned(), Collections.emptySet())) + .isInstanceOf(IllegalStateException.class) + .hasMessage( + "Equality field columns shouldn't be empty when configuring to use UPSERT data."); Review Comment: Agreed. Moving the check out of DynamicWriter left the wiring untested: removing the validateUpsert call from the processor, from the update operator, or from both did not fail any test. It's now covered at the processor and update-operator level, including upsert records on an older spec of the table in both directions (upsertOnOlderUnpartitionedSpecOfPartitionedTable and upsertOnOlderPartitionedSpecOfUnpartitionedTable). TestDynamicSinkUtil keeps the unit tests of the helper. -- 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]
