查询读取cassandra hector中的复合列

时间:2013-07-15 08:29:24

标签: cassandra hector

我需要根据行键读取cassandra列族中的所有值。 我只获得一行密钥。我想查询列族中的所有键。

列族的模式

  

rowKey是String,值在列名称本身中,如date:subject:marks   即在db 2013-04-13 00:00:00 UTC中保存,科学,99为rowkey = 1

尝试这样

  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 个答案:

答案 0 :(得分:0)

你能试试吗???

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