3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 package org
.apache
.hadoop
.hbase
.client
;
22 import java
.io
.IOException
;
23 import java
.util
.List
;
25 import java
.util
.NavigableMap
;
26 import java
.util
.UUID
;
27 import org
.apache
.hadoop
.hbase
.Cell
;
28 import org
.apache
.hadoop
.hbase
.CellBuilder
;
29 import org
.apache
.hadoop
.hbase
.CellBuilderType
;
30 import org
.apache
.hadoop
.hbase
.HConstants
;
31 import org
.apache
.hadoop
.hbase
.KeyValue
;
32 import org
.apache
.hadoop
.hbase
.security
.access
.Permission
;
33 import org
.apache
.hadoop
.hbase
.security
.visibility
.CellVisibility
;
34 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
35 import org
.apache
.yetus
.audience
.InterfaceAudience
;
38 * Used to perform Delete operations on a single row.
40 * To delete an entire row, instantiate a Delete object with the row
41 * to delete. To further define the scope of what to delete, perform
42 * additional methods as outlined below.
44 * To delete specific families, execute {@link #addFamily(byte[]) deleteFamily}
45 * for each family to delete.
47 * To delete multiple versions of specific columns, execute
48 * {@link #addColumns(byte[], byte[]) deleteColumns}
49 * for each column to delete.
51 * To delete specific versions of specific columns, execute
52 * {@link #addColumn(byte[], byte[], long) deleteColumn}
53 * for each column version to delete.
55 * Specifying timestamps, deleteFamily and deleteColumns will delete all
56 * versions with a timestamp less than or equal to that passed. If no
57 * timestamp is specified, an entry is added with a timestamp of 'now'
58 * where 'now' is the servers's EnvironmentEdgeManager.currentTime().
59 * Specifying a timestamp to the deleteColumn method will
60 * delete versions only with a timestamp equal to that specified.
61 * If no timestamp is passed to deleteColumn, internally, it figures the
62 * most recent cell's timestamp and adds a delete at that timestamp; i.e.
63 * it deletes the most recently added cell.
64 * <p>The timestamp passed to the constructor is used ONLY for delete of
65 * rows. For anything less -- a deleteColumn, deleteColumns or
66 * deleteFamily -- then you need to use the method overrides that take a
67 * timestamp. The constructor timestamp is not referenced.
69 @InterfaceAudience.Public
70 public class Delete
extends Mutation
{
72 * Create a Delete operation for the specified row.
74 * If no further operations are done, this will delete everything
75 * associated with the specified row (all versions of all columns in all
76 * families), with timestamp from current point in time to the past.
77 * Cells defining timestamp for a future point in time
78 * (timestamp > current time) will not be deleted.
81 public Delete(byte [] row
) {
82 this(row
, HConstants
.LATEST_TIMESTAMP
);
86 * Create a Delete operation for the specified row and timestamp.<p>
88 * If no further operations are done, this will delete all columns in all
89 * families of the specified row with a timestamp less than or equal to the
90 * specified timestamp.<p>
92 * This timestamp is ONLY used for a delete row operation. If specifying
93 * families or columns, you must specify each timestamp individually.
95 * @param timestamp maximum version timestamp (only for delete row)
97 public Delete(byte [] row
, long timestamp
) {
98 this(row
, 0, row
.length
, timestamp
);
102 * Create a Delete operation for the specified row and timestamp.<p>
104 * If no further operations are done, this will delete all columns in all
105 * families of the specified row with a timestamp less than or equal to the
106 * specified timestamp.<p>
108 * This timestamp is ONLY used for a delete row operation. If specifying
109 * families or columns, you must specify each timestamp individually.
110 * @param row We make a local copy of this passed in row.
114 public Delete(final byte[] row
, final int rowOffset
, final int rowLength
) {
115 this(row
, rowOffset
, rowLength
, HConstants
.LATEST_TIMESTAMP
);
119 * Create a Delete operation for the specified row and timestamp.<p>
121 * If no further operations are done, this will delete all columns in all
122 * families of the specified row with a timestamp less than or equal to the
123 * specified timestamp.<p>
125 * This timestamp is ONLY used for a delete row operation. If specifying
126 * families or columns, you must specify each timestamp individually.
127 * @param row We make a local copy of this passed in row.
130 * @param timestamp maximum version timestamp (only for delete row)
132 public Delete(final byte[] row
, final int rowOffset
, final int rowLength
, long timestamp
) {
133 checkRow(row
, rowOffset
, rowLength
);
134 this.row
= Bytes
.copy(row
, rowOffset
, rowLength
);
135 setTimestamp(timestamp
);
139 * @param deleteToCopy delete to copy
141 public Delete(final Delete deleteToCopy
) {
146 * Construct the Delete with user defined data. NOTED:
147 * 1) all cells in the familyMap must have the delete type.
148 * see {@link org.apache.hadoop.hbase.Cell.Type}
149 * 2) the row of each cell must be same with passed row.
150 * @param row row. CAN'T be null
151 * @param ts timestamp
152 * @param familyMap the map to collect all cells internally. CAN'T be null
154 public Delete(byte[] row
, long ts
, NavigableMap
<byte [], List
<Cell
>> familyMap
) {
155 super(row
, ts
, familyMap
);
159 * Add an existing delete marker to this Delete object.
160 * @param cell An existing cell of type "delete".
161 * @return this for invocation chaining
162 * @throws IOException
164 public Delete
add(Cell cell
) throws IOException
{
170 * Delete all versions of all columns of the specified family.
172 * Overrides previous calls to deleteColumn and deleteColumns for the
174 * @param family family name
175 * @return this for invocation chaining
177 public Delete
addFamily(final byte [] family
) {
178 this.addFamily(family
, this.ts
);
183 * Delete all columns of the specified family with a timestamp less than
184 * or equal to the specified timestamp.
186 * Overrides previous calls to deleteColumn and deleteColumns for the
188 * @param family family name
189 * @param timestamp maximum version timestamp
190 * @return this for invocation chaining
192 public Delete
addFamily(final byte [] family
, final long timestamp
) {
194 throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + timestamp
);
196 List
<Cell
> list
= getCellList(family
);
197 if(!list
.isEmpty()) {
200 KeyValue kv
= new KeyValue(row
, family
, null, timestamp
, KeyValue
.Type
.DeleteFamily
);
206 * Delete all columns of the specified family with a timestamp equal to
207 * the specified timestamp.
208 * @param family family name
209 * @param timestamp version timestamp
210 * @return this for invocation chaining
212 public Delete
addFamilyVersion(final byte [] family
, final long timestamp
) {
213 List
<Cell
> list
= getCellList(family
);
214 list
.add(new KeyValue(row
, family
, null, timestamp
,
215 KeyValue
.Type
.DeleteFamilyVersion
));
220 * Delete all versions of the specified column.
221 * @param family family name
222 * @param qualifier column qualifier
223 * @return this for invocation chaining
225 public Delete
addColumns(final byte [] family
, final byte [] qualifier
) {
226 addColumns(family
, qualifier
, this.ts
);
231 * Delete all versions of the specified column with a timestamp less than
232 * or equal to the specified timestamp.
233 * @param family family name
234 * @param qualifier column qualifier
235 * @param timestamp maximum version timestamp
236 * @return this for invocation chaining
238 public Delete
addColumns(final byte [] family
, final byte [] qualifier
, final long timestamp
) {
240 throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + timestamp
);
242 List
<Cell
> list
= getCellList(family
);
243 list
.add(new KeyValue(this.row
, family
, qualifier
, timestamp
,
244 KeyValue
.Type
.DeleteColumn
));
249 * Delete the latest version of the specified column.
250 * This is an expensive call in that on the server-side, it first does a
251 * get to find the latest versions timestamp. Then it adds a delete using
252 * the fetched cells timestamp.
253 * @param family family name
254 * @param qualifier column qualifier
255 * @return this for invocation chaining
257 public Delete
addColumn(final byte [] family
, final byte [] qualifier
) {
258 this.addColumn(family
, qualifier
, this.ts
);
263 * Delete the specified version of the specified column.
264 * @param family family name
265 * @param qualifier column qualifier
266 * @param timestamp version timestamp
267 * @return this for invocation chaining
269 public Delete
addColumn(byte [] family
, byte [] qualifier
, long timestamp
) {
271 throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + timestamp
);
273 List
<Cell
> list
= getCellList(family
);
274 KeyValue kv
= new KeyValue(this.row
, family
, qualifier
, timestamp
, KeyValue
.Type
.Delete
);
280 public Delete
setTimestamp(long timestamp
) {
281 super.setTimestamp(timestamp
);
286 public Delete
setAttribute(String name
, byte[] value
) {
287 return (Delete
) super.setAttribute(name
, value
);
291 public Delete
setId(String id
) {
292 return (Delete
) super.setId(id
);
296 public Delete
setDurability(Durability d
) {
297 return (Delete
) super.setDurability(d
);
301 public Delete
setClusterIds(List
<UUID
> clusterIds
) {
302 return (Delete
) super.setClusterIds(clusterIds
);
306 public Delete
setCellVisibility(CellVisibility expression
) {
307 return (Delete
) super.setCellVisibility(expression
);
311 public Delete
setACL(String user
, Permission perms
) {
312 return (Delete
) super.setACL(user
, perms
);
316 public Delete
setACL(Map
<String
, Permission
> perms
) {
317 return (Delete
) super.setACL(perms
);
321 public Delete
setTTL(long ttl
) {
322 throw new UnsupportedOperationException("Setting TTLs on Deletes is not supported");
326 public Delete
setPriority(int priority
) {
327 return (Delete
) super.setPriority(priority
);
331 public CellBuilder
getCellBuilder(CellBuilderType type
) {
332 return getCellBuilder(type
, Cell
.Type
.Delete
);