【问题标题】:'Abort' reading of cassandra results“中止”读取 cassandra 结果
【发布时间】:2016-06-28 18:09:36
【问题描述】:

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

类似这样的:

                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 优雅地实现这一点?

【问题讨论】:

    标签: node.js cassandra datastax-enterprise


    【解决方案1】:

    您应该改用manual paging

    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/

    【讨论】:

    • 这适用于纯 CQL 查询。但是,如果 CQL 在 where 子句中带有 solr_query,则不会发生分页。这是 node.js 驱动程序/DSE Cassandra 的已知限制吗?
    猜你喜欢
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-11
    • 2015-08-08
    • 2011-12-10
    • 2015-10-19
    相关资源
    最近更新 更多