问题
I have the following code segment. The composite column has two compoents. Is it possible to retrieve columns if I know only the first component? In some sense, apply some dilcards election on the some of the components of the composite (especially the last component).
Thanks.
Mutator<String> mutator = HFactory.createMutator(keyspace, stringSerializer);
String key="TX:512";
String CF="StateNpaIndexStatic";
HColumnImpl<Composite, String> column = new HColumnImpl<Composite, String>(cs, StringSerializer.get());
column.setClock(keyspace.createClock());
Composite dc = new Composite();
dc.add(0, "review");
dc.add(1, "T23333");
column.setName(dc);
column.setValue("aa");
mutator.addInsertion(key, CF, column);
mutator.execute();
Composite start = new Composite();
start.add(0, start0);
start.add(1,"*");
Composite end = new Composite();
end.add(0, end0);
end.add(1, "*");
SliceQuery<String,Composite, String> sliceQuery =HFactory.createSliceQuery(keyspace,stringSerializer, CompositeSerializer.get(), StringSerializer.get());
sliceQuery.setColumnFamily(CF);
sliceQuery.setKey(key);
sliceQuery.setRange(start, start, false, 1);
QueryResult<ColumnSlice<Composite, String>> result = sliceQuery.execute();
System.out.println("Result :"+result.get().getColumns().size()+"=========="+result);
回答1:
You don't have to specify all the components in the composite. You can miss ones off the end (but not the middle or beginning) and do a range query on these, rather like passing in empty ranges into a get_slice query on normal columns.
If, in your example, you did a query with
Composite start = new Composite();
start.addComponent(0, start0, ComponentEquality.EQUAL);
Composite end = new Composite();
end.add(0, end0, ComponentEquality.GREATER_THAN_EQUAL);
you would get everything that starts with start0 up to end0. The ComponentEquality flags set whether to include or exclude the end ranges. The ones above include both start and end. You would exclude the beginning with ComponentEquality.GREATER_THAN_EQUAL; to exclude the end use ComponentEquality.EQUAL.
来源:https://stackoverflow.com/questions/16795873/composite-type-wildcard-on-last-component