我有一个超级列系列,当我这样查询时一切正常:
private static Cluster cluster = HFactory.getOrCreateCluster("cluster1", "localhost:9160");
private static Keyspace keyspace = HFactory.createKeyspace("keyspace1",cluster);
private static Serializer se = StringSerializer.get();
SuperColumnQuery<String, String, String, String> scq = HFactory.createSuperColumnQuery(keyspace, se, se, se, se);
scq.setColumnFamily("step_wise_stats")
.setKey("1001")
.setSuperName("124");
QueryResult<HSuperColumn<String, String, String>> qres = scq.execute();
System.out.println(qres.get());
但是在密钥1001下面还有更多超级名称,如125,126等。这些也是动态的(我不提前知道这些名字)。我如何查询它们?
答案 0 :(得分:0)
许多专家和文档表明,使用复合柱比使用Super Column要好得多,因为缺少二级索引......所以尽可能使用复合柱。否则在这种情况下你应该使用timeUUID您的动态值并尝试使用MultigetSubSliceQuery
,使用以下代码进行更改,这可能会增加您的编程工作以生成所需的结果
ArrayList<String> listco = new ArrayList<String>();
listco.add("1001");
listco.add("1002");
MultigetSubSliceQuery<String,String, String, String> rangeSlicesQuery =
HFactory.
createMultigetSubSliceQuery(keyspace,stringSerializer, stringSerializer, stringSerializer, stringSerializer);
rangeSlicesQuery.setColumnFamily("step_wise_stats");
rangeSlicesQuery.setSuperColumn("your super column");
rangeSlicesQuery.setKeys(listco);
rangeSlicesQuery.setRange("", "", false, 1000);
QueryResult<Rows<String, String, String>> result = rangeSlicesQuery.execute();