Java Code Examples for org.apache.hadoop.hbase.CompareOperator#NOT_EQUAL

The following examples show how to use org.apache.hadoop.hbase.CompareOperator#NOT_EQUAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HbaseQuery.java    From tephra with MIT License 6 votes vote down vote up
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;
}
 
Example 2
Source File: TestFilterSerialization.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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))));
}
 
Example 3
Source File: CompareFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: ParseFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * 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");
}
 
Example 5
Source File: ColumnValueFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: ThriftUtilities.java    From hbase with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example 7
Source File: TestFilter.java    From hbase with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 8
Source File: TestScannersWithFilters.java    From hbase with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 9
Source File: TestSingleColumnValueFilter.java    From hbase with Apache License 2.0 4 votes vote down vote up
private Filter nullFilterNew() {
  return new SingleColumnValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER, CompareOperator.NOT_EQUAL,
      new NullComparator());
}