use of org.locationtech.geowave.datastore.hbase.operations.HBaseOperations in project geowave by locationtech.
the class HBaseSplitsProvider method populateIntermediateSplits.
@Override
protected TreeSet<IntermediateSplitInfo> populateIntermediateSplits(final TreeSet<IntermediateSplitInfo> splits, final DataStoreOperations operations, final Index index, final List<Short> adapterIds, final Map<Pair<Index, ByteArray>, RowRangeHistogramValue> statsCache, final TransientAdapterStore adapterStore, final InternalAdapterStore internalAdapterStore, final DataStatisticsStore statsStore, final Integer maxSplits, final QueryConstraints query, final double[] targetResolutionPerDimensionForHierarchicalIndex, final IndexMetaData[] indexMetadata, final String[] authorizations) throws IOException {
HBaseOperations hbaseOperations = null;
if (operations instanceof HBaseOperations) {
hbaseOperations = (HBaseOperations) operations;
} else {
LOGGER.error("HBaseSplitsProvider requires BasicHBaseOperations object.");
return splits;
}
final String tableName = hbaseOperations.getQualifiedTableName(index.getName());
final Map<HRegionLocation, Map<HRegionInfo, List<ByteArrayRange>>> binnedRanges = new HashMap<>();
final RegionLocator regionLocator = hbaseOperations.getRegionLocator(tableName);
if (regionLocator == null) {
LOGGER.error("Unable to retrieve RegionLocator for " + tableName);
return splits;
}
// Build list of row ranges from query
List<ByteArrayRange> ranges = null;
if (query != null) {
final List<MultiDimensionalNumericData> indexConstraints = query.getIndexConstraints(index);
if ((maxSplits != null) && (maxSplits > 0)) {
ranges = DataStoreUtils.constraintsToQueryRanges(indexConstraints, index, targetResolutionPerDimensionForHierarchicalIndex, maxSplits, indexMetadata).getCompositeQueryRanges();
} else {
ranges = DataStoreUtils.constraintsToQueryRanges(indexConstraints, index, targetResolutionPerDimensionForHierarchicalIndex, -1, indexMetadata).getCompositeQueryRanges();
}
}
PersistentAdapterStore persistentAdapterStore = new AdapterStoreWrapper(adapterStore, internalAdapterStore);
if (ranges == null) {
// get partition ranges from stats
final PartitionsValue statistics = InternalStatisticsHelper.getPartitions(index, adapterIds, persistentAdapterStore, statsStore, authorizations);
if (statistics != null) {
ranges = Lists.newArrayList();
byte[] prevKey = HConstants.EMPTY_BYTE_ARRAY;
final TreeSet<ByteArray> sortedPartitions = new TreeSet<>(statistics.getValue());
for (final ByteArray partitionKey : sortedPartitions) {
final ByteArrayRange range = new ByteArrayRange(prevKey, partitionKey.getBytes());
ranges.add(range);
prevKey = partitionKey.getBytes();
}
ranges.add(new ByteArrayRange(prevKey, HConstants.EMPTY_BYTE_ARRAY));
binRanges(ranges, binnedRanges, regionLocator);
} else {
binFullRange(binnedRanges, regionLocator);
}
} else {
while (!ranges.isEmpty()) {
ranges = binRanges(ranges, binnedRanges, regionLocator);
}
}
for (final Entry<HRegionLocation, Map<HRegionInfo, List<ByteArrayRange>>> locationEntry : binnedRanges.entrySet()) {
final String hostname = locationEntry.getKey().getHostname();
for (final Entry<HRegionInfo, List<ByteArrayRange>> regionEntry : locationEntry.getValue().entrySet()) {
final Map<String, SplitInfo> splitInfo = new HashMap<>();
final List<RangeLocationPair> rangeList = new ArrayList<>();
for (final ByteArrayRange range : regionEntry.getValue()) {
final GeoWaveRowRange gwRange = toRowRange(range, index.getIndexStrategy().getPartitionKeyLength());
final double cardinality = getCardinality(getHistStats(index, adapterIds, persistentAdapterStore, statsStore, statsCache, new ByteArray(gwRange.getPartitionKey()), authorizations), gwRange);
rangeList.add(new RangeLocationPair(gwRange, hostname, cardinality < 1 ? 1.0 : cardinality));
}
if (!rangeList.isEmpty()) {
splitInfo.put(index.getName(), new SplitInfo(index, rangeList));
splits.add(new IntermediateSplitInfo(splitInfo, this));
}
}
}
return splits;
}
Aggregations