0
votes

cassandra-thrift-1.1.2.jar

Problem code:

            ColumnOrSuperColumn cosc = null;
        org.apache.cassandra.thrift.Column c = new org.apache.cassandra.thrift.Column ();
        c.setName  ("full_name".getBytes ("UTF-8"));
        c.setValue ("Test name".getBytes ("UTF-8"));
        c.setTimestamp (System.currentTimeMillis());

        // insert data
//        long timestamp = System.currentTimeMillis();

        try {
            client.set_keyspace("CClient");

            bb=ByteBuffer.allocate (10);
            client.insert  (bb.putInt(1), 
                            new ColumnParent ("users"), 
                            c, 
                            ConsistencyLevel.QUORUM);
            bb.putInt (2);
            cosc = client.get (bb, cp, ConsistencyLevel.QUORUM);
        }
        catch (TimedOutException toe) {
            System.out.println (toe.getMessage());
        } 
        catch (org.apache.cassandra.thrift.UnavailableException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            System.out.println (new String (cosc.getColumn().getName()) + "-" + new String (cosc.getColumn().getValue()));
        }

The code shown above inserts some junk or null into the database, I don't understand the reason why?

See how it looks on the CLI:

 
RowKey:
=> (column=full_name, value=Test name, timestamp=1345743985973)

Any help in this is greatly appreciated.

Thanks.

1
I don't really follow your question, but it will be a lot easier if you use a client library like Hector rather than using the raw thrift.sbridges
@sbridges you should make this an answer, because it's the correct answer.Tyler Hobbs
I looked up Hector source to find out how inserts are being done and ByteBufferUtil is the one. client.insert (ByteBufferUtil.bytes (1), new ColumnParent ("users"), c, ConsistencyLevel.QUORUM); Aswin Kumar

1 Answers

0
votes

You're creating a row with row key as bytes. In Cassandra cli you'll probably see the row key if you list the rows as bytes. E.g. in cassandra cli type:
assume users keys as bytes;
list users;