You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2023/04/03 13:03:06 UTC
[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #5816: feat: add optimization support to LOG and POWER functions
alamb commented on code in PR #5816:
URL: https://github.com/apache/arrow-datafusion/pull/5816#discussion_r1155932650
##########
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
Review Comment:
```suggestion
// Log(c3, c4) ===> Log(c3, c4)
```
##########
datafusion/optimizer/src/simplify_expressions/utils.rs:
##########
@@ -350,6 +351,73 @@ pub fn distribute_negation(expr: Expr) -> Expr {
}
}
+/// Simplify the `log` function by the relevant rules:
+/// 1. Log(a, 1) ===> 0
+/// 2. Log(a, a) ===> 1
+/// 3. Log(a, Power(a, b)) ===> b
Review Comment:
I think this is a good set of changes for now.
##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -1072,6 +1072,18 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for Simplifier<'a, S> {
out_expr.rewrite(self)?
}
+ // log
Review Comment:
I agree splitting it into smaller modules would be a great idea for a follow on PR
##########
datafusion/common/src/scalar.rs:
##########
@@ -1723,6 +1745,27 @@ impl ScalarValue {
})
}
+ pub fn new_ten(datatype: &DataType) -> Result<ScalarValue> {
Review Comment:
It sounds like a reasonable idea. Thanks @izveigor
It might be possible to to use the traits defined in arrow-rs for this: https://docs.rs/arrow/latest/arrow/array/trait.ArrowPrimitiveType.html
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org