Examples of HScannerInterface


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

Examples of org.apache.hadoop.hbase.HScannerInterface

   
    // 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

Examples of org.apache.hadoop.hbase.HScannerInterface

  }

  private void scanTable(final String tableName, final boolean printValues) throws IOException {
    HTable table = new HTable(conf, new Text(tableName));

    HScannerInterface scanner = table.obtainScanner(columns, HConstants.EMPTY_START_ROW);
    int numFound = doScan(scanner, printValues);
    Assert.assertEquals(NUM_ROWS, numFound);
  }
View Full Code Here

Examples of org.apache.hadoop.hbase.HScannerInterface

  private void scanTableWithRowFilter(final String tableName, final boolean printValues) throws IOException {
    HTable table = new HTable(conf, new Text(tableName));
    Map<Text, byte[]> columnMap = new HashMap<Text, byte[]>();
    columnMap.put(TEXT_COLUMN1, VALUE);
    RegExpRowFilter filter = new RegExpRowFilter(null, columnMap);
    HScannerInterface scanner = table.obtainScanner(columns, HConstants.EMPTY_START_ROW, filter);
    int numFound = doScan(scanner, printValues);
    Assert.assertEquals(NUM_ROWS, numFound);
  }
View Full Code Here

Examples of org.apache.hadoop.hbase.HScannerInterface

  }

  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

Examples of org.apache.hadoop.hbase.HScannerInterface

      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

Examples of org.apache.hadoop.hbase.HScannerInterface

   * @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

Examples of org.apache.hadoop.hbase.HScannerInterface

   
    Text[] columns = {
        TEXT_INPUT_COLUMN,
        TEXT_OUTPUT_COLUMN
    };
    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)) {
        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++;
        }
       
        // verify second value is the reverse of the first
        assertNotNull(firstValue);
        assertNotNull(secondValue);
        assertEquals(firstValue.length, secondValue.length);
        for (int i=0; i<firstValue.length; i++) {
          assertEquals(firstValue[i], secondValue[firstValue.length-i-1]);
        }
      }
     
    } finally {
      scanner.close();
    }
  }
View Full Code Here

Examples of org.apache.hadoop.hbase.HScannerInterface

  }

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

Examples of org.apache.hadoop.hbase.HScannerInterface

    Path localDir = new Path(this.testDir, "index_" +
      Integer.toString(new Random().nextInt()));
    this.fs.copyToLocalFile(new Path(INDEX_DIR), localDir);
    Path [] indexDirs = this.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(c, new Text(TABLE_NAME));
      Text[] columns = { TEXT_INPUT_COLUMN, TEXT_OUTPUT_COLUMN };
      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 = c.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();
        Term term = new Term(rowkeyName, value);
        int hitCount = searcher.search(new TermQuery(term)).length();
        assertEquals("check row " + value, 1, hitCount);
        count++;
      }
      int maxDoc = searcher.maxDoc();
      assertEquals("check number of rows", count, maxDoc);
    } finally {
      if (null != searcher)
        searcher.close();
      if (null != scanner)
        scanner.close();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.