In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
There are many filters in hbase: comparison filters and special filters. The function of the filter is to determine whether the data meets the conditions on the server side, and then only returns the data that meets the conditions to the client.
Comparison operator for hbase filter:
LESS-
< LESS_OR_EQUAL ----- = GREATER ----- >NO_OP # excluding all
Comparator for HBase filter (specify comparison mechanism):
BinaryComparator compares the specified byte array in byte index order, using the same Bytes.compareTo (byte []) BinaryPrefixComparator as before, but comparing the data at the left end to determine whether the data is the same NullComparator to determine whether the given empty BitComparator bitwise comparison RegexStringComparator provides a regular comparator that only supports EQUAL and non-EQUALSubstringComparator to determine whether the provided substring appears in the value. 1. Comparison filter / / Row key filter RowFilterFilter filter1 = new RowFilter (CompareOp.LESS_OR_EQUAL, newBinaryComparator (Bytes.toBytes ("user0000")); scan.setFilter (filter1); / / Cluster filter FamilyFilterFilter filter1 = new FamilyFilter (CompareOp.LESS, newBinaryComparator (Bytes.toBytes ("base_info")); scan.setFilter (filter1); / / column filter QualifierFilterFilter filter = new QualifierFilter (CompareOp.LESS_OR_EQUAL, newBinaryComparator (Bytes.toBytes ("name")); scan.setFilter (filter1)) / / value filter ValueFilterFilter filter = new ValueFilter (CompareOp.EQUAL, new SubstringComparator ("zhangsan")); scan.setFilter (filter1); / / timestamp filter TimestampsFilterList tss = new ArrayList (); tss.add (14953988330021); Filter filter1 = new TimestampsFilter (tss); scan.setFilter (filter1); 2. Dedicated filter / / single-column value filter SingleColumnValueFilter-returns the entire row SingleColumnValueFilter filter = new SingleColumnValueFilter (Bytes.toBytes ("colfam1"), Bytes.toBytes ("col-5"), CompareFilter.CompareOp.NOT_EQUAL, new SubstringComparator ("val-5"); filter.setFilterIfMissing (true); / / if not set to true, those rows that do not contain the specified column will also return scan.setFilter (filter1) / / single column value eliminator SingleColumnValueExcludeFilter-returns the result excluding the column SingleColumnValueExcludeFilter filter = new SingleColumnValueExcludeFilter (Bytes.toBytes ("colfam1"), Bytes.toBytes ("col-5"), CompareFilter.CompareOp.NOT_EQUAL, new SubstringComparator ("val-5"); filter.setFilterIfMissing (true); / / if not set to true, rows that do not contain the specified column will also return scan.setFilter (filter1) / / prefix filter PrefixFilter---- for row key Filter filter = new PrefixFilter (Bytes.toBytes ("row1")); scan.setFilter (filter1); / / column prefix filter ColumnPrefixFilterFilter filter = new ColumnPrefixFilter (Bytes.toBytes ("qual2")); scan.setFilter (filter1)
Actual combat cases:
Public class HBase_Filter01 {private static String ZK_KEY = "hbase.zookeeper.quorum"; private static String ZK_VALUE = "hadoop01:2181,hadoop02:2181,hadoop03:2181"; private static Configuration conf; private static Connection connection; private static Admin admin; static {conf = HBaseConfiguration.create (); conf.set (ZK_KEY,ZK_VALUE); try {connection= ConnectionFactory.createConnection (conf); admin=connection.getAdmin () } catch (IOException e) {e.printStackTrace ();}} public static void main (String [] args) {Scan scan=new Scan (); ValueFilter filter = new ValueFilter (CompareFilter.CompareOp.EQUAL, new SubstringComparator ("a")); scan.setFilter (filter); TableName tableName = TableName.valueOf ("user_info"); try {Table table = connection.getTable (tableName) ResultScanner scanner = table.getScanner (scan); Iterator iterator=scanner.iterator (); while (iterator.hasNext ()) {Result result = iterator.next (); System.out.println (result.list ()); byte [] row = result.getRow (); System.out.println (new String (row)) } catch (IOException e) {e.printStackTrace ();}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 228
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.