pythoncassandrapycassa

Specify column type in pycassa


I want to do the equivalence of these CLI command in pycassa:

CREATE 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}
{column_name: gender, validation_class: UTF8Type}
{column_name: birth_year, validation_class: LongType}
];

What is the equivalence in pycassa? Thanks


Solution

  • You can try this. Don't know much about python client, still ...

     validators = {'full_name': UTF8_TYPE,
                  'email': UTF8_TYPE,
                  'state': UTF8_TYPE,
                  'gender': UTF8_TYPE,
                  'birth_year': LONG_TYPE}
     sys.create_column_family('TestKeyspace', 'TestCF', super=False,
                  comparator_type=UTF8Type,
                  key_validation_class=UTF8Type, 
                  column_validation_classes=validators)