You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/06/06 22:17:37 UTC

[GitHub] [arrow-datafusion] jychen7 commented on a change in pull request #519: 110 support group by positions

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



##########
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>>()
+}
+
+pub(crate) fn resolve_positions_to_exprs(
+    expr: &Expr,
+    positions: &HashMap<String, Expr>,
+) -> Result<Expr> {

Review comment:
       @Dandandan thanks for the suggestion.
   I use HashMap initially because of the `to_string()` type cast is easier to handle. After some exploring, I now change it to array.




-- 
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:
users@infra.apache.org