我在cassandra表中有一个set字段,并且我正在创建一个apachesparks数据集,该数据集包含一些其他字段。当我打印数据集的值时,会打印这些值,但是当我将数据集Map到pojo时,设置了type的字段会给出null值,其余字段会给出各自的值。
cassandra中的test\uids字段是set类型,在java中我使用hashset来表示它。如果有人能帮忙,请回答。
Dataset<Row> dsQ = spark1.read().format("org.apache.spark.sql.cassandra").options(props1).load();
dsQ.show();
Dataset<Employee> res = dsQ.as(Encoders.bean(Employee.class));
res.collectAsList().forEach(employee -> {
System.out.println("POJO: " + employee);
});
//POJO Class
@Column("emp_branch")
private String empBranch;
@Column("epoch_hour")
private int epochHour;
@Column("test_ids")
private Set<String> testIds = new HashSet<String>();
public String getEmpBranch() {
return empBranch;
}
public void setEmpBranch(String empBranch) {
this.empBranch = empBranch;
}
public int getEpochHour() {
return epochHour;
}
public void setEpochHour(int epochHour) {
this.epochHour = epochHour;
}
public Set<String> getTestIds() {
return testIds;
}
public void setTestIds(Set<String> testIds) {
this.testIds = testIds;
}
@Override
public String toString() {
return "StackOverflow [empBranch=" + empBranch + ", epochHour=" + epochHour + ", testIds=" + testIds + "]";
}
[实际结果]emp\u branch=cs,epoch\u hour=433064,test\u id=[]
[预期结果]emp\u branch=cs,epoch\u hour=433064,test\u id=['1234']
1条答案
按热度按时间pokxtpni1#
你的员工pojo应该有这样的东西;