Cassandra getting back a whole row

337 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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 {

            }
        }