Copilot commented on code in PR #2657:
URL: https://github.com/apache/phoenix/pull/2657#discussion_r4471322473
##########
phoenix-core-client/src/main/java/org/apache/phoenix/util/ByteUtil.java:
##########
@@ -470,9 +470,10 @@ public static byte[] previousKey(byte[] key) {
* [startKey, endKey). If startKey and endKey are empty, the empty key is
returned. This function
* is used to return valid rowkey for some ungrouped aggregation e.g. while
returning count value
* after scanning the rows. If any error or validation issues (e.g. startKey
> endKey) are
- * encountered, null value is returned.
+ * encountered, null value is returned. An empty endKey means that the range
has no upper bound.
+ * Then the returned rowkey is a rowkey just after startKey.
* @param startKey start rowkey for the range.
- * @param endKey end rowkey for the range.
+ * @param endKey end rowkey for the range, or the empty key for no upper
bound.
Review Comment:
The added Javadoc implies that when `endKey` is empty the method returns a
row key “just after startKey”, but the Javadoc earlier also states that if both
`startKey` and `endKey` are empty, the empty key is returned (which is not
“after” `startKey`). Consider rewording to explicitly scope the “just after
startKey” behavior to the `endKey is empty AND startKey is non-empty` case (or
otherwise describe the special case) to avoid contradictory guidance for
callers.
##########
phoenix-core-client/src/main/java/org/apache/phoenix/util/ByteUtil.java:
##########
@@ -535,7 +536,11 @@ public static byte[]
getLargestPossibleRowKeyInRange(byte[] startKey, byte[] end
Bytes.toStringBinary(startKey), Bytes.toStringBinary(endKey));
return null;
}
- if (Bytes.compareTo(startKey, rowKey) >= 0 || Bytes.compareTo(rowKey,
endKey) >= 0) {
+ // An empty endKey is not an upper bound, so only a non-empty endKey
limits the rowkey.
+ if (
+ Bytes.compareTo(startKey, rowKey) >= 0
+ || (endKey.length > 0 && Bytes.compareTo(rowKey, endKey) >= 0)
+ ) {
Review Comment:
The validation condition is now more complex and harder to scan inline.
Consider extracting `boolean hasUpperBound = endKey.length > 0;` and/or
`boolean outOfRange = ...` before the `if` to improve readability and reduce
the likelihood of future mistakes when this logic is modified again.
--
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]