public AggregationGroupByOperatorPlanNode( IndexSegment indexSegment, BrokerRequest query, AggregationGroupByImplementationType aggregationGroupByImplementationType) { _indexSegment = indexSegment; _brokerRequest = query; _aggregationGroupByImplementationType = aggregationGroupByImplementationType; _projectionPlanNode = new ProjectionPlanNode( _indexSegment, getAggregationGroupByRelatedColumns(), new DocIdSetPlanNode(_indexSegment, _brokerRequest)); for (int i = 0; i < _brokerRequest.getAggregationsInfo().size(); ++i) { AggregationInfo aggregationInfo = _brokerRequest.getAggregationsInfo().get(i); AggregationFunctionUtils.ensureAggregationColumnsAreSingleValued( aggregationInfo, _indexSegment); boolean hasDictionary = AggregationFunctionUtils.isAggregationFunctionWithDictionary( aggregationInfo, _indexSegment); _aggregationFunctionGroupByPlanNodes.add( new AggregationFunctionGroupByPlanNode( aggregationInfo, _brokerRequest.getGroupBy(), _projectionPlanNode, _aggregationGroupByImplementationType, hasDictionary)); } }
@Override public void showTree(String prefix) { LOGGER.debug(prefix + "Inner-Segment Plan Node :"); LOGGER.debug(prefix + "Operator: MAggregationGroupByOperator"); LOGGER.debug(prefix + "Argument 0: Projection - "); _projectionPlanNode.showTree(prefix + " "); for (int i = 0; i < _brokerRequest.getAggregationsInfo().size(); ++i) { LOGGER.debug(prefix + "Argument " + (i + 1) + ": AggregationGroupBy - "); _aggregationFunctionGroupByPlanNodes.get(i).showTree(prefix + " "); } }
private String[] getAggregationGroupByRelatedColumns() { Set<String> aggregationGroupByRelatedColumns = new HashSet<String>(); for (AggregationInfo aggregationInfo : _brokerRequest.getAggregationsInfo()) { if (aggregationInfo.getAggregationType().equalsIgnoreCase("count")) { continue; } String columns = aggregationInfo.getAggregationParams().get("column").trim(); aggregationGroupByRelatedColumns.addAll(Arrays.asList(columns.split(","))); } aggregationGroupByRelatedColumns.addAll(_brokerRequest.getGroupBy().getColumns()); return aggregationGroupByRelatedColumns.toArray(new String[0]); }
@Override public Operator run() { List<AggregationFunctionGroupByOperator> aggregationFunctionOperatorList = new ArrayList<AggregationFunctionGroupByOperator>(); for (AggregationFunctionGroupByPlanNode aggregationFunctionGroupByPlanNode : _aggregationFunctionGroupByPlanNodes) { aggregationFunctionOperatorList.add( (AggregationFunctionGroupByOperator) aggregationFunctionGroupByPlanNode.run()); } return new MAggregationGroupByOperator( _indexSegment, _brokerRequest.getAggregationsInfo(), _brokerRequest.getGroupBy(), _projectionPlanNode.run(), aggregationFunctionOperatorList); }
private static List<Map<String, Serializable>> combineAggregationGroupByResults1( BrokerRequest brokerRequest, List<Map<String, Serializable>> list1, List<Map<String, Serializable>> list2) { if (list1 == null) { return list2; } if (list2 == null) { return list1; } for (int i = 0; i < list1.size(); ++i) { list1.set( i, mergeTwoGroupedResults( brokerRequest.getAggregationsInfo().get(i), list1.get(i), list2.get(i))); } return list1; }
@Test public void testInnerSegmentPlanMakerForAggregationGroupByWithFilter() { BrokerRequest brokerRequest = getAggregationGroupByWithFilterBrokerRequest(); brokerRequest.getGroupBy().getColumns().clear(); brokerRequest.getGroupBy().getColumns().add("dim0"); brokerRequest.getGroupBy().getColumns().add("dim1"); PlanMaker instancePlanMaker = new InstancePlanMakerImplV2(); PlanNode rootPlanNode = instancePlanMaker.makeInnerSegmentPlan(_indexSegment, brokerRequest); rootPlanNode.showTree(""); IntermediateResultsBlock resultBlock = (IntermediateResultsBlock) rootPlanNode.run().nextBlock(); LOGGER.debug("RunningTime: {}", resultBlock.getTimeUsedMs()); LOGGER.debug("NumDocsScanned: {}", resultBlock.getNumDocsScanned()); LOGGER.debug("TotalDocs: {}", resultBlock.getTotalRawDocs()); List<Map<String, Serializable>> combinedGroupByResult = resultBlock.getAggregationGroupByOperatorResult(); for (int i = 0; i < combinedGroupByResult.size(); ++i) { LOGGER.debug("function: {}", brokerRequest.getAggregationsInfo().get(i)); for (String keyString : combinedGroupByResult.get(i).keySet()) { LOGGER.debug( "grouped key: {}, value: {}", keyString, combinedGroupByResult.get(i).get(keyString)); } } }