Hbase 检索成绩在80到90之间的同学姓名
给定一个student表,列族包含学生ID,姓名和成绩,检索成绩在80到90之间的同学姓名
create 'student','S_NO','S_NAME','S_SCORE'
put 'student','s001','S_NO','2022001'
put 'student','s001','S_NAME','小王'
put 'student','s001','S_SCORE','45'
put 'student','s002','S_NO','2022002'
put 'student','s002','S_NAME','小林'
put 'student','s002','S_SCORE','67'
put 'student','s003','S_NO','2022003'
put 'student','s003','S_NAME','小张'
put 'student','s003','S_SCORE','85'
put 'student','s004','S_NO','2022004'
put 'student','s004','S_NAME','小刘'
put 'student','s004','S_SCORE','95'
put 'student','s005','S_NO','2022005'
put 'student','s005','S_NAME','小李'
put 'student','s005','S_SCORE','61'
put 'student','s006','S_NO','2022006'
put 'student','s006','S_NAME','小冰'
put 'student','s006','S_SCORE','83'
put 'student','s007','S_NO','2022007'
put 'student','s007','S_NAME','小明'
put 'student','s007','S_SCORE','71'
put 'student','s008','S_NO','2022008'
put 'student','s008','S_NAME','小帅'
put 'student','s008','S_SCORE','88'
put 'student','s009','S_NO','2022009'
put 'student','s009','S_NAME','小东'
put 'student','s009','S_SCORE','09'
在 hbase 中,一般都转成字符串,然后再保存
类似 价格、年龄 这类数字,前面补
0
,转成定长的,再保存,这样便于过滤原因是Hbase的四种过滤器都是字符串比较,不能直接进行数字类型比较
-
BinaryComparator - lexicographically compares against the specified byte array using the Bytes.compareTo(byte[], byte[]) method.
-
BinaryPrefixComparator - lexicographically compares against a specified byte array. It only compares up to the length of this byte array.
-
RegexStringComparator - compares against the specified byte array using the given regular expression. Only EQUAL and NOT_EQUAL comparisons are valid with this comparator.
-
SubStringComparator - tests whether or not the given substring appears in a specified byte array. The comparison is case insensitive. Only EQUAL and NOT_EQUAL comparisons are valid with this comparator.
scan 'student',FILTER => "SingleColumnValueFilter('S_SCORE', '', >=, 'binary:80') AND SingleColumnValueFilter('S_SCORE','',<=,'binary:90')",FORMATTER=>'toString'
toString用于将shell返回结果的人名从UTF-8编码显示为正常的字符串。
hbase(main):038:0> scan 'student',FILTER => "SingleColumnValueFilter('S_SCORE', '', >=, 'binary:80') AND SingleColumnValueFilter('S_SCORE','',<=,'binary:90')",FORMATTER=>'toString'
ROW COLUMN+CELL
s003 column=S_NAME:, timestamp=1681065615165, value=小张
s003 column=S_NO:, timestamp=1681065615130, value=2022003
s003 column=S_SCORE:, timestamp=1681065615198, value=85
s006 column=S_NAME:, timestamp=1681065615575, value=小冰
s006 column=S_NO:, timestamp=1681065615542, value=2022006
s006 column=S_SCORE:, timestamp=1681065615611, value=83
s008 column=S_NAME:, timestamp=1681065615804, value=小帅
s008 column=S_NO:, timestamp=1681065615773, value=2022008
s008 column=S_SCORE:, timestamp=1681065615847, value=88
资料
https://docs.cloudera.com/documentation/enterprise/6/6.3/topics/admin_hbase_filtering.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2022-04-10 Python 国家地震台网 地震数据集完整分析、pyecharts、plotly,分析强震次数、震级分布、震级震源关系、发生位置、发生时段、最大震级、平均震级