tokoko commented on code in PR #12800:
URL: https://github.com/apache/datafusion/pull/12800#discussion_r1792372978


##########
datafusion/substrait/src/logical_plan/consumer.rs:
##########
@@ -990,24 +978,46 @@ pub async fn from_substrait_rel(
 fn ensure_schema_compatability(
     table: DataFrame,
     substrait_schema: DFSchema,
-) -> Result<DataFrame> {
-    let df_schema = table.schema().to_owned().strip_qualifiers();
+) -> Result<LogicalPlan> {
+    let df_schema = table.schema().to_owned();
+
+    let t = table.into_unoptimized_plan();
+
     if df_schema.logically_equivalent_names_and_types(&substrait_schema) {
-        return Ok(table);
+        return Ok(t);
     }
-    let selected_columns = substrait_schema
-        .strip_qualifiers()
-        .fields()
-        .iter()
-        .map(|substrait_field| {
-            let df_field =
-                df_schema.field_with_unqualified_name(substrait_field.name())?;
-            ensure_field_compatability(df_field, substrait_field)?;
-            Ok(col(format!("\"{}\"", df_field.name())))
-        })
-        .collect::<Result<_>>()?;
 
-    table.select(selected_columns)
+    match t {
+        LogicalPlan::TableScan(mut scan) => {
+            let column_indices: Vec<usize> = substrait_schema
+                .strip_qualifiers()
+                .fields()
+                .iter()
+                .map(|substrait_field| {
+                    let df_field =
+                        
df_schema.field_with_unqualified_name(substrait_field.name())?;
+                    ensure_field_compatability(df_field, substrait_field)?;
+
+                    Ok(df_schema
+                        .index_of_column_by_name(None, 
substrait_field.name().as_str())
+                        .unwrap())

Review Comment:
   yes, that's right. In addition there's a `ensure_field_compatability` check 
in there to check that individual data types match up.
   
   ...and also all this comes into play only if base_schema is different from 
catalog table schema. if they match (ln 986), we don't need a projection.



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