我有一个文件,其中包含由复合分隔符分隔的压缩数据(~~#&#&#~~) 我正在尝试创建一个映射器来读取文件中的记录并处理它们。
我写了一个Mapper类,比如
在Split循环中,我为每个分割记录打印前20个字符但是没有按预期看到数据。我猜斯普利特没有采用它。
可以帮助一些人。
我一直在尝试使用Text和String或Text和BytesWritable之间的转换技术数量......但似乎没有任何工作。
import java.io.IOException;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
public class DeSerializeMapper extends MapReduceBase
implements Mapper
{
public void map(LongWritable key, Text value, OutputCollector output, Reporter reporter) throws IOException
{
String allRec = value.toString();
for (String recStr : allRec.split("~~#&#&#~~"))
{
try
{
System.out.println("DEBUG ::::::::::::::::::::::::::Before calling SubstringIn : " + recStr.substring(0,20));
output.collect(new Text(recStr), new Text(getOutputString(recStr)));
}catch(Exception e){
e.printStackTrace();
throw new IOException("Failed in map", e);
}
}
}
public static String getOutputString(String recStr) throws Exception
{
try {
dosomething();
return (lineBuffer);
} catch(Exception e){
e.printStackTrace();
throw new Exception("Failed in readFile", e);
}
}
}
答案 0 :(得分:0)
请记住,在MR代码中添加时,您的System.out.println()
语句不会出现在控制台上。它们将附加到MR作业系统日志中。
要查看System.out.println()
语句,请访问JobTracker页面(主要在端口50030上运行),转到已执行的特定MR作业,然后检查映射任务日志。您会在 stdout logs (如果有)下找到System.out.println()
语句。