Search in sources :

Example 16 with CompareOperator

use of org.apache.hadoop.hbase.CompareOperator in project hbase by apache.

the class SingleColumnValueFilter method parseFrom.

/**
 * @param pbBytes A pb serialized {@link SingleColumnValueFilter} instance
 * @return An instance of {@link SingleColumnValueFilter} made from <code>bytes</code>
 * @throws org.apache.hadoop.hbase.exceptions.DeserializationException
 * @see #toByteArray
 */
public static SingleColumnValueFilter parseFrom(final byte[] pbBytes) throws DeserializationException {
    FilterProtos.SingleColumnValueFilter proto;
    try {
        proto = FilterProtos.SingleColumnValueFilter.parseFrom(pbBytes);
    } catch (InvalidProtocolBufferException e) {
        throw new DeserializationException(e);
    }
    final CompareOperator compareOp = CompareOperator.valueOf(proto.getCompareOp().name());
    final org.apache.hadoop.hbase.filter.ByteArrayComparable comparator;
    try {
        comparator = ProtobufUtil.toComparator(proto.getComparator());
    } catch (IOException ioe) {
        throw new DeserializationException(ioe);
    }
    return new SingleColumnValueFilter(proto.hasColumnFamily() ? proto.getColumnFamily().toByteArray() : null, proto.hasColumnQualifier() ? proto.getColumnQualifier().toByteArray() : null, compareOp, comparator, proto.getFilterIfMissing(), proto.getLatestVersionOnly());
}
Also used : CompareOperator(org.apache.hadoop.hbase.CompareOperator) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) FilterProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos) IOException(java.io.IOException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Example 17 with CompareOperator

use of org.apache.hadoop.hbase.CompareOperator in project hbase by apache.

the class ValueFilter method parseFrom.

/**
 * @param pbBytes A pb serialized {@link ValueFilter} instance
 * @return An instance of {@link ValueFilter} made from <code>bytes</code>
 * @throws DeserializationException
 * @see #toByteArray
 */
public static ValueFilter parseFrom(final byte[] pbBytes) throws DeserializationException {
    FilterProtos.ValueFilter proto;
    try {
        proto = FilterProtos.ValueFilter.parseFrom(pbBytes);
    } catch (InvalidProtocolBufferException e) {
        throw new DeserializationException(e);
    }
    final CompareOperator valueCompareOp = CompareOperator.valueOf(proto.getCompareFilter().getCompareOp().name());
    ByteArrayComparable valueComparator = null;
    try {
        if (proto.getCompareFilter().hasComparator()) {
            valueComparator = ProtobufUtil.toComparator(proto.getCompareFilter().getComparator());
        }
    } catch (IOException ioe) {
        throw new DeserializationException(ioe);
    }
    return new ValueFilter(valueCompareOp, valueComparator);
}
Also used : CompareOperator(org.apache.hadoop.hbase.CompareOperator) InvalidProtocolBufferException(org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException) FilterProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos) IOException(java.io.IOException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Example 18 with CompareOperator

use of org.apache.hadoop.hbase.CompareOperator in project hbase by apache.

the class ValueFilter method createFilterFromArguments.

public static Filter createFilterFromArguments(ArrayList<byte[]> filterArguments) {
    // for arguments
    @SuppressWarnings("rawtypes") ArrayList arguments = CompareFilter.extractArguments(filterArguments);
    CompareOperator compareOp = (CompareOperator) arguments.get(0);
    ByteArrayComparable comparator = (ByteArrayComparable) arguments.get(1);
    return new ValueFilter(compareOp, comparator);
}
Also used : CompareOperator(org.apache.hadoop.hbase.CompareOperator) ArrayList(java.util.ArrayList)

Example 19 with CompareOperator

use of org.apache.hadoop.hbase.CompareOperator in project hbase by apache.

the class CompareFilter method extractArguments.

// returns an array of heterogeneous objects
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;
}
Also used : CompareOperator(org.apache.hadoop.hbase.CompareOperator) ArrayList(java.util.ArrayList)

Aggregations

CompareOperator (org.apache.hadoop.hbase.CompareOperator)19 IOException (java.io.IOException)8 DeserializationException (org.apache.hadoop.hbase.exceptions.DeserializationException)8 FilterProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos)8 InvalidProtocolBufferException (org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException)8 ArrayList (java.util.ArrayList)5 Cell (org.apache.hadoop.hbase.Cell)2 Get (org.apache.hadoop.hbase.client.Get)2 Scan (org.apache.hadoop.hbase.client.Scan)2 ByteArrayComparable (org.apache.hadoop.hbase.filter.ByteArrayComparable)2 Filter (org.apache.hadoop.hbase.filter.Filter)2 TimeRange (org.apache.hadoop.hbase.io.TimeRange)2 FilterList (org.apache.gora.filter.FilterList)1 MapFieldValueFilter (org.apache.gora.filter.MapFieldValueFilter)1 SingleFieldValueFilter (org.apache.gora.filter.SingleFieldValueFilter)1 HBaseColumn (org.apache.gora.hbase.store.HBaseColumn)1 ByteBufferExtendedCell (org.apache.hadoop.hbase.ByteBufferExtendedCell)1 CheckAndMutateResult (org.apache.hadoop.hbase.client.CheckAndMutateResult)1 Mutation (org.apache.hadoop.hbase.client.Mutation)1 Put (org.apache.hadoop.hbase.client.Put)1