blackmwk commented on code in PR #2349: URL: https://github.com/apache/iceberg-rust/pull/2349#discussion_r3115858809
########## crates/iceberg/src/arrow/scan_metrics.rs: ########## @@ -0,0 +1,75 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Scan metrics and I/O counting for Parquet data file reads. + +use std::ops::Range; +use std::sync::Arc; +use std::sync::atomic::{AtomicU64, Ordering}; + +use bytes::Bytes; + +use crate::error::Result; +use crate::io::FileRead; + +/// Wraps a [`FileRead`] to count bytes read via a shared atomic counter. +pub(crate) struct CountingFileRead { Review Comment: Is it possible to make this accept a generic parameter as following: ``` struct CountFileRead<F: FileRead> { reader: F } ``` ########## crates/iceberg/src/arrow/reader.rs: ########## @@ -242,34 +244,51 @@ pub struct ArrowReader { parquet_read_options: ParquetReadOptions, } +/// Per-scan state for processing [`FileScanTask`]s. Created once per +/// [`ArrowReader::read`] call and cloned per task. +#[derive(Clone)] +struct FileScanTaskReader { + batch_size: Option<usize>, + file_io: FileIO, + delete_file_loader: CachingDeleteFileLoader, + row_group_filtering_enabled: bool, + row_selection_enabled: bool, + parquet_read_options: ParquetReadOptions, + scan_metrics: ScanMetrics, +} + impl ArrowReader { /// Take a stream of FileScanTasks and reads all the files. - /// Returns a stream of Arrow RecordBatches containing the data from the files + /// Returns a stream of Arrow RecordBatches containing the data from the files. pub fn read(self, tasks: FileScanTaskStream) -> Result<ArrowRecordBatchStream> { - let file_io = self.file_io.clone(); - let batch_size = self.batch_size; + let (stream, _metrics) = self.read_with_metrics(tasks)?; + Ok(stream) + } + + /// Same as [`read`](Self::read), but also returns [`ScanMetrics`] tracking + /// I/O during the scan. + pub fn read_with_metrics( + self, + tasks: FileScanTaskStream, + ) -> Result<(ArrowRecordBatchStream, ScanMetrics)> { Review Comment: I don't like the tuple, maybe a new struct `ScanResult` ? ########## crates/iceberg/src/arrow/reader.rs: ########## @@ -242,34 +244,51 @@ pub struct ArrowReader { parquet_read_options: ParquetReadOptions, } +/// Per-scan state for processing [`FileScanTask`]s. Created once per +/// [`ArrowReader::read`] call and cloned per task. +#[derive(Clone)] +struct FileScanTaskReader { + batch_size: Option<usize>, + file_io: FileIO, + delete_file_loader: CachingDeleteFileLoader, + row_group_filtering_enabled: bool, + row_selection_enabled: bool, + parquet_read_options: ParquetReadOptions, + scan_metrics: ScanMetrics, +} + impl ArrowReader { /// Take a stream of FileScanTasks and reads all the files. - /// Returns a stream of Arrow RecordBatches containing the data from the files + /// Returns a stream of Arrow RecordBatches containing the data from the files. pub fn read(self, tasks: FileScanTaskStream) -> Result<ArrowRecordBatchStream> { - let file_io = self.file_io.clone(); - let batch_size = self.batch_size; + let (stream, _metrics) = self.read_with_metrics(tasks)?; + Ok(stream) + } + + /// Same as [`read`](Self::read), but also returns [`ScanMetrics`] tracking + /// I/O during the scan. + pub fn read_with_metrics( Review Comment: +1, i think it would be beneficial for other users. -- 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]
