crm26 commented on code in PR #21861: URL: https://github.com/apache/datafusion/pull/21861#discussion_r3174635889
########## datafusion/functions-nested/src/inner_product.rs: ########## @@ -0,0 +1,208 @@ +// 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 inner_product function. + +use crate::utils::make_scalar_function; +use arrow::array::{Array, ArrayRef, Float64Array, OffsetSizeTrait}; +use arrow::datatypes::{ + DataType, + DataType::{FixedSizeList, LargeList, List, Null}, + Field, +}; +use datafusion_common::cast::{as_float64_array, as_generic_list_array}; +use datafusion_common::utils::{ListCoercion, coerced_type_with_base_type_only}; +use datafusion_common::{ + Result, exec_err, internal_err, plan_err, utils::take_function_args, +}; +use datafusion_expr::{ + ColumnarValue, Documentation, ScalarFunctionArgs, ScalarUDFImpl, Signature, + Volatility, +}; +use datafusion_macros::user_doc; +use std::sync::Arc; + +make_udf_expr_and_func!( + InnerProduct, + inner_product, + array1 array2, + "returns the inner product (dot product) of two numeric arrays.", + inner_product_udf +); + +#[user_doc( + doc_section(label = "Array Functions"), + description = "Returns the inner product (dot product) of two input arrays of equal length, computed as `sum(array1[i] * array2[i])`. Returns NULL if either array is NULL or contains NULL elements. Returns 0.0 for two empty arrays.", + syntax_example = "inner_product(array1, array2)", + sql_example = r#"```sql +> select inner_product([1.0, 2.0, 3.0], [4.0, 5.0, 6.0]); ++-------------------------------------------------------+ +| inner_product(List([1.0,2.0,3.0]),List([4.0,5.0,6.0])) | ++-------------------------------------------------------+ +| 32.0 | ++-------------------------------------------------------+ +```"#, + argument( + name = "array1", + description = "Array expression. Can be a constant, column, or function, and any combination of array operators." + ), + argument( + name = "array2", + description = "Array expression. Can be a constant, column, or function, and any combination of array operators." + ) +)] +#[derive(Debug, PartialEq, Eq, Hash)] +pub struct InnerProduct { + signature: Signature, Review Comment: Thanks @Jefffrey — added `dot_product` as an alias in `ef9895005`, with SLT coverage for both a constant-args and a multi-row-with-NULL case. Doc regen picked up the alias automatically (`#### Aliases` block under `inner_product`, plus a top-level `### dot_product` _Alias of_ stub). -- 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]
