hadoop MultipleInputs fails with ClassCastException (get fileName)

 

来自:http://stackoverflow.com/questions/11130145/hadoop-multipleinputs-fails-with-classcastexception

 

Following up on my comment, the Javadocs for TaggedInputSplit confirms that you are probably wrongly casting the input split to a FileSplit:

/*** An {@link InputSplit} that tags another InputSplit with extra data for use* by {@link DelegatingInputFormat}s and {@link DelegatingMapper}s.*/

My guess is your setup method looks something like this:

@Override
protected void setup(Context context) throws IOException,InterruptedException {FileSplit split = (FileSplit) context.getInputSplit();
}

Unfortunately TaggedInputSplit is not public visible, so you can't easily do an instanceof style check, followed by a cast and then call to TaggedInputSplit.getInputSplit() to get the actual underlying FileSplit. So either you'll need to update the source yourself and re-compile&deploy, post a JIRA ticket to ask this to be fixed in future version (if it already hasn't been actioned in 2+) or perform some nasty nasty reflection hackery to get to the underlying InputSplit

This is completely untested:

@Override
protected void setup(Context context) throws IOException,InterruptedException {InputSplit split = context.getInputSplit();Class<? extends InputSplit> splitClass = split.getClass();FileSplit fileSplit = null;if (splitClass.equals(FileSplit.class)) {fileSplit = (FileSplit) split;} else if (splitClass.getName().equals("org.apache.hadoop.mapreduce.lib.input.TaggedInputSplit")) {// begin reflection hackery...try {Method getInputSplitMethod = splitClass.getDeclaredMethod("getInputSplit");getInputSplitMethod.setAccessible(true);fileSplit = (FileSplit) getInputSplitMethod.invoke(split);} catch (Exception e) {// wrap and re-throw errorthrow new IOException(e);}// end reflection hackery}
}

Reflection Hackery Explained:

With TaggedInputSplit being declared protected scope, it's not visible to classes outside the org.apache.hadoop.mapreduce.lib.input package, and therefore you cannot reference that class in your setup method. To get around this, we perform a number of reflection based operations:

  1. Inspecting the class name, we can test for the type TaggedInputSplit using it's fully qualified name

    splitClass.getName().equals("org.apache.hadoop.mapreduce.lib.input.TaggedInputSplit")

  2. We know we want to call the TaggedInputSplit.getInputSplit() method to recover the wrapped input split, so we utilize the Class.getMethod(..) reflection method to acquire a reference to the method:

    Method getInputSplitMethod = splitClass.getDeclaredMethod("getInputSplit");

  3. The class still isn't public visible so we use the setAccessible(..) method to override this, stopping the security manager from throwing an exception

    getInputSplitMethod.setAccessible(true);

  4. Finally we invoke the method on the reference to the input split and cast the result to a FileSplit (optimistically hoping its a instance of this type!):

    fileSplit = (FileSplit) getInputSplitMethod.invoke(split);

转载于:https://www.cnblogs.com/sunxucool/p/3727200.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/420937.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

自己常用的Linux命令总结

原则&#xff1a;自己使用过的&#xff0c;不易记忆的&#xff0c;功能强大的 grep 名称意义&#xff1a;全称Global Regular Expression Print&#xff0c;表示全局正则表达式是一个强大的文本搜索工具&#xff0c;采用正则匹配命令格式&#xff1a;grep [options] files O…

XSS与CSRF两种跨站攻击比较

XSS&#xff1a;跨站脚本&#xff08;Cross-site scripting&#xff09; CSRF&#xff1a;跨站请求伪造&#xff08;Cross-site request forgery&#xff09; 在那个年代&#xff0c;大家一般用拼接字符串的方式来构造动态SQL 语句创建应用&#xff0c;于是SQL 注入成了很流行的…

褚时健:现在的年轻人太急了,我快90了还在摸爬滚打

转自&#xff1a;http://news.163.com/17/0715/08/CPCF0D6R00018AOR.html &#xff08;本人说明&#xff1a;这篇访谈太“鸡汤”了&#xff0c;我读了好几遍&#xff0c;里面精彩的部分我用红字标出来了&#xff0c;感觉褚时健老前辈的精神和做事的态度方法真的值得学习&#…

Java日期格式化SimpleDateFormat

package test;import java.text.SimpleDateFormat; import java.util.Date;public class TestDate {public static void main(String[] args) {// 大写的HH是24小时 小写的是12小时SimpleDateFormat sdf new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date d null;…

VS或编译的时候不生成Release文件夹

今天在编译第三方类的时候&#xff0c;总是发布的时候报没有第三方类库的的Release版本 解决方案&#xff1a; Build>Configuration Manager>Release 编译》配置管理》选择发布版本 再编译就有了转载于:https://www.cnblogs.com/flyfish2012/p/3728516.html

el表达式,c标签的使用

el表达式的使用 学生类 public class Student {int id;String name;String sex;String birth;public Student() {}public Student(int id, String name, String sex, String birth) {super();this.id id;this.name name;this.sex sex;this.birth birth;}// el 表达式取实…

conda虚拟环境中安装ipython

问题&#xff1a;今天安装了tensorflow&#xff0c;启动ipython竟然提示如下&#xff1a; In [1]: import tensorflow as tf --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recen…

Web前端行业的了解

即将从事Web前端的工作的 先对即将从事的行业有个了解。 Web前端发展史&#xff1a; 第一个网页诞生于90年代初&#xff0c;早期的网页除了一些小图片和毫无布局可言的标题段落&#xff0c;其全由文字构成。然而随着时代的进步&#xff0c;互联网的 不断发展&#xff0c;接下来…

使用session保持登录状态,cookie保存用户账号密码

session保存登录状态与cookie保存账号密码1. session维持登录状态1.1 代码实现2. cookie保存账号密码2.1 什么是cookie2.2 cookie记住账号密码1. session维持登录状态 利用session的生命周期实现 1.1 代码实现 login页面表单部分 <form action"judgeLoginSession&qu…

用conda安装虚拟的R环境

R语言能不能像python一样创建虚拟环境&#xff0c;今天探索了这个问题&#xff0c;用如下方式。 1、建立一个python虚拟环境 conda create -n R_env python3.7 2、在R_env中安装R语言 conda install R 3、在R_env中安装Rstudio conda install rstudio 4、启动Rstudio成功…

js表单验证,给出友好的提示

js验证表单 注意&#xff1a; 只做非空验证, 只是个小demo学习思想&#xff0c;onblur onfocus onsubmit的使用&#xff0c;给出友好提示网上有很多有良好&#xff0c;强大的控件&#xff0c;用于用户输入 代码实现 js代码 <script>function check_form(form) {// 得到f…

conda安装特定版本的包

conda search python /*python 3.3.1 0 anaconda/pkgs/free*/ conda install python3.3.1 即是安装了python3.3.1

项目开发问题

开发过程中才用Gearman做后台计算&#xff0c;node做socket连接服务器和数据传输及基本验证&#xff0c;Gearman通过接收Action和参数后将相应的结果回调给node&#xff1b;node负责接收前端发送的action和参数给Gearman&#xff0c;并将Gearman计算的结果推送给前端&#xff0…

注册demo,使用jQuery异步验证账号是否存在

功能 jQuery验证账号是否存在form表单提交判断&#xff0c;失焦判断 界面 Ajax代码&#xff0c;验证用户rye1是否存在 function check_UserId() {$userId $("#userId").val();$.post("checkUserId","userId" $userId,function (result) { // 异…

虚拟机的网络连接模式

本文参考文章如下&#xff0c;感谢原作者&#xff1a; 《虚拟机的桥接模式和NAT模式》 https://blog.csdn.net/qq_40198004/article/details/89785806 1、桥接模式 桥接模式:直接连接物理网络&#xff0c;也就是连的你交换机的网络和你主机的IP在一个网段上&#xff0c;将虚拟…

自考感悟,话谈备忘录模式

引言&#xff1a; 2014年4月20号上午11:30&#xff0c;正式结束了自己的自学考试&#xff01;考完之后瞬间感觉放松了开来&#xff01;全身无力则是自己20号下午的唯一感受。放松了半天&#xff0c;今天回归正轨&#xff01;又回到了和生活息息相关的设计模式上来&#xff01;今…

小白教你用Java生成验证码

验证码生成效果一&#xff0c;生成验证码二&#xff0c;页面收到验证码三&#xff0c;验证验证码是否填写正确效果 点击验证码可切换 给出提示 一&#xff0c;生成验证码 package servlet;import java.io.IOException;import javax.servlet.ServletException; import jav…

modbus rtu 协议转DLT645-2007和DLT645-1997电表协议转换器定制,

现场会碰到现场数据为Modbus协议&#xff0c;但是后台系统为DLT645协议系统&#xff0c;本模块支持将工业ModbusRtu协议转换为电表国标协议DLT645协议&#xff0c;支持1997和2007俩种标准&#xff0c;只需要进行简单的配置&#xff0c;就可以实现Modbus 协议转DLT645协议&#…

关于pycharm deployment消失的问题

settings --> Appearance --> Menus and Toolbars 点开Tools文件夹&#xff0c;选中Tools中的一个子文件夹&#xff08;Deployment就放在了这个工具后面了&#xff09; 点击上面的号&#xff0c;选择choose action to add 搜索deployment&#xff0c;找到Deployment文…