incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anurag Gujral <anurag.guj...@gmail.com>
Subject Re: cassandra client sample code for 0.7.3
Date Fri, 25 Mar 2011 13:14:05 GMT
Hi Narendra,
                  Thanks for your email Which thrift version are you using.I
am using thrift-0.0.5 in which batch_mutate takes
map<ByteBuffer,map<String,List<Mutations>>  as argument
in ur sample code ur map is of type map<String,map<String,List<Mutations>>
Please Suggest
Thanks
Anurag

On Fri, Mar 25, 2011 at 12:10 AM, Narendra Sharma <narendra.sharma@gmail.com
> wrote:

> Hope you find following useful. It uses raw thirft. In case you find
> difficulty in build and/or running the code, please reply back.
>
> private Cassandra.Client createClient(String host, int port) {
>     TTransport framedTransport = new TFramedTransport(new TSocket(host,
> port));
>     TProtocol framedProtocol = new TBinaryProtocol(framedTransport);
>     Cassandra.Client client = new Cassandra.Client(framedProtocol);
>     framedTransport.open();
>     client.set_keyspace("Keyspace");
>     return client;
> }
>
> private Mutation getMutation(SuperColumn sc) {
>  ColumnOrSuperColumn csc = new ColumnOrSuperColumn();
>  csc.setSuper_column(sc);
>  csc.setSuper_columnIsSet(true);
>  Mutation m = new Mutation();
>  m.setColumn_or_supercolumn(csc);
>  m.setColumn_or_supercolumnIsSet(true);
>  return m;
> }
>
> private Mutation getMutation(Column c) {
>  ColumnOrSuperColumn csc = new ColumnOrSuperColumn();
>  csc.setColumn(c);
>  csc.setColumnIsSet(true);
>  Mutation m = new Mutation();
>  m.setColumn_or_supercolumn(csc);
>  m.setColumn_or_supercolumnIsSet(true);
>  return m;
> }
>
>
> private Column createColumn(String name, String value, long time) {
> Column c = new Column();
>  c.setName(name.getBytes());
>  c.setValue(value.getBytes());
>  c.setTimestamp(time);
>  return c;
> }
>
> Cassandra.Client client = createClient(host, port);
> long timeStamp = System.currentTimeMillis();
>
> //For Standard CF
> Column col1 = createColumn("name1", "value1", timeStamp);
> Column col2 = createColumn("name2", "value2", timeStamp);
>
> Map<String, List<Mutation>> mutations = new HashMap<String,
> List<Mutation>>();
> List<Mutation> mutation = new ArrayList<Mutation>();
> mutation.add(getMutation(col1));
> mutation.add(getMutation(col2));
>
> mutations.put("StandardCF", mutation);
> Map<ByteBuffer, Map<String, List<Mutation>>> mutationMap = new
> HashMap<ByteBuffer, Map<String, List<Mutation>>>();
> mutationMap.put(ByteBuffer.wrap(getBytes("rowkey")), mutations);
> client.batch_mutate(mutationMap, CL);
>
>
> //for Super CF
> SuperColumn info = new SuperColumn();
> info.setName("info");
> List<Column> cols = new ArrayList<Column>();
> cols.add(createColumn("name1", "val1", timeStamp));
> cols.add(createColumn("name2", "val2", timeStamp));
> info.setColumns(cols);
>
>
> Map<String, List<Mutation>> mutations = new HashMap<String,
> List<Mutation>>();
> List<Mutation> mutation = new ArrayList<Mutation>();
> mutation.add(getMutation(info));
>
> mutations.put("SuperCF", mutation);
> Map<ByteBuffer, Map<String, List<Mutation>>> mutationMap = new
> HashMap<ByteBuffer, Map<String, List<Mutation>>>();
> mutationMap.put(ByteBuffer.wrap(getBytes("row-key")), mutations);
> client.batch_mutate(mutationMap, CL);
>
> Thanks,
> Naren
>
>
> On Thu, Mar 24, 2011 at 10:01 PM, Anurag Gujral <anurag.gujral@gmail.com>wrote:
>
>> I am in need of sample code(basically cassandra client) in java using
>> batch_mutate
>> If someone has please reply back
>> Thanks
>> Anurag
>>
>
>

Mime
View raw message