在 Spring Boot 应用程序中分页来自 Cassandra 的 SELECT 查询结果 [英] Paging SELECT query results from Cassandra in Spring Boot application

查看:63
本文介绍了在 Spring Boot 应用程序中分页来自 Cassandra 的 SELECT 查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的研究中,我遇到了 Spring-Data-Cassandra 的 JIRA:https://jira.spring.io/browse/DATACASS-56

During my research I have come across this JIRA for Spring-Data-Cassandra: https://jira.spring.io/browse/DATACASS-56

现在,根据上面的帖子,由于 Cassandra 的结构,目前 SDC 不支持 Spring App 中的 Pagination.但是,我在想,如果我可以将整个行列表拉入 Java 列表,我可以对该列表进行分页吗?我在 Spring 方面没有太多经验,但是当我认为可以做到这一点时,我是否遗漏了什么?

Now, according to the post above, currently SDC is not supporting Pagination in the Spring App due to structure of Cassandra. However, I'm thinking, if I can pull the entire rows list into a Java List, can I Paginate that list ? I don't have much experience in Spring, but is there something I am missing when I assume this can be done ?

推荐答案

Cassandra 不支持指向特定页面(限制/偏移)的意义上的分页,但会生成继续标记(PagingState) 那是一组 byte .拉取记录的 List 会将所有记录加载到内存中,并可能耗尽您的内存(取决于数据量).

Cassandra does not support pagination in the sense of pointing to a specific page (limit/offset) but generates a continuation token (PagingState) that is a set of bytes. Pulling a List of records will load all records in memory and possibly exhaust your memory (depending on the amount of data).

Spring Data Cassandra 1.5.0 RC1 带有 流式 APICassandraTemplate:

Spring Data Cassandra 1.5.0 RC1 comes with a streaming API in CassandraTemplate:

Iterator<Person> it = template.stream("SELECT * FROM person WHERE … ;", Person.class);

while(it.hasNext()) {
   // …
}

CassandraTemplate.stream(...) 将返回一个 Iterator 操作底层 ResultSet.DataStax 驱动程序使用可配置的提取大小(默认为 5000 行)进行批量提取.流式数据访问可以获取处理数据所需的尽可能多或尽可能少的数据.驱动程序和 Spring Data Cassandra 都不会保留数据,一旦从 Iterator 中检索到获取的批量,底层 ResultSet 将自行获取下一个批量.

CassandraTemplate.stream(…) will return an Iterator that operates on an underlying ResultSet. The DataStax driver uses a configurable fetch-size (5000 rows by default) for bulk fetching. Streaming data access can fetch as much or as little data as you require to process data. Data is not retained by the driver nor Spring Data Cassandra, and once the fetched bulk is retrieved from the Iterator, the underlying ResultSet will fetch the next bulk itself.

另一种选择是直接使用 ResultSet,它让您可以访问 PagingState 并自己完成所有的延续/分页业务.您将失去 Spring Data Cassandra 的所有更高级别的好处.

The other alternative is using ResultSet directly that gives you access to PagingState and do all the continuation/paging business yourself. You would lose all the higher level benefits of Spring Data Cassandra.

这篇关于在 Spring Boot 应用程序中分页来自 Cassandra 的 SELECT 查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆