HBase 关于Versions以及TimeStamp操作,hbasetimestamp
HBase 关于Versions以及TimeStamp操作总结。
说明
hbase在建表的时候,一个列族可以指定一个versions,用以表示所存数据的版本数,默认该值为3,即保存最近的3个版本的数据。在每一个cell中有同一数据的多个版本,按时间倒序排序。我们可以在建表的时候指定versions,在放数据的时候以一个时间戳(一个long值)来表示该数据的版本号。取数据时可以取最新的数据,也可以取特定时间戳的数据,某段时间戳的数据以及全部数据。下面将分别给出实示例说明。
示例及解释
val conf = hBaseConfig.get
val connection = ConnectionFactory.createConnection(conf)
val admin = connection.getAdmin
val tableNameObj = TableName.valueOf("hbaseTest")
val hTableDescriptor = new HTableDescriptor(tableNameObj)
val hColumnDescriptor = new HColumnDescriptor(Bytes.toBytes("testFamily"))
hColumnDescriptor.setMaxVersions(Int.MaxValue)
hTableDescriptor.addFamily(hColumnDescriptor)
admin.createTable(hTableDescriptor)
val put=new Put(Bytes.toBytes("row"))
for(i<-0 to 100){
put.addColumn(familyBytes,Bytes.toBytes("q1"),i.toLong,Bytes.toBytes(i+"data_2"))
}
for(i<-0 to 200){
put.addColumn(familyBytes,Bytes.toBytes("q2"),i.toLong,Bytes.toBytes(i+"data2"))
}
table.put(put)
其他问题说明:
val cell: Cell =result.listCells().get(0)
System.out.println("RowName:"+new String(CellUtil.cloneRow(cell))+" ")
System.out.println("Timetamp:"+cell.getTimestamp()+" ")
System.out.println("column Family:"+new String(CellUtil.cloneFamily(cell))+" ")
System.out.println("row Name:"+new String(CellUtil.cloneQualifier(cell))+" ")
System.out.println("value:"+new String(CellUtil.cloneValue(cell))+" ")
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。