thomas-k-cameron commented on issue #6649:
URL: 
https://github.com/apache/arrow-datafusion/issues/6649#issuecomment-1587727901

   Seems like sql parse doesn't re-organize when it gets `div`/`mul`.
   I think this is the cause of the issue.
   
   `datafusion/sql/src/expr/mod.rs`
   
   ```rust
   impl<'a, S: ContextProvider> SqlToRel<'a, S> {
       pub(crate) fn sql_expr_to_logical_expr(
           &self,
           sql: SQLExpr,
           schema: &DFSchema,
           planner_context: &mut PlannerContext,
       ) -> Result<Expr> {
           enum StackEntry {
               SQLExpr(Box<SQLExpr>),
               Operator(Operator),
           }
   
           // Virtual stack machine to convert SQLExpr to Expr
           // This allows visiting the expr tree in a depth-first manner which
           // produces expressions in postfix notations, i.e. `a + b` => `a b 
+`.
           // See https://github.com/apache/arrow-datafusion/issues/1444
           let mut stack = vec![StackEntry::SQLExpr(Box::new(sql))];
           let mut eval_stack = vec![];
   
           while let Some(entry) = stack.pop() {
               match entry {
                   StackEntry::SQLExpr(sql_expr) => {
                       match *sql_expr {
                           SQLExpr::BinaryOp { left, op, right } => {
                               // Note the order that we push the entries to 
the stack
                               // is important. We want to visit the left node 
first.
                               // todo!
                               let op = self.parse_sql_binary_op(op)?;
                               stack.push(StackEntry::Operator(op));
                               stack.push(StackEntry::SQLExpr(right));
                               stack.push(StackEntry::SQLExpr(left));
                           }
                           _ => {
                               let expr = 
self.sql_expr_to_logical_expr_internal(
                                   *sql_expr,
                                   schema,
                                   planner_context,
                               )?;
                               eval_stack.push(expr);
                           }
                       }
                   }
                   StackEntry::Operator(op) => {
                       let right = eval_stack.pop().unwrap();
                       let left = eval_stack.pop().unwrap();
                       let expr = Expr::BinaryExpr(BinaryExpr::new(
                           Box::new(left),
                           op,
                           Box::new(right),
                       ));
                       eval_stack.push(expr);
                   }
               }
           }
   
           assert_eq!(1, eval_stack.len());
           let expr = eval_stack.pop().unwrap();
           Ok(expr)
       }
   
   ```


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

Reply via email to