八天学会hadoop (6) hbase

hbase 基于Hdfs 文件系统  hbase 支持随机高速访问

hbase 没有事务特性 hbase不能处理联合关系处理 比如mysql 里面的join 

hbase优点在于存放非常大的表 百万行 百万列 支持随机高速访问

 

Hbase 表结构

表名->行键->列族(column family)->列名(qualifier)->版本号

 

具体请查看:https://www.cnblogs.com/steven-note/p/7209398.html

hbase 创建 增加数据代码展示

public class HbaseTest {


    public static void main(String[] args) {
        Configuration configuration = HBaseConfiguration.create();
        configuration.set("hbase.zookeeper.quorum","192.168.36.139:2181,192.168.36.139:2182,192.168.36.139:2183");
        //createTable(configuration);

        InsertTest(configuration);

    }

    public static void InsertTest(Configuration configuration) {
        HTable hTable = null;
        try {
            hTable = new HTable(configuration, "dj");
        } catch (IOException e) {
            e.printStackTrace();
        }

        Put row1 = new Put(Bytes.toBytes("row1"));
        row1.add(Bytes.toBytes("f1"), Bytes.toBytes("tuya"), Bytes.toBytes("zhuangbi"));
        Put row2 = new Put(Bytes.toBytes("row2"));
        row2.add(Bytes.toBytes("f1"), Bytes.toBytes("xiaopeng"), Bytes.toBytes("wanyingde"));

        ArrayList<Put> puts = new ArrayList<>();
        puts.add(row1);
        puts.add(row2);

        try {
            hTable.put(puts);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }




    public static void createTable(Configuration configuration) {


        HBaseAdmin hBaseAdmin=null;
        try {
            hBaseAdmin= new HBaseAdmin(configuration);
        } catch (IOException e) {
            e.printStackTrace();
        }
        TableName table = TableName.valueOf("dj");
        HTableDescriptor hTableDescriptor = new HTableDescriptor(table);
        HColumnDescriptor f1 = new HColumnDescriptor("f1");
        hTableDescriptor.addFamily(f1);
        try {
            hBaseAdmin.createTable(hTableDescriptor);
        } catch (IOException e) {
            e.printStackTrace();
        }


    }



}

 

 

 

 

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值