Skip to content

ComponentSelect for controlling column fields in results

edwardcapriolo edited this page Feb 17, 2013 · 2 revisions

Cassandra's RPC library, thrift returned fairly complicated Column objects which had fields like timestamp, that are not always useful. On the other hand CQL hides you from information making it harder to get at. IntraVert has a "meet me in the middle" approach. By default, read operations return the name and value of a column. However, this operation can be adjusted in the session state.

This can be a large performance boost all around. For example, in cases where the user knows the value is not populated or the column is not needed they can remove this from the results. This can save the expense of sending these over the wire (and save Cassandra/IntraVert the overhead of having to convert these types)

API

In a request adjust the want

Set<String> wanted = new HashSet<String>();
wanted.addAll( Arrays.asList( new String []{"value","timestamp"}));
req.add( Operations.componentSelect(wanted)); 

Slice operations now only returned the desired attributes.

req.add(Operations.getOp("optional", 1).set("keyspace", "myks")
.set("columnfamily", "mycf")); // 5
....
List<Map> x = (List<Map>) res.getOpsRes().get(5);
Assert.assertEquals("wow", x.get(0).get("value"));
Assert.assertEquals(true, x.get(0).containsKey("timestamp"));
Assert.assertTrue( (Long)x.get(0).get("timestamp") > 0);