aokolnychyi commented on a change in pull request #2164:
URL: https://github.com/apache/iceberg/pull/2164#discussion_r565517279
##########
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) {
+ if (orderId != null && orderId == 0 && fields.size() != 0) {
throw new IllegalArgumentException("Sort order ID 0 is reserved for
unsorted order");
}
- if (fields.size() == 0 && orderId != 0) {
+ if (fields.size() == 0 && orderId != null && orderId != 0) {
throw new IllegalArgumentException("Unsorted order ID must be 0");
}
- SortOrder sortOrder = new SortOrder(schema, orderId, fields);
+ if (fields.isEmpty()) {
Review comment:
I have two options here:
```
if (fields.isEmpty()) {
if (orderId == null || orderId == 0) {
return SortOrder.unsorted();
} else {
throw new IllegalArgumentException("Unsorted order ID must be 0");
}
} else if (orderId != null && orderId == 0) {
throw new IllegalArgumentException("Sort order ID 0 is reserved for
unsorted order");
}
...
```
or
```
if (fields.isEmpty()) {
if (orderId != null && orderId != 0) {
throw new IllegalArgumentException("Unsorted order ID must be 0");
}
return SortOrder.unsorted();
}
if (orderId != null && orderId == 0) {
throw new IllegalArgumentException("Sort order ID 0 is reserved for
unsorted order");
}
...
```
I tend to like the second option a bit more. What do you think,
@RussellSpitzer?
----------------------------------------------------------------
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]