Skip to content

[spark] Support deleted record metrics for V2 delete#8486

Open
kerwin-zk wants to merge 1 commit into
apache:masterfrom
kerwin-zk:v2-delete-record-metrics
Open

[spark] Support deleted record metrics for V2 delete#8486
kerwin-zk wants to merge 1 commit into
apache:masterfrom
kerwin-zk:v2-delete-record-metrics

Conversation

@kerwin-zk

@kerwin-zk kerwin-zk commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Purpose

This PR adds a number of deleted records commit metric for V2 copy-on-write DELETE. The V2 row-level operation path only applies to append tables without deletion vectors or data evolution, so the file-level row counts are exact and the number of deleted records is exactly:

deletedRecords = rowCount(removed files) - rowCount(rewritten files)

The value is computed at commit time from the commit messages (no extra IO) and posted through the existing driver metrics mechanism.

For UPDATE and MERGE, the rewritten files mix copied rows with modified rows, so record-level counts cannot be derived from file statistics and remain unreported.

Tests

Extended PaimonMetricTest ("Paimon Metric: delete") to assert deletedRecords for both a partial-file delete and a whole-file delete.

// For DELETE, the number of deleted records is exactly the row count difference between
// the removed files and the rewritten files. For UPDATE and MERGE, the rewritten files
// mix copied rows with modified rows, so record metrics cannot be derived from file stats.
if (operationType.contains(Snapshot.Operation.DELETE)) {

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.

This condition misses the DELETE plan used by the added test: metrics("deletedRecords") is absent before the write runs. I ran mvn -pl paimon-spark/paimon-spark-ut -am -Pfast-build -DfailIfNoTests=false -DwildcardSuites=org.apache.paimon.spark.sql.PaimonMetricTest -Dtest=none test, and Paimon Metric: delete fails with NoSuchElementException: key not found: deletedRecords at PaimonMetricTest.scala:188. Since Spark builds the command metrics from supportedCustomMetrics, we need to register PaimonDeletedRecordsMetric for the row-level DELETE write path that actually reaches this test, or ensure operationType is populated before supportedCustomMetrics is queried.

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