Search in sources :

Example 1 with EquatableValueSet

use of com.facebook.presto.common.predicate.EquatableValueSet in project presto by prestodb.

the class KuduClientSession method addConstraintPredicates.

/**
 * translates TupleDomain to KuduPredicates.
 *
 * @return false if TupleDomain or one of its domains is none
 */
private boolean addConstraintPredicates(KuduTable table, KuduScanToken.KuduScanTokenBuilder builder, TupleDomain<ColumnHandle> constraintSummary) {
    if (constraintSummary.isNone()) {
        return false;
    } else if (!constraintSummary.isAll()) {
        Schema schema = table.getSchema();
        for (TupleDomain.ColumnDomain<ColumnHandle> columnDomain : constraintSummary.getColumnDomains().get()) {
            int position = ((KuduColumnHandle) columnDomain.getColumn()).getOrdinalPosition();
            ColumnSchema columnSchema = schema.getColumnByIndex(position);
            Domain domain = columnDomain.getDomain();
            if (domain.isNone()) {
                return false;
            } else if (domain.isAll()) {
            // no restriction
            } else if (domain.isOnlyNull()) {
                builder.addPredicate(KuduPredicate.newIsNullPredicate(columnSchema));
            } else if (domain.getValues().isAll() && domain.isNullAllowed()) {
                builder.addPredicate(KuduPredicate.newIsNotNullPredicate(columnSchema));
            } else if (domain.isSingleValue()) {
                KuduPredicate predicate = createEqualsPredicate(columnSchema, domain.getSingleValue());
                builder.addPredicate(predicate);
            } else {
                ValueSet valueSet = domain.getValues();
                if (valueSet instanceof EquatableValueSet) {
                    DiscreteValues discreteValues = valueSet.getDiscreteValues();
                    KuduPredicate predicate = createInListPredicate(columnSchema, discreteValues);
                    builder.addPredicate(predicate);
                } else if (valueSet instanceof SortedRangeSet) {
                    Ranges ranges = ((SortedRangeSet) valueSet).getRanges();
                    Range span = ranges.getSpan();
                    Marker low = span.getLow();
                    if (!low.isLowerUnbounded()) {
                        KuduPredicate.ComparisonOp op = (low.getBound() == Marker.Bound.ABOVE) ? KuduPredicate.ComparisonOp.GREATER : KuduPredicate.ComparisonOp.GREATER_EQUAL;
                        KuduPredicate predicate = createComparisonPredicate(columnSchema, op, low.getValue());
                        builder.addPredicate(predicate);
                    }
                    Marker high = span.getHigh();
                    if (!high.isUpperUnbounded()) {
                        KuduPredicate.ComparisonOp op = (low.getBound() == Marker.Bound.BELOW) ? KuduPredicate.ComparisonOp.LESS : KuduPredicate.ComparisonOp.LESS_EQUAL;
                        KuduPredicate predicate = createComparisonPredicate(columnSchema, op, high.getValue());
                        builder.addPredicate(predicate);
                    }
                } else {
                    throw new IllegalStateException("Unexpected domain: " + domain);
                }
            }
        }
    }
    return true;
}
Also used : Ranges(com.facebook.presto.common.predicate.Ranges) Schema(org.apache.kudu.Schema) ColumnSchema(org.apache.kudu.ColumnSchema) EquatableValueSet(com.facebook.presto.common.predicate.EquatableValueSet) ColumnSchema(org.apache.kudu.ColumnSchema) Marker(com.facebook.presto.common.predicate.Marker) Range(com.facebook.presto.common.predicate.Range) KuduPredicate(org.apache.kudu.client.KuduPredicate) SortedRangeSet(com.facebook.presto.common.predicate.SortedRangeSet) DiscreteValues(com.facebook.presto.common.predicate.DiscreteValues) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) EquatableValueSet(com.facebook.presto.common.predicate.EquatableValueSet) ValueSet(com.facebook.presto.common.predicate.ValueSet)

Aggregations

DiscreteValues (com.facebook.presto.common.predicate.DiscreteValues)1 Domain (com.facebook.presto.common.predicate.Domain)1 EquatableValueSet (com.facebook.presto.common.predicate.EquatableValueSet)1 Marker (com.facebook.presto.common.predicate.Marker)1 Range (com.facebook.presto.common.predicate.Range)1 Ranges (com.facebook.presto.common.predicate.Ranges)1 SortedRangeSet (com.facebook.presto.common.predicate.SortedRangeSet)1 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 ValueSet (com.facebook.presto.common.predicate.ValueSet)1 ColumnSchema (org.apache.kudu.ColumnSchema)1 Schema (org.apache.kudu.Schema)1 KuduPredicate (org.apache.kudu.client.KuduPredicate)1