Return to Snippet

Revision: 44293
at April 9, 2011 06:27 by abelperez

Initial Code
import java.nio.ByteBuffer;

import org.apache.cassandra.thrift.*;
import org.apache.cassandra.thrift.TBinaryProtocol;

import org.apache.thrift.protocol.*;
import org.apache.thrift.transport.*;
import org.apache.thrift.transport.TTransport;

 * Example of how to insert a new Column into a Cassandra ColumnFamily.
 * This example assumes the keyspace is "mindplex", the ColumnFamily is
 * "User", the row to add a new Column too is row id "100" and the new 
 * Column is "description".
 * @author Abel perez
public class CassandraInsertExample
    public static void main(String[] args) throws Exception {

        TTransport transport = new TFramedTransport(new TSocket("localhost", 9160));
        TProtocol protocol = new TBinaryProtocol(transport);

        Cassandra.Client client = new Cassandra.Client(protocol);


        ColumnParent parent = new ColumnParent("User");

        ByteBuffer rowid = ByteBuffer.wrap("100".getBytes());

        Column column = new Column();
        column.setValue("some value here...".getBytes());

        client.insert(rowid, parent, column, ConsistencyLevel.ONE);


Initial URL

Initial Description
Simple way to insert a new Column into a Cassandra ColumnFamily using the Thrift API.  This snippet uses Cassandra 0.7.3 and Thrift 0.5.  For a full explanation of how this code works, check out a detailed tutorial with a screencast here:

Initial Title
Cassandra - Insert Column into ColumnFamily

Initial Tags

Initial Language