Search in sources :

Example 56 with VariableReferenceExpression

use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.

the class TestLocalDynamicFilter method testCreateSingleColumn.

@Test
public void testCreateSingleColumn() throws ExecutionException, InterruptedException {
    SubPlan subplan = subplan("SELECT count() FROM lineitem, orders WHERE lineitem.orderkey = orders.orderkey " + "AND orders.custkey < 10", LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED, false);
    JoinNode joinNode = searchJoins(subplan.getChildren().get(0).getFragment()).findOnlyElement();
    LocalDynamicFilter filter = LocalDynamicFilter.create(joinNode, 1).orElseThrow(NoSuchElementException::new);
    String filterId = Iterables.getOnlyElement(filter.getBuildChannels().keySet());
    VariableReferenceExpression probeVariable = Iterables.getOnlyElement(joinNode.getCriteria()).getLeft();
    filter.getTupleDomainConsumer().accept(TupleDomain.withColumnDomains(ImmutableMap.of(filterId, Domain.singleValue(BIGINT, 3L))));
    assertEquals(filter.getResultFuture().get(), TupleDomain.withColumnDomains(ImmutableMap.of(probeVariable, Domain.singleValue(BIGINT, 3L))));
}
Also used : JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) NoSuchElementException(java.util.NoSuchElementException) BasePlanTest(com.facebook.presto.sql.planner.assertions.BasePlanTest) Test(org.testng.annotations.Test)

Example 57 with VariableReferenceExpression

use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.

the class TestLocalDynamicFilter method testMultiplePartitionsAndColumns.

@Test
public void testMultiplePartitionsAndColumns() throws ExecutionException, InterruptedException {
    LocalDynamicFilter filter = new LocalDynamicFilter(ImmutableMultimap.of("123", new DynamicFilterPlaceholder("123", new VariableReferenceExpression(Optional.empty(), "a", INTEGER), EQUAL), "456", new DynamicFilterPlaceholder("456", new VariableReferenceExpression(Optional.empty(), "b", BIGINT), EQUAL)), ImmutableMap.of("123", 0, "456", 1), 2);
    assertEquals(filter.getBuildChannels(), ImmutableMap.of("123", 0, "456", 1));
    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), "456", Domain.singleValue(BIGINT, 100L))));
    assertFalse(result.isDone());
    consumer.accept(TupleDomain.withColumnDomains(ImmutableMap.of("123", Domain.singleValue(INTEGER, 20L), "456", Domain.singleValue(BIGINT, 200L))));
    assertEquals(result.get(), TupleDomain.withColumnDomains(ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "a", INTEGER), Domain.multipleValues(INTEGER, ImmutableList.of(10L, 20L)), new VariableReferenceExpression(Optional.empty(), "b", BIGINT), Domain.multipleValues(BIGINT, ImmutableList.of(100L, 200L)))));
}
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 58 with VariableReferenceExpression

use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.

the class TestRowExpressionDomainTranslator method testNumericTypeTranslation.

private void testNumericTypeTranslation(NumericValues columnValues, NumericValues literalValues) {
    Type columnType = columnValues.getInput().getType();
    Type literalType = literalValues.getInput().getType();
    Type superType = metadata.getFunctionAndTypeManager().getCommonSuperType(columnType, literalType).orElseThrow(() -> new IllegalArgumentException("incompatible types in test (" + columnType + ", " + literalType + ")"));
    RowExpression max = toRowExpression(literalValues.getMax(), literalType);
    RowExpression min = toRowExpression(literalValues.getMin(), literalType);
    RowExpression integerPositive = toRowExpression(literalValues.getIntegerPositive(), literalType);
    RowExpression integerNegative = toRowExpression(literalValues.getIntegerNegative(), literalType);
    RowExpression fractionalPositive = toRowExpression(literalValues.getFractionalPositive(), literalType);
    RowExpression fractionalNegative = toRowExpression(literalValues.getFractionalNegative(), literalType);
    if (!literalType.equals(superType)) {
        max = cast(max, superType);
        min = cast(min, superType);
        integerPositive = cast(integerPositive, superType);
        integerNegative = cast(integerNegative, superType);
        fractionalPositive = cast(fractionalPositive, superType);
        fractionalNegative = cast(fractionalNegative, superType);
    }
    VariableReferenceExpression columnSymbol = columnValues.getInput();
    RowExpression columnExpression = columnSymbol;
    if (!columnType.equals(superType)) {
        columnExpression = cast(columnExpression, superType);
    }
    // greater than or equal
    testSimpleComparison(greaterThanOrEqual(columnExpression, integerPositive), columnSymbol, Range.greaterThanOrEqual(columnType, columnValues.getIntegerPositive()));
    testSimpleComparison(greaterThanOrEqual(columnExpression, integerNegative), columnSymbol, Range.greaterThanOrEqual(columnType, columnValues.getIntegerNegative()));
    testSimpleComparison(greaterThanOrEqual(columnExpression, max), columnSymbol, Range.greaterThan(columnType, columnValues.getMax()));
    testSimpleComparison(greaterThanOrEqual(columnExpression, min), columnSymbol, Range.greaterThanOrEqual(columnType, columnValues.getMin()));
    if (literalValues.isFractional()) {
        testSimpleComparison(greaterThanOrEqual(columnExpression, fractionalPositive), columnSymbol, Range.greaterThan(columnType, columnValues.getFractionalPositive()));
        testSimpleComparison(greaterThanOrEqual(columnExpression, fractionalNegative), columnSymbol, Range.greaterThan(columnType, columnValues.getFractionalNegative()));
    }
    // greater than
    testSimpleComparison(greaterThan(columnExpression, integerPositive), columnSymbol, Range.greaterThan(columnType, columnValues.getIntegerPositive()));
    testSimpleComparison(greaterThan(columnExpression, integerNegative), columnSymbol, Range.greaterThan(columnType, columnValues.getIntegerNegative()));
    testSimpleComparison(greaterThan(columnExpression, max), columnSymbol, Range.greaterThan(columnType, columnValues.getMax()));
    testSimpleComparison(greaterThan(columnExpression, min), columnSymbol, Range.greaterThanOrEqual(columnType, columnValues.getMin()));
    if (literalValues.isFractional()) {
        testSimpleComparison(greaterThan(columnExpression, fractionalPositive), columnSymbol, Range.greaterThan(columnType, columnValues.getFractionalPositive()));
        testSimpleComparison(greaterThan(columnExpression, fractionalNegative), columnSymbol, Range.greaterThan(columnType, columnValues.getFractionalNegative()));
    }
    // less than or equal
    testSimpleComparison(lessThanOrEqual(columnExpression, integerPositive), columnSymbol, Range.lessThanOrEqual(columnType, columnValues.getIntegerPositive()));
    testSimpleComparison(lessThanOrEqual(columnExpression, integerNegative), columnSymbol, Range.lessThanOrEqual(columnType, columnValues.getIntegerNegative()));
    testSimpleComparison(lessThanOrEqual(columnExpression, max), columnSymbol, Range.lessThanOrEqual(columnType, columnValues.getMax()));
    testSimpleComparison(lessThanOrEqual(columnExpression, min), columnSymbol, Range.lessThan(columnType, columnValues.getMin()));
    if (literalValues.isFractional()) {
        testSimpleComparison(lessThanOrEqual(columnExpression, fractionalPositive), columnSymbol, Range.lessThanOrEqual(columnType, columnValues.getFractionalPositive()));
        testSimpleComparison(lessThanOrEqual(columnExpression, fractionalNegative), columnSymbol, Range.lessThanOrEqual(columnType, columnValues.getFractionalNegative()));
    }
    // less than
    testSimpleComparison(lessThan(columnExpression, integerPositive), columnSymbol, Range.lessThan(columnType, columnValues.getIntegerPositive()));
    testSimpleComparison(lessThan(columnExpression, integerNegative), columnSymbol, Range.lessThan(columnType, columnValues.getIntegerNegative()));
    testSimpleComparison(lessThan(columnExpression, max), columnSymbol, Range.lessThanOrEqual(columnType, columnValues.getMax()));
    testSimpleComparison(lessThan(columnExpression, min), columnSymbol, Range.lessThan(columnType, columnValues.getMin()));
    if (literalValues.isFractional()) {
        testSimpleComparison(lessThan(columnExpression, fractionalPositive), columnSymbol, Range.lessThanOrEqual(columnType, columnValues.getFractionalPositive()));
        testSimpleComparison(lessThan(columnExpression, fractionalNegative), columnSymbol, Range.lessThanOrEqual(columnType, columnValues.getFractionalNegative()));
    }
    // equal
    testSimpleComparison(equal(columnExpression, integerPositive), columnSymbol, Range.equal(columnType, columnValues.getIntegerPositive()));
    testSimpleComparison(equal(columnExpression, integerNegative), columnSymbol, Range.equal(columnType, columnValues.getIntegerNegative()));
    testSimpleComparison(equal(columnExpression, max), columnSymbol, Domain.none(columnType));
    testSimpleComparison(equal(columnExpression, min), columnSymbol, Domain.none(columnType));
    if (literalValues.isFractional()) {
        testSimpleComparison(equal(columnExpression, fractionalPositive), columnSymbol, Domain.none(columnType));
        testSimpleComparison(equal(columnExpression, fractionalNegative), columnSymbol, Domain.none(columnType));
    }
    // not equal
    testSimpleComparison(notEqual(columnExpression, integerPositive), columnSymbol, Domain.create(ValueSet.ofRanges(Range.lessThan(columnType, columnValues.getIntegerPositive()), Range.greaterThan(columnType, columnValues.getIntegerPositive())), false));
    testSimpleComparison(notEqual(columnExpression, integerNegative), columnSymbol, Domain.create(ValueSet.ofRanges(Range.lessThan(columnType, columnValues.getIntegerNegative()), Range.greaterThan(columnType, columnValues.getIntegerNegative())), false));
    testSimpleComparison(notEqual(columnExpression, max), columnSymbol, Domain.notNull(columnType));
    testSimpleComparison(notEqual(columnExpression, min), columnSymbol, Domain.notNull(columnType));
    if (literalValues.isFractional()) {
        testSimpleComparison(notEqual(columnExpression, fractionalPositive), columnSymbol, Domain.notNull(columnType));
        testSimpleComparison(notEqual(columnExpression, fractionalNegative), columnSymbol, Domain.notNull(columnType));
    }
    // is distinct from
    testSimpleComparison(isDistinctFrom(columnExpression, integerPositive), columnSymbol, Domain.create(ValueSet.ofRanges(Range.lessThan(columnType, columnValues.getIntegerPositive()), Range.greaterThan(columnType, columnValues.getIntegerPositive())), true));
    testSimpleComparison(isDistinctFrom(columnExpression, integerNegative), columnSymbol, Domain.create(ValueSet.ofRanges(Range.lessThan(columnType, columnValues.getIntegerNegative()), Range.greaterThan(columnType, columnValues.getIntegerNegative())), true));
    testSimpleComparison(isDistinctFrom(columnExpression, max), columnSymbol, Domain.all(columnType));
    testSimpleComparison(isDistinctFrom(columnExpression, min), columnSymbol, Domain.all(columnType));
    if (literalValues.isFractional()) {
        testSimpleComparison(isDistinctFrom(columnExpression, fractionalPositive), columnSymbol, Domain.all(columnType));
        testSimpleComparison(isDistinctFrom(columnExpression, fractionalNegative), columnSymbol, Domain.all(columnType));
    }
}
Also used : CharType.createCharType(com.facebook.presto.common.type.CharType.createCharType) DecimalType(com.facebook.presto.common.type.DecimalType) CastType(com.facebook.presto.metadata.CastType) Type(com.facebook.presto.common.type.Type) OperatorType(com.facebook.presto.common.function.OperatorType) DecimalType.createDecimalType(com.facebook.presto.common.type.DecimalType.createDecimalType) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) LiteralEncoder.toRowExpression(com.facebook.presto.sql.planner.LiteralEncoder.toRowExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression)

Example 59 with VariableReferenceExpression

use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.

the class TestRowExpressionDomainTranslator method testSimpleComparison.

private void testSimpleComparison(RowExpression expression, VariableReferenceExpression input, Domain domain) {
    ExtractionResult result = fromPredicate(expression);
    assertEquals(result.getRemainingExpression(), TRUE_CONSTANT);
    TupleDomain<VariableReferenceExpression> actual = result.getTupleDomain();
    TupleDomain<VariableReferenceExpression> expected = withColumnDomains(ImmutableMap.of(input, domain));
    if (!actual.equals(expected)) {
        fail(format("for comparison [%s] expected %s but found %s", expression.toString(), expected.toString(SESSION.getSqlFunctionProperties()), actual.toString(SESSION.getSqlFunctionProperties())));
    }
}
Also used : VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) ExtractionResult(com.facebook.presto.spi.relation.DomainTranslator.ExtractionResult)

Example 60 with VariableReferenceExpression

use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.

the class TestRowExpressionDomainTranslator method testNoneRoundTrip.

@Test
public void testNoneRoundTrip() {
    TupleDomain<VariableReferenceExpression> tupleDomain = TupleDomain.none();
    ExtractionResult result = fromPredicate(toPredicate(tupleDomain));
    assertEquals(result.getRemainingExpression(), TRUE_CONSTANT);
    assertEquals(result.getTupleDomain(), tupleDomain);
}
Also used : VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) ExtractionResult(com.facebook.presto.spi.relation.DomainTranslator.ExtractionResult) Test(org.testng.annotations.Test)

Aggregations

VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)340 Test (org.testng.annotations.Test)129 ImmutableList (com.google.common.collect.ImmutableList)109 RowExpression (com.facebook.presto.spi.relation.RowExpression)93 ImmutableMap (com.google.common.collect.ImmutableMap)89 PlanNode (com.facebook.presto.spi.plan.PlanNode)85 Optional (java.util.Optional)84 Map (java.util.Map)73 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)61 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)58 List (java.util.List)58 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)52 CallExpression (com.facebook.presto.spi.relation.CallExpression)49 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)48 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)45 Expression (com.facebook.presto.sql.tree.Expression)44 Assignments (com.facebook.presto.spi.plan.Assignments)42 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)42 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)42 ColumnHandle (com.facebook.presto.spi.ColumnHandle)40