[Original] a problem where data cannot be inserted into the HBase table

Source: Internet
Author: User
Reprinted must indicate the source: www.codelast.com encountered a problem where data cannot be inserted into HBase. After discovering the problem, I thought it was a super record. [1] before writing a program, use hbaseshell to create a data table: createtest, {NAMEf, COMPRESSIONNONE, VERSIONS

Reprinted must indicate the source: http://www.codelast.com/encountered a case can not be inserted into HBase data problems, found the problem after think super record. [1] before writing a program, use hbase shell to create a data table: create 'test', {NAME = 'F', COMPRESSION = 'none', VERSIONS

Reprint must indicate the source: http://www.codelast.com/

In the case of a problem where data cannot be inserted into HBase, I thought it was a super record.

[1] before writing a program, create a data table through hbase shell:

create 'test', {NAME => 'f', COMPRESSION => 'NONE', VERSIONS => '1', TTL => '5184000', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}

In this way, an HBase table named "test" is created, and its column family is "f ".

[2] Write Java code to insert a record into the HBase table. The Code is as follows:

import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.client.HTable;import org.apache.hadoop.hbase.client.Put;import org.apache.hadoop.hbase.util.Bytes;import org.apache.log4j.Logger;import java.io.IOException;import java.util.ArrayList;import java.util.List;public class HBasePutTest {  private static Logger LOGGER = Logger.getLogger(HBasePutTest.class);  private static List
 
   list = new ArrayList
  
   ();  private static HTable tableTest = initHTableTest();  public static HTable initHTableTest() {    HTable table = null;    try {      table = new HTable(new HBaseConfiguration(), "test");    } catch (IOException e) {      LOGGER.error(e.toString());    }    return table;  }  public static void main(String[] args) {    Put put = new Put(Bytes.toBytes("abc"));    put.add(Bytes.toBytes("f"),            Bytes.toBytes("q"), 13399L,            Bytes.toBytes("123"));    list.add(put);    try {      tableTest.put(list);      LOGGER.info("Successfully put 1 record into HBase.");    } catch (Exception e) {      LOGGER.error(e.toString());    } finally {      list.clear();    }  }}
  
 

Source: http://www.codelast.com/
The above code inserts a record into the "test" table of HBase. row key is "abc", value is "123", and column family is "f ", qualifier is "q" (that is, column is "f: q"), and the record timestamp is 13399 (a random value ).

[3] The Code seems to be okay. Therefore, we execute it and return to hbase shell to check whether the record is successfully inserted into the HBase table named "test:

get 'test', 'abc'

This indicates that all records whose row key is "abc" are retrieved from the "test" table.
The result is: no one is returned. Why?

[4] analyze the problem. After the experiment, I found that setting the timestamp of the record to the current time in the Java code can successfully insert a record to HBase, so I finally found that the original is: when creating an HBase table, the set TTL value makes the record whose timestamp is 13399. Even if an HBase table is inserted, it will be deleted immediately. Therefore, hbase shell cannot be used.
Source: http://www.codelast.com/
Therefore, you must pay attention to the traps in the test environment during debugging.

Original article address: [original] an issue where data cannot be inserted into the HBase table. Thank you for sharing with me.

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.