2013-04-02 47 views
1

我有hbase 0.94.0。我試圖檢索所有區域的StartKey和EndKey。獲取區域開始鍵和結束鍵-HBase

我用下面的代碼來獲取hbase中的區域。

MetaScanner ms=new MetaScanner(); 
System.out.println("Region of .META. "+ms.listAllRegions(config)); 

它產生了以下輸出。

Region of .META. [{NAME => 'Student9,,1364452609604.9955bddb298229d6b9fa749dfa7d6b40.', STARTKEY => '', ENDKEY => '0011000', ENCODED => 9955bddb298229d6b9fa749dfa7d6b40,}, {NAME => 'Student9,0011000,1364452609604.f1766f38ceabbe6400c266f99d1a9a29.', STARTKEY => '0011000', ENDKEY => '0011\x85\x85\x85', ENCODED => f1766f38ceabbe6400c266f99d1a9a29,}, 

現在我想檢索每個區域startkey和endkey在.META.表。

我該怎麼做? 幫助一個示例代碼!

回答

0
Pair<byte[][],byte[][]> pair=table1.getStartEndKeys(); 
      byte[][] start=pair.getFirst(); 
      byte[][] end=pair.getSecond(); 
      for(int c=0;c<start.length;c++) 
      { 
        String st_end=new String(start[c]); 
        String en2=new String(end[c]);  
        System.out.println("StartKey :"+st_end+" "+"End Key :"+en2); 
      } 
0

在Java中,

try (HTable table = new HTable(new JobConf(HBaseConfiguration.create()), TABLE_NAME)) { 
     byte[][] keys = table.getStartKeys(); 
     for (byte[] keyBytes : keys) { 
      String key = new String(keyBytes, StandardCharsets.UTF_8); 
      // first region does not have start key (is null) 
      // last region does not have end key 
      if (StringUtils.isNotBlank(key)) { 
       System.out.println(key); 
      } 
     } 
    } 
相關問題