hector-examples
hector-examples copied to clipboard
read a single row
Hi am new to cassandra 0.7. could u able to clear my doubt???
This is my code for read a single row
public class Read1Column
{
private static StringSerializer stringSerializer = StringSerializer.get();
private static DoubleSerializer doubtSerializer = DoubleSerializer.get();
public static void main(String[] args) throws Exception {
String keyspaceName = "User";
String columnFamilyName ="User_Details";
String serverAddress = "localhost:9160";
//String username="stu1";
String Uid="0001";
// String FirstName="ss";
// String LastName="kk";
// String EMail="sksk";
String password="ssss";
// Create a cluster
Cluster cluster = HFactory.getOrCreateCluster("TestCluster", serverAddress);
Keyspace keyspaceOperator = HFactory.createKeyspace(keyspaceName, cluster);
try{
Iterator<SuperRow<String, String, String, Double>> rowIter =
HFactory.createRangeSuperSlicesQuery(keyspaceOperator,
stringSerializer, stringSerializer, stringSerializer,
doubtSerializer)
.setColumnFamily(columnFamilyName)
.setKeys(Uid,password)
.setRange(Uid, password, false, 40)
.execute()
.get()
.iterator();
while (rowIter.hasNext()) {
SuperRow<String, String, String, Double> row =
rowIter.next();
List<HSuperColumn<String, String, Double>> scList =
row.getSuperSlice().getSuperColumns();
for (int i=0; i<scList.size(); i++) {
HSuperColumn<String, String, Double> sc =
scList.get(i);
// Double val = sc.get(2).getValue();
// gets the value of column 2 within the supercolumn
System.out.println(sc.get(2).getValue());
}
}
} catch (HectorException e) {
e.printStackTrace();
}
// client.getConnectionManager().shutdown();
}
}
its show the error:
log4j:WARN No appenders could be found for logger (me.prettyprint.cassandra.connection.CassandraHostRetryService).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NullPointerException: Null not allowed, number 1
at me.prettyprint.cassandra.utils.Assert.noneNull(Assert.java:25)
at me.prettyprint.cassandra.model.HSuperColumnImpl.
Strange - looks like you got a null SC back in the result list. Can you show me output from cassandra-cli of what you expect to be there?
If i give the key(Uid) means its display the entire column from the cassandra-cli. This is my expecting output.