• Package org.apache.hadoop.hbase.client

    提供HBase客户端接口

    参考: Description

    Interface概要  
    Interface Description
    Attributes  
    HConnection
    创建于集群间的连接.
    HTableInterface
    使用单一的HBase表进行数据交互.
    HTableInterfaceFactory
    定义了创建HTableInterface的方法.
    ResultScanner
    提供客户端扫描表的接口.
    Row
    HBase表中的一行数据.
  • Class概要
    Class Description
    Append
    在单行上进行追加操作.
    ClientScanner
    实现了面向HBase客户端调用的scanner接口.
    ClientSmallScanner
    用于客户端scanner的小范围扫描.
    Delete
    用于在单行上执行Delete操作.
    Get
    用于在单行上执行Get操作.
    HBaseAdmin
    提供了一个接口和admin级别方法去管理HBase数据库及相关表数据.
    HConnectionManager
    用于创建的 HConnections的不可实例化的类.
    HTable
    用于访问单个HBase表.
    HTableFactory
    用于创建HTable实例的工厂类.
    HTableMultiplexer
    HTableMultiplexer提供了应用于表间的线程安全非阻塞的PUT API.
    Increment
    用于在单行上执行增量操作.
    Mutation  
    Operation
    可以匹配可能的应用级别查询的任意类型的超类.
    OperationWithAttributes  
    Put
    用于在单行上执行Put操作.
    Result
    查询 GetScan的单行结果.
    RowMutations
    在单行上执行原子性的多种更新操作(Put or Delete).
    Scan
    用于执行查询Scan操作.
    UnmodifyableHTableDescriptor
    Read-only表的描述符.
  • Enum概要
    Enum Description
    Durability
    该枚举类型描述了表操作的持续性(不被切换或中断)类型,意味着数据项必须按增量的durability顺序来存储。
    IsolationLevel
    查询操作的隔离级别.
  • Exception Summary  
    Exception Description
    NoServerForRegionException
    当无法找到分区的regionserver时报此异常
    RegionOfflineException
    当无法定义某个表时报此异常
    RetriesExhaustedException
    某些操作被连续尝试但一直失败时,与HTable相关的方法报此异常.
    RetriesExhaustedWithDetailsException
    当有更多的类似与哪个服务器上的哪一行数据引起异常的信息时,它 作为 RetriesExhaustedException的子类被抛出
    ScannerTimeoutException
    Scan操作超时.
    WrongRowIOException  

Package org.apache.hadoop.hbase.client Description

提供HBase客户端

关于表

  • Overview
  • Example API Usage

Overview

对于HBase管理员, 可使用 HBaseAdmin进行增删查改操作. 表一旦被创建,可通过 HTable的一个实例来访问,如一次向一个表插入一行. 而插入操作可通过 Put 对象来完成. 通过指定值,目标列及可选的时间戳,类似于 HTable.put(Put)即可提交更新. 
可使用 Get 来获取已插入的值.  Get 使用的范围较广-- 获取某一行的所有数据 --或一部分(如返回一列). 在创建了Get的实例后,可以调用  HTable.get(Get)
使用 Scan 可创建扫描器 -- 如用于访问数据的游标. 在创建及配置Scan实例后, 调用  HTable.getScanner(Scan)并在返回对象激活下一个scanner.  HTable.get(Get) 与  HTable.getScanner(Scan) 都会返回一个  Result对象. 一个Result对象就是一组 KeyValues的队列. 它被以不同的格式打包后返回. 
使用  Delete 可删除数据. 你可以删除单个列或整个列族, 等等. 具体删除用法如  HTable.delete(Delete) .

Put, Get 和 Delete这些操作在执行期间会对行进行加锁. 而在单行上的并发修改会被序列化执行. 在没有行锁的制约时,Get and scan可并行运行,并且保证不返回包含未完全写入的数据.

通过ZooKeeper,客户端代码可访问某个集群信息. 这意味着必须在客户端上的CLASSPATH设置了ZooKeeper的代理配置,才能正常使用. 这通常也是说要保证客户端能找到hbase-site.xml文件.

用法用例

当你拥有一个正在运行的HBase服务, 你可能回想在上面运行你的一个应用. 如果你的程序是用Java构建的,那么就应该使用Java API来进行对HBase的操作. 以下是一个简单的操作HBase示例. 该示例假定已创建了一个名为"myTable"的表,其列族名为"myColumnFamily".

import java.io.IOException;import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;// Class that has nothing but a main.
// Does a Put, Get and a Scan against an hbase table.
public class MyLittleHBaseClient {public static void main(String[] args) throws IOException {// You need a configuration object to tell the client where to connect.// When you create a HBaseConfiguration, it reads in whatever you've set// into your hbase-site.xml and in hbase-default.xml, as long as these can// be found on the CLASSPATHConfiguration config = HBaseConfiguration.create();// This instantiates an HTable object that connects you to// the "myLittleHBaseTable" table.HTable table = new HTable(config, "myLittleHBaseTable");// To add to a row, use Put.  A Put constructor takes the name of the row// you want to insert into as a byte array.  In HBase, the Bytes class has// utility for converting all kinds of java types to byte arrays.  In the// below, we are converting the String "myLittleRow" into a byte array to// use as a row key for our update. Once you have a Put instance, you can// adorn it by setting the names of columns you want to update on the row,// the timestamp to use in your update, etc.If no timestamp, the server// applies current time to the edits.Put p = new Put(Bytes.toBytes("myLittleRow"));// To set the value you'd like to update in the row 'myLittleRow', specify// the column family, column qualifier, and value of the table cell you'd// like to update.  The column family must already exist in your table// schema.  The qualifier can be anything.  All must be specified as byte// arrays as hbase is all about byte arrays.  Lets pretend the table// 'myLittleHBaseTable' was created with a family 'myLittleFamily'.p.add(Bytes.toBytes("myLittleFamily"), Bytes.toBytes("someQualifier"),Bytes.toBytes("Some Value"));// Once you've adorned your Put instance with all the updates you want to// make, to commit it do the following (The HTable#put method takes the// Put instance you've been building and pushes the changes you made into// hbase)table.put(p);// Now, to retrieve the data we just wrote. The values that come back are// Result instances. Generally, a Result is an object that will package up// the hbase return into the form you find most palatable.Get g = new Get(Bytes.toBytes("myLittleRow"));Result r = table.get(g);byte [] value = r.getValue(Bytes.toBytes("myLittleFamily"),Bytes.toBytes("someQualifier"));// If we convert the value bytes, we should get back 'Some Value', the// value we inserted at this location.String valueStr = Bytes.toString(value);System.out.println("GET: " + valueStr);// Sometimes, you won't know the row you're looking for. In this case, you// use a Scanner. This will give you cursor-like interface to the contents// of the table.  To set up a Scanner, do like you did above making a Put// and a Get, create a Scan.  Adorn it with column names, etc.Scan s = new Scan();s.addColumn(Bytes.toBytes("myLittleFamily"), Bytes.toBytes("someQualifier"));ResultScanner scanner = table.getScanner(s);try {// Scanners return Result instances.// Now, for the actual iteration. One way is to use a while loop like so:for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {// print out the row we found and the columns we were looking forSystem.out.println("Found row: " + rr);}// The other approach is to use a foreach loop. Scanners are iterable!// for (Result rr : scanner) {//   System.out.println("Found row: " + rr);// }} finally {// Make sure you close your scanners when you are done!// Thats why we have it inside a try/finally clausescanner.close();}}
}

关于插入数据到HBase或从中获取数据,还有更多的方法, 但目前上面的示例已经可以让你开始访问并操作HBase数据了. 可参考HTable javadoc以了解更多的方法. 另外,类HBaseAdmin提供很多管理HBase表的方法接口.

如果你的程序并非为Java所构建的, 那你应该考虑使用Thrift或者REST中的库了.

相关文档

  • HBase Home Page
  • HBase Wiki
  • Hadoop Home Page

同时可参考HBase Reference Guide一节,其内容提及了 HBase Client. 其中还有一小节介绍了如何在多线程下访问HBase,并在客户端程序中如何控制资源等等.

原文链接:http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/package-summary.html

【HBase】关于包org.apache.hadoop.hbase.client相关推荐

  1. 启动HBase抛出org.apache.hadoop.hbase.ClockOutOfSyncException异常:hmaster正常,节点hregionserver启动失败

    启动HBase抛出org.apache.hadoop.hbase.ClockOutOfSyncException异常 原因 节点间时间不一致,时间同步出了问题: 解决 进行时间同步: [root@cm ...

  2. 【hbase问题】org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not run

    启动后无论什么命令都会报Server is not run,查询日志后发现各种问题都有,但是没得都不能解决问题.遂一气之下重装hbase,然后重新启动,依旧报错,查看日志,发现日志有新的报错信息 经排 ...

  3. Exception in thread “main“ org.apache.hadoop.hbase.client.RetriesExhaustedException: Can‘t get the l

    看尚硅谷视频,在windows上运行集群上的hbase时 package org.example;import org.apache.hadoop.hbase.HBaseConfiguration; ...

  4. HBase出现java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration问题

    问题:Hbase在集群上运行报错:NoClassDefFoundError:org/apache/hadoop/hbase/HBaseConfiguration 需求:HBase使用Java创建表,打 ...

  5. org.apache.hadoop.hbase.NotServingRegionException: hbase:meta,,1 is not online问题(暂时没有解决)

    在试图使用 sqoop从mysql导数据到hbase的过程中,发生下面报错: 2020-06-30 11:53:38,636 ERROR [main] tool.ImportTool (ImportT ...

  6. org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet

    hbase 进行 javaAPI 操作时报了如下错误 : org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after ...

  7. 【异常】org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=36, exceptions:

    [异常]org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=36, exceptions: ...

  8. (Hive)org.apache.hadoop.hbase.client.Put.setDurability(Lorg/apache/hadoophbase/client/Durability;)V

    报错信息: Error: java.lang.RuntimeException: java.lang.NoSuchMethodError:org.apache.hadoop.hbase.client. ...

  9. 处理org.apache.hadoop.hbase.client.ScannerTimeoutException

    使用spark读取hbase数据成为rdd数据结构时,不论spark作业的运行模式是client和cluster都报了一个异常: org.apache.hadoop.hbase.client.Scan ...

最新文章

  1. Edgware.RC1中ZuulFallbackProvider的改进
  2. 队列和通知区别_消息队列,阻塞队列
  3. 依赖项出现感叹号怎么办_SpringBoot中如何对依赖进行管理?
  4. sort降序shell_排序之希尔排序(shell sort)
  5. ECMAScript 6环境搭建
  6. .NET中的跟踪与调试(TraceDebug)
  7. 【Nacos】Nacos MySQL 配置后无法登录 愚蠢的问题
  8. Hadoop权威指南读书笔记(2) — Yarn简介及Capacity Fair Scheduler
  9. 进行计算机系统管理调度监控和维护的软件是,MES车间调度监控系统软件
  10. 二级考试内容之C和Python
  11. 断臂求生!捷信全线退出医美市场
  12. oracle ebcdic 转换,使用sqlldr导入EBCDIC格式数据并新增Oracle字符集
  13. 虚拟机Ubuntu18.04开机后没有网络的解决办法
  14. php imap 存草稿,学习猿地-PHP-imap 使用参考
  15. CSS3干货28:妙用 transition 实现中英文切换导航
  16. 计算机网络课程见习报告
  17. JZOJ_7.8C组第一题 音乐节拍
  18. JavaWeb-旅游网-注册和登录
  19. 报考PMP的条件和费用都有哪些?培训费和报考费是分开的吗?过来人教你如何避免被 pian!
  20. R-studio超强数据恢复工具(含带注册码)

热门文章

  1. UOJ224/洛谷P1737 【NOI2016】旷野大计算 造计算机
  2. 克里希纳穆提的作品!
  3. 【历史上的今天】9 月 11 日:Adobe 公司联合创始人出生;现代游戏机鼻祖诞生;谷歌推出 Android Pay
  4. 手撸一款第三方链克钱包
  5. UE4场景“郊区”:建模技术,使用Substance纹理化和顶点绘制等
  6. 微信链接卡片在线制作工具及教程
  7. 动力学分析基础(一)
  8. 什么叫显示动力学_ANSYS-什么叫显示动力学
  9. Cookies和Session的介绍
  10. vue 3.0 即将发布,敬请期待