公司用HBase,学习了Phoenix。记录一些问题
1. Phoenix映射表问题
- 如果只做查询,强烈建议使用 phoenix 视图方式映射,删除视图不影响 hbase 源数据,语法如下。
create view "test1"(
pk VARCHAR PRIMARY KEY,
"i"."name" VARCHAR,
"i"."age" VARCHAR);
- 必须要表映射,需要禁用列映射规则(会降低查询性能),如下:
create table "test1"(
pk VARCHAR PRIMARY KEY,
"i"."name" VARCHAR,
"i"."age" VARCHAR)
column_encoded_bytes=0;
表名和列族以及列名需要用双引号括起来,因为HBase是区分大小写的,如果不用双引号括起来的话Phoenix在创建表的时候会自动将小写转换为大写字母
可以参考 http://phoenix.apache.org/columnencoding.html
2. 通过SQOOP导数据
- SQOOP还不支持phoenix,先导到HBASE中,再建映射。
sqoop import --connect jdbc:mysql://localhost/test --username xxx --password xxx --table mytable --hbase-create-table --hbase-table mytable --column-family cf --hbase-row-key id --split-by id -m 10 --columns id,insert_time,info
- SQOOP最新的版本可能支持,没有试过。
sqoop import --connect jdbc:mysql://localhost/test --username root -P --verbose --query "SELECT rowid,name FROM employee WHERE \$CONDITIONS" --target-dir /tmp/employee --phoenix-table EMP --phoenix-column-mapping "rowid;ID,name;NAME" --phoenix-bulkload
Arguments:
--phoenix-table : Required . The phoenix table
--phoenix-column-mapping: Optional. This property should be specified if the column names between sqoop table and phoenix table differ.
--phoenix-bulkload Optional . Bulk loads data onto the phoenix table.
参考:https://issues.apache.org/jira/browse/PHOENIX-763
3. Phoenix 二级索引
- Phoenix4.8以上版本需要配置在Region Server配置hbase-site.xml,不用再配置Master的hbase-site.xml。配置如下
<property>
<name>hbase.regionserver.wal.codec</name><value>org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec</value></property>
<property>
<name>hbase.region.server.rpc.scheduler.factory.class</name><value>org.apache.hadoop.hbase.ipc.PhoenixRpcSchedulerFactory</value><description>Factory to create the Phoenix RPC Scheduler that uses separate queues for index and metadata updates</description>
</property>
<property>
<name>hbase.rpc.controllerfactory.class</name><value>org.apache.hadoop.hbase.ipc.controller.ServerRpcControllerFactory</value>
<description>Factory to create the Phoenix RPC Scheduler that uses separate queues for index and metadata updates</description>
</property>
- 二级索引和oracle 的索引不一样。
SELECT v2 FROM my_table WHERE v1 = 'foo'
这样查询,要用上索引,需要v1,v2一起建索引。如果查询结果中字段有多的,将用不上索引。查询结果是rowkey的话,可以不要INCLUDE。
CREATE INDEX my_index ON my_table (v1) INCLUDE (v2)
英文好的,请直接看官方文档:http://phoenix.apache.org/secondary_indexing.html