복붙노트

[HADOOP] 자바 API를 HBase를 연결하는 데 실패

HADOOP

자바 API를 HBase를 연결하는 데 실패

나는 (하둡없이) 독립형 모드에서 HBase를 연결하는 자바 API를 사용할 수 있습니까?

여기 내 코드입니다, 나는 그것이 작동하는 방법 궁금 해서요. 나는 변수 '설정'몇 가지 속성을 설정해야합니까?

나는이 로컬로 설치 한 : HBase를-0.98.0 하둡 2.2.0

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
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;


public class MyLittleHBaseClient {
  public static void main(String[] args) throws IOException {

    // maybe I should do some configuration here, but I don't know how
    Configuration config = HBaseConfiguration.create();

    HTable table = new HTable(config, "myLittleHBaseTable");

    Put p = new Put(Bytes.toBytes("myLittleRow"));

    p.add(Bytes.toBytes("myLittleFamily"), Bytes.toBytes("someQualifier"),
      Bytes.toBytes("Some Value"));

    table.put(p);

    Get g = new Get(Bytes.toBytes("myLittleRow"));
    Result r = table.get(g);
    byte [] value = r.getValue(Bytes.toBytes("myLittleFamily"),
      Bytes.toBytes("someQualifier"));

    String valueStr = Bytes.toString(value);
    System.out.println("GET: " + valueStr);

    Scan s = new Scan();
    s.addColumn(Bytes.toBytes("myLittleFamily"), Bytes.toBytes("someQualifier"));
    ResultScanner scanner = table.getScanner(s);
    try {

      for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {

        System.out.println("Found row: " + rr);
      }

    } finally {

      scanner.close();
    }
  }
}

해결법

  1. ==============================

    1.독립형 모드에서 HBase를-site.xml의 ()가 비어있는 경우, 당신은 어떤 일을 설정할 필요가 없습니다. HBase를-site.xml 파일에 아무것도 오버라이드 (override) 한 경우, 더 나은 대신 별도로 매개 변수를 설정하는 것을 HBase를-site.xml 파일을 추가합니다.

    독립형 모드에서 HBase를-site.xml의 ()가 비어있는 경우, 당신은 어떤 일을 설정할 필요가 없습니다. HBase를-site.xml 파일에 아무것도 오버라이드 (override) 한 경우, 더 나은 대신 별도로 매개 변수를 설정하는 것을 HBase를-site.xml 파일을 추가합니다.

    Configuration config = HBaseConfiguration.create();
    config.addResource("<HBASE_CONF_DIR_PATH>/hbase-site.xml");
    
  2. from https://stackoverflow.com/questions/22680433/fail-to-connect-to-hbase-with-java-api by cc-by-sa and MIT license