rluvaton commented on code in PR #17220:
URL: https://github.com/apache/datafusion/pull/17220#discussion_r2290479805


##########
datafusion/functions-nested/src/array_filter.rs:
##########
@@ -0,0 +1,364 @@
+// 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.
+
+//! [`ScalarUDFImpl`] definitions for array_filter function.
+
+use arrow::array::{Array, ArrayRef, GenericListArray, OffsetSizeTrait, 
RecordBatch};
+use arrow::buffer::OffsetBuffer;
+use arrow::compute::filter;
+use arrow::datatypes::DataType::{LargeList, List};
+use arrow::datatypes::{DataType, Field, Schema};
+use datafusion_common::cast::{as_boolean_array, as_large_list_array, 
as_list_array};
+use datafusion_common::utils::take_function_args;
+use datafusion_common::{exec_err, plan_err, DFSchema, Result};
+use datafusion_expr::expr::{schema_name_from_exprs_ref, ScalarFunction};
+use datafusion_expr::{
+    ColumnarValue, Documentation, ExprSchemable, ScalarUDFImpl, Signature, 
Volatility,
+};
+use datafusion_expr::{Expr, LambdaPlanner, PhysicalLambda, ScalarUDF};
+use datafusion_macros::user_doc;
+
+use std::any::Any;
+use std::hash::{Hash, Hasher};
+use std::sync::Arc;
+
+use crate::utils::make_scalar_function;
+
+make_udf_expr_and_func!(ArrayFilter,
+    array_filter,
+    array lambda, // arg names
+    "filters array elements using a lambda function, returning a new array 
with elements where the lambda returns true.", // doc
+    array_filter_udf // internal function name
+);
+
+/// Implementation of the `array_filter` scalar user-defined function.
+///
+/// This function filters array elements using a lambda function, returning a 
new array
+/// containing only the elements for which the lambda function returns true.
+///
+/// The struct maintains both logical and physical representations of the 
lambda:
+/// - `lambda`: The logical lambda expression from the SQL query
+/// - `physical_lambda`: The planned physical lambda that can be executed
+/// - `signature`: Function signature indicating it operates on arrays
+#[user_doc(
+    doc_section(label = "Array Functions"),
+    description = "Filters array elements using a lambda function.",
+    syntax_example = "array_filter(array, lambda)",
+    sql_example = r#"```sql
+> select array_filter([1, 2, 3, 4, 5], x -> x > 3);
++--------------------------------------------------+
+| array_filter(List([1,2,3,4,5]), x -> x > 3)      |
++--------------------------------------------------+
+| [4, 5]                                           |
++--------------------------------------------------+
+```"#,
+    argument(
+        name = "array",
+        description = "Array expression. Can be a constant, column, or 
function, and any combination of array operators."
+    ),
+    argument(
+        name = "lambda",
+        description = "Lambda function with one argument that returns a 
boolean. The lambda is applied to each element of the array."

Review Comment:
   please add that returning null will be the same as false



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

Reply via email to