Search in sources :

Example 11 with Metadata

use of datawave.webservice.query.result.event.Metadata 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;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) FieldBase(datawave.webservice.query.result.event.FieldBase) Metadata(datawave.webservice.query.result.event.Metadata)

Example 12 with Metadata

use of datawave.webservice.query.result.event.Metadata in project datawave by NationalSecurityAgency.

the class ParentDocumentTransformer method transform.

@Override
public EventBase transform(Entry<Key, Value> input) {
    EventBase event = super.transform(input);
    Metadata md = event.getMetadata();
    byte[] id = md.getInternalId().getBytes();
    ByteSequence parentIdBytes = TLD.parseParentPointerFromId(new ArrayByteSequence(id));
    String parentId = new String(parentIdBytes.getBackingArray(), parentIdBytes.offset(), parentIdBytes.length());
    md.setInternalId(parentId);
    return event;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) Metadata(datawave.webservice.query.result.event.Metadata) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence) ByteSequence(org.apache.accumulo.core.data.ByteSequence) ArrayByteSequence(org.apache.accumulo.core.data.ArrayByteSequence)

Example 13 with Metadata

use of datawave.webservice.query.result.event.Metadata in project datawave by NationalSecurityAgency.

the class ShardQueryCountTableTransformer method writeToCache.

@Override
public List<CacheableQueryRow> writeToCache(Object o) throws QueryException {
    List<CacheableQueryRow> cqoList = new ArrayList<>();
    EventBase event = (EventBase) o;
    CacheableQueryRowImpl 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());
    }
    // set the size in bytes using the initial event size as an approximation
    cqo.setSizeInBytes(event.getSizeInBytes());
    cqoList.add(cqo);
    return cqoList;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) ArrayList(java.util.ArrayList) Metadata(datawave.webservice.query.result.event.Metadata) FieldBase(datawave.webservice.query.result.event.FieldBase) CacheableQueryRow(datawave.webservice.query.cachedresults.CacheableQueryRow) CacheableQueryRowImpl(datawave.webservice.query.cachedresults.CacheableQueryRowImpl)

Example 14 with Metadata

use of datawave.webservice.query.result.event.Metadata in project datawave by NationalSecurityAgency.

the class ShardQueryCountTableTransformer 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 = responseObjectFactory.getEvent();
        event.setMarkings(markings);
        Metadata metadata = new Metadata();
        metadata.setDataType(dataType);
        metadata.setInternalId(internalId);
        metadata.setRow(row);
        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 = 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;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) ArrayList(java.util.ArrayList) Metadata(datawave.webservice.query.result.event.Metadata) CacheableQueryRow(datawave.webservice.query.cachedresults.CacheableQueryRow) FieldBase(datawave.webservice.query.result.event.FieldBase) Map(java.util.Map)

Example 15 with Metadata

use of datawave.webservice.query.result.event.Metadata in project datawave by NationalSecurityAgency.

the class ShardQueryCountTableTransformer method transform.

@Override
public EventBase transform(Entry<Long, ColumnVisibility> untypedEntry) {
    Long count = untypedEntry.getKey();
    ColumnVisibility vis = untypedEntry.getValue();
    Map<String, String> markings;
    try {
        markings = markingFunctions.translateFromColumnVisibilityForAuths(vis, auths);
    } catch (Exception e1) {
        throw new IllegalArgumentException("Unable to translate markings", e1);
    }
    EventBase e = this.responseObjectFactory.getEvent();
    e.setMarkings(markings);
    FieldBase field = this.makeField(COUNT_CELL, markings, vis, System.currentTimeMillis(), count);
    e.setMarkings(markings);
    List<FieldBase> fields = new ArrayList<>();
    fields.add(field);
    e.setFields(fields);
    Metadata metadata = new Metadata();
    metadata.setDataType(Constants.EMPTY_STRING);
    // There is only one item returned for the entire query logic.
    metadata.setInternalId(field.getName());
    metadata.setRow(Constants.EMPTY_STRING);
    e.setMetadata(metadata);
    return e;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) FieldBase(datawave.webservice.query.result.event.FieldBase) ArrayList(java.util.ArrayList) Metadata(datawave.webservice.query.result.event.Metadata) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) QueryException(datawave.webservice.query.exception.QueryException) Exception(datawave.marking.MarkingFunctions.Exception)

Aggregations

Metadata (datawave.webservice.query.result.event.Metadata)20 EventBase (datawave.webservice.query.result.event.EventBase)18 FieldBase (datawave.webservice.query.result.event.FieldBase)15 ArrayList (java.util.ArrayList)15 CacheableQueryRow (datawave.webservice.query.cachedresults.CacheableQueryRow)10 Exception (datawave.marking.MarkingFunctions.Exception)5 Map (java.util.Map)5 QueryException (datawave.webservice.query.exception.QueryException)4 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)4 CacheableQueryRowImpl (datawave.webservice.query.cachedresults.CacheableQueryRowImpl)3 DefaultEvent (datawave.webservice.query.result.event.DefaultEvent)2 DefaultField (datawave.webservice.query.result.event.DefaultField)2 HashMap (java.util.HashMap)2 Key (org.apache.accumulo.core.data.Key)2 Value (org.apache.accumulo.core.data.Value)2 Input (com.esotericsoftware.kryo.io.Input)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Uid (datawave.ingest.protobuf.Uid)1 EventFields (datawave.query.parser.EventFields)1 FieldValue (datawave.query.parser.EventFields.FieldValue)1