Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Accumulo, mail # user - Question About Table Design in User Manual


Copy link to this message
-
Re: Question About Table Design in User Manual
Josh Elser 2012-02-23, 03:39
On 2/22/2012 9:50 PM, David Medinets wrote:
> At the start of the Table Design chapter created from the svn trunk, I
> see this code:
>
> Mutation m = new Mutation(new Text(userid));
> m.put(new Text("age"), age);
> m.put(new Text("address"), address);
>
> However, when I try to write working code, I need to use this:
>
> Mutation m = new Mutation(new Text("medined"));
> m.put(new Text("age"), new Text("COLFAMILY"), 48, new Value(new
> Integer(age).toString().getBytes()));
> m.put(new Text("height"), new Text("COLFAMILY"), 49, new Value(new
> Integer(height).toString().getBytes()));
I think you have one too many arguments to put(). Either of the
following would make sense to me:

1)
Mutation m = new Mutation(new Text("medined"));
m.put(new Text("age"), new Text(""), new Value(new Integer(age).toString().getBytes()));
m.put(new Text("height"), new Text(""), new Value(new Integer(height).toString().getBytes()));

2)
Mutation m = new Mutation(new Text("medined"));
m.put(new Text("age"), 48, new Value("".getBytes()));
m.put(new Text("height"), 49, new Value("".getBytes()));

Which is correct? IMO, it comes down to what is appropriate for how you
want to structure your data (read as, how you want to fetch your data).
Accumulo is very non-rigid when it comes to how you store you data in
the Key/Value format.
> In the code in the user manual intended to be pseudo-code? Is there a
> version of put that provides a default column family? Does it make
> sense to provide alternate constructors for a Value object?
Accumulo doesn't have a concept of a default column family, so no to
that. I believe the original semantics of the Value class was meant to
be a simple byte array container, being why there is no String
convenience constructor You can easily put the bytes of a String in the
Value; however, you could also do fancy things like put serialized data
structures inside the Value.
> I also see this code in the Table Design chapter which I don't find
> when looking at actual code. Maybe this line should be removed. At
> this stage of the chapter, simply creating the Mutation is good
> enough?
>
> writer.add(m);
A Mutation is simply a local object which encapsulates Key/Values to be
written to Accumulo. Simply instantiating Mutations (as above) does not
insert them into Accumulo. You need to write the Mutation into a
BatchWriter; that line is necessary.

  - Josh