You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "RussellSpitzer (via GitHub)" <gi...@apache.org> on 2023/04/12 18:04:56 UTC

[GitHub] [iceberg] RussellSpitzer commented on a diff in pull request #7326: Spark 3.3: Output the net changes across snapshots in CDC

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


##########
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:
   I don't understand the example here. Why would we have two identical records in an invalid way?



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