phoenix安装好以后,我们发现在phoenix中创建的表,在hbase中也能看到,但是hbase已存在的表却没有出现在phoenix中,因此我们需要手动将hbase的表映射到phoenix中。
phoenix映射hbase表的方式分为两种,一种是表映射,一种是视图映射。
官方文档http://phoenix.apache.org/language/index.html#
下面具体看一下两种映射方式:
1. 表映射
create 'STUDENT', 'INFO'
put 'STUDENT', 'bbbZZZ1004', 'INFO:NAME', 'WeiDong'
put 'STUDENT', 'bbbZZZ1004', 'INFO:AGE', '27'
put 'STUDENT', 'bbbZZZ1004', 'INFO:HOME', 'ZhouKou'
put 'STUDENT', 'bbbZZZ1005', 'INFO:NAME', 'XiaoMeng'
put 'STUDENT', 'bbbZZZ1005', 'INFO:AGE', '27'
put 'STUDENT', 'bbbZZZ1005', 'INFO:HOME', 'YuLin'
put 'STUDENT', 'bbbTTT1006', 'INFO:NAME', 'GuiPing'
put 'STUDENT', 'bbbTTT1006', 'INFO:AGE', '39'
put 'STUDENT', 'bbbTTT1006', 'INFO:HOME', 'ZhengZhou'
put 'STUDENT', 'bbbTTT1007', 'INFO:NAME', 'xiaoming'
put 'STUDENT', 'bbbTTT1007', 'INFO:AGE', '10'
put 'STUDENT', 'bbbTTT1007', 'INFO:HOME', 'hebei'
create table student (
id varchar primary key,
info.name varchar,
info.age varchar,
info.home varchar
)column_encoded_bytes=0
注意:末尾要加上column_encoded_bytes=0,不加的话select时会出现查不出数据的情况
查看表 !table
插入(更新)数据 upsert into student values('bbbAAA1003','xixi','21','beijing');
删除数据 delete from teacher where home='beijing';
hbase和phoenix无论哪一端插入/更新/删除数据,另一端对应的表都会同步插入/更新/删除
2. 视图映射
create 'TEACHER', 'INFO'
put 'TEACHER', 'bbbZZZ1004', 'INFO:NAME', 'WeiDong'
put 'TEACHER', 'bbbZZZ1004', 'INFO:AGE', '27'
put 'TEACHER', 'bbbZZZ1004', 'INFO:HOME', 'ZhouKou'
put 'TEACHER', 'bbbZZZ1005', 'INFO:NAME', 'XiaoMeng'
put 'TEACHER', 'bbbZZZ1005', 'INFO:AGE', '27'
put 'TEACHER', 'bbbZZZ1005', 'INFO:HOME', 'YuLin'
put 'TEACHER', 'bbbTTT1006', 'INFO:NAME', 'GuiPing'
put 'TEACHER', 'bbbTTT1006', 'INFO:AGE', '39'
put 'TEACHER', 'bbbTTT1006', 'INFO:HOME', 'ZhengZhou'
put 'TEACHER', 'bbbTTT1007', 'INFO:NAME', 'xiaoming'
put 'TEACHER', 'bbbTTT1007', 'INFO:AGE', '10'
put 'TEACHER', 'bbbTTT1007', 'INFO:HOME', 'hebei'
create view teacher (
pk varchar primary key,
info.name varchar,
info.age varchar,
info.home varchar
)
查看表 !table
0: jdbc:phoenix:myhbase,xmhl,xmhl30:2181> upsert into teacher values('bbbAAA1003','xixi','21','beijing');
Error: ERROR 505 (42000): Table is read only. (state=42000,code=505)
hbase插入/更新/删除数据,对应的phoenix映射表中也会同步数据