把格式如下的数据导入到Hbase表中
1.先创建一个表(hbase-csv1),且列族为info
[hadoop@MASTER ~]$ hbase shell
hbase(main):002:0> create 'hbase-csv1','info'
2.把文件上传至HDFS
#要上传的文件
[hadoop@MASTER ~]$ ls -l small_user_hbase.csv
-rw-r--r-- 1 hadoop hadoop 12542830 Dec 3 2018 small_user_hbase.csv
#上传
[hadoop@MASTER ~]$ hadoop fs -put small_user_hbase.csv /
3.把small_user_hbase.csv导入hbase的hbase-csv1表中
格式:hbase [类] [分隔符] [行键,列族] [表] [导入文件]
[hadoop@MASTER ~]$ hbase org.apache.hadoop.hbase.mapreduce.ImportTsv -Dimporttsv.separator="," -Dimporttsv.columns=HBASE_ROW_KEY,info:user_id,info:item_id,info:behavior_type,info:behavior_type,info:time hbase-csv1 /small_user_hbase.csv
info是列族,后边的user_id,item_id...是small_user_hbase.csv中的头部信息,导入后就是info列族中的列
4.查看是否导入
hbase(main):002:0> scan 'hbase-csv1'
ROW COLUMN+CELL
10001082 column=info:behavior_type, timestamp=1543569641473, value=2014-12-14 16
10001082 column=info:item_id, timestamp=1543569641473, value=1
10001082 column=info:user_id, timestamp=1543569641473, value=85851739
100029775 column=info:behavior_type, timestamp=1543569641473, value=2014-12-09 18
100029775 column=info:item_id, timestamp=1543569641473, value=1
100029775 column=info:user_id, timestamp=1543569641473, value=70394849
100068031 column=info:behavior_type, timestamp=1543569641473, value=2014-12-11 09
100068031 column=info:item_id, timestamp=1543569641473, value=1
100068031 column=info:user_id, timestamp=1543569641473, value=315643365
100076491 column=info:behavior_type, timestamp=1543569641473, value=2014-12-09 08
100076491 column=info:item_id, timestamp=1543569641473, value=1
100076491 column=info:user_id, timestamp=1543569641473, value=75205807
导入成功!
5.导出CSV文件
[hadoop@MASTER ~]$ hbase org.apache.hadoop.hbase.mapreduce.Export hbase-csv1 /test1
6.查看
[hadoop@MASTER ~]$ hadoop fs -cat /test1/part-m-00000
导出成功!
1.将hbase-csv1表信息导出至HDFS
[hadoop@MASTER ~]$ hbase org.apache.hadoop.hbase.mapreduce.Export hbase-csv1 /test2
2.创建新表
[hadoop@MASTER ~]$ hbase shell
hbase(main):002:0> create 'hbase-csv2','info'
3.导入Hbase
[hadoop@MASTER ~]$ hbase org.apache.hadoop.hbase.mapreduce.Import hbase-csv2 /test2
4.查看
[hadoop@MASTER ~]$ hbase shell
hbase(main):002:0> scan 'hbase-csv2'
101570788 column=info:user_id, timestamp=1543569641473, value=
314675107
101575870 column=info:behavior_type, timestamp=1543569641473,
value=2014-12-13 19
101575870 column=info:item_id, timestamp=1543569641473, value=
1
101575870 column=info:user_id, timestamp=1543569641473, value=
401863214
101612200 column=info:behavior_type, timestamp=1543569641473,
value=2014-11-25 09
101612200 column=info:item_id, timestamp=1543569641473, value=
1
导入成功!
[1]https://blog.csdn.net/scgaliguodong123_/article/details/46771929#commentBox
[2]https://blog.csdn.net/helloxiaozhe/article/details/80325212
[3]https://blog.csdn.net/qq_41665356/article/details/80265656
[4]https://www.cnblogs.com/cxzdy/p/5583239.html