2

我正在尝试实现一个数据模型,其中行键是字符串,列名是 Long,列值是 DynamicComposites。使用 Hector,存储过程的示例如下所示:

// create the value
DynamicComposite colVal = new DynamicComposite(); 
colVal.add(0, "someString");
colVal.setComparatorByPosition(0, "org.apache.cassandra.db.marshal.UTF8Type");
colVal.setSerializerByPosition(0, StringSerializer.get());

// create the column
HColumnImpl<Long, DynamicComposite> newCol = new
    HColumnImpl<Long, DynamicComposite>(longSerializer, 
        dynamicCompositeSerializer);

newCol.setName(longValue);
newCol.setValue(colVal);
newCol.setClock(keySpace.createClock());

// insert the new column
Mutator<String> mutator = HFactory.createMutator(keySpace,stringSerializer);
mutator.addInsertion("rowKey","columnFamilyName",newCol);
mutator.execute();

现在,当我尝试检索数据时:

// create the query
SliceQuery<String,Long,DynamicComposite> sq =
    HFactory.createSliceQuery(keySpace, stringSerializer, longSerializer, 
        dynamicCompositeSerializer);

// set the query
sq.setColumnFamily("columnFamilyName");
sq.setKey("rowKey");
sq.setColumnNames(longValue);

// execute the query
QueryResult<ColumnSlice<Long, DynamicComposite>> qr = sq.execute();

// get the data
qr.get().getColumnByName(longValue).getValue();

或者当我只是想简单地说再见时:

// get the data    
dynamicSerializer.fromByteBuffer(qr.get().
    getColumnByName(longValue).getValueBytes());

我遇到了一个异常:

Exception in thread "main" java.lang.NullPointerException
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:191)
    at com.google.common.collect.ImmutableClassToInstanceMap.getInstance(ImmutableClassToInstanceMap.java:147)
    at me.prettyprint.hector.api.beans.AbstractComposite.serializerForComparator(AbstractComposite.java:321)
    at me.prettyprint.hector.api.beans.AbstractComposite.getSerializer(AbstractComposite.java:344)
    at me.prettyprint.hector.api.beans.AbstractComposite.deserialize(AbstractComposite.java:713)
    at me.prettyprint.hector.api.beans.DynamicComposite.fromByteBuffer(DynamicComposite.java:25)
    at me.prettyprint.cassandra.serializers.DynamicCompositeSerializer.fromByteBuffer(DynamicCompositeSerializer.java:35)

据我从阅读的所有教程中了解到,应该可以使用 DynamicComposite 作为列值。因此我想问:我做错了什么?从例外看来,我只是忘记在某处设置一些东西。

4

1 回答 1

2

拉多万,

这可能是由于与 Hector 版本结合使用的 Guava 库的兼容性问题。

另见:https ://github.com/hector-client/hector/pull/591

我在 Hector-core-1.1-1.jar 上,结合 Guava-14.0.jar 我得到和你一样的错误。当我将它与 Guava-12.0.1.jar 一起使用时,它对我来说效果很好。

于 2013-03-22T14:38:07.843 回答