retikulum commented on issue #3615:
URL: 
https://github.com/apache/arrow-datafusion/issues/3615#issuecomment-1275331189

   Hi. While I was looking for good first issues, I found this one. I am not a 
professional developer (try to improve my rust skills) and it is my first try 
to contribute a project.
   
   I would like to ask if i am doing things right. Sorry, if I waste your time.
   
   Generally, how do you handle null?  I used 
```Expr::Literal(ScalarValue::Int32(None))``` for this implementation. 
   
   First I added 0 / 0 condition as BinaryExp just like other operators. You 
can find the code below:
   
   ```
               // 0 / 0 -> null
               BinaryExpr {
                   left,
                   op: Divide,
                   right,
               } if is_zero(&left) && is_zero(&right) => 
Expr::Literal(ScalarValue::Int32(None)),
   ```
   Secondly, I changed 
https://github.com/apache/arrow-datafusion/blob/master/datafusion/optimizer/src/simplify_expressions.rs#L798
 to this: 
   
   ```
   } if !info.nullable(&left)? && !info.nullable(&right)? && (left == right) && 
!( is_zero(&left) && is_zero(&right) ) => lit(1),
   ```
   I wrote test but I am not sure about quality.
   
   ```
       #[test]
       fn test_simplify_divide_zero_by_zero() {
           let expr = binary_expr(lit(0), Operator::Divide, lit(0));
           let expected = Expr::Literal(ScalarValue::Int32(None));
   
           assert_eq!(simplify(expr), expected);
       }
   ```
   Thanks in advance :)


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