0
votes

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());
  }
1

1 Answers

0
votes

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();