你好,游客 登录 注册 搜索
背景:
阅读新闻

使用Sqoop将MySQL数据导入到Hadoop

[日期:2014-12-10] 来源:Linux社区  作者:ssrc0604hx [字体:大 中 小]

TEST 1 计算平均年龄

测试数据:300.8 W
1. 计算广东的平均年龄
mysql:select (sum(year(NOW()) - SUBSTRING(borth,1,4))/count(*)) as ageAvge from test_sfz where address like '广东%';
用时: 0.877s
 
hive:select (sum(year('2014-10-01') - SUBSTRING(borth,1,4))/count(*)) as ageAvge from test_sfz where address like '广东%';
用时:25.012s
 
2. 对每个城市的的平均年龄进行从高到低的排序
mysql:select address, (sum(year(NOW()) - SUBSTRING(borth,1,4))/count(*)) as ageAvge from test_sfz GROUP BY address order by ageAvge desc;
用时:2.949s
 
hive:select address, (sum(year('2014-10-01') - SUBSTRING(borth,1,4))/count(*)) as ageAvge from test_sfz GROUP BY address order by ageAvge desc;
用时:51.29s
 
可以看到,在耗时上面,hive的增长速度较mysql慢。
 

TEST 2

测试数据:1200W
mysql 引擎: MyISAM(为了加快查询速度)
导入到hive:
 
1. 计算广东的平均年龄
mysql:select (sum(year(NOW()) - SUBSTRING(borth,1,4))/count(*)) as ageAvge from test_sfz2 where address like '广东%';
用时: 5.642s
 
hive:select (sum(year('2014-10-01') - SUBSTRING(borth,1,4))/count(*)) as ageAvge from test_sfz2 where address like '广东%';
用时:168.259s
 
2. 对每个城市的的平均年龄进行从高到低的排序
mysql:select address, (sum(year(NOW()) - SUBSTRING(borth,1,4))/count(*)) as ageAvge from test_sfz2 GROUP BY address order by ageAvge desc;
用时:11.964s
 
hive:select address, (sum(year('2014-10-01') - SUBSTRING(borth,1,4))/count(*)) as ageAvge from test_sfz2 GROUP BY address order by ageAvge desc;
用时:311.714s
 

TEST 3

测试数据:2000W
mysql 引擎: MyISAM(为了加快查询速度)
导入到hive:
(这次用的时间很短!可能是因为TEST2中的导入时,我的主机在做其他耗资源的工作..)
 
1. 计算广东的平均年龄
mysql:select (sum(year(NOW()) - SUBSTRING(borth,1,4))/count(*)) as ageAvge from test_sfz2 where address like '广东%';
用时: 6.605s
 
hive:select (sum(year('2014-10-01') - SUBSTRING(borth,1,4))/count(*)) as ageAvge from test_sfz2 where address like '广东%';
用时:188.206s
 
2. 对每个城市的的平均年龄进行从高到低的排序
mysql:select address, (sum(year(NOW()) - SUBSTRING(borth,1,4))/count(*)) as ageAvge from test_sfz2 GROUP BY address order by ageAvge desc;
用时:19.926s
 
hive:select address, (sum(year('2014-10-01') - SUBSTRING(borth,1,4))/count(*)) as ageAvge from test_sfz2 GROUP BY address order by ageAvge desc;
用时:411.816s

更多Hadoop相关信息见Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13

本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-12/1103.htm

linux
相关资讯       Sqoop  Hadoop导入数据