首页 \ 问答 \ MapReduce与Hadoop:类型不匹配(MapReduce with Hadoop: Type mismatch)

MapReduce与Hadoop:类型不匹配(MapReduce with Hadoop: Type mismatch)

我正在运行一个简单的hadoop程序,我收到以下错误:

java.io.IOException: Type mismatch in key from map: expected org.apache.hadoop.io.Text, recieved org.apache.hadoop.io.LongWritable

制图员:

public static class myMapper extends Mapper<LongWritable, Text, Text, Text>
public void map(LongWritable key, Text line,OutputCollector<Text,Text> output, Reporter reporter) throws IOException, InterruptedException

减速器:

public static class triangleCounterReducer extends Reducer<Text, Text, Text, Text> 
public void reduce(Text key,Iterable<Text> line,OutputCollector<Text,Text> output,Reporter reporter) throws IOException, InterruptedException

主要:

...
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
...

我怎样才能解决这个问题????


I'm running a simple hadoop program, and I get the following error:

java.io.IOException: Type mismatch in key from map: expected org.apache.hadoop.io.Text, recieved org.apache.hadoop.io.LongWritable

Mapper:

public static class myMapper extends Mapper<LongWritable, Text, Text, Text>
public void map(LongWritable key, Text line,OutputCollector<Text,Text> output, Reporter reporter) throws IOException, InterruptedException

Reducer:

public static class triangleCounterReducer extends Reducer<Text, Text, Text, Text> 
public void reduce(Text key,Iterable<Text> line,OutputCollector<Text,Text> output,Reporter reporter) throws IOException, InterruptedException

Main:

...
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
...

How can i fix this????


原文:https://stackoverflow.com/questions/14665711
更新时间:2023-08-09 09:08

最满意答案

尝试在{之前但在{之前删除分号。

改变这个:

for(int x = 1; x <= 20; x++); {

对此:

for(int x = 1; x <= 20; x++) {

; 结束for循环。 你在代码中所做的是有一个完整的for循环,后跟一个不相关的代码块。 x仅在for循环的范围内可见,这意味着该错误的分号。


Try removing the semicolon after for but before the {.

Change this:

for(int x = 1; x <= 20; x++); {

to this:

for(int x = 1; x <= 20; x++) {

The ; ends the for loop. What you have done in your code is have a complete for loop followed by an unrelated block of code. The x is only visible within the scope of the for loop, which means up to that errant semicolon.

相关问答

更多
  • 如果我们假设您将'效率'视为运行时间 (与其他措施,例如击键次数,例如),那么您最初拥有的效率就像它获得的那样高效: if($var == $var1 || $var == $var2) 条件运算符|| 和&& 短路时它们可以,这意味着如果$var恰好等于$var1 ,那么与$var2的比较将永远不会发生。 如果你开始有很多条件,你只是想保持你的代码干净,你可以将所有可能的值存储在一个数组中,并检查$var是否在数组中: $possibleVals = array( 1, 2, 3 ); $var = 1 ...
  • ruby编译器非常清楚这个,它没有想到你的孤独:在第4行的author.rb 。它显然不是有效的ruby,你应该按照validates_presence_of的文档 。 这条线应该简单地说 validates_presence_of :first_name, :last_name The ruby compiler is exceptionally clear on this one, it did not expect your solitary : in author.rb on line 4. It ...
  • 这在功能上等同于您的代码在一行中: msgbox % var ~= "^(abc|def|ghi)$" ? "Yes" : "No" This is functionally equivalent to your code in one line: msgbox % var ~= "^(abc|def|ghi)$" ? "Yes" : "No"
  • 尝试在{之前但在{之前删除分号。 改变这个: for(int x = 1; x <= 20; x++); { 对此: for(int x = 1; x <= 20; x++) { 的; 结束for循环。 你在代码中所做的是有一个完整的for循环,后跟一个不相关的代码块。 x仅在for循环的范围内可见,这意味着该错误的分号。 Try removing the semicolon after for but before the {. Change this: for(int x = 1; x <= 20; x ...
  • 使用var真的很糟糕吗? 我应该在我的库中转换响应,以便他可以在他的应用程序中明确键入它吗? 在我看来,我宁愿使用var并节省一些时间然后花40分钟尝试去明确。 在C#中, var只是一个编译器“技巧”。 没有涉及动态类型,编译的代码完全相同。 将鼠标悬停在变量上时,IDE将告诉您使用的“真实”类型。 无论他使用var还是实际的返回类型,在创建库的方面都不重要。 如果您的图书馆不必要地返回dynamic ,这可能是一个不同的问题,并且用户可能有有效的投诉。 与var (仅仅是编译时技巧)不同, dynami ...
  • 代替: var result; 使用db.Jobs.FindAll返回的实际类型: IEnumerable result; Instead of: var result; Use the actual type returned by db.Jobs.FindAll: IEnumerable result;
  • 你的代码片段看起来更像是一个错误,而不是代码风格的例子。 我会假设你的意思是: $('.element').each(function () { var $this = $(this); ... }); 是的,这是完全可以接受的。 正如你可以在这里看到的 : 变量名称必须以字母开头 变量名称也可以以$和_(1)开头(但我们不会使用它) 现在,就目标而言:这是一个可读性问题 - 许多使用jQuery的人发现,使用$name前缀他们的jQuery对象变量更容易阅读。 例如,这使得更容易一眼看出什么是j ...
  • !var等价于var==NULL 。 因此,您的第一个测试检查if (var == NULL) 。 你的第二个测试检查与此相反的结果,所以给出了相反的结果。 这种行为! 运算符在C11中描述6.5.3.3一元算术运算符 p5 逻辑否定运算符的结果! 如果其操作数的值不等于0,则为0;如果操作数的值等于0,则为1。 !var is equivalent to var==NULL. Your first test therefore checks if (var == NULL). Your second te ...
  • 您希望使用Popen进行communicate ,如文档中所述: >>> from subprocess import * >>> Popen(['echo', 'Hi'], stdout=PIPE).communicate()[0] 'Hi\n' You want to use Popen with communicate, as described in the docs: >>> from subprocess import * >>> Popen(['echo', 'Hi'], stdout=PI ...
  • Fordi der er en typo i din kode。 var locations = locations; 本来应该的 var locations = location; Þegarþúskilgreinirstaðsetningarsemvarstaðsetningar var locations = locations; ,首先评估右侧页面,它是undefined (因为它尚未初始化)。 因此, undefined将分配给locations 。 调用Object.keys , locat ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。