Search in sources :

Example 26 with FieldBase

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

the class AbstractFunctionalQuery method runCountTest.

/**
 * Executes test cases that use {@link CountingShardQueryLogic}.
 *
 * @param query
 *            query for evaluation
 * @throws Exception
 *             error condition during execution of query
 */
protected void runCountTest(String query) throws Exception {
    Date[] startEndDate = this.dataManager.getShardStartEndDate();
    if (log.isDebugEnabled()) {
        log.debug("  count query[" + query + "]  start(" + YMD_DateFormat.format(startEndDate[0]) + ")  end(" + YMD_DateFormat.format(startEndDate[1]) + ")");
    }
    QueryImpl q = new QueryImpl();
    q.setBeginDate(startEndDate[0]);
    q.setEndDate(startEndDate[1]);
    q.setQuery(query);
    q.setId(UUID.randomUUID());
    q.setPagesize(Integer.MAX_VALUE);
    q.setQueryAuthorizations(auths.toString());
    RunningQuery runner = new RunningQuery(connector, AccumuloConnectionFactory.Priority.NORMAL, this.countLogic, q, "", principal, new QueryMetricFactoryImpl());
    TransformIterator it = runner.getTransformIterator();
    ShardQueryCountTableTransformer ctt = (ShardQueryCountTableTransformer) it.getTransformer();
    EventQueryResponseBase resp = (EventQueryResponseBase) ctt.createResponse(runner.next());
    Collection<String> expect = getExpectedKeyResponse(query);
    List<EventBase> events = resp.getEvents();
    Assert.assertEquals(1, events.size());
    EventBase<?, ?> event = events.get(0);
    List<?> fields = event.getFields();
    Assert.assertEquals(1, fields.size());
    FieldBase<?> count = (FieldBase) fields.get(0);
    String val = count.getValueString();
    if (log.isDebugEnabled()) {
        log.debug("expected count(" + expect.size() + ") actual count(" + val + ")");
    }
    Assert.assertEquals("" + expect.size(), val);
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) TransformIterator(org.apache.commons.collections4.iterators.TransformIterator) ShardQueryCountTableTransformer(datawave.query.transformer.ShardQueryCountTableTransformer) Date(java.util.Date) EventQueryResponseBase(datawave.webservice.result.EventQueryResponseBase) QueryImpl(datawave.webservice.query.QueryImpl) RunningQuery(datawave.webservice.query.runner.RunningQuery) FieldBase(datawave.webservice.query.result.event.FieldBase) QueryMetricFactoryImpl(datawave.microservice.querymetric.QueryMetricFactoryImpl)

Example 27 with FieldBase

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

the class GroupingTestWithModel 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 genderKey = "";
        String ageKey = "";
        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":
                    genderKey = fieldBase.getValueString();
                    break;
                case "GEN":
                    genderKey = fieldBase.getValueString();
                    break;
                case "AGE":
                    ageKey = fieldBase.getValueString();
                    break;
                case "AG":
                    ageKey = fieldBase.getValueString();
                    break;
            }
        }
        log.debug("mapping is " + genderKey + "-" + ageKey + " count:" + value);
        String key;
        if (!genderKey.isEmpty() && !ageKey.isEmpty()) {
            key = genderKey + "-" + ageKey;
        } else if (!genderKey.isEmpty()) {
            key = genderKey;
        } else {
            key = ageKey;
        }
        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 28 with FieldBase

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

the class GroupingTestWithModel method digest.

// grab the relevant stuff from the events and do some formatting
private List<String> digest(List<List<EventBase>> in) {
    List<String> stringList = new ArrayList<>();
    for (List<EventBase> list : in) {
        StringBuilder builder = new StringBuilder();
        for (EventBase eb : list) {
            for (Object field : eb.getFields()) {
                FieldBase fieldBase = (FieldBase) field;
                builder.append(fieldBase.getName());
                builder.append(':');
                builder.append(fieldBase.getTypedValue().getValue());
                builder.append(',');
            }
        }
        stringList.add(builder.toString() + '\n');
    }
    return stringList;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) ArrayList(java.util.ArrayList) FieldBase(datawave.webservice.query.result.event.FieldBase)

Example 29 with FieldBase

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

the class GroupingTest method testGroupingWithReducedResponse.

@Test
public void testGroupingWithReducedResponse() throws Exception {
    Map<String, String> extraParameters = new HashMap<>();
    Date startDate = format.parse("20091231");
    Date endDate = format.parse("20150101");
    String queryString = "UUID =~ '^[CS].*'";
    Map<String, Integer> expectedMap = ImmutableMap.of("MALE", 10, "FEMALE", 2);
    extraParameters.put("reduced.response", "true");
    extraParameters.put("group.fields", "GENDER");
    extraParameters.put("group.fields.batch.size", "0");
    for (RebuildingScannerTestHelper.TEARDOWN teardown : TEARDOWNS) {
        for (RebuildingScannerTestHelper.INTERRUPT interrupt : INTERRUPTS) {
            EventQueryResponseBase response = (EventQueryResponseBase) runTestQueryWithGrouping(expectedMap, queryString, startDate, endDate, extraParameters, teardown, interrupt);
            for (EventBase event : response.getEvents()) {
                // The event should have a collapsed columnVisibility
                String actualCV = event.getMarkings().get(COLVIS_MARKING).toString();
                Assert.assertEquals(EXPECTED_COLVIS, actualCV);
                // The fields should have no columnVisibility
                for (Object f : event.getFields()) {
                    FieldBase<?> field = (FieldBase<?>) f;
                    Assert.assertNull(field.getMarkings().get(COLVIS_MARKING));
                }
            }
        }
    }
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) HashMap(java.util.HashMap) Date(java.util.Date) EventQueryResponseBase(datawave.webservice.result.EventQueryResponseBase) FieldBase(datawave.webservice.query.result.event.FieldBase) RebuildingScannerTestHelper(datawave.query.RebuildingScannerTestHelper) Test(org.junit.Test)

Example 30 with FieldBase

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

the class GroupingTest method digest.

// grab the relevant stuff from the events and do some formatting
private List<String> digest(List<List<EventBase>> in) {
    List<String> stringList = new ArrayList<>();
    for (List<EventBase> list : in) {
        StringBuilder builder = new StringBuilder();
        for (EventBase eb : list) {
            for (Object field : eb.getFields()) {
                FieldBase fieldBase = (FieldBase) field;
                builder.append(fieldBase.getName());
                builder.append(':');
                builder.append(fieldBase.getTypedValue().getValue());
                builder.append(',');
            }
        }
        stringList.add(builder.toString() + '\n');
    }
    return stringList;
}
Also used : EventBase(datawave.webservice.query.result.event.EventBase) ArrayList(java.util.ArrayList) 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