2013-04-02 20 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); 
      } 
     } 
    } 
相关问题