Search in sources :

Example 6 with EventBase

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

the class TermFrequencyQueryTransformer method createResponse.

@Override
public BaseQueryResponse createResponse(List<Object> resultList) {
    DefaultEventQueryResponse response = new DefaultEventQueryResponse();
    List<EventBase> eventList = new ArrayList<>();
    for (Object o : resultList) {
        EventBase result = (EventBase) o;
        eventList.add(result);
    }
    response.setEvents(eventList);
    response.setReturnedEvents(new Long(eventList.size()));
    return response;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) DefaultEventQueryResponse(datawave.webservice.result.DefaultEventQueryResponse) ArrayList(java.util.ArrayList)

Example 7 with EventBase

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

the class GroupingTest method runTestQueryWithGrouping.

protected BaseQueryResponse runTestQueryWithGrouping(Map<String, Integer> expected, String querystr, Date startDate, Date endDate, Map<String, String> extraParms, Connector connector) throws Exception {
    log.debug("runTestQueryWithGrouping");
    QueryImpl settings = new QueryImpl();
    settings.setBeginDate(startDate);
    settings.setEndDate(endDate);
    settings.setPagesize(Integer.MAX_VALUE);
    settings.setQueryAuthorizations(auths.serialize());
    settings.setQuery(querystr);
    settings.setParameters(extraParms);
    settings.setId(UUID.randomUUID());
    log.debug("query: " + settings.getQuery());
    log.debug("logic: " + settings.getQueryLogicName());
    GenericQueryConfiguration config = logic.initialize(connector, settings, authSet);
    logic.setupQuery(config);
    DocumentTransformer transformer = (DocumentTransformer) (logic.getTransformer(settings));
    TransformIterator iter = new DatawaveTransformIterator(logic.iterator(), transformer);
    List<Object> eventList = new ArrayList<>();
    while (iter.hasNext()) {
        eventList.add(iter.next());
    }
    BaseQueryResponse response = transformer.createResponse(eventList);
    // un-comment to look at the json output
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME);
    mapper.writeValue(temporaryFolder.newFile(), response);
    Assert.assertTrue(response instanceof DefaultEventQueryResponse);
    DefaultEventQueryResponse eventQueryResponse = (DefaultEventQueryResponse) response;
    Assert.assertEquals("Got the wrong number of events", expected.size(), (long) eventQueryResponse.getReturnedEvents());
    for (EventBase event : eventQueryResponse.getEvents()) {
        String firstKey = "";
        String secondKey = "";
        Integer value = null;
        for (Object field : event.getFields()) {
            FieldBase fieldBase = (FieldBase) field;
            switch(fieldBase.getName()) {
                case "COUNT":
                    value = Integer.valueOf(fieldBase.getValueString());
                    break;
                case "GENDER":
                case "GEN":
                case "BIRTHDAY":
                    firstKey = fieldBase.getValueString();
                    break;
                case "AGE":
                case "AG":
                case "RECORD":
                    secondKey = fieldBase.getValueString();
                    break;
            }
        }
        log.debug("mapping is " + firstKey + "-" + secondKey + " count:" + value);
        String key;
        if (!firstKey.isEmpty() && !secondKey.isEmpty()) {
            key = firstKey + "-" + secondKey;
        } else if (!firstKey.isEmpty()) {
            key = firstKey;
        } else {
            key = secondKey;
        }
        Assert.assertEquals(expected.get(key), value);
    }
    return response;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) DefaultEventQueryResponse(datawave.webservice.result.DefaultEventQueryResponse) TransformIterator(org.apache.commons.collections4.iterators.TransformIterator) DatawaveTransformIterator(datawave.webservice.query.iterator.DatawaveTransformIterator) DatawaveTransformIterator(datawave.webservice.query.iterator.DatawaveTransformIterator) ArrayList(java.util.ArrayList) GenericQueryConfiguration(datawave.webservice.query.configuration.GenericQueryConfiguration) QueryImpl(datawave.webservice.query.QueryImpl) BaseQueryResponse(datawave.webservice.result.BaseQueryResponse) FieldBase(datawave.webservice.query.result.event.FieldBase) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 8 with EventBase

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

the class QueryWizardResultResponse method buildTableColumnHeadings.

private HashSet<String> buildTableColumnHeadings(StringBuilder builder, DefaultEventQueryResponse tempResponse) {
    HashSet<String> fieldnameSet = new HashSet<>();
    builder.append("<thead><tr><th>DataType</th>");
    for (EventBase event : tempResponse.getEvents()) {
        for (Object field : event.getFields()) {
            if (field instanceof DefaultField) {
                fieldnameSet.add(((DefaultField) field).getName());
            }
        }
    }
    for (String fieldname : fieldnameSet) {
        builder.append("<th>");
        builder.append(fieldname);
        builder.append("</th>");
    }
    builder.append("</tr></thead>");
    return fieldnameSet;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) DefaultField(datawave.webservice.query.result.event.DefaultField) HashSet(java.util.HashSet)

Example 9 with EventBase

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

the class DefaultEventQueryResponse method merge.

@Override
public void merge(EventQueryResponseBase other) {
    if (null != other.getEvents()) {
        if (null == this.events) {
            this.events = new ArrayList<DefaultEvent>();
        }
        for (EventBase event : other.getEvents()) {
            this.events.add((DefaultEvent) event);
        }
    }
    if (null != other.getFields()) {
        if (null == this.fields) {
            this.fields = new ArrayList<String>(other.getFields());
        } else {
            this.fields.addAll(other.getFields());
        }
    }
    this.returnedEvents += other.getReturnedEvents();
    this.totalEvents += other.getTotalEvents();
    this.setOperationTimeMS(this.getOperationTimeMS() + other.getOperationTimeMS());
    // If either is partial results, then this is partial results
    if (this.isPartialResults() != other.isPartialResults()) {
        this.setPartialResults(true);
    }
    if (null != other.getMessages()) {
        if (null == this.getMessages()) {
            this.setMessages(other.getMessages());
        } else {
            this.getMessages().addAll(other.getMessages());
        }
    }
    if (null != other.getExceptions()) {
        if (null == this.getExceptions()) {
            this.setExceptions(new LinkedList<QueryExceptionType>(other.getExceptions()));
        } else {
            this.getExceptions().addAll(other.getExceptions());
        }
    }
}
Also used : DefaultEvent(datawave.webservice.query.result.event.DefaultEvent) EventBase(datawave.webservice.query.result.event.EventBase) QueryExceptionType(datawave.webservice.query.exception.QueryExceptionType)

Example 10 with EventBase

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

the class DefaultEventQueryResponse method setEvents.

/*
     * (non-Javadoc)
     * 
     * @see datawave.webservice.result.EventQueryResponse#setEvents(java.util.List)
     */
@Override
public void setEvents(List<EventBase> entries) {
    if (entries == null) {
        this.events = null;
    } else {
        List<DefaultEvent> events = new ArrayList<>(entries.size());
        for (EventBase event : entries) {
            events.add((DefaultEvent) event);
        }
        this.events = events;
    }
}
Also used : DefaultEvent(datawave.webservice.query.result.event.DefaultEvent) EventBase(datawave.webservice.query.result.event.EventBase) ArrayList(java.util.ArrayList)

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