Package org.apache.hadoop.hbase.client

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


    try {
      verify(scanner);
    } finally {
      scanner.close();
    }
    Scanner scanner2 = table.getScanner(columns, startRow);
    try {
      for (RowResult r : scanner2) {
        assertTrue("row key", values.containsKey(r.getRow()));

        SortedMap<byte [], Cell> columnValues = values.get(r.getRow());
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

    HTable t = new HTable(conf, TABLE_NAME);
   
    // Case 1: scan with LATEST_TIMESTAMP. Should get two rows
   
    int count = 0;
    Scanner s = t.getScanner(HConstants.COLUMN_FAMILY_ARRAY);
    try {
      while (s.next() != null) {
        count += 1;
      }
      assertEquals("Number of rows should be 2", 2, count);
    } finally {
      s.close();
    }

    // Case 2: Scan with a timestamp greater than most recent timestamp
    // (in this case > 1000 and < LATEST_TIMESTAMP. Should get 2 rows.
   
    count = 0;
    s = t.getScanner(HConstants.COLUMN_FAMILY_ARRAY, HConstants.EMPTY_START_ROW,
        10000L);
    try {
      while (s.next() != null) {
        count += 1;
      }
      assertEquals("Number of rows should be 2", 2, count);
    } finally {
      s.close();
    }
   
    // Case 3: scan with timestamp equal to most recent timestamp
    // (in this case == 1000. Should get 2 rows.
   
    count = 0;
    s = t.getScanner(HConstants.COLUMN_FAMILY_ARRAY, HConstants.EMPTY_START_ROW,
        1000L);
    try {
      while (s.next() != null) {
        count += 1;
      }
      assertEquals("Number of rows should be 2", 2, count);
    } finally {
      s.close();
    }
   
    // Case 4: scan with timestamp greater than first timestamp but less than
    // second timestamp (100 < timestamp < 1000). Should get 2 rows.
   
    count = 0;
    s = t.getScanner(HConstants.COLUMN_FAMILY_ARRAY, HConstants.EMPTY_START_ROW,
        500L);
    try {
      while (s.next() != null) {
        count += 1;
      }
      assertEquals("Number of rows should be 2", 2, count);
    } finally {
      s.close();
    }
   
    // Case 5: scan with timestamp equal to first timestamp (100)
    // Should get 2 rows.
   
    count = 0;
    s = t.getScanner(HConstants.COLUMN_FAMILY_ARRAY, HConstants.EMPTY_START_ROW,
        100L);
    try {
      while (s.next() != null) {
        count += 1;
      }
      assertEquals("Number of rows should be 2", 2, count);
    } finally {
      s.close();
    }
  }
View Full Code Here

    byte [][] cols = new byte [][] {Bytes.toBytes(ANCHORNUM + "[0-9]+"),
      CONTENTS_BASIC};
   
    long startTime = System.currentTimeMillis();
   
    Scanner s = table.getScanner(cols, HConstants.EMPTY_BYTE_ARRAY);
    try {

      int contentsFetched = 0;
      int anchorFetched = 0;
      int k = 0;
      for (RowResult curVals : s) {
        for (Iterator<byte []> it = curVals.keySet().iterator(); it.hasNext(); ) {
          byte [] col = it.next();
          byte val[] = curVals.get(col).getValue();
          String curval = Bytes.toString(val);
          if (Bytes.compareTo(col, CONTENTS_BASIC) == 0) {
            assertTrue("Error at:" + curVals.getRow()
                + ", Value for " + col + " should start with: " + CONTENTSTR
                + ", but was fetched as: " + curval,
                curval.startsWith(CONTENTSTR));
            contentsFetched++;
           
          } else if (Bytes.toString(col).startsWith(ANCHORNUM)) {
            assertTrue("Error at:" + curVals.getRow()
                + ", Value for " + col + " should start with: " + ANCHORSTR
                + ", but was fetched as: " + curval,
                curval.startsWith(ANCHORSTR));
            anchorFetched++;
           
          } else {
            LOG.info(Bytes.toString(col));
          }
        }
        k++;
      }
      assertEquals("Expected " + NUM_VALS + " " +
        Bytes.toString(CONTENTS_BASIC) + " values, but fetched " +
        contentsFetched,
        NUM_VALS, contentsFetched);
      assertEquals("Expected " + NUM_VALS + " " + ANCHORNUM +
        " values, but fetched " + anchorFetched,
        NUM_VALS, anchorFetched);

      LOG.info("Scanned " + NUM_VALS
          + " rows. Elapsed time: "
          + ((System.currentTimeMillis() - startTime) / 1000.0));

    } finally {
      s.close();
    }
  }
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

        HTable table = getTable(tableName);
        byte [][] columnsText = new byte[columns.size()][];
        for (int i = 0; i < columns.size(); ++i) {
          columnsText[i] = getText(columns.get(i));
        }
        Scanner scanner = table.getScanner(columnsText,
            getText(startRow));
        return addScanner(scanner);
      } catch (IOException e) {
        throw new IOError(e.getMessage());
      }
View Full Code Here

        HTable table = getTable(tableName);
        byte [][] columnsText = new byte[columns.size()][];
        for (int i = 0; i < columns.size(); ++i) {
          columnsText[i] = getText(columns.get(i));
        }
        Scanner scanner = table.getScanner(columnsText,
            getText(startRow), getText(stopRow));
        return addScanner(scanner);
      } catch (IOException e) {
        throw new IOError(e.getMessage());
      }
View Full Code Here

        HTable table = getTable(tableName);
        byte [][] columnsText = new byte[columns.size()][];
        for (int i = 0; i < columns.size(); ++i) {
          columnsText[i] = getText(columns.get(i));
        }
        Scanner scanner = table.getScanner(columnsText,
            getText(startRow), timestamp);
        return addScanner(scanner);
      } catch (IOException e) {
        throw new IOError(e.getMessage());
      }
View Full Code Here

        HTable table = getTable(tableName);
        byte [][] columnsText = new byte[columns.size()][];
        for (int i = 0; i < columns.size(); ++i) {
          columnsText[i] = getText(columns.get(i));
        }
        Scanner scanner = table.getScanner(columnsText,
            getText(startRow), getText(stopRow), timestamp);
        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.