xanderbailey commented on code in PR #2997:
URL: https://github.com/apache/iceberg-rust/pull/2997#discussion_r3842850597


##########
crates/iceberg/src/scan/mod.rs:
##########
@@ -42,14 +44,172 @@ use crate::metadata_columns::{
 };
 use crate::partitioning::compute_unified_partition_type;
 use crate::runtime::Runtime;
-use crate::spec::{DEFAULT_SCHEMA_NAME_MAPPING, DataContentType, NameMapping, 
SnapshotRef};
+use crate::spec::{
+    DEFAULT_SCHEMA_NAME_MAPPING, DataContentType, NameMapping, SchemaRef, 
SnapshotRef,
+};
 use crate::table::Table;
 use crate::util::available_parallelism;
 use crate::{Error, ErrorKind, Result};
 
 /// A stream of arrow [`RecordBatch`]es.
 pub type ArrowRecordBatchStream = BoxStream<'static, Result<RecordBatch>>;
 
+/// Shared configuration extracted from scan builders, used by both
+/// [`TableScanBuilder`] and [`IncrementalAppendScanBuilder`].
+pub(crate) struct ScanConfig<'a> {
+    table: &'a Table,
+    column_names: Option<Vec<String>>,
+    batch_size: Option<usize>,
+    case_sensitive: bool,
+    filter: Option<Predicate>,
+    concurrency_limit_data_files: usize,
+    concurrency_limit_manifest_entries: usize,
+    concurrency_limit_manifest_files: usize,
+    row_group_filtering_enabled: bool,
+    row_selection_enabled: bool,
+    /// Schema to project the scan onto. A standard scan passes the snapshot's
+    /// own schema (the correct behavior for time-travel scans). An incremental
+    /// scan passes the table's current schema so that rows written under an
+    /// older schema in the range are projected onto it (newer columns become
+    /// `NULL`), matching the Java and PyIceberg implementations.
+    schema: SchemaRef,
+}
+
+/// Shared build logic: validates columns, resolves field IDs, binds 
predicates,
+/// and constructs [`PlanContext`] + [`TableScan`].
+pub(crate) fn build_table_scan(
+    config: ScanConfig<'_>,
+    snapshot: SnapshotRef,
+    manifest_file_filter: Option<ManifestFileFilter>,
+    manifest_entry_filter: Option<ManifestEntryFilter>,
+) -> Result<TableScan> {
+    let schema = config.schema.clone();
+
+    // Check that all column names exist in the schema (skip reserved columns).
+    if let Some(column_names) = config.column_names.as_ref() {
+        for column_name in column_names {
+            if is_metadata_column_name(column_name) {
+                continue;
+            }
+            if schema.field_by_name(column_name).is_none() {
+                return Err(Error::new(
+                    ErrorKind::DataInvalid,
+                    format!("Column {column_name} not found in table. Schema: 
{schema}"),
+                ));
+            }
+        }
+    }
+
+    let mut field_ids = vec![];
+    let column_names = config.column_names.clone().unwrap_or_else(|| {
+        schema
+            .as_struct()
+            .fields()
+            .iter()
+            .map(|f| f.name.clone())
+            .collect()
+    });
+
+    for column_name in column_names.iter() {
+        if is_metadata_column_name(column_name) {
+            field_ids.push(get_metadata_field_id(column_name)?);
+            continue;
+        }
+
+        let field_id = schema.field_id_by_name(column_name).ok_or_else(|| {
+            Error::new(
+                ErrorKind::DataInvalid,
+                format!("Column {column_name} not found in table. Schema: 
{schema}"),
+            )
+        })?;
+
+        schema
+            .as_struct()
+            .field_by_id(field_id)
+            .ok_or_else(|| {
+                Error::new(
+                    ErrorKind::FeatureUnsupported,
+                    format!(
+                        "Column {column_name} is not a direct child of schema 
but a nested field, which is not supported now. Schema: {schema}"
+                    ),
+                )
+            })?;
+
+        field_ids.push(field_id);
+    }
+
+    let snapshot_bound_predicate = if let Some(ref predicates) = config.filter 
{
+        Some(predicates.bind(schema.clone(), true)?)

Review Comment:
   Merged and resolved on this branch also.



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