| ±à¼ÍƼö: |
±¾ÎÄÀ´×ÔÓÚcsdn
,±¾ÎĽéÉÜ2ÖÖ»ñÈ¡ÁÐµÄ¶à°æ±¾Êý¾ÝµÄ·½Ê½£ºshellºÍspring data
hadoop¡£ |
|
Ò»¡¢hbase shellÖÐÈçºÎ»ñÈ¡
1¡¢ÔÚshell¶Ë´´½¨Ò»¸öHbase±í
2¡¢²é¿´±í½á¹¹
±í½á¹¹ÈçÏ£º
Table t1 is
ENABLED
t1
COLUMN FAMILIES DESCRIPTION
{NAME => 'f1', BLOOMFILTER => 'ROW', VERSIONS
=> '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS
=> 'FALSE', DATA_BLOCK_ENCODING => 'NON
E', TTL => 'FOREVER', COMPRESSION => 'NONE',
MIN_VERSIONS => '0', BLOCKCACHE => 'true',
BLOCKSIZE => '65536', REPLICATION_SCOPE =>
'0'
}
1 row(s) in 0.1370 seconds |
´ÓÉÏÃæµÄ±í½á¹¹ÖУ¬ÎÒÃÇ¿ÉÒÔ¿´µ½£¬VERSIONSΪ1£¬Ò²¾ÍÊÇ˵£¬Ä¬ÈÏÇé¿öÖ»»á´æÈ¡Ò»¸ö°æ±¾µÄÁÐÊý¾Ý£¬µ±ÔٴβåÈëµÄʱºò£¬ºóÃæµÄÖµ»á¸²¸ÇÇ°ÃæµÄÖµ¡£
3¡¢Ð޸ıí½á¹¹£¬ÈÃHbase±íÖ§³Ö´æ´¢3¸öVERSIONSµÄ°æ±¾ÁÐÊý¾Ý
| alter 't1',{NAME=>'f1',VERSIONS=>3} |
Ð޸ĺó£¬shellÖÕ¶ËÏÔʾÈçÏ£º
Updating all
regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 2.5680 seconds |
Ôٴβ鿴±í½á¹¹£º
Table t1 is
ENABLED
t1
COLUMN FAMILIES DESCRIPTION
{NAME => 'f1', BLOOMFILTER => 'ROW', VERSIONS
=> '3', IN_MEMORY => 'false', KEEP_DELETED_CELLS
=> 'FALSE', DATA_BLOCK_ENCODING => 'NON
E', TTL => 'FOREVER', COMPRESSION => 'NONE',
MIN_VERSIONS => '0', BLOCKCACHE => 'true',
BLOCKSIZE => '65536', REPLICATION_SCOPE =>
'0'
}
1 row(s) in 0.0330 seconds |
ÎÒÃǻᷢÏÖVERSIONSÒѾÐ޸ijÉÁË3.
4¡¢²åÈë3ÐÐÊý¾Ý
hbase(main):015:0>
put 't1','rowkey1','f1:name','chhliu'
0 row(s) in 0.5890 seconds
hbase(main):016:0> put 't1','rowkey1','f1:name','xyh123'
0 row(s) in 0.1900 seconds
hbase(main):017:0> put 't1','rowkey1','f1:name','chhliuxyh'
0 row(s) in 0.1580 seconds
hbase(main):018:0> get 't1','rowkey1','f1:name'
COLUMN CELL
f1:name timestamp=1482820567560, value=chhliuxyh
1 row(s) in 0.2110 seconds |
´ÓÉÏÃæ¿ÉÒÔ¿´³ö£¬²åÈëÁË3ÐÐÊý¾Ýµ½±íÖУ¬²¢ÇÒ3ÐÐÊý¾ÝµÄrowkeyÒ»Ö£¬È»ºóʹÓÃgetÃüÁîÀ´»ñÈ¡ÕâÒ»ÐÐÊý¾Ý£¬·¢ÏÖÖ»·µ»ØÁË×îеÄÒ»ÐÐÊý¾Ý¡£
5¡¢»ñÈ¡¶àÐÐÊý¾Ý·½·¨
hbase(main):002:0>
get 't1','rowkey1',{COLUMN=>'f1:name',VERSIONS=>3}
COLUMN CELL
f1:name timestamp=1482820567560, value=chhliuxyh
f1:name timestamp=1482820541363, value=xyh123
f1:name timestamp=1482820503889, value=chhliu
3 row(s) in 0.0960 seconds |
´ÓÉÏÃæµÄ²âÊÔ½á¹ûÖУ¬¿ÉÒÔ¿´³ö£¬Ò»´ÎÐÔ»ñÈ¡ÁË3¸ö°æ±¾µÄÊý¾Ý¡£
¶þ¡¢spring data hadoop»ñÈ¡¶à°æ±¾ÐÅÏ¢
1¡¢·þÎñ·â×°ÈçÏ£º
public List<String>
get(final String tableName, final byte[] rowName,
final String familyName,
final String qualifier) {
return htemplate.execute(tableName, new TableCallback<List<String>>()
{
@Override
public List<String> doInTable(HTableInterface
table) throws Throwable {
Get get = new Get(rowName);
get.setMaxVersions(3); // ÉèÖÃÒ»´ÎÐÔ»ñÈ¡¶àÉÙ¸ö°æ±¾µÄÊý¾Ý
get.addColumn(familyName.getBytes(), qualifier.getBytes());
Result result = table.get(get);
List<Cell> cells = result.listCells();
String res = "";
List<String> list = new ArrayList<String>();
if(null != cells && !cells.isEmpty()){
for(Cell ce:cells){
res = Bytes.toString(ce.getValueArray(),
ce.getValueOffset(),
ce.getValueLength());
System.out.println("res:"+res+"
timestamp:"+ce.getTimestamp());
list.add(res);
}
}
return list;
}
});
} |
2¡¢²âÊÔ
List<String>
result = hService.get("t1", rowKey,
"f1", "name");
System.out.println("result:"+result);
res:chhliuxyh timestamp:1482820567560
res:xyh123 timestamp:1482820541363
res:chhliu timestamp:1482820503889 |
´ÓÉÏÃæµÄ²âÊÔ½á¹û¿ÉÒÔ¿´³ö£¬Í¬Ê±»ñÈ¡ÁË3¸ö°æ±¾µÄÁÐÐÅÏ¢
PS£ºspring data hadoopĬÈÏÌṩµÄ½Ó¿ÚÖУ¬ÊÇûÓÐÌṩһ´ÎÐÔ»ñÈ¡¶à¸ö°æ±¾µÄÁÐÐÅÏ¢µÄ½Ó¿ÚµÄ£¬ÐèÒªÎÒÃÇ×Ô¼ºÊ¹ÓÃHbaseÔÉúµÄAPI½øÐзâ×°¡£¾ßÌå·â×°·½·¨£¬ÈçÉÏ¡£ |