Tutorial-LoadingData
Hive加载数据的6种方式
#格式
load data [local] inpath '/op/datas/xxx.txt' [overwrite] into table tablename [partition (partcol1 = val1,partcol2 = val2)];
1.从本地文件系统加载
load data local inpath '/opt/datas/xxx.txt' into table tablename;
2.从 hdfs 加载(相当于移动,原来的位置文件会被删除)
load data inpath '/user/cen/datas/xxx.txt' into table tablename;
3.覆盖加载
load data inpath '/user/cen/datas/xxx.txt' overwrite into table tablename;
4.创建表时候 select 加载
create table tablename as select * form tablename2;
4.insert加载(两种方式等价)
create table tablename like tablename2;
insert into table tablename select * from tablename2;
5.创建表时候指定location加载
CREATE EXTERNAL TABLE page_view_stg(viewTime INT, userid BIGINT,
page_url STRING, referrer_url STRING,
ip STRING COMMENT 'IP Address of the User',
country STRING COMMENT 'country of origination')
COMMENT 'This is the staging page view table'
ROW FORMAT DELIMITED FIELDS TERMINATED BY '44' LINES TERMINATED BY '12'
STORED AS TEXTFILE
LOCATION '/user/data/staging/page_view';
hadoop dfs -put /tmp/pv_2008-06-08.txt /user/data/staging/page_view
Hive数据导出
1.指定本地系统文件导出
insert overwrite local directory '/opt/datas/hive_exp_emp'
ROW FORMAT DELIMITED FIELDS TERMINATED BY ' '
select * from tablename;
2.指定 hdfs 文件系统目录
insert overwrite directory '/user/cen/output'
ROW FORMAT DELIMITED FIELDS TERMINATED BY ' '
select * from tablename;
3.通过 hive -e/-f 执行SQL语句,并将结果指向文件(默认分隔符为'/t')
bin/hive -e "select * from databasename.tablename;" > /opt/datas/hive_exp_emp/exp.txt
4.sqoop
hdfs/hive > rdbms
rdbms > hdfs/hive/hbase
import和export(数据备份)
import export
注意是hdfs文件系统目录,其他的文档说明的很详细,属于DML