網(wǎng)站首頁 編程語言 正文
文章目錄
- 源碼
- KeyValue結(jié)構(gòu)
- KeyValue的實(shí)現(xiàn)
- 操作KeyValue
源碼
- 源碼注釋部分翻譯
HBase 鍵值。這是基本的 HBase 類型。
KeyValue 包裝一個(gè)字節(jié)數(shù)組,并將偏移量和長度放入傳遞的數(shù)組中,從哪里開始將內(nèi)容解釋為 KeyValue。
字節(jié)數(shù)組中的 KeyValue 格式為: <keylength> <valuelength> <key> <value>
Key 進(jìn)一步分解為: <rowlength> <row> <columnfamilylength> <columnfamily> <columnqualifier> <timestamp> <keytype>
行長最大值為 Short.MAX_SIZE,
列族長度最大值為 Byte.MAX_SIZE,
列限定符 + 鍵長度必須 < Integer.MAX_SIZE。
該列不包含 familyqualifier 分隔符 COLUMN_FAMILY_DELIMITER
KeyValue結(jié)構(gòu)
- 在KeyValue中,其中的KeyLength為4B:
- ValueLength標(biāo)識(shí)Value在字節(jié)數(shù)組中所占的長度,為4B:
- Row Length:存儲(chǔ)rowkey的長度,為2B
- TimeStamp是Long型,肯定就是占8B:
- KeyType為1B:
從ColumnQualifier開始內(nèi)容前面不在帶有長度了。TimeStamp和KeyType因?yàn)樗嫉拈L度是固定的,所以不用包含長度信息。而Qualifier的長度信息,則用以下的方式可以得出:
new Ordering[(ImmutableBytesWritable, KeyValue)] {
override def compare(x: (ImmutableBytesWritable, KeyValue), y: (ImmutableBytesWritable, KeyValue)): Int = {
x._2.getFamilyLength()
x._2.getQualifierLength
}
}
KeyValue的實(shí)現(xiàn)
在Hbase中,所有數(shù)據(jù)都是以Byte的形式存在的。在KeyValue中,使用的是byte數(shù)組來存儲(chǔ)實(shí)際內(nèi)容。
// KeyValue core instance fields.
private byte [] bytes = null; // an immutable byte array that contains the KV
private int offset = 0; // offset into bytes buffer KV starts at
private int length = 0; // length of the KV starting from offset.
其中,bytes數(shù)組用來存儲(chǔ)KeyValue中的實(shí)際內(nèi)容,offset表示KeyValue在數(shù)組bytes中的起始位置
,length則是KeyValue在數(shù)組bytes中自起始位置offset后的長度
。
KeyValue提供了一系列的Offset方法在數(shù)組中定位各個(gè)字段的的起始位置,如getValueOffset,getRowOffset等。也提供了一系列的length方法來獲取KeyValue中各個(gè)字段的大小。
操作KeyValue
把keyValue 數(shù)據(jù)取出放到Map里
Map<String, Object> stringMap = new HashMap<>();
stringMap.put("row", Bytes.toStringBinary(getRowArray(), getRowOffset(), getRowLength()));
stringMap.put("family",Bytes.toStringBinary(getFamilyArray(), getFamilyOffset(), getFamilyLength()));
stringMap.put("qualifier",Bytes.toStringBinary(getQualifierArray(), getQualifierOffset(), getQualifierLength()));
stringMap.put("timestamp", getTimestamp());
stringMap.put("vlen", getValueLength());
Iterator<Tag> tags = getTags();
if (tags != null) {
List<String> tagsString = new ArrayList<String>();
while (tags.hasNext()) {
tagsString.add(tags.next().toString());
}
stringMap.put("tag", tagsString);
}
原文鏈接:https://blog.csdn.net/Lzx116/article/details/126609986
相關(guān)推薦
- 2022-04-18 python?request?post?列表的方法詳解_python
- 2023-03-15 Docker網(wǎng)絡(luò)配置及部署SpringCloud項(xiàng)目詳解_docker
- 2022-09-06 Minio設(shè)置文件鏈接永久有效的完整步驟_其它綜合
- 2022-07-01 淺談C語言中的sizeof()和strlen()的區(qū)別_C 語言
- 2022-06-01 如何寫好?Python?的?Lambda?函數(shù)_python
- 2022-10-04 混合棧跳轉(zhuǎn)導(dǎo)致Flutter頁面事件卡死問題解決_IOS
- 2023-10-16 elementUI日期選擇器快速選擇 快捷選擇(本周、上周、本月、上月、季度等)
- 2022-11-23 Python?copy()與deepcopy()方法之間有什么區(qū)別_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支