aokolnychyi commented on a change in pull request #2164:
URL: https://github.com/apache/iceberg/pull/2164#discussion_r565698495



##########
File path: api/src/main/java/org/apache/iceberg/SortOrder.java
##########
@@ -258,14 +257,20 @@ Builder addSortField(String transformAsString, int 
sourceId, SortDirection direc
     }
 
     public SortOrder build() {
-      if (orderId == 0 && fields.size() != 0) {
-        throw new IllegalArgumentException("Sort order ID 0 is reserved for 
unsorted order");
+      if (fields.isEmpty()) {
+        if (orderId != null && orderId != 0) {
+          throw new IllegalArgumentException("Unsorted order ID must be 0");
+        }
+        return SortOrder.unsorted();
       }
-      if (fields.size() == 0 && orderId != 0) {
-        throw new IllegalArgumentException("Unsorted order ID must be 0");
+
+      if (orderId != null && orderId == 0) {

Review comment:
       After this change, `orderId` is no longer a primitive. This check avoids 
an NPE.




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

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