hive是一个可以将sql翻译为MR程序的工具
不用写大量的mr程序来分析数据,只需要写sql脚本即可
hive的使用方法
hive>select * from t_test;
创建表
[root@hdp01 ~]#hive -e “use default;create table test_1(id int,name string);”
创建文件
[root@hadoop2 home]#vi /home/useinfo.txt
1,xiaoming,20
2,xiaowang,30
[root@hadoop2 home]# vi a.hql
use default;
create table test_2(id int,name string,age int)
row format delimited
fields terminated by ',';
load data local inpath '/home/userinfo.txt' into table test_2;
select count(*) from test_2;
内部表和外部表
内部,删除表hdfs中的文件也会被删除
外部,
上传文件 [root@hadoop1 home]# hadoop fs -put salary.txt /aa/bb/
区别: 内部表的目录由hive创建在默认的仓库目录下:/user/hive/warehouse/…
外部表的目录由用户建表时自己指定: location ‘/位置/’
drop一个内部表时,表的元信息和表数据目录都会被删除;
drop一个外部表时,只删除表的元信息,表的数据目录不会删除;
意义: 通常,一个数据仓库系统,数据总有一个源头,而源头一般是别的应用系统产生的,
其目录无定法,为了方便映射,就可以在hive中用外部表进行映射;并且,就算在hive中把
这个表给drop掉,也不会删除数据目录,也就不会影响到别的应用系统;