cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tamar Fraenkel <ta...@tok-media.com>
Subject Re: get all columns for a row
Date Mon, 23 Jan 2012 17:46:58 GMT
Thanks.
Tamar



On January 23, 2012 at 11:24 AM aaron morton <aaron@thelastpickle.com> wrote:


> The columns are stored at the intersection of the row and the CF. So if you
> read all the columns for a row in a CF you are only getting those ones. 
>  
> Your hector code (using the range) looks correct to me. 
>  
> Have fun. 
> Aaron
> 
> 
> 
> 
> 
> 
> 
> -----------------
> Aaron Morton
> Freelance Developer
> @aaronmorton
> http://www.thelastpickle.com
> 
> 
> On 23/01/2012, at 9:24 PM, Tamar Fraenkel wrote:
> 
> > 
> > 
> > Hi!
> > 
> > I am getting started with Cassandra and Hector and have a question.
> > If I have CF with many columns, only a small portion of them having values
> > for any given key. I want to read all columns for a given key, but I don't
> > know which columns were populated.
> > I managed to do that with the code below (assumes that column names are
> > incremental numbers).
> > Is there any better way?
> > Thanks,
> > Tamar 
> > private static void readAllColunsForRowKey(String key) {
> >   MultigetSliceQuery<String, Long, String> multigetSlicesQuery =
> >     HFactory.createMultigetSliceQuery(tutorialKeyspace,
> > StringSerializer.get(), LongSerializer.get(),
> >        StringSerializer.get());
> >   multigetSlicesQuery.setColumnFamily(CF);
> >   multigetSlicesQuery.setKeys(key);
> >   multigetSlicesQuery.setRange(null, null, false, COL_COUNT);
> >   QueryResult<Rows<String, Long, String>> results =
> > multigetSlicesQuery.execute();
> >   Long lastColName;
> >   while ((lastColName = printColsAndGetLastColName(results, key)) != null) {
> >     multigetSlicesQuery.setRange(lastColName + 1, null, false, COL_COUNT);
> >     results = multigetSlicesQuery.execute();
> >   }
> > }
> > 
> > private static Long printColsAndGetLastColName(QueryResult<Rows<String,
> > Long, String>> results, String key) {
> >   Rows<String, Long, String> rows = results.get();
> >   if (rows.getCount() != 1) {
> >     System.out.println("No such key");
> >     return null;
> >   }
> >   Row<String, Long, String> row = rows.getByKey(key);
> >   ColumnSlice<Long, String> columnSlice = row.getColumnSlice();
> >   List<HColumn<Long, String>> columns = columnSlice.getColumns();
> >   for (HColumn<Long, String> column : columns) {
> >     System.out.println("Column Name: " + column.getName()
> >       + ", Column Val: " + column.getValue());
> >   }
> >   if (columns.size() == COL_COUNT) {
> >     return columns.get(COL_COUNT - 1).getName();
> >   }
> >   return null;
> > }
> > 


 
Mime
View raw message