在HBase Column Family上应用过滤器

时间:2018-03-20 08:55:05

标签: java hadoop mapreduce hbase

我在HBase中有一个表,其中包含以下数据:

EmployeeDetails:

Options -Indexes -MultiViews +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Saffron/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php? [L]
</IfModule>

997942是此表的关键。我想仅使用Java为OrganizationID = 19提取记录,为此,我编写了以下代码:

 997942                                column=Employee_details:Qualifications, timestamp=1520592579241, value=$ EmployeeCode:02404#EmployeeName:ABC
                                       #EducationLevel:#Course:#SubjectOfSpecialization:#InstituteName:#UniversityName:#CourseType:#ScoreType:#Sc
                                       ore:#StartYear:#EndYear:#EduHistoryID:#EmploymentStatus:Exited#ModifiedDate:#MinorSpecialization:General#IsTra
                                       ck:Yes#OrganizationID:19
 997942                                column=Employee_details:RefferelDetails, timestamp=1520592579241, value=$ EmployeeCode:02404#EmployeeName:ABC
                                       #Name:#ContactNumber:#Email:#Designation:#OrganizationName:#OrganizationAddress:#ReferenceRelationshipTyp
                                       e:#IsInternalReference:No#EmployeeCodeRef:#EmploymentStatus:Exited#EmployeeReferenceDetailID:#ModifiedDate:Nov
                                        16 2015  5:52PM#OrganizationID:19
 997942                                column=Employee_details:Skills, timestamp=1520592579241, value=$ EmployeeCode:02404#EmployeeName:ABC#Cer
                                       tificateLevel:#IsCompleted:#CompletionDate:#EmploymentStatus:Exited#ModifiedDate:#OrganizationID:19
 997942                                column=Employee_details:organizationid, timestamp=1520592579241, value=19

所有组织的数据都被拉了。过滤器无法正常工作。我们有替代方案吗?

1 个答案:

答案 0 :(得分:1)

问题在于

SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes.toBytes(TableName),
    Bytes.toBytes("organizationid"), CompareFilter.CompareOp.EQUAL,
    new BinaryComparator(Bytes.toBytes(String.valueOf(organizationId))));

SingleColumnValueFilter的构造函数具有签名

SingleColumnValueFilter(final byte [] family, final byte [] qualifier,
   final CompareOp compareOp, final byte[] value)

您将第一个参数作为TableName给出,它应该是列族。

改为使用:

SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes.toBytes("Employee_details"),
    Bytes.toBytes("organizationid"), CompareFilter.CompareOp.EQUAL,
    Bytes.toBytes(organizationId));

另外,您不需要FilterList,因为您只使用一个过滤器。