设为首页 收藏本站
查看: 1345|回复: 0

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

[复制链接]

尚未签到

发表于 2015-11-11 11:29:44 | 显示全部楼层 |阅读模式




  • 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

    查询Get或Scan的单行结果.

    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 CLASSPATH
Configuration 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 for
System.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 clause
scanner.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



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-137847-1-1.html 上篇帖子: Ubuntu14.04下hadoop-2.6.0单机配置和伪分布式配置 下篇帖子: hadoop2.2+hive0.13安装和配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表