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);
}
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;
}
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;
}
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));
}
}
}
}
}
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;
}
Aggregations