用户登录
用户注册

分享至

hadoop 多个mapreduce

  • 作者: 银白色
  • 来源: 51数据库
  • 2020-10-03
hadoop mapreduce 可以处理多个文件
NI Measurement Studio 2010~2013 的版本才支持 VS2010 我装了个D版的 NI Measurement Studio 2013 但只支持C# 和 vb的 Measurement Studio 工程,没有VC++的,据说只有买正版的软件客服才会提供支持VC++的包。这个并没有哪个比哪个好的问题,这三个面向的用户群不同。根据NI官方的定义和解释: LabVIEW是一个公认的集成式开发环境,它以图形化的方式连接测量和控制硬件、分析数据、 呈现结果并发布系统。



  尽量在写mapreduce程序处理日志时,需要解析json配置文件,简化java程序和处理逻辑。但是hadoop本身似乎没有内置对json文件的解析功能,我们不得不求助于第三方json工具包。这里选择json-simple实现我们的功能。
在hadoop上执行java程序的命令如下所示:
[hadoop@localhost]$ hadoop jar my-mapreduce.jar
my-mapreduce.jar是我们进行日志处理的mapreduce程序。现在假定我们需要在其中处理json格式的配置文件,这里忽略如何在hadoop集群读取文件的细节,只关注如何使用json工具包。下面是简单的helloworld程序:
import org.json.simple.jsonobject;
public class helloworld{
public static void main(string[] args){
jsonobject obj=new jsonobject();
obj.put("name","foo");
obj.put("num",new integer(100));
obj.put("balance",new double(1000.21));
obj.put("is_vip",new boolean(true));
obj.put("nickname",null);
system.out.print(obj);
}
}
在helloworld程序中,只简单修改json对象,将其内容打印输出,从而验证解析修改json内容的过程。
编译:
由于mapreduce程序需提交到hadoop集群执行,所以helloworld依赖的json-simple包必须存在于集群的classpath路径中,如果集群上没有对应的jar包。执行helloworld会出现如下异常:
exception in thread "main" java.lang.noclassdeffounderror: org/json/simple/jsonobject
简单的解决方法是将json-simple包直接和helloworld编译结果一起打包,然后即可使用命令hadoop jar helloworld.jar执行。需将json-simple的jar包解压再同helloworld打包。
编译命令如下所示:
[hadoop@localhost]$ jar tf json-simple-1.1.1.jar
meta-inf/manifest.mf
meta-inf/
meta-inf/maven/
meta-inf/maven/com.googlecode.json-simple/
meta-inf/maven/com.googlecode.json-simple/json-simple/
meta-inf/maven/com.googlecode.json-simple/json-simple/pom.properties
meta-inf/maven/com.googlecode.json-simple/json-simple/pom.xml
org/
org/json/
org/json/simple/
org/json/simple/itemlist.class
org/json/simple/jsonarray.class
org/json/simple/jsonaware.class
org/json/simple/jsonobject.class
org/json/simple/jsonstreamaware.class
org/json/simple/jsonvalue.class
org/json/simple/parser/
org/json/simple/parser/containerfactory.class
org/json/simple/parser/contenthandler.class
org/json/simple/parser/jsonparser.class
org/json/simple/parser/parseexception.class
org/json/simple/parser/yylex.class
org/json/simple/parser/yytoken.class
[hadoop@localhost]$ unzip json-simple-1.1.1.jar
[hadoop@localhost]$ javac -classpath ./json-simple-1.1.1.jar helloworld.java
[hadoop@localhost]$ jar -cfe helloworld.jar helloworld helloworld.class ./org/
执行helloworld
[hadoop@localhost]$ hadoop jar helloworld.jar
{"balance":1000.21,"num":100,"nickname":null,"is_vip":true,"name":"foo"}
软件
前端设计
程序设计
Java相关