当我尝试使用一些新列添加一个列家庭时,我正在学习使用Hector并收到错误。
以下代码有效,我只编辑了没有新定义列的columnfamily。
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);
如果我移动评论,那么我会收到错误消息:
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)
引起:
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
任何人都可以帮助我吗?
答案 0 :(得分:0)
如果指定索引名称,则还必须指定索引类型
尝试添加
cd1.setIndexType(ColumnIndexType.KEYS);