2016-06-17 3 views
0

나는 며칠 전 Hbase를 시작했고 온라인의 모든 자료를 검토했다.HBase Java 클라이언트 이해

HBase를 설치하고 구성했으며 쉘 명령이 정상적으로 작동합니다.

HBase 테이블에서 데이터를 가져 오기 위해 Java 클라이언트의 예제가 있는데 성공적으로 실행되었지만 어떻게 작동하는지 이해할 수 없었습니다. 코드에서 우리는 Hbase 서버의 호스트, 포트를 언급하지 않았습니다. 어떻게 테이블에서 데이터를 가져올 수 있습니까? 당신이 githubHBaseConfiguration의 소스 코드를 보면

Output:
name: raju city: hyderabad

답변

1

나는 진 멍청이 들아 더 나은 이해를 위해 좀 더 흥미로운 정보를 추가

답변에 동의합니다.

귀하의 질문 :이 작동하는 방법을

나는 이해할 수 없었다? 코드에서 아무데도 포트, Hbase 서버의 호스트 언급? 테이블에서 데이터를 가져 오는 방법은 무엇입니까?

당신이 클러스터에 있기 때문에 당신이 .. 클러스터 모든 클러스터 속성이 클러스터 내부에서 처리 될 것입니다

// Instantiating Configuration class 
    Configuration config = HBaseConfiguration.create() 

에서이 프로그램을 실행하고 있고 HBase와 자바 클라이언트 프로그램을 실행하고 있기 때문에.

이제 (Windows에서 원격 시스템 이클립스와 다른 방법으로 동일한 프로그램을 실행하여 이전과 현재의 차이점을 알아보십시오.) 다음과 같이 시도하십시오.

public static Configuration configuration; // this is class variable 
     static { //fill clusternode1,clusternode2,clusternode3 from your cluster 
      configuration = HBaseConfiguration.create(); 
      configuration.set("hbase.zookeeper.property.clientPort", "2181"); 
      configuration.set("hbase.zookeeper.quorum", 
      "clusternode1,clusternode2,clusternode3"); 
      configuration.set("hbase.master", "clusternode1:600000"); 
     } 

호프가 이해하기를 바랍니다.

1

은 당신이 무엇을 볼 수 있습니다

public class RetriveData { 

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

     // Instantiating Configuration class 
     Configuration config = HBaseConfiguration.create(); 

     // Instantiating HTable class 
     @SuppressWarnings({ "deprecation", "resource" }) 
     HTable table = new HTable(config, "emp"); 

     // Instantiating Get class 
     Get g = new Get(Bytes.toBytes("1")); 

     // Reading the data 
     Result result = table.get(g); 

     // Reading values from Result class object 
     byte [] value = result.getValue(Bytes.toBytes("personal data"),Bytes.toBytes("name")); 

     byte [] value1 = result.getValue(Bytes.toBytes("personal data"),Bytes.toBytes("city")); 

     // Printing the values 
     String name = Bytes.toString(value); 
     String city = Bytes.toString(value1); 

     System.out.println("name: " + name + " city: " + city);   
    } 

} 

출력은 다음과 같습니다

내 코드입니다 create()로 전화하면됩니다. 당신의 HBase를 구성 파일 hbase-default.xmlhbase-site.xml에서

public static Configuration addHbaseResources(Configuration conf) { 
    conf.addResource("hbase-default.xml"); 
    conf.addResource("hbase-site.xml"); 

    checkDefaultsVersion(conf); 
    HeapMemorySizeUtil.checkForClusterFreeMemoryLimit(conf); 
    return conf; 
    } 

그래서 그것의 로딩 구성 :

public static Configuration create() { 
    Configuration conf = new Configuration(); 
    // In case HBaseConfiguration is loaded from a different classloader than 
    // Configuration, conf needs to be set with appropriate class loader to resolve 
    // HBase resources. 
    conf.setClassLoader(HBaseConfiguration.class.getClassLoader()); 
    return addHbaseResources(conf); 
    } 

가 하였다.

+0

감사합니다. 기본 구현을 이해하는 데 실제로 도움이됩니다. Java 클라이언트를 원격 호스트에서 실행하려면 ** RamaPrada G **에서 제안한대로 구성을 무시해야합니다. –

+0

예,'conf.set()'를 사용하여 직접 설정을하거나 XML 파일을 복사하여로드 할 수 있습니다. 어느 쪽이든 그것은 같은 효과를 가져야합니다. –