gpt4 book ai didi

java - hbase:根据输入值分配 CompareFilter.CompareOp

转载 作者:行者123 更新时间:2023-11-30 10:43:30 25 4
gpt4 key购买 nike

我们可以根据输入值取 compareOperator 值吗?例如,如果我的输入是 eq,那么它应该选择 CompareFilter.CompareOp.EQUAL,否则如果输入是 ne,它应该选择 CompareFilter.CompareOp.NOT_EQUAL.

有点像

if(input.equals("eq")) {
myCompareOp = EQUAL;
}else if(input.equals("ne")) {
myCompareOp = NOT_EQUAL;
}

SingleColumnValueFilter colValFilter = new SingleColumnValueFilter(Bytes.toBytes(<CF>), Bytes.toBytes(<CQ>)
, myCompareOp, new BinaryComparator(Bytes.toBytes(<value>)));

任何建议将不胜感激

最佳答案

基于上面的代码,是的,它会起作用。下面是示例代码片段,你也可以看看。其中 ConditionType 是枚举...这样你也可以准备自己的枚举(如果条件也可以,则不是强制性的)

private Filter buildSimpleQuery(ConditionType ct, String name, Object value) {
name = super.getRealPropertyName(name);
validatePropertyValue(name, value);
Class<?> clazz = getPrimitiveFieldClass(name, value.getClass());
CompareOp compareOp = null;
boolean regexCompRequired = false;
switch (ct) {
case EQUALS:
compareOp = CompareOp.EQUAL;
regexCompRequired = String.class == clazz && value.toString().endsWith("*");
break;
case NOT_EQUALS:
compareOp = CompareOp.NOT_EQUAL;
regexCompRequired = String.class == clazz && value.toString().endsWith("*");
break;
case GREATER_THAN:
compareOp = CompareOp.GREATER;
break;
case GREATER_OR_EQUALS:
compareOp = CompareOp.GREATER_OR_EQUAL;
break;
case LESS_THAN:
compareOp = CompareOp.LESS;
break;
case LESS_OR_EQUALS:
compareOp = CompareOp.LESS_OR_EQUAL;
break;
default:
break;
}
String qualifier = name;
String theFamily = family != null ? family : familyMap.get(qualifier);
ByteArrayComparable byteArrayComparable = regexCompRequired
? new RegexStringComparator(value.toString().replace("*", "."))
: new BinaryComparator(value.toString().getBytes(StandardCharsets.UTF_8));

Filter query = new SingleColumnValueFilter(theFamily.getBytes(StandardCharsets.UTF_8),
qualifier.getBytes(StandardCharsets.UTF_8),
compareOp,
byteArrayComparable);
return query;
}

关于java - hbase:根据输入值分配 CompareFilter.CompareOp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37736586/

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