简体   繁体   中英

multiget in sorted order using phpcassa

I have a keyspace in cassandra with columnfamily(let A) which is having composite key another column family(let B) i am storing an exact number of rows which exist in the A column family. when i am fetching the data using multiget it's not giving the actual sorted data.

A: [1] = 13;

B:
   [6014:2:0] = "aaaaaa";
   [6014:2:1] = "bbbbbb";
   [6014:2:2] = "cccccc";
   [6014:2:3] = "dddddd";
   [6014:2:4] = "eeeeee";
   [6014:2:5] = "ffffff";
   [6014:2:6] = "gggggg";
   [6014:2:7] = "hhhhhh";
   [6014:2:8] = "iiiiii";
   [6014:2:9] = "jjjjjj";
   [6014:2:10] = "kkkkkkk";
   [6014:2:11] = "lllllll";
   [6014:2:12] = "mmmmmmm";

my code

require_once(__DIR__.'/phpcassa/lib/autoload.php');
use phpcassa\Connection\ConnectionPool;
use phpcassa\ColumnFamily;
use phpcassa\SystemManager;
use phpcassa\Schema\StrategyClass;

$connection = new ConnectionPool('KEYSPACE', array('XXXX', 'YYYY', 'ZZZZ'));
$numDtls = new ColumnFamily($connection, 'A');
$key = 1;
$num_details = $numDtls->get($key);
$num = $num_details;

$json = '';
$key_array = array();
if(isset($num)){
    $str = new ColumnFamily($connection, 'B');
    for($i = 0;$i <= $num; $i++){
        $key_array[] = array($table, $flag, $i);
    }

    $detail = $str->multiget($key_array);
    $json = json_encode($detail);
}

its giving the output as

6014:2:0
6014:2:6
6014:2:9
6014:2:11
6014:2:4
6014:2:1
6014:2:12
6014:2:8
6014:2:7
6014:2:10
6014:2:3
6014:2:5
6014:2:2

it giving output in jumbled order... How to get in sorted manner? And how to get more than 100 rows?

Multiget makes no ordering guarantees, full stop. As to how to get more than 100 rows... you're asking the wrong question, large multigets are an antipattern. You need to denormalize so you can get the data you want with a single slice, instead. Check out my "timeline" example here: http://www.datastax.com/dev/blog/schema-in-cassandra-1-1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM