bubulalabu commented on code in PR #18019:
URL: https://github.com/apache/datafusion/pull/18019#discussion_r2443307448
##########
datafusion/expr-common/src/signature.rs:
##########
@@ -996,13 +1159,119 @@ impl Signature {
},
),
volatility,
+ parameter_names: None,
}
}
/// Specialized [Signature] for ArrayEmpty and similar functions.
pub fn array(volatility: Volatility) -> Self {
Signature::arrays(1, Some(ListCoercion::FixedSizedListToList),
volatility)
}
+
+ /// Add parameter names to this signature, enabling named argument
notation.
+ ///
+ /// # Example
+ /// ```
+ /// # use datafusion_expr_common::signature::{Signature, Volatility};
+ /// # use arrow::datatypes::DataType;
+ /// let sig = Signature::exact(vec![DataType::Int32, DataType::Utf8],
Volatility::Immutable)
+ /// .with_parameter_names(vec!["count".to_string(),
"name".to_string()]);
+ /// ```
+ ///
+ /// # Errors
+ /// Returns an error if the number of parameter names doesn't match the
signature's arity.
+ /// For signatures with variable arity (e.g., `Variadic`, `VariadicAny`),
parameter names
+ /// cannot be specified.
+ pub fn with_parameter_names(
+ mut self,
+ names: Vec<String>,
+ ) -> datafusion_common::Result<Self> {
+ // Validate that the number of names matches the signature
+ self.validate_parameter_names(&names)?;
+ self.parameter_names = Some(names);
+ Ok(self)
+ }
+
+ /// Validate that parameter names are compatible with this signature
+ fn validate_parameter_names(
+ &self,
+ names: &[String],
+ ) -> datafusion_common::Result<()> {
+ // Get expected argument count from the type signature
+ let expected_count = match &self.type_signature {
+ TypeSignature::Exact(types) => Some(types.len()),
+ TypeSignature::Uniform(count, _) => Some(*count),
+ TypeSignature::Numeric(count) => Some(*count),
+ TypeSignature::String(count) => Some(*count),
+ TypeSignature::Comparable(count) => Some(*count),
+ TypeSignature::Any(count) => Some(*count),
+ TypeSignature::Coercible(types) => Some(types.len()),
+ TypeSignature::Nullary => Some(0),
+ TypeSignature::ArraySignature(ArrayFunctionSignature::Array {
+ arguments,
+ ..
+ }) => Some(arguments.len()),
+
TypeSignature::ArraySignature(ArrayFunctionSignature::RecursiveArray) => {
+ Some(1)
+ }
+ TypeSignature::ArraySignature(ArrayFunctionSignature::MapArray) =>
Some(1),
+ // For OneOf, get the maximum arity from all variants
+ TypeSignature::OneOf(variants) => {
+ // Get max arity from all variants
+ let max_arity = variants
+ .iter()
+ .filter_map(|v| match v {
+ TypeSignature::Any(count)
+ | TypeSignature::Uniform(count, _)
+ | TypeSignature::Numeric(count)
+ | TypeSignature::String(count)
+ | TypeSignature::Comparable(count) => Some(*count),
+ TypeSignature::Exact(types) => Some(types.len()),
+ TypeSignature::Coercible(types) => Some(types.len()),
+ TypeSignature::Nullary => Some(0),
+ _ => None,
+ })
+ .max();
+ max_arity
+ }
+ // Variable arity signatures cannot have parameter names
+ TypeSignature::Variadic(_)
+ | TypeSignature::VariadicAny
+ | TypeSignature::UserDefined => None,
+ };
+
+ if let Some(expected) = expected_count {
+ if names.len() != expected {
+ return datafusion_common::plan_err!(
+ "Parameter names count ({}) does not match signature arity
({})",
+ names.len(),
+ expected
+ );
+ }
+ } else {
+ // For UserDefined signatures, allow parameter names
+ // The function implementer is responsible for validating the
names match the actual arguments
+ if !matches!(self.type_signature, TypeSignature::UserDefined) {
+ return datafusion_common::plan_err!(
Review Comment:
done
--
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]