Package org.apache.hadoop.hbase.client

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


  }

  private void scanTable(boolean printResults)
  throws IOException {
    HTable table = new HTable(conf, TABLE_NAME);
    Scanner scanner = table.getScanner(columns,
        HConstants.EMPTY_START_ROW);
    try {
      for (RowResult r : scanner) {
        if (printResults) {
          LOG.info("row: " + r.getRow());
        }
        for (Map.Entry<byte [], Cell> e : r.entrySet()) {
          if (printResults) {
            LOG.info(" column: " + e.getKey() + " value: "
                + new String(e.getValue().getValue(), HConstants.UTF8_ENCODING));
          }
        }
      }
    } finally {
      scanner.close();
    }
  }
View Full Code Here


      Integer.toString(new Random().nextInt()));
    this.fs.copyToLocalFile(new Path(INDEX_DIR), localDir);
    FileSystem localfs = FileSystem.getLocal(conf);
    FileStatus [] indexDirs = localfs.listStatus(localDir);
    Searcher searcher = null;
    Scanner scanner = null;
    try {
      if (indexDirs.length == 1) {
        searcher = new IndexSearcher((new File(indexDirs[0].getPath().
          toUri())).getAbsolutePath());
      } else if (indexDirs.length > 1) {
        Searchable[] searchers = new Searchable[indexDirs.length];
        for (int i = 0; i < indexDirs.length; i++) {
          searchers[i] = new IndexSearcher((new File(indexDirs[i].getPath().
            toUri()).getAbsolutePath()));
        }
        searcher = new MultiSearcher(searchers);
      } else {
        throw new IOException("no index directory found");
      }

      HTable table = new HTable(conf, TABLE_NAME);
      scanner = table.getScanner(columns, HConstants.EMPTY_START_ROW);

      IndexConfiguration indexConf = new IndexConfiguration();
      String content = conf.get("hbase.index.conf");
      if (content != null) {
        indexConf.addFromXML(content);
      }
      String rowkeyName = indexConf.getRowkeyName();

      int count = 0;
      for (RowResult r : scanner) {
        String value = Bytes.toString(r.getRow());
        Term term = new Term(rowkeyName, value);
        int hitCount = searcher.search(new TermQuery(term)).length();
        assertEquals("check row " + value, 1, hitCount);
        count++;
      }
      LOG.debug("Searcher.maxDoc: " + searcher.maxDoc());
      LOG.debug("IndexReader.numDocs: " + ((IndexSearcher)searcher).getIndexReader().numDocs());     
      int maxDoc = ((IndexSearcher)searcher).getIndexReader().numDocs();
      assertEquals("check number of rows", maxDoc, count);
    } finally {
      if (null != searcher)
        searcher.close();
      if (null != scanner)
        scanner.close();
    }
  }
View Full Code Here

   * @param table Table to scan.
   * @throws IOException
   * @throws NullPointerException if we failed to find a cell value
   */
  private void verifyAttempt(final HTable table) throws IOException, NullPointerException {
    Scanner scanner =
      table.getScanner(columns, HConstants.EMPTY_START_ROW);
    try {
      for (RowResult r : scanner) {
        if (LOG.isDebugEnabled()) {
          if (r.size() > 2 ) {
            throw new IOException("Too many results, expected 2 got " +
              r.size());
          }
        }
        byte[] firstValue = null;
        byte[] secondValue = null;
        int count = 0;
        for(Map.Entry<byte [], Cell> e: r.entrySet()) {
          if (count == 0) {
            firstValue = e.getValue().getValue();
          }
          if (count == 1) {
            secondValue = e.getValue().getValue();
          }
          count++;
          if (count == 2) {
            break;
          }
        }
       
        String first = "";
        if (firstValue == null) {
          throw new NullPointerException(Bytes.toString(r.getRow()) +
            ": first value is null");
        }
        first = new String(firstValue, HConstants.UTF8_ENCODING);
       
        String second = "";
        if (secondValue == null) {
          throw new NullPointerException(Bytes.toString(r.getRow()) +
            ": second value is null");
        }
        byte[] secondReversed = new byte[secondValue.length];
        for (int i = 0, j = secondValue.length - 1; j >= 0; j--, i++) {
          secondReversed[i] = secondValue[j];
        }
        second = new String(secondReversed, HConstants.UTF8_ENCODING);

        if (first.compareTo(second) != 0) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("second key is not the reverse of first. row=" +
                r.getRow() + ", first value=" + first + ", second value=" +
                second);
          }
          fail();
        }
      }
    } finally {
      scanner.close();
    }
  }
View Full Code Here

      // Delete again so we go get it all fresh.
      HConnectionManager.deleteConnectionInfo(conf, false);
      HTable t = new HTable(this.conf, TABLENAME);
      int count = 0;
      LOG.info("OPENING SCANNER");
      Scanner s = t.getScanner(TABLENAME_COLUMNS);
      try {
        for (RowResult r: s) {
          if (r == null || r.size() == 0) {
            break;
          }
          count++;
          if (count % 1000 == 0 && count > 0) {
            LOG.info("Iterated over " + count + " rows.");
          }
        }
        assertEquals(EXPECTED_COUNT, count);
      } finally {
        s.close();
      }
    } finally {
      HConnectionManager.deleteConnectionInfo(conf, false);
      cluster.shutdown();
    }
View Full Code Here

    writeInitalRows();
    assertRowsInOrder(NUM_ROWS);
  }
 
  private void assertRowsInOrder(int numRowsExpected) throws IndexNotFoundException, IOException {
    Scanner scanner = table.getIndexedScanner(INDEX_COL_A,
        HConstants.EMPTY_START_ROW, null, null, null);
    int numRows = 0;
    byte[] lastColA = null;
    for (RowResult rowResult : scanner) {
      byte[] colA = rowResult.get(COL_A).getValue();
View Full Code Here

    byte [] endRow = request.getParameter(END_ROW) == null?
      HConstants.EMPTY_START_ROW:
      Bytes.toBytes(URLDecoder.decode(request.getParameter(END_ROW),
        HConstants.UTF8_ENCODING));

    Scanner scanner = (request.getParameter(END_ROW) == null)?
       table.getScanner(columns, startRow):
       table.getScanner(columns, startRow, endRow);
   
    // Make a scanner id by hashing the object toString value (object name +
    // an id).  Will make identifier less burdensome and more url friendly.
    String scannerid =
      Integer.toHexString(JenkinsHash.getInstance().hash(scanner.toString().getBytes(), -1));
    ScannerRecord sr = new ScannerRecord(scanner);
   
    // store the scanner for subsequent requests
    this.scanners.put(scannerid, sr);
   
View Full Code Here

      }
    }

    public void scannerClose(int id) throws IOError, IllegalArgument {
      LOG.debug("scannerClose: id=" + id);
      Scanner scanner = getScanner(id);
      if (scanner == null) {
        throw new IllegalArgument("scanner ID is invalid");
      }
      scanner.close();
      removeScanner(id);
    }
View Full Code Here

    }
   
    public TRowResult scannerGet(int id) throws IllegalArgument, NotFound,
        IOError {
      LOG.debug("scannerGet: id=" + id);
      Scanner scanner = getScanner(id);
      if (scanner == null) {
        throw new IllegalArgument("scanner ID is invalid");
      }
     
      RowResult results = null;
     
      try {
        results = scanner.next();
        if (results == null) {
          throw new NotFound("end of scanner reached");
        }
      } catch (IOException e) {
        throw new IOError(e.getMessage());
View Full Code Here

   
    public int scannerOpen(byte[] tableName, byte[] startRow,
        List<byte[]> columns) throws IOError {
      try {
        HTable table = getTable(tableName);
        Scanner scanner = table.getScanner(columns.toArray(new byte[0][]),
            startRow);
        return addScanner(scanner);
      } catch (IOException e) {
        throw new IOError(e.getMessage());
      }
View Full Code Here

   
    public int scannerOpenWithStop(byte[] tableName, byte[] startRow,
        byte[] stopRow, List<byte[]> columns) throws IOError, TException {
      try {
        HTable table = getTable(tableName);
        Scanner scanner = table.getScanner(columns.toArray(new byte[0][]),
            startRow, stopRow);
        return addScanner(scanner);
      } catch (IOException e) {
        throw new IOError(e.getMessage());
      }
View Full Code Here

TOP

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

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.