Hbase-Phoenix集成(二)基本命令+表的映射

Posted on 2020-04-30 10:24  MissRong  阅读(131)  评论(0)    收藏  举报

Phoenix集成(二)基本命令+表的映射

一、基本命令

1.展示表

> !table

 

和Hive一样不能加载原有的表,想加载就需要创建关联表。

2.创建表

> create table test(id integer not null primary key,name varchar);

当想创建以小写字母为名的表时,将表名用双引号引住即可。

> create table "plus"(

id integer not null primary key,

name varchar);

这里的key就相当于Hbase里表中的ROW

3.删除表

drop table test; 

这里就将那个大写的TEST删除了

4.插入数据

upsert into "plus" values(1,'plus');

> upsert into users(name) values('toms');

5.查询数据

phoenix > select * from test;

hbase > scan 'test'

 

6.退出phoenix

> !q

7.删除数据

delete from "Andy" where id=4;

8.sum函数的使用

select sum(id) from "Andy";

9.增加一列

alter table "Andy" add address varchar;

10.删除一列

alter table "Andy" drop column address;

其他语法详见:http://phoenix.apache.org/language/index.html

二、表映射

1.hbase中创建表

create 'teacher1','info','contact'

2.插入数据

put 'teacher1','1001','info:name','Jack'

put 'teacher1','1001','info:age','28'

put 'teacher1','1001','info:gender','male'

put 'teacher1','1001','contact:address','shanghai'

put 'teacher1','1001','contact:phone','13458646987'

 

put 'teacher1','1002','info:name','Jim'

put 'teacher1','1002','info:age','30'

put 'teacher1','1002','info:gender','male'

put 'teacher1','1002','contact:address','tianjian'

put 'teacher1','1002','contact:phone','13512436987'

3.在Phoenix创建映射表

create view "teacher1"(

"id" varchar primary key,

"info"."age"  varchar,

"info"."gender" varchar,

"info"."name" varchar

);

这里的后三行顺序无先后之分,哪个在前哪个就更靠左。

 

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3