Search in sources :

Example 11 with EventBase

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

the class EventQueryTransformerSupport method createResponse.

@Override
public BaseQueryResponse createResponse(List<Object> resultList) {
    EventQueryResponseBase response = this.responseObjectFactory.getEventQueryResponse();
    List<EventBase> eventList = new ArrayList<>();
    Set<String> fieldSet = new TreeSet<>();
    for (Object o : resultList) {
        EventBase<?, ?> e = (EventBase<?, ?>) o;
        for (FieldBase<?> f : e.getFields()) {
            fieldSet.add(f.getName());
        }
        eventList.add(e);
    }
    response.setFields(Lists.newArrayList(fieldSet));
    response.setEvents(eventList);
    response.setReturnedEvents((long) eventList.size());
    return response;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) EventQueryResponseBase(datawave.webservice.result.EventQueryResponseBase)

Example 12 with EventBase

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

the class FieldIndexCountQueryTransformer method transform.

@Override
public EventBase transform(Entry<String, Tuple> entry) {
    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());
    }
    String key = entry.getKey();
    Tuple val = entry.getValue();
    Map<String, String> markings = null;
    try {
        markings = this.markingFunctions.translateFromColumnVisibilityForAuths(val.getColumnVisibility(), this.auths);
    } catch (Exception e) {
        log.error("could not translate " + val.getColumnVisibility() + " to markings, skipping entry");
        return null;
    }
    if (null == markings || markings.isEmpty()) {
        // can't process this one because we did not have valid security markings
        log.error("Transformer visibility interpreter was null, skipping entry");
        return null;
    }
    EventBase event = this.responseObjectFactory.getEvent();
    event.setMarkings(markings);
    List<FieldBase> fields = new ArrayList<>();
    int idx1 = key.indexOf(Constants.NULL_BYTE_STRING);
    if (idx1 == -1) {
        log.error("Invalid entry to FieldIndexCountQueryTransformer");
    }
    // NOTE: fieldName has already been re-mapped by query model in the queryLogic class.
    String fieldName = key.substring(0, idx1);
    String fieldValue;
    String dataType = null;
    // parse from the end to handle nasty field values
    int idx2 = key.lastIndexOf(Constants.NULL_BYTE_STRING);
    if (idx2 > idx1) {
        fieldValue = key.substring(idx1 + 1, idx2);
        dataType = key.substring(idx2 + 1);
    } else {
        fieldValue = key.substring(idx1 + 1);
    }
    String colVis = new String(val.getColumnVisibility().getExpression());
    fields.add(this.makeField("FIELD", markings, colVis, 0L, fieldName));
    fields.add(this.makeField("VALUE", markings, colVis, 0L, fieldValue));
    if (dataType != null) {
        fields.add(this.makeField("DATATYPE", markings, colVis, 0L, dataType));
    }
    fields.add(this.makeField("MOST_RECENT", markings, colVis, 0L, Long.toString(val.getMaxTimestamp())));
    fields.add(this.makeField("RECORD_COUNT", markings, colVis, 0L, Long.toString(val.getCount())));
    event.setFields(fields);
    Text uid = new Text(fieldName);
    TextUtil.textAppend(uid, fieldValue);
    if (null != dataType) {
        TextUtil.textAppend(uid, dataType);
    }
    Metadata metadata = new Metadata();
    metadata.setDataType(Constants.EMPTY_STRING);
    metadata.setInternalId((UID.builder().newId(uid.getBytes())).toString());
    metadata.setRow(Constants.EMPTY_STRING);
    metadata.setTable(logic.getTableName());
    event.setMetadata(metadata);
    if (log.isTraceEnabled()) {
        log.trace("Transformer returning: ");
        log.trace("\tfieldName: " + fieldName);
        log.trace("\tfieldValue: " + fieldValue);
        log.trace("\tdataType: " + ((null != dataType) ? dataType : ""));
        log.trace("\tcount: " + Long.toString(val.getCount()));
        log.trace("\ttimestamp: " + Long.toString(val.getMaxTimestamp()));
    }
    return event;
}
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) Text(org.apache.hadoop.io.Text) Tuple(datawave.query.tables.shard.FieldIndexCountQueryLogic.Tuple) QueryException(datawave.webservice.query.exception.QueryException)

Example 13 with EventBase

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

the class FieldIndexCountQueryTransformer method createResponse.

@Override
public BaseQueryResponse createResponse(List<Object> resultList) {
    EventQueryResponseBase response = responseObjectFactory.getEventQueryResponse();
    List<EventBase> eventList = new ArrayList<>();
    for (Object o : resultList) {
        EventBase<?, ?> e = (EventBase<?, ?>) o;
        eventList.add(e);
    }
    response.setFields(variableFieldList);
    response.setEvents(eventList);
    response.setReturnedEvents((long) eventList.size());
    return (BaseQueryResponse) response;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) ArrayList(java.util.ArrayList) BaseQueryResponse(datawave.webservice.result.BaseQueryResponse) EventQueryResponseBase(datawave.webservice.result.EventQueryResponseBase)

Example 14 with EventBase

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

the class FieldIndexCountQueryTransformer 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();
            Map<String, String> columnMarkings = cqr.getColumnMarkings(columnName);
            String columnVisibility = cqr.getColumnVisibility(columnName);
            Long columnTimestamp = cqr.getColumnTimestamp(columnName);
            FieldBase field = this.makeField(columnName, columnMarkings, columnVisibility, columnTimestamp, 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 EventBase

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

the class FieldIndexCountQueryTransformer method writeToCache.

@Override
public List<CacheableQueryRow> writeToCache(Object o) throws QueryException {
    List<CacheableQueryRow> cqoList = new ArrayList<>();
    EventBase event = (EventBase) o;
    CacheableQueryRow cqo = responseObjectFactory.getCacheableQueryRow();
    Metadata metadata = event.getMetadata();
    cqo.setColFam(metadata.getDataType() + ":" + cqo.getEventId());
    cqo.setDataType(metadata.getDataType());
    cqo.setEventId(metadata.getInternalId());
    cqo.setRow(metadata.getRow());
    List<? extends 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)

Aggregations

EventBase (datawave.webservice.query.result.event.EventBase)43 ArrayList (java.util.ArrayList)28 FieldBase (datawave.webservice.query.result.event.FieldBase)23 Metadata (datawave.webservice.query.result.event.Metadata)18 EventQueryResponseBase (datawave.webservice.result.EventQueryResponseBase)11 CacheableQueryRow (datawave.webservice.query.cachedresults.CacheableQueryRow)10 BaseQueryResponse (datawave.webservice.result.BaseQueryResponse)6 DefaultEventQueryResponse (datawave.webservice.result.DefaultEventQueryResponse)5 Map (java.util.Map)5 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)5 TransformIterator (org.apache.commons.collections4.iterators.TransformIterator)5 Exception (datawave.marking.MarkingFunctions.Exception)4 QueryImpl (datawave.webservice.query.QueryImpl)4 QueryException (datawave.webservice.query.exception.QueryException)4 HashMap (java.util.HashMap)4 CacheableQueryRowImpl (datawave.webservice.query.cachedresults.CacheableQueryRowImpl)3 GenericQueryConfiguration (datawave.webservice.query.configuration.GenericQueryConfiguration)3 DatawaveTransformIterator (datawave.webservice.query.iterator.DatawaveTransformIterator)3 DefaultEvent (datawave.webservice.query.result.event.DefaultEvent)3 Date (java.util.Date)3