/**
* 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.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.client.BufferedMutator;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Mutation;
import java.util.List;
import java.util.ArrayList;
public class PutBufferExample {
public static void main(String[] args) throws IOException {
//获取陪着参数
Configuration config = HBaseConfiguration.create();
//建立连接
Connection connection = ConnectionFactory.createConnection(config);
try {
//连接表 获取表对象
Table t = connection.getTable(TableName.valueOf("testtable"));
BufferedMutator table = connection.getBufferedMutator(TableName.valueOf("testtable"));
try {
Put p = new Put(Bytes.toBytes("myrow-1"));
//p.add(); 这个地方的add 是个过期的方法然而我并不知道Cell的用法是什么
p.add(Bytes.toBytes("colfam1"), Bytes.toBytes("name1"), Bytes.toBytes("zhangsan1"));
//table.put(p);
List<Mutation> mutations = new ArrayList<Mutation>();
mutations.add(p);
table.mutate(mutations);
//如果不flush 在后面get可能是看不见的
table.flush();
// Close your table and cluster connection.
Get get=new Get(Bytes.toBytes("myrow-1"));
Result result=t.get(get);
for(Cell cell:result.rawCells()){
System.out.print("行健: "+new String(CellUtil.cloneRow(cell)));
System.out.print("\t列簇: "+new String(CellUtil.cloneFamily(cell)));
System.out.print("\t列: "+new String(CellUtil.cloneQualifier(cell)));
System.out.print("\t值: "+new String(CellUtil.cloneValue(cell)));
System.out.println("\t时间戳: "+cell.getTimestamp());
}
System.out.print(">>>>end");
} finally {
if (table != null) table.close();
}
} finally {
connection.close();
}
}
}

  

Hbase之批量数据写入的更多相关文章

  1. POI解析excel,将批量数据写入文件或数据库

    .personSunflowerP { background: rgba(51, 153, 0, 0.66); border-bottom: 1px solid rgba(0, 102, 0, 1); ...

  2. hbase 从hbase上读取数据写入到hdfs

    Mapper package cn.hbase.mapreduce.hb2hdfs; import java.io.IOException; import org.apache.hadoop.hbas ...

  3. [转帖]时序数据库技术体系 – InfluxDB TSM存储引擎之数据写入

    时序数据库技术体系 – InfluxDB TSM存储引擎之数据写入 http://hbasefly.com/2018/03/27/timeseries-database-6/  2018年3月27日  ...

  4. 使用bulkload向hbase中批量写入数据

    1.数据样式 写入之前,需要整理以下数据的格式,之后将数据保存到hdfs中,本例使用的样式如下(用tab分开): row1 N row2 M row3 B row4 V row5 N row6 M r ...

  5. hbase大规模数据写入的优化历程

    业务背景:由于需要将ngix日志过滤出来的1亿+条用户行为记录存入Hbase数据库,以此根据一定的条件来提供近实时查询,比如根据用户id及一定的时间段等条件来过滤符合要求的若干行为记录,满足这一场景的 ...

  6. HBase - 数据写入流程解析

    本文由  网易云发布. 作者:范欣欣 本篇文章仅限内部分享,如需转载,请联系网易获取授权. 众所周知,HBase默认适用于写多读少的应用,正是依赖于它相当出色的写入性能:一个100台RS的集群可以轻松 ...

  7. 亿级用户下的新浪微博平台架构 前端机(提供 API 接口服务),队列机(处理上行业务逻辑,主要是数据写入),存储(mc、mysql、mcq、redis 、HBase等)

    https://mp.weixin.qq.com/s/f319mm6QsetwxntvSXpKxg 亿级用户下的新浪微博平台架构 炼数成金前沿推荐 2014-12-04 序言 新浪微博在2014年3月 ...

  8. 大数据学习day34---spark14------1 redis的事务(pipeline)测试 ,2. 利用redis的pipeline实现数据统计的exactlyonce ,3 SparkStreaming中数据写入Hbase实现ExactlyOnce, 4.Spark StandAlone的执行模式,5 spark on yarn

    1 redis的事务(pipeline)测试 Redis本身对数据进行操作,单条命令是原子性的,但事务不保证原子性,且没有回滚.事务中任何命令执行失败,其余的命令仍会被执行,将Redis的多个操作放到 ...

  9. HBase 高性能获取数据(多线程批量式解决办法) + MySQL和HBase性能测试比较

    摘要:   在前篇博客里已经讲述了通过一个自定义 HBase Filter来获取数据的办法,在末尾指出此办法的性能是不能满足应用要求的,很显然对于如此成熟的HBase来说,高性能获取数据应该不是问题. ...

随机推荐

  1. sql中decode(...)函数的用法

    相当于if语句 decode函数比较1个参数时 SELECT ID,DECODE(inParam,'beComparedParam','值1' ,'值2') name FROM bank #如果第一个 ...

  2. bash中一些基础知识

    bash是linux操作系统的shell.以下是Multi-Perspective Sentence Similarity Modeling论文实现时碰到的一个bash: #!/bin/bash py ...

  3. 2016年10月24日 星期一 --出埃及记 Exodus 19:8

    2016年10月24日 星期一 --出埃及记 Exodus 19:8 The people all responded together, "We will do everything th ...

  4. windows7安装phpnow Apache非管理员权限不能操作Windows NT服务的解决方法

    科普一下:PHPnow 是什么?        Win32 下绿色免费的 Apache + PHP + MySQL 环境套件包.简易安装.快速搭建支持虚拟主机的 PHP 环境,可以安装 Discuz! ...

  5. SqlSever基础 right函数 从右边开始,截取字符串

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  6. 【leetcode❤python】107. Binary Tree Level Order Traversal II

    #-*- coding: UTF-8 -*- # Definition for a binary tree node.# class TreeNode(object):#     def __init ...

  7. java web开发必备知识

    从各种招聘网站的要求上筛选出了一些java开发的一些基本的要求,对照自身看看有哪些缺陷. java基础 既然是java web开发,java SE肯定要学好了. 多线程,IO,集合等,对队列,缓存,消 ...

  8. 解决properties文件乱码问题(eclipse和MyEclipse)

    windows——>Preferences——>General——>ContentTypes——>Text——>Java Properties File,设置Defaul ...

  9. NoSQL系列:选择合适的数据库

    NoSQL系列:选择合适的数据库 为什么使用NoSQL数据库? 阻抗失衡 关系模型和内存中的数据结构不匹配 采用更为方便的数据交互方式提升开发效率 待处理的数据量很大 数据量超过关系型数据库的承载能力 ...

  10. shift移动变量

    1.移动变量 脚本 sh05.sh #!/bin/bash # Program # Program shows the effect of shift function # History: # // ...