Search in sources :

Example 16 with Expression

use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.

the class TestEffectivePredicateExtractor method testWindow.

@Test
public void testWindow() throws Exception {
    PlanNode node = new WindowNode(newId(), filter(baseTableScan, and(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), new WindowNode.Specification(ImmutableList.of(A), ImmutableList.of(A), ImmutableMap.of(A, SortOrder.ASC_NULLS_LAST)), ImmutableMap.of(), Optional.empty(), ImmutableSet.of(), 0);
    Expression effectivePredicate = EffectivePredicateExtractor.extract(node, TYPES);
    // Pass through
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10))));
}
Also used : WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) Test(org.testng.annotations.Test)

Example 17 with Expression

use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.

the class TestEffectivePredicateExtractor method testLeftJoin.

@Test
public void testLeftJoin() throws Exception {
    ImmutableList.Builder<JoinNode.EquiJoinClause> criteriaBuilder = ImmutableList.builder();
    criteriaBuilder.add(new JoinNode.EquiJoinClause(A, D));
    criteriaBuilder.add(new JoinNode.EquiJoinClause(B, E));
    List<JoinNode.EquiJoinClause> criteria = criteriaBuilder.build();
    Map<Symbol, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(A, B, C)));
    TableScanNode leftScan = new TableScanNode(newId(), DUAL_TABLE_HANDLE, ImmutableList.copyOf(leftAssignments.keySet()), leftAssignments, Optional.empty(), TupleDomain.all(), null);
    Map<Symbol, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(D, E, F)));
    TableScanNode rightScan = new TableScanNode(newId(), DUAL_TABLE_HANDLE, ImmutableList.copyOf(rightAssignments.keySet()), rightAssignments, Optional.empty(), TupleDomain.all(), null);
    FilterNode left = filter(leftScan, and(lessThan(BE, AE), lessThan(CE, bigintLiteral(10)), equals(GE, bigintLiteral(10))));
    FilterNode right = filter(rightScan, and(equals(DE, EE), lessThan(FE, bigintLiteral(100))));
    PlanNode node = new JoinNode(newId(), JoinNode.Type.LEFT, left, right, criteria, ImmutableList.<Symbol>builder().addAll(left.getOutputSymbols()).addAll(right.getOutputSymbols()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    Expression effectivePredicate = EffectivePredicateExtractor.extract(node, TYPES);
    // All right side symbols having output symbols should be checked against NULL
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(BE, AE), lessThan(CE, bigintLiteral(10)), or(equals(DE, EE), and(isNull(DE), isNull(EE))), or(lessThan(FE, bigintLiteral(100)), isNull(FE)), or(equals(AE, DE), isNull(DE)), or(equals(BE, EE), isNull(EE))));
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableList(com.google.common.collect.ImmutableList) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode) FilterNode(com.facebook.presto.sql.planner.plan.FilterNode) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) TableScanNode(com.facebook.presto.sql.planner.plan.TableScanNode) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) Test(org.testng.annotations.Test)

Example 18 with Expression

use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.

the class TestEffectivePredicateExtractor method testFilter.

@Test
public void testFilter() throws Exception {
    PlanNode node = filter(baseTableScan, and(greaterThan(AE, new FunctionCall(QualifiedName.of("rand"), ImmutableList.of())), lessThan(BE, bigintLiteral(10))));
    Expression effectivePredicate = EffectivePredicateExtractor.extract(node, TYPES);
    // Non-deterministic functions should be purged
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(BE, bigintLiteral(10))));
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 19 with Expression

use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.

the class TestEqualityInference method testTransitivity.

@Test
public void testTransitivity() throws Exception {
    EqualityInference.Builder builder = new EqualityInference.Builder();
    addEquality("a1", "b1", builder);
    addEquality("b1", "c1", builder);
    addEquality("d1", "c1", builder);
    addEquality("a2", "b2", builder);
    addEquality("b2", "a2", builder);
    addEquality("b2", "c2", builder);
    addEquality("d2", "b2", builder);
    addEquality("c2", "d2", builder);
    EqualityInference inference = builder.build();
    assertEquals(inference.rewriteExpression(someExpression("a1", "a2"), matchesSymbols("d1", "d2")), someExpression("d1", "d2"));
    assertEquals(inference.rewriteExpression(someExpression("a1", "c1"), matchesSymbols("b1")), someExpression("b1", "b1"));
    assertEquals(inference.rewriteExpression(someExpression("a1", "a2"), matchesSymbols("b1", "d2", "c3")), someExpression("b1", "d2"));
    // Both starting expressions should canonicalize to the same expression
    assertEquals(inference.getScopedCanonical(nameReference("a2"), matchesSymbols("c2", "d2")), inference.getScopedCanonical(nameReference("b2"), matchesSymbols("c2", "d2")));
    Expression canonical = inference.getScopedCanonical(nameReference("a2"), matchesSymbols("c2", "d2"));
    // Given multiple translatable candidates, should choose the canonical
    assertEquals(inference.rewriteExpression(someExpression("a2", "b2"), matchesSymbols("c2", "d2")), someExpression(canonical, canonical));
}
Also used : InListExpression(com.facebook.presto.sql.tree.InListExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) NullIfExpression(com.facebook.presto.sql.tree.NullIfExpression) SubscriptExpression(com.facebook.presto.sql.tree.SubscriptExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) IfExpression(com.facebook.presto.sql.tree.IfExpression) ArithmeticBinaryExpression(com.facebook.presto.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(com.facebook.presto.sql.tree.SearchedCaseExpression) SimpleCaseExpression(com.facebook.presto.sql.tree.SimpleCaseExpression) Test(org.testng.annotations.Test)

Example 20 with Expression

use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.

the class TestEqualityInference method testTriviallyRewritable.

@Test
public void testTriviallyRewritable() throws Exception {
    EqualityInference.Builder builder = new EqualityInference.Builder();
    Expression expression = builder.build().rewriteExpression(someExpression("a1", "a2"), matchesSymbols("a1", "a2"));
    assertEquals(expression, someExpression("a1", "a2"));
}
Also used : InListExpression(com.facebook.presto.sql.tree.InListExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) NullIfExpression(com.facebook.presto.sql.tree.NullIfExpression) SubscriptExpression(com.facebook.presto.sql.tree.SubscriptExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) IfExpression(com.facebook.presto.sql.tree.IfExpression) ArithmeticBinaryExpression(com.facebook.presto.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(com.facebook.presto.sql.tree.SearchedCaseExpression) SimpleCaseExpression(com.facebook.presto.sql.tree.SimpleCaseExpression) Test(org.testng.annotations.Test)

Aggregations

Expression (com.facebook.presto.sql.tree.Expression)137 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)74 Test (org.testng.annotations.Test)46 NotExpression (com.facebook.presto.sql.tree.NotExpression)42 InListExpression (com.facebook.presto.sql.tree.InListExpression)40 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)33 Type (com.facebook.presto.spi.type.Type)26 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)26 LiteralInterpreter.toExpression (com.facebook.presto.sql.planner.LiteralInterpreter.toExpression)25 LogicalBinaryExpression (com.facebook.presto.sql.tree.LogicalBinaryExpression)22 ImmutableList (com.google.common.collect.ImmutableList)22 LambdaExpression (com.facebook.presto.sql.tree.LambdaExpression)19 ArithmeticBinaryExpression (com.facebook.presto.sql.tree.ArithmeticBinaryExpression)18 Cast (com.facebook.presto.sql.tree.Cast)17 ArrayList (java.util.ArrayList)17 ExtractionResult (com.facebook.presto.sql.planner.DomainTranslator.ExtractionResult)16 CoalesceExpression (com.facebook.presto.sql.tree.CoalesceExpression)16 SubqueryExpression (com.facebook.presto.sql.tree.SubqueryExpression)16 SubscriptExpression (com.facebook.presto.sql.tree.SubscriptExpression)16 QuantifiedComparisonExpression (com.facebook.presto.sql.tree.QuantifiedComparisonExpression)15