0lai0 opened a new pull request, #3798:
URL: https://github.com/apache/datafusion-comet/pull/3798

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax. For example `Closes #123` 
indicates that this PR will close issue #123.
   -->
   
   Closes #3791 
   
   ## Rationale for this change
   
   In `CometScanExec`, calling `getFilePartitions()` unconditionally executes 
`sendDriverMetrics()`. Because `getFilePartitions()` can be evaluated multiple 
times during planning (e.g., converting to `CometNativeScanExec`) and execution 
(e.g., fetching partitions), the `SQLMetric` accumulators like `numFiles` and 
`filesSize` were being duplicated. This led to incorrect double-counted values 
rendering in the Spark UI.
   
   ## What changes are included in this PR?
   
   * Replaced `metrics(...).add()` with `metrics(...).set()` in `CometScanExec` 
to ensure idempotency when reporting metrics. 
   * Wrapped the driver metric updates and Spark listener event dispatching 
inside a `lazy val`. This prevents both double-counting during Catalyst 
transformations (`makeCopy`) and sending redundant UI events.
   
   ## How are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they covered by existing tests)?
   -->
   
   * Added a dedicated end-to-end unit test in `CometExecSuite`.
   * The test writes a dummy Parquet dataset, sequentially triggers multiple UI 
actions (`count` and `collect`) to force severe plan evaluations, and strictly 
asserts that `numFiles` is exactly `2` without any duplication.
   


-- 
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