Пример #1
0
  public Map<String, Object> parse(Result result) {
    Map<String, Object> parsed = new HashMap<String, Object>();

    byte[] qualifierBytes = new byte[0];
    for (Entry<byte[], NavigableMap<byte[], byte[]>> e : result.getNoVersionMap().entrySet()) {
      String name = Serialization.deserializeString(e.getKey());
      parsed.put(name, this.streamers.get(name).read(e.getValue().get(qualifierBytes)));
    }

    return parsed;
  }
Пример #2
0
 private void printResult(Result result) {
   if (result != null) {
     Map<String, String> map = new HashMap<String, String>();
     for (KeyValue kv : result.list()) { // 需要判断
       map.put(Bytes.toString(kv.getQualifier()), Bytes.toString(kv.getValue()));
     }
     logger.info(map.toString());
     NavigableMap<byte[], NavigableMap<byte[], byte[]>> map2 = result.getNoVersionMap();
     for (byte[] key : map2.keySet()) {
       Map<String, String> mm = new HashMap<String, String>();
       mm.put("family", Bytes.toString(key));
       NavigableMap<byte[], byte[]> navigableMap = map2.get(key);
       for (byte[] key2 : navigableMap.keySet()) {
         mm.put(Bytes.toString(key2), Bytes.toString(navigableMap.get(key2)));
       }
       logger.info(mm.toString());
     }
   }
 }
Пример #3
0
 private static void deleteTable(byte[] tableName) {
   HTablePool pool = new HTablePool();
   HTableInterface table = null;
   try {
     table = pool.getTable(tableName);
     Scan scan = new Scan();
     ResultScanner scanner = table.getScanner(scan);
     for (Result r : scanner) {
       Delete delete = new Delete(r.getRow());
       NavigableMap<byte[], NavigableMap<byte[], byte[]>> map = r.getNoVersionMap();
       for (Map.Entry<byte[], NavigableMap<byte[], byte[]>> family : map.entrySet()) {
         delete.deleteFamily(family.getKey());
       }
       table.delete(delete);
     }
     Delete delete = new Delete(new byte[0]);
     table.delete(delete);
   } catch (Exception e) {
     // ignore
   } finally {
     if (table != null) pool.putTable(table);
   }
 }