Search in sources :

Example 11 with InnerJoinOperatorBase

use of org.apache.flink.api.common.operators.base.InnerJoinOperatorBase in project flink by apache.

the class SemanticPropertiesAPIToPlanTest method forwardFieldsTestJoin.

@Test
public void forwardFieldsTestJoin() {
    ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
    DataSet<Tuple3<Integer, Integer, Integer>> in1 = env.readCsvFile(IN_FILE).types(Integer.class, Integer.class, Integer.class);
    DataSet<Tuple3<Integer, Integer, Integer>> in2 = env.readCsvFile(IN_FILE).types(Integer.class, Integer.class, Integer.class);
    in1 = in1.map(new MockMapper()).withForwardedFields("*").groupBy(0).reduce(new MockReducer()).withForwardedFields("f0->f1");
    in2 = in2.map(new MockMapper()).withForwardedFields("*").groupBy(1).reduce(new MockReducer()).withForwardedFields("f1->f2");
    DataSet<Tuple3<Integer, Integer, Integer>> out = in1.join(in2).where(1).equalTo(2).with(new MockJoin());
    out.output(new DiscardingOutputFormat<Tuple3<Integer, Integer, Integer>>());
    Plan plan = env.createProgramPlan();
    OptimizedPlan oPlan = compileWithStats(plan);
    oPlan.accept(new Visitor<PlanNode>() {

        @Override
        public boolean preVisit(PlanNode visitable) {
            if (visitable instanceof DualInputPlanNode && visitable.getProgramOperator() instanceof InnerJoinOperatorBase) {
                DualInputPlanNode node = ((DualInputPlanNode) visitable);
                final Channel inConn1 = node.getInput1();
                final Channel inConn2 = node.getInput2();
                Assert.assertTrue("Join should just forward the input if it is already partitioned", inConn1.getShipStrategy() == ShipStrategyType.FORWARD);
                Assert.assertTrue("Join should just forward the input if it is already partitioned", inConn2.getShipStrategy() == ShipStrategyType.FORWARD);
                return false;
            }
            return true;
        }

        @Override
        public void postVisit(PlanNode visitable) {
        }
    });
}
Also used : ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Channel(org.apache.flink.optimizer.plan.Channel) Plan(org.apache.flink.api.common.Plan) OptimizedPlan(org.apache.flink.optimizer.plan.OptimizedPlan) OptimizedPlan(org.apache.flink.optimizer.plan.OptimizedPlan) DualInputPlanNode(org.apache.flink.optimizer.plan.DualInputPlanNode) DualInputPlanNode(org.apache.flink.optimizer.plan.DualInputPlanNode) PlanNode(org.apache.flink.optimizer.plan.PlanNode) SingleInputPlanNode(org.apache.flink.optimizer.plan.SingleInputPlanNode) Tuple3(org.apache.flink.api.java.tuple.Tuple3) InnerJoinOperatorBase(org.apache.flink.api.common.operators.base.InnerJoinOperatorBase) Test(org.junit.Test)

Aggregations

InnerJoinOperatorBase (org.apache.flink.api.common.operators.base.InnerJoinOperatorBase)11 Plan (org.apache.flink.api.common.Plan)10 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)10 Test (org.junit.Test)10 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)8 DualInputSemanticProperties (org.apache.flink.api.common.operators.DualInputSemanticProperties)7 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)7 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)2 GenericDataSinkBase (org.apache.flink.api.common.operators.GenericDataSinkBase)2 DeltaIterationBase (org.apache.flink.api.common.operators.base.DeltaIterationBase)2 MapOperatorBase (org.apache.flink.api.common.operators.base.MapOperatorBase)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 LongSumAggregator (org.apache.flink.api.common.aggregators.LongSumAggregator)1 FlatJoinFunction (org.apache.flink.api.common.functions.FlatJoinFunction)1 GenericDataSourceBase (org.apache.flink.api.common.operators.GenericDataSourceBase)1 Operator (org.apache.flink.api.common.operators.Operator)1 Union (org.apache.flink.api.common.operators.Union)1 BulkIterationBase (org.apache.flink.api.common.operators.base.BulkIterationBase)1 CoGroupOperatorBase (org.apache.flink.api.common.operators.base.CoGroupOperatorBase)1