问题描述
我在PCollection中有一个car对象的列表。
PCollection<List<Car>>
每辆车都有颜色。
我想对这个列表进行排序,其中颜色是关键,而具有该颜色的汽车是值,并以KV<String,List<Car>>
{“红色”:[car1,car2],“绿色”:[car3,car4]}
Car car1 = new Car();
Car car2 = new Car();
Car car3 = new Car();
Car car4 = new Car();
car1.setColor("red");
car2.setColor("red");
car3.setColor("green");
car4.setColor("green");
final List<Cars> cars = Arrays.asList(car1,car2,car3,car4);
PCollection<Car> carsCollection = pipeline.apply(Create.of(cars));
PCollection<KV<String,List<Car>>> sortedCars = carsCollection.apply(...)
也许是这样的作品
PCollection<KV<String,List<Car>>> sortedCars =
cars.apply(WithKeys.of(new SimpleFunction<String,List<Car>>() {
@Override
public String apply(Car car) {
return cat.getColor();
}
}));
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)