/**
* 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. Android:onNewIntent()触发机制及注意事项

    一.onNewIntent() 在IntentActivity中重写下列方法:onCreate onStart onRestart  onResume  onPause onStop onDestro ...

  2. 2016年10月20日 星期四 --出埃及记 Exodus 19:4

    2016年10月20日 星期四 --出埃及记 Exodus 19:4 `You yourselves have seen what I did to Egypt, and how I carried ...

  3. ListableBeanFactory

    ListableBeanFactory public interface ListableBeanFactory extends BeanFactory 该接口中定义了可以获取配置中所有bean的信息 ...

  4. 命名空间std引用<iostream>时使用

    所谓namespace,是指标识符的各种可见范围. C++标准程序库中的所有标识符都被定义于一个名为std的namespace中,这样命名空间std内定义的所有标识符都有效. 为什么把cout等放在s ...

  5. CodeForces 670D2 Magic Powder 二分

    D2. Magic Powder - 2 The term of this problem is the same as the previous one, the only exception — ...

  6. Codeoforces 558 B. Duff in Love

    //   B. Duff in Love time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. SqlSever基础 rtrim函数 除去字符串的右边的空格,左边中间的不管

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

  8. ruby学习总结05

    1.数值类(Numeric) 有理数:Rational(分子,分母) 复数:Complex(实数,虚数) 随机数:Rnadom   rand()  返回比1小的浮点数,rand(种子数)  返回0到该 ...

  9. (1)建立一个名叫Cat的类: 属性:姓名、毛色、年龄 行为:显示姓名、喊叫 (2)编写主类: 创建一个对象猫,姓名为“妮妮”,毛色为“灰色”,年龄为2岁,在屏幕上输 出该对象的毛色和年龄,让该对象调用显示姓名和喊叫两个方法。

    package lianxi; public class Cat { String Name, Color; int Age; void getName() { System.out.println( ...

  10. Android 基础

    1. 安卓的平台构建 例如我的手机 内核版本就是ubuntu  为手机硬件提供各种驱动. 架构的简单理解: Application(应用程序层) 我们一般说的应用层的开发就是在这个层次上进行的,当然包 ...