public IndexRangeLocation split( final RowRangeHistogramStatistics<?> stats, final double currentCardinality, final double targetCardinality) { if (stats == null) { return null; } final double thisCardinalty = rangeLocationPair.getCardinality(); final double fraction = (targetCardinality - currentCardinality) / thisCardinalty; final int splitCardinality = (int) (thisCardinalty * fraction); final byte[] start = rangeLocationPair.getRange().getStart().getBytes(); final byte[] end = rangeLocationPair.getRange().getEnd().getBytes(); final double cdfStart = stats.cdf(start); final double cdfEnd = stats.cdf(end); final byte[] expectedEnd = stats.quantile(cdfStart + ((cdfEnd - cdfStart) * fraction)); final int maxCardinality = Math.max(start.length, end.length); final byte[] splitKey = expandBytes(expectedEnd, maxCardinality); if (Arrays.equals(start, splitKey) || Arrays.equals(end, splitKey)) { return null; } final String location = rangeLocationPair.getLocation(); try { final RangeLocationPair newPair = new RangeLocationPair( new HBaseMRRowRange( rangeLocationPair.getRange().getStart(), new ByteArrayId(splitKey)), location, splitCardinality); rangeLocationPair = new RangeLocationPair( new HBaseMRRowRange( new ByteArrayId(splitKey), rangeLocationPair.getRange().getEnd()), location, rangeLocationPair.getCardinality() - splitCardinality); return new IndexRangeLocation(newPair, index); } catch (final java.lang.IllegalArgumentException ex) { LOGGER.info("Unable to split range: " + ex.getLocalizedMessage()); return null; } }
private static RowRangeHistogramStatistics<?> getRangeStats( final PrimaryIndex index, final List<DataAdapter<Object>> adapters, final AdapterStore adapterStore, final DataStatisticsStore store, final String[] authorizations) { RowRangeHistogramStatistics<?> singleStats = null; for (final DataAdapter<?> adapter : adapters) { final RowRangeHistogramStatistics<?> rowStat = (RowRangeHistogramStatistics<?>) store.getDataStatistics( adapter.getAdapterId(), RowRangeHistogramStatistics.composeId(index.getId()), authorizations); if (singleStats == null) { singleStats = rowStat; } else { singleStats.merge(rowStat); } } return singleStats; }
private static double getCardinality( final RowRangeHistogramStatistics<?> rangeStats, final HBaseMRRowRange range) { return rangeStats == null ? getRangeLength(range) : rangeStats.cardinality(range.getStart().getBytes(), range.getEnd().getBytes()); }