gpt4 book ai didi

java - java中mapreduce编程没有输出值

转载 作者:可可西里 更新时间:2023-11-01 16:37:16 24 4
gpt4 key购买 nike

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;



public class StubMapper extends Mapper<LongWritable, Text, Text, MinMaxCountTuple> {

private Text outUserId = new Text();
private MinMaxCountTuple outTuple = new MinMaxCountTuple();

private final static SimpleDateFormat frmt =
new SimpleDateFormat("yyyy-MM--dd'T'HH:mm:ss.SSS");

// public static HashMap<String, String> getMapFromCSV(String filePath) throws IOException
// {
//
// HashMap<String, String> words = new HashMap<String, String>();
//
// /*BufferedReader in = new BufferedReader(new FileReader(filePath));
//
// String line;
// //= in.readLine())
// while ((line = in.readLine()) != null) {
// String columns[] = line.split(",");
// if (!words.containsKey(columns[1])) {
// words.put(columns[1], columns[6]);
// }
//
// }
//
// return words;
//
// */
//
//
//
// String line=filePath;
//
// while(line!=null){
//
// String columns[] = line.split(",");
// if (columns.length>6){
// if (!words.containsKey(columns[1])) {
// words.put(columns[1], columns[6]);
// }
// }
//
// }
// return words;
// }

@Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {


// HashMap<String, String> parsed = getMapFromCSV(value.toString());
//String columns[] = value.toString().split("\t");

// String strDate = parsed.get("CheckoutDateTime");

//String userId = columns[1];
//String strDate = columns[6];
if(value.toString().startsWith("BibNumber"))
{
return;
}
// String userId = parsed.get("BibNumber");
String data[] = value.toString().split(",",-1);
String userId = data[0];
String DateTime = data[5];


Date creationDate = frmt.parse(DateTime);

outTuple.setMin(creationDate);
outTuple.setMax(creationDate);

outTuple.setCount(1);

outUserId.set(userId);

context.write(outUserId, outTuple);


// TODO Auto-generated catch block
e.printStackTrace();
}


}
}




import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.hadoop.io.Writable;

public class MinMaxCountTuple implements Writable{

private Date min = new Date();
private Date max = new Date();
private long count = 0;

private final static SimpleDateFormat frmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");

public Date getMin()
{
return min;
}

public void setMin(Date min)
{
this.min = min;
}

public Date getMax()
{
return max;
}

public void setMax(Date max)
{
this.max = max;
}

public long getCount()
{
return count;
}

public void setCount(long count)
{
this.count = count;
}

@Override
public void write(DataOutput out) throws IOException {
// TODO Auto-generated method stub
out.writeLong(min.getTime());
out.writeLong(max.getTime());
out.writeLong(count);
}

public String toString()
{
return frmt.format(min) + "\t" + frmt.format(max) + "\t" + count;
}

@Override
public void readFields(DataInput in) throws IOException {
// TODO Auto-generated method stub
min = new Date(in.readLong());
max = new Date(in.readLong());
count = in.readLong();
}

}

这两个代码是 mapper 类和 minmax 类,它们可以找到最大的 checkoutdate 时间。基本上,我想要做的是获得一些输出,这些输出主要用于租借一本书。所以,我只是在 csv 文件中使用键和值作为 userId 和 checkoutdatetime。代码运行良好,但问题是映射器输入显示了数据的大小,然而,映射器输出的文件大小仅为 0,这意味着它没有从输入中获得一些输出。我不知道哪一部分是错误的。我张贴了我的 csv 文件的屏幕截图。请赐教,不胜感激。谢谢。如果您需要我的代码的更多信息,请告诉我,我会提供更多信息。

18/03/30 01:38:41 INFO mapred.JobClient:     Map input records=3794727
18/03/30 01:38:41 INFO mapred.JobClient: Map output records=0
18/03/30 01:38:41 INFO mapred.JobClient: Map output bytes=0
18/03/30 01:38:41 INFO mapred.JobClient: Input split bytes=416
18/03/30 01:38:41 INFO mapred.JobClient: Combine input records=0
18/03/30 01:38:41 INFO mapred.JobClient: Combine output records=0
18/03/30 01:38:41 INFO mapred.JobClient: Reduce input groups=0
18/03/30 01:38:41 INFO mapred.JobClient: Reduce shuffle bytes=24
18/03/30 01:38:41 INFO mapred.JobClient: Reduce input records=0
18/03/30 01:38:41 INFO mapred.JobClient: Reduce output records=0

enter image description here

最佳答案

Mapper 代码看起来不错。您是否在驱动程序中明确添加了 Output Key 和 Output Value。

job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(MinMaxCountTuple.class);

驱动中没有提到的可以试试。

关于java - java中mapreduce编程没有输出值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49569618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com