Start using RangeSliceQuery instead of IndexedSliceQuery as IndexedSliceQuery is Deprecated with Hector 1.2 +



In my earlier post i have shown you How to use IndexedSliceQuery in Cassandra. Well it is time now to switch it with RangeSliceQuery since IndexedSliceQuery is now Deprecated with Hector 1.1+ release.


You Can Download the latest Version of Hector API from here.

So as i told you in the last tutorial that If you want to query on column value you can use IndexSliceQuery. Here you can do the same with RangeSliceQuery.

Lets say you want to do a query using Hector API which is similar to:

Select * from tableName where columnName ="desired Value";

The Implementation  of the same in Hector API using RangeSliceQuery will be something like the code given below:

1
2
3
4
5
6
7
RangeSlicesQuery<String, String, String> rangeSlicesQuery =
HFactory.createIndexedSlicesQuery(keyspace, StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
rangeSlicesQuery.addEqualsExpression("columnName", "columnValue");
rangeSlicesQuery.setColumnNames("ColumnNameWantToRetrive");
rangeSlicesQuery.setColumnFamily("ColumnFamilyName");
QueryResult<OrderedRows<String, String, String>> result =
rangeSlicesQuery.execute();

Here you can give the columnName as many as you want to fetch the Values of those Column Names.

Again one of the important Propery of IndexedSlicesQuery  is that you can implement an And Condition with it in Hecotr API.

If we again go with the SQL, it will be something like:

Select * from tableName where columnName1="desired Value1" and columnName2="desired Value2";

The Implementation  of the same in Hector API will be something like:

USING AND IN HECTOR API with Rangeslicequery



1
2
3
4
5
6
7
8
RangeSlicesQuery<String, String, String> rangeSlicesQuery =
HFactory.createIndexedSlicesQuery(keyspace, StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
rangeSlicesQuery.addEqualsExpression("columnName1", "columnValue1");
rangeSlicesQuery.addEqualsExpression("columnName2", "columnValue2");
rangeSlicesQuery.setColumnNames("ColumnNameWantToRetrive");
rangeSlicesQuery.setColumnFamily("ColumnFamilyName");
QueryResult<OrderedRows<String, String, String>> result =
rangeSlicesQuery.execute();


USING OR IN HECTOR API

* And as i have told this earlier too, till now there is no support for OR in Cassandra or Hector API. So if you want to implement the same, you have to try it in your Business Logic.

Find Comments below or Add one

Post a Comment