“中止”cassandra结果的阅读

我有一个cql,我需要执行和使用node.js驱动程序stream结果。 但是,如果满足某个条件,我需要中止stream式传输。

像这样的东西:

client.eachRow(cql, [], { autoPage: true }, function(n, row) { if(applySomeFilterLogic(row) === 'some val') { //abort streaming } else { rows.push(row); } }, function(err, result) { logger.error("server responded with error : %s", err); }); 

数据不能用过滤逻辑进行预处理,并保留在cassandra中。 它需要在运行时计算,基于一些数据持久化时不知道的标准。

有没有办法通过node.js驱动程序或cassandra来优雅地实现这一点?

您应该使用手动分页来代替:

 const options = { prepare : true }; client.eachRow(query, parameters, options, function (n, row) { // Invoked per each row in all the pages }, function (err, result) { // Called once the page has been fully retrieved. if (yourCondition && result.nextPage) { // Retrieve the following pages based on your condition: // the same row handler from above will be used result.nextPage(); } } ); 

您可以阅读有关驱动程序文档的更多信息: http : //datastax.github.io/nodejs-driver/features/paging/