建表
hbase建表
put 't1','key001','f1:col1','hello'
put 't1','key001','f1:age',20
put 't1','key002','f1:col1','hello1'
put 't1','key002','f1:age',21
建立phonex视图
0: jdbc:phoenix:localhost> CREATE VIEW "t1" ("tid" VARCHAR PRIMARY KEY,"f1"."age" VARCHAR,"f1"."col1" VARCHAR);
No rows affected (0.087 seconds)
0: jdbc:phoenix:localhost> select * from "t1";
+---------+------+---------+
| tid | age | col1 |
+---------+------+---------+
| key001 | 20 | hello |
| key002 | 21 | hello1 |
+---------+------+---------+
2 rows selected (0.065 seconds)
复合主键
创建hbase表
put 't2',"k009\09",'f1:col1','kkkkkkkkkkkkkkkkkkkkkkkk'
put 't2',"k009\09",'f1:age',21
rowkey需要使用双引号限定
创建phoenix表
CREATE VIEW "t2" ("k1" VARCHAR,"k2" VARCHAR,"f1"."age" VARCHAR,"f1"."col1" VARCHAR CONSTRAINT PK PRIMARY KEY ("k1", "k2"));
0: jdbc:phoenix:localhost> select * from "t2";
+--------------+-----+------+---------------------------+
| k1 | k2 | age | col1 |
+--------------+-----+------+---------------------------+
| k009 | 9 | 21 | kkkkkkkkkkkkkkkkkkkkkkkk |
使用phoenix插入数据
建表
0: jdbc:phoenix:localhost> CREATE table "t3" ("k1" VARCHAR,"k2" VARCHAR,"f1"."age" VARCHAR,"f1"."col1" VARCHAR CONSTRAINT PK PRIMARY KEY ("k1", "k2"));
No rows affected (0.651 seconds)
插入数据
0: jdbc:phoenix:localhost> upsert into "t3" values('k009','9','29','9');
1 row affected (0.008 seconds)
查询数据
0: jdbc:phoenix:localhost> select * from "t3";
+-------+-----+------+-------+
| k1 | k2 | age | col1 |
+-------+-----+------+-------+
| k001 | 1 | 20 | 9 |
+-------+-----+------+-------+