alamb commented on code in PR #16984: URL: https://github.com/apache/datafusion/pull/16984#discussion_r2258213266
########## datafusion/substrait/src/logical_plan/consumer/expr/scalar_function.rs: ########## @@ -283,6 +290,91 @@ impl BuiltinExprBuilder { case_insensitive, })) } + + async fn build_binary_expr( + consumer: &impl SubstraitConsumer, + fn_name: &str, + f: &ScalarFunction, + input_schema: &DFSchema, + ) -> Result<Expr> { + if f.arguments.len() != 2 { + return substrait_err!("Expect two arguments for `{fn_name}` expr"); + } + let Some(ArgType::Value(a_substrait)) = &f.arguments[0].arg_type else { + return substrait_err!("Invalid argument type for `{fn_name}` expr"); + }; + let a = consumer + .consume_expression(a_substrait, input_schema) + .await?; + let Some(ArgType::Value(b_substrait)) = &f.arguments[1].arg_type else { + return substrait_err!("Invalid argument type for `{fn_name}` expr"); + }; + let b = consumer + .consume_expression(b_substrait, input_schema) + .await?; + match fn_name { + "and_not" => Ok(Self::build_and_not_expr(a, b)), + "xor" => Ok(Self::build_xor_expr(a, b)), + _ => not_impl_err!("Unsupported builtin expression: {}", fn_name), + } + } + + fn build_and_not_expr(a: Expr, b: Expr) -> Expr { + Expr::BinaryExpr(BinaryExpr { + left: Box::new(a), + op: Operator::And, + right: Box::new(Expr::Not(Box::new(b))), + }) + } Review Comment: 🤔 yeah it appears there is a free function https://docs.rs/datafusion/latest/datafusion/logical_expr/fn.not.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-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org