Reputation: 24154
I am working with Cassandra database. I have created one column family which has 10 columns in that.
Now I am interested in retrieving only the columns that I required. I don't need to retrieve all the columns value from the Cassandra database.
Suppose if I have below columns in my column family users
.
colA
colB
colC
colD
And I need to get only colA and colB
data from Cassandra database. Then what I am supposed to do? I don't want to get all the columns data from Cassandra and then loop around to get the required columns.
Something like-
SELECT colA, colB from table1;
I am working with Pelops client
.
Below is my code.
public void readTest() {
// read back the data we just wrote
Selector selector = Pelops.createSelector(poolName);
List<Column> columns = selector.getColumnsFromRow(colFamilyName, rowKey, false, ConsistencyLevel.ONE);
System.out.println("Name: " + Selector.getColumnStringValue(columns, "name"));
System.out.println("Age: " + Selector.getColumnValue(columns, "age").toInt());
}
Upvotes: 1
Views: 274
Reputation: 4031
You need to use a getColumnsFromRow call which takes a "SlicePredicate" to specify the column names. Such as:
getColumnsFromRow(String columnFamily, Bytes rowKey, SlicePredicate colPredicate, ConsistencyLevel cLevel)
Upvotes: 2