fix: Native_datafusion reports correct files and bytes scanned#3798
fix: Native_datafusion reports correct files and bytes scanned#3798comphead merged 2 commits intoapache:mainfrom
Conversation
There was a problem hiding this comment.
So basically it's an artifact of wrapping CometNativeScan in CometScan, which we hopefully won't do in the future anyway.
Thanks for the fix in the meantime, @0lai0!
| spark.range(100).repartition(2).write.mode("overwrite").parquet(path) | ||
|
|
||
| withSQLConf( | ||
| CometConf.COMET_ENABLED.key -> "true", |
There was a problem hiding this comment.
Please include --conf spark.comet.scan.impl=native_datafusion
There was a problem hiding this comment.
Thanks @comphead for review. I added this to the latest commit.
|
Thank you all for the feedback. I’ll investigate this matter and fix it. |
|
Marking this as draft so we don't accidentally merge it, feel free to flip it back when it's ready for another look. Thanks @0lai0! |
|
Thanks @mbutrovich . I'm still investigating the issue and trying to reproduce the scenario, but I haven't identified the root cause yet. |
|
Thank you all for the review. After checking further, I've simplified the fix by changing |
|
Checking, btw output_rows looks already also fixed in #3842 testing num Files |
| } | ||
|
|
||
| test("Native_datafusion reports correct files and bytes scanned") { | ||
| withTempDir { dir => |
There was a problem hiding this comment.
| withTempDir { dir => | |
| val inputFiles = 2 | |
| withTempDir { dir => |
| test("Native_datafusion reports correct files and bytes scanned") { | ||
| withTempDir { dir => | ||
| val path = new java.io.File(dir, "test_metrics").getAbsolutePath | ||
| spark.range(100).repartition(2).write.mode("overwrite").parquet(path) |
There was a problem hiding this comment.
| spark.range(100).repartition(2).write.mode("overwrite").parquet(path) | |
| spark.range(100).repartition(inputFiles).write.mode("overwrite").parquet(path) |
|
|
||
| val numFiles = scanNode.metrics("numFiles").value | ||
| assert( | ||
| numFiles == 2, |
There was a problem hiding this comment.
| numFiles == 2, | |
| numFiles == inputFiles, |
| val numFiles = scanNode.metrics("numFiles").value | ||
| assert( | ||
| numFiles == 2, | ||
| s"Expected exactly 2 files to be scanned, but got metrics reporting $numFiles") |
There was a problem hiding this comment.
| s"Expected exactly 2 files to be scanned, but got metrics reporting $numFiles") | |
| s"Expected exactly $inputFiles files to be scanned, but got metrics reporting $numFiles") |
|
I went ahead with the merge to test it sooner |
|
Hi @comphead , apologies for the late reply! Thanks for taking care of the merge to test it sooner. I'll open a quick follow-up PR shortly to polish the test as you suggested. |

Which issue does this PR close?
Closes #3791
Rationale for this change
In
CometScanExec, callinggetFilePartitions()unconditionally executessendDriverMetrics(). BecausegetFilePartitions()can be evaluated multiple times during planning (e.g., converting toCometNativeScanExec) and execution (e.g., fetching partitions), theSQLMetricaccumulators likenumFilesandfilesSizewere being duplicated. This led to incorrect double-counted values rendering in the Spark UI.What changes are included in this PR?
metrics(...).add()withmetrics(...).set()inCometScanExecto ensure idempotency when reporting metrics.lazy val. This prevents both double-counting during Catalyst transformations (makeCopy) and sending redundant UI events.How are these changes tested?
CometExecSuite.countandcollect) to force severe plan evaluations, and strictly asserts thatnumFilesis exactly2without any duplication.