jpisaac commented on code in PR #1598:
URL: https://github.com/apache/phoenix/pull/1598#discussion_r1247320076
##########
phoenix-core/src/main/java/org/apache/phoenix/iterate/ExplainTable.java:
##########
@@ -284,6 +355,106 @@ protected void explain(String prefix, List<String>
planSteps,
}
}
+ /**
+ * Retrieve region locations and set the values in the explain plan output.
+ *
+ * @param planSteps list of plan steps to add explain plan output to.
+ * @param explainPlanAttributesBuilder explain plan v2 attributes builder
instance.
+ * @param scansList list of the list of scans, to be used for parallel
scans.
+ */
+ private void getRegionLocations(List<String> planSteps,
+ ExplainPlanAttributesBuilder
explainPlanAttributesBuilder,
+ List<List<Scan>> scansList) {
+ String regionLocationPlan =
getRegionLocationsForExplainPlan(explainPlanAttributesBuilder,
+ scansList);
+ if (regionLocationPlan.length() > 0) {
+ planSteps.add(regionLocationPlan);
+ }
+ }
+
+ /**
+ * Retrieve region locations from hbase client and set the values for the
explain plan output.
+ * If the list of region locations exceed max limit, print only list with
the max limit and
+ * print num of total list size.
+ *
+ * @param explainPlanAttributesBuilder explain plan v2 attributes builder
instance.
+ * @param scansList list of the list of scans, to be used for parallel
scans.
+ * @return region locations to be added to the explain plan output.
+ */
+ private String getRegionLocationsForExplainPlan(
+ ExplainPlanAttributesBuilder explainPlanAttributesBuilder,
+ List<List<Scan>> scansList) {
+ try {
+ StringBuilder buf = new StringBuilder().append(REGION_LOCATIONS);
+ Set<RegionBoundary> regionBoundaries = new HashSet<>();
+ List<HRegionLocation> regionLocations = new ArrayList<>();
+ for (List<Scan> scans : scansList) {
+ for (Scan eachScan : scans) {
+
getRegionsInRange(tableRef.getTable().getPhysicalName().getBytes(),
+ eachScan.getStartRow(),
+ eachScan.getStopRow(),
+ true,
+ false,
+ regionBoundaries,
+ regionLocations);
+ }
+ }
+ int maxLimitRegionLoc =
context.getConnection().getQueryServices().getConfiguration()
+
.getInt(QueryServices.MAX_REGION_LOCATIONS_SIZE_EXPLAIN_PLAN,
+
QueryServicesOptions.DEFAULT_MAX_REGION_LOCATIONS_SIZE_EXPLAIN_PLAN);
+ if (explainPlanAttributesBuilder != null) {
+ explainPlanAttributesBuilder.setRegionLocations(
+ Collections.unmodifiableList(regionLocations));
+ }
+ if (regionLocations.size() > maxLimitRegionLoc) {
+ int originalSize = regionLocations.size();
+ List<HRegionLocation> trimmedRegionLocations =
+ regionLocations.subList(0, maxLimitRegionLoc);
+ buf.append(trimmedRegionLocations);
+ buf.append("...total size = ");
+ buf.append(originalSize);
+ } else {
+ buf.append(regionLocations);
+ }
+ buf.append(") ");
+ return buf.toString();
+ } catch (IOException | SQLException | UnsupportedOperationException e)
{
+ LOGGER.error("Explain table unable to add region locations.", e);
+ return "";
+ }
+ }
+
+ /**
+ * Region boundary class with start and end key of the region.
+ */
+ private static class RegionBoundary {
+ private final byte[] startKey;
+ private final byte[] endKey;
+
+ RegionBoundary(byte[] startKey, byte[] endKey) {
+ this.startKey = startKey;
+ this.endKey = endKey;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ RegionBoundary that = (RegionBoundary) o;
+ return Bytes.compareTo(startKey, that.startKey) == 0
+ && Bytes.compareTo(endKey, that.endKey) == 0;
+ }
+
+ @Override
+ public int hashCode() {
+ return 0;
Review Comment:
why hashcode of zero?
--
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]