Skip to content

Commit d2aef56

Browse files
author
Saurabh Rai
committed
Make a util method - deriveRowKeyFromScanOrRegionBoundaries
1 parent 28de02e commit d2aef56

2 files changed

Lines changed: 31 additions & 17 deletions

File tree

phoenix-core-server/src/main/java/org/apache/phoenix/iterate/NonAggregateRegionScannerFactory.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
import org.apache.phoenix.util.EncodedColumnsUtil;
8484
import org.apache.phoenix.util.IndexUtil;
8585
import org.apache.phoenix.util.ScanUtil;
86+
import org.apache.phoenix.util.ServerUtil;
8687
import org.slf4j.Logger;
8788
import org.slf4j.LoggerFactory;
8889

@@ -499,23 +500,7 @@ public boolean next(List<Cell> results, ScannerContext scannerContext) throws IO
499500
kv = getOffsetKvWithLastScannedRowKey(remainingOffset, tuple);
500501
} else {
501502
// Use fallback logic when tuple is empty (PHOENIX-7524)
502-
byte[] rowKey;
503-
byte[] startKey = scan.getStartRow().length > 0
504-
? scan.getStartRow()
505-
: region.getRegionInfo().getStartKey();
506-
byte[] endKey = scan.getStopRow().length > 0
507-
? scan.getStopRow()
508-
: region.getRegionInfo().getEndKey();
509-
rowKey = ByteUtil.getLargestPossibleRowKeyInRange(startKey, endKey);
510-
if (rowKey == null) {
511-
if (scan.includeStartRow()) {
512-
rowKey = startKey;
513-
} else if (scan.includeStopRow()) {
514-
rowKey = endKey;
515-
} else {
516-
rowKey = HConstants.EMPTY_END_ROW;
517-
}
518-
}
503+
byte[] rowKey = ServerUtil.deriveRowKeyFromScanOrRegionBoundaries(scan, region);
519504
kv = new KeyValue(rowKey, QueryConstants.OFFSET_FAMILY,
520505
QueryConstants.OFFSET_COLUMN, remainingOffset);
521506
}

phoenix-core-server/src/main/java/org/apache/phoenix/util/ServerUtil.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,33 @@ public static <T> Throwable getExceptionFromFailedFuture(Future<T> f) {
291291
}
292292
return t;
293293
}
294+
295+
/**
296+
* Derives a safe row key for empty result sets based on scan or region boundaries. Used when
297+
* constructing KeyValues for aggregate results or OFFSET responses when no actual data rows were
298+
* scanned.
299+
* @param scan The scan being executed
300+
* @param region The region being scanned
301+
* @return A valid row key derived from scan or region boundaries
302+
*/
303+
public static byte[] deriveRowKeyFromScanOrRegionBoundaries(Scan scan, Region region) {
304+
byte[] startKey =
305+
scan.getStartRow().length > 0 ? scan.getStartRow() : region.getRegionInfo().getStartKey();
306+
byte[] endKey =
307+
scan.getStopRow().length > 0 ? scan.getStopRow() : region.getRegionInfo().getEndKey();
308+
309+
byte[] rowKey = ByteUtil.getLargestPossibleRowKeyInRange(startKey, endKey);
310+
311+
if (rowKey == null) {
312+
if (scan.includeStartRow()) {
313+
rowKey = startKey;
314+
} else if (scan.includeStopRow()) {
315+
rowKey = endKey;
316+
} else {
317+
rowKey = HConstants.EMPTY_END_ROW;
318+
}
319+
}
320+
321+
return rowKey;
322+
}
294323
}

0 commit comments

Comments
 (0)