2016-06-27 22 views
1

我有一個cql,我需要執行並使用node.js driver將結果串流化。但是,如果滿足某些條件,我需要中止流式傳輸。'abort'讀取cassandra結果

像這樣:

   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); 
       }); 

數據不能與過濾邏輯預處理和在卡桑德拉持續存在。它需要在運行時進行計算,並基於一些在數據持久存在時不知道的標準。

有沒有一種方法可以通過node.js驅動程序或cassandra正常實現這一點?

回答

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/

+0

這工作得很好,以純CQL查詢。但是,如果CQL在where子句中帶有'solr_query',那麼分頁不會發生。這是node.js驅動程序/ DSE Cassandra的已知限制嗎? – raks81