Hbase CRUD Operations(Java API)

 Put Method

 

void put(Put put)throws IOException

 

 Put的构造方法

 

Put(byte[] row)
Put(byte[] row,RowLock rowLock)
Put(byte[] row,long ts)
Put(byte[] row,long ts,RowLock rowLock)

 

 add()

 

Put add(byte[] family,byte[] qualifier,byte[] value)
Put add(byte[] family,byte[] qualifier,long ts,byte[]
value)
Put add(KeyValue kv)throws IOException

 Each call to add() specifies exactly one column,or,in combination with an optional timestamp,one single cell.

 

原子操作

boolean checkAndPut(Bytes.toBytes("item"), Bytes.toBytes("happy"),
				Bytes.toBytes("live"), null, put1)
 

 

 

delete()

 

void delete(Delete delete)throws IOException

Delete(byte[] row)
Delete(byte[] row,long timestamp,RowLock rowLock)

原子操作

boolean checkAndDelete(byte[] row,byte[] family,byte[]
qualifier,byte[] value,Delete delete)throws IOException
 

 

 

Delete deleteFamily(byte[] family)
Delete deleteFamily(byte[] family,long timestamp)//the timestamp matches the same and all older versions of all columns
Delete deleteColumns(byte[] family,byte[] qualifier)
Delete deleteColumns(byte[] family,byte[] qualifier,long
timestamp)
Delete deleteColumn(byte[] family,byte[] qualifier)
Delete deleteColumn(byte[] family,byte[] qualifier,long
timestamp)
void setTimestamp(long timestamp)
 

 

 

 

 

 

get()

 

List<KeyValue> get(byte[] family,byte[] qualifier)

Map<byte[] ,List<KeyValue>>getFamilyMap()

 

 

Get addFamily(byte[] family)
Get addColumn(byte[] family,byte[] qualifier)
Get setTimeRange(long minStamp,long maxStamp)throws
IOException
Get setTimeStamp(long timestamp)
Get setMaxVersions()
Get setMaxVersions(int maxVersions)throws IOException
 

 

 

 

has()

 

boolean has(byte[]family,byte[] qualifier)
boolean has(byte[]family,byte[] qualifier,long ts)
boolean has(byte[]family,byte[] qualifier,byte[] value)
boolean has(byte[]family,byte[] qualifier,long ts,byte[] value)
 

 

Example

 

 

public class PutExample{
public static void main(String[] args)throws IOException
{
Configuration conf= HBaseConfiguration.create();//hbase-default.xml and hbase-site.xml
HTable table= newHTable(conf,"testtable");
Put put= new Put(Bytes.toBytes("row1"));
//org.apache.hadoop.hbase.util.Bytes
put.add(Bytes.toBytes("colfam1"),
Bytes.toBytes("qual1"),
Bytes.toBytes("val1"));
put.add(Bytes.toBytes("colfam1"),
Bytes.toBytes("qual2"),
Bytes.toBytes("val2"));
table.put(put);
}
}
 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值