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;
}
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;
}
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
}
}
}
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
}
}
}
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;
}
Aggregations