Dandandan commented on code in PR #11483:
URL: https://github.com/apache/datafusion/pull/11483#discussion_r1681127065


##########
datafusion/core/src/physical_optimizer/pruning.rs:
##########
@@ -736,12 +738,22 @@ impl RequiredColumns {
         Self::default()
     }
 
-    /// Returns number of unique columns
-    pub(crate) fn n_columns(&self) -> usize {
-        self.iter()
-            .map(|(c, _s, _f)| c)
-            .collect::<HashSet<_>>()
-            .len()
+    /// Returns Some(column) if this is a single column predicate.
+    ///
+    /// Returns None if this is a multi-column predicate.
+    ///
+    /// Examples:
+    /// * `a > 5 OR a < 10` returns `Some(a)`
+    /// * `a > 5 OR b < 10` returns `None`
+    /// * `true` returns None
+    pub(crate) fn single_column(&self) -> Option<&phys_expr::Column> {
+        let cols = self.iter().map(|(c, _s, _f)| c).collect::<HashSet<_>>();

Review Comment:
   It seems a bit wasteful to collect into a `HashSet` only to decide whether 
it's a single column?
   We can do e.g. `self.columns.windows(2).all(|[x, y]| x.0 == y.0)`



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