14 Data Model operations

Source: Internet
Author: User

Operation of the data Model HBase's 4 main operations for the data model include Get, Put, Scan, and Delete. Operate through Htbale instances. HBase All data modification Operations guarantee row-level atomicity. Either read the latest data or wait for the system to allow changes to be written to the row.

The Get () method is provided in the 1 Get Htable class, along with a get class corresponding to which a get operation returns one or more rows of data
When the Get method gets the data, HBase returns a result that contains all matching cell data that is encapsulated in a result instance that is returned to the user. Using the method provided by the Result class, you can get specific return values that match the specified rows from the server side, including column families, column qualifiers, and timestamps.
               Configuration conf = hbaseconfiguration.Create();Connection Connection = connectionfactory. createconnection (conf);Table table=connection.gettable (TableName. ValueOf(TableName));            Getget=New Get (Rowkey.getbytes ());            Resultresult = Table.get (get);

2 put put can be inserted one line at a time or you can insert a collection at a time.
If you need to modify data for some rows frequently, users should create an instance of Rowlock to prevent other users from modifying the row's data. (HBase thread, hbase thing, HBase Lock) The put operation initiates an RPC operation to the server each time, and if there is a large amount of data to write to the table, there will be thousands of RPC operations, which is inefficient. The HBase client has a buffer that is responsible for sending the data to the server only through a single RPC operation, which can greatly improve performance, the default client write buffer is off and needs to be turned on (HBase optimized)
When a Put collection is submitted to the server, a partially successful partial failure may occur, and the failed data is saved in the cache for retry.
HBase provides a compare-and-set operation, which is checked first and then executed after the condition is met, and the operation is atomic to the row.    HBase does not have an Update operation, it is a Put operation to complete the modification of the data.

3 Scan scan operations allow multiple lines of specific attribute iterations, in a manner similar to Get. Works in a similar way to iterators. StartRow defines the starting row key for the scan HBase table. Stoprow the stop of the restricted read.
All column families and all columns of the table are scanned by default after creation.    Read data can be qualified in several ways. Scan has a lot of optimizations, and using a good scan will bring an enormous boost to HBase queries.


public static void Main (string[] args) throws IOException {       //scan class common method description       & nbsp Specify the desired family or column, and if no addfamily or column is called, all columns;        //scan.addfamily () are returned;         //Scan.addcolumn ();       //scan.setmaxversions (); Specifies the maximum number of versions. If you call setmaxversions without any arguments, it means that all versions are taken. If you do not use Setmaxversions, you will only be taken to the latest version .       //Scan.settimerange (); Specifies the maximum timestamp and minimum timestamp, only the cell within this range can be obtained .       //Scan.settimestamp (); Specify timestamp        //Scan.setfilter (); Specify filter to filter out unwanted information        //Scan.setstartrow (); Specifies the starting line. If not called, start with the header;       //Scan.setstoprow (); Specify the end of the line (excluding this line);       //Scan.setbatch (); Specifies the maximum number of cells to return. Used to prevent excessive data in a row, resulting in outofmemory errors.                //Filters        //1, filterlist represents a filter list &nbs P &nbsp    //filterlist.operator.must_pass_all-->and       //filterlist.operator.must_ Pass_one-->or       //eg, filterlist list = new filterlist (FilterList.Operator.MUST_PASS_ONE); nbsp      //2, singlecolumnvaluefilter       //3, Columnprefixfilter for specifying column name prefix values equal   & nbsp    //4, Multiplecolumnprefixfilter and columnprefixfilter behave similarly, but multiple prefixes can be specified.        //5, Qualifierfilter is a filter based on the column name.        //6, rowfilter       //7, Regexstringcomparator are comparators that support regular expressions.        //8, Substringcomparator is used to detect if a substring exists in a value and is case insensitive.                 htable table= (htable) Gethtablepool (). GetTable ("Tb_stu"); nbsp       Scan scan=new scan ();        scan.setmaxversions ();       // Specifies the maximum number of cells to return. Used to prevent excessive data in a row, resulting in outofmemory errors.       &NBSp Scan.setbatch (1000);
       //scan.settimestamp (Numberutils.tolong ("1370336286283"));       // Scan.settimerange (Numberutils.tolong ("1370336286283"), Numberutils.tolong ("1370336337163"));       //scan.setstartrow (bytes.tobytes ("Quanzhou"));       //scan.setstoprow (Bytes.tobytes (" Xiamen "));       //scan.addfamily (bytes.tobytes (" info "));        // Scan.addcolumn (bytes.tobytes ("info"), bytes.tobytes ("id"));               //Query column arrowheads to info, column ID value 1 records        //Method one (single query)        //Filter filter = new Sing Lecolumnvaluefilter (       //        bytes.tobytes ("info"), bytes.tobytes ("id" ), Compareop.equal, Bytes.tobytes ("1");        //Scan.setfilter (filter);               //Method II (combination query)     &NBSp  //filterlist filterlist=new filterlist ();       //filter Filter = new Singlecolumnvaluefilter (       //   bytes.tobytes ("info"), bytes.tobytes ("id"), compareop.equal, bytes.tobytes ("1"));        //filterlist.addfilter (filter);       //scan.setfilter (filterlist); nbsp               Resultscanner rs = table.getscanner (scan);      &NBSP ;         for (Result R:rs) {            for (KeyValue Kv:r.raw ()) {                SYSTEM.OUT.PRINTLN (String.Format ("row:%s, family:%s, Qualifi er:%s, qualifiervalue:%s, timestamp:%s. ",                     &NBSP ;   Bytes.tostring (Kv.getrow ()),                       &NBS P Bytes.tostriNg (kv.getfamily ()),                         Bytes.tostrin G (Kv.getqualifier ()),                         BYTES.TOSTR ING (Kv.getvalue ()),                      Kv.gettimestamp ())) ;           }       }            &N Bsp   Rs.close ();   }







                                                                                                                    God has given me a gift. Only one. I am the most complete fighter. My whole life, I had trained. I must prove I am worthy of someting.                                                             rocky_24





From for notes (Wiz)

14 Data Model operations

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.