hBase客户端API-增删改
来源:互联网 发布:房地产大数据公司 编辑:程序博客网 时间:2024/04/29 18:51
package os.hbase.index;import java.io.IOException;import java.util.ArrayList;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.HColumnDescriptor;import org.apache.hadoop.hbase.HTableDescriptor;import org.apache.hadoop.hbase.MasterNotRunningException;import org.apache.hadoop.hbase.TableName;import org.apache.hadoop.hbase.ZooKeeperConnectionException;import org.apache.hadoop.hbase.client.Delete;import org.apache.hadoop.hbase.client.HBaseAdmin;import org.apache.hadoop.hbase.client.HTable;import org.apache.hadoop.hbase.client.Put;import org.apache.hadoop.hbase.util.Bytes;import org.junit.Test;public class HbaseDaoDemo { /* * 删除数据 */ @Test public void testDel() throws IOException { Configuration conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum","os-1:2181,os-2:2181,os-3:2181"); //拿到一个客户端对象 HTable hTable = new HTable(conf, "cart"); //指定删除的行键中指定的列 Delete delete = new Delete(Bytes.toBytes("user_02")); delete.deleteColumn(Bytes.toBytes("product"),Bytes.toBytes("product_id_01")); hTable.delete(delete); } /* * 一次插入多行数据 */ @Test public void testPuts() throws IOException { Configuration conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum","os-1:2181,os-2:2181,os-3:2181"); //拿到一个客户端对象 HTable hTable = new HTable(conf, "cart"); ArrayList<Put> puts = new ArrayList<Put>(); Put put = new Put(Bytes.toBytes("user_02")); put.add(Bytes.toBytes("product"), Bytes.toBytes("product_id_01"),Bytes.toBytes("pd-0002--01")); put.add(Bytes.toBytes("product"), Bytes.toBytes("product_num"),Bytes.toBytes("5")); put.add(Bytes.toBytes("goods"), Bytes.toBytes("product_id"),Bytes.toBytes("gd-0001-99")); put.add(Bytes.toBytes("goods"), Bytes.toBytes("product_num_01"),Bytes.toBytes("6")); Put put1 = new Put(Bytes.toBytes("user_03")); put1.add(Bytes.toBytes("product"), Bytes.toBytes("product_id_01"),Bytes.toBytes("pd-0002--01")); put1.add(Bytes.toBytes("product"), Bytes.toBytes("product_num"),Bytes.toBytes("5")); put1.add(Bytes.toBytes("goods"), Bytes.toBytes("product_id"),Bytes.toBytes("gd-0001-99")); put1.add(Bytes.toBytes("goods"), Bytes.toBytes("product_num_01"),Bytes.toBytes("6")); puts.add(put); puts.add(put1); hTable.put(puts); hTable.close(); } /* * 一次插入一行数据 */ @Test public void testPut() throws IOException{ Configuration conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum","os-1:2181,os-2:2181,os-3:2181"); //拿到一个客户端对象 HTable hTable = new HTable(conf, "cart"); //将插入的数据封装成对象 Put put = new Put(Bytes.toBytes("user_01")); put.add(Bytes.toBytes("product"), Bytes.toBytes("product_id"),Bytes.toBytes("pd-0001")); put.add(Bytes.toBytes("product"), Bytes.toBytes("product_num"),Bytes.toBytes("5")); put.add(Bytes.toBytes("goods"), Bytes.toBytes("product_id"),Bytes.toBytes("gd-0001")); put.add(Bytes.toBytes("goods"), Bytes.toBytes("product_num"),Bytes.toBytes("6")); //插入数据 hTable.put(put); //关闭连接 hTable.close(); } /* * 修改数据 */ @Test public void testUpdate() throws IOException { Configuration conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum","os-1:2181,os-2:2181,os-3:2181"); //拿到一个客户端对象 HTable hTable = new HTable(conf, "cart"); Put put = new Put(Bytes.toBytes("user_03")); put.add(Bytes.toBytes("product"),Bytes.toBytes("product_num"),Bytes.toBytes("222")); hTable.put(put); hTable.close();}
阅读全文
0 0
- hBase客户端API-增删改
- HBase 1.1.2 Java 客户端 api(hbase 1.0 增删改查,建表、删表等)
- hbase 增删改查 api 简单操作
- HBase基本API(java)操作(增删改查)
- HBase基本API(java)操作(增删改查)
- HBase基本API(java)操作(增删改查)
- Java API连接HBase 进行增删查改操作
- hbase 增删改查
- hbase数据增删改查
- hbase 增删查改操作
- HbaseDaoImp HBASE 增删改查
- HBase初学-增删查改
- Hbase基于java API的增删改查(旧API)
- HBase 使用 Java Api 实现对数据的增删改查
- java实现hbase数据库的增删改查操作(新API)
- JPA客户端增删改查
- Hbase 基础客户端API
- HBase--客户端API(基础知识)
- RemoveElement
- 【C++ 模板】 如何根据模版中数据类型做对应操作?
- 如何构建物联网支付安全云
- Tomcat-高并发并设置
- 二-十进制编码即BCD编码
- hBase客户端API-增删改
- 自定义 sudo 在你输入错误的密码时嘲讽信息
- 剑指offer
- 矩形覆盖
- Timer与TimerTask
- 漂亮的Ribbon界面
- 【bzoj2654】【二分+最小生成树】tree
- Web网站技术架构总结
- 8465:马走日(2.5基本算法之搜索)