use of com.facebook.presto.accumulo.model.TabletSplitMetadata in project presto by prestodb.
the class AccumuloSplitManager method getSplits.
@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout) {
AccumuloTableLayoutHandle layoutHandle = (AccumuloTableLayoutHandle) layout;
AccumuloTableHandle tableHandle = layoutHandle.getTable();
String schemaName = tableHandle.getSchema();
String tableName = tableHandle.getTable();
String rowIdName = tableHandle.getRowId();
// Get non-row ID column constraints
List<AccumuloColumnConstraint> constraints = getColumnConstraints(rowIdName, layoutHandle.getConstraint());
// Get the row domain column range
Optional<Domain> rDom = getRangeDomain(rowIdName, layoutHandle.getConstraint());
// Call out to our client to retrieve all tablet split metadata using the row ID domain and the secondary index
List<TabletSplitMetadata> tabletSplits = client.getTabletSplits(session, schemaName, tableName, rDom, constraints, tableHandle.getSerializerInstance());
// Pack the tablet split metadata into a connector split
ImmutableList.Builder<ConnectorSplit> cSplits = ImmutableList.builder();
for (TabletSplitMetadata splitMetadata : tabletSplits) {
AccumuloSplit split = new AccumuloSplit(connectorId, schemaName, tableName, rowIdName, tableHandle.getSerializerClassName(), splitMetadata.getRanges().stream().map(WrappedRange::new).collect(Collectors.toList()), constraints, tableHandle.getScanAuthorizations(), splitMetadata.getHostPort());
cSplits.add(split);
}
return new FixedSplitSource(cSplits.build());
}
use of com.facebook.presto.accumulo.model.TabletSplitMetadata in project presto by prestodb.
the class AccumuloClient method getTabletSplits.
/**
* Fetches the TabletSplitMetadata for a query against an Accumulo table.
* <p>
* Does a whole bunch of fun stuff! Splitting on row ID ranges, applying secondary indexes, column pruning,
* all sorts of sweet optimizations. What you have here is an important method.
*
* @param session Current session
* @param schema Schema name
* @param table Table Name
* @param rowIdDomain Domain for the row ID
* @param constraints Column constraints for the query
* @param serializer Instance of a row serializer
* @return List of TabletSplitMetadata objects for Presto
*/
public List<TabletSplitMetadata> getTabletSplits(ConnectorSession session, String schema, String table, Optional<Domain> rowIdDomain, List<AccumuloColumnConstraint> constraints, AccumuloRowSerializer serializer) {
try {
String tableName = AccumuloTable.getFullTableName(schema, table);
LOG.debug("Getting tablet splits for table %s", tableName);
// Get the initial Range based on the row ID domain
Collection<Range> rowIdRanges = getRangesFromDomain(rowIdDomain, serializer);
List<TabletSplitMetadata> tabletSplits = new ArrayList<>();
// Use the secondary index, if enabled
if (AccumuloSessionProperties.isOptimizeIndexEnabled(session)) {
// Get the scan authorizations to query the index
Authorizations auths = getScanAuthorizations(session, schema, table);
// If this returns true, return the tablet splits to Presto
if (indexLookup.applyIndex(schema, table, session, constraints, rowIdRanges, tabletSplits, serializer, auths)) {
return tabletSplits;
}
}
// If we can't (or shouldn't) use the secondary index, we will just use the Range from the row ID domain
// Split the ranges on tablet boundaries, if enabled
Collection<Range> splitRanges;
if (AccumuloSessionProperties.isOptimizeSplitRangesEnabled(session)) {
splitRanges = splitByTabletBoundaries(tableName, rowIdRanges);
} else {
// if not enabled, just use the same collection
splitRanges = rowIdRanges;
}
// Create TabletSplitMetadata objects for each range
boolean fetchTabletLocations = AccumuloSessionProperties.isOptimizeLocalityEnabled(session);
LOG.debug("Fetching tablet locations: %s", fetchTabletLocations);
for (Range range : splitRanges) {
// If locality is enabled, then fetch tablet location
if (fetchTabletLocations) {
tabletSplits.add(new TabletSplitMetadata(getTabletLocation(tableName, range.getStartKey()), ImmutableList.of(range)));
} else {
// else, just use the default location
tabletSplits.add(new TabletSplitMetadata(Optional.empty(), ImmutableList.of(range)));
}
}
// Log some fun stuff and return the tablet splits
LOG.debug("Number of splits for table %s is %d with %d ranges", tableName, tabletSplits.size(), splitRanges.size());
return tabletSplits;
} catch (Exception e) {
throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to get splits from Accumulo", e);
}
}
use of com.facebook.presto.accumulo.model.TabletSplitMetadata in project presto by prestodb.
the class AccumuloSplitManager method getSplits.
@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout, SplitSchedulingContext splitSchedulingContext) {
AccumuloTableLayoutHandle layoutHandle = (AccumuloTableLayoutHandle) layout;
AccumuloTableHandle tableHandle = layoutHandle.getTable();
String schemaName = tableHandle.getSchema();
String tableName = tableHandle.getTable();
String rowIdName = tableHandle.getRowId();
// Get non-row ID column constraints
List<AccumuloColumnConstraint> constraints = getColumnConstraints(rowIdName, layoutHandle.getConstraint());
// Get the row domain column range
Optional<Domain> rDom = getRangeDomain(rowIdName, layoutHandle.getConstraint());
// Call out to our client to retrieve all tablet split metadata using the row ID domain and the secondary index
List<TabletSplitMetadata> tabletSplits = client.getTabletSplits(session, schemaName, tableName, rDom, constraints, tableHandle.getSerializerInstance());
// Pack the tablet split metadata into a connector split
ImmutableList.Builder<ConnectorSplit> cSplits = ImmutableList.builder();
for (TabletSplitMetadata splitMetadata : tabletSplits) {
AccumuloSplit split = new AccumuloSplit(connectorId, schemaName, tableName, rowIdName, tableHandle.getSerializerClassName(), splitMetadata.getRanges().stream().map(WrappedRange::new).collect(Collectors.toList()), constraints, tableHandle.getScanAuthorizations(), splitMetadata.getHostPort());
cSplits.add(split);
}
return new FixedSplitSource(cSplits.build());
}
use of com.facebook.presto.accumulo.model.TabletSplitMetadata in project presto by prestodb.
the class IndexLookup method binRanges.
private static void binRanges(int numRangesPerBin, List<Range> splitRanges, List<TabletSplitMetadata> prestoSplits) {
checkArgument(numRangesPerBin > 0, "number of ranges per bin must positivebe greater than zero");
int toAdd = splitRanges.size();
int fromIndex = 0;
int toIndex = Math.min(toAdd, numRangesPerBin);
do {
// Add the sublist of range handles
// Use an empty location because we are binning multiple Ranges spread across many tablet servers
prestoSplits.add(new TabletSplitMetadata(Optional.empty(), splitRanges.subList(fromIndex, toIndex)));
toAdd -= toIndex - fromIndex;
fromIndex = toIndex;
toIndex += Math.min(toAdd, numRangesPerBin);
} while (toAdd > 0);
}
Aggregations