版本号:cdh5.0.0+hadoop2.3.0+hive0.12

一、原始数据:

1. 本地数据

[root@node33 data]# ll
total 12936
-rw-r--r--. 1 root root 13245467 May 1 17:08 hbase-data.csv
[root@node33 data]# head -n 3 hbase-data.csv
1,1.52101,13.64,4.49,1.1,71.78,0.06,8.75,0,0,1
2,1.51761,13.89,3.6,1.36,72.73,0.48,7.83,0,0,1
3,1.51618,13.53,3.55,1.54,72.99,0.39,7.78,0,0,1

2. hdfs数据:

[root@node33 data]# hadoop fs -ls /input
Found 1 items
-rwxrwxrwx 1 hdfs supergroup 13245467 2014-05-01 17:09 /input/hbase-data.csv
[root@node33 data]# hadoop fs -cat /input/* | head -n 3
1,1.52101,13.64,4.49,1.1,71.78,0.06,8.75,0,0,1
2,1.51761,13.89,3.6,1.36,72.73,0.48,7.83,0,0,1
3,1.51618,13.53,3.55,1.54,72.99,0.39,7.78,0,0,1

二、创建hive表:

1.hive外部表:

[root@node33 hive]# cat employees_ext.sql
create external table if not exists employees_ext(
id int,
x1 float,
x2 float,
x3 float,
x4 float,
x5 float,
x6 float,
x7 float,
x8 float,
x9 float,
y int)
row format delimited fields terminated by ','
location '/input/'

创建表,client执行 :hive -f employees_ext.sql

2. hive表

[root@node33 hive]# cat employees.sql
create table employees(
id int,
x1 float,
x2 float,
x3 float,
x4 float,
x5 float,
x6 float,
x7 float,
x8 float,
x9 float
)
partitioned by (y int);

创建表,client执行:hive -f employees.sql

3. hive表(orc方式存储)

[root@node33 hive]# cat employees_orc.sql
create table employees_orc(
id int,
x1 float,
x2 float,
x3 float,
x4 float,
x5 float,
x6 float,
x7 float,
x8 float,
x9 float
)
partitioned by (y int)
row format serde "org.apache.hadoop.hive.ql.io.orc.OrcSerde"
stored as orc;

执行:hive -f employees_orc.sql

三、导入数据:

1. employees_ext 表导入employees表:

[root@node33 hive]# cat employees_ext-to-employees.sql 

set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.eec.max.dynamic.partitions.pernode=1000; insert overwrite table employees
partition(y)
select
emp_ext.id,
emp_ext.x1,
emp_ext.x2,
emp_ext.x3,
emp_ext.x4,
emp_ext.x5,
emp_ext.x6,
emp_ext.x7,
emp_ext.x8,
emp_ext.x9,
emp_ext.y
from employees_ext emp_ext;

执行:hive -f employees_ext-to-employees.sql。其部分log例如以下:

Partition default.employees{y=1} stats: [num_files: 1, num_rows: 0, total_size: 3622, raw_data_size: 0]
Partition default.employees{y=2} stats: [num_files: 1, num_rows: 0, total_size: 4060, raw_data_size: 0]
Partition default.employees{y=3} stats: [num_files: 1, num_rows: 0, total_size: 910, raw_data_size: 0]
Partition default.employees{y=5} stats: [num_files: 1, num_rows: 0, total_size: 699, raw_data_size: 0]
Partition default.employees{y=6} stats: [num_files: 1, num_rows: 0, total_size: 473, raw_data_size: 0]
Partition default.employees{y=7} stats: [num_files: 1, num_rows: 0, total_size: 13561851, raw_data_size: 0]
Table default.employees stats: [num_partitions: 6, num_files: 6, num_rows: 0, total_size: 13571615, raw_data_size: 0]
MapReduce Jobs Launched:
Job 0: Map: 1 Cumulative CPU: 6.78 sec HDFS Read: 13245660 HDFS Write: 13571615 SUCCESS
Total MapReduce CPU Time Spent: 6 seconds 780 msec
OK
Time taken: 186.743 seconds

查看hdfs文件大小:

[root@node33 hive]# hadoop fs -count /user/hive/warehouse/employees
7 6 13571615 /user/hive/warehouse/employees

查看hdfs文件内容:

bash-4.1$ hadoop fs -cat /user/hive/warehouse/employees/y=1/* | head -n 1
11.5210113.644.491.171.780.068.750.00.0

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZmFuc3kxOTkw/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />

(截图的内容为输出,拷贝到代码块里面有问题)

2. employees_ext 表导入employees_orc表:

[root@node33 hive]# cat employees_ext-to-employees_orc.sql 

set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.eec.max.dynamic.partitions.pernode=1000; insert overwrite table employees_orc
partition(y)
select
emp_ext.id,
emp_ext.x1,
emp_ext.x2,
emp_ext.x3,
emp_ext.x4,
emp_ext.x5,
emp_ext.x6,
emp_ext.x7,
emp_ext.x8,
emp_ext.x9,
emp_ext.y
from employees_ext emp_ext;

执行:hive -f employees_ext-to-employees_orc.sql,其部分log例如以下:

Partition default.employees_orc{y=1} stats: [num_files: 1, num_rows: 0, total_size: 2355, raw_data_size: 0]
Partition default.employees_orc{y=2} stats: [num_files: 1, num_rows: 0, total_size: 2539, raw_data_size: 0]
Partition default.employees_orc{y=3} stats: [num_files: 1, num_rows: 0, total_size: 1290, raw_data_size: 0]
Partition default.employees_orc{y=5} stats: [num_files: 1, num_rows: 0, total_size: 1165, raw_data_size: 0]
Partition default.employees_orc{y=6} stats: [num_files: 1, num_rows: 0, total_size: 955, raw_data_size: 0]
Partition default.employees_orc{y=7} stats: [num_files: 1, num_rows: 0, total_size: 1424599, raw_data_size: 0]
Table default.employees_orc stats: [num_partitions: 6, num_files: 6, num_rows: 0, total_size: 1432903, raw_data_size: 0]
MapReduce Jobs Launched:
Job 0: Map: 1 Cumulative CPU: 7.84 sec HDFS Read: 13245660 HDFS Write: 1432903 SUCCESS
Total MapReduce CPU Time Spent: 7 seconds 840 msec
OK
Time taken: 53.014 seconds

查看hdfs文件大小:

[root@node33 hive]# hadoop fs -count /user/hive/warehouse/employees_orc
7 6 1432903 /user/hive/warehouse/employees_orc

查看hdfs文件内容:

 

3. 比較两者性能

 

  时间 压缩率
employees表: 186.7秒 13571615/13245660=1.0246
employees_orc表: 53.0秒 1432903/13245660=0.108

时间上来说,orc的表现方式会好非常多。同一时候压缩率也好非常多。

只是,这个測试是在本人虚拟机上測试的,并且是单机測试的,所以參考价值不是非常大,可是压缩率还是有一定參考价值的。

四、导出数据

1. employees表:

[root@node33 hive]# cat export_employees.sql 

insert overwrite local directory '/opt/hivedata/employees.dat'
row format delimited
fields terminated by ','
select
emp.id,
emp.x1,
emp.x2,
emp.x3,
emp.x4,
emp.x5,
emp.x6,
emp.x7,
emp.x8,
emp.x9,
emp.y
from employees emp

执行:hive -f export_employees.sql
部分log:

MapReduce Total cumulative CPU time: 9 seconds 630 msec
Ended Job = job_1398958404577_0007
Copying data to local directory /opt/hivedata/employees.dat
Copying data to local directory /opt/hivedata/employees.dat
MapReduce Jobs Launched:
Job 0: Map: 1 Cumulative CPU: 9.63 sec HDFS Read: 13572220 HDFS Write: 13978615 SUCCESS
Total MapReduce CPU Time Spent: 9 seconds 630 msec
OK
Time taken: 183.841 seconds

数据查看:

[root@node33 hive]# ll /opt/hivedata/employees.dat/
total 13652
-rw-r--r--. 1 root root 13978615 May 2 05:15 000000_0
[root@node33 hive]# head -n 1 /opt/hivedata/employees.dat/000000_0
1,1.52101,13.64,4.49,1.1,71.78,0.06,8.75,0.0,0.0,1

2. employees_orc表:

[root@node33 hive]# cat export_employees_orc.sql 

insert overwrite local directory '/opt/hivedata/employees_orc.dat'
row format delimited
fields terminated by ','
select
emp.id,
emp.x1,
emp.x2,
emp.x3,
emp.x4,
emp.x5,
emp.x6,
emp.x7,
emp.x8,
emp.x9,
emp.y
from employees_orc emp

执行 hive -f export_employees_orc.sql

部分log:

MapReduce Total cumulative CPU time: 4 seconds 920 msec
Ended Job = job_1398958404577_0008
Copying data to local directory /opt/hivedata/employees_orc.dat
Copying data to local directory /opt/hivedata/employees_orc.dat
MapReduce Jobs Launched:
Job 0: Map: 1 Cumulative CPU: 4.92 sec HDFS Read: 1451352 HDFS Write: 13978615 SUCCESS
Total MapReduce CPU Time Spent: 4 seconds 920 msec
OK
Time taken: 41.686 second

查看数据:

[root@node33 hive]# head -n 1 /opt/hivedata/employees_orc.dat/000000_0
1,1.52101,13.64,4.49,1.1,71.78,0.06,8.75,0.0,0.0,1
[root@node33 hive]# ll /opt/hivedata/employees_orc.dat/
total 13652
-rw-r--r--. 1 root root 13978615 May 2 05:18 000000_0

这里的数据和原始数据的大小不一样。原始数据是13245467, 而导出到本地的是13978615 。这是由于数据的精度问题,比如原始数据中的0都被存储为了0.0。

 

分享,成长。快乐

转载请注明blog地址:http://blog.csdn.net/fansy1990

 

 

 

Hive实践(hive0.12)的更多相关文章

  1. hive-0.12升级成hive 0.13.1

    安装了0.12之后,听说0.13.1有许多新的特性,包括永久函数,所以想更新成0.13版的(元数据放在mysql中) 2014年8月5日实验成功 hive0.13.1的新特性 新特性详见 http:/ ...

  2. hbase0.96与hive0.12整合高可靠文档及问题总结

    本文链接:http://www.aboutyun.com/thread-7881-1-1.html 问题导读:1.hive安装是否需要安装mysql?2.hive是否分为客户端和服务器端?3.hive ...

  3. Hadoop2.2.0 hive0.12 hbase0.94 配置问题记录

    环境:centos6.2 Hadoop2.2.0 hive0.12 hbase0.94 1>hadoop配好之后,跑任务老失败,yarn失败,报out of memory错误,然后怎么调整内存大 ...

  4. 在Hadoop1.2.1分布式集群环境下安装hive0.12

    在Hadoop1.2.1分布式集群环境下安装hive0.12 ● 前言: 1. 大家最好通读一遍过后,在理解的基础上再按照步骤搭建. 2. 之前写过两篇<<在VMware下安装Ubuntu ...

  5. Hadoop2.3+Hive0.12集群部署

    0 机器说明   IP Role 192.168.1.106 NameNode.DataNode.NodeManager.ResourceManager 192.168.1.107 Secondary ...

  6. Caused by: org.xml.sax.SAXParseException; systemId: file:/home/hadoop/hive-0.12.0/conf/hive-site.xml; lineNumber: 5; columnNumber: 2; The markup in the document following the root element must be well

    1:Hive安装的过程(Hive启动的时候报的错误),贴一下错误,和为什么错,以及解决方法: [root@master bin]# ./hive // :: INFO Configuration.de ...

  7. hive-0.12.0-cdh5.1.0安装

    先前条件: 要先安装好MYSQL 下载:hive-0.12.0-cdh5.1.0.tar.gz,并解压到安装目录 1. 添加环境变量 修改/etc/profile文件. #vi /etc/profil ...

  8. 黑盒测试实践--Day7 12.1

    黑盒测试实践--Day7 12.1 今天完成任务情况: 录制小组作业中的自动化测试工具实践视频 汇总大家提交的各种作业模块,打包完成小组共同作业 小组成员完成个人情况说明后在截止时间前分别提交作业 小 ...

  9. 敏捷软件开发:原则、模式与实践——第12章 ISP:接口隔离原则

    第12章 ISP:接口隔离原则 不应该强迫客户程序依赖并未使用的方法. 这个原则用来处理“胖”接口所存在的缺点.如果类的接口不是内敛的,就表示该类具有“胖”接口.换句话说,类的“胖”接口可以分解成多组 ...

随机推荐

  1. SpringMVC入门及拦截器

    SSM最后一个框架springmvc,其实上手特别简单.但是我昨天看一个深入源码的视频,差点GG.其实以前学过很多东西,都忘了,不敢说学会,现在有了本书,看过一遍之后.多多少少记住一些,权当我会用了, ...

  2. Linux安装配置Nginx服务器

    如有需要可以加我Q群[308742428]大家一起讨论技术,有偿服务. 后面会不定时为大家更新文章,敬请期待. 喜欢的朋友可以关注下. 前言 今天搭建nginx服务器,来访问静态资源文件. Nginx ...

  3. java全栈商业小程序开发

    此次开发只为学习和巩固,第一次学习开发 一.开发前需要了解: 开发框架MVVM.痛点.开源工具.VUE前端框架.微信支付模块.uni-app前端框架.小程序申请.开发工具下载.编写测试小程序.小程序结 ...

  4. 为 STM32 移植 Berry 脚本语言

    Berry 是我为单片机设计的一款脚本语言,该语言具有资源占用小.平台无关.执行速度快和易于掌握等优点.在单片机上使用脚本语言可以提高单片机的二次开发能力以及调试效率,同时也是一种比较新颖的玩法.本教 ...

  5. 【JZOJ6435】【luoguP5666】【CSP-S2019】树的重心

    description analysis 需要知道一棵树的重心一定在从根出发的重链上,可以考虑先进行树链剖分弄出重儿子和次重儿子,再倍增维护重儿子 由于重链上有一个或两个重心,接下来求的重心都是深度较 ...

  6. go函数声明

    go函数声明 这是一个很好的机会去介绍函数支持多值返回.查看下面3个函数:一个没有返回值,一个返回一个值,一个返回2个值. func log(message string) { } func add( ...

  7. asp.net MVC遇到的问题

    参考:http://blog.csdn.net/chenqiangdage/article/details/48996101 asp.netMVC 如何解决“上下文模型已在数据库创建后发生更改” 问题 ...

  8. sql 投影查询

    使用SELECT * FROM <表名> WHERE <条件>可以选出表中的若干条记录.我们注意到返回的二维表结构和原表是相同的,即结果集的所有列与原表的所有列都一一对应. 如 ...

  9. Delphi 获取系统当前进程、窗口句柄、文件属性以及程序运行状态

    uses TLHelp32,PsAPI;(1)显示进程列表: procedure TForm1.Button2Click(Sender: TObject); var lppe: TProcessEnt ...

  10. 2015ICPC chanchun HDU 5534 (树形题转换完全背包)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5534 题意:给你n个点,让你加上n-1条边使他变成一棵树,题目首先给你a[1] a[2].....a[n- ...