load数据时,若为宿主机文件,语法为load file local inputpath PATH insert into table TABLENAME,当文件为HDFS文件时,去掉local即可【load结束之后,原HDFS上的数据则会转移到/user/hive/warehouse/TABLENAME/ 路径下,原文件删除】。
load数据时,若为宿主机文件,语法为load file local inputpath PATH insert into table TABLENAME,当文件为HDFS文件时,去掉local即可【原文件不删除】。
-- 创建静态分区表 createtable tb_p_order( oid int , dt string , cost double ) partitioned by (dy string) row format delimited fields terminated by "," ;
load data local inpath "/hive/data/06-18.txt" intotable tb_p_order partition(dy="06-18"); load data local inpath "/hive/data/06-19.txt" intotable tb_p_order partition(dy="06-19");
u001 ZSS 23 M beijing u002 YMM 33 F nanjing u003 LSS 43 M beijing u004 ZY 23 F beijing u005 ZM 23 M beijing u006 CL 23 M dongjing u007 LX 23 F beijing u008 YZ 23 M beijing u009 YM 23 F nanjing u010 XM 23 M beijing u011 XD 23 F beijing u012 LH 23 M dongjing u013 FTM 23 F dongjing
创建一个临时表 导入数据
1 2 3 4 5 6 7 8 9
createtable if notexists tb_user( uid string , name string , age int , gender string , address string ) row format delimited fields terminated by " " ; load data local inpath "/hive/data/user.txt" intotable tb_user ;
创建分区表
1 2 3 4 5 6 7 8 9
createtable if notexists tb_p_user( uid string , name string , age int , gender string , address string ) partitioned by (addr string) row format delimited fields terminated by " " ;
开启动态分区功能
1 2 3 4 5
set hive.exec.dynamic.partition=true; 表示开启动态分区功能(默认为false) set hive.exec.dynamic.partition.mode=nonstrict; 表示允许所有分区都是动态的(默认为strict:少需要有一个是静态分区),可以从普通表中导入数据 set hive.exec.max.dynamic.partitions=1000 表示允许动态分区的最大数量(默认为1000) set hive.exec.max.dynamic.partitions.pernode =100 表示单个节点上的mapper/reducer允许创建的最大分区 -- insert overwrite 是覆盖 insert into 是追加