博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hbase SingleColumnValueFilter 列不存在 无法过滤
阅读量:4474 次
发布时间:2019-06-08

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

问题描述

对一张log表按时间过滤

正常数据的话,每行有一个时间戳列timestamp作为操作时间,按这个列值过滤出特定时间段的log信息

但是不知怎么的log表中多了一些垃圾数据(不一定是垃圾数据,只是没有timestamp这个字段)。

过滤第一天的话会有5800条没有操作时间(timestamp),

过滤第二天的时候还是有5800条没有操作时间的,

过滤前两天的时候还是5800条。

问题分析

问题很明显了,就是当某一行没有要过滤的字段时,SingleColumnValueFilter是默认这一行符合过滤条件的。

接下来就要让SingleColumnValueFilter在判断的时候把这个策略改改。

查看源码发现是有方法可以更改这个策略的

代码展现

在SingleColumnValueFilter的源码开头的一段注释中(加粗加大的位置)说明了方法

/** * This filter is used to filter cells based on value. It takes a {@link CompareFilter.CompareOp} * operator (equal, greater, not equal, etc), and either a byte [] value or * a ByteArrayComparable. * 

* If we have a byte [] value then we just do a lexicographic compare. For * example, if passed value is 'b' and cell has 'a' and the compare operator * is LESS, then we will filter out this cell (return true). If this is not * sufficient (eg you want to deserialize a long and then compare it to a fixed * long value), then you can pass in your own comparator instead. *

* You must also specify a family and qualifier. Only the value of this column * will be tested. When using this filter on a {@link Scan} with specified * inputs, the column to be tested should also be added as input (otherwise * the filter will regard the column as missing). *

* To prevent the entire row from being emitted if the column is not found * on a row, use {@link #setFilterIfMissing}. * Otherwise, if the column is found, the entire row will be emitted only if * the value passes. If the value fails, the row will be filtered out. *

* In order to test values of previous versions (timestamps), set * {@link #setLatestVersionOnly} to false. The default is true, meaning that * only the latest version's value is tested and all previous versions are ignored. *

* To filter based on the value of all scanned columns, use {@link ValueFilter}. */

更改代码

SingleColumnValueFilter f1 = new SingleColumnValueFilter(Bytes.toBytes(FAMILY), Bytes.toBytes("timestamp"), CompareOp.GREATER_OR_EQUAL, Bytes.toBytes(starttime));SingleColumnValueFilter f2 = new SingleColumnValueFilter(Bytes.toBytes(FAMILY), Bytes.toBytes("timestamp"), CompareOp.LESS, Bytes.toBytes(endtime));f1.setFilterIfMissing(true);  //true 跳过改行;false 通过该行f2.setFilterIfMissing(true);filters.add(f1);filters.add(f2);

反思

一开始打算继承出一个新类,然后重写部分方法,不过好像还是这样更灵活一些

转载于:https://www.cnblogs.com/erbin/p/4330734.html

你可能感兴趣的文章
C语言常见问题 如何用Visual Studio编写C语言程序测试
查看>>
Web用户的身份验证及WebApi权限验证流程的设计和实现
查看>>
ECMAScript6-let与const命令详解
查看>>
什么是敏捷设计
查看>>
.NET中栈和堆的比较
查看>>
如何优化limit
查看>>
几种常用数据库字段类型查询语句
查看>>
Java判断语句中判断条件的执行顺序
查看>>
Windows平台下tomcat+java的web程序持续占cpu问题调试
查看>>
Content Server HA搭建
查看>>
[leetCode]Linked List Cycle I+II
查看>>
leetcode中的python学习
查看>>
Zookeeper zkui-zookeeper图形化管理工具
查看>>
CenOS+宝塔(模拟)上线博客项目
查看>>
接口,lambda表达式与内部类(二)
查看>>
Phabricator是什么,代码审查工具
查看>>
DirectX:函数可以连接任意两个filter 分类: Direct...
查看>>
算法:求从1到n这n个整数的十进制表示中1出现的次数-- python 实现
查看>>
CSU 1160 把十进制整数转换为十六进制,格式为0x开头,10~15由大写字母A~F表示
查看>>
WinPE启动U盘的制作方法与软件下载(通用PE工具箱/老毛桃/大白菜WinPE)(转载)...
查看>>