You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "xudong963 (via GitHub)" <gi...@apache.org> on 2026/02/12 10:25:52 UTC
[PR] Add metrics for parquet sink [datafusion]
xudong963 opened a new pull request, #20307:
URL: https://github.com/apache/datafusion/pull/20307
## 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 #.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## 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)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add metrics for parquet sink [datafusion]
Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 commented on PR #20307:
URL: https://github.com/apache/datafusion/pull/20307#issuecomment-3981032290
@kosiew thanks for the review, applied your suggestions in the [commit](https://github.com/apache/datafusion/pull/20307/changes/50d3d0f15ece648c03f7e06ccce9c6dc386399cc)
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add metrics for parquet sink [datafusion]
Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 commented on code in PR #20307:
URL: https://github.com/apache/datafusion/pull/20307#discussion_r2869757453
##########
datafusion/datasource-parquet/src/file_format.rs:
##########
@@ -1333,6 +1339,14 @@ impl FileSink for ParquetSink {
mut file_stream_rx: DemuxedStreamReceiver,
object_store: Arc<dyn ObjectStore>,
) -> Result<u64> {
+ let rows_written_counter =
+ MetricBuilder::new(&self.metrics).global_counter("rows_written");
Review Comment:
Makes sense, I'll open an issue and make a follow-up PR for this.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add metrics for parquet sink [datafusion]
Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 commented on code in PR #20307:
URL: https://github.com/apache/datafusion/pull/20307#discussion_r2869756600
##########
datafusion/datasource-parquet/src/file_format.rs:
##########
@@ -1410,12 +1424,18 @@ impl FileSink for ParquetSink {
}
}
- let mut row_count = 0;
while let Some(result) = file_write_tasks.join_next().await {
match result {
Ok(r) => {
let (path, parquet_meta_data) = r?;
- row_count += parquet_meta_data.file_metadata().num_rows();
+ let file_rows = parquet_meta_data.file_metadata().num_rows() as usize;
+ let file_bytes: usize = parquet_meta_data
+ .row_groups()
+ .iter()
+ .map(|rg| rg.compressed_size() as usize)
+ .sum();
+ rows_written_counter.add(file_rows);
+ bytes_written_counter.add(file_bytes);
Review Comment:
Good point, I think `bytes_written` is the intuitive name that users expect for a sink metric. I'd like to keep the name `bytes_written` but adding a brief doc comment explaining what it measures.
(Renaming to `compressed_row_group_bytes` is overly verbose and would surprise users familiar with standard sink metrics. )
##########
datafusion/core/src/dataframe/parquet.rs:
##########
@@ -430,6 +430,149 @@ mod tests {
Ok(())
}
+ /// Test that ParquetSink exposes rows_written, bytes_written, and
+ /// elapsed_compute metrics via DataSinkExec.
+ #[tokio::test]
+ async fn test_parquet_sink_metrics() -> Result<()> {
+ use arrow::array::Int32Array;
+ use arrow::datatypes::{DataType, Field, Schema};
+ use arrow::record_batch::RecordBatch;
+ use datafusion_execution::TaskContext;
+
+ use futures::TryStreamExt;
+
+ let ctx = SessionContext::new();
+ let tmp_dir = TempDir::new()?;
+ let output_path = tmp_dir.path().join("metrics_test.parquet");
+ let output_path_str = output_path.to_str().unwrap();
+
+ // Register a table with 100 rows
+ let schema = Arc::new(Schema::new(vec![
+ Field::new("id", DataType::Int32, false),
+ Field::new("val", DataType::Int32, false),
+ ]));
+ let ids: Vec<i32> = (0..100).collect();
+ let vals: Vec<i32> = (100..200).collect();
+ let batch = RecordBatch::try_new(
+ Arc::clone(&schema),
+ vec![
+ Arc::new(Int32Array::from(ids)),
+ Arc::new(Int32Array::from(vals)),
+ ],
+ )?;
+ ctx.register_batch("source", batch)?;
+
+ // Create the physical plan for COPY TO
+ let df = ctx
+ .sql(&format!(
+ "COPY source TO '{output_path_str}' STORED AS PARQUET"
+ ))
+ .await?;
+ let plan = df.create_physical_plan().await?;
+
+ // Execute the plan
+ let task_ctx = Arc::new(TaskContext::from(&ctx.state()));
+ let stream = plan.execute(0, task_ctx)?;
+ let _batches: Vec<_> = stream.try_collect().await?;
+
+ // Check metrics on the DataSinkExec (top-level plan)
+ let metrics = plan
+ .metrics()
+ .expect("DataSinkExec should return metrics from ParquetSink");
+ let aggregated = metrics.aggregate_by_name();
+
+ // rows_written should be 100
+ let rows_written = aggregated
+ .iter()
+ .find(|m| m.value().name() == "rows_written")
+ .expect("should have rows_written metric");
Review Comment:
Good point!
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add metrics for parquet sink [datafusion]
Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 merged PR #20307:
URL: https://github.com/apache/datafusion/pull/20307
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add metrics for parquet sink [datafusion]
Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 commented on code in PR #20307:
URL: https://github.com/apache/datafusion/pull/20307#discussion_r2871902154
##########
datafusion/datasource-parquet/src/file_format.rs:
##########
@@ -1333,6 +1339,14 @@ impl FileSink for ParquetSink {
mut file_stream_rx: DemuxedStreamReceiver,
object_store: Arc<dyn ObjectStore>,
) -> Result<u64> {
+ let rows_written_counter =
+ MetricBuilder::new(&self.metrics).global_counter("rows_written");
Review Comment:
opened an issue https://github.com/apache/datafusion/issues/20644
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org