hbase RowFilter如何根据rowkey查询以及实例实现代码 habase模糊查询【转】

时间:2021-07-18 00:17:05
RowFilter用于过滤row key
Operator Description
LESS 小于
LESS_OR_EQUAL 小于等于
[EQUAL 等于
NOT_EQUAL 不等于
GREATER_OR_EQUAL 大于等于
GREATER 大于
NO_OP 排除所有
Comparator Description
BinaryComparator 使用Bytes.compareTo()比较
BinaryPrefixComparator 和BinaryComparator差不多,从前面开始比较
NullComparator Does not compare against an actual value but whether a given one is null, or not  null.
BitComparator Performs a bitwise comparison, providing a BitwiseOp class with OR, and XORoperators.
RegexStringComparator 正则表达式
SubstringComparator 把数据当成字符串,用contains()来判断
  1. import java.io.IOException;
  2. import org.apache.hadoop.conf.Configuration;
  3. import org.apache.hadoop.hbase.HBaseConfiguration;
  4. import org.apache.hadoop.hbase.HColumnDescriptor;
  5. import org.apache.hadoop.hbase.HTableDescriptor;
  6. import org.apache.hadoop.hbase.client.HBaseAdmin;
  7. import org.apache.hadoop.hbase.client.HTable;
  8. import org.apache.hadoop.hbase.client.Put;
  9. import org.apache.hadoop.hbase.client.Result;
  10. import org.apache.hadoop.hbase.client.ResultScanner;
  11. import org.apache.hadoop.hbase.client.Scan;
  12. import org.apache.hadoop.hbase.filter.BinaryComparator;
  13. import org.apache.hadoop.hbase.filter.BinaryPrefixComparator;
  14. import org.apache.hadoop.hbase.filter.CompareFilter;
  15. import org.apache.hadoop.hbase.filter.Filter;
  16. import org.apache.hadoop.hbase.filter.RegexStringComparator;
  17. import org.apache.hadoop.hbase.filter.RowFilter;
  18. import org.apache.hadoop.hbase.filter.SubstringComparator;
  19. public class TestHbaseRowFilter {
  20. String tableName = "test_row_filter";
  21. Configuration config = HBaseConfiguration.create();
  22. /**
  23. * 部分代码来自hbase权威指南
  24. * @throws IOException
  25. */
  26. public void testRowFilter() throws IOException {
  27. HTable table = new HTable(config, tableName);
  28. Scan scan = new Scan();
  29. System.out.println("小于等于row010的行");
  30. Filter filter1 = new RowFilter(CompareFilter.CompareOp.LESS_OR_EQUAL,
  31. new BinaryComparator("row010".getBytes()));
  32. scan.setFilter(filter1);
  33. ResultScanner scanner1 = table.getScanner(scan);
  34. for (Result res : scanner1) {
  35. System.out.println(res);
  36. }
  37. scanner1.close();
  38. System.out.println("正则获取结尾为5的行");
  39. Filter filter2 = new RowFilter(CompareFilter.CompareOp.EQUAL,
  40. new RegexStringComparator(".*5[        DISCUZ_CODE_0        ]quot;));
  41. scan.setFilter(filter2);
  42. ResultScanner scanner2 = table.getScanner(scan);
  43. for (Result res : scanner2) {
  44. System.out.println(res);
  45. }
  46. scanner2.close();
  47. System.out.println("包含有5的行");
  48. Filter filter3 = new RowFilter(CompareFilter.CompareOp.EQUAL,
  49. new SubstringComparator("5"));
  50. scan.setFilter(filter3);
  51. ResultScanner scanner3 = table.getScanner(scan);
  52. for (Result res : scanner3) {
  53. System.out.println(res);
  54. }
  55. scanner3.close();
  56. System.out.println("开头是row01的");
  57. Filter filter4 = new RowFilter(CompareFilter.CompareOp.EQUAL,
  58. new BinaryPrefixComparator("row01".getBytes()));
  59. scan.setFilter(filter4);
  60. ResultScanner scanner4 = table.getScanner(scan);
  61. for (Result res : scanner4) {
  62. System.out.println(res);
  63. }
  64. scanner3.close();
  65. }
  66. /**
  67. * 初始化数据
  68. */
  69. public void init() {
  70. // 创建表和初始化数据
  71. try {
  72. HBaseAdmin admin = new HBaseAdmin(config);
  73. if (!admin.tableExists(tableName)) {
  74. HTableDescriptor htd = new HTableDescriptor(tableName);
  75. HColumnDescriptor hcd1 = new HColumnDescriptor("data");
  76. htd.addFamily(hcd1);
  77. HColumnDescriptor hcd2 = new HColumnDescriptor("url");
  78. htd.addFamily(hcd2);
  79. admin.createTable(htd);
  80. }
  81. HTable table = new HTable(config, tableName);
  82. table.setAutoFlush(false);
  83. int count = 50;
  84. for (int i = 1; i <= count; ++i) {
  85. Put p = new Put(String.format("row%03d", i).getBytes());
  86. p.add("data".getBytes(), String.format("col%01d", i % 10)
  87. .getBytes(), String.format("data%03d", i).getBytes());
  88. p.add("url".getBytes(), String.format("col%01d", i % 10)
  89. .getBytes(), String.format("url%03d", i).getBytes());
  90. table.put(p);
  91. }
  92. table.close();
  93. } catch (IOException e) {
  94. e.printStackTrace();
  95. }
  96. }
  97. /**
  98. * @param args
  99. * @throws IOException
  100. */
  101. public static void main(String[] args) throws IOException {
  102. TestHbaseRowFilter test = new TestHbaseRowFilter();
  103. test.init();
  104. test.testRowFilter();
  105. }
  106. }

复制代码

输出结果
  1. 小于等于row010的行
  2. keyvalues={row001/data:col1/1364133382268/Put/vlen=7, row001/url:col1/1364133382268/Put/vlen=6}
  3. keyvalues={row002/data:col2/1364133382268/Put/vlen=7, row002/url:col2/1364133382268/Put/vlen=6}
  4. keyvalues={row003/data:col3/1364133382268/Put/vlen=7, row003/url:col3/1364133382268/Put/vlen=6}
  5. keyvalues={row004/data:col4/1364133382268/Put/vlen=7, row004/url:col4/1364133382268/Put/vlen=6}
  6. keyvalues={row005/data:col5/1364133382268/Put/vlen=7, row005/url:col5/1364133382268/Put/vlen=6}
  7. keyvalues={row006/data:col6/1364133382268/Put/vlen=7, row006/url:col6/1364133382268/Put/vlen=6}
  8. keyvalues={row007/data:col7/1364133382268/Put/vlen=7, row007/url:col7/1364133382268/Put/vlen=6}
  9. keyvalues={row008/data:col8/1364133382268/Put/vlen=7, row008/url:col8/1364133382268/Put/vlen=6}
  10. keyvalues={row009/data:col9/1364133382268/Put/vlen=7, row009/url:col9/1364133382268/Put/vlen=6}
  11. keyvalues={row010/data:col0/1364133382268/Put/vlen=7, row010/url:col0/1364133382268/Put/vlen=6}
  12. 正则获取结尾为5的行
  13. keyvalues={row005/data:col5/1364133382268/Put/vlen=7, row005/url:col5/1364133382268/Put/vlen=6}
  14. keyvalues={row015/data:col5/1364133382268/Put/vlen=7, row015/url:col5/1364133382268/Put/vlen=6}
  15. keyvalues={row025/data:col5/1364133382268/Put/vlen=7, row025/url:col5/1364133382268/Put/vlen=6}
  16. keyvalues={row035/data:col5/1364133382268/Put/vlen=7, row035/url:col5/1364133382268/Put/vlen=6}
  17. keyvalues={row045/data:col5/1364133382268/Put/vlen=7, row045/url:col5/1364133382268/Put/vlen=6}
  18. 包行有5的行
  19. keyvalues={row005/data:col5/1364133382268/Put/vlen=7, row005/url:col5/1364133382268/Put/vlen=6}
  20. keyvalues={row015/data:col5/1364133382268/Put/vlen=7, row015/url:col5/1364133382268/Put/vlen=6}
  21. keyvalues={row025/data:col5/1364133382268/Put/vlen=7, row025/url:col5/1364133382268/Put/vlen=6}
  22. keyvalues={row035/data:col5/1364133382268/Put/vlen=7, row035/url:col5/1364133382268/Put/vlen=6}
  23. keyvalues={row045/data:col5/1364133382268/Put/vlen=7, row045/url:col5/1364133382268/Put/vlen=6}
  24. keyvalues={row050/data:col0/1364133382268/Put/vlen=7, row050/url:col0/1364133382268/Put/vlen=6}
  25. 开头是row01的
  26. keyvalues={row010/data:col0/1364133382268/Put/vlen=7, row010/url:col0/1364133382268/Put/vlen=6}
  27. keyvalues={row011/data:col1/1364133382268/Put/vlen=7, row011/url:col1/1364133382268/Put/vlen=6}
  28. keyvalues={row012/data:col2/1364133382268/Put/vlen=7, row012/url:col2/1364133382268/Put/vlen=6}
  29. keyvalues={row013/data:col3/1364133382268/Put/vlen=7, row013/url:col3/1364133382268/Put/vlen=6}
  30. keyvalues={row014/data:col4/1364133382268/Put/vlen=7, row014/url:col4/1364133382268/Put/vlen=6}
  31. keyvalues={row015/data:col5/1364133382268/Put/vlen=7, row015/url:col5/1364133382268/Put/vlen=6}
  32. keyvalues={row016/data:col6/1364133382268/Put/vlen=7, row016/url:col6/1364133382268/Put/vlen=6}
  33. keyvalues={row017/data:col7/1364133382268/Put/vlen=7, row017/url:col7/1364133382268/Put/vlen=6}
  34. keyvalues={row018/data:col8/1364133382268/Put/vlen=7, row018/url:col8/1364133382268/Put/vlen=6}
  35. keyvalues={row019/data:col9/1364133382268/Put/vlen=7, row019/url:col9/1364133382268/Put/vlen=6}

复制代码

 
 
 
RowFilter用于过滤row key
Operator Description
LESS 小于
LESS_OR_EQUAL 小于等于
[EQUAL 等于
NOT_EQUAL 不等于
GREATER_OR_EQUAL 大于等于
GREATER 大于
NO_OP 排除所有
Comparator Description
BinaryComparator 使用Bytes.compareTo()比较
BinaryPrefixComparator 和BinaryComparator差不多,从前面开始比较
NullComparator Does not compare against an actual value but whether a given one is null, or not  null.
BitComparator Performs a bitwise comparison, providing a BitwiseOp class with OR, and XORoperators.
RegexStringComparator 正则表达式
SubstringComparator 把数据当成字符串,用contains()来判断
  1. import java.io.IOException;
  2. import org.apache.hadoop.conf.Configuration;
  3. import org.apache.hadoop.hbase.HBaseConfiguration;
  4. import org.apache.hadoop.hbase.HColumnDescriptor;
  5. import org.apache.hadoop.hbase.HTableDescriptor;
  6. import org.apache.hadoop.hbase.client.HBaseAdmin;
  7. import org.apache.hadoop.hbase.client.HTable;
  8. import org.apache.hadoop.hbase.client.Put;
  9. import org.apache.hadoop.hbase.client.Result;
  10. import org.apache.hadoop.hbase.client.ResultScanner;
  11. import org.apache.hadoop.hbase.client.Scan;
  12. import org.apache.hadoop.hbase.filter.BinaryComparator;
  13. import org.apache.hadoop.hbase.filter.BinaryPrefixComparator;
  14. import org.apache.hadoop.hbase.filter.CompareFilter;
  15. import org.apache.hadoop.hbase.filter.Filter;
  16. import org.apache.hadoop.hbase.filter.RegexStringComparator;
  17. import org.apache.hadoop.hbase.filter.RowFilter;
  18. import org.apache.hadoop.hbase.filter.SubstringComparator;
  19. public class TestHbaseRowFilter {
  20. String tableName = "test_row_filter";
  21. Configuration config = HBaseConfiguration.create();
  22. /**
  23. * 部分代码来自hbase权威指南
  24. * @throws IOException
  25. */
  26. public void testRowFilter() throws IOException {
  27. HTable table = new HTable(config, tableName);
  28. Scan scan = new Scan();
  29. System.out.println("小于等于row010的行");
  30. Filter filter1 = new RowFilter(CompareFilter.CompareOp.LESS_OR_EQUAL,
  31. new BinaryComparator("row010".getBytes()));
  32. scan.setFilter(filter1);
  33. ResultScanner scanner1 = table.getScanner(scan);
  34. for (Result res : scanner1) {
  35. System.out.println(res);
  36. }
  37. scanner1.close();
  38. System.out.println("正则获取结尾为5的行");
  39. Filter filter2 = new RowFilter(CompareFilter.CompareOp.EQUAL,
  40. new RegexStringComparator(".*5[        DISCUZ_CODE_0        ]quot;));
  41. scan.setFilter(filter2);
  42. ResultScanner scanner2 = table.getScanner(scan);
  43. for (Result res : scanner2) {
  44. System.out.println(res);
  45. }
  46. scanner2.close();
  47. System.out.println("包含有5的行");
  48. Filter filter3 = new RowFilter(CompareFilter.CompareOp.EQUAL,
  49. new SubstringComparator("5"));
  50. scan.setFilter(filter3);
  51. ResultScanner scanner3 = table.getScanner(scan);
  52. for (Result res : scanner3) {
  53. System.out.println(res);
  54. }
  55. scanner3.close();
  56. System.out.println("开头是row01的");
  57. Filter filter4 = new RowFilter(CompareFilter.CompareOp.EQUAL,
  58. new BinaryPrefixComparator("row01".getBytes()));
  59. scan.setFilter(filter4);
  60. ResultScanner scanner4 = table.getScanner(scan);
  61. for (Result res : scanner4) {
  62. System.out.println(res);
  63. }
  64. scanner3.close();
  65. }
  66. /**
  67. * 初始化数据
  68. */
  69. public void init() {
  70. // 创建表和初始化数据
  71. try {
  72. HBaseAdmin admin = new HBaseAdmin(config);
  73. if (!admin.tableExists(tableName)) {
  74. HTableDescriptor htd = new HTableDescriptor(tableName);
  75. HColumnDescriptor hcd1 = new HColumnDescriptor("data");
  76. htd.addFamily(hcd1);
  77. HColumnDescriptor hcd2 = new HColumnDescriptor("url");
  78. htd.addFamily(hcd2);
  79. admin.createTable(htd);
  80. }
  81. HTable table = new HTable(config, tableName);
  82. table.setAutoFlush(false);
  83. int count = 50;
  84. for (int i = 1; i <= count; ++i) {
  85. Put p = new Put(String.format("row%03d", i).getBytes());
  86. p.add("data".getBytes(), String.format("col%01d", i % 10)
  87. .getBytes(), String.format("data%03d", i).getBytes());
  88. p.add("url".getBytes(), String.format("col%01d", i % 10)
  89. .getBytes(), String.format("url%03d", i).getBytes());
  90. table.put(p);
  91. }
  92. table.close();
  93. } catch (IOException e) {
  94. e.printStackTrace();
  95. }
  96. }
  97. /**
  98. * @param args
  99. * @throws IOException
  100. */
  101. public static void main(String[] args) throws IOException {
  102. TestHbaseRowFilter test = new TestHbaseRowFilter();
  103. test.init();
  104. test.testRowFilter();
  105. }
  106. }

复制代码

输出结果
  1. 小于等于row010的行
  2. keyvalues={row001/data:col1/1364133382268/Put/vlen=7, row001/url:col1/1364133382268/Put/vlen=6}
  3. keyvalues={row002/data:col2/1364133382268/Put/vlen=7, row002/url:col2/1364133382268/Put/vlen=6}
  4. keyvalues={row003/data:col3/1364133382268/Put/vlen=7, row003/url:col3/1364133382268/Put/vlen=6}
  5. keyvalues={row004/data:col4/1364133382268/Put/vlen=7, row004/url:col4/1364133382268/Put/vlen=6}
  6. keyvalues={row005/data:col5/1364133382268/Put/vlen=7, row005/url:col5/1364133382268/Put/vlen=6}
  7. keyvalues={row006/data:col6/1364133382268/Put/vlen=7, row006/url:col6/1364133382268/Put/vlen=6}
  8. keyvalues={row007/data:col7/1364133382268/Put/vlen=7, row007/url:col7/1364133382268/Put/vlen=6}
  9. keyvalues={row008/data:col8/1364133382268/Put/vlen=7, row008/url:col8/1364133382268/Put/vlen=6}
  10. keyvalues={row009/data:col9/1364133382268/Put/vlen=7, row009/url:col9/1364133382268/Put/vlen=6}
  11. keyvalues={row010/data:col0/1364133382268/Put/vlen=7, row010/url:col0/1364133382268/Put/vlen=6}
  12. 正则获取结尾为5的行
  13. keyvalues={row005/data:col5/1364133382268/Put/vlen=7, row005/url:col5/1364133382268/Put/vlen=6}
  14. keyvalues={row015/data:col5/1364133382268/Put/vlen=7, row015/url:col5/1364133382268/Put/vlen=6}
  15. keyvalues={row025/data:col5/1364133382268/Put/vlen=7, row025/url:col5/1364133382268/Put/vlen=6}
  16. keyvalues={row035/data:col5/1364133382268/Put/vlen=7, row035/url:col5/1364133382268/Put/vlen=6}
  17. keyvalues={row045/data:col5/1364133382268/Put/vlen=7, row045/url:col5/1364133382268/Put/vlen=6}
  18. 包行有5的行
  19. keyvalues={row005/data:col5/1364133382268/Put/vlen=7, row005/url:col5/1364133382268/Put/vlen=6}
  20. keyvalues={row015/data:col5/1364133382268/Put/vlen=7, row015/url:col5/1364133382268/Put/vlen=6}
  21. keyvalues={row025/data:col5/1364133382268/Put/vlen=7, row025/url:col5/1364133382268/Put/vlen=6}
  22. keyvalues={row035/data:col5/1364133382268/Put/vlen=7, row035/url:col5/1364133382268/Put/vlen=6}
  23. keyvalues={row045/data:col5/1364133382268/Put/vlen=7, row045/url:col5/1364133382268/Put/vlen=6}
  24. keyvalues={row050/data:col0/1364133382268/Put/vlen=7, row050/url:col0/1364133382268/Put/vlen=6}
  25. 开头是row01的
  26. keyvalues={row010/data:col0/1364133382268/Put/vlen=7, row010/url:col0/1364133382268/Put/vlen=6}
  27. keyvalues={row011/data:col1/1364133382268/Put/vlen=7, row011/url:col1/1364133382268/Put/vlen=6}
  28. keyvalues={row012/data:col2/1364133382268/Put/vlen=7, row012/url:col2/1364133382268/Put/vlen=6}
  29. keyvalues={row013/data:col3/1364133382268/Put/vlen=7, row013/url:col3/1364133382268/Put/vlen=6}
  30. keyvalues={row014/data:col4/1364133382268/Put/vlen=7, row014/url:col4/1364133382268/Put/vlen=6}
  31. keyvalues={row015/data:col5/1364133382268/Put/vlen=7, row015/url:col5/1364133382268/Put/vlen=6}
  32. keyvalues={row016/data:col6/1364133382268/Put/vlen=7, row016/url:col6/1364133382268/Put/vlen=6}
  33. keyvalues={row017/data:col7/1364133382268/Put/vlen=7, row017/url:col7/1364133382268/Put/vlen=6}
  34. keyvalues={row018/data:col8/1364133382268/Put/vlen=7, row018/url:col8/1364133382268/Put/vlen=6}
  35. keyvalues={row019/data:col9/1364133382268/Put/vlen=7, row019/url:col9/1364133382268/Put/vlen=6}

复制代码

RowFilter用于过滤row key
Operator Description
LESS 小于
LESS_OR_EQUAL 小于等于
[EQUAL 等于
NOT_EQUAL 不等于
GREATER_OR_EQUAL 大于等于
GREATER 大于
NO_OP 排除所有
Comparator Description
BinaryComparator 使用Bytes.compareTo()比较
BinaryPrefixComparator 和BinaryComparator差不多,从前面开始比较
NullComparator Does not compare against an actual value but whether a given one is null, or not  null.
BitComparator Performs a bitwise comparison, providing a BitwiseOp class with OR, and XORoperators.
RegexStringComparator 正则表达式
SubstringComparator 把数据当成字符串,用contains()来判断
  1. import java.io.IOException;
  2. import org.apache.hadoop.conf.Configuration;
  3. import org.apache.hadoop.hbase.HBaseConfiguration;
  4. import org.apache.hadoop.hbase.HColumnDescriptor;
  5. import org.apache.hadoop.hbase.HTableDescriptor;
  6. import org.apache.hadoop.hbase.client.HBaseAdmin;
  7. import org.apache.hadoop.hbase.client.HTable;
  8. import org.apache.hadoop.hbase.client.Put;
  9. import org.apache.hadoop.hbase.client.Result;
  10. import org.apache.hadoop.hbase.client.ResultScanner;
  11. import org.apache.hadoop.hbase.client.Scan;
  12. import org.apache.hadoop.hbase.filter.BinaryComparator;
  13. import org.apache.hadoop.hbase.filter.BinaryPrefixComparator;
  14. import org.apache.hadoop.hbase.filter.CompareFilter;
  15. import org.apache.hadoop.hbase.filter.Filter;
  16. import org.apache.hadoop.hbase.filter.RegexStringComparator;
  17. import org.apache.hadoop.hbase.filter.RowFilter;
  18. import org.apache.hadoop.hbase.filter.SubstringComparator;
  19. public class TestHbaseRowFilter {
  20. String tableName = "test_row_filter";
  21. Configuration config = HBaseConfiguration.create();
  22. /**
  23. * 部分代码来自hbase权威指南
  24. * @throws IOException
  25. */
  26. public void testRowFilter() throws IOException {
  27. HTable table = new HTable(config, tableName);
  28. Scan scan = new Scan();
  29. System.out.println("小于等于row010的行");
  30. Filter filter1 = new RowFilter(CompareFilter.CompareOp.LESS_OR_EQUAL,
  31. new BinaryComparator("row010".getBytes()));
  32. scan.setFilter(filter1);
  33. ResultScanner scanner1 = table.getScanner(scan);
  34. for (Result res : scanner1) {
  35. System.out.println(res);
  36. }
  37. scanner1.close();
  38. System.out.println("正则获取结尾为5的行");
  39. Filter filter2 = new RowFilter(CompareFilter.CompareOp.EQUAL,
  40. new RegexStringComparator(".*5[        DISCUZ_CODE_0        ]quot;));
  41. scan.setFilter(filter2);
  42. ResultScanner scanner2 = table.getScanner(scan);
  43. for (Result res : scanner2) {
  44. System.out.println(res);
  45. }
  46. scanner2.close();
  47. System.out.println("包含有5的行");
  48. Filter filter3 = new RowFilter(CompareFilter.CompareOp.EQUAL,
  49. new SubstringComparator("5"));
  50. scan.setFilter(filter3);
  51. ResultScanner scanner3 = table.getScanner(scan);
  52. for (Result res : scanner3) {
  53. System.out.println(res);
  54. }
  55. scanner3.close();
  56. System.out.println("开头是row01的");
  57. Filter filter4 = new RowFilter(CompareFilter.CompareOp.EQUAL,
  58. new BinaryPrefixComparator("row01".getBytes()));
  59. scan.setFilter(filter4);
  60. ResultScanner scanner4 = table.getScanner(scan);
  61. for (Result res : scanner4) {
  62. System.out.println(res);
  63. }
  64. scanner3.close();
  65. }
  66. /**
  67. * 初始化数据
  68. */
  69. public void init() {
  70. // 创建表和初始化数据
  71. try {
  72. HBaseAdmin admin = new HBaseAdmin(config);
  73. if (!admin.tableExists(tableName)) {
  74. HTableDescriptor htd = new HTableDescriptor(tableName);
  75. HColumnDescriptor hcd1 = new HColumnDescriptor("data");
  76. htd.addFamily(hcd1);
  77. HColumnDescriptor hcd2 = new HColumnDescriptor("url");
  78. htd.addFamily(hcd2);
  79. admin.createTable(htd);
  80. }
  81. HTable table = new HTable(config, tableName);
  82. table.setAutoFlush(false);
  83. int count = 50;
  84. for (int i = 1; i <= count; ++i) {
  85. Put p = new Put(String.format("row%03d", i).getBytes());
  86. p.add("data".getBytes(), String.format("col%01d", i % 10)
  87. .getBytes(), String.format("data%03d", i).getBytes());
  88. p.add("url".getBytes(), String.format("col%01d", i % 10)
  89. .getBytes(), String.format("url%03d", i).getBytes());
  90. table.put(p);
  91. }
  92. table.close();
  93. } catch (IOException e) {
  94. e.printStackTrace();
  95. }
  96. }
  97. /**
  98. * @param args
  99. * @throws IOException
  100. */
  101. public static void main(String[] args) throws IOException {
  102. TestHbaseRowFilter test = new TestHbaseRowFilter();
  103. test.init();
  104. test.testRowFilter();
  105. }
  106. }

复制代码

输出结果
  1. 小于等于row010的行
  2. keyvalues={row001/data:col1/1364133382268/Put/vlen=7, row001/url:col1/1364133382268/Put/vlen=6}
  3. keyvalues={row002/data:col2/1364133382268/Put/vlen=7, row002/url:col2/1364133382268/Put/vlen=6}
  4. keyvalues={row003/data:col3/1364133382268/Put/vlen=7, row003/url:col3/1364133382268/Put/vlen=6}
  5. keyvalues={row004/data:col4/1364133382268/Put/vlen=7, row004/url:col4/1364133382268/Put/vlen=6}
  6. keyvalues={row005/data:col5/1364133382268/Put/vlen=7, row005/url:col5/1364133382268/Put/vlen=6}
  7. keyvalues={row006/data:col6/1364133382268/Put/vlen=7, row006/url:col6/1364133382268/Put/vlen=6}
  8. keyvalues={row007/data:col7/1364133382268/Put/vlen=7, row007/url:col7/1364133382268/Put/vlen=6}
  9. keyvalues={row008/data:col8/1364133382268/Put/vlen=7, row008/url:col8/1364133382268/Put/vlen=6}
  10. keyvalues={row009/data:col9/1364133382268/Put/vlen=7, row009/url:col9/1364133382268/Put/vlen=6}
  11. keyvalues={row010/data:col0/1364133382268/Put/vlen=7, row010/url:col0/1364133382268/Put/vlen=6}
  12. 正则获取结尾为5的行
  13. keyvalues={row005/data:col5/1364133382268/Put/vlen=7, row005/url:col5/1364133382268/Put/vlen=6}
  14. keyvalues={row015/data:col5/1364133382268/Put/vlen=7, row015/url:col5/1364133382268/Put/vlen=6}
  15. keyvalues={row025/data:col5/1364133382268/Put/vlen=7, row025/url:col5/1364133382268/Put/vlen=6}
  16. keyvalues={row035/data:col5/1364133382268/Put/vlen=7, row035/url:col5/1364133382268/Put/vlen=6}
  17. keyvalues={row045/data:col5/1364133382268/Put/vlen=7, row045/url:col5/1364133382268/Put/vlen=6}
  18. 包行有5的行
  19. keyvalues={row005/data:col5/1364133382268/Put/vlen=7, row005/url:col5/1364133382268/Put/vlen=6}
  20. keyvalues={row015/data:col5/1364133382268/Put/vlen=7, row015/url:col5/1364133382268/Put/vlen=6}
  21. keyvalues={row025/data:col5/1364133382268/Put/vlen=7, row025/url:col5/1364133382268/Put/vlen=6}
  22. keyvalues={row035/data:col5/1364133382268/Put/vlen=7, row035/url:col5/1364133382268/Put/vlen=6}
  23. keyvalues={row045/data:col5/1364133382268/Put/vlen=7, row045/url:col5/1364133382268/Put/vlen=6}
  24. keyvalues={row050/data:col0/1364133382268/Put/vlen=7, row050/url:col0/1364133382268/Put/vlen=6}
  25. 开头是row01的
  26. keyvalues={row010/data:col0/1364133382268/Put/vlen=7, row010/url:col0/1364133382268/Put/vlen=6}
  27. keyvalues={row011/data:col1/1364133382268/Put/vlen=7, row011/url:col1/1364133382268/Put/vlen=6}
  28. keyvalues={row012/data:col2/1364133382268/Put/vlen=7, row012/url:col2/1364133382268/Put/vlen=6}
  29. keyvalues={row013/data:col3/1364133382268/Put/vlen=7, row013/url:col3/1364133382268/Put/vlen=6}
  30. keyvalues={row014/data:col4/1364133382268/Put/vlen=7, row014/url:col4/1364133382268/Put/vlen=6}
  31. keyvalues={row015/data:col5/1364133382268/Put/vlen=7, row015/url:col5/1364133382268/Put/vlen=6}
  32. keyvalues={row016/data:col6/1364133382268/Put/vlen=7, row016/url:col6/1364133382268/Put/vlen=6}
  33. keyvalues={row017/data:col7/1364133382268/Put/vlen=7, row017/url:col7/1364133382268/Put/vlen=6}
  34. keyvalues={row018/data:col8/1364133382268/Put/vlen=7, row018/url:col8/1364133382268/Put/vlen=6}
  35. keyvalues={row019/data:col9/1364133382268/Put/vlen=7, row019/url:col9/1364133382268/Put/vlen=6}

复制代码

hbase RowFilter如何根据rowkey查询以及实例实现代码 habase模糊查询【转】的更多相关文章

  1. Python 代码实现模糊查询

    Python 代码实现模糊查询 1.导语: 模糊匹配可以算是现代编辑器(如 Eclipse 等各种 IDE)的一个必备特性了,它所做的就是根据用户输入的部分内容,猜测用户想要的文件名,并提供一个推荐列 ...

  2. query&lowbar;string查询支持全部的Apache Lucene查询语法 低频词划分依据 模糊查询 Disjunction Max

    3.3 基本查询3.3.1词条查询 词条查询是未经分析的,要跟索引文档中的词条完全匹配注意:在输入数据中,title字段含有Crime and Punishment,但我们使用小写开头的crime来搜 ...

  3. 10 行 Python 代码实现模糊查询&sol;智能提示

    10 行 Python 代码实现模糊查询/智能提示   1.导语: 模糊匹配可以算是现代编辑器(如 Eclipse 等各种 IDE)的一个必备特性了,它所做的就是根据用户输入的部分内容,猜测用户想要的 ...

  4. ASP&period;NET MVC&plus;EF框架&plus;EasyUI实现权限管理系列&lpar;20&rpar;-多条件模糊查询和回收站还原的实现

    原文:ASP.NET MVC+EF框架+EasyUI实现权限管理系列(20)-多条件模糊查询和回收站还原的实现 ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇)   (1):框架 ...

  5. stark组件的分页,模糊查询,批量删除

    1.分页组件高阶 2.整合展示数据showlist类 3.stark组件之分页 3.stark组件之search模糊查询 4.action批量处理数据 4.总结 1.分页组件高阶 1.分页的class ...

  6. 10 star组件之分页, search模糊查询, action批量处理

    1.分页组件高阶 1.分页的class形式(有bug,请看下面的) """ 自定义分页组件 """ class Pagination(obj ...

  7. ASP&period;NET操作ORACLE数据库之模糊查询

    ASP.NET操作ORACLE数据库之模糊查询 一.ASP.NET MVC利用OracleHelper辅助类操作ORACLE数据库 //连接Oracle数据库的连接字符串 string connect ...

  8. T-SQL---多值模糊查询的处理

    多值模糊查询的处理 所谓多值模糊查询,就是应用程序中传递过来多个参数,对这些参数做拆分,拆分之后,对拆分结果的key值分别做模糊查询处理 对于精确匹配时,不管是单个Key值还是多个Key值,都很容易处 ...

  9. JAVA 模糊查询方法

    当我们需要开发一个方法用来查询数据库的时候,往往会遇到这样一个问题:就是不知道用户到底会输入什么条件,那么怎么样处理sql语句才能让我们开发的方法不管接受到什么样的条件都可以正常工作呢?这时where ...

随机推荐

  1. MQTT V3&period;1--我的理解

    最近因为工作需要,需要对推送消息了解,因此对MQTT进行了整理,这里更多的是对MQTT英文版的翻译和理解. MQTT(Message Queue Telemetry Transport),遥测传输协议 ...

  2. &lbrack;&period;NET领域驱动设计实战系列&rsqb;专题九:DDD案例:网上书店AOP和站点地图的实现

    一.引言 在前面一专题介绍到,要让缓存生效还需要实现对AOP(面向切面编程)的支持.所以本专题将介绍了网上书店案例中AOP的实现.关于AOP的概念,大家可以参考文章:http://www.cnblog ...

  3. 基础知识系列☞C&num;中&srarr;属性和字段的区别

    "好吧...准备写个'基础知识系列',算是记录下吧,时时看看,更加加深记忆···" 其实本来准备叫"面试系列"... 字段.属性.你先知道的哪个概念? ***我 ...

  4. 双绞线线序&plus;POE供电网线

    0 重点 一般情况下会用1236(橙白.橙.绿白.绿)传输数据,1.2用于发送,3.6用于接收,45(蓝.蓝白)电源正极 78(棕白.棕)电源负极. 一 网线线序 12发 36收 二 poe网线供电 ...

  5. H5 input type&equals;&quot&semi;search&quot&semi; 不显示搜索 解决方法

    在IOS(ipad iPhone等)系统的浏览器里打开H5页面.如下写法: <input type="search" name="search” id=" ...

  6. Shadow Mapping 的原理与实践(一)

    早在上世纪七十年代末,Williams在他的“Casting Curved Shadows on Curved Surface”一文中提出了名为Shadow Map的阴影生成技术.之后,他人在此基础上 ...

  7. R语言的数据结构

    首先声明,R语言对大小写敏感. 一.向量 vector类型可以存储数字.字符和逻辑类型.构建函数为C(): > a <- c(1,2,3,4) > b <- c('dau',' ...

  8. Spring&period;NET程序

    第一个Spring.NET程序   Spring.NET环境准备 pring.NET 1.3.2下载地址:http://down.51cto.com/data/861700 下载后解压 Spring. ...

  9. jsplumb 中文基础教程

    jsplumb 中文基础教程 https://github.com/wangduanduan/jsplumb-chinese-tutorial

  10. ElasticSearch&lpar;十&rpar;Elasticsearch检索出的数据列表按字段匹配的优先顺序及搜索单词拼音一部分搜不到数据

    检索出的数据列表按字段匹配的优先顺序 一.举例 比如,发布一篇文章,文章包括基本的字段包括标题.发布时间.点击率.关键字.内容.当在页面中输入“教育”搜索关键词,会检索出指定字段包括“教育”的所有数据 ...