timsaucer commented on code in PR #18624:
URL: https://github.com/apache/datafusion/pull/18624#discussion_r2515511516


##########
datafusion/core/src/dataframe/mod.rs:
##########
@@ -310,11 +310,20 @@ impl DataFrame {
     pub fn select_columns(self, columns: &[&str]) -> Result<DataFrame> {
         let fields = columns
             .iter()
-            .flat_map(|name| {
-                self.plan
+            .map(|name| {
+                let fields = self
+                    .plan
                     .schema()
-                    .qualified_fields_with_unqualified_name(name)
+                    .qualified_fields_with_unqualified_name(name);
+                if fields.is_empty() {
+                    Err(unqualified_field_not_found(name, self.plan.schema()))
+                } else {
+                    Ok(fields)

Review Comment:
   I do think this check will ensure we have all the fields. In fact, the unit 
test I added has 1 field that does exist and 2 that do not.
   
   The if a single one of the requested columns returns no fields, then the 
entire operation should fail. Is there a different case you're thinking of?



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