You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2021/12/09 08:52:23 UTC

[GitHub] [iceberg] rawataaryan9 opened a new pull request #3696: Core : Adding more information in CreateSnapshotEvent Summary

rawataaryan9 opened a new pull request #3696:
URL: https://github.com/apache/iceberg/pull/3696


   In the existing implementation for generating `CreateSnapshotEvent` for listeners, the summary of `CreateSnapshotEvent` only contains information about the updates that happened. Ex: added-records, deleted-records, added-files, deleted-files etc. 
   As part of this PR, the aim is to get the total stats info as well in the `CreateSnapshotEvent`. Ex: total-records, total-files etc. 
   
   The possible use case here is a streaming application which wants to track the updates stats as well as the current total stats for an iceberg table for every insert/update/delete commit that happens in a micro-batch in the application. 
   Other way to get total stats would be to identify the latest written snapshot by this application and read the stats from summary, which is cumbersome. 
   
   @rdblue @jackye1995 @RussellSpitzer 


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rawataaryan9 edited a comment on pull request #3696: Core : Adding more information in CreateSnapshotEvent Summary

Posted by GitBox <gi...@apache.org>.
rawataaryan9 edited a comment on pull request #3696:
URL: https://github.com/apache/iceberg/pull/3696#issuecomment-992286915


   Thanks @rdblue for the review and the comments. Have made the changes accordingly, please take a look.


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rawataaryan9 commented on a change in pull request #3696: Core : Adding more information in CreateSnapshotEvent Summary

Posted by GitBox <gi...@apache.org>.
rawataaryan9 commented on a change in pull request #3696:
URL: https://github.com/apache/iceberg/pull/3696#discussion_r767432545



##########
File path: core/src/main/java/org/apache/iceberg/SnapshotSummary.java
##########
@@ -321,6 +323,23 @@ void merge(UpdateMetrics other) {
     }
   }
 
+  protected static Map<String, String> fetchTotalStatsFromSummary(Map<String, String> summary) {
+    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
+    List<String> totalProps = Arrays.asList(
+            TOTAL_DATA_FILES_PROP,
+            TOTAL_DELETE_FILES_PROP,
+            TOTAL_EQ_DELETES_PROP,
+            TOTAL_POS_DELETES_PROP,
+            TOTAL_FILE_SIZE_PROP,
+            TOTAL_RECORDS_PROP);

Review comment:
       agreed, removing this entire method due to above comment changes.




-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rawataaryan9 commented on pull request #3696: Core : Adding more information in CreateSnapshotEvent Summary

Posted by GitBox <gi...@apache.org>.
rawataaryan9 commented on pull request #3696:
URL: https://github.com/apache/iceberg/pull/3696#issuecomment-992286915


   Thanks @rdblue for the comments. Have made the changes accordingly, please take a look.


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue merged pull request #3696: Core : Adding more information in CreateSnapshotEvent Summary

Posted by GitBox <gi...@apache.org>.
rdblue merged pull request #3696:
URL: https://github.com/apache/iceberg/pull/3696


   


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rdblue commented on pull request #3696: Core : Adding more information in CreateSnapshotEvent Summary

Posted by GitBox <gi...@apache.org>.
rdblue commented on pull request #3696:
URL: https://github.com/apache/iceberg/pull/3696#issuecomment-994143598


   Thanks for updating this, @rawataaryan9! Looks good so I merged it.


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rawataaryan9 commented on a change in pull request #3696: Core : Adding more information in CreateSnapshotEvent Summary

Posted by GitBox <gi...@apache.org>.
rawataaryan9 commented on a change in pull request #3696:
URL: https://github.com/apache/iceberg/pull/3696#discussion_r767432650



##########
File path: core/src/test/java/org/apache/iceberg/TestCreateSnapshotEvent.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.
+ */
+
+/*
+ * Licensed 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.events.CreateSnapshotEvent;
+import org.apache.iceberg.events.Listener;
+import org.apache.iceberg.events.Listeners;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class TestCreateSnapshotEvent extends TableTestBase {
+  @Parameterized.Parameters(name = "formatVersion = {0}")
+  public static Object[] parameters() {
+    return new Object[] {1, 2};
+  }
+
+  private CreateSnapshotEvent currentEvent;
+
+  public TestCreateSnapshotEvent(int formatVersion) {
+    super(formatVersion);
+    Listeners.register(new MyListener(), CreateSnapshotEvent.class);
+  }
+
+  @Test
+  public void testAppendCommitEvent() {
+    Assert.assertEquals("Table should start empty", 0, listManifestFiles().size());
+
+    table.newAppend().appendFile(FILE_A).commit();
+    Assert.assertNotNull(currentEvent);
+    Assert.assertEquals("Added records in the table should be 1",
+            "1", currentEvent.summary().get("added-records"));
+    Assert.assertEquals("Added files in the table should be 1",
+            "1", currentEvent.summary().get("added-data-files"));
+    Assert.assertEquals("Total records in the table should be 1",
+            "1", currentEvent.summary().get("total-records"));
+    Assert.assertEquals("Total data files in the table should be 1",
+            "1", currentEvent.summary().get("total-data-files"));
+
+    table.newAppend().appendFile(FILE_A).commit();
+    Assert.assertNotNull(currentEvent);
+    Assert.assertEquals("Added records in the table should be 1",
+            "1", currentEvent.summary().get("added-records"));
+    Assert.assertEquals("Added files in the table should be 1",
+            "1", currentEvent.summary().get("added-data-files"));
+    Assert.assertEquals("Total records in the table should be 2",
+            "2", currentEvent.summary().get("total-records"));
+    Assert.assertEquals("Total data files in the table should be 2",
+            "2", currentEvent.summary().get("total-data-files"));
+  }
+
+  @Test
+  public void testAppendAndDeleteCommitEvent() {
+    Assert.assertEquals("Table should start empty", 0, listManifestFiles().size());
+
+    table.newAppend().appendFile(FILE_A).appendFile(FILE_B).commit();
+    Assert.assertNotNull(currentEvent);
+    Assert.assertEquals("Added records in the table should be 2",
+            "2", currentEvent.summary().get("added-records"));
+    Assert.assertEquals("Added files in the table should be 2",
+            "2", currentEvent.summary().get("added-data-files"));
+    Assert.assertEquals("Total records in the table should be 2",
+            "2", currentEvent.summary().get("total-records"));
+    Assert.assertEquals("Total data files in the table should be 2",
+            "2", currentEvent.summary().get("total-data-files"));
+
+    table.newDelete().deleteFile(FILE_A).commit();
+    Assert.assertNotNull(currentEvent);
+    Assert.assertEquals("Deleted records in the table should be 1",
+            "1", currentEvent.summary().get("deleted-records"));
+    Assert.assertEquals("Deleted files in the table should be 1",
+            "1", currentEvent.summary().get("deleted-data-files"));
+    Assert.assertEquals("Total records in the table should be 1",
+            "1", currentEvent.summary().get("total-records"));
+    Assert.assertEquals("Total data files in the table should be 1",
+            "1", currentEvent.summary().get("total-data-files"));
+  }
+
+  class MyListener implements Listener<CreateSnapshotEvent> {
+    @Override
+    public void notify(CreateSnapshotEvent event) {
+      System.out.println("Event :: " + event.summary());

Review comment:
       this is a miss, removing it.




-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


[GitHub] [iceberg] rawataaryan9 commented on a change in pull request #3696: Core : Adding more information in CreateSnapshotEvent Summary

Posted by GitBox <gi...@apache.org>.
rawataaryan9 commented on a change in pull request #3696:
URL: https://github.com/apache/iceberg/pull/3696#discussion_r767432070



##########
File path: core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java
##########
@@ -551,20 +552,25 @@ public Object updateEvent() {
     long snapshotId = snapshotId();
     Snapshot justSaved = ops.refresh().snapshot(snapshotId);
     long sequenceNumber = TableMetadata.INVALID_SEQUENCE_NUMBER;
+    Map<String, String> summary = summary();
     if (justSaved == null) {
       // The snapshot just saved may not be present if the latest metadata couldn't be loaded due to eventual
       // consistency problems in refresh.
       LOG.warn("Failed to load committed snapshot: omitting sequence number from notifications");
     } else {
       sequenceNumber = justSaved.sequenceNumber();
+      summary = ImmutableMap.<String, String>builder()
+              .putAll(summary)
+              .putAll(SnapshotSummary.fetchTotalStatsFromSummary(justSaved.summary()))
+              .build();
     }
 
     return new CreateSnapshotEvent(
         tableName,
         operation(),
         snapshotId,
         sequenceNumber,
-        summary());
+        summary);

Review comment:
       makes sense, will use entire summary instead. It will cover any further info in summary directly.




-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org