0

I need to read all values in a cassandra column family according to the row key. I am getting only for one row key. I want to query for all the keys in the column family.

Schema of the column family

rowKey is String and the values are in the column names itself like date:subject:marks i.e saved like this in the db 2013-04-13 00:00:00 UTC,science,99 for rowkey=1

trying like this

  Cluster cluster = HFactory.getOrCreateCluster("Test Cluster", "localhost:9160");
  Keyspace keyspaceOperator = HFactory.createKeyspace(student, cluster);
  System.out.println( "Connected to cassandra " + cluster);
  String rowKey = "1";


  SliceQuery<String,String,String> columnQuery = HFactory.createSliceQuery(keyspaceOperator, StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
  columnQuery.setColumnFamily("studentInfo").setKey(rowKey).setRange(null, null, false, 100);
  System.out.println(columnQuery);
  QueryResult<ColumnSlice<String,String>> result = columnQuery.execute();
  for (HColumn<String, String> column : result.get().getColumns()) {
    System.out.println(column.getName());
  }
Jubin Patel
  • 1,959
  • 19
  • 38
Shalu
  • 251
  • 2
  • 4
  • 15

1 Answers1

0

Can you try this???

      SliceQuery<String,String,String> columnQuery = HFactory.createSliceQuery(ksp, StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
      columnQuery.setColumnFamily("studentInfo").setKey(rowKey).setColumnNames("id","name");
      QueryResult<ColumnSlice<String,String>> result = columnQuery.execute();
abhi
  • 4,762
  • 4
  • 29
  • 49
  • yes this works but only for one row i am not able to iterate over all rows in the keyspace.. Also columns in my keyspace dont have a label they are saved in column names like `1 | 2013-04-01,science,96` – Shalu Jul 15 '13 at 11:06
  • do you mean a single column whose value is like 2013-04-01,science,96 – abhi Jul 15 '13 at 11:30
  • Also in your question, code snippet, you want to know the result corresponding to a single rowKey. I am not getting the whole thing properly. Need to be clarified – abhi Jul 15 '13 at 11:33
  • See this is the column family structure in my app ` rowkey studentinfo 1 | 2013-04-01,science,96 2 | 2013-04-01,science,96 | 2013-04-02,maths,96 | 2012-04-03,english,90` I want to query row by row on each column – Shalu Jul 15 '13 at 11:59
  • `rowkey studentinfo` `1 | 2013-04-01,science,96` `2 | 2013-04-01,science,96 | 2013-04-02,maths,96 | 2012-04-03,english,90` – Shalu Jul 15 '13 at 12:02
  • @abhi, I also have similar question [here](http://stackoverflow.com/questions/18921964/composite-column-values-in-cassandra). Can you please take a look? – arsenal Sep 21 '13 at 00:13