Ejemplo n.º 1
0
 public void initData() {
   IndexHTable hTable = null;
   try {
     hTable = new IndexHTable(conf, tableName);
     hTable.setAutoFlushTo(false);
     List<Put> puts = new ArrayList<Put>();
     byte[] familyBytes = columnFamily.getBytes();
     byte[] qualifier = columnName.getBytes();
     for (int i = 0; i < 100; i++) {
       Put put = new Put(Bytes.toBytes("row" + i));
       put.add(familyBytes, qualifier, ("value" + i).getBytes());
       puts.add(put);
     }
     hTable.put(puts);
     hTable.flushCommits();
   } catch (Exception e) {
     LOG.error(e.getMessage(), e);
   } finally {
     try {
       hTable.close();
     } catch (IOException e) {
       LOG.error("htable close error");
     }
   }
 }
Ejemplo n.º 2
0
  public void scan() {
    IndexHTable hTable = null;
    try {
      hTable = new IndexHTable(conf, tableName);
      Scan scan = new Scan();
      scan.setFilter(
          getInFilter(
              columnFamily.getBytes(),
              columnName.getBytes(),
              "value3".getBytes(),
              "value9".getBytes()));
      scan.setIndexColumn(Bytes.toBytes(indexName));
      ResultScanner rs = hTable.getScanner(scan);
      Result result = null;
      while (null != (result = rs.next())) {
        System.out.println("================" + Bytes.toString(result.getRow()));
      }

    } catch (Exception e) {
    }
  }