简体   繁体   中英

How to get all column names of a row in cassandra using phpcassa?

I want to get all column names of a row in cassandra , how can I do it in phpcassa?

If phpcassa does not support it, does any other language, libs can do it?

In my case, column names are short, but rows are long(around 1000+),data are big(around 100K)

You have a good question. Try something like that:

$pool = new ConnectionPool('feed', array('127.0.0.1'));
$raw = $pool->get();
$rows = $raw->client->execute_cql_query("SELECT * FROM posts", cassandra_Compression::NONE);
var_dump($rows);

Maybe it will help...

Do you mean to get the names directly and only with phpCassa? I don't know any way to do it directly but I used to do that by getting all the row and then executing a foreach loop over the array I have from the column family, like this:

1.- A small function to use everywhere (build your own if you need ;) ):

function f_get_data_as_array($p_pool, $p_cf, $p_key, $p_col_count = 100, $p_column_names = NULL, $p_range_start = '', $p_range_end = '', $p_inverted_sort = false)
{
    try{
        $lv_slice = new ColumnSlice($p_range_start, $p_range_end, $p_col_count, p_inverted_sort);
        $lv_cf =    new ColumnFamily($p_pool, $p_cf);
        $lv_cf->insert_format = ColumnFamily::ARRAY_FORMAT;
        $lv_cf->return_format = ColumnFamily::ARRAY_FORMAT;         
        $lv_result = $lv_cf->get($p_key, $lv_slice, $p_column_names);
    }catch(Exception $lv_e)
    {
        return false;   
    }
    return $lv_result;

2.- I call it using the first four parameters, setting the pool, the column family name, the key I need and the number of columns I want to get (set the number as you need).

3.- A foreach loop over the returned array to get each column name. Or, if you know the structure you will get from your column family, you just need to use the right indexes, probably: $lv_result[0][0], $lv_result[0][1], and so...

Hope it helps. And sorry for my English!

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