Dandandan commented on a change in pull request #519:
URL: https://github.com/apache/arrow-datafusion/pull/519#discussion_r646165045



##########
File path: datafusion/src/sql/utils.rs
##########
@@ -390,6 +390,42 @@ pub(crate) fn extract_aliases(exprs: &[Expr]) -> 
HashMap<String, Expr> {
         .collect::<HashMap<String, Expr>>()
 }
 
+/// Returns mapping of each position (`String`) to the expression (`Expr`) it 
is
+/// aliasing.
+pub(crate) fn extract_positions(exprs: &[Expr]) -> HashMap<String, Expr> {
+    let mut position = 0;
+    exprs
+        .iter()
+        .filter_map(|expr| match expr {
+            // position starts with 1
+            Expr::Alias(nested_expr, _alias_name) => {
+                position += 1;
+                Some((position.clone().to_string(), *nested_expr.clone()))
+            }
+            _ => {
+                position += 1;
+                Some((position.clone().to_string(), expr.clone()))
+            }
+        })
+        .collect::<HashMap<String, Expr>>()

Review comment:
       I think there might be no need to build a hashmap as we can index the 
expression slice directly.




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