Search in sources :

Example 1 with CompareOperator

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

the class SingleColumnValueFilter method createFilterFromArguments.

public static Filter createFilterFromArguments(ArrayList<byte[]> filterArguments) {
    Preconditions.checkArgument(filterArguments.size() == 4 || filterArguments.size() == 6, "Expected 4 or 6 but got: %s", filterArguments.size());
    byte[] family = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0));
    byte[] qualifier = ParseFilter.removeQuotesFromByteArray(filterArguments.get(1));
    CompareOperator op = ParseFilter.createCompareOperator(filterArguments.get(2));
    org.apache.hadoop.hbase.filter.ByteArrayComparable comparator = ParseFilter.createComparator(ParseFilter.removeQuotesFromByteArray(filterArguments.get(3)));
    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");
        }
    }
    SingleColumnValueFilter filter = new SingleColumnValueFilter(family, qualifier, op, comparator);
    if (filterArguments.size() == 6) {
        boolean filterIfMissing = ParseFilter.convertByteArrayToBoolean(filterArguments.get(4));
        boolean latestVersionOnly = ParseFilter.convertByteArrayToBoolean(filterArguments.get(5));
        filter.setFilterIfMissing(filterIfMissing);
        filter.setLatestVersionOnly(latestVersionOnly);
    }
    return filter;
}
Also used : CompareOperator(org.apache.hadoop.hbase.CompareOperator)

Example 2 with CompareOperator

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

the class QualifierFilter method parseFrom.

/**
 * @param pbBytes A pb serialized {@link QualifierFilter} instance
 * @return An instance of {@link QualifierFilter} made from <code>bytes</code>
 * @throws org.apache.hadoop.hbase.exceptions.DeserializationException
 * @see #toByteArray
 */
public static QualifierFilter parseFrom(final byte[] pbBytes) throws DeserializationException {
    FilterProtos.QualifierFilter proto;
    try {
        proto = FilterProtos.QualifierFilter.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 QualifierFilter(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 3 with CompareOperator

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

the class ColumnValueFilter method parseFrom.

/**
 * Parse protobuf bytes to a ColumnValueFilter
 * @param pbBytes pbBytes
 * @return a ColumnValueFilter
 * @throws DeserializationException deserialization exception
 */
public static ColumnValueFilter parseFrom(final byte[] pbBytes) throws DeserializationException {
    FilterProtos.ColumnValueFilter proto;
    try {
        proto = FilterProtos.ColumnValueFilter.parseFrom(pbBytes);
    } catch (InvalidProtocolBufferException e) {
        throw new DeserializationException(e);
    }
    final CompareOperator compareOp = CompareOperator.valueOf(proto.getCompareOp().name());
    final ByteArrayComparable comparator;
    try {
        comparator = ProtobufUtil.toComparator(proto.getComparator());
    } catch (IOException ioe) {
        throw new DeserializationException(ioe);
    }
    return new ColumnValueFilter(proto.getFamily().toByteArray(), proto.getQualifier().toByteArray(), compareOp, comparator);
}
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 4 with CompareOperator

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

the class ColumnValueFilter method createFilterFromArguments.

/**
 * 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);
}
Also used : CompareOperator(org.apache.hadoop.hbase.CompareOperator)

Example 5 with CompareOperator

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

the class DependentColumnFilter method createFilterFromArguments.

public static Filter createFilterFromArguments(ArrayList<byte[]> filterArguments) {
    Preconditions.checkArgument(filterArguments.size() == 2 || filterArguments.size() == 3 || filterArguments.size() == 5, "Expected 2, 3 or 5 but got: %s", filterArguments.size());
    if (filterArguments.size() == 2) {
        byte[] family = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0));
        byte[] qualifier = ParseFilter.removeQuotesFromByteArray(filterArguments.get(1));
        return new DependentColumnFilter(family, qualifier);
    } else if (filterArguments.size() == 3) {
        byte[] family = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0));
        byte[] qualifier = ParseFilter.removeQuotesFromByteArray(filterArguments.get(1));
        boolean dropDependentColumn = ParseFilter.convertByteArrayToBoolean(filterArguments.get(2));
        return new DependentColumnFilter(family, qualifier, dropDependentColumn);
    } else if (filterArguments.size() == 5) {
        byte[] family = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0));
        byte[] qualifier = ParseFilter.removeQuotesFromByteArray(filterArguments.get(1));
        boolean dropDependentColumn = ParseFilter.convertByteArrayToBoolean(filterArguments.get(2));
        CompareOperator op = ParseFilter.createCompareOperator(filterArguments.get(3));
        ByteArrayComparable comparator = ParseFilter.createComparator(ParseFilter.removeQuotesFromByteArray(filterArguments.get(4)));
        return new DependentColumnFilter(family, qualifier, dropDependentColumn, op, comparator);
    } else {
        throw new IllegalArgumentException("Expected 2, 3 or 5 but got: " + filterArguments.size());
    }
}
Also used : CompareOperator(org.apache.hadoop.hbase.CompareOperator)

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