I'm new to cassandra and hector so i'm trying to execute cql queries but the problem is that not all columns are of type string so how dow I execute the query "select * from users"?
My column family looks like this:
UPDATE COLUMN FAMILY users
WITH comparator = UTF8Type
AND key_validation_class=UTF8Type
AND column_metadata = [
{column_name: full_name, validation_class: UTF8Type}
{column_name: email, validation_class: UTF8Type}
{column_name: state, validation_class: UTF8Type, index_type: KEYS}
{column_name: gender, validation_class: UTF8Type}
{column_name: birth_year, validation_class: LongType, index_type: KEYS}
{column_name: education, validation_class: UTF8Type}
];
I use the following code to execute the query:
CqlQuery<String, String, String> cqlQuery = new CqlQuery<String, String, String>(Keyspace,stringSerializer,stringSerializer,stringSerializer);
cqlQuery.setQuery("select * from users");
QueryResult<CqlRows<String, String, String>> result = cqlQuery.execute();
if (result != null && result.get() != null) {
List<Row<String, String, String>> list = result.get().getList();
for (Row row : list) {
System.out.println(".");
List columns = row.getColumnSlice().getColumns();
for (Iterator iterator = columns.iterator(); iterator.hasNext();) {
HColumn column = (HColumn) iterator.next();
System.out.print(column.getName() + ":" + column.getValue()
+ "\t");
}
System.out.println("");
}
}
But because of the 'birth_year' column with validation class Long I can't get the value. I get the following result assuming that there is only one record:
KEY:Carl birth_year: 'strange chars?' full_name:Carl Smith gender:M eduction:electrician state:LA
If I change my query to this:
CqlQuery<String, String, Long> cqlQuery = new CqlQuery<String, String, Long>
TutorialBase.tutorialKeyspace, stringSerializer, stringSerializer, longSerializer);
cqlQuery.setQuery("select birth_year from users");
Than it works.
So how can I do this with only one query and what if I have more datatypes like booleans and floats in the rows of a column family?