Hbase之批量数据写入
来源:互联网 发布:moga算法 编辑:程序博客网 时间:2024/05/17 01:14
/**
* 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();
}
}
}
0 0
- Hbase之批量数据写入
- 【HBase基础教程】6、HBase之读取MapReduce数据写入HBase
- 【HBase基础教程】7、HBase之读取HBase数据写入HDFS
- MR之wc数据写入Hbase
- HBase数据写入测试
- HBase数据写入测试
- Hbase的数据写入
- Hbase 数据写入
- java hbase api 批量高效写入数据(线程池方式)
- ADO.NET之数据库表之间批量写入数据
- mapreduce写入HBase,数据异常
- HBase写入数据的过程
- 大数据技术-HBase:HBase写入路径
- Hadoop之——HBASE结合MapReduce批量导入数据
- sqlserver数据批量写入(转)
- Laravel批量写入数据详解
- HBase优化之bulkload写入
- spark将数据写入hbase以及从hbase读取数据
- mysql5.6启动失败的一般解决方法
- 几个NP-完全问题的证明
- 生成对抗网络GANs理解(附代码)
- Hololens——Assetbundle处理
- 线性表顺序存储设计与实现_框架搭建
- Hbase之批量数据写入
- loadrunner11 报Abnormal termination, caused by mdrv process termination的解决方法.
- FrameLayout
- 玲珑Round #7-1071 - Boring Game
- pat-bl-1028
- Multi-view Convolutional Neural Networks for 3D Shape Recognition
- Android音视频学习第1章:使用ffmpeg进行视频解码
- 解释器模式--Excel公式嵌套
- 性能测试2-性能测试流程