下面列出了org.apache.hadoop.hbase.CompareOperator#NOT_EQUAL 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected CompareOperator getCompare(Where where) {
if (where == Where.Equals)
return CompareOperator.EQUAL;
if (where == Where.NotEquals)
return CompareOperator.NOT_EQUAL;
if (where == Where.Less)
return CompareOperator.LESS;
if (where == Where.LessEquals)
return CompareOperator.LESS_OR_EQUAL;
if (where == Where.Greater)
return CompareOperator.GREATER;
if (where == Where.GreaterEquals)
return CompareOperator.GREATER_OR_EQUAL;
return CompareOperator.EQUAL;
}
@Test
public void testSingleColumnValueFilter() throws Exception {
// null family/column SingleColumnValueFilter
SingleColumnValueFilter singleColumnValueFilter =
new SingleColumnValueFilter(null, null,
CompareOperator.LESS, Bytes.toBytes("value"));
assertTrue(singleColumnValueFilter.areSerializedFieldsEqual(
ProtobufUtil.toFilter(ProtobufUtil.toFilter(singleColumnValueFilter))));
// non-null family/column SingleColumnValueFilter
singleColumnValueFilter =
new SingleColumnValueFilter(Bytes.toBytes("family"), Bytes.toBytes("qualifier"),
CompareOperator.NOT_EQUAL, new NullComparator(), true, true);
assertTrue(singleColumnValueFilter.areSerializedFieldsEqual(
ProtobufUtil.toFilter(ProtobufUtil.toFilter(singleColumnValueFilter))));
}
public static ArrayList<Object> extractArguments(ArrayList<byte []> filterArguments) {
Preconditions.checkArgument(filterArguments.size() == 2,
"Expected 2 but got: %s", filterArguments.size());
CompareOperator op = ParseFilter.createCompareOperator(filterArguments.get(0));
ByteArrayComparable comparator = ParseFilter.createComparator(
ParseFilter.removeQuotesFromByteArray(filterArguments.get(1)));
if (comparator instanceof RegexStringComparator ||
comparator instanceof SubstringComparator) {
if (op != CompareOperator.EQUAL &&
op != CompareOperator.NOT_EQUAL) {
throw new IllegalArgumentException ("A regexstring comparator and substring comparator" +
" can only be used with EQUAL and NOT_EQUAL");
}
}
ArrayList<Object> arguments = new ArrayList<>(2);
arguments.add(op);
arguments.add(comparator);
return arguments;
}
/**
* Takes a compareOperator symbol as a byte array and returns the corresponding CompareOperator
* @param compareOpAsByteArray the comparatorOperator symbol as a byte array
* @return the Compare Operator
*/
public static CompareOperator createCompareOperator (byte [] compareOpAsByteArray) {
ByteBuffer compareOp = ByteBuffer.wrap(compareOpAsByteArray);
if (compareOp.equals(ParseConstants.LESS_THAN_BUFFER))
return CompareOperator.LESS;
else if (compareOp.equals(ParseConstants.LESS_THAN_OR_EQUAL_TO_BUFFER))
return CompareOperator.LESS_OR_EQUAL;
else if (compareOp.equals(ParseConstants.GREATER_THAN_BUFFER))
return CompareOperator.GREATER;
else if (compareOp.equals(ParseConstants.GREATER_THAN_OR_EQUAL_TO_BUFFER))
return CompareOperator.GREATER_OR_EQUAL;
else if (compareOp.equals(ParseConstants.NOT_EQUAL_TO_BUFFER))
return CompareOperator.NOT_EQUAL;
else if (compareOp.equals(ParseConstants.EQUAL_TO_BUFFER))
return CompareOperator.EQUAL;
else
throw new IllegalArgumentException("Invalid compare operator");
}
/**
* Creating this filter by reflection, it is used by {@link ParseFilter},
* @param filterArguments arguments for creating a ColumnValueFilter
* @return a ColumnValueFilter
*/
public static Filter createFilterFromArguments(ArrayList<byte[]> filterArguments) {
Preconditions.checkArgument(filterArguments.size() == 4,
"Expect 4 arguments: %s", filterArguments.size());
byte[] family = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0));
byte[] qualifier = ParseFilter.removeQuotesFromByteArray(filterArguments.get(1));
CompareOperator operator = ParseFilter.createCompareOperator(filterArguments.get(2));
ByteArrayComparable comparator =
ParseFilter.createComparator(ParseFilter.removeQuotesFromByteArray(filterArguments.get(3)));
if (comparator instanceof RegexStringComparator ||
comparator instanceof SubstringComparator) {
if (operator != CompareOperator.EQUAL &&
operator != CompareOperator.NOT_EQUAL) {
throw new IllegalArgumentException("A regexstring comparator and substring comparator " +
"can only be used with EQUAL and NOT_EQUAL");
}
}
return new ColumnValueFilter(family, qualifier, operator, comparator);
}
public static CompareOperator compareOpFromThrift(TCompareOperator tCompareOp) {
switch (tCompareOp.getValue()) {
case 0: return CompareOperator.LESS;
case 1: return CompareOperator.LESS_OR_EQUAL;
case 2: return CompareOperator.EQUAL;
case 3: return CompareOperator.NOT_EQUAL;
case 4: return CompareOperator.GREATER_OR_EQUAL;
case 5: return CompareOperator.GREATER;
case 6: return CompareOperator.NO_OP;
default: return null;
}
}
@Test
public void testSkipFilter() throws IOException {
// Test for qualifier regex: "testQualifierOne-2"
// Should only get rows from second group, and all keys
Filter f = new SkipFilter(new QualifierFilter(CompareOperator.NOT_EQUAL,
new BinaryComparator(Bytes.toBytes("testQualifierOne-2"))));
Scan s = new Scan();
s.setFilter(f);
KeyValue [] kvs = {
// testRowTwo-0
new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]),
new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]),
new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]),
new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]),
new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]),
new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]),
// testRowTwo-2
new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]),
new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]),
new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]),
new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]),
new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]),
new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]),
// testRowTwo-3
new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]),
new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]),
new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]),
new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]),
new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]),
new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]),
};
verifyScanFull(s, kvs);
}
@Test
public void testSkipFilter() throws Exception {
// Test for qualifier regex: "testQualifierOne-2"
// Should only get rows from second group, and all keys
Filter f = new SkipFilter(new QualifierFilter(CompareOperator.NOT_EQUAL,
new BinaryComparator(Bytes.toBytes("testQualifierOne-2"))));
Scan s = new Scan();
s.setFilter(f);
KeyValue [] kvs = {
// testRowTwo-0
new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]),
new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]),
new KeyValue(ROWS_TWO[0], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]),
new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]),
new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]),
new KeyValue(ROWS_TWO[0], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]),
// testRowTwo-2
new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]),
new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]),
new KeyValue(ROWS_TWO[2], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]),
new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]),
new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]),
new KeyValue(ROWS_TWO[2], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]),
// testRowTwo-3
new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[0], VALUES[1]),
new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[2], VALUES[1]),
new KeyValue(ROWS_TWO[3], FAMILIES[0], QUALIFIERS_TWO[3], VALUES[1]),
new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[0], VALUES[1]),
new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[2], VALUES[1]),
new KeyValue(ROWS_TWO[3], FAMILIES[1], QUALIFIERS_TWO[3], VALUES[1]),
};
verifyScanFull(s, kvs);
}
private Filter nullFilterNew() {
return new SingleColumnValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER, CompareOperator.NOT_EQUAL,
new NullComparator());
}