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


##########
spark/v3.3/spark/src/main/java/org/apache/iceberg/spark/procedures/CreateChangelogViewProcedure.java:
##########
@@ -223,13 +234,28 @@ private Dataset<Row> applyChangelogIterator(Dataset<Row> 
df, Column[] repartitio
         .sortWithinPartitions(sortSpec)
         .mapPartitions(
             (MapPartitionsFunction<Row, Row>)
-                rowIterator -> ChangelogIterator.create(rowIterator, schema, 
identifierFields),
+                rowIterator ->
+                    ChangelogIterator.create(rowIterator, schema, 
identifierFields, netChanges),
             RowEncoder.apply(schema));
   }
 
   private static Column[] sortSpec(Dataset<Row> df, Column[] repartitionSpec) {
-    Column[] sortSpec = new Column[repartitionSpec.length + 1];
+    Column changeOrdinal = df.col(MetadataColumns.CHANGE_ORDINAL.name());
+    boolean noChangeOrdinal =
+        Arrays.stream(repartitionSpec).noneMatch(c -> c.equals(changeOrdinal));
+
+    Column[] sortSpec;
+    if (noChangeOrdinal) {
+      sortSpec = new Column[repartitionSpec.length + 2];
+    } else {
+      sortSpec = new Column[repartitionSpec.length + 1];
+    }
+

Review Comment:
   Yes, we do. The new test in class `TestCreateChangelogViewProcedure` covers 
line 249, while existing tests cover line 251.



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