예제 #1
0
파일: Test.java 프로젝트: imace/tutorials
  public static void main(String[] args) throws IOException {
    Configuration conf = HBaseConfiguration.create();
    HTableInterface literaturesTable = new HTable(conf, "pb_literatures");

    Scan s = new Scan();
    s.addFamily(Bytes.toBytes("info"));
    ResultScanner rs = literaturesTable.getScanner(s);
    for (Result r : rs) {
      byte[] b = r.getValue(Bytes.toBytes("info"), Bytes.toBytes("title"));
      System.out.println(Bytes.toString(b));
    }
  }
예제 #2
0
 /** Return the number of rows in the given table. */
 public static int countMobRows(final Table table, final byte[]... families) throws IOException {
   Scan scan = new Scan();
   for (byte[] family : families) {
     scan.addFamily(family);
   }
   ResultScanner results = table.getScanner(scan);
   int count = 0;
   for (Result res : results) {
     count++;
     List<Cell> cells = res.listCells();
     for (Cell cell : cells) {
       // Verify the value
       Assert.assertTrue(CellUtil.cloneValue(cell).length > 0);
     }
   }
   results.close();
   return count;
 }
예제 #3
0
 public void scan(
     Consumer<Result> callback, String tableName, String columnFamily, String... qualifiers) {
   if (callback != null && tableName != null && columnFamily != null && qualifiers != null) {
     Scan s = new Scan();
     byte[] family = Bytes.toBytes(columnFamily);
     for (String qualifier : qualifiers) {
       s.addColumn(family, Bytes.toBytes(qualifier));
     }
     try {
       final Table table = connection.getTable(TableName.valueOf(tableName));
       ResultScanner scanner = table.getScanner(s);
       for (Result r = scanner.next(); r != null; r = scanner.next()) {
         callback.accept(r);
       }
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
 }