for (EventBean aNewData : newData)
{
EventBean[] eventsPerStream = new EventBean[] {aNewData};
Object mk = generateGroupKey(eventsPerStream, true);
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) {
// if this is a newly encountered group, generate the remove stream event
if (groupRepsView.put(mk, eventsPerStream) == null)
{
if (prototype.isSelectRStream())
{
generateOutputBatched(false, mk, eventsPerStream, false, generateSynthetic, oldEvents, oldEventsSortKey);
}
}
}
aggregationService.applyEnter(eventsPerStream, mk, agentInstanceContext);
}
}
if (oldData != null)
{
// apply old data to aggregates
for (EventBean anOldData : oldData)
{
EventBean[] eventsPerStream = new EventBean[] {anOldData};
Object mk = generateGroupKey(eventsPerStream, true);
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(0, 1);
if (pass) {
if (groupRepsView.put(mk, eventsPerStream) == null)
{
if (prototype.isSelectRStream())
{
generateOutputBatched(false, mk, eventsPerStream, false, generateSynthetic, oldEvents, oldEventsSortKey);
}
}
}
aggregationService.applyLeave(eventsPerStream, mk, agentInstanceContext);
}
}
}
}
else { // having clause present, having clause evaluates at the level of individual posts
EventBean[] eventsPerStreamOneStream = new EventBean[1];
groupRepsView.clear();
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];
aggregationService.applyEnter(eventsPerStreamOneStream, newDataMultiKey[i], agentInstanceContext);
}
}
if (oldData != null)
{
// apply old data to aggregates
for (int i = 0; i < oldData.length; i++)
{
eventsPerStreamOneStream[0] = oldData[i];
aggregationService.applyLeave(eventsPerStreamOneStream, oldDataMultiKey[i], agentInstanceContext);
}
}
// evaluate having-clause
if (newData != null)
{
for (int i = 0; i < newData.length; i++)
{
Object mk = newDataMultiKey[i];
eventsPerStreamOneStream[0] = newData[i];
aggregationService.setCurrentAccess(mk, agentInstanceContext.getAgentInstanceId(), null);
// Filter the having clause
if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().qHavingClauseNonJoin(newData[i]);}
Boolean result = (Boolean) prototype.getOptionalHavingNode().evaluate(eventsPerStreamOneStream, true, agentInstanceContext);
if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().aHavingClauseNonJoin(result);}
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(0, 1);
if (pass) {
EventBean[] eventsPerStream = new EventBean[] {newData[i]};
if (groupRepsView.put(mk, eventsPerStream) == null)
{
if (prototype.isSelectRStream())
{
generateOutputBatched(false, mk, eventsPerStream, true, generateSynthetic, oldEvents, oldEventsSortKey);
}
}
}
}
}
// evaluate having-clause
if (oldData != null)
{
for (int i = 0; i < oldData.length; i++)
{
Object mk = oldDataMultiKey[i];
eventsPerStreamOneStream[0] = oldData[i];
aggregationService.setCurrentAccess(mk, agentInstanceContext.getAgentInstanceId(), null);
// Filter the having clause
if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().qHavingClauseNonJoin(oldData[i]);}
Boolean result = (Boolean) prototype.getOptionalHavingNode().evaluate(eventsPerStreamOneStream, false, agentInstanceContext);
if (InstrumentationHelper.ENABLED) { InstrumentationHelper.get().aHavingClauseNonJoin(result);}
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(0, 1);
if (pass) {
EventBean[] eventsPerStream = new EventBean[] {oldData[i]};
if (groupRepsView.put(mk, eventsPerStream) == null)
{
if (prototype.isSelectRStream())