1、 从hive中导出数据至本地目录
insert overwrite local directory '/export/tmp' select * from test1 where create_time = '2013-11-25';
列数据之间默认以^A隔开。
2、将本地数据上传另一个集群的hdfs
/usr/local/hadoop-2.2.0/bin/hdfs dfs -put /export/tmp hdfs://host:port/tmp
3、将hdfs中的数据文件导入hive表中
hive -e "load data inpath '/tmp' into table test1;"
但某些表创建时,设置的以 '\t' 分割数据,在读取不到 '\t' 时,会将整行数据都导入第一列。
如果是hive-0.11.0版本,可以这样导出:
hive> insert overwrite local directory '/export/tmp'
hive> row format delimited
hive> fields terminated by '\t'
hive> select * from test1 where create_time = '2013-11-25';
如果是低版本的hive,只好将导出的数据文件中的^A,替换为'\t':
sed -i 's/^A/\t/g' filename
同时需要将隐藏的.filename.crc校验文件删除掉,不然在上传的过程中,Hadoop将通过FSInputChecker判断需要上传的文件是否存在进行校验的crc文件,即.filename.crc,如果存在crc文件,将会对其内容一致性进行校验,如果校验 失败,会报fs.FSInputChecker: Found checksum error,停止上传该文件,最终导致整个MR任务无法执行。