问题描述
我是Hbase的新手。
I am new to Hbase.
我有一个场景,我需要根据状态和当前日期提取文件名。
I have a scenario where I need to pull a filename based on the status and current date.
我创建了3列; 文件名
,状态
和日期
c> Hbase 表。
So I have created 3 columns; filename
, status
and date
in the Hbase
table.
如何根据 status = true
和日期是今天的条件获取文件名?
How can I get the filename based on the condition that the status=true
and date is today?
这个查询需要在Hbase shell上执行。
This query needs to be executed on the Hbase shell.
推荐答案
这以一种简洁的方式是困难的。但这是我所做的。
hbase shell
是一个 JRuby
shell,它使我们能够完成以下示例。
Achieving this in a concise way is difficult. But here is what I did.hbase shell
is a JRuby
shell, which enables us to do the following example.
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter
import org.apache.hadoop.hbase.filter.CompareFilter
import org.apache.hadoop.hbase.filter.SubstringComparator
import org.apache.hadoop.hbase.filter.FilterList
filter1 = SingleColumnValueFilter.new(Bytes.toBytes('cf'), Bytes.toBytes('qualifier'), CompareFilter::CompareOp.valueOf('EQUAL'), SubstringComparator.new('valueToSearch'));
filter2 = SingleColumnValueFilter.new(Bytes.toBytes('cf'), Bytes.toBytes('qualifier2'), CompareFilter::CompareOp.valueOf('EQUAL'), SubstringComparator.new('valueToSearch2'));
filterList = FilterList.new([filter1, filter2]);
scan 'table', {FILTER => filterList}
您可以导入任何其他过滤器
, Comparator
, Java
对象等等
You could import any other Filters
, Comparator
, Java
objects etc
SubstringComparator
用于测试。
您的情况应该是 BinaryComparator
)
请参阅问题,如果你想阅读更多关于类似的黑客。
Refer this question if you want to read more about a similar hack.
希望它有帮助。
这篇关于如何根据标准(如Hbase shell中的where子句)获取列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!