Search in sources :

Example 1 with TabletSplitMetadata

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());
}
Also used : AccumuloColumnConstraint(com.facebook.presto.accumulo.model.AccumuloColumnConstraint) ImmutableList(com.google.common.collect.ImmutableList) TabletSplitMetadata(com.facebook.presto.accumulo.model.TabletSplitMetadata) AccumuloSplit(com.facebook.presto.accumulo.model.AccumuloSplit) WrappedRange(com.facebook.presto.accumulo.model.WrappedRange) AccumuloTableLayoutHandle(com.facebook.presto.accumulo.model.AccumuloTableLayoutHandle) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) AccumuloTableHandle(com.facebook.presto.accumulo.model.AccumuloTableHandle) ColumnDomain(com.facebook.presto.spi.predicate.TupleDomain.ColumnDomain) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 2 with TabletSplitMetadata

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);
    }
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) ArrayList(java.util.ArrayList) PrestoException(com.facebook.presto.spi.PrestoException) TabletSplitMetadata(com.facebook.presto.accumulo.model.TabletSplitMetadata) Range(org.apache.accumulo.core.data.Range) InvalidParameterException(java.security.InvalidParameterException) PrestoException(com.facebook.presto.spi.PrestoException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException)

Example 3 with TabletSplitMetadata

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());
}
Also used : AccumuloColumnConstraint(com.facebook.presto.accumulo.model.AccumuloColumnConstraint) ImmutableList(com.google.common.collect.ImmutableList) TabletSplitMetadata(com.facebook.presto.accumulo.model.TabletSplitMetadata) AccumuloSplit(com.facebook.presto.accumulo.model.AccumuloSplit) WrappedRange(com.facebook.presto.accumulo.model.WrappedRange) AccumuloTableLayoutHandle(com.facebook.presto.accumulo.model.AccumuloTableLayoutHandle) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) AccumuloTableHandle(com.facebook.presto.accumulo.model.AccumuloTableHandle) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) ColumnDomain(com.facebook.presto.common.predicate.TupleDomain.ColumnDomain) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 4 with TabletSplitMetadata

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);
}
Also used : TabletSplitMetadata(com.facebook.presto.accumulo.model.TabletSplitMetadata) AccumuloColumnConstraint(com.facebook.presto.accumulo.model.AccumuloColumnConstraint)

Aggregations

TabletSplitMetadata (com.facebook.presto.accumulo.model.TabletSplitMetadata)4 AccumuloColumnConstraint (com.facebook.presto.accumulo.model.AccumuloColumnConstraint)3 AccumuloSplit (com.facebook.presto.accumulo.model.AccumuloSplit)2 AccumuloTableHandle (com.facebook.presto.accumulo.model.AccumuloTableHandle)2 AccumuloTableLayoutHandle (com.facebook.presto.accumulo.model.AccumuloTableLayoutHandle)2 WrappedRange (com.facebook.presto.accumulo.model.WrappedRange)2 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)2 FixedSplitSource (com.facebook.presto.spi.FixedSplitSource)2 ImmutableList (com.google.common.collect.ImmutableList)2 Domain (com.facebook.presto.common.predicate.Domain)1 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 ColumnDomain (com.facebook.presto.common.predicate.TupleDomain.ColumnDomain)1 PrestoException (com.facebook.presto.spi.PrestoException)1 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)1 Domain (com.facebook.presto.spi.predicate.Domain)1 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)1 ColumnDomain (com.facebook.presto.spi.predicate.TupleDomain.ColumnDomain)1 InvalidParameterException (java.security.InvalidParameterException)1 ArrayList (java.util.ArrayList)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1