Example usage for org.apache.hadoop.io MapWritable isEmpty

List of usage examples for org.apache.hadoop.io MapWritable isEmpty

Introduction

In this page you can find the example usage for org.apache.hadoop.io MapWritable isEmpty.

Prototype

@Override
    public boolean isEmpty() 

Source Link

Usage

From source file:com.digitalpebble.behemoth.DocumentFilter.java

License:Apache License

/** Returns true if the document can be kept, false otherwise **/
public boolean keep(BehemothDocument input) {
    // filter if null
    if (input == null)
        return false;

    // check length content
    if (input.getContent() != null && maxContentLength != -1) {
        if (input.getContent().length > maxContentLength)
            return false;
    }//w ww  . j a  va  2  s. c o m

    // check on the URL
    if (URLRegex != null) {
        if (input.getUrl() == null)
            return false;
        boolean match = URLRegex.matcher(input.getUrl()).matches();
        if (!match)
            return false;
    }

    // check on the MimeType
    if (MimetypeRegex != null) {
        if (input.getContentType() == null)
            return false;
        boolean match = MimetypeRegex.matcher(input.getContentType()).matches();
        if (!match)
            return false;
    }

    MapWritable metadata = input.getMetadata();
    // no rules at all -> fine!
    if (KVpatterns.size() == 0)
        return true;

    // document MUST have a certain value to be kept
    if (metadata == null || metadata.isEmpty()) {
        if (!negativeMode)
            return false;
        else
            return true;
    }

    boolean hasMatch = false;

    // find common keys between filters and content of doc
    boolean matchesAll = true;
    Iterator<String> kiter = KVpatterns.keySet().iterator();
    while (kiter.hasNext()) {
        String k = kiter.next();
        String regex = KVpatterns.get(k);
        // see if we have a metadata for that key
        Writable value = metadata.get(new Text(k));
        if (value == null) {
            matchesAll = false;
            continue;
        }
        if (value.toString().matches(regex)) {
            hasMatch = true;
        } else
            matchesAll = false;
    }

    boolean successMatching = false;

    if (medataMode.equalsIgnoreCase("AND")) {
        if (matchesAll)
            successMatching = true;
    } else if (hasMatch)
        successMatching = true;

    if (successMatching) {
        return (!negativeMode);
    }

    // no negative rule matching
    if (negativeMode)
        return true;

    // no positive rule matching
    return false;
}

From source file:gaffer.accumulostore.key.core.AbstractCoreKeyAccumuloElementConverter.java

License:Apache License

@Override
public Value getValueFromProperties(final Properties properties, final String group)
        throws AccumuloElementConversionException {
    final MapWritable map = new MapWritable();
    for (final Map.Entry<String, Object> entry : properties.entrySet()) {
        final String propertyName = entry.getKey();
        final StorePropertyDefinition propertyDefinition = storeSchema.getElement(group)
                .getProperty(propertyName);
        if (propertyDefinition != null) {
            if (StorePositions.VALUE.isEqual(propertyDefinition.getPosition())) {
                try {
                    map.put(new Text(propertyName),
                            new BytesWritable(propertyDefinition.getSerialiser().serialise(entry.getValue())));
                } catch (final SerialisationException e) {
                    throw new AccumuloElementConversionException("Failed to serialise property " + propertyName,
                            e);//  w w  w .j  a  v  a 2 s  .c o m
                }
            }
        }
    }
    if (map.isEmpty()) {
        return new Value();
    }
    return new Value(WritableUtils.toByteArray(map));
}