如何使用hbase java apiI操作Hbase

HBase Java API 类简单介绍_中华文本库
第1页/共3页
文本预览:
HBase Java API 几个相关类与 HBase 数据模型之间的对应关系
java 类 HBaseAdmin 数据库(DataBase) HBaseConfiguration HTable HTableDescriptor Put Get Scanner 列修饰符(Column Qualifier) 表(Table) 列族(Column Family) HBase 数据模型
一、HBaseConfiguration 关系:org.apache.hadoop.hbase.HBaseConfiguration 作用:对 HBase 进行配置
返回值 函数 void void addResource(Path file) clear() 描述 通过给定的路径所指的文件来添加资源 清空所有已设置的属性 获取属性名对应的值 获取为 boolean 类型的属性值,如果其属性值类型部位 boolean,则返回默认属性值 通过属性名来设置值
string get(String name) getBoolean(String name, boolean defaultValue) set(String name, String value) setBoolean(String name, boolean value)
设置 boolean 类型的属性值
用法示例:HBaseConfiguration hconfig = new HBaseConfiguration();
hconfig.set("hbase.zookeeper.property.clientPort""2181");
该方法设置了"hbase.zookeeper.property.clientPort"的端口号为 2181。 一般情况 下,HBaseConfiguration 会使用构造函数进行初始化,然后在使用其他方法。 二、HBaseAdmin 关系:org.apache.hadoop.hbase.client.HBaseAdmin
作用:提供了一个接口来管理 HBase 数据库的表信息。它提供的方法包括:创建表,删除 表,列出表项,使表有效或无效,以及添加或删除表列族成员等。
返回值 函数 addColumn(String tableName, HColumnDescriptor column) 静态函数,查看 HBase 是否 处于运行状态 创建一个表,同步操作 删除一个已经存在的表 使表处于有效状态 使表处于无效状态 列出所有用户控件表项 描述
向一个已经存在的表添加咧
checkHBaseAvailable(HBaseConfiguration conf) void
createTable(HTableDescriptor desc) deleteTable(byte[] tableName) enableTable(byte[] tableName) disableTable(byte[] tableName)
HTableDescriptor[] listTables()
modifyTable(byte[] tableName, HTableDescriptor 修改表的模式,是异步的操 htd) tableExists(String tableName) 作,可能需要花费一定的时间 检查表是否存在
用法示例:HBaseAdmin admin = new HBaseAdmin(config);
admin.disableTable("tablename")
三、HTableDescriptor 关系:org.apache.hadoop.hbase.HTableDescriptor 作用:包含了表的名字极其对应表的列族
返回值 void HColumnDescriptor byte[] byte[] void 函数 addFamily(HColumnDescriptor) removeFamily(byte[] column) getName() getValue(byte[] key) setValue(String key, String value) 描述 添加一个列族 移除一个列族 获取表的名字 获取属性的值 设置属性的值
用法示例:
HTableDescriptor htd = new HTableDescriptor(table);
htd.addFamily(new HcolumnDescriptor("family"));
在上述例子中,通过一个 HColumnDescriptor 实例,为 HTableDescriptor 添加了一个 列族:family 四、HColumnDescriptor 关系:org.apache.hadoop.hbase.HColumnDescri
第1页/共3页
寻找更多 ""Java通过api 操作hbase 0.98 - 下载频道
- CSDN.NET
&&&&Java通过api 操作hbase 0.98
Java通过api 操作hbase 0.98
在集群中创建java项目调用api来操作hbase,主要涉及对hbase的创建表格,删除表格,插入数据,删除数据,查询一条数据,查询所有数据等操作。
具体流程如下:
1.创建项目
2.获取jar包到项目的lib目录下(这边试用的事hbase 0.98 lib目录下的所有jar包)
3.编写java程序
4.编写ant脚本
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
您可能还需要
开发技术下载排行Java HBase 多线程 | X-Space1)">1)">1" ng-class="{current:{{currentPage==page}}}" ng-repeat="page in pages"><li class='page' ng-if="(endIndex<li class='page next' ng-if="(currentPage
相关文章阅读包依赖比较麻烦,找了好久,我用的CDH5.0 现将所依赖的包的列表清单如下:
public class EmployeeDao {
* @param args
*/ public static Configu   static {
    configuration = new Configuration();
    String filePath = "hbase-site.xml";
    Path path = new Path(filePath);
    configuration.addResource(path);
    configuration = HBaseConfiguration.create(configuration);   }   //使用过滤器实现查询   public List&Employee& QueryEmployeeByName(String name) throws Exception {
    String rowKey =
    HTable table = new HTable(configuration, "employee".getBytes());
    Scan scan = new Scan();
    // select ..... from .. where filter
    scan.addColumn("info".getBytes(), "age".getBytes());
    scan.addColumn("info".getBytes(), "sex".getBytes());
    RowFilter filter = new RowFilter(CompareOp.EQUAL,
    new RegexStringComparator(rowKey));
    scan.setFilter(filter);
    List&Employee& list = new ArrayList&Employee&();
    ResultScanner rScanner = table.getScanner(scan);
    for (Result rs : rScanner) {
      Employee e = new Employee();
      for (KeyValue kValue : rs.list()) {
        if ("sex".equalsIgnoreCase(new String(kValue.getQualifier()))) {
          e.setSex(new String(kValue.getValue()));
        }
        if ("age".equalsIgnoreCase(new String(kValue.getQualifier()))) {
          e.setAge(Integer.parseInt((new String(kValue.getValue()))));
        }
      }
      list.add(e);
       }   // 插入一个单元格数据   public static void insertOneRow(String tableName, String rowkey,
    String columnFamily, String column, String value) throws Exception {
    HTable table = new HTable(configuration, tableName);
    Put put = new Put(Bytes.toBytes(rowkey));
    put.add(Bytes.toBytes(columnFamily), Bytes.toBytes(column),
    Bytes.toBytes(value));
    table.put(put);// 放入表
    table.close();// 释放资源   }
  public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    EmployeeDao dao = new EmployeeDao();
    List&Employee& l = dao.QueryEmployeeByName("oftenlin");
    for (Employee e : l) {
      System.out.println("Name:oftenlin," + "Sex:" + e.getSex() + ",Age:"+ e.getAge());
    //insertOneRow("employee","allen","info","scholl","shi yan mid school");
    insertOneRow("employee","gold fly","info","scholl","shi yan mid school");
    System.out.println("写入成功!");   }
hbase-site.xml 的清单
&?xml version="1.0" encoding="UTF-8"?&
&!--Autogenerated by Cloudera Manager--&&configuration&
&property&
&name&hbase.rootdir&/name&
&value&hdfs://CentOS-cm:8020/hbase&/value&
&/property&
&property&
&name&hbase.client.write.buffer&/name&
&value&2097152&/value&
&/property&
&property&
&name&hbase.client.pause&/name&
&value&100&/value&
&/property&
&property&
&name&hbase.client.retries.number&/name&
&value&35&/value&
&/property&
&property&
&name&hbase.client.scanner.caching&/name&
&value&100&/value&
&/property&
&property&
&name&hbase.client.keyvalue.maxsize&/name&
&value&&/value&
&/property&
&property&
&name&hbase.rpc.timeout&/name&
&value&60000&/value&
&/property&
&property&
&name&hbase.snapshot.enabled&/name&
&value&true&/value&
&/property&
&property&
&name&hbase.security.authentication&/name&
&value&simple&/value&
&/property&
&property&
&name&zookeeper.session.timeout&/name&
&value&60000&/value&
&/property&
&property&
&name&zookeeper.znode.parent&/name&
&value&/hbase&/value&
&/property&
&property&
&name&zookeeper.znode.rootserver&/name&
&value&root-region-server&/value&
&/property&
&property&
&name&hbase.zookeeper.quorum&/name&
&value&CentOS-server3,CentOS-server2,CentOS-server1&/value&
&/property&
&property&
&name&hbase.zookeeper.property.clientPort&/name&
&value&2181&/value&
&/property&&/configuration&
阅读(...) 评论()

我要回帖

更多关于 hbase api 的文章

 

随机推荐