kbendick commented on code in PR #4514: URL: https://github.com/apache/iceberg/pull/4514#discussion_r844116305
########## core/src/test/java/org/apache/iceberg/TestV1ToV2RowDeltaDelete.java: ########## @@ -0,0 +1,202 @@ +/* + * 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.util.List; +import org.apache.iceberg.relocated.com.google.common.collect.Iterables; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.relocated.com.google.common.collect.Sets; +import org.junit.Assert; +import org.junit.Test; + +import static org.apache.iceberg.expressions.Expressions.bucket; +import static org.apache.iceberg.expressions.Expressions.equal; + +public class TestV1ToV2RowDeltaDelete extends TableTestBase { + + public TestV1ToV2RowDeltaDelete() { + super(1 /* table format version */); + } + + static final DeleteFile FILE_A_POS_1 = FileMetadata.deleteFileBuilder(SPEC) + .ofPositionDeletes() + .withPath("/path/to/data-a-pos-deletes.parquet") + .withFileSizeInBytes(10) + .withPartition(FILE_A.partition()) + .withRecordCount(1) + .build(); + + static final DeleteFile FILE_A_EQ_1 = FileMetadata.deleteFileBuilder(SPEC) + .ofEqualityDeletes() + .withPath("/path/to/data-a-eq-deletes.parquet") + .withFileSizeInBytes(10) + .withPartition(FILE_A.partition()) + .withRecordCount(1) + .build(); + + + @Test + public void testPartitionedTableWithPartitionEqDeletes() { + table.newAppend() + .appendFile(FILE_A) + .appendFile(FILE_B) + .appendFile(FILE_C) + .appendFile(FILE_D) + .commit(); + + // update table version to 2 + TableOperations ops = ((BaseTable) table).operations(); + TableMetadata base = ops.current(); + ops.commit(base, base.upgradeToFormatVersion(2)); + + table.newRowDelta() + .addDeletes(FILE_A_EQ_1) + .commit(); + + List<FileScanTask> tasks = Lists.newArrayList(table.newScan().planFiles().iterator()); + Assert.assertEquals("Should have one task", 4, tasks.size()); + + FileScanTask task = tasks.get(0); + Assert.assertEquals("Should have one associated delete file", + 1, task.deletes().size()); + Assert.assertEquals("Should have only pos delete file", + FILE_A_EQ_1.path(), task.deletes().get(0).path()); + + table.newDelete().deleteFile(FILE_B).commit(); + tasks = Lists.newArrayList(table.newScan().planFiles().iterator()); + Assert.assertEquals("Should have one task", 3, tasks.size()); Review Comment: Nit: `Should have three tasks`. ########## core/src/test/java/org/apache/iceberg/TestV1ToV2RowDeltaDelete.java: ########## @@ -0,0 +1,202 @@ +/* + * 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.util.List; +import org.apache.iceberg.relocated.com.google.common.collect.Iterables; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.relocated.com.google.common.collect.Sets; +import org.junit.Assert; +import org.junit.Test; + +import static org.apache.iceberg.expressions.Expressions.bucket; +import static org.apache.iceberg.expressions.Expressions.equal; + +public class TestV1ToV2RowDeltaDelete extends TableTestBase { + + public TestV1ToV2RowDeltaDelete() { + super(1 /* table format version */); + } + + static final DeleteFile FILE_A_POS_1 = FileMetadata.deleteFileBuilder(SPEC) + .ofPositionDeletes() + .withPath("/path/to/data-a-pos-deletes.parquet") + .withFileSizeInBytes(10) + .withPartition(FILE_A.partition()) + .withRecordCount(1) + .build(); + + static final DeleteFile FILE_A_EQ_1 = FileMetadata.deleteFileBuilder(SPEC) + .ofEqualityDeletes() + .withPath("/path/to/data-a-eq-deletes.parquet") + .withFileSizeInBytes(10) + .withPartition(FILE_A.partition()) + .withRecordCount(1) + .build(); + + + @Test + public void testPartitionedTableWithPartitionEqDeletes() { + table.newAppend() + .appendFile(FILE_A) + .appendFile(FILE_B) + .appendFile(FILE_C) + .appendFile(FILE_D) + .commit(); + + // update table version to 2 + TableOperations ops = ((BaseTable) table).operations(); + TableMetadata base = ops.current(); + ops.commit(base, base.upgradeToFormatVersion(2)); + + table.newRowDelta() + .addDeletes(FILE_A_EQ_1) + .commit(); + + List<FileScanTask> tasks = Lists.newArrayList(table.newScan().planFiles().iterator()); + Assert.assertEquals("Should have one task", 4, tasks.size()); + + FileScanTask task = tasks.get(0); + Assert.assertEquals("Should have one associated delete file", + 1, task.deletes().size()); + Assert.assertEquals("Should have only pos delete file", + FILE_A_EQ_1.path(), task.deletes().get(0).path()); + + table.newDelete().deleteFile(FILE_B).commit(); + tasks = Lists.newArrayList(table.newScan().planFiles().iterator()); + Assert.assertEquals("Should have one task", 3, tasks.size()); + Assert.assertEquals("Should have one associated delete file", + 1, tasks.get(0).deletes().size()); + + // row delta delete-file will be dropped because minDataSequenceNumber calculated is wrong + // in the second commit. + table.newDelete().deleteFile(FILE_C).commit(); + tasks = Lists.newArrayList(table.newScan().planFiles().iterator()); + Assert.assertEquals("Should have one task", 2, tasks.size()); Review Comment: Nit: Wrong number of tasks in assertion statement. ########## core/src/test/java/org/apache/iceberg/TestV1ToV2RowDeltaDelete.java: ########## @@ -0,0 +1,202 @@ +/* + * 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.util.List; +import org.apache.iceberg.relocated.com.google.common.collect.Iterables; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.relocated.com.google.common.collect.Sets; +import org.junit.Assert; +import org.junit.Test; + +import static org.apache.iceberg.expressions.Expressions.bucket; +import static org.apache.iceberg.expressions.Expressions.equal; + +public class TestV1ToV2RowDeltaDelete extends TableTestBase { + + public TestV1ToV2RowDeltaDelete() { + super(1 /* table format version */); + } + + static final DeleteFile FILE_A_POS_1 = FileMetadata.deleteFileBuilder(SPEC) + .ofPositionDeletes() + .withPath("/path/to/data-a-pos-deletes.parquet") + .withFileSizeInBytes(10) + .withPartition(FILE_A.partition()) + .withRecordCount(1) + .build(); + + static final DeleteFile FILE_A_EQ_1 = FileMetadata.deleteFileBuilder(SPEC) + .ofEqualityDeletes() + .withPath("/path/to/data-a-eq-deletes.parquet") + .withFileSizeInBytes(10) + .withPartition(FILE_A.partition()) + .withRecordCount(1) + .build(); + + + @Test + public void testPartitionedTableWithPartitionEqDeletes() { + table.newAppend() + .appendFile(FILE_A) + .appendFile(FILE_B) + .appendFile(FILE_C) + .appendFile(FILE_D) + .commit(); + + // update table version to 2 + TableOperations ops = ((BaseTable) table).operations(); + TableMetadata base = ops.current(); + ops.commit(base, base.upgradeToFormatVersion(2)); + + table.newRowDelta() + .addDeletes(FILE_A_EQ_1) + .commit(); + + List<FileScanTask> tasks = Lists.newArrayList(table.newScan().planFiles().iterator()); + Assert.assertEquals("Should have one task", 4, tasks.size()); + + FileScanTask task = tasks.get(0); + Assert.assertEquals("Should have one associated delete file", + 1, task.deletes().size()); + Assert.assertEquals("Should have only pos delete file", + FILE_A_EQ_1.path(), task.deletes().get(0).path()); + + table.newDelete().deleteFile(FILE_B).commit(); + tasks = Lists.newArrayList(table.newScan().planFiles().iterator()); + Assert.assertEquals("Should have one task", 3, tasks.size()); + Assert.assertEquals("Should have one associated delete file", + 1, tasks.get(0).deletes().size()); + + // row delta delete-file will be dropped because minDataSequenceNumber calculated is wrong + // in the second commit. Review Comment: Nit: Does this comment still apply? This is the situation that we're fixing, right? If I understand correctly, this is what was causing the issue. If this comment is no longer applicable because we've fixed it, we should remove it. Maybe it would make a better comment on the PR? ########## core/src/test/java/org/apache/iceberg/TestV1ToV2RowDeltaDelete.java: ########## @@ -0,0 +1,202 @@ +/* + * 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.util.List; +import org.apache.iceberg.relocated.com.google.common.collect.Iterables; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.relocated.com.google.common.collect.Sets; +import org.junit.Assert; +import org.junit.Test; + +import static org.apache.iceberg.expressions.Expressions.bucket; +import static org.apache.iceberg.expressions.Expressions.equal; + +public class TestV1ToV2RowDeltaDelete extends TableTestBase { + + public TestV1ToV2RowDeltaDelete() { + super(1 /* table format version */); + } + + static final DeleteFile FILE_A_POS_1 = FileMetadata.deleteFileBuilder(SPEC) + .ofPositionDeletes() + .withPath("/path/to/data-a-pos-deletes.parquet") + .withFileSizeInBytes(10) + .withPartition(FILE_A.partition()) + .withRecordCount(1) + .build(); + + static final DeleteFile FILE_A_EQ_1 = FileMetadata.deleteFileBuilder(SPEC) + .ofEqualityDeletes() + .withPath("/path/to/data-a-eq-deletes.parquet") + .withFileSizeInBytes(10) + .withPartition(FILE_A.partition()) + .withRecordCount(1) + .build(); + + + @Test + public void testPartitionedTableWithPartitionEqDeletes() { + table.newAppend() + .appendFile(FILE_A) + .appendFile(FILE_B) + .appendFile(FILE_C) + .appendFile(FILE_D) + .commit(); + + // update table version to 2 + TableOperations ops = ((BaseTable) table).operations(); + TableMetadata base = ops.current(); + ops.commit(base, base.upgradeToFormatVersion(2)); + + table.newRowDelta() + .addDeletes(FILE_A_EQ_1) + .commit(); + + List<FileScanTask> tasks = Lists.newArrayList(table.newScan().planFiles().iterator()); + Assert.assertEquals("Should have one task", 4, tasks.size()); Review Comment: Nit: Wrong number of tasks. -- 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]
