【发布时间】:2017-08-30 15:59:47
【问题描述】:
我正在尝试基于云数据流管道中的自定义对象来实现 Groupby 键。
public static void main(String[] args) {
Pipeline pipeline = Pipeline.create(PipelineOptionsFactory.create());
List<KV<Student,StudentValues>> studentList = new ArrayList<>();
studentList.add(KV.of(new Student("pawan", 10,"govt"),
new StudentValues("V1", 123,"govt")));
studentList.add(KV.of(new Student("pawan", 13223,"word"),
new StudentValues("V2", 456,"govt")));
PCollection<KV<Student,StudentValues>> pc =
pipeline.apply(Create.of(studentList));
PCollection<KV<Student, Iterable<StudentValues>>> groupedWords =
pc.apply(GroupByKey.<Student,StudentValues>create());
}
我只是想根据 Student 对象对 PCollection 记录进行分组。
@DefaultCoder(AvroCoder.class)
static class Student /*implements Serializable*/{
public Student(){}
public Student(String n, Integer i, String sc){
name = n;
id = i;
school = sc;
}
public String name;
public Integer id;
public String school;
@Override
public boolean equals(Object obj) {
System.out.println("obj = "+obj);
System.out.println("this = "+this);
Student stObj= (Student)obj;
if (stObj.Name== this.Name){
return true;
} else{
return false;
}
}
}
我已经覆盖了我的自定义类的 equals 方法,但是每次我得到相同的 Student 对象实例来比较 equals 方法。 理想情况下,它应该将第一个学生密钥与第二个学生密钥进行比较。
我在这里做错了什么。
【问题讨论】:
标签: google-cloud-dataflow google-cloud-dataproc