HBase 由 Java 语言实现,同时他也是最主要最高效的客户端。 相关的类在org.apache.hadoop.hbase.client 包中。涵盖所有 增删改查 API 。 主要的类包含: HTable、HBaseAdmin、Put、Get、Scan、Increment 和 Delete 等。

        HBase 是一个 NoSQL数据库。JAVA客户端提供了增删改查表的DDL操作,同时提供了一些工具。类似合并、分裂 Region 等。

 

       使用 HBase 原生客户端需要创建 配置类、定义 HMaster 地址、定义 Zookeeper 端口、 Zookeeper 队列名称 以及需要操作的表的名字。

       

         1. 简单的配置实例:

 

import java.io.IOException;

 

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;

import org.apache.hadoop.hbase.client.HBaseAdmin;

import org.apache.hadoop.hbase.client.HTable;

import org.apache.hadoop.hbase.util.Bytes;

 

public class HBaseManager extends Thread{

    /** 客户端的配置类 */

    public Configuration config;

    /**  */

    public HTable table;

    public HBaseAdmin admin;

    

    @SuppressWarnings("deprecation")

    public HBaseManager(){

        config = HBaseConfiguration.create();

        config.set("hbase.master", "test:80000");                   // HMaster 地址

        config.set("hbase.zookeeper.propertity.clientPort", "2181");// ZooKeeper 端口

        config.set("hbase.zookeeper.quorum", "test1,test2,test3");  // ZooKeeper 队列名称

        try {

            table = new HTable(config, Bytes.toBytes("demo_table"));// 用于连接单独的表(非线程安全)

         // table = new HTable(config, "test",new ExecutorService); //   外部独立维护的线程池类

            admin = new HBaseAdmin(config);                         // 管理数据库

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

}

          读数据

                1,初始化 HTable 实例

                2,构造实体类 Get  // get可以在new时设置行键, 可以 设置查询属性,如只要 addColumn() 如 addFamily()。 是否开启缓存 setCacheBlocks()、设置返回多少版本 setMaxVersions()。setTimeRange(long)方法用于设置返回那个时间戳版本。 setTimeRange(long,long)返回时间戳区间

                      构造实体类 Scan 实际上Get方法内部也是使用 Scan去实现的。

                3,执行查询

 

 

    ExecutorService pool)

 

 

        

mac hbase客户端 hbase客户端工具_客户端

 

 

 

 

 

 

 

 

 

 

 

 

                                                                                                                    God has given me a gift. Only one. m the most complete fighter in the world. My whole life, I have trained. I must prove I am worthy of someting.                                                             rocky_24


God has given me a gift. Only one. I am the most complete fighter in the world. My whole life, I have trained. I must prove I am worthy of someting. rocky_24