Phoenix 使用遇到的問題

公司用HBase,學習了Phoenix。記錄一些問題html

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在建立表的時候會自動將小寫轉換爲大寫字母mysql

能夠參考 http://phoenix.apache.org/columnencoding.htmlsql

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-763apache

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。bash

CREATE INDEX my_index ON my_table (v1) INCLUDE (v2)

英文好的,請直接看官方文檔:http://phoenix.apache.org/secondary_indexing.htmloracle

相關文章
相關標籤/搜索