2012-11-09 5 views
4

hbase java API를 통해 행 ID 목록을 기준으로 hbase 데이터 레코드를 가져올 수 있습니까?hbase api - 행 ID 목록으로 데이터 행 정보 가져 오기

예를 들어, 나는 HBase를 행 ID의 알려진 목록을 가지고 :

mykey1 : myhash1, mykey1 : myhash2, mykey1 : myhash3, mykey2 : myhash5, ...

및 I 모든 관련 열 셀 정보를 hbase하는 단일 호출을 원합니다. 나는 hbase에 익숙하지 않고 API로 지원되는지도 모르겠다.

API의 의사 코드 : 그런

GetById(String tableName, List<byte[]> rowIds); 

뭔가?

Get(byte[] rowName)으로 단일 행에서 정보를 검색 할 수 있지만 rowIds 목록이있을 때마다 여러 번 get 액션을 실행해야 연결이 설정되고 매번 완료 될 때 종료됩니다. 당신이 일괄 적으로 실행할 수 있습니다

감사

답변

12

배치 호출에 Get 작업 목록을 전달합니다

... 
import org.apache.hadoop.conf.Configuration; 
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.Result; 
import org.apache.hadoop.hbase.util.Bytes; 
... 
     HTable htable = null; 
     try { 
      htable = new HTable(conf, "mytable"); 
      List<Get> queryRowList = new ArrayList<Get>(); 
      queryRowList.add(new Get(Bytes.toBytes("mykey1:myhash1"))); 
      queryRowList.add(new Get(Bytes.toBytes("mykey1:myhash2"))); 
      queryRowList.add(new Get(Bytes.toBytes("mykey1:myhash3"))); 
      queryRowList.add(new Get(Bytes.toBytes("mykey2:myhash5"))); 

      Result[] results = htable.get(queryRowList); 
      for (Result r : results) { 
       //do something 
      } 
     } 
     finally { 
      if (htable != null) { 
       htable.close(); 
      } 
     } 
... 
+0

덕분에, 매력 : – jMn

+2

처럼 일이 단 한 번의 키를 누른 다음 결과 [] 것이다 테이블에없는 경우 비어있어 라. 더 나은 행동을 보이는 API가 있습니까? – Gevorg

0

여러 GET에 대한 컨테이너로 MultiAction를 사용 (또는 넣고, 삭제 및 그들의 조합) 할 수 있습니다.

즉, 매번 연결을 닫거나 다시 열지 않고도 여러 번의 get 작업을 수행 할 수 있습니다.