alexanderbianchi commented on code in PR #113:
URL: 
https://github.com/apache/datafusion-iceberg/pull/113#discussion_r4622543071


##########
crates/datafusion/src/read/scan.rs:
##########
@@ -15,162 +15,210 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::pin::Pin;
+use std::fmt::{Debug, Formatter};
 use std::sync::Arc;
 
-use datafusion::arrow::array::RecordBatch;
+use super::file_scan_task_provider::{FileScanTaskProvider, 
FileScanTaskProviderContext};
+use crate::to_datafusion_error;
+
 use datafusion::arrow::datatypes::SchemaRef as ArrowSchemaRef;
-use datafusion::common::Statistics;
 use datafusion::common::tree_node::TreeNodeRecursion;
+use datafusion::common::{Statistics, exec_datafusion_err, exec_err};
 use datafusion::datasource::source::DataSource;
 use datafusion::error::Result;
 use datafusion::execution::{SendableRecordBatchStream, TaskContext};
 use datafusion::physical_expr::projection::ProjectionExprs;
 use datafusion::physical_expr::{EquivalenceProperties, PhysicalExpr};
+use datafusion::physical_plan::limit::LimitStream;
+use datafusion::physical_plan::metrics::{BaselineMetrics, 
ExecutionPlanMetricsSet};
 use datafusion::physical_plan::stream::RecordBatchStreamAdapter;
 use datafusion::physical_plan::{DisplayFormatType, Partitioning};
-use datafusion::prelude::Expr;
-use futures::{Stream, TryStreamExt};
-use iceberg::expr::Predicate;
-use iceberg::table::Table;
-
-use super::predicate::convert_filters_to_predicate;
-use crate::to_datafusion_error;
+use datafusion::prelude::SessionConfig;
+use futures::TryStreamExt;
+use iceberg::arrow::{ArrowReader, ArrowReaderBuilder};
+use iceberg::io::FileIO;
 
-/// Manages the scanning process of an Iceberg [`Table`], encapsulating the
-/// necessary details and computed properties required for execution planning.
-#[derive(Debug, Clone)]
+/// Reads the tasks of a [`FileScanTaskProvider`] using a process-local reader.
+///
+/// The source does not require a table. Lazy discovery retains its table in 
the
+/// provider; eager and remote providers can supply tasks without one. The 
reader
+/// is shared across partitions, including its loaded delete files and 
settings.
+#[derive(Clone)]
 pub struct IcebergDataSource {
-    /// A table in the catalog.
-    table: Table,
-    /// Snapshot of the table to scan.
-    snapshot_id: Option<i64>,
-    /// Schema returned by this data source after projection.
     schema: ArrowSchemaRef,
-    /// Projection column names in the output schema.
-    projection: Vec<String>,
-    /// Filter to apply to the table scan
-    predicate: Option<Predicate>,
-    /// Optional limit on the number of rows to return
+    file_io: FileIO,
+    reader: ArrowReader,
     fetch: Option<usize>,
+    file_scan_task_provider: Arc<dyn FileScanTaskProvider>,
+    metrics: ExecutionPlanMetricsSet,
+}
+
+impl Debug for IcebergDataSource {
+    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("IcebergDataSource")
+            .field("schema", &self.schema)
+            .field("fetch", &self.fetch)
+            .field("file_scan_task_provider", &self.file_scan_task_provider)
+            .finish_non_exhaustive()
+    }
 }
 
 impl IcebergDataSource {
-    /// Starts building a source that scans `table` and returns the columns of
-    /// `schema`, all of them unless 
[`IcebergDataSourceBuilder::with_projection`]
-    /// selects some. Columns are read from Iceberg by name.
-    pub fn builder(table: Table, schema: ArrowSchemaRef) -> 
IcebergDataSourceBuilder {
+    /// Starts source construction with session reader settings and explicit 
local
+    /// storage/runtime resources. `reader` must use the supplied `file_io`.
+    /// Batch size and page-index settings come from `config`; file concurrency
+    /// defaults to one because DataFusion runs partitions concurrently.
+    /// A later [`IcebergDataSourceBuilder::with_reader`] overrides these 
defaults.
+    /// No discovery or current-runtime lookup is performed, even with eager
+    /// planning enabled: the caller supplies the task provider explicitly.
+    pub fn builder(
+        config: &SessionConfig,
+        schema: ArrowSchemaRef,
+        file_io: FileIO,
+        reader: ArrowReaderBuilder,
+    ) -> IcebergDataSourceBuilder {
         IcebergDataSourceBuilder {
-            table,
             schema,
-            projection: None,
-            snapshot_id: None,
-            predicate: None,
+            file_io,
+            reader: reader
+                .with_batch_size(config.batch_size())
+                .with_row_selection_enabled(
+                    config.options().execution.parquet.enable_page_index,
+                )
+                .with_data_file_concurrency_limit(1)
+                .build(),
             fetch: None,
+            file_scan_task_provider: None,

Review Comment:
   I'd say we keep the builder. I find it easier to read code composing 
builders rather then code that switches between construction styles. And there 
could be other things that come up.



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