findepi commented on code in PR #5794:
URL: https://github.com/apache/iceberg/pull/5794#discussion_r975132411


##########
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() {
+    return Stream.concat(
+            // Retained statistics
+            ops.current().statisticsFiles().stream()
+                .filter(
+                    statisticsFile -> 
!statisticsToSet.containsKey(statisticsFile.snapshotId())),
+            // New statistics
+            
statisticsToSet.values().stream().filter(Optional::isPresent).map(Optional::get))
+        .collect(ImmutableList.toImmutableList());
+  }
+
+  @Override
+  public void commit() {
+    TableMetadata base = ops.current(); // or ops.refresh() ?

Review Comment:
   if i am reading implementations of `org.apache.iceberg.PendingUpdate#commit` 
correctly
   
   - `BaseUpdatePartitionSpec`, `PropertiesUpdate`, `SchemaUpdate`, 
`UpdateSnapshotReferencesOperation`, `SnapshotProducer`  use `current` 
(acquired at the constructor invocation time?)
   - `SetLocation`, `RemoveSnapshots`, `BaseReplaceSortOrder` use `refresh`
   
   Now, it's maybe `apply` should call the `refresh`?
   
   - `SnapshotProducer`, `SetSnapshotOperation` do so
   - `UpdateSnapshotReferencesOperation`, `BaseUpdatePartitionSpec` do not seem 
to do that (and doesn't refresh at commit time)
   - `RemoveSnapshots`, `SchemaUpdate` do not do that (maybe they should?), but 
then call `refresh` at commit time)
   - `BaseReplaceSortOrder`, `SetLocation` do not do that (do not need to), but 
then call `refresh` at commit time)
   
   That's as far as the code lecture goes. I am not expert on the lifecycle and 
concurrency of these entities, so it's hard for me to judge which one to use 
(hence the code comment). The code frequency stats don't seem to determine that.



-- 
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]

Reply via email to