HBase API Put

Put(byte[] rowArray, int rowOffset, int rowLength, long ts)  We make a copy of the passed in row key to keep local

Put(byte[] row)  Create a Put operation for the specified row.

Put(byte[] row, long ts) Create a Put operation for the specified row, using a given timestamp.创建一个指定行,使用给定的时间戳

add(byte[] family, byte[] qualifier, byte[] value)  Add the specified column and value to this Put operation.添加指定的列和值

性能

setWriteToWAL: WAL是Write Ahead Log的缩写,指的是HBase在插入操作前是否写Log。默认是打开,关掉会提高性能,但是如果系统出现故障(负责插入的Region Server挂掉),数据可能会丢失。

另外HTable也有两个方法也会影响插入的性能

setAutoFlash: AutoFlush指的是在每次调用HBase的Put操作,是否提交到HBase Server。默认是true,每次会提交。如果此时是单条插入,就会有更多的IO,从而降低性能.

setWriteBufferSize: Write Buffer Size在AutoFlush为false的时候起作用,默认是2MB,也就是当插入数据超过2MB,就会自动提交到Server


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
HBase是一个分布式的、高可靠性的、面向列的NoSQL数据库系统,它是建立在Hadoop分布式文件系统HDFS上的,可以处理大量的结构化和半结构化的数据。在HBase中,数据是按照行键(rowkey)、列族(column family)、列限定符(column qualifier)和时间戳(timestamp)进行组织的。HBase提供了Java和REST API两种访问方式,下面是HBase Java API的应用方法: 1. 创建HBase配置对象: Configuration conf = HBaseConfiguration.create(); 2. 创建HBase连接对象: Connection conn = ConnectionFactory.createConnection(conf); 3. 获取一个HBase表对象: Table table = conn.getTable(TableName.valueOf("table_name")); 4. 向表中添加数据: Put put = new Put(Bytes.toBytes("row_key")); put.addColumn(Bytes.toBytes("column_family"), Bytes.toBytes("column_qualifier"), Bytes.toBytes("value")); table.put(put); 5. 从表中获取数据: Get get = new Get(Bytes.toBytes("row_key")); Result result = table.get(get); byte[] value = result.getValue(Bytes.toBytes("column_family"), Bytes.toBytes("column_qualifier")); 6. 扫描表中的数据: Scan scan = new Scan(); ResultScanner scanner = table.getScanner(scan); for (Result result : scanner) { byte[] value = result.getValue(Bytes.toBytes("column_family"), Bytes.toBytes("column_qualifier")); // do something with the value } 7. 删除表中的数据: Delete delete = new Delete(Bytes.toBytes("row_key")); delete.addColumn(Bytes.toBytes("column_family"), Bytes.toBytes("column_qualifier")); table.delete(delete); 8. 关闭HBase连接: table.close(); conn.close(); 以上是HBase Java API的基本应用方法,可以根据实际需求进行调整和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值