phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramkrish86 <...@git.apache.org>
Subject [GitHub] phoenix pull request: Phoenix-180
Date Mon, 15 Sep 2014 03:33:15 GMT
Github user ramkrish86 commented on the pull request:

    https://github.com/apache/phoenix/pull/12#issuecomment-55550080
  
            protected List<KeyRange> genKeyRanges(List<HRegionLocation> regions)
{
            if (regions.isEmpty()) { return Collections.emptyList(); }
            Scan scan = context.getScan();
            PTable table = this.tableRef.getTable();
            byte[] defaultCF = SchemaUtil.getEmptyColumnFamily(table);
            List<byte[]> gps = null;
            try {
                if (table.getColumnFamilies().isEmpty()) {
                    // For sure we can get the defaultCF from the table
                    gps = table.getTableStats().getGuidePosts().get(defaultCF);
                } else {
                    if (scan.getFamilyMap().size() > 0) {
                        if (scan.getFamilyMap().containsKey(defaultCF)) { // Favor using default
CF if it's used in scan
                            gps = table.getColumnFamily(defaultCF).getGuidePosts();
                        } else { // Otherwise, just use first CF in use by scan
                            gps = table.getColumnFamily(scan.getFamilyMap().keySet().iterator().next()).getGuidePosts();
                        }
                    } else {
                        gps = table.getColumnFamily(defaultCF).getGuidePosts();
                    }
                }
            } catch (Exception cfne) {
                logger.error("Error while getting guideposts for the cf " + Bytes.toString(defaultCF));
            }
    
            List<KeyRange> regionStartEndKey = Lists.newArrayListWithExpectedSize(regions.size());
            for (HRegionLocation region : regions) {
                regionStartEndKey.add(KeyRange.getKeyRange(region.getRegionInfo().getStartKey(),
region.getRegionInfo()
                        .getEndKey()));
            }
            List<KeyRange> guidePosts = Lists.newArrayListWithCapacity(regions.size());
            List<byte[]> guidePostsBytes = Lists.newArrayListWithCapacity(regions.size());
            // Only one cf to be used here
            if (gps != null) {
                // the guide posts will arrive in sorted order here as we are focusing on
only one cf
                for (byte[] guidePost : gps) {
                    PhoenixArray array = (PhoenixArray)PDataType.VARBINARY_ARRAY.toObject(guidePost);
                    if (array != null && array.getDimensions() != 0) {
                        for (int j = 0; j < array.getDimensions(); j++) {
                            guidePostsBytes.add(array.toBytes(j));
                        }
                    }
                }
            }
            int size = guidePostsBytes.size();
            if (size > 0) {
                if (size > 1) {
                    guidePosts.add(KeyRange.getKeyRange(HConstants.EMPTY_BYTE_ARRAY, guidePostsBytes.get(0)));
                    for (int i = 0; i < size - 2; i++) {
                        guidePosts.add(KeyRange.getKeyRange(guidePostsBytes.get(i), (guidePostsBytes.get(i
+ 1))));
                    }
                    guidePosts.add(KeyRange.getKeyRange(guidePostsBytes.get(size - 2), (guidePostsBytes.get(size
- 1))));
                    guidePosts.add(KeyRange.getKeyRange(guidePostsBytes.get(size - 1), (HConstants.EMPTY_BYTE_ARRAY)));
                } else {
                    byte[] gp = guidePostsBytes.get(0);
                    guidePosts.add(KeyRange.getKeyRange(HConstants.EMPTY_BYTE_ARRAY, gp));
                    guidePosts.add(KeyRange.getKeyRange(gp, HConstants.EMPTY_BYTE_ARRAY));
                }
    
            }
            if (guidePosts.size() > 0) {
                List<KeyRange> intersect = KeyRange.intersect(guidePosts, regionStartEndKey);
                return intersect;
            } else {
                return regionStartEndKey;
            }
        }
    Do you think this will work out?  Here trying to form keyranges from all the guideposts
and intersecting with the region boundaries?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message