Skip to content

[GLUTEN-9003][CORE] Carry native counter counts into SQL metrics - #13358

Open
malinjawi wants to merge 4 commits into
apache:mainfrom
malinjawi:feat/native-expression-stats-metrics
Open

malinjawi wants to merge 4 commits into
apache:mainfrom
malinjawi:feat/native-expression-stats-metrics

Conversation

@malinjawi

@malinjawi malinjawi commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Part of #9003. This is the JVM half of #13165, split out to make review easier.

  • IncrementMetricCall (gluten-substrait): an unevaluable pass-through expression that is sent to the backend as a call to one of its counter functions.
  • BackendSettingsApi.supportNativeIncrementMetric(), false by default. The Velox backend turns it on in [GLUTEN-9003][VL] Count Delta's IncrementMetric natively #13165.
  • The Velox metrics path reads the counters' processed-row counts (expressionStats) from the native operator metrics, merges them across operators, and ProjectMetricsUpdater credits each SQL metric from its counter.
  • FilterMetricsUpdater needs no counter branch: Delta's filter counters never run natively. [GLUTEN-9003][VL] Count Delta's IncrementMetric natively #13165 offloads a filter counter only over a literal true, which keeps every row, so it is still credited with the filter's output rows.

Nothing emits IncrementMetricCall yet, so behavior doesn't change. The native functions are in #13357.

How was this patch tested?

New ProjectMetricsUpdaterSuite: a counter is credited with the rows its function processed, a counter that never ran with zero, and the existing increment_metric path still with the output rows.

New MetricsUtilSuite: expressionStats is read from the native metrics JSON (with entries, missing, empty) and summed across merged operators.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: IBM Bob

The JVM side of counting Delta's IncrementMetric natively:

- IncrementMetricCall, an unevaluable pass-through expression that is
  sent to the backend as a call to one of its counter functions.
- BackendSettingsApi.supportNativeIncrementMetric(), false by default.
- The Velox metrics path reads the counters' processed-row counts
  (expressionStats) from the native operator metrics, merges them across
  operators, and ProjectMetricsUpdater credits each SQL metric from its
  counter.

Nothing emits IncrementMetricCall yet, so behavior is unchanged.
@malinjawi

Copy link
Copy Markdown
Contributor Author

cc: @zhouyuan @felipepessoto

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@zhouyuan
zhouyuan requested a balanced review from Copilot October 20, 2026 16:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

5 open issues
What changed in this PR

This PR adds support for carrying native “increment metric” processed-row counts from Velox operator metrics into Spark SQL metrics, introducing a pass-through expression (IncrementMetricCall) and wiring expression-level stats through the Velox metrics pipeline.

Changes:

  • Introduces IncrementMetricCall and backend capability flag supportNativeIncrementMetric().
  • Parses, aggregates, and forwards per-expression processed row counts (expressionStats) from Velox metrics JSON into OperatorMetrics.
  • Updates ProjectMetricsUpdater and adds a new Velox test suite validating native counter crediting behavior.
File Description
shims/​common/​src/​main/​scala/​org/​apache/​gluten/​expression/​ExpressionNames.scala Adds a named expression constant for increment_metric.
gluten-substrait/​src/​main/​scala/​org/​apache/​gluten/​expression/​IncrementMetricCall.scala Adds a new unevaluable pass-through expression used to represent native counter function calls.
gluten-substrait/​src/​main/​scala/​org/​apache/​gluten/​backendsapi/​BackendSettingsApi.scala Adds a backend capability flag for native increment-metric support.
backends-velox/​src/​test/​scala/​org/​apache/​gluten/​metrics/​ProjectMetricsUpdaterSuite.scala Adds unit tests covering the updated counter crediting logic.
backends-velox/​src/​main/​scala/​org/​apache/​gluten/​metrics/​ProjectMetricsUpdater.scala Credits SQL metrics from expressionStats for native counters keyed by function name.
backends-velox/​src/​main/​scala/​org/​apache/​gluten/​metrics/​MetricsUtil.scala Parses expressionStats from JSON and aggregates it across operators.
backends-velox/​src/​main/​scala/​org/​apache/​gluten/​backendsapi/​velox/​VeloxSparkPlanExecApi.scala Wires IncrementMetricCall into the Velox expression signature registry.
backends-velox/​src/​main/​java/​org/​apache/​gluten/​metrics/​OperatorMetrics.java Adds expressionStats field to carry per-expression processed row counts.

Review effort: Lite

…ementMetricCall naming

Addresses review:
- MetricsUtil merges expressionStats into a java.util.HashMap, like the
  one every OperatorMetrics starts with, instead of wrapping a Scala map
  with asJava.
- MetricsUtilSuite covers reading expressionStats from the native
  metrics JSON (with entries, missing, empty) and summing it across
  merged operators.
- IncrementMetricCall documents why it is mapped by class under
  increment_metric while its prettyName stays the slot name: Gluten
  recognizes Delta's IncrementMetric by the name increment_metric.
malinjawi added a commit to malinjawi/incubator-gluten that referenced this pull request Oct 20, 2026
…ementMetricCall naming

Addresses review:
- MetricsUtil merges expressionStats into a java.util.HashMap, like the
  one every OperatorMetrics starts with, instead of wrapping a Scala map
  with asJava.
- MetricsUtilSuite covers reading expressionStats from the native
  metrics JSON (with entries, missing, empty) and summing it across
  merged operators.
- IncrementMetricCall documents why it is mapped by class under
  increment_metric while its prettyName stays the slot name: Gluten
  recognizes Delta's IncrementMetric by the name increment_metric.

Same change as apache#13358.
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Review follow-ups:
- Only Delta's project transformer emits IncrementMetricCall. A filter
  counter is offloaded only over a literal true, which keeps every row, so
  FilterMetricsUpdater keeps crediting its output rows; say so there.
- Fix the IncrementMetricCall and OperatorMetrics docs to match.
- Read a slot's count with getOrDefault.
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CORE works for Gluten Core VELOX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants