|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.hbase.HTable
public class HTable
Used to communicate with a single HBase table
Nested Class Summary | |
---|---|
protected class |
HTable.ClientScanner
Implements the scanner interface for the HBase client. |
protected class |
HTable.ServerCallable<T>
Inherits from Callable, used to define the particular actions you would like to take with retry logic. |
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 boolean |
tableDoesNotExist
|
protected org.apache.hadoop.io.Text |
tableName
|
Constructor Summary | |
---|---|
HTable(HBaseConfiguration conf,
org.apache.hadoop.io.Text tableName)
Creates an object to access a HBase table |
Method Summary | ||
---|---|---|
void |
abort(long lockid)
Abort a row mutation. |
|
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. |
|
void |
commit(long lockid,
long timestamp)
Finalize a row mutation and release any resources associated with the update. |
|
void |
delete(long lockid,
org.apache.hadoop.io.Text column)
Delete the value for a column. |
|
void |
deleteAll(org.apache.hadoop.io.Text row)
Completely delete the row's cells. |
|
void |
deleteAll(org.apache.hadoop.io.Text row,
long ts)
Completely delete the row's cells of the same timestamp or older. |
|
void |
deleteAll(org.apache.hadoop.io.Text row,
org.apache.hadoop.io.Text column)
Delete all cells that match the passed row and column. |
|
void |
deleteAll(org.apache.hadoop.io.Text row,
org.apache.hadoop.io.Text column,
long ts)
Delete all cells that match the passed row and column and whose timestamp is equal-to or older than the passed timestamp. |
|
void |
deleteFamily(org.apache.hadoop.io.Text row,
org.apache.hadoop.io.Text family)
Delete all cells for a row with matching column family at all timestamps. |
|
void |
deleteFamily(org.apache.hadoop.io.Text row,
org.apache.hadoop.io.Text family,
long timestamp)
Delete all cells for a row with matching column family with timestamps less than or equal to timestamp. |
|
byte[] |
get(org.apache.hadoop.io.Text row,
org.apache.hadoop.io.Text column)
Get a single value for the specified row and column |
|
byte[][] |
get(org.apache.hadoop.io.Text row,
org.apache.hadoop.io.Text column,
int numVersions)
Get the specified number of versions of the specified row and column |
|
byte[][] |
get(org.apache.hadoop.io.Text row,
org.apache.hadoop.io.Text column,
long timestamp,
int numVersions)
Get the specified number of versions of the specified row and column with the specified timestamp. |
|
HConnection |
getConnection()
|
|
HTableDescriptor |
getMetadata()
|
|
protected
|
getRegionServerWithRetries(HTable.ServerCallable<T> callable)
Pass in a ServerCallable with your particular bit of logic defined and this method will manage the process of doing retries with timed waits and refinds of missing regions. |
|
SortedMap<org.apache.hadoop.io.Text,byte[]> |
getRow(org.apache.hadoop.io.Text row)
Get all the data for the specified row at the latest timestamp |
|
SortedMap<org.apache.hadoop.io.Text,byte[]> |
getRow(org.apache.hadoop.io.Text row,
long ts)
Get all the data for the specified row at a specified timestamp |
|
org.apache.hadoop.io.Text[] |
getStartKeys()
Gets the starting row key for every region in the currently open table |
|
org.apache.hadoop.io.Text |
getTableName()
|
|
HScannerInterface |
obtainScanner(org.apache.hadoop.io.Text[] columns,
org.apache.hadoop.io.Text startRow)
Get a scanner on the current table starting at the specified row. |
|
HScannerInterface |
obtainScanner(org.apache.hadoop.io.Text[] columns,
org.apache.hadoop.io.Text startRow,
long timestamp)
Get a scanner on the current table starting at the specified row. |
|
HScannerInterface |
obtainScanner(org.apache.hadoop.io.Text[] columns,
org.apache.hadoop.io.Text startRow,
long timestamp,
RowFilterInterface filter)
Get a scanner on the current table starting at the specified row. |
|
HScannerInterface |
obtainScanner(org.apache.hadoop.io.Text[] columns,
org.apache.hadoop.io.Text startRow,
RowFilterInterface filter)
Get a scanner on the current table starting at the specified row. |
|
HScannerInterface |
obtainScanner(org.apache.hadoop.io.Text[] columns,
org.apache.hadoop.io.Text startRow,
org.apache.hadoop.io.Text stopRow)
Get a scanner on the current table starting at the specified row and ending just before stopRow |
|
HScannerInterface |
obtainScanner(org.apache.hadoop.io.Text[] columns,
org.apache.hadoop.io.Text startRow,
org.apache.hadoop.io.Text stopRow,
long timestamp)
Get a scanner on the current table starting at the specified row and ending just before stopRow |
|
void |
put(long lockid,
org.apache.hadoop.io.Text column,
byte[] val)
Update a value for the specified column. |
|
void |
put(long lockid,
org.apache.hadoop.io.Text column,
org.apache.hadoop.io.Writable val)
Update a value for the specified column. |
|
long |
startUpdate(org.apache.hadoop.io.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 |
---|
protected final org.apache.commons.logging.Log LOG
protected final HConnection connection
protected final org.apache.hadoop.io.Text tableName
protected final long pause
protected final int numRetries
protected Random rand
protected AtomicReference<BatchUpdate> batch
protected volatile boolean tableDoesNotExist
protected volatile boolean closed
Constructor Detail |
---|
public HTable(HBaseConfiguration conf, org.apache.hadoop.io.Text tableName) throws IOException
conf
- configuration objecttableName
- name of the table
IOException
Method Detail |
---|
protected void checkClosed()
public HConnection getConnection()
public void close()
public void checkUpdateInProgress()
public org.apache.hadoop.io.Text getTableName()
public HTableDescriptor getMetadata() throws IOException
IOException
public org.apache.hadoop.io.Text[] getStartKeys() throws IOException
IOException
public byte[] get(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text column) throws IOException
row
- row keycolumn
- column name
IOException
public byte[][] get(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text column, int numVersions) throws IOException
row
- - row keycolumn
- - column namenumVersions
- - number of versions to retrieve
IOException
public byte[][] get(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text column, long timestamp, int numVersions) throws IOException
row
- - row keycolumn
- - column nametimestamp
- - timestampnumVersions
- - number of versions to retrieve
IOException
public SortedMap<org.apache.hadoop.io.Text,byte[]> getRow(org.apache.hadoop.io.Text row) throws IOException
row
- row key
IOException
public SortedMap<org.apache.hadoop.io.Text,byte[]> getRow(org.apache.hadoop.io.Text row, long ts) throws IOException
row
- row keyts
- timestamp
IOException
public HScannerInterface obtainScanner(org.apache.hadoop.io.Text[] columns, org.apache.hadoop.io.Text startRow) throws IOException
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
IOException
public HScannerInterface obtainScanner(org.apache.hadoop.io.Text[] columns, org.apache.hadoop.io.Text startRow, long timestamp) throws IOException
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 scantimestamp
- only return results whose timestamp <= this value
IOException
public HScannerInterface obtainScanner(org.apache.hadoop.io.Text[] columns, org.apache.hadoop.io.Text startRow, RowFilterInterface filter) throws IOException
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 scanfilter
- a row filter using row-key regexp and/or column data filter.
IOException
public HScannerInterface obtainScanner(org.apache.hadoop.io.Text[] columns, org.apache.hadoop.io.Text startRow, org.apache.hadoop.io.Text stopRow) throws IOException
stopRow.
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 scanstopRow
- Row to stop scanning on. Once we hit this row we stop
returning values; i.e. we return the row before this one but not the
stopRow
itself.
- Returns:
- scanner
- Throws:
IOException
public HScannerInterface obtainScanner(org.apache.hadoop.io.Text[] columns, org.apache.hadoop.io.Text startRow, org.apache.hadoop.io.Text stopRow, long timestamp) throws IOException
stopRow.
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 scanstopRow
- Row to stop scanning on. Once we hit this row we stop
returning values; i.e. we return the row before this one but not the
stopRow
itself.timestamp
- only return results whose timestamp <= this value
- Returns:
- scanner
- Throws:
IOException
public HScannerInterface obtainScanner(org.apache.hadoop.io.Text[] columns, org.apache.hadoop.io.Text startRow, long timestamp, RowFilterInterface filter) throws IOException
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 scantimestamp
- only return results whose timestamp <= this valuefilter
- a row filter using row-key regexp and/or column data filter.
IOException
public long startUpdate(org.apache.hadoop.io.Text row)
Example:
long lockid = table.startUpdate(new Text(article.getName()));
for (File articleInfo: article.listFiles(new NonDirectories())) {
String article = null;
try {
DataInputStream in = new DataInputStream(new FileInputStream(articleInfo));
article = in.readUTF();
} catch (IOException e) {
// Input error - abandon update
table.abort(lockid);
throw e;
}
try {
table.put(lockid, columnName(articleInfo.getName()), article.getBytes());
} catch (RuntimeException e) {
// Put failed - abandon update
table.abort(lockid);
throw e;
}
}
table.commit(lockid);
row
- Name of row to start update against. Note, choose row names
with care. Rows are sorted lexicographically (comparison is done
using Text.compareTo(Object)
. If your keys are numeric,
lexicographic sorting means that 46 sorts AFTER 450 (If you want to use
numerics for keys, zero-pad).
commit(long)
,
commit(long, long)
,
abort(long)
public void put(long lockid, org.apache.hadoop.io.Text column, byte[] val)
abort(long)
if exception thrown.
lockid
- lock id returned from startUpdatecolumn
- column whose value is being setval
- new value for column. Cannot be null.public void put(long lockid, org.apache.hadoop.io.Text column, org.apache.hadoop.io.Writable val) throws IOException
abort(long)
if exception thrown.
lockid
- lock id returned from startUpdatecolumn
- column whose value is being setval
- new value for column. Cannot be null.
IOException
- throws this if the writable can't be
converted into a byte arraypublic void delete(long lockid, org.apache.hadoop.io.Text column)
lockid
- lock id returned from startUpdatecolumn
- name of column whose value is to be deletedpublic void deleteAll(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text column) throws IOException
row
- Row to updatecolumn
- name of column whose value is to be deleted
IOException
public void deleteAll(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text column, long ts) throws IOException
row
- Row to updatecolumn
- name of column whose value is to be deletedts
- Delete all cells of the same timestamp or older.
IOException
public void deleteAll(org.apache.hadoop.io.Text row, long ts) throws IOException
row
- Key of the row you want to completely delete.ts
- Timestamp of cells to delete
IOException
public void deleteAll(org.apache.hadoop.io.Text row) throws IOException
row
- Key of the row you want to completely delete.
IOException
public void deleteFamily(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text family, long timestamp) throws IOException
row
- The row to operate onfamily
- The column family to matchtimestamp
- Timestamp to match
IOException
public void deleteFamily(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text family) throws IOException
row
- The row to operate onfamily
- The column family to match
IOException
public void abort(long lockid)
lockid
- lock id returned from startUpdatepublic void commit(long lockid) throws IOException
lockid
- lock id returned from startUpdate
IOException
commit(long, long)
public void commit(long lockid, long timestamp) throws IOException
lockid
- lock id returned from startUpdatetimestamp
- time to associate with the change
IOException
protected <T> T getRegionServerWithRetries(HTable.ServerCallable<T> callable) throws IOException, RuntimeException
IOException
RuntimeException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |