简体   繁体   中英

Query to read on composite columns in cassandra hector

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM