|
||||||||||
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. |
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 Text |
tableName
|
Constructor Summary | |
---|---|
HTable(HBaseConfiguration 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. |
void |
commit(long lockid,
long timestamp)
Finalize a row mutation and release any resources associated with the update. |
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)
Completely delete the row's cells. |
void |
deleteAll(Text row,
long ts)
Completely delete the row's cells of the same timestamp or older. |
void |
deleteAll(Text row,
Text column)
Delete all cells that match the passed row and column. |
void |
deleteAll(Text row,
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(Text row,
Text family)
Delete all cells for a row with matching column family at all timestamps. |
void |
deleteFamily(Text row,
Text family,
long timestamp)
Delete all cells for a row with matching column family with timestamps less than or equal to timestamp. |
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()
|
HTableDescriptor |
getMetadata()
|
SortedMap<Text,byte[]> |
getRow(Text row)
Get all the data for the specified row at the latest timestamp |
SortedMap<Text,byte[]> |
getRow(Text row,
long ts)
Get all the data for the specified row at a specified timestamp |
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. |
HScannerInterface |
obtainScanner(Text[] columns,
Text startRow,
Text stopRow)
Get a scanner on the current table starting at the specified row and ending just before stopRow |
HScannerInterface |
obtainScanner(Text[] columns,
Text startRow,
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,
Text column,
byte[] val)
Update a value for the specified column. |
void |
put(long lockid,
Text column,
Writable val)
Update 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 |
---|
protected final org.apache.commons.logging.Log LOG
protected final HConnection connection
protected final 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, 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 Text getTableName()
public HTableDescriptor getMetadata() throws IOException
IOException
public Text[] getStartKeys() throws IOException
IOException
public byte[] get(Text row, Text column) throws IOException
row
- row keycolumn
- column name
IOException
public byte[][] get(Text row, Text column, int numVersions) throws IOException
row
- - row keycolumn
- - column namenumVersions
- - number of versions to retrieve
IOException
public byte[][] get(Text row, Text column, long timestamp, int numVersions) throws IOException
row
- - row keycolumn
- - column nametimestamp
- - timestampnumVersions
- - number of versions to retrieve
IOException
public SortedMap<Text,byte[]> getRow(Text row) throws IOException
row
- row key
IOException
public SortedMap<Text,byte[]> getRow(Text row, long ts) throws IOException
row
- row keyts
- timestamp
IOException
public HScannerInterface obtainScanner(Text[] columns, 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(Text[] columns, 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(Text[] columns, 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(Text[] columns, Text startRow, 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(Text[] columns, Text startRow, 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(Text[] columns, 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
@Deprecated public long startBatchUpdate(Text row)
startUpdate(Text)
row
- name of row to be updated
@Deprecated public void abortBatch(long lockid)
abort(long)
lockid
- lock id returned by startBatchUpdate@Deprecated public void commitBatch(long lockid) throws IOException
commit(long)
lockid
- lock id returned by startBatchUpdate
IOException
@Deprecated public void commitBatch(long lockid, long timestamp) throws IOException
commit(long, long)
lockid
- lock id returned by startBatchUpdatetimestamp
- time to associate with all the changes
IOException
public long startUpdate(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, 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, Text column, 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, Text column)
lockid
- lock id returned from startUpdatecolumn
- name of column whose value is to be deletedpublic void deleteAll(Text row, Text column) throws IOException
row
- Row to updatecolumn
- name of column whose value is to be deleted
IOException
public void deleteAll(Text row, 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(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(Text row) throws IOException
row
- Key of the row you want to completely delete.
IOException
public void deleteFamily(Text row, Text family, long timestamp) throws IOException
row
- The row to operate onfamily
- The column family to matchtimestamp
- Timestamp to match
IOException
public void deleteFamily(Text row, 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
@Deprecated public void renewLease(long lockid)
lockid
- - lock id returned from startUpdate
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |