/// <summary> /// Ctor. /// </summary> /// <param name="evaluators">evaluate the sub-expression within the aggregate function (ie. Sum(4*myNum))</param> /// <param name="prototypes">collect the aggregation state that evaluators evaluate to, act as prototypes for new aggregationsaggregation states for each group</param> /// <param name="groupKeyBinding">The group key binding.</param> /// <param name="methodResolutionService">factory for creating additional aggregation method instances per group key</param> /// <param name="accessors">accessor definitions</param> /// <param name="accessAggregations">access aggs</param> /// <param name="isJoin">true for join, false for single-stream</param> /// <param name="rollupLevelDesc">The rollup level desc.</param> /// <param name="topGroupAggregators">The top group aggregators.</param> /// <param name="topGroupStates">The top group states.</param> public AggSvcGroupByRefcountedWAccessRollupImpl(ExprEvaluator[] evaluators, AggregationMethodFactory[] prototypes, Object groupKeyBinding, MethodResolutionService methodResolutionService, AggregationAccessorSlotPair[] accessors, AggregationStateFactory[] accessAggregations, bool isJoin, AggregationGroupByRollupDesc rollupLevelDesc, AggregationMethod[] topGroupAggregators, AggregationState[] topGroupStates) : base(evaluators, prototypes, groupKeyBinding) { _methodResolutionService = methodResolutionService; _aggregatorsPerGroup = new IDictionary <object, AggregationMethodPairRow> [rollupLevelDesc.NumLevelsAggregation]; _removedKeys = new List <object> [rollupLevelDesc.NumLevelsAggregation]; for (var i = 0; i < rollupLevelDesc.NumLevelsAggregation; i++) { _aggregatorsPerGroup[i] = new Dictionary <Object, AggregationMethodPairRow>(); _removedKeys[i] = new List <Object>(2); } _accessors = accessors; _accessAggregations = accessAggregations; _isJoin = isJoin; _rollupLevelDesc = rollupLevelDesc; _aggregatorTopGroup = new AggregationMethodPairRow(0, topGroupAggregators, topGroupStates); _methodParameterValues = new Object[evaluators.Length]; }
public void ApplyLeave( EventBean[] eventsPerStream, object groupByKeyProvided, ExprEvaluatorContext exprEvaluatorContext) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggregationGroupedApplyEnterLeave(false, LocalGroupByPlan.NumMethods, LocalGroupByPlan.NumAccess, groupByKeyProvided); } if (LocalGroupByPlan.OptionalLevelTop != null) { if (AggregatorsTopLevel == null) { AggregatorsTopLevel = AggSvcGroupByUtil.NewAggregators(LocalGroupByPlan.OptionalLevelTop.MethodFactories); StatesTopLevel = AggSvcGroupByUtil.NewAccesses(exprEvaluatorContext.AgentInstanceId, IsJoin, LocalGroupByPlan.OptionalLevelTop.StateFactories, null, null); } AggregateIntoLeave( LocalGroupByPlan.OptionalLevelTop, AggregatorsTopLevel, StatesTopLevel, eventsPerStream, exprEvaluatorContext); InternalHandleUpdatedTop(); } for (var levelNum = 0; levelNum < LocalGroupByPlan.AllLevels.Length; levelNum++) { var level = LocalGroupByPlan.AllLevels[levelNum]; var partitionEval = level.PartitionEvaluators; var groupByKey = ComputeGroupKey( level, groupByKeyProvided, partitionEval, eventsPerStream, true, exprEvaluatorContext); var row = AggregatorsPerLevelAndGroup[levelNum].Get(groupByKey); if (row == null) { var rowAggregators = AggSvcGroupByUtil.NewAggregators(level.MethodFactories); AggregationState[] rowStates = AggSvcGroupByUtil.NewAccesses(exprEvaluatorContext.AgentInstanceId, IsJoin, level.StateFactories, groupByKey, null); row = new AggregationMethodPairRow(1, rowAggregators, rowStates); AggregatorsPerLevelAndGroup[levelNum].Put(groupByKey, row); } else { row.DecreaseRefcount(); if (row.Refcount <= 0) { RemovedKeys.Add(new Pair <int, object>(levelNum, groupByKey)); } } AggregateIntoLeave(level, row.Methods, row.States, eventsPerStream, exprEvaluatorContext); InternalHandleUpdatedGroup(levelNum, groupByKey, row); } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggregationGroupedApplyEnterLeave(false); } }
public void ApplyEnter(EventBean[] eventsPerStream, object groupByKeyProvided, ExprEvaluatorContext exprEvaluatorContext) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggregationGroupedApplyEnterLeave(true, localGroupByPlan.NumMethods, localGroupByPlan.NumAccess, groupByKeyProvided); } HandleRemovedKeys(); if (localGroupByPlan.OptionalLevelTop != null) { if (AggregatorsTopLevel == null) { AggregatorsTopLevel = methodResolutionService.NewAggregators(localGroupByPlan.OptionalLevelTop.MethodFactories, exprEvaluatorContext.AgentInstanceId, null, null, null); StatesTopLevel = methodResolutionService.NewAccesses(exprEvaluatorContext.AgentInstanceId, isJoin, localGroupByPlan.OptionalLevelTop.StateFactories, null, null, null); } AggregateIntoEnter(localGroupByPlan.OptionalLevelTop, AggregatorsTopLevel, StatesTopLevel, eventsPerStream, exprEvaluatorContext); InternalHandleUpdatedTop(); } for (var levelNum = 0; levelNum < localGroupByPlan.AllLevels.Length; levelNum++) { var level = localGroupByPlan.AllLevels[levelNum]; var partitionEval = level.PartitionEvaluators; var groupByKey = ComputeGroupKey(level, groupByKeyProvided, partitionEval, eventsPerStream, true, exprEvaluatorContext); var row = AggregatorsPerLevelAndGroup[levelNum].Get(groupByKey); if (row == null) { var rowAggregators = methodResolutionService.NewAggregators(level.MethodFactories, exprEvaluatorContext.AgentInstanceId, groupByKey, null, null); var rowStates = methodResolutionService.NewAccesses(exprEvaluatorContext.AgentInstanceId, isJoin, level.StateFactories, groupByKey, null, null); row = new AggregationMethodPairRow(methodResolutionService.GetCurrentRowCount(rowAggregators, rowStates) + 1, rowAggregators, rowStates); AggregatorsPerLevelAndGroup[levelNum].Put(groupByKey, row); } else { row.IncreaseRefcount(); } AggregateIntoEnter(level, row.Methods, row.States, eventsPerStream, exprEvaluatorContext); InternalHandleUpdatedGroup(levelNum, groupByKey, row); } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggregationGroupedApplyEnterLeave(true); } }
public override object GetValue(int column, int agentInstanceId, EvaluateParams evaluateParams) { AggregationLocalGroupByColumn col = LocalGroupByPlan.Columns[column]; if (col.PartitionEvaluators.Length == 0) { if (col.IsMethodAgg) { return(AggregatorsTopLevel[col.MethodOffset].Value); } return(col.Pair.Accessor.GetValue(StatesTopLevel[col.Pair.Slot], evaluateParams)); } var groupByKey = ComputeGroupKey(col.PartitionEvaluators, evaluateParams.EventsPerStream, true, evaluateParams.ExprEvaluatorContext); AggregationMethodPairRow row = AggregatorsPerLevelAndGroup[col.LevelNum].Get(groupByKey); if (col.IsMethodAgg) { return(row.Methods[col.MethodOffset].Value); } return(col.Pair.Accessor.GetValue(row.States[col.Pair.Slot], evaluateParams)); }
public override void ApplyEnter(EventBean[] eventsPerStream, Object groupByKey, ExprEvaluatorContext exprEvaluatorContext) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggregationGroupedApplyEnterLeave(true, Aggregators.Length, AccessAggregations.Length, groupByKey); } HandleRemovedKeys(); var row = AggregatorsPerGroup.Get(groupByKey); // The aggregators for this group do not exist, need to create them from the prototypes AggregationMethod[] groupAggregators; AggregationState[] groupStates; if (row == null) { groupAggregators = AggSvcGroupByUtil.NewAggregators(Aggregators); groupStates = AggSvcGroupByUtil.NewAccesses(exprEvaluatorContext.AgentInstanceId, IsJoin, AccessAggregations, groupByKey, null); row = new AggregationMethodPairRow(1, groupAggregators, groupStates); AggregatorsPerGroup.Put(groupByKey, row); } else { groupAggregators = row.Methods; groupStates = row.States; row.IncreaseRefcount(); } var evaluateParams = new EvaluateParams(eventsPerStream, true, exprEvaluatorContext); // For this row, evaluate sub-expressions, enter result _currentAggregatorMethods = groupAggregators; _currentAggregatorStates = groupStates; for (var j = 0; j < Evaluators.Length; j++) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggNoAccessEnterLeave(true, j, groupAggregators[j], Aggregators[j].AggregationExpression); } var columnResult = Evaluators[j].Evaluate(evaluateParams); groupAggregators[j].Enter(columnResult); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggNoAccessEnterLeave(true, j, groupAggregators[j]); } } for (var i = 0; i < _currentAggregatorStates.Length; i++) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggAccessEnterLeave(true, i, _currentAggregatorStates[i], AccessAggregations[i].AggregationExpression); } _currentAggregatorStates[i].ApplyEnter(eventsPerStream, exprEvaluatorContext); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggAccessEnterLeave(true, i, _currentAggregatorStates[i]); } } InternalHandleGroupUpdate(groupByKey, row); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggregationGroupedApplyEnterLeave(true); } }
public void InternalHandleGroupUpdate(Object groupByKey, AggregationMethodPairRow row) { // no action required }
public override void ApplyEnter(EventBean[] eventsPerStream, Object compositeGroupKey, ExprEvaluatorContext exprEvaluatorContext) { HandleRemovedKeys(); var evaluateParams = new EvaluateParams(eventsPerStream, true, exprEvaluatorContext); for (var i = 0; i < Evaluators.Length; i++) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggregationGroupedRollupEvalParam(true, _methodParameterValues.Length); } _methodParameterValues[i] = Evaluators[i].Evaluate(evaluateParams); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggregationGroupedRollupEvalParam(_methodParameterValues[i]); } } var groupKeyPerLevel = (Object[])compositeGroupKey; for (var i = 0; i < groupKeyPerLevel.Length; i++) { var level = _rollupLevelDesc.Levels[i]; var groupKey = groupKeyPerLevel[i]; AggregationMethodPairRow row; if (!level.IsAggregationTop) { row = _aggregatorsPerGroup[level.AggregationOffset].Get(groupKey); } else { row = _aggregatorTopGroup; } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggregationGroupedApplyEnterLeave(true, Aggregators.Length, _accessAggregations.Length, groupKey); } // The aggregators for this group do not exist, need to create them from the prototypes AggregationMethod[] groupAggregators; AggregationState[] groupStates; if (row == null) { groupAggregators = AggSvcGroupByUtil.NewAggregators(Aggregators); groupStates = AggSvcGroupByUtil.NewAccesses(exprEvaluatorContext.AgentInstanceId, _isJoin, _accessAggregations, groupKey, null); row = new AggregationMethodPairRow(1, groupAggregators, groupStates); if (!level.IsAggregationTop) { _aggregatorsPerGroup[level.AggregationOffset].Put(groupKey, row); } } else { groupAggregators = row.Methods; groupStates = row.States; row.IncreaseRefcount(); } // For this row, evaluate sub-expressions, enter result _currentAggregatorMethods = groupAggregators; _currentAggregatorStates = groupStates; for (var j = 0; j < Evaluators.Length; j++) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggNoAccessEnterLeave(true, j, groupAggregators[j], Aggregators[j].AggregationExpression); } groupAggregators[j].Enter(_methodParameterValues[j]); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggNoAccessEnterLeave(true, j, groupAggregators[j]); } } for (var j = 0; j < _currentAggregatorStates.Length; j++) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggAccessEnterLeave(true, j, _currentAggregatorStates[j], _accessAggregations[j].AggregationExpression); } _currentAggregatorStates[j].ApplyEnter(eventsPerStream, exprEvaluatorContext); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggAccessEnterLeave(true, j, _currentAggregatorStates[j]); } } InternalHandleGroupUpdate(groupKey, row, level); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggregationGroupedApplyEnterLeave(true); } } }
public override void ApplyLeave(EventBean[] eventsPerStream, Object compositeGroupKey, ExprEvaluatorContext exprEvaluatorContext) { var evaluateParams = new EvaluateParams(eventsPerStream, false, exprEvaluatorContext); for (var i = 0; i < Evaluators.Length; i++) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggregationGroupedRollupEvalParam(false, _methodParameterValues.Length); } _methodParameterValues[i] = Evaluators[i].Evaluate(evaluateParams); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggregationGroupedRollupEvalParam(_methodParameterValues[i]); } } var groupKeyPerLevel = (Object[])compositeGroupKey; for (var i = 0; i < groupKeyPerLevel.Length; i++) { var level = _rollupLevelDesc.Levels[i]; var groupKey = groupKeyPerLevel[i]; AggregationMethodPairRow row; if (!level.IsAggregationTop) { row = _aggregatorsPerGroup[level.AggregationOffset].Get(groupKey); } else { row = _aggregatorTopGroup; } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggregationGroupedApplyEnterLeave(false, Aggregators.Length, _accessAggregations.Length, groupKey); } // The aggregators for this group do not exist, need to create them from the prototypes AggregationMethod[] groupAggregators; AggregationState[] groupStates; if (row != null) { groupAggregators = row.Methods; groupStates = row.States; } else { groupAggregators = _methodResolutionService.NewAggregators(Aggregators, exprEvaluatorContext.AgentInstanceId, groupKey, GroupKeyBinding, level); groupStates = _methodResolutionService.NewAccesses(exprEvaluatorContext.AgentInstanceId, _isJoin, _accessAggregations, groupKey, GroupKeyBinding, level); row = new AggregationMethodPairRow(_methodResolutionService.GetCurrentRowCount(groupAggregators, groupStates) + 1, groupAggregators, groupStates); if (!level.IsAggregationTop) { _aggregatorsPerGroup[level.AggregationOffset].Put(groupKey, row); } } // For this row, evaluate sub-expressions, enter result _currentAggregatorMethods = groupAggregators; _currentAggregatorStates = groupStates; for (var j = 0; j < Evaluators.Length; j++) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggNoAccessEnterLeave(false, j, groupAggregators[j], Aggregators[j].AggregationExpression); } groupAggregators[j].Leave(_methodParameterValues[j]); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggNoAccessEnterLeave(false, j, groupAggregators[j]); } } for (var j = 0; j < _currentAggregatorStates.Length; j++) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggAccessEnterLeave(false, j, _currentAggregatorStates[j], _accessAggregations[j].AggregationExpression); } _currentAggregatorStates[j].ApplyLeave(eventsPerStream, exprEvaluatorContext); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggAccessEnterLeave(false, j, _currentAggregatorStates[j]); } } row.DecreaseRefcount(); if (row.Refcount <= 0) { _hasRemovedKey = true; if (!level.IsAggregationTop) { _removedKeys[level.AggregationOffset].Add(groupKey); } _methodResolutionService.RemoveAggregators(exprEvaluatorContext.AgentInstanceId, groupKey, GroupKeyBinding, level); // allow persistence to remove keys already } InternalHandleGroupUpdate(groupKey, row, level); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggregationGroupedApplyEnterLeave(false); } } }
public void InternalHandleUpdatedGroup(int level, object groupByKey, AggregationMethodPairRow row) { // no action required }
public override void ApplyLeave(EventBean[] eventsPerStream, Object groupByKey, ExprEvaluatorContext exprEvaluatorContext) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggregationGroupedApplyEnterLeave(false, Aggregators.Length, AccessAggregations.Length, groupByKey); } var row = AggregatorsPerGroup.Get(groupByKey); // The aggregators for this group do not exist, need to create them from the prototypes AggregationMethod[] groupAggregators; AggregationState[] groupStates; if (row != null) { groupAggregators = row.Methods; groupStates = row.States; } else { groupAggregators = _methodResolutionService.NewAggregators(Aggregators, exprEvaluatorContext.AgentInstanceId, groupByKey, GroupKeyBinding, null); groupStates = _methodResolutionService.NewAccesses(exprEvaluatorContext.AgentInstanceId, IsJoin, AccessAggregations, groupByKey, GroupKeyBinding, null, null); row = new AggregationMethodPairRow(_methodResolutionService.GetCurrentRowCount(groupAggregators, groupStates) + 1, groupAggregators, groupStates); AggregatorsPerGroup.Put(groupByKey, row); } var evaluateParams = new EvaluateParams(eventsPerStream, false, exprEvaluatorContext); // For this row, evaluate sub-expressions, enter result _currentAggregatorMethods = groupAggregators; _currentAggregatorStates = groupStates; for (var j = 0; j < Evaluators.Length; j++) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggNoAccessEnterLeave(false, j, groupAggregators[j], Aggregators[j].AggregationExpression); } var columnResult = Evaluators[j].Evaluate(evaluateParams); groupAggregators[j].Leave(columnResult); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggNoAccessEnterLeave(false, j, groupAggregators[j]); } } for (var i = 0; i < _currentAggregatorStates.Length; i++) { if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().QAggAccessEnterLeave(false, i, _currentAggregatorStates[i], AccessAggregations[i].AggregationExpression); } _currentAggregatorStates[i].ApplyLeave(eventsPerStream, exprEvaluatorContext); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggAccessEnterLeave(false, i, _currentAggregatorStates[i]); } } row.DecreaseRefcount(); if (row.Refcount <= 0) { RemovedKeys.Add(groupByKey); _methodResolutionService.RemoveAggregators(exprEvaluatorContext.AgentInstanceId, groupByKey, GroupKeyBinding, null); // allow persistence to remove keys already } InternalHandleGroupUpdate(groupByKey, row); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.Get().AAggregationGroupedApplyEnterLeave(false); } }