天天看點

hive內建phoenix

因為有用到phoenix往hbase中建表及填充資料,是以在使用到hive的時候不能直接通過hive建立hbase的外部表
  • 1. 指定hive的HIVE_AUX_JARS_PATH
vi hive-env.sh
           
HIVE_AUX_JARS_PATH=<path to jar>
           
vi hive-site.xml 
           
<property>
  <name>hive.aux.jars.path</name>
  <value>file://<path></value>
</property>

           
  • 2. 拷貝相關phoenix的jar包

将以下3個jar包放入

1.

中指定的目錄中

phoenix-hive-4.13.1-HBase-1.2.jar
phoenix-core-4.13.1-HBase-1.2.jar
phoenix-4.13.1-HBase-1.2-hive.jar
           
  • 3. 建立外部表
create external table ext_table (
  i1 int,
  s1 string,
  f1 float,
  d1 decimal
)
STORED BY 'org.apache.phoenix.hive.PhoenixStorageHandler'
TBLPROPERTIES (
  "phoenix.table.name" = "ext_table",
  "phoenix.zookeeper.quorum" = "localhost",
  "phoenix.zookeeper.znode.parent" = "/hbase",
  "phoenix.zookeeper.client.port" = "2181",
  "phoenix.rowkeys" = "i1",
  "phoenix.column.mapping" = "i1:i1, s1:s1, f1:f1, d1:d1"
);

           

說明:

phoenix.column.mapping

hive

phoenix

中字段的對應關系

删除外部表隻删除hive中的meta資訊

  • 4. 建立内部表
create table phoenix_table (
  s1 string,
  i1 int,
  f1 float,
  d1 double
)
STORED BY 'org.apache.phoenix.hive.PhoenixStorageHandler'
TBLPROPERTIES (
  "phoenix.table.name" = "phoenix_table",
  "phoenix.zookeeper.quorum" = "localhost",
  "phoenix.zookeeper.znode.parent" = "/hbase",
  "phoenix.zookeeper.client.port" = "2181",
  "phoenix.rowkeys" = "s1, i1",
  "phoenix.column.mapping" = "s1:s1, i1:i1, f1:f1, d1:d1",
  "phoenix.table.options" = "SALT_BUCKETS=10, DATA_BLOCK_ENCODING='DIFF'"
);

           

說明:在hive中建立即phoenix中也會建立相應的表,删除時兩邊的資料都會删除。

繼續閱讀