flyrain commented on code in PR #7326:
URL: https://github.com/apache/iceberg/pull/7326#discussion_r1164666433


##########
spark/v3.3/spark/src/main/java/org/apache/iceberg/spark/NetChangelogIterator.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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.spark;
+
+import java.util.Iterator;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.types.StructType;
+
+public class NetChangelogIterator extends ChangelogIterator {
+
+  private Row firstRow = null;
+  private Row postImage = null;
+
+  protected NetChangelogIterator(
+      Iterator<Row> rowIterator, StructType rowType, String[] 
identifierFields) {
+    super(rowIterator, rowType, identifierFields);
+  }
+
+  @Override
+  public boolean hasNext() {
+    if (postImage != null || firstRow != null) {
+      return true;
+    }
+    return getRowIterator().hasNext();
+  }
+
+  /**
+   * This method iterates all versions of the same logical row across multiple 
snapshots. It caches
+   * the row's first version, and removes every version in between, then 
compares the last version
+   * with the first version to get the net change. Please note that it also 
removes any invalid
+   * data. For example, if there are two identical records, it will remove one 
of them.

Review Comment:
   The net change requires the identifier fields. That means for a particular 
key, there should be only one record. That's why we think duplicated records 
are invalid.



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