You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by "W.P. McNeill" <bi...@gmail.com> on 2011/04/18 23:11:34 UTC
How do I serialize a MapWritable value?
I have a reducer that outputs pairs of the form <Text, MapWritable>. The
MapWritable is a map from Text to Long. The key and output values of my
reducer are declared like so:
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(MapWritable.class);
The last few lines of my reducer look like this:
MapWritable value = new MapWritable();
for (Map.Entry<String, Long> entry : totalWordCount.entrySet())
value.put(new Text(entry.getKey()), new
LongWritable(entry.getValue()));
context.write(key, value);
In the debugger I can see that my MapWritable value is a map with the values
I expect it to contain. However, when I run the MapReduce process the
output literally looks like this:
key1 org.apache.hadoop.io.MapWritable@396cbd97
key2 org.apache.hadoop.io.MapWritable@17991de1
key3 org.apache.hadoop.io.MapWritable@18f63055
The values are descriptive stringifications of the MapWritable class without
any data. What I want instead are serializations of the maps that contain
their data. I thought the point of the MapWritable class was that it handled
serialization for you. Is there a step I'm missing?
Re: How do I serialize a MapWritable value?
Posted by Marcos M Rubinelli <ma...@buscape-inc.com>.
MapWritable works if you use a binary format like
SequenceFileOutputFormat. If you need a plain text output, you can use a
library like Jackson to generate a string representation -- or look for
a custom OutputFormat that already does that for you.
> I have a reducer that outputs pairs of the form<Text, MapWritable>. The
> MapWritable is a map from Text to Long. The key and output values of my
> reducer are declared like so:
>
> job.setOutputKeyClass(Text.class);
> job.setOutputValueClass(MapWritable.class);
>
> The last few lines of my reducer look like this:
>
> MapWritable value = new MapWritable();
> for (Map.Entry<String, Long> entry : totalWordCount.entrySet())
> value.put(new Text(entry.getKey()), new
> LongWritable(entry.getValue()));
> context.write(key, value);
>
> In the debugger I can see that my MapWritable value is a map with the values
> I expect it to contain. However, when I run the MapReduce process the
> output literally looks like this:
>
> key1 org.apache.hadoop.io.MapWritable@396cbd97
> key2 org.apache.hadoop.io.MapWritable@17991de1
> key3 org.apache.hadoop.io.MapWritable@18f63055
>
> The values are descriptive stringifications of the MapWritable class without
> any data. What I want instead are serializations of the maps that contain
> their data. I thought the point of the MapWritable class was that it handled
> serialization for you. Is there a step I'm missing?
Cheers,
Marcos
--
------------------------------------------------------------------------
Marcos Medrado Rubinelli
EstatĂstica - Comparison Shopping - BuscaPĂ©