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

The following examples show how to use com.facebook.presto.spi.predicate.TupleDomain. 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: KubeSplitManager.java    From kubesql with Apache License 2.0 6 votes vote down vote up
@Override
public ConnectorSplitSource getSplits(
        ConnectorTransactionHandle transactionHandle,
        ConnectorSession session,
        ConnectorTableLayoutHandle layout,
        SplitSchedulingContext splitSchedulingContext)
{
    KubeTableLayoutHandle layoutHandle = (KubeTableLayoutHandle) layout;
    KubeTableHandle tableHandle = layoutHandle.getTable();

    TupleDomain<KubeColumnHandle> effectivePredicate = layoutHandle.getConstraint()
            .transform(KubeColumnHandle.class::cast);

    List<ConnectorSplit> splits = nodeManager.getAllNodes().stream()
            .map(node -> new KubeSplit(node.getHostAndPort(), tableHandle.getSchemaTableName(), effectivePredicate))
            .collect(Collectors.toList());

    return new FixedSplitSource(splits);
}
 
Example #2
Source File: ParaflowTableLayoutHandle.java    From paraflow with Apache License 2.0 6 votes vote down vote up
@JsonCreator
public ParaflowTableLayoutHandle(
        @JsonProperty("table") ParaflowTableHandle table,
        @JsonProperty("fiberColumn") ParaflowColumnHandle fiberColumn,
        @JsonProperty("timestampColumn") ParaflowColumnHandle timestampColumn,
        @JsonProperty("fiberPartitioner") String fiberPartitioner,
        @JsonProperty("storageFormat") StorageFormat storageFormat,
        @JsonProperty("predicates") Optional<TupleDomain<ColumnHandle>> predicates)
{
    this.table = requireNonNull(table, "table is null");
    this.fiberColumn = requireNonNull(fiberColumn, "fiberColumn is null");
    this.timestampColumn = requireNonNull(timestampColumn, "timestampColumn is null");
    this.fiberPartitioner = requireNonNull(fiberPartitioner, "fiberPartitioner is null");
    this.storageFormat = requireNonNull(storageFormat, "storageFormat is null");
    this.predicates = requireNonNull(predicates, "predicates is null");
}
 
Example #3
Source File: HbaseSplitManager.java    From presto-connectors with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a list of {@link HbaseColumnConstraint} based on the given constraint ID, excluding the row ID column
 *
 * @param rowIdName Presto column name mapping to the Hbase row ID
 * @param constraint Set of query constraints
 * @return List of all column constraints
 */
private static List<HbaseColumnConstraint> getColumnConstraints(String rowIdName, TupleDomain<ColumnHandle> constraint)
{
    ImmutableList.Builder<HbaseColumnConstraint> constraintBuilder = ImmutableList.builder();
    for (TupleDomain.ColumnDomain<ColumnHandle> columnDomain : constraint.getColumnDomains().get()) {
        HbaseColumnHandle columnHandle = (HbaseColumnHandle) columnDomain.getColumn();

        if (!columnHandle.getName().equals(rowIdName)) {
            // Family and qualifier will exist for non-row ID columns
            constraintBuilder.add(new HbaseColumnConstraint(
                    columnHandle.getName(),
                    columnHandle.getFamily().get(),
                    columnHandle.getQualifier().get(),
                    Optional.of(columnDomain.getDomain()),
                    columnHandle.isIndexed()));
        }
    }

    return constraintBuilder.build();
}
 
Example #4
Source File: KubeTableLayoutHandle.java    From kubesql with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public KubeTableLayoutHandle(
        @JsonProperty("table") KubeTableHandle table,
        @JsonProperty("constraint") TupleDomain<ColumnHandle> constraint)
{
    this.table = requireNonNull(table, "table is null");
    this.constraint = requireNonNull(constraint, "constraint is null");
}
 
Example #5
Source File: KubeSplit.java    From kubesql with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public KubeSplit(
        @JsonProperty("address") HostAddress address,
        @JsonProperty("tableName") SchemaTableName tableName,
        @JsonProperty("effectivePredicate") TupleDomain<KubeColumnHandle> effectivePredicate)
{
    this.address = requireNonNull(address, "address is null");
    this.tableName = requireNonNull(tableName, "tableName is null");
    this.effectivePredicate = requireNonNull(effectivePredicate, "effectivePredicate is null");
}
 
Example #6
Source File: KuduTableLayoutHandle.java    From presto-kudu with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public KuduTableLayoutHandle(@JsonProperty("tableHandle") KuduTableHandle tableHandle,
                             @JsonProperty("constraintSummary") TupleDomain<ColumnHandle> constraintSummary,
                             @JsonProperty("desiredColumns") Optional<Set<ColumnHandle>> desiredColumns) {
    this.tableHandle = requireNonNull(tableHandle, "table is null");
    this.constraintSummary = constraintSummary;
    this.desiredColumns = desiredColumns;
}
 
Example #7
Source File: KubeRecordCursor.java    From kubesql with Apache License 2.0 5 votes vote down vote up
public KubeRecordCursor(KubeTables kubeTables, List<KubeColumnHandle> columns, SchemaTableName tableName, HostAddress address, TupleDomain<KubeColumnHandle> predicate) {
    this.columns = requireNonNull(columns, "columns is null");
    this.address = requireNonNull(address, "address is null");

    fieldToColumnName = new String[columns.size()];
    fieldToColumnIndex = new int[columns.size()];
    for (int i = 0; i < columns.size(); i++) {
        KubeColumnHandle columnHandle = columns.get(i);
        fieldToColumnIndex[i] = columnHandle.getOrdinalPosition();
        fieldToColumnName[i] = columnHandle.getColumnName();
    }
    resources = kubeTables.getKubeCache().getCache(tableName).values().iterator();
}
 
Example #8
Source File: ElasticsearchTableLayoutHandle.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public ElasticsearchTableLayoutHandle(
        @JsonProperty("table") ElasticsearchTableHandle table,
        @JsonProperty("constraint") TupleDomain<ColumnHandle> constraint)
{
    this.table = requireNonNull(table, "table is null");
    this.constraint = requireNonNull(constraint, "constraint is null");
}
 
Example #9
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 #10
Source File: HbaseTableLayoutHandle.java    From presto-connectors with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public HbaseTableLayoutHandle(
        @JsonProperty("table") HbaseTableHandle table,
        @JsonProperty("constraint") TupleDomain<ColumnHandle> constraint)
{
    this.table = requireNonNull(table, "table is null");
    this.constraint = requireNonNull(constraint, "constraint is null");
}
 
Example #11
Source File: KuduTableLayoutHandle.java    From presto-kudu with Apache License 2.0 4 votes vote down vote up
@JsonProperty
public TupleDomain<ColumnHandle> getConstraintSummary() {
    return constraintSummary;
}
 
Example #12
Source File: ParaflowTableLayoutHandle.java    From paraflow with Apache License 2.0 4 votes vote down vote up
public void setPredicates(Optional<TupleDomain<ColumnHandle>> predicates)
{
    this.predicates = predicates;
}
 
Example #13
Source File: ParaflowTableLayoutHandle.java    From paraflow with Apache License 2.0 4 votes vote down vote up
@JsonProperty
public Optional<TupleDomain<ColumnHandle>> getPredicates()
{
    return predicates;
}
 
Example #14
Source File: Elasticsearch5Client.java    From presto-connectors with Apache License 2.0 4 votes vote down vote up
private static Map<String, String> getQueryDsl(TupleDomain<ColumnHandle> constraint)
{
    final Map<String, Object> mergeDslMap = new HashMap<>();
    Map<String, String> dslCacher = new HashMap<>();

    if (constraint.getColumnDomains().isPresent()) {
        for (TupleDomain.ColumnDomain<ColumnHandle> cd : constraint.getColumnDomains().get()) {
            ElasticsearchColumnHandle column = (ElasticsearchColumnHandle) cd.getColumn();
            String columnName = column.getName();

            if ("_type".equals(columnName)) {
                throw new UnsupportedOperationException("this _type filter have't support!");
            }
            else if (columnName.startsWith("_")) {
                getRangesFromDomain(cd.getDomain()).forEach(range -> {
                    checkArgument(range.isSingleValue(), "dsl is must [=] demo where _dsl = \"..dsl string\"");
                    checkArgument(range.getType() instanceof VarcharType, "_dsl filter is not string");
                    String dsl = ((Slice) range.getSingleValue()).toStringUtf8();
                    dslCacher.put(columnName, dsl);
                    if (!"_dsl".equals(columnName)) {
                        dsl = dsl.replace(MatchQueryFunction.MATCH_COLUMN_SEP, columnName.substring(1));
                    }
                    addEsQueryFilter(mergeDslMap, dsl);
                });
            }
            else {
                getRangesFromDomain(cd.getDomain()).forEach(range -> {
                    checkArgument(column.getType().equals(range.getType()), "filter type is " + range.getType() + " but column [" + columnName + "] type is " + column.getType());
                    QueryBuilder queryBuilder = getQueryBuilderFromPrestoRange(columnName, range);
                    addEsQueryFilter(mergeDslMap, queryBuilder.toString());
                });
            }
        }
    }
    try {
        String allDsl = mergeDslMap.isEmpty() ? QueryBuilders.boolQuery().toString() :
                MAPPER.writeValueAsString(mergeDslMap.get("query"));   //es5和 6开始只能返回 query的自节点
        dslCacher.put("_allDsl", allDsl);
        return dslCacher;
    }
    catch (JsonProcessingException e) {
        throw new PrestoException(ES_DSL_ERROR, e);
    }
}
 
Example #15
Source File: HbaseTableLayoutHandle.java    From presto-connectors with Apache License 2.0 4 votes vote down vote up
@JsonProperty
public TupleDomain<ColumnHandle> getConstraint()
{
    return constraint;
}
 
Example #16
Source File: ElasticsearchTableLayoutHandle.java    From presto-connectors with Apache License 2.0 4 votes vote down vote up
@JsonProperty
public TupleDomain<ColumnHandle> getConstraint()
{
    return constraint;
}
 
Example #17
Source File: Elasticsearch6Client.java    From presto-connectors with Apache License 2.0 4 votes vote down vote up
private static Map<String, String> getQueryDsl(TupleDomain<ColumnHandle> constraint)
{
    final Map<String, Object> mergeDslMap = new HashMap<>();
    Map<String, String> dslCacher = new HashMap<>();

    if (constraint.getColumnDomains().isPresent()) {
        for (TupleDomain.ColumnDomain<ColumnHandle> cd : constraint.getColumnDomains().get()) {
            ElasticsearchColumnHandle column = (ElasticsearchColumnHandle) cd.getColumn();
            String columnName = column.getName();

            if ("_type".equals(columnName)) {
                throw new UnsupportedOperationException("this _type filter have't support!");
            }
            else if (columnName.startsWith("_")) {
                getRangesFromDomain(cd.getDomain()).forEach(range -> {
                    checkArgument(range.isSingleValue(), "dsl is must [=] demo where _dsl = \"..dsl string\"");
                    checkArgument(range.getType() instanceof VarcharType, "_dsl filter is not string");
                    String dsl = ((Slice) range.getSingleValue()).toStringUtf8();
                    dslCacher.put(columnName, dsl);
                    if (!"_dsl".equals(columnName)) {
                        dsl = dsl.replace(MatchQueryFunction.MATCH_COLUMN_SEP, columnName.substring(1));
                    }
                    addEsQueryFilter(mergeDslMap, dsl);
                });
            }
            else {
                getRangesFromDomain(cd.getDomain()).forEach(range -> {
                    checkArgument(column.getType().equals(range.getType()), "filter type is " + range.getType() + " but column [" + columnName + "] type is " + column.getType());
                    QueryBuilder queryBuilder = getQueryBuilderFromPrestoRange(columnName, range);
                    addEsQueryFilter(mergeDslMap, queryBuilder.toString());
                });
            }
        }
    }
    try {
        String allDsl = mergeDslMap.isEmpty() ? QueryBuilders.boolQuery().toString() :
                MAPPER.writeValueAsString(mergeDslMap.get("query"));   //es5和 6开始只能返回 query的自节点
        dslCacher.put("_allDsl", allDsl);
        return dslCacher;
    }
    catch (JsonProcessingException e) {
        throw new PrestoException(ES_DSL_ERROR, e);
    }
}
 
Example #18
Source File: Elasticsearch2Client.java    From presto-connectors with Apache License 2.0 4 votes vote down vote up
private static Map<String, String> getQueryDsl(TupleDomain<ColumnHandle> constraint)
{
    final Map<String, Object> mergeDslMap = new HashMap<>();
    Map<String, String> dslCacher = new HashMap<>();

    if (constraint.getColumnDomains().isPresent()) {
        for (TupleDomain.ColumnDomain<ColumnHandle> cd : constraint.getColumnDomains().get()) {
            ElasticsearchColumnHandle column = (ElasticsearchColumnHandle) cd.getColumn();
            String columnName = column.getName();

            if ("_type".equals(columnName)) {
                throw new UnsupportedOperationException("this _type filter have't support!");
            }
            else if (columnName.startsWith("_")) {
                getRangesFromDomain(cd.getDomain()).forEach(range -> {
                    checkArgument(range.isSingleValue(), "dsl is must [=] demo where _dsl = \"..dsl string\"");
                    checkArgument(range.getType() instanceof VarcharType, "_dsl filter is not string");
                    String dsl = ((Slice) range.getSingleValue()).toStringUtf8();
                    dslCacher.put(columnName, dsl);
                    if (!"_dsl".equals(columnName)) {
                        dsl = dsl.replace(MatchQueryFunction.MATCH_COLUMN_SEP, columnName.substring(1));
                    }
                    addEsQueryFilter(mergeDslMap, dsl);
                });
            }
            else {
                getRangesFromDomain(cd.getDomain()).forEach(range -> {
                    checkArgument(column.getType().equals(range.getType()), "filter type is " + range.getType() + " but column [" + columnName + "] type is " + column.getType());
                    QueryBuilder queryBuilder = getQueryBuilderFromPrestoRange(columnName, range);
                    addEsQueryFilter(mergeDslMap, queryBuilder.toString());
                });
            }
        }
    }
    try {
        String allDsl = mergeDslMap.isEmpty() ? QueryBuilders.boolQuery().toString() : MAPPER.writeValueAsString(mergeDslMap);
        dslCacher.put("_allDsl", allDsl);
        return dslCacher;
    }
    catch (JsonProcessingException e) {
        throw new PrestoException(ES_DSL_ERROR, e);
    }
}
 
Example #19
Source File: KubeSplit.java    From kubesql with Apache License 2.0 4 votes vote down vote up
@JsonProperty
public TupleDomain<KubeColumnHandle> getEffectivePredicate()
{
    return effectivePredicate;
}
 
Example #20
Source File: KubeTableLayoutHandle.java    From kubesql with Apache License 2.0 4 votes vote down vote up
@JsonProperty
public TupleDomain<ColumnHandle> getConstraint()
{
    return constraint;
}