jpisaac commented on code in PR #1598:
URL: https://github.com/apache/phoenix/pull/1598#discussion_r1247322349


##########
phoenix-core/src/main/java/org/apache/phoenix/iterate/ExplainTable.java:
##########
@@ -111,8 +126,63 @@ private String explainSkipScan() {
         return buf.toString();
     }
 
-    protected void explain(String prefix, List<String> planSteps,
-            ExplainPlanAttributesBuilder explainPlanAttributesBuilder) {
+    /**
+     * Get regions that represent the given range of start and end key for the 
given table, and
+     * all the regions to the regionLocations list.
+     *
+     * @param tableName the table name.
+     * @param startKey the start rowkey.
+     * @param endKey the end rowkey.
+     * @param includeEndKey true if end key needs to be included.
+     * @param reload true if reload from meta is necessary.
+     * @param regionBoundaries set of region boundaries to get the unique list 
of region locations.
+     * @param regionLocations the list of region locations as output.
+     * @throws IOException if something goes wrong while creating connection 
or querying region
+     * locations.
+     */
+    private void getRegionsInRange(final byte[] tableName,
+                                   final byte[] startKey,
+                                   final byte[] endKey,
+                                   final boolean includeEndKey,
+                                   final boolean reload,
+                                   Set<RegionBoundary> regionBoundaries,
+                                   List<HRegionLocation> regionLocations)
+            throws IOException, SQLException {
+        final boolean endKeyIsEndOfTable = Bytes.equals(endKey, 
HConstants.EMPTY_END_ROW);
+        if ((Bytes.compareTo(startKey, endKey) > 0) && !endKeyIsEndOfTable) {
+            throw new IllegalArgumentException(
+                    "Invalid range: " + Bytes.toStringBinary(startKey) + " > " 
+
+                            Bytes.toStringBinary(endKey));
+        }
+        byte[] currentKey = startKey;
+        try (Table table = 
context.getConnection().getQueryServices().getTable(tableName)) {
+            do {
+                HRegionLocation regionLocation =
+                        table.getRegionLocator().getRegionLocation(currentKey, 
reload);
+                RegionBoundary regionBoundary =
+                        new 
RegionBoundary(regionLocation.getRegion().getStartKey(),
+                                regionLocation.getRegion().getEndKey());
+                if (!regionBoundaries.contains(regionBoundary)) {
+                    regionLocations.add(regionLocation);
+                    regionBoundaries.add(regionBoundary);
+                }
+                currentKey = regionLocation.getRegion().getEndKey();
+                // condition1 = currentKey != END_ROW_KEY
+                // condition2 = endKeyIsEndOfTable == true
+                // condition3 = currentKey < endKey
+                // condition4 = includeEndKey == true
+                // condition5 = currentKey == endKey
+                // while (condition1 && (condition2 || condition3 || 
(condition4 && condition5)))

Review Comment:
   nit: Might be easier on the reader if it is in plain layman's language



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