Hbase之原子性插入
/**
* Created by similarface on 16/8/16.
*/ import java.io.IOException; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil; import java.util.List;
import java.util.ArrayList; /**
* 批量插入的时候 如果其中一行有问题 该行实效其余的会入库
*/
public class PutDataWithAtomic {
public static void main(String[] args) throws IOException {
//获取陪着参数
Configuration config = HBaseConfiguration.create();
//建立连接
Connection connection = ConnectionFactory.createConnection(config); //连接表 获取表对象
Table table = connection.getTable(TableName.valueOf("testtable"));
Put put1 = new Put(Bytes.toBytes("10000"));
put1.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("company"), Bytes.toBytes("dianxin"));
boolean res1 = table.checkAndPut(Bytes.toBytes("10000"), Bytes.toBytes("colfam1"), Bytes.toBytes("company"), null, put1);
System.out.println("Put 1a applied: " + res1); boolean res2 = table.checkAndPut(Bytes.toBytes("10000"), Bytes.toBytes("colfam1"), Bytes.toBytes("company"), null, put1);
System.out.println("Put 1b applied: " + res2); Put put2 = new Put(Bytes.toBytes("10000"));
put2.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("company"), Bytes.toBytes("dx"));
boolean res3 = table.checkAndPut(Bytes.toBytes("10000"), Bytes.toBytes("colfam1"), Bytes.toBytes("dianxin"), Bytes.toBytes("val1"), put2);
System.out.println("Put 2 applied: " + res3); Put put3 = new Put(Bytes.toBytes("10086"));
put3.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("company"), Bytes.toBytes("yidong"));
boolean res4 = table.checkAndPut(Bytes.toBytes("10000"), Bytes.toBytes("colfam1"), Bytes.toBytes("company"), Bytes.toBytes("val1"), put3);
System.out.println("Put 3 applied: " + res4);
connection.close(); }
}
Hbase之原子性插入的更多相关文章
- Hive 实现HBase 数据批量插入
HBase 数据的插入可以使用Java API 来写Java 程序逐条倒入,但是不是很方便.利用Hive自带的一个Jar包,可以建立Hive和HBase的映射关系 利用Hive 的insert可以将批 ...
- Hbase之原子性更新数据
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; impo ...
- 7 Hbase put方式插入数据
package com.hikvision.hbase.vertify.test; import org.apache.hadoop.conf.Configuration; import org.ap ...
- 大数据组件原理总结-Hadoop、Hbase、Kafka、Zookeeper、Spark
Hadoop原理 分为HDFS与Yarn两个部分.HDFS有Namenode和Datanode两个部分.每个节点占用一个电脑.Datanode定时向Namenode发送心跳包,心跳包中包含Datano ...
- HBase 高性能加入数据 - 按批多“粮仓”式解决办法
摘要:如何从HBase中的海量数据中,以很快的速度的获取大批量数据,这一议题已经在<HBase 高性能获取数据>(http://www.cnblogs.com/wgp13x/p/42451 ...
- hbase读写流程
一. Hbase读流程 META表记录着表的原信息,根据rowkey查询META表,获取所在region信息 客户端去相应的regionServer查询数据,先查询memStore(memstore是 ...
- Hive集成HBase详解
摘要 Hive提供了与HBase的集成,使得能够在HBase表上使用HQL语句进行查询 插入操作以及进行Join和Union等复杂查询 应用场景 1. 将ETL操作的数据存入HBase 2. HB ...
- Centos中hive/hbase/hadoop/mysql实际操作及问题总结
目录 Hive中文乱码问题 hive和hbase的版本不一致 Ambari hive插入Hbase出错 Hive0.12和Hbase0.96不兼容,重新编译hive0.12.0 hiveserver不 ...
- Hive与Hbase整合
Hive与Hbase整合 1.文档 Hive HBase Integration 2.拷贝jar文件 2.1.把Hbase的lib目录下面的jar文件全部拷贝到Hive的lib目录下面 cd /hom ...
随机推荐
- uwsgi安装过程中遇到的问题
参考这篇文章: [root@crz_oa webserver]# uwsgi --http :9090 --wsgi-file home.py --daemonize /var/log/uwsgi.l ...
- Python 中对文件的输入输出
#! /usr/bin/python # Filename:using_file.py poem = '''\ Programming is fun When the work is done if ...
- OBD芯片应用开发手册 OBD2开发 内部资料分享 汽车电子通讯开发TDA61 TDA66芯片
OBD产品及各种汽车电子相关的开发.往往需要开发者学习各种汽车协议,深入了解全部OBD规范和汽车各性能参数.这往往需要开发者很长的时间学习研究,大大延缓了OBD产品的上市开发进度.为此深圳芯方案电子公 ...
- httpclient4.3.6/httpcore-4.4自己封装的工具类
引入jar包 httpclient4.3.6/httpcore-4.4 package com.develop.util; import java.io.IOException; import jav ...
- hdu So Easy!
So Easy! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- Outlook 无法更新全球通讯簿,错误 0×80190194
当 Outlook 客户端尝试更新全球通讯簿,实际上是下载脱机通讯簿(Officeline Address Book,简称 OAB)时,可能会收到 0×80190194 的错误.错误代码 0×8019 ...
- linux内核中的GPIO系统之(1):软件框架
一.前言 作为一个工作多年的系统工程师,免不了做两件事情:培训新员工和给新员工分配任务.对于那些刚刚从学校出来的学生,一般在开始的时候总是分配一些非常简单的任务,例如GPIO driver.LED d ...
- SD卡驱动分析(二)
三.下面分析一下高通的android2.3的代码中SD卡驱动的流程. 在kernel中,SD卡是作为平台设备加入到内核中去的,在/kernel/arch/arm/mach-msm/devices-ms ...
- 反弹SHELL汇总
http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet Reverse Shell Cheat Sheet If y ...
- [C程序设计语言]第一部分
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...