hcrosse commented on code in PR #21689: URL: https://github.com/apache/datafusion/pull/21689#discussion_r3119770145
########## datafusion/functions-nested/src/concat_rewrite.rs: ########## @@ -0,0 +1,86 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! [`ConcatArrayRewrite`] rewrites `concat(array, ...)` to `array_concat(array, ...)`. + +use std::any::Any; + +use arrow::datatypes::DataType; +use datafusion_common::config::ConfigOptions; +use datafusion_common::tree_node::Transformed; +use datafusion_common::{DFSchema, Result, plan_err}; +use datafusion_expr::Expr; +use datafusion_expr::ExprSchemable; +use datafusion_expr::expr::ScalarFunction; +use datafusion_expr::expr_rewriter::FunctionRewrite; +use datafusion_functions::string::concat::ConcatFunc; + +use crate::concat::array_concat; + +/// [`FunctionRewrite`] that turns `concat(array, ...)` into +/// `array_concat(array, ...)` at the analyzer phase. +/// +/// `concat` calls with only non-array arguments are left unchanged. +/// Mixed array and non-array arguments are rejected with a plan error. +#[derive(Debug, Default)] +pub struct ConcatArrayRewrite; + +impl FunctionRewrite for ConcatArrayRewrite { Review Comment: I think the ask is for `ConcatFunc::simplify()` to return `Simplified(array_concat(...))` on list args, right? If so, the blocker is crate layering: `ConcatFunc` is in datafusion-functions, `array_concat_udf` is in datafusion-functions-nested, so the dep goes one way. `SimplifyContext` is a concrete struct with no `FunctionRegistry` extension point, so `simplify()` has no supported way to resolve the target UDF. That's what pointed me at `FunctionRewrite`; the trait docs use concat → array_concat as the example, and a custom `AnalyzerRule` looks like it'd work too. One way to unblock the simplify path would be threading `OptimizerConfig::function_registry()` into `SimplifyContext`. Would you prefer we take that approach instead? -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
