Package org.apache.hadoop.hbase

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


    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


    // 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, true);
    LOG.info("Print table contents using scanner+filter before map/reduce for " + TABLE_NAME);
View Full Code Here

  /*
   * Get an HTable instance by it's table name.
   */
  protected HTable getTable(final String tableName) throws IOException {
    return new HTable(this.conf, new Text(tableName));
  }
View Full Code Here

   */
  private void openScanner(final HttpServletRequest request,
      final HttpServletResponse response, final String [] pathSegments)
  throws IOException, ServletException {
    // get the table
    HTable table = getTable(getTableName(pathSegments));
   
    // get the list of columns we're supposed to interact with
    String[] raw_columns = request.getParameterValues(COLUMN);
    Text [] columns = null;
   
    if (raw_columns != null) {
      columns = new Text [raw_columns.length];
      for (int i = 0; i < raw_columns.length; i++) {
        // I think this decoding is redundant.
        columns[i] =
          new Text(URLDecoder.decode(raw_columns[i], HConstants.UTF8_ENCODING));
      }
    } else {
      // TODO: Need to put into the scanner all of the table's column
      // families.  TODO: Verify this returns all rows.  For now just fail.
      doMethodNotAllowed(response, "Unspecified columns parameter currently not supported!");
      return;
    }

    // TODO: Parse according to the timestamp format we agree on.   
    String raw_ts = request.getParameter(TIMESTAMP);

    // TODO: Are these decodings redundant?
    Text startRow = request.getParameter(START_ROW) == null?
      HConstants.EMPTY_START_ROW:
      new Text(URLDecoder.decode(request.getParameter(START_ROW),
        HConstants.UTF8_ENCODING));
    // Empty start row is same value as empty end row.
    Text endRow = request.getParameter(END_ROW) == null?
      HConstants.EMPTY_START_ROW:
      new Text(URLDecoder.decode(request.getParameter(END_ROW),
        HConstants.UTF8_ENCODING));

    HScannerInterface scanner = (request.getParameter(END_ROW) == null)?
       table.obtainScanner(columns, startRow):
       table.obtainScanner(columns, startRow, endRow);
   
    // Make a scanner id by hashing the object toString value (object name +
    // an id).  Will make identifier less burdensome and more url friendly.
    String scannerid =
      Integer.toHexString(JenkinsHash.hash(scanner.toString().getBytes(), -1));
View Full Code Here

    // if it's just table name, return the metadata
    if (pathSegments.length == 1) {
      getTableMetadata(request, response, pathSegments[0]);
    }
    else{
      HTable table = getTable(pathSegments[0]);
      if (pathSegments[1].toLowerCase().equals(REGIONS)) {
        // get a region list
        getTableRegions(table, request, response);
      }
      else if (pathSegments[1].toLowerCase().equals(ROW)) {
View Full Code Here

   * Do a put based on the client request.
   */
  private void putRow(final HttpServletRequest request,
    final HttpServletResponse response, final String [] pathSegments)
  throws IOException, ServletException {
    HTable table = getTable(pathSegments[0]);

    // pull the row key out of the path
    String row = URLDecoder.decode(pathSegments[2], HConstants.UTF8_ENCODING);
   
    switch(ContentType.getContentType(request.getHeader(CONTENT_TYPE))) {
View Full Code Here

   */
   private void deleteRow(final HttpServletRequest request,
    final HttpServletResponse response, final String [] pathSegments)
  throws IOException, ServletException {
    // grab the table we're operating on
    HTable table = getTable(getTableName(pathSegments));
   
    // pull the row key out of the path
    String row = URLDecoder.decode(pathSegments[2], HConstants.UTF8_ENCODING);
   
    Text key = new Text(row);

    String[] columns = request.getParameterValues(COLUMN);
       
    // hack - we'll actually test for the presence of the timestamp parameter
    // eventually
    boolean timestamp_present = false;
    if(timestamp_present){ // do a timestamp-aware delete
      doMethodNotAllowed(response, "DELETE with a timestamp not implemented!");
    }
    else{ // ignore timestamps
      if(columns == null || columns.length == 0){
        // retrieve all the columns
        doMethodNotAllowed(response,
          "DELETE without specified columns not implemented!");
      } else{
        // delete each column in turn     
        for(int i = 0; i < columns.length; i++){
          table.deleteAll(key, new Text(columns[i]));
        }
      }
      response.setStatus(202);
    }
  }
View Full Code Here

      @SuppressWarnings("unused") Progressable progress) throws IOException {
   
    // expecting exactly one path
   
    Text tableName = new Text(job.get(OUTPUT_TABLE));
    HTable table = null;
    try {
      table = new HTable(new HBaseConfiguration(job), tableName);
    } catch(IOException e) {
      LOG.error(e);
      throw e;
    }
    return new TableRecordWriter(table);
View Full Code Here

    m_cols = new Text[colNames.length];
    for(int i = 0; i < m_cols.length; i++) {
      m_cols[i] = new Text(colNames[i]);
    }
    try {
      m_table = new HTable(new HBaseConfiguration(job), m_tableName);
    } catch (Exception e) {
      LOG.error(e);
    }
  }
View Full Code Here

     * @throws IOException
     * @throws IOException
     */
    protected HTable getTable(final byte[] tableName) throws IOError,
        IOException {
      return new HTable(this.conf, getText(tableName));
    }
View Full Code Here

TOP

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

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.