HBase 批量插入数据

相信你看到这篇文章的时候你已经使用过HBase插入数据了,HBase插入数据的时候每次只能插入一个单元,如果要插入多条数据的话是非常麻烦的,当然,按照官方文档,除了编程的方式,你还可以写一个脚本,利用HBase shell 运行这个脚本来插入数据,脚本要遵行HBase的命令格式。

1. 假设要建立如下表的数据模型

例表

2. 编写脚本,例如名为:ToHbase.sh

create 'Student','Sno','Sname','Ssex','Sage'
put 'Student','01','Sno','2015001'
put 'Student','01','Sname','Zhangsan'
put 'Student','01','Ssex','male'
put 'Student','01','Sage','23'
put 'Student','02','Sno','2015002'
put 'Student','02','Sname','Mary'
put 'Student','02','Ssex','female'
put 'Student','02','Sage','22'
put 'Student','03','Sno','2015003'
put 'Student','03','Sname','Lisi'
put 'Student','03','Ssex','male'
put 'Student','03','Sage','24'
create 'Course','Cno','Cname','Ccredit'
put 'Course','01','Cno','123001'
put 'Course','01','Cname','Math'
put 'Course','01','Ccredit','2.0' 
put 'Course','02','Cno','123002'
put 'Course','02','Cname','Computer Science'
put 'Course','02','Ccredit','5.0' 
put 'Course','03','Cno','123003'
put 'Course','03','Cname','Englist'
put 'Course','03','Ccredit','3.0' 
create 'SC','SCSno','SCCno','SCScore'
put 'SC','01','SCSno','2015001'
put 'SC','01','SCCno','123001'
put 'SC','01','SCScore','86'
put 'SC','02','SCSno','2015001'
put 'SC','02','SCCno','123003'
put 'SC','02','SCScore','69'
put 'SC','03','SCSno','2015002'
put 'SC','03','SCCno','123002'
put 'SC','03','SCScore','77'
put 'SC','04','SCSno','2015002'
put 'SC','04','SCCno','123003'
put 'SC','04','SCScore','99'
put 'SC','05','SCSno','2015003'
put 'SC','05','SCCno','123001'
put 'SC','05','SCScore','98'
put 'SC','06','SCSno','2015003'
put 'SC','06','SCCno','123002'
put 'SC','06','SCScore','95'

3. 执行脚本

hbase shell ToHbase.sh

你可能感兴趣的:(HBase 批量插入数据)