问题
I'm using RethinkDB driver for Java. I want to filter the rows without field endedAt
in table jam
like this:
public List<Jam> getCurrent(){
Cursor cursor = r.table("jam")
.filter(row -> row.hasFields("endedAt")).not()
.run(conn);
List<Map<String,Object>> list=cursor.toList();
return list.stream().map(item->JamRepository.toJam(item)).collect(Collectors.toList());
}
And I've got this error Expected type DATUM but found SELECTION Java
I have another filter function in another class:
public List<Speedlog> getByTime(long time){
Cursor cursor = r.table("speedlog")
.filter(row -> row.g("createdAt").eq(time))
.run(conn);
List<Map<String,Object>> list=cursor.toList();
return list.stream().map(item->SpeedlogRepository.toSpeedlog(item)).collect(Collectors.toList());
}
This function works properly
Could anyone please explain what makes the difference between these two? Why does getCurrent
function get that error? What is its meaning and how to fix? Thank you
回答1:
not()
should be right after row.hasFields("endedAt")
. For now you are trying to call not()
on the result of filter
function. So, correct code:
public List<Jam> getCurrent(){
Cursor cursor = r.table("jam")
.filter(row -> row.hasFields("endedAt").not())
.run(conn);
List<Map<String,Object>> list=cursor.toList();
return list.stream().map(item->JamRepository.toJam(item)).collect(Collectors.toList());
}
来源:https://stackoverflow.com/questions/40206697/java-rethinkdb-expected-type-datum-but-found-selection