alamb commented on code in PR #14439:
URL: https://github.com/apache/datafusion/pull/14439#discussion_r1947188396


##########
datafusion/common/src/error.rs:
##########
@@ -569,6 +601,63 @@ impl DataFusionError {
 
         DiagnosticsIterator { head: self }.next()
     }
+
+    /// Sometimes DataFusion is able to collect multiple errors in a SQL query
+    /// before terminating, e.g. across different expressions in a SELECT
+    /// statements or different sides of a UNION. This method returns an
+    /// iterator over all the errors in the collection.
+    ///
+    /// For this to work, the top-level error must be a
+    /// `DataFusionError::Collection`, not something that contains it.
+    pub fn iter(&self) -> impl Iterator<Item = &DataFusionError> {
+        struct ErrorIterator<'a> {
+            queue: VecDeque<&'a DataFusionError>,
+        }
+
+        impl<'a> Iterator for ErrorIterator<'a> {
+            type Item = &'a DataFusionError;
+
+            fn next(&mut self) -> Option<Self::Item> {
+                loop {
+                    let popped = self.queue.pop_front()?;
+                    match popped {
+                        DataFusionError::Collection(errs) => 
self.queue.extend(errs),
+                        _ => return Some(popped),
+                    }
+                }
+            }
+        }
+
+        let mut queue = VecDeque::new();
+        queue.push_back(self);
+        ErrorIterator { queue }
+    }
+}
+
+pub struct DataFusionErrorBuilder(Vec<DataFusionError>);

Review Comment:
   I made a follow on PR to add docs and examples:
   - https://github.com/apache/datafusion/pull/14551



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to