Dandandan commented on a change in pull request #519:
URL: https://github.com/apache/arrow-datafusion/pull/519#discussion_r646165300
##########
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:
If we pass the `exprs: &[Expr]` to this function we can index to it
directly by `i - 1`.
--
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]