Hive 使用首记

    安装配置过程略,简单记录一下Hive的基础使用。Cloudera HUE提供的WEB页面可以非常容易的操控Hive:

    image

这里就讲下用Hive Shell吧。

    一、登录Hive Shell。出于权限和安全的考虑,应指定用户启动。比如用hdfs用户登录Hive:

sudo su -m -c 'hive' hdfs

image   

二、创建数据表。前提是数据已生成,然后按数据格式建表。以下示例就是用Flume收集Tengine的日志到HDFS,日志用‘|’分隔:

log_format logger '$http_host|$remote_addr|$msec|$status|$request_length|$bytes_sent|$request|$request_time|$http_referer';

 

CREATE TABLE access_log (http_host string,remote_addr string,msec float,status int,request_length int,bytes_send int,request string,request_time float,http_refer string) fields terminated BY '|' ;

image

    完成之后可以在列表里看到数据表信息,以及里面的数据:

 image

三、导入数据。Hive解析你的SQL然后将源目标的文件加载到数据库目录,并生成数据表。

load data inpath '/flume/tengine/access.*.log' overwrite into table access_log ;

image

四、验证。此时可以查看表数据,或执行一个统计SQL以验证正确性。

    a. 查看文件是否真的过来了

    image

    b. 通过SQL查询文件行数

    higkoo

    c. 通过fuse挂载hdfs,然后通过Linux shell计算文件行数

    image

    d. 使用Hive Shell也来看看结果吧

    higkoo

OK,Hive的基本流程在此算是走通了。   

posted @ 2013-05-16 12:29  higkoo  阅读(361)  评论(0编辑  收藏  举报