hive → phoenix数据导入导出方案

主要是使用Phoenix Storage Handler for Apache Hive Feature Installation,优势是phoenix自带的feature,支持力度比较好
phoenix主页上相关的介绍[https://phoenix.apache.org/hive_storage_handler.html ]

1. 调研的环境

phoenix 4.8
hive 1.2.1
测试环境共有两个集群。 hbase和hadoop

2. 操作过程

2.1 需要开启的配置项

hbase-site.xml 集群和客户端都需要开启这两项配置

<property>
 <name>phoenix.schema.isNamespaceMappingEnabled</name>
 <value>true</value>
</property>
<property>
 <name>phoenix.schema.mapSystemTablesToNamespace</name>
 <value>false</value>
</property>

hive-site.xml

<property>
    <name>hive.aux.jars.path</name>
    <value>file:///home/hadoop/apache-hive-1.2.1-bin/lib/phoenix-4.8.0-HBase-0.98-hive.jar</value>
</property>

hive-env.sh

export HIVE_AUX_JARS_PATH=/home/hadoop/apache-hive-1.2.1-bin/lib/phoenix-4.8.0-HBase-0.98-hive.jar

2.2 创建phoenix schema

create schema if not exists ABC;

2.3 创建hive内部表,关联到phoenix

create table g_order_phoenix 
(
 order_id bigint,
 driver_id bigint,
 driver_phone string,
 passenger_id bigint
 )
STORED BY 'org.apache.phoenix.hive.PhoenixStorageHandler'   TBLPROPERTIES
 (
"phoenix.table.name" = "ABC.G_ORDER_PHOENIX",
"phoenix.zookeeper.quorum" = "10.93.18.30,10.93.18.31,10.93.18.32",
"phoenix.zookeeper.znode.parent" = "/hbase",
"phoenix.zookeeper.client.port" = "2181",
"phoenix.rowkeys" = "order_id,driver_id",
"phoenix.column.mapping" = "order_id:order_id, driver_id:driver_id, driver_phone:driver_phone, passenger_id:passenger_id",
"phoenix.table.options" = "SALT_BUCKETS=10, DATA_BLOCK_ENCODING='DIFF'"
);

###2.4 创建待导出数据的hive表,这部分数据在hadoop HDFS上

CREATE TABLE `g_order`
(
   `order_id` bigint COMMENT '订单id', 
   `driver_id` bigint COMMENT '司机id,司机抢单前该值为0', 
   `driver_phone` string COMMENT '司机电话', 
   `passenger_id` bigint COMMENT '乘客id'
 );

2.5 插入数据

insert into table g_order 
select order_id, driver_id,driver_phone,passenger_id from g_order_phoenix where driver_id!=0 and order_id!=0;
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值