org.apache.hadoop.hbase
Class HTable

java.lang.Object
  extended by org.apache.hadoop.hbase.HTable
All Implemented Interfaces:
HConstants

public class HTable
extends Object
implements HConstants

Used to communicate with a single HBase table


Nested Class Summary
protected  class HTable.ClientScanner
          Implements the scanner interface for the HBase client.
 
Field Summary
protected  AtomicReference<BatchUpdate> batch
           
protected  boolean closed
           
protected  HConnection connection
           
protected  org.apache.commons.logging.Log LOG
           
protected  int numRetries
           
protected  long pause
           
protected  Random rand
           
protected  Text tableName
           
protected  SortedMap<Text,HRegionLocation> tableServers
           
 
Fields inherited from interface org.apache.hadoop.hbase.HConstants
ALL_VERSIONS, COL_REGIONINFO, COL_REGIONINFO_ARRAY, COL_SERVER, COL_SPLITA, COL_SPLITB, COL_STARTCODE, COLUMN_FAMILY, COLUMN_FAMILY_ARRAY, COLUMN_FAMILY_STR, DEFAULT_HBASE_DIR, DEFAULT_HOST, DEFAULT_MASTER_ADDRESS, DEFAULT_MASTER_INFOPORT, DEFAULT_MAX_FILE_SIZE, DEFAULT_REGION_SERVER_CLASS, DEFAULT_REGIONSERVER_ADDRESS, DEFAULT_REGIONSERVER_INFOPORT, EMPTY_START_ROW, EMPTY_TEXT, HBASE_DIR, HREGION_LOGDIR_NAME, HREGION_OLDLOGFILE_NAME, HREGIONDIR_PREFIX, LATEST_TIMESTAMP, MASTER_ADDRESS, META_TABLE_NAME, REGION_SERVER_CLASS, REGIONSERVER_ADDRESS, ROOT_TABLE_NAME, THREAD_WAKE_FREQUENCY, UTF8_ENCODING
 
Constructor Summary
HTable(Configuration conf, Text tableName)
          Creates an object to access a HBase table
 
Method Summary
 void abort(long lockid)
          Abort a row mutation
 void abortBatch(long lockid)
          Deprecated. Batch operations are now the default. abortBatch is now implemented by @see abort(long)
protected  void checkClosed()
           
 void checkUpdateInProgress()
          Verifies that no update is in progress
 void close()
          Releases resources associated with this table.
 void commit(long lockid)
          Finalize a row mutation When this method is specified, we pass the server a value that says use the 'latest' timestamp.
 void commit(long lockid, long timestamp)
          Finalize a row mutation
 void commitBatch(long lockid)
          Deprecated. Batch operations are now the default. commitBatch(long) is now implemented by @see commit(long)
 void commitBatch(long lockid, long timestamp)
          Deprecated. Batch operations are now the default. commitBatch(long, long) is now implemented by @see commit(long, long)
 void delete(long lockid, Text column)
          Delete the value for a column.
 void deleteAll(Text row, Text column)
          Delete all values for a column
 void deleteAll(Text row, Text column, long ts)
          Delete all values for a column
 byte[] get(Text row, Text column)
          Get a single value for the specified row and column
 byte[][] get(Text row, Text column, int numVersions)
          Get the specified number of versions of the specified row and column
 byte[][] get(Text row, Text column, long timestamp, int numVersions)
          Get the specified number of versions of the specified row and column with the specified timestamp.
 HConnection getConnection()
           
 SortedMap<Text,byte[]> getRow(Text row)
          Get all the data for the specified row
 Text[] getStartKeys()
          Gets the starting row key for every region in the currently open table
 Text getTableName()
           
 HScannerInterface obtainScanner(Text[] columns, Text startRow)
          Get a scanner on the current table starting at the specified row.
 HScannerInterface obtainScanner(Text[] columns, Text startRow, long timestamp)
          Get a scanner on the current table starting at the specified row.
 HScannerInterface obtainScanner(Text[] columns, Text startRow, long timestamp, RowFilterInterface filter)
          Get a scanner on the current table starting at the specified row.
 HScannerInterface obtainScanner(Text[] columns, Text startRow, RowFilterInterface filter)
          Get a scanner on the current table starting at the specified row.
 void put(long lockid, Text column, byte[] val)
          Change a value for the specified column.
 void renewLease(long lockid)
          Deprecated. Batch updates are now the default. Consequently this method does nothing.
 long startBatchUpdate(Text row)
          Deprecated. Batch operations are now the default. startBatchUpdate is now implemented by @see startUpdate(Text)
 long startUpdate(Text row)
          Start an atomic row insertion/update.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected final org.apache.commons.logging.Log LOG

connection

protected final HConnection connection

tableName

protected final Text tableName

pause

protected final long pause

numRetries

protected final int numRetries

rand

protected Random rand

tableServers

protected volatile SortedMap<Text,HRegionLocation> tableServers

batch

protected AtomicReference<BatchUpdate> batch

closed

protected volatile boolean closed
Constructor Detail

HTable

public HTable(Configuration conf,
              Text tableName)
       throws IOException
Creates an object to access a HBase table

Parameters:
conf - configuration object
tableName - name of the table
Throws:
IOException
Method Detail

checkClosed

protected void checkClosed()

getConnection

public HConnection getConnection()
Returns:
the connection

close

public void close()
Releases resources associated with this table. After calling close(), all other methods will throw an IllegalStateException


checkUpdateInProgress

public void checkUpdateInProgress()
Verifies that no update is in progress


getTableName

public Text getTableName()
Returns:
the table name

getStartKeys

public Text[] getStartKeys()
Gets the starting row key for every region in the currently open table

Returns:
Array of region starting row keys

get

public byte[] get(Text row,
                  Text column)
           throws IOException
Get a single value for the specified row and column

Parameters:
row - row key
column - column name
Returns:
value for specified row/column
Throws:
IOException

get

public byte[][] get(Text row,
                    Text column,
                    int numVersions)
             throws IOException
Get the specified number of versions of the specified row and column

Parameters:
row - - row key
column - - column name
numVersions - - number of versions to retrieve
Returns:
- array byte values
Throws:
IOException

get

public byte[][] get(Text row,
                    Text column,
                    long timestamp,
                    int numVersions)
             throws IOException
Get the specified number of versions of the specified row and column with the specified timestamp.

Parameters:
row - - row key
column - - column name
timestamp - - timestamp
numVersions - - number of versions to retrieve
Returns:
- array of values that match the above criteria
Throws:
IOException

getRow

public SortedMap<Text,byte[]> getRow(Text row)
                              throws IOException
Get all the data for the specified row

Parameters:
row - row key
Returns:
map of colums to values
Throws:
IOException

obtainScanner

public HScannerInterface obtainScanner(Text[] columns,
                                       Text startRow)
                                throws IOException
Get a scanner on the current table starting at the specified row. Return the specified columns.

Parameters:
columns - columns to scan. If column name is a column family, all columns of the specified column family are returned. Its also possible to pass a regex in the column qualifier. A column qualifier is judged to be a regex if it contains at least one of the following characters: \+|^&*$[]]}{)(.
startRow - starting row in table to scan
Returns:
scanner
Throws:
IOException

obtainScanner

public HScannerInterface obtainScanner(Text[] columns,
                                       Text startRow,
                                       long timestamp)
                                throws IOException
Get a scanner on the current table starting at the specified row. Return the specified columns.

Parameters:
columns - columns to scan. If column name is a column family, all columns of the specified column family are returned. Its also possible to pass a regex in the column qualifier. A column qualifier is judged to be a regex if it contains at least one of the following characters: \+|^&*$[]]}{)(.
startRow - starting row in table to scan
timestamp - only return results whose timestamp <= this value
Returns:
scanner
Throws:
IOException

obtainScanner

public HScannerInterface obtainScanner(Text[] columns,
                                       Text startRow,
                                       RowFilterInterface filter)
                                throws IOException
Get a scanner on the current table starting at the specified row. Return the specified columns.

Parameters:
columns - columns to scan. If column name is a column family, all columns of the specified column family are returned. Its also possible to pass a regex in the column qualifier. A column qualifier is judged to be a regex if it contains at least one of the following characters: \+|^&*$[]]}{)(.
startRow - starting row in table to scan
filter - a row filter using row-key regexp and/or column data filter.
Returns:
scanner
Throws:
IOException

obtainScanner

public HScannerInterface obtainScanner(Text[] columns,
                                       Text startRow,
                                       long timestamp,
                                       RowFilterInterface filter)
                                throws IOException
Get a scanner on the current table starting at the specified row. Return the specified columns.

Parameters:
columns - columns to scan. If column name is a column family, all columns of the specified column family are returned. Its also possible to pass a regex in the column qualifier. A column qualifier is judged to be a regex if it contains at least one of the following characters: \+|^&*$[]]}{)(.
startRow - starting row in table to scan
timestamp - only return results whose timestamp <= this value
filter - a row filter using row-key regexp and/or column data filter.
Returns:
scanner
Throws:
IOException

startBatchUpdate

@Deprecated
public long startBatchUpdate(Text row)
Deprecated. Batch operations are now the default. startBatchUpdate is now implemented by @see startUpdate(Text)

Start a batch of row insertions/updates. No changes are committed until the call to commitBatchUpdate returns. A call to abortBatchUpdate will abandon the entire batch.

Parameters:
row - name of row to be updated
Returns:
lockid to be used in subsequent put, delete and commit calls

abortBatch

@Deprecated
public void abortBatch(long lockid)
Deprecated. Batch operations are now the default. abortBatch is now implemented by @see abort(long)

Abort a batch mutation

Parameters:
lockid - lock id returned by startBatchUpdate

commitBatch

@Deprecated
public void commitBatch(long lockid)
                 throws IOException
Deprecated. Batch operations are now the default. commitBatch(long) is now implemented by @see commit(long)

Finalize a batch mutation

Parameters:
lockid - lock id returned by startBatchUpdate
Throws:
IOException

commitBatch

@Deprecated
public void commitBatch(long lockid,
                                   long timestamp)
                 throws IOException
Deprecated. Batch operations are now the default. commitBatch(long, long) is now implemented by @see commit(long, long)

Finalize a batch mutation

Parameters:
lockid - lock id returned by startBatchUpdate
timestamp - time to associate with all the changes
Throws:
IOException

startUpdate

public long startUpdate(Text row)
Start an atomic row insertion/update. No changes are committed until the call to commit() returns. A call to abort() will abandon any updates in progress.

Parameters:
row - Name of row to start update against.
Returns:
Row lockid.

put

public void put(long lockid,
                Text column,
                byte[] val)
Change a value for the specified column. Runs abort(long) if exception thrown.

Parameters:
lockid - lock id returned from startUpdate
column - column whose value is being set
val - new value for column

delete

public void delete(long lockid,
                   Text column)
Delete the value for a column. Deletes the cell whose row/column/commit-timestamp match those of the delete.

Parameters:
lockid - lock id returned from startUpdate
column - name of column whose value is to be deleted

deleteAll

public void deleteAll(Text row,
                      Text column)
               throws IOException
Delete all values for a column

Parameters:
row - Row to update
column - name of column whose value is to be deleted
Throws:
IOException

deleteAll

public void deleteAll(Text row,
                      Text column,
                      long ts)
               throws IOException
Delete all values for a column

Parameters:
row - Row to update
column - name of column whose value is to be deleted
ts - Delete all cells of the same timestamp or older.
Throws:
IOException

abort

public void abort(long lockid)
Abort a row mutation

Parameters:
lockid - lock id returned from startUpdate

commit

public void commit(long lockid)
            throws IOException
Finalize a row mutation When this method is specified, we pass the server a value that says use the 'latest' timestamp. If we are doing a put, on the server-side, cells will be given the servers's current timestamp. If the we are commiting deletes, then delete removes the most recently modified cell of stipulated column.

Parameters:
lockid - lock id returned from startUpdate
Throws:
IOException

commit

public void commit(long lockid,
                   long timestamp)
            throws IOException
Finalize a row mutation

Parameters:
lockid - lock id returned from startUpdate
timestamp - time to associate with the change
Throws:
IOException

renewLease

@Deprecated
public void renewLease(long lockid)
Deprecated. Batch updates are now the default. Consequently this method does nothing.

Renew lease on update

Parameters:
lockid - - lock id returned from startUpdate


Copyright © 2006 The Apache Software Foundation