phoenix映射hbase中数据类型问题

关于Phoenix映射Hbase数据字段类型Demo

一. 原理

在这里插入图片描述
在这里插入图片描述

注意:1.在hbase中必须将value值进行Bytes.toBytes(),才能在phoenix中映射出你所需要的字段值

2.在Phoenix映射表的时候必须使用unsigned_*类型

二. 使用Hbase Shell

2.1 Hbase中操作

2.1.1 创建表
create 'jinshan' ,'info','info1'

在这里插入图片描述

2.1.2 插入数据
put 'jinshan','1001','info:createtime',Bytes.toBytes(1602237645881)
put 'jinshan','1001','info1:age',Bytes.toBytes(16)

在这里插入图片描述

2.2 Phoenix操作

2.2.1 使用视图的方式映射Hbase中表
create view "jinshan" (id varchar primary key,"info"."createtime" UNSIGNED_DATE,"info1"."age" UNSIGNED_LONG)column_encoded_bytes=0;
2.2.2 查询
 select * from "jinshan";

在这里插入图片描述

三. 使用API

3.1 java中连接hbase api添加数据代码片段:

 public static void insertData(String tableName) {
        TableName tablename = TableName.valueOf(tableName);
        // rowKey
        Put put=new Put(Bytes.toBytes("user-111"));
        //参数:1.列族名  2.列名  3.值
        put.addColumn(Bytes.toBytes("mycg"),Bytes.toBytes("name"),Bytes.toBytes("lisa")) ;
        put.addColumn(Bytes.toBytes("mycg"),Bytes.toBytes("age"),Bytes.toBytes(10)) ;                 put.addColumn(Bytes.toBytes("mycg"),Bytes.toBytes("datestr"),Bytes.toBytes(1602237645881L)) ;
        Table table = null;
        try {
            table = connection.getTable(tablename);
            table.put(put);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

3.2 Hbase中操作

3.2.1 在hbase中查询:
scan 't2_hbase'

在这里插入图片描述

3.3 Phoenix操作

3.3.1 使用表方式映射hbase中已存在的表
create table "t2_hbase" (id varchar primary key,"mycg"."age" UNSIGNED_INT,"mycg"."datestr" UNSIGNED_DATE,"mycg"."name" varchar)column_encoded_bytes=0;
3.3.2 查询
select * from "t2_hbase";

在这里插入图片描述

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值