Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Hbase1.0.0- official documentation-java-api- fundamentals

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

@ see 67.1.1. API as of HBase 1.0.0

@ see 67.1.1. API as of HBase 1.0.0_detail

It's been cleaned up and users are returned Interfaces to work against rather than particular types.

In HBase 1.0, obtain a Connection object from ConnectionFactory and thereafter, get from it instances of Table, Admin, and RegionLocator on an as-need basis.

When done, close the obtained instances.

The old API has been cleaned up and users use interfaces rather than specific classes to manipulate API.

In HBase 1. 0, get a Connection object from _ ConnectionFactory, and then get instances from Table,Admin and RegionLocator_ as needed. Close when you're done.

Finally, be sure to cleanup your Connection instance before exiting.

Connections are heavyweight objects but thread-safe so you can create one for your application and keep the instance around.

Finally, be sure to clean up the Connection instance before exiting.

Connection is a heavyweight object, but thread-safe, so you can create one for your application and keep the instance.

Table, Admin and RegionLocator instances are lightweight.

Create as you go and then let go as soon as you are done by closing them.

See the Client Package Javadoc Description for example usage of the new HBase 1.0 API.

Table,Admin and RegionLocator instances are lightweight.

Create them at any time, and then turn them off as soon as you're done.

Check the instructions for the client software package Javadoc for examples of how to use the new HBase 1.0 API.

To administer HBase, create and drop tables, list and alter tables, use Admin.

Once created, table access is via an instance of Table.

You add content to a table a row at a time.

To manage HBase,create and delete tables, list and alter tables, use Admin (DDL).

Once the table is created, access the table: Table (DML) instance.

Add one row at a time to the table.

To insert, create an instance of a Put object.

Specify value, target column and optionally a timestamp.

Commit your update using Table.put (Put).

To insert, create an instance of the Put object. Specify a value, target column, and optional timestamp.

Use _ Table.put (Put) _ to submit the update.

To fetch your inserted value, use Get.

The Get can be specified to be broad-- get all on a particular row-- or narrow; I.E. Return only a single cell value.

After creating an instance of Get, invoke Table.get (Get).

To get the value you inserted, use Get.

Get can be specified as broad-get all the contents of a line-or narrow down the content

That is, only one cell value is returned. After creating an instance of Get, call Table.get (Get).

Use Scan to set up a scanner-- a Cursor- like access.

After creating and configuring your Scan instance, call Table.getScanner (Scan) and then invoke next on the returned object.

Both Table.get (Get) and Table.getScanner (Scan) return a Result.

Use Scan to set Scanner-cursor-like access.

After creating and configuring the Scan instance, call Table.getScanner (Scan), and then call next on the returned object.

Both _ Table.get (Get) and Table.getScanner (Scan) return Result_.

Use Delete to remove content.

You can remove individual cells or entire families, etc.

Pass it to Table.delete (Delete) to execute.

Use Delete to delete content.

You can delete a single cell or an entire column family.

Pass the Delete to Table.delete (Delete) for execution.

Puts, Gets and Deletes take out a lock on the target row for the duration of their operation.

Concurrent modifications to a single row are serialized.

Gets and scans run concurrently without interference of the row locks and are guaranteed to not to return half written rows.

Put, Get, and Delete take locks on the target row during the operation.

Modifying a line in parallel is serialized (one by one).

Get and Scan run concurrently without lock interference and are guaranteed not to return half the data (it would be awkward to return half a row of data).

Client code accessing a cluster finds the cluster by querying ZooKeeper.

This means that the ZooKeeper quorum to use must be on the client CLASSPATH.

Usually this means make sure the client can find your hbase-site.xml.

The client code that visits the cluster finds the cluster by querying ZooKeeper.

This means that the ZooKeeper arbitration to be used must be on the client-side CLASSPATH.

Usually this means making sure that the client can find your hbase-site.xml.

Package com.niewj.util;import java.io.IOException;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.TableName;import org.apache.hadoop.hbase.client.Connection;import org.apache.hadoop.hbase.client.ConnectionFactory;import org.apache.hadoop.hbase.client.Get;import org.apache.hadoop.hbase.client.Table;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;// Put, Get, Scan for a hbase table. API is based on HBase 1.0.public class MyLittleHBaseClient {public static void main (String [] args) throws IOException {/ / library and can be created through hbase shell: create 'zoo_htable_1',' cf1' String tableNameString = "zoo_htable_1"; Configuration config = HBaseConfiguration.create () / / load hbase information config.set ("hbase.zookeeper.quorum", "master.14.niewj.spark,slave1.146.niewj.spark,slave2.207.niewj.spark"); config.set ("hbase.zookeeper.property.clientPort", "2181"); config.set ("zookeeper.znode.parent", "/ hbase") from zk configuration; / / 1. Next, you need to connect to the cluster. Create one. When it's done, close it. / / 2. Try / finally is a good way to make sure it is turned off (or using jdk7,try-with-resources) / 3. Connection is heavyweight. Create one and keep it. / / 4. From Connection, take the Table instance to access the Tables, manage the Admin instance of the cluster, and RegionLocator to find the zone on the cluster. / / 5. In contrast to Connections, Table,Admin and RegionLocator instances are lightweight; they are created as needed, and then closed when finished. Connection connection = ConnectionFactory.createConnection (config); try {/ / 1. Let's instantiate a Table object that connects you to the "zoo_htable_1" table (TableName.valueOf converts String to a TableName instance). / / 2. When it is finished, close it (should start an attempt / finally after this creation, so it is sure that Table table = connection.getTable (TableName.valueOf (tableNameString)); try {/ / 1. To add to a row, use Put. The name of the row to be inserted by the Put constructor as a byte array. / / in HBase, the Bytes class has utilities for converting various java types into byte arrays. / / below, we convert the string "myLittleRow" into a byte array as our updated rowkey. / / once you have an instance of Put, you can set the name of the updated column on the line, the timestamp used, etc.: if there is no timestamp, the server uses the current time for editing. Put p = new Put (Bytes.toBytes ("rk_100001")); / / set the value to update in the "rk_100001" row, specify the column family, column name, and value of the cell. / / the column family must already exist. Specify that it can be anything. All values must be byte arrays, because hbase is all about byte arrays. / / Let's pretend that the table myLittleHBaseTable is a p.addColumn created with the cf1 series (Bytes.toBytes ("cf1"), Bytes.toBytes ("uname"), Bytes.toBytes ("Jobs"); / / all updates are in the Put instance, submit it and push it to hbase table.put (p) using HTable#put; / / now, retrieve the data just written. The returned value is the Result instance. The result is that a hbase returns the most delicious form of object Get g = new Get (Bytes.toBytes ("rk_100001")); Result r = table.get (g); byte [] value = r.getValue (Bytes.toBytes ("cf1"), Bytes.toBytes ("uname")) / / convert the byte value and return the actual inserted value String valueStr = Bytes.toString (value); System.out.println ("\ t GET:" + valueStr); / / sometimes you don't know the line you're looking for. In this case, you are using a Scanner. Provides a pointer-like interface for the contents of the table. Set up Scanner to create a Scan just like assembling Put and Get. Decorate with column names. Scan s = new Scan (); s.addColumn (Bytes.toBytes ("cf1"), Bytes.toBytes ("uname")); ResultScanner scanner = table.getScanner (s); try {/ / Scanners returns the Result instance. Iterative result method 1: for (Result result = scanner.next (); result! = null; result = scanner.next ()) {/ / print out the found columns content System.out.println ("Found row:" + result);} / / another method is to use the foreach loop. Scanner is iterable / / for (Result rr: scanner) {/ / System.out.println ("Found row:" + rr); / /} finally {/ / make sure to close scanners after use! So put in finally: scanner.close ();} / close table, close connection} finally {if (table! = null) {table.close ();} finally {connection.close () }}}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report