Search in sources :

Example 51 with TupleDomain

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

the class TestLocalDynamicFilter method testMultiplePartitions.

@Test
public void testMultiplePartitions() throws ExecutionException, InterruptedException {
    LocalDynamicFilter filter = new LocalDynamicFilter(ImmutableMultimap.of("123", new DynamicFilterPlaceholder("123", new VariableReferenceExpression(Optional.empty(), "a", INTEGER), EQUAL)), ImmutableMap.of("123", 0), 2);
    assertEquals(filter.getBuildChannels(), ImmutableMap.of("123", 0));
    Consumer<TupleDomain<String>> consumer = filter.getTupleDomainConsumer();
    ListenableFuture<TupleDomain<VariableReferenceExpression>> result = filter.getResultFuture();
    assertFalse(result.isDone());
    consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of("123", Domain.singleValue(INTEGER, 10L))));
    assertFalse(result.isDone());
    consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of("123", Domain.singleValue(INTEGER, 20L))));
    assertEquals(result.get(), TupleDomain.withColumnDomains(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "a", INTEGER), Domain.multipleValues(INTEGER, ImmutableList.of(10L, 20L)))));
}
Also used : TupleDomain(com.facebook.presto.common.predicate.TupleDomain) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) DynamicFilterPlaceholder(com.facebook.presto.expressions.DynamicFilters.DynamicFilterPlaceholder) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 52 with TupleDomain

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

the class TestLocalDynamicFilter method testMultipleProbeVariables.

@Test
public void testMultipleProbeVariables() throws ExecutionException, InterruptedException {
    LocalDynamicFilter filter = new LocalDynamicFilter(ImmutableMultimap.of("123", new DynamicFilterPlaceholder("123", new VariableReferenceExpression(Optional.empty(), "a1", INTEGER), EQUAL), "123", new DynamicFilterPlaceholder("123", new VariableReferenceExpression(Optional.empty(), "a2", INTEGER), EQUAL)), ImmutableMap.of("123", 0), 1);
    assertEquals(filter.getBuildChannels(), ImmutableMap.of("123", 0));
    Consumer<TupleDomain<String>> consumer = filter.getTupleDomainConsumer();
    ListenableFuture<TupleDomain<VariableReferenceExpression>> result = filter.getResultFuture();
    assertFalse(result.isDone());
    consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of("123", Domain.singleValue(INTEGER, 7L))));
    assertEquals(result.get(), TupleDomain.withColumnDomains(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "a1", INTEGER), Domain.singleValue(INTEGER, 7L), new VariableReferenceExpression(Optional.empty(), "a2", INTEGER), Domain.singleValue(INTEGER, 7L))));
}
Also used : TupleDomain(com.facebook.presto.common.predicate.TupleDomain) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) DynamicFilterPlaceholder(com.facebook.presto.expressions.DynamicFilters.DynamicFilterPlaceholder) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 53 with TupleDomain

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

the class TestLocalDynamicFilter method testNone.

@Test
public void testNone() throws ExecutionException, InterruptedException {
    LocalDynamicFilter filter = new LocalDynamicFilter(ImmutableMultimap.of("123", new DynamicFilterPlaceholder("123", new VariableReferenceExpression(Optional.empty(), "a", INTEGER), EQUAL)), ImmutableMap.of("123", 0), 1);
    assertEquals(filter.getBuildChannels(), ImmutableMap.of("123", 0));
    Consumer<TupleDomain<String>> consumer = filter.getTupleDomainConsumer();
    ListenableFuture<TupleDomain<VariableReferenceExpression>> result = filter.getResultFuture();
    assertFalse(result.isDone());
    consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of("123", Domain.none(INTEGER))));
    assertEquals(result.get(), TupleDomain.withColumnDomains(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "a", INTEGER), Domain.none(INTEGER))));
}
Also used : TupleDomain(com.facebook.presto.common.predicate.TupleDomain) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) DynamicFilterPlaceholder(com.facebook.presto.expressions.DynamicFilters.DynamicFilterPlaceholder) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 54 with TupleDomain

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

the class TestLocalDynamicFilter method testSimple.

@Test
public void testSimple() throws ExecutionException, InterruptedException {
    LocalDynamicFilter filter = new LocalDynamicFilter(ImmutableMultimap.of("123", new DynamicFilterPlaceholder("123", new VariableReferenceExpression(Optional.empty(), "a", INTEGER), EQUAL)), ImmutableMap.of("123", 0), 1);
    assertEquals(filter.getBuildChannels(), ImmutableMap.of("123", 0));
    Consumer<TupleDomain<String>> consumer = filter.getTupleDomainConsumer();
    ListenableFuture<TupleDomain<VariableReferenceExpression>> result = filter.getResultFuture();
    assertFalse(result.isDone());
    consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of("123", Domain.singleValue(INTEGER, 7L))));
    assertEquals(result.get(), TupleDomain.withColumnDomains(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "a", INTEGER), Domain.singleValue(INTEGER, 7L))));
}
Also used : TupleDomain(com.facebook.presto.common.predicate.TupleDomain) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) DynamicFilterPlaceholder(com.facebook.presto.expressions.DynamicFilters.DynamicFilterPlaceholder) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 55 with TupleDomain

use of com.facebook.presto.common.predicate.TupleDomain 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

TupleDomain (com.facebook.presto.common.predicate.TupleDomain)76 Domain (com.facebook.presto.common.predicate.Domain)54 Map (java.util.Map)39 ColumnHandle (com.facebook.presto.spi.ColumnHandle)36 ImmutableList (com.google.common.collect.ImmutableList)33 ImmutableMap (com.google.common.collect.ImmutableMap)31 List (java.util.List)27 Optional (java.util.Optional)26 Objects.requireNonNull (java.util.Objects.requireNonNull)25 Test (org.testng.annotations.Test)25 ConnectorSession (com.facebook.presto.spi.ConnectorSession)22 SchemaTableName (com.facebook.presto.spi.SchemaTableName)22 Set (java.util.Set)21 Type (com.facebook.presto.common.type.Type)20 PrestoException (com.facebook.presto.spi.PrestoException)20 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)19 ImmutableSet (com.google.common.collect.ImmutableSet)19 String.format (java.lang.String.format)19 NullableValue (com.facebook.presto.common.predicate.NullableValue)17 TypeManager (com.facebook.presto.common.type.TypeManager)15