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
最佳答案
Mapper 代码看起来不错。您是否在驱动程序中明确添加了 Output Key 和 Output Value。
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(MinMaxCountTuple.class);
驱动中没有提到的可以试试。
关于java - java中mapreduce编程没有输出值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49569618/
我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
我正在使用puppet为ruby程序提供一组常量。我需要提供一组主机名,我的程序将对其进行迭代。在我之前使用的bash脚本中,我只是将它作为一个puppet变量hosts=>"host1,host2"我将其提供给bash脚本作为HOSTS=显然这对ruby不太适用——我需要它的格式hosts=["host1","host2"]自从phosts和putsmy_array.inspect提供输出["host1","host2"]我希望使用其中之一。不幸的是,我终其一生都无法弄清楚如何让它发挥作用。我尝试了以下各项:我发现某处他们指出我需要在函数调用前放置“function_”……这
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
这是一道面试题,我没有答对,但还是很好奇怎么解。你有N个人的大家庭,分别是1,2,3,...,N岁。你想给你的大家庭拍张照片。所有的家庭成员都排成一排。“我是家里的friend,建议家庭成员安排如下:”1岁的家庭成员坐在这一排的最左边。每两个坐在一起的家庭成员的年龄相差不得超过2岁。输入:整数N,1≤N≤55。输出:摄影师可以拍摄的照片数量。示例->输入:4,输出:4符合条件的数组:[1,2,3,4][1,2,4,3][1,3,2,4][1,3,4,2]另一个例子:输入:5输出:6符合条件的数组:[1,2,3,4,5][1,2,3,5,4][1,2,4,3,5][1,2,4,5,3][
几个月前,我读了一篇关于rubygem的博客文章,它可以通过阅读代码本身来确定编程语言。对于我的生活,我不记得博客或gem的名称。谷歌搜索“ruby编程语言猜测”及其变体也无济于事。有人碰巧知道相关gem的名称吗? 最佳答案 是这个吗:http://github.com/chrislo/sourceclassifier/tree/master 关于ruby-寻找通过阅读代码确定编程语言的rubygem?,我们在StackOverflow上找到一个类似的问题:
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
大家好!我想知道Ruby中未使用语法ClassName.method_name调用的方法是如何工作的。我头脑中的一些是puts、print、gets、chomp。可以在不使用点运算符的情况下调用这些方法。为什么是这样?他们来自哪里?我怎样才能看到这些方法的完整列表? 最佳答案 Kernel中的所有方法都可用于Object类的所有对象或从Object派生的任何类。您可以使用Kernel.instance_methods列出它们。 关于没有类的Ruby方法?,我们在StackOverflow