也能够经过hadoop操做把文件导入到数据库中,使用hive来进行操做,也就是说只要是在建立的数据库中的存储位置,均可以进行hive的操做sql
假设导入的数据字段缺失,那么会出现null,而且null在字段的最后数据库
假如导入的数据多出一个字段,那么多出的字段不会显示app
hive表有两大类:oop
managed_table:存储的位置默认在/user/hive/warehourse/spa
external:3d
建立一个uuu.data数据,hadoop fs -put / 上传到hdfs的/目录中code
想要把这个uuu.data数据导入到hive表中 load data inpath '/uuu.data' into table t_order_wk;orm
导入后发现/目录下uuu.data不见了,出现到咱们建的表的目录下blog
这样的缺点就是把咱们业务数据会移动位置,会干预咱们业务系统的运行hadoop
所以hive提供了external格式,数据能够在任何一个位置不影响,这样对数据的操做就不会影响业务数据
建立external表
1.hdfs上建立指定目录,而且导入数据
hadoop fs -mkdir /hive_ext
hadoop fs -put jjj.data /hive_ext
2.建立external表
create external table t_order_ex(id int,name,string,price double) row format delimited fields ternimated by '/t' location '/hive_ex';
业务数据并无发生位置变化
3.查询数据
建立external的特色:
1.秩序关联,无需移动位置;
2.删除表时候,内部表及元数据都删除了,外部表的删除,只会删除表,业务数据不会删除,就是元数据时候删除的区别;
临时中间表的建立:
主要用于建立一些临时表存储中间结果,同时也会造成一个元数据
crete table t_order_simople as select id,name,price from t_order_wk;
create table t_simple like t_order_wk;
insert overwrite table t_simple;用于向临时表中追加中间结果数据
partitioned by:
假如未使用分区,要查询某个月份的订单,使用group by 就会扫描所有数据,若是按月份建立了分区,那么就能够直接在某个月份的分区中查找
1.建立分区表
create table t_order(id int,name string,price double) partitioned by(month string) row format delimited fields ternimated by '/t''
2.向分区中导入数据
load data local inpath '/home/hadoop/apps/xxx.data' into table t_order_wk partition(month='201401')
分区数据是先存储在表的文件夹/建立的分区名/分区表
3.按照分区进行查询
select count(*) from t_order_pt where month='201401'
把分区数据当成一个字段进行约束查询