alamb commented on code in PR #5816:
URL: https://github.com/apache/arrow-datafusion/pull/5816#discussion_r1154833265


##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -2210,6 +2222,68 @@ mod tests {
         assert_eq!(simplify(expr_eq), lit(true));
     }
 
+    #[test]
+    fn test_simplify_log() {
+        // Log(c3, 1) ===> 0
+        {
+            let expr = log(col("c3_non_null"), lit(1));
+            let expected = lit(0i64);
+            assert_eq!(simplify(expr), expected);
+        }
+        // Log(c3, c3) ===> 1
+        {
+            let expr = log(col("c3_non_null"), col("c3_non_null"));
+            let expected = lit(1i64);
+            assert_eq!(simplify(expr), expected);
+        }
+        // Log(c3, Power(c3, c4)) ===> c4
+        {
+            let expr = log(
+                col("c3_non_null"),
+                power(col("c3_non_null"), col("c4_non_null")),
+            );
+            let expected = col("c4_non_null");
+            assert_eq!(simplify(expr), expected);
+        }
+        // Log(c3, c4) ===> c4
+        {
+            let expr = log(col("c3_non_null"), col("c4_non_null"));
+            let expected = log(col("c3_non_null"), col("c4_non_null"));
+            assert_eq!(simplify(expr), expected);
+        }
+    }
+
+    #[test]
+    fn test_simplify_power() {
+        // Power(c3, 0) ===> 0
+        {
+            let expr = power(col("c3_non_null"), lit(0));
+            let expected = lit(0i64);
+            assert_eq!(simplify(expr), expected);
+        }
+        // Power(c3, 1) ===> a

Review Comment:
   ```suggestion
           // Power(c3, 1) ===> c3
   ```



##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -2210,6 +2222,68 @@ mod tests {
         assert_eq!(simplify(expr_eq), lit(true));
     }
 
+    #[test]
+    fn test_simplify_log() {
+        // Log(c3, 1) ===> 0
+        {
+            let expr = log(col("c3_non_null"), lit(1));
+            let expected = lit(0i64);
+            assert_eq!(simplify(expr), expected);
+        }
+        // Log(c3, c3) ===> 1
+        {
+            let expr = log(col("c3_non_null"), col("c3_non_null"));
+            let expected = lit(1i64);
+            assert_eq!(simplify(expr), expected);
+        }
+        // Log(c3, Power(c3, c4)) ===> c4
+        {
+            let expr = log(
+                col("c3_non_null"),
+                power(col("c3_non_null"), col("c4_non_null")),
+            );
+            let expected = col("c4_non_null");
+            assert_eq!(simplify(expr), expected);
+        }
+        // Log(c3, c4) ===> c4
+        {
+            let expr = log(col("c3_non_null"), col("c4_non_null"));
+            let expected = log(col("c3_non_null"), col("c4_non_null"));
+            assert_eq!(simplify(expr), expected);
+        }
+    }
+
+    #[test]
+    fn test_simplify_power() {
+        // Power(c3, 0) ===> 0

Review Comment:
   Shouldn't `c^0` be `1` (not `0`)?



##########
datafusion/common/src/scalar.rs:
##########
@@ -1705,6 +1705,29 @@ impl ScalarValue {
         })
     }
 
+    /// Create an one value in the given type.
+    pub fn new_one(datatype: &DataType) -> Result<ScalarValue> {
+        assert!(datatype.is_primitive());
+        Ok(match datatype {
+            DataType::Boolean => ScalarValue::Boolean(Some(true)),

Review Comment:
   Boolean doesn't make sense to me as it isn't numeric. I think Boolean should 
also return an error



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