0

当我尝试添加带有一些新列的列族时,我正在学习使用 Hector 并出现错误。

以下代码有效,我只编辑没有新定义的列的列族。

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

谁能帮我吗?

4

1 回答 1

0

如果指定索引名称,则还必须指定索引类型

尝试添加

cd1.setIndexType(ColumnIndexType.KEYS);
于 2013-10-02T15:11:48.970 回答