HBase中的简单整数比较 [英] Simple integer comparison in HBase

查看:163
本文介绍了HBase中的简单整数比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HBase中尝试了一个非常简单的例子。以下是我如何创建表和将数据:

  create'newdb3','data'
put'newdb3' ,'row1','data:name','Thexxx Beatles'
放入'newdb3','row2','data:name','披头士'
放入'newdb3','row3' ,'data:name','Beatles'
放'newdb3','row4','data:name','Thexxx'
放'newdb3','row1','data:duration' ,400
放'newdb3','row2','data:duration',300
放'newdb3','row3','data:duration',200
放'newdb3' ,'row4','data:duration',100

scan'newdb3',{COLUMNS => 'data:name',FILTER => SingleColumnValueFilter('data','duration',>,'binaryprefix:200')}

但结果总是4列。我尝试使用或不使用字符串的数字,并使用十六进制值。我也试过'binary'而不是'binaryprefix'。如何存储和比较hbase中的整数?

解决方案

这是否会产生预期的输出?

  import org.apache.hadoop.hbase.filter.CompareFilter 
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter
import org .apache.hadoop.hbase.filter.SubstringComparator
import org.apache.hadoop.hbase.util.Bytes

扫描'newdb3',{FILTER => SingleColumnValueFilter.new(Bytes.toBytes('data'),\
Bytes.toBytes('duration'),
CompareFilter :: CompareOp.valueOf('GREATER'),\
BinaryComparator.new(Bytes.toBytes('200')))}

注意:二进制比较和数字,只有当它们是0填充的时候它才能工作

I am trying out a very simple example in HBase. Following is how I create table and put data:

create 'newdb3','data'
put 'newdb3','row1','data:name','Thexxx Beatles'
put 'newdb3','row2','data:name','The Beatles'
put 'newdb3','row3','data:name','Beatles'
put 'newdb3','row4','data:name','Thexxx'
put 'newdb3','row1','data:duration',400
put 'newdb3','row2','data:duration',300
put 'newdb3','row3','data:duration',200
put 'newdb3','row4','data:duration',100

scan 'newdb3', {COLUMNS => 'data:name', FILTER => "SingleColumnValueFilter('data','duration', > ,'binaryprefix:200')"}

But the result is always all 4 columns. I tried number with or without string, and using hex values. I also tried 'binary' instead of 'binaryprefix'. How do I store and compare integer in hbase?

解决方案

Does this produce the expected output?

import org.apache.hadoop.hbase.filter.CompareFilter
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter
import org.apache.hadoop.hbase.filter.SubstringComparator
import org.apache.hadoop.hbase.util.Bytes

scan 'newdb3', { FILTER => SingleColumnValueFilter.new(Bytes.toBytes('data'), \
    Bytes.toBytes('duration'), 
    CompareFilter::CompareOp.valueOf('GREATER'), \
    BinaryComparator.new(Bytes.toBytes('200'))) }

NOTE: This will do a binary comparison and for numbers it will work only if they are 0-padded

这篇关于HBase中的简单整数比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆