学生成绩单,用name作为一个行键,sex作为一个列族,成绩作为一个列族
说明:列族必须在建立表的时候就固定,后面无法扩展新增,子列可以新增
1. 建立一个表stu, 包含列族为sex,score
create 'stu','sex','score'
2. 按设计的表,增加值
put 'stu','lucy','sex:','1'
put 'stu','lucy','score:chinese','90'
put 'stu','lucy','score:math','89'
put 'stu','jack','sex:','2'
put 'stu','jack','score:chinese','95'
put 'stu','jack','score:math','100'
sex列族下没有子列,只需要 sex: 就可以了。
3. 扫描表
hbase(main):021:0> scan 'stu'
ROW COLUMN+CELL
jack column=score:chinese, timestamp=1581217877981, value=95
jack column=score:math, timestamp=1581217881272, value=100
jack column=sex:, timestamp=1581217874667, value=2
lucy column=score:chinese, timestamp=1581217867470, value=90
lucy column=score:math, timestamp=1581217871196, value=89
lucy column=sex:, timestamp=1581217863401, value=1
2 row(s)
Took 0.0361 seconds
4. 读取一行的数据
读取lucy这个学生的数据
hbase(main):022:0> get 'stu','lucy'
COLUMN CELL
score:chinese timestamp=1581217867470, value=90
score:math timestamp=1581217871196, value=89
sex: timestamp=1581217863401, value=1
1 row(s)
Took 0.0210 seconds
读取这个学生的数学成绩
hbase(main):023:0> get 'stu','lucy','score:math'
COLUMN CELL
score:math timestamp=1581217871196, value=89
1 row(s)
Took 0.0051 seconds
或者
hbase(main):024:0> get 'stu','lucy',{COLUMN=>'score:math'}
COLUMN CELL
score:math timestamp=1581217871196, value=89
1 row(s)
Took 0.0055 seconds
5. 为列族score加一个子列
列族score可以自由添加,比如一个学生到了初一多个科目英语 只需要增加数据
put 'stu','lucy','score:english','77'
hbase(main):027:0> get 'stu','lucy'
COLUMN CELL
score:chinese timestamp=1581217867470, value=90
score:english timestamp=1581218279668, value=77
score:math timestamp=1581217871196, value=89
sex: timestamp=1581217863401, value=1
1 row(s)
Took 0.0175 seconds