Single Deletes
The variant of the delete()
call that takes a single Delete
instance is:
void delete(Delete delete) throws IOException
HBase中用来做删除操作的接口,通过构造一个Delete的实例,传给delete就OK了!
Just as with the get and put calls you have seen already, you will have to create aDelete
instance and then adding details about the data you want to remove. The constructors are:
Delete(byte[] row)
Delete(byte[] row, long timestamp, RowLock rowLock)
两个基本的构造函数,row key是必须存在的,另外可以根据需要是否client提供rowLock。其他的细节使用下面的函数设定来缩小范围。
You need to provide the row
you want to modify, and optionally provide a rowLock
, an instance of RowLock
to specify your own lock details, in case you want to modify the same row more than once subsequently. Otherwise you would be wise to narrow down what you want to remove from the given row, using one of the following methods:
Delete deleteFamily(byte[] family)
Delete deleteFamily(byte[] family, long timestamp)
Delete deleteColumns(byte[] family, byte[] qualifier)
Delete deleteColumns(byte[] family, byte[] qualifier, long timestamp)
Delete deleteColumn(byte[] family, byte[] qualifier)
Delete deleteColumn(byte[] family, byte[] qualifier, long timestamp)
void setTimestamp(long timestamp)
这里面的方法分为四类:1)deleteFamily 2)deleteColomns 3)deleteColumn 4)setTimestamp
- 不带timestamp表示删除column family里面所有版本的cells,而带timestamp表示只删除column family指定timestamp版本或者所有更老的版本的cells。
- 不带timestamp表示删除column qualifier所有版本的cells,而带timestamp表示只删除指定timestamp版本或者更老版本的cells。
- 不带timestamp表示删除最新版本的cell,而带timestamp表示删除指定timestamp的cell
- 表示删除指定timestamp或者所有更老版本的cells
You do have a choice to narrow in on what to remove using four types of calls: first you can use the deleteFamily()
methods to remove an entire column family, including all contained columns. You have the option to specify a timestamp that triggers more specific filtering of cell versions. If specified, the timestamp matches the same and all older versions of all columns.
The next type is deleteColumns()
, which operates on exactly one column and deletes either all versions of that cell when no timestamp is given, or all matching and older versions when a timestamp is specified.t
The third type is similar, using deleteColumn()
. They also operate on a specific, given column only, but either delete the most current, or the specified version, i.e., the one with the exact matching timestamp.
Finally there is just setTimestamp()
, which is not considered when using any of the other three types of calls. But if you do not specify either a family or a column then this call can make the difference between deleting the entire row, or just all contained columns, in all column families, that match or have an older timestamp compared to the given one. Table 3.5, “Functionality matrix of the delete() calls”shows the functionality in a matrix to make the semantics more readable.
Table 3.5. Functionality matrix of the delete()
calls
Method | Deletes without Timestamp | Deletes With Timestamp |
---|---|---|
none | Entire row, i.e., all columns, all versions | All versions of all columns in all column families, whose timestamp is equal or older than the given timestamp |
deleteColumn() | Only the latest version of the given column, older versions are kept | Only exactly the specified version of the given column, with the matching timestamp. If non-existent then nothing is deleted. |
deleteColumns() | All versions of the given column | Versions equal or older than the given timestamp of the given column |
deleteFamily() | All columns (including all versions) of the given family | Versions equal or older than the given timestamp of all column of the given family |