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/07 15:02:42 UTC

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

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



##########
File path: datafusion/src/sql/utils.rs
##########
@@ -390,6 +391,29 @@ pub(crate) fn extract_aliases(exprs: &[Expr]) -> HashMap<String, Expr> {
         .collect::<HashMap<String, Expr>>()
 }
 
+pub(crate) fn resolve_positions_to_exprs(
+    expr: &Expr,
+    select_exprs: &[Expr],
+) -> Result<Expr> {
+    match expr {
+        // sql_expr_to_logical_expr maps number to i64
+        // https://github.com/apache/arrow-datafusion/blob/8d175c759e17190980f270b5894348dc4cff9bbf/datafusion/src/sql/planner.rs#L882-L887
+        Expr::Literal(ScalarValue::Int64(Some(pos))) => {

Review comment:
       I left some suggestions for tests which I think will help cover this case as well

##########
File path: datafusion/src/sql/planner.rs
##########
@@ -2319,6 +2320,16 @@ mod tests {
         );
     }
 
+    #[test]
+    fn select_simple_aggregate_with_groupby_can_use_positions() {
+        quick_test(
+            "SELECT state, age AS b, COUNT(1) FROM person GROUP BY 1, 2",
+            "Projection: #state, #age AS b, #COUNT(UInt8(1))\
+             \n  Aggregate: groupBy=[[#state, #age]], aggr=[[COUNT(UInt8(1))]]\
+             \n    TableScan: person projection=None",
+        );
+    }

Review comment:
       Can you also please add the following tests:
   
   1. A test that groups in an order other than written, for example,  `SELECT state, age AS b, COUNT(1) FROM person GROUP BY 2,1 `?
   2. A test that has an invalid group index. for example,  `SELECT state, age AS b, COUNT(1) FROM person GROUP BY 5`?
   3. A test that where the index is not valid at all, for example:  `SELECT state, age AS b, COUNT(1) FROM person GROUP BY 0`?

##########
File path: datafusion/src/sql/utils.rs
##########
@@ -390,6 +391,29 @@ pub(crate) fn extract_aliases(exprs: &[Expr]) -> HashMap<String, Expr> {
         .collect::<HashMap<String, Expr>>()
 }
 
+pub(crate) fn resolve_positions_to_exprs(
+    expr: &Expr,

Review comment:
       You can probably save a clone here by passing in `expr` directly (rather than a reference)




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