Hbase 查询命令 条件筛选
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                Hbase 查询命令 条件筛选
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                Hbase 查詢命令 條件篩選
方便測試
建一下表
hbase(main):001:0> create 'student','c1'不寫namespace的話就是默認在default里
查詢有哪些namespace
hbase(main):001:0> list_namespace查看表的全量數據
hbase(main):002:0> scan 'default:student'放入一些測試數據
put 'student','1001','c1:id','1001' put 'student','1002','c1:id','1002' put 'student','1003','c1:id','1003' put 'student','1004','c1:id','1004' put 'student','1005','c1:id','1005'只查詢一行
hbase(main):025:0> scan 'student',LIMIT=>1 ROW COLUMN+CELL1001 column=c1:id, timestamp=1658911986336, value=1001查詢表的總記錄數
count 'student'按寫入的時間戳查詢數據
scan 'student', {COLUMN => 'c1', TIMERANGE => [1658827317000,1658913717000]}查詢值為1002的記錄
hbase(main):004:0> scan 'student',FILTER=>"ValueFilter(=,'binary:1002')" ROW COLUMN+CELL1002 column=c1:id, timestamp=1658911989184, value=1002 1 row(s) in 0.1060 seconds查詢c1:id列的值為1002的
hbase(main):006:0> scan 'student',COLUMNS => 'c1:id',FILTER=>"ValueFilter(=,'binary:1002')" ROW COLUMN+CELL1002 column=c1:id, timestamp=1658911989184, value=1002 1 row(s) in 0.0340 seconds查詢值包含100的記錄,就跟sql的模糊匹配一樣
hbase(main):007:0> scan 'student',FILTER=>"ValueFilter(=,'substring:100')" ROW COLUMN+CELL1001 column=c1:id, timestamp=1658911986336, value=10011002 column=c1:id, timestamp=1658911989184, value=10021003 column=c1:id, timestamp=1658911989217, value=10031004 column=c1:id, timestamp=1658911989243, value=10041005 column=c1:id, timestamp=1658911989788, value=1005 5 row(s) in 0.0470 seconds為了方便列的其他查詢,多放入一個列
put 'student','1001','c1:sex','1' put 'student','1002','c1:sex','2' put 'student','1003','c1:sex','1' put 'student','1004','c1:sex','2' put 'student','1005','c1:sex','1'hbase(main):015:0* scan 'student' ROW COLUMN+CELL1001 column=c1:id, timestamp=1658911986336, value=10011001 column=c1:sex, timestamp=1658914149713, value=11002 column=c1:id, timestamp=1658911989184, value=10021002 column=c1:sex, timestamp=1658914152500, value=21003 column=c1:id, timestamp=1658911989217, value=10031003 column=c1:sex, timestamp=1658914152535, value=11004 column=c1:id, timestamp=1658911989243, value=10041004 column=c1:sex, timestamp=1658914152563, value=21005 column=c1:id, timestamp=1658911989788, value=10051005 column=c1:sex, timestamp=1658914153242, value=1 5 row(s) in 0.0390 seconds查詢列為id打頭的值
hbase(main):019:0> scan 'student',FILTER=>"ColumnPrefixFilter('id')" ROW COLUMN+CELL1001 column=c1:id, timestamp=1658911986336, value=10011002 column=c1:id, timestamp=1658911989184, value=10021003 column=c1:id, timestamp=1658911989217, value=10031004 column=c1:id, timestamp=1658911989243, value=10041005 column=c1:id, timestamp=1658911989788, value=1005 5 row(s) in 0.0270 seconds各項查詢的條件是可以疊加的,比如下面這個
查詢列為id打頭且值為1003的
hbase(main):020:0> scan 'student',FILTER=>"ColumnPrefixFilter('id') AND ValueFilter(=,'binary:1003')" ROW COLUMN+CELL1003 column=c1:id, timestamp=1658911989217, value=1003 1 row(s) in 0.0550 seconds查詢rowkey為100打頭的
hbase(main):021:0> scan 'student',FILTER=>"PrefixFilter('100')" ROW COLUMN+CELL1001 column=c1:id, timestamp=1658911986336, value=10011001 column=c1:sex, timestamp=1658914149713, value=11002 column=c1:id, timestamp=1658911989184, value=10021002 column=c1:sex, timestamp=1658914152500, value=21003 column=c1:id, timestamp=1658911989217, value=10031003 column=c1:sex, timestamp=1658914152535, value=11004 column=c1:id, timestamp=1658911989243, value=10041004 column=c1:sex, timestamp=1658914152563, value=21005 column=c1:id, timestamp=1658911989788, value=10051005 column=c1:sex, timestamp=1658914153242, value=1查詢rowkey為100打頭的且不同返回列信息
hbase(main):022:0> scan 'student',FILTER=>"PrefixFilter('100') AND KeyOnlyFilter()" ROW COLUMN+CELL1001 column=c1:id, timestamp=1658911986336, value=1001 column=c1:sex, timestamp=1658914149713, value=1002 column=c1:id, timestamp=1658911989184, value=1002 column=c1:sex, timestamp=1658914152500, value=1003 column=c1:id, timestamp=1658911989217, value=1003 column=c1:sex, timestamp=1658914152535, value=1004 column=c1:id, timestamp=1658911989243, value=1004 column=c1:sex, timestamp=1658914152563, value=1005 column=c1:id, timestamp=1658911989788, value=1005 column=c1:sex, timestamp=1658914153242, value= 5 row(s) in 0.0670 seconds從特定行開始查三行
hbase(main):006:0> scan 'student',{STARTROW=>'1002',LIMIT=>3} ROW COLUMN+CELL1002 column=c1:id, timestamp=1658911989184, value=10021002 column=c1:sex, timestamp=1658914152500, value=21003 column=c1:id, timestamp=1658911989217, value=10031003 column=c1:sex, timestamp=1658914152535, value=11004 column=c1:id, timestamp=1658911989243, value=10041004 column=c1:sex, timestamp=1658914152563, value=2 3 row(s) in 0.0300 seconds獲取特定的行
hbase(main):007:0> get 'student','1001' COLUMN CELLc1:id timestamp=1658911986336, value=1001c1:sex timestamp=1658914149713, value=1 2 row(s) in 0.0170 seconds默認的查詢是正序,倒敘使用REVERSED => TRUE
scan 'student',{REVERSED => TRUE,LIMIT=>1}以上這些命令基本滿足大部分的查詢需求了
總結
以上是生活随笔為你收集整理的Hbase 查询命令 条件筛选的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: linux可执行文件的后缀是什么?
 - 下一篇: 宝塔linux 屏蔽ip,宝塔屏蔽国外I