Hbase Java API

Source: Internet
Author: User

Correspondence between several related classes and hbase Data Models

Java class Hbase Data Model
Hbaseadmin Database)
Hbaseconfiguration
Htable Table)
Htabledescriptor Column family)
Put Column modifier (column qualifier)
Get
Bytes

 

I. hbaseconfiguration

Link: org. Apache. hadoop. hbase. hbaseconfiguration

Purpose: Configure hbase

Return Value Function Description
Void Addresource (path file) Add resources by specifying the file in the specified path
Void Clear () Clear all set properties
String Get (string name) Get the value corresponding to the property name
String Getboolean (string name, Boolean defaultvalue) Obtain the attribute value of the boolean type. If the attribute value type is Boolean, the default attribute value is returned.
Void Set (string name, string value) Set Value Through attribute name
Void Setboolean (string name, Boolean value) Set attribute values of the Boolean Type

Usage example:

HBaseConfiguration hconfig = new HBaseConfiguration();hconfig.set("hbase.zookeeper.property.clientPort","2181");

This method sets "hbase. zookeeper. Property. clientport" to 2181. Generally, hbaseconfiguration uses constructors for initialization and other methods.

Ii. hbaseadmin

Link: org. Apache. hadoop. hbase. Client. hbaseadmin

Function: provides an interface for managing table information of hbase databases. It provides the following methods: Create a table, delete a table, List table items, make the table valid or invalid, and add or delete table columnfamily members.

Return Value Function Description
Void AddColumn (string tablename, hcolumndescriptor column) Add an existing table
Checkhbaseavailable (hbaseconfiguration conf) Static function to check whether hbase is running
Createtable (htabledescriptor DESC) Create a table for synchronization
Deletetable (byte [] tablename) Delete an existing table
Enabletable (byte [] tablename) Make the table valid
Disabletable (byte [] tablename) Make the table invalid
Htabledescriptor [] Listtables () List all user controls
Void Modifytable (byte [] tablename, htabledescriptor htd) It may take some time to modify the table mode, which is an asynchronous operation.
Boolean Tableexists (string tablename) Check whether the table exists

Usage example:

HBaseAdmin admin = new HBaseAdmin(config);admin.disableTable("tablename")

3. htabledescriptor

Link: org. Apache. hadoop. hbase. htabledescriptor

Function: contains the columnfamily of the table whose names are extremely matched.

Return Value Function Description
Void Addfamily (hcolumndescriptor) Add a columnfamily
Hcolumndescriptor Removefamily (byte [] column) Remove a columnfamily
Byte [] Getname () Get the table name
Byte [] Getvalue (byte [] key) Get Attribute Value
Void Setvalue (string key, string value) Set attribute values

Usage example:

HTableDescriptor htd = new HTableDescriptor(table);htd.addFamily(new HcolumnDescriptor("family"));

In the preceding example, an hcolumndescriptor instance is used to add a columnfamily for the htabledescriptor.

Iv. hcolumndescriptor

Link: org. Apache. hadoop. hbase. hcolumndescriptor

Purpose: maintain information about the column family, such as the version number and compression settings. It is usually used when creating a table or adding a column family to a table. After a column family is created, it cannot be directly modified. You can only delete it and recreate it. When a column family is deleted, the data in the column family is also deleted.

Return Value Function Description
Byte [] Getname () Obtains the name of a column family.
Byte [] Getvalue (byte [] key) Get the value of the corresponding attribute
Void Setvalue (string key, string value) Set the value of the corresponding attribute

Usage example:

HTableDescriptor htd = new HTableDescriptor(tablename);HColumnDescriptor col = new HColumnDescriptor("content:");htd.addFamily(col);

In this example, a column family of content is added.

5. htable

Link: org. Apache. hadoop. hbase. Client. htable

Purpose: it can be used to directly communicate with hbase tables. This method is not thread-safe for update operations.

Return Value Function Description
Void Checkadnput (byte [] row, byte [] family, byte [] qualifier, byte [] value, put Automatically checks whether row/family/qualifier matches the specified value.
Void Close () Release all resources or suspend updates in the internal buffer
Boolean Exists (get) Check whether the value specified by the get instance exists in the htable column.
Result Get (get) Obtains the values of certain cells in a specified row.
Byte [] [] Getendkeys () Obtains the end key value of each area of the currently opened table.
Resulttables Getiterator (byte [] Family) Obtains the region instance of the given columnfamily.
Htabledescriptor Gettabledescriptor () Obtains the htabledescriptor instance of the current table.
Byte [] Gettablename () Get table name
Static Boolean Istableenabled (hbaseconfiguration Conf, string tablename) Check whether the table is valid
Void Put (put) Add value to table

Usage example:

HTable table = new HTable(conf, Bytes.toBytes(tablename));ResultScanner scanner =  table.getScanner(family);

Vi. Put

Link: org. Apache. hadoop. hbase. Client. Put

Role: Used to add a single row

Return Value Function Description
Put Add (byte [] family, byte [] qualifier, byte [] value) Add the specified column and corresponding value to the put instance.
Put Add (byte [] family, byte [] qualifier, long ts, byte [] value) Add the specified column, corresponding value, and timestamp to the put instance.
Byte [] Getrow () Get Put instance rows
Rowlock Getrowlock () Get the row lock of the put instance
Long Gettimestamp () Obtain the time stamp of the put instance.
Boolean Isempty () Check whether familymap is empty
Put Settimestamp (long timestamp) Set the time stamp of the put instance

Usage example:

Htable table = new htable (Conf, bytes. tobytes (tablename); Put P = new put (brow); // create a put Operation P for the specified row. add (family, qualifier, value); table. put (P );

VII. Get

Link: org. Apache. hadoop. hbase. Client. Get

Function: used to obtain information about a single row.

Return Value Function Description
Get AddColumn (byte [] family, byte [] qualifier) Obtains the columns corresponding to the specified column family and column modifier.
Get Addfamily (byte [] Family) Obtains all columns of the corresponding columns through the specified column family.
Get Settimerange (long minstamp, long maxstamp) Obtains the version number of the specified pickup column.
Get Setfilter (filter) Set the server-side filter when performing the get operation.

Usage example:

HTable table = new HTable(conf, Bytes.toBytes(tablename));Get g = new Get(Bytes.toBytes(row));

8. Result

Link: org. Apache. hadoop. hbase. Client. Result

Purpose: store the get or scan operation and obtain the single row value of the table. The methods provided by this class can be used to directly obtain values or various map structures (key-value pairs)

Return Value Function Description
Boolean Containscolumn (byte [] family, byte [] qualifier) Check whether the specified Column exists
Navigablemap <byte [], byte []> Getfamilymap (byte [] Family) Obtains the key-value pairs of modifiers and values contained in the corresponding columnfamily.
Byte [] Getvalue (byte [] family, byte [] qualifier) Obtain the latest value of the corresponding column

9. resulttables

Link: Interface

Function: interface for obtaining value from the client

Return Value Function Description
Void Close () Close the allocate and release the resources allocated to it.
Result Next () Get the value of the next row
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.