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


##########
crates/datafusion/src/read/builder.rs:
##########
@@ -0,0 +1,453 @@
+// 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.
+
+//! Session-configured construction of table scans and already-planned scans.
+
+use std::fmt::{Debug, Formatter};
+use std::sync::Arc;
+
+use datafusion::arrow::datatypes::SchemaRef;
+use datafusion::common::Result;
+use datafusion::datasource::source::DataSource;
+use datafusion::execution::TaskContext;
+use datafusion::prelude::Expr;
+use iceberg::arrow::ArrowReader;
+use iceberg::expr::Predicate;
+use iceberg::io::FileIO;
+use iceberg::scan::FileScanTask;
+use iceberg::table::Table;
+
+use super::eager::EagerIcebergDataSource;
+use super::file_planning::PlannedFileScan;
+use super::predicate::convert_filters_to_predicate;
+use super::scan::{IcebergDataSource, build_table_scan};
+use crate::IcebergDataFusionConfig;
+
+/// Builds a scan using the session settings and memory pool in a task context.
+///
+/// Obtain the context from `SessionContext::task_ctx()` or the `Session` 
passed to
+/// a table provider. Eager planning, target partitions, batch size and 
page-index
+/// settings come from that context, not separate builder options.
+///
+/// Select either a table or already-planned files after supplying the schema.
+/// Only table input exposes discovery projection, snapshot and filter 
settings.
+/// Table scans finish asynchronously; reconstruction finishes synchronously 
and
+/// never discovers files. Both return an `Arc<dyn DataSource>`.
+///
+/// ```
+/// # use datafusion::arrow::datatypes::SchemaRef;
+/// # use datafusion::common::Result;
+/// # use datafusion::datasource::source::DataSource;
+/// # use datafusion::execution::TaskContext;
+/// # use iceberg::table::Table;
+/// # use iceberg_datafusion::read::IcebergDataSourceBuilder;
+/// # use std::sync::Arc;
+/// async fn scan(table: Table, schema: SchemaRef, context: &TaskContext)
+///     -> Result<Arc<dyn DataSource>>
+/// {
+///     IcebergDataSourceBuilder::new(context)
+///         .with_schema(schema)
+///         .with_table(table)
+///         .build()
+///         .await
+/// }
+/// ```
+///
+/// Reconstruction uses the same entry point but has no asynchronous discovery:
+/// ```
+/// # use datafusion::arrow::datatypes::SchemaRef;
+/// # use datafusion::common::Result;
+/// # use datafusion::datasource::source::DataSource;
+/// # use datafusion::execution::TaskContext;
+/// # use iceberg::arrow::ArrowReader;
+/// # use iceberg::io::FileIO;
+/// # use iceberg::scan::FileScanTask;
+/// # use iceberg_datafusion::read::IcebergDataSourceBuilder;
+/// # use std::sync::Arc;
+/// fn restore(context: &TaskContext, schema: SchemaRef,
+///     groups: Vec<Vec<FileScanTask>>, file_io: FileIO, reader: ArrowReader)
+///     -> Result<Arc<dyn DataSource>>
+/// {
+///     IcebergDataSourceBuilder::new(context)
+///         .with_schema(schema)
+///         .with_planned_files(groups)
+///         .with_file_io(file_io)
+///         .with_reader(reader)
+///         .build()
+/// }
+/// ```
+///
+/// Planned input cannot request snapshot discovery:
+/// ```compile_fail,E0599
+/// # use datafusion::arrow::datatypes::SchemaRef;
+/// # use datafusion::execution::TaskContext;
+/// # use iceberg::arrow::ArrowReader;
+/// # use iceberg::io::FileIO;
+/// # use iceberg::scan::FileScanTask;
+/// # use iceberg_datafusion::read::IcebergDataSourceBuilder;
+/// fn invalid(context: &TaskContext, schema: SchemaRef,
+///     groups: Vec<Vec<FileScanTask>>, file_io: FileIO, reader: ArrowReader)
+/// {
+///     IcebergDataSourceBuilder::new(context)
+///         .with_schema(schema)
+///         .with_planned_files(groups)
+///         .with_file_io(file_io)
+///         .with_reader(reader)
+///         .with_snapshot_id(Some(1));
+/// }
+/// ```
+///
+/// Reconstruction cannot finish without a process-local reader:
+/// ```compile_fail,E0599
+/// # use datafusion::arrow::datatypes::SchemaRef;
+/// # use datafusion::execution::TaskContext;
+/// # use iceberg::io::FileIO;
+/// # use iceberg::scan::FileScanTask;
+/// # use iceberg_datafusion::read::IcebergDataSourceBuilder;
+/// fn invalid(context: &TaskContext, schema: SchemaRef,
+///     groups: Vec<Vec<FileScanTask>>, file_io: FileIO)
+/// {
+///     IcebergDataSourceBuilder::new(context)
+///         .with_schema(schema)
+///         .with_planned_files(groups)
+///         .with_file_io(file_io)
+///         .build();
+/// }
+/// ```
+#[derive(Clone)]
+#[must_use]
+pub struct IcebergDataSourceBuilder<'a, Input = NeedsSchema> {
+    context: &'a TaskContext,
+    input: Input,
+    fetch: Option<usize>,

Review Comment:
   For the file scan task provider I know it works for lazy that was. The file 
scan task provider I have a PR either open or in draft for it, not sure it'll 
solve the eager use case entirely though.



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