alamb commented on a change in pull request #8870:
URL: https://github.com/apache/arrow/pull/8870#discussion_r539631894



##########
File path: rust/datafusion/src/logical_plan/builder.rs
##########
@@ -71,37 +98,44 @@ impl LogicalPlanBuilder {
         };
 
         let projected_schema = projection
-            .clone()
             .map(|p| Schema::new(p.iter().map(|i| 
schema.field(*i).clone()).collect()))
-            .or(Some(schema.clone()))
+            .or(Some(schema))
             .unwrap();
+        let projected_schema = 
DFSchemaRef::new(DFSchema::from(&projected_schema)?);
 
-        Ok(Self::from(&LogicalPlan::CsvScan {
-            path: path.to_owned(),
-            schema: SchemaRef::new(schema),
-            has_header,
-            delimiter: Some(delimiter),
-            projection,
-            projected_schema: 
DFSchemaRef::new(DFSchema::from(&projected_schema)?),
-        }))
+        let provider = Arc::new(CsvFile::try_new(path, options)?);
+        let schema = provider.schema();
+
+        let table_scan = LogicalPlan::TableScan {
+            schema_name: "".to_string(),
+            source: TableSource::FromProvider(provider),
+            table_schema: schema,
+            projected_schema,
+            projection: None,
+        };
+
+        Ok(Self::from(&table_scan))
     }
 
     /// Scan a Parquet data source
     pub fn scan_parquet(path: &str, projection: Option<Vec<usize>>) -> 
Result<Self> {
-        let p = ParquetTable::try_new(path)?;
-        let schema = p.schema();
+        let provider = Arc::new(ParquetTable::try_new(path)?);
+        let schema = provider.schema();
 
         let projected_schema = projection
-            .clone()
             .map(|p| Schema::new(p.iter().map(|i| 
schema.field(*i).clone()).collect()));
         let projected_schema = projected_schema.map_or(schema.clone(), 
SchemaRef::new);
+        let projected_schema = 
DFSchemaRef::new(DFSchema::from(&projected_schema)?);

Review comment:
       As an aside I find the current conversion code to/from 
`Schema`/`DFSchema` quite cumbersome and hope to get a PR up later today to 
make it easier to use




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to