Part8---Java删除Hbase数据
01.查看原始表02.删除Hbase数据2.1删除指定行键的整条记录import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.TableName;import org.apache.hadoop.hbase.client.Connection;import org.apache.hadoop.hbase.c
·
01.查看原始表
02.删除Hbase数据
2.1 删除指定行键的整条记录
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
/***
* 删除Hbase中某一条数据
*/
public class DeleteHbaseDataOfAll {
public static void main(String[] args) throws Exception{
Configuration conf = new Configuration();
conf.set("hbase.zookeeper.quorum","192.168.1.10:2181");
Connection conn = ConnectionFactory.createConnection(conf);
Table gadaite = conn.getTable(TableName.valueOf("Gadaite"));
Delete delete = new Delete(Bytes.toBytes("101"));
gadaite.delete(delete);
gadaite.close();
conn.close();
}
}
执行结果:
行键为”101“的数据已经被删除
2.2 指定列簇删除
指定列簇需要先指定行键
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
public class DeleteHbaseDataOfFamily {
public static void main(String[] args) throws Exception{
Configuration conf = new Configuration();
conf.set("hbase.zookeeper.quorum","192.168.1.10");
Connection conn = ConnectionFactory.createConnection(conf);
Table gadaite = conn.getTable(TableName.valueOf("Gadaite"));
// new Delete(Bytes.toBytes("这里填写行键是直接删除该行键对应的所有记录"));
Delete delete = new Delete(Bytes.toBytes("001"));
Delete delete1 = delete.addFamily(Bytes.toBytes("F1"));
gadaite.delete(delete1);
gadaite.close();
conn.close();
}
}
执行结果:
001行键下,F1列簇的数据被删除
2.2 指定字段删除
需要先指定行键,列簇,字段
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
public class DelectHbaseDataOfColumn {
public static void main(String[] args) throws Exception{
Configuration conf = new Configuration();
conf.set("hbase.zookeeper.quorum","192.168.1.10");
Connection conn = ConnectionFactory.createConnection(conf);
Table gadaite = conn.getTable(TableName.valueOf("Gadaite"));
Delete delete = new Delete(Bytes.toBytes("001"));
// 删除某个列簇下指定的某个字段时,使用addColum,并传递两个参数
Delete delete1 = delete.addColumn(Bytes.toBytes("F2"), Bytes.toBytes("F22"));
gadaite.delete(delete1);
gadaite.close();
conn.close();
}
}
001行键,F2列簇,F22字段内容被删除
更多推荐
已为社区贡献3条内容
所有评论(0)