Tuesday, October 30, 2012

Cassandra keys in Unix/linux server and client in java windows

In this link talk about to count in rows in cassandra. But there a little problem when Unix database and client java Windows. The serialize UUID dont work.
byte[] start = null;
byte[] lastEnd = null;
int count = 0;
while (true) {
RangeSlicesQuery rsq = HFactory
 .createRangeSlicesQuery(keyspaceOperator,
       me.prettyprint.cassandra.serializers.BytesArraySerializer.get(), StringSerializer.get(),
 StringSerializer.get());
 rsq.setColumnFamily("columnFamily");
 rsq.setColumnNames("uuid","idUser","timestamp","urlPageVisited","processed");
 rsq.setKeys(start, null);
 rsq.setReturnKeysOnly(); // Return column names instead of values
 rsq.setRowCount(3); // Arbitrary default
 OrderedRows rows = rsq.execute().get();
 int rowCount = rows.getCount();

if (rowCount == 0) {
 break;
} else {
 start = rows.peekLast().getKey();

 if (lastEnd != null && Arrays.equals(start,lastEnd) ) { // modify this line
  break;
 }
 count += rowCount - 1;
 lastEnd = start;
}
  if (count > 0) {
   count += 1;
  }
  System.out.print("count de la tabla " + count);
  return count;
 }
change the UUID identify. Put byte[]

No comments:

Post a Comment