Package org.apache.hadoop.hbase

Examples of org.apache.hadoop.hbase.HScannerInterface


    if (this.rootRegion == null) {
      openRootRegion();
    }

    HScannerInterface rootScanner = rootRegion.getScanner(
        HConstants.COL_REGIONINFO_ARRAY, HConstants.EMPTY_START_ROW,
        HConstants.LATEST_TIMESTAMP, null);

    try {
      HStoreKey key = new HStoreKey();
      SortedMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
      while (rootScanner.next(key, results)) {
        HRegionInfo info = Writables.getHRegionInfoOrNull(
            results.get(HConstants.COL_REGIONINFO));
        if (info == null) {
          LOG.warn("region info is null for row " + key.getRow() +
              " in table " + HConstants.ROOT_TABLE_NAME);
          continue;
        }
        if (!listener.processRow(info)) {
          break;
        }
        results.clear();
      }

    } finally {
      rootScanner.close();
    }
  }
View Full Code Here


   
    // Open meta region so we can scan it

    HRegion metaRegion = openMetaRegion(metaRegionInfo);

    HScannerInterface metaScanner = metaRegion.getScanner(
        HConstants.COL_REGIONINFO_ARRAY, HConstants.EMPTY_START_ROW,
        HConstants.LATEST_TIMESTAMP, null);

    try {
      HStoreKey key = new HStoreKey();
      SortedMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
      while (metaScanner.next(key, results)) {
        HRegionInfo info = Writables.getHRegionInfoOrNull(
            results.get(HConstants.COL_REGIONINFO));
        if (info == null) {
          LOG.warn("region info is null for row " + key.getRow() +
              " in table " + HConstants.META_TABLE_NAME);
          continue;
        }
        if (!listener.processRow(info)) {
          break;
        }
        results.clear();
      }

    } finally {
      metaScanner.close();
    }
  }
View Full Code Here

    }
  }

  private int scanPrint(HTable table, HBaseAdmin admin) {
    int count = 0;
    HScannerInterface scan = null;
    try {
      ParsedColumns parsedColumns = getColumns(admin, true);
      Text[] cols = parsedColumns.getColumns().toArray(new Text[] {});
      if (timestamp == 0) {
        scan = table.obtainScanner(cols, rowKey);
      } else {
        scan = table.obtainScanner(cols, rowKey, timestamp);
      }

      if (this.stopRow.toString().length() > 0) {
        RowFilterInterface filter = new WhileMatchRowFilter(new StopRowFilter(
            stopRow));
        scan = table.obtainScanner(cols, rowKey, filter);
      }

      HStoreKey key = new HStoreKey();
      TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
      // If only one column in query, then don't print out the column.
      while (scan.next(key, results) && checkLimit(count)) {
        if (count == 0 && !countFunction) {
          formatter.header((parsedColumns.isMultiple()) ? HEADER : HEADER_ROW_CELL);
        }

        Text r = key.getRow();

        if (!countFunction) {
          for (Text columnKey : results.keySet()) {
            String cellData = toString(columnKey, results.get(columnKey));
            if (parsedColumns.isMultiple()) {
              formatter.row(new String[] { r.toString(), columnKey.toString(),
                  cellData });
            } else {
              // Don't print out the column since only one specified in query.
              formatter.row(new String[] { r.toString(), cellData });
            }
            if (limit > 0 && count >= limit) {
              break;
            }
          }
        }

        count++;
        // Clear results else subsequent results polluted w/ previous finds.
        results.clear();
      }

      if (count == 0 && Shell.HTML_OPTION != null && !countFunction) {
        formatter.header((parsedColumns.isMultiple()) ? HEADER : HEADER_ROW_CELL);
      }

      formatter.footer();
      scan.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return count;
  }
View Full Code Here

      Integer.toString(new Random().nextInt()));
    this.fs.copyToLocalFile(new Path(INDEX_DIR), localDir);
    FileSystem localfs = FileSystem.getLocal(conf);
    Path [] indexDirs = localfs.listPaths(new Path [] {localDir});
    Searcher searcher = null;
    HScannerInterface scanner = null;
    try {
      if (indexDirs.length == 1) {
        searcher = new IndexSearcher((new File(indexDirs[0].
          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].
            toUri()).getAbsolutePath()));
        }
        searcher = new MultiSearcher(searchers);
      } else {
        throw new IOException("no index directory found");
      }

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

      HStoreKey key = new HStoreKey();
      TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();

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

      int count = 0;
      while (scanner.next(key, results)) {
        String value = key.getRow().toString();
        LOG.debug("Scanned over " + key.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

  private void scanTable(String tableName, boolean printValues)
  throws IOException {
    HTable table = new HTable(conf, new Text(tableName));
   
    HScannerInterface scanner =
      table.obtainScanner(columns, HConstants.EMPTY_START_ROW);
   
    try {
      HStoreKey key = new HStoreKey();
      TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
     
      while(scanner.next(key, results)) {
        if (printValues) {
          LOG.info("row: " + key.getRow());

          for(Map.Entry<Text, byte[]> e: results.entrySet()) {
            LOG.info(" column: " + e.getKey() + " value: "
                + new String(e.getValue(), HConstants.UTF8_ENCODING));
          }
        }
      }
     
    } finally {
      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 {
    HScannerInterface scanner =
      table.obtainScanner(columns, HConstants.EMPTY_START_ROW);
    try {
      HStoreKey key = new HStoreKey();
      TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
     
      while(scanner.next(key, results)) {
        if (LOG.isDebugEnabled()) {
          if (results.size() > 2 ) {
            throw new IOException("Too many results, expected 2 got " +
              results.size());
          }
        }
        byte[] firstValue = null;
        byte[] secondValue = null;
        int count = 0;
        for(Map.Entry<Text, byte[]> e: results.entrySet()) {
          if (count == 0) {
            firstValue = e.getValue();
          }
          if (count == 1) {
            secondValue = e.getValue();
          }
          count++;
          if (count == 2) {
            break;
          }
        }
       
        String first = "";
        if (firstValue == null) {
          throw new NullPointerException(key.getRow().toString() +
            ": first value is null");
        }
        first = new String(firstValue, HConstants.UTF8_ENCODING);
       
        String second = "";
        if (secondValue == null) {
          throw new NullPointerException(key.getRow().toString() +
            ": 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=" +
                key.getRow() + ", first value=" + first + ", second value=" +
                second);
          }
          fail();
        }
      }
    } finally {
      scanner.close();
    }
  }
View Full Code Here

  }

  private void scanTable(boolean printResults)
  throws IOException {
    HTable table = new HTable(conf, new Text(TABLE_NAME));
    HScannerInterface scanner = table.obtainScanner(columns,
        HConstants.EMPTY_START_ROW);
    try {
      HStoreKey key = new HStoreKey();
      TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
      while (scanner.next(key, results)) {
        if (printResults) {
          LOG.info("row: " + key.getRow());
        }
        for (Map.Entry<Text, byte[]> e : results.entrySet()) {
          if (printResults) {
            LOG.info(" column: " + e.getKey() + " value: "
                + new String(e.getValue(), HConstants.UTF8_ENCODING));
          }
        }
      }
    } finally {
      scanner.close();
    }
  }
View Full Code Here

    if (this.rootRegion == null) {
      openRootRegion();
    }

    HScannerInterface rootScanner = rootRegion.getScanner(
        HConstants.COL_REGIONINFO_ARRAY, HConstants.EMPTY_START_ROW,
        HConstants.LATEST_TIMESTAMP, null);

    try {
      HStoreKey key = new HStoreKey();
      SortedMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
      while (rootScanner.next(key, results)) {
        HRegionInfo info = Writables.getHRegionInfoOrNull(
            results.get(HConstants.COL_REGIONINFO));
        if (info == null) {
          LOG.warn("region info is null for row " + key.getRow() +
              " in table " + HConstants.ROOT_TABLE_NAME);
          continue;
        }
        if (!listener.processRow(info)) {
          break;
        }
        results.clear();
      }

    } finally {
      rootScanner.close();
    }
  }
View Full Code Here

   
    // Open meta region so we can scan it

    HRegion metaRegion = openMetaRegion(metaRegionInfo);

    HScannerInterface metaScanner = metaRegion.getScanner(
        HConstants.COL_REGIONINFO_ARRAY, HConstants.EMPTY_START_ROW,
        HConstants.LATEST_TIMESTAMP, null);

    try {
      HStoreKey key = new HStoreKey();
      SortedMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
      while (metaScanner.next(key, results)) {
        HRegionInfo info = Writables.getHRegionInfoOrNull(
            results.get(HConstants.COL_REGIONINFO));
        if (info == null) {
          LOG.warn("region info is null for row " + key.getRow() +
              " in table " + HConstants.META_TABLE_NAME);
          continue;
        }
        if (!listener.processRow(info)) {
          break;
        }
        results.clear();
      }

    } finally {
      metaScanner.close();
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.HScannerInterface

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.