Mapper类如何将SequenceFile标识为hadoop中的输入文件?(How does Mapper class identify the SequenceFile as inputfile in hadoop?)
在我的一个MapReduce任务中,我将BytesWritable重写为KeyBytesWritable,并将ByteWritable重写为ValueBytesWritable。 然后我使用SequenceFileOutputFormat输出结果。
我的问题是当我开始下一个MapReduce任务时,我想使用这个SequenceFile作为输入文件。 那么我怎样才能设置工作类,以及Mapper类如何识别我之前被覆盖的SequenceFile中的键和值?
我明白我可以使用SequenceFile.Reader来读取关键字和值。
Configuration config = new Configuration(); Path path = new Path(PATH_TO_YOUR_FILE); SequenceFile.Reader reader = new SequenceFile.Reader(FileSystem.get(config), path, config); WritableComparable key = (WritableComparable) reader.getKeyClass().newInstance(); Writable value = (Writable) reader.getValueClass().newInstance(); while (reader.next(key, value))
但是我不知道如何使用这个Reader将键和值作为参数传递给Mapper类。 我怎样才能将Conf.setInputFormat设置为SequenceFileInputFormat,然后让Mapper获得关键字和值?
谢谢
In my one MapReduce task, I override the BytesWritable as KeyBytesWritable, and override the ByteWritable as ValueBytesWritable. Then I output the result using SequenceFileOutputFormat.
My question is when I start the next MapReduce task, I want to use this SequenceFile as inputfile. So how could I set the jobclass, and how the Mapper class could identify the key and value in the SequenceFile which I overrided before?
I understand that I could SequenceFile.Reader to read the key and value.
Configuration config = new Configuration(); Path path = new Path(PATH_TO_YOUR_FILE); SequenceFile.Reader reader = new SequenceFile.Reader(FileSystem.get(config), path, config); WritableComparable key = (WritableComparable) reader.getKeyClass().newInstance(); Writable value = (Writable) reader.getValueClass().newInstance(); while (reader.next(key, value))
But I don't know how to use this Reader to pass the key and value into Mapper class as Parameters. How could I set conf.setInputFormat to SequenceFileInputFormat and then let Mapper get the key and values?
Thanks
原文:https://stackoverflow.com/questions/15179456
最满意答案
您可以调用
Type.GetType
方法来获取具有给定(程序集限定)名称的Type
对象。您可以调用
Activator.CreateInstance
方法来创建类型的实例。 (假设该类型具有公共默认构造函数,或者您知道它采用的构造函数参数)。例如:
Activator.CreateInstance(Type.GetType(name));
You can call the
Type.GetType
method to get aType
object with the given (assembly-qualified) name.You can call the
Activator.CreateInstance
method to create an instance of a type. (assuming that the type has a public default constructor, or that you know what constructor arguments it takes).For example:
Activator.CreateInstance(Type.GetType(name));
相关问答
更多-
如何在.NET中传递字符串?(How are strings passed in .NET?)[2021-08-31]
要回答您的问题,请考虑以下代码: void Main() { string strMain = "main"; DoSomething(strMain); Console.Write(strMain); // What gets printed? } void DoSomething(string strLocal) { strLocal = "local"; } 你需要知道三件事来预测这里会发生什么,并了解它为什么会这样做。 字符串是C#中的引用类型。 但这只是图片的一部 ... -
您想在.NET平台内运行这些语言的程序吗? 你需要IronPython或IronRuby(我觉得像IronPerl这样的东西不存在)。 如果你想运行“普通”Python / Ruby / Perl / Java程序,那么是的,你需要安装Python解释器,Ruby解释器,Perl解释器和Java VM。 Do you want to run programs in these languages inside the .NET platform? You'd need IronPython or IronR ...
-
您可以调用Type.GetType方法来获取具有给定(程序集限定)名称的Type对象。 您可以调用Activator.CreateInstance方法来创建类型的实例。 (假设该类型具有公共默认构造函数,或者您知道它采用的构造函数参数)。 例如: Activator.CreateInstance(Type.GetType(name)); You can call the Type.GetType method to get a Type object with the given (assembly-qu ...
-
在有关向Windows发送消息的主题中查看我的帖子 。 通过使用此类API函数,您可以轻松控制或更改其他窗口。 常见的例子是最大化另一个窗口,最小化另一个窗口,从视图中隐藏另一个窗口,抓住另一个窗口并将其放置在您自己的窗口(设置其父窗口)中,改变另一个窗口的标题,改变另一个窗口的文本框中的文本(等等, )将键击和鼠标点击发送到窗口(或其中一个按钮),在另一个窗口中运行菜单等。 See my post in a thread about sending messages to windows. With th ...
-
您可以使用DataBinder.Eval动态计算路径表达式(尽管这将意味着向System.Web添加依赖项): http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx C#示例: using System; using System.Web.UI; namespace DataBinderEval { internal class Program { private static void Main() { ...
-
调试卡住了程序(Debugging stuck go programs)[2021-11-16]
这是司机的问题。 通过删除延迟调用并检查数组边界来修复它。 This was a issue with the driver. Fixed it by removing the defer call & checking the array bounds. -
在.NET中提取字符串(Extracting strings in .NET)[2022-02-07]
使用lookahead和lookbehind断言有另一种正则表达式方法来实现这一点: Regex regex = new Regex("(?<=Args\\(\").*?(?=\"\\))"); string input = "Args(\"token1\") + Args(\"token2\")"; MatchCollection matches = regex.Matches(input); foreach (var match in matches) { ... -
WCF(Windows Communication Foundation)就是你想要的。 WCF (Windows Communication Foundation) is what you want.
-
正如cnicutar所说使用net.ParseCIDR 。 这是一个关于如何实际使用它的工作示例。 http://play.golang.org/p/Wtqy56LS2Y package main import ( "fmt" "net" ) func main() { ipList := []string{"192.168.1.1/24", "fd04:3e42:4a4e:3381::/64"} for i := 0; i < len(ipList); i += 1 { ...
-
创建一个能够存储所有可能的数字格式的自定义类: class ParsedNumber { NumberType Type; //Integer, FloatingPoint, Decimal BigInteger Integer; double FolatingPoint; decimal Decimal; } 该类应该可以实现相等和比较运算符。 您可以将每个单元格解析为此类的实例。 该类应该抽象不同的格式,以便您可以将其视为一个数字。 您还可以将此结构化为保存堆分配。 Create a cust ...