Search in sources :

Example 1 with FieldBase

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

the class GroupingDocumentTransformer method createGroupedResponse.

protected BaseQueryResponse createGroupedResponse(Multiset<Collection<FieldBase<?>>> multiset) {
    Map<String, String> markings = Maps.newHashMap();
    EventQueryResponseBase response = this.responseObjectFactory.getEventQueryResponse();
    List<EventBase> events = new ArrayList<>();
    for (Collection<FieldBase<?>> entry : multiset.elementSet()) {
        EventBase event = this.responseObjectFactory.getEvent();
        event.setMarkings(markings);
        List<FieldBase<?>> fields = new ArrayList(entry);
        FieldBase<?> counter = this.responseObjectFactory.getField();
        counter.setName("COUNT");
        counter.setMarkings(markings);
        counter.setValue(multiset.count(entry));
        counter.setTimestamp(0L);
        fields.add(counter);
        event.setFields(fields);
        events.add(event);
    }
    response.setEvents(events);
    response.setTotalEvents((long) events.size());
    response.setReturnedEvents((long) events.size());
    return response;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) ArrayList(java.util.ArrayList) FieldBase(datawave.webservice.query.result.event.FieldBase) EventQueryResponseBase(datawave.webservice.result.EventQueryResponseBase)

Example 2 with FieldBase

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

the class ShardIndexQueryTransformer 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);
        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 = 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 3 with FieldBase

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

the class ShardIndexQueryTransformer 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 4 with FieldBase

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

the class ShardIndexQueryTransformer method transform.

@Override
public EventBase transform(Entry<Key, Value> input) {
    log.debug("Transform got " + input);
    @SuppressWarnings("unchecked") Entry<Key, Value> entry = (Entry<Key, Value>) input;
    if (entry.getKey() == null && entry.getValue() == null) {
        return null;
    }
    if (null == entry.getKey() || null == entry.getValue()) {
        throw new IllegalArgumentException("Null key or value. Key:" + entry.getKey() + ", Value: " + entry.getValue());
    }
    EventBase event = responseObjectFactory.getEvent();
    ColumnVisibility columnVisibility = new ColumnVisibility(entry.getKey().getColumnVisibility());
    Map<String, String> markings;
    try {
        markings = this.markingFunctions.translateFromColumnVisibilityForAuths(columnVisibility, this.auths);
    } catch (Exception e1) {
        throw new RuntimeException("could not make markings from: " + columnVisibility);
    }
    event.setMarkings(markings);
    List<FieldBase> fields = new ArrayList<>();
    Key key = entry.getKey();
    String row = key.getRow().toString();
    String cf = key.getColumnFamily().toString();
    String cq = key.getColumnQualifier().toString();
    String cv = key.getColumnVisibility().toString();
    fields.add(makeField("VALUE", markings, cv, 0L, row));
    /**
     * Added query model to alias FIELD
     */
    fields.add(makeField("FIELD", markings, cv, 0L, myQueryModel.aliasFieldNameReverseModel(cf)));
    fields.add(makeField("DATE", markings, cv, 0L, cq.substring(0, 8)));
    fields.add(makeField("DATA TYPE", markings, cv, 0L, cq.substring(9)));
    // Parse the UID.List object from the value
    Uid.List uidList = null;
    long count = 0;
    try {
        uidList = Uid.List.parseFrom(entry.getValue().get());
        if (null != uidList) {
            count = uidList.getCOUNT();
        }
    } catch (InvalidProtocolBufferException e) {
        log.error("Failed to parse Uid List", e);
    }
    fields.add(makeField("RECORD COUNT", markings, cv, 0L, Long.toString(count)));
    event.setFields(fields);
    Metadata metadata = new Metadata();
    String id = logic.getTableName() + ":" + row + ":" + cf + ":" + cq;
    metadata.setInternalId(UUID.nameUUIDFromBytes(id.getBytes()).toString());
    metadata.setDataType(entry.getKey().getColumnFamily().toString());
    metadata.setRow(entry.getKey().getRow().toString());
    metadata.setTable(logic.getTableName());
    event.setMetadata(metadata);
    return event;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) ArrayList(java.util.ArrayList) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Metadata(datawave.webservice.query.result.event.Metadata) Exception(datawave.marking.MarkingFunctions.Exception) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) QueryException(datawave.webservice.query.exception.QueryException) Uid(datawave.ingest.protobuf.Uid) Entry(java.util.Map.Entry) Value(org.apache.accumulo.core.data.Value) FieldBase(datawave.webservice.query.result.event.FieldBase) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key)

Example 5 with FieldBase

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

the class ShardIndexQueryTransformer method makeField.

private FieldBase makeField(String name, Map<String, String> markings, String columnVisibility, Long timestamp, Object value) {
    FieldBase field = this.responseObjectFactory.getField();
    field.setName(name);
    field.setMarkings(markings);
    field.setColumnVisibility(columnVisibility);
    field.setTimestamp(timestamp);
    field.setValue(value);
    return field;
}
Also used : FieldBase(datawave.webservice.query.result.event.FieldBase)

Aggregations

FieldBase (datawave.webservice.query.result.event.FieldBase)32 EventBase (datawave.webservice.query.result.event.EventBase)24 ArrayList (java.util.ArrayList)20 Metadata (datawave.webservice.query.result.event.Metadata)15 CacheableQueryRow (datawave.webservice.query.cachedresults.CacheableQueryRow)9 Map (java.util.Map)6 Exception (datawave.marking.MarkingFunctions.Exception)4 QueryException (datawave.webservice.query.exception.QueryException)4 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)4 QueryImpl (datawave.webservice.query.QueryImpl)3 CacheableQueryRowImpl (datawave.webservice.query.cachedresults.CacheableQueryRowImpl)3 EventQueryResponseBase (datawave.webservice.result.EventQueryResponseBase)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 TransformIterator (org.apache.commons.collections4.iterators.TransformIterator)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 GenericQueryConfiguration (datawave.webservice.query.configuration.GenericQueryConfiguration)2 DatawaveTransformIterator (datawave.webservice.query.iterator.DatawaveTransformIterator)2 BaseQueryResponse (datawave.webservice.result.BaseQueryResponse)2 DefaultEventQueryResponse (datawave.webservice.result.DefaultEventQueryResponse)2