您好,欢迎访问一九零五行业门户网

Hbase DependentColumnFilter

here you have a more complex filter that does not simply filter out data based on directly available information. rather, it lets you specify a dependent column—or reference column—that controls how other columns are filtered. it uses th
here you have a more complex filter that does not simply filter out data based on
directly available information. rather, it lets you specify a dependent column—or
reference column—that controls how other columns are filtered. it uses the timestamp
of the reference column and includes all other columns that have the same timestamp.
尝试找到该列所在的每一行,并返回该行具有相同时间戳的全部键值对。如果某一行不包含指定的列,则该行的任何键值对都不返回。
如果dropdependentcolumn=true,则从属列不返回。
via: http://abloz.com/2012/08/22/the-hbases-content-query-2.html
package com.fatkun.filter.comparison;import java.io.ioexception;import org.apache.hadoop.conf.configuration;import org.apache.hadoop.hbase.hbaseconfiguration;import org.apache.hadoop.hbase.hcolumndescriptor;import org.apache.hadoop.hbase.htabledescriptor;import org.apache.hadoop.hbase.keyvalue;import org.apache.hadoop.hbase.client.get;import org.apache.hadoop.hbase.client.hbaseadmin;import org.apache.hadoop.hbase.client.htable;import org.apache.hadoop.hbase.client.put;import org.apache.hadoop.hbase.client.result;import org.apache.hadoop.hbase.client.resultscanner;import org.apache.hadoop.hbase.client.scan;import org.apache.hadoop.hbase.filter.binaryprefixcomparator;import org.apache.hadoop.hbase.filter.comparefilter;import org.apache.hadoop.hbase.filter.dependentcolumnfilter;import org.apache.hadoop.hbase.filter.filter;import org.apache.hadoop.hbase.filter.substringcomparator;import org.apache.hadoop.hbase.filter.valuefilter;import org.apache.hadoop.hbase.filter.writablebytearraycomparable;import org.apache.hadoop.hbase.util.bytes;public class testhbasedependentcolumnfilter { string tablename = test_value_filter; configuration config = hbaseconfiguration.create(); public void filter(boolean drop, comparefilter.compareop operator, writablebytearraycomparable comparator) throws ioexception { htable table = new htable(config, tablename); // filter filter; if (comparator != null) { // drop为true时,filter表示对col1列以外的所有data1列族数据做filter操作 // drop为false时,表示对所有data1列族的数据做filter操作 filter = new dependentcolumnfilter(bytes.tobytes(data1), bytes.tobytes(col1), drop, operator, comparator); } else { filter = new dependentcolumnfilter(bytes.tobytes(data1), bytes.tobytes(col1), drop); } // filter应用于scan scan scan = new scan(); scan.setfilter(filter); resultscanner scanner = table.getscanner(scan); for (result result : scanner) { for (keyvalue kv : result.list()) { system.out.println(kv= + kv.tostring() + ,value= + bytes.tostring(kv.getvalue())); } } scanner.close(); table.close(); } /** * 部分代码来自hbase权威指南 * * @throws ioexception */ public void testfilter() throws ioexception { // the dropdependentcolumn parameter is giving you additional control // over how the reference column is handled: it is either included or // dropped by the filter // 1.获取整个data1列族当前version中的所有timestamp等于参照列data1:col1的数据 system.out.println(drop=false); filter(false, comparefilter.compareop.no_op, null); // 2.获取除了col1列以外的data1列族中的所有timestamp等于参照列data1:col1的数据 system.out.println(drop=true); filter(true, comparefilter.compareop.no_op, null); // 3.获取除了col1列以外的data1列族当前version中的所有timestamp等于参照列data1:col1的,value以data100开头的所有数据 system.out.println(比较); filter(true, comparefilter.compareop.equal, new binaryprefixcomparator( bytes.tobytes(data100))); } /** * 初始化数据 */ public void init() { // 创建表和初始化数据 try { hbaseadmin admin = new hbaseadmin(config); if (!admin.tableexists(tablename)) { htabledescriptor htd = new htabledescriptor(tablename); hcolumndescriptor hcd1 = new hcolumndescriptor(data1); htd.addfamily(hcd1); hcolumndescriptor hcd2 = new hcolumndescriptor(data2); htd.addfamily(hcd2); hcolumndescriptor hcd3 = new hcolumndescriptor(data3); htd.addfamily(hcd3); admin.createtable(htd); } htable table = new htable(config, tablename); table.setautoflush(false); int count = 50; for (int i = 1; i 原文地址:hbase dependentcolumnfilter, 感谢原作者分享。

其它类似信息

推荐信息