Skip to content

Instantly share code, notes, and snippets.

@winse
Last active December 3, 2015 08:30
Show Gist options
  • Save winse/438cbeffea11e5629d86 to your computer and use it in GitHub Desktop.
Save winse/438cbeffea11e5629d86 to your computer and use it in GitHub Desktop.
hbase命令行使用SingleColumnValueFilter(V0.96.0)
014-07-10 20:04:19,384 INFO LogHbaseService: 过滤的条件为: FilterList AND (2/2): [SingleColumnValueFilter (cf, logType, EQUAL, 3), KeyOnlyFilter]
2014-07-10 20:04:19,384 INFO LogHbaseService: Page FirstResult : 0
2014-07-10 20:04:19,385 INFO LogHbaseService: Page MaxResult : 100
2014-07-10 20:04:19,397 INFO LogHbaseService: 获取总数请求成功, 计算总数量...
2014-07-10 20:05:23,595 INFO LogHbaseService: 获取总数耗时: 64198, 数量: 557574
- - - -
2014-07-10 20:00:46,093 INFO LogHbaseService: 过滤的条件为: FilterList AND (2/2): [FirstKeyOnlyFilter, KeyOnlyFilter]
2014-07-10 20:00:46,093 INFO LogHbaseService: Page FirstResult : 0
2014-07-10 20:00:46,093 INFO LogHbaseService: Page MaxResult : 100
2014-07-10 20:00:46,460 INFO LogHbaseService: 获取总数请求成功, 计算总数量...
2014-07-10 20:01:00,203 INFO LogHbaseService: 获取总数耗时: 13743, 数量: 557574
- - - -
2014-07-10 20:15:11,311 INFO LogHbaseService: 过滤的条件为: FilterList AND (2/2): [SingleColumnValueFilter (cf, logType, EQUAL, 3), KeyOnlyFilter]
2014-07-10 20:15:11,311 INFO LogHbaseService: Page FirstResult : 0
2014-07-10 20:15:11,311 INFO LogHbaseService: Page MaxResult : 100
2014-07-10 20:15:11,333 INFO LogHbaseService: 获取总数请求成功, 计算总数量...
2014-07-10 20:34:33,104 INFO LogHbaseService: 获取总数耗时: 1161771, 数量: 2598526
- - - -
2014-07-10 20:52:27,108 INFO LogHbaseService: 过滤的条件为: FilterList AND (2/2): [FirstKeyOnlyFilter, KeyOnlyFilter]
2014-07-10 20:52:27,108 INFO LogHbaseService: Page FirstResult : 0
2014-07-10 20:52:27,108 INFO LogHbaseService: Page MaxResult : 100
2014-07-10 20:52:27,116 INFO LogHbaseService: 获取总数请求成功, 计算总数量...
2014-07-10 20:57:21,085 INFO LogHbaseService: 获取总数耗时: 293969, 数量: 5577980
2014-07-10 20:57:21,143 INFO LogHbaseService: 获取记录[0-100], 用时: 58
scan 't_ods_idc_isp_log2',{FILTER => "SingleColumnValueFilter('cf','commandld',=,'binary:141032279')", LIMIT => 1}

binary是比较的类型,还可以是binaryprefix,regexstring,substring一共四种。

调试命令

在hbase的shell脚本添加远程调试代码:

export HBASE_JRUBY_OPTS="$HBASE_JRUBY_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8074"
HBASE_OPTS="$HBASE_OPTS $HBASE_JRUBY_OPTS"
CLASS="org.jruby.Main -X+O ${JRUBY_OPTS} ${HBASE_HOME}/bin/hirb.rb"

然后一步步的查看hbase内部是如何简析的。

scan 'test',{FILTER => "SingleColumnValueFilter('cf','test',=,'binary:23')"}

其他有用的hbase shell查询

-- scan 't_ods_idc_isp_log2',{FILTER => "PrefixFilter('3|2014061212')", LIMIT => 5}
scan 't_ods_idc_isp_log2',{STARTROW => '3|2014061212', LIMIT => 5}
scan 't_ods_idc_isp_log2',{STARTROW => '3006583531|', FILTER => "FirstKeyOnlyFilter()" }

scan 't_ods_idc_isp_log2',{STARTROW => '3269959031|' , FILTER => "PrefixFilter('3269959031|') AND FirstKeyOnlyFilter()"}

参考

set HBASE_JRUBY_OPTS=%HBASE_JRUBY_OPTS% -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8074
set HBASE_OPTS=%HBASE_OPTS% %HBASE_JRUBY_OPTS%

  set CLASS=org.jruby.Main -X+O %JRUBY_OPTS% %HBASE_HOME%\bin\hirb.rb
hbase shell

hbase(main):006:0> create 't1', 'f1'

hbase(main):006:0> put "t1","rowid", "f1:q1","datavalue"

hbase(main):007:0> scan "t1"
ROW                   COLUMN+CELL

 rowid                column=f1:q1, timestamp=1404444230866, value=datavalue

scan 't1',{FILTER => "SingleColumnValueFilter('f1','q1',=,'binary:141032279')", LIMIT => 1}	

在filter.SingleColumnValueFilter#createFilterFromArguments打个断点,或者在filter.ParseFilter#parseSimpleFilterExpression。切记运行程序版本和源码的版本一定要对的上哦!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment