Package org.apache.hadoop.hbase

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


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

    try {
      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 for " +
        SINGLE_REGION_TABLE_NAME);
      scanTable(SINGLE_REGION_TABLE_NAME, true);

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

      try {
        JobConf jobConf = new JobConf(conf, TestTableMapReduce.class);
        jobConf.setJobName("process column contents");
        jobConf.setNumMapTasks(1);
        jobConf.setNumReduceTasks(1);

        TableMap.initJob(SINGLE_REGION_TABLE_NAME, INPUT_COLUMN,
            ProcessContentsMapper.class, jobConf);

        TableReduce.initJob(SINGLE_REGION_TABLE_NAME,
            IdentityTableReduce.class, jobConf);
        LOG.info("Started " + SINGLE_REGION_TABLE_NAME);
        JobClient.runJob(jobConf);

        LOG.info("Print table contents after map/reduce for " +
          SINGLE_REGION_TABLE_NAME);
      scanTable(SINGLE_REGION_TABLE_NAME, true);

      // verify map-reduce results
      verify(SINGLE_REGION_TABLE_NAME);
      } finally {
        mrCluster.shutdown();
      }
    } finally {
      table.close();
    }
  }
View Full Code Here


    // Populate a table into multiple regions
    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));
    try {
      Text[] startKeys = table.getStartKeys();
      assertTrue(startKeys.length > 1);

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

      try {
        JobConf jobConf = new JobConf(conf, TestTableMapReduce.class);
        jobConf.setJobName("process column contents");
        jobConf.setNumMapTasks(2);
        jobConf.setNumReduceTasks(1);

        TableMap.initJob(MULTI_REGION_TABLE_NAME, INPUT_COLUMN,
            ProcessContentsMapper.class, jobConf);

        TableReduce.initJob(MULTI_REGION_TABLE_NAME,
            IdentityTableReduce.class, jobConf);
        LOG.info("Started " + MULTI_REGION_TABLE_NAME);
        JobClient.runJob(jobConf);

        // verify map-reduce results
        verify(MULTI_REGION_TABLE_NAME);
      } finally {
        mrCluster.shutdown();
      }
    } finally {
      table.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[]>();
     
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

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

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.