forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-1290] Fix Optimizer to create plans when encountering incompat…
…ible partitionings.
- Loading branch information
1 parent
a1100af
commit 45fb6d8
Showing
5 changed files
with
270 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
flink-compiler/src/test/java/org/apache/flink/compiler/SortPartialReuseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.compiler; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
import org.apache.flink.api.common.Plan; | ||
import org.apache.flink.api.common.functions.Partitioner; | ||
import org.apache.flink.api.java.DataSet; | ||
import org.apache.flink.api.java.ExecutionEnvironment; | ||
import org.apache.flink.api.java.tuple.Tuple3; | ||
import org.apache.flink.compiler.plan.OptimizedPlan; | ||
import org.apache.flink.compiler.plan.SingleInputPlanNode; | ||
import org.apache.flink.compiler.plan.SinkPlanNode; | ||
import org.apache.flink.compiler.testfunctions.IdentityGroupReducer; | ||
import org.apache.flink.compiler.testfunctions.IdentityMapper; | ||
import org.apache.flink.runtime.operators.shipping.ShipStrategyType; | ||
import org.apache.flink.runtime.operators.util.LocalStrategy; | ||
|
||
@SuppressWarnings("serial") | ||
public class SortPartialReuseTest extends CompilerTestBase { | ||
|
||
@Test | ||
public void testPartialPartitioningReuse() { | ||
try { | ||
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); | ||
|
||
@SuppressWarnings("unchecked") | ||
DataSet<Tuple3<Long, Long, Long>> input = env.fromElements(new Tuple3<Long, Long, Long>(0L, 0L, 0L)); | ||
|
||
input | ||
.partitionByHash(0) | ||
.map(new IdentityMapper<Tuple3<Long,Long,Long>>()).withConstantSet("0", "1", "2") | ||
|
||
.groupBy(0, 1) | ||
.reduceGroup(new IdentityGroupReducer<Tuple3<Long,Long,Long>>()).withConstantSet("0", "1", "2") | ||
|
||
.groupBy(0) | ||
.reduceGroup(new IdentityGroupReducer<Tuple3<Long,Long,Long>>()) | ||
|
||
.print(); | ||
|
||
Plan p = env.createProgramPlan(); | ||
OptimizedPlan op = compileNoStats(p); | ||
|
||
SinkPlanNode sink = op.getDataSinks().iterator().next(); | ||
SingleInputPlanNode reducer2 = (SingleInputPlanNode) sink.getInput().getSource(); | ||
SingleInputPlanNode reducer1 = (SingleInputPlanNode) reducer2.getInput().getSource(); | ||
|
||
assertEquals(ShipStrategyType.FORWARD, sink.getInput().getShipStrategy()); | ||
|
||
// should be locally forwarding, reusing sort and partitioning | ||
assertEquals(ShipStrategyType.FORWARD, reducer2.getInput().getShipStrategy()); | ||
assertEquals(LocalStrategy.NONE, reducer2.getInput().getLocalStrategy()); | ||
|
||
assertEquals(ShipStrategyType.FORWARD, reducer1.getInput().getShipStrategy()); | ||
assertEquals(LocalStrategy.COMBININGSORT, reducer1.getInput().getLocalStrategy()); | ||
} | ||
catch (Exception e) { | ||
e.printStackTrace(); | ||
fail(e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCustomPartitioningNotReused() { | ||
try { | ||
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); | ||
|
||
@SuppressWarnings("unchecked") | ||
DataSet<Tuple3<Long, Long, Long>> input = env.fromElements(new Tuple3<Long, Long, Long>(0L, 0L, 0L)); | ||
|
||
input | ||
.partitionCustom(new Partitioner<Long>() { | ||
@Override | ||
public int partition(Long key, int numPartitions) { return 0; } | ||
}, 0) | ||
.map(new IdentityMapper<Tuple3<Long,Long,Long>>()).withConstantSet("0", "1", "2") | ||
|
||
.groupBy(0, 1) | ||
.reduceGroup(new IdentityGroupReducer<Tuple3<Long,Long,Long>>()).withConstantSet("0", "1", "2") | ||
|
||
.groupBy(1) | ||
.reduceGroup(new IdentityGroupReducer<Tuple3<Long,Long,Long>>()) | ||
|
||
.print(); | ||
|
||
Plan p = env.createProgramPlan(); | ||
OptimizedPlan op = compileNoStats(p); | ||
|
||
SinkPlanNode sink = op.getDataSinks().iterator().next(); | ||
SingleInputPlanNode reducer2 = (SingleInputPlanNode) sink.getInput().getSource(); | ||
SingleInputPlanNode combiner = (SingleInputPlanNode) reducer2.getInput().getSource(); | ||
SingleInputPlanNode reducer1 = (SingleInputPlanNode) combiner.getInput().getSource(); | ||
|
||
assertEquals(ShipStrategyType.FORWARD, sink.getInput().getShipStrategy()); | ||
|
||
// should be locally forwarding, reusing sort and partitioning | ||
assertEquals(ShipStrategyType.PARTITION_HASH, reducer2.getInput().getShipStrategy()); | ||
assertEquals(LocalStrategy.COMBININGSORT, reducer2.getInput().getLocalStrategy()); | ||
|
||
assertEquals(ShipStrategyType.FORWARD, combiner.getInput().getShipStrategy()); | ||
assertEquals(LocalStrategy.NONE, combiner.getInput().getLocalStrategy()); | ||
|
||
assertEquals(ShipStrategyType.FORWARD, reducer1.getInput().getShipStrategy()); | ||
assertEquals(LocalStrategy.COMBININGSORT, reducer1.getInput().getLocalStrategy()); | ||
} | ||
catch (Exception e) { | ||
e.printStackTrace(); | ||
fail(e.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters