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


##########
spark/v3.3/spark/src/main/java/org/apache/iceberg/spark/procedures/CreateChangelogViewProcedure.java:
##########
@@ -228,22 +247,45 @@ private Dataset<Row> applyChangelogIterator(Dataset<Row> 
df, Column[] repartitio
             RowEncoder.apply(schema));
   }
 
-  private Dataset<Row> applyCarryoverRemoveIterator(Dataset<Row> df, Column[] 
repartitionSpec) {
-    Column[] sortSpec = sortSpec(df, repartitionSpec);
+  private Dataset<Row> applyCarryoverRemoveIterator(
+      Dataset<Row> df, Column[] repartitionSpec, boolean netChanges) {
+    Column[] sortSpec = sortSpec(df, repartitionSpec, netChanges);
     StructType schema = df.schema();
 
     return df.repartition(repartitionSpec)
         .sortWithinPartitions(sortSpec)
         .mapPartitions(
             (MapPartitionsFunction<Row, Row>)
-                rowIterator -> ChangelogIterator.removeCarryovers(rowIterator, 
schema),
+                rowIterator ->
+                    netChanges
+                        ? ChangelogIterator.removeNetCarryovers(rowIterator, 
schema)
+                        : ChangelogIterator.removeCarryovers(rowIterator, 
schema),
             RowEncoder.apply(schema));
   }
 
-  private static Column[] sortSpec(Dataset<Row> df, Column[] repartitionSpec) {
-    Column[] sortSpec = new Column[repartitionSpec.length + 1];
+  private static Column[] sortSpec(Dataset<Row> df, Column[] repartitionSpec, 
boolean netChanges) {
+    Column changeOrdinal = df.col(MetadataColumns.CHANGE_ORDINAL.name());
+    boolean noChangeOrdinal =
+        Arrays.stream(repartitionSpec).noneMatch(c -> c.equals(changeOrdinal));
+
+    if (netChanges) {
+      Preconditions.checkState(noChangeOrdinal, "Change ordinal should not be 
in repartition spec");
+    }
+
+    Column[] sortSpec;
+    if (netChanges) {
+      sortSpec = new Column[repartitionSpec.length + 2];
+    } else {
+      sortSpec = new Column[repartitionSpec.length + 1];
+    }
+
     System.arraycopy(repartitionSpec, 0, sortSpec, 0, repartitionSpec.length);
+
     sortSpec[sortSpec.length - 1] = df.col(MetadataColumns.CHANGE_TYPE.name());
+
+    if (netChanges) {
+      sortSpec[sortSpec.length - 2] = changeOrdinal;

Review Comment:
   we can do this right after 277, I don't think we need another branch



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