Skip to content

[SPARK-56598][SQL] Custom metrics support for TruncatableTable#55511

Closed
ZiyaZa wants to merge 8 commits intoapache:masterfrom
ZiyaZa:custom-metrics
Closed

[SPARK-56598][SQL] Custom metrics support for TruncatableTable#55511
ZiyaZa wants to merge 8 commits intoapache:masterfrom
ZiyaZa:custom-metrics

Conversation

@ZiyaZa
Copy link
Copy Markdown
Contributor

@ZiyaZa ZiyaZa commented Apr 23, 2026

What changes were proposed in this pull request?

Added support for connectors to provide custom metrics in Truncate and Delete operations. Refactored the existing custom metrics logic to be reusable across different plan nodes.

Why are the changes needed?

For connectors to provide metric values.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Existing tests.

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

Generated-by: Claude Opus 4.7

@ZiyaZa ZiyaZa changed the title [SQL] Custom metrics support for TruncatableTable [SPARK-56598][SQL] Custom metrics support for TruncatableTable Apr 23, 2026

override protected def run(): Seq[InternalRow] = {
table.deleteWhere(condition)
postDriverMetrics(table.reportDriverMetrics())
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.

Do we need to move this into a finally block?

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.

Similar to V2ExistingTableWriteExec?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved to finally.

* Returns an array of supported custom metrics with name and description.
* By default it returns empty array.
*/
default CustomMetric[] supportedCustomMetrics() {
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.

Do we need @since for the new methods?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added.

*/
protected def createCustomMetrics(metrics: Array[CustomMetric]): Map[String, SQLMetric] = {
metrics.map { m =>
m.name() -> SQLMetrics.createV2CustomMetric(sparkContext, m)
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.

Minor: m.name() -> m.name for simple getter access

}
val executionId = sparkContext.getLocalProperty(SQLExecution.EXECUTION_ID_KEY)
SQLMetrics.postDriverMetricUpdates(
sparkContext, executionId, updated.toImmutableArraySeq)
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.

Can this entire method call fit on one line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It fits.

Copy link
Copy Markdown
Contributor

@aokolnychyi aokolnychyi left a comment

Choose a reason for hiding this comment

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

A few minor nits.

@aokolnychyi
Copy link
Copy Markdown
Contributor

@ZiyaZa, test failures seem unrelated? Can you check?

@aokolnychyi
Copy link
Copy Markdown
Contributor

Looks like there is a conflict too.

ZiyaZa added 3 commits April 29, 2026 07:51
# Conflicts:
#	sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/WriteToDataSourceV2Exec.scala
# Conflicts:
#	sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/DeleteFromTableExec.scala
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants