gpt4 book ai didi

java - 在 HBase 列族上应用过滤器

转载 作者:可可西里 更新时间:2023-11-01 15:24:00 25 4
gpt4 key购买 nike

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

员工详细信息:

 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

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

HTable table = new HTable(config, "EmployeeDetails");
FilterList list = new FilterList(FilterList.Operator.MUST_PASS_ALL);
SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes.toBytes("Employee_details"),
Bytes.toBytes("organizationid"), CompareFilter.CompareOp.EQUAL,
new BinaryComparator(Bytes.toBytes(String.valueOf("19"))));
list.addFilter(filter);
Scan scan = new Scan();
scan.setFilter(list);
scanner = table.getScanner(scan);

正在提取所有组织的数据。过滤器工作不正常。我们有什么替代方案吗?

最佳答案

问题在于

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,因为您只使用了一个过滤器。

关于java - 在 HBase 列族上应用过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49379857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com