phoenix-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [phoenix] BinShi-SecularBird commented on a change in pull request #485: Add common utility function ScanUtil.splityKeyRangesByBoundaries()
Date Wed, 17 Apr 2019 13:48:13 GMT
BinShi-SecularBird commented on a change in pull request #485: Add common utility function
ScanUtil.splityKeyRangesByBoundaries()
URL: https://github.com/apache/phoenix/pull/485#discussion_r276247697
 
 

 ##########
 File path: phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
 ##########
 @@ -953,4 +953,80 @@ public static int getClientVersion(Scan scan) {
     public static void setClientVersion(Scan scan, int version) {
         scan.setAttribute(BaseScannerRegionObserver.CLIENT_VERSION, Bytes.toBytes(version));
     }
+
+    /**
+     * Split the key ranges into multiple groups along the given boundaries
+     *
+     * @param boundaries
+     *     The boundaries is a byte[] list like "b0, b1, ..., bn" which forms
+     *     space (UNBOUND, b0), [b0, b1), ..., [bn, UNBOUND)
+     * @param keyRanges
+     *     The key ranges to split along the given boundaries. Coalesced.
+     * @return
+     *     key ranges in two dimensions.
+     */
+    public static List<List<KeyRange>> splitKeyRangesByBoundaries(List<byte[]>
boundaries, List<KeyRange> keyRanges) {
+        if (boundaries == null || keyRanges == null || keyRanges.size() == 0) {
+            return null;
+        }
+
+        ScanUtil.BytesComparator comparator = ScanUtil.getComparator(true, SortOrder.ASC);
+        int countOfBoundaries = boundaries.size();
+        int countOfKeyRanges = keyRanges.size();
+        int indexOfBoundary = 0;
+        int indexOfKeyRange = 0;
+
+        List<List<KeyRange>> keyRangesGrouped = Lists.newArrayListWithExpectedSize(1);
+        List<KeyRange> keyRangesOfGroup = Lists.<KeyRange>newArrayList();
+        keyRangesGrouped.add(keyRangesOfGroup);
+
+        KeyRange currentKeyRange = null;
+        while (indexOfKeyRange < countOfKeyRanges) {
+            if (currentKeyRange == null) {
+                currentKeyRange = keyRanges.get(indexOfKeyRange);
+            }
+
+            if (indexOfBoundary >= countOfBoundaries) {
+                keyRangesOfGroup.add(currentKeyRange);
+                currentKeyRange = null;
+                indexOfKeyRange++;
+                continue;
+            }
+
+            byte[] regionBoundary = boundaries.get(indexOfBoundary);
+            int lowerToUpper = currentKeyRange.compareLowerToUpperBound(
+                    regionBoundary, 0, regionBoundary.length, false, comparator);
+            if (lowerToUpper < 0) {
+                int upperToUpper = currentKeyRange.compareUpperRange(regionBoundary, 0, regionBoundary.length,
false);
+                if (upperToUpper >= 0) {
+                    keyRangesOfGroup.add(KeyRange.getKeyRange(
+                            currentKeyRange.getLowerRange(), currentKeyRange.isLowerInclusive(),
regionBoundary, false));
+                    if (upperToUpper > 0) {
+                        currentKeyRange = KeyRange.getKeyRange(regionBoundary, true,
+                                currentKeyRange.getUpperRange(), currentKeyRange.isUpperInclusive());
+                    } else {
+                        currentKeyRange = null;
+                        indexOfKeyRange++;
+                    }
+                } else {
+                    keyRangesOfGroup.add(currentKeyRange);
+                    currentKeyRange = null;
+                    indexOfKeyRange++;
+                    continue;
+                }
+            }
+
+            // Increase region boundary
+            indexOfBoundary++;
+            keyRangesOfGroup = Lists.<KeyRange>newArrayList();
 
 Review comment:
   Regarding the first comment, the current design is that, before the last region which has
non-empty query key range list, for every region which has no query key range, we generate
empty query key range list for it. This is for keeping region index information because it
will be used by the caller of this function. I'm considering to return List<Pair<Integer,
List<KeyRange>>> represents List<Pair<RegionIndex, Query Key Range List
in this region>>.
   
   Regarding the second comment, could you show me more compact and cleaner code without using
continue? I'm very curious how it would look like

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message