HBase - 在不扫描的情况下删除具有时间戳范围的行列
HBase - delete columns of rows with range of timestamp without scanning
我想知道是否可以在不扫描整个数据库的情况下删除某些带有时间戳的行的某些列
我的代码如下:
public static final void deleteBatch(long date, String column, String...ids) throws Exception{
Connection con = null; // connection instance
HTable table = null; // htable instance
List<Delete> deletes = new ArrayList<Delete>(ids.length);
for(int i = 0; i < ids.length; i++){
String id = ids[i];
Delete delete = new Delete(id.getBytes());
delete.addColumn(/* CF */, Bytes.toString(column));
/*
also tried:
delete.addColumn(/* CF */, Bytes.toString(column), date);
*/
delete.setTimestamp(date);
deletes.add(delete);
}
table.delete(deletes);
table.close();
}
这有效,但会删除给定日期之前的所有列,
我想要这样的东西:
Delete delete = new Delete(id.getBytes());
delete.setTimestamp(date-1, date);
我不想删除特定日期之前或之后的内容,我想删除我指定的确切时间范围。
此外,我的 HTableDescriptor MaxVersion 设置为 Integer.MAX_VALUE 以保留所有更改。
Specifying timestamps, deleteFamily and deleteColumns will delete all
versions with a timestamp less than or equal to that passed
它删除时间戳等于或小于给定日期的所有列。
我怎样才能做到这一点?
感谢任何回答
经过几周的努力,我找到了解决这个问题的方法。
apache HBase has a feature called coprocessor 托管和管理数据级操作(get、delete、put ...)的核心执行,并且可以覆盖(开发)自定义计算,例如数据聚合和批量处理客户端范围外的数据。
对于 bulk delete 等常见问题有一些基本的实现。
我想知道是否可以在不扫描整个数据库的情况下删除某些带有时间戳的行的某些列
我的代码如下:
public static final void deleteBatch(long date, String column, String...ids) throws Exception{
Connection con = null; // connection instance
HTable table = null; // htable instance
List<Delete> deletes = new ArrayList<Delete>(ids.length);
for(int i = 0; i < ids.length; i++){
String id = ids[i];
Delete delete = new Delete(id.getBytes());
delete.addColumn(/* CF */, Bytes.toString(column));
/*
also tried:
delete.addColumn(/* CF */, Bytes.toString(column), date);
*/
delete.setTimestamp(date);
deletes.add(delete);
}
table.delete(deletes);
table.close();
}
这有效,但会删除给定日期之前的所有列, 我想要这样的东西:
Delete delete = new Delete(id.getBytes());
delete.setTimestamp(date-1, date);
我不想删除特定日期之前或之后的内容,我想删除我指定的确切时间范围。 此外,我的 HTableDescriptor MaxVersion 设置为 Integer.MAX_VALUE 以保留所有更改。
Specifying timestamps, deleteFamily and deleteColumns will delete all versions with a timestamp less than or equal to that passed
它删除时间戳等于或小于给定日期的所有列。
我怎样才能做到这一点?
感谢任何回答
经过几周的努力,我找到了解决这个问题的方法。
apache HBase has a feature called coprocessor 托管和管理数据级操作(get、delete、put ...)的核心执行,并且可以覆盖(开发)自定义计算,例如数据聚合和批量处理客户端范围外的数据。
对于 bulk delete 等常见问题有一些基本的实现。