Copilot commented on code in PR #2657:
URL: https://github.com/apache/phoenix/pull/2657#discussion_r4472089830


##########
phoenix-core/src/test/java/org/apache/phoenix/util/ByteUtilTest.java:
##########
@@ -65,4 +66,29 @@ public void testNextKey() {
     key = new byte[] { (byte) 255 };
     assertNull(ByteUtil.nextKey(key));
   }
+
+  @Test
+  public void testLargestPossibleRowKeyInRangeWithEmptyEndKey() {
+    byte[][] startKeys = new byte[][] { Bytes.toBytes("t0005"), new byte[] { 
(byte) 0x80, 0, 0 },
+      new byte[] { 0 }, new byte[] { (byte) 255, (byte) 255 } };
+    for (byte[] startKey : startKeys) {
+      byte[] rowKey = ByteUtil.getLargestPossibleRowKeyInRange(startKey, 
HConstants.EMPTY_END_ROW);
+      assertNotNull(Bytes.toStringBinary(startKey), rowKey);
+      assertTrue(Bytes.toStringBinary(rowKey), Bytes.compareTo(startKey, 
rowKey) < 0);
+    }
+  }

Review Comment:
   These tests cover code in `phoenix-core-client` (`ByteUtil`), but they live 
under the `phoenix-core` module. If `phoenix-core-client` is built/tested 
independently (or reused as a standalone dependency), this behavior can become 
untested. Consider moving/duplicating these tests into 
`phoenix-core-client/src/test/...` (or whichever module owns `ByteUtil`) to 
ensure the changed client utility behavior is always covered.



##########
phoenix-core-client/src/main/java/org/apache/phoenix/util/ByteUtil.java:
##########
@@ -535,7 +537,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.
+      boolean hasUpperBound = endKey.length > 0;

Review Comment:
   For readability/intent, consider using an existing utility predicate (if 
available in this codebase) such as `Bytes.isEmpty(endKey)` (or a Phoenix 
equivalent) instead of `endKey.length > 0`. This makes the 'empty end key means 
unbounded' rule more self-documenting at the call site.



##########
phoenix-core-client/src/main/java/org/apache/phoenix/util/ByteUtil.java:
##########
@@ -470,9 +470,11 @@ 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.
+   * If startKey is not empty and endKey is empty, 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.
    * @return best attempt of largest rowkey in the range of [startKey, endKey).

Review Comment:
   The method name/contract says 'largest possible rowkey', but the added 
Javadoc states that when `endKey` is empty the function returns a key 'just 
after startKey' (which is not 'largest' in any meaningful sense for an 
unbounded interval). Consider rewording to avoid the 'largest' implication in 
the unbounded case (e.g., document that it returns a 'valid synthetic rowkey 
within the scan range' and that for unbounded upper limit it returns a key 
immediately after `startKey`).



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

Reply via email to