});
mapPartitionData.print();
## 2、Filter与Distinct
//获取运行环境
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
ArrayList data = new ArrayList();
data.add(“I love Beijing”);
data.add(“I love China”);
data.add(“Beijing is the capital of China”);
DataSource text = env.fromCollection(data);
DataSet flatMapData = text.flatMap(new FlatMapFunction<String, String>() {
public void flatMap(String data, Collector<String> collection) throws Exception {
String[] words = data.split(" ");
for(String w:words){
collection.collect(w);
}
}
});
//去掉重复的单词
flatMapData.distinct().print();
System.out.println(“*********************”);
//选出长度大于3的单词
flatMapData.filter(new FilterFunction() {
public boolean filter(String word) throws Exception {
int length = word.length();
return length>3?true:false;
}
}).print();
## 3、Join操作
//获取运行的环境
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
//创建第一张表:用户ID 姓名
ArrayList<Tuple2<Integer, String>> data1 = new ArrayList<Tuple2<Integer,String>>();
data1.add(new Tuple2(1,“Tom”));
data1.add(new Tuple2(2,“Mike”));
data1.add(new Tuple2(3,“Mary”));
data1.add(new Tuple2(4,“Jone”));
//创建第二张表:用户ID 所在的城市
ArrayList<Tuple2<Integer, String>> data2 = new ArrayList<Tuple2<Integer,String>>();
data2.add(new Tupl