findepi commented on code in PR #5794: URL: https://github.com/apache/iceberg/pull/5794#discussion_r979739307
########## core/src/test/java/org/apache/iceberg/TestSetStatistics.java: ########## @@ -0,0 +1,131 @@ +/* + * 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 org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class TestSetStatistics extends TableTestBase { + @Parameterized.Parameters(name = "formatVersion = {0}") + public static Object[] parameters() { + return new Object[] {1, 2}; + } + + public TestSetStatistics(int formatVersion) { + super(formatVersion); + } + + @Test + public void testEmptyUpdateStatistics() { + Assert.assertEquals("Table should be on version 0", 0, (int) version()); + TableMetadata base = readMetadata(); + + table.updateStatistics().commit(); + + Assert.assertSame( + "Base metadata should not change when commit is created", base, table.ops().current()); + Assert.assertEquals("Table should be on version 1", 1, (int) version()); Review Comment: I am not sure why. I copied the version-related assertions from `TestTransaction`, but the other tests don't do that. I can remove it from here. BTW if i add the following to `TestSortOrder`, it passes for me locally, indicating that no-op change results in a table version bump there too. ```java @Test public void testNoopUpdateBumpsVersion() { PartitionSpec spec = PartitionSpec.builderFor(SCHEMA).withSpecId(5).identity("data").build(); SortOrder order = SortOrder.builderFor(SCHEMA) .withOrderId(10) .asc("s.id", NULLS_LAST) .desc(truncate("data", 10), NULLS_FIRST) .build(); TestTables.TestTable table = TestTables.create(tableDir, "test", SCHEMA, spec, order, formatVersion); Assert.assertEquals("Table should be on version 0", 0, (int) TestTables.metadataVersion("test")); table.replaceSortOrder().commit(); Assert.assertEquals("Table should be on version 1", 1, (int) TestTables.metadataVersion("test")); } ``` ########## core/src/main/java/org/apache/iceberg/SetStatistics.java: ########## @@ -0,0 +1,77 @@ +/* + * 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 java.util.Map; +import java.util.Optional; +import java.util.stream.Stream; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; + +public class SetStatistics implements UpdateStatistics { + private final TableOperations ops; + private final Map<Long, Optional<StatisticsFile>> statisticsToSet = Maps.newHashMap(); + + public SetStatistics(TableOperations ops) { + this.ops = ops; + } + + @Override + public UpdateStatistics setStatistics(long snapshotId, StatisticsFile statisticsFile) { + Preconditions.checkArgument(snapshotId == statisticsFile.snapshotId()); + statisticsToSet.put(snapshotId, Optional.of(statisticsFile)); + return this; + } + + @Override + public UpdateStatistics removeStatistics(long snapshotId) { + statisticsToSet.put(snapshotId, Optional.empty()); + return this; + } + + @Override + public List<StatisticsFile> apply() { Review Comment: Will do! -- 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]
