blackmwk commented on code in PR #3514:
URL: https://github.com/apache/iceberg-rust/pull/3514#discussion_r4358524597


##########
crates/iceberg/src/arrow/reader/scan_options.rs:
##########
@@ -0,0 +1,116 @@
+// 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.
+
+use serde::{Deserialize, Serialize};
+
+use super::ArrowReaderBuilder;
+
+/// Reader settings captured from a [`TableScan`](crate::scan::TableScan).
+///
+/// Contains no I/O handles, runtime, or planning state. Apply these options 
to a
+/// locally constructed builder, then build one reader and clone it across
+/// partitions to share its delete-file cache.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
+pub struct TableScanReaderOptions {

Review Comment:
   We should derive typed buidler rather than make field crate visible, all 
fields should be private.



##########
crates/iceberg/src/arrow/reader/scan_options.rs:
##########
@@ -0,0 +1,116 @@
+// 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.
+
+use serde::{Deserialize, Serialize};
+
+use super::ArrowReaderBuilder;
+
+/// Reader settings captured from a [`TableScan`](crate::scan::TableScan).
+///
+/// Contains no I/O handles, runtime, or planning state. Apply these options 
to a
+/// locally constructed builder, then build one reader and clone it across
+/// partitions to share its delete-file cache.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
+pub struct TableScanReaderOptions {

Review Comment:
   ```suggestion
   pub struct ArrowReaderOptions {
   ```



##########
crates/iceberg/src/arrow/reader/scan_options.rs:
##########
@@ -0,0 +1,116 @@
+// 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.
+
+use serde::{Deserialize, Serialize};
+
+use super::ArrowReaderBuilder;
+
+/// Reader settings captured from a [`TableScan`](crate::scan::TableScan).
+///
+/// Contains no I/O handles, runtime, or planning state. Apply these options 
to a
+/// locally constructed builder, then build one reader and clone it across
+/// partitions to share its delete-file cache.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
+pub struct TableScanReaderOptions {
+    pub(crate) batch_size: Option<usize>,
+    pub(crate) data_file_concurrency_limit: usize,
+    pub(crate) row_group_filtering_enabled: bool,
+    pub(crate) row_selection_enabled: bool,
+    pub(crate) bloom_filter_enabled: bool,
+}
+
+impl TableScanReaderOptions {
+    /// The requested record batch size, or the reader default.
+    pub fn batch_size(&self) -> Option<usize> {
+        self.batch_size
+    }
+
+    /// The maximum number of data files read concurrently.
+    pub fn data_file_concurrency_limit(&self) -> usize {
+        self.data_file_concurrency_limit
+    }
+
+    /// Whether row-group filtering is enabled.
+    pub fn row_group_filtering_enabled(&self) -> bool {
+        self.row_group_filtering_enabled
+    }
+
+    /// Whether page-index row selection is enabled.
+    pub fn row_selection_enabled(&self) -> bool {
+        self.row_selection_enabled
+    }
+
+    /// Whether bloom-filter row-group filtering is enabled.
+    pub fn bloom_filter_enabled(&self) -> bool {
+        self.bloom_filter_enabled
+    }
+
+    /// Applies all scan reader settings, preserving the builder's local 
resources
+    /// and Parquet I/O tuning. An unset batch size restores the reader 
default.
+    pub fn apply_to(&self, mut builder: ArrowReaderBuilder) -> 
ArrowReaderBuilder {

Review Comment:
   We should not add this, instead, we should add a `with_options` methods in 
ArrowReaderBuidler and pass in this struct.



##########
crates/iceberg/src/arrow/reader/scan_options.rs:
##########


Review Comment:
   Reanme this to options.



##########
crates/iceberg/src/scan/mod.rs:
##########
@@ -602,23 +602,51 @@ impl TableScan {
 
     /// Returns an [`ArrowRecordBatchStream`].
     pub async fn to_arrow(&self) -> Result<ArrowRecordBatchStream> {
-        let mut arrow_reader_builder =
-            ArrowReaderBuilder::new(self.file_io.clone(), self.runtime.clone())
-                
.with_data_file_concurrency_limit(self.concurrency_limit_data_files)
-                
.with_row_group_filtering_enabled(self.row_group_filtering_enabled)
-                .with_row_selection_enabled(self.row_selection_enabled)
-                .with_bloom_filter_enabled(self.bloom_filter_enabled);
-
-        if let Some(batch_size) = self.batch_size {
-            arrow_reader_builder = 
arrow_reader_builder.with_batch_size(batch_size);
-        }
-
-        arrow_reader_builder
+        self.reader_options()
+            .apply_to(ArrowReaderBuilder::new(
+                self.file_io.clone(),
+                self.runtime.clone(),
+            ))
             .build()
             .read(self.plan_files().await?)
             .map(|result| result.stream())
     }
 
+    /// Captures reader settings independently of this scan's planning state.
+    ///
+    /// Projection, predicates, and delete references are carried by the 
planned
+    /// file tasks; manifest-planning concurrency is not a reader setting.
+    ///
+    /// ```no_run
+    /// # use futures::{TryStreamExt, stream};
+    /// # use iceberg::{Result, Runtime, arrow::ArrowReaderBuilder, 
io::FileIO, table::Table};
+    /// # async fn read(table: &Table, local_io: FileIO, local_runtime: 
Runtime) -> Result<()> {
+    /// let scan = table.scan().with_batch_size(Some(1024)).build()?;
+    /// let options = scan.reader_options();
+    /// let tasks: Vec<_> = scan.plan_files().await?.try_collect().await?;
+    /// drop(scan);
+    ///
+    /// let reader = options
+    ///     .apply_to(ArrowReaderBuilder::new(local_io, local_runtime))
+    ///     .build();
+    /// let batches: Vec<_> = reader
+    ///     .read(Box::pin(stream::iter(tasks.into_iter().map(Ok))))?
+    ///     .stream()
+    ///     .try_collect()
+    ///     .await?;
+    /// # Ok(())
+    /// # }
+    /// ```
+    pub fn reader_options(&self) -> TableScanReaderOptions {

Review Comment:
   No, we should not add this method, and we should remove all methods used to 
config arrow reader options.



##########
crates/iceberg/src/scan/mod.rs:
##########
@@ -602,23 +602,51 @@ impl TableScan {
 
     /// Returns an [`ArrowRecordBatchStream`].
     pub async fn to_arrow(&self) -> Result<ArrowRecordBatchStream> {

Review Comment:
   ```suggestion
       pub async fn to_arrow(&self, options: ArrowReaderOptions) -> 
Result<ArrowRecordBatchStream> {
   ```



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