cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roshan Dawrani <roshandawr...@gmail.com>
Subject Re: quick question about super columns
Date Fri, 07 Jan 2011 07:03:06 GMT
On Fri, Jan 7, 2011 at 12:12 PM, Arijit Mukherjee <arijit72@gmail.com>wrote:

> Thank you. And is it similar if I want to search a subcolumn within a
> given supercolumn? I mean I have the supercolumn key and the subcolumn
> key - can I fetch the particular subcolumn?
>
> Can you share a small piece of example code for both?
>

Have you gone through the examples  @
https://github.com/rantav/hector/blob/master/core/src/test/java/me/prettyprint/hector/api/ApiV2SystemTest.java?

For now, here are some snippets to help you:

1) So, say, for a given row and a given super-column, if u want to fetch one
particular sub-column, this is how you can do it:

SubSliceQuery subSliceQuery = HFactory.createSubSliceQuery(keyspace, .., ..,
.., ..)
subSliceQuery.setColumnFamily(<name_of_col_family>)
.setKey(<row_key>).setSuperColumn(<super-column-key>).setRange(subCol,
subCol, false, 1)

You can manipulate the range, if you want more than 1 sub-column from there.

2) Inserting a new super-column (with its sub-columns) in a row

HSuperColumn superCol = HFactory.createSuperColumn(<super-column-key>,
                   [HFactory.createColumn(<sub-column-key>, new byte[0], US,
BAS)],
                   SS, US, BAS) - /* SS, US, etc are serializers used here.
*/

mutator.addInsertion(<row-key>, <name_of_col_family>, superCol)

This example inserts in a row a new super-column that has 1 sub-column (you
can add as many as u like to the list of sub-cols being passed)


<#12d5f46d9509473c_>
<#12d5f46d9509473c_>             <#12d5f46d9509473c_>
<#12d5f46d9509473c_>
                                                   <#>
<#>
<#>       <#>

Mime
View raw message