Previous Next

How to specify what data to retrieve from a Cassandra data source

In this procedure, use the following open clause in a CQL query:

importPackage(Packages.java.util);
importPackage(Packages.me.prettyprint.cassandra.serializers);
importPackage(Packages.me.prettyprint.cassandra.service);
importPackage(Packages.me.prettyprint.hector.api);
importPackage(Packages.me.prettyprint.hector.api.beans);
importPackage(Packages.me.prettyprint.hector.api.factory);
importPackage(Packages.me.prettyprint.hector.api.query);
importPackage(Packages.me.prettyprint.cassandra.model);
var cluster = HFactory.getOrCreateCluster("Test Cluster",new CassandraHostConfigurator("192.168.218.246:9160"));
var keyspace = HFactory.createKeyspace("users", cluster);
var cqlQuery = new CqlQuery(keyspace, StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
cqlQuery.setQuery("select * from User");
var resultCQL = cqlQuery.execute();
rowsIterator = resultCQL.get().iterator();

Also use the following fetch clause:

if (rowsIterator.hasNext()) {
var myrow = rowsIterator.next();
var cols = myrow.getColumnSlice().getColumns();
for( ii=0; ii < cols.size(); ii++ ){
row[cols.get(ii).getName()] = cols.get(ii).getValue();
}
return true;
}else{
return false;
}
1  
2  
1  
2  
3  
3  
*
*
*
*
*
*
When finished specifying the data set column properties, choose OK.

Figure 2-2 Adding an output column

Figure 2-2  Adding an output column
The specified output columns appear in New Data Set, as shown in Figure 2-3. In this example, the output columns are first, last, and age.

Figure 2-3 Specifying output columns to retrieve

Figure 2-3  Specifying output columns to retrieve
4  
5  
1  
importPackage(Packages.java.util);
importPackage(Packages.me.prettyprint.cassandra.serializers);
importPackage(Packages.me.prettyprint.cassandra.service);
importPackage(Packages.me.prettyprint.hector.api);
importPackage(Packages.me.prettyprint.hector.api.beans);
importPackage(Packages.me.prettyprint.hector.api.factory);
importPackage(Packages.me.prettyprint.hector.api.query);
importPackage(Packages.me.prettyprint.cassandra.model);
var cluster = HFactory.getOrCreateCluster("Test Cluster",new CassandraHostConfigurator("192.168.218.246:9160"));
var keyspace = HFactory.createKeyspace("users", cluster);
var cqlQuery = new CqlQuery(keyspace, StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
cqlQuery.setQuery("select * from User");
var resultCQL = cqlQuery.execute();
rowsIterator = resultCQL.get().iterator();

Figure 2-4 Specifying the open clause

Figure 2-4  Specifying the open clause
2  
if (rowsIterator.hasNext()) {
var myrow = rowsIterator.next();
var cols = myrow.getColumnSlice().getColumns();
for( ii=0; ii < cols.size(); ii++ ){
row[cols.get(ii).getName()] = cols.get(ii).getValue();
}
return true;
}else{
return false;
}

Figure 2-5 Specifying the fetch clause

Figure 2-5  Specifying the fetch clause
3  

(c) Copyright Actuate Corporation 2013