博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hbase 参考列过滤器
阅读量:4159 次
发布时间:2019-05-26

本文共 2542 字,大约阅读时间需要 8 分钟。

1.代码

测试数据:

package hbase.hbasseAPI.Filter;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.TableName;import org.apache.hadoop.hbase.client.*;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.util.Bytes;import java.io.IOException;/** * 参考列过滤器 * public DependentColumnFilter(final byte [] family, final byte[] qualifier, * final boolean dropDependentColumn, final CompareOp valueCompareOp, * final ByteArrayComparable valueComparator) * family 和qualifier是选择参考列,会获取参考列时间戳(只是针对参考列的时间戳和该列所在行的其他字段的时间戳的比较) * dropDependentColumn,作为参考列 ,false输出,true 不输出, * CompareOp,//加上这个条件后,限定这个条件输出结果 * ByteArrayComparable */public class MyDependColFilter {    public static void main(String[] args) throws IOException {        System.setProperty("hadoop.home.dir", "E:\\software\\bigdate\\hadoop-2.6.0-cdh5.15.0\\hadoop-2.6.0-cdh5.15.0");        Configuration conf = new Configuration();        conf.set("zookeeper.znode.parent", "/hbase");        conf.set("hbase.zookeeper.quorum", "wangfutai");        conf.set("hbase.zookeeper.property.clientPort", "2181");        Connection connection = ConnectionFactory.createConnection(conf);        TableName tableName = TableName.valueOf("hadoop:human");        Table table = connection.getTable(tableName);        Scan scan = new Scan();        DependentColumnFilter dependentColumnFilter =                new DependentColumnFilter(                        Bytes.toBytes("info"),                        Bytes.toBytes("name"),                        false,                        CompareFilter.CompareOp.EQUAL,//加上这个条件后,限定这个条件输出结果                        new BinaryPrefixComparator(Bytes.toBytes("wangfutai")));        scan.setFilter(dependentColumnFilter);        ResultScanner scanner = table.getScanner(scan);        for (Result tmp : scanner) {            System.out.println(tmp);        }        scanner.close();    }}

输出结果:

keyvalues={1/info:age/1547176413283/Put/vlen=3/seqid=0, 1/info:name/1547176413283/Put/vlen=9/seqid=0}keyvalues={12/info:age/1547526043294/Put/vlen=4/seqid=0, 12/info:id/1547526043294/Put/vlen=4/seqid=0, 12/info:name/1547526043294/Put/vlen=9/seqid=0}keyvalues={6/info:id/1547526231270/Put/vlen=4/seqid=0, 6/info:name/1547526231270/Put/vlen=9/seqid=0}keyvalues={8/info:id/1547526231270/Put/vlen=4/seqid=0, 8/info:name/1547526231270/Put/vlen=9/seqid=0}keyvalues={9/info:name/1547526231270/Put/vlen=9/seqid=0}

结果分析:

转载地址:http://dgjxi.baihongyu.com/

你可能感兴趣的文章
Multiple People Tracking by Lifted Multicut and Person Re-identification
查看>>
Visual Tracking Using Attention-Modulated Disintegration and Integration
查看>>
Action-Decision Networks for Visual Tracking with Deep Reinforcement Learning
查看>>
Multiple Object Tracking with High Performance Detection and Appearance Feature
查看>>
深度学习入门(上)-第一章 必备基础知识点
查看>>
ubuntu unzip解压时提示错误 解决方法
查看>>
sprintf函数的说明
查看>>
BOOST_TYPEOF和BOOST_AUTO 作用
查看>>
随机森林概述
查看>>
2011十大战略技术
查看>>
大学应该学的软件知识
查看>>
腾讯与360战争背后的云计算阴影
查看>>
腾讯看了会沉默,360看了会流泪
查看>>
李开复:移动互联网机会最大 微博会现最大赢家
查看>>
2006年的IT十大战略技术
查看>>
操作系统介绍
查看>>
Desktop Linux: The Dream Is Dead
查看>>
我的9年IT路
查看>>
任正非:让用户像用电一样享受云计算
查看>>
学习技术的几个境界
查看>>