删除数据|学习笔记

简介: 快速学习 删除数据

开发者学堂课程【分布式数据库 HBase 快速入门:删除数据】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/101/detail/1751


删除数据


内容简介:

1. 删除表的操作方法

2. 删除列的两种操作方法

3. 批量删除

 

1.删除表的操作方法

在命令行当中,删除操作有两种:

一种是删除某 rowkey 的全部数据,要用 deleteall;

hbase(main):016:0>deleteall ’student’,‘1001‘,

一种是删除某 rowkey 的某一列数据,要用 delete。

而在 API 中,删除操作的参数有:表名、rowkey、cf、cn。

Public static void delete(String tablename,String rowkey,String cf,String cn){

connection getTable()public static void delete (String tableName, String rowKey, String cf,String cn) throws

I0Exception {

//获取 table 对象

Table table = connection. getTable (TableName. valueOf(tableName));

// 创建 delete 对象

Delete delete = new Delete (Bytes. toBytes(rowKey));

//执行删除操作

table. delete (delete);

table. close() ;

 

2.删除列的两种操作方法

删除列共有两种方法:

1) delete. addColumns (Bytes. toBytes(cf), Bytes. toBytes(cn)) ;

2) delete. addColumn (Bytes. toBytes(cf), Bytes. toBytes(cn)) ;

1)删除指定列的所有版本

* Delete all versions of the specified column.

* @param family family name

* @param qualifier column qualifier

* @return this for invocation chaining

*/

public Delete addColumns(final byte [ ] family, final byte [ ] qualifier){

addColumns(family,qualifier,this.ts);

return this;

2)删除指定列的最新版本

* Delete the latest version of the specified column.This is an expensive call in that on the serverside, it first does a* get to find the latest versions timestamp.Then it adds a delete using

* the fetched ce1ls timestamp.

* @param family family name

* @aram qualifier column qualifier

* @return this for invocation chaining

*/public Delete addColumn(final byte [] family, final byte [ ] qualifier) {

this. deleteColumn (family, qualifier, this. ts);

return this;

在公司中建议用第一种放法,因为第二种方法在使用过程中,如果删除了最新版本,老版本的数据依然能被获取到。

在多版本情况下,使用第二种方法时,一定要加上时间戳。

 

3.批量删除

与 put 相同,一个 delete 里可以放多个列的数据,delete 对象与 rowkey 是一一对应的关系。

相关文章
|
XML 数据格式
Camunda常用功能
Camunda常用接口简介
4693 1
Camunda常用功能
|
关系型数据库 MySQL Java
Flink作业报错:Caused by: The connector is trying to read binlog starting at GTIDs ..., but this is no longer available on the server
Flink作业报错:Caused by: The connector is trying to read binlog starting at GTIDs ..., but this is no longer available on the server
Flink作业报错:Caused by: The connector is trying to read binlog starting at GTIDs ..., but this is no longer available on the server
|
SQL 分布式计算 Java
数据治理之元数据管理的利器——Atlas入门宝典(二)
随着数字化转型的工作推进,数据治理的工作已经被越来越多的公司提上了日程。作为Hadoop生态最紧密的元数据管理与发现工具,Atlas在其中扮演着重要的位置。但是其官方文档不是很丰富,也不够详细。所以整理了这份文档供大家学习使用。
3678 1
数据治理之元数据管理的利器——Atlas入门宝典(二)
|
10月前
|
消息中间件 存储 NoSQL
Django 实战:Celery 异步任务从环境搭建到调用全掌握
本文详解 Celery 核心概念、架构组成及工作流程,并实战演示如何在 Django 项目中集成 Celery,实现异步任务调用与事务提交控制,助你掌握从配置到部署的全流程开发技巧。
937 3
|
大数据 分布式数据库 Hbase
Hbase学习三:Hbase常用命令总结
Hbase学习三:Hbase常用命令总结
4892 0
|
存储 大数据 关系型数据库
HBase系列学习:基础知识
HBase系列学习:基础知识
655 1
HBase系列学习:基础知识
|
消息中间件 存储 监控
Django后端架构开发:Celery异步调优,任务队列和调度
Django后端架构开发:Celery异步调优,任务队列和调度
779 1
|
Linux
|
XML JSON 关系型数据库
PostgreSQL支持多种数据类型
PostgreSQL支持多种数据类型
1335 2

热门文章

最新文章