Wednesday, November 10, 2010

Batch insert in cassandra using hector api 0.7

I am going to write a sample program which can do a batch insert or a batch mutation of two columns in a column family


public static void main(String[] args) throws HectorException {
final StringSerializer serializer = StringSerializer.get();

Keyspace keyspace = null;
Cluster cluster = HFactory.getOrCreateCluster("test", "192.168.1.3:9160");
keyspace = HFactory.createKeyspace("sample", cluster);
try {


Mutator m = HFactory.createMutator(keyspace,serializer);

m.addInsertion("testbatch", "feed", HFactory.createStringColumn("Type", "somevalue"));
m.addInsertion("testbatch", "feed", HFactory.createStringColumn("TypeBatch", "somevalue"));
m.execute();

} catch(Exception e) {
e.printStackTrace();
}
}

No comments:

Post a Comment