Reference Guide

Table Of Contents
case TOPIC:
StringColumn<String> topic1 =
(StringColumn) row1.getColumn(TOPIC_COL_NAME);
StringColumn<String> topic2 =
(StringColumn) row2.getColumn(TOPIC_COL_NAME);
retVal = topic1.compareTo(topic2);
break;
}
return retVal;
}
}
...
In this code, there is defined a constructor and the main column family. The Alerts in this code is
the main column family in the CassandraAlertDao and has following columns:
sysId
severity
timestamp
origin
topic
description
state
These columns are defined along with the data type for each column, a decoder to assist in the
read operation and a method to compare columns while sorting a read result.
In addition to this column family, free form queries are supported on a combination of values of
severity, timestamp, origin, topic, state and description.
To enable this, a secondary index for each of these columns needs to be created and maintained.
This secondary index is another column family and it is called the secondary column family. An
example is AlertsBySeverity column family as shown below.
The secondary column families use composite columns and a row in AlertsBySeverity would look
like this.
RowKey CRITICAL : 1 | CRITICAL : 2 | INFO : 3 | WARNING : 5 | ……
Here the first part of the composite column name is the value of Severity that is wanted to match
and the second part of the column name is the primary key / row key of the matching row in the
main column family. To lookup all Alerts matching Severity = CRITICAL, rows 1 and 2 will be
returned. Do an additional lookup in the main column family to retrieve the data from rows 1 and
2. Once the data is retrieved, convert the same into a storable and return the query back to the
application.
CassandraAlertDao.java AlertsBySeverity Column Family:
public static class SeverityComposite implements
Serializable, Comparable<SeverityComposite>{
@Component (ordinal = 0)
private String severity;
97