当前位置:首页 > PHP教程 > PHP总结归纳

ApacheHive一点一点进步(1)简单介绍

hive是一个 hadoop 的数据仓库,便于对 hadoop 中存储的大数据进行数据汇总,点对点查询,以及分析。 hive提供了一套管理机制用于管理hdfs中的数据及一套类型于sql的查询语言hiveql。 同时当hiveql无法满足逻辑的时候,这种语言支持传统的mr程序,以插件的形

hive是一个hadoop的数据仓库,便于对hadoop中存储的大数据进行数据汇总,点对点查询,以及分析。

hive提供了一套管理机制用于管理hdfs中的数据及一套类型于sql的查询语言hiveql。

同时当hiveql无法满足逻辑的时候,这种语言支持传统的mr程序,以插件的形式集成到hive的mr中。

hive是apache基金会下的一个开源志愿者项目。以前他是一个hadoop的子项目。但是现在他已经升级为一个顶级项目。

安装

requirements java1.6,hadoop0.20.xx选择一个稳定版进行安装 http://hive.apache.org/releases.html解压缩tarball。$ tar -xzvf hive-x.y.z.tar.gz$ cd hive-x.y.z $ export hive_home={{pwd}}

配置 hive默认的配置是/conf/hive-default.xml如果需要变更配置,可以重新配置于 /conf/hive-site.xmllog4j配置储存于/conf/hive-log4j.propertieshive的配置是基于对hadoop的一个覆盖,意思是hadoop的配置变量是缺省继承的。hive变量的配置方法:1.修改hive-site.xml文件2.通过cli客户端使用set命令进行3.通过授权hive使用如下语法$ bin/hive -hiveconf x1=y1 -hiveconf x2=y2

运行时配置

hive的查询是通过mr查询执行的,因此,这样的查询行为都是被hadoop的配置变量进行控制的。hive> set mapred.job.tracker=myhost.mycompany.com:50030;hive> set -v;上面的最后一条语句可以显示当前的所有配置。如果不加-v参数,则只显示与基础的hadoop配置不同的配置。

local模式

hive> set mapred.job.tracker=local;hive> set hive.exec.mode.local.auto=false;$ export path=$hive_home/bin:$path

修改log路径

bin/hive -hiveconf hive.root.logger=info,consolebin/hive -hiveconf hive.root.logger=info,drfametastoremodel描述文件位置:src/contrib/hive/metastore/src/modeldml operations默认的文件分割呼号是ctr+a文件上传的默认目录是: hive-default.xml 中的hive.metastore.warehouse.dir上传文件的两种方式:本地文件load data local inpath './examples/files/kv2.txt' overwrite into table invites partition (ds='2008-08-15');远程文件 load data inpath '/user/myname/kv2.txt' overwrite into table invites partition (ds='2008-08-15');上面的命令会发生文件和目录的转移。将结果插入到hdfs insert overwrite directory '/tmp/hdfs_out' select a.* from invites a where a.ds='2008-08-15';将结果插入到本地文件insert overwrite local directory '/tmp/local_out' select a.* from pokes a;

只定义mapper任务:py

import sysimport datetimefor line in sys.stdin: line = line.strip() userid, movieid, rating, unixtime = line.split('t') weekday = datetime.datetime.fromtimestamp(float(unixtime)).isoweekday() print 't'.join([userid, movieid, rating, str(weekday)])create table u_data_new ( userid int, movieid int, rating int, weekday int)row format delimitedfields terminated by 't';add file weekday_mapper.py;insert overwrite table u_data_newselect transform (userid, movieid, rating, unixtime) using 'python weekday_mapper.py' as (userid, movieid, rating, weekday)from u_data;select weekday, count(*)from u_data_newgroup by weekday;



【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!