开发者

Cassandra getting back a whole row

I'm trying Cassandra with a very simple example. I have a column family stored in the cassandra database:

[default@Hotelier] list Hotel;
Using default limit of开发者_运维百科 100
-------------------
RowKey: AZS_011
=> (column=name, value=43616d6272696120537569746573, timestamp=527682928555011)

The value above is actually "Cambria Suites". And when I use the following code to retrieve the value from the database:

    String key = "AZS_011";
    Connector connector = new Connector();
    Cassandra.Client client = connector.connect();

    ColumnPath cp = new ColumnPath("Hotel");
    cp.setColumn(to_bb("name"));

    ColumnOrSuperColumn col = client.get(to_bb(key), cp, CL);                                                                    
    String hotel_name = new String(col.column.value.array(), UTF8);
    System.out.println("I found: " + hotel_name);
    connector.close();

I end up with the output: I found: ?getnameCambria Suites ??B?

It seems that by referring to col.column.value, I have got everything within the whole row. My question is how can I only get the value without the name and timestamp part? Thanks a lot.


Use following way to get each column. I made method get the values as below:

for (ColumnOrSuperColumn c : result) {
            if (c.getColumn() != null) {
                String name = new String(c.getColumn().getName(), ENCODING);
                String value = new String(c.getColumn().getValue(), ENCODING);
                long timestamp = c.getColumn().getTimestamp();
                System.out.println("  name: '" + name + "', value: '" + value + "', timestamp: " + timestamp);
            } else {

            }
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜