将MapWritable转换为Hadoop中的字符串

时间:2014-04-22 02:09:28

标签: hadoop

当我使用toString()方法运行输出时,我得到了:

#zombie org.apache.hadoop.io.MapWritable@b779f586
#zombies        org.apache.hadoop.io.MapWritable@c8008ef9
#zona   org.apache.hadoop.io.MapWritable@99e061a1
#zoology        org.apache.hadoop.io.MapWritable@9d0060be
#zzp    org.apache.hadoop.io.MapWritable@3e52c108

这是我的reducer代码,我怎样才能将地图值打印出来呢?

package sample;

import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.MapWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.Reducer;

public class IntSumReducer 
extends Reducer<Text,MapWritable,Text,MapWritable> {
private MapWritable result = new MapWritable();
String temp = "";
public void reduce(Text key, Iterable<MapWritable> values, Context context)throws IOException, InterruptedException {
    result.clear();
    for (MapWritable val : values) {
        Iterable<Writable> keys = val.keySet();
        for (Writable k : keys) {
            IntWritable tally = (IntWritable) val.get(k);
            if (result.containsKey(k)) {
                IntWritable tallies = (IntWritable) result.get(k);
                tallies.set(tallies.get() + tally.get());
                temp = toString() + " : " + tallies.get();
                result.put(new Text(temp), tallies);
            } else {
                temp = k.toString() + " : " + tally.get();
                result.put(new Text(temp), tally);
            }
         }
    }
    context.write(key, result);
}
}

感谢您的帮助

2 个答案:

答案 0 :(得分:2)

添加这样的类应该有效:

  var player: SKSpriteNode = SKSpriteNode(imageNamed: "player1.png")

然后这样称呼它:

<html>
<?php
$homepage = file_get_contents('https://auspuff-schuelerzeitung.de/');
echo $homepage; //you can strip the closing <html> if it bothers..
?>
<link rel='stylesheet' href='my_changes.css' type='text/css'/>


</html>

答案 1 :(得分:0)

您的resultMapWritable,并且在MapWritable中未覆盖toString()方法。 您可以创建扩展MapWritable的新类,并在其中创建自己的toString()方法。 之后将代码更改为:

public class IntSumReducer extends Reducer<Text,MapWritable,Text,YourMapWritable> {
  private YourMapWritable result = new YourMapWritable();
  String temp = "";
  ...