如何使用 java8 逐个分区地 load/read 来自 cassandra 的数据?

How to load/read data from cassandra by partition by partition using java8?

我正在使用 spring-boot、datastax-java-cassandra-connector_2.11-2.4.1.jar 和 java8。

I have scenario where I need to read/load the data from C* table, but this table might have million of records.

I need to load this data from C* table, is there anyway in java/spring-boot using datastax-java-cassandra-connector API I can pull the data partition by partition?

虽然 select * from table 可能有效,但更有效的方法可能是使用 select * from table where token(part_key) > beginRange and token(part_key) <= endRange 等查询按标记范围读取数据。 Spark Cassandra 连接器的工作方式相同——它获取所有可用令牌范围的列表,然后从每个令牌范围中获取数据,但将其直接发送到持有该令牌范围的节点(与 select * from table 相反通过协调器节点检索所有数据)。

您在计算令牌边界时需要小心,尤其是整个范围的开始和结束。你可以找一个example of the Java code in my repository(太长了贴在这里)。