use of datawave.webservice.query.result.event.EventBase in project datawave by NationalSecurityAgency.
the class DiscoveryTransformer method readFromCache.
@Override
public List<Object> readFromCache(List<CacheableQueryRow> cacheableQueryRowList) {
List<Object> eventList = new ArrayList<>();
for (CacheableQueryRow cqr : cacheableQueryRowList) {
if (this.variableFieldList == null) {
this.variableFieldList = cqr.getVariableColumnNames();
}
Map<String, String> markings = cqr.getMarkings();
String dataType = cqr.getDataType();
String internalId = cqr.getEventId();
String row = cqr.getRow();
EventBase event = this.responseObjectFactory.getEvent();
event.setMarkings(markings);
Metadata metadata = new Metadata();
metadata.setDataType(dataType);
metadata.setInternalId(internalId);
metadata.setRow(row);
metadata.setTable(logic.getTableName());
event.setMetadata(metadata);
List<FieldBase> fieldList = new ArrayList<>();
Map<String, String> columnValueMap = cqr.getColumnValues();
for (Map.Entry<String, String> entry : columnValueMap.entrySet()) {
String columnName = entry.getKey();
String columnValue = entry.getValue();
String columnVisibility = cqr.getColumnVisibility(columnName);
Long columnTimestamp = cqr.getColumnTimestamp(columnName);
Map<String, String> columnMarkings = cqr.getColumnMarkings(columnName);
FieldBase field = this.responseObjectFactory.getField();
field.setName(columnName);
field.setMarkings(columnMarkings);
field.setColumnVisibility(columnVisibility);
field.setTimestamp(columnTimestamp);
field.setValue(columnValue);
fieldList.add(field);
}
event.setFields(fieldList);
eventList.add(event);
}
return eventList;
}
use of datawave.webservice.query.result.event.EventBase in project datawave by NationalSecurityAgency.
the class DiscoveryTransformer method writeToCache.
@Override
public List<CacheableQueryRow> writeToCache(Object o) throws QueryException {
List<CacheableQueryRow> cqoList = new ArrayList<>();
EventBase event = (EventBase) o;
CacheableQueryRow cqo = new CacheableQueryRowImpl();
Metadata metadata = event.getMetadata();
cqo.setColFam(metadata.getDataType() + ":" + cqo.getEventId());
cqo.setDataType(metadata.getDataType());
cqo.setEventId(metadata.getInternalId());
cqo.setRow(metadata.getRow());
List<FieldBase> fields = event.getFields();
for (FieldBase f : fields) {
cqo.addColumn(f.getName(), f.getTypedValue(), f.getMarkings(), f.getColumnVisibility(), f.getTimestamp());
}
cqoList.add(cqo);
return cqoList;
}
use of datawave.webservice.query.result.event.EventBase in project datawave by NationalSecurityAgency.
the class DocumentTransformer method buildResponse.
protected EventBase buildResponse(Document document, Key documentKey, ColumnVisibility eventCV, String colf, String row, MarkingFunctions mf) throws MarkingFunctions.Exception {
Map<String, String> markings = mf.translateFromColumnVisibility(eventCV);
EventBase event = null;
final Collection<FieldBase<?>> documentFields = buildDocumentFields(documentKey, null, document, eventCV, mf);
// if documentFields is empty, then the response contained only timing metadata
if (!documentFields.isEmpty()) {
event = this.responseObjectFactory.getEvent();
event.setMarkings(markings);
event.setFields(new ArrayList<>(documentFields));
Metadata metadata = new Metadata();
String[] colfParts = StringUtils.split(colf, '\0');
if (colfParts.length >= 1) {
metadata.setDataType(colfParts[0]);
}
if (colfParts.length >= 2) {
metadata.setInternalId(colfParts[1]);
}
if (this.tableName != null) {
metadata.setTable(this.tableName);
}
metadata.setRow(row);
event.setMetadata(metadata);
if (eventQueryDataDecoratorTransformer != null) {
event = (EventBase) eventQueryDataDecoratorTransformer.transform(event);
}
// assign an estimate of the event size based on the document size
// in practice this is about 2.5 times the size of the document estimated size
// we need to set something here for page size trigger purposes.
event.setSizeInBytes(Math.round(document.sizeInBytes() * 2.5d));
}
return event;
}
use of datawave.webservice.query.result.event.EventBase 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;
}
use of datawave.webservice.query.result.event.EventBase in project datawave by NationalSecurityAgency.
the class EventQueryDataDecoratorTransformer method transform.
@Override
public Object transform(Object o) {
if (o instanceof EventBase) {
EventBase e = (EventBase) o;
List<? extends FieldBase> fields = e.getFields();
Multimap<String, FieldBase> fieldMap = HashMultimap.create();
for (FieldBase f : fields) {
fieldMap.put(f.getName(), f);
}
for (String d : requestedDecorators) {
EventQueryDataDecorator decorator = dataDecorators.get(d);
if (decorator != null) {
decorator.decorateData(fieldMap);
}
}
e.setFields(new ArrayList<>(fieldMap.values()));
return e;
} else {
return o;
}
}
Aggregations