kosiew commented on code in PR #24024:
URL: https://github.com/apache/datafusion/pull/24024#discussion_r3747151790


##########
datafusion/physical-plan/src/aggregates/group_values/metrics.rs:
##########
@@ -19,6 +19,43 @@
 
 use crate::metrics::{ExecutionPlanMetricsSet, MetricBuilder, Time};
 
+#[derive(Clone)]
+pub(crate) struct AggregateArgumentMetrics {
+    argument_times: Vec<Time>,
+}
+
+impl AggregateArgumentMetrics {
+    pub(crate) fn new<T>(
+        metrics: &ExecutionPlanMetricsSet,
+        partition: usize,
+        aggregate_labels: impl IntoIterator<Item = T>,
+    ) -> Self
+    where
+        T: Into<String>,
+    {
+        let argument_times = aggregate_labels
+            .into_iter()
+            .enumerate()
+            .map(|(idx, label)| {
+                MetricBuilder::new(metrics)
+                    .with_new_label("aggregate", label.into())
+                    .subset_time(format!("agg_expr_{idx}_arguments_time"), 
partition)

Review Comment:
   @rluvaton 
   
   The stable indexed metric name is paired with an `aggregate` label built 
from the aggregate display/alias (`aggregate_metric_label`). The regression 
asserts `agg_expr_0_arguments_time, aggregate=SUM(a)` and 
`agg_expr_1_arguments_time, aggregate=SUM(b)`. 
   
   The default view keeps compact indexed names, whose order matches the 
adjacent `aggr=[...]` list.
   `EXPLAIN ANALYZE VERBOSE` renders those labels.
   
   
   Example:
   ```
   cat >/tmp/aggregate_metrics.sql <<'SQL'
   CREATE TABLE t AS
   SELECT
     CAST(value % 100 AS INT) AS k,
     CAST(value AS BIGINT) AS a,
     CAST(value * 2 AS BIGINT) AS b,
     CAST(value % 3 AS BIGINT) AS c
   FROM range(1000000);
   
   EXPLAIN ANALYZE VERBOSE
   SELECT k, SUM(a), SUM(b), COUNT(c)
   FROM t
   GROUP BY k;
   SQL
   
   cargo run -p datafusion-cli -- -q -f /tmp/aggregate_metrics.sql
   ```
   
   The partial `AggregateExec` per-partition metrics include distinct stable 
keys and expression labels, e.g.:
   
   ```text
   agg_expr_0_arguments_time{partition=3, aggregate=sum(t.a)}=...
   agg_expr_1_arguments_time{partition=3, aggregate=sum(t.b)}=...
   agg_expr_2_arguments_time{partition=3, aggregate=count(t.c)}=...
   aggregate_arguments_time{partition=3}=...
   ```
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to