com.facebook.presto.spi.predicate.Domain Java Examples

The following examples show how to use com.facebook.presto.spi.predicate.Domain. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Elasticsearch2Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
public static Collection<Range> getRangesFromDomain(Domain domain)
        throws TableNotFoundException
{
    Collection<Range> rangeBuilder = domain.getValues().getRanges().getOrderedRanges();

    return rangeBuilder;
}
 
Example #2
Source File: Elasticsearch6Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
public static Collection<Range> getRangesFromDomain(Domain domain)
        throws TableNotFoundException
{
    Collection<Range> rangeBuilder = domain.getValues().getRanges().getOrderedRanges();

    return rangeBuilder;
}
 
Example #3
Source File: HbaseSplitManager.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layout, SplitSchedulingStrategy splitSchedulingStrategy)
{
    HbaseTableLayoutHandle layoutHandle = (HbaseTableLayoutHandle) layout;
    HbaseTableHandle tableHandle = layoutHandle.getTable();

    String schemaName = tableHandle.getSchema();
    String tableName = tableHandle.getTable();
    String rowIdName = tableHandle.getRowId();

    // Get non-row ID column constraints
    List<HbaseColumnConstraint> 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) {
        HbaseSplit split = new HbaseSplit(
                connectorId,
                schemaName,
                tableName,
                rowIdName,
                splitMetadata,
                constraints,
                tableHandle.getScanAuthorizations());
        cSplits.add(split);
    }

    return new FixedSplitSource(cSplits.build());
}
 
Example #4
Source File: HbaseSplitManager.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
private static Optional<Domain> getRangeDomain(String rowIdName, TupleDomain<ColumnHandle> constraint)
{
    if (constraint.getColumnDomains().isPresent()) {
        for (TupleDomain.ColumnDomain<ColumnHandle> cd : constraint.getColumnDomains().get()) {
            HbaseColumnHandle col = (HbaseColumnHandle) cd.getColumn();
            if (col.getName().equals(rowIdName)) {
                return Optional.of(cd.getDomain());
            }
        }
    }

    return Optional.empty();
}
 
Example #5
Source File: HbaseColumnConstraint.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public HbaseColumnConstraint(
        @JsonProperty("name") String name,
        @JsonProperty("family") String family,
        @JsonProperty("qualifier") String qualifier,
        @JsonProperty("domain") Optional<Domain> domain,
        @JsonProperty("indexed") boolean indexed)
{
    this.name = requireNonNull(name, "name is null");
    this.family = requireNonNull(family, "family is null");
    this.qualifier = requireNonNull(qualifier, "qualifier is null");
    this.indexed = requireNonNull(indexed, "indexed is null");
    this.domain = requireNonNull(domain, "domain is null");
}
 
Example #6
Source File: HbaseClient.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a collection of Hbase Range objects from the given Presto domain.
 * This maps the column constraints of the given Domain to an Hbase Range scan.
 *
 * @param domain Domain, can be null (returns (-inf, +inf) Range)
 * @return A collection of Hbase Range objects
 * @throws TableNotFoundException If the Hbase table is not found
 */
public static Collection<Range> getRangesFromDomain(Optional<Domain> domain)
        throws TableNotFoundException
{
    // if we have no predicate pushdown, use the full range
    if (!domain.isPresent()) {
        return ImmutableSet.of();
    }

    Collection<Range> rangeBuilder = domain.get().getValues().getRanges().getOrderedRanges();

    return rangeBuilder;
}
 
Example #7
Source File: Elasticsearch5Client.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
public static Collection<Range> getRangesFromDomain(Domain domain)
        throws TableNotFoundException
{
    Collection<Range> rangeBuilder = domain.getValues().getRanges().getOrderedRanges();

    return rangeBuilder;
}
 
Example #8
Source File: HbaseColumnConstraint.java    From presto-connectors with Apache License 2.0 4 votes vote down vote up
@JsonProperty
public Optional<Domain> getDomain()
{
    return domain;
}
 
Example #9
Source File: HbaseClient.java    From presto-connectors with Apache License 2.0 4 votes vote down vote up
/**
 * Fetches the TabletSplitMetadata for a query against an Hbase 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
 * @return List of TabletSplitMetadata objects for Presto
 */
public List<TabletSplitMetadata> getTabletSplits(
        ConnectorSession session,
        String schema,
        String table,
        Optional<Domain> rowIdDomain,
        List<HbaseColumnConstraint> constraints) //HbaseRowSerializer serializer
{
    try {
        TableName tableName = TableName.valueOf(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

        // Split the ranges on tablet boundaries, if enabled
        // Create TabletSplitMetadata objects for each range
        boolean fetchTabletLocations = HbaseSessionProperties.isOptimizeLocalityEnabled(session);

        LOG.debug("Fetching tablet locations: %s", fetchTabletLocations);

        ImmutableList.Builder<TabletSplitMetadata> builder = ImmutableList.builder();
        if (rowIdRanges.size() == 0) {  //无 rowkey过滤
            LOG.warn("This request has no rowkey filter");
        }
        List<Scan> rowIdScans = rowIdRanges.size() == 0 ?
                Arrays.asList(new Scan())
                : rowIdRanges.stream().map(HbaseClient::getScanFromPrestoRange).collect(Collectors.toList());

        for (Scan scan : rowIdScans) {
            TableInputFormat tableInputFormat = getNewTableInputFormat(connection, tableName);
            tableInputFormat.setConf(connection.getConfiguration());
            tableInputFormat.setScan(scan);

            JobContext context = new JobContextImpl(new JobConf(), null);
            List<TableSplit> splits = tableInputFormat.getSplits(context)
                    .stream().map(x -> (TableSplit) x).collect(Collectors.toList());

            for (TableSplit split : splits) {
                TabletSplitMetadata metadata = new TabletSplitMetadata(
                        split.getTable().getName(),
                        split.getStartRow(),
                        split.getEndRow(),
                        TabletSplitMetadata.convertScanToString(split.getScan()),
                        split.getRegionLocation(),
                        split.getLength());
                builder.add(metadata);
            }
        }
        List<TabletSplitMetadata> tabletSplits = builder.build();

        // 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(), rowIdRanges.size());
        return tabletSplits;
    }
    catch (Exception e) {
        throw new PrestoException(UNEXPECTED_HBASE_ERROR, "Failed to get splits from Hbase", e);
    }
}