On Tue, Nov 13, 2012 at 1:00 PM, David Medinets
<[email protected]> wrote:
> The following code (the TextTest class) displays:
>
> cq: [5000000000000000]
> cq: [16]
> cq: [16]
> cq: [5000000000000000]
> cq: [16]
> cq: [17]
>
> You'll notice that the last two numbers are different, but they should
> both be 16. This bug affects Accumulo because of the following code in

Its ok that its 17.  The byte array text uses may be longer than the
data.  Thats why its important to use Text.getLength()

> Mutation:
>
>   private void put(byte b[]) {
>     buffer.writeVLong(b.length);
>     buffer.add(b, 0, b.length);
>   }
>
>   private void put(Text t) {
>     buffer.writeVLong(t.getLength());
>     buffer.add(t.getBytes(), 0, t.getLength());
>   }
>
> I should be able to call either of the following to get the same
> result but I can't.
>
>   put("5000000000000000".getBytes());
>   put(new Text("5000000000000000"));
>
> Has anyone else run into this issue? Any workarounds or fixes?
>
> ----
>
> package com.codebits.accumulo;
>
> import org.apache.hadoop.io.Text;
>
> public class TextTest {
>
>   public static void main(String[] args) {
>     String s = "5000000000000000";
>     System.out.println("cq: [" + s + "]");
>     System.out.println("cq: [" + s.length() + "]");
>     System.out.println("cq: [" + s.getBytes().length + "]");
>
>     Text cq = new Text(s);
>     System.out.println("cq: [" + cq + "]");
>     System.out.println("cq: [" + cq.getLength() + "]");
>     System.out.println("cq: [" + cq.getBytes().length + "]");
>   }
>
> }

Reply via email to