izveigor commented on code in PR #5816:
URL: https://github.com/apache/arrow-datafusion/pull/5816#discussion_r1154823149
##########
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
+pub fn simpl_log(current_args: Vec<Expr>, info: &dyn SimplifyInfo) ->
Result<Expr> {
+ let base = ¤t_args[0];
+ let number = ¤t_args[1];
+
+ match number {
+ Expr::Literal(value)
+ if value == &ScalarValue::new_one(&info.get_data_type(number)?)? =>
+ {
+ Ok(Expr::Literal(ScalarValue::new_zero(
+ &info.get_data_type(base)?,
+ )?))
+ }
+ Expr::ScalarFunction {
+ fun: BuiltinScalarFunction::Power,
+ args,
+ } if base == &args[0] => Ok(args[1].clone()),
+ _ => {
+ if number == base {
+ Ok(Expr::Literal(ScalarValue::new_one(
+ &info.get_data_type(number)?,
+ )?))
+ } else {
+ Ok(Expr::ScalarFunction {
+ fun: BuiltinScalarFunction::Log,
+ args: current_args,
+ })
+ }
+ }
+ }
+}
+
+/// Simplify the `power` function by the relevant rules:
+/// 1. Power(a, 0) ===> 0
+/// 2. Power(a, 1) ===> a
+/// 3. Power(a, Log(a, b)) ===> b
Review Comment:
Should we use the law: Power(a1, a2*a3*a4*Log(a1, a5)) ===> a2*a3*a4*a5? 🤔
--
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]