1. 程式人生 > 實用技巧 >HBase shell查詢指定範圍行鍵

HBase shell查詢指定範圍行鍵

最簡單的方法就用SCAN加引數STARTROW和ENDROW

hbase(main):024:0> scan 'score',{STARTROW=>'0005',ENDROW=>'0008'}

輸出結果:

ROW COLUMN+CELL
0005 column=course:Operating System, time
0005 column=grade:order2, timestamp=98, v
0006 column=course:math, timestamp=160533
0006 column=grade:order3, timestamp=16053
0007 column=course:math, timestamp=160533
0007 column=grade:order4, timestamp=92, v
3 row(s) in 0.0330 seconds

或者引數和過濾器混用

hbase(main):021:0> scan 'score',{STARTROW=>'0005',FILTER=>"RowFilter(<=,'binary:0007')"}

輸出結果:

ROW COLUMN+CELL
0005 column=course:Operating System, timestamp=1605339202987, value=91
0005 column=grade:order2, timestamp=98, value=course:math
0006 column=course:math, timestamp=1605339211226, value=95
0006 column=grade:order3, timestamp=1605339603983, value=No.4
0007 column=course:math, timestamp=1605339216074, value=92
0007 column=grade:order4, timestamp=92, value=course:Java
3 row(s) in 0.0430 seconds

hbase(main):022:0> scan 'score',{ENDROW=>'0008',FILTER=>"RowFilter(>=,'binary:0005')"}

輸出結果:
ROW COLUMN+CELL
0005 column=course:Operating System, timestamp=1605339202987, value=91
0005 column=grade:order2, timestamp=98, value=course:math
0006 column=course:math, timestamp=1605339211226, value=95
0006 column=grade:order3, timestamp=1605339603983, value=No.4
0007 column=course:math, timestamp=1605339216074, value=92
0007 column=grade:order4, timestamp=92, value=course:Java
3 row(s) in 0.0430 seconds

兩個過濾器的話無法實現,會單執行後面的過濾器

測試輸入:

hbase(main):023:0> scan 'score',{FILTER=>"RowFilter(>=,'binary:0005')",FILTER=>"RowFilter(<=,'binary:0007')"}

輸出結果:
ROW COLUMN+CELL
0001 column=course:math, timestamp=1605339168973, value=99
0001 column=grade:order1, timestamp=99, value=course:math
00010 column=course:Java, timestamp=1605339236065, value=97
0002 column=course:english, timestamp=160
0002 column=grade:order1, timestamp=96, v
0003 column=course:english, timestamp=160
0003 column=grade:order1, timestamp=93, v
0004 column=course:Java, timestamp=160533
0004 column=course:math, timestamp=160533
0004 column=grade:order1, timestamp=95, v
0005 column=course:Operating System, time
0005 column=grade:order2, timestamp=98, v
0006 column=course:math, timestamp=160533
0006 column=grade:order3, timestamp=16053
0007 column=course:math, timestamp=160533
0007 column=grade:order4, timestamp=92, v
8 row(s) in 0.0280 seconds