gortiz commented on code in PR #15245: URL: https://github.com/apache/pinot/pull/15245#discussion_r2032823867
########## pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/MultiStageOperator.java: ########## @@ -122,24 +123,37 @@ protected void earlyTerminate() { } } + @Override + public abstract List<MultiStageOperator> getChildOperators(); + /** - * Adds the current operator stats as the last operator in the open stats of the given holder. + * Calculates and returns the stats for the operator. * - * It is assumed that: - * <ol> - * <li>The current stage of the holder is equal to the stage id of this operator.</li> - * <li>The holder already contains the stats of the previous operators of the same stage in inorder</li> - * </ol> + * Each time this method is called, a new instance of the stats is created. This is because the stats are mutable and + * can be updated by the operator or the caller after the stats are returned. */ - protected void addStats(MultiStageQueryStats holder, StatMap<?> statMap) { - Preconditions.checkArgument(holder.getCurrentStageId() == _context.getStageId(), + public final MultiStageQueryStats calculateStats() { + MultiStageQueryStats upstreamStats = calculateUpstreamStats(); + + Preconditions.checkArgument(upstreamStats.getCurrentStageId() == _context.getStageId(), "The holder's stage id should be the same as the current operator's stage id. Expected %s, got %s", - _context.getStageId(), holder.getCurrentStageId()); - holder.getCurrentStats().addLastOperator(getOperatorType(), statMap); + _context.getStageId(), upstreamStats.getCurrentStageId()); + upstreamStats.getCurrentStats().addLastOperator(getOperatorType(), copyStatMaps()); + return upstreamStats; } - @Override - public abstract List<MultiStageOperator> getChildOperators(); + protected MultiStageQueryStats calculateUpstreamStats() { Review Comment: I've added a utility method in MultiStageQueryStats to document how it works -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org