Package org.apache.hadoop.hbase.client

Examples of org.apache.hadoop.hbase.client.ResultScanner


  /**
   * Return the number of rows in the given table.
   */
  public int countRows(final HTable table) throws IOException {
    Scan scan = new Scan();
    ResultScanner results = table.getScanner(scan);
    int count = 0;
    for (@SuppressWarnings("unused") Result res : results) {
      count++;
    }
    results.close();
    return count;
  }
View Full Code Here


  public int countRows(final HTable 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 (@SuppressWarnings("unused") Result res : results) {
      count++;
    }
    results.close();
    return count;
  }
View Full Code Here

  /**
   * Return an md5 digest of the entire contents of a table.
   */
  public String checksumRows(final HTable table) throws Exception {
    Scan scan = new Scan();
    ResultScanner results = table.getScanner(scan);
    MessageDigest digest = MessageDigest.getInstance("MD5");
    for (Result res : results) {
      digest.update(res.getRow());
    }
    results.close();
    return digest.toString();
  }
View Full Code Here

   */
  public List<byte[]> getMetaTableRows() throws IOException {
    // TODO: Redo using MetaReader class
    HTable t = new HTable(new Configuration(this.conf), HConstants.META_TABLE_NAME);
    List<byte[]> rows = new ArrayList<byte[]>();
    ResultScanner s = t.getScanner(new Scan());
    for (Result result : s) {
      LOG.info("getMetaTableRows: row -> " +
        Bytes.toStringBinary(result.getRow()));
      rows.add(result.getRow());
    }
    s.close();
    t.close();
    return rows;
  }
View Full Code Here

   */
  public List<byte[]> getMetaTableRows(byte[] tableName) throws IOException {
    // TODO: Redo using MetaReader.
    HTable t = new HTable(new Configuration(this.conf), HConstants.META_TABLE_NAME);
    List<byte[]> rows = new ArrayList<byte[]>();
    ResultScanner s = t.getScanner(new Scan());
    for (Result result : s) {
      byte[] val = result.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
      if (val == null) {
        LOG.error("No region info for row " + Bytes.toString(result.getRow()));
        // TODO figure out what to do for this new hosed case.
        continue;
      }
      HRegionInfo info = Writables.getHRegionInfo(val);
      if (Bytes.compareTo(info.getTableName(), tableName) == 0) {
        LOG.info("getMetaTableRows: row -> " +
            Bytes.toStringBinary(result.getRow()) + info);
        rows.add(result.getRow());
      }
    }
    s.close();
    t.close();
    return rows;
  }
View Full Code Here

    try {
      while (true) {
        boolean allRegionsAssigned = true;
        Scan scan = new Scan();
        scan.addFamily(HConstants.CATALOG_FAMILY);
        ResultScanner s = meta.getScanner(scan);
        try {
          Result r;
          while ((r = s.next()) != null) {
            byte [] b = r.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
            HRegionInfo info = Writables.getHRegionInfoOrNull(b);
            if (info != null && Bytes.equals(info.getTableName(), tableName)) {
              b = r.getValue(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER);
              allRegionsAssigned &= (b != null);
            }
          }
        } finally {
          s.close();
        }
        if (allRegionsAssigned) {
          return;
        }
        long now = System.currentTimeMillis();
View Full Code Here

    public void doAnAction() throws Exception {
      Scan s = new Scan();
      for (byte[] family : targetFamilies) {
        s.addFamily(family);
      }
      ResultScanner scanner = table.getScanner(s);

      for (Result res : scanner) {
        byte[] gotValue = null;

        for (byte[] family : targetFamilies) {
View Full Code Here

                     String.format("(%s%s%s)|(%s%s)$",
                     ACL_KEY_DELIMITER, columnName, ACL_KEY_DELIMITER,
                     ACL_KEY_DELIMITER, columnName))));

      Set<byte[]> qualifierSet = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
      ResultScanner scanner = acls.getScanner(scan);
      try {
        for (Result res : scanner) {
          for (byte[] q : res.getFamilyMap(ACL_LIST_FAMILY).navigableKeySet()) {
            qualifierSet.add(q);
          }
        }
      } finally {
        scanner.close();
      }

      if (qualifierSet.size() > 0) {
        Delete d = new Delete(tableName);
        for (byte[] qualifier : qualifierSet) {
View Full Code Here

    Scan scan = new Scan();
    scan.addFamily(ACL_LIST_FAMILY);

    HTable acls = null;
    ResultScanner scanner = null;
    try {
      acls = new HTable(conf, ACL_TABLE_NAME);
      scanner = acls.getScanner(scan);
      for (Result row : scanner) {
        ListMultimap<String,TablePermission> resultPerms =
            parseTablePermissions(row.getRow(), row);
        allPerms.put(row.getRow(), resultPerms);
      }
    } finally {
      if (scanner != null) scanner.close();
      if (acls != null) acls.close();
    }

    return allPerms;
  }
View Full Code Here

      public Object run() throws Exception {
        Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
        // force a new RS connection
        conf.set("testkey", UUID.randomUUID().toString());
        HTable t = new HTable(conf, TABLE);
        ResultScanner rs = t.getScanner(new Scan());
        int rowcnt = 0;
        for (Result r : rs) {
          rowcnt++;
          int rownum = Bytes.toInt(r.getRow());
          assertTrue(r.containsColumn(FAMILY, PRIVATE_COL));
          assertEquals("secret "+rownum, Bytes.toString(r.getValue(FAMILY, PRIVATE_COL)));
          assertTrue(r.containsColumn(FAMILY, PUBLIC_COL));
          assertEquals("info "+rownum, Bytes.toString(r.getValue(FAMILY, PUBLIC_COL)));
        }
        assertEquals("Expected 100 rows returned", 100, rowcnt);
        return null;
      }
    });

    // test read with qualifier filter
    LIMITED.runAs(new PrivilegedExceptionAction<Object>() {
      public Object run() throws Exception {
        Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
        // force a new RS connection
        conf.set("testkey", UUID.randomUUID().toString());
        HTable t = new HTable(conf, TABLE);
        ResultScanner rs = t.getScanner(new Scan());
        int rowcnt = 0;
        for (Result r : rs) {
          rowcnt++;
          int rownum = Bytes.toInt(r.getRow());
          assertFalse(r.containsColumn(FAMILY, PRIVATE_COL));
          assertTrue(r.containsColumn(FAMILY, PUBLIC_COL));
          assertEquals("info " + rownum, Bytes.toString(r.getValue(FAMILY, PUBLIC_COL)));
        }
        assertEquals("Expected 100 rows returned", 100, rowcnt);
        return null;
      }
    });

    // test as user with no permission
    DENIED.runAs(new PrivilegedExceptionAction(){
      public Object run() throws Exception {
        try {
          Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
          // force a new RS connection
          conf.set("testkey", UUID.randomUUID().toString());
          HTable t = new HTable(conf, TABLE);
          ResultScanner rs = t.getScanner(new Scan());
          fail("Attempt to open scanner should have been denied");
        } catch (AccessDeniedException ade) {
          // expected
        }
        return null;
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.client.ResultScanner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.