Search in sources :

Example 16 with EquiJoinClause

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

the class TestPushLimitThroughOuterJoin method testLimitWithPreSortedInputsLeftJoin.

@Test
public void testLimitWithPreSortedInputsLeftJoin() {
    tester().assertThat(new PushLimitThroughOuterJoin()).on(p -> {
        Symbol leftKey = p.symbol("leftKey");
        Symbol rightKey = p.symbol("rightKey");
        return p.limit(1, false, ImmutableList.of(rightKey), p.join(LEFT, p.values(5, leftKey), p.values(5, rightKey), new EquiJoinClause(leftKey, rightKey)));
    }).doesNotFire();
    tester().assertThat(new PushLimitThroughOuterJoin()).on(p -> {
        Symbol leftKey = p.symbol("leftKey");
        Symbol rightKey = p.symbol("rightKey");
        return p.limit(1, false, ImmutableList.of(leftKey), p.join(LEFT, p.values(5, leftKey), p.values(5, rightKey), new EquiJoinClause(leftKey, rightKey)));
    }).matches(limit(1, ImmutableList.of(), false, ImmutableList.of("leftKey"), join(LEFT, ImmutableList.of(equiJoinClause("leftKey", "rightKey")), limit(1, ImmutableList.of(), true, ImmutableList.of("leftKey"), values("leftKey")), values("rightKey"))));
}
Also used : Symbol(io.trino.sql.planner.Symbol) PlanMatchPattern.limit(io.trino.sql.planner.assertions.PlanMatchPattern.limit) LEFT(io.trino.sql.planner.plan.JoinNode.Type.LEFT) ImmutableList(com.google.common.collect.ImmutableList) RIGHT(io.trino.sql.planner.plan.JoinNode.Type.RIGHT) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) EquiJoinClause(io.trino.sql.planner.plan.JoinNode.EquiJoinClause) FULL(io.trino.sql.planner.plan.JoinNode.Type.FULL) PlanMatchPattern.equiJoinClause(io.trino.sql.planner.assertions.PlanMatchPattern.equiJoinClause) Test(org.testng.annotations.Test) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) PlanMatchPattern.join(io.trino.sql.planner.assertions.PlanMatchPattern.join) Symbol(io.trino.sql.planner.Symbol) EquiJoinClause(io.trino.sql.planner.plan.JoinNode.EquiJoinClause) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Example 17 with EquiJoinClause

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

the class TestPushAggregationThroughOuterJoin method testDoesNotFireWhenAggregationOnMultipleSymbolsDoesNotHaveSomeSymbols.

@Test
public void testDoesNotFireWhenAggregationOnMultipleSymbolsDoesNotHaveSomeSymbols() {
    tester().assertThat(new PushAggregationThroughOuterJoin()).on(p -> p.aggregation(ab -> ab.source(p.join(LEFT, p.values(ImmutableList.of(p.symbol("COL1")), ImmutableList.of(expressions("10"))), p.values(ImmutableList.of(p.symbol("COL2"), p.symbol("COL3")), ImmutableList.of(expressions("20", "30"))), ImmutableList.of(new EquiJoinClause(new Symbol("COL1"), new Symbol("COL2"))), ImmutableList.of(new Symbol("COL1")), ImmutableList.of(new Symbol("COL2")), Optional.empty(), Optional.empty(), Optional.empty())).addAggregation(new Symbol("MIN_BY"), PlanBuilder.expression("min_by(COL2, COL1)"), ImmutableList.of(DOUBLE, DOUBLE)).singleGroupingSet(new Symbol("COL1")))).doesNotFire();
    tester().assertThat(new PushAggregationThroughOuterJoin()).on(p -> p.aggregation(ab -> ab.source(p.join(LEFT, p.values(ImmutableList.of(p.symbol("COL1")), ImmutableList.of(expressions("10"))), p.values(ImmutableList.of(p.symbol("COL2"), p.symbol("COL3")), ImmutableList.of(expressions("20", "30"))), ImmutableList.of(new EquiJoinClause(new Symbol("COL1"), new Symbol("COL2"))), ImmutableList.of(new Symbol("COL1")), ImmutableList.of(new Symbol("COL2")), Optional.empty(), Optional.empty(), Optional.empty())).addAggregation(new Symbol("SUM"), PlanBuilder.expression("sum(COL2)"), ImmutableList.of(DOUBLE)).addAggregation(new Symbol("MIN_BY"), PlanBuilder.expression("min_by(COL2, COL3)"), ImmutableList.of(DOUBLE, DOUBLE)).addAggregation(new Symbol("MAX_BY"), PlanBuilder.expression("max_by(COL2, COL1)"), ImmutableList.of(DOUBLE, DOUBLE)).singleGroupingSet(new Symbol("COL1")))).doesNotFire();
}
Also used : PlanMatchPattern.aggregation(io.trino.sql.planner.assertions.PlanMatchPattern.aggregation) INNER(io.trino.sql.planner.plan.JoinNode.Type.INNER) SINGLE(io.trino.sql.planner.plan.AggregationNode.Step.SINGLE) Test(org.testng.annotations.Test) LEFT(io.trino.sql.planner.plan.JoinNode.Type.LEFT) PlanBuilder.expressions(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expressions) ImmutableList(com.google.common.collect.ImmutableList) EquiJoinClause(io.trino.sql.planner.plan.JoinNode.EquiJoinClause) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) PlanMatchPattern.equiJoinClause(io.trino.sql.planner.assertions.PlanMatchPattern.equiJoinClause) PlanMatchPattern.join(io.trino.sql.planner.assertions.PlanMatchPattern.join) Symbol(io.trino.sql.planner.Symbol) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Assignments(io.trino.sql.planner.plan.Assignments) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) PlanMatchPattern.globalAggregation(io.trino.sql.planner.assertions.PlanMatchPattern.globalAggregation) PlanMatchPattern.singleGroupingSet(io.trino.sql.planner.assertions.PlanMatchPattern.singleGroupingSet) PlanMatchPattern.functionCall(io.trino.sql.planner.assertions.PlanMatchPattern.functionCall) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) AggregationNode.groupingSets(io.trino.sql.planner.plan.AggregationNode.groupingSets) BIGINT(io.trino.spi.type.BigintType.BIGINT) PlanMatchPattern.project(io.trino.sql.planner.assertions.PlanMatchPattern.project) RIGHT(io.trino.sql.planner.plan.JoinNode.Type.RIGHT) Optional(java.util.Optional) EquiJoinClause(io.trino.sql.planner.plan.JoinNode.EquiJoinClause) Symbol(io.trino.sql.planner.Symbol) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 18 with EquiJoinClause

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

the class TestPushAggregationThroughOuterJoin method testDoesNotFireWhenNotDistinct.

@Test
public void testDoesNotFireWhenNotDistinct() {
    tester().assertThat(new PushAggregationThroughOuterJoin()).on(p -> p.aggregation(ab -> ab.source(p.join(LEFT, p.values(ImmutableList.of(p.symbol("COL1")), ImmutableList.of(expressions("10"), expressions("11"))), p.values(new Symbol("COL2")), ImmutableList.of(new EquiJoinClause(new Symbol("COL1"), new Symbol("COL2"))), ImmutableList.of(p.symbol("COL1")), ImmutableList.of(p.symbol("COL2")), Optional.empty(), Optional.empty(), Optional.empty())).addAggregation(new Symbol("AVG"), PlanBuilder.expression("avg(COL2)"), ImmutableList.of(DOUBLE)).singleGroupingSet(new Symbol("COL1")))).doesNotFire();
    // https://github.com/prestodb/presto/issues/10592
    tester().assertThat(new PushAggregationThroughOuterJoin()).on(p -> p.aggregation(ab -> ab.source(p.join(LEFT, p.project(Assignments.builder().putIdentity(p.symbol("COL1", BIGINT)).build(), p.aggregation(builder -> builder.singleGroupingSet(p.symbol("COL1"), p.symbol("unused")).source(p.values(ImmutableList.of(p.symbol("COL1"), p.symbol("unused")), ImmutableList.of(expressions("10", "1"), expressions("10", "2")))))), p.values(p.symbol("COL2")), ImmutableList.of(new EquiJoinClause(p.symbol("COL1"), p.symbol("COL2"))), ImmutableList.of(p.symbol("COL1")), ImmutableList.of(p.symbol("COL2")), Optional.empty(), Optional.empty(), Optional.empty())).addAggregation(p.symbol("AVG", DOUBLE), PlanBuilder.expression("avg(COL2)"), ImmutableList.of(DOUBLE)).singleGroupingSet(p.symbol("COL1")))).doesNotFire();
}
Also used : PlanMatchPattern.aggregation(io.trino.sql.planner.assertions.PlanMatchPattern.aggregation) INNER(io.trino.sql.planner.plan.JoinNode.Type.INNER) SINGLE(io.trino.sql.planner.plan.AggregationNode.Step.SINGLE) Test(org.testng.annotations.Test) LEFT(io.trino.sql.planner.plan.JoinNode.Type.LEFT) PlanBuilder.expressions(io.trino.sql.planner.iterative.rule.test.PlanBuilder.expressions) ImmutableList(com.google.common.collect.ImmutableList) EquiJoinClause(io.trino.sql.planner.plan.JoinNode.EquiJoinClause) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) PlanMatchPattern.equiJoinClause(io.trino.sql.planner.assertions.PlanMatchPattern.equiJoinClause) PlanMatchPattern.join(io.trino.sql.planner.assertions.PlanMatchPattern.join) Symbol(io.trino.sql.planner.Symbol) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Assignments(io.trino.sql.planner.plan.Assignments) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) PlanMatchPattern.globalAggregation(io.trino.sql.planner.assertions.PlanMatchPattern.globalAggregation) PlanMatchPattern.singleGroupingSet(io.trino.sql.planner.assertions.PlanMatchPattern.singleGroupingSet) PlanMatchPattern.functionCall(io.trino.sql.planner.assertions.PlanMatchPattern.functionCall) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) AggregationNode.groupingSets(io.trino.sql.planner.plan.AggregationNode.groupingSets) BIGINT(io.trino.spi.type.BigintType.BIGINT) PlanMatchPattern.project(io.trino.sql.planner.assertions.PlanMatchPattern.project) RIGHT(io.trino.sql.planner.plan.JoinNode.Type.RIGHT) Optional(java.util.Optional) Symbol(io.trino.sql.planner.Symbol) EquiJoinClause(io.trino.sql.planner.plan.JoinNode.EquiJoinClause) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Aggregations

EquiJoinClause (io.trino.sql.planner.plan.JoinNode.EquiJoinClause)18 Symbol (io.trino.sql.planner.Symbol)15 Test (org.testng.annotations.Test)15 ImmutableList (com.google.common.collect.ImmutableList)11 Optional (java.util.Optional)10 ImmutableMap (com.google.common.collect.ImmutableMap)9 PlanMatchPattern.values (io.trino.sql.planner.assertions.PlanMatchPattern.values)9 INNER (io.trino.sql.planner.plan.JoinNode.Type.INNER)9 PlanMatchPattern.equiJoinClause (io.trino.sql.planner.assertions.PlanMatchPattern.equiJoinClause)8 PlanMatchPattern.join (io.trino.sql.planner.assertions.PlanMatchPattern.join)8 Assignments (io.trino.sql.planner.plan.Assignments)7 Type (io.trino.spi.type.Type)6 SymbolStatsEstimate (io.trino.cost.SymbolStatsEstimate)5 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)5 JoinDistributionType (io.trino.sql.planner.OptimizerConfig.JoinDistributionType)5 PLANNER_CONTEXT (io.trino.sql.planner.TestingPlannerContext.PLANNER_CONTEXT)5 TypeAnalyzer.createTestingTypeAnalyzer (io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer)5 PlanMatchPattern.expression (io.trino.sql.planner.assertions.PlanMatchPattern.expression)5 LEFT (io.trino.sql.planner.plan.JoinNode.Type.LEFT)5 RIGHT (io.trino.sql.planner.plan.JoinNode.Type.RIGHT)5