HBase导入大数据三大方式之(二)——importtsv +completebulkload 方式


做大数据时,经常需要用到将大量格式化的文本数据导入到hbase中。此处就用到的三种方式:hive类SQL语句方式、importtsv +completebulkload 方式、mapreduce+completebulkload 方式,做下简单示例。上篇介绍了hive类SQL语句方式,现在介绍importtsv +completebulkload 方式

实例中,我以虚拟话单作为需要导入的数据,格式上篇文章中有介绍。

1、  首先在hive shell里面建表:

2、  建hive识别的hbase表,方便以后做hive查询,其中只有一个列组info:

预处理脚本方式需要6.5mins 10G。数据导入hive数据表需要15mins 10G。

把txt数据传到hdfs上,目前用put命令。该阶段耗时25分钟。

CREATE TABLE bill(00_selfnumber string,01_day string,02_hour string,03_duration string,04_calltype string, 05_targetnumber string, 06_address string, 07_longdtype string, 08_basecost float, 09_longdcost float, 10_infocost float,11_privilege string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" = "info:01_day,info:02_hour,info:03_duration,info:04_calltype,info:05_targetnumber,info:06_address,info:07_longdtype,info:08_basecost,info:09_longdcost,info:10_infocost,info:11_privilege") TBLPROPERTIES ("hbase.table.name" = "bill");

3、使用importtsv命令,注意文本中的分隔符是","

//该过程花费时间较长:13:52开始——17:23结束耗时3.5小时 10G

bin/hadoop jar/usr/hadoop/hbase-0.92.1-cdh4.1.5/hbase-0.92.1-cdh4.1.5-security.jar importtsv-Dimporttsv.separator="," -Dimporttsv.bulk.output=/user/hadoop/output-Dimporttsv.columns=HBASE_ROW_KEY,info:day,info:hour,info:duration,info:calltype,info:targetnumber,info:address,info:longdtype,info:basecost,info:longdcost,info:infocost,info:privilegesheet /input


4、使用completebulkload加载数据

//这个过程很快,瞬间完成。

bin/hadoop jar/usr/hadoop/hbase-0.92.1-cdh4.1.5/hbase-0.92.1-cdh4.1.5-security.jar completebulkload /user/hadoop/output sheet

查询:1分钟。


注意:

注意completebulkload 导入命令只能执行一次。

报错:

1、NoClassDefFoundError:org/apache/hadoop/hbase/HBaseConfiguration

解决办法:jar包的时候没有把用到的lib打包进去,建个lib,把要用到的jar放里面一起打包。

2、zookeeperException

解决办法:zookeeper没有找到,尝试:1、关闭防火墙;2、hadoop的hadoop-env.sh 里面配置HADOOP_CLASSPATH包含hbase的一些jar,core-site.xml里面配置好zookeeper的几个server。重启hadoop、hbase、zookeeper。

3、Caused by:java.io.FileNotFoundException: HFileOutputFormat dir /user/hadoop/output notfound

解决办法:命令里面要写完整hdfs的路径,不然找不到。

4、ERROR mapreduce.LoadIncrementalHFiles:IOException during splitting
java.util.concurrent.ExecutionException:org.apache.hadoop.hbase.io.hfile.CorruptHFileException: Problem reading HFileTrailer from file hdfs://master:9000/user/hadoop/output/clusters-0/part-00004

load一次就相当于剪切了,再次load就会出错。


OK!GOOD LUCK!小伙伴们加油!

相关内容