use of org.apache.commons.collections4.iterators.TransformIterator in project datawave by NationalSecurityAgency.
the class DashboardQueryLogic method getTransformIterator.
@Override
@SuppressWarnings("unchecked")
public TransformIterator getTransformIterator(Query settings) {
TransformIterator origIter = super.getTransformIterator(settings);
QueryLogicTransformer transformer = super.getTransformer(settings);
DashboardSummary summary = new DashboardSummary(settings.getEndDate());
while (origIter.hasNext()) {
EventBase event = (EventBase) transformer.transform(origIter.next());
DashboardFields.addEvent(summary, event);
}
return new TransformIterator(Arrays.asList(summary).iterator(), this);
}
use of org.apache.commons.collections4.iterators.TransformIterator 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;
}
use of org.apache.commons.collections4.iterators.TransformIterator in project datawave by NationalSecurityAgency.
the class CompositeQueryLogicTest method testQueryLogicNoData.
@Test
public void testQueryLogicNoData() throws Exception {
List<BaseQueryLogic<?>> logics = new ArrayList<>();
TestQueryLogic logic1 = new TestQueryLogic();
TestQueryLogic2 logic2 = new TestQueryLogic2();
logics.add(logic1);
logics.add(logic2);
QueryImpl settings = new QueryImpl();
settings.setPagesize(100);
settings.setQueryAuthorizations(auths.serialize());
settings.setQuery("FOO == 'BAR'");
settings.setParameters(new HashSet<>());
settings.setId(UUID.randomUUID());
CompositeQueryLogic c = new CompositeQueryLogic();
/**
* RunningQuery.setupConnection()
*/
c.setQueryLogics(logics);
c.initialize((Connector) null, (Query) settings, Collections.singleton(auths));
c.setupQuery(null);
TransformIterator iter = c.getTransformIterator((Query) settings);
/**
* RunningQuery.next() - iterate over results coming from tablet server through the TransformIterator to turn them into the objects.
*/
List<Object> results = new ArrayList<>();
while (iter.hasNext()) {
Object o = iter.next();
if (null == o)
break;
Assert.assertTrue(o instanceof TestQueryResponse);
results.add((TestQueryResponse) o);
}
Assert.assertEquals(0, results.size());
c.close();
}
use of org.apache.commons.collections4.iterators.TransformIterator in project datawave by NationalSecurityAgency.
the class CompositeQueryLogicTest method testQueryLogic.
@Test
public // testQueryLogic with max.results.override not set
void testQueryLogic() throws Exception {
Logger.getLogger(CompositeQueryLogic.class).setLevel(Level.TRACE);
Logger.getLogger(CompositeQueryLogicResults.class).setLevel(Level.TRACE);
Logger.getLogger(CompositeQueryLogicTransformer.class).setLevel(Level.TRACE);
List<BaseQueryLogic<?>> logics = new ArrayList<>();
TestQueryLogic logic1 = new TestQueryLogic();
TestQueryLogic2 logic2 = new TestQueryLogic2();
logics.add(logic1);
logics.add(logic2);
logic1.getData().put(key1, value1);
logic1.getData().put(key2, value2);
logic2.getData().put(key3, value3);
logic2.getData().put(key4, value4);
logic1.getData().put(key5, value5);
logic1.getData().put(key6, value6);
logic2.getData().put(key7, value7);
logic2.getData().put(key8, value8);
QueryImpl settings = new QueryImpl();
settings.setPagesize(100);
settings.setQueryAuthorizations(auths.toString());
settings.setQuery("FOO == 'BAR'");
settings.setParameters(new HashSet<>());
settings.setId(UUID.randomUUID());
CompositeQueryLogic c = new CompositeQueryLogic();
// max.results.override is set to -1 when it is not passed in as it is an optional paramter
logic1.setMaxResults(-1);
logic2.setMaxResults(-1);
/**
* RunningQuery.setupConnection()
*/
c.setQueryLogics(logics);
c.initialize((Connector) null, (Query) settings, Collections.singleton(auths));
c.setupQuery(null);
TransformIterator iter = c.getTransformIterator((Query) settings);
/**
* RunningQuery.next() - iterate over results coming from tablet server through the TransformIterator to turn them into the objects.
*/
List<Object> results = new ArrayList<>();
while (iter.hasNext()) {
Object o = iter.next();
if (null == o)
break;
Assert.assertTrue(o instanceof TestQueryResponse);
results.add((TestQueryResponse) o);
}
Assert.assertEquals(8, results.size());
ResultsPage page = new ResultsPage(results, Status.COMPLETE);
/**
* QueryExecutorBean.next() - transform list of objects into JAXB response
*/
TestQueryResponseList response = (TestQueryResponseList) c.getTransformer((Query) settings).createResponse(page);
Assert.assertEquals(8, response.getResponses().size());
for (TestQueryResponse r : response.getResponses()) {
Assert.assertNotNull(r);
}
c.close();
}
use of org.apache.commons.collections4.iterators.TransformIterator in project datawave by NationalSecurityAgency.
the class CompositeQueryLogicTest method testQueryLogicWithMaxResultsOverride.
@Test
public // testQueryLogic with max.results.override is set
void testQueryLogicWithMaxResultsOverride() throws Exception {
Logger.getLogger(CompositeQueryLogic.class).setLevel(Level.TRACE);
Logger.getLogger(CompositeQueryLogicResults.class).setLevel(Level.TRACE);
Logger.getLogger(CompositeQueryLogicTransformer.class).setLevel(Level.TRACE);
List<BaseQueryLogic<?>> logics = new ArrayList<>();
TestQueryLogic logic1 = new TestQueryLogic();
TestQueryLogic2 logic2 = new TestQueryLogic2();
logics.add(logic1);
logics.add(logic2);
logic1.getData().put(key1, value1);
logic1.getData().put(key2, value2);
logic2.getData().put(key3, value3);
logic2.getData().put(key4, value4);
logic1.getData().put(key5, value5);
logic1.getData().put(key6, value6);
logic2.getData().put(key7, value7);
logic2.getData().put(key8, value8);
QueryImpl settings = new QueryImpl();
settings.setPagesize(100);
settings.setQueryAuthorizations(auths.toString());
settings.setQuery("FOO == 'BAR'");
settings.setParameters(new HashSet<>());
settings.setId(UUID.randomUUID());
CompositeQueryLogic c = new CompositeQueryLogic();
// max.results.override is set to -1 when it is not passed in as it is an optional parameter
logic1.setMaxResults(0);
logic2.setMaxResults(4);
/**
* RunningQuery.setupConnection()
*/
c.setQueryLogics(logics);
c.initialize((Connector) null, (Query) settings, Collections.singleton(auths));
c.setupQuery(null);
TransformIterator iter = c.getTransformIterator((Query) settings);
/**
* RunningQuery.next() - iterate over results coming from tablet server through the TransformIterator to turn them into the objects.
*/
List<Object> results = new ArrayList<>();
while (iter.hasNext()) {
Object o = iter.next();
if (null == o)
break;
Assert.assertTrue(o instanceof TestQueryResponse);
results.add((TestQueryResponse) o);
}
Assert.assertEquals(4, results.size());
ResultsPage page = new ResultsPage(results, Status.COMPLETE);
/**
* QueryExecutorBean.next() - transform list of objects into JAXB response
*/
TestQueryResponseList response = (TestQueryResponseList) c.getTransformer((Query) settings).createResponse(page);
Assert.assertEquals(4, response.getResponses().size());
for (TestQueryResponse r : response.getResponses()) {
Assert.assertNotNull(r);
}
c.close();
}
Aggregations