// apply new data to aggregates
for (int i = 0; i < newData.length; i++)
{
eventsPerStreamOneStream[0] = newData[i];
Object mk = newDataMultiKey[i];
OutputConditionPolled outputStateGroup = outputState.get(mk);
if (outputStateGroup == null) {
try {
outputStateGroup = OutputConditionPolledFactory.createCondition(prototype.getOutputLimitSpec(), agentInstanceContext);
}
catch (ExprValidationException e) {
log.error("Error starting output limit for group for statement '" + agentInstanceContext.getStatementContext().getStatementName() + "'");
}
outputState.put(newDataMultiKey[i], outputStateGroup);
}
boolean pass = outputStateGroup.updateOutputCondition(1, 0);
if (pass) {
workCollection.put(mk, new EventBean[]{newData[i]});
}
aggregationService.applyEnter(eventsPerStreamOneStream, mk, agentInstanceContext);
}
}
if (oldData != null)
{
// apply new data to aggregates
for (int i = 0; i < oldData.length; i++)
{
eventsPerStreamOneStream[0] = oldData[i];
Object mk = oldDataMultiKey[i];
OutputConditionPolled outputStateGroup = outputState.get(mk);
if (outputStateGroup == null) {
try {
outputStateGroup = OutputConditionPolledFactory.createCondition(prototype.getOutputLimitSpec(), agentInstanceContext);
}
catch (ExprValidationException e) {
log.error("Error starting output limit for group for statement '" + agentInstanceContext.getStatementContext().getStatementName() + "'");
}
outputState.put(oldDataMultiKey[i], outputStateGroup);
}
boolean pass = outputStateGroup.updateOutputCondition(0, 1);
if (pass) {
workCollection.put(mk, new EventBean[]{oldData[i]});
}
aggregationService.applyLeave(eventsPerStreamOneStream, mk, agentInstanceContext);
}
}
// there is no remove stream currently for output first
generateOutputBatchedArr(workCollection, false, generateSynthetic, resultNewEvents, resultNewSortKeys);
}
}
else { // has a having-clause
for (UniformPair<EventBean[]> pair : viewEventsList)
{
EventBean[] newData = pair.getFirst();
EventBean[] oldData = pair.getSecond();
Object[] newDataMultiKey = generateGroupKeys(newData, true);
Object[] oldDataMultiKey = generateGroupKeys(oldData, false);
if (newData != null)
{
// apply new data to aggregates
for (int i = 0; i < newData.length; i++)
{
eventsPerStreamOneStream[0] = newData[i];
Object mk = newDataMultiKey[i];
aggregationService.applyEnter(eventsPerStreamOneStream, mk, agentInstanceContext);
}
}
if (oldData != null)
{
for (int i = 0; i < oldData.length; i++)
{
eventsPerStreamOneStream[0] = oldData[i];
Object mk = oldDataMultiKey[i];
aggregationService.applyLeave(eventsPerStreamOneStream, mk, agentInstanceContext);
}
}
if (newData != null)
{
// check having clause and first-condition
for (int i = 0; i < newData.length; i++)
{
eventsPerStreamOneStream[0] = newData[i];
Object mk = newDataMultiKey[i];
aggregationService.setCurrentAccess(mk, agentInstanceContext.getAgentInstanceId());
// Filter the having clause
Boolean result = (Boolean) prototype.getOptionalHavingNode().evaluate(eventsPerStreamOneStream, true, agentInstanceContext);
if ((result == null) || (!result))
{
continue;
}
OutputConditionPolled outputStateGroup = outputState.get(mk);
if (outputStateGroup == null) {
try {
outputStateGroup = OutputConditionPolledFactory.createCondition(prototype.getOutputLimitSpec(), agentInstanceContext);
}
catch (ExprValidationException e) {
log.error("Error starting output limit for group for statement '" + agentInstanceContext.getStatementContext().getStatementName() + "'");
}
outputState.put(mk, outputStateGroup);
}
boolean pass = outputStateGroup.updateOutputCondition(1, 0);
if (pass) {
workCollection.put(mk, new EventBean[]{newData[i]});
}
}
}
if (oldData != null)
{
// apply new data to aggregates
for (int i = 0; i < oldData.length; i++)
{
eventsPerStreamOneStream[0] = oldData[i];
Object mk = oldDataMultiKey[i];
aggregationService.setCurrentAccess(mk, agentInstanceContext.getAgentInstanceId());
// Filter the having clause
Boolean result = (Boolean) prototype.getOptionalHavingNode().evaluate(eventsPerStreamOneStream, true, agentInstanceContext);
if ((result == null) || (!result))
{
continue;
}
OutputConditionPolled outputStateGroup = outputState.get(mk);
if (outputStateGroup == null) {
try {
outputStateGroup = OutputConditionPolledFactory.createCondition(prototype.getOutputLimitSpec(), agentInstanceContext);
}
catch (ExprValidationException e) {
log.error("Error starting output limit for group for statement '" + agentInstanceContext.getStatementContext().getStatementName() + "'");
}
outputState.put(oldDataMultiKey[i], outputStateGroup);
}
boolean pass = outputStateGroup.updateOutputCondition(0, 1);
if (pass) {
workCollection.put(mk, new EventBean[]{oldData[i]});
}
}
}