Search in sources :

Example 1 with EmptyObjectException

use of datawave.webservice.query.exception.EmptyObjectException in project datawave by NationalSecurityAgency.

the class TermFrequencyQueryTransformer method transform.

@Override
public DefaultEvent transform(Entry<Key, Value> entry) throws EmptyObjectException {
    if (entry.getKey() == null && entry.getValue() == null) {
        return null;
    }
    if (entry.getKey() == null || entry.getValue() == null) {
        throw new IllegalArgumentException("Null keyy or value. Key:" + entry.getKey() + ", Value: " + entry.getValue());
    }
    TermFrequencyKeyValue tfkv;
    try {
        tfkv = TermFrequencyKeyValueFactory.parse(entry.getKey(), entry.getValue(), auths, markingFunctions);
    } catch (Exception e) {
        throw new IllegalArgumentException("Unable to parse visibility", e);
    }
    DefaultEvent e = new DefaultEvent();
    e.setMarkings(tfkv.getMarkings());
    Metadata m = new Metadata();
    m.setRow(tfkv.getShardId());
    m.setDataType(tfkv.getShardId());
    m.setInternalId(tfkv.getUid());
    e.setMetadata(m);
    List<DefaultField> fields = ImmutableList.of(createField(tfkv, entry, "FIELD_NAME", tfkv.getFieldName()), createField(tfkv, entry, "FIELD_VALUE", tfkv.getFieldValue()), createField(tfkv, entry, "OFFSET_COUNT", String.valueOf(tfkv.getCount())), createField(tfkv, entry, "OFFSETS", tfkv.getOffsets().toString()));
    e.setFields(fields);
    return e;
}
Also used : TermFrequencyKeyValue(datawave.query.table.parser.TermFrequencyKeyValueFactory.TermFrequencyKeyValue) DefaultEvent(datawave.webservice.query.result.event.DefaultEvent) Metadata(datawave.webservice.query.result.event.Metadata) DefaultField(datawave.webservice.query.result.event.DefaultField) EmptyObjectException(datawave.webservice.query.exception.EmptyObjectException)

Example 2 with EmptyObjectException

use of datawave.webservice.query.exception.EmptyObjectException in project datawave by NationalSecurityAgency.

the class FacetedTransformer method _transform.

private FacetsBase _transform(Entry<Key, Document> documentEntry) throws EmptyObjectException {
    if (documentEntry == null) {
        // buildResponse will return a null object if there was only metadata in the document
        throw new EmptyObjectException();
    }
    Key documentKey = correctKey(documentEntry.getKey());
    Document document = documentEntry.getValue();
    if (null == documentKey || null == document)
        throw new IllegalArgumentException("Null key or value. Key:" + documentKey + ", Value: " + documentEntry.getValue());
    extractMetrics(document, documentKey);
    document.debugDocumentSize(documentKey);
    String row = documentKey.getRow().toString();
    String colf = documentKey.getColumnFamily().toString();
    int index = colf.indexOf("\0");
    Preconditions.checkArgument(-1 != index);
    String dataType = colf.substring(0, index);
    String uid = colf.substring(index + 1);
    // We don't have to consult the Document to rebuild the Visibility, the key
    // should have the correct top-level visibility
    ColumnVisibility eventCV = new ColumnVisibility(documentKey.getColumnVisibility());
    FacetsBase output = null;
    try {
        // build response method here
        output = buildResponse(document, documentKey, eventCV, colf, row, this.markingFunctions);
    } catch (Exception ex) {
        log.error("Error building response document", ex);
        throw new RuntimeException(ex);
    }
    if (output == null) {
        // buildResponse will return a null object if there was only metadata in the document
        throw new EmptyObjectException();
    }
    if (cardinalityConfiguration != null) {
        collectCardinalities(document, documentKey, uid, dataType);
    }
    return output;
}
Also used : EmptyObjectException(datawave.webservice.query.exception.EmptyObjectException) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Document(datawave.query.attributes.Document) Key(org.apache.accumulo.core.data.Key) EmptyObjectException(datawave.webservice.query.exception.EmptyObjectException) FacetsBase(datawave.webservice.query.result.event.FacetsBase)

Example 3 with EmptyObjectException

use of datawave.webservice.query.exception.EmptyObjectException in project datawave by NationalSecurityAgency.

the class BulkResultsFileOutputMapper method map.

@Override
protected void map(Key key, Value value, org.apache.hadoop.mapreduce.Mapper<Key, Value, Key, Value>.Context context) throws IOException, InterruptedException {
    entries.clear();
    entries.put(key, value);
    for (Entry<Key, Value> entry : entries.entrySet()) {
        try {
            Object o = t.transform(entry);
            BaseQueryResponse response = t.createResponse(new ResultsPage(Collections.singletonList(o)));
            Class<? extends BaseQueryResponse> responseClass = null;
            try {
                responseClass = getResponseClass(response.getClass().getName());
            } catch (ClassNotFoundException e) {
                throw new RuntimeException("Unable to find response class: " + response.getClass().getName(), e);
            }
            try {
                Value val = serializeResponse(responseClass, response, this.format);
                // Write out the original key and the new value.
                if (context.getOutputKeyClass() == null || context.getOutputKeyClass().equals(NullWritable.class)) {
                    // don't write the key in this case, write only the value
                    key = null;
                } else {
                    // to preserve whatever the reason was for this wrapping of the key in the original code
                    key = new Key(key);
                }
                context.write(key, val);
            } catch (Exception e) {
                throw new RuntimeException("Unable to serialize response of class: " + response.getClass().getName(), e);
            }
            context.progress();
        } catch (EmptyObjectException e) {
        // not yet done, so continue fetching next
        }
    }
}
Also used : EmptyObjectException(datawave.webservice.query.exception.EmptyObjectException) Value(org.apache.accumulo.core.data.Value) BaseQueryResponse(datawave.webservice.result.BaseQueryResponse) ResultsPage(datawave.webservice.query.cache.ResultsPage) NullWritable(org.apache.hadoop.io.NullWritable) Key(org.apache.accumulo.core.data.Key) EmptyObjectException(datawave.webservice.query.exception.EmptyObjectException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException)

Example 4 with EmptyObjectException

use of datawave.webservice.query.exception.EmptyObjectException in project datawave by NationalSecurityAgency.

the class BulkResultsTableOutputMapper method map.

@Override
protected void map(Key key, Value value, org.apache.hadoop.mapreduce.Mapper<Key, Value, Text, Mutation>.Context context) throws IOException, InterruptedException {
    entries.clear();
    entries.put(key, value);
    for (Entry<Key, Value> entry : entries.entrySet()) {
        try {
            Object o = t.transform(entry);
            BaseQueryResponse response = t.createResponse(new ResultsPage(Collections.singletonList(o)));
            Class<? extends BaseQueryResponse> responseClass = null;
            try {
                responseClass = getResponseClass(response.getClass().getName());
            } catch (ClassNotFoundException e) {
                throw new RuntimeException("Unable to find response class: " + response.getClass().getName(), e);
            }
            try {
                Value val = BulkResultsFileOutputMapper.serializeResponse(responseClass, response, this.format);
                // Write out the original key and the new value.
                Mutation m = new Mutation(key.getRow());
                m.put(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibility()), key.getTimestamp(), val);
                context.write(this.tableName, m);
            } catch (Exception e) {
                throw new RuntimeException("Unable to serialize response of class: " + response.getClass().getName(), e);
            }
            context.progress();
        } catch (EmptyObjectException e) {
        // not yet done, so continue fetching next
        }
    }
}
Also used : ResultsPage(datawave.webservice.query.cache.ResultsPage) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) EmptyObjectException(datawave.webservice.query.exception.EmptyObjectException) EmptyObjectException(datawave.webservice.query.exception.EmptyObjectException) Value(org.apache.accumulo.core.data.Value) BaseQueryResponse(datawave.webservice.result.BaseQueryResponse) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key)

Example 5 with EmptyObjectException

use of datawave.webservice.query.exception.EmptyObjectException in project datawave by NationalSecurityAgency.

the class DocumentTransformer method _transform.

private EventBase _transform(Entry<Key, Document> documentEntry) throws EmptyObjectException {
    if (documentEntry == null) {
        // buildResponse will return a null object if there was only metadata in the document
        throw new EmptyObjectException();
    }
    Key documentKey = correctKey(documentEntry.getKey());
    Document document = documentEntry.getValue();
    if (null == documentKey || null == document)
        throw new IllegalArgumentException("Null key or value. Key:" + documentKey + ", Value: " + documentEntry.getValue());
    extractMetrics(document, documentKey);
    document.debugDocumentSize(documentKey);
    String row = documentKey.getRow().toString();
    String colf = documentKey.getColumnFamily().toString();
    int index = colf.indexOf("\0");
    Preconditions.checkArgument(-1 != index);
    String dataType = colf.substring(0, index);
    String uid = colf.substring(index + 1);
    // We don't have to consult the Document to rebuild the Visibility, the key
    // should have the correct top-level visibility
    ColumnVisibility eventCV = new ColumnVisibility(documentKey.getColumnVisibility());
    EventBase output = null;
    try {
        // build response method here
        output = buildResponse(document, documentKey, eventCV, colf, row, this.markingFunctions);
    } catch (Exception ex) {
        log.error("Error building response document", ex);
        throw new RuntimeException(ex);
    }
    if (output == null) {
        // buildResponse will return a null object if there was only metadata in the document
        throw new EmptyObjectException();
    }
    if (cardinalityConfiguration != null) {
        collectCardinalities(document, documentKey, uid, dataType);
    }
    return output;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) EmptyObjectException(datawave.webservice.query.exception.EmptyObjectException) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Document(datawave.query.attributes.Document) Key(org.apache.accumulo.core.data.Key) EmptyObjectException(datawave.webservice.query.exception.EmptyObjectException)

Aggregations

EmptyObjectException (datawave.webservice.query.exception.EmptyObjectException)6 Key (org.apache.accumulo.core.data.Key)4 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)3 Document (datawave.query.attributes.Document)2 ResultsPage (datawave.webservice.query.cache.ResultsPage)2 BaseQueryResponse (datawave.webservice.result.BaseQueryResponse)2 IOException (java.io.IOException)2 JAXBException (javax.xml.bind.JAXBException)2 Value (org.apache.accumulo.core.data.Value)2 Attribute (datawave.query.attributes.Attribute)1 TimingMetadata (datawave.query.attributes.TimingMetadata)1 TermFrequencyKeyValue (datawave.query.table.parser.TermFrequencyKeyValueFactory.TermFrequencyKeyValue)1 DefaultEvent (datawave.webservice.query.result.event.DefaultEvent)1 DefaultField (datawave.webservice.query.result.event.DefaultField)1 EventBase (datawave.webservice.query.result.event.EventBase)1 FacetsBase (datawave.webservice.query.result.event.FacetsBase)1 Metadata (datawave.webservice.query.result.event.Metadata)1 Mutation (org.apache.accumulo.core.data.Mutation)1 NullWritable (org.apache.hadoop.io.NullWritable)1