Search in sources :

Example 11 with JoinNode

use of io.trino.sql.planner.plan.JoinNode in project trino by trinodb.

the class TestLocalDynamicFilterConsumer method testDynamicFilterPruning.

@Test
public void testDynamicFilterPruning() throws Exception {
    PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata(), getQueryRunner().getDefaultSession());
    Symbol left1 = planBuilder.symbol("left1", BIGINT);
    Symbol left2 = planBuilder.symbol("left2", INTEGER);
    Symbol left3 = planBuilder.symbol("left3", SMALLINT);
    Symbol right1 = planBuilder.symbol("right1", BIGINT);
    Symbol right2 = planBuilder.symbol("right2", INTEGER);
    Symbol right3 = planBuilder.symbol("right3", SMALLINT);
    DynamicFilterId filter1 = new DynamicFilterId("filter1");
    DynamicFilterId filter2 = new DynamicFilterId("filter2");
    DynamicFilterId filter3 = new DynamicFilterId("filter3");
    JoinNode joinNode = planBuilder.join(INNER, planBuilder.values(left1, left2, left3), planBuilder.values(right1, right2, right3), ImmutableList.of(new EquiJoinClause(left1, right1), new EquiJoinClause(left2, right2), new EquiJoinClause(left3, right3)), ImmutableList.of(), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(filter1, right1, filter2, right2, filter3, right3));
    LocalDynamicFilterConsumer consumer = LocalDynamicFilterConsumer.create(joinNode, ImmutableList.of(BIGINT, INTEGER, SMALLINT), 1, ImmutableSet.of(filter1, filter3));
    assertEquals(consumer.getBuildChannels(), ImmutableMap.of(filter1, 0, filter3, 2));
    // make sure domain types got propagated correctly
    consumer.getTupleDomainConsumer().accept(TupleDomain.none());
    assertEquals(consumer.getDynamicFilterDomains().get(), ImmutableMap.of(filter1, Domain.none(BIGINT), filter3, Domain.none(SMALLINT)));
}
Also used : JoinNode(io.trino.sql.planner.plan.JoinNode) EquiJoinClause(io.trino.sql.planner.plan.JoinNode.EquiJoinClause) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Example 12 with JoinNode

use of io.trino.sql.planner.plan.JoinNode in project trino by trinodb.

the class TestEffectivePredicateExtractor method testInnerJoin.

@Test
public void testInnerJoin() {
    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 = tableScanNode(leftAssignments);
    Map<Symbol, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(D, E, F)));
    TableScanNode rightScan = tableScanNode(rightAssignments);
    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.INNER, left, right, criteria, left.getOutputSymbols(), right.getOutputSymbols(), false, Optional.of(lessThanOrEqual(BE, EE)), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(), Optional.empty());
    Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    // All predicates having output symbol should be carried through
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(BE, AE), lessThan(CE, bigintLiteral(10)), equals(DE, EE), lessThan(FE, bigintLiteral(100)), equals(AE, DE), equals(BE, EE), lessThanOrEqual(BE, EE)));
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) TestingColumnHandle(io.trino.testing.TestingMetadata.TestingColumnHandle) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) SemiJoinNode(io.trino.sql.planner.plan.SemiJoinNode) JoinNode(io.trino.sql.planner.plan.JoinNode) FilterNode(io.trino.sql.planner.plan.FilterNode) PlanNode(io.trino.sql.planner.plan.PlanNode) TableScanNode(io.trino.sql.planner.plan.TableScanNode) InListExpression(io.trino.sql.tree.InListExpression) NotExpression(io.trino.sql.tree.NotExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) Expression(io.trino.sql.tree.Expression) Test(org.testng.annotations.Test)

Example 13 with JoinNode

use of io.trino.sql.planner.plan.JoinNode in project trino by trinodb.

the class TestEffectivePredicateExtractor method testInnerJoinWithFalseFilter.

@Test
public void testInnerJoinWithFalseFilter() {
    Map<Symbol, ColumnHandle> leftAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(A, B, C)));
    TableScanNode leftScan = tableScanNode(leftAssignments);
    Map<Symbol, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(D, E, F)));
    TableScanNode rightScan = tableScanNode(rightAssignments);
    PlanNode node = new JoinNode(newId(), JoinNode.Type.INNER, leftScan, rightScan, ImmutableList.of(new JoinNode.EquiJoinClause(A, D)), leftScan.getOutputSymbols(), rightScan.getOutputSymbols(), false, Optional.of(FALSE_LITERAL), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(), Optional.empty());
    Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    assertEquals(effectivePredicate, FALSE_LITERAL);
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) TestingColumnHandle(io.trino.testing.TestingMetadata.TestingColumnHandle) PlanNode(io.trino.sql.planner.plan.PlanNode) TableScanNode(io.trino.sql.planner.plan.TableScanNode) InListExpression(io.trino.sql.tree.InListExpression) NotExpression(io.trino.sql.tree.NotExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) Expression(io.trino.sql.tree.Expression) SemiJoinNode(io.trino.sql.planner.plan.SemiJoinNode) JoinNode(io.trino.sql.planner.plan.JoinNode) Test(org.testng.annotations.Test)

Example 14 with JoinNode

use of io.trino.sql.planner.plan.JoinNode in project trino by trinodb.

the class TestEffectivePredicateExtractor method testRightJoin.

@Test
public void testRightJoin() {
    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 = tableScanNode(leftAssignments);
    Map<Symbol, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(D, E, F)));
    TableScanNode rightScan = tableScanNode(rightAssignments);
    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.RIGHT, left, right, criteria, left.getOutputSymbols(), right.getOutputSymbols(), false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(), Optional.empty());
    Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    // All left side symbols should be checked against NULL
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(or(lessThan(BE, AE), and(isNull(BE), isNull(AE))), or(lessThan(CE, bigintLiteral(10)), isNull(CE)), equals(DE, EE), lessThan(FE, bigintLiteral(100)), or(equals(AE, DE), isNull(AE)), or(equals(BE, EE), isNull(BE))));
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) TestingColumnHandle(io.trino.testing.TestingMetadata.TestingColumnHandle) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) SemiJoinNode(io.trino.sql.planner.plan.SemiJoinNode) JoinNode(io.trino.sql.planner.plan.JoinNode) FilterNode(io.trino.sql.planner.plan.FilterNode) PlanNode(io.trino.sql.planner.plan.PlanNode) TableScanNode(io.trino.sql.planner.plan.TableScanNode) InListExpression(io.trino.sql.tree.InListExpression) NotExpression(io.trino.sql.tree.NotExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) Expression(io.trino.sql.tree.Expression) Test(org.testng.annotations.Test)

Example 15 with JoinNode

use of io.trino.sql.planner.plan.JoinNode in project trino by trinodb.

the class TestEffectivePredicateExtractor method testLeftJoin.

@Test
public void testLeftJoin() {
    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 = tableScanNode(leftAssignments);
    Map<Symbol, ColumnHandle> rightAssignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(D, E, F)));
    TableScanNode rightScan = tableScanNode(rightAssignments);
    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, left.getOutputSymbols(), right.getOutputSymbols(), false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(), Optional.empty());
    Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    // 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(io.trino.spi.connector.ColumnHandle) TestingColumnHandle(io.trino.testing.TestingMetadata.TestingColumnHandle) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) SemiJoinNode(io.trino.sql.planner.plan.SemiJoinNode) JoinNode(io.trino.sql.planner.plan.JoinNode) FilterNode(io.trino.sql.planner.plan.FilterNode) PlanNode(io.trino.sql.planner.plan.PlanNode) TableScanNode(io.trino.sql.planner.plan.TableScanNode) InListExpression(io.trino.sql.tree.InListExpression) NotExpression(io.trino.sql.tree.NotExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) Expression(io.trino.sql.tree.Expression) Test(org.testng.annotations.Test)

Aggregations

JoinNode (io.trino.sql.planner.plan.JoinNode)56 Symbol (io.trino.sql.planner.Symbol)35 PlanNode (io.trino.sql.planner.plan.PlanNode)34 Expression (io.trino.sql.tree.Expression)22 Test (org.testng.annotations.Test)22 TableScanNode (io.trino.sql.planner.plan.TableScanNode)17 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)16 FilterNode (io.trino.sql.planner.plan.FilterNode)15 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)15 ImmutableList (com.google.common.collect.ImmutableList)14 ProjectNode (io.trino.sql.planner.plan.ProjectNode)14 Assignments (io.trino.sql.planner.plan.Assignments)13 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)13 ColumnHandle (io.trino.spi.connector.ColumnHandle)10 PlanNodeIdAllocator (io.trino.sql.planner.PlanNodeIdAllocator)10 AggregationNode (io.trino.sql.planner.plan.AggregationNode)10 CorrelatedJoinNode (io.trino.sql.planner.plan.CorrelatedJoinNode)10 NotExpression (io.trino.sql.tree.NotExpression)10 Map (java.util.Map)10 Type (io.trino.spi.type.Type)9