Java - Converting Cassandra ResultSet to Java 8 Stream
1
2
3
4
5
6
7
8
Statement stmt = QueryBuilder().select().all().from('table');
ResultSet rs = session.execute(stmt);
StreamSupport.stream(
Spliterators.spliteratorUnknownSize(
rs.iterator(), Spliterator.ORDERED), false)
.forEach(row -> {
...
});
As input stream is sorted by partition key and input order is important, the following example can be used.
1
2
3
4
5
6
7
8
Statement stmt = QueryBuilder().select().all().from('table');
ResultSet rs = session.execute(stmt);
StreamSupport.stream(
Spliterators.spliteratorUnknownSize(
rs.iterator(), Spliterator.ORDERED | Spliterator.SORTED), false)
.forEach(row -> {
...
});