sanjeet006py commented on code in PR #2377:
URL: https://github.com/apache/phoenix/pull/2377#discussion_r2831295168


##########
phoenix-core-client/src/main/java/org/apache/phoenix/compile/RVCOffsetCompiler.java:
##########
@@ -247,17 +248,19 @@ public CompiledOffset getRVCOffset(StatementContext 
context, FilterableStatement
     // check to see if this was a single key expression
     ScanRanges scanRanges = context.getScanRanges();
 
-    // We do not generate a point lookup today in phoenix if the rowkey has a 
trailing null, we
-    // generate a range scan.
+    // Always generate point lookup for RVC Offset
     if (!scanRanges.isPointLookup()) {
-      // Since we use a range scan to guarantee we get only the null value and 
the upper bound is
-      // unset this suffices
-      // sanity check
-      if (!rowKeyColumnExpressionOutput.isTrailingNull()) {
-        throw new RowValueConstructorOffsetNotCoercibleException(
-          "RVC Offset must be a point lookup.");
-      }
-      key = scanRanges.getScanRange().getUpperRange();
+      throw new RowValueConstructorOffsetNotCoercibleException(
+        "RVC Offset must be a point lookup.");
+    }
+    if (rowKeyColumnExpressionOutput.isTrailingNull()) {
+      // Handle trailing nulls in RVC offset by appending null byte at the end 
to generate immediate
+      // next key
+      key = scanRanges.getScanRange().getLowerRange();
+      byte[] keyCopy = new byte[key.length + 1];
+      System.arraycopy(key, 0, keyCopy, 0, key.length);
+      keyCopy[key.length] = QueryConstants.SEPARATOR_BYTE;
+      key = keyCopy;

Review Comment:
   If we use `ByteUtil.nextKey()` then we can miss out on some values to 
return. Ex- we have a query `SELECT * FROM TABLE OFFSET (PK1, PK2) = ('1', 
null)`. In this case we would want to return values `('1', '1')` or `('1', 
'10')` also. But if we use `ByteUtil.nextKey()` on the `key` output from 
ScanRanges then `OFFSET` will show all the rows starting `('2', null)` and we 
would miss seeing rows starting with `'1'`. 
   
   There is an existing IT for exact scenario I described above: 
`RowValueConstructorOffsetIT#rvcOffsetTrailingNullKeyTest()`.



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