Friday, February 3, 2012

Cassandra Validation Classes / Types


Cassandra validates column names and row keys using validation classes.
This is put in place when you construct a columnFamily.

As an example, in the Thrift API:

CfDef columnFamily = new CfDef(KEYSPACE, COLUMN_FAMILY);
columnFamily.setKey_validation_class("UTF8Type");
columnFamily.setDefault_validation_class("UTF8Type");



The default_validation_class is used to validate row keys.
The key_validation_class is used to validate column names.

Googling didn't provide a handy list of validation classes for Cassandra.
So, here it is:

AsciiType.java BooleanType.java 
BytesType.java 
CompositeType.java 
DateType.java 
DecimalType.java 
DoubleType.java 
DynamicCompositeType.java 
FloatType.java 
Int32Type.java 
IntegerType.java 
LexicalUUIDType.java 
LocalByPartionerType.java 
LongType.java 
ReversedType.java 
TimeUUIDType.java 
TypeParser.java 
UTF8Type.java 
UUIDType.java

8 comments:

Rasik Bihari said...

Very handy information Brian. You saved my day. I was struggling for last two days to insert data into my cassandra column family as I had set the key validation class and default validation class to bytes type. It got resolved after I set the type to ascii. Now my CQL queries are working like charm. Thanks again!

Max Lam said...

Thanks for the effort. Very helpful indeed.

Caroline said...

What if I want to set some values, f.ex:
{column_name: CommentID, validation_class: LongType},
{column_name: Date, validation_class: DateType},

set posts['1']['CommentID'] = '1' or 1 (without '');
set posts['1']['Date'] = 21.10.2013 or 21/10/2013;

Bhathiya Jayasekara said...

Hi Brian,

That list is very useful. Thanks for that.

But I'm a little confused about

"The default_validation_class is used to validate row keys.
The key_validation_class is used to validate column names."

IIUC,

The default_validation_class is used to validate column values.
The key_validation_class is used to validate row keys.

Correct me if I'm wrong.

Thanks,
Bhathiya

Dave Rim said...

Dude, you rock!

Dave Rim said...

Dude, you rock!

Matli Pushpa Sekhar Reddy said...

Very Helpful

shoe said...

bhathiya is right, the language of the article is misleading. probably should fix that.