cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Grossman <richie...@gmail.com>
Subject Re: how to insert a supercolumn with java ?
Date Mon, 25 Jan 2010 09:43:45 GMT
Here is a code to insert SuperColumn with batch_insert

    Map<String, List<ColumnOrSuperColumn>> insertDataMap = new
HashMap<String, List<ColumnOrSuperColumn>>();
        List<ColumnOrSuperColumn> rowData = new
ArrayList<ColumnOrSuperColumn>();
        List<Column> columns = new ArrayList<Column>();

        long timestamp = System.currentTimeMillis();

        // THESE ARE THE SUPERCOLUMN COLUMNS
        columns.add(new Column(("colname1").getBytes("UTF-8"),
colvalue1.getBytes("UTF-8"), timestamp));
        columns.add(new Column(("colname2").getBytes("UTF-8"),
colvalue2.getBytes("UTF-8"), timestamp));
        columns.add(new Column(("colname3").getBytes("UTF-8"),
colvalue2.getBytes("UTF-8"), timestamp));

        // HERE THE SUPER COLUMN
        SuperColumn superColumn =  new
SuperColumn(superColumnNAME.getBytes("UTF-8"), columns);
        ColumnOrSuperColumn columnOrSuperColumn = new ColumnOrSuperColumn();
        columnOrSuperColumn.setSuper_column(superColumn);

        rowData.add(columnOrSuperColumn);
        insertDataMap.put(ColumnFamilyName, rowData);

        clientCassandra.batch_insert("Keyspace1", Key, insertDataMap,
ConsistencyLevel.QUORUM);

On Mon, Jan 25, 2010 at 2:58 AM, Patrick de Torcy <pdetorcy@gmail.com>wrote:

>
> Despite a lot of googling, I couldn't find any example of how to create and
> insert a super column in Cassandra with java. I think that I have to use
> batch_insert, but it needs the class BatchMutation, which is not described
> in the javadoc.
> Where can I find examples of how to use the API in java ? The javadoc seems
> completely out of date and clientExamples is very, very short !
>
> Thanks

Mime
View raw message