MapReduce是一种数据处理思想,最早由Google的Jeff Dean等人发明,论文公开后,由Yahoo!的Doug Cutting实现了开源版本的MapReduce实现,发展为后来的Hadoop
Hadoop包含一个开源的MapReduce计算框架,和一个分布式文件系统:HDFS
MapReduce的精髓是并行处理、移动程序比移动数据更划算
你如果只是做一些简单的统计(如SQL中的count, group by, order by, avg, max, min等),Hive会更适合你,当你把500G都导入hive后,就可以直接在hive的命令行输入SQL(严格的讲,它不是SQL,但真的跟SQL很像很像)来执行你要的查询了
Hive和Pig都是基于Hadoop的数据分析工具,它们都依赖Hadoop,但Hadoop不一定用来做数据分析和统计,比如Google拿它来做Index Building
简介:
尽量在写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"}
Hadoop|
Apache Pig|
Apache Kafka|
Apache Storm|
Impala|
Zookeeper|
SAS|
TensorFlow|
人工智能基础|
Apache Kylin|
Openstack|
Flink|
MapReduce|
大数据|
云计算|
用户登录
还没有账号?立即注册
用户注册
投稿取消
文章分类: |
|
还能输入300字
上传中....