Created
July 14, 2015 17:47
-
-
Save chiwanpark/e71d27cc8edae8bc7298 to your computer and use it in GitHub Desktop.
Flink Custom Partitioner Example
This file contains hidden or 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
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.Tuple2; | |
public class PartitionCustomExample { | |
public static class MyPartitioner implements Partitioner<Integer> { | |
@Override | |
public int partition(Integer key, int numPartitions) { | |
return key % numPartitions; | |
} | |
} | |
public static void main(String[] args) throws Exception { | |
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); | |
DataSet<Tuple2<Integer, String>> data = env.fromElements( | |
new Tuple2<Integer, String>(1, "a"), new Tuple2<Integer, String>(1000, "b"), | |
new Tuple2<Integer, String>(2, "k"), new Tuple2<Integer, String>(1020, "c")); | |
DataSet<Tuple2<Integer, String>> partitionedData = | |
data.partitionCustom(new MyPartitioner(), 0); | |
partitionedData.print(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment