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!

Chris Rigano
  • 687
  • 1
  • 11
  • 23
  • 1
    What is `while (counter <= counter)` meant to do? (And why do you not actually have a closing bracket?) – Jon Skeet Jun 12 '14 at 20:45
  • It should read:while (counter <= counter{ String uidStr = uids.getUID(counter).toString(); system.out.println(uidStr); } – Chris Rigano Jun 13 '14 at 01:24
  • Can you edit your post? Is that even valid syntax? – FuriousGeorge Jun 13 '14 at 01:29
  • The counter uses an index to got through the list [1], [2], I was grappling for something so I tried Uid.List.parseFrom to try to read the Uid.List I wrote into a Accumulo value out as a list and then tried to get each item of the list I read out of the accumulo value out individually using uids.getUID(counter).toString(); It was a desperate attempt to read the list and access uids. I appreciate advice on the right approach. Thanks Job, Chris – Chris Rigano Jun 13 '14 at 01:30
  • Hi user1146334, I corrected the syntax. It is just code segments. I am trying to write protobuf Uid.List to Accumulo Value (seems to work) and I have an example; I failed to read the Uid.List out and gave an example of my failed attempt. – Chris Rigano Jun 13 '14 at 02:13
  • You've corrected the syntax, but it's still a pointless loop condition, and you haven't declared `counter`. It would really help if you'd give us a short but *complete* program demonstrating the problem (and a link to the protos you're using). – Jon Skeet Jun 13 '14 at 06:03

1 Answers1

0

I would suggest changing the second bit of code to something along the lines of:

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);
}

This code does work as long as the UIDs in your list are properly cleaned before the list is built by protobuf. If you have characters within the data (such as unicode nulls) that are used by protobuf as part of the list format then, when parsing the data back out, it is going to break because data characters will be recognized as format characters that don't properly match the data schema. I would start by taking a look at your data and ensuring that it meets data quality and cleanliness standards for what you are trying to achieve.