I am learning to use Hector and get a Error when I try to add a columnfamily with some new columns.
The following code works, I only edit the columnfamily without new defined columns.
KeyspaceDefinition kd = gameCluster
.describeKeyspace("testKeySpace");
//here i am try to add new columns in the columnfamily in the meanwhile
//BasicColumnDefinition cd1 = new BasicColumnDefinition();
//cd1.setName(StringSerializer.get().toByteBuffer("basicColumnname1"));
//cd1.setIndexName("testIndex");
//cd1.setValidationClass(ComparatorType.BYTESTYPE.getClassName());
BasicColumnFamilyDefinition bcf = new BasicColumnFamilyDefinition();
//add it to the new columnfamily
//bcf.addColumnDefinition(cd1);
bcf.setKeyspaceName("testKeySpace");
bcf.setName("testColumnFamily");
bcf.setComparatorType(ComparatorType.UTF8TYPE);
gameCluster.addColumnFamily(bcf);
If i move the comment, then I get a error saying:
Exception in thread "main" me.prettyprint.hector.api.exceptions.HectorException: java.lang.NullPointerException
at me.prettyprint.cassandra.service.ExceptionsTranslatorImpl.translate(ExceptionsTranslatorImpl.java:67)
at me.prettyprint.cassandra.service.ThriftCluster$4.execute(ThriftCluster.java:105)
at me.prettyprint.cassandra.service.ThriftCluster$4.execute(ThriftCluster.java:92)
at me.prettyprint.cassandra.service.Operation.executeAndSetResult(Operation.java:104)
at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:258)
at me.prettyprint.cassandra.service.ThriftCluster.addColumnFamily(ThriftCluster.java:109)
at me.prettyprint.cassandra.service.ThriftCluster.addColumnFamily(ThriftCluster.java:84)
at game.cassandra.conn.DataPrepopulate.testAddColumnFamily(DataPrepopulate.java:91)
at game.cassandra.conn.DataPrepopulate.main(DataPrepopulate.java:101)
Caused by:
java.lang.NullPointerException
at me.prettyprint.cassandra.service.ThriftColumnDef.indexTypeToThrift(ThriftColumnDef.java:105)
at me.prettyprint.cassandra.service.ThriftColumnDef.toThrift(ThriftColumnDef.java:97)
at me.prettyprint.cassandra.service.ThriftColumnDef.toThriftList(ThriftColumnDef.java:88)
at me.prettyprint.cassandra.service.ThriftCfDef.toThrift(ThriftCfDef.java:265)
at me.prettyprint.cassandra.service.ThriftCluster$4.execute(ThriftCluster.java:99)
... 7 more
Can anyone help me out?
If you specify an index name you must also specify an index type
Try to add
cd1.setIndexType(ColumnIndexType.KEYS);