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


##########
crates/iceberg/src/scan/mod.rs:
##########
@@ -61,6 +64,103 @@ fn resolve_field_id(schema: &Schema, column_name: &str, 
case_sensitive: bool) ->
     }
 }
 
+fn projected_field_ids(
+    schema: &Schema,
+    column_names: Option<&[String]>,
+    case_sensitive: bool,
+) -> Result<Vec<i32>> {
+    let mut field_ids = vec![];
+    let column_names = column_names.map(<[String]>::to_vec).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 = resolve_field_id(schema, column_name, 
case_sensitive).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);
+    }
+
+    Ok(field_ids)
+}
+
+fn bind_scan_predicate(
+    schema: &SchemaRef,
+    predicate: Option<&Predicate>,
+    case_sensitive: bool,
+) -> Result<Option<Arc<BoundPredicate>>> {
+    predicate
+        .map(|predicate| predicate.bind(schema.clone(), case_sensitive))
+        .transpose()
+        .map(|predicate| predicate.map(Arc::new))
+}
+
+fn table_name_mapping(table: &Table) -> Result<Option<Arc<NameMapping>>> {
+    Ok(table
+        .metadata()
+        .properties()
+        .get(DEFAULT_SCHEMA_NAME_MAPPING)
+        .map(|raw| {
+            serde_json::from_str::<NameMapping>(raw).map_err(|error| {
+                Error::new(
+                    ErrorKind::DataInvalid,
+                    format!(
+                        "Failed to parse table property 
{DEFAULT_SCHEMA_NAME_MAPPING} as a NameMapping"
+                    ),
+                )
+                .with_source(error)
+            })
+        })
+        .transpose()?
+        .map(Arc::new))
+}
+
+fn projected_partition_type(
+    table: &Table,
+    schema: &Schema,
+    field_ids: &[i32],
+) -> Result<Option<Arc<StructType>>> {
+    if !field_ids.contains(&RESERVED_FIELD_ID_PARTITION) {
+        return Ok(None);
+    }
+
+    compute_unified_partition_type(
+        table
+            .metadata()
+            .partition_specs_iter()
+            .map(|spec| spec.as_ref()),
+        schema,
+    )
+    .map(Arc::new)
+    .map(Some)

Review Comment:
   Since it's a metadata only operation, I moved it to TableMetadata rather 
than Table, hope that works?



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