0

I am attempting to write and read Uids from Accumulo Value (key,Value) into Uid.List using protobuf. Specifically: org.apache.accumulo.examples.wikisearch.protobuf.Uid;import org.apache.accumulo.examples.wikisearch.protobuf.Uid.List.Builder

I use the following code to write Uid.List where I declare UidListCount as #of uids in List Cseq:

Builder uidBuilder = Uid.List.newBuilder();
uidBuilder.setIGNORE(false);
for String entry : seq){
    uidBuilder.addUID(entry);
}
Uid.List uidList = uidBuilder.build();

Value newAccumuloValue = new Value(uidList.toByteArray());

This seems to work fine.

When I Try to read the Uid.List out of accumulo value,where value is a protobuf Uid.List, its a no-go:

byte[] byteVal = value.getBytes; //retrieving Accumulo Value containing Uid.List
Uid.List uids= Uid.List.parseFrom(byteVal);
while (counter <= counter){
    String uidStr = uids.getUID(counter).toString();
    system.out.println(uidStr);
}

I keep getting "tag errors"

I would really like to understand how to read out what goes in.

Thanks!

4

1 回答 1

0

我建议将第二段代码更改为以下内容:

byte[] byteVal = value.getBytes;
Uid.List uids= Uid.List.parseFrom(byteVal); 
int count = uids.getUIDCount(); 
for (int i = 0; i< count; i++){ 
    String uidStr = uids.getUID(i).toString();
    system.out.println(uidStr);
}

只要在 protobuf 构建列表之前正确清理列表中的 UID,此代码就可以工作。如果数据中有字符(例如 unicode nulls)被 protobuf 用作列表格式的一部分,那么在解析数据时,它将会中断,因为数据字符将被识别为格式字符t 正确匹配数据模式。我将首先查看您的数据,并确保它符合您想要实现的数据质量和清洁度标准。

于 2014-06-13T15:09:50.133 回答