Package org.apache.hadoop.hbase

Examples of org.apache.hadoop.hbase.HTable$ClientScanner


   * @throws IOException
   */
  public static void changeOnlineStatus (final HBaseConfiguration c,
      final Text row, final boolean onlineOffline)
  throws IOException {
    HTable t = new HTable(c, HConstants.META_TABLE_NAME);
    byte [] cell = t.get(row, HConstants.COL_REGIONINFO);
    // Throws exception if null.
    HRegionInfo info = Writables.getHRegionInfo(cell);
    long id = t.startUpdate(row);
    info.setOffline(onlineOffline);
    t.put(id, HConstants.COL_REGIONINFO, Writables.getBytes(info));
    t.delete(id, HConstants.COL_SERVER);
    t.delete(id, HConstants.COL_STARTCODE);
    t.commit(id);
  }
View Full Code Here


    // Create a table.
    HBaseAdmin admin = new HBaseAdmin(this.conf);
    admin.createTable(desc);

    // insert some data into the test table
    HTable table = new HTable(conf, new Text(TABLE_NAME));

    for (int i = 0; i < NUM_ROWS; i++) {
      long id = table.startUpdate(new Text("row_" + String.format("%1$05d", i)));

      table.put(id, TEXT_COLUMN1, VALUE);
      table.put(id, TEXT_COLUMN2, String.format("%1$05d", i).getBytes());
      table.commit(id);
    }

    // LOG.info("Print table contents using scanner before map/reduce for " + TABLE_NAME);
    // scanTable(TABLE_NAME, false);
    // LOG.info("Print table contents using scanner+filter before map/reduce for " + TABLE_NAME);
    // scanTableWithRowFilter(TABLE_NAME, false);

    // Do some identity write operations on one column of the data.
    for (int n = 0; n < NUM_REWRITES; n++) {
      for (int i = 0; i < NUM_ROWS; i++) {
        long id = table.startUpdate(new Text("row_" + String.format("%1$05d", i)));

        table.put(id, TEXT_COLUMN2, String.format("%1$05d", i).getBytes());
        table.commit(id);
      }
    }

    // Wait for the flush to happen
    LOG.info("Waiting, for flushes to complete");
    Thread.sleep(5 * 1000);
    // Wait for the flush to happen
    LOG.info("Done. No flush should happen after this");

    // Do another round so to populate the mem cache
    for (int i = 0; i < NUM_ROWS; i++) {
      long id = table.startUpdate(new Text("row_" + String.format("%1$05d", i)));

      table.put(id, TEXT_COLUMN2, String.format("%1$05d", i).getBytes());
      table.commit(id);
    }

    LOG.info("Print table contents using scanner after map/reduce for " + TABLE_NAME);
    scanTable(TABLE_NAME, true);
    LOG.info("Print table contents using scanner+filter after map/reduce for " + TABLE_NAME);
View Full Code Here

    LOG.info("Print table contents using scanner+filter after map/reduce for " + TABLE_NAME);
    scanTableWithRowFilter(TABLE_NAME, true);
  }

  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

    int numFound = doScan(scanner, printValues);
    Assert.assertEquals(NUM_ROWS, numFound);
  }

  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

    return c.toString();
  }

  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)) {
View Full Code Here

        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();
View Full Code Here

    }
  }

  @SuppressWarnings("null")
  private void verify(String tableName) throws IOException {
    HTable table = new HTable(conf, new Text(tableName));
    boolean verified = false;
    long pause = conf.getLong("hbase.client.pause", 5 * 1000);
    int numRetries = conf.getInt("hbase.client.retries.number", 5);
    for (int i = 0; i < numRetries; i++) {
      try {
View Full Code Here

    // Create a table.
    HBaseAdmin admin = new HBaseAdmin(this.conf);
    admin.createTable(desc);

    // insert some data into the test table
    HTable table = new HTable(conf, new Text(SINGLE_REGION_TABLE_NAME));

    for(int i = 0; i < values.length; i++) {
      long lockid = table.startUpdate(new Text("row_"
          + String.format("%1$05d", i)));

      try {
        table.put(lockid, TEXT_INPUT_COLUMN, values[i]);
        table.commit(lockid, System.currentTimeMillis());
        lockid = -1;
      } finally {
        if (lockid != -1)
          table.abort(lockid);
      }
    }

    LOG.info("Print table contents before map/reduce");
    scanTable(conf, SINGLE_REGION_TABLE_NAME);
View Full Code Here

    // Populate a table into multiple regions
    MultiRegionTable.makeMultiRegionTable(conf, hCluster, fs,
        MULTI_REGION_TABLE_NAME, INPUT_COLUMN);
   
    // Verify table indeed has multiple regions
    HTable table = new HTable(conf, new Text(MULTI_REGION_TABLE_NAME));
    Text[] startKeys = table.getStartKeys();
    assertTrue(startKeys.length > 1);

    @SuppressWarnings("deprecation")
    MiniMRCluster mrCluster = new MiniMRCluster(2, fs.getUri().toString(), 1);
View Full Code Here

    verify(conf, MULTI_REGION_TABLE_NAME);
  }

  private void scanTable(Configuration conf, String tableName)
  throws IOException {
    HTable table = new HTable(conf, new Text(tableName));
   
    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[]>();
     
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.HTable$ClientScanner

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.